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  {
25  edm::ConsumesCollector iC = consumesCollector();
26  compatibilityFiller_ = 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 
35  }
38  delete compatibilityFiller_;
39  }
40 
41 private:
42  void produce(edm::Event&, const edm::EventSetup&) override;
44  std::vector<edm::InputTag> inputTrackCollections_;
46  std::vector<edm::EDGetTokenT<reco::TrackCollection> > trackTokens_;
47 
48 
50 };
51 
52 void
54 {
56  iEvent.getByToken(muonToken_, muons);
57  // reserve some space
58  std::vector<unsigned int> values;
59  values.reserve(muons->size());
60 
61  std::vector<reco::MuonCosmicCompatibility> compValues;
62  compValues.reserve(muons->size());
63 
64  for(reco::MuonCollection::const_iterator muon = muons->begin();
65  muon != muons->end(); ++muon)
66  {
67  unsigned int foundPartner(0);
68  if ( muon->innerTrack().isNonnull() ){
69  for ( unsigned int i=0; i<inputTrackCollections_.size(); ++i )
70  {
72  iEvent.getByToken(trackTokens_.at(i), tracks);
73  if ( muonid::findOppositeTrack(tracks,*muon->innerTrack()).isNonnull() ){
74  foundPartner = i+1;
75  break;
76  }
77  }
78  }
79  values.push_back(foundPartner);
80 
81  compValues.push_back(compatibilityFiller_->fillCompatibility(*muon, iEvent, iSetup));
82  }
83 
84  // create and fill value map
85  auto out = std::make_unique<edm::ValueMap<unsigned int>>();
87  filler.insert(muons, values.begin(), values.end());
88  filler.fill();
89 
90 
91  auto outC = std::make_unique<edm::ValueMap<reco::MuonCosmicCompatibility>>();
93  fillerC.insert(muons, compValues.begin(), compValues.end());
94  fillerC.fill();
95 
96  // put value map into event
97  iEvent.put(std::move(out));
98  iEvent.put(std::move(outC));
99 }
void produce(edm::Event &, const edm::EventSetup &) override
T getParameter(std::string const &) const
std::vector< edm::EDGetTokenT< reco::TrackCollection > > trackTokens_
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:136
reco::TrackRef findOppositeTrack(const edm::Handle< reco::TrackCollection > &collection, const reco::Track &muon, double angleMatch=0.01, double momentumMatch=0.05)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:519
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
std::vector< edm::InputTag > inputTrackCollections_
int iEvent
Definition: GenABIO.cc:230
MuonCosmicCompatibilityFiller * compatibilityFiller_
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:510