24 template <
class T_element>
29 template <
class T_element>
31 return hCollection->size();
34 template <
class T_element>
44 return &(*pTrackCollection.product())[
index];
79 keys.insert(ref.key());
83 template <
typename Coll>
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,
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_);
165 template <
class T_TrackCollection,
class T_TrackingParticleCollection,
class T_hitOrClusterAssociator>
170 T_hitOrClusterAssociator hitOrClusterAssociator)
const {
179 for (
size_t i = 0;
i < collectionSize; ++
i) {
184 std::vector<std::pair<edm::Ref<TrackingParticleCollection>,
double> > trackingParticleQualityPairs =
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;
227 template <
class T_TrackCollection,
class T_TrackingParticleCollection,
class T_hitOrClusterAssociator>
232 T_hitOrClusterAssociator hitOrClusterAssociator)
const {
241 for (
size_t i = 0;
i < collectionSize; ++
i) {
246 std::vector<std::pair<edm::Ref<TrackingParticleCollection>,
double> > trackingParticleQualityPairs =
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);
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 =
325 for (
size_t i = 0;
i < collectionSize; ++
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())
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());
757 const auto pixelHits =
p.numberOfValidPixelHits();
758 const auto otherHits =
p.numberOfValidHits() - pixelHits;
765 for (
auto iHit =
seed.recHits().begin(); iHit !=
seed.recHits().end(); ++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;
804 return weightedClusters;