Skip to content

Commit

Permalink
Merge pull request cms-sw#12 from bendavid/WmassNanoProd_106X_genWeig…
Browse files Browse the repository at this point in the history
…hts_trackrefit_improve

Updates to muon track refit and nano content
  • Loading branch information
kdlong authored Feb 17, 2022
2 parents 5272516 + 2f13a8b commit ab97831
Show file tree
Hide file tree
Showing 3 changed files with 212 additions and 69 deletions.
78 changes: 78 additions & 0 deletions Analysis/HitAnalyzer/plugins/GlobalIdxProducer.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#include "FWCore/Framework/interface/stream/EDProducer.h"
#include "FWCore/Framework/interface/MakerMacros.h"

#include "DataFormats/TrackReco/interface/Track.h"
#include "DataFormats/TrackReco/interface/TrackFwd.h"
#include "DataFormats/TrackReco/interface/TrackExtraFwd.h"

class GlobalIdxProducer : public edm::stream::EDProducer<>
{
public:
explicit GlobalIdxProducer(const edm::ParameterSet &);
~GlobalIdxProducer() {}

// static void fillDescriptions(edm::ConfigurationDescriptions &descriptions);

private:

virtual void produce(edm::Event &, const edm::EventSetup &) override;

using map_t = edm::ValueMap<std::vector<int>>;

edm::EDGetTokenT<map_t> inputGlobalIdxs0_;
edm::EDGetTokenT<map_t> inputGlobalIdxs1_;
edm::EDPutTokenT<map_t> outputGlobalIdxs_;


};


GlobalIdxProducer::GlobalIdxProducer(const edm::ParameterSet &iConfig)

{
inputGlobalIdxs0_ = consumes<map_t>(iConfig.getParameter<edm::InputTag>("src0"));
inputGlobalIdxs1_ = consumes<map_t>(iConfig.getParameter<edm::InputTag>("src1"));

outputGlobalIdxs_ = produces<map_t>();
}

// ------------ method called for each event ------------
void GlobalIdxProducer::produce(edm::Event &iEvent, const edm::EventSetup &iSetup)
{
using namespace edm;

Handle<map_t> idxs0;
iEvent.getByToken(inputGlobalIdxs0_, idxs0);

Handle<map_t> idxs1;
iEvent.getByToken(inputGlobalIdxs1_, idxs1);


// take idxs from idxs0, unless idxs0 is empty, then take them from idxs1
map_t idxsout = *idxs0;

for (auto it = idxsout.begin(); it != idxsout.end(); ++it) {
auto const id = it.id();
auto const size = it.size();
if (!idxs1->contains(id)) {
throw std::runtime_error("product ids should always match");
}
for (std::size_t i = 0; i < size; ++i) {
auto &valout = idxsout.get(id, i);
auto const &val1 = idxs1->get(id, i);

if (!valout.empty() && ! val1.empty() && valout != val1) {
throw std::runtime_error("idxs should always be either empty or equal;");
}

if (valout.empty() && !val1.empty()) {
valout = val1;
}
}
}

iEvent.emplace(outputGlobalIdxs_, std::move(idxsout));

}

DEFINE_FWK_MODULE(GlobalIdxProducer);
Loading

0 comments on commit ab97831

Please sign in to comment.