28 template<
class T_element>
31 return collection.
size();
34 template<
class T_element>
37 return hCollection->size();
40 template<
class T_element>
43 return collection.
size();
48 return &*trackCollection[
index];
53 return &(*pTrackCollection.product())[index];
58 return &(*pCollection.
product())[index];
63 return &*collection[
index];
68 return trackCollection[
index];
83 return collection[
index];
90 absoluteNumberOfHits_( config.getParameter<bool>(
"AbsoluteNumberOfHits" ) ),
91 qualitySimToReco_( config.getParameter<double>(
"Quality_SimToReco" ) ),
92 puritySimToReco_( config.getParameter<double>(
"Purity_SimToReco" ) ),
93 cutRecoToSim_( config.getParameter<double>(
"Cut_RecoToSim" ) ),
94 threeHitTracksAreSpecial_( config.getParameter<bool>(
"ThreeHitTracksAreSpecial" ) ),
95 useClusterTPAssociation_( config.getParameter<bool>(
"useClusterTPAssociation" ) ),
96 cluster2TPSrc_( config.getParameter < edm::InputTag > (
"cluster2TPSrc") )
105 else throw cms::Exception(
"QuickTrackAssociatorByHits" ) <<
"SimToRecoDenominator not specified as sim or reco";
121 bool useGrouped, useSplitting;
123 else useGrouped=
true;
125 if( config.
exists(
"UseSplitting") ) useSplitting=config.
getParameter<
bool>(
"UseSplitting");
126 else useSplitting=
true;
130 if( !(useGrouped && useSplitting) )
132 edm::LogWarning(
"QuickTrackAssociatorByHits") <<
"UseGrouped and/or UseSplitting has been set to false, but this associator ignores that setting.";
144 std::unique_ptr<ClusterTPAssociationList> pClusterToTPMap;
145 std::unique_ptr<TrackerHitAssociator> pHitAssociator;
157 std::unique_ptr<ClusterTPAssociationList> pClusterToTPMap;
158 std::unique_ptr<TrackerHitAssociator> pHitAssociator;
170 std::unique_ptr<ClusterTPAssociationList> pClusterToTPMap;
171 std::unique_ptr<TrackerHitAssociator> pHitAssociator;
183 std::unique_ptr<ClusterTPAssociationList> pClusterToTPMap;
184 std::unique_ptr<TrackerHitAssociator> pHitAssociator;
194 template<
class T_TrackCollection,
class T_TrackingParticleCollection,
class T_hitOrClusterAssociator>
199 size_t collectionSize=::collectionSize(trackCollection);
201 for(
size_t i=0;
i < collectionSize; ++
i )
203 const reco::Track* pTrack=::getTrackAt(trackCollection,
i);
206 std::vector < std::pair<edm::Ref<TrackingParticleCollection>,
size_t> > trackingParticleQualityPairs=
associateTrack( hitOrClusterAssociator, trackingParticleCollection, pTrack->
recHitsBegin(), pTrack->
recHitsEnd() );
210 trackingParticleQualityPairs.begin(); iTrackingParticleQualityPair != trackingParticleQualityPairs.end();
211 ++iTrackingParticleQualityPair )
214 size_t numberOfSharedHits=iTrackingParticleQualityPair->second;
215 size_t numberOfValidTrackHits=pTrack->
found();
217 if( numberOfSharedHits == 0 )
continue;
220 if(
abs( trackingParticleRef->pdgId() ) == 11 && (trackingParticleRef->g4Track_end() - trackingParticleRef->g4Track_begin()) > 1 )
227 else if( numberOfValidTrackHits != 0 ) quality=
228 (
static_cast<double>( numberOfSharedHits ) / static_cast<double>( numberOfValidTrackHits ));
233 returnValue.
insert( ::getRefToTrackAt(trackCollection,
i), std::make_pair( trackingParticleRef, quality ) );
240 template<
class T_TrackCollection,
class T_TrackingParticleCollection,
class T_hitOrClusterAssociator>
245 size_t collectionSize=::collectionSize(trackCollection);
247 for(
size_t i=0;
i<collectionSize; ++
i )
249 const reco::Track* pTrack=::getTrackAt(trackCollection,
i);
252 std::vector < std::pair<edm::Ref<TrackingParticleCollection>,
size_t> > trackingParticleQualityPairs=
associateTrack( hitOrClusterAssociator, trackingParticleCollection, pTrack->
recHitsBegin(), pTrack->
recHitsEnd() );
256 iTrackingParticleQualityPair!=trackingParticleQualityPairs.end(); ++iTrackingParticleQualityPair )
259 size_t numberOfSharedHits=iTrackingParticleQualityPair->second;
260 size_t numberOfValidTrackHits=pTrack->
found();
261 size_t numberOfSimulatedHits=0;
263 if( numberOfSharedHits==0 )
continue;
271 numberOfSimulatedHits=trackingParticleRef->numberOfTrackerHits();
275 if (
abs(trackingParticleRef->pdgId())==11 && (trackingParticleRef->g4Track_end() - trackingParticleRef->g4Track_begin()) > 1 )
280 double purity=
static_cast<double>(numberOfSharedHits)/static_cast<double>(numberOfValidTrackHits);
283 else if(
simToRecoDenominator_==
denomsim && numberOfSimulatedHits != 0 ) quality=
static_cast<double>(numberOfSharedHits)/static_cast<double>(numberOfSimulatedHits);
290 returnValue.
insert( trackingParticleRef, std::make_pair( ::getRefToTrackAt(trackCollection,
i), quality ) );
301 std::vector< std::pair<edm::Ref<TrackingParticleCollection>,
size_t> > returnValue;
306 std::vector< std::pair<SimTrackIdentifiers,size_t> > hitIdentifiers=
getAllSimTrackIdentifiers( hitAssociator, begin, end );
309 size_t collectionSize=::collectionSize(trackingParticles);
311 for(
size_t i=0;
i<collectionSize; ++
i )
313 const TrackingParticle* pTrackingParticle=getTrackingParticleAt( trackingParticles,
i );
318 size_t numberOfAssociatedHits=0;
321 for( std::vector< std::pair<SimTrackIdentifiers,size_t> >::const_iterator iIdentifierCountPair=hitIdentifiers.begin(); iIdentifierCountPair!=hitIdentifiers.end(); ++iIdentifierCountPair )
326 if( numberOfAssociatedHits>0 )
328 returnValue.push_back( std::make_pair( getRefToTrackingParticleAt(trackingParticles,
i), numberOfAssociatedHits ) );
341 if( pCluster2TPListH.
isValid() )
347 pHitAssociator.reset();
353 <<
" not found. Using DigiSimLink based associator";
363 pClusterToTPMap.reset();
374 std::vector < std::pair<edm::Ref<TrackingParticleCollection>,
size_t> > returnValue;
375 if( clusterToTPMap.empty() )
return returnValue;
383 std::map < TrackingParticleRef, size_t > lmap;
384 for( std::vector<OmniClusterRef>::const_iterator it=oClusters.begin(); it != oClusters.end(); ++it )
387 std::pair < OmniClusterRef, TrackingParticleRef > clusterTPpairWithDummyTP( *it,
TrackingParticleRef() );
389 if( range.first != range.second )
391 for(
auto ip=range.first; ip != range.second; ++ip )
397 if( trackingParticle->numberOfHits() == 0 )
continue;
412 auto jpos=lmap.find( trackingParticle );
413 if( jpos != lmap.end() ) ++jpos->second;
414 else lmap.insert( std::make_pair( trackingParticle, 1 ) );
419 for(
auto ip=lmap.begin(); ip != lmap.end(); ++ip )
421 returnValue.push_back( std::make_pair( ip->first, ip->second ) );
428 std::vector<OmniClusterRef> returnValue;
429 for (
iter iRecHit = begin; iRecHit !=
end; ++iRecHit) {
436 edm::LogError(
"TrackAssociator") <<
">>> RecHit does not have an associated cluster!" <<
" file: " << __FILE__ <<
" line: " << __LINE__;
440 const std::type_info &tid =
typeid(*rhit);
444 edm::LogError(
"TrackAssociator") <<
">>> RecHit does not have an associated cluster!" <<
" file: " << __FILE__ <<
" line: " << __LINE__;
451 edm::LogError(
"TrackAssociator") <<
">>> RecHit does not have an associated cluster!" <<
" file: " << __FILE__ <<
" line: " << __LINE__;
457 edm::LogError(
"TrackAssociator") <<
">>> RecHit does not have an associated cluster!" <<
" file: " << __FILE__ <<
" line: " << __LINE__;
462 if ( thit.isProjected() ) {
464 edm::LogError(
"TrackAssociator") <<
">>> getMatchedClusters: TrackingRecHit not associated to any SiStripCluster! subdetid = " << subdetid;
469 edm::LogError(
"TrackAssociator") <<
">>> getMatchedClusters: TrackingRecHit not associated to any cluster! subdetid = " << subdetid;
479 std::vector < std::pair<SimTrackIdentifiers,size_t> > returnValue;
481 std::vector<SimTrackIdentifiers> simTrackIdentifiers;
484 for(
iter iRecHit=begin; iRecHit !=
end; ++iRecHit )
488 simTrackIdentifiers.clear();
494 for( std::vector<SimTrackIdentifiers>::const_iterator iIdentifier=simTrackIdentifiers.begin(); iIdentifier != simTrackIdentifiers.end();
497 std::vector<std::pair<SimTrackIdentifiers,size_t> >::iterator iIdentifierCountPair;
498 for( iIdentifierCountPair=returnValue.begin(); iIdentifierCountPair != returnValue.end(); ++iIdentifierCountPair )
500 if( iIdentifierCountPair->first.first == iIdentifier->first && iIdentifierCountPair->first.second == iIdentifier->second )
503 ++iIdentifierCountPair->second;
507 if( iIdentifierCountPair == returnValue.end() ) returnValue.push_back( std::make_pair( *iIdentifier, 1 ) );
518 for( std::vector<SimTrack>::const_iterator iSimTrack=pTrackingParticle->
g4Track_begin(); iSimTrack != pTrackingParticle->
g4Track_end();
522 if( iSimTrack->eventId() == identifier.second && iSimTrack->trackId() == identifier.first )
539 std::vector < SimHitIdpr > SimTrackIdsDC;
541 for(
iter iHit=startIterator; iHit != endIterator; iHit++ )
545 SimTrackIdsDC.clear();
547 if( SimTrackIdsDC.size() > 1 )
552 if(
find( SimTrackIdsDC.begin(), SimTrackIdsDC.end(),
SimHitIdpr( ( *g4T).trackId(), SimTrackIdsDC.begin()->second ) )
553 != SimTrackIdsDC.end() )
559 if( idcount > 1 ) doubleCount+=(idcount - 1);
571 std::vector < SimHitIdpr > SimTrackIdsDC;
573 for(
iter iHit=startIterator; iHit != endIterator; iHit++ )
578 for( std::vector<OmniClusterRef>::const_iterator it=oClusters.begin(); it != oClusters.end(); ++it )
580 std::pair<OmniClusterRef,TrackingParticleRef> clusterTPpairWithDummyTP( *it,
TrackingParticleRef() );
582 if( range.first != range.second )
584 for(
auto ip=range.first; ip != range.second; ++ip )
587 if( associatedTrackingParticle == trackingParticle )
595 if( idcount > 1 ) doubleCount+=(idcount - 1);
605 edm::LogVerbatim(
"TrackAssociator" ) <<
"Starting TrackAssociatorByHits::associateRecoToSim - #seeds=" << pSeedCollectionHandle_->size()
606 <<
" #TPs=" << trackingParticleCollectionHandle->size();
613 std::unique_ptr<ClusterTPAssociationList> pClusterToTPList;
614 std::unique_ptr<TrackerHitAssociator> pTrackerHitAssociator;
624 size_t collectionSize=pSeedCollectionHandle_->
size();
626 for(
size_t i=0;
i < collectionSize; ++
i )
631 std::vector < std::pair<edm::Ref<TrackingParticleCollection>,
size_t> > trackingParticleQualityPairs=
634 trackingParticleQualityPairs.begin(); iTrackingParticleQualityPair != trackingParticleQualityPairs.end();
635 ++iTrackingParticleQualityPair )
638 size_t numberOfSharedHits=iTrackingParticleQualityPair->second;
639 size_t numberOfValidTrackHits=pSeed->
recHits().second - pSeed->
recHits().first;
641 if( numberOfSharedHits == 0 )
continue;
644 if(
abs( trackingParticleRef->pdgId() ) == 11 && (trackingParticleRef->g4Track_end() - trackingParticleRef->g4Track_begin()) > 1 )
646 if( pClusterToTPList!=
nullptr ) numberOfSharedHits-=
getDoubleCount( *pClusterToTPList, pSeed->
recHits().first, pSeed->
recHits().second, trackingParticleRef );
647 else numberOfSharedHits-=
getDoubleCount( *pTrackerHitAssociator, pSeed->
recHits().first, pSeed->
recHits().second, trackingParticleRef );
652 else if( numberOfValidTrackHits != 0 ) quality=
653 (
static_cast<double>( numberOfSharedHits ) / static_cast<double>( numberOfValidTrackHits ));
663 LogTrace(
"TrackAssociator" ) <<
"% of Assoc Seeds=" << ((double)returnValue.
size()) / ((
double)pSeedCollectionHandle_->size());
673 edm::LogVerbatim(
"TrackAssociator" ) <<
"Starting TrackAssociatorByHits::associateSimToReco - #seeds=" << pSeedCollectionHandle_->size()
674 <<
" #TPs=" << trackingParticleCollectionHandle->size();
681 std::unique_ptr<ClusterTPAssociationList> pClusterToTPList;
682 std::unique_ptr<TrackerHitAssociator> pTrackerHitAssociator;
692 size_t collectionSize=pSeedCollectionHandle_->
size();
694 for(
size_t i=0;
i < collectionSize; ++
i )
699 std::vector < std::pair<edm::Ref<TrackingParticleCollection>,
size_t> > trackingParticleQualityPairs=
702 trackingParticleQualityPairs.begin(); iTrackingParticleQualityPair != trackingParticleQualityPairs.end();
703 ++iTrackingParticleQualityPair )
706 size_t numberOfSharedHits=iTrackingParticleQualityPair->second;
707 size_t numberOfValidTrackHits=pSeed->
recHits().second - pSeed->
recHits().first;
708 size_t numberOfSimulatedHits=0;
710 if( numberOfSharedHits == 0 )
continue;
713 if(
abs( trackingParticleRef->pdgId() ) == 11 && (trackingParticleRef->g4Track_end() - trackingParticleRef->g4Track_begin()) > 1 )
715 if( pClusterToTPList!=
nullptr ) numberOfSharedHits-=
getDoubleCount( *pClusterToTPList, pSeed->
recHits().first, pSeed->
recHits().second, trackingParticleRef );
716 else numberOfSharedHits-=
getDoubleCount( *pTrackerHitAssociator, pSeed->
recHits().first, pSeed->
recHits().second, trackingParticleRef );
725 numberOfSimulatedHits=trackingParticleRef->numberOfTrackerHits();
728 double purity=
static_cast<double>( numberOfSharedHits ) / static_cast<double>( numberOfValidTrackHits );
732 / static_cast<double>( numberOfSimulatedHits );
745 LogTrace(
"TrackAssociator") <<
"% of Assoc TPs=" << ((double)returnValue.
size())/((
double)trackingParticleCollectionHandle->size());
ClusterRef cluster() const
reco::SimToRecoCollection associateSimToRecoImplementation(T_TrackCollection trackCollection, T_TrackingParticleCollection trackingParticleCollection, T_hitOrClusterAssociator hitOrClusterAssociator) const
The method that does the work for both overloads of associateSimToReco.
T getParameter(std::string const &) const
const TrackingRecHit * getHitFromIter(trackingRecHit_iterator iter) const
bool isNonnull() const
Checks for non-null.
static bool clusterTPAssociationListGreater(std::pair< OmniClusterRef, TrackingParticleRef > i, std::pair< OmniClusterRef, TrackingParticleRef > j)
std::vector< TrackingParticle > TrackingParticleCollection
bool trackingParticleContainsIdentifier(const TrackingParticle *pTrackingParticle, const SimTrackIdentifiers &identifier) const
Returns true if the supplied TrackingParticle has the supplied g4 track identifiers.
g4t_iterator g4Track_begin() const
OmniClusterRef const & stereoClusterRef() const
virtual 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 override
compare reco to sim the handle of reco::Track and TrackingParticle collections
bool exists(std::string const ¶meterName) const
checks if a parameter exists
QuickTrackAssociatorByHits(const edm::ParameterSet &config)
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
std::vector< std::pair< edm::Ref< TrackingParticleCollection >, size_t > > associateTrack(const TrackerHitAssociator &hitAssociator, T_TPCollection trackingParticles, iter begin, iter end) const
Returns the TrackingParticle that has the most associated hits to the given track.
std::pair< uint32_t, EncodedEventId > SimTrackIdentifiers
This is enough information to uniquely identify a sim track.
bool absoluteNumberOfHits_
void post_insert()
post insert action
bool threeHitTracksAreSpecial_
void addParameter(std::string const &name, T const &value)
std::vector< std::pair< OmniClusterRef, TrackingParticleRef > > ClusterTPAssociationList
virtual 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 override
compare reco to sim the handle of reco::Track and TrackingParticle collections
Abs< T >::type abs(const T &t)
ClusterRef cluster() const
trackingRecHit_iterator recHitsBegin() const
Iterator to first hit on the track.
OmniClusterRef const & monoClusterRef() const
int subdetId() const
get the contents of the subdetector field (not cast into any detector's numbering enum) ...
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
std::vector< SimTrack >::const_iterator g4t_iterator
OmniClusterRef const & omniClusterRef() const
std::pair< uint32_t, EncodedEventId > SimHitIdpr
SiStripRecHit2D stereoHit() const
size_type size() const
map size
T const * product() const
void insert(const key_type &k, const data_type &v)
insert an association
void prepareEitherHitAssociatorOrClusterToTPMap(const edm::Event *pEvent, std::unique_ptr< ClusterTPAssociationList > &pClusterToTPMap, std::unique_ptr< TrackerHitAssociator > &pHitAssociator) const
creates either a ClusterTPAssociationList OR a TrackerHitAssociator and stores it in the provided uni...
edm::ParameterSet hitAssociatorParameters_
int getDoubleCount(const TrackerHitAssociator &hitAssociator, iter begin, iter end, TrackingParticleRef associatedTrackingParticle) const
This method was copied almost verbatim from the standard TrackAssociatorByHits.
bool useClusterTPAssociation_
ClusterRef cluster() const
int numberOfHits() const
Gives the total number of hits, including muon hits. Hits on overlaps in the same layer count separat...
std::vector< std::pair< SimTrackIdentifiers, size_t > > getAllSimTrackIdentifiers(const TrackerHitAssociator &hitAssociator, iter begin, iter end) const
Returns a vector of pairs where first is a SimTrackIdentifiers (see typedef above) and second is the ...
SiStripRecHit2D monoHit() const
std::vector< SimHitIdpr > associateHitId(const TrackingRecHit &thit) const
std::vector< OmniClusterRef > getMatchedClusters(iter begin, iter end) const
unsigned short found() const
Number of valid hits on track.
size_type size() const
Size of the RefVector.
reco::RecoToSimCollection associateRecoToSimImplementation(T_TrackCollection trackCollection, T_TrackingParticleCollection trackingParticleCollection, T_hitOrClusterAssociator hitOrClusterAssociator) const
The method that does the work for both overloads of associateRecoToSim.
Monte Carlo truth information used for tracking validation.
SimToRecoDenomType simToRecoDenominator_
DetId geographicalId() const
~QuickTrackAssociatorByHits()
g4t_iterator g4Track_end() const
void setup(std::vector< TH2F > &depth, std::string name, std::string units="")
edm::Ref< TrackingParticleCollection > TrackingParticleRef
edm::InputTag cluster2TPSrc_
trackingRecHit_iterator recHitsEnd() const
Iterator to last hit on the track.