CMS 3D CMS Logo

List of all members | Public Types | Public Member Functions | Private Types | Private Member Functions | Static Private Member Functions | Private Attributes
QuickTrackAssociatorByHitsImpl Class Reference

TrackToTrackingParticleAssociator that associates by hits a bit quicker than the normal TrackAssociatorByHitsImpl class. More...

#include <QuickTrackAssociatorByHitsImpl.h>

Inheritance diagram for QuickTrackAssociatorByHitsImpl:
reco::TrackToTrackingParticleAssociatorBaseImpl

Public Types

enum  SimToRecoDenomType { denomnone, denomsim, denomreco }
 

Public Member Functions

reco::RecoToSimCollection associateRecoToSim (const edm::Handle< edm::View< reco::Track > > &trackCollectionHandle, const edm::Handle< TrackingParticleCollection > &trackingParticleCollectionHandle) const override
 compare reco to sim the handle of reco::Track and TrackingParticle collections More...
 
reco::RecoToSimCollection associateRecoToSim (const edm::RefToBaseVector< reco::Track > &trackCollection, const edm::RefVector< TrackingParticleCollection > &trackingParticleCollection) const override
 Association Reco To Sim with Collections. More...
 
reco::RecoToSimCollectionSeed associateRecoToSim (const edm::Handle< edm::View< TrajectorySeed > > &, const edm::Handle< TrackingParticleCollection > &) const override
 
reco::SimToRecoCollection associateSimToReco (const edm::Handle< edm::View< reco::Track > > &trackCollectionHandle, const edm::Handle< TrackingParticleCollection > &trackingParticleCollectionHandle) const override
 compare reco to sim the handle of reco::Track and TrackingParticle collections More...
 
reco::SimToRecoCollection associateSimToReco (const edm::RefToBaseVector< reco::Track > &trackCollection, const edm::RefVector< TrackingParticleCollection > &trackingParticleCollection) const override
 Association Sim To Reco with Collections. More...
 
reco::SimToRecoCollectionSeed associateSimToReco (const edm::Handle< edm::View< TrajectorySeed > > &, const edm::Handle< TrackingParticleCollection > &) const override
 
 QuickTrackAssociatorByHitsImpl (edm::EDProductGetter const &productGetter, std::unique_ptr< const TrackerHitAssociator > hitAssoc, const ClusterTPAssociation *clusterToTPMap, bool absoluteNumberOfHits, double qualitySimToReco, double puritySimToReco, double cutRecoToSim, double pixelHitWeight, bool threeHitTracksAreSpecial, SimToRecoDenomType simToRecoDenominator)
 
- 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 Types

typedef std::pair< uint32_t, EncodedEventIdSimTrackIdentifiers
 This is enough information to uniquely identify a sim track. More...
 
typedef edm::IndexSet TrackingParticleRefKeySet
 Set for TrackingParticleRef keys. More...
 

Private Member Functions

template<class T_TrackCollection , class T_TrackingParticleCollection , class T_hitOrClusterAssociator >
reco::RecoToSimCollection associateRecoToSimImplementation (const T_TrackCollection &trackCollection, const T_TrackingParticleCollection &trackingParticleCollection, const TrackingParticleRefKeySet *trackingParticleKeys, T_hitOrClusterAssociator hitOrClusterAssociator) const
 The method that does the work for both overloads of associateRecoToSim. More...
 
template<class T_TrackCollection , class T_TrackingParticleCollection , class T_hitOrClusterAssociator >
reco::SimToRecoCollection associateSimToRecoImplementation (const T_TrackCollection &trackCollection, const T_TrackingParticleCollection &trackingParticleCollection, const TrackingParticleRefKeySet *trackingParticleKeys, T_hitOrClusterAssociator hitOrClusterAssociator) const
 The method that does the work for both overloads of associateSimToReco. More...
 
template<typename T_TPCollection , typename iter >
std::vector< std::pair< edm::Ref< TrackingParticleCollection >, double > > associateTrack (const TrackerHitAssociator &hitAssociator, const T_TPCollection &trackingParticles, const TrackingParticleRefKeySet *trackingParticleKeys, iter begin, iter end) const
 Returns the TrackingParticle that has the most associated hits to the given track. More...
 
template<typename T_TPCollection , typename iter >
std::vector< std::pair< edm::Ref< TrackingParticleCollection >, double > > associateTrack (const ClusterTPAssociation &clusterToTPMap, const T_TPCollection &trackingParticles, const TrackingParticleRefKeySet *trackingParticleKeys, iter begin, iter end) const
 Returns the TrackingParticle that has the most associated hits to the given track. More...
 
template<typename iter >
std::vector< std::pair< SimTrackIdentifiers, double > > getAllSimTrackIdentifiers (const TrackerHitAssociator &hitAssociator, iter begin, iter end) const
 Returns a vector of pairs where first is a SimTrackIdentifiers (see typedef above) and second is the number of hits that came from that sim track. More...
 
template<typename iter >
double getDoubleCount (const TrackerHitAssociator &hitAssociator, iter begin, iter end, TrackingParticleRef associatedTrackingParticle) const
 This method was copied almost verbatim from the standard TrackAssociatorByHits. More...
 
template<typename iter >
double getDoubleCount (const ClusterTPAssociation &clusterToTPList, iter begin, iter end, TrackingParticleRef associatedTrackingParticle) const
 Overload for when using cluster to TrackingParticle association list. More...
 
const TrackingRecHitgetHitFromIter (trackingRecHit_iterator iter) const
 
const TrackingRecHitgetHitFromIter (TrackingRecHitCollection::const_iterator iter) const
 
template<typename iter >
std::vector< OmniClusterRefgetMatchedClusters (iter begin, iter end) const
 
bool trackingParticleContainsIdentifier (const TrackingParticle *pTrackingParticle, const SimTrackIdentifiers &identifier) const
 Returns true if the supplied TrackingParticle has the supplied g4 track identifiers. More...
 
double weightedNumberOfTrackClusters (const reco::Track &track, const TrackerHitAssociator &) const
 
double weightedNumberOfTrackClusters (const TrajectorySeed &seed, const TrackerHitAssociator &) const
 
double weightedNumberOfTrackClusters (const reco::Track &track, const ClusterTPAssociation &) const
 
double weightedNumberOfTrackClusters (const TrajectorySeed &seed, const ClusterTPAssociation &) const
 
template<typename iter >
double weightedNumberOfTrackClusters (iter begin, iter end) const
 

Static Private Member Functions

static bool tpIntPairGreater (std::pair< edm::Ref< TrackingParticleCollection >, size_t > i, std::pair< edm::Ref< TrackingParticleCollection >, size_t > j)
 

Private Attributes

bool absoluteNumberOfHits_
 
const ClusterTPAssociationclusterToTPMap_
 
double cutRecoToSim_
 
std::unique_ptr< const TrackerHitAssociatorhitAssociator_
 
double pixelHitWeight_
 
edm::EDProductGetter const * productGetter_
 creates either a ClusterTPAssociation OR a TrackerHitAssociator and stores it in the provided unique_ptr. The other will be null. More...
 
double puritySimToReco_
 
double qualitySimToReco_
 
SimToRecoDenomType simToRecoDenominator_
 
bool threeHitTracksAreSpecial_
 

Detailed Description

TrackToTrackingParticleAssociator that associates by hits a bit quicker than the normal TrackAssociatorByHitsImpl class.

NOTE - Doesn't implement the TrackCandidate association methods (from TrackAssociatorBase) so will always return empty associations for those.

This track associator (mostly) does the same as TrackAssociatorByHitsImpl, but faster. I've tested it a fair bit and can't find any differences between the results of this and the standard TrackAssociatorByHitsImpl.

Configuration parameters:

AbsoluteNumberOfHits - bool - if true, Quality_SimToReco and Cut_RecoToSim are the absolute number of shared hits required for association, not the percentage.

Quality_SimToReco - double - The minimum amount of shared hits required, as a percentage of either the reconstructed hits or simulated hits (see SimToRecoDenominator), for the track to be considered associated during a call to associateSimToReco. See also AbsoluteNumberOfHits.

Purity_SimToReco - double - The minimum amount of shared hits required, as a percentage of the reconstructed hits, for the track to be considered associated during a call to associateSimToReco. Has no effect if AbsoluteNumberOfHits is true.

Cut_RecoToSim - double - The minimum amount of shared hits required, as a percentage of the reconstructed hits, for the track to be considered associated during a call to associateRecoToSim. See also AbsoluteNumberOfHits.

ThreeHitTracksAreSpecial - bool - If true, tracks with 3 hits must have all their hits associated.

SimToRecoDenominator - string - Must be either "sim" or "reco". If "sim" Quality_SimToReco is the percentage of simulated hits that need to be shared. If "reco" then it's the percentage of reconstructed hits (i.e. same as Purity_SimToReco).

associatePixel - bool - Passed on to the hit associator.

associateStrip - bool - Passed on to the hit associator.

requireStoredHits - bool - Whether or not to insist all TrackingParticles have at least one PSimHit. The PSimHits are not required for the association, but the old TrackAssociatorByHitsImpl still had this requirement. Storing PSimHits in the TrackingParticle is now optional (see TrackingTruthAccumulator which replaces TrackingTruthProducer). Having requireStoredHits set to true will mean no TrackingParticles will be associated if you have chosen not to store the hits. The flag is only kept in order to retain the old behaviour which can give very slightly different results.

Note that the TrackAssociatorByHitsImpl parameters UseGrouped and UseSplitting are not used.

Author
Mark Grimes (mark..nosp@m.grim.nosp@m.es@ce.nosp@m.rn.c.nosp@m.h)
Date
09/Nov/2010 Significant changes to remove any differences to the standard TrackAssociatorByHitsImpl results 07/Jul/2011. Association for TrajectorySeeds added by Giuseppe Cerati sometime between 2011 and 2013. Functionality to associate using pre calculated cluster to TrackingParticle maps added by Subir Sarker sometime in 2013. Overhauled to remove mutables to make it thread safe by Mark Grimes 01/May/2014.

Definition at line 66 of file QuickTrackAssociatorByHitsImpl.h.

Member Typedef Documentation

This is enough information to uniquely identify a sim track.

Definition at line 101 of file QuickTrackAssociatorByHitsImpl.h.

Set for TrackingParticleRef keys.

Definition at line 103 of file QuickTrackAssociatorByHitsImpl.h.

Member Enumeration Documentation

Constructor & Destructor Documentation

QuickTrackAssociatorByHitsImpl::QuickTrackAssociatorByHitsImpl ( edm::EDProductGetter const &  productGetter,
std::unique_ptr< const TrackerHitAssociator hitAssoc,
const ClusterTPAssociation clusterToTPMap,
bool  absoluteNumberOfHits,
double  qualitySimToReco,
double  puritySimToReco,
double  cutRecoToSim,
double  pixelHitWeight,
bool  threeHitTracksAreSpecial,
SimToRecoDenomType  simToRecoDenominator 
)

Definition at line 104 of file QuickTrackAssociatorByHitsImpl.cc.

114  :
116  hitAssociator_(std::move(hitAssoc)),
117  clusterToTPMap_(clusterToTPMap),
118  qualitySimToReco_(qualitySimToReco),
119  puritySimToReco_(puritySimToReco),
120  pixelHitWeight_(pixelHitWeight),
121  cutRecoToSim_(cutRecoToSim),
122  simToRecoDenominator_(simToRecoDenominator) ,
123  threeHitTracksAreSpecial_(threeHitTracksAreSpecial),
124  absoluteNumberOfHits_(absoluteNumberOfHits)
125  {}
edm::EDProductGetter const * productGetter_
creates either a ClusterTPAssociation OR a TrackerHitAssociator and stores it in the provided unique_...
const ClusterTPAssociation * clusterToTPMap_
EDProductGetter const * productGetter(std::atomic< void const * > const &iCache)
def move(src, dest)
Definition: eostools.py:510
std::unique_ptr< const TrackerHitAssociator > hitAssociator_

Member Function Documentation

reco::RecoToSimCollection QuickTrackAssociatorByHitsImpl::associateRecoToSim ( const edm::Handle< edm::View< reco::Track > > &  tCH,
const edm::Handle< TrackingParticleCollection > &  tPCH 
) const
overridevirtual

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

Reimplemented from reco::TrackToTrackingParticleAssociatorBaseImpl.

Definition at line 128 of file QuickTrackAssociatorByHitsImpl.cc.

References associateRecoToSimImplementation(), clusterToTPMap_, and hitAssociator_.

130 {
131  // Only pass the one that was successfully created to the templated method.
132  if( not clusterToTPMap_ ) return associateRecoToSimImplementation( trackCollectionHandle, trackingParticleCollectionHandle, nullptr, *hitAssociator_ );
133  else return associateRecoToSimImplementation( trackCollectionHandle, trackingParticleCollectionHandle, nullptr, *clusterToTPMap_ );
134 }
reco::RecoToSimCollection associateRecoToSimImplementation(const T_TrackCollection &trackCollection, const T_TrackingParticleCollection &trackingParticleCollection, const TrackingParticleRefKeySet *trackingParticleKeys, T_hitOrClusterAssociator hitOrClusterAssociator) const
The method that does the work for both overloads of associateRecoToSim.
const ClusterTPAssociation * clusterToTPMap_
std::unique_ptr< const TrackerHitAssociator > hitAssociator_
reco::RecoToSimCollection QuickTrackAssociatorByHitsImpl::associateRecoToSim ( const edm::RefToBaseVector< reco::Track > &  tc,
const edm::RefVector< TrackingParticleCollection > &  tpc 
) const
overridevirtual

Association Reco To Sim with Collections.

Implements reco::TrackToTrackingParticleAssociatorBaseImpl.

Definition at line 144 of file QuickTrackAssociatorByHitsImpl.cc.

References associateRecoToSimImplementation(), clusterToTPMap_, and hitAssociator_.

146 {
147  // Only pass the one that was successfully created to the templated method.
149  else {
151  fillKeys(tpKeys, trackingParticleCollection);
153  }
154 }
reco::RecoToSimCollection associateRecoToSimImplementation(const T_TrackCollection &trackCollection, const T_TrackingParticleCollection &trackingParticleCollection, const TrackingParticleRefKeySet *trackingParticleKeys, T_hitOrClusterAssociator hitOrClusterAssociator) const
The method that does the work for both overloads of associateRecoToSim.
const ClusterTPAssociation * clusterToTPMap_
edm::IndexSet TrackingParticleRefKeySet
Set for TrackingParticleRef keys.
std::unique_ptr< const TrackerHitAssociator > hitAssociator_
reco::RecoToSimCollectionSeed QuickTrackAssociatorByHitsImpl::associateRecoToSim ( const edm::Handle< edm::View< TrajectorySeed > > &  pSeedCollectionHandle_,
const edm::Handle< TrackingParticleCollection > &  trackingParticleCollectionHandle 
) const
overridevirtual

Reimplemented from reco::TrackToTrackingParticleAssociatorBaseImpl.

Definition at line 608 of file QuickTrackAssociatorByHitsImpl.cc.

References funct::abs(), absoluteNumberOfHits_, associateTrack(), clusterToTPMap_, cutRecoToSim_, getDoubleCount(), hitAssociator_, mps_fire::i, edm::AssociationMap< Tag >::insert(), LogTrace, TrajectorySeed::nHits(), edm::AssociationMap< Tag >::post_insert(), productGetter_, btvTracks_cfi::quality, TrajectorySeed::recHits(), edm::AssociationMap< Tag >::size(), threeHitTracksAreSpecial_, and weightedNumberOfTrackClusters().

610 {
611 
612  edm::LogVerbatim( "TrackAssociator" ) << "Starting TrackAssociatorByHitsImpl::associateRecoToSim - #seeds=" << pSeedCollectionHandle_->size()
613  << " #TPs=" << trackingParticleCollectionHandle->size();
614 
616 
617  size_t collectionSize=pSeedCollectionHandle_->size();
618 
619  for( size_t i=0; i < collectionSize; ++i )
620  {
621  const TrajectorySeed* pSeed= &( *pSeedCollectionHandle_)[i];
622 
623  // The return of this function has first as the index and second as the number of associated hits
624  std::vector < std::pair<edm::Ref<TrackingParticleCollection>,double> > trackingParticleQualityPairs=
625  (clusterToTPMap_) ? associateTrack( *clusterToTPMap_, trackingParticleCollectionHandle, nullptr, pSeed->recHits().first, pSeed->recHits().second ) : associateTrack( *hitAssociator_, trackingParticleCollectionHandle, nullptr, pSeed->recHits().first, pSeed->recHits().second );
626  for( auto iTrackingParticleQualityPair=
627  trackingParticleQualityPairs.begin(); iTrackingParticleQualityPair != trackingParticleQualityPairs.end();
628  ++iTrackingParticleQualityPair )
629  {
630  const edm::Ref<TrackingParticleCollection>& trackingParticleRef=iTrackingParticleQualityPair->first;
631  double numberOfSharedClusters=iTrackingParticleQualityPair->second;
632  double numberOfValidTrackClusters = clusterToTPMap_ ? weightedNumberOfTrackClusters(*pSeed, *clusterToTPMap_) : weightedNumberOfTrackClusters(*pSeed, *hitAssociator_);
633 
634  if( numberOfSharedClusters == 0.0 ) continue; // No point in continuing if there was no association
635 
636  //if electron subtract double counting
637  if( abs( trackingParticleRef->pdgId() ) == 11 && (trackingParticleRef->g4Track_end() - trackingParticleRef->g4Track_begin()) > 1 )
638  {
639  if( clusterToTPMap_ ) numberOfSharedClusters-=getDoubleCount( *clusterToTPMap_, pSeed->recHits().first, pSeed->recHits().second, trackingParticleRef );
640  else numberOfSharedClusters-=getDoubleCount( *hitAssociator_, pSeed->recHits().first, pSeed->recHits().second, trackingParticleRef );
641  }
642 
643  double quality;
644  if( absoluteNumberOfHits_ ) quality = numberOfSharedClusters;
645  else if( numberOfValidTrackClusters != 0.0 ) quality = numberOfSharedClusters / numberOfValidTrackClusters;
646  else quality=0;
647 
648  if( quality > cutRecoToSim_ && !(threeHitTracksAreSpecial_ && pSeed->nHits() == 3 && numberOfSharedClusters < 3.0) )
649  {
650  returnValue.insert( edm::RefToBase < TrajectorySeed > (pSeedCollectionHandle_, i), std::make_pair( trackingParticleRef, quality ) );
651  }
652  }
653  }
654 
655  LogTrace( "TrackAssociator" ) << "% of Assoc Seeds=" << ((double)returnValue.size()) / ((double)pSeedCollectionHandle_->size());
656  returnValue.post_insert();
657  return returnValue;
658 
659 }
std::vector< std::pair< edm::Ref< TrackingParticleCollection >, double > > associateTrack(const TrackerHitAssociator &hitAssociator, const T_TPCollection &trackingParticles, const TrackingParticleRefKeySet *trackingParticleKeys, iter begin, iter end) const
Returns the TrackingParticle that has the most associated hits to the given track.
edm::EDProductGetter const * productGetter_
creates either a ClusterTPAssociation OR a TrackerHitAssociator and stores it in the provided unique_...
const ClusterTPAssociation * clusterToTPMap_
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
#define LogTrace(id)
double getDoubleCount(const TrackerHitAssociator &hitAssociator, iter begin, iter end, TrackingParticleRef associatedTrackingParticle) const
This method was copied almost verbatim from the standard TrackAssociatorByHits.
range recHits() const
unsigned int nHits() const
double weightedNumberOfTrackClusters(const reco::Track &track, const TrackerHitAssociator &) const
std::unique_ptr< const TrackerHitAssociator > hitAssociator_
template<class T_TrackCollection , class T_TrackingParticleCollection , class T_hitOrClusterAssociator >
reco::RecoToSimCollection QuickTrackAssociatorByHitsImpl::associateRecoToSimImplementation ( const T_TrackCollection &  trackCollection,
const T_TrackingParticleCollection &  trackingParticleCollection,
const TrackingParticleRefKeySet trackingParticleKeys,
T_hitOrClusterAssociator  hitOrClusterAssociator 
) const
private

The method that does the work for both overloads of associateRecoToSim.

Parts that actually rely on the type of the collections are delegated out to overloaded functions in the unnamed namespace of the .cc file. Parts that rely on the type of T_hitOrClusterAssociator are delegated out to overloaded methods.

Definition at line 170 of file QuickTrackAssociatorByHitsImpl.cc.

References funct::abs(), absoluteNumberOfHits_, associateTrack(), cutRecoToSim_, getDoubleCount(), mps_fire::i, edm::AssociationMap< Tag >::insert(), reco::TrackBase::numberOfValidHits(), edm::AssociationMap< Tag >::post_insert(), productGetter_, btvTracks_cfi::quality, reco::Track::recHitsBegin(), reco::Track::recHitsEnd(), threeHitTracksAreSpecial_, and weightedNumberOfTrackClusters().

Referenced by associateRecoToSim().

171 {
173  if(::collectionSize(trackingParticleCollection) == 0)
174  return returnValue;
175 
176  checkClusterMapProductID(hitOrClusterAssociator, trackingParticleCollection);
177 
178  size_t collectionSize=::collectionSize(trackCollection); // Delegate away type specific part
179 
180  for( size_t i=0; i < collectionSize; ++i )
181  {
182  const reco::Track* pTrack=::getTrackAt(trackCollection,i); // Get a normal pointer for ease of use. This part is type specific so delegate.
183 
184  // The return of this function has first as the index and second as the number of associated hits
185  std::vector < std::pair<edm::Ref<TrackingParticleCollection>,double> > trackingParticleQualityPairs=associateTrack( hitOrClusterAssociator, trackingParticleCollection, trackingParticleKeys, pTrack->recHitsBegin(), pTrack->recHitsEnd() );
186 
187  // int nt = 0;
188  for( auto iTrackingParticleQualityPair=
189  trackingParticleQualityPairs.begin(); iTrackingParticleQualityPair != trackingParticleQualityPairs.end();
190  ++iTrackingParticleQualityPair )
191  {
192  const edm::Ref<TrackingParticleCollection>& trackingParticleRef=iTrackingParticleQualityPair->first;
193  double numberOfSharedClusters=iTrackingParticleQualityPair->second;
194  double numberOfValidTrackClusters=weightedNumberOfTrackClusters(*pTrack, hitOrClusterAssociator);
195 
196  if( numberOfSharedClusters == 0.0 ) continue; // No point in continuing if there was no association
197 
198  //if electron subtract double counting
199  if( abs( trackingParticleRef->pdgId() ) == 11 && (trackingParticleRef->g4Track_end() - trackingParticleRef->g4Track_begin()) > 1 )
200  {
201  numberOfSharedClusters-=getDoubleCount( hitOrClusterAssociator, pTrack->recHitsBegin(), pTrack->recHitsEnd(), trackingParticleRef );
202  }
203 
204  double quality;
205  if( absoluteNumberOfHits_ ) quality = numberOfSharedClusters;
206  else if( numberOfValidTrackClusters != 0.0 ) quality = numberOfSharedClusters / numberOfValidTrackClusters;
207  else quality=0;
208  if( quality > cutRecoToSim_ && !(threeHitTracksAreSpecial_ && pTrack->numberOfValidHits() == 3 && numberOfSharedClusters < 3.0) )
209  {
210  // Getting the RefToBase is dependent on the type of trackCollection, so delegate that to an overload.
211  returnValue.insert( ::getRefToTrackAt(trackCollection,i), std::make_pair( trackingParticleRef, quality ) );
212  }
213  }
214  }
215  returnValue.post_insert();
216  return returnValue;
217 }
std::vector< std::pair< edm::Ref< TrackingParticleCollection >, double > > associateTrack(const TrackerHitAssociator &hitAssociator, const T_TPCollection &trackingParticles, const TrackingParticleRefKeySet *trackingParticleKeys, iter begin, iter end) const
Returns the TrackingParticle that has the most associated hits to the given track.
edm::EDProductGetter const * productGetter_
creates either a ClusterTPAssociation OR a TrackerHitAssociator and stores it in the provided unique_...
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
unsigned short numberOfValidHits() const
number of valid hits found
Definition: TrackBase.h:820
trackingRecHit_iterator recHitsBegin() const
Iterator to first hit on the track.
Definition: Track.h:104
double getDoubleCount(const TrackerHitAssociator &hitAssociator, iter begin, iter end, TrackingParticleRef associatedTrackingParticle) const
This method was copied almost verbatim from the standard TrackAssociatorByHits.
double weightedNumberOfTrackClusters(const reco::Track &track, const TrackerHitAssociator &) const
trackingRecHit_iterator recHitsEnd() const
Iterator to last hit on the track.
Definition: Track.h:109
reco::SimToRecoCollection QuickTrackAssociatorByHitsImpl::associateSimToReco ( const edm::Handle< edm::View< reco::Track > > &  tCH,
const edm::Handle< TrackingParticleCollection > &  tPCH 
) const
overridevirtual

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

Reimplemented from reco::TrackToTrackingParticleAssociatorBaseImpl.

Definition at line 136 of file QuickTrackAssociatorByHitsImpl.cc.

References associateSimToRecoImplementation(), clusterToTPMap_, and hitAssociator_.

138 {
139  // Only pass the one that was successfully created to the templated method.
140  if( not clusterToTPMap_ ) return associateSimToRecoImplementation( trackCollectionHandle, trackingParticleCollectionHandle, nullptr, *hitAssociator_ );
141  else return associateSimToRecoImplementation( trackCollectionHandle, trackingParticleCollectionHandle, nullptr, *clusterToTPMap_ );
142 }
const ClusterTPAssociation * clusterToTPMap_
reco::SimToRecoCollection associateSimToRecoImplementation(const T_TrackCollection &trackCollection, const T_TrackingParticleCollection &trackingParticleCollection, const TrackingParticleRefKeySet *trackingParticleKeys, T_hitOrClusterAssociator hitOrClusterAssociator) const
The method that does the work for both overloads of associateSimToReco.
std::unique_ptr< const TrackerHitAssociator > hitAssociator_
reco::SimToRecoCollection QuickTrackAssociatorByHitsImpl::associateSimToReco ( const edm::RefToBaseVector< reco::Track > &  tc,
const edm::RefVector< TrackingParticleCollection > &  tpc 
) const
overridevirtual

Association Sim To Reco with Collections.

Implements reco::TrackToTrackingParticleAssociatorBaseImpl.

Definition at line 156 of file QuickTrackAssociatorByHitsImpl.cc.

References associateSimToRecoImplementation(), clusterToTPMap_, and hitAssociator_.

158 {
159  // Only pass the one that was successfully created to the templated method.
161  else {
163  fillKeys(tpKeys, trackingParticleCollection);
165  }
166 }
const ClusterTPAssociation * clusterToTPMap_
reco::SimToRecoCollection associateSimToRecoImplementation(const T_TrackCollection &trackCollection, const T_TrackingParticleCollection &trackingParticleCollection, const TrackingParticleRefKeySet *trackingParticleKeys, T_hitOrClusterAssociator hitOrClusterAssociator) const
The method that does the work for both overloads of associateSimToReco.
edm::IndexSet TrackingParticleRefKeySet
Set for TrackingParticleRef keys.
std::unique_ptr< const TrackerHitAssociator > hitAssociator_
reco::SimToRecoCollectionSeed QuickTrackAssociatorByHitsImpl::associateSimToReco ( const edm::Handle< edm::View< TrajectorySeed > > &  pSeedCollectionHandle_,
const edm::Handle< TrackingParticleCollection > &  trackingParticleCollectionHandle 
) const
overridevirtual

Reimplemented from reco::TrackToTrackingParticleAssociatorBaseImpl.

Definition at line 661 of file QuickTrackAssociatorByHitsImpl.cc.

References funct::abs(), absoluteNumberOfHits_, associateTrack(), clusterToTPMap_, denomreco, denomsim, getDoubleCount(), hitAssociator_, mps_fire::i, edm::AssociationMap< Tag >::insert(), LogTrace, edm::AssociationMap< Tag >::post_insert(), productGetter_, puritySimToReco_, btvTracks_cfi::quality, qualitySimToReco_, TrajectorySeed::recHits(), simToRecoDenominator_, edm::AssociationMap< Tag >::size(), threeHitTracksAreSpecial_, and weightedNumberOfTrackClusters().

663 {
664 
665  edm::LogVerbatim( "TrackAssociator" ) << "Starting TrackAssociatorByHitsImpl::associateSimToReco - #seeds=" << pSeedCollectionHandle_->size()
666  << " #TPs=" << trackingParticleCollectionHandle->size();
667 
669  if(trackingParticleCollectionHandle->empty())
670  return returnValue;
671 
672  if(clusterToTPMap_) {
673  checkClusterMapProductID(*clusterToTPMap_, trackingParticleCollectionHandle);
674  }
675 
676  size_t collectionSize=pSeedCollectionHandle_->size();
677 
678  for( size_t i=0; i < collectionSize; ++i )
679  {
680  const TrajectorySeed* pSeed= &( *pSeedCollectionHandle_)[i];
681 
682  // The return of this function has first as an edm:Ref to the associated TrackingParticle, and second as the number of associated hits
683  std::vector < std::pair<edm::Ref<TrackingParticleCollection>,double> > trackingParticleQualityPairs=
684  (clusterToTPMap_) ? associateTrack( *clusterToTPMap_, trackingParticleCollectionHandle, nullptr, pSeed->recHits().first, pSeed->recHits().second ) : associateTrack( *hitAssociator_, trackingParticleCollectionHandle, nullptr, pSeed->recHits().first, pSeed->recHits().second );
685  for( auto iTrackingParticleQualityPair=
686  trackingParticleQualityPairs.begin(); iTrackingParticleQualityPair != trackingParticleQualityPairs.end();
687  ++iTrackingParticleQualityPair )
688  {
689  const edm::Ref<TrackingParticleCollection>& trackingParticleRef=iTrackingParticleQualityPair->first;
690  double numberOfSharedClusters=iTrackingParticleQualityPair->second;
691  double numberOfValidTrackClusters = clusterToTPMap_ ? weightedNumberOfTrackClusters(*pSeed, *clusterToTPMap_) :weightedNumberOfTrackClusters(*pSeed, *hitAssociator_);
692  size_t numberOfSimulatedHits=0; // Set a few lines below, but only if required.
693 
694  if( numberOfSharedClusters == 0.0 ) continue; // No point in continuing if there was no association
695 
696  //if electron subtract double counting
697  if( abs( trackingParticleRef->pdgId() ) == 11 && (trackingParticleRef->g4Track_end() - trackingParticleRef->g4Track_begin()) > 1 )
698  {
699  if( clusterToTPMap_ ) numberOfSharedClusters-=getDoubleCount( *clusterToTPMap_, pSeed->recHits().first, pSeed->recHits().second, trackingParticleRef );
700  else numberOfSharedClusters-=getDoubleCount( *hitAssociator_, pSeed->recHits().first, pSeed->recHits().second, trackingParticleRef );
701  }
702 
703  if( simToRecoDenominator_ == denomsim || (numberOfSharedClusters < 3.0 && threeHitTracksAreSpecial_) ) // the numberOfSimulatedHits is not always required, so can skip counting in some circumstances
704  {
705  // Note that in the standard TrackAssociatorByHits, all of the hits in associatedTrackingParticleHits are checked for
706  // various things. I'm not sure what these checks are for but they depend on the UseGrouping and UseSplitting settings.
707  // This associator works as though both UseGrouping and UseSplitting were set to true, i.e. just counts the number of
708  // hits in the tracker.
709  numberOfSimulatedHits=trackingParticleRef->numberOfTrackerHits();
710  }
711 
712  double purity = numberOfSharedClusters / numberOfValidTrackClusters;
713  double quality;
714  if( absoluteNumberOfHits_ ) quality = numberOfSharedClusters;
715  else if( simToRecoDenominator_ == denomsim && numberOfSimulatedHits != 0 ) quality= numberOfSharedClusters
716  / static_cast<double>( numberOfSimulatedHits );
717  else if( simToRecoDenominator_ == denomreco && numberOfValidTrackClusters != 0.0 ) quality=purity;
718  else quality=0;
719 
720  if( quality > qualitySimToReco_ && !(threeHitTracksAreSpecial_ && numberOfSimulatedHits == 3 && numberOfSharedClusters < 3.0)
721  && (absoluteNumberOfHits_ || (purity > puritySimToReco_)) )
722  {
723  returnValue.insert( trackingParticleRef, std::make_pair( edm::RefToBase < TrajectorySeed > (pSeedCollectionHandle_, i), quality ) );
724  }
725  }
726  }
727 
728  LogTrace("TrackAssociator") << "% of Assoc TPs=" << ((double)returnValue.size())/((double)trackingParticleCollectionHandle->size());
729  returnValue.post_insert();
730  return returnValue;
731 }
std::vector< std::pair< edm::Ref< TrackingParticleCollection >, double > > associateTrack(const TrackerHitAssociator &hitAssociator, const T_TPCollection &trackingParticles, const TrackingParticleRefKeySet *trackingParticleKeys, iter begin, iter end) const
Returns the TrackingParticle that has the most associated hits to the given track.
edm::EDProductGetter const * productGetter_
creates either a ClusterTPAssociation OR a TrackerHitAssociator and stores it in the provided unique_...
const ClusterTPAssociation * clusterToTPMap_
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
#define LogTrace(id)
double getDoubleCount(const TrackerHitAssociator &hitAssociator, iter begin, iter end, TrackingParticleRef associatedTrackingParticle) const
This method was copied almost verbatim from the standard TrackAssociatorByHits.
range recHits() const
double weightedNumberOfTrackClusters(const reco::Track &track, const TrackerHitAssociator &) const
std::unique_ptr< const TrackerHitAssociator > hitAssociator_
template<class T_TrackCollection , class T_TrackingParticleCollection , class T_hitOrClusterAssociator >
reco::SimToRecoCollection QuickTrackAssociatorByHitsImpl::associateSimToRecoImplementation ( const T_TrackCollection &  trackCollection,
const T_TrackingParticleCollection &  trackingParticleCollection,
const TrackingParticleRefKeySet trackingParticleKeys,
T_hitOrClusterAssociator  hitOrClusterAssociator 
) const
private

The method that does the work for both overloads of associateSimToReco.

Parts that actually rely on the type of the collections are delegated out to overloaded functions in the unnamed namespace of the .cc file. Parts that rely on the type of T_hitOrClusterAssociator are delegated out to overloaded methods.

Definition at line 220 of file QuickTrackAssociatorByHitsImpl.cc.

References funct::abs(), absoluteNumberOfHits_, associateTrack(), denomreco, denomsim, getDoubleCount(), mps_fire::i, edm::AssociationMap< Tag >::insert(), edm::AssociationMap< Tag >::post_insert(), productGetter_, puritySimToReco_, btvTracks_cfi::quality, qualitySimToReco_, reco::Track::recHitsBegin(), reco::Track::recHitsEnd(), simToRecoDenominator_, threeHitTracksAreSpecial_, and weightedNumberOfTrackClusters().

Referenced by associateSimToReco().

221 {
223  if(::collectionSize(trackingParticleCollection) == 0)
224  return returnValue;
225 
226  checkClusterMapProductID(hitOrClusterAssociator, trackingParticleCollection);
227 
228  size_t collectionSize=::collectionSize(trackCollection); // Delegate away type specific part
229 
230  for( size_t i=0; i<collectionSize; ++i )
231  {
232  const reco::Track* pTrack=::getTrackAt(trackCollection,i); // Get a normal pointer for ease of use. This part is type specific so delegate.
233 
234  // The return of this function has first as an edm:Ref to the associated TrackingParticle, and second as the number of associated hits
235  std::vector < std::pair<edm::Ref<TrackingParticleCollection>,double> > trackingParticleQualityPairs=associateTrack( hitOrClusterAssociator, trackingParticleCollection, trackingParticleKeys, pTrack->recHitsBegin(), pTrack->recHitsEnd() );
236 
237  // int nt = 0;
238  for( auto iTrackingParticleQualityPair=trackingParticleQualityPairs.begin();
239  iTrackingParticleQualityPair!=trackingParticleQualityPairs.end(); ++iTrackingParticleQualityPair )
240  {
241  const edm::Ref<TrackingParticleCollection>& trackingParticleRef=iTrackingParticleQualityPair->first;
242  double numberOfSharedClusters=iTrackingParticleQualityPair->second;
243  double numberOfValidTrackClusters=weightedNumberOfTrackClusters(*pTrack, hitOrClusterAssociator);
244  size_t numberOfSimulatedHits=0; // Set a few lines below, but only if required.
245 
246  if( numberOfSharedClusters==0.0 ) continue; // No point in continuing if there was no association
247 
248  if( simToRecoDenominator_==denomsim || (numberOfSharedClusters<3.0 && threeHitTracksAreSpecial_) ) // the numberOfSimulatedHits is not always required, so can skip counting in some circumstances
249  {
250  // Note that in the standard TrackAssociatorByHits, all of the hits in associatedTrackingParticleHits are checked for
251  // various things. I'm not sure what these checks are for but they depend on the UseGrouping and UseSplitting settings.
252  // This associator works as though both UseGrouping and UseSplitting were set to true, i.e. just counts the number of
253  // hits in the tracker.
254  numberOfSimulatedHits=trackingParticleRef->numberOfTrackerHits();
255  }
256 
257  //if electron subtract double counting
258  if (abs(trackingParticleRef->pdgId())==11 && (trackingParticleRef->g4Track_end() - trackingParticleRef->g4Track_begin()) > 1 )
259  {
260  numberOfSharedClusters -= getDoubleCount( hitOrClusterAssociator, pTrack->recHitsBegin(), pTrack->recHitsEnd(), trackingParticleRef );
261  }
262 
263  double purity = numberOfSharedClusters/numberOfValidTrackClusters;
264  double quality;
265  if( absoluteNumberOfHits_ ) quality = numberOfSharedClusters;
266  else if( simToRecoDenominator_==denomsim && numberOfSimulatedHits != 0 ) quality = numberOfSharedClusters/static_cast<double>(numberOfSimulatedHits);
267  else if( simToRecoDenominator_==denomreco && numberOfValidTrackClusters != 0 ) quality=purity;
268  else quality=0;
269 
270  if( quality>qualitySimToReco_ && !( threeHitTracksAreSpecial_ && numberOfSimulatedHits==3 && numberOfSharedClusters<3.0 ) && ( absoluteNumberOfHits_ || (purity>puritySimToReco_) ) )
271  {
272  // Getting the RefToBase is dependent on the type of trackCollection, so delegate that to an overload.
273  returnValue.insert( trackingParticleRef, std::make_pair( ::getRefToTrackAt(trackCollection,i), quality ) );
274  }
275  }
276  }
277  returnValue.post_insert();
278  return returnValue;
279 
280 }
std::vector< std::pair< edm::Ref< TrackingParticleCollection >, double > > associateTrack(const TrackerHitAssociator &hitAssociator, const T_TPCollection &trackingParticles, const TrackingParticleRefKeySet *trackingParticleKeys, iter begin, iter end) const
Returns the TrackingParticle that has the most associated hits to the given track.
edm::EDProductGetter const * productGetter_
creates either a ClusterTPAssociation OR a TrackerHitAssociator and stores it in the provided unique_...
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
trackingRecHit_iterator recHitsBegin() const
Iterator to first hit on the track.
Definition: Track.h:104
double getDoubleCount(const TrackerHitAssociator &hitAssociator, iter begin, iter end, TrackingParticleRef associatedTrackingParticle) const
This method was copied almost verbatim from the standard TrackAssociatorByHits.
double weightedNumberOfTrackClusters(const reco::Track &track, const TrackerHitAssociator &) const
trackingRecHit_iterator recHitsEnd() const
Iterator to last hit on the track.
Definition: Track.h:109
template<typename T_TPCollection , typename iter >
std::vector< std::pair< edm::Ref< TrackingParticleCollection >, double > > QuickTrackAssociatorByHitsImpl::associateTrack ( const TrackerHitAssociator hitAssociator,
const T_TPCollection &  trackingParticles,
const TrackingParticleRefKeySet trackingParticleKeys,
iter  begin,
iter  end 
) const
private

Returns the TrackingParticle that has the most associated hits to the given track.

Return value is a vector of pairs, where first is an edm::Ref to the associated TrackingParticle, and second is the number of associated hits.

Definition at line 282 of file QuickTrackAssociatorByHitsImpl.cc.

References getAllSimTrackIdentifiers(), mps_fire::i, and trackingParticleContainsIdentifier().

Referenced by associateRecoToSim(), associateRecoToSimImplementation(), associateSimToReco(), and associateSimToRecoImplementation().

283 {
284  // The pairs in this vector have a Ref to the associated TrackingParticle as "first" and the weighted number of associated hits as "second"
285  std::vector< std::pair<edm::Ref<TrackingParticleCollection>,double> > returnValue;
286 
287  // The pairs in this vector have first as the sim track identifiers, and second the number of reco hits associated to that sim track.
288  // Most reco hits will probably have come from the same sim track, so the number of entries in this vector should be fewer than the
289  // number of reco hits. The pair::second entries should add up to the total number of reco hits though.
290  std::vector< std::pair<SimTrackIdentifiers,double> > hitIdentifiers=getAllSimTrackIdentifiers( hitAssociator, begin, end );
291 
292  // Loop over the TrackingParticles
293  size_t collectionSize=::collectionSize(trackingParticles);
294 
295  for( size_t i=0; i<collectionSize; ++i )
296  {
297  const TrackingParticle* pTrackingParticle=getTrackingParticleAt( trackingParticles, i );
298 
299  // Historically there was a requirement that pTrackingParticle->numberOfHits() > 0
300  // However, in TrackingTruthAccumulator, the numberOfHits is calculated from a subset
301  // of the SimHits of the SimTracks of a TrackingParticle (essentially limiting the
302  // processType and particleType to those of the "first" hit, and particleType to the pdgId of the SimTrack).
303  // But, here the association between tracks and TrackingParticles is done with *all* the hits of
304  // TrackingParticle, so we should not rely on the numberOfHits() calculated with a subset of SimHits.
305 
306  double numberOfAssociatedHits=0;
307  // Loop over all of the sim track identifiers and see if any of them are part of this TrackingParticle. If they are, add
308  // the number of reco hits associated to that sim track to the total number of associated hits.
309  for( const auto& identifierCountPair: hitIdentifiers)
310  {
311  if( trackingParticleContainsIdentifier( pTrackingParticle, identifierCountPair.first ) ) numberOfAssociatedHits+=identifierCountPair.second;
312  }
313 
314  if( numberOfAssociatedHits>0 )
315  {
316  returnValue.push_back( std::make_pair( getRefToTrackingParticleAt(trackingParticles,i), numberOfAssociatedHits ) );
317  }
318  }
319 
320  return returnValue;
321 }
#define end
Definition: vmac.h:37
#define begin
Definition: vmac.h:30
Monte Carlo truth information used for tracking validation.
std::vector< std::pair< SimTrackIdentifiers, double > > getAllSimTrackIdentifiers(const TrackerHitAssociator &hitAssociator, iter begin, iter end) const
Returns a vector of pairs where first is a SimTrackIdentifiers (see typedef above) and second is the ...
bool trackingParticleContainsIdentifier(const TrackingParticle *pTrackingParticle, const SimTrackIdentifiers &identifier) const
Returns true if the supplied TrackingParticle has the supplied g4 track identifiers.
template<typename T_TPCollection , typename iter >
std::vector< std::pair< edm::Ref< TrackingParticleCollection >, double > > QuickTrackAssociatorByHitsImpl::associateTrack ( const ClusterTPAssociation clusterToTPMap,
const T_TPCollection &  trackingParticles,
const TrackingParticleRefKeySet trackingParticleKeys,
iter  begin,
iter  end 
) const
private

Returns the TrackingParticle that has the most associated hits to the given track.

See the notes for the other overload for the return type.

Note that the trackingParticles parameter is not actually required since all the information is in clusterToTPMap, but the method signature has to match the other overload because it is called from a templated method.

Definition at line 323 of file QuickTrackAssociatorByHitsImpl.cc.

References ClusterTPAssociation::empty(), ClusterTPAssociation::equal_range(), getMatchedClusters(), edm::IndexSet::has(), edm::Ref< C, T, F >::key(), and pixelHitWeight_.

324 {
325  // Note that the trackingParticles parameter is not actually required since all the information is in clusterToTPMap,
326  // but the method signature has to match the other overload because it is called from a templated method.
327 
328  // Note further, that we can't completely ignore the
329  // trackingParticles parameter, in case it is a subset of those
330  // TrackingParticles used to construct clusterToTPMap (via the
331  // TrackingParticleRefVector overloads). The trackingParticles
332  // parameter is still ignored since looping over it on every call
333  // would be expensive, but the keys of the TrackingParticleRefs are
334  // cached to an IndexSet (trackingParticleKeys) which is used
335  // as a fast search structure.
336 
337  // The pairs in this vector have a Ref to the associated TrackingParticle as "first" and the weighted number of associated clusters as "second"
338  // Note: typedef edm::Ref<TrackingParticleCollection> TrackingParticleRef;
339  std::vector < std::pair<edm::Ref<TrackingParticleCollection>,double> > returnValue;
340  if( clusterToTPMap.empty() ) return returnValue;
341 
342  // The pairs in this vector have first as the TP, and second the number of reco clusters associated to that TP.
343  // Most reco clusters will probably have come from the same sim track (i.e TP), so the number of entries in this
344  // vector should be fewer than the number of clusters. The pair::second entries should add up to the total
345  // number of reco clusters though.
346  std::vector<OmniClusterRef> oClusters=getMatchedClusters( begin, end );
347 
348  std::map < TrackingParticleRef, double > lmap;
349  for( std::vector<OmniClusterRef>::const_iterator it=oClusters.begin(); it != oClusters.end(); ++it )
350  {
351  auto range = clusterToTPMap.equal_range(*it);
352  const double weight = it->isPixel() ? pixelHitWeight_ : 1.0;
353  if( range.first != range.second )
354  {
355  for( auto ip=range.first; ip != range.second; ++ip )
356  {
357 
358  const TrackingParticleRef trackingParticle=(ip->second);
359 
360  if(trackingParticleKeys && !trackingParticleKeys->has(trackingParticle.key()))
361  continue;
362 
363  // Historically there was a requirement that pTrackingParticle->numberOfHits() > 0
364  // However, in TrackingTruthAccumulator, the numberOfHits is calculated from a subset
365  // of the SimHits of the SimTracks of a TrackingParticle (essentially limiting the
366  // processType and particleType to those of the "first" hit, and particleType to the pdgId of the SimTrack).
367  // But, here the association between tracks and TrackingParticles is done with *all* the hits of
368  // TrackingParticle, so we should not rely on the numberOfHits() calculated with a subset of SimHits.
369 
370  /* Alternative implementation to avoid the use of lmap... memory slightly improved but slightly slower...
371  std::pair<edm::Ref<TrackingParticleCollection>,size_t> tpIntPair(trackingParticle, 1);
372  auto tp_range = std::equal_range(returnValue.begin(), returnValue.end(), tpIntPair, tpIntPairGreater);
373  if ((tp_range.second-tp_range.first)>1) {
374  edm::LogError("TrackAssociator") << ">>> Error in counting TPs!" << " file: " << __FILE__ << " line: " << __LINE__;
375  }
376  if(tp_range.first != tp_range.second) {
377  tp_range.first->second++;
378  } else {
379  returnValue.push_back(tpIntPair);
380  std::sort(returnValue.begin(), returnValue.end(), tpIntPairGreater);
381  }
382  */
383  auto jpos=lmap.find( trackingParticle );
384  if( jpos != lmap.end() ) jpos->second += weight;
385  else lmap.insert( std::make_pair( trackingParticle, weight ) );
386  }
387  }
388  }
389  // now copy the map to returnValue
390  for( auto ip=lmap.begin(); ip != lmap.end(); ++ip )
391  {
392  returnValue.push_back( std::make_pair( ip->first, ip->second ) );
393  }
394  return returnValue;
395 }
Definition: weight.py:1
key_type key() const
Accessor for product key.
Definition: Ref.h:265
range equal_range(const OmniClusterRef &key) const
#define end
Definition: vmac.h:37
#define begin
Definition: vmac.h:30
std::vector< OmniClusterRef > getMatchedClusters(iter begin, iter end) const
template<typename iter >
std::vector< std::pair< QuickTrackAssociatorByHitsImpl::SimTrackIdentifiers, double > > QuickTrackAssociatorByHitsImpl::getAllSimTrackIdentifiers ( const TrackerHitAssociator hitAssociator,
iter  begin,
iter  end 
) const
private

Returns a vector of pairs where first is a SimTrackIdentifiers (see typedef above) and second is the number of hits that came from that sim track.

This is used so that the TrackingParticle collection only has to be looped over once to search for each sim track, rather than once per hit. E.g. If all the hits in the reco track come from the same sim track, then there will only be one entry with second as the number of hits in the track.

Definition at line 453 of file QuickTrackAssociatorByHitsImpl.cc.

References TrackerHitAssociator::associateHitId(), end, TrackingRecHit::geographicalId(), getHitFromIter(), PixelSubdetector::PixelBarrel, PixelSubdetector::PixelEndcap, pixelHitWeight_, DetId::subdetId(), and mps_merge::weight.

Referenced by associateTrack().

454 {
455  // The pairs in this vector have first as the sim track identifiers, and second the number of reco hits associated to that sim track.
456  std::vector < std::pair<SimTrackIdentifiers,double> > returnValue;
457 
458  std::vector<SimTrackIdentifiers> simTrackIdentifiers;
459  // Loop over all of the rec hits in the track
460  //iter tRHIterBeginEnd = getTRHIterBeginEnd( pTrack );
461  for( iter iRecHit=begin; iRecHit != end; ++iRecHit )
462  {
463  if( getHitFromIter( iRecHit )->isValid() )
464  {
465  simTrackIdentifiers.clear();
466 
467  // Get the identifiers for the sim track that this hit came from. There should only be one entry unless clusters
468  // have merged (as far as I know).
469  hitAssociator.associateHitId( *(getHitFromIter( iRecHit )), simTrackIdentifiers ); // This call fills simTrackIdentifiers
470 
471  const auto subdetId = getHitFromIter(iRecHit)->geographicalId().subdetId();
472  const double weight = (subdetId == PixelSubdetector::PixelBarrel || subdetId == PixelSubdetector::PixelEndcap) ? pixelHitWeight_ : 1.0;
473 
474  // Loop over each identifier, and add it to the return value only if it's not already in there
475  for( std::vector<SimTrackIdentifiers>::const_iterator iIdentifier=simTrackIdentifiers.begin(); iIdentifier != simTrackIdentifiers.end();
476  ++iIdentifier )
477  {
478  std::vector<std::pair<SimTrackIdentifiers,double> >::iterator iIdentifierCountPair;
479  for(auto iIdentifierCountPair=returnValue.begin(); iIdentifierCountPair != returnValue.end(); ++iIdentifierCountPair )
480  {
481  if( iIdentifierCountPair->first.first == iIdentifier->first && iIdentifierCountPair->first.second == iIdentifier->second )
482  {
483  // This sim track identifier is already in the list, so increment the count of how many hits it relates to.
484  iIdentifierCountPair->second += weight;
485  break;
486  }
487  }
488  if( iIdentifierCountPair == returnValue.end() ) returnValue.push_back( std::make_pair( *iIdentifier, 1.0 ) );
489  // This identifier wasn't found, so add it
490  }
491  }
492  }
493  return returnValue;
494 }
Definition: weight.py:1
const TrackingRecHit * getHitFromIter(trackingRecHit_iterator iter) const
#define end
Definition: vmac.h:37
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:37
std::vector< SimHitIdpr > associateHitId(const TrackingRecHit &thit) const
#define begin
Definition: vmac.h:30
DetId geographicalId() const
template<typename iter >
double QuickTrackAssociatorByHitsImpl::getDoubleCount ( const TrackerHitAssociator hitAssociator,
iter  begin,
iter  end,
TrackingParticleRef  associatedTrackingParticle 
) const
private

This method was copied almost verbatim from the standard TrackAssociatorByHits.

Modified 01/May/2014 to take the TrackerHitAssociator as a parameter rather than using a member.

Definition at line 514 of file QuickTrackAssociatorByHitsImpl.cc.

References TrackerHitAssociator::associateHitId(), spr::find(), TrackingRecHit::geographicalId(), getHitFromIter(), PixelSubdetector::PixelBarrel, PixelSubdetector::PixelEndcap, pixelHitWeight_, and DetId::subdetId().

Referenced by associateRecoToSim(), associateRecoToSimImplementation(), associateSimToReco(), and associateSimToRecoImplementation().

515 {
516  // This method is largely copied from the standard TrackAssociatorByHits. Once I've tested how much difference
517  // it makes I'll go through and comment it properly.
518 
519  // FIXME: It may be that this piece is not fully correct for
520  // counting how many times a single *cluster* is matched to many
521  // SimTracks of a single TrackingParticle (see comments in
522  // getDoubleCount(ClusterTPAssociation) overload). To be verified
523  // some time.
524 
525  double doubleCount=0.0;
526  std::vector < SimHitIdpr > SimTrackIdsDC;
527 
528  for( iter iHit=startIterator; iHit != endIterator; iHit++ )
529  {
530  int idcount=0;
531 
532  SimTrackIdsDC.clear();
533  hitAssociator.associateHitId( *(getHitFromIter( iHit )), SimTrackIdsDC );
534  if( SimTrackIdsDC.size() > 1 )
535  {
536  for( TrackingParticle::g4t_iterator g4T=associatedTrackingParticle->g4Track_begin(); g4T != associatedTrackingParticle->g4Track_end();
537  ++g4T )
538  {
539  if( find( SimTrackIdsDC.begin(), SimTrackIdsDC.end(), SimHitIdpr( ( *g4T).trackId(), SimTrackIdsDC.begin()->second ) )
540  != SimTrackIdsDC.end() )
541  {
542  idcount++;
543  }
544  }
545  }
546  if( idcount > 1 ) {
547  const auto subdetId = getHitFromIter(iHit)->geographicalId().subdetId();
548  const double weight = (subdetId == PixelSubdetector::PixelBarrel || subdetId == PixelSubdetector::PixelEndcap) ? pixelHitWeight_ : 1.0;
549  doubleCount += weight*(idcount - 1);
550  }
551  }
552 
553  return doubleCount;
554 }
Definition: weight.py:1
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:20
const TrackingRecHit * getHitFromIter(trackingRecHit_iterator iter) const
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:37
std::vector< SimTrack >::const_iterator g4t_iterator
std::pair< uint32_t, EncodedEventId > SimHitIdpr
std::vector< SimHitIdpr > associateHitId(const TrackingRecHit &thit) const
DetId geographicalId() const
template<typename iter >
double QuickTrackAssociatorByHitsImpl::getDoubleCount ( const ClusterTPAssociation clusterToTPList,
iter  begin,
iter  end,
TrackingParticleRef  associatedTrackingParticle 
) const
private

Overload for when using cluster to TrackingParticle association list.

Definition at line 556 of file QuickTrackAssociatorByHitsImpl.cc.

References ClusterTPAssociation::equal_range(), TrackingRecHit::geographicalId(), getHitFromIter(), getMatchedClusters(), PixelSubdetector::PixelBarrel, PixelSubdetector::PixelEndcap, pixelHitWeight_, and DetId::subdetId().

557 {
558  // This code here was written by Subir Sarkar. I'm just splitting it off into a
559  // separate method. - Grimes 01/May/2014
560 
561  // The point here is that the electron TrackingParticles may contain
562  // multiple SimTracks (from the bremsstrahling), and (historically)
563  // the each matched hit/cluster has been multiplied by "how many
564  // SimTracks from the TrackingParticle" it contains charge from.
565  // Here the amount of this double counting is calculated, so that it
566  // can be subtracted by the calling code.
567  //
568  // Note that recently (hence "historically" in the paragraph above)
569  // the ClusterTPAssociationProducer was changed to remove the
570  // duplicate cluster->TP associations (hence making this function
571  // obsolete), but there is more recent proof that there is some
572  // duplication left (to be investigated).
573 
574  double doubleCount=0;
575  std::vector < SimHitIdpr > SimTrackIdsDC;
576 
577  for( iter iHit=startIterator; iHit != endIterator; iHit++ )
578  {
579  std::vector < OmniClusterRef > oClusters=getMatchedClusters( iHit, iHit + 1 ); //only for the cluster being checked
580  for( std::vector<OmniClusterRef>::const_iterator it=oClusters.begin(); it != oClusters.end(); ++it )
581  {
582  int idcount=0;
583 
584  auto range = clusterToTPList.equal_range(*it);
585  if( range.first != range.second )
586  {
587  for( auto ip=range.first; ip != range.second; ++ip )
588  {
589  const TrackingParticleRef trackingParticle=(ip->second);
590  if( associatedTrackingParticle == trackingParticle )
591  {
592  idcount++;
593  }
594  }
595  }
596 
597  if( idcount > 1 ) {
598  const auto subdetId = getHitFromIter(iHit)->geographicalId().subdetId();
599  const double weight = (subdetId == PixelSubdetector::PixelBarrel || subdetId == PixelSubdetector::PixelEndcap) ? pixelHitWeight_ : 1.0;
600  doubleCount += weight*(idcount - 1);
601  }
602  }
603  }
604 
605  return doubleCount;
606 }
Definition: weight.py:1
const TrackingRecHit * getHitFromIter(trackingRecHit_iterator iter) const
range equal_range(const OmniClusterRef &key) const
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:37
DetId geographicalId() const
std::vector< OmniClusterRef > getMatchedClusters(iter begin, iter end) const
const TrackingRecHit* QuickTrackAssociatorByHitsImpl::getHitFromIter ( trackingRecHit_iterator  iter) const
inlineprivate

Definition at line 166 of file QuickTrackAssociatorByHitsImpl.h.

Referenced by getAllSimTrackIdentifiers(), getDoubleCount(), getMatchedClusters(), and weightedNumberOfTrackClusters().

166  {
167  return &(**iter);
168  }
const TrackingRecHit* QuickTrackAssociatorByHitsImpl::getHitFromIter ( TrackingRecHitCollection::const_iterator  iter) const
inlineprivate

Definition at line 170 of file QuickTrackAssociatorByHitsImpl.h.

References SurveyInfoScenario_cff::seed, and HiIsolationCommonParameters_cff::track.

170  {
171  return &(*iter);
172  }
template<typename iter >
std::vector< OmniClusterRef > QuickTrackAssociatorByHitsImpl::getMatchedClusters ( iter  begin,
iter  end 
) const
private

Definition at line 397 of file QuickTrackAssociatorByHitsImpl.cc.

References SiStripRecHit1D::cluster(), Phase2TrackerRecHit1D::cluster(), SiStripRecHit2D::cluster(), SiPixelRecHit::cluster(), end, TrackingRecHit::geographicalId(), getHitFromIter(), edm::Ref< C, T, F >::isNonnull(), TrackingRecHit::isValid(), SiStripMatchedRecHit2D::monoClusterRef(), SiStripMatchedRecHit2D::monoHit(), TrackerSingleRecHit::omniClusterRef(), PixelSubdetector::PixelBarrel, PixelSubdetector::PixelEndcap, SiStripMatchedRecHit2D::stereoClusterRef(), SiStripMatchedRecHit2D::stereoHit(), DetId::subdetId(), SiStripDetId::TEC, SiStripDetId::TIB, SiStripDetId::TID, and SiStripDetId::TOB.

Referenced by associateTrack(), getDoubleCount(), and weightedNumberOfTrackClusters().

398 {
399  std::vector<OmniClusterRef> returnValue;
400  for (iter iRecHit = begin; iRecHit != end; ++iRecHit) {
401  const TrackingRecHit* rhit = getHitFromIter(iRecHit);
402  if (rhit->isValid()) {
403  int subdetid = rhit->geographicalId().subdetId();
405  const SiPixelRecHit* pRHit = dynamic_cast<const SiPixelRecHit*>(rhit);
406  if (!pRHit->cluster().isNonnull())
407  edm::LogError("TrackAssociator") << ">>> RecHit does not have an associated cluster!" << " file: " << __FILE__ << " line: " << __LINE__;
408  returnValue.push_back(pRHit->omniClusterRef());
409  }
410  else if (subdetid==SiStripDetId::TIB||subdetid==SiStripDetId::TOB||subdetid==SiStripDetId::TID||subdetid==SiStripDetId::TEC) {
411  const std::type_info &tid = typeid(*rhit);
412  if (tid == typeid(SiStripMatchedRecHit2D)) {
413  const SiStripMatchedRecHit2D* sMatchedRHit = dynamic_cast<const SiStripMatchedRecHit2D*>(rhit);
414  if (!sMatchedRHit->monoHit().cluster().isNonnull() || !sMatchedRHit->stereoHit().cluster().isNonnull())
415  edm::LogError("TrackAssociator") << ">>> RecHit does not have an associated cluster!" << " file: " << __FILE__ << " line: " << __LINE__;
416  returnValue.push_back(sMatchedRHit->monoClusterRef());
417  returnValue.push_back(sMatchedRHit->stereoClusterRef());
418  }
419  else if (tid == typeid(SiStripRecHit2D)) {
420  const SiStripRecHit2D* sRHit = dynamic_cast<const SiStripRecHit2D*>(rhit);
421  if (!sRHit->cluster().isNonnull())
422  edm::LogError("TrackAssociator") << ">>> RecHit does not have an associated cluster!" << " file: " << __FILE__ << " line: " << __LINE__;
423  returnValue.push_back(sRHit->omniClusterRef());
424  }
425  else if (tid == typeid(SiStripRecHit1D)) {
426  const SiStripRecHit1D* sRHit = dynamic_cast<const SiStripRecHit1D*>(rhit);
427  if (!sRHit->cluster().isNonnull())
428  edm::LogError("TrackAssociator") << ">>> RecHit does not have an associated cluster!" << " file: " << __FILE__ << " line: " << __LINE__;
429  returnValue.push_back(sRHit->omniClusterRef());
430  }
431  else if (tid == typeid(Phase2TrackerRecHit1D)) {
432  const Phase2TrackerRecHit1D* ph2Hit = dynamic_cast<const Phase2TrackerRecHit1D*>(rhit);
433  if (!ph2Hit->cluster().isNonnull() )
434  edm::LogError("TrackAssociator") << ">>> RecHit does not have an associated cluster!" << " file: " << __FILE__ << " line: " << __LINE__;
435  returnValue.push_back(ph2Hit->omniClusterRef());
436  }
437  else {
438  auto const & thit = static_cast<BaseTrackerRecHit const&>(*rhit);
439  if ( thit.isProjected() ) {
440  } else {
441  edm::LogError("TrackAssociator") << ">>> getMatchedClusters: TrackingRecHit not associated to any SiStripCluster! subdetid = " << subdetid;
442  }
443  }
444  }
445  else {
446  edm::LogError("TrackAssociator") << ">>> getMatchedClusters: TrackingRecHit not associated to any cluster! subdetid = " << subdetid;
447  }
448  }
449  }
450  return returnValue;
451 }
ClusterRef cluster() const
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:253
OmniClusterRef const & stereoClusterRef() const
const TrackingRecHit * getHitFromIter(trackingRecHit_iterator iter) const
ClusterRef cluster() const
#define end
Definition: vmac.h:37
OmniClusterRef const & monoClusterRef() const
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:37
OmniClusterRef const & omniClusterRef() const
SiStripRecHit2D stereoHit() const
ClusterRef cluster() const
Definition: SiPixelRecHit.h:49
bool isValid() const
SiStripRecHit2D monoHit() const
#define begin
Definition: vmac.h:30
DetId geographicalId() const
Our base class.
Definition: SiPixelRecHit.h:23
static bool QuickTrackAssociatorByHitsImpl::tpIntPairGreater ( std::pair< edm::Ref< TrackingParticleCollection >, size_t >  i,
std::pair< edm::Ref< TrackingParticleCollection >, size_t >  j 
)
inlinestaticprivate

Definition at line 106 of file QuickTrackAssociatorByHitsImpl.h.

References begin, end, TrackQuality_cff::hitAssociator, mps_fire::i, and trackingTruthProducer_cfi::trackingParticles.

106 { return (i.first.key()>j.first.key()); }
bool QuickTrackAssociatorByHitsImpl::trackingParticleContainsIdentifier ( const TrackingParticle pTrackingParticle,
const SimTrackIdentifiers identifier 
) const
private

Returns true if the supplied TrackingParticle has the supplied g4 track identifiers.

Definition at line 496 of file QuickTrackAssociatorByHitsImpl.cc.

References TrackingParticle::g4Track_begin(), and TrackingParticle::g4Track_end().

Referenced by associateTrack().

497 {
498  // Loop over all of the g4 tracks in the tracking particle
499  for( std::vector<SimTrack>::const_iterator iSimTrack=pTrackingParticle->g4Track_begin(); iSimTrack != pTrackingParticle->g4Track_end();
500  ++iSimTrack )
501  {
502  // And see if the sim track identifiers match
503  if( iSimTrack->eventId() == identifier.second && iSimTrack->trackId() == identifier.first )
504  {
505  return true;
506  }
507  }
508 
509  // If control has made it this far then none of the identifiers were found in
510  // any of the g4 tracks, so return false.
511  return false;
512 }
g4t_iterator g4Track_begin() const
g4t_iterator g4Track_end() const
double QuickTrackAssociatorByHitsImpl::weightedNumberOfTrackClusters ( const reco::Track track,
const TrackerHitAssociator  
) const
private
double QuickTrackAssociatorByHitsImpl::weightedNumberOfTrackClusters ( const TrajectorySeed seed,
const TrackerHitAssociator  
) const
private

Definition at line 741 of file QuickTrackAssociatorByHitsImpl.cc.

References TrackingRecHit::geographicalId(), getHitFromIter(), PixelSubdetector::PixelBarrel, PixelSubdetector::PixelEndcap, pixelHitWeight_, TrajectorySeed::recHits(), DetId::subdetId(), and mps_merge::weight.

741  {
742  double sum = 0.0;
743  for(auto iHit=seed.recHits().first; iHit!=seed.recHits().second; ++iHit) {
744  const auto subdetId = getHitFromIter(iHit)->geographicalId().subdetId();
745  const double weight = (subdetId == PixelSubdetector::PixelBarrel || subdetId == PixelSubdetector::PixelEndcap) ? pixelHitWeight_ : 1.0;
746  sum += weight;
747  }
748  return sum;
749 }
Definition: weight.py:1
const TrackingRecHit * getHitFromIter(trackingRecHit_iterator iter) const
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:37
range recHits() const
DetId geographicalId() const
double QuickTrackAssociatorByHitsImpl::weightedNumberOfTrackClusters ( const reco::Track track,
const ClusterTPAssociation  
) const
private

Definition at line 752 of file QuickTrackAssociatorByHitsImpl.cc.

References reco::Track::recHitsBegin(), reco::Track::recHitsEnd(), and weightedNumberOfTrackClusters().

752  {
753  return weightedNumberOfTrackClusters(track.recHitsBegin(), track.recHitsEnd());
754 }
trackingRecHit_iterator recHitsBegin() const
Iterator to first hit on the track.
Definition: Track.h:104
double weightedNumberOfTrackClusters(const reco::Track &track, const TrackerHitAssociator &) const
trackingRecHit_iterator recHitsEnd() const
Iterator to last hit on the track.
Definition: Track.h:109
double QuickTrackAssociatorByHitsImpl::weightedNumberOfTrackClusters ( const TrajectorySeed seed,
const ClusterTPAssociation  
) const
private

Definition at line 755 of file QuickTrackAssociatorByHitsImpl.cc.

References TrajectorySeed::recHits(), and weightedNumberOfTrackClusters().

755  {
756  const auto& hitRange = seed.recHits();
757  return weightedNumberOfTrackClusters(hitRange.first, hitRange.second);
758 }
range recHits() const
double weightedNumberOfTrackClusters(const reco::Track &track, const TrackerHitAssociator &) const
template<typename iter >
double QuickTrackAssociatorByHitsImpl::weightedNumberOfTrackClusters ( iter  begin,
iter  end 
) const
private

Definition at line 760 of file QuickTrackAssociatorByHitsImpl.cc.

References end, TrackingRecHit::geographicalId(), getHitFromIter(), getMatchedClusters(), LogTrace, PixelSubdetector::PixelBarrel, PixelSubdetector::PixelEndcap, pixelHitWeight_, DetId::rawId(), DetId::subdetId(), and mps_merge::weight.

760  {
761 
762  double weightedClusters = 0.0;
763  for (iter iRecHit = begin; iRecHit != end; ++iRecHit) {
764 
765  const auto subdetId = getHitFromIter(iRecHit)->geographicalId().subdetId();
766  const double weight = (subdetId == PixelSubdetector::PixelBarrel || subdetId == PixelSubdetector::PixelEndcap) ? pixelHitWeight_ : 1.0;
767  LogTrace("QuickTrackAssociatorByHitsImpl") << " detId: " << getHitFromIter(iRecHit)->geographicalId().rawId();
768  LogTrace("QuickTrackAssociatorByHitsImpl") << " weight: " << weight;
769  std::vector < OmniClusterRef > oClusters=getMatchedClusters( iRecHit, iRecHit + 1 ); //only for the cluster being checked
770  for( std::vector<OmniClusterRef>::const_iterator it=oClusters.begin(); it != oClusters.end(); ++it ) {
771  weightedClusters += weight;
772  }
773  }
774  LogTrace("QuickTrackAssociatorByHitsImpl") << " total weighted clusters: " << weightedClusters;
775 
776  return weightedClusters;
777 }
Definition: weight.py:1
uint32_t rawId() const
get the raw id
Definition: DetId.h:43
const TrackingRecHit * getHitFromIter(trackingRecHit_iterator iter) const
#define end
Definition: vmac.h:37
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:37
#define LogTrace(id)
#define begin
Definition: vmac.h:30
DetId geographicalId() const
std::vector< OmniClusterRef > getMatchedClusters(iter begin, iter end) const

Member Data Documentation

bool QuickTrackAssociatorByHitsImpl::absoluteNumberOfHits_
private
const ClusterTPAssociation* QuickTrackAssociatorByHitsImpl::clusterToTPMap_
private

Definition at line 200 of file QuickTrackAssociatorByHitsImpl.h.

Referenced by associateRecoToSim(), and associateSimToReco().

double QuickTrackAssociatorByHitsImpl::cutRecoToSim_
private
std::unique_ptr<const TrackerHitAssociator> QuickTrackAssociatorByHitsImpl::hitAssociator_
private

Definition at line 199 of file QuickTrackAssociatorByHitsImpl.h.

Referenced by associateRecoToSim(), and associateSimToReco().

double QuickTrackAssociatorByHitsImpl::pixelHitWeight_
private
edm::EDProductGetter const* QuickTrackAssociatorByHitsImpl::productGetter_
private

creates either a ClusterTPAssociation OR a TrackerHitAssociator and stores it in the provided unique_ptr. The other will be null.

A decision is made whether to create a ClusterTPAssociation or a TrackerHitAssociator depending on how this track associator was configured. If the ClusterTPAssociation couldn't be fetched from the event then it falls back to creating a TrackerHitAssociator.

Only one type will be created, never both. The other unique_ptr reference will be null so check for that and decide which to use.

N.B. The value of useClusterTPAssociation_ should not be used to decide which of the two pointers to use. If the cluster to TrackingParticle couldn't be retrieved from the event then pClusterToTPMap will be null but useClusterTPAssociation_ is no longer changed to false.

Definition at line 198 of file QuickTrackAssociatorByHitsImpl.h.

Referenced by associateRecoToSim(), associateRecoToSimImplementation(), associateSimToReco(), and associateSimToRecoImplementation().

double QuickTrackAssociatorByHitsImpl::puritySimToReco_
private
double QuickTrackAssociatorByHitsImpl::qualitySimToReco_
private
SimToRecoDenomType QuickTrackAssociatorByHitsImpl::simToRecoDenominator_
private
bool QuickTrackAssociatorByHitsImpl::threeHitTracksAreSpecial_
private