24 template <
class T_element>
26 return collection.
size();
29 template <
class T_element>
31 return hCollection->size();
34 template <
class T_element>
36 return collection.
size();
40 return &*trackCollection[
index];
44 return &(*pTrackCollection.product())[index];
49 return &(*pCollection.
product())[index];
54 return &*collection[
index];
58 return trackCollection[
index];
73 return collection[
index];
78 for (
const auto& ref : collection) {
83 template <
typename Coll>
84 void checkClusterMapProductID(
const ClusterTPAssociation& clusterToTPMap,
const Coll& collection) {
88 template <
typename Coll>
94 std::unique_ptr<const TrackerHitAssociator> hitAssoc,
97 bool absoluteNumberOfHits,
98 double qualitySimToReco,
99 double puritySimToReco,
100 double pixelHitWeight,
102 bool threeHitTracksAreSpecial,
104 : productGetter_(&productGetter),
105 hitAssociator_(
std::
move(hitAssoc)),
106 clusterToTPMap_(clusterToTPMap),
107 qualitySimToReco_(qualitySimToReco),
108 puritySimToReco_(puritySimToReco),
109 pixelHitWeight_(pixelHitWeight),
110 cutRecoToSim_(cutRecoToSim),
111 simToRecoDenominator_(simToRecoDenominator),
112 threeHitTracksAreSpecial_(threeHitTracksAreSpecial),
113 absoluteNumberOfHits_(absoluteNumberOfHits) {}
121 trackCollectionHandle, trackingParticleCollectionHandle,
nullptr, *
hitAssociator_);
124 trackCollectionHandle, trackingParticleCollectionHandle,
nullptr, *clusterToTPMap_);
133 trackCollectionHandle, trackingParticleCollectionHandle,
nullptr, *
hitAssociator_);
136 trackCollectionHandle, trackingParticleCollectionHandle,
nullptr, *clusterToTPMap_);
147 fillKeys(tpKeys, trackingParticleCollection);
160 fillKeys(tpKeys, trackingParticleCollection);
165 template <
class T_TrackCollection,
class T_TrackingParticleCollection,
class T_hitOrClusterAssociator>
170 T_hitOrClusterAssociator hitOrClusterAssociator)
const {
172 if (::collectionSize(trackingParticleCollection) == 0)
175 checkClusterMapProductID(hitOrClusterAssociator, trackingParticleCollection);
177 size_t collectionSize = ::collectionSize(trackCollection);
179 for (
size_t i = 0;
i < collectionSize; ++
i) {
184 std::vector<std::pair<edm::Ref<TrackingParticleCollection>,
double> > trackingParticleQualityPairs =
186 trackingParticleCollection,
187 trackingParticleKeys,
192 for (
auto iTrackingParticleQualityPair = trackingParticleQualityPairs.begin();
193 iTrackingParticleQualityPair != trackingParticleQualityPairs.end();
194 ++iTrackingParticleQualityPair) {
196 double numberOfSharedClusters = iTrackingParticleQualityPair->second;
199 if (numberOfSharedClusters == 0.0)
203 if (
abs(trackingParticleRef->pdgId()) == 11 &&
204 (trackingParticleRef->g4Track_end() - trackingParticleRef->g4Track_begin()) > 1) {
205 numberOfSharedClusters -=
211 quality = numberOfSharedClusters;
212 else if (numberOfValidTrackClusters != 0.0)
213 quality = numberOfSharedClusters / numberOfValidTrackClusters;
219 returnValue.
insert(::getRefToTrackAt(trackCollection,
i), std::make_pair(trackingParticleRef, quality));
227 template <
class T_TrackCollection,
class T_TrackingParticleCollection,
class T_hitOrClusterAssociator>
232 T_hitOrClusterAssociator hitOrClusterAssociator)
const {
234 if (::collectionSize(trackingParticleCollection) == 0)
237 checkClusterMapProductID(hitOrClusterAssociator, trackingParticleCollection);
239 size_t collectionSize = ::collectionSize(trackCollection);
241 for (
size_t i = 0;
i < collectionSize; ++
i) {
246 std::vector<std::pair<edm::Ref<TrackingParticleCollection>,
double> > trackingParticleQualityPairs =
248 trackingParticleCollection,
249 trackingParticleKeys,
254 for (
auto iTrackingParticleQualityPair = trackingParticleQualityPairs.begin();
255 iTrackingParticleQualityPair != trackingParticleQualityPairs.end();
256 ++iTrackingParticleQualityPair) {
258 double numberOfSharedClusters = iTrackingParticleQualityPair->second;
260 size_t numberOfSimulatedHits = 0;
262 if (numberOfSharedClusters == 0.0)
266 (numberOfSharedClusters < 3.0 &&
273 numberOfSimulatedHits = trackingParticleRef->numberOfTrackerHits();
277 if (
abs(trackingParticleRef->pdgId()) == 11 &&
278 (trackingParticleRef->g4Track_end() - trackingParticleRef->g4Track_begin()) > 1) {
279 numberOfSharedClusters -=
283 double purity = numberOfSharedClusters / numberOfValidTrackClusters;
286 quality = numberOfSharedClusters;
288 quality = numberOfSharedClusters /
static_cast<double>(numberOfSimulatedHits);
298 returnValue.
insert(trackingParticleRef, std::make_pair(::getRefToTrackAt(trackCollection,
i), quality));
306 template <
typename T_TPCollection,
typename iter>
314 std::vector<std::pair<edm::Ref<TrackingParticleCollection>,
double> > returnValue;
319 std::vector<std::pair<SimTrackIdentifiers, double> > hitIdentifiers =
323 size_t collectionSize = ::collectionSize(trackingParticles);
325 for (
size_t i = 0;
i < collectionSize; ++
i) {
326 const TrackingParticle* pTrackingParticle = getTrackingParticleAt(trackingParticles,
i);
335 double numberOfAssociatedHits = 0;
338 for (
const auto& identifierCountPair : hitIdentifiers) {
340 numberOfAssociatedHits += identifierCountPair.second;
343 if (numberOfAssociatedHits > 0) {
344 returnValue.push_back(std::make_pair(getRefToTrackingParticleAt(trackingParticles,
i), numberOfAssociatedHits));
351 template <
typename T_TPCollection,
typename iter>
372 std::vector<std::pair<edm::Ref<TrackingParticleCollection>,
double> > returnValue;
373 if (clusterToTPMap.
empty())
382 std::map<TrackingParticleRef, double> lmap;
383 for (std::vector<OmniClusterRef>::const_iterator it = oClusters.begin(); it != oClusters.end(); ++it) {
387 for (
auto ip =
range.first; ip !=
range.second; ++ip) {
390 if (trackingParticleKeys && !trackingParticleKeys->
has(trackingParticle.
key()))
413 auto jpos = lmap.find(trackingParticle);
414 if (jpos != lmap.end())
415 jpos->second += weight;
417 lmap.insert(std::make_pair(trackingParticle, weight));
422 for (
auto ip = lmap.begin(); ip != lmap.end(); ++ip) {
423 returnValue.push_back(std::make_pair(ip->first, ip->second));
428 template <
typename iter>
429 std::vector<std::pair<QuickTrackAssociatorByHitsImpl::SimTrackIdentifiers, double> >
434 std::vector<std::pair<SimTrackIdentifiers, double> > returnValue;
436 std::vector<SimTrackIdentifiers> simTrackIdentifiers;
439 for (iter iRecHit = begin; iRecHit !=
end; ++iRecHit) {
441 simTrackIdentifiers.clear();
446 simTrackIdentifiers);
454 for (std::vector<SimTrackIdentifiers>::const_iterator iIdentifier = simTrackIdentifiers.begin();
455 iIdentifier != simTrackIdentifiers.end();
457 std::vector<std::pair<SimTrackIdentifiers, double> >::iterator iIdentifierCountPair;
458 for (
auto iIdentifierCountPair = returnValue.begin(); iIdentifierCountPair != returnValue.end();
459 ++iIdentifierCountPair) {
460 if (iIdentifierCountPair->first.first == iIdentifier->first &&
461 iIdentifierCountPair->first.second == iIdentifier->second) {
463 iIdentifierCountPair->second +=
weight;
467 if (iIdentifierCountPair == returnValue.end())
468 returnValue.push_back(std::make_pair(*iIdentifier, 1.0));
479 for (std::vector<SimTrack>::const_iterator iSimTrack = pTrackingParticle->
g4Track_begin();
483 if (iSimTrack->eventId() == identifier.second && iSimTrack->trackId() == identifier.first) {
493 template <
typename iter>
507 double doubleCount = 0.0;
508 std::vector<SimHitIdpr> SimTrackIdsDC;
510 for (iter iHit = startIterator; iHit != endIterator; iHit++) {
513 SimTrackIdsDC.clear();
515 if (SimTrackIdsDC.size() > 1) {
517 g4T != associatedTrackingParticle->g4Track_end();
519 if (
find(SimTrackIdsDC.begin(),
521 SimHitIdpr((*g4T).trackId(), SimTrackIdsDC.begin()->second)) != SimTrackIdsDC.end()) {
531 doubleCount += weight * (idcount - 1);
538 template <
typename iter>
559 double doubleCount = 0;
560 std::vector<SimHitIdpr> SimTrackIdsDC;
562 for (iter iHit = startIterator; iHit != endIterator; iHit++) {
563 std::vector<OmniClusterRef> oClusters =
565 for (std::vector<OmniClusterRef>::const_iterator it = oClusters.begin(); it != oClusters.end(); ++it) {
570 for (
auto ip =
range.first; ip !=
range.second; ++ip) {
572 if (associatedTrackingParticle == trackingParticle) {
583 doubleCount += weight * (idcount - 1);
594 edm::LogVerbatim(
"TrackAssociator") <<
"Starting TrackAssociatorByHitsImpl::associateRecoToSim - #seeds=" 595 << pSeedCollectionHandle_->size()
596 <<
" #TPs=" << trackingParticleCollectionHandle->size();
600 size_t collectionSize = pSeedCollectionHandle_->size();
602 for (
size_t i = 0;
i < collectionSize; ++
i) {
606 std::vector<std::pair<edm::Ref<TrackingParticleCollection>,
double> > trackingParticleQualityPairs =
608 trackingParticleCollectionHandle,
613 trackingParticleCollectionHandle,
617 for (
auto iTrackingParticleQualityPair = trackingParticleQualityPairs.begin();
618 iTrackingParticleQualityPair != trackingParticleQualityPairs.end();
619 ++iTrackingParticleQualityPair) {
621 double numberOfSharedClusters = iTrackingParticleQualityPair->second;
625 if (numberOfSharedClusters == 0.0)
629 if (
abs(trackingParticleRef->pdgId()) == 11 &&
630 (trackingParticleRef->g4Track_end() - trackingParticleRef->g4Track_begin()) > 1) {
632 numberOfSharedClusters -=
635 numberOfSharedClusters -=
641 quality = numberOfSharedClusters;
642 else if (numberOfValidTrackClusters != 0.0)
643 quality = numberOfSharedClusters / numberOfValidTrackClusters;
650 std::make_pair(trackingParticleRef, quality));
655 LogTrace(
"TrackAssociator") <<
"% of Assoc Seeds=" 656 << ((double)returnValue.
size()) / ((
double)pSeedCollectionHandle_->size());
664 edm::LogVerbatim(
"TrackAssociator") <<
"Starting TrackAssociatorByHitsImpl::associateSimToReco - #seeds=" 665 << pSeedCollectionHandle_->size()
666 <<
" #TPs=" << trackingParticleCollectionHandle->size();
669 if (trackingParticleCollectionHandle->empty())
673 checkClusterMapProductID(*
clusterToTPMap_, trackingParticleCollectionHandle);
676 size_t collectionSize = pSeedCollectionHandle_->size();
678 for (
size_t i = 0;
i < collectionSize; ++
i) {
682 std::vector<std::pair<edm::Ref<TrackingParticleCollection>,
double> > trackingParticleQualityPairs =
684 trackingParticleCollectionHandle,
689 trackingParticleCollectionHandle,
693 for (
auto iTrackingParticleQualityPair = trackingParticleQualityPairs.begin();
694 iTrackingParticleQualityPair != trackingParticleQualityPairs.end();
695 ++iTrackingParticleQualityPair) {
697 double numberOfSharedClusters = iTrackingParticleQualityPair->second;
700 size_t numberOfSimulatedHits = 0;
702 if (numberOfSharedClusters == 0.0)
706 if (
abs(trackingParticleRef->pdgId()) == 11 &&
707 (trackingParticleRef->g4Track_end() - trackingParticleRef->g4Track_begin()) > 1) {
709 numberOfSharedClusters -=
712 numberOfSharedClusters -=
717 (numberOfSharedClusters < 3.0 &&
724 numberOfSimulatedHits = trackingParticleRef->numberOfTrackerHits();
727 double purity = numberOfSharedClusters / numberOfValidTrackClusters;
730 quality = numberOfSharedClusters;
732 quality = numberOfSharedClusters /
static_cast<double>(numberOfSimulatedHits);
741 returnValue.
insert(trackingParticleRef,
747 LogTrace(
"TrackAssociator") <<
"% of Assoc TPs=" 748 << ((double)returnValue.
size()) / ((
double)trackingParticleCollectionHandle->size());
765 for (
auto iHit = seed.
recHits().first; iHit != seed.
recHits().second; ++iHit) {
782 const auto& hitRange = seed.
recHits();
786 template <
typename iter>
788 double weightedClusters = 0.0;
789 for (iter iRecHit = begin; iRecHit !=
end; ++iRecHit) {
794 LogTrace(
"QuickTrackAssociatorByHitsImpl")
796 LogTrace(
"QuickTrackAssociatorByHitsImpl") <<
" weight: " <<
weight;
797 std::vector<OmniClusterRef> oClusters =
799 for (std::vector<OmniClusterRef>::const_iterator it = oClusters.begin(); it != oClusters.end(); ++it) {
800 weightedClusters +=
weight;
803 LogTrace(
"QuickTrackAssociatorByHitsImpl") <<
" total weighted clusters: " << weightedClusters;
805 return weightedClusters;
reco::SimToRecoCollection associateSimToReco(const edm::Handle< edm::View< reco::Track > > &trackCollectionHandle, const edm::Handle< TrackingParticleCollection > &trackingParticleCollectionHandle) const override
std::pair< uint32_t, EncodedEventId > SimTrackIdentifiers
This is enough information to uniquely identify a sim track.
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
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 > 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.