CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Types | Public Member Functions | Private Member Functions | Private Attributes
TrackAssociatorByHitsImpl Class Reference

#include <TrackAssociatorByHitsImpl.h>

Inheritance diagram for TrackAssociatorByHitsImpl:
reco::TrackToTrackingParticleAssociatorBaseImpl

Public Types

typedef std::vector< std::pair
< OmniClusterRef,
TrackingParticleRef > > 
ClusterTPAssociationList
 
typedef std::vector< SimHitTPPairSimHitTPAssociationList
 
typedef std::pair
< TrackingParticleRef,
TrackPSimHitRef
SimHitTPPair
 
enum  SimToRecoDenomType { denomnone, denomsim, denomreco }
 

Public Member Functions

virtual reco::RecoToSimCollection associateRecoToSim (const edm::RefToBaseVector< reco::Track > &, const edm::RefVector< TrackingParticleCollection > &) const override
 Association Reco To Sim with Collections. More...
 
virtual reco::RecoToSimCollection associateRecoToSim (const edm::Handle< edm::View< reco::Track > > &tCH, const edm::Handle< TrackingParticleCollection > &tPCH) const override
 compare reco to sim the handle of reco::Track and TrackingParticle collections More...
 
virtual
reco::RecoToSimCollectionSeed 
associateRecoToSim (const edm::Handle< edm::View< TrajectorySeed > > &, const edm::Handle< TrackingParticleCollection > &) const override
 
virtual reco::SimToRecoCollection associateSimToReco (const edm::RefToBaseVector< reco::Track > &, const edm::RefVector< TrackingParticleCollection > &) const override
 Association Sim To Reco with Collections. More...
 
virtual reco::SimToRecoCollection associateSimToReco (const edm::Handle< edm::View< reco::Track > > &tCH, const edm::Handle< TrackingParticleCollection > &tPCH) const override
 compare reco to sim the handle of reco::Track and TrackingParticle collections More...
 
virtual
reco::SimToRecoCollectionSeed 
associateSimToReco (const edm::Handle< edm::View< TrajectorySeed > > &, const edm::Handle< TrackingParticleCollection > &) const override
 
 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)
 
- Public Member Functions inherited from reco::TrackToTrackingParticleAssociatorBaseImpl
virtual
reco::RecoToSimCollectionTCandidate 
associateRecoToSim (const edm::Handle< TrackCandidateCollection > &, const edm::Handle< TrackingParticleCollection > &) const
 
virtual
reco::SimToRecoCollectionTCandidate 
associateSimToReco (const edm::Handle< TrackCandidateCollection > &, const edm::Handle< TrackingParticleCollection > &) const
 
 TrackToTrackingParticleAssociatorBaseImpl ()
 Constructor. More...
 
virtual ~TrackToTrackingParticleAssociatorBaseImpl ()
 Destructor. More...
 

Private Member Functions

template<typename iter >
int getDoubleCount (iter, iter, TrackerHitAssociator *, TrackingParticle const &) const
 
const TrackingRecHitgetHitPtr (edm::OwnVector< TrackingRecHit >::const_iterator iter) const
 
const TrackingRecHitgetHitPtr (trackingRecHit_iterator iter) const
 
template<typename iter >
void getMatchedIds (std::vector< SimHitIdpr > &, std::vector< SimHitIdpr > &, int &, iter, iter, TrackerHitAssociator *) const
 
int getShared (std::vector< SimHitIdpr > &, std::vector< SimHitIdpr > &, TrackingParticle const &) const
 

Private Attributes

const bool AbsoluteNumberOfHits
 
std::unique_ptr
< TrackerHitAssociator
associate
 
const double cut_RecoToSim
 
const double purity_SimToReco
 
const double quality_SimToReco
 
SimHitTPAssociationList const * simHitsTPAssoc
 
SimToRecoDenomType SimToRecoDenominator
 
const bool ThreeHitTracksAreSpecial
 
TrackerTopology const * tTopo
 
const bool UseGrouped
 
const bool UsePixels
 
const bool UseSplitting
 

Detailed Description

Definition at line 19 of file TrackAssociatorByHitsImpl.h.

Member Typedef Documentation

Definition at line 25 of file TrackAssociatorByHitsImpl.h.

Definition at line 27 of file TrackAssociatorByHitsImpl.h.

Definition at line 26 of file TrackAssociatorByHitsImpl.h.

Member Enumeration Documentation

Constructor & Destructor Documentation

TrackAssociatorByHitsImpl::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 
)

Definition at line 33 of file TrackAssociatorByHitsImpl.cc.

44  :
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) {}
std::unique_ptr< TrackerHitAssociator > associate
SimHitTPAssociationList const * simHitsTPAssoc
def move
Definition: eostools.py:508

Member Function Documentation

RecoToSimCollection TrackAssociatorByHitsImpl::associateRecoToSim ( const edm::RefToBaseVector< reco::Track > &  tC,
const edm::RefVector< TrackingParticleCollection > &  TPCollectionH 
) const
overridevirtual

Association Reco To Sim with Collections.

Implements reco::TrackToTrackingParticleAssociatorBaseImpl.

Definition at line 91 of file TrackAssociatorByHitsImpl.cc.

References funct::abs(), AbsoluteNumberOfHits, associate, edm::RefToBaseVector< T >::begin(), edm::AssociationMap< Tag >::clear(), cut_RecoToSim, edm::RefToBaseVector< T >::end(), getShared(), edm::AssociationMap< Tag >::insert(), edm::AssociationMap< Tag >::post_insert(), HLT_25ns14e33_v1_cff::quality, edmStreamStallGrapher::t, and ThreeHitTracksAreSpecial.

92  {
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 }
const_iterator end() const
void clear()
clear map
std::unique_ptr< TrackerHitAssociator > associate
int getShared(std::vector< SimHitIdpr > &, std::vector< SimHitIdpr > &, TrackingParticle const &) const
void post_insert()
post insert action
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
void insert(const key_type &k, const data_type &v)
insert an association
const_iterator begin() const
virtual reco::RecoToSimCollection TrackAssociatorByHitsImpl::associateRecoToSim ( const edm::Handle< edm::View< reco::Track > > &  tCH,
const edm::Handle< TrackingParticleCollection > &  tPCH 
) const
inlineoverridevirtual

compare reco to sim the handle of reco::Track and TrackingParticle collections

Reimplemented from reco::TrackToTrackingParticleAssociatorBaseImpl.

Definition at line 57 of file TrackAssociatorByHitsImpl.h.

58  {
59  return TrackToTrackingParticleAssociatorBaseImpl::associateRecoToSim(tCH,tPCH);
60  }
RecoToSimCollectionSeed TrackAssociatorByHitsImpl::associateRecoToSim ( const edm::Handle< edm::View< TrajectorySeed > > &  seedCollectionH,
const edm::Handle< TrackingParticleCollection > &  TPCollectionH 
) const
overridevirtual

Reimplemented from reco::TrackToTrackingParticleAssociatorBaseImpl.

Definition at line 322 of file TrackAssociatorByHitsImpl.cc.

References funct::abs(), AbsoluteNumberOfHits, associate, edm::View< T >::begin(), cut_RecoToSim, edm::View< T >::end(), getShared(), edm::AssociationMap< Tag >::insert(), LogTrace, edm::AssociationMap< Tag >::post_insert(), edm::Handle< T >::product(), HLT_25ns14e33_v1_cff::quality, fileCollector::seed, edm::AssociationMap< Tag >::size(), edmStreamStallGrapher::t, and ThreeHitTracksAreSpecial.

323  {
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 }
std::vector< TrackingParticle > TrackingParticleCollection
std::unique_ptr< TrackerHitAssociator > associate
int getShared(std::vector< SimHitIdpr > &, std::vector< SimHitIdpr > &, TrackingParticle const &) const
const_iterator begin() const
void post_insert()
post insert action
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
#define LogTrace(id)
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
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:81
const_iterator end() const
SimToRecoCollection TrackAssociatorByHitsImpl::associateSimToReco ( const edm::RefToBaseVector< reco::Track > &  tC,
const edm::RefVector< TrackingParticleCollection > &  TPCollectionH 
) const
overridevirtual

Association Sim To Reco with Collections.

Implements reco::TrackToTrackingParticleAssociatorBaseImpl.

Definition at line 168 of file TrackAssociatorByHitsImpl.cc.

References AbsoluteNumberOfHits, associate, edm::RefToBaseVector< T >::begin(), edm::AssociationMap< Tag >::clear(), denomreco, denomsim, edm::RefToBaseVector< T >::end(), getShared(), edm::AssociationMap< Tag >::insert(), TrackerTopology::layer(), SiStripDetId::partnerDetId(), PixelSubdetector::PixelBarrel, PixelSubdetector::PixelEndcap, edm::AssociationMap< Tag >::post_insert(), purity_SimToReco, HLT_25ns14e33_v1_cff::quality, quality_SimToReco, DetId::rawId(), simHitsTPAssoc, SimHitTPAssociationProducer::simHitTPAssociationListGreater(), SimToRecoDenominator, DetId::subdetId(), edmStreamStallGrapher::t, SiStripDetId::TEC, ThreeHitTracksAreSpecial, SiStripDetId::TIB, SiStripDetId::TID, SiStripDetId::TOB, tTopo, UseGrouped, UsePixels, and UseSplitting.

169  {
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 }
static bool simHitTPAssociationListGreater(SimHitTPPair i, SimHitTPPair j)
const_iterator end() const
void clear()
clear map
std::unique_ptr< TrackerHitAssociator > associate
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 post_insert()
post insert action
uint32_t partnerDetId() const
Definition: SiStripDetId.h:168
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:37
Detector identifier class for the strip tracker.
Definition: SiStripDetId.h:17
Definition: DetId.h:18
void insert(const key_type &k, const data_type &v)
insert an association
const_iterator begin() const
unsigned int layer(const DetId &id) const
edm::Ref< edm::PSimHitContainer > TrackPSimHitRef
virtual reco::SimToRecoCollection TrackAssociatorByHitsImpl::associateSimToReco ( const edm::Handle< edm::View< reco::Track > > &  tCH,
const edm::Handle< TrackingParticleCollection > &  tPCH 
) const
inlineoverridevirtual

compare reco to sim the handle of reco::Track and TrackingParticle collections

Reimplemented from reco::TrackToTrackingParticleAssociatorBaseImpl.

Definition at line 64 of file TrackAssociatorByHitsImpl.h.

65  {
66  return TrackToTrackingParticleAssociatorBaseImpl::associateSimToReco(tCH,tPCH);
67  }
SimToRecoCollectionSeed TrackAssociatorByHitsImpl::associateSimToReco ( const edm::Handle< edm::View< TrajectorySeed > > &  seedCollectionH,
const edm::Handle< TrackingParticleCollection > &  TPCollectionH 
) const
overridevirtual

Reimplemented from reco::TrackToTrackingParticleAssociatorBaseImpl.

Definition at line 386 of file TrackAssociatorByHitsImpl.cc.

References AbsoluteNumberOfHits, associate, edm::View< T >::begin(), edm::View< T >::end(), getShared(), edm::AssociationMap< Tag >::insert(), LogTrace, edm::AssociationMap< Tag >::post_insert(), edm::Handle< T >::product(), HLT_25ns14e33_v1_cff::quality, quality_SimToReco, fileCollector::seed, edm::AssociationMap< Tag >::size(), edmStreamStallGrapher::t, and ThreeHitTracksAreSpecial.

387  {
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 }
std::vector< TrackingParticle > TrackingParticleCollection
std::unique_ptr< TrackerHitAssociator > associate
int getShared(std::vector< SimHitIdpr > &, std::vector< SimHitIdpr > &, TrackingParticle const &) const
const_iterator begin() const
void post_insert()
post insert action
#define LogTrace(id)
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
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:81
const_iterator end() const
template<typename iter >
int TrackAssociatorByHitsImpl::getDoubleCount ( iter  begin,
iter  end,
TrackerHitAssociator associate,
TrackingParticle const &  t 
) const
private

Definition at line 526 of file TrackAssociatorByHitsImpl.cc.

References TrackerHitAssociator::associateHitId(), end, spr::find(), getHitPtr(), and getDQMSummary::iter.

529  {
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 }
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
#define end
Definition: vmac.h:37
std::vector< SimTrack >::const_iterator g4t_iterator
const TrackingRecHit * getHitPtr(edm::OwnVector< TrackingRecHit >::const_iterator iter) const
std::pair< uint32_t, EncodedEventId > SimHitIdpr
std::vector< SimHitIdpr > associateHitId(const TrackingRecHit &thit) const
#define begin
Definition: vmac.h:30
const TrackingRecHit* TrackAssociatorByHitsImpl::getHitPtr ( edm::OwnVector< TrackingRecHit >::const_iterator  iter) const
inlineprivate

Definition at line 110 of file TrackAssociatorByHitsImpl.h.

References getDQMSummary::iter.

Referenced by getDoubleCount(), and getMatchedIds().

110 {return &*iter;}
const TrackingRecHit* TrackAssociatorByHitsImpl::getHitPtr ( trackingRecHit_iterator  iter) const
inlineprivate

Definition at line 111 of file TrackAssociatorByHitsImpl.h.

References getDQMSummary::iter.

111 {return &**iter;}
template<typename iter >
void TrackAssociatorByHitsImpl::getMatchedIds ( std::vector< SimHitIdpr > &  matchedIds,
std::vector< SimHitIdpr > &  SimTrackIds,
int &  ri,
iter  begin,
iter  end,
TrackerHitAssociator associate 
) const
private

Definition at line 443 of file TrackAssociatorByHitsImpl.cc.

References TrackerHitAssociator::associateHitId(), end, TrackingRecHit::geographicalId(), getHitPtr(), TrackingRecHit::isValid(), getDQMSummary::iter, j, LogTrace, and DetId::rawId().

448  {
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 }
uint32_t rawId() const
get the raw id
Definition: DetId.h:43
int j
Definition: DBlmapReader.cc:9
#define end
Definition: vmac.h:37
#define LogTrace(id)
const TrackingRecHit * getHitPtr(edm::OwnVector< TrackingRecHit >::const_iterator iter) const
bool isValid() const
std::vector< SimHitIdpr > associateHitId(const TrackingRecHit &thit) const
#define begin
Definition: vmac.h:30
DetId geographicalId() const
int TrackAssociatorByHitsImpl::getShared ( std::vector< SimHitIdpr > &  matchedIds,
std::vector< SimHitIdpr > &  idcachev,
TrackingParticle const &  t 
) const
private

Definition at line 491 of file TrackAssociatorByHitsImpl.cc.

References prof2calltree::count, TrackingParticle::eventId(), spr::find(), j, and TrackingParticle::numberOfHits().

Referenced by associateRecoToSim(), and associateSimToReco().

493  {
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 }
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
int j
Definition: DBlmapReader.cc:9
std::vector< SimTrack >::const_iterator g4t_iterator

Member Data Documentation

const bool TrackAssociatorByHitsImpl::AbsoluteNumberOfHits
private

Definition at line 108 of file TrackAssociatorByHitsImpl.h.

Referenced by associateRecoToSim(), and associateSimToReco().

std::unique_ptr<TrackerHitAssociator> TrackAssociatorByHitsImpl::associate
private

Definition at line 96 of file TrackAssociatorByHitsImpl.h.

Referenced by associateRecoToSim(), and associateSimToReco().

const double TrackAssociatorByHitsImpl::cut_RecoToSim
private

Definition at line 103 of file TrackAssociatorByHitsImpl.h.

Referenced by associateRecoToSim().

const double TrackAssociatorByHitsImpl::purity_SimToReco
private

Definition at line 102 of file TrackAssociatorByHitsImpl.h.

Referenced by associateSimToReco().

const double TrackAssociatorByHitsImpl::quality_SimToReco
private

Definition at line 101 of file TrackAssociatorByHitsImpl.h.

Referenced by associateSimToReco().

SimHitTPAssociationList const* TrackAssociatorByHitsImpl::simHitsTPAssoc
private

Definition at line 98 of file TrackAssociatorByHitsImpl.h.

Referenced by associateSimToReco().

SimToRecoDenomType TrackAssociatorByHitsImpl::SimToRecoDenominator
private

Definition at line 100 of file TrackAssociatorByHitsImpl.h.

Referenced by associateSimToReco().

const bool TrackAssociatorByHitsImpl::ThreeHitTracksAreSpecial
private

Definition at line 107 of file TrackAssociatorByHitsImpl.h.

Referenced by associateRecoToSim(), and associateSimToReco().

TrackerTopology const* TrackAssociatorByHitsImpl::tTopo
private

Definition at line 97 of file TrackAssociatorByHitsImpl.h.

Referenced by associateSimToReco().

const bool TrackAssociatorByHitsImpl::UseGrouped
private

Definition at line 105 of file TrackAssociatorByHitsImpl.h.

Referenced by associateSimToReco().

const bool TrackAssociatorByHitsImpl::UsePixels
private

Definition at line 104 of file TrackAssociatorByHitsImpl.h.

Referenced by associateSimToReco().

const bool TrackAssociatorByHitsImpl::UseSplitting
private

Definition at line 106 of file TrackAssociatorByHitsImpl.h.

Referenced by associateSimToReco().