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];
88 for(
const auto& ref: collection) {
89 keys.insert(ref.key());
93 template <
typename Coll>
94 void checkClusterMapProductID(
const ClusterTPAssociation& clusterToTPMap,
const Coll& collection) {
98 template <
typename Coll>
99 void checkClusterMapProductID(
const TrackerHitAssociator& hitAssociator,
const Coll& collection) {}
104 std::unique_ptr<const TrackerHitAssociator> hitAssoc,
107 bool absoluteNumberOfHits,
108 double qualitySimToReco,
109 double puritySimToReco,
111 bool threeHitTracksAreSpecial,
113 productGetter_(&productGetter),
114 hitAssociator_(std::
move(hitAssoc)),
115 clusterToTPMap_(clusterToTPMap),
116 qualitySimToReco_(qualitySimToReco),
117 puritySimToReco_(puritySimToReco),
118 cutRecoToSim_(cutRecoToSim),
119 simToRecoDenominator_(simToRecoDenominator) ,
120 threeHitTracksAreSpecial_(threeHitTracksAreSpecial),
121 absoluteNumberOfHits_(absoluteNumberOfHits)
148 fillKeys(tpKeys, trackingParticleCollection);
160 fillKeys(tpKeys, trackingParticleCollection);
166 template<
class T_TrackCollection,
class T_TrackingParticleCollection,
class T_hitOrClusterAssociator>
171 checkClusterMapProductID(hitOrClusterAssociator, trackingParticleCollection);
173 size_t collectionSize=::collectionSize(trackCollection);
175 for(
size_t i=0;
i < collectionSize; ++
i )
177 const reco::Track* pTrack=::getTrackAt(trackCollection,
i);
180 std::vector < std::pair<edm::Ref<TrackingParticleCollection>,
size_t> > trackingParticleQualityPairs=
associateTrack( hitOrClusterAssociator, trackingParticleCollection, trackingParticleKeys, pTrack->
recHitsBegin(), pTrack->
recHitsEnd() );
184 trackingParticleQualityPairs.begin(); iTrackingParticleQualityPair != trackingParticleQualityPairs.end();
185 ++iTrackingParticleQualityPair )
188 size_t numberOfSharedHits=iTrackingParticleQualityPair->second;
189 size_t numberOfValidTrackHits=pTrack->
found();
191 if( numberOfSharedHits == 0 )
continue;
194 if(
abs( trackingParticleRef->pdgId() ) == 11 && (trackingParticleRef->g4Track_end() - trackingParticleRef->g4Track_begin()) > 1 )
201 else if( numberOfValidTrackHits != 0 ) quality=
202 (
static_cast<double>( numberOfSharedHits ) / static_cast<double>( numberOfValidTrackHits ));
207 returnValue.
insert( ::getRefToTrackAt(trackCollection,
i), std::make_pair( trackingParticleRef, quality ) );
215 template<
class T_TrackCollection,
class T_TrackingParticleCollection,
class T_hitOrClusterAssociator>
220 checkClusterMapProductID(hitOrClusterAssociator, trackingParticleCollection);
222 size_t collectionSize=::collectionSize(trackCollection);
224 for(
size_t i=0;
i<collectionSize; ++
i )
226 const reco::Track* pTrack=::getTrackAt(trackCollection,
i);
229 std::vector < std::pair<edm::Ref<TrackingParticleCollection>,
size_t> > trackingParticleQualityPairs=
associateTrack( hitOrClusterAssociator, trackingParticleCollection, trackingParticleKeys, pTrack->
recHitsBegin(), pTrack->
recHitsEnd() );
233 iTrackingParticleQualityPair!=trackingParticleQualityPairs.end(); ++iTrackingParticleQualityPair )
236 size_t numberOfSharedHits=iTrackingParticleQualityPair->second;
237 size_t numberOfValidTrackHits=pTrack->
found();
238 size_t numberOfSimulatedHits=0;
240 if( numberOfSharedHits==0 )
continue;
248 numberOfSimulatedHits=trackingParticleRef->numberOfTrackerHits();
252 if (
abs(trackingParticleRef->pdgId())==11 && (trackingParticleRef->g4Track_end() - trackingParticleRef->g4Track_begin()) > 1 )
257 double purity=
static_cast<double>(numberOfSharedHits)/static_cast<double>(numberOfValidTrackHits);
260 else if(
simToRecoDenominator_==
denomsim && numberOfSimulatedHits != 0 ) quality=
static_cast<double>(numberOfSharedHits)/static_cast<double>(numberOfSimulatedHits);
267 returnValue.
insert( trackingParticleRef, std::make_pair( ::getRefToTrackAt(trackCollection,
i), quality ) );
279 std::vector< std::pair<edm::Ref<TrackingParticleCollection>,
size_t> > returnValue;
284 std::vector< std::pair<SimTrackIdentifiers,size_t> > hitIdentifiers=
getAllSimTrackIdentifiers( hitAssociator, begin, end );
287 size_t collectionSize=::collectionSize(trackingParticles);
289 for(
size_t i=0;
i<collectionSize; ++
i )
291 const TrackingParticle* pTrackingParticle=getTrackingParticleAt( trackingParticles,
i );
296 size_t numberOfAssociatedHits=0;
299 for( std::vector< std::pair<SimTrackIdentifiers,size_t> >::const_iterator iIdentifierCountPair=hitIdentifiers.begin(); iIdentifierCountPair!=hitIdentifiers.end(); ++iIdentifierCountPair )
304 if( numberOfAssociatedHits>0 )
306 returnValue.push_back( std::make_pair( getRefToTrackingParticleAt(trackingParticles,
i), numberOfAssociatedHits ) );
329 std::vector < std::pair<edm::Ref<TrackingParticleCollection>,
size_t> > returnValue;
330 if( clusterToTPMap.
empty() )
return returnValue;
338 std::map < TrackingParticleRef, size_t > lmap;
339 for( std::vector<OmniClusterRef>::const_iterator it=oClusters.begin(); it != oClusters.end(); ++it )
342 if( range.first != range.second )
344 for(
auto ip=range.first; ip != range.second; ++ip )
349 if(trackingParticleKeys && trackingParticleKeys->find(trackingParticle.
key()) == trackingParticleKeys->end())
353 if( trackingParticle->numberOfHits() == 0 )
continue;
368 auto jpos=lmap.find( trackingParticle );
369 if( jpos != lmap.end() ) ++jpos->second;
370 else lmap.insert( std::make_pair( trackingParticle, 1 ) );
375 for(
auto ip=lmap.begin(); ip != lmap.end(); ++ip )
377 returnValue.push_back( std::make_pair( ip->first, ip->second ) );
384 std::vector<OmniClusterRef> returnValue;
385 for (iter iRecHit = begin; iRecHit !=
end; ++iRecHit) {
392 edm::LogError(
"TrackAssociator") <<
">>> RecHit does not have an associated cluster!" <<
" file: " << __FILE__ <<
" line: " << __LINE__;
396 const std::type_info &tid =
typeid(*rhit);
400 edm::LogError(
"TrackAssociator") <<
">>> RecHit does not have an associated cluster!" <<
" file: " << __FILE__ <<
" line: " << __LINE__;
407 edm::LogError(
"TrackAssociator") <<
">>> RecHit does not have an associated cluster!" <<
" file: " << __FILE__ <<
" line: " << __LINE__;
413 edm::LogError(
"TrackAssociator") <<
">>> RecHit does not have an associated cluster!" <<
" file: " << __FILE__ <<
" line: " << __LINE__;
418 if ( thit.isProjected() ) {
420 edm::LogError(
"TrackAssociator") <<
">>> getMatchedClusters: TrackingRecHit not associated to any SiStripCluster! subdetid = " << subdetid;
425 edm::LogError(
"TrackAssociator") <<
">>> getMatchedClusters: TrackingRecHit not associated to any cluster! subdetid = " << subdetid;
435 std::vector < std::pair<SimTrackIdentifiers,size_t> > returnValue;
437 std::vector<SimTrackIdentifiers> simTrackIdentifiers;
440 for( iter iRecHit=begin; iRecHit !=
end; ++iRecHit )
444 simTrackIdentifiers.clear();
450 for( std::vector<SimTrackIdentifiers>::const_iterator iIdentifier=simTrackIdentifiers.begin(); iIdentifier != simTrackIdentifiers.end();
453 std::vector<std::pair<SimTrackIdentifiers,size_t> >::iterator iIdentifierCountPair;
454 for( iIdentifierCountPair=returnValue.begin(); iIdentifierCountPair != returnValue.end(); ++iIdentifierCountPair )
456 if( iIdentifierCountPair->first.first == iIdentifier->first && iIdentifierCountPair->first.second == iIdentifier->second )
459 ++iIdentifierCountPair->second;
463 if( iIdentifierCountPair == returnValue.end() ) returnValue.push_back( std::make_pair( *iIdentifier, 1 ) );
474 for( std::vector<SimTrack>::const_iterator iSimTrack=pTrackingParticle->
g4Track_begin(); iSimTrack != pTrackingParticle->
g4Track_end();
478 if( iSimTrack->eventId() == identifier.second && iSimTrack->trackId() == identifier.first )
495 std::vector < SimHitIdpr > SimTrackIdsDC;
497 for( iter iHit=startIterator; iHit != endIterator; iHit++ )
501 SimTrackIdsDC.clear();
503 if( SimTrackIdsDC.size() > 1 )
508 if(
find( SimTrackIdsDC.begin(), SimTrackIdsDC.end(),
SimHitIdpr( ( *g4T).trackId(), SimTrackIdsDC.begin()->second ) )
509 != SimTrackIdsDC.end() )
515 if( idcount > 1 ) doubleCount+=(idcount - 1);
527 std::vector < SimHitIdpr > SimTrackIdsDC;
529 for( iter iHit=startIterator; iHit != endIterator; iHit++ )
534 for( std::vector<OmniClusterRef>::const_iterator it=oClusters.begin(); it != oClusters.end(); ++it )
537 if( range.first != range.second )
539 for(
auto ip=range.first; ip != range.second; ++ip )
542 if( associatedTrackingParticle == trackingParticle )
550 if( idcount > 1 ) doubleCount+=(idcount - 1);
560 edm::LogVerbatim(
"TrackAssociator" ) <<
"Starting TrackAssociatorByHitsImpl::associateRecoToSim - #seeds=" << pSeedCollectionHandle_->size()
561 <<
" #TPs=" << trackingParticleCollectionHandle->size();
565 size_t collectionSize=pSeedCollectionHandle_->size();
567 for(
size_t i=0;
i < collectionSize; ++
i )
572 std::vector < std::pair<edm::Ref<TrackingParticleCollection>,
size_t> > trackingParticleQualityPairs=
575 trackingParticleQualityPairs.begin(); iTrackingParticleQualityPair != trackingParticleQualityPairs.end();
576 ++iTrackingParticleQualityPair )
579 size_t numberOfSharedHits=iTrackingParticleQualityPair->second;
580 size_t numberOfValidTrackHits=pSeed->
recHits().second - pSeed->
recHits().first;
582 if( numberOfSharedHits == 0 )
continue;
585 if(
abs( trackingParticleRef->pdgId() ) == 11 && (trackingParticleRef->g4Track_end() - trackingParticleRef->g4Track_begin()) > 1 )
593 else if( numberOfValidTrackHits != 0 ) quality=
594 (
static_cast<double>( numberOfSharedHits ) / static_cast<double>( numberOfValidTrackHits ));
604 LogTrace(
"TrackAssociator" ) <<
"% of Assoc Seeds=" << ((double)returnValue.
size()) / ((
double)pSeedCollectionHandle_->size());
614 edm::LogVerbatim(
"TrackAssociator" ) <<
"Starting TrackAssociatorByHitsImpl::associateSimToReco - #seeds=" << pSeedCollectionHandle_->size()
615 <<
" #TPs=" << trackingParticleCollectionHandle->size();
620 checkClusterMapProductID(*
clusterToTPMap_, trackingParticleCollectionHandle);
623 size_t collectionSize=pSeedCollectionHandle_->size();
625 for(
size_t i=0;
i < collectionSize; ++
i )
630 std::vector < std::pair<edm::Ref<TrackingParticleCollection>,
size_t> > trackingParticleQualityPairs=
633 trackingParticleQualityPairs.begin(); iTrackingParticleQualityPair != trackingParticleQualityPairs.end();
634 ++iTrackingParticleQualityPair )
637 size_t numberOfSharedHits=iTrackingParticleQualityPair->second;
638 size_t numberOfValidTrackHits=pSeed->
recHits().second - pSeed->
recHits().first;
639 size_t numberOfSimulatedHits=0;
641 if( numberOfSharedHits == 0 )
continue;
644 if(
abs( trackingParticleRef->pdgId() ) == 11 && (trackingParticleRef->g4Track_end() - trackingParticleRef->g4Track_begin()) > 1 )
656 numberOfSimulatedHits=trackingParticleRef->numberOfTrackerHits();
659 double purity=
static_cast<double>( numberOfSharedHits ) / static_cast<double>( numberOfValidTrackHits );
663 / static_cast<double>( numberOfSimulatedHits );
675 LogTrace(
"TrackAssociator") <<
"% of Assoc TPs=" << ((double)returnValue.
size())/((
double)trackingParticleCollectionHandle->size());
ClusterRef cluster() const
bool isNonnull() const
Checks for non-null.
reco::RecoToSimCollection associateRecoToSimImplementation(const T_TrackCollection &trackCollection, const T_TrackingParticleCollection &trackingParticleCollection, const TrackingParticleRefKeySet *trackingParticleKeys, T_hitOrClusterAssociator hitOrClusterAssociator) const
The method that does the work for both overloads of associateRecoToSim.
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
key_type key() const
Accessor for product key.
bool threeHitTracksAreSpecial_
edm::EDProductGetter const * productGetter_
creates either a ClusterTPAssociation OR a TrackerHitAssociator and stores it in the provided unique_...
const ClusterTPAssociation * clusterToTPMap_
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
EDProductGetter const * productGetter(std::atomic< void const * > const &iCache)
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::SimToRecoCollection associateSimToRecoImplementation(const T_TrackCollection &trackCollection, const T_TrackingParticleCollection &trackingParticleCollection, const TrackingParticleRefKeySet *trackingParticleKeys, T_hitOrClusterAssociator hitOrClusterAssociator) const
The method that does the work for both overloads of associateSimToReco.
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)
std::vector< std::pair< edm::Ref< TrackingParticleCollection >, size_t > > associateTrack(const TrackerHitAssociator &hitAssociator, const T_TPCollection &trackingParticles, const TrackingParticleRefKeySet *trackingParticleKeys, iter begin, iter end) const
Returns the TrackingParticle that has the most associated hits to the given track.
ClusterRef cluster() const
range equal_range(const OmniClusterRef &key) 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) ...
std::vector< SimTrack >::const_iterator g4t_iterator
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
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
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_
void checkMappedProductID(const edm::HandleBase &mappedHandle) const
std::vector< SimHitIdpr > associateHitId(const TrackingRecHit &thit) const
std::unordered_set< reco::RecoToSimCollection::index_type > TrackingParticleRefKeySet
Set for TrackingParticleRef keys.
unsigned short found() const
Number of valid hits on track.
QuickTrackAssociatorByHitsImpl(edm::EDProductGetter const &productGetter, std::unique_ptr< const TrackerHitAssociator > hitAssoc, const ClusterTPAssociation *clusterToTPMap, bool absoluteNumberOfHits, double qualitySimToReco, double puritySimToReco, double cutRecoToSim, bool threeHitTracksAreSpecial, SimToRecoDenomType simToRecoDenominator)
size_type size() const
Size of the RefVector.
Monte Carlo truth information used for tracking validation.
DetId geographicalId() const
g4t_iterator g4Track_end() const
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
std::unique_ptr< const TrackerHitAssociator > hitAssociator_
trackingRecHit_iterator recHitsEnd() const
Iterator to last hit on the track.