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 //
14 
15 //reco track
19 //TrackingParticle
23 //##---new stuff
35 using namespace reco;
36 using namespace std;
37 
38 /* Constructor */
40  conf_(conf),
41  AbsoluteNumberOfHits(conf_.getParameter<bool>("AbsoluteNumberOfHits")),
42  SimToRecoDenominator(denomnone),
43  quality_SimToReco(conf_.getParameter<double>("Quality_SimToReco")),
44  purity_SimToReco(conf_.getParameter<double>("Purity_SimToReco")),
45  cut_RecoToSim(conf_.getParameter<double>("Cut_RecoToSim")),
46  UsePixels(conf_.getParameter<bool>("UsePixels")),
47  UseGrouped(conf_.getParameter<bool>("UseGrouped")),
48  UseSplitting(conf_.getParameter<bool>("UseSplitting")),
49  ThreeHitTracksAreSpecial(conf_.getParameter<bool>("ThreeHitTracksAreSpecial"))
50 {
51  std::string tmp = conf_.getParameter<string>("SimToRecoDenominator");
52  if (tmp=="sim") {
54  } else if (tmp == "reco") {
56  }
57 
59  throw cms::Exception("TrackAssociatorByHits") << "SimToRecoDenominator not specified as sim or reco";
60  }
61 
62 }
63 
64 
65 /* Destructor */
67 {
68  //do cleanup here
69 }
70 
71 //
72 //---member functions
73 //
74 
77  const edm::RefVector<TrackingParticleCollection>& TPCollectionH,
78  const edm::Event * e,
79  const edm::EventSetup *setup ) const{
80 
81  //edm::LogVerbatim("TrackAssociator") << "Starting TrackAssociatorByHits::associateRecoToSim - #tracks="<<tC.size()<<" #TPs="<<TPCollectionH.size();
82  int nshared = 0;
83  float quality=0;//fraction or absolute number of shared hits
84  std::vector< SimHitIdpr> SimTrackIds;
85  std::vector< SimHitIdpr> matchedIds;
86  RecoToSimCollection outputCollection;
87 
88  TrackerHitAssociator * associate = new TrackerHitAssociator(*e, conf_);
89 
91  if (TPCollectionH.size()!=0) tPC = *const_cast<TrackingParticleCollection*>(TPCollectionH.product());
92 
93  //get the ID of the recotrack by hits
94  int tindex=0;
96  matchedIds.clear();
97  int ri=0;//valid rechits
98  //LogTrace("TrackAssociator") << "\nNEW TRACK - track number " << tindex <<" with pt =" << (*track)->pt() << " # valid=" << (*track)->found();
99  getMatchedIds<trackingRecHit_iterator>(matchedIds, SimTrackIds, ri, (*track)->recHitsBegin(), (*track)->recHitsEnd(), associate);
100 
101  //LogTrace("TrackAssociator") << "MATCHED IDS LIST BEGIN" ;
102  //for(size_t j=0; j<matchedIds.size(); j++){
103  // LogTrace("TrackAssociator") << "matchedIds[j].first=" << matchedIds[j].first;
104  //}
105  //LogTrace("TrackAssociator") << "MATCHED IDS LIST END" ;
106  //LogTrace("TrackAssociator") << "#matched ids=" << matchedIds.size() << " #tps=" << tPC.size();
107 
108  //save id for the track
109  std::vector<SimHitIdpr> idcachev;
110  if(!matchedIds.empty()){
111 
112  int tpindex =0;
113  for (TrackingParticleCollection::iterator t = tPC.begin(); t != tPC.end(); ++t, ++tpindex) {
114  //int nsimhit = t->trackPSimHit(DetId::Tracker).size();
115  //LogTrace("TrackAssociator") << "TP number " << tpindex << " pdgId=" << t->pdgId() << " with number of PSimHits: " << nsimhit;
116  idcachev.clear();
117  nshared = getShared(matchedIds, idcachev, t);
118 
119  //if electron subtract double counting
120  if (abs(t->pdgId())==11&&(t->g4Track_end()-t->g4Track_begin())>1){
121  nshared-=getDoubleCount<trackingRecHit_iterator>((*track)->recHitsBegin(), (*track)->recHitsEnd(), associate, t);
122  }
123 
124  if (AbsoluteNumberOfHits) quality = static_cast<double>(nshared);
125  else if(ri!=0) quality = (static_cast<double>(nshared)/static_cast<double>(ri));
126  else quality = 0;
127  //cut on the fraction
128  //float purity = 1.0*nshared/ri;
129  if(quality > cut_RecoToSim && !(ThreeHitTracksAreSpecial && ri==3 && nshared<3)){
130  //if a track has just 3 hits we require that all 3 hits are shared
131  outputCollection.insert(tC[tindex],
132  std::make_pair(edm::Ref<TrackingParticleCollection>(TPCollectionH, tpindex),
133  quality));
134 // LogTrace("TrackAssociator") << "reco::Track number " << tindex << " with #hits=" << ri <<" pt=" << (*track)->pt()
135 // << " associated to TP (pdgId, nb segments, p) = "
136 // << (*t).pdgId() << " " << (*t).g4Tracks().size()
137 // << " " << (*t).momentum() << " #hits=" << nsimhit
138 // << " TP index=" << tpindex<< " with quality =" << quality;
139  } else {
140 // LogTrace("TrackAssociator") <<"reco::Track number " << tindex << " with #hits=" << ri
141 // << " NOT associated with quality =" << quality;
142  }
143  }//TP loop
144  }
145  }
146  //LogTrace("TrackAssociator") << "% of Assoc Tracks=" << ((double)outputCollection.size())/((double)tC.size());
147  delete associate;
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 // edm::LogVerbatim("TrackAssociator") << "Starting TrackAssociatorByHits::associateSimToReco - #tracks="<<tC.size()<<" #TPs="<<TPCollectionH.size();
159  float quality=0;//fraction or absolute number of shared hits
160  int nshared = 0;
161  std::vector< SimHitIdpr> SimTrackIds;
162  std::vector< SimHitIdpr> matchedIds;
163  SimToRecoCollection outputCollection;
164 
165  TrackerHitAssociator * associate = new TrackerHitAssociator(*e, conf_);
166 
168  if (TPCollectionH.size()!=0) tPC = *const_cast<TrackingParticleCollection*>(TPCollectionH.product());
169 
170  //for (TrackingParticleCollection::const_iterator t = tPC.begin(); t != tPC.end(); ++t) {
171  // LogTrace("TrackAssociator") << "NEW TP DUMP";
172  // for (TrackingParticle::g4t_iterator g4T = t -> g4Track_begin();g4T != t -> g4Track_end(); ++g4T) {
173  // LogTrace("TrackAssociator") << "(*g4T).trackId()=" <<(*g4T).trackId() ;
174  // }
175  //}
176 
177  //get the ID of the recotrack by hits
178  int tindex=0;
180  //LogTrace("TrackAssociator") << "\nNEW TRACK - hits of track number " << tindex <<" with pt =" << (*track)->pt() << " # valid=" << (*track)->found();
181  int ri=0;//valid rechits
182  getMatchedIds<trackingRecHit_iterator>(matchedIds, SimTrackIds, ri, (*track)->recHitsBegin(), (*track)->recHitsEnd(), associate);
183 
184  //save id for the track
185  std::vector<SimHitIdpr> idcachev;
186  if(!matchedIds.empty()){
187 
188  int tpindex =0;
189  for (TrackingParticleCollection::iterator t = tPC.begin(); t != tPC.end(); ++t, ++tpindex) {
190  idcachev.clear();
191  std::vector<PSimHit> trackerPSimHit( t->trackPSimHit(DetId::Tracker) );
192  //int nsimhit = trackerPSimHit.size();
193  float totsimhit = 0;
194  std::vector<PSimHit> tphits;
195  //LogTrace("TrackAssociator") << "TP number " << tpindex << " pdgId=" << t->pdgId() << " with number of PSimHits: " << nsimhit;
196 
197  nshared = getShared(matchedIds, idcachev, t);
198 
199  //for(std::vector<PSimHit>::const_iterator TPhit = t->trackerPSimHit_begin(); TPhit != t->trackerPSimHit_end(); TPhit++){
200  // unsigned int detid = TPhit->detUnitId();
201  // DetId detId = DetId(TPhit->detUnitId());
202  // LogTrace("TrackAssociator") << " hit trackId= " << TPhit->trackId() << " det ID = " << detid
203  // << " SUBDET = " << detId.subdetId() << " layer = " << LayerFromDetid(detId);
204  //}
205 
206  if (nshared!=0) {//do not waste time recounting when it is not needed!!!!
207 
208  //count the TP simhit
209  //LogTrace("TrackAssociator") << "recounting of tp hits";
210  for(std::vector<PSimHit>::const_iterator TPhit = trackerPSimHit.begin(); TPhit != trackerPSimHit.end(); TPhit++){
211  DetId dId = DetId(TPhit->detUnitId());
212 
213  unsigned int subdetId = static_cast<unsigned int>(dId.subdetId());
215  continue;
216 
217  //unsigned int dRawId = dId.rawId();
218  SiStripDetId* stripDetId = 0;
219  if (subdetId==SiStripDetId::TIB||subdetId==SiStripDetId::TOB||
220  subdetId==SiStripDetId::TID||subdetId==SiStripDetId::TEC)
221  stripDetId= new SiStripDetId(dId);
222  //LogTrace("TrackAssociator") << "consider hit SUBDET = " << subdetId
223  // << " layer = " << LayerFromDetid(dId)
224  // << " id = " << dId.rawId();
225  bool newhit = true;
226  for(std::vector<PSimHit>::const_iterator TPhitOK = tphits.begin(); TPhitOK != tphits.end(); TPhitOK++){
227  DetId dIdOK = DetId(TPhitOK->detUnitId());
228  //unsigned int dRawIdOK = dIdOK.rawId();
229  //LogTrace("TrackAssociator") << "\t\tcompare with SUBDET = " << dIdOK.subdetId()
230  // << " layer = " << LayerFromDetid(dIdOK)
231  // << " id = " << dIdOK.rawId();
232  //no grouped, no splitting
233  if (!UseGrouped && !UseSplitting)
234  if (LayerFromDetid(dId)==LayerFromDetid(dIdOK) &&
235  dId.subdetId()==dIdOK.subdetId()) newhit = false;
236  //no grouped, splitting
237  if (!UseGrouped && UseSplitting)
238  if (LayerFromDetid(dId)==LayerFromDetid(dIdOK) &&
239  dId.subdetId()==dIdOK.subdetId() &&
240  (stripDetId==0 || stripDetId->partnerDetId()!=dIdOK.rawId()))
241  newhit = false;
242  //grouped, no splitting
243  if (UseGrouped && !UseSplitting)
244  if (LayerFromDetid(dId)==LayerFromDetid(dIdOK) &&
245  dId.subdetId()==dIdOK.subdetId() &&
246  stripDetId!=0 && stripDetId->partnerDetId()==dIdOK.rawId())
247  newhit = false;
248  //grouped, splitting
249  if (UseGrouped && UseSplitting)
250  newhit = true;
251  }
252  if (newhit) {
253  //LogTrace("TrackAssociator") << "\t\tok";
254  tphits.push_back(*TPhit);
255  }
256  //else LogTrace("TrackAssociator") << "\t\tno";
257  delete stripDetId;
258  }
259  totsimhit = tphits.size();
260  }
261 
262  if (AbsoluteNumberOfHits) quality = static_cast<double>(nshared);
263  else if(SimToRecoDenominator == denomsim && totsimhit!=0) quality = ((double) nshared)/((double)totsimhit);
264  else if(SimToRecoDenominator == denomreco && ri!=0) quality = ((double) nshared)/((double)ri);
265  else quality = 0;
266  //LogTrace("TrackAssociator") << "Final count: nhit(TP) = " << nsimhit << " re-counted = " << totsimhit
267  //<< " nshared = " << nshared << " nrechit = " << ri;
268 
269  float purity = 1.0*nshared/ri;
270  if (quality>quality_SimToReco && !(ThreeHitTracksAreSpecial && totsimhit==3 && nshared<3) && (AbsoluteNumberOfHits||(purity>purity_SimToReco))) {
271  //if a track has just 3 hits we require that all 3 hits are shared
272  outputCollection.insert(edm::Ref<TrackingParticleCollection>(TPCollectionH, tpindex),
273  std::make_pair(tC[tindex],quality));
274 // LogTrace("TrackAssociator") << "TrackingParticle number " << tpindex << " with #hits=" << nsimhit
275 // << " re-counted = " << totsimhit << " nshared = " << nshared
276 // << " associated to track number " << tindex << " with pt=" << (*track)->pt()
277 // << " with hit quality =" << quality ;
278  } else {
279 // LogTrace("TrackAssociator") << "TrackingParticle number " << tpindex << " with #hits=" << nsimhit
280 // << " re-counted = " << totsimhit << " nshared = " << nshared
281 // << " NOT associated with quality =" << quality;
282  }
283  }
284  }
285  }
286  //LogTrace("TrackAssociator") << "% of Assoc TPs=" << ((double)outputCollection.size())/((double)TPCollectionH.size());
287  delete associate;
288  outputCollection.post_insert();
289  return outputCollection;
290 }
291 
293 {
294  int layerNumber=0;
295  unsigned int subdetId = static_cast<unsigned int>(detId.subdetId());
296  if ( subdetId == StripSubdetector::TIB)
297  {
298  TIBDetId tibid(detId.rawId());
299  layerNumber = tibid.layer();
300  }
301  else if ( subdetId == StripSubdetector::TOB )
302  {
303  TOBDetId tobid(detId.rawId());
304  layerNumber = tobid.layer();
305  }
306  else if ( subdetId == StripSubdetector::TID)
307  {
308  TIDDetId tidid(detId.rawId());
309  layerNumber = tidid.wheel();
310  }
311  else if ( subdetId == StripSubdetector::TEC )
312  {
313  TECDetId tecid(detId.rawId());
314  layerNumber = tecid.wheel();
315  }
316  else if ( subdetId == PixelSubdetector::PixelBarrel )
317  {
318  PXBDetId pxbid(detId.rawId());
319  layerNumber = pxbid.layer();
320  }
321  else if ( subdetId == PixelSubdetector::PixelEndcap )
322  {
323  PXFDetId pxfid(detId.rawId());
324  layerNumber = pxfid.disk();
325  }
326  else
327  LogTrace("TrackAssociator") << "Unknown subdetid: " << subdetId;
328 
329  return layerNumber;
330 }
331 
335  const edm::Event * e,
336  const edm::EventSetup *setup ) const{
337 
338  edm::LogVerbatim("TrackAssociator") << "Starting TrackAssociatorByHits::associateRecoToSim - #seeds="
339  <<seedCollectionH->size()<<" #TPs="<<TPCollectionH->size();
340  int nshared = 0;
341  float quality=0;//fraction or absolute number of shared hits
342  std::vector< SimHitIdpr> SimTrackIds;
343  std::vector< SimHitIdpr> matchedIds;
344  RecoToSimCollectionSeed outputCollection;
345 
346  TrackerHitAssociator * associate = new TrackerHitAssociator(*e, conf_);
347 
348  const TrackingParticleCollection tPC = *(TPCollectionH.product());
349 
350  const edm::View<TrajectorySeed> sC = *(seedCollectionH.product());
351 
352  //get the ID of the recotrack by hits
353  int tindex=0;
354  for (edm::View<TrajectorySeed>::const_iterator seed=sC.begin(); seed!=sC.end(); seed++, tindex++) {
355  matchedIds.clear();
356  int ri=0;//valid rechits
357  int nsimhit = seed->recHits().second-seed->recHits().first;
358  LogTrace("TrackAssociator") << "\nNEW SEED - seed number " << tindex << " # valid=" << nsimhit;
359  getMatchedIds<edm::OwnVector<TrackingRecHit>::const_iterator>(matchedIds, SimTrackIds, ri, seed->recHits().first, seed->recHits().second, associate );
360 
361  //save id for the track
362  std::vector<SimHitIdpr> idcachev;
363  if(!matchedIds.empty()){
364 
365  int tpindex =0;
366  for (TrackingParticleCollection::const_iterator t = tPC.begin(); t != tPC.end(); ++t, ++tpindex) {
367  LogTrace("TrackAssociator") << "TP number " << tpindex << " pdgId=" << t->pdgId() << " with number of PSimHits: " << nsimhit;
368  idcachev.clear();
369  nshared = getShared(matchedIds, idcachev, t);
370 
371  //if electron subtract double counting
372  if (abs(t->pdgId())==11&&(t->g4Track_end()-t->g4Track_begin())>1){
373  nshared-=getDoubleCount<edm::OwnVector<TrackingRecHit>::const_iterator>(seed->recHits().first, seed->recHits().second, associate, t);
374  }
375 
376  if (AbsoluteNumberOfHits) quality = static_cast<double>(nshared);
377  else if(ri!=0) quality = (static_cast<double>(nshared)/static_cast<double>(ri));
378  else quality = 0;
379  //cut on the fraction
380  if(quality > cut_RecoToSim && !(ThreeHitTracksAreSpecial && ri==3 && nshared<3) ){
381  //if a track has just 3 hits we require that all 3 hits are shared
382  outputCollection.insert(edm::RefToBase<TrajectorySeed>(seedCollectionH,tindex),
383  std::make_pair(edm::Ref<TrackingParticleCollection>(TPCollectionH, tpindex),quality));
384  LogTrace("TrackAssociator") << "Seed number " << tindex << " with #hits=" << ri
385  << "associated to TP (pdgId, nb segments, p) = "
386  << (*t).pdgId() << " " << (*t).g4Tracks().size()
387  << " " << (*t).momentum() <<" number " << tpindex << " with quality =" << quality;
388  } else {
389  LogTrace("TrackAssociator") <<"Seed number " << tindex << " with #hits=" << ri << " NOT associated with quality =" << quality;
390  }
391  }//TP loop
392  }
393  }
394  LogTrace("TrackAssociator") << "% of Assoc Seeds=" << ((double)outputCollection.size())/((double)seedCollectionH->size());
395  delete associate;
396  outputCollection.post_insert();
397  return outputCollection;
398 }
399 
400 
404  const edm::Event * e,
405  const edm::EventSetup *setup ) const{
406 
407  edm::LogVerbatim("TrackAssociator") << "Starting TrackAssociatorByHits::associateSimToReco - #seeds="
408  <<seedCollectionH->size()<<" #TPs="<<TPCollectionH->size();
409  float quality=0;//fraction or absolute number of shared hits
410  int nshared = 0;
411  std::vector< SimHitIdpr> SimTrackIds;
412  std::vector< SimHitIdpr> matchedIds;
413  SimToRecoCollectionSeed outputCollection;
414 
415  TrackerHitAssociator * associate = new TrackerHitAssociator(*e, conf_);
416 
417  TrackingParticleCollection tPC =*const_cast<TrackingParticleCollection*>(TPCollectionH.product());
418 
419  const edm::View<TrajectorySeed> sC = *(seedCollectionH.product());
420 
421  //get the ID of the recotrack by hits
422  int tindex=0;
423  for (edm::View<TrajectorySeed>::const_iterator seed=sC.begin(); seed!=sC.end(); seed++, tindex++) {
424  int ri=0;//valid rechits
425  LogTrace("TrackAssociator") << "\nNEW SEED - seed number " << tindex << " # valid=" << seed->recHits().second-seed->recHits().first;
426  getMatchedIds<edm::OwnVector<TrackingRecHit>::const_iterator>(matchedIds, SimTrackIds, ri, seed->recHits().first, seed->recHits().second, associate );
427 
428  //save id for the track
429  std::vector<SimHitIdpr> idcachev;
430  if(!matchedIds.empty()){
431  int tpindex =0;
432  for (TrackingParticleCollection::iterator t = tPC.begin(); t != tPC.end(); ++t, ++tpindex) {
433  idcachev.clear();
434  int nsimhit = t->trackPSimHit(DetId::Tracker).size();
435  LogTrace("TrackAssociator") << "TP number " << tpindex << " pdgId=" << t->pdgId() << " with number of PSimHits: " << nsimhit;
436  nshared = getShared(matchedIds, idcachev, t);
437 
438  if (AbsoluteNumberOfHits) quality = static_cast<double>(nshared);
439  else if(ri!=0) quality = ((double) nshared)/((double)ri);
440  else quality = 0;
441  //LogTrace("TrackAssociator") << "Final count: nhit(TP) = " << nsimhit
442  //<< " nshared = " << nshared
443  //<< " nrechit = " << ri;
444  if(quality > quality_SimToReco && !(ThreeHitTracksAreSpecial && ri==3 && nshared<3) ){
445  outputCollection.insert(edm::Ref<TrackingParticleCollection>(TPCollectionH, tpindex),
446  std::make_pair(edm::RefToBase<TrajectorySeed>(seedCollectionH,tindex), quality));
447  LogTrace("TrackAssociator") << "TrackingParticle number " << tpindex << " with #hits=" << nsimhit
448  << " associated to seed number " << tindex << " with #hits=" << ri
449  << " with hit quality =" << quality ;
450  }
451  else {
452  LogTrace("TrackAssociator") << "TrackingParticle number " << tpindex << " with #hits=" << nsimhit << " NOT associated with quality =" << quality;
453  }
454  }
455  }
456  }
457  LogTrace("TrackAssociator") << "% of Assoc TPs=" << ((double)outputCollection.size())/((double)TPCollectionH->size());
458  delete associate;
459  outputCollection.post_insert();
460  return outputCollection;
461 }
462 
463 template<typename iter>
464 void TrackAssociatorByHits::getMatchedIds(std::vector<SimHitIdpr>& matchedIds,
465  std::vector<SimHitIdpr>& SimTrackIds,
466  int& ri,
467  iter begin,
468  iter end,
469  TrackerHitAssociator* associate ) const {
470  matchedIds.clear();
471  ri=0;//valid rechits
472  for (iter it = begin; it != end; it++){
473  const TrackingRecHit *hit=getHitPtr(it);
474  if (hit->isValid()){
475  ri++;
476  uint32_t t_detID= hit->geographicalId().rawId();
477  SimTrackIds.clear();
478  associate->associateHitId(*hit, SimTrackIds);
479  //save all the id of matched simtracks
480  if(!SimTrackIds.empty()){
481  for(size_t j=0; j<SimTrackIds.size(); j++){
482  LogTrace("TrackAssociator") << " hit # " << ri << " valid=" << hit->isValid()
483  << " det id = " << t_detID << " SimId " << SimTrackIds[j].first
484  << " evt=" << SimTrackIds[j].second.event()
485  << " bc=" << SimTrackIds[j].second.bunchCrossing();
486  matchedIds.push_back(SimTrackIds[j]);
487  }
488  }
490  //****to be used when the crossing frame is in the event and with flag TrackAssociatorByHitsESProducer.associateRecoTracks = false
491  //std::vector<PSimHit> tmpSimHits = associate->associateHit(*getHitPtr(it));
493  //for(size_t j=0; j<tmpSimHits.size(); j++) {
494  // LogTrace("TrackAssociator") << " hit # " << ri << " valid=" << getHitPtr(it)->isValid()
495  // << " det id = " << t_detID << " SimId " << SimTrackIds[j].first
496  // << " evt=" << SimTrackIds[j].second.event()
497  // << " bc=" << SimTrackIds[j].second.bunchCrossing()
498  // << " process=" << tmpSimHits[j].processType()
499  // << " eloss=" << tmpSimHits[j].energyLoss()
500  // << " part type=" << tmpSimHits[j].particleType()
501  // << " pabs=" << tmpSimHits[j].pabs()
502  // << " trId=" << tmpSimHits[j].trackId();
503  //}
505  }else{
506  LogTrace("TrackAssociator") <<"\t\t Invalid Hit On "<<hit->geographicalId().rawId();
507  }
508  }//trackingRecHit loop
509 }
510 
511 
512 int TrackAssociatorByHits::getShared(std::vector<SimHitIdpr>& matchedIds,
513  std::vector<SimHitIdpr>& idcachev,
514  TrackingParticleCollection::const_iterator t) const {
515  int nshared = 0;
516  if (t->trackPSimHit().size()==0) return nshared;//should use trackerPSimHit but is not const
517 
518  for(size_t j=0; j<matchedIds.size(); j++){
519  //LogTrace("TrackAssociator") << "now matchedId=" << matchedIds[j].first;
520  if(find(idcachev.begin(), idcachev.end(),matchedIds[j]) == idcachev.end() ){
521  //only the first time we see this ID
522  idcachev.push_back(matchedIds[j]);
523 
524  for (TrackingParticle::g4t_iterator g4T = t -> g4Track_begin(); g4T != t -> g4Track_end(); ++g4T) {
525 // LogTrace("TrackAssociator") << " TP (ID, Ev, BC) = " << (*g4T).trackId()
526 // << ", " << t->eventId().event() << ", "<< t->eventId().bunchCrossing()
527 // << " Match(ID, Ev, BC) = " << matchedIds[j].first
528 // << ", " << matchedIds[j].second.event() << ", "
529 // << matchedIds[j].second.bunchCrossing() ;
530  //<< "\t G4 Track Momentum " << (*g4T).momentum()
531  //<< " \t reco Track Momentum " << track->momentum();
532  if((*g4T).trackId() == matchedIds[j].first && t->eventId() == matchedIds[j].second){
533  int countedhits = std::count(matchedIds.begin(), matchedIds.end(), matchedIds[j]);
534  nshared += countedhits;
535 
536 // LogTrace("TrackAssociator") << "hits shared by this segment : " << countedhits;
537 // LogTrace("TrackAssociator") << "hits shared so far : " << nshared;
538  }
539  }//g4Tracks loop
540  }
541  }
542  return nshared;
543 }
544 
545 
546 template<typename iter>
548  iter end,
549  TrackerHitAssociator* associate,
550  TrackingParticleCollection::const_iterator t) const {
551  int doublecount = 0 ;
552  std::vector<SimHitIdpr> SimTrackIdsDC;
553  // cout<<begin-end<<endl;
554  for (iter it = begin; it != end; it++){
555  int idcount = 0;
556  SimTrackIdsDC.clear();
557  associate->associateHitId(*getHitPtr(it), SimTrackIdsDC);
558  // cout<<SimTrackIdsDC.size()<<endl;
559  if(SimTrackIdsDC.size()>1){
560  // cout<<(t->g4Track_end()-t->g4Track_begin())<<endl;
561  for (TrackingParticle::g4t_iterator g4T = t -> g4Track_begin(); g4T != t -> g4Track_end(); ++g4T) {
562  if(find(SimTrackIdsDC.begin(), SimTrackIdsDC.end(),SimHitIdpr((*g4T).trackId(), SimTrackIdsDC.begin()->second)) != SimTrackIdsDC.end() ){
563  idcount++;
564  }
565  }
566  }
567  if (idcount>1) doublecount+=(idcount-1);
568  }
569  return doublecount;
570 }
T getParameter(std::string const &) const
TrackAssociatorByHits(const edm::ParameterSet &)
void getMatchedIds(std::vector< SimHitIdpr > &, std::vector< SimHitIdpr > &, int &, iter, iter, TrackerHitAssociator *) const
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:86
unsigned int layer() const
layer id
Definition: TOBDetId.h:39
C const * product() const
Accessor for product collection.
Definition: RefVector.h:268
int getShared(std::vector< SimHitIdpr > &, std::vector< SimHitIdpr > &, TrackingParticleCollection::const_iterator) const
unsigned int layerNumber(align::ID)
Layer number increases with rho from 1 to 8.
Definition: TIBNameSpace.h:85
const_iterator end() const
#define abs(x)
Definition: mlp_lapack.h:159
int LayerFromDetid(const DetId &) const
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
std::vector< SimHitIdpr > associateHitId(const TrackingRecHit &thit)
unsigned int layer() const
layer id
Definition: PXBDetId.h:35
uint32_t rawId() const
get the raw id
Definition: DetId.h:45
const TrackingRecHit * getHitPtr(edm::OwnVector< TrackingRecHit >::const_iterator iter) const
void post_insert()
post insert action
virtual uint32_t partnerDetId() const
Definition: SiStripDetId.h:156
int j
Definition: DBlmapReader.cc:9
#define end
Definition: vmac.h:38
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:39
#define LogTrace(id)
unsigned int disk() const
disk id
Definition: PXFDetId.h:43
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:20
reco::SimToRecoCollection associateSimToReco(const edm::RefToBaseVector< reco::Track > &, const edm::RefVector< TrackingParticleCollection > &, const edm::Event *event=0, const edm::EventSetup *setup=0) const
Association Sim To Reco with Collections.
std::pair< uint32_t, EncodedEventId > SimHitIdpr
size_type size() const
map size
void insert(const key_type &k, const data_type &v)
insert an association
bool isValid() const
const edm::ParameterSet & conf_
int getDoubleCount(iter, iter, TrackerHitAssociator *, TrackingParticleCollection::const_iterator) const
T const * product() const
Definition: Handle.h:74
unsigned int wheel() const
wheel id
Definition: TECDetId.h:52
const_iterator begin() const
unsigned int layer() const
layer id
Definition: TIBDetId.h:41
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
#define begin
Definition: vmac.h:31
size_type size() const
Size of the RefVector.
Definition: RefVector.h:85
reco::RecoToSimCollection associateRecoToSim(const edm::RefToBaseVector< reco::Track > &, const edm::RefVector< TrackingParticleCollection > &, const edm::Event *event=0, const edm::EventSetup *setup=0) const
Association Reco To Sim with Collections.
const_iterator begin() const
const_iterator end() const
std::vector< TrackingParticle > TrackingParticleCollection
DetId geographicalId() const
SimToRecoDenomType SimToRecoDenominator
unsigned int wheel() const
wheel id
Definition: TIDDetId.h:50