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->nHits();
346  LogTrace("TrackAssociator") << "\nNEW SEED - seed number " << tindex << " # valid=" << nsimhit;
347  getMatchedIds<edm::OwnVector<TrackingRecHit>::const_iterator>(
348  matchedIds, SimTrackIds, ri, seed->recHits().begin(), seed->recHits().end(), 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().begin(), seed->recHits().end(), 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 << " # valid=" << seed->nHits();
416  getMatchedIds<edm::OwnVector<TrackingRecHit>::const_iterator>(
417  matchedIds, SimTrackIds, ri, seed->recHits().begin(), seed->recHits().end(), associate.get());
418 
419  //save id for the track
420  std::vector<SimHitIdpr> idcachev;
421  if (!matchedIds.empty()) {
422  int tpindex = 0;
423  for (TrackingParticleCollection::const_iterator t = tPC.begin(); t != tPC.end(); ++t, ++tpindex) {
424  idcachev.clear();
425  int nsimhit = t->numberOfTrackerHits();
426  LogTrace("TrackAssociator") << "TP number " << tpindex << " pdgId=" << t->pdgId()
427  << " with number of PSimHits: " << nsimhit;
428  nshared = getShared(matchedIds, idcachev, *t);
429 
431  quality = static_cast<double>(nshared);
432  else if (ri != 0)
433  quality = ((double)nshared) / ((double)ri);
434  else
435  quality = 0;
436  //LogTrace("TrackAssociator") << "Final count: nhit(TP) = " << nsimhit
437  //<< " nshared = " << nshared
438  //<< " nrechit = " << ri;
439  if (quality > quality_SimToReco && !(ThreeHitTracksAreSpecial && ri == 3 && nshared < 3)) {
440  outputCollection.insert(edm::Ref<TrackingParticleCollection>(TPCollectionH, tpindex),
441  std::make_pair(edm::RefToBase<TrajectorySeed>(seedCollectionH, tindex), quality));
442  LogTrace("TrackAssociator") << "TrackingParticle number " << tpindex << " with #hits=" << nsimhit
443  << " associated to seed number " << tindex << " with #hits=" << ri
444  << " with hit quality =" << quality;
445  } else {
446  LogTrace("TrackAssociator") << "TrackingParticle number " << tpindex << " with #hits=" << nsimhit
447  << " NOT associated with quality =" << quality;
448  }
449  }
450  }
451  }
452  LogTrace("TrackAssociator") << "% of Assoc TPs="
453  << ((double)outputCollection.size()) / ((double)TPCollectionH->size());
454  outputCollection.post_insert();
455  return outputCollection;
456 }
457 
458 template <typename iter>
459 void TrackAssociatorByHitsImpl::getMatchedIds(std::vector<SimHitIdpr>& matchedIds,
460  std::vector<SimHitIdpr>& SimTrackIds,
461  int& ri,
462  iter begin,
463  iter end,
464  TrackerHitAssociator* associate) const {
465  matchedIds.clear();
466  ri = 0; //valid rechits
467  for (iter it = begin; it != end; it++) {
468  const TrackingRecHit* hit = getHitPtr(it);
469  if (hit->isValid()) {
470  ri++;
471  uint32_t t_detID = hit->geographicalId().rawId();
472  SimTrackIds.clear();
473  associate->associateHitId(*hit, SimTrackIds);
474  //save all the id of matched simtracks
475  if (!SimTrackIds.empty()) {
476  for (size_t j = 0; j < SimTrackIds.size(); j++) {
477  LogTrace("TrackAssociator") << " hit # " << ri << " valid=" << hit->isValid() << " det id = " << t_detID
478  << " SimId " << SimTrackIds[j].first << " evt=" << SimTrackIds[j].second.event()
479  << " bc=" << SimTrackIds[j].second.bunchCrossing();
480  matchedIds.push_back(SimTrackIds[j]);
481  }
482  }
484  //****to be used when the crossing frame is in the event and with flag TrackAssociatorByHitsImplESProducer.associateRecoTracks = false
485  //std::vector<PSimHit> tmpSimHits = associate->associateHit(*getHitPtr(it));
487  //for(size_t j=0; j<tmpSimHits.size(); j++) {
488  // LogTrace("TrackAssociator") << " hit # " << ri << " valid=" << getHitPtr(it)->isValid()
489  // << " det id = " << t_detID << " SimId " << SimTrackIds[j].first
490  // << " evt=" << SimTrackIds[j].second.event()
491  // << " bc=" << SimTrackIds[j].second.bunchCrossing()
492  // << " process=" << tmpSimHits[j].processType()
493  // << " eloss=" << tmpSimHits[j].energyLoss()
494  // << " part type=" << tmpSimHits[j].particleType()
495  // << " pabs=" << tmpSimHits[j].pabs()
496  // << " trId=" << tmpSimHits[j].trackId();
497  //}
499  } else {
500  LogTrace("TrackAssociator") << "\t\t Invalid Hit On " << hit->geographicalId().rawId();
501  }
502  } //trackingRecHit loop
503 }
504 
505 int TrackAssociatorByHitsImpl::getShared(std::vector<SimHitIdpr>& matchedIds,
506  std::vector<SimHitIdpr>& idcachev,
507  TrackingParticle const& t) const {
508  int nshared = 0;
509  if (t.numberOfHits() == 0)
510  return nshared; //should use trackerPSimHit but is not const
511 
512  for (size_t j = 0; j < matchedIds.size(); j++) {
513  //LogTrace("TrackAssociator") << "now matchedId=" << matchedIds[j].first;
514  if (find(idcachev.begin(), idcachev.end(), matchedIds[j]) == idcachev.end()) {
515  //only the first time we see this ID
516  idcachev.push_back(matchedIds[j]);
517 
518  for (TrackingParticle::g4t_iterator g4T = t.g4Track_begin(); g4T != t.g4Track_end(); ++g4T) {
519  // LogTrace("TrackAssociator") << " TP (ID, Ev, BC) = " << (*g4T).trackId()
520  // << ", " << t.eventId().event() << ", "<< t.eventId().bunchCrossing()
521  // << " Match(ID, Ev, BC) = " << matchedIds[j].first
522  // << ", " << matchedIds[j].second.event() << ", "
523  // << matchedIds[j].second.bunchCrossing() ;
524  //<< "\t G4 Track Momentum " << (*g4T).momentum()
525  //<< " \t reco Track Momentum " << track->momentum();
526  if ((*g4T).trackId() == matchedIds[j].first && t.eventId() == matchedIds[j].second) {
527  int countedhits = std::count(matchedIds.begin(), matchedIds.end(), matchedIds[j]);
528  nshared += countedhits;
529 
530  // LogTrace("TrackAssociator") << "hits shared by this segment : " << countedhits;
531  // LogTrace("TrackAssociator") << "hits shared so far : " << nshared;
532  }
533  } //g4Tracks loop
534  }
535  }
536  return nshared;
537 }
538 
539 template <typename iter>
541  iter end,
542  TrackerHitAssociator* associate,
543  TrackingParticle const& t) const {
544  int doublecount = 0;
545  std::vector<SimHitIdpr> SimTrackIdsDC;
546  // cout<<begin-end<<endl;
547  for (iter it = begin; it != end; it++) {
548  int idcount = 0;
549  SimTrackIdsDC.clear();
550  associate->associateHitId(*getHitPtr(it), SimTrackIdsDC);
551  // cout<<SimTrackIdsDC.size()<<endl;
552  if (SimTrackIdsDC.size() > 1) {
553  // cout<<(t.g4Track_end()-t.g4Track_begin())<<endl;
554  for (TrackingParticle::g4t_iterator g4T = t.g4Track_begin(); g4T != t.g4Track_end(); ++g4T) {
555  if (find(SimTrackIdsDC.begin(),
556  SimTrackIdsDC.end(),
557  SimHitIdpr((*g4T).trackId(), SimTrackIdsDC.begin()->second)) != SimTrackIdsDC.end()) {
558  idcount++;
559  }
560  }
561  }
562  if (idcount > 1)
563  doublecount += (idcount - 1);
564  }
565  return doublecount;
566 }
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
HLT_FULL_cff.track
track
Definition: HLT_FULL_cff.py:11713
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:459
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
edm::Ref
Definition: AssociativeIterator.h:58
quality
const uint32_t *__restrict__ Quality * quality
Definition: CAHitNtupletGeneratorKernelsImpl.h:109
fileCollector.seed
seed
Definition: fileCollector.py:127
edm::EDProductGetter
Definition: EDProductGetter.h:41
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
mps_fire.end
end
Definition: mps_fire.py:242
edm::reftobase::BaseVectorHolder::const_iterator
Definition: BaseVectorHolder.h:54
submitPVResolutionJobs.count
count
Definition: submitPVResolutionJobs.py:352
TrackAssociatorByHitsImpl::denomsim
Definition: TrackAssociatorByHitsImpl.h:25
MuonAssociatorByHits_cfi.UseSplitting
UseSplitting
Definition: MuonAssociatorByHits_cfi.py:34
TrackAssociatorByHitsImpl::denomreco
Definition: TrackAssociatorByHitsImpl.h:25
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:505
edm::AssociationMap< edm::OneToManyWithQualityGeneric< edm::View< reco::Track >, TrackingParticleCollection, double > >
MuonAssociatorByHits_cfi.UseGrouped
UseGrouped
Definition: MuonAssociatorByHits_cfi.py:33
TrackAssociatorByHitsImpl::UseSplitting
const bool UseSplitting
Definition: TrackAssociatorByHitsImpl.h:98
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:540
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
DetId.h
TrackingParticleFwd.h
edm::LogVerbatim
Log< level::Info, true > LogVerbatim
Definition: MessageLogger.h:128
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:9
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
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
LogTrace
#define LogTrace(id)
Definition: MessageLogger.h:234
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
submitPVValidationJobs.t
string t
Definition: submitPVValidationJobs.py:644
quickTrackAssociatorByHits_cfi.SimToRecoDenominator
SimToRecoDenominator
Definition: quickTrackAssociatorByHits_cfi.py:6
TrackAssociatorByHitsImpl::purity_SimToReco
const double purity_SimToReco
Definition: TrackAssociatorByHitsImpl.h:94
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