CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
MuonAssociatorByHits.cc
Go to the documentation of this file.
14 #include <sstream>
15 
16 using namespace reco;
17 using namespace std;
18 using namespace muonAssociatorByHitsDiagnostics;
19 
20 namespace muonAssociatorByHitsDiagnostics {
22 
23  class InputDumper {
24  public:
26  simtracksTag(conf.getParameter<edm::InputTag>("simtracksTag")),
27  simtracksXFTag(conf.getParameter<edm::InputTag>("simtracksXFTag")),
28  crossingframe(conf.getParameter<bool>("crossingframe")) {}
29 
31  InputDumper(conf)
32  {
33  if (crossingframe) {
34  iC.consumes<CrossingFrame<SimTrack> >(simtracksXFTag);
35  iC.consumes<CrossingFrame<SimVertex> >(simtracksXFTag);
36  }
37  else{
38  iC.consumes<edm::SimTrackContainer>(simtracksTag);
39  iC.consumes<edm::SimVertexContainer>(simtracksTag);
40  }
41  }
42 
43  void dump(const TrackHitsCollection&, const TrackingParticleCollection&, const edm::Event&) const;
44 
45  private:
48  bool const crossingframe;
49  };
50 
51  void
53  // reco::Track collection
54  edm::LogVerbatim("MuonAssociatorByHits")<<"\n"<<"reco::Track collection --- size = "<<tC.size();
55 
56 
57  // TrackingParticle collection
58  edm::LogVerbatim("MuonAssociatorByHits")<<"\n"<<"TrackingParticle collection --- size = "<<tPC.size();
59  int j = 0;
60  for(TrackingParticleCollection::const_iterator ITER=tPC.begin(); ITER!=tPC.end(); ITER++, j++) {
61  edm::LogVerbatim("MuonAssociatorByHits")
62  <<"TrackingParticle "<<j<<", q = "<<ITER->charge()<<", p = "<<ITER->p()
63  <<", pT = "<<ITER->pt()<<", eta = "<<ITER->eta()<<", phi = "<<ITER->phi();
64 
65  edm::LogVerbatim("MuonAssociatorByHits")
66  <<"\t pdg code = "<<ITER->pdgId()<<", made of "<<ITER->numberOfHits()<<" PSimHit"
67  <<" (in "<<ITER->numberOfTrackerLayers()<<" layers)"
68  <<" from "<<ITER->g4Tracks().size()<<" SimTrack:";
69  for (TrackingParticle::g4t_iterator g4T=ITER->g4Track_begin(); g4T!=ITER->g4Track_end(); g4T++) {
70  edm::LogVerbatim("MuonAssociatorByHits")
71  <<"\t\t Id:"<<g4T->trackId()<<"/Evt:("<<g4T->eventId().event()<<","<<g4T->eventId().bunchCrossing()<<")";
72  }
73  }
74 
75  // SimTrack collection
77  edm::Handle<edm::SimTrackContainer> simTrackCollection;
78 
79  // SimVertex collection
80  edm::Handle<CrossingFrame<SimVertex> > cf_simvertices;
81  edm::Handle<edm::SimVertexContainer> simVertexCollection;
82 
83  if (crossingframe) {
84  event.getByLabel(simtracksXFTag,cf_simtracks);
85  auto_ptr<MixCollection<SimTrack> > SimTk( new MixCollection<SimTrack>(cf_simtracks.product()) );
86  edm::LogVerbatim("MuonAssociatorByHits")<<"\n"<<"CrossingFrame<SimTrack> collection with InputTag = "<<simtracksXFTag
87  <<" has size = "<<SimTk->size();
88  int k = 0;
89  for (MixCollection<SimTrack>::MixItr ITER=SimTk->begin(); ITER!=SimTk->end(); ITER++, k++) {
90  edm::LogVerbatim("MuonAssociatorByHits")
91  <<"SimTrack "<<k
92  <<" - Id:"<<ITER->trackId()<<"/Evt:("<<ITER->eventId().event()<<","<<ITER->eventId().bunchCrossing()<<")"
93  <<" pdgId = "<<ITER->type()<<", q = "<<ITER->charge()<<", p = "<<ITER->momentum().P()
94  <<", pT = "<<ITER->momentum().Pt()<<", eta = "<<ITER->momentum().Eta()<<", phi = "<<ITER->momentum().Phi()
95  <<"\n * "<<*ITER <<endl;
96  }
97  event.getByLabel(simtracksXFTag,cf_simvertices);
98  auto_ptr<MixCollection<SimVertex> > SimVtx( new MixCollection<SimVertex>(cf_simvertices.product()) );
99  edm::LogVerbatim("MuonAssociatorByHits")<<"\n"<<"CrossingFrame<SimVertex> collection with InputTag = "<<simtracksXFTag
100  <<" has size = "<<SimVtx->size();
101  int kv = 0;
102  for (MixCollection<SimVertex>::MixItr VITER=SimVtx->begin(); VITER!=SimVtx->end(); VITER++, kv++){
103  edm::LogVerbatim("MuonAssociatorByHits")
104  <<"SimVertex "<<kv
105  << " : "<< *VITER <<endl;
106  }
107  }
108  else {
109  event.getByLabel(simtracksTag,simTrackCollection);
110  const edm::SimTrackContainer simTC = *(simTrackCollection.product());
111  edm::LogVerbatim("MuonAssociatorByHits")<<"\n"<<"SimTrack collection with InputTag = "<<simtracksTag
112  <<" has size = "<<simTC.size()<<endl;
113  int k = 0;
114  for(edm::SimTrackContainer::const_iterator ITER=simTC.begin(); ITER!=simTC.end(); ITER++, k++){
115  edm::LogVerbatim("MuonAssociatorByHits")
116  <<"SimTrack "<<k
117  <<" - Id:"<<ITER->trackId()<<"/Evt:("<<ITER->eventId().event()<<","<<ITER->eventId().bunchCrossing()<<")"
118  <<" pdgId = "<<ITER->type()<<", q = "<<ITER->charge()<<", p = "<<ITER->momentum().P()
119  <<", pT = "<<ITER->momentum().Pt()<<", eta = "<<ITER->momentum().Eta()<<", phi = "<<ITER->momentum().Phi()
120  <<"\n * "<<*ITER <<endl;
121  }
122  event.getByLabel(simtracksTag,simVertexCollection);
123  const edm::SimVertexContainer simVC = *(simVertexCollection.product());
124  edm::LogVerbatim("MuonAssociatorByHits")<<"\n"<<"SimVertex collection with InputTag = "<<"g4SimHits"
125  <<" has size = "<<simVC.size()<<endl;
126  int kv = 0;
127  for (edm::SimVertexContainer::const_iterator VITER=simVC.begin(); VITER!=simVC.end(); VITER++, kv++){
128  edm::LogVerbatim("MuonAssociatorByHits")
129  <<"SimVertex "<<kv
130  << " : "<< *VITER <<endl;
131  }
132  }
133  }
134 
135 }
136 
137 
139  helper_(conf),
140  conf_(conf)
141 {
142  //hack for consumes
143  RPCHitAssociator rpctruth(conf,std::move(iC));
144  DTHitAssociator dttruth(conf,std::move(iC));
145  CSCHitAssociator muonTruth(conf,std::move(iC));
146  TrackerHitAssociator trackertruth(conf,std::move(iC));
147  if( conf.getUntrackedParameter<bool>("dumpInputCollections") ) {
148  diagnostics_.reset( new InputDumper(conf, std::move(iC)) );
149  }
150 }
151 
152 //compatibility constructor - argh
154  helper_(conf),
155  conf_(conf)
156 {
157  if( conf.getUntrackedParameter<bool>("dumpInputCollections") ) {
158  diagnostics_.reset( new InputDumper(conf) );
159  }
160 }
161 
162 
163 
165 {
166 }
167 
170  const edm::RefVector<TrackingParticleCollection>& TPCollectionH,
171  const edm::Event * e, const edm::EventSetup * setup) const{
172  RecoToSimCollection outputCollection;
173 
175  for (auto it = tC.begin(), ed = tC.end(); it != ed; ++it) {
176  tH.push_back(std::make_pair((*it)->recHitsBegin(), (*it)->recHitsEnd()));
177  }
178 
179  //Retrieve tracker topology from geometry
181  setup->get<IdealGeometryRecord>().get(tTopoHand);
182  const TrackerTopology *tTopo=tTopoHand.product();
183 
184 
185  // Tracker hit association
186  TrackerHitAssociator trackertruth(*e, conf_);
187  // CSC hit association
188  CSCHitAssociator csctruth(*e,*setup,conf_);
189  // DT hit association
190  bool printRtS(true);
191  DTHitAssociator dttruth(*e,*setup,conf_,printRtS);
192  // RPC hit association
193  RPCHitAssociator rpctruth(*e,*setup,conf_);
194 
195  MuonAssociatorByHitsHelper::Resources resources = {tTopo, &trackertruth, &csctruth, &dttruth, &rpctruth};
196 
197  if(diagnostics_) {
198  resources.diagnostics_ = [this, e](const TrackHitsCollection& hC, const TrackingParticleCollection& pC) {
199  diagnostics_->dump(hC,pC, *e);
200  };
201  }
202 
203  auto bareAssoc = helper_.associateRecoToSimIndices(tH, TPCollectionH, resources);
204  for (auto it = bareAssoc.begin(), ed = bareAssoc.end(); it != ed; ++it) {
205  for (auto itma = it->second.begin(), edma = it->second.end(); itma != edma; ++itma) {
206  outputCollection.insert(tC[it->first], std::make_pair(TPCollectionH[itma->idx], itma->quality));
207  }
208  }
209 
210  outputCollection.post_insert(); // perhaps not even necessary
211  return outputCollection;
212 }
213 
216  const edm::RefVector<TrackingParticleCollection>& TPCollectionH,
217  const edm::Event * e, const edm::EventSetup * setup) const{
218 
219  SimToRecoCollection outputCollection;
221  for (auto it = tC.begin(), ed = tC.end(); it != ed; ++it) {
222  tH.push_back(std::make_pair((*it)->recHitsBegin(), (*it)->recHitsEnd()));
223  }
224 
225  //Retrieve tracker topology from geometry
227  setup->get<IdealGeometryRecord>().get(tTopoHand);
228  const TrackerTopology *tTopo=tTopoHand.product();
229 
230  // Tracker hit association
231  TrackerHitAssociator trackertruth(*e, conf_);
232  // CSC hit association
233  CSCHitAssociator csctruth(*e,*setup,conf_);
234  // DT hit association
235  bool printRtS = false;
236  DTHitAssociator dttruth(*e,*setup,conf_,printRtS);
237  // RPC hit association
238  RPCHitAssociator rpctruth(*e,*setup,conf_);
239 
240  MuonAssociatorByHitsHelper::Resources resources = {tTopo, &trackertruth, &csctruth, &dttruth, &rpctruth};
241 
242  auto bareAssoc = helper_.associateSimToRecoIndices(tH, TPCollectionH, resources);
243  for (auto it = bareAssoc.begin(), ed = bareAssoc.end(); it != ed; ++it) {
244  for (auto itma = it->second.begin(), edma = it->second.end(); itma != edma; ++itma) {
245  outputCollection.insert(TPCollectionH[ it->first],
246  std::make_pair(tC[itma->idx], itma->quality));
247  }
248  }
249 
250  outputCollection.post_insert(); // perhaps not even necessary
251  return outputCollection;
252 }
T getUntrackedParameter(std::string const &, T const &) const
edm::ParameterSet const conf_
MuonAssociatorByHits(const edm::ParameterSet &conf, edm::ConsumesCollector &&iC)
reco::RecoToSimCollection associateRecoToSim(const edm::RefToBaseVector< reco::Track > &, const edm::RefVector< TrackingParticleCollection > &, const edm::Event *event=0, const edm::EventSetup *setup=0) const override
Association Reco To Sim with Collections.
std::vector< TrackingParticle > TrackingParticleCollection
const_iterator end() const
IndexAssociation associateSimToRecoIndices(const TrackHitsCollection &, const edm::RefVector< TrackingParticleCollection > &, Resources const &) const
std::unique_ptr< muonAssociatorByHitsDiagnostics::InputDumper > diagnostics_
std::vector< std::pair< trackingRecHit_iterator, trackingRecHit_iterator > > TrackHitsCollection
void post_insert()
post insert action
int j
Definition: DBlmapReader.cc:9
std::function< void(const TrackHitsCollection &, const TrackingParticleCollection &)> diagnostics_
MuonAssociatorByHitsHelper::TrackHitsCollection TrackHitsCollection
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
reco::SimToRecoCollection associateSimToReco(const edm::RefToBaseVector< reco::Track > &, const edm::RefVector< TrackingParticleCollection > &, const edm::Event *event=0, const edm::EventSetup *setup=0) const override
Association Sim To Reco with Collections.
tuple conf
Definition: dbtoconf.py:185
std::vector< SimTrack >::const_iterator g4t_iterator
T const * product() const
Definition: Handle.h:81
void insert(const key_type &k, const data_type &v)
insert an association
const T & get() const
Definition: EventSetup.h:55
std::vector< SimVertex > SimVertexContainer
T const * product() const
Definition: ESHandle.h:86
const_iterator begin() const
IndexAssociation associateRecoToSimIndices(const TrackHitsCollection &, const edm::RefVector< TrackingParticleCollection > &, Resources const &) const
MuonAssociatorByHitsHelper helper_
std::vector< SimTrack > SimTrackContainer
void setup(std::vector< TH2F > &depth, std::string name, std::string units="")
InputDumper(const edm::ParameterSet &conf, edm::ConsumesCollector &&iC)