CMS 3D CMS Logo

TrackAssociatorByHitsImpl.cc
Go to the documentation of this file.
1 //
2 //
4 
6 
10 
11 //reco track
15 //TrackingParticle
20 //##---new stuff
27 
28 using namespace reco;
29 using namespace std;
30 
31 /* Constructor */
32 
34  std::unique_ptr<TrackerHitAssociator> iAssociate,
35  TrackerTopology const* iTopo,
36  SimHitTPAssociationList const* iSimHitsTPAssoc,
37  SimToRecoDenomType iSimToRecoDenominator,
38  double iQuality_SimToReco,
39  double iPurity_SimToReco,
40  double iCut_RecoToSim,
41  bool iUsePixels,
42  bool iUseGrouped,
43  bool iUseSplitting,
44  bool iThreeHitTracksAreSpecial,
45  bool iAbsoluteNumberOfHits)
46  : productGetter_(&productGetter),
47  associate(std::move(iAssociate)),
48  tTopo(iTopo),
49  simHitsTPAssoc(iSimHitsTPAssoc),
50  SimToRecoDenominator(iSimToRecoDenominator),
51  quality_SimToReco(iQuality_SimToReco),
52  purity_SimToReco(iPurity_SimToReco),
53  cut_RecoToSim(iCut_RecoToSim),
54  UsePixels(iUsePixels),
55  UseGrouped(iUseGrouped),
56  UseSplitting(iUseSplitting),
57  ThreeHitTracksAreSpecial(iThreeHitTracksAreSpecial),
58  AbsoluteNumberOfHits(iAbsoluteNumberOfHits) {}
59 
60 /*
61 TrackAssociatorByHitsImpl::TrackAssociatorByHitsImpl (const edm::ParameterSet& conf) :
62  conf_(conf),
63  AbsoluteNumberOfHits(conf_.getParameter<bool>("AbsoluteNumberOfHits")),
64  SimToRecoDenominator(denomnone),
65  quality_SimToReco(conf_.getParameter<double>("Quality_SimToReco")),
66  purity_SimToReco(conf_.getParameter<double>("Purity_SimToReco")),
67  cut_RecoToSim(conf_.getParameter<double>("Cut_RecoToSim")),
68  UsePixels(conf_.getParameter<bool>("UsePixels")),
69  UseGrouped(conf_.getParameter<bool>("UseGrouped")),
70  UseSplitting(conf_.getParameter<bool>("UseSplitting")),
71  ThreeHitTracksAreSpecial(conf_.getParameter<bool>("ThreeHitTracksAreSpecial")),
72  _simHitTpMapTag(conf_.getParameter<edm::InputTag>("simHitTpMapTag"))
73 {
74  std::string tmp = conf_.getParameter<string>("SimToRecoDenominator");
75  if (tmp=="sim") {
76  SimToRecoDenominator = denomsim;
77  } else if (tmp == "reco") {
78  SimToRecoDenominator = denomreco;
79  }
80 
81  if (SimToRecoDenominator == denomnone) {
82  throw cms::Exception("TrackAssociatorByHitsImpl") << "SimToRecoDenominator not specified as sim or reco";
83  }
84 
85 }
86 */
87 
88 //
89 //---member functions
90 //
91 
94  const edm::RefVector<TrackingParticleCollection>& TPCollectionH) const {
95  //edm::LogVerbatim("TrackAssociator") << "Starting TrackAssociatorByHitsImpl::associateRecoToSim - #tracks="<<tC.size()<<" #TPs="<<TPCollectionH.size();
96  int nshared = 0;
97  float quality = 0; //fraction or absolute number of shared hits
98  std::vector<SimHitIdpr> SimTrackIds;
99  std::vector<SimHitIdpr> matchedIds;
100  RecoToSimCollection outputCollection(productGetter_);
101 
102  //dereference the edm::Refs only once
103  std::vector<TrackingParticle const*> tPC;
104  tPC.reserve(tPC.size());
105  for (auto const& ref : TPCollectionH) {
106  tPC.push_back(&(*ref));
107  }
108 
109  //get the ID of the recotrack by hits
110  int tindex = 0;
111  for (edm::RefToBaseVector<reco::Track>::const_iterator track = tC.begin(); track != tC.end(); track++, tindex++) {
112  matchedIds.clear();
113  int ri = 0; //valid rechits
114  //LogTrace("TrackAssociator") << "\nNEW TRACK - track number " << tindex <<" with pt =" << (*track)->pt() << " # valid=" << (*track)->found();
115  getMatchedIds<trackingRecHit_iterator>(
116  matchedIds, SimTrackIds, ri, (*track)->recHitsBegin(), (*track)->recHitsEnd(), associate.get());
117 
118  //LogTrace("TrackAssociator") << "MATCHED IDS LIST BEGIN" ;
119  //for(size_t j=0; j<matchedIds.size(); j++){
120  // LogTrace("TrackAssociator") << "matchedIds[j].first=" << matchedIds[j].first;
121  //}
122  //LogTrace("TrackAssociator") << "MATCHED IDS LIST END" ;
123  //LogTrace("TrackAssociator") << "#matched ids=" << matchedIds.size() << " #tps=" << tPC.size();
124 
125  //save id for the track
126  std::vector<SimHitIdpr> idcachev;
127  if (!matchedIds.empty()) {
128  int tpindex = 0;
129  for (auto t = tPC.begin(); t != tPC.end(); ++t, ++tpindex) {
130  //int nsimhit = (*t)->trackPSimHit(DetId::Tracker).size();
131  //LogTrace("TrackAssociator") << "TP number " << tpindex << " pdgId=" << (*t)->pdgId() << " with number of PSimHits: " << nsimhit;
132  idcachev.clear();
133  nshared = getShared(matchedIds, idcachev, **t);
134 
135  //if electron subtract double counting
136  if (abs((*t)->pdgId()) == 11 && ((*t)->g4Track_end() - (*t)->g4Track_begin()) > 1) {
137  nshared -= getDoubleCount<trackingRecHit_iterator>(
138  (*track)->recHitsBegin(), (*track)->recHitsEnd(), associate.get(), **t);
139  }
140 
142  quality = static_cast<double>(nshared);
143  else if (ri != 0)
144  quality = (static_cast<double>(nshared) / static_cast<double>(ri));
145  else
146  quality = 0;
147  //cut on the fraction
148  //float purity = 1.0*nshared/ri;
149  if (quality > cut_RecoToSim && !(ThreeHitTracksAreSpecial && ri == 3 && nshared < 3)) {
150  //if a track has just 3 hits we require that all 3 hits are shared
151  outputCollection.insert(tC[tindex], std::make_pair(TPCollectionH[tpindex], quality));
152  // LogTrace("TrackAssociator") << "reco::Track number " << tindex << " with #hits=" << ri <<" pt=" << (*track)->pt()
153  // << " associated to TP (pdgId, nb segments, p) = "
154  // << (*t).pdgId() << " " << (*t).g4Tracks().size()
155  // << " " << (*t).momentum() << " #hits=" << nsimhit
156  // << " TP index=" << tpindex<< " with quality =" << quality;
157  } else {
158  // LogTrace("TrackAssociator") <<"reco::Track number " << tindex << " with #hits=" << ri
159  // << " NOT associated with quality =" << quality;
160  }
161  } //TP loop
162  }
163  }
164  //LogTrace("TrackAssociator") << "% of Assoc Tracks=" << ((double)outputCollection.size())/((double)tC.size());
165  outputCollection.post_insert();
166  return outputCollection;
167 }
168 
171  const edm::RefVector<TrackingParticleCollection>& TPCollectionH) const {
172  //edm::ESHandle<TrackerTopology> tTopoHand;
173  //setup->get<IdealGeometryRecord>().get(tTopoHand);
174 
175  // edm::LogVerbatim("TrackAssociator") << "Starting TrackAssociatorByHitsImpl::associateSimToReco - #tracks="<<tC.size()<<" #TPs="<<TPCollectionH.size();
176  float quality = 0; //fraction or absolute number of shared hits
177  int nshared = 0;
178  std::vector<SimHitIdpr> SimTrackIds;
179  std::vector<SimHitIdpr> matchedIds;
180  SimToRecoCollection outputCollection(productGetter_);
181 
182  //dereferene the edm::Refs only once
183  std::vector<TrackingParticle const*> tPC;
184  tPC.reserve(tPC.size());
185  for (auto const& ref : TPCollectionH) {
186  tPC.push_back(&(*ref));
187  }
188 
189  //for (TrackingParticleCollection::const_iterator t = tPC.begin(); t != tPC.end(); ++t) {
190  // LogTrace("TrackAssociator") << "NEW TP DUMP";
191  // for (TrackingParticle::g4t_iterator g4T = t -> g4Track_begin();g4T != t -> g4Track_end(); ++g4T) {
192  // LogTrace("TrackAssociator") << "(*g4T).trackId()=" <<(*g4T).trackId() ;
193  // }
194  //}
195 
196  //cdj edm::Handle<SimHitTPAssociationProducer::SimHitTPAssociationList> simHitsTPAssoc;
197  //warning: make sure the TP collection used in the map is the same used in the associator!
198  //e->getByLabel(_simHitTpMapTag,simHitsTPAssoc);
199 
200  //get the ID of the recotrack by hits
201  int tindex = 0;
202  for (edm::RefToBaseVector<reco::Track>::const_iterator track = tC.begin(); track != tC.end(); track++, tindex++) {
203  //LogTrace("TrackAssociator") << "\nNEW TRACK - hits of track number " << tindex <<" with pt =" << (*track)->pt() << " # valid=" << (*track)->found();
204  int ri = 0; //valid rechits
205  getMatchedIds<trackingRecHit_iterator>(
206  matchedIds, SimTrackIds, ri, (*track)->recHitsBegin(), (*track)->recHitsEnd(), associate.get());
207 
208  //save id for the track
209  std::vector<SimHitIdpr> idcachev;
210  if (!matchedIds.empty()) {
211  int tpindex = 0;
212  for (auto t = tPC.begin(); t != tPC.end(); ++t, ++tpindex) {
213  idcachev.clear();
214  float totsimhit = 0;
215 
216  //int nsimhit = trackerPSimHit.size();
217  std::vector<PSimHit> tphits;
218  //LogTrace("TrackAssociator") << "TP number " << tpindex << " pdgId=" << (*t)->pdgId() << " with number of PSimHits: " << nsimhit;
219 
220  nshared = getShared(matchedIds, idcachev, **t);
221 
222  //for(std::vector<PSimHit>::const_iterator TPhit = (*t)->trackerPSimHit_begin(); TPhit != (*t)->trackerPSimHit_end(); TPhit++){
223  // unsigned int detid = TPhit->detUnitId();
224  // DetId detId = DetId(TPhit->detUnitId());
225  // LogTrace("TrackAssociator") << " hit trackId= " << TPhit->trackId() << " det ID = " << detid
226  // << " SUBDET = " << detId.subdetId() << " layer = " << LayerFromDetid(detId);
227  //}
228 
229  if (nshared != 0) { //do not waste time recounting when it is not needed!!!!
230 
231  //count the TP simhit
232  //LogTrace("TrackAssociator") << "recounting of tp hits";
233 
234  std::pair<TrackingParticleRef, TrackPSimHitRef> clusterTPpairWithDummyTP(
235  TPCollectionH[tpindex], TrackPSimHitRef()); //SimHit is dummy: for simHitTPAssociationListGreater
236  // sorting only the cluster is needed
237  auto range = std::equal_range(simHitsTPAssoc->begin(),
238  simHitsTPAssoc->end(),
239  clusterTPpairWithDummyTP,
241  for (auto ip = range.first; ip != range.second; ++ip) {
242  TrackPSimHitRef TPhit = ip->second;
243  DetId dId = DetId(TPhit->detUnitId());
244 
245  unsigned int subdetId = static_cast<unsigned int>(dId.subdetId());
246  if (!UsePixels && (subdetId == PixelSubdetector::PixelBarrel || subdetId == PixelSubdetector::PixelEndcap))
247  continue;
248 
249  //unsigned int dRawId = dId.rawId();
250  SiStripDetId* stripDetId = nullptr;
251  if (subdetId == SiStripDetId::TIB || subdetId == SiStripDetId::TOB || subdetId == SiStripDetId::TID ||
252  subdetId == SiStripDetId::TEC)
253  stripDetId = new SiStripDetId(dId);
254  //LogTrace("TrackAssociator") << "consider hit SUBDET = " << subdetId
255  // << " layer = " << LayerFromDetid(dId)
256  // << " id = " << dId.rawId();
257  bool newhit = true;
258  for (std::vector<PSimHit>::const_iterator TPhitOK = tphits.begin(); TPhitOK != tphits.end(); TPhitOK++) {
259  DetId dIdOK = DetId(TPhitOK->detUnitId());
260  //unsigned int dRawIdOK = dIdOK.rawId();
261  //LogTrace("TrackAssociator") << "\t\tcompare with SUBDET = " << dIdOK.subdetId()
262  // << " layer = " << LayerFromDetid(dIdOK)
263  // << " id = " << dIdOK.rawId();
264  //no grouped, no splitting
265  if (!UseGrouped && !UseSplitting)
266  if (tTopo->layer(dId) == tTopo->layer(dIdOK) && dId.subdetId() == dIdOK.subdetId())
267  newhit = false;
268  //no grouped, splitting
269  if (!UseGrouped && UseSplitting)
270  if (tTopo->layer(dId) == tTopo->layer(dIdOK) && dId.subdetId() == dIdOK.subdetId() &&
271  (stripDetId == nullptr || stripDetId->partnerDetId() != dIdOK.rawId()))
272  newhit = false;
273  //grouped, no splitting
274  if (UseGrouped && !UseSplitting)
275  if (tTopo->layer(dId) == tTopo->layer(dIdOK) && dId.subdetId() == dIdOK.subdetId() &&
276  stripDetId != nullptr && stripDetId->partnerDetId() == dIdOK.rawId())
277  newhit = false;
278  //grouped, splitting
279  if (UseGrouped && UseSplitting)
280  newhit = true;
281  }
282  if (newhit) {
283  //LogTrace("TrackAssociator") << "\t\tok";
284  tphits.push_back(*TPhit);
285  }
286  //else LogTrace("TrackAssociator") << "\t\tno";
287  delete stripDetId;
288  }
289  totsimhit = tphits.size();
290  }
291 
293  quality = static_cast<double>(nshared);
294  else if (SimToRecoDenominator == denomsim && totsimhit != 0)
295  quality = ((double)nshared) / ((double)totsimhit);
296  else if (SimToRecoDenominator == denomreco && ri != 0)
297  quality = ((double)nshared) / ((double)ri);
298  else
299  quality = 0;
300  //LogTrace("TrackAssociator") << "Final count: nhit(TP) = " << nsimhit << " re-counted = " << totsimhit
301  //<< " nshared = " << nshared << " nrechit = " << ri;
302 
303  float purity = 1.0 * nshared / ri;
304  if (quality > quality_SimToReco && !(ThreeHitTracksAreSpecial && totsimhit == 3 && nshared < 3) &&
305  (AbsoluteNumberOfHits || (purity > purity_SimToReco))) {
306  //if a track has just 3 hits we require that all 3 hits are shared
307  outputCollection.insert(TPCollectionH[tpindex], std::make_pair(tC[tindex], quality));
308  // LogTrace("TrackAssociator") << "TrackingParticle number " << tpindex << " with #hits=" << nsimhit
309  // << " re-counted = " << totsimhit << " nshared = " << nshared
310  // << " associated to track number " << tindex << " with pt=" << (*track)->pt()
311  // << " with hit quality =" << quality ;
312  } else {
313  // LogTrace("TrackAssociator") << "TrackingParticle number " << tpindex << " with #hits=" << nsimhit
314  // << " re-counted = " << totsimhit << " nshared = " << nshared
315  // << " NOT associated with quality =" << quality;
316  }
317  }
318  }
319  }
320  //LogTrace("TrackAssociator") << "% of Assoc TPs=" << ((double)outputCollection.size())/((double)TPCollectionH.size());
321  outputCollection.post_insert();
322  return outputCollection;
323 }
324 
326  const edm::Handle<edm::View<TrajectorySeed> >& seedCollectionH,
327  const edm::Handle<TrackingParticleCollection>& TPCollectionH) const {
328  edm::LogVerbatim("TrackAssociator") << "Starting TrackAssociatorByHitsImpl::associateRecoToSim - #seeds="
329  << seedCollectionH->size() << " #TPs=" << TPCollectionH->size();
330  int nshared = 0;
331  float quality = 0; //fraction or absolute number of shared hits
332  std::vector<SimHitIdpr> SimTrackIds;
333  std::vector<SimHitIdpr> matchedIds;
334  RecoToSimCollectionSeed outputCollection(productGetter_);
335 
336  const TrackingParticleCollection& tPC = *(TPCollectionH.product());
337 
338  const edm::View<TrajectorySeed> sC = *(seedCollectionH.product());
339 
340  //get the ID of the recotrack by hits
341  int tindex = 0;
342  for (edm::View<TrajectorySeed>::const_iterator seed = sC.begin(); seed != sC.end(); seed++, tindex++) {
343  matchedIds.clear();
344  int ri = 0; //valid rechits
345  int nsimhit = seed->recHits().second - seed->recHits().first;
346  LogTrace("TrackAssociator") << "\nNEW SEED - seed number " << tindex << " # valid=" << nsimhit;
347  getMatchedIds<edm::OwnVector<TrackingRecHit>::const_iterator>(
348  matchedIds, SimTrackIds, ri, seed->recHits().first, seed->recHits().second, associate.get());
349 
350  //save id for the track
351  std::vector<SimHitIdpr> idcachev;
352  if (!matchedIds.empty()) {
353  int tpindex = 0;
354  for (TrackingParticleCollection::const_iterator t = tPC.begin(); t != tPC.end(); ++t, ++tpindex) {
355  LogTrace("TrackAssociator") << "TP number " << tpindex << " pdgId=" << t->pdgId()
356  << " with number of PSimHits: " << nsimhit;
357  idcachev.clear();
358  nshared = getShared(matchedIds, idcachev, *t);
359 
360  //if electron subtract double counting
361  if (abs(t->pdgId()) == 11 && (t->g4Track_end() - t->g4Track_begin()) > 1) {
362  nshared -= getDoubleCount<edm::OwnVector<TrackingRecHit>::const_iterator>(
363  seed->recHits().first, seed->recHits().second, associate.get(), *t);
364  }
365 
367  quality = static_cast<double>(nshared);
368  else if (ri != 0)
369  quality = (static_cast<double>(nshared) / static_cast<double>(ri));
370  else
371  quality = 0;
372  //cut on the fraction
373  if (quality > cut_RecoToSim && !(ThreeHitTracksAreSpecial && ri == 3 && nshared < 3)) {
374  //if a track has just 3 hits we require that all 3 hits are shared
375  outputCollection.insert(
376  edm::RefToBase<TrajectorySeed>(seedCollectionH, tindex),
377  std::make_pair(edm::Ref<TrackingParticleCollection>(TPCollectionH, tpindex), quality));
378  LogTrace("TrackAssociator") << "Seed number " << tindex << " with #hits=" << ri
379  << "associated to TP (pdgId, nb segments, p) = " << (*t).pdgId() << " "
380  << (*t).g4Tracks().size() << " " << (*t).momentum() << " number " << tpindex
381  << " with quality =" << quality;
382  } else {
383  LogTrace("TrackAssociator") << "Seed number " << tindex << " with #hits=" << ri
384  << " NOT associated with quality =" << quality;
385  }
386  } //TP loop
387  }
388  }
389  LogTrace("TrackAssociator") << "% of Assoc Seeds="
390  << ((double)outputCollection.size()) / ((double)seedCollectionH->size());
391 
392  outputCollection.post_insert();
393  return outputCollection;
394 }
395 
397  const edm::Handle<edm::View<TrajectorySeed> >& seedCollectionH,
398  const edm::Handle<TrackingParticleCollection>& TPCollectionH) const {
399  edm::LogVerbatim("TrackAssociator") << "Starting TrackAssociatorByHitsImpl::associateSimToReco - #seeds="
400  << seedCollectionH->size() << " #TPs=" << TPCollectionH->size();
401  float quality = 0; //fraction or absolute number of shared hits
402  int nshared = 0;
403  std::vector<SimHitIdpr> SimTrackIds;
404  std::vector<SimHitIdpr> matchedIds;
405  SimToRecoCollectionSeed outputCollection(productGetter_);
406 
407  const TrackingParticleCollection& tPC = *TPCollectionH.product();
408 
409  const edm::View<TrajectorySeed> sC = *(seedCollectionH.product());
410 
411  //get the ID of the recotrack by hits
412  int tindex = 0;
413  for (edm::View<TrajectorySeed>::const_iterator seed = sC.begin(); seed != sC.end(); seed++, tindex++) {
414  int ri = 0; //valid rechits
415  LogTrace("TrackAssociator") << "\nNEW SEED - seed number " << tindex
416  << " # valid=" << seed->recHits().second - seed->recHits().first;
417  getMatchedIds<edm::OwnVector<TrackingRecHit>::const_iterator>(
418  matchedIds, SimTrackIds, ri, seed->recHits().first, seed->recHits().second, associate.get());
419 
420  //save id for the track
421  std::vector<SimHitIdpr> idcachev;
422  if (!matchedIds.empty()) {
423  int tpindex = 0;
424  for (TrackingParticleCollection::const_iterator t = tPC.begin(); t != tPC.end(); ++t, ++tpindex) {
425  idcachev.clear();
426  int nsimhit = t->numberOfTrackerHits();
427  LogTrace("TrackAssociator") << "TP number " << tpindex << " pdgId=" << t->pdgId()
428  << " with number of PSimHits: " << nsimhit;
429  nshared = getShared(matchedIds, idcachev, *t);
430 
432  quality = static_cast<double>(nshared);
433  else if (ri != 0)
434  quality = ((double)nshared) / ((double)ri);
435  else
436  quality = 0;
437  //LogTrace("TrackAssociator") << "Final count: nhit(TP) = " << nsimhit
438  //<< " nshared = " << nshared
439  //<< " nrechit = " << ri;
440  if (quality > quality_SimToReco && !(ThreeHitTracksAreSpecial && ri == 3 && nshared < 3)) {
441  outputCollection.insert(edm::Ref<TrackingParticleCollection>(TPCollectionH, tpindex),
442  std::make_pair(edm::RefToBase<TrajectorySeed>(seedCollectionH, tindex), quality));
443  LogTrace("TrackAssociator") << "TrackingParticle number " << tpindex << " with #hits=" << nsimhit
444  << " associated to seed number " << tindex << " with #hits=" << ri
445  << " with hit quality =" << quality;
446  } else {
447  LogTrace("TrackAssociator") << "TrackingParticle number " << tpindex << " with #hits=" << nsimhit
448  << " NOT associated with quality =" << quality;
449  }
450  }
451  }
452  }
453  LogTrace("TrackAssociator") << "% of Assoc TPs="
454  << ((double)outputCollection.size()) / ((double)TPCollectionH->size());
455  outputCollection.post_insert();
456  return outputCollection;
457 }
458 
459 template <typename iter>
460 void TrackAssociatorByHitsImpl::getMatchedIds(std::vector<SimHitIdpr>& matchedIds,
461  std::vector<SimHitIdpr>& SimTrackIds,
462  int& ri,
463  iter begin,
464  iter end,
465  TrackerHitAssociator* associate) const {
466  matchedIds.clear();
467  ri = 0; //valid rechits
468  for (iter it = begin; it != end; it++) {
469  const TrackingRecHit* hit = getHitPtr(it);
470  if (hit->isValid()) {
471  ri++;
472  uint32_t t_detID = hit->geographicalId().rawId();
473  SimTrackIds.clear();
474  associate->associateHitId(*hit, SimTrackIds);
475  //save all the id of matched simtracks
476  if (!SimTrackIds.empty()) {
477  for (size_t j = 0; j < SimTrackIds.size(); j++) {
478  LogTrace("TrackAssociator") << " hit # " << ri << " valid=" << hit->isValid() << " det id = " << t_detID
479  << " SimId " << SimTrackIds[j].first << " evt=" << SimTrackIds[j].second.event()
480  << " bc=" << SimTrackIds[j].second.bunchCrossing();
481  matchedIds.push_back(SimTrackIds[j]);
482  }
483  }
485  //****to be used when the crossing frame is in the event and with flag TrackAssociatorByHitsImplESProducer.associateRecoTracks = false
486  //std::vector<PSimHit> tmpSimHits = associate->associateHit(*getHitPtr(it));
488  //for(size_t j=0; j<tmpSimHits.size(); j++) {
489  // LogTrace("TrackAssociator") << " hit # " << ri << " valid=" << getHitPtr(it)->isValid()
490  // << " det id = " << t_detID << " SimId " << SimTrackIds[j].first
491  // << " evt=" << SimTrackIds[j].second.event()
492  // << " bc=" << SimTrackIds[j].second.bunchCrossing()
493  // << " process=" << tmpSimHits[j].processType()
494  // << " eloss=" << tmpSimHits[j].energyLoss()
495  // << " part type=" << tmpSimHits[j].particleType()
496  // << " pabs=" << tmpSimHits[j].pabs()
497  // << " trId=" << tmpSimHits[j].trackId();
498  //}
500  } else {
501  LogTrace("TrackAssociator") << "\t\t Invalid Hit On " << hit->geographicalId().rawId();
502  }
503  } //trackingRecHit loop
504 }
505 
506 int TrackAssociatorByHitsImpl::getShared(std::vector<SimHitIdpr>& matchedIds,
507  std::vector<SimHitIdpr>& idcachev,
508  TrackingParticle const& t) const {
509  int nshared = 0;
510  if (t.numberOfHits() == 0)
511  return nshared; //should use trackerPSimHit but is not const
512 
513  for (size_t j = 0; j < matchedIds.size(); j++) {
514  //LogTrace("TrackAssociator") << "now matchedId=" << matchedIds[j].first;
515  if (find(idcachev.begin(), idcachev.end(), matchedIds[j]) == idcachev.end()) {
516  //only the first time we see this ID
517  idcachev.push_back(matchedIds[j]);
518 
519  for (TrackingParticle::g4t_iterator g4T = t.g4Track_begin(); g4T != t.g4Track_end(); ++g4T) {
520  // LogTrace("TrackAssociator") << " TP (ID, Ev, BC) = " << (*g4T).trackId()
521  // << ", " << t.eventId().event() << ", "<< t.eventId().bunchCrossing()
522  // << " Match(ID, Ev, BC) = " << matchedIds[j].first
523  // << ", " << matchedIds[j].second.event() << ", "
524  // << matchedIds[j].second.bunchCrossing() ;
525  //<< "\t G4 Track Momentum " << (*g4T).momentum()
526  //<< " \t reco Track Momentum " << track->momentum();
527  if ((*g4T).trackId() == matchedIds[j].first && t.eventId() == matchedIds[j].second) {
528  int countedhits = std::count(matchedIds.begin(), matchedIds.end(), matchedIds[j]);
529  nshared += countedhits;
530 
531  // LogTrace("TrackAssociator") << "hits shared by this segment : " << countedhits;
532  // LogTrace("TrackAssociator") << "hits shared so far : " << nshared;
533  }
534  } //g4Tracks loop
535  }
536  }
537  return nshared;
538 }
539 
540 template <typename iter>
542  iter end,
543  TrackerHitAssociator* associate,
544  TrackingParticle const& t) const {
545  int doublecount = 0;
546  std::vector<SimHitIdpr> SimTrackIdsDC;
547  // cout<<begin-end<<endl;
548  for (iter it = begin; it != end; it++) {
549  int idcount = 0;
550  SimTrackIdsDC.clear();
551  associate->associateHitId(*getHitPtr(it), SimTrackIdsDC);
552  // cout<<SimTrackIdsDC.size()<<endl;
553  if (SimTrackIdsDC.size() > 1) {
554  // cout<<(t.g4Track_end()-t.g4Track_begin())<<endl;
555  for (TrackingParticle::g4t_iterator g4T = t.g4Track_begin(); g4T != t.g4Track_end(); ++g4T) {
556  if (find(SimTrackIdsDC.begin(),
557  SimTrackIdsDC.end(),
558  SimHitIdpr((*g4T).trackId(), SimTrackIdsDC.begin()->second)) != SimTrackIdsDC.end()) {
559  idcount++;
560  }
561  }
562  }
563  if (idcount > 1)
564  doublecount += (idcount - 1);
565  }
566  return doublecount;
567 }
edm::RefToBaseVector::end
const_iterator end() const
Definition: RefToBaseVector.h:186
FastTimerService_cff.range
range
Definition: FastTimerService_cff.py:34
edm::View::begin
const_iterator begin() const
TrackAssociatorByHitsImpl::productGetter_
edm::EDProductGetter const * productGetter_
Definition: TrackAssociatorByHitsImpl.h:87
TrackAssociatorByHitsImpl::associateRecoToSim
reco::RecoToSimCollection associateRecoToSim(const edm::RefToBaseVector< reco::Track > &, const edm::RefVector< TrackingParticleCollection > &) const override
Association Reco To Sim with Collections.
Definition: TrackAssociatorByHitsImpl.cc:92
PixelSubdetector.h
MessageLogger.h
TrackAssociatorByHitsImpl::AbsoluteNumberOfHits
const bool AbsoluteNumberOfHits
Definition: TrackAssociatorByHitsImpl.h:100
TrackAssociatorByHitsImpl::associateSimToReco
reco::SimToRecoCollection associateSimToReco(const edm::RefToBaseVector< reco::Track > &, const edm::RefVector< TrackingParticleCollection > &) const override
Association Sim To Reco with Collections.
Definition: TrackAssociatorByHitsImpl.cc:169
PixelSubdetector::PixelEndcap
Definition: PixelSubdetector.h:11
TrackAssociatorByHitsImpl::SimHitTPAssociationList
std::vector< SimHitTPPair > SimHitTPAssociationList
Definition: TrackAssociatorByHitsImpl.h:28
TrackerGeometry.h
PixelSubdetector::PixelBarrel
Definition: PixelSubdetector.h:11
edm::Handle::product
T const * product() const
Definition: Handle.h:70
SimHitIdpr
std::pair< uint32_t, EncodedEventId > SimHitIdpr
Definition: TrackerHitAssociator.h:54
TrackerTopology
Definition: TrackerTopology.h:16
MuonAssociatorByHits_cfi.UsePixels
UsePixels
Definition: MuonAssociatorByHits_cfi.py:32
TrackingParticle::g4t_iterator
std::vector< SimTrack >::const_iterator g4t_iterator
Definition: TrackingParticle.h:41
TrackerTopology::layer
unsigned int layer(const DetId &id) const
Definition: TrackerTopology.cc:47
SiStripDetId.h
TrackerHitAssociator.h
TrackAssociatorByHitsImpl::getMatchedIds
void getMatchedIds(std::vector< SimHitIdpr > &, std::vector< SimHitIdpr > &, int &, iter, iter, TrackerHitAssociator *) const
Definition: TrackAssociatorByHitsImpl.cc:460
TrackAssociatorByHitsImpl::UsePixels
const bool UsePixels
Definition: TrackAssociatorByHitsImpl.h:96
edm::RefVector< TrackingParticleCollection >
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:45
TrackAssociatorByHitsImpl::associate
std::unique_ptr< TrackerHitAssociator > associate
Definition: TrackAssociatorByHitsImpl.h:88
spr::find
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
edm::Handle
Definition: AssociativeIterator.h:50
end
#define end
Definition: vmac.h:39
edm::Ref
Definition: AssociativeIterator.h:58
edm::EDProductGetter
Definition: EDProductGetter.h:32
DetId
Definition: DetId.h:17
edm::AssociationMap::post_insert
void post_insert()
post insert action
Definition: AssociationMap.h:229
TrackerTopology.h
TrackingRecHit.h
Track.h
TrackFwd.h
TrackAssociatorByHitsImpl::SimToRecoDenominator
SimToRecoDenomType SimToRecoDenominator
Definition: TrackAssociatorByHitsImpl.h:92
TrackingParticle
Monte Carlo truth information used for tracking validation.
Definition: TrackingParticle.h:29
edm::reftobase::BaseVectorHolder::const_iterator
Definition: BaseVectorHolder.h:54
TrackAssociatorByHitsImpl::denomsim
Definition: TrackAssociatorByHitsImpl.h:25
MuonAssociatorByHits_cfi.UseSplitting
UseSplitting
Definition: MuonAssociatorByHits_cfi.py:34
TrackAssociatorByHitsImpl::denomreco
Definition: TrackAssociatorByHitsImpl.h:25
OrderedSet.t
t
Definition: OrderedSet.py:90
SiStripDetId::TEC
static constexpr auto TEC
Definition: SiStripDetId.h:40
DetId::subdetId
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector's numbering enum)
Definition: DetId.h:48
TrackAssociatorByHitsImpl::UseGrouped
const bool UseGrouped
Definition: TrackAssociatorByHitsImpl.h:97
edm::View
Definition: CaloClusterFwd.h:14
edm::AssociationMap::size
size_type size() const
map size
Definition: AssociationMap.h:162
TrackAssociatorByHitsImpl::getShared
int getShared(std::vector< SimHitIdpr > &, std::vector< SimHitIdpr > &, TrackingParticle const &) const
Definition: TrackAssociatorByHitsImpl.cc:506
edm::AssociationMap< edm::OneToManyWithQualityGeneric< edm::View< reco::Track >, TrackingParticleCollection, double > >
KineDebug3::count
void count()
Definition: KinematicConstrainedVertexUpdatorT.h:21
MuonAssociatorByHits_cfi.UseGrouped
UseGrouped
Definition: MuonAssociatorByHits_cfi.py:33
TrackAssociatorByHitsImpl::UseSplitting
const bool UseSplitting
Definition: TrackAssociatorByHitsImpl.h:98
edm::LogVerbatim
Definition: MessageLogger.h:297
edm::refcoreimpl::productGetter
EDProductGetter const * productGetter(std::atomic< void const * > const &iCache)
Definition: refcore_implementation.h:72
SiStripDetId::TOB
static constexpr auto TOB
Definition: SiStripDetId.h:39
edm::RefToBaseVector< reco::Track >
TrackAssociatorByHitsImpl::getDoubleCount
int getDoubleCount(iter, iter, TrackerHitAssociator *, TrackingParticle const &) const
Definition: TrackAssociatorByHitsImpl.cc:541
TrackAssociatorByHitsImpl::simHitsTPAssoc
SimHitTPAssociationList const * simHitsTPAssoc
Definition: TrackAssociatorByHitsImpl.h:90
TrackingRecHit
Definition: TrackingRecHit.h:21
SimHitTPAssociationProducer.h
SiStripDetId::TID
static constexpr auto TID
Definition: SiStripDetId.h:38
edm::AssociationMap::insert
void insert(const key_type &k, const data_type &v)
insert an association
Definition: AssociationMap.h:166
TrackAssociatorByHitsImpl::ThreeHitTracksAreSpecial
const bool ThreeHitTracksAreSpecial
Definition: TrackAssociatorByHitsImpl.h:99
TrackingParticle.h
TrackerHitAssociator
Definition: TrackerHitAssociator.h:55
GeomDet.h
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
DetId::rawId
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
Ref.h
qcdUeDQM_cfi.quality
quality
Definition: qcdUeDQM_cfi.py:31
DetId.h
TrackingParticleFwd.h
quickTrackAssociatorByHits_cfi.AbsoluteNumberOfHits
AbsoluteNumberOfHits
Definition: quickTrackAssociatorByHits_cfi.py:4
TrackAssociatorByHitsImpl::quality_SimToReco
const double quality_SimToReco
Definition: TrackAssociatorByHitsImpl.h:93
SiStripDetId::TIB
static constexpr auto TIB
Definition: SiStripDetId.h:37
TrackPSimHitRef
edm::Ref< edm::PSimHitContainer > TrackPSimHitRef
Definition: PSimHitContainer.h:14
TrackingParticleCollection
std::vector< TrackingParticle > TrackingParticleCollection
Definition: TrackingParticleFwd.h:8
edm::RefToBase< TrajectorySeed >
Exception.h
edm::RefToBaseVector::begin
const_iterator begin() const
Definition: RefToBaseVector.h:181
TrackAssociatorByHitsImpl::getHitPtr
const TrackingRecHit * getHitPtr(edm::OwnVector< TrackingRecHit >::const_iterator iter) const
Definition: TrackAssociatorByHitsImpl.h:102
edm::View::const_iterator
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:86
TrackAssociatorByHitsImpl.h
HLT_2018_cff.track
track
Definition: HLT_2018_cff.py:10352
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
LogTrace
#define LogTrace(id)
Definition: MessageLogger.h:671
edm::View::end
const_iterator end() const
SiStripDetId
Detector identifier class for the strip tracker.
Definition: SiStripDetId.h:18
TrackAssociatorByHitsImpl::SimToRecoDenomType
SimToRecoDenomType
Definition: TrackAssociatorByHitsImpl.h:25
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
SiStripDetId::partnerDetId
uint32_t partnerDetId() const
Definition: SiStripDetId.h:170
quickTrackAssociatorByHits_cfi.SimToRecoDenominator
SimToRecoDenominator
Definition: quickTrackAssociatorByHits_cfi.py:6
TrackAssociatorByHitsImpl::purity_SimToReco
const double purity_SimToReco
Definition: TrackAssociatorByHitsImpl.h:94
begin
#define begin
Definition: vmac.h:32
SurveyInfoScenario_cff.seed
seed
Definition: SurveyInfoScenario_cff.py:295
hit
Definition: SiStripHitEffFromCalibTree.cc:88
MuonAssociatorByHits_cfi.ThreeHitTracksAreSpecial
ThreeHitTracksAreSpecial
Definition: MuonAssociatorByHits_cfi.py:35
TrackAssociatorByHitsImpl::tTopo
TrackerTopology const * tTopo
Definition: TrackAssociatorByHitsImpl.h:89
TrackAssociatorByHitsImpl::cut_RecoToSim
const double cut_RecoToSim
Definition: TrackAssociatorByHitsImpl.h:95
SimHitTPAssociationProducer::simHitTPAssociationListGreater
static bool simHitTPAssociationListGreater(SimHitTPPair i, SimHitTPPair j)
Definition: SimHitTPAssociationProducer.h:23
TrackAssociatorByHitsImpl::TrackAssociatorByHitsImpl
TrackAssociatorByHitsImpl(edm::EDProductGetter const &productGetter, std::unique_ptr< TrackerHitAssociator > iAssociate, TrackerTopology const *iTopo, SimHitTPAssociationList const *iSimHitsTPAssoc, SimToRecoDenomType iSimToRecoDenominator, double iQuality_SimToReco, double iPurity_SimToReco, double iCut_RecoToSim, bool iUsePixels, bool iUseGrouped, bool iUseSplitting, bool ThreeHitTracksAreSpecial, bool AbsoluteNumberOfHits)
Definition: TrackAssociatorByHitsImpl.cc:33
EncodedEventId.h