CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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  {
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  virtual 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  std::auto_ptr<edm::ValueMap<unsigned int> > out(new edm::ValueMap<unsigned int>());
87  filler.insert(muons, values.begin(), values.end());
88  filler.fill();
89 
90 
91  std::auto_ptr<edm::ValueMap<reco::MuonCosmicCompatibility> > outC(new 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(out);
98  iEvent.put(outC);
99 }
virtual void produce(edm::Event &, const edm::EventSetup &) override
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
std::vector< edm::EDGetTokenT< reco::TrackCollection > > trackTokens_
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:446
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
void insert(const H &h, I begin, I end)
Definition: ValueMap.h:52
std::vector< edm::InputTag > inputTrackCollections_
int iEvent
Definition: GenABIO.cc:230
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:113
ConsumesCollector consumesCollector()
Use a ConsumesCollector to gather consumes information from helper functions.
MuonCosmicCompatibilityFiller * compatibilityFiller_
reco::MuonCosmicCompatibility fillCompatibility(const reco::Muon &muon, edm::Event &, const edm::EventSetup &)
fill cosmic compatibility variables
tuple out
Definition: dbtoconf.py:99
tuple tracks
Definition: testEve_cfg.py:39
edm::EDGetTokenT< reco::MuonCollection > muonToken_
tuple muons
Definition: patZpeak.py:38
CosmicsMuonIdProducer(const edm::ParameterSet &iConfig)