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