CMS 3D CMS Logo

Public Member Functions | Private Types | Private Member Functions | Static 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::RecoToSimCollectionSeed associateRecoToSim (edm::Handle< edm::View< TrajectorySeed > > &, edm::Handle< TrackingParticleCollection > &, const edm::Event *event, const edm::EventSetup *setup) const
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::SimToRecoCollectionSeed associateSimToReco (edm::Handle< edm::View< TrajectorySeed > > &, edm::Handle< TrackingParticleCollection > &, const edm::Event *event, const edm::EventSetup *setup) const
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)
void prepareCluster2TPMap (const edm::Event *pEvent) const
 QuickTrackAssociatorByHits (const QuickTrackAssociatorByHits &otherAssociator)
 QuickTrackAssociatorByHits (const edm::ParameterSet &config)
 ~QuickTrackAssociatorByHits ()

Private Types

typedef std::vector< std::pair
< OmniClusterRef,
TrackingParticleRef > > 
ClusterTPAssociationList
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.
template<typename iter >
std::vector< std::pair
< edm::Ref
< TrackingParticleCollection >
, size_t > > 
associateTrack (iter begin, iter end) const
 Returns the TrackingParticle that has the most associated hits to the given track.
template<typename iter >
std::vector< std::pair
< edm::Ref
< TrackingParticleCollection >
, size_t > > 
associateTrackByCluster (iter begin, iter end) const
template<typename iter >
std::vector< std::pair
< SimTrackIdentifiers, size_t > > 
getAllSimTrackIdentifiers (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.
template<typename iter >
int getDoubleCount (iter begin, iter end, TrackingParticleRef associatedTrackingParticle) const
 This method was copied almost verbatim from the standard TrackAssociatorByHits.
const TrackingRecHitgetHitFromIter (trackingRecHit_iterator iter) const
const TrackingRecHitgetHitFromIter (TrackingRecHitCollection::const_iterator iter) const
template<typename iter >
std::vector< OmniClusterRefgetMatchedClusters (iter begin, iter end) const
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.

Static Private Member Functions

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

Private Attributes

bool absoluteNumberOfHits_
edm::InputTag cluster2TPSrc_
double cutRecoToSim_
edm::ParameterSet hitAssociatorParameters_
ClusterTPAssociationList pCluster2TPList_
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_
bool useClusterTPAssociation_

Detailed Description

TrackAssociator that associates by hits a bit quicker than the normal TrackAssociatorByHits 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 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.

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 TrackAssociatorByHits 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 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 59 of file QuickTrackAssociatorByHits.h.


Member Typedef Documentation

Definition at line 101 of file QuickTrackAssociatorByHits.h.

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

Definition at line 97 of file QuickTrackAssociatorByHits.h.


Member Enumeration Documentation

Enumerator:
denomnone 
denomsim 
denomreco 

Definition at line 98 of file QuickTrackAssociatorByHits.h.


Constructor & Destructor Documentation

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

Definition at line 17 of file QuickTrackAssociatorByHits.cc.

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

        : 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" ) ),
          useClusterTPAssociation_(config.getParameter<bool>("useClusterTPAssociation")),
          cluster2TPSrc_(config.getParameter<edm::InputTag>("cluster2TPSrc"))
{
        //
        // 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 65 of file QuickTrackAssociatorByHits.cc.

References pHitAssociator_.

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

Definition at line 70 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_),
          useClusterTPAssociation_(otherAssociator.useClusterTPAssociation_),
          cluster2TPSrc_(otherAssociator.cluster2TPSrc_)
{
        // 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 126 of file QuickTrackAssociatorByHits.cc.

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

{

        // get the Cluster2TPMap or initialize hit associator
        if (useClusterTPAssociation_) prepareCluster2TPMap(pEvent);
        else 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 165 of file QuickTrackAssociatorByHits.cc.

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

{

  // get the Cluster2TPMap or initialize hit associator
  if (useClusterTPAssociation_) prepareCluster2TPMap(pEvent);
  else 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::RecoToSimCollectionSeed QuickTrackAssociatorByHits::associateRecoToSim ( edm::Handle< edm::View< TrajectorySeed > > &  pSeedCollectionHandle_,
edm::Handle< TrackingParticleCollection > &  trackingParticleCollectionHandle,
const edm::Event event,
const edm::EventSetup setup 
) const [virtual]

Reimplemented from TrackAssociatorBase.

Definition at line 608 of file QuickTrackAssociatorByHits.cc.

References abs, absoluteNumberOfHits_, associateTrack(), associateTrackByCluster(), cutRecoToSim_, getDoubleCount(), i, initialiseHitAssociator(), edm::AssociationMap< Tag >::insert(), LogTrace, NULL, edm::AssociationMap< Tag >::post_insert(), pTrackCollection_, pTrackCollectionHandle_, pTrackingParticleCollection_, pTrackingParticleCollectionHandle_, TrajectorySeed::recHits(), edm::AssociationMap< Tag >::size(), threeHitTracksAreSpecial_, and useClusterTPAssociation_.

                                                                                 {

  edm::LogVerbatim("TrackAssociator") << "Starting TrackAssociatorByHits::associateRecoToSim - #seeds="
                                      << pSeedCollectionHandle_->size()<<" #TPs="<<trackingParticleCollectionHandle->size();

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

  reco::RecoToSimCollectionSeed  returnValue;

  size_t collectionSize=pSeedCollectionHandle_->size();
  
  for( size_t i=0; i<collectionSize; ++i )
    {
      const TrajectorySeed* pSeed = &(*pSeedCollectionHandle_)[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 =  (useClusterTPAssociation_) 
        ? associateTrackByCluster( pSeed->recHits().first,pSeed->recHits().second )
        : associateTrack( pSeed->recHits().first,pSeed->recHits().second );
      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=pSeed->recHits().second-pSeed->recHits().first;
          
          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( pSeed->recHits().first, pSeed->recHits().second, 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 ) )
            {
              returnValue.insert( edm::RefToBase<TrajectorySeed>(pSeedCollectionHandle_,i), std::make_pair( trackingParticleRef, quality ));
            }
        }
    }
  
  LogTrace("TrackAssociator") << "% of Assoc Seeds=" << ((double)returnValue.size())/((double)pSeedCollectionHandle_->size());
  returnValue.post_insert();
  return returnValue;
  
}
reco::RecoToSimCollection QuickTrackAssociatorByHits::associateRecoToSimImplementation ( ) const [private]

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

Definition at line 203 of file QuickTrackAssociatorByHits.cc.

References abs, absoluteNumberOfHits_, associateTrack(), associateTrackByCluster(), 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(), threeHitTracksAreSpecial_, and useClusterTPAssociation_.

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();

  //std::cout << "#reco Tracks = " << collectionSize << std::endl;
  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];
    //    std::cout << ">>> recoTrack #index = " << i << " pt = " << pTrack->pt() << std::endl;

    // 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 = (useClusterTPAssociation_) 
      ? associateTrackByCluster( pTrack->recHitsBegin(),pTrack->recHitsEnd() )
      : associateTrack( pTrack->recHitsBegin(), pTrack->recHitsEnd() );

    // int nt = 0;
    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();
          
      //std::cout << ">>> reco2sim. numberOfSharedHits = " << nt++ << ", " << numberOfSharedHits << std::endl;
      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 184 of file QuickTrackAssociatorByHits.cc.

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

{

  // get the Cluster2TPMap or initialize hit associator
  if (useClusterTPAssociation_) prepareCluster2TPMap(pEvent);
  else 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 145 of file QuickTrackAssociatorByHits.cc.

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

{

        // get the Cluster2TPMap or initialize hit associator
        if (useClusterTPAssociation_) prepareCluster2TPMap(pEvent);
        else 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::SimToRecoCollectionSeed QuickTrackAssociatorByHits::associateSimToReco ( edm::Handle< edm::View< TrajectorySeed > > &  pSeedCollectionHandle_,
edm::Handle< TrackingParticleCollection > &  trackingParticleCollectionHandle,
const edm::Event event,
const edm::EventSetup setup 
) const [virtual]

Reimplemented from TrackAssociatorBase.

Definition at line 669 of file QuickTrackAssociatorByHits.cc.

References abs, absoluteNumberOfHits_, associateTrack(), associateTrackByCluster(), denomreco, denomsim, getDoubleCount(), i, initialiseHitAssociator(), edm::AssociationMap< Tag >::insert(), LogTrace, NULL, edm::AssociationMap< Tag >::post_insert(), pTrackCollection_, pTrackCollectionHandle_, pTrackingParticleCollection_, pTrackingParticleCollectionHandle_, puritySimToReco_, qualitySimToReco_, TrajectorySeed::recHits(), simToRecoDenominator_, edm::AssociationMap< Tag >::size(), threeHitTracksAreSpecial_, and useClusterTPAssociation_.

                                                                                 {

  edm::LogVerbatim("TrackAssociator") << "Starting TrackAssociatorByHits::associateSimToReco - #seeds="
                                      <<pSeedCollectionHandle_->size()<<" #TPs="<<trackingParticleCollectionHandle->size();

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

  reco::SimToRecoCollectionSeed  returnValue;

  size_t collectionSize=pSeedCollectionHandle_->size();
  
  for( size_t i=0; i<collectionSize; ++i )
    {
      const TrajectorySeed* pSeed=&(*pSeedCollectionHandle_)[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 =  (useClusterTPAssociation_) 
        ? associateTrackByCluster( pSeed->recHits().first,pSeed->recHits().second )
        : associateTrack( pSeed->recHits().first,pSeed->recHits().second );
      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=pSeed->recHits().second-pSeed->recHits().first;
          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 electron subtract double counting
          if( abs(trackingParticleRef->pdgId())==11 && (trackingParticleRef->g4Track_end() - trackingParticleRef->g4Track_begin()) > 1 )
            {
              numberOfSharedHits-=getDoubleCount( pSeed->recHits().first, pSeed->recHits().second, trackingParticleRef );
            }
          
          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->numberOfTrackerHits();
            }
          
          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_) ) )
            {
              returnValue.insert( trackingParticleRef, std::make_pair( edm::RefToBase<TrajectorySeed>(pSeedCollectionHandle_,i) , quality ) );
            }
        }
    }
  return returnValue;
  
  LogTrace("TrackAssociator") << "% of Assoc TPs=" << ((double)returnValue.size())/((double)trackingParticleCollectionHandle->size());
  returnValue.post_insert();
  return returnValue;
}
reco::SimToRecoCollection QuickTrackAssociatorByHits::associateSimToRecoImplementation ( ) const [private]

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

Definition at line 258 of file QuickTrackAssociatorByHits.cc.

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

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 = (useClusterTPAssociation_) 
                ? associateTrackByCluster( pTrack->recHitsBegin(),pTrack->recHitsEnd() )
                : associateTrack( pTrack->recHitsBegin(),pTrack->recHitsEnd() );

                // int nt = 0;
                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.

                        //std::cout << ">>> sim2reco. numberOfSharedHits = " << nt++ << ", " << numberOfSharedHits << std::endl;
                        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->numberOfTrackerHits();
                        }


                        //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 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;

}
template<typename iter >
std::vector< std::pair< edm::Ref< TrackingParticleCollection >, size_t > > QuickTrackAssociatorByHits::associateTrack ( 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 325 of file QuickTrackAssociatorByHits.cc.

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

Referenced by associateRecoToSim(), associateRecoToSimImplementation(), associateSimToReco(), 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(begin, end);

        // 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->numberOfHits()==0 ) 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;
}
template<typename iter >
std::vector< std::pair< edm::Ref< TrackingParticleCollection >, size_t > > QuickTrackAssociatorByHits::associateTrackByCluster ( iter  begin,
iter  end 
) const [private]

Definition at line 383 of file QuickTrackAssociatorByHits.cc.

References clusterTPAssociationListGreater(), getMatchedClusters(), and pCluster2TPList_.

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

{
  // The pairs in this vector have a Ref to the associated TrackingParticle as "first" and the number of associated clusters as "second"
  // Note: typedef edm::Ref<TrackingParticleCollection> TrackingParticleRef;
  std::vector<std::pair<edm::Ref<TrackingParticleCollection>, size_t> > returnValue;
  if (!pCluster2TPList_.size()) return returnValue;
  
  // The pairs in this vector have first as the TP, and second the number of reco clusters associated to that TP.
  // Most reco clusters will probably have come from the same sim track (i.e TP), so the number of entries in this 
  // vector should be fewer than the number of clusters. The pair::second entries should add up to the total 
  // number of reco clusters though.
  std::vector<OmniClusterRef> oClusters = getMatchedClusters(begin, end);

  std::map<TrackingParticleRef, size_t> lmap; 
  for (std::vector<OmniClusterRef>::const_iterator it = oClusters.begin(); it != oClusters.end(); ++it) {

    std::pair<OmniClusterRef, TrackingParticleRef> clusterTPpairWithDummyTP(*it,TrackingParticleRef());//TP is dummy: for clusterTPAssociationListGreater sorting only the cluster is needed
    auto range = std::equal_range(pCluster2TPList_.begin(), pCluster2TPList_.end(), clusterTPpairWithDummyTP, clusterTPAssociationListGreater);
    if(range.first != range.second) {
      for(auto ip = range.first; ip != range.second; ++ip) {

        const TrackingParticleRef trackingParticle = (ip->second);

        // Ignore TrackingParticles with no hits
        if (trackingParticle->numberOfHits()==0) continue;

        /* Alternative implementation to avoid the use of lmap... memory slightly improved but slightly slower...
        std::pair<edm::Ref<TrackingParticleCollection>,size_t> tpIntPair(trackingParticle, 1);
        auto tp_range = std::equal_range(returnValue.begin(), returnValue.end(), tpIntPair, tpIntPairGreater);
        if ((tp_range.second-tp_range.first)>1) {
          edm::LogError("TrackAssociator") << ">>> Error in counting TPs!" << " file: " << __FILE__ << " line: " << __LINE__;
        }
        if(tp_range.first != tp_range.second) {
          tp_range.first->second++;
        } else {
          returnValue.push_back(tpIntPair);
          std::sort(returnValue.begin(), returnValue.end(), tpIntPairGreater);
        }
        */
        auto jpos = lmap.find(trackingParticle);     
        if (jpos != lmap.end())
          ++jpos->second; 
        else 
          lmap.insert(std::make_pair(trackingParticle, 1));
      }
    }
  }
  // now copy the map to returnValue
  for (auto ip = lmap.begin(); ip != lmap.end(); ++ip) {
    returnValue.push_back(std::make_pair(ip->first, ip->second));
  }
  return returnValue;
}
static bool QuickTrackAssociatorByHits::clusterTPAssociationListGreater ( std::pair< OmniClusterRef, TrackingParticleRef i,
std::pair< OmniClusterRef, TrackingParticleRef j 
) [inline, static, private]

Definition at line 102 of file QuickTrackAssociatorByHits.h.

Referenced by associateTrackByCluster(), getDoubleCount(), and prepareCluster2TPMap().

{ return (i.first.rawIndex()>j.first.rawIndex()); }
template<typename iter >
std::vector< std::pair< QuickTrackAssociatorByHits::SimTrackIdentifiers, size_t > > QuickTrackAssociatorByHits::getAllSimTrackIdentifiers ( 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 483 of file QuickTrackAssociatorByHits.cc.

References TrackerHitAssociator::associateHitId(), end, getHitFromIter(), and pHitAssociator_.

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
  //iter tRHIterBeginEnd = getTRHIterBeginEnd( pTrack );
  for( iter iRecHit=begin; iRecHit!=end; ++iRecHit )
  {
    if( getHitFromIter(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( *(getHitFromIter(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;
}
template<typename iter >
int QuickTrackAssociatorByHits::getDoubleCount ( iter  begin,
iter  end,
TrackingParticleRef  associatedTrackingParticle 
) const [private]

This method was copied almost verbatim from the standard TrackAssociatorByHits.

Definition at line 540 of file QuickTrackAssociatorByHits.cc.

References TrackerHitAssociator::associateHitId(), clusterTPAssociationListGreater(), spr::find(), getHitFromIter(), getMatchedClusters(), pCluster2TPList_, pHitAssociator_, and useClusterTPAssociation_.

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

{
  // 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( iter iHit=startIterator; iHit != endIterator; iHit++ )
    {
      int idcount=0;

      if (useClusterTPAssociation_) {
        std::vector<OmniClusterRef> oClusters = getMatchedClusters(iHit, iHit+1);//only for the cluster being checked
        for (std::vector<OmniClusterRef>::const_iterator it = oClusters.begin(); it != oClusters.end(); ++it) {   
          std::pair<OmniClusterRef, TrackingParticleRef> clusterTPpairWithDummyTP(*it,TrackingParticleRef());//TP is dummy: for clusterTPAssociationListGreater sorting only the cluster is needed
          auto range = std::equal_range(pCluster2TPList_.begin(), pCluster2TPList_.end(), clusterTPpairWithDummyTP, clusterTPAssociationListGreater);
          if(range.first != range.second) {
            for(auto ip = range.first; ip != range.second; ++ip) {
              const TrackingParticleRef trackingParticle = (ip->second);
              if (associatedTrackingParticle==trackingParticle) {
                idcount++;
              }
            }
          }
        }
      } else {
        SimTrackIdsDC.clear();
        pHitAssociator_->associateHitId( *(getHitFromIter(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;
}
const TrackingRecHit* QuickTrackAssociatorByHits::getHitFromIter ( trackingRecHit_iterator  iter) const [inline, private]

Definition at line 139 of file QuickTrackAssociatorByHits.h.

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

                                                                                 {
          return &(**iter);
        }
const TrackingRecHit* QuickTrackAssociatorByHits::getHitFromIter ( TrackingRecHitCollection::const_iterator  iter) const [inline, private]

Definition at line 143 of file QuickTrackAssociatorByHits.h.

                                                                                                {
          return &(*iter);
        }
template<typename iter >
std::vector< OmniClusterRef > QuickTrackAssociatorByHits::getMatchedClusters ( iter  begin,
iter  end 
) const [private]

Definition at line 437 of file QuickTrackAssociatorByHits.cc.

References end, TrackingRecHit::geographicalId(), getHitFromIter(), TrackingRecHit::isValid(), PixelSubdetector::PixelBarrel, PixelSubdetector::PixelEndcap, DetId::subdetId(), SiStripDetId::TEC, SiStripDetId::TIB, SiStripDetId::TID, and SiStripDetId::TOB.

Referenced by associateTrackByCluster(), and getDoubleCount().

{
  std::vector<OmniClusterRef> returnValue;
  for (iter iRecHit = begin; iRecHit != end; ++iRecHit) {
    const TrackingRecHit* rhit = getHitFromIter(iRecHit);
    if (rhit->isValid()) {
      int subdetid = rhit->geographicalId().subdetId();
      if (subdetid==PixelSubdetector::PixelBarrel||subdetid==PixelSubdetector::PixelEndcap) {
        const SiPixelRecHit* pRHit = dynamic_cast<const SiPixelRecHit*>(rhit);
        if (!pRHit->cluster().isNonnull()) 
          edm::LogError("TrackAssociator") << ">>> RecHit does not have an associated cluster!" << " file: " << __FILE__ << " line: " << __LINE__;
        returnValue.push_back(pRHit->omniClusterRef());
      }
      else if (subdetid==SiStripDetId::TIB||subdetid==SiStripDetId::TOB||subdetid==SiStripDetId::TID||subdetid==SiStripDetId::TEC) {
        const std::type_info &tid = typeid(*rhit);
        if (tid == typeid(SiStripMatchedRecHit2D)) {
          const SiStripMatchedRecHit2D* sMatchedRHit = dynamic_cast<const SiStripMatchedRecHit2D*>(rhit);
          if (!sMatchedRHit->monoHit().cluster().isNonnull() || !sMatchedRHit->stereoHit().cluster().isNonnull())  
            edm::LogError("TrackAssociator") << ">>> RecHit does not have an associated cluster!" << " file: " << __FILE__ << " line: " << __LINE__;
          returnValue.push_back(sMatchedRHit->monoClusterRef()); 
          returnValue.push_back(sMatchedRHit->stereoClusterRef()); 
        }
        else if (tid == typeid(SiStripRecHit2D)) {
          const SiStripRecHit2D* sRHit = dynamic_cast<const SiStripRecHit2D*>(rhit);
          if (!sRHit->cluster().isNonnull()) 
            edm::LogError("TrackAssociator") << ">>> RecHit does not have an associated cluster!" << " file: " << __FILE__ << " line: " << __LINE__;
          returnValue.push_back(sRHit->omniClusterRef());
        }
        else if (tid == typeid(SiStripRecHit1D)) {
          const SiStripRecHit1D* sRHit = dynamic_cast<const SiStripRecHit1D*>(rhit);
          if (!sRHit->cluster().isNonnull()) 
            edm::LogError("TrackAssociator") << ">>> RecHit does not have an associated cluster!" << " file: " << __FILE__ << " line: " << __LINE__;
          returnValue.push_back(sRHit->omniClusterRef());
        }
        else {
          edm::LogError("TrackAssociator") << ">>> getMatchedClusters: TrackingRecHit not associated to any SiStripCluster! subdetid = " << subdetid;
        }
      }
      else {
        edm::LogError("TrackAssociator") << ">>> getMatchedClusters: TrackingRecHit not associated to any cluster! subdetid = " << subdetid;
      }
    }
  }
  return returnValue;
}
void QuickTrackAssociatorByHits::initialiseHitAssociator ( const edm::Event event) const [private]

Definition at line 588 of file QuickTrackAssociatorByHits.cc.

References hitAssociatorParameters_, pEventForWhichAssociatorIsValid_, and pHitAssociator_.

Referenced by associateRecoToSim(), associateSimToReco(), and prepareCluster2TPMap().

{
        // 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 97 of file QuickTrackAssociatorByHits.cc.

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

{
        // 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_;
        useClusterTPAssociation_ = otherAssociator.useClusterTPAssociation_,
        cluster2TPSrc_ = otherAssociator.cluster2TPSrc_;
        simToRecoDenominator_=otherAssociator.simToRecoDenominator_;
        pTrackCollectionHandle_=otherAssociator.pTrackCollectionHandle_;
        pTrackCollection_=otherAssociator.pTrackCollection_;
        pTrackingParticleCollectionHandle_=otherAssociator.pTrackingParticleCollectionHandle_;
        pTrackingParticleCollection_=otherAssociator.pTrackingParticleCollection_;

        return *this;
}
void QuickTrackAssociatorByHits::prepareCluster2TPMap ( const edm::Event pEvent) const

Definition at line 367 of file QuickTrackAssociatorByHits.cc.

References cluster2TPSrc_, clusterTPAssociationListGreater(), edm::Event::getByLabel(), initialiseHitAssociator(), edm::HandleBase::isValid(), pCluster2TPList_, edm::Handle< T >::product(), python::multivaluedict::sort(), and useClusterTPAssociation_.

Referenced by associateRecoToSim(), and associateSimToReco().

{
  //get the Cluster2TPList
  edm::Handle<ClusterTPAssociationList> pCluster2TPListH;
  pEvent->getByLabel(cluster2TPSrc_, pCluster2TPListH);
  if (pCluster2TPListH.isValid()) {
    pCluster2TPList_ = *(pCluster2TPListH.product());
    //make sure it is properly sorted
    std::sort(pCluster2TPList_.begin(), pCluster2TPList_.end(), clusterTPAssociationListGreater);
  } else {
    edm::LogInfo("TrackAssociator") << "ClusterTPAssociationList with label "<<cluster2TPSrc_<<" not found. Using DigiSimLink based associator";
    initialiseHitAssociator( pEvent );
    useClusterTPAssociation_ = false;
  }
}
static bool QuickTrackAssociatorByHits::tpIntPairGreater ( std::pair< edm::Ref< TrackingParticleCollection >, size_t >  i,
std::pair< edm::Ref< TrackingParticleCollection >, size_t >  j 
) [inline, static, private]

Definition at line 103 of file QuickTrackAssociatorByHits.h.

References i, and j.

{ return (i.first.key()>j.first.key()); }
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 523 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 197 of file QuickTrackAssociatorByHits.h.

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

Definition at line 152 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 179 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 172 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 193 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 186 of file QuickTrackAssociatorByHits.h.

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