CMS 3D CMS Logo

CosmicsMuonIdProducer.cc
Go to the documentation of this file.
1 #include <string>
2 #include <vector>
3 
9 
16 
18 
20 public:
22  : inputMuonCollection_(iConfig.getParameter<edm::InputTag>("muonCollection")),
23  inputTrackCollections_(iConfig.getParameter<std::vector<edm::InputTag>>("trackCollections")) {
24  edm::ConsumesCollector iC = consumesCollector();
26  new MuonCosmicCompatibilityFiller(iConfig.getParameter<edm::ParameterSet>("CosmicCompFillerParameters"), iC);
27 
28  produces<edm::ValueMap<unsigned int>>().setBranchAlias("cosmicsVeto");
29  produces<edm::ValueMap<reco::MuonCosmicCompatibility>>().setBranchAlias("cosmicCompatibility");
30 
31  muonToken_ = consumes<reco::MuonCollection>(inputMuonCollection_);
32  for (unsigned int i = 0; i < inputTrackCollections_.size(); ++i)
33  trackTokens_.push_back(consumes<reco::TrackCollection>(inputTrackCollections_.at(i)));
34  }
37  delete compatibilityFiller_;
38  }
39 
40 private:
41  void produce(edm::Event&, const edm::EventSetup&) override;
43  std::vector<edm::InputTag> inputTrackCollections_;
45  std::vector<edm::EDGetTokenT<reco::TrackCollection>> trackTokens_;
46 
48 };
49 
52  iEvent.getByToken(muonToken_, muons);
53  // reserve some space
54  std::vector<unsigned int> values;
55  values.reserve(muons->size());
56 
57  std::vector<reco::MuonCosmicCompatibility> compValues;
58  compValues.reserve(muons->size());
59 
60  for (reco::MuonCollection::const_iterator muon = muons->begin(); muon != muons->end(); ++muon) {
61  unsigned int foundPartner(0);
62  if (muon->innerTrack().isNonnull()) {
63  for (unsigned int i = 0; i < inputTrackCollections_.size(); ++i) {
65  iEvent.getByToken(trackTokens_.at(i), tracks);
66  if (muonid::findOppositeTrack(tracks, *muon->innerTrack()).isNonnull()) {
67  foundPartner = i + 1;
68  break;
69  }
70  }
71  }
72  values.push_back(foundPartner);
73 
74  compValues.push_back(compatibilityFiller_->fillCompatibility(*muon, iEvent, iSetup));
75  }
76 
77  // create and fill value map
78  auto out = std::make_unique<edm::ValueMap<unsigned int>>();
80  filler.insert(muons, values.begin(), values.end());
81  filler.fill();
82 
83  auto outC = std::make_unique<edm::ValueMap<reco::MuonCosmicCompatibility>>();
85  fillerC.insert(muons, compValues.begin(), compValues.end());
86  fillerC.fill();
87 
88  // put value map into event
89  iEvent.put(std::move(out));
90  iEvent.put(std::move(outC));
91 }
void produce(edm::Event &, const edm::EventSetup &) override
std::vector< edm::EDGetTokenT< reco::TrackCollection > > trackTokens_
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
reco::TrackRef findOppositeTrack(const edm::Handle< reco::TrackCollection > &collection, const reco::Track &muon, double angleMatch=0.01, double momentumMatch=0.05)
std::vector< edm::InputTag > inputTrackCollections_
muons
the two sets of parameters below are mutually exclusive, depending if RECO or ALCARECO is used the us...
Definition: DiMuonV_cfg.py:212
int iEvent
Definition: GenABIO.cc:224
MuonCosmicCompatibilityFiller * compatibilityFiller_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
reco::MuonCosmicCompatibility fillCompatibility(const reco::Muon &muon, edm::Event &, const edm::EventSetup &)
fill cosmic compatibility variables
edm::EDGetTokenT< reco::MuonCollection > muonToken_
HLT enums.
CosmicsMuonIdProducer(const edm::ParameterSet &iConfig)
def move(src, dest)
Definition: eostools.py:511