25 template<
class T_element>
28 return collection.
size();
31 template<
class T_element>
34 return hCollection->size();
37 template<
class T_element>
40 return collection.
size();
45 return &*trackCollection[
index];
50 return &(*pTrackCollection.product())[index];
55 return &(*pCollection.
product())[index];
60 return &*collection[
index];
65 return trackCollection[
index];
80 return collection[
index];
85 for(
const auto& ref: collection) {
90 template <
typename Coll>
91 void checkClusterMapProductID(
const ClusterTPAssociation& clusterToTPMap,
const Coll& collection) {
95 template <
typename Coll>
101 std::unique_ptr<const TrackerHitAssociator> hitAssoc,
104 bool absoluteNumberOfHits,
105 double qualitySimToReco,
106 double puritySimToReco,
107 double pixelHitWeight,
109 bool threeHitTracksAreSpecial,
111 productGetter_(&productGetter),
112 hitAssociator_(
std::
move(hitAssoc)),
113 clusterToTPMap_(clusterToTPMap),
114 qualitySimToReco_(qualitySimToReco),
115 puritySimToReco_(puritySimToReco),
116 pixelHitWeight_(pixelHitWeight),
117 cutRecoToSim_(cutRecoToSim),
118 simToRecoDenominator_(simToRecoDenominator) ,
119 threeHitTracksAreSpecial_(threeHitTracksAreSpecial),
120 absoluteNumberOfHits_(absoluteNumberOfHits)
147 fillKeys(tpKeys, trackingParticleCollection);
159 fillKeys(tpKeys, trackingParticleCollection);
165 template<
class T_TrackCollection,
class T_TrackingParticleCollection,
class T_hitOrClusterAssociator>
169 if(::collectionSize(trackingParticleCollection) == 0)
172 checkClusterMapProductID(hitOrClusterAssociator, trackingParticleCollection);
174 size_t collectionSize=::collectionSize(trackCollection);
176 for(
size_t i=0;
i < collectionSize; ++
i )
178 const reco::Track* pTrack=::getTrackAt(trackCollection,
i);
181 std::vector < std::pair<edm::Ref<TrackingParticleCollection>,
double> > trackingParticleQualityPairs=
associateTrack( hitOrClusterAssociator, trackingParticleCollection, trackingParticleKeys, pTrack->
recHitsBegin(), pTrack->
recHitsEnd() );
184 for(
auto iTrackingParticleQualityPair=
185 trackingParticleQualityPairs.begin(); iTrackingParticleQualityPair != trackingParticleQualityPairs.end();
186 ++iTrackingParticleQualityPair )
189 double numberOfSharedClusters=iTrackingParticleQualityPair->second;
192 if( numberOfSharedClusters == 0.0 )
continue;
195 if(
abs( trackingParticleRef->pdgId() ) == 11 && (trackingParticleRef->g4Track_end() - trackingParticleRef->g4Track_begin()) > 1 )
202 else if( numberOfValidTrackClusters != 0.0 ) quality = numberOfSharedClusters / numberOfValidTrackClusters;
207 returnValue.
insert( ::getRefToTrackAt(trackCollection,
i), std::make_pair( trackingParticleRef, quality ) );
215 template<
class T_TrackCollection,
class T_TrackingParticleCollection,
class T_hitOrClusterAssociator>
219 if(::collectionSize(trackingParticleCollection) == 0)
222 checkClusterMapProductID(hitOrClusterAssociator, trackingParticleCollection);
224 size_t collectionSize=::collectionSize(trackCollection);
226 for(
size_t i=0;
i<collectionSize; ++
i )
228 const reco::Track* pTrack=::getTrackAt(trackCollection,
i);
231 std::vector < std::pair<edm::Ref<TrackingParticleCollection>,
double> > trackingParticleQualityPairs=
associateTrack( hitOrClusterAssociator, trackingParticleCollection, trackingParticleKeys, pTrack->
recHitsBegin(), pTrack->
recHitsEnd() );
234 for(
auto iTrackingParticleQualityPair=trackingParticleQualityPairs.begin();
235 iTrackingParticleQualityPair!=trackingParticleQualityPairs.end(); ++iTrackingParticleQualityPair )
238 double numberOfSharedClusters=iTrackingParticleQualityPair->second;
240 size_t numberOfSimulatedHits=0;
242 if( numberOfSharedClusters==0.0 )
continue;
250 numberOfSimulatedHits=trackingParticleRef->numberOfTrackerHits();
254 if (
abs(trackingParticleRef->pdgId())==11 && (trackingParticleRef->g4Track_end() - trackingParticleRef->g4Track_begin()) > 1 )
259 double purity = numberOfSharedClusters/numberOfValidTrackClusters;
262 else if(
simToRecoDenominator_==
denomsim && numberOfSimulatedHits != 0 ) quality = numberOfSharedClusters/
static_cast<double>(numberOfSimulatedHits);
269 returnValue.
insert( trackingParticleRef, std::make_pair( ::getRefToTrackAt(trackCollection,
i), quality ) );
281 std::vector< std::pair<edm::Ref<TrackingParticleCollection>,
double> > returnValue;
286 std::vector< std::pair<SimTrackIdentifiers,double> > hitIdentifiers=
getAllSimTrackIdentifiers( hitAssociator, begin, end );
289 size_t collectionSize=::collectionSize(trackingParticles);
291 for(
size_t i=0;
i<collectionSize; ++
i )
293 const TrackingParticle* pTrackingParticle=getTrackingParticleAt( trackingParticles,
i );
302 double numberOfAssociatedHits=0;
305 for(
const auto& identifierCountPair: hitIdentifiers)
310 if( numberOfAssociatedHits>0 )
312 returnValue.push_back( std::make_pair( getRefToTrackingParticleAt(trackingParticles,
i), numberOfAssociatedHits ) );
335 std::vector < std::pair<edm::Ref<TrackingParticleCollection>,
double> > returnValue;
336 if( clusterToTPMap.
empty() )
return returnValue;
344 std::map < TrackingParticleRef, double > lmap;
345 for( std::vector<OmniClusterRef>::const_iterator it=oClusters.begin(); it != oClusters.end(); ++it )
349 if( range.first != range.second )
351 for(
auto ip=range.first; ip != range.second; ++ip )
356 if(trackingParticleKeys && !trackingParticleKeys->
has(trackingParticle.
key()))
379 auto jpos=lmap.find( trackingParticle );
380 if( jpos != lmap.end() ) jpos->second += weight;
381 else lmap.insert( std::make_pair( trackingParticle, weight ) );
386 for(
auto ip=lmap.begin(); ip != lmap.end(); ++ip )
388 returnValue.push_back( std::make_pair( ip->first, ip->second ) );
397 std::vector < std::pair<SimTrackIdentifiers,double> > returnValue;
399 std::vector<SimTrackIdentifiers> simTrackIdentifiers;
402 for( iter iRecHit=begin; iRecHit !=
end; ++iRecHit )
406 simTrackIdentifiers.clear();
416 for( std::vector<SimTrackIdentifiers>::const_iterator iIdentifier=simTrackIdentifiers.begin(); iIdentifier != simTrackIdentifiers.end();
419 std::vector<std::pair<SimTrackIdentifiers,double> >::iterator iIdentifierCountPair;
420 for(
auto iIdentifierCountPair=returnValue.begin(); iIdentifierCountPair != returnValue.end(); ++iIdentifierCountPair )
422 if( iIdentifierCountPair->first.first == iIdentifier->first && iIdentifierCountPair->first.second == iIdentifier->second )
425 iIdentifierCountPair->second +=
weight;
429 if( iIdentifierCountPair == returnValue.end() ) returnValue.push_back( std::make_pair( *iIdentifier, 1.0 ) );
440 for( std::vector<SimTrack>::const_iterator iSimTrack=pTrackingParticle->
g4Track_begin(); iSimTrack != pTrackingParticle->
g4Track_end();
444 if( iSimTrack->eventId() == identifier.second && iSimTrack->trackId() == identifier.first )
466 double doubleCount=0.0;
467 std::vector < SimHitIdpr > SimTrackIdsDC;
469 for( iter iHit=startIterator; iHit != endIterator; iHit++ )
473 SimTrackIdsDC.clear();
475 if( SimTrackIdsDC.size() > 1 )
480 if(
find( SimTrackIdsDC.begin(), SimTrackIdsDC.end(),
SimHitIdpr( ( *g4T).trackId(), SimTrackIdsDC.begin()->second ) )
481 != SimTrackIdsDC.end() )
490 doubleCount += weight*(idcount - 1);
515 double doubleCount=0;
516 std::vector < SimHitIdpr > SimTrackIdsDC;
518 for( iter iHit=startIterator; iHit != endIterator; iHit++ )
521 for( std::vector<OmniClusterRef>::const_iterator it=oClusters.begin(); it != oClusters.end(); ++it )
526 if( range.first != range.second )
528 for(
auto ip=range.first; ip != range.second; ++ip )
531 if( associatedTrackingParticle == trackingParticle )
541 doubleCount += weight*(idcount - 1);
553 edm::LogVerbatim(
"TrackAssociator" ) <<
"Starting TrackAssociatorByHitsImpl::associateRecoToSim - #seeds=" << pSeedCollectionHandle_->size()
554 <<
" #TPs=" << trackingParticleCollectionHandle->size();
558 size_t collectionSize=pSeedCollectionHandle_->size();
560 for(
size_t i=0;
i < collectionSize; ++
i )
565 std::vector < std::pair<edm::Ref<TrackingParticleCollection>,
double> > trackingParticleQualityPairs=
567 for(
auto iTrackingParticleQualityPair=
568 trackingParticleQualityPairs.begin(); iTrackingParticleQualityPair != trackingParticleQualityPairs.end();
569 ++iTrackingParticleQualityPair )
572 double numberOfSharedClusters=iTrackingParticleQualityPair->second;
575 if( numberOfSharedClusters == 0.0 )
continue;
578 if(
abs( trackingParticleRef->pdgId() ) == 11 && (trackingParticleRef->g4Track_end() - trackingParticleRef->g4Track_begin()) > 1 )
586 else if( numberOfValidTrackClusters != 0.0 ) quality = numberOfSharedClusters / numberOfValidTrackClusters;
596 LogTrace(
"TrackAssociator" ) <<
"% of Assoc Seeds=" << ((double)returnValue.
size()) / ((
double)pSeedCollectionHandle_->size());
606 edm::LogVerbatim(
"TrackAssociator" ) <<
"Starting TrackAssociatorByHitsImpl::associateSimToReco - #seeds=" << pSeedCollectionHandle_->size()
607 <<
" #TPs=" << trackingParticleCollectionHandle->size();
610 if(trackingParticleCollectionHandle->empty())
614 checkClusterMapProductID(*
clusterToTPMap_, trackingParticleCollectionHandle);
617 size_t collectionSize=pSeedCollectionHandle_->size();
619 for(
size_t i=0;
i < collectionSize; ++
i )
624 std::vector < std::pair<edm::Ref<TrackingParticleCollection>,
double> > trackingParticleQualityPairs=
626 for(
auto iTrackingParticleQualityPair=
627 trackingParticleQualityPairs.begin(); iTrackingParticleQualityPair != trackingParticleQualityPairs.end();
628 ++iTrackingParticleQualityPair )
631 double numberOfSharedClusters=iTrackingParticleQualityPair->second;
633 size_t numberOfSimulatedHits=0;
635 if( numberOfSharedClusters == 0.0 )
continue;
638 if(
abs( trackingParticleRef->pdgId() ) == 11 && (trackingParticleRef->g4Track_end() - trackingParticleRef->g4Track_begin()) > 1 )
650 numberOfSimulatedHits=trackingParticleRef->numberOfTrackerHits();
653 double purity = numberOfSharedClusters / numberOfValidTrackClusters;
657 /
static_cast<double>( numberOfSimulatedHits );
669 LogTrace(
"TrackAssociator") <<
"% of Assoc TPs=" << ((double)returnValue.
size())/((
double)trackingParticleCollectionHandle->size());
684 for(
auto iHit=seed.
recHits().first; iHit!=seed.
recHits().second; ++iHit) {
697 const auto& hitRange = seed.
recHits();
703 double weightedClusters = 0.0;
704 for (iter iRecHit = begin; iRecHit !=
end; ++iRecHit) {
709 LogTrace(
"QuickTrackAssociatorByHitsImpl") <<
" weight: " <<
weight;
711 for( std::vector<OmniClusterRef>::const_iterator it=oClusters.begin(); it != oClusters.end(); ++it ) {
712 weightedClusters +=
weight;
715 LogTrace(
"QuickTrackAssociatorByHitsImpl") <<
" total weighted clusters: " << weightedClusters;
717 return weightedClusters;
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(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
trackingParticleCollection
constexpr uint32_t rawId() const
get the raw id
std::vector< OmniClusterRef > hitsToClusterRefs(iter begin, iter end)
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.
bool has(unsigned int index) const
Check if an element (=index) is in the set.
void post_insert()
post insert action
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector's numbering enum) ...
Abs< T >::type abs(const T &t)
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
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.
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
std::pair< uint32_t, EncodedEventId > SimTrackIdentifiers
This is enough information to uniquely identify a sim track.
std::pair< uint32_t, EncodedEventId > SimHitIdpr
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.
const TrackingRecHit * getHitFromIter(trackingRecHit_iterator iter)
bool absoluteNumberOfHits_
void checkMappedProductID(const edm::HandleBase &mappedHandle) const
std::vector< SimHitIdpr > associateHitId(const TrackingRecHit &thit) const
unsigned int nHits() const
double weightedNumberOfTrackClusters(const reco::Track &track, const TrackerHitAssociator &) const
int numberOfValidPixelHits() const
size_type size() const
Size of the RefVector.
Monte Carlo truth information used for tracking validation.
void insert(unsigned int index)
Insert an element (=index) to the set.
DetId geographicalId() const
g4t_iterator g4Track_end() const
void reserve(unsigned int size)
Reserve memory for the set.
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::unique_ptr< const TrackerHitAssociator > hitAssociator_
trackingRecHit_iterator recHitsEnd() const
Iterator to last hit on the track.