CMS 3D CMS Logo

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< SimHitTPPairSimHitTPAssociationList
 
typedef std::pair< TrackingParticleRef, TrackPSimHitRefSimHitTPPair
 
enum  SimToRecoDenomType { denomnone, denomsim, denomreco }
 

Public Member Functions

reco::RecoToSimCollection associateRecoToSim (const edm::RefToBaseVector< reco::Track > &, const edm::RefVector< TrackingParticleCollection > &) const override
 Association Reco To Sim with Collections. More...
 
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...
 
reco::RecoToSimCollectionSeed associateRecoToSim (const edm::Handle< edm::View< TrajectorySeed > > &, const edm::Handle< TrackingParticleCollection > &) const override
 
reco::SimToRecoCollection associateSimToReco (const edm::RefToBaseVector< reco::Track > &, const edm::RefVector< TrackingParticleCollection > &) const override
 Association Sim To Reco with Collections. More...
 
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...
 
reco::SimToRecoCollectionSeed associateSimToReco (const edm::Handle< edm::View< TrajectorySeed > > &, const edm::Handle< TrackingParticleCollection > &) const override
 
 TrackAssociatorByHitsImpl (edm::EDProductGetter const &productGetter, 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::RecoToSimCollection associateRecoToSim (const edm::Handle< edm::View< reco::Track >> &tCH, const edm::Handle< TrackingParticleCollection > &tPCH) const
 
virtual reco::RecoToSimCollectionSeed associateRecoToSim (const edm::Handle< edm::View< TrajectorySeed >> &, const edm::Handle< TrackingParticleCollection > &) const
 
virtual reco::RecoToSimCollectionTCandidate associateRecoToSim (const edm::Handle< TrackCandidateCollection > &, const edm::Handle< TrackingParticleCollection > &) const
 
virtual reco::SimToRecoCollection associateSimToReco (const edm::Handle< edm::View< reco::Track >> &tCH, const edm::Handle< TrackingParticleCollection > &tPCH) const
 
virtual reco::SimToRecoCollectionSeed associateSimToReco (const edm::Handle< edm::View< TrajectorySeed >> &, 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< TrackerHitAssociatorassociate
 
const double cut_RecoToSim
 
edm::EDProductGetter const * productGetter_
 
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 23 of file TrackAssociatorByHitsImpl.h.

Member Typedef Documentation

Definition at line 28 of file TrackAssociatorByHitsImpl.h.

Definition at line 27 of file TrackAssociatorByHitsImpl.h.

Member Enumeration Documentation

Constructor & Destructor Documentation

TrackAssociatorByHitsImpl::TrackAssociatorByHitsImpl ( edm::EDProductGetter const &  productGetter,
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.

47  associate(std::move(iAssociate)),
48  tTopo(iTopo),
49  simHitsTPAssoc(iSimHitsTPAssoc),
50  SimToRecoDenominator(iSimToRecoDenominator),
51  quality_SimToReco(iQuality_SimToReco),
52  purity_SimToReco(iPurity_SimToReco),
53  cut_RecoToSim(iCut_RecoToSim),
54  UsePixels(iUsePixels),
55  UseGrouped(iUseGrouped),
56  UseSplitting(iUseSplitting),
57  ThreeHitTracksAreSpecial(iThreeHitTracksAreSpecial),
58  AbsoluteNumberOfHits(iAbsoluteNumberOfHits) {}
edm::EDProductGetter const * productGetter_
std::unique_ptr< TrackerHitAssociator > associate
EDProductGetter const * productGetter(std::atomic< void const * > const &iCache)
SimHitTPAssociationList const * simHitsTPAssoc
def move(src, dest)
Definition: eostools.py:511

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 92 of file TrackAssociatorByHitsImpl.cc.

References funct::abs(), AbsoluteNumberOfHits, associate, edm::RefToBaseVector< T >::begin(), cut_RecoToSim, edm::RefToBaseVector< T >::end(), getShared(), edm::AssociationMap< Tag >::insert(), edm::AssociationMap< Tag >::post_insert(), productGetter_, qcdUeDQM_cfi::quality, OrderedSet::t, ThreeHitTracksAreSpecial, and HLT_2018_cff::track.

94  {
95  //edm::LogVerbatim("TrackAssociator") << "Starting TrackAssociatorByHitsImpl::associateRecoToSim - #tracks="<<tC.size()<<" #TPs="<<TPCollectionH.size();
96  int nshared = 0;
97  float quality = 0; //fraction or absolute number of shared hits
98  std::vector<SimHitIdpr> SimTrackIds;
99  std::vector<SimHitIdpr> matchedIds;
100  RecoToSimCollection outputCollection(productGetter_);
101 
102  //dereference the edm::Refs only once
103  std::vector<TrackingParticle const*> tPC;
104  tPC.reserve(tPC.size());
105  for (auto const& ref : TPCollectionH) {
106  tPC.push_back(&(*ref));
107  }
108 
109  //get the ID of the recotrack by hits
110  int tindex = 0;
111  for (edm::RefToBaseVector<reco::Track>::const_iterator track = tC.begin(); track != tC.end(); track++, tindex++) {
112  matchedIds.clear();
113  int ri = 0; //valid rechits
114  //LogTrace("TrackAssociator") << "\nNEW TRACK - track number " << tindex <<" with pt =" << (*track)->pt() << " # valid=" << (*track)->found();
115  getMatchedIds<trackingRecHit_iterator>(
116  matchedIds, SimTrackIds, ri, (*track)->recHitsBegin(), (*track)->recHitsEnd(), associate.get());
117 
118  //LogTrace("TrackAssociator") << "MATCHED IDS LIST BEGIN" ;
119  //for(size_t j=0; j<matchedIds.size(); j++){
120  // LogTrace("TrackAssociator") << "matchedIds[j].first=" << matchedIds[j].first;
121  //}
122  //LogTrace("TrackAssociator") << "MATCHED IDS LIST END" ;
123  //LogTrace("TrackAssociator") << "#matched ids=" << matchedIds.size() << " #tps=" << tPC.size();
124 
125  //save id for the track
126  std::vector<SimHitIdpr> idcachev;
127  if (!matchedIds.empty()) {
128  int tpindex = 0;
129  for (auto t = tPC.begin(); t != tPC.end(); ++t, ++tpindex) {
130  //int nsimhit = (*t)->trackPSimHit(DetId::Tracker).size();
131  //LogTrace("TrackAssociator") << "TP number " << tpindex << " pdgId=" << (*t)->pdgId() << " with number of PSimHits: " << nsimhit;
132  idcachev.clear();
133  nshared = getShared(matchedIds, idcachev, **t);
134 
135  //if electron subtract double counting
136  if (abs((*t)->pdgId()) == 11 && ((*t)->g4Track_end() - (*t)->g4Track_begin()) > 1) {
137  nshared -= getDoubleCount<trackingRecHit_iterator>(
138  (*track)->recHitsBegin(), (*track)->recHitsEnd(), associate.get(), **t);
139  }
140 
142  quality = static_cast<double>(nshared);
143  else if (ri != 0)
144  quality = (static_cast<double>(nshared) / static_cast<double>(ri));
145  else
146  quality = 0;
147  //cut on the fraction
148  //float purity = 1.0*nshared/ri;
149  if (quality > cut_RecoToSim && !(ThreeHitTracksAreSpecial && ri == 3 && nshared < 3)) {
150  //if a track has just 3 hits we require that all 3 hits are shared
151  outputCollection.insert(tC[tindex], std::make_pair(TPCollectionH[tpindex], quality));
152  // LogTrace("TrackAssociator") << "reco::Track number " << tindex << " with #hits=" << ri <<" pt=" << (*track)->pt()
153  // << " associated to TP (pdgId, nb segments, p) = "
154  // << (*t).pdgId() << " " << (*t).g4Tracks().size()
155  // << " " << (*t).momentum() << " #hits=" << nsimhit
156  // << " TP index=" << tpindex<< " with quality =" << quality;
157  } else {
158  // LogTrace("TrackAssociator") <<"reco::Track number " << tindex << " with #hits=" << ri
159  // << " NOT associated with quality =" << quality;
160  }
161  } //TP loop
162  }
163  }
164  //LogTrace("TrackAssociator") << "% of Assoc Tracks=" << ((double)outputCollection.size())/((double)tC.size());
165  outputCollection.post_insert();
166  return outputCollection;
167 }
const_iterator end() const
edm::EDProductGetter const * productGetter_
std::unique_ptr< TrackerHitAssociator > associate
int getShared(std::vector< SimHitIdpr > &, std::vector< SimHitIdpr > &, TrackingParticle const &) const
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
const_iterator begin() const
reco::RecoToSimCollection TrackAssociatorByHitsImpl::associateRecoToSim ( const edm::Handle< edm::View< reco::Track > > &  tCH,
const edm::Handle< TrackingParticleCollection > &  tPCH 
) const
inlineoverride

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

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
override

Definition at line 325 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(), productGetter_, qcdUeDQM_cfi::quality, SurveyInfoScenario_cff::seed, edm::AssociationMap< Tag >::size(), OrderedSet::t, and ThreeHitTracksAreSpecial.

327  {
328  edm::LogVerbatim("TrackAssociator") << "Starting TrackAssociatorByHitsImpl::associateRecoToSim - #seeds="
329  << seedCollectionH->size() << " #TPs=" << TPCollectionH->size();
330  int nshared = 0;
331  float quality = 0; //fraction or absolute number of shared hits
332  std::vector<SimHitIdpr> SimTrackIds;
333  std::vector<SimHitIdpr> matchedIds;
334  RecoToSimCollectionSeed outputCollection(productGetter_);
335 
336  const TrackingParticleCollection& tPC = *(TPCollectionH.product());
337 
338  const edm::View<TrajectorySeed> sC = *(seedCollectionH.product());
339 
340  //get the ID of the recotrack by hits
341  int tindex = 0;
342  for (edm::View<TrajectorySeed>::const_iterator seed = sC.begin(); seed != sC.end(); seed++, tindex++) {
343  matchedIds.clear();
344  int ri = 0; //valid rechits
345  int nsimhit = seed->recHits().second - seed->recHits().first;
346  LogTrace("TrackAssociator") << "\nNEW SEED - seed number " << tindex << " # valid=" << nsimhit;
347  getMatchedIds<edm::OwnVector<TrackingRecHit>::const_iterator>(
348  matchedIds, SimTrackIds, ri, seed->recHits().first, seed->recHits().second, associate.get());
349 
350  //save id for the track
351  std::vector<SimHitIdpr> idcachev;
352  if (!matchedIds.empty()) {
353  int tpindex = 0;
354  for (TrackingParticleCollection::const_iterator t = tPC.begin(); t != tPC.end(); ++t, ++tpindex) {
355  LogTrace("TrackAssociator") << "TP number " << tpindex << " pdgId=" << t->pdgId()
356  << " with number of PSimHits: " << nsimhit;
357  idcachev.clear();
358  nshared = getShared(matchedIds, idcachev, *t);
359 
360  //if electron subtract double counting
361  if (abs(t->pdgId()) == 11 && (t->g4Track_end() - t->g4Track_begin()) > 1) {
362  nshared -= getDoubleCount<edm::OwnVector<TrackingRecHit>::const_iterator>(
363  seed->recHits().first, seed->recHits().second, associate.get(), *t);
364  }
365 
367  quality = static_cast<double>(nshared);
368  else if (ri != 0)
369  quality = (static_cast<double>(nshared) / static_cast<double>(ri));
370  else
371  quality = 0;
372  //cut on the fraction
373  if (quality > cut_RecoToSim && !(ThreeHitTracksAreSpecial && ri == 3 && nshared < 3)) {
374  //if a track has just 3 hits we require that all 3 hits are shared
375  outputCollection.insert(
376  edm::RefToBase<TrajectorySeed>(seedCollectionH, tindex),
377  std::make_pair(edm::Ref<TrackingParticleCollection>(TPCollectionH, tpindex), quality));
378  LogTrace("TrackAssociator") << "Seed number " << tindex << " with #hits=" << ri
379  << "associated to TP (pdgId, nb segments, p) = " << (*t).pdgId() << " "
380  << (*t).g4Tracks().size() << " " << (*t).momentum() << " number " << tpindex
381  << " with quality =" << quality;
382  } else {
383  LogTrace("TrackAssociator") << "Seed number " << tindex << " with #hits=" << ri
384  << " NOT associated with quality =" << quality;
385  }
386  } //TP loop
387  }
388  }
389  LogTrace("TrackAssociator") << "% of Assoc Seeds="
390  << ((double)outputCollection.size()) / ((double)seedCollectionH->size());
391 
392  outputCollection.post_insert();
393  return outputCollection;
394 }
std::vector< TrackingParticle > TrackingParticleCollection
edm::EDProductGetter const * productGetter_
std::unique_ptr< TrackerHitAssociator > associate
int getShared(std::vector< SimHitIdpr > &, std::vector< SimHitIdpr > &, TrackingParticle const &) const
const_iterator begin() const
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
#define LogTrace(id)
T const * product() const
Definition: Handle.h:69
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:86
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 169 of file TrackAssociatorByHitsImpl.cc.

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

171  {
172  //edm::ESHandle<TrackerTopology> tTopoHand;
173  //setup->get<IdealGeometryRecord>().get(tTopoHand);
174 
175  // edm::LogVerbatim("TrackAssociator") << "Starting TrackAssociatorByHitsImpl::associateSimToReco - #tracks="<<tC.size()<<" #TPs="<<TPCollectionH.size();
176  float quality = 0; //fraction or absolute number of shared hits
177  int nshared = 0;
178  std::vector<SimHitIdpr> SimTrackIds;
179  std::vector<SimHitIdpr> matchedIds;
180  SimToRecoCollection outputCollection(productGetter_);
181 
182  //dereferene the edm::Refs only once
183  std::vector<TrackingParticle const*> tPC;
184  tPC.reserve(tPC.size());
185  for (auto const& ref : TPCollectionH) {
186  tPC.push_back(&(*ref));
187  }
188 
189  //for (TrackingParticleCollection::const_iterator t = tPC.begin(); t != tPC.end(); ++t) {
190  // LogTrace("TrackAssociator") << "NEW TP DUMP";
191  // for (TrackingParticle::g4t_iterator g4T = t -> g4Track_begin();g4T != t -> g4Track_end(); ++g4T) {
192  // LogTrace("TrackAssociator") << "(*g4T).trackId()=" <<(*g4T).trackId() ;
193  // }
194  //}
195 
196  //cdj edm::Handle<SimHitTPAssociationProducer::SimHitTPAssociationList> simHitsTPAssoc;
197  //warning: make sure the TP collection used in the map is the same used in the associator!
198  //e->getByLabel(_simHitTpMapTag,simHitsTPAssoc);
199 
200  //get the ID of the recotrack by hits
201  int tindex = 0;
202  for (edm::RefToBaseVector<reco::Track>::const_iterator track = tC.begin(); track != tC.end(); track++, tindex++) {
203  //LogTrace("TrackAssociator") << "\nNEW TRACK - hits of track number " << tindex <<" with pt =" << (*track)->pt() << " # valid=" << (*track)->found();
204  int ri = 0; //valid rechits
205  getMatchedIds<trackingRecHit_iterator>(
206  matchedIds, SimTrackIds, ri, (*track)->recHitsBegin(), (*track)->recHitsEnd(), associate.get());
207 
208  //save id for the track
209  std::vector<SimHitIdpr> idcachev;
210  if (!matchedIds.empty()) {
211  int tpindex = 0;
212  for (auto t = tPC.begin(); t != tPC.end(); ++t, ++tpindex) {
213  idcachev.clear();
214  float totsimhit = 0;
215 
216  //int nsimhit = trackerPSimHit.size();
217  std::vector<PSimHit> tphits;
218  //LogTrace("TrackAssociator") << "TP number " << tpindex << " pdgId=" << (*t)->pdgId() << " with number of PSimHits: " << nsimhit;
219 
220  nshared = getShared(matchedIds, idcachev, **t);
221 
222  //for(std::vector<PSimHit>::const_iterator TPhit = (*t)->trackerPSimHit_begin(); TPhit != (*t)->trackerPSimHit_end(); TPhit++){
223  // unsigned int detid = TPhit->detUnitId();
224  // DetId detId = DetId(TPhit->detUnitId());
225  // LogTrace("TrackAssociator") << " hit trackId= " << TPhit->trackId() << " det ID = " << detid
226  // << " SUBDET = " << detId.subdetId() << " layer = " << LayerFromDetid(detId);
227  //}
228 
229  if (nshared != 0) { //do not waste time recounting when it is not needed!!!!
230 
231  //count the TP simhit
232  //LogTrace("TrackAssociator") << "recounting of tp hits";
233 
234  std::pair<TrackingParticleRef, TrackPSimHitRef> clusterTPpairWithDummyTP(
235  TPCollectionH[tpindex], TrackPSimHitRef()); //SimHit is dummy: for simHitTPAssociationListGreater
236  // sorting only the cluster is needed
237  auto range = std::equal_range(simHitsTPAssoc->begin(),
238  simHitsTPAssoc->end(),
239  clusterTPpairWithDummyTP,
241  for (auto ip = range.first; ip != range.second; ++ip) {
242  TrackPSimHitRef TPhit = ip->second;
243  DetId dId = DetId(TPhit->detUnitId());
244 
245  unsigned int subdetId = static_cast<unsigned int>(dId.subdetId());
246  if (!UsePixels && (subdetId == PixelSubdetector::PixelBarrel || subdetId == PixelSubdetector::PixelEndcap))
247  continue;
248 
249  //unsigned int dRawId = dId.rawId();
250  SiStripDetId* stripDetId = nullptr;
251  if (subdetId == SiStripDetId::TIB || subdetId == SiStripDetId::TOB || subdetId == SiStripDetId::TID ||
252  subdetId == SiStripDetId::TEC)
253  stripDetId = new SiStripDetId(dId);
254  //LogTrace("TrackAssociator") << "consider hit SUBDET = " << subdetId
255  // << " layer = " << LayerFromDetid(dId)
256  // << " id = " << dId.rawId();
257  bool newhit = true;
258  for (std::vector<PSimHit>::const_iterator TPhitOK = tphits.begin(); TPhitOK != tphits.end(); TPhitOK++) {
259  DetId dIdOK = DetId(TPhitOK->detUnitId());
260  //unsigned int dRawIdOK = dIdOK.rawId();
261  //LogTrace("TrackAssociator") << "\t\tcompare with SUBDET = " << dIdOK.subdetId()
262  // << " layer = " << LayerFromDetid(dIdOK)
263  // << " id = " << dIdOK.rawId();
264  //no grouped, no splitting
265  if (!UseGrouped && !UseSplitting)
266  if (tTopo->layer(dId) == tTopo->layer(dIdOK) && dId.subdetId() == dIdOK.subdetId())
267  newhit = false;
268  //no grouped, splitting
269  if (!UseGrouped && UseSplitting)
270  if (tTopo->layer(dId) == tTopo->layer(dIdOK) && dId.subdetId() == dIdOK.subdetId() &&
271  (stripDetId == nullptr || stripDetId->partnerDetId() != dIdOK.rawId()))
272  newhit = false;
273  //grouped, no splitting
274  if (UseGrouped && !UseSplitting)
275  if (tTopo->layer(dId) == tTopo->layer(dIdOK) && dId.subdetId() == dIdOK.subdetId() &&
276  stripDetId != nullptr && stripDetId->partnerDetId() == dIdOK.rawId())
277  newhit = false;
278  //grouped, splitting
279  if (UseGrouped && UseSplitting)
280  newhit = true;
281  }
282  if (newhit) {
283  //LogTrace("TrackAssociator") << "\t\tok";
284  tphits.push_back(*TPhit);
285  }
286  //else LogTrace("TrackAssociator") << "\t\tno";
287  delete stripDetId;
288  }
289  totsimhit = tphits.size();
290  }
291 
293  quality = static_cast<double>(nshared);
294  else if (SimToRecoDenominator == denomsim && totsimhit != 0)
295  quality = ((double)nshared) / ((double)totsimhit);
296  else if (SimToRecoDenominator == denomreco && ri != 0)
297  quality = ((double)nshared) / ((double)ri);
298  else
299  quality = 0;
300  //LogTrace("TrackAssociator") << "Final count: nhit(TP) = " << nsimhit << " re-counted = " << totsimhit
301  //<< " nshared = " << nshared << " nrechit = " << ri;
302 
303  float purity = 1.0 * nshared / ri;
304  if (quality > quality_SimToReco && !(ThreeHitTracksAreSpecial && totsimhit == 3 && nshared < 3) &&
305  (AbsoluteNumberOfHits || (purity > purity_SimToReco))) {
306  //if a track has just 3 hits we require that all 3 hits are shared
307  outputCollection.insert(TPCollectionH[tpindex], std::make_pair(tC[tindex], quality));
308  // LogTrace("TrackAssociator") << "TrackingParticle number " << tpindex << " with #hits=" << nsimhit
309  // << " re-counted = " << totsimhit << " nshared = " << nshared
310  // << " associated to track number " << tindex << " with pt=" << (*track)->pt()
311  // << " with hit quality =" << quality ;
312  } else {
313  // LogTrace("TrackAssociator") << "TrackingParticle number " << tpindex << " with #hits=" << nsimhit
314  // << " re-counted = " << totsimhit << " nshared = " << nshared
315  // << " NOT associated with quality =" << quality;
316  }
317  }
318  }
319  }
320  //LogTrace("TrackAssociator") << "% of Assoc TPs=" << ((double)outputCollection.size())/((double)TPCollectionH.size());
321  outputCollection.post_insert();
322  return outputCollection;
323 }
static bool simHitTPAssociationListGreater(SimHitTPPair i, SimHitTPPair j)
static constexpr auto TID
Definition: SiStripDetId.h:38
const_iterator end() const
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
edm::EDProductGetter const * productGetter_
std::unique_ptr< TrackerHitAssociator > associate
SimHitTPAssociationList const * simHitsTPAssoc
int getShared(std::vector< SimHitIdpr > &, std::vector< SimHitIdpr > &, TrackingParticle const &) const
uint32_t partnerDetId() const
Definition: SiStripDetId.h:170
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:48
static constexpr auto TOB
Definition: SiStripDetId.h:39
Detector identifier class for the strip tracker.
Definition: SiStripDetId.h:18
Definition: DetId.h:17
const_iterator begin() const
static constexpr auto TIB
Definition: SiStripDetId.h:37
unsigned int layer(const DetId &id) const
edm::Ref< edm::PSimHitContainer > TrackPSimHitRef
static constexpr auto TEC
Definition: SiStripDetId.h:40
reco::SimToRecoCollection TrackAssociatorByHitsImpl::associateSimToReco ( const edm::Handle< edm::View< reco::Track > > &  tCH,
const edm::Handle< TrackingParticleCollection > &  tPCH 
) const
inlineoverride

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

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
override

Definition at line 396 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(), productGetter_, qcdUeDQM_cfi::quality, quality_SimToReco, SurveyInfoScenario_cff::seed, edm::AssociationMap< Tag >::size(), OrderedSet::t, and ThreeHitTracksAreSpecial.

398  {
399  edm::LogVerbatim("TrackAssociator") << "Starting TrackAssociatorByHitsImpl::associateSimToReco - #seeds="
400  << seedCollectionH->size() << " #TPs=" << TPCollectionH->size();
401  float quality = 0; //fraction or absolute number of shared hits
402  int nshared = 0;
403  std::vector<SimHitIdpr> SimTrackIds;
404  std::vector<SimHitIdpr> matchedIds;
405  SimToRecoCollectionSeed outputCollection(productGetter_);
406 
407  const TrackingParticleCollection& tPC = *TPCollectionH.product();
408 
409  const edm::View<TrajectorySeed> sC = *(seedCollectionH.product());
410 
411  //get the ID of the recotrack by hits
412  int tindex = 0;
413  for (edm::View<TrajectorySeed>::const_iterator seed = sC.begin(); seed != sC.end(); seed++, tindex++) {
414  int ri = 0; //valid rechits
415  LogTrace("TrackAssociator") << "\nNEW SEED - seed number " << tindex
416  << " # valid=" << seed->recHits().second - seed->recHits().first;
417  getMatchedIds<edm::OwnVector<TrackingRecHit>::const_iterator>(
418  matchedIds, SimTrackIds, ri, seed->recHits().first, seed->recHits().second, associate.get());
419 
420  //save id for the track
421  std::vector<SimHitIdpr> idcachev;
422  if (!matchedIds.empty()) {
423  int tpindex = 0;
424  for (TrackingParticleCollection::const_iterator t = tPC.begin(); t != tPC.end(); ++t, ++tpindex) {
425  idcachev.clear();
426  int nsimhit = t->numberOfTrackerHits();
427  LogTrace("TrackAssociator") << "TP number " << tpindex << " pdgId=" << t->pdgId()
428  << " with number of PSimHits: " << nsimhit;
429  nshared = getShared(matchedIds, idcachev, *t);
430 
432  quality = static_cast<double>(nshared);
433  else if (ri != 0)
434  quality = ((double)nshared) / ((double)ri);
435  else
436  quality = 0;
437  //LogTrace("TrackAssociator") << "Final count: nhit(TP) = " << nsimhit
438  //<< " nshared = " << nshared
439  //<< " nrechit = " << ri;
440  if (quality > quality_SimToReco && !(ThreeHitTracksAreSpecial && ri == 3 && nshared < 3)) {
441  outputCollection.insert(edm::Ref<TrackingParticleCollection>(TPCollectionH, tpindex),
442  std::make_pair(edm::RefToBase<TrajectorySeed>(seedCollectionH, tindex), quality));
443  LogTrace("TrackAssociator") << "TrackingParticle number " << tpindex << " with #hits=" << nsimhit
444  << " associated to seed number " << tindex << " with #hits=" << ri
445  << " with hit quality =" << quality;
446  } else {
447  LogTrace("TrackAssociator") << "TrackingParticle number " << tpindex << " with #hits=" << nsimhit
448  << " NOT associated with quality =" << quality;
449  }
450  }
451  }
452  }
453  LogTrace("TrackAssociator") << "% of Assoc TPs="
454  << ((double)outputCollection.size()) / ((double)TPCollectionH->size());
455  outputCollection.post_insert();
456  return outputCollection;
457 }
std::vector< TrackingParticle > TrackingParticleCollection
edm::EDProductGetter const * productGetter_
std::unique_ptr< TrackerHitAssociator > associate
int getShared(std::vector< SimHitIdpr > &, std::vector< SimHitIdpr > &, TrackingParticle const &) const
const_iterator begin() const
#define LogTrace(id)
T const * product() const
Definition: Handle.h:69
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:86
const_iterator end() const
template<typename iter >
int TrackAssociatorByHitsImpl::getDoubleCount ( iter  begin,
iter  end,
TrackerHitAssociator associate,
TrackingParticle const &  t 
) const
private

Definition at line 541 of file TrackAssociatorByHitsImpl.cc.

References TrackerHitAssociator::associateHitId(), end, spr::find(), TrackingParticle::g4Track_begin(), TrackingParticle::g4Track_end(), and getHitPtr().

544  {
545  int doublecount = 0;
546  std::vector<SimHitIdpr> SimTrackIdsDC;
547  // cout<<begin-end<<endl;
548  for (iter it = begin; it != end; it++) {
549  int idcount = 0;
550  SimTrackIdsDC.clear();
551  associate->associateHitId(*getHitPtr(it), SimTrackIdsDC);
552  // cout<<SimTrackIdsDC.size()<<endl;
553  if (SimTrackIdsDC.size() > 1) {
554  // cout<<(t.g4Track_end()-t.g4Track_begin())<<endl;
555  for (TrackingParticle::g4t_iterator g4T = t.g4Track_begin(); g4T != t.g4Track_end(); ++g4T) {
556  if (find(SimTrackIdsDC.begin(),
557  SimTrackIdsDC.end(),
558  SimHitIdpr((*g4T).trackId(), SimTrackIdsDC.begin()->second)) != SimTrackIdsDC.end()) {
559  idcount++;
560  }
561  }
562  }
563  if (idcount > 1)
564  doublecount += (idcount - 1);
565  }
566  return doublecount;
567 }
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
#define end
Definition: vmac.h:39
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:32
const TrackingRecHit* TrackAssociatorByHitsImpl::getHitPtr ( edm::OwnVector< TrackingRecHit >::const_iterator  iter) const
inlineprivate

Definition at line 102 of file TrackAssociatorByHitsImpl.h.

Referenced by getDoubleCount(), and getMatchedIds().

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

Definition at line 103 of file TrackAssociatorByHitsImpl.h.

103 { 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 460 of file TrackAssociatorByHitsImpl.cc.

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

465  {
466  matchedIds.clear();
467  ri = 0; //valid rechits
468  for (iter it = begin; it != end; it++) {
469  const TrackingRecHit* hit = getHitPtr(it);
470  if (hit->isValid()) {
471  ri++;
472  uint32_t t_detID = hit->geographicalId().rawId();
473  SimTrackIds.clear();
474  associate->associateHitId(*hit, SimTrackIds);
475  //save all the id of matched simtracks
476  if (!SimTrackIds.empty()) {
477  for (size_t j = 0; j < SimTrackIds.size(); j++) {
478  LogTrace("TrackAssociator") << " hit # " << ri << " valid=" << hit->isValid() << " det id = " << t_detID
479  << " SimId " << SimTrackIds[j].first << " evt=" << SimTrackIds[j].second.event()
480  << " bc=" << SimTrackIds[j].second.bunchCrossing();
481  matchedIds.push_back(SimTrackIds[j]);
482  }
483  }
485  //****to be used when the crossing frame is in the event and with flag TrackAssociatorByHitsImplESProducer.associateRecoTracks = false
486  //std::vector<PSimHit> tmpSimHits = associate->associateHit(*getHitPtr(it));
488  //for(size_t j=0; j<tmpSimHits.size(); j++) {
489  // LogTrace("TrackAssociator") << " hit # " << ri << " valid=" << getHitPtr(it)->isValid()
490  // << " det id = " << t_detID << " SimId " << SimTrackIds[j].first
491  // << " evt=" << SimTrackIds[j].second.event()
492  // << " bc=" << SimTrackIds[j].second.bunchCrossing()
493  // << " process=" << tmpSimHits[j].processType()
494  // << " eloss=" << tmpSimHits[j].energyLoss()
495  // << " part type=" << tmpSimHits[j].particleType()
496  // << " pabs=" << tmpSimHits[j].pabs()
497  // << " trId=" << tmpSimHits[j].trackId();
498  //}
500  } else {
501  LogTrace("TrackAssociator") << "\t\t Invalid Hit On " << hit->geographicalId().rawId();
502  }
503  } //trackingRecHit loop
504 }
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
#define end
Definition: vmac.h:39
#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:32
DetId geographicalId() const
int TrackAssociatorByHitsImpl::getShared ( std::vector< SimHitIdpr > &  matchedIds,
std::vector< SimHitIdpr > &  idcachev,
TrackingParticle const &  t 
) const
private

Definition at line 506 of file TrackAssociatorByHitsImpl.cc.

References KineDebug3::count(), TrackingParticle::eventId(), spr::find(), TrackingParticle::g4Track_begin(), TrackingParticle::g4Track_end(), dqmiolumiharvest::j, and TrackingParticle::numberOfHits().

Referenced by associateRecoToSim(), and associateSimToReco().

508  {
509  int nshared = 0;
510  if (t.numberOfHits() == 0)
511  return nshared; //should use trackerPSimHit but is not const
512 
513  for (size_t j = 0; j < matchedIds.size(); j++) {
514  //LogTrace("TrackAssociator") << "now matchedId=" << matchedIds[j].first;
515  if (find(idcachev.begin(), idcachev.end(), matchedIds[j]) == idcachev.end()) {
516  //only the first time we see this ID
517  idcachev.push_back(matchedIds[j]);
518 
519  for (TrackingParticle::g4t_iterator g4T = t.g4Track_begin(); g4T != t.g4Track_end(); ++g4T) {
520  // LogTrace("TrackAssociator") << " TP (ID, Ev, BC) = " << (*g4T).trackId()
521  // << ", " << t.eventId().event() << ", "<< t.eventId().bunchCrossing()
522  // << " Match(ID, Ev, BC) = " << matchedIds[j].first
523  // << ", " << matchedIds[j].second.event() << ", "
524  // << matchedIds[j].second.bunchCrossing() ;
525  //<< "\t G4 Track Momentum " << (*g4T).momentum()
526  //<< " \t reco Track Momentum " << track->momentum();
527  if ((*g4T).trackId() == matchedIds[j].first && t.eventId() == matchedIds[j].second) {
528  int countedhits = std::count(matchedIds.begin(), matchedIds.end(), matchedIds[j]);
529  nshared += countedhits;
530 
531  // LogTrace("TrackAssociator") << "hits shared by this segment : " << countedhits;
532  // LogTrace("TrackAssociator") << "hits shared so far : " << nshared;
533  }
534  } //g4Tracks loop
535  }
536  }
537  return nshared;
538 }
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
std::vector< SimTrack >::const_iterator g4t_iterator

Member Data Documentation

const bool TrackAssociatorByHitsImpl::AbsoluteNumberOfHits
private

Definition at line 100 of file TrackAssociatorByHitsImpl.h.

Referenced by associateRecoToSim(), and associateSimToReco().

std::unique_ptr<TrackerHitAssociator> TrackAssociatorByHitsImpl::associate
private
const double TrackAssociatorByHitsImpl::cut_RecoToSim
private

Definition at line 95 of file TrackAssociatorByHitsImpl.h.

Referenced by associateRecoToSim().

edm::EDProductGetter const* TrackAssociatorByHitsImpl::productGetter_
private

Definition at line 87 of file TrackAssociatorByHitsImpl.h.

Referenced by associateRecoToSim(), and associateSimToReco().

const double TrackAssociatorByHitsImpl::purity_SimToReco
private

Definition at line 94 of file TrackAssociatorByHitsImpl.h.

Referenced by associateSimToReco().

const double TrackAssociatorByHitsImpl::quality_SimToReco
private

Definition at line 93 of file TrackAssociatorByHitsImpl.h.

Referenced by associateSimToReco().

SimHitTPAssociationList const* TrackAssociatorByHitsImpl::simHitsTPAssoc
private

Definition at line 90 of file TrackAssociatorByHitsImpl.h.

Referenced by associateSimToReco().

SimToRecoDenomType TrackAssociatorByHitsImpl::SimToRecoDenominator
private

Definition at line 92 of file TrackAssociatorByHitsImpl.h.

Referenced by associateSimToReco().

const bool TrackAssociatorByHitsImpl::ThreeHitTracksAreSpecial
private

Definition at line 99 of file TrackAssociatorByHitsImpl.h.

Referenced by associateRecoToSim(), and associateSimToReco().

TrackerTopology const* TrackAssociatorByHitsImpl::tTopo
private

Definition at line 89 of file TrackAssociatorByHitsImpl.h.

Referenced by associateSimToReco().

const bool TrackAssociatorByHitsImpl::UseGrouped
private

Definition at line 97 of file TrackAssociatorByHitsImpl.h.

Referenced by associateSimToReco().

const bool TrackAssociatorByHitsImpl::UsePixels
private

Definition at line 96 of file TrackAssociatorByHitsImpl.h.

Referenced by associateSimToReco().

const bool TrackAssociatorByHitsImpl::UseSplitting
private

Definition at line 98 of file TrackAssociatorByHitsImpl.h.

Referenced by associateSimToReco().