26 template <
class T_element>
31 template <
class T_element>
33 return hCollection->size();
36 template <
class T_element>
41 template <
typename T_Track>
46 template <
typename T_Coll>
48 return &(*pTrackCollection)[
index];
51 template <
typename T_Track>
53 return std::count_if(
track.recHits().begin(),
track.recHits().end(), [](
auto const&
h) {
return h.isValid(); });
57 return track.numberOfValidHits();
70 template <
typename T_Track>
74 template <
typename T_Track>
78 template <
typename T_Track>
97 keys.insert(ref.key());
101 template <
typename Coll>
106 template <
typename Coll>
112 std::unique_ptr<const TrackerHitAssociator> hitAssoc,
115 bool absoluteNumberOfHits,
116 double qualitySimToReco,
117 double puritySimToReco,
118 double pixelHitWeight,
120 bool threeHitTracksAreSpecial,
123 hitAssociator_(
std::
move(hitAssoc)),
124 clusterToTPMap_(clusterToTPMap),
125 qualitySimToReco_(qualitySimToReco),
126 puritySimToReco_(puritySimToReco),
127 pixelHitWeight_(pixelHitWeight),
128 cutRecoToSim_(cutRecoToSim),
129 simToRecoDenominator_(simToRecoDenominator),
130 threeHitTracksAreSpecial_(threeHitTracksAreSpecial),
131 absoluteNumberOfHits_(absoluteNumberOfHits) {}
138 return associateRecoToSimImplementation<reco::RecoToSimCollection>(
139 trackCollectionHandle, trackingParticleCollectionHandle,
nullptr, *
hitAssociator_);
141 return associateRecoToSimImplementation<reco::RecoToSimCollection>(
142 trackCollectionHandle, trackingParticleCollectionHandle,
nullptr, *
clusterToTPMap_);
150 return associateSimToRecoImplementation<reco::SimToRecoCollection>(
151 trackCollectionHandle, trackingParticleCollectionHandle,
nullptr, *
hitAssociator_);
153 return associateSimToRecoImplementation<reco::SimToRecoCollection>(
154 trackCollectionHandle, trackingParticleCollectionHandle,
nullptr, *
clusterToTPMap_);
162 return associateRecoToSimImplementation<reco::RecoToSimCollection>(
167 return associateRecoToSimImplementation<reco::RecoToSimCollection>(
177 return associateSimToRecoImplementation<reco::SimToRecoCollection>(
182 return associateSimToRecoImplementation<reco::SimToRecoCollection>(
187 template <
class T_RecoToSimCollection,
188 class T_TrackCollection,
189 class T_TrackingParticleCollection,
190 class T_hitOrClusterAssociator>
195 T_hitOrClusterAssociator hitOrClusterAssociator)
const {
204 for (
size_t i = 0;
i < collectionSize; ++
i) {
209 std::vector<std::pair<edm::Ref<TrackingParticleCollection>,
double>> trackingParticleQualityPairs =
212 trackingParticleKeys,
213 pTrack->recHits().begin(),
214 pTrack->recHits().end());
217 for (
auto iTrackingParticleQualityPair = trackingParticleQualityPairs.begin();
218 iTrackingParticleQualityPair != trackingParticleQualityPairs.end();
219 ++iTrackingParticleQualityPair) {
221 double numberOfSharedClusters = iTrackingParticleQualityPair->second;
224 if (numberOfSharedClusters == 0.0)
228 if (
abs(trackingParticleRef->pdgId()) == 11 &&
229 (trackingParticleRef->g4Track_end() - trackingParticleRef->g4Track_begin()) > 1) {
231 hitOrClusterAssociator, pTrack->recHits().begin(), pTrack->recHits().end(), trackingParticleRef);
236 quality = numberOfSharedClusters;
237 else if (numberOfValidTrackClusters != 0.0)
238 quality = numberOfSharedClusters / numberOfValidTrackClusters;
248 returnValue.post_insert();
252 template <
class T_SimToRecoCollection,
253 class T_TrackCollection,
254 class T_TrackingParticleCollection,
255 class T_hitOrClusterAssociator>
260 T_hitOrClusterAssociator hitOrClusterAssociator)
const {
269 for (
size_t i = 0;
i < collectionSize; ++
i) {
274 std::vector<std::pair<edm::Ref<TrackingParticleCollection>,
double>> trackingParticleQualityPairs =
277 trackingParticleKeys,
278 pTrack->recHits().begin(),
279 pTrack->recHits().end());
282 for (
auto iTrackingParticleQualityPair = trackingParticleQualityPairs.begin();
283 iTrackingParticleQualityPair != trackingParticleQualityPairs.end();
284 ++iTrackingParticleQualityPair) {
286 double numberOfSharedClusters = iTrackingParticleQualityPair->second;
288 size_t numberOfSimulatedHits = 0;
290 if (numberOfSharedClusters == 0.0)
294 (numberOfSharedClusters < 3.0 &&
301 numberOfSimulatedHits = trackingParticleRef->numberOfTrackerHits();
305 if (
abs(trackingParticleRef->pdgId()) == 11 &&
306 (trackingParticleRef->g4Track_end() - trackingParticleRef->g4Track_begin()) > 1) {
308 hitOrClusterAssociator, pTrack->recHits().begin(), pTrack->recHits().end(), trackingParticleRef);
311 double purity = numberOfSharedClusters / numberOfValidTrackClusters;
314 quality = numberOfSharedClusters;
316 quality = numberOfSharedClusters /
static_cast<double>(numberOfSimulatedHits);
330 returnValue.post_insert();
334 template <
typename T_TPCollection,
typename iter>
342 std::vector<std::pair<edm::Ref<TrackingParticleCollection>,
double>> returnValue;
347 std::vector<std::pair<SimTrackIdentifiers, double>> hitIdentifiers =
353 for (
size_t i = 0;
i < collectionSize; ++
i) {
363 double numberOfAssociatedHits = 0;
366 for (
const auto& identifierCountPair : hitIdentifiers) {
368 numberOfAssociatedHits += identifierCountPair.second;
371 if (numberOfAssociatedHits > 0) {
372 returnValue.push_back(std::make_pair(getRefToTrackingParticleAt(
trackingParticles,
i), numberOfAssociatedHits));
379 template <
typename T_TPCollection,
typename iter>
400 std::vector<std::pair<edm::Ref<TrackingParticleCollection>,
double>> returnValue;
401 if (clusterToTPMap.
empty())
410 std::map<TrackingParticleRef, double> lmap;
411 for (std::vector<OmniClusterRef>::const_iterator
it = oClusters.begin();
it != oClusters.end(); ++
it) {
415 for (
auto ip =
range.first; ip !=
range.second; ++ip) {
418 if (trackingParticleKeys && !trackingParticleKeys->
has(trackingParticle.
key()))
441 auto jpos = lmap.find(trackingParticle);
442 if (jpos != lmap.end())
445 lmap.insert(std::make_pair(trackingParticle,
weight));
450 for (
auto ip = lmap.begin(); ip != lmap.end(); ++ip) {
451 returnValue.push_back(std::make_pair(ip->first, ip->second));
456 template <
typename iter>
457 std::vector<std::pair<QuickTrackAssociatorByHitsImpl::SimTrackIdentifiers, double>>
462 std::vector<std::pair<SimTrackIdentifiers, double>> returnValue;
464 std::vector<SimTrackIdentifiers> simTrackIdentifiers;
467 for (iter iRecHit = begin; iRecHit !=
end; ++iRecHit) {
469 simTrackIdentifiers.clear();
474 simTrackIdentifiers);
482 for (std::vector<SimTrackIdentifiers>::const_iterator iIdentifier = simTrackIdentifiers.begin();
483 iIdentifier != simTrackIdentifiers.end();
485 std::vector<std::pair<SimTrackIdentifiers, double>>::iterator iIdentifierCountPair;
486 for (
auto iIdentifierCountPair = returnValue.begin(); iIdentifierCountPair != returnValue.end();
487 ++iIdentifierCountPair) {
488 if (iIdentifierCountPair->first.first == iIdentifier->first &&
489 iIdentifierCountPair->first.second == iIdentifier->second) {
491 iIdentifierCountPair->second +=
weight;
495 if (iIdentifierCountPair == returnValue.end())
496 returnValue.push_back(std::make_pair(*iIdentifier, 1.0));
507 for (std::vector<SimTrack>::const_iterator iSimTrack = pTrackingParticle->
g4Track_begin();
511 if (iSimTrack->eventId() == identifier.second && iSimTrack->trackId() == identifier.first) {
521 template <
typename iter>
535 double doubleCount = 0.0;
536 std::vector<SimHitIdpr> SimTrackIdsDC;
538 for (iter iHit = startIterator; iHit != endIterator; iHit++) {
541 SimTrackIdsDC.clear();
543 if (SimTrackIdsDC.size() > 1) {
545 g4T != associatedTrackingParticle->g4Track_end();
547 if (
find(SimTrackIdsDC.begin(),
549 SimHitIdpr((*g4T).trackId(), SimTrackIdsDC.begin()->second)) != SimTrackIdsDC.end()) {
559 doubleCount +=
weight * (idcount - 1);
566 template <
typename iter>
587 double doubleCount = 0;
588 std::vector<SimHitIdpr> SimTrackIdsDC;
590 for (iter iHit = startIterator; iHit != endIterator; iHit++) {
591 std::vector<OmniClusterRef> oClusters =
593 for (std::vector<OmniClusterRef>::const_iterator
it = oClusters.begin();
it != oClusters.end(); ++
it) {
598 for (
auto ip =
range.first; ip !=
range.second; ++ip) {
600 if (associatedTrackingParticle == trackingParticle) {
611 doubleCount +=
weight * (idcount - 1);
622 edm::LogVerbatim(
"TrackAssociator") <<
"Starting TrackAssociatorByHitsImpl::associateRecoToSim - #seeds=" 623 << pSeedCollectionHandle_->size()
624 <<
" #TPs=" << trackingParticleCollectionHandle->size();
628 size_t collectionSize = pSeedCollectionHandle_->size();
630 for (
size_t i = 0;
i < collectionSize; ++
i) {
634 std::vector<std::pair<edm::Ref<TrackingParticleCollection>,
double>> trackingParticleQualityPairs =
636 trackingParticleCollectionHandle,
641 trackingParticleCollectionHandle,
645 for (
auto iTrackingParticleQualityPair = trackingParticleQualityPairs.begin();
646 iTrackingParticleQualityPair != trackingParticleQualityPairs.end();
647 ++iTrackingParticleQualityPair) {
649 double numberOfSharedClusters = iTrackingParticleQualityPair->second;
653 if (numberOfSharedClusters == 0.0)
657 if (
abs(trackingParticleRef->pdgId()) == 11 &&
658 (trackingParticleRef->g4Track_end() - trackingParticleRef->g4Track_begin()) > 1) {
660 numberOfSharedClusters -=
663 numberOfSharedClusters -=
669 quality = numberOfSharedClusters;
670 else if (numberOfValidTrackClusters != 0.0)
671 quality = numberOfSharedClusters / numberOfValidTrackClusters;
678 std::make_pair(trackingParticleRef,
quality));
683 LogTrace(
"TrackAssociator") <<
"% of Assoc Seeds=" 684 << ((double)returnValue.size()) / ((
double)pSeedCollectionHandle_->size());
685 returnValue.post_insert();
692 edm::LogVerbatim(
"TrackAssociator") <<
"Starting TrackAssociatorByHitsImpl::associateSimToReco - #seeds=" 693 << pSeedCollectionHandle_->size()
694 <<
" #TPs=" << trackingParticleCollectionHandle->size();
697 if (trackingParticleCollectionHandle->empty())
701 checkClusterMapProductID(*
clusterToTPMap_, trackingParticleCollectionHandle);
704 size_t collectionSize = pSeedCollectionHandle_->size();
706 for (
size_t i = 0;
i < collectionSize; ++
i) {
710 std::vector<std::pair<edm::Ref<TrackingParticleCollection>,
double>> trackingParticleQualityPairs =
712 trackingParticleCollectionHandle,
717 trackingParticleCollectionHandle,
721 for (
auto iTrackingParticleQualityPair = trackingParticleQualityPairs.begin();
722 iTrackingParticleQualityPair != trackingParticleQualityPairs.end();
723 ++iTrackingParticleQualityPair) {
725 double numberOfSharedClusters = iTrackingParticleQualityPair->second;
728 size_t numberOfSimulatedHits = 0;
730 if (numberOfSharedClusters == 0.0)
734 if (
abs(trackingParticleRef->pdgId()) == 11 &&
735 (trackingParticleRef->g4Track_end() - trackingParticleRef->g4Track_begin()) > 1) {
737 numberOfSharedClusters -=
740 numberOfSharedClusters -=
745 (numberOfSharedClusters < 3.0 &&
752 numberOfSimulatedHits = trackingParticleRef->numberOfTrackerHits();
755 double purity = numberOfSharedClusters / numberOfValidTrackClusters;
758 quality = numberOfSharedClusters;
760 quality = numberOfSharedClusters /
static_cast<double>(numberOfSimulatedHits);
769 returnValue.insert(trackingParticleRef,
775 LogTrace(
"TrackAssociator") <<
"% of Assoc TPs=" 776 << ((double)returnValue.size()) / ((
double)trackingParticleCollectionHandle->size());
777 returnValue.post_insert();
786 return associateRecoToSimImplementation<reco::RecoToSimCollectionTCandidate>(
787 trackCollectionHandle, trackingParticleCollectionHandle,
nullptr, *
hitAssociator_);
789 return associateRecoToSimImplementation<reco::RecoToSimCollectionTCandidate>(
790 trackCollectionHandle, trackingParticleCollectionHandle,
nullptr, *
clusterToTPMap_);
798 return associateSimToRecoImplementation<reco::SimToRecoCollectionTCandidate>(
799 trackCollectionHandle, trackingParticleCollectionHandle,
nullptr, *
hitAssociator_);
801 return associateSimToRecoImplementation<reco::SimToRecoCollectionTCandidate>(
802 trackCollectionHandle, trackingParticleCollectionHandle,
nullptr, *
clusterToTPMap_);
810 const auto pixelHits =
p.numberOfValidPixelHits();
811 const auto otherHits =
p.numberOfValidHits() -
pixelHits;
815 template <
typename T_Track>
819 for (
auto iHit =
seed.recHits().begin(); iHit !=
seed.recHits().end(); ++iHit) {
835 template <
typename T_Track>
838 const auto& hitRange =
seed.recHits();
842 template <
typename iter>
844 double weightedClusters = 0.0;
845 for (iter iRecHit = begin; iRecHit !=
end; ++iRecHit) {
850 LogTrace(
"QuickTrackAssociatorByHitsImpl")
852 LogTrace(
"QuickTrackAssociatorByHitsImpl") <<
" weight: " <<
weight;
853 std::vector<OmniClusterRef> oClusters =
855 for (std::vector<OmniClusterRef>::const_iterator
it = oClusters.begin();
it != oClusters.end(); ++
it) {
856 weightedClusters +=
weight;
859 LogTrace(
"QuickTrackAssociatorByHitsImpl") <<
" total weighted clusters: " << weightedClusters;
860 return weightedClusters;
Log< level::Info, true > LogVerbatim
std::pair< uint32_t, EncodedEventId > SimTrackIdentifiers
This is enough information to uniquely identify a sim track.
const bool isValid(const Frame &aFrame, const FrameQuality &aQuality, const uint16_t aExpectedPos)
double weightedNumberOfTrackClusters(const T_Track &track, const TrackerHitAssociator &) const
range equal_range(const OmniClusterRef &key) const
RecHitRange recHits() const
reco::RecoToSimCollection associateRecoToSim(const edm::Handle< edm::View< reco::Track > > &trackCollectionHandle, const edm::Handle< TrackingParticleCollection > &trackingParticleCollectionHandle) const override
trackingParticleCollection
T const * product() const
std::vector< OmniClusterRef > hitsToClusterRefs(iter begin, iter end)
bool has(unsigned int index) const
Check if an element (=index) is in the set.
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)
key_type key() const
Accessor for product key.
reco::SimToRecoCollection associateSimToReco(const edm::Handle< edm::View< reco::Track > > &trackCollectionHandle, const edm::Handle< TrackingParticleCollection > &trackingParticleCollectionHandle) const override
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_end() const
unsigned int nHits() const
Abs< T >::type abs(const T &t)
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector's numbering enum) ...
SimToRecoDenomType simToRecoDenominator_
const TrackingRecHit * getHitFromIter(trackingRecHit_iterator iter)
T_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< SimTrack >::const_iterator g4t_iterator
g4t_iterator g4Track_begin() const
std::pair< uint32_t, EncodedEventId > SimHitIdpr
DetId geographicalId() const
constexpr uint32_t rawId() const
get the raw id
bool absoluteNumberOfHits_
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 ...
void checkMappedProductID(const edm::HandleBase &mappedHandle) const
Monte Carlo truth information used for tracking validation.
EDProductGetter const * productGetter(std::atomic< void const *> const &iCache)
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
T_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.
double getDoubleCount(const TrackerHitAssociator &hitAssociator, iter begin, iter end, TrackingParticleRef associatedTrackingParticle) const
This method was copied almost verbatim from the standard TrackAssociatorByHits.
std::unique_ptr< const TrackerHitAssociator > hitAssociator_
bool trackingParticleContainsIdentifier(const TrackingParticle *pTrackingParticle, const SimTrackIdentifiers &identifier) const
Returns true if the supplied TrackingParticle has the supplied g4 track identifiers.