CMS 3D CMS Logo

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