CMS 3D CMS Logo

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