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];
89 std::shared_ptr<const ClusterTPAssociationList> clusterToTPMap,
91 bool absoluteNumberOfHits,
92 double qualitySimToReco,
93 double puritySimToReco,
95 bool threeHitTracksAreSpecial,
97 hitAssociator_(std::move(hitAssoc)),
98 clusterToTPMap_(std::move(clusterToTPMap)),
99 qualitySimToReco_(qualitySimToReco),
100 puritySimToReco_(puritySimToReco),
101 cutRecoToSim_(cutRecoToSim),
102 simToRecoDenominator_(simToRecoDenominator) ,
103 threeHitTracksAreSpecial_(threeHitTracksAreSpecial),
104 absoluteNumberOfHits_(absoluteNumberOfHits)
141 template<
class T_TrackCollection,
class T_TrackingParticleCollection,
class T_hitOrClusterAssociator>
146 size_t collectionSize=::collectionSize(trackCollection);
148 for(
size_t i=0;
i < collectionSize; ++
i )
150 const reco::Track* pTrack=::getTrackAt(trackCollection,
i);
153 std::vector < std::pair<edm::Ref<TrackingParticleCollection>,
size_t> > trackingParticleQualityPairs=
associateTrack( hitOrClusterAssociator, trackingParticleCollection, pTrack->
recHitsBegin(), pTrack->
recHitsEnd() );
157 trackingParticleQualityPairs.begin(); iTrackingParticleQualityPair != trackingParticleQualityPairs.end();
158 ++iTrackingParticleQualityPair )
161 size_t numberOfSharedHits=iTrackingParticleQualityPair->second;
162 size_t numberOfValidTrackHits=pTrack->
found();
164 if( numberOfSharedHits == 0 )
continue;
167 if(
abs( trackingParticleRef->pdgId() ) == 11 && (trackingParticleRef->g4Track_end() - trackingParticleRef->g4Track_begin()) > 1 )
174 else if( numberOfValidTrackHits != 0 ) quality=
175 (
static_cast<double>( numberOfSharedHits ) / static_cast<double>( numberOfValidTrackHits ));
180 returnValue.
insert( ::getRefToTrackAt(trackCollection,
i), std::make_pair( trackingParticleRef, quality ) );
187 template<
class T_TrackCollection,
class T_TrackingParticleCollection,
class T_hitOrClusterAssociator>
192 size_t collectionSize=::collectionSize(trackCollection);
194 for(
size_t i=0;
i<collectionSize; ++
i )
196 const reco::Track* pTrack=::getTrackAt(trackCollection,
i);
199 std::vector < std::pair<edm::Ref<TrackingParticleCollection>,
size_t> > trackingParticleQualityPairs=
associateTrack( hitOrClusterAssociator, trackingParticleCollection, pTrack->
recHitsBegin(), pTrack->
recHitsEnd() );
203 iTrackingParticleQualityPair!=trackingParticleQualityPairs.end(); ++iTrackingParticleQualityPair )
206 size_t numberOfSharedHits=iTrackingParticleQualityPair->second;
207 size_t numberOfValidTrackHits=pTrack->
found();
208 size_t numberOfSimulatedHits=0;
210 if( numberOfSharedHits==0 )
continue;
218 numberOfSimulatedHits=trackingParticleRef->numberOfTrackerHits();
222 if (
abs(trackingParticleRef->pdgId())==11 && (trackingParticleRef->g4Track_end() - trackingParticleRef->g4Track_begin()) > 1 )
227 double purity=
static_cast<double>(numberOfSharedHits)/static_cast<double>(numberOfValidTrackHits);
230 else if(
simToRecoDenominator_==
denomsim && numberOfSimulatedHits != 0 ) quality=
static_cast<double>(numberOfSharedHits)/static_cast<double>(numberOfSimulatedHits);
237 returnValue.
insert( trackingParticleRef, std::make_pair( ::getRefToTrackAt(trackCollection,
i), quality ) );
248 std::vector< std::pair<edm::Ref<TrackingParticleCollection>,
size_t> > returnValue;
253 std::vector< std::pair<SimTrackIdentifiers,size_t> > hitIdentifiers=
getAllSimTrackIdentifiers( hitAssociator, begin, end );
256 size_t collectionSize=::collectionSize(trackingParticles);
258 for(
size_t i=0;
i<collectionSize; ++
i )
260 const TrackingParticle* pTrackingParticle=getTrackingParticleAt( trackingParticles,
i );
265 size_t numberOfAssociatedHits=0;
268 for( std::vector< std::pair<SimTrackIdentifiers,size_t> >::const_iterator iIdentifierCountPair=hitIdentifiers.begin(); iIdentifierCountPair!=hitIdentifiers.end(); ++iIdentifierCountPair )
273 if( numberOfAssociatedHits>0 )
275 returnValue.push_back( std::make_pair( getRefToTrackingParticleAt(trackingParticles,
i), numberOfAssociatedHits ) );
289 std::vector < std::pair<edm::Ref<TrackingParticleCollection>,
size_t> > returnValue;
290 if( clusterToTPMap.empty() )
return returnValue;
298 std::map < TrackingParticleRef, size_t > lmap;
299 for( std::vector<OmniClusterRef>::const_iterator it=oClusters.begin(); it != oClusters.end(); ++it )
302 std::pair < OmniClusterRef, TrackingParticleRef > clusterTPpairWithDummyTP( *it,
TrackingParticleRef() );
304 if( range.first != range.second )
306 for(
auto ip=range.first; ip != range.second; ++ip )
312 if( trackingParticle->numberOfHits() == 0 )
continue;
327 auto jpos=lmap.find( trackingParticle );
328 if( jpos != lmap.end() ) ++jpos->second;
329 else lmap.insert( std::make_pair( trackingParticle, 1 ) );
334 for(
auto ip=lmap.begin(); ip != lmap.end(); ++ip )
336 returnValue.push_back( std::make_pair( ip->first, ip->second ) );
343 std::vector<OmniClusterRef> returnValue;
344 for (
iter iRecHit = begin; iRecHit !=
end; ++iRecHit) {
351 edm::LogError(
"TrackAssociator") <<
">>> RecHit does not have an associated cluster!" <<
" file: " << __FILE__ <<
" line: " << __LINE__;
355 const std::type_info &tid =
typeid(*rhit);
359 edm::LogError(
"TrackAssociator") <<
">>> RecHit does not have an associated cluster!" <<
" file: " << __FILE__ <<
" line: " << __LINE__;
366 edm::LogError(
"TrackAssociator") <<
">>> RecHit does not have an associated cluster!" <<
" file: " << __FILE__ <<
" line: " << __LINE__;
372 edm::LogError(
"TrackAssociator") <<
">>> RecHit does not have an associated cluster!" <<
" file: " << __FILE__ <<
" line: " << __LINE__;
377 if ( thit.isProjected() ) {
379 edm::LogError(
"TrackAssociator") <<
">>> getMatchedClusters: TrackingRecHit not associated to any SiStripCluster! subdetid = " << subdetid;
384 edm::LogError(
"TrackAssociator") <<
">>> getMatchedClusters: TrackingRecHit not associated to any cluster! subdetid = " << subdetid;
394 std::vector < std::pair<SimTrackIdentifiers,size_t> > returnValue;
396 std::vector<SimTrackIdentifiers> simTrackIdentifiers;
399 for(
iter iRecHit=begin; iRecHit !=
end; ++iRecHit )
403 simTrackIdentifiers.clear();
409 for( std::vector<SimTrackIdentifiers>::const_iterator iIdentifier=simTrackIdentifiers.begin(); iIdentifier != simTrackIdentifiers.end();
412 std::vector<std::pair<SimTrackIdentifiers,size_t> >::iterator iIdentifierCountPair;
413 for( iIdentifierCountPair=returnValue.begin(); iIdentifierCountPair != returnValue.end(); ++iIdentifierCountPair )
415 if( iIdentifierCountPair->first.first == iIdentifier->first && iIdentifierCountPair->first.second == iIdentifier->second )
418 ++iIdentifierCountPair->second;
422 if( iIdentifierCountPair == returnValue.end() ) returnValue.push_back( std::make_pair( *iIdentifier, 1 ) );
433 for( std::vector<SimTrack>::const_iterator iSimTrack=pTrackingParticle->
g4Track_begin(); iSimTrack != pTrackingParticle->
g4Track_end();
437 if( iSimTrack->eventId() == identifier.second && iSimTrack->trackId() == identifier.first )
454 std::vector < SimHitIdpr > SimTrackIdsDC;
456 for(
iter iHit=startIterator; iHit != endIterator; iHit++ )
460 SimTrackIdsDC.clear();
462 if( SimTrackIdsDC.size() > 1 )
467 if(
find( SimTrackIdsDC.begin(), SimTrackIdsDC.end(),
SimHitIdpr( ( *g4T).trackId(), SimTrackIdsDC.begin()->second ) )
468 != SimTrackIdsDC.end() )
474 if( idcount > 1 ) doubleCount+=(idcount - 1);
486 std::vector < SimHitIdpr > SimTrackIdsDC;
488 for(
iter iHit=startIterator; iHit != endIterator; iHit++ )
493 for( std::vector<OmniClusterRef>::const_iterator it=oClusters.begin(); it != oClusters.end(); ++it )
495 std::pair<OmniClusterRef,TrackingParticleRef> clusterTPpairWithDummyTP( *it,
TrackingParticleRef() );
497 if( range.first != range.second )
499 for(
auto ip=range.first; ip != range.second; ++ip )
502 if( associatedTrackingParticle == trackingParticle )
510 if( idcount > 1 ) doubleCount+=(idcount - 1);
520 edm::LogVerbatim(
"TrackAssociator" ) <<
"Starting TrackAssociatorByHitsImpl::associateRecoToSim - #seeds=" << pSeedCollectionHandle_->size()
521 <<
" #TPs=" << trackingParticleCollectionHandle->size();
525 size_t collectionSize=pSeedCollectionHandle_->
size();
527 for(
size_t i=0;
i < collectionSize; ++
i )
532 std::vector < std::pair<edm::Ref<TrackingParticleCollection>,
size_t> > trackingParticleQualityPairs=
535 trackingParticleQualityPairs.begin(); iTrackingParticleQualityPair != trackingParticleQualityPairs.end();
536 ++iTrackingParticleQualityPair )
539 size_t numberOfSharedHits=iTrackingParticleQualityPair->second;
540 size_t numberOfValidTrackHits=pSeed->
recHits().second - pSeed->
recHits().first;
542 if( numberOfSharedHits == 0 )
continue;
545 if(
abs( trackingParticleRef->pdgId() ) == 11 && (trackingParticleRef->g4Track_end() - trackingParticleRef->g4Track_begin()) > 1 )
553 else if( numberOfValidTrackHits != 0 ) quality=
554 (
static_cast<double>( numberOfSharedHits ) / static_cast<double>( numberOfValidTrackHits ));
564 LogTrace(
"TrackAssociator" ) <<
"% of Assoc Seeds=" << ((double)returnValue.
size()) / ((
double)pSeedCollectionHandle_->size());
574 edm::LogVerbatim(
"TrackAssociator" ) <<
"Starting TrackAssociatorByHitsImpl::associateSimToReco - #seeds=" << pSeedCollectionHandle_->size()
575 <<
" #TPs=" << trackingParticleCollectionHandle->size();
579 size_t collectionSize=pSeedCollectionHandle_->
size();
581 for(
size_t i=0;
i < collectionSize; ++
i )
586 std::vector < std::pair<edm::Ref<TrackingParticleCollection>,
size_t> > trackingParticleQualityPairs=
589 trackingParticleQualityPairs.begin(); iTrackingParticleQualityPair != trackingParticleQualityPairs.end();
590 ++iTrackingParticleQualityPair )
593 size_t numberOfSharedHits=iTrackingParticleQualityPair->second;
594 size_t numberOfValidTrackHits=pSeed->
recHits().second - pSeed->
recHits().first;
595 size_t numberOfSimulatedHits=0;
597 if( numberOfSharedHits == 0 )
continue;
600 if(
abs( trackingParticleRef->pdgId() ) == 11 && (trackingParticleRef->g4Track_end() - trackingParticleRef->g4Track_begin()) > 1 )
612 numberOfSimulatedHits=trackingParticleRef->numberOfTrackerHits();
615 double purity=
static_cast<double>( numberOfSharedHits ) / static_cast<double>( numberOfValidTrackHits );
619 / static_cast<double>( numberOfSimulatedHits );
632 LogTrace(
"TrackAssociator") <<
"% of Assoc TPs=" << ((double)returnValue.
size())/((
double)trackingParticleCollectionHandle->size());
ClusterRef cluster() const
bool isNonnull() const
Checks for non-null.
std::vector< std::pair< OmniClusterRef, TrackingParticleRef > > ClusterTPAssociationList
std::shared_ptr< const ClusterTPAssociationList > clusterToTPMap_
virtual reco::RecoToSimCollection associateRecoToSim(const edm::Handle< edm::View< reco::Track > > &trackCollectionHandle, const edm::Handle< TrackingParticleCollection > &trackingParticleCollectionHandle) const override
compare reco to sim the handle of reco::Track and TrackingParticle collections
g4t_iterator g4Track_begin() const
OmniClusterRef const & stereoClusterRef() const
bool threeHitTracksAreSpecial_
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
virtual reco::SimToRecoCollection associateSimToReco(const edm::Handle< edm::View< reco::Track > > &trackCollectionHandle, const edm::Handle< TrackingParticleCollection > &trackingParticleCollectionHandle) const override
compare reco to sim the handle of reco::Track and TrackingParticle collections
reco::RecoToSimCollection associateRecoToSimImplementation(T_TrackCollection trackCollection, T_TrackingParticleCollection trackingParticleCollection, T_hitOrClusterAssociator hitOrClusterAssociator) const
The method that does the work for both overloads of associateRecoToSim.
const TrackingRecHit * getHitFromIter(trackingRecHit_iterator iter) const
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 ...
void post_insert()
post insert action
Abs< T >::type abs(const T &t)
ClusterRef cluster() const
SimToRecoDenomType simToRecoDenominator_
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 clusterTPAssociationListGreater(std::pair< OmniClusterRef, TrackingParticleRef > i, std::pair< OmniClusterRef, TrackingParticleRef > j)
TrackToTrackingParticleAssociator that associates by hits a bit quicker than the normal TrackAssociat...
std::vector< SimTrack >::const_iterator g4t_iterator
std::shared_ptr< const TrackerHitAssociator > hitAssociator_
creates either a ClusterTPAssociationList OR a TrackerHitAssociator and stores it in the provided uni...
OmniClusterRef const & omniClusterRef() const
std::pair< uint32_t, EncodedEventId > SimTrackIdentifiers
This is enough information to uniquely identify a sim track.
std::pair< uint32_t, EncodedEventId > SimHitIdpr
SiStripRecHit2D stereoHit() const
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.
int getDoubleCount(const TrackerHitAssociator &hitAssociator, iter begin, iter end, TrackingParticleRef associatedTrackingParticle) const
This method was copied almost verbatim from the standard TrackAssociatorByHits.
size_type size() const
map size
T const * product() const
void insert(const key_type &k, const data_type &v)
insert an association
ClusterRef cluster() const
QuickTrackAssociatorByHitsImpl(std::shared_ptr< const TrackerHitAssociator > hitAssoc, std::shared_ptr< const ClusterTPAssociationList > clusterToTPMap, bool absoluteNumberOfHits, double qualitySimToReco, double puritySimToReco, double cutRecoToSim, bool threeHitTracksAreSpecial, SimToRecoDenomType simToRecoDenominator)
int numberOfHits() const
Gives the total number of hits, including muon hits. Hits on overlaps in the same layer count separat...
SiStripRecHit2D monoHit() const
bool absoluteNumberOfHits_
std::vector< SimHitIdpr > associateHitId(const TrackingRecHit &thit) 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.
unsigned short found() const
Number of valid hits on track.
size_type size() const
Size of the RefVector.
Monte Carlo truth information used for tracking validation.
DetId geographicalId() const
g4t_iterator g4Track_end() const
edm::Ref< TrackingParticleCollection > TrackingParticleRef
bool trackingParticleContainsIdentifier(const TrackingParticle *pTrackingParticle, const SimTrackIdentifiers &identifier) const
Returns true if the supplied TrackingParticle has the supplied g4 track identifiers.
std::vector< OmniClusterRef > getMatchedClusters(iter begin, iter end) const
trackingRecHit_iterator recHitsEnd() const
Iterator to last hit on the track.