29 template<
class T_element>
32 return collection.
size();
35 template<
class T_element>
38 return hCollection->size();
41 template<
class T_element>
44 return collection.
size();
49 return &*trackCollection[
index];
54 return &(*pTrackCollection.product())[index];
59 return &(*pCollection.
product())[index];
64 return &*collection[
index];
69 return trackCollection[
index];
84 return collection[
index];
89 for(
const auto& ref: collection) {
90 keys.insert(ref.key());
94 template <
typename Coll>
95 void checkClusterMapProductID(
const ClusterTPAssociation& clusterToTPMap,
const Coll& collection) {
99 template <
typename Coll>
105 std::unique_ptr<const TrackerHitAssociator> hitAssoc,
108 bool absoluteNumberOfHits,
109 double qualitySimToReco,
110 double puritySimToReco,
111 double pixelHitWeight,
113 bool threeHitTracksAreSpecial,
115 productGetter_(&productGetter),
116 hitAssociator_(
std::
move(hitAssoc)),
117 clusterToTPMap_(clusterToTPMap),
118 qualitySimToReco_(qualitySimToReco),
119 puritySimToReco_(puritySimToReco),
120 pixelHitWeight_(pixelHitWeight),
121 cutRecoToSim_(cutRecoToSim),
122 simToRecoDenominator_(simToRecoDenominator) ,
123 threeHitTracksAreSpecial_(threeHitTracksAreSpecial),
124 absoluteNumberOfHits_(absoluteNumberOfHits)
151 fillKeys(tpKeys, trackingParticleCollection);
163 fillKeys(tpKeys, trackingParticleCollection);
169 template<
class T_TrackCollection,
class T_TrackingParticleCollection,
class T_hitOrClusterAssociator>
173 if(::collectionSize(trackingParticleCollection) == 0)
176 checkClusterMapProductID(hitOrClusterAssociator, trackingParticleCollection);
178 size_t collectionSize=::collectionSize(trackCollection);
180 for(
size_t i=0;
i < collectionSize; ++
i )
182 const reco::Track* pTrack=::getTrackAt(trackCollection,
i);
185 std::vector < std::pair<edm::Ref<TrackingParticleCollection>,
double> > trackingParticleQualityPairs=
associateTrack( hitOrClusterAssociator, trackingParticleCollection, trackingParticleKeys, pTrack->
recHitsBegin(), pTrack->
recHitsEnd() );
188 for(
auto iTrackingParticleQualityPair=
189 trackingParticleQualityPairs.begin(); iTrackingParticleQualityPair != trackingParticleQualityPairs.end();
190 ++iTrackingParticleQualityPair )
193 double numberOfSharedHits=iTrackingParticleQualityPair->second;
196 if( numberOfSharedHits == 0.0 )
continue;
199 if(
abs( trackingParticleRef->pdgId() ) == 11 && (trackingParticleRef->g4Track_end() - trackingParticleRef->g4Track_begin()) > 1 )
206 else if( numberOfValidTrackHits != 0.0 ) quality = numberOfSharedHits / numberOfValidTrackHits;
211 returnValue.
insert( ::getRefToTrackAt(trackCollection,
i), std::make_pair( trackingParticleRef, quality ) );
219 template<
class T_TrackCollection,
class T_TrackingParticleCollection,
class T_hitOrClusterAssociator>
223 if(::collectionSize(trackingParticleCollection) == 0)
226 checkClusterMapProductID(hitOrClusterAssociator, trackingParticleCollection);
228 size_t collectionSize=::collectionSize(trackCollection);
230 for(
size_t i=0;
i<collectionSize; ++
i )
232 const reco::Track* pTrack=::getTrackAt(trackCollection,
i);
235 std::vector < std::pair<edm::Ref<TrackingParticleCollection>,
double> > trackingParticleQualityPairs=
associateTrack( hitOrClusterAssociator, trackingParticleCollection, trackingParticleKeys, pTrack->
recHitsBegin(), pTrack->
recHitsEnd() );
238 for(
auto iTrackingParticleQualityPair=trackingParticleQualityPairs.begin();
239 iTrackingParticleQualityPair!=trackingParticleQualityPairs.end(); ++iTrackingParticleQualityPair )
242 double numberOfSharedHits=iTrackingParticleQualityPair->second;
244 size_t numberOfSimulatedHits=0;
246 if( numberOfSharedHits==0.0 )
continue;
254 numberOfSimulatedHits=trackingParticleRef->numberOfTrackerHits();
258 if (
abs(trackingParticleRef->pdgId())==11 && (trackingParticleRef->g4Track_end() - trackingParticleRef->g4Track_begin()) > 1 )
263 double purity = numberOfSharedHits/numberOfValidTrackHits;
266 else if(
simToRecoDenominator_==
denomsim && numberOfSimulatedHits != 0 ) quality = numberOfSharedHits/
static_cast<double>(numberOfSimulatedHits);
273 returnValue.
insert( trackingParticleRef, std::make_pair( ::getRefToTrackAt(trackCollection,
i), quality ) );
285 std::vector< std::pair<edm::Ref<TrackingParticleCollection>,
double> > returnValue;
290 std::vector< std::pair<SimTrackIdentifiers,double> > hitIdentifiers=
getAllSimTrackIdentifiers( hitAssociator, begin, end );
293 size_t collectionSize=::collectionSize(trackingParticles);
295 for(
size_t i=0;
i<collectionSize; ++
i )
297 const TrackingParticle* pTrackingParticle=getTrackingParticleAt( trackingParticles,
i );
306 double numberOfAssociatedHits=0;
309 for(
const auto& identifierCountPair: hitIdentifiers)
314 if( numberOfAssociatedHits>0 )
316 returnValue.push_back( std::make_pair( getRefToTrackingParticleAt(trackingParticles,
i), numberOfAssociatedHits ) );
339 std::vector < std::pair<edm::Ref<TrackingParticleCollection>,
double> > returnValue;
340 if( clusterToTPMap.
empty() )
return returnValue;
348 std::map < TrackingParticleRef, double > lmap;
349 for( std::vector<OmniClusterRef>::const_iterator it=oClusters.begin(); it != oClusters.end(); ++it )
353 if( range.first != range.second )
355 for(
auto ip=range.first; ip != range.second; ++ip )
360 if(trackingParticleKeys && trackingParticleKeys->find(trackingParticle.
key()) == trackingParticleKeys->end())
383 auto jpos=lmap.find( trackingParticle );
384 if( jpos != lmap.end() ) jpos->second += weight;
385 else lmap.insert( std::make_pair( trackingParticle, weight ) );
390 for(
auto ip=lmap.begin(); ip != lmap.end(); ++ip )
392 returnValue.push_back( std::make_pair( ip->first, ip->second ) );
399 std::vector<OmniClusterRef> returnValue;
400 for (iter iRecHit = begin; iRecHit !=
end; ++iRecHit) {
407 edm::LogError(
"TrackAssociator") <<
">>> RecHit does not have an associated cluster!" <<
" file: " << __FILE__ <<
" line: " << __LINE__;
411 const std::type_info &tid =
typeid(*rhit);
415 edm::LogError(
"TrackAssociator") <<
">>> RecHit does not have an associated cluster!" <<
" file: " << __FILE__ <<
" line: " << __LINE__;
422 edm::LogError(
"TrackAssociator") <<
">>> RecHit does not have an associated cluster!" <<
" file: " << __FILE__ <<
" line: " << __LINE__;
428 edm::LogError(
"TrackAssociator") <<
">>> RecHit does not have an associated cluster!" <<
" file: " << __FILE__ <<
" line: " << __LINE__;
434 edm::LogError(
"TrackAssociator") <<
">>> RecHit does not have an associated cluster!" <<
" file: " << __FILE__ <<
" line: " << __LINE__;
439 if ( thit.isProjected() ) {
441 edm::LogError(
"TrackAssociator") <<
">>> getMatchedClusters: TrackingRecHit not associated to any SiStripCluster! subdetid = " << subdetid;
446 edm::LogError(
"TrackAssociator") <<
">>> getMatchedClusters: TrackingRecHit not associated to any cluster! subdetid = " << subdetid;
456 std::vector < std::pair<SimTrackIdentifiers,double> > returnValue;
458 std::vector<SimTrackIdentifiers> simTrackIdentifiers;
461 for( iter iRecHit=begin; iRecHit !=
end; ++iRecHit )
465 simTrackIdentifiers.clear();
475 for( std::vector<SimTrackIdentifiers>::const_iterator iIdentifier=simTrackIdentifiers.begin(); iIdentifier != simTrackIdentifiers.end();
478 std::vector<std::pair<SimTrackIdentifiers,double> >::iterator iIdentifierCountPair;
479 for(
auto iIdentifierCountPair=returnValue.begin(); iIdentifierCountPair != returnValue.end(); ++iIdentifierCountPair )
481 if( iIdentifierCountPair->first.first == iIdentifier->first && iIdentifierCountPair->first.second == iIdentifier->second )
484 iIdentifierCountPair->second +=
weight;
488 if( iIdentifierCountPair == returnValue.end() ) returnValue.push_back( std::make_pair( *iIdentifier, 1.0 ) );
499 for( std::vector<SimTrack>::const_iterator iSimTrack=pTrackingParticle->
g4Track_begin(); iSimTrack != pTrackingParticle->
g4Track_end();
503 if( iSimTrack->eventId() == identifier.second && iSimTrack->trackId() == identifier.first )
519 double doubleCount=0.0;
520 std::vector < SimHitIdpr > SimTrackIdsDC;
522 for( iter iHit=startIterator; iHit != endIterator; iHit++ )
526 SimTrackIdsDC.clear();
528 if( SimTrackIdsDC.size() > 1 )
533 if(
find( SimTrackIdsDC.begin(), SimTrackIdsDC.end(),
SimHitIdpr( ( *g4T).trackId(), SimTrackIdsDC.begin()->second ) )
534 != SimTrackIdsDC.end() )
543 doubleCount += weight*(idcount - 1);
555 double doubleCount=0;
556 std::vector < SimHitIdpr > SimTrackIdsDC;
558 for( iter iHit=startIterator; iHit != endIterator; iHit++ )
563 for( std::vector<OmniClusterRef>::const_iterator it=oClusters.begin(); it != oClusters.end(); ++it )
566 if( range.first != range.second )
568 for(
auto ip=range.first; ip != range.second; ++ip )
571 if( associatedTrackingParticle == trackingParticle )
582 doubleCount += weight*(idcount - 1);
593 edm::LogVerbatim(
"TrackAssociator" ) <<
"Starting TrackAssociatorByHitsImpl::associateRecoToSim - #seeds=" << pSeedCollectionHandle_->size()
594 <<
" #TPs=" << trackingParticleCollectionHandle->size();
598 size_t collectionSize=pSeedCollectionHandle_->size();
600 for(
size_t i=0;
i < collectionSize; ++
i )
605 std::vector < std::pair<edm::Ref<TrackingParticleCollection>,
double> > trackingParticleQualityPairs=
607 for(
auto iTrackingParticleQualityPair=
608 trackingParticleQualityPairs.begin(); iTrackingParticleQualityPair != trackingParticleQualityPairs.end();
609 ++iTrackingParticleQualityPair )
612 double numberOfSharedHits=iTrackingParticleQualityPair->second;
615 if( numberOfSharedHits == 0.0 )
continue;
618 if(
abs( trackingParticleRef->pdgId() ) == 11 && (trackingParticleRef->g4Track_end() - trackingParticleRef->g4Track_begin()) > 1 )
626 else if( numberOfValidTrackHits != 0.0 ) quality = numberOfSharedHits / numberOfValidTrackHits;
636 LogTrace(
"TrackAssociator" ) <<
"% of Assoc Seeds=" << ((double)returnValue.
size()) / ((
double)pSeedCollectionHandle_->size());
646 edm::LogVerbatim(
"TrackAssociator" ) <<
"Starting TrackAssociatorByHitsImpl::associateSimToReco - #seeds=" << pSeedCollectionHandle_->size()
647 <<
" #TPs=" << trackingParticleCollectionHandle->size();
650 if(trackingParticleCollectionHandle->empty())
654 checkClusterMapProductID(*
clusterToTPMap_, trackingParticleCollectionHandle);
657 size_t collectionSize=pSeedCollectionHandle_->size();
659 for(
size_t i=0;
i < collectionSize; ++
i )
664 std::vector < std::pair<edm::Ref<TrackingParticleCollection>,
double> > trackingParticleQualityPairs=
666 for(
auto iTrackingParticleQualityPair=
667 trackingParticleQualityPairs.begin(); iTrackingParticleQualityPair != trackingParticleQualityPairs.end();
668 ++iTrackingParticleQualityPair )
671 double numberOfSharedHits=iTrackingParticleQualityPair->second;
673 size_t numberOfSimulatedHits=0;
675 if( numberOfSharedHits == 0.0 )
continue;
678 if(
abs( trackingParticleRef->pdgId() ) == 11 && (trackingParticleRef->g4Track_end() - trackingParticleRef->g4Track_begin()) > 1 )
690 numberOfSimulatedHits=trackingParticleRef->numberOfTrackerHits();
693 double purity = numberOfSharedHits / numberOfValidTrackHits;
697 /
static_cast<double>( numberOfSimulatedHits );
709 LogTrace(
"TrackAssociator") <<
"% of Assoc TPs=" << ((double)returnValue.
size())/((
double)trackingParticleCollectionHandle->size());
723 for(
auto iHit=seed.
recHits().first; iHit!=seed.
recHits().second; ++iHit) {
ClusterRef cluster() const
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
bool isNonnull() const
Checks for non-null.
double weightedNumberOfTrackHits(const reco::Track &track) const
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.
std::vector< std::pair< edm::Ref< TrackingParticleCollection >, double > > 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.
g4t_iterator g4Track_begin() const
int numberOfValidHits() const
OmniClusterRef const & stereoClusterRef() const
trackingParticleCollection
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)
QuickTrackAssociatorByHitsImpl(edm::EDProductGetter const &productGetter, std::unique_ptr< const TrackerHitAssociator > hitAssoc, const ClusterTPAssociation *clusterToTPMap, bool absoluteNumberOfHits, double qualitySimToReco, double puritySimToReco, double cutRecoToSim, double pixelHitWeight, bool threeHitTracksAreSpecial, SimToRecoDenomType simToRecoDenominator)
EDProductGetter const * productGetter(std::atomic< void const * > const &iCache)
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
void post_insert()
post insert action
Abs< T >::type abs(const T &t)
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
ClusterRef cluster() const
range equal_range(const OmniClusterRef &key) const
unsigned short numberOfValidHits() const
number of valid hits found
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) ...
double getDoubleCount(const TrackerHitAssociator &hitAssociator, iter begin, iter end, TrackingParticleRef associatedTrackingParticle) const
This method was copied almost verbatim from the standard TrackAssociatorByHits.
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
size_type size() const
map size
T const * product() const
void insert(const key_type &k, const data_type &v)
insert an association
const HitPattern & hitPattern() const
Access the hit pattern, indicating in which Tracker layers the track has hits.
ClusterRef cluster() const
SiStripRecHit2D monoHit() const
bool absoluteNumberOfHits_
void checkMappedProductID(const edm::HandleBase &mappedHandle) const
std::vector< SimHitIdpr > associateHitId(const TrackingRecHit &thit) const
unsigned int nHits() const
std::unordered_set< reco::RecoToSimCollection::index_type > TrackingParticleRefKeySet
Set for TrackingParticleRef keys.
int numberOfValidPixelHits() const
size_type size() const
Size of the RefVector.
Monte Carlo truth information used for tracking validation.
DetId geographicalId() const
g4t_iterator g4Track_end() const
std::vector< std::pair< SimTrackIdentifiers, double > > 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 ...
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.