CMS 3D CMS Logo

Public Member Functions | Private Types | Private Member Functions | Private Attributes

QuickTrackAssociatorByHits Class Reference

TrackAssociator that associates by hits a bit quicker than the normal TrackAssociatorByHits class. More...

#include <QuickTrackAssociatorByHits.h>

Inheritance diagram for QuickTrackAssociatorByHits:
TrackAssociatorBase

List of all members.

Public Member Functions

reco::RecoToSimCollection associateRecoToSim (edm::Handle< edm::View< reco::Track > > &trackCollectionHandle, edm::Handle< TrackingParticleCollection > &trackingParticleCollectionHandle, const edm::Event *pEvent=0, const edm::EventSetup *pSetup=0) const
 compare reco to sim the handle of reco::Track and TrackingParticle collections
reco::RecoToSimCollection associateRecoToSim (const edm::RefToBaseVector< reco::Track > &trackCollection, const edm::RefVector< TrackingParticleCollection > &trackingParticleCollection, const edm::Event *pEvent=0, const edm::EventSetup *pSetup=0) const
 Association Reco To Sim with Collections.
reco::SimToRecoCollection associateSimToReco (const edm::RefToBaseVector< reco::Track > &trackCollection, const edm::RefVector< TrackingParticleCollection > &trackingParticleCollection, const edm::Event *pEvent=0, const edm::EventSetup *pSetup=0) const
 Association Sim To Reco with Collections.
reco::SimToRecoCollection associateSimToReco (edm::Handle< edm::View< reco::Track > > &trackCollectionHandle, edm::Handle< TrackingParticleCollection > &trackingParticleCollectionHandle, const edm::Event *pEvent=0, const edm::EventSetup *pSetup=0) const
 compare reco to sim the handle of reco::Track and TrackingParticle collections
QuickTrackAssociatorByHitsoperator= (const QuickTrackAssociatorByHits &otherAssociator)
 QuickTrackAssociatorByHits (const edm::ParameterSet &config)
 QuickTrackAssociatorByHits (const QuickTrackAssociatorByHits &otherAssociator)
 ~QuickTrackAssociatorByHits ()

Private Types

enum  SimToRecoDenomType { denomnone, denomsim, denomreco }
typedef std::pair< uint32_t,
EncodedEventId
SimTrackIdentifiers

Private Member Functions

reco::RecoToSimCollection associateRecoToSimImplementation () const
 The method that does the work for both overloads of associateRecoToSim.
reco::SimToRecoCollection associateSimToRecoImplementation () const
 The method that does the work for both overloads of associateSimToReco.
std::vector< std::pair
< edm::Ref
< TrackingParticleCollection >
, size_t > > 
associateTrack (const reco::Track *pTrack) const
 Returns the TrackingParticle that has the most associated hits to the given track.
std::vector< std::pair
< SimTrackIdentifiers, size_t > > 
getAllSimTrackIdentifiers (const reco::Track *pTrack) 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.
int getDoubleCount (trackingRecHit_iterator begin, trackingRecHit_iterator end, const TrackingParticle &associatedTrackingParticle) const
 This method was copied almost verbatim from the standard TrackAssociatorByHits.
void initialiseHitAssociator (const edm::Event *event) const
bool trackingParticleContainsIdentifier (const TrackingParticle *pTrackingParticle, const SimTrackIdentifiers &identifier) const
 Returns true if the supplied TrackingParticle has the supplied g4 track identifiers.

Private Attributes

bool absoluteNumberOfHits_
double cutRecoToSim_
edm::ParameterSet hitAssociatorParameters_
const edm::EventpEventForWhichAssociatorIsValid_
TrackerHitAssociatorpHitAssociator_
const edm::RefToBaseVector
< reco::Track > * 
pTrackCollection_
 Pointer to the track collection.
edm::Handle< edm::View
< reco::Track > > * 
pTrackCollectionHandle_
 Pointer to the handle to the track collection.
const edm::RefVector
< TrackingParticleCollection > * 
pTrackingParticleCollection_
 Pointer to the TrackingParticle collection handle.
edm::Handle
< TrackingParticleCollection > * 
pTrackingParticleCollectionHandle_
 Pointer to the TrackingParticle collection handle.
double puritySimToReco_
double qualitySimToReco_
SimToRecoDenomType simToRecoDenominator_
bool threeHitTracksAreSpecial_

Detailed Description

TrackAssociator that associates by hits a bit quicker than the normal TrackAssociatorByHits class.

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

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

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.

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

Author:
Mark Grimes (mark.grimes@cern.ch)
Date:
09/Nov/2010 Significant changes to remove any differences to the standard TrackAssociatorByHits results 07/Jul/2011

Definition at line 49 of file QuickTrackAssociatorByHits.h.


Member Typedef Documentation

typedef std::pair<uint32_t,EncodedEventId> QuickTrackAssociatorByHits::SimTrackIdentifiers [private]

Definition at line 73 of file QuickTrackAssociatorByHits.h.


Member Enumeration Documentation

Enumerator:
denomnone 
denomsim 
denomreco 

Definition at line 74 of file QuickTrackAssociatorByHits.h.


Constructor & Destructor Documentation

QuickTrackAssociatorByHits::QuickTrackAssociatorByHits ( const edm::ParameterSet config)

Definition at line 6 of file QuickTrackAssociatorByHits.cc.

References edm::ParameterSet::addParameter(), denomreco, denomsim, Exception, edm::ParameterSet::exists(), edm::ParameterSet::getParameter(), hitAssociatorParameters_, and simToRecoDenominator_.

        : pHitAssociator_(NULL), pEventForWhichAssociatorIsValid_(NULL),
          absoluteNumberOfHits_( config.getParameter<bool>( "AbsoluteNumberOfHits" ) ),
          qualitySimToReco_( config.getParameter<double>( "Quality_SimToReco" ) ),
          puritySimToReco_( config.getParameter<double>( "Purity_SimToReco" ) ),
          cutRecoToSim_( config.getParameter<double>( "Cut_RecoToSim" ) ),
          threeHitTracksAreSpecial_( config.getParameter<bool> ( "ThreeHitTracksAreSpecial" ) )
{
        //
        // Check whether the denominator when working out the percentage of shared hits should
        // be the number of simulated hits or the number of reconstructed hits.
        //
        std::string denominatorString=config.getParameter<std::string>("SimToRecoDenominator");
        if( denominatorString=="sim" ) simToRecoDenominator_=denomsim;
        else if( denominatorString=="reco" ) simToRecoDenominator_=denomreco;
        else throw cms::Exception( "QuickTrackAssociatorByHits" ) << "SimToRecoDenominator not specified as sim or reco";

        //
        // Set up the parameter set for the hit associator
        //
        hitAssociatorParameters_.addParameter<bool>( "associatePixel", config.getParameter<bool>("associatePixel") );
        hitAssociatorParameters_.addParameter<bool>( "associateStrip", config.getParameter<bool>("associateStrip") );
        // This is the important one, it stops the hit associator searching through the list of sim hits.
        // I only want to use the hit associator methods that work on the hit IDs (i.e. the uint32_t trackId
        // and the EncodedEventId eventId) so I'm not interested in matching that to the PSimHit objects.
        hitAssociatorParameters_.addParameter<bool>("associateRecoTracks",true);

        //
        // Do some checks on whether UseGrouped or UseSplitting have been set. They're not used
        // unlike the standard TrackAssociatorByHits so show a warning.
        //
        bool useGrouped, useSplitting;
        if( config.exists("UseGrouped") ) useGrouped=config.getParameter<bool>("UseGrouped");
        else useGrouped=true;

        if( config.exists("UseSplitting") ) useSplitting=config.getParameter<bool>("UseSplitting");
        else useSplitting=true;

        // This associator works as though both UseGrouped and UseSplitting were set to true, so show a
        // warning if this isn't the case.
        if( !(useGrouped && useSplitting) )
        {
                edm::LogWarning("QuickTrackAssociatorByHits") << "UseGrouped and/or UseSplitting has been set to false, but this associator ignores that setting.";
        }
}
QuickTrackAssociatorByHits::~QuickTrackAssociatorByHits ( )

Definition at line 52 of file QuickTrackAssociatorByHits.cc.

References pHitAssociator_.

{
        delete pHitAssociator_;
}
QuickTrackAssociatorByHits::QuickTrackAssociatorByHits ( const QuickTrackAssociatorByHits otherAssociator)

Definition at line 57 of file QuickTrackAssociatorByHits.cc.

References NULL, and pHitAssociator_.

        : pEventForWhichAssociatorIsValid_(otherAssociator.pEventForWhichAssociatorIsValid_),
          hitAssociatorParameters_(otherAssociator.hitAssociatorParameters_),
          absoluteNumberOfHits_(otherAssociator.absoluteNumberOfHits_),
          qualitySimToReco_(otherAssociator.qualitySimToReco_),
          puritySimToReco_(otherAssociator.puritySimToReco_),
          cutRecoToSim_(otherAssociator.cutRecoToSim_),
          threeHitTracksAreSpecial_(otherAssociator.threeHitTracksAreSpecial_),
          simToRecoDenominator_(otherAssociator.simToRecoDenominator_),
          pTrackCollectionHandle_(otherAssociator.pTrackCollectionHandle_),
          pTrackCollection_(otherAssociator.pTrackCollection_),
          pTrackingParticleCollectionHandle_(otherAssociator.pTrackingParticleCollectionHandle_),
          pTrackingParticleCollection_(otherAssociator.pTrackingParticleCollection_)

{
        // No operation other than the initialiser list. That copies everything straight from the other
        // associator, except for pHitAssociator_ which needs a deep copy or both instances will try
        // and free it on deletion.  If it wasn't for pHitAssociator_ the default copy constructor and
        // assignment operator would be sufficient.

        // Actually, need to check the other hit associator isn't null or the pointer dereference would
        // probably cause a segmentation fault.
        if( otherAssociator.pHitAssociator_ ) pHitAssociator_=new TrackerHitAssociator(*otherAssociator.pHitAssociator_);
        else pHitAssociator_=NULL;
}

Member Function Documentation

reco::RecoToSimCollection QuickTrackAssociatorByHits::associateRecoToSim ( edm::Handle< edm::View< reco::Track > > &  tCH,
edm::Handle< TrackingParticleCollection > &  tPCH,
const edm::Event event = 0,
const edm::EventSetup setup = 0 
) const [virtual]

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

Reimplemented from TrackAssociatorBase.

Definition at line 110 of file QuickTrackAssociatorByHits.cc.

References associateRecoToSimImplementation(), initialiseHitAssociator(), NULL, pTrackCollection_, pTrackCollectionHandle_, pTrackingParticleCollection_, and pTrackingParticleCollectionHandle_.

{
        initialiseHitAssociator( pEvent );
        pTrackCollectionHandle_=&trackCollectionHandle;
        pTrackingParticleCollectionHandle_=&trackingParticleCollectionHandle;
        pTrackCollection_=NULL;
        pTrackingParticleCollection_=NULL;

        // This method checks which collection type is set to NULL, and uses the other one.
        return associateRecoToSimImplementation();
}
reco::RecoToSimCollection QuickTrackAssociatorByHits::associateRecoToSim ( const edm::RefToBaseVector< reco::Track > &  tc,
const edm::RefVector< TrackingParticleCollection > &  tpc,
const edm::Event event = 0,
const edm::EventSetup setup = 0 
) const [virtual]

Association Reco To Sim with Collections.

Implements TrackAssociatorBase.

Definition at line 141 of file QuickTrackAssociatorByHits.cc.

References associateRecoToSimImplementation(), initialiseHitAssociator(), NULL, pTrackCollection_, pTrackCollectionHandle_, pTrackingParticleCollection_, and pTrackingParticleCollectionHandle_.

{
        initialiseHitAssociator( pEvent );
        pTrackCollectionHandle_=NULL;
        pTrackingParticleCollectionHandle_=NULL;
        pTrackCollection_=&trackCollection;
        pTrackingParticleCollection_=&trackingParticleCollection;

        // This method checks which collection type is set to NULL, and uses the other one.
        return associateRecoToSimImplementation();
}
reco::RecoToSimCollection QuickTrackAssociatorByHits::associateRecoToSimImplementation ( ) const [private]

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

Definition at line 171 of file QuickTrackAssociatorByHits.cc.

References abs, absoluteNumberOfHits_, associateTrack(), cutRecoToSim_, reco::Track::found(), getDoubleCount(), i, edm::AssociationMap< Tag >::insert(), edm::Handle< T >::product(), pTrackCollection_, pTrackCollectionHandle_, reco::Track::recHitsBegin(), reco::Track::recHitsEnd(), edm::RefToBaseVector< T >::size(), and threeHitTracksAreSpecial_.

Referenced by associateRecoToSim().

{
        reco::RecoToSimCollection returnValue;

        size_t collectionSize;
        // Need to check which pointer is valid to get the collection size
        if( pTrackCollection_ ) collectionSize=pTrackCollection_->size();
        else collectionSize=(*pTrackCollectionHandle_)->size();

        for( size_t i=0; i<collectionSize; ++i )
        {
                const reco::Track* pTrack; // Get a normal pointer for ease of use.
                if( pTrackCollection_ ) pTrack=&*(*pTrackCollection_)[i]; // Possibly the most obscure dereference I've ever had to write
                else pTrack=&(*pTrackCollectionHandle_->product())[i];

                // The return of this function has first as the index and second as the number of associated hits
                std::vector< std::pair<edm::Ref<TrackingParticleCollection>,size_t> > trackingParticleQualityPairs=associateTrack( pTrack );
                for( std::vector< std::pair<edm::Ref<TrackingParticleCollection>,size_t> >::const_iterator iTrackingParticleQualityPair=trackingParticleQualityPairs.begin();
                                                iTrackingParticleQualityPair!=trackingParticleQualityPairs.end(); ++iTrackingParticleQualityPair )
                {
                        const edm::Ref<TrackingParticleCollection>& trackingParticleRef=iTrackingParticleQualityPair->first;
                        size_t numberOfSharedHits=iTrackingParticleQualityPair->second;
                        size_t numberOfValidTrackHits=pTrack->found();

                        if( numberOfSharedHits==0 ) continue; // No point in continuing if there was no association

                        //if electron subtract double counting
                        if( abs(trackingParticleRef->pdgId())==11 && (trackingParticleRef->g4Track_end() - trackingParticleRef->g4Track_begin()) > 1 )
                        {
                                numberOfSharedHits-=getDoubleCount( pTrack->recHitsBegin(), pTrack->recHitsEnd(), *trackingParticleRef );
                        }

                        double quality;
                        if( absoluteNumberOfHits_ ) quality=static_cast<double>( numberOfSharedHits );
                        else if( numberOfValidTrackHits != 0 ) quality=(static_cast<double>(numberOfSharedHits) / static_cast<double>(numberOfValidTrackHits) );
                        else quality=0;

                        if( quality > cutRecoToSim_ && !( threeHitTracksAreSpecial_ && numberOfValidTrackHits==3 && numberOfSharedHits<3 ) )
                        {
                                if( pTrackCollection_ ) returnValue.insert( (*pTrackCollection_)[i], std::make_pair( trackingParticleRef, quality ));
                                else returnValue.insert( edm::RefToBase<reco::Track>(*pTrackCollectionHandle_,i), std::make_pair( trackingParticleRef, quality ));
                        }
                }
        }
        return returnValue;
}
reco::SimToRecoCollection QuickTrackAssociatorByHits::associateSimToReco ( const edm::RefToBaseVector< reco::Track > &  tc,
const edm::RefVector< TrackingParticleCollection > &  tpc,
const edm::Event event = 0,
const edm::EventSetup setup = 0 
) const [virtual]

Association Sim To Reco with Collections.

Implements TrackAssociatorBase.

Definition at line 156 of file QuickTrackAssociatorByHits.cc.

References associateSimToRecoImplementation(), initialiseHitAssociator(), NULL, pTrackCollection_, pTrackCollectionHandle_, pTrackingParticleCollection_, and pTrackingParticleCollectionHandle_.

{
        initialiseHitAssociator( pEvent );
        pTrackCollectionHandle_=NULL;
        pTrackingParticleCollectionHandle_=NULL;
        pTrackCollection_=&trackCollection;
        pTrackingParticleCollection_=&trackingParticleCollection;

        // This method checks which collection type is set to NULL, and uses the other one.
        return associateSimToRecoImplementation();
}
reco::SimToRecoCollection QuickTrackAssociatorByHits::associateSimToReco ( edm::Handle< edm::View< reco::Track > > &  tCH,
edm::Handle< TrackingParticleCollection > &  tPCH,
const edm::Event event = 0,
const edm::EventSetup setup = 0 
) const [virtual]

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

Reimplemented from TrackAssociatorBase.

Definition at line 125 of file QuickTrackAssociatorByHits.cc.

References associateSimToRecoImplementation(), initialiseHitAssociator(), NULL, pTrackCollection_, pTrackCollectionHandle_, pTrackingParticleCollection_, and pTrackingParticleCollectionHandle_.

{
        initialiseHitAssociator( pEvent );
        pTrackCollectionHandle_=&trackCollectionHandle;
        pTrackingParticleCollectionHandle_=&trackingParticleCollectionHandle;
        pTrackCollection_=NULL;
        pTrackingParticleCollection_=NULL;

        // This method checks which collection type is set to NULL, and uses the other one.
        return associateSimToRecoImplementation();
}
reco::SimToRecoCollection QuickTrackAssociatorByHits::associateSimToRecoImplementation ( ) const [private]

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

Definition at line 218 of file QuickTrackAssociatorByHits.cc.

References absoluteNumberOfHits_, associateTrack(), denomreco, denomsim, reco::Track::found(), i, edm::AssociationMap< Tag >::insert(), edm::Handle< T >::product(), pTrackCollection_, pTrackCollectionHandle_, puritySimToReco_, qualitySimToReco_, simToRecoDenominator_, edm::RefToBaseVector< T >::size(), threeHitTracksAreSpecial_, and DetId::Tracker.

Referenced by associateSimToReco().

{
        reco::SimToRecoCollection returnValue;

        size_t collectionSize;
        // Need to check which pointer is valid to get the collection size
        if( pTrackCollection_ ) collectionSize=pTrackCollection_->size();
        else collectionSize=(*pTrackCollectionHandle_)->size();

        for( size_t i=0; i<collectionSize; ++i )
        {
                const reco::Track* pTrack; // Get a normal pointer for ease of use.
                if( pTrackCollection_ ) pTrack=&*(*pTrackCollection_)[i]; // Possibly the most obscure dereference I've ever had to write
                else pTrack=&(*pTrackCollectionHandle_->product())[i];

                // The return of this function has first as an edm:Ref to the associated TrackingParticle, and second as the number of associated hits
                std::vector< std::pair<edm::Ref<TrackingParticleCollection>,size_t> > trackingParticleQualityPairs=associateTrack( pTrack );
                for( std::vector< std::pair<edm::Ref<TrackingParticleCollection>,size_t> >::const_iterator iTrackingParticleQualityPair=trackingParticleQualityPairs.begin();
                                iTrackingParticleQualityPair!=trackingParticleQualityPairs.end(); ++iTrackingParticleQualityPair )
                {
                        const edm::Ref<TrackingParticleCollection>& trackingParticleRef=iTrackingParticleQualityPair->first;
                        size_t numberOfSharedHits=iTrackingParticleQualityPair->second;
                        size_t numberOfValidTrackHits=pTrack->found();
                        size_t numberOfSimulatedHits=0; // Set a few lines below, but only if required.

                        if( numberOfSharedHits==0 ) continue; // No point in continuing if there was no association

                        if( simToRecoDenominator_==denomsim || (numberOfSharedHits<3 && threeHitTracksAreSpecial_) ) // the numberOfSimulatedHits is not always required, so can skip counting in some circumstances
                        {
                                // Note that in the standard TrackAssociatorByHits, all of the hits in associatedTrackingParticleHits are checked for
                                // various things.  I'm not sure what these checks are for but they depend on the UseGrouping and UseSplitting settings.
                                // This associator works as though both UseGrouping and UseSplitting were set to true, i.e. just counts the number of
                                // hits in the tracker.
                                numberOfSimulatedHits=trackingParticleRef->trackPSimHit(DetId::Tracker).size();
                        }

                        double purity=static_cast<double>(numberOfSharedHits)/static_cast<double>(numberOfValidTrackHits);
                        double quality;
                        if( absoluteNumberOfHits_ ) quality=static_cast<double>(numberOfSharedHits);
                        else if( simToRecoDenominator_==denomsim && numberOfSimulatedHits != 0 ) quality=static_cast<double>(numberOfSharedHits)/static_cast<double>(numberOfSimulatedHits);
                        else if( simToRecoDenominator_==denomreco && numberOfValidTrackHits != 0 ) quality=purity;
                        else quality=0;

                        if( quality>qualitySimToReco_ && !( threeHitTracksAreSpecial_ && numberOfSimulatedHits==3 && numberOfSharedHits<3 ) && ( absoluteNumberOfHits_ || (purity>puritySimToReco_) ) )
                        {
                                if( pTrackCollection_ ) returnValue.insert( trackingParticleRef, std::make_pair( (*pTrackCollection_)[i], quality ) );
                                else returnValue.insert( trackingParticleRef, std::make_pair( edm::RefToBase<reco::Track>(*pTrackCollectionHandle_,i) , quality ) );
                        }
                }
        }
        return returnValue;

}
std::vector< std::pair< edm::Ref< TrackingParticleCollection >, size_t > > QuickTrackAssociatorByHits::associateTrack ( const reco::Track pTrack) 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 272 of file QuickTrackAssociatorByHits.cc.

References getAllSimTrackIdentifiers(), i, edm::Handle< T >::product(), pTrackingParticleCollection_, pTrackingParticleCollectionHandle_, edm::RefVector< C, T, F >::size(), trackingParticleContainsIdentifier(), and TrackingParticle::trackPSimHit().

Referenced by associateRecoToSimImplementation(), and associateSimToRecoImplementation().

{
        // The pairs in this vector have a Ref to the associated TrackingParticle as "first" and the number of associated hits as "second"
        std::vector< std::pair<edm::Ref<TrackingParticleCollection>,size_t> > returnValue;

        // The pairs in this vector have first as the sim track identifiers, and second the number of reco hits associated to that sim track.
        // 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
        // number of reco hits.  The pair::second entries should add up to the total number of reco hits though.
        std::vector< std::pair<SimTrackIdentifiers,size_t> > hitIdentifiers=getAllSimTrackIdentifiers(pTrack);

        // Loop over the TrackingParticles
        size_t collectionSize;
        if( pTrackingParticleCollection_ ) collectionSize=pTrackingParticleCollection_->size();
        else collectionSize=(*pTrackingParticleCollectionHandle_)->size();

        for( size_t i=0; i<collectionSize; ++i )
        {
                const TrackingParticle* pTrackingParticle; // Convert to raw pointer for ease of use
                if( pTrackingParticleCollection_ ) pTrackingParticle=&*(*pTrackingParticleCollection_)[i];
                else pTrackingParticle=&(*pTrackingParticleCollectionHandle_->product())[i];

                // Ignore TrackingParticles with no hits
                if( pTrackingParticle->trackPSimHit().empty() ) continue;

                size_t numberOfAssociatedHits=0;
                // Loop over all of the sim track identifiers and see if any of them are part of this TrackingParticle. If they are, add
                // the number of reco hits associated to that sim track to the total number of associated hits.
                for( std::vector< std::pair<SimTrackIdentifiers,size_t> >::const_iterator iIdentifierCountPair=hitIdentifiers.begin(); iIdentifierCountPair!=hitIdentifiers.end(); ++iIdentifierCountPair )
                {
                        if( trackingParticleContainsIdentifier( pTrackingParticle, iIdentifierCountPair->first ) ) numberOfAssociatedHits+=iIdentifierCountPair->second;
                }

                if( numberOfAssociatedHits>0 )
                {
                        if( pTrackingParticleCollection_ ) returnValue.push_back( std::make_pair( (*pTrackingParticleCollection_)[i], numberOfAssociatedHits ) );
                        else returnValue.push_back( std::make_pair( edm::Ref<TrackingParticleCollection>( *pTrackingParticleCollectionHandle_, i ), numberOfAssociatedHits ) );
                }
        }

        return returnValue;
}
std::vector< std::pair< QuickTrackAssociatorByHits::SimTrackIdentifiers, size_t > > QuickTrackAssociatorByHits::getAllSimTrackIdentifiers ( const reco::Track pTrack) 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 314 of file QuickTrackAssociatorByHits.cc.

References TrackerHitAssociator::associateHitId(), pHitAssociator_, reco::Track::recHitsBegin(), and reco::Track::recHitsEnd().

Referenced by associateTrack().

{
        // The pairs in this vector have first as the sim track identifiers, and second the number of reco hits associated to that sim track.
        std::vector< std::pair<SimTrackIdentifiers,size_t> > returnValue;

        std::vector<SimTrackIdentifiers> simTrackIdentifiers;
        // Loop over all of the rec hits in the track
        for( trackingRecHit_iterator iRecHit=pTrack->recHitsBegin(); iRecHit!=pTrack->recHitsEnd(); ++iRecHit )
        {
                if( (*iRecHit)->isValid() )
                {
                        simTrackIdentifiers.clear();

                        // Get the identifiers for the sim track that this hit came from. There should only be one entry unless clusters
                        // have merged (as far as I know).
                        pHitAssociator_->associateHitId( **iRecHit, simTrackIdentifiers ); // This call fills simTrackIdentifiers

                        // Loop over each identifier, and add it to the return value only if it's not already in there
                        for( std::vector<SimTrackIdentifiers>::const_iterator iIdentifier=simTrackIdentifiers.begin(); iIdentifier!=simTrackIdentifiers.end(); ++iIdentifier )
                        {
                                std::vector< std::pair<SimTrackIdentifiers,size_t> >::iterator iIdentifierCountPair;
                                for( iIdentifierCountPair=returnValue.begin(); iIdentifierCountPair!=returnValue.end(); ++iIdentifierCountPair )
                                {
                                        if( iIdentifierCountPair->first.first==iIdentifier->first && iIdentifierCountPair->first.second==iIdentifier->second )
                                        {
                                                // This sim track identifier is already in the list, so increment the count of how many hits it relates to.
                                                ++iIdentifierCountPair->second;
                                                break;
                                        }
                                }
                                if( iIdentifierCountPair==returnValue.end() ) returnValue.push_back( std::make_pair(*iIdentifier,1) ); // This identifier wasn't found, so add it
                        }
                }
        }

        return returnValue;
}
int QuickTrackAssociatorByHits::getDoubleCount ( trackingRecHit_iterator  begin,
trackingRecHit_iterator  end,
const TrackingParticle associatedTrackingParticle 
) const [private]

This method was copied almost verbatim from the standard TrackAssociatorByHits.

Definition at line 369 of file QuickTrackAssociatorByHits.cc.

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

Referenced by associateRecoToSimImplementation().

{
        // This method is largely copied from the standard TrackAssociatorByHits. Once I've tested how much difference
        // it makes I'll go through and comment it properly.

        int doubleCount=0;
        std::vector<SimHitIdpr> SimTrackIdsDC;

        for( trackingRecHit_iterator iHit=startIterator; iHit != endIterator; iHit++ )
        {
                int idcount=0;
                SimTrackIdsDC.clear();
                pHitAssociator_->associateHitId( **iHit, SimTrackIdsDC );

                if( SimTrackIdsDC.size() > 1 )
                {
                        for( TrackingParticle::g4t_iterator g4T=associatedTrackingParticle.g4Track_begin(); g4T != associatedTrackingParticle.g4Track_end(); ++g4T )
                        {
                                if( find( SimTrackIdsDC.begin(), SimTrackIdsDC.end(), SimHitIdpr( ( *g4T).trackId(), SimTrackIdsDC.begin()->second ) )
                                                != SimTrackIdsDC.end() )
                                {
                                        idcount++;
                                }
                        }
                }
                if( idcount > 1 ) doubleCount+=(idcount - 1);
        }

        return doubleCount;
}
void QuickTrackAssociatorByHits::initialiseHitAssociator ( const edm::Event event) const [private]

Definition at line 401 of file QuickTrackAssociatorByHits.cc.

References hitAssociatorParameters_, pEventForWhichAssociatorIsValid_, and pHitAssociator_.

Referenced by associateRecoToSim(), and associateSimToReco().

{
        // The intention of this function was to check whether the hit associator is still valid
        // (since in general associateSimToReco and associateRecoToSim are called for the same
        // event). I was doing this by recording the event pointer and checking it hasn't changed
        // but this doesn't appear to work. Until I find a way of uniquely identifying an event
        // I'll just create it anew each time.
//      if( pEventForWhichAssociatorIsValid_==pEvent && pEventForWhichAssociatorIsValid_!=NULL ) return; // Already set up so no need to do anything

        // Free up the previous instantiation
        delete pHitAssociator_;

        // Create a new instantiation using the new event
        pHitAssociator_=new TrackerHitAssociator( *pEvent, hitAssociatorParameters_ );
        pEventForWhichAssociatorIsValid_=pEvent;
}
QuickTrackAssociatorByHits & QuickTrackAssociatorByHits::operator= ( const QuickTrackAssociatorByHits otherAssociator)

Definition at line 83 of file QuickTrackAssociatorByHits.cc.

References absoluteNumberOfHits_, cutRecoToSim_, hitAssociatorParameters_, NULL, pEventForWhichAssociatorIsValid_, pHitAssociator_, pTrackCollection_, pTrackCollectionHandle_, pTrackingParticleCollection_, pTrackingParticleCollectionHandle_, puritySimToReco_, qualitySimToReco_, simToRecoDenominator_, and threeHitTracksAreSpecial_.

{
        // Free up the old pHitAssociator_
        delete pHitAssociator_;

        //
        // pHitAssociator_ needs to be given a deep copy of the object, but everything else can
        // can be shallow copied from the other associator.
        //
        if( otherAssociator.pHitAssociator_ ) pHitAssociator_=new TrackerHitAssociator(*otherAssociator.pHitAssociator_);
        else pHitAssociator_=NULL;
        pEventForWhichAssociatorIsValid_=otherAssociator.pEventForWhichAssociatorIsValid_;
        hitAssociatorParameters_=otherAssociator.hitAssociatorParameters_;
        absoluteNumberOfHits_=otherAssociator.absoluteNumberOfHits_;
        qualitySimToReco_=otherAssociator.qualitySimToReco_;
        puritySimToReco_=otherAssociator.puritySimToReco_;
        cutRecoToSim_=otherAssociator.cutRecoToSim_;
        threeHitTracksAreSpecial_=otherAssociator.threeHitTracksAreSpecial_;
        simToRecoDenominator_=otherAssociator.simToRecoDenominator_;
        pTrackCollectionHandle_=otherAssociator.pTrackCollectionHandle_;
        pTrackCollection_=otherAssociator.pTrackCollection_;
        pTrackingParticleCollectionHandle_=otherAssociator.pTrackingParticleCollectionHandle_;
        pTrackingParticleCollection_=otherAssociator.pTrackingParticleCollection_;

        return *this;
}
bool QuickTrackAssociatorByHits::trackingParticleContainsIdentifier ( const TrackingParticle pTrackingParticle,
const SimTrackIdentifiers identifier 
) const [private]

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

Definition at line 352 of file QuickTrackAssociatorByHits.cc.

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

Referenced by associateTrack().

{
        // Loop over all of the g4 tracks in the tracking particle
        for( std::vector<SimTrack>::const_iterator iSimTrack=pTrackingParticle->g4Track_begin(); iSimTrack!=pTrackingParticle->g4Track_end(); ++iSimTrack )
        {
                // And see if the sim track identifiers match
                if( iSimTrack->eventId()==identifier.second && iSimTrack->trackId()==identifier.first )
                {
                        return true;
                }
        }

        // If control has made it this far then none of the identifiers were found in
        // any of the g4 tracks, so return false.
        return false;
}

Member Data Documentation

Definition at line 118 of file QuickTrackAssociatorByHits.h.

Referenced by associateRecoToSimImplementation(), and operator=().

Definition at line 110 of file QuickTrackAssociatorByHits.h.

Referenced by initialiseHitAssociator(), and operator=().

Pointer to the track collection.

Either this or pTrackCollectionHandle_ will be set, the other will be Null. See the comment on pTrackCollectionHandle_ for reasons why.

Definition at line 137 of file QuickTrackAssociatorByHits.h.

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

Pointer to the handle to the track collection.

Only one of pTrackCollectionHandle_ or pTrackCollection_ will ever be non Null. This is so that both flavours of the associateRecoToSim (one takes a Handle, the other a RefToBaseVector) can use the same associateRecoToSimImplementation method and keep the logic for both in one place. The old implementation for the handle flavour copied everything into a new RefToBaseVector, wasting memory. I tried to do something clever with templates but couldn't get it to work, so the associateRecoToSimImplementation method checks which is non Null and uses that to get the tracks.

Definition at line 130 of file QuickTrackAssociatorByHits.h.

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

Pointer to the TrackingParticle collection handle.

Either this or pTrackingParticleCollectionHandle_ will be set, the other will be Null. See the comment on pTrackCollectionHandle_ for reasons why.

Definition at line 151 of file QuickTrackAssociatorByHits.h.

Referenced by associateRecoToSim(), associateSimToReco(), associateTrack(), and operator=().

Pointer to the TrackingParticle collection handle.

Either this or pTrackingParticleCollection_ will be set, the other will be Null. See the comment on pTrackCollectionHandle_ for reasons why.

Definition at line 144 of file QuickTrackAssociatorByHits.h.

Referenced by associateRecoToSim(), associateSimToReco(), associateTrack(), and operator=().

Definition at line 117 of file QuickTrackAssociatorByHits.h.

Referenced by associateSimToRecoImplementation(), and operator=().

Definition at line 116 of file QuickTrackAssociatorByHits.h.

Referenced by associateSimToRecoImplementation(), and operator=().