From 2fe556d70c958065959e9b10ac2610cf19c8bf0c Mon Sep 17 00:00:00 2001 From: Ian Tomalin Date: Sun, 13 Dec 2020 20:14:16 +0000 Subject: [PATCH 1/6] Clean up of L1 tracker cluster, stub and track assocation code --- .../L1TrackTrigger/interface/TTTypes.h | 23 +++- .../interface/TrackingParticleFwd.h | 2 + .../interface/TTClusterAssociationMap.h | 121 +++++++++-------- .../interface/TTStubAssociationMap.h | 104 +++++++++------ .../interface/TTTrackAssociationMap.h | 101 +++++++++----- .../plugins/TTClusterAssociator.cc | 60 ++++----- .../plugins/TTClusterAssociator.h | 18 +-- .../plugins/TTStubAssociator.cc | 92 ++++++------- .../plugins/TTStubAssociator.h | 22 +-- .../plugins/TTTrackAssociator.cc | 126 +++++++++--------- .../plugins/TTTrackAssociator.h | 20 +-- .../src/TTTrackAssociationMap.cc | 37 +++-- 12 files changed, 381 insertions(+), 345 deletions(-) diff --git a/DataFormats/L1TrackTrigger/interface/TTTypes.h b/DataFormats/L1TrackTrigger/interface/TTTypes.h index b78ce53efd8a4..1c46c4624c01d 100644 --- a/DataFormats/L1TrackTrigger/interface/TTTypes.h +++ b/DataFormats/L1TrackTrigger/interface/TTTypes.h @@ -19,15 +19,26 @@ #include "DataFormats/L1TrackTrigger/interface/TTTrack.h" #include "DataFormats/L1TrackTrigger/interface/TTTrack_TrackWord.h" -/// The reference types -typedef edm::Ref, Phase2TrackerDigi> Ref_Phase2TrackerDigi_; +/// Templated aliases +template using TTClusterDetSetVecT = edmNew::DetSetVector >; +template using TTStubDetSetVecT = edmNew::DetSetVector >; + +template using TTClusterRefT = edm::Ref, TTCluster >; +template using TTStubRefT = edm::Ref, TTStub >; -typedef edmNew::DetSetVector > TTClusterDetSetVec; -typedef edmNew::DetSetVector > TTStubDetSetVec; +template using TTTrackPtrT = edm::Ptr >; -typedef edm::Ref > TTStubRef; -typedef edm::Ref > TTClusterRef; +/// Specialized aliases +typedef edm::Ref, Phase2TrackerDigi> Ref_Phase2TrackerDigi_; typedef edmNew::DetSet > TTStubDetSet; +typedef TTClusterDetSetVecT TTClusterDetSetVec; +typedef TTStubDetSetVecT TTStubDetSetVec; + +typedef TTClusterRefT TTClusterRef; +typedef TTStubRefT TTStubRef; + +typedef TTTrackPtrT TTTrackPtr; + #endif diff --git a/SimDataFormats/TrackingAnalysis/interface/TrackingParticleFwd.h b/SimDataFormats/TrackingAnalysis/interface/TrackingParticleFwd.h index 8ce7e93de2e45..9b1ebbd9f4b1f 100644 --- a/SimDataFormats/TrackingAnalysis/interface/TrackingParticleFwd.h +++ b/SimDataFormats/TrackingAnalysis/interface/TrackingParticleFwd.h @@ -1,12 +1,14 @@ #ifndef TrackingAnalysis_TrackingParticleFwd_h #define TrackingAnalysis_TrackingParticleFwd_h #include +#include "DataFormats/Common/interface/Ptr.h" #include "DataFormats/Common/interface/Ref.h" #include "DataFormats/Common/interface/RefVector.h" #include "DataFormats/Common/interface/RefProd.h" class TrackingParticle; typedef std::vector TrackingParticleCollection; +typedef edm::Ptr TrackingParticlePtr; typedef edm::Ref TrackingParticleRef; typedef edm::RefVector TrackingParticleRefVector; typedef edm::RefProd TrackingParticleRefProd; diff --git a/SimTracker/TrackTriggerAssociation/interface/TTClusterAssociationMap.h b/SimTracker/TrackTriggerAssociation/interface/TTClusterAssociationMap.h index 3c61c14b7b44a..143e1e0435640 100644 --- a/SimTracker/TrackTriggerAssociation/interface/TTClusterAssociationMap.h +++ b/SimTracker/TrackTriggerAssociation/interface/TTClusterAssociationMap.h @@ -1,13 +1,16 @@ /*! \class TTClusterAssociationMap - * \brief Class to store the MC truth of L1 Track Trigger clusters - * \details After moving from SimDataFormats to DataFormats, - * the template structure of the class was maintained - * in order to accomodate any types other than PixelDigis - * in case there is such a need in the future. + * \brief Stores association of Truth Particles (TP) to L1 Track-Trigger Clusters + * + * \details Contains two maps. One associates each cluster to a vector + * of all TPs that made its hits. The other associates each TP + * to a vector of all clusters it contributed to. + * + * (The template structure is used to accomodate types + * other than PixelDigis, in case they are needed in future). * * \author Nicola Pozzobon * \date 2013, Jul 19 - * + * (tidy up: Ian Tomalin, 2020) */ #ifndef L1_TRACK_TRIGGER_CLUSTER_ASSOCIATION_FORMAT_H @@ -15,6 +18,8 @@ #include "DataFormats/Common/interface/Ref.h" #include "DataFormats/Common/interface/Ptr.h" +#include "DataFormats/L1TrackTrigger/interface/TTTypes.h" +#include "SimDataFormats/TrackingAnalysis/interface/TrackingParticleFwd.h" #include "DataFormats/Common/interface/DetSet.h" #include "DataFormats/Common/interface/DetSetVector.h" #include "DataFormats/Common/interface/DetSetVectorNew.h" @@ -29,6 +34,10 @@ #include "SimDataFormats/EncodedEventId/interface/EncodedEventId.h" #include "SimDataFormats/TrackingAnalysis/interface/TrackingParticle.h" +// Templated aliases +template using MapClusToVecTP = std::map, std::vector >; +template using MapTPToVecClus = std::map > >; + template class TTClusterAssociationMap { public: @@ -38,48 +47,46 @@ class TTClusterAssociationMap { /// Destructor ~TTClusterAssociationMap(); - /// Data members: getABC( ... ) - /// Helper methods: findABC( ... ) + /// Get/set cluster <-> truth association maps - /// Maps - std::map >, TTCluster >, std::vector > > - getTTClusterToTrackingParticlesMap() const { + const MapClusToVecTP& getTTClusterToTrackingParticlesMap() const { return clusterToTrackingParticleVectorMap; } - std::map, std::vector >, TTCluster > > > - getTrackingParticleToTTClustersMap() const { + const MapTPToVecClus& getTrackingParticleToTTClustersMap() const { return trackingParticleToClusterVectorMap; } - void setTTClusterToTrackingParticlesMap(std::map >, TTCluster >, - std::vector > > aMap) { + void setTTClusterToTrackingParticlesMap(const MapClusToVecTP& aMap) { clusterToTrackingParticleVectorMap = aMap; } - void setTrackingParticleToTTClustersMap( - std::map, std::vector >, TTCluster > > > - aMap) { + void setTrackingParticleToTTClustersMap(const MapTPToVecClus& aMap) { trackingParticleToClusterVectorMap = aMap; } - /// Operations - std::vector > findTrackingParticlePtrs( - edm::Ref >, TTCluster > aCluster) const; - edm::Ptr findTrackingParticlePtr( - edm::Ref >, TTCluster > aCluster) const; - std::vector >, TTCluster > > findTTClusterRefs( - edm::Ptr aTrackingParticle) const; + /// Get all TPs associated to a cluster + std::vector findTrackingParticlePtrs(TTClusterRefT aCluster) const; + /// Get main TP associated to a cluster. (Non-NULL if isGenuine() below is true). + TrackingParticlePtr findTrackingParticlePtr(TTClusterRefT aCluster) const; - /// MC Truth methods - bool isGenuine(edm::Ref >, TTCluster > aCluster) const; - bool isCombinatoric(edm::Ref >, TTCluster > aCluster) const; - bool isUnknown(edm::Ref >, TTCluster > aCluster) const; + // Get all clusters associated to TP. + std::vector> findTTClusterRefs(TrackingParticlePtr aTrackingParticle) const; + + ///--- Get quality of L1 cluster based on truth info. + /// (exactly 1 of following 3 functions is always true) + + /// Cluster "genuine": i.e. cluster associated to exactly 1 TP. + /// (If other TPs are associated, but have in total < 1% of Pt of main TP, + /// or if they are null, then they are neglected here). + bool isGenuine(TTClusterRefT aCluster) const; + /// Cluster "unknown": i.e. not associated with any TP. + bool isUnknown(TTClusterRefT aCluster) const; + /// Cluster is not "genuine" or "unknown". + bool isCombinatoric(TTClusterRefT aCluster) const; private: /// Data members - std::map >, TTCluster >, std::vector > > - clusterToTrackingParticleVectorMap; - std::map, std::vector >, TTCluster > > > - trackingParticleToClusterVectorMap; + MapClusToVecTP clusterToTrackingParticleVectorMap; + MapTPToVecClus trackingParticleToClusterVectorMap; int nclus; @@ -108,25 +115,25 @@ TTClusterAssociationMap::~TTClusterAssociationMap() {} /// Operations template -std::vector >, TTCluster > > -TTClusterAssociationMap::findTTClusterRefs(edm::Ptr aTrackingParticle) const { +std::vector< TTClusterRefT > +TTClusterAssociationMap::findTTClusterRefs(TrackingParticlePtr aTrackingParticle) const { if (trackingParticleToClusterVectorMap.find(aTrackingParticle) != trackingParticleToClusterVectorMap.end()) { return trackingParticleToClusterVectorMap.find(aTrackingParticle)->second; } - std::vector >, TTCluster > > tempVector; + std::vector< TTClusterRefT > tempVector; tempVector.clear(); return tempVector; } template -std::vector > TTClusterAssociationMap::findTrackingParticlePtrs( - edm::Ref >, TTCluster > aCluster) const { +std::vector TTClusterAssociationMap::findTrackingParticlePtrs( + TTClusterRefT aCluster) const { if (clusterToTrackingParticleVectorMap.find(aCluster) != clusterToTrackingParticleVectorMap.end()) { return clusterToTrackingParticleVectorMap.find(aCluster)->second; } - std::vector > tempVector; + std::vector tempVector; tempVector.clear(); return tempVector; } @@ -137,6 +144,8 @@ std::vector > TTClusterAssociationMap::findTrackin /// N = number of NULL TP pointers /// D = number of GOOD TP pointers different from each other /// +/// OLD DEFINITION +/// /// N / D--> | 0 | 1 | >1 /// ---------------------- /// 0 | U | G | C @@ -144,19 +153,19 @@ std::vector > TTClusterAssociationMap::findTrackin /// >0 | U | C | C /// -/// NEW SV 060617 +/// NEW DEFINITION SV 060617 /// -/// N / D--> | 0 | 1 | >1 (with 1 TP getting >99 of the total pT) | >1 +/// N / D--> | 0 | 1 | >1 (with 1 TP getting >99% of the total pT) | >1 /// ------------------------------------------------------------------- -/// 0 | U | G | G | C +/// 0 | U | G | G | C /// ------------------------------------------------------------------- -/// >0 | U | G | G | C +/// >0 | U | G | G | C /// template -bool TTClusterAssociationMap::isGenuine(edm::Ref >, TTCluster > aCluster) const { +bool TTClusterAssociationMap::isGenuine(TTClusterRefT aCluster) const { /// Get the TrackingParticles - std::vector > theseTrackingParticles = this->findTrackingParticlePtrs(aCluster); + std::vector theseTrackingParticles = this->findTrackingParticlePtrs(aCluster); /// If the vector is empty, then the cluster is UNKNOWN if (theseTrackingParticles.empty()) @@ -174,7 +183,7 @@ bool TTClusterAssociationMap::isGenuine(edm::Ref& curTP = tp; + const TrackingParticlePtr& curTP = tp; /// Count the NULL TrackingParticles if (curTP.isNull()) { @@ -191,7 +200,7 @@ bool TTClusterAssociationMap::isGenuine(edm::Ref curTP = theseTrackingParticles.at(itp); + TrackingParticlePtr curTP = theseTrackingParticles.at(itp); /// Count the NULL TrackingParticles if (tp_mom.at(itp) <= 0.01 * tp_tot) { @@ -212,9 +221,9 @@ bool TTClusterAssociationMap::isGenuine(edm::Ref -bool TTClusterAssociationMap::isUnknown(edm::Ref >, TTCluster > aCluster) const { +bool TTClusterAssociationMap::isUnknown(TTClusterRefT aCluster) const { /// Get the TrackingParticles - std::vector > theseTrackingParticles = this->findTrackingParticlePtrs(aCluster); + std::vector theseTrackingParticles = this->findTrackingParticlePtrs(aCluster); /// If the vector is empty, then the cluster is UNKNOWN if (theseTrackingParticles.empty()) @@ -227,7 +236,7 @@ bool TTClusterAssociationMap::isUnknown(edm::Ref curTP = theseTrackingParticles.at(itp); + TrackingParticlePtr curTP = theseTrackingParticles.at(itp); /// Count the non-NULL TrackingParticles if (!curTP.isNull()) { @@ -247,10 +256,9 @@ bool TTClusterAssociationMap::isUnknown(edm::Ref -bool TTClusterAssociationMap::isCombinatoric( - edm::Ref >, TTCluster > aCluster) const { +bool TTClusterAssociationMap::isCombinatoric(TTClusterRefT aCluster) const { /// Get the TrackingParticles - std::vector > theseTrackingParticles = this->findTrackingParticlePtrs(aCluster); + std::vector theseTrackingParticles = this->findTrackingParticlePtrs(aCluster); /// If the vector is empty, then the cluster is UNKNOWN if (theseTrackingParticles.empty()) @@ -272,7 +280,7 @@ bool TTClusterAssociationMap::isCombinatoric( /// Loop over the TrackingParticles for (unsigned int itp = 0; itp < theseTrackingParticles.size(); itp++) { /// Get the TrackingParticle - edm::Ptr curTP = theseTrackingParticles.at(itp); + TrackingParticlePtr curTP = theseTrackingParticles.at(itp); /// Count the NULL TrackingParticles if (curTP.isNull()) { @@ -296,13 +304,12 @@ bool TTClusterAssociationMap::isCombinatoric( } template -edm::Ptr TTClusterAssociationMap::findTrackingParticlePtr( - edm::Ref >, TTCluster > aCluster) const { +TrackingParticlePtr TTClusterAssociationMap::findTrackingParticlePtr(TTClusterRefT aCluster) const { if (this->isGenuine(aCluster)) { return this->findTrackingParticlePtrs(aCluster).at(0); } - edm::Ptr* temp = new edm::Ptr(); + TrackingParticlePtr* temp = new TrackingParticlePtr(); return *temp; } diff --git a/SimTracker/TrackTriggerAssociation/interface/TTStubAssociationMap.h b/SimTracker/TrackTriggerAssociation/interface/TTStubAssociationMap.h index b0d0ee293aee0..8ac9843da7a87 100644 --- a/SimTracker/TrackTriggerAssociation/interface/TTStubAssociationMap.h +++ b/SimTracker/TrackTriggerAssociation/interface/TTStubAssociationMap.h @@ -1,13 +1,18 @@ /*! \class TTStubAssociationMap - * \brief Class to store the MC truth of L1 Track Trigger stubs - * \details After moving from SimDataFormats to DataFormats, - * the template structure of the class was maintained - * in order to accomodate any types other than PixelDigis - * in case there is such a need in the future. + * \brief Stores association of Truth Particles (TP) to L1 Track-Trigger Stubs + * + * \details Contains two maps. One associates each stub to its principle TP. + * (i.e. Not to all TP that contributed to it). + * The other associates each TP to a vector of all stubs + * it contributed to. The two maps are therefore not + * forward-backward symmetric. + * + * (The template structure is used to accomodate types + * other than PixelDigis, in case they are needed in future). * * \author Nicola Pozzobon * \date 2013, Jul 19 - * + * (tidy up: Ian Tomalin, 2020) */ #ifndef L1_TRACK_TRIGGER_STUB_ASSOCIATION_FORMAT_H @@ -16,6 +21,8 @@ #include "DataFormats/Common/interface/Ref.h" #include "DataFormats/Common/interface/RefProd.h" #include "DataFormats/Common/interface/Ptr.h" +#include "DataFormats/L1TrackTrigger/interface/TTTypes.h" +#include "SimDataFormats/TrackingAnalysis/interface/TrackingParticleFwd.h" #include "DataFormats/Common/interface/DetSet.h" #include "DataFormats/Common/interface/DetSetVector.h" #include "DataFormats/Common/interface/DetSetVectorNew.h" @@ -32,6 +39,10 @@ #include "SimDataFormats/TrackingAnalysis/interface/TrackingParticle.h" #include "SimTracker/TrackTriggerAssociation/interface/TTClusterAssociationMap.h" +// Templated aliases +template using MapStubToTP = std::map, TrackingParticlePtr >; +template using MapTPToVecStub = std::map > >; + template class TTStubAssociationMap { public: @@ -41,47 +52,62 @@ class TTStubAssociationMap { /// Destructor ~TTStubAssociationMap(); - /// Data members: getABC( ... ) - /// Helper methods: findABC( ... ) + /// Get/set stub <-> truth association maps - /// Maps - std::map >, TTStub >, edm::Ptr > - getTTStubToTrackingParticleMap() const { + const MapStubToTP& getTTStubToTrackingParticleMap() const { return stubToTrackingParticleMap; } - std::map, std::vector >, TTStub > > > - getTrackingParticleToTTStubsMap() const { + const MapTPToVecStub& getTrackingParticleToTTStubsMap() const { return trackingParticleToStubVectorMap; } - void setTTStubToTrackingParticleMap( - std::map >, TTStub >, edm::Ptr > aMap) { + void setTTStubToTrackingParticleMap(const MapStubToTP& aMap) { stubToTrackingParticleMap = aMap; } - void setTrackingParticleToTTStubsMap( - std::map, std::vector >, TTStub > > > aMap) { + void setTrackingParticleToTTStubsMap(const MapTPToVecStub& aMap) { trackingParticleToStubVectorMap = aMap; } + + /// Set cluster <-> truth association object. void setTTClusterAssociationMap(edm::RefProd > aCluAssoMap) { theClusterAssociationMap = aCluAssoMap; } - /// Operations - edm::Ptr findTrackingParticlePtr(edm::Ref >, TTStub > aStub) const; - std::vector >, TTStub > > findTTStubRefs( - edm::Ptr aTrackingParticle) const; - - /// MC Truth methods - bool isGenuine(edm::Ref >, TTStub > aStub) const; - bool isCombinatoric(edm::Ref >, TTStub > aStub) const; - bool isUnknown(edm::Ref >, TTStub > aStub) const; + /// Get principle TP associated to a stub. (Non-NULL if isGenuine() below is true). + /// (N.B. There is no function returning all TP associated to a stub). + /// (P.S. As this function only returns principle TP, it is not used when constructing + /// the TTTrackAssociationMap). + TrackingParticlePtr findTrackingParticlePtr(TTStubRefT aStub) const; + + /// Get all stubs associated to a TP. + /// (Even if the TP just contributes to one cluster in stub, + /// and even if their are other such TP, it is still listed here). + std::vector> findTTStubRefs(TrackingParticlePtr aTrackingParticle) const; + + ///--- Get quality of stub based on truth info. + /// (N.B. Both genuine & combinatoric stubs contribute to "genuine" L1 tracks + /// associated by TTTrackAssociationMap). + /// (exactly 1 of following 3 functions is always true) + + /// If both clusters are unknown, the stub is "unknown". + /// If only one cluster is unknown, the stub is combinatoric. + /// If both clusters are genuine, and are associated to the same (main) TrackingParticle, + /// the stub is "genuine". + /// If both clusters are genuine, but are associated to different (main) TrackingParticles, + /// the stub is "combinatoric". + /// If one cluster is combinatoric and the other is genuine/combinatoric, and they both share exactly + /// one TrackingParticle in common, then the stub is "genuine". (The clusters can have other + /// TrackingParticles besides the shared one, as long as these are not shared). If instead the clusters + /// share 0 or ≥2 TrackingParticles in common, then the stub is "combinatoric". + + bool isGenuine(TTStubRefT aStub) const; + bool isCombinatoric(TTStubRefT aStub) const; + bool isUnknown(TTStubRefT aStub) const; private: /// Data members - std::map >, TTStub >, edm::Ptr > - stubToTrackingParticleMap; - std::map, std::vector >, TTStub > > > - trackingParticleToStubVectorMap; + MapStubToTP stubToTrackingParticleMap; + MapTPToVecStub trackingParticleToStubVectorMap; edm::RefProd > theClusterAssociationMap; }; /// Close class @@ -110,32 +136,30 @@ TTStubAssociationMap::~TTStubAssociationMap() {} /// Operations template -edm::Ptr TTStubAssociationMap::findTrackingParticlePtr( - edm::Ref >, TTStub > aStub) const { +TrackingParticlePtr TTStubAssociationMap::findTrackingParticlePtr(TTStubRefT aStub) const { if (stubToTrackingParticleMap.find(aStub) != stubToTrackingParticleMap.end()) { return stubToTrackingParticleMap.find(aStub)->second; } /// Default: return NULL - //edm::Ptr< TrackingParticle >* temp = new edm::Ptr< TrackingParticle >(); - return edm::Ptr(); + return TrackingParticlePtr(); } template -std::vector >, TTStub > > TTStubAssociationMap::findTTStubRefs( - edm::Ptr aTrackingParticle) const { +std::vector< TTStubRefT > TTStubAssociationMap::findTTStubRefs( + TrackingParticlePtr aTrackingParticle) const { if (trackingParticleToStubVectorMap.find(aTrackingParticle) != trackingParticleToStubVectorMap.end()) { return trackingParticleToStubVectorMap.find(aTrackingParticle)->second; } - std::vector >, TTStub > > tempVector; + std::vector< TTStubRefT > tempVector; tempVector.clear(); return tempVector; } /// MC truth template -bool TTStubAssociationMap::isGenuine(edm::Ref >, TTStub > aStub) const { +bool TTStubAssociationMap::isGenuine(TTStubRefT aStub) const { /// Check if there is a SimTrack if ((this->findTrackingParticlePtr(aStub)).isNull()) return false; @@ -144,7 +168,7 @@ bool TTStubAssociationMap::isGenuine(edm::Ref } template -bool TTStubAssociationMap::isCombinatoric(edm::Ref >, TTStub > aStub) const { +bool TTStubAssociationMap::isCombinatoric(TTStubRefT aStub) const { /// Defined by exclusion if (this->isGenuine(aStub)) return false; @@ -156,7 +180,7 @@ bool TTStubAssociationMap::isCombinatoric(edm::Ref -bool TTStubAssociationMap::isUnknown(edm::Ref >, TTStub > aStub) const { +bool TTStubAssociationMap::isUnknown(TTStubRefT aStub) const { /// UNKNOWN means that both clusters are unknown //std::vector< edm::Ref< edmNew::DetSetVector< TTCluster< T > >, TTCluster< T > > > theseClusters = aStub->getClusterRefs(); diff --git a/SimTracker/TrackTriggerAssociation/interface/TTTrackAssociationMap.h b/SimTracker/TrackTriggerAssociation/interface/TTTrackAssociationMap.h index c1478740a3277..33cf1838ca23f 100644 --- a/SimTracker/TrackTriggerAssociation/interface/TTTrackAssociationMap.h +++ b/SimTracker/TrackTriggerAssociation/interface/TTTrackAssociationMap.h @@ -1,13 +1,18 @@ /*! \class TTTrackAssociationMap - * \brief Class to store the MC truth of L1 Track Trigger tracks - * \details After moving from SimDataFormats to DataFormats, - * the template structure of the class was maintained - * in order to accomodate any types other than PixelDigis - * in case there is such a need in the future. + * \brief Stores association of Truth Particles (TP) to L1 Track-Trigger Tracks + * + * \details Contains two maps. One associates each L1 track its principle TP. + * (i.e. Not to all TP that contributed to it). + * The other associates each TP to a vector of all L1 tracks + * it contributed to. The two maps are therefore not + * forward-backward symmetric. + * + * (The template structure is used to accomodate types + * other than PixelDigis, in case they are needed in future). * * \author Nicola Pozzobon * \date 2013, Jul 19 - * + * (tidy up: Ian Tomalin, 2020) */ #ifndef L1_TRACK_TRIGGER_TRACK_ASSOCIATION_FORMAT_H @@ -15,6 +20,8 @@ #include "DataFormats/Common/interface/Ref.h" #include "DataFormats/Common/interface/Ptr.h" +#include "DataFormats/L1TrackTrigger/interface/TTTypes.h" +#include "SimDataFormats/TrackingAnalysis/interface/TrackingParticleFwd.h" #include "DataFormats/Common/interface/DetSet.h" #include "DataFormats/Common/interface/DetSetVector.h" #include "DataFormats/Common/interface/DetSetVectorNew.h" @@ -22,7 +29,6 @@ #include "DataFormats/Phase2TrackerDigi/interface/Phase2TrackerDigi.h" #include "DataFormats/GeometryCommonDetAlgo/interface/MeasurementPoint.h" #include "DataFormats/GeometryVector/interface/GlobalPoint.h" /// NOTE: this is needed even if it seems not -#include "DataFormats/L1TrackTrigger/interface/TTTypes.h" #include "SimDataFormats/TrackerDigiSimLink/interface/PixelDigiSimLink.h" #include "SimDataFormats/Track/interface/SimTrack.h" #include "SimDataFormats/Track/interface/SimTrackContainer.h" @@ -30,6 +36,10 @@ #include "SimDataFormats/TrackingAnalysis/interface/TrackingParticle.h" #include "SimTracker/TrackTriggerAssociation/interface/TTStubAssociationMap.h" +// Templated aliases +template using MapL1TrackToTP = std::map, TrackingParticlePtr >; +template using MapTPToVecL1Track = std::map> >; + template class TTTrackAssociationMap { public: @@ -39,45 +49,64 @@ class TTTrackAssociationMap { /// Destructor ~TTTrackAssociationMap(); - /// Data members: getABC( ... ) - /// Helper methods: findABC( ... ) + /// Get/set stub <-> truth association maps - /// Maps - std::map >, edm::Ptr > getTTTrackToTrackingParticleMap() const { + const MapL1TrackToTP& getTTTrackToTrackingParticleMap() const { return trackToTrackingParticleMap; } - std::map, std::vector > > > getTrackingParticleToTTTracksMap() const { + const MapTPToVecL1Track& getTrackingParticleToTTTracksMap() const { return trackingParticleToTrackVectorMap; } - void setTTTrackToTrackingParticleMap(std::map >, edm::Ptr > aMap) { + void setTTTrackToTrackingParticleMap(const MapL1TrackToTP& aMap) { trackToTrackingParticleMap = aMap; } - void setTrackingParticleToTTTracksMap( - std::map, std::vector > > > aMap) { + void setTrackingParticleToTTTracksMap(const MapTPToVecL1Track& aMap) { trackingParticleToTrackVectorMap = aMap; } + + /// Set stub <-> truth association object. void setTTStubAssociationMap(edm::RefProd > aStubAssoMap) { theStubAssociationMap = aStubAssoMap; } - /// Operations - edm::Ptr findTrackingParticlePtr(edm::Ptr > aTrack) const; - std::vector > > findTTTrackPtrs(edm::Ptr aTrackingParticle) const; - - /// MC Truth methods - bool isGenuine(edm::Ptr > aTrack) const; - bool isLooselyGenuine(edm::Ptr > aTrack) const; - bool isCombinatoric(edm::Ptr > aTrack) const; - bool isUnknown(edm::Ptr > aTrack) const; - + /// Get principle TP associated to a L1 track. (Non-NULL if isLooselyGenuine() below is true). + /// (N.B. There is no function returning all TP associated to a L1 track). + TrackingParticlePtr findTrackingParticlePtr(TTTrackPtrT aTrack) const; + + /// Get all L1 tracks associated to a TP. + /// (Even if the TP just contributes to one cluster in one stub, + /// and even if their are other such TP, it is still listed here). + std::vector > findTTTrackPtrs(TrackingParticlePtr aTrackingParticle) const; + + ///--- Get quality of L1 track based on truth info. + /// (N.B. "genuine" tracks are used for official L1 track efficiency measurements). + + /// Exactly one (i.e. not 0 or >= 2) unique TP contributes to every stub on the track. + /// (even if it is not the principle TP in a stub, or contributes to only one cluster + /// in the stub, it still counts). + /// N.B. If cfg param getAllowOneFalse2SStub() is true, then one incorrect stub in + /// a 2S module is alowed + /// ISSUE: a track with 4 stubs can be accepted if only 3 of its stubs are correct! + /// ISSUE: isLooselyGenuine() must also be true. So if 2 TPs match track, one with + /// an incorrect PS stub, both isGenuine() & isLooselyGenuine() will be false! + bool isGenuine(TTTrackPtrT aTrack) const; + /// Same criteria as for "genuine" track, except that one incorrect stub in either + /// PS or 2S module is allowed, irrespective of value of cfg param getAllowOneFalse2SStub(). + bool isLooselyGenuine(TTTrackPtrT aTrack) const; + /// More than one stub on track is "unknown". + bool isUnknown(TTTrackPtrT aTrack) const; + /// Both isLooselyGenuine() & isUnknown() are false. + bool isCombinatoric(TTTrackPtrT aTrack) const; + + // Cfg param allowing one incorrect 2S stub in "genuine" tracks. void setAllowOneFalse2SStub(bool allowFalse2SStub); bool getAllowOneFalse2SStub(); private: /// Data members - std::map >, edm::Ptr > trackToTrackingParticleMap; - std::map, std::vector > > > trackingParticleToTrackVectorMap; + MapL1TrackToTP trackToTrackingParticleMap; + MapTPToVecL1Track trackingParticleToTrackVectorMap; edm::RefProd > theStubAssociationMap; bool AllowOneFalse2SStub; @@ -106,27 +135,25 @@ TTTrackAssociationMap::~TTTrackAssociationMap() {} /// Operations template <> -edm::Ptr TTTrackAssociationMap::findTrackingParticlePtr( - edm::Ptr > aTrack) const; +TrackingParticlePtr TTTrackAssociationMap::findTrackingParticlePtr( + TTTrackPtr aTrack) const; template <> -std::vector > > TTTrackAssociationMap::findTTTrackPtrs( - edm::Ptr aTrackingParticle) const; +std::vector TTTrackAssociationMap::findTTTrackPtrs( + TrackingParticlePtr aTrackingParticle) const; /// MC truth template <> -bool TTTrackAssociationMap::isLooselyGenuine( - edm::Ptr > aTrack) const; +bool TTTrackAssociationMap::isLooselyGenuine(TTTrackPtr aTrack) const; /// MC truth template <> -bool TTTrackAssociationMap::isGenuine(edm::Ptr > aTrack) const; +bool TTTrackAssociationMap::isGenuine(TTTrackPtr aTrack) const; template <> -bool TTTrackAssociationMap::isCombinatoric( - edm::Ptr > aTrack) const; +bool TTTrackAssociationMap::isCombinatoric(TTTrackPtr aTrack) const; template <> -bool TTTrackAssociationMap::isUnknown(edm::Ptr > aTrack) const; +bool TTTrackAssociationMap::isUnknown(TTTrackPtr aTrack) const; #endif diff --git a/SimTracker/TrackTriggerAssociation/plugins/TTClusterAssociator.cc b/SimTracker/TrackTriggerAssociation/plugins/TTClusterAssociator.cc index 25d395b03866b..8c8efbb9b3d36 100644 --- a/SimTracker/TrackTriggerAssociation/plugins/TTClusterAssociator.cc +++ b/SimTracker/TrackTriggerAssociation/plugins/TTClusterAssociator.cc @@ -21,32 +21,30 @@ void TTClusterAssociator::produce(edm::Event& iEvent, co /// Get the TrackingParticles - iEvent.getByToken(tpToken, TrackingParticleHandle); + iEvent.getByToken(tpToken, trackingParticleHandle); // const TrackerTopology* const tTopo = theTrackerTopology.product(); const TrackerGeometry* const theTrackerGeom = theTrackerGeometry.product(); /// Preliminary task: map SimTracks by TrackingParticle /// Prepare the map - std::map, edm::Ptr> simTrackUniqueToTPMap; + std::map, TrackingParticlePtr> simTrackUniqueToTPMap; simTrackUniqueToTPMap.clear(); - if (!TrackingParticleHandle->empty()) { + if (not trackingParticleHandle->empty()) { /// Loop over TrackingParticles - unsigned int tpCnt = 0; std::vector::const_iterator iterTPart; - for (iterTPart = TrackingParticleHandle->begin(); iterTPart != TrackingParticleHandle->end(); ++iterTPart) { + for (unsigned int tpCnt = 0; tpCnt < trackingParticleHandle->size(); tpCnt++) { /// Make the pointer to the TrackingParticle - edm::Ptr tempTPPtr(TrackingParticleHandle, tpCnt++); + TrackingParticlePtr tempTPPtr(trackingParticleHandle, tpCnt); /// Get the EncodedEventId EncodedEventId eventId = EncodedEventId(tempTPPtr->eventId()); /// Loop over SimTracks inside TrackingParticle - std::vector::const_iterator iterSimTrack; - for (iterSimTrack = tempTPPtr->g4Tracks().begin(); iterSimTrack != tempTPPtr->g4Tracks().end(); ++iterSimTrack) { + for (const auto& simTrack : tempTPPtr->g4Tracks()) { /// Build the unique SimTrack Id (which is SimTrack ID + EncodedEventId) - std::pair simTrackUniqueId(iterSimTrack->trackId(), eventId); + std::pair simTrackUniqueId(simTrack.trackId(), eventId); simTrackUniqueToTPMap.insert(std::make_pair(simTrackUniqueId, tempTPPtr)); } } /// End of loop over TrackingParticles @@ -56,29 +54,26 @@ void TTClusterAssociator::produce(edm::Event& iEvent, co int ncont1 = 0; - for (auto iTag = TTClustersTokens.begin(); iTag != TTClustersTokens.end(); iTag++) { + for (const auto& iTag : ttClustersTokens) { /// Prepare output auto associationMapForOutput = std::make_unique>(); /// Get the Clusters already stored away - edm::Handle>> TTClusterHandle; + edm::Handle TTClusterHandle; - iEvent.getByToken(*iTag, TTClusterHandle); + iEvent.getByToken(iTag, TTClusterHandle); /// Prepare the necessary maps - std::map>, TTCluster>, - std::vector>> + std::map> clusterToTrackingParticleVectorMap; - std::map, - std::vector< - edm::Ref>, TTCluster>>> + std::map > trackingParticleToClusterVectorMap; clusterToTrackingParticleVectorMap.clear(); trackingParticleToClusterVectorMap.clear(); /// Loop over the input Clusters - for (auto gd = theTrackerGeom->dets().begin(); gd != theTrackerGeom->dets().end(); gd++) { - DetId detid = (*gd)->geographicalId(); + for (const auto& gd : theTrackerGeom->dets()) { + DetId detid = gd->geographicalId(); if (detid.subdetId() != StripSubdetector::TOB && detid.subdetId() != StripSubdetector::TID) continue; // only run on OT @@ -90,12 +85,12 @@ void TTClusterAssociator::produce(edm::Event& iEvent, co for (auto contentIter = clusters.begin(); contentIter != clusters.end(); ++contentIter) { /// Make the reference to be put in the map - edm::Ref>, TTCluster> tempCluRef = + TTClusterRef tempCluRef = edmNew::makeRefTo(TTClusterHandle, contentIter); /// Prepare the maps wrt TTCluster if (clusterToTrackingParticleVectorMap.find(tempCluRef) == clusterToTrackingParticleVectorMap.end()) { - std::vector> tpVector; + std::vector tpVector; tpVector.clear(); clusterToTrackingParticleVectorMap.insert(std::make_pair(tempCluRef, tpVector)); } @@ -111,7 +106,7 @@ void TTClusterAssociator::produce(edm::Event& iEvent, co for (unsigned int i = 0; i < theseHits.size(); i++) { /// No SimLink is found by definition /// Then store NULL MC truth for all the digis - edm::Ptr tempTPPtr; // = new edm::Ptr< TrackingParticle >(); + TrackingParticlePtr tempTPPtr; // = new edm::Ptr< TrackingParticle >(); clusterToTrackingParticleVectorMap.find(tempCluRef)->second.push_back(tempTPPtr); } @@ -140,7 +135,7 @@ void TTClusterAssociator::produce(edm::Event& iEvent, co /// Get the corresponding TrackingParticle if (simTrackUniqueToTPMap.find(thisUniqueId) != simTrackUniqueToTPMap.end()) { - edm::Ptr thisTrackingParticle = simTrackUniqueToTPMap.find(thisUniqueId)->second; + TrackingParticlePtr thisTrackingParticle = simTrackUniqueToTPMap.find(thisUniqueId)->second; /// Store the TrackingParticle clusterToTrackingParticleVectorMap.find(tempCluRef)->second.push_back(thisTrackingParticle); @@ -148,9 +143,7 @@ void TTClusterAssociator::produce(edm::Event& iEvent, co /// Prepare the maps wrt TrackingParticle if (trackingParticleToClusterVectorMap.find(thisTrackingParticle) == trackingParticleToClusterVectorMap.end()) { - std::vector< - edm::Ref>, TTCluster>> - clusterVector; + std::vector clusterVector; clusterVector.clear(); trackingParticleToClusterVectorMap.insert(std::make_pair(thisTrackingParticle, clusterVector)); } @@ -159,14 +152,14 @@ void TTClusterAssociator::produce(edm::Event& iEvent, co } else { /// In case no TrackingParticle is found, store a NULL pointer - edm::Ptr tempTPPtr; // = new edm::Ptr< TrackingParticle >(); + TrackingParticlePtr tempTPPtr; // = new edm::Ptr< TrackingParticle >(); clusterToTrackingParticleVectorMap.find(tempCluRef)->second.push_back(tempTPPtr); } } /// End of loop over PixelDigiSimLink } /// End of loop over all the hits composing the Cluster /// Check that the cluster has a non-NULL TP pointer - std::vector> theseClusterTrackingParticlePtrs = + std::vector theseClusterTrackingParticlePtrs = clusterToTrackingParticleVectorMap.find(tempCluRef)->second; bool allOfThemAreNull = true; for (unsigned int tpi = 0; tpi < theseClusterTrackingParticlePtrs.size() && allOfThemAreNull; tpi++) { @@ -183,15 +176,13 @@ void TTClusterAssociator::produce(edm::Event& iEvent, co /// Clean the maps that need cleaning /// Prepare the output map wrt TrackingParticle - std::map, - std::vector>, - TTCluster>>>::iterator iterMapToClean; + std::map>::iterator iterMapToClean; for (iterMapToClean = trackingParticleToClusterVectorMap.begin(); iterMapToClean != trackingParticleToClusterVectorMap.end(); ++iterMapToClean) { /// Get the vector of references to TTCluster - std::vector>, TTCluster>> - tempVector = iterMapToClean->second; + std::vector tempVector = iterMapToClean->second; /// Sort and remove duplicates std::sort(tempVector.begin(), tempVector.end()); @@ -204,8 +195,7 @@ void TTClusterAssociator::produce(edm::Event& iEvent, co associationMapForOutput->setTrackingParticleToTTClustersMap(trackingParticleToClusterVectorMap); /// Put output in the event - // iEvent.put( associationMapForOutput, (*iTag).instance() ); - iEvent.put(std::move(associationMapForOutput), TTClustersInputTags.at(ncont1).instance()); + iEvent.put(std::move(associationMapForOutput), ttClustersInputTags.at(ncont1).instance()); ++ncont1; diff --git a/SimTracker/TrackTriggerAssociation/plugins/TTClusterAssociator.h b/SimTracker/TrackTriggerAssociation/plugins/TTClusterAssociator.h index 6f2f54b9ab354..6db01f17149b2 100644 --- a/SimTracker/TrackTriggerAssociation/plugins/TTClusterAssociator.h +++ b/SimTracker/TrackTriggerAssociation/plugins/TTClusterAssociator.h @@ -53,17 +53,13 @@ class TTClusterAssociator : public edm::stream::EDProducer<> { private: /// Data members edm::Handle > thePixelDigiSimLinkHandle; - edm::Handle > TrackingParticleHandle; + edm::Handle > trackingParticleHandle; - std::vector TTClustersInputTags; + std::vector ttClustersInputTags; edm::EDGetTokenT > digisimLinkToken; edm::EDGetTokenT > tpToken; - //std::vector< edm::EDGetTokenT< edm::DetSetVector< TTCluster< T > > > > TTClustersTokens; - std::vector > > > TTClustersTokens; - - // const StackedTrackerGeometry *theStackedTrackers; - //unsigned int ADCThreshold; + std::vector > > > ttClustersTokens; edm::ESHandle theTrackerGeometry; edm::ESHandle theTrackerTopology; @@ -89,12 +85,12 @@ TTClusterAssociator::TTClusterAssociator(const edm::ParameterSet& iConfig) { consumes >(iConfig.getParameter("digiSimLinks")); tpToken = consumes >(iConfig.getParameter("trackingParts")); - TTClustersInputTags = iConfig.getParameter >("TTClusters"); + ttClustersInputTags = iConfig.getParameter >("TTClusters"); - for (auto iTag = TTClustersInputTags.begin(); iTag != TTClustersInputTags.end(); iTag++) { - TTClustersTokens.push_back(consumes > >(*iTag)); + for (const auto& iTag : ttClustersInputTags) { + ttClustersTokens.push_back(consumes > >(iTag)); - produces >((*iTag).instance()); + produces >(iTag.instance()); } } diff --git a/SimTracker/TrackTriggerAssociation/plugins/TTStubAssociator.cc b/SimTracker/TrackTriggerAssociation/plugins/TTStubAssociator.cc index bd6dccecda8a8..e57c4f5bcc8d1 100644 --- a/SimTracker/TrackTriggerAssociation/plugins/TTStubAssociator.cc +++ b/SimTracker/TrackTriggerAssociation/plugins/TTStubAssociator.cc @@ -17,7 +17,7 @@ void TTStubAssociator::produce(edm::Event& iEvent, const return; /// Exit if the vectors are uncorrectly dimensioned - if (TTClusterTruthInputTags.size() != TTStubsInputTags.size()) { + if (ttClusterTruthInputTags.size() != ttStubsInputTags.size()) { edm::LogError("TTStubAsso ") << "E R R O R! the InputTag vectors have different size!"; return; } @@ -29,33 +29,30 @@ void TTStubAssociator::produce(edm::Event& iEvent, const /// Loop over the InputTags to handle multiple collections - for (auto iTag = TTStubsTokens.begin(); iTag != TTStubsTokens.end(); iTag++) { + for (const auto& iTag : ttStubsTokens) { /// Prepare output auto associationMapForOutput = std::make_unique>(); /// Get the Stubs already stored away - edm::Handle>> TTStubHandle; - iEvent.getByToken(*iTag, TTStubHandle); + edm::Handle ttStubHandle; + iEvent.getByToken(iTag, ttStubHandle); /// Get the Cluster MC truth - edm::Handle> TTClusterAssociationMapHandle; - iEvent.getByToken(TTClusterTruthTokens.at(ncont1), TTClusterAssociationMapHandle); + edm::Handle> ttClusterAssociationMapHandle; + iEvent.getByToken(ttClusterTruthTokens.at(ncont1), ttClusterAssociationMapHandle); /// Prepare the necessary maps - std::map>, TTStub>, - edm::Ptr> - stubToTrackingParticleMap; - std::map, - std::vector>, TTStub>>> + std::map stubToTrackingParticleMap; + std::map> trackingParticleToStubVectorMap; stubToTrackingParticleMap.clear(); trackingParticleToStubVectorMap.clear(); /// Loop over the input Stubs - if (!TTStubHandle->empty()) { - for (auto gd = theTrackerGeom->dets().begin(); gd != theTrackerGeom->dets().end(); gd++) { - DetId detid = (*gd)->geographicalId(); + if (not ttStubHandle->empty()) { + for (const auto& gd : theTrackerGeom->dets()) { + DetId detid = gd->geographicalId(); if (detid.subdetId() != StripSubdetector::TOB && detid.subdetId() != StripSubdetector::TID) continue; // only run on OT @@ -64,36 +61,29 @@ void TTStubAssociator::produce(edm::Event& iEvent, const DetId stackDetid = tTopo->stack(detid); // Stub module detid - if (TTStubHandle->find(stackDetid) == TTStubHandle->end()) + if (ttStubHandle->find(stackDetid) == ttStubHandle->end()) continue; /// Get the DetSets of the Clusters - edmNew::DetSet> stubs = (*TTStubHandle)[stackDetid]; + edmNew::DetSet> stubs = (*ttStubHandle)[stackDetid]; for (auto contentIter = stubs.begin(); contentIter != stubs.end(); ++contentIter) { /// Make the reference to be put in the map - edm::Ref>, TTStub> tempStubRef = - edmNew::makeRefTo(TTStubHandle, contentIter); - - /// Get the two clusters - // std::vector< edm::Ref< edmNew::DetSetVector< TTCluster< Ref_Phase2TrackerDigi_ > >, TTCluster< Ref_Phase2TrackerDigi_ > > > theseClusters = tempStubRef->getClusterRefs(); + TTStubRef tempStubRef = edmNew::makeRefTo(ttStubHandle, contentIter); /// Fill the inclusive map which is careless of the stub classification - for (unsigned int ic = 0; ic < 2; ic++) { - std::vector> tempTPs = - TTClusterAssociationMapHandle->findTrackingParticlePtrs(tempStubRef->clusterRef(ic)); + for (unsigned int ic = 0; ic < 2; ic++) { + std::vector tempTPs = + ttClusterAssociationMapHandle->findTrackingParticlePtrs(tempStubRef->clusterRef(ic)); - for (unsigned int itp = 0; itp < tempTPs.size(); itp++) { - edm::Ptr testTP = tempTPs.at(itp); + for (const TrackingParticlePtr& testTP : tempTPs) { if (testTP.isNull()) continue; /// Prepare the maps wrt TrackingParticle if (trackingParticleToStubVectorMap.find(testTP) == trackingParticleToStubVectorMap.end()) { - std::vector< - edm::Ref>, TTStub>> - stubVector; + std::vector stubVector; stubVector.clear(); trackingParticleToStubVectorMap.insert(std::make_pair(testTP, stubVector)); } @@ -104,8 +94,8 @@ void TTStubAssociator::produce(edm::Event& iEvent, const /// GENUINE for clusters means not combinatoric and /// not unknown: same MC truth content MUST be found /// in both clusters composing the stub - if (TTClusterAssociationMapHandle->isUnknown(tempStubRef->clusterRef(0)) || - TTClusterAssociationMapHandle->isUnknown(tempStubRef->clusterRef(1))) { + if (ttClusterAssociationMapHandle->isUnknown(tempStubRef->clusterRef(0)) || + ttClusterAssociationMapHandle->isUnknown(tempStubRef->clusterRef(1))) { /// If at least one cluster is unknown, it means /// either unknown, either combinatoric /// Do nothing, and go to the next Stub @@ -114,16 +104,16 @@ void TTStubAssociator::produce(edm::Event& iEvent, const /// Here both are clusters are genuine/combinatoric /// If both clusters have some known SimTrack content /// they must be compared to each other - if (TTClusterAssociationMapHandle->isGenuine(tempStubRef->clusterRef(0)) && - TTClusterAssociationMapHandle->isGenuine(tempStubRef->clusterRef(1))) { + if (ttClusterAssociationMapHandle->isGenuine(tempStubRef->clusterRef(0)) && + ttClusterAssociationMapHandle->isGenuine(tempStubRef->clusterRef(1))) { /// If both clusters are genuine, they must be associated to the same TrackingParticle /// in order to return a genuine stub. Period. Note we can perform safely /// this comparison because, if both clusters are genuine, their TrackingParticle shall NEVER be NULL - if (TTClusterAssociationMapHandle->findTrackingParticlePtr(tempStubRef->clusterRef(0)).get() == - TTClusterAssociationMapHandle->findTrackingParticlePtr(tempStubRef->clusterRef(1)).get()) { + if (ttClusterAssociationMapHandle->findTrackingParticlePtr(tempStubRef->clusterRef(0)).get() == + ttClusterAssociationMapHandle->findTrackingParticlePtr(tempStubRef->clusterRef(1)).get()) { /// Two genuine clusters with same SimTrack content mean genuine - edm::Ptr testTP = - TTClusterAssociationMapHandle->findTrackingParticlePtr(tempStubRef->clusterRef(0)); + TrackingParticlePtr testTP = + ttClusterAssociationMapHandle->findTrackingParticlePtr(tempStubRef->clusterRef(0)); /// Fill the map: by construction, this will always be the first time the /// stub is inserted into the map: no need for "find" @@ -141,10 +131,10 @@ void TTStubAssociator::produce(edm::Event& iEvent, const TrackingParticle* prevTPAddress = nullptr; unsigned int whichTP = 0; - std::vector> trackingParticles0 = - TTClusterAssociationMapHandle->findTrackingParticlePtrs(tempStubRef->clusterRef(0)); - std::vector> trackingParticles1 = - TTClusterAssociationMapHandle->findTrackingParticlePtrs(tempStubRef->clusterRef(1)); + std::vector trackingParticles0 = + ttClusterAssociationMapHandle->findTrackingParticlePtrs(tempStubRef->clusterRef(0)); + std::vector trackingParticles1 = + ttClusterAssociationMapHandle->findTrackingParticlePtrs(tempStubRef->clusterRef(1)); bool escape = false; @@ -188,7 +178,7 @@ void TTStubAssociator::produce(edm::Event& iEvent, const /// even if one of the clusters (or both) are combinatoric: /// this means there is only one track that participates in /// both clusters, hence the stub is genuine - edm::Ptr testTP = trackingParticles1.at(whichTP); + TrackingParticlePtr testTP = trackingParticles1.at(whichTP); /// Fill the map: by construction, this will always be the first time the /// stub is inserted into the map: no need for "find" @@ -205,26 +195,22 @@ void TTStubAssociator::produce(edm::Event& iEvent, const /// Clean the only map that needs cleaning /// Prepare the output map wrt TrackingParticle - typename std::map, - std::vector>, - TTStub>>>::iterator iterMapToClean; - for (iterMapToClean = trackingParticleToStubVectorMap.begin(); - iterMapToClean != trackingParticleToStubVectorMap.end(); - ++iterMapToClean) { + typename std::map>::iterator iterMapToClean; + for (auto& p : trackingParticleToStubVectorMap) { /// Get the vector of references to TTStub - std::vector>, TTStub>> - tempVector = iterMapToClean->second; + std::vector tempVector = p.second; /// Sort and remove duplicates std::sort(tempVector.begin(), tempVector.end()); tempVector.erase(std::unique(tempVector.begin(), tempVector.end()), tempVector.end()); /// Put the vector in the output map - iterMapToClean->second = tempVector; + p.second = tempVector; } /// Also, create the pointer to the TTClusterAssociationMap - edm::RefProd> theCluAssoMap(TTClusterAssociationMapHandle); + edm::RefProd> theCluAssoMap(ttClusterAssociationMapHandle); /// Put the maps in the association object associationMapForOutput->setTTStubToTrackingParticleMap(stubToTrackingParticleMap); @@ -232,7 +218,7 @@ void TTStubAssociator::produce(edm::Event& iEvent, const associationMapForOutput->setTTClusterAssociationMap(theCluAssoMap); /// Put output in the event - iEvent.put(std::move(associationMapForOutput), TTStubsInputTags.at(ncont1).instance()); + iEvent.put(std::move(associationMapForOutput), ttStubsInputTags.at(ncont1).instance()); ++ncont1; } /// End of loop over InputTags diff --git a/SimTracker/TrackTriggerAssociation/plugins/TTStubAssociator.h b/SimTracker/TrackTriggerAssociation/plugins/TTStubAssociator.h index 50a259e71b8f9..a905250116406 100644 --- a/SimTracker/TrackTriggerAssociation/plugins/TTStubAssociator.h +++ b/SimTracker/TrackTriggerAssociation/plugins/TTStubAssociator.h @@ -53,11 +53,11 @@ class TTStubAssociator : public edm::stream::EDProducer<> { private: /// Data members - std::vector TTStubsInputTags; - std::vector TTClusterTruthInputTags; + std::vector ttStubsInputTags; + std::vector ttClusterTruthInputTags; - std::vector > > > TTStubsTokens; - std::vector > > TTClusterTruthTokens; + std::vector > > > ttStubsTokens; + std::vector > > ttClusterTruthTokens; edm::ESHandle theTrackerGeometry; edm::ESHandle theTrackerTopology; @@ -79,17 +79,17 @@ class TTStubAssociator : public edm::stream::EDProducer<> { /// Constructors template TTStubAssociator::TTStubAssociator(const edm::ParameterSet& iConfig) { - TTStubsInputTags = iConfig.getParameter >("TTStubs"); - TTClusterTruthInputTags = iConfig.getParameter >("TTClusterTruth"); + ttStubsInputTags = iConfig.getParameter >("TTStubs"); + ttClusterTruthInputTags = iConfig.getParameter >("TTClusterTruth"); - for (auto iTag = TTClusterTruthInputTags.begin(); iTag != TTClusterTruthInputTags.end(); iTag++) { - TTClusterTruthTokens.push_back(consumes >(*iTag)); + for (const auto& iTag : ttClusterTruthInputTags) { + ttClusterTruthTokens.push_back(consumes >(iTag)); } - for (auto iTag = TTStubsInputTags.begin(); iTag != TTStubsInputTags.end(); iTag++) { - TTStubsTokens.push_back(consumes > >(*iTag)); + for (const auto& iTag : ttStubsInputTags) { + ttStubsTokens.push_back(consumes > >(iTag)); - produces >((*iTag).instance()); + produces >(iTag.instance()); } } diff --git a/SimTracker/TrackTriggerAssociation/plugins/TTTrackAssociator.cc b/SimTracker/TrackTriggerAssociation/plugins/TTTrackAssociator.cc index feebace089572..3aa06108556f0 100644 --- a/SimTracker/TrackTriggerAssociation/plugins/TTTrackAssociator.cc +++ b/SimTracker/TrackTriggerAssociation/plugins/TTTrackAssociator.cc @@ -4,9 +4,11 @@ * * \author Nicola Pozzobon * \date 2013, Jul 19 - * + * */ +// FIX: N.B Code below could surely be more efficiently written? + #include "SimTracker/TrackTriggerAssociation/plugins/TTTrackAssociator.h" /// Implement the producer @@ -17,62 +19,59 @@ void TTTrackAssociator::produce(edm::Event& iEvent, cons return; /// Get the Stub and Cluster MC truth - edm::Handle> TTClusterAssociationMapHandle; - iEvent.getByToken(TTClusterTruthToken, TTClusterAssociationMapHandle); - edm::Handle> TTStubAssociationMapHandle; - iEvent.getByToken(TTStubTruthToken, TTStubAssociationMapHandle); + edm::Handle> ttClusterAssociationMapHandle; + iEvent.getByToken(ttClusterTruthToken, ttClusterAssociationMapHandle); + edm::Handle> ttStubAssociationMapHandle; + iEvent.getByToken(ttStubTruthToken, ttStubAssociationMapHandle); int ncont1 = 0; /// Loop over InputTags to handle multiple collections - for (auto iTag = TTTracksTokens.begin(); iTag != TTTracksTokens.end(); iTag++) { + for (const auto& iTag : ttTracksTokens) { /// Prepare output auto associationMapForOutput = std::make_unique>(); /// Get the Tracks already stored away edm::Handle>> TTTrackHandle; - iEvent.getByToken(*iTag, TTTrackHandle); + iEvent.getByToken(iTag, TTTrackHandle); /// Prepare the necessary maps - std::map>, edm::Ptr> trackToTrackingParticleMap; - std::map, std::vector>>> + std::map trackToTrackingParticleMap; + std::map> trackingParticleToTrackVectorMap; trackToTrackingParticleMap.clear(); trackingParticleToTrackVectorMap.clear(); // Start the loop on tracks - unsigned int j = 0; /// Counter needed to build the edm::Ptr to the TTTrack typename std::vector>::const_iterator inputIter; - for (inputIter = TTTrackHandle->begin(); inputIter != TTTrackHandle->end(); ++inputIter) { + for (unsigned int jTrk = 0; jTrk < TTTrackHandle->size(); jTrk++) { /// Make the pointer to be put in the map - edm::Ptr> tempTrackPtr(TTTrackHandle, j++); + TTTrackPtr tempTrackPtr(TTTrackHandle, jTrk); - /// Get the stubs of the TTTrack (theseStubs) - std::vector>, TTStub>> - theseStubs = tempTrackPtr->getStubRefs(); + /// Get all the stubs of the TTTrack (theseStubs) + std::vector theseStubs = tempTrackPtr->getStubRefs(); - /// Auxiliary map to store TP addresses and TP edm::Ptr - std::map> auxMap; + /// Auxiliary map to relate TP addresses and TP edm::Ptr + std::map auxMap; auxMap.clear(); int mayCombinUnknown = 0; - /// Fill the inclusive map which is careless of the stub classification - for (unsigned int is = 0; is < theseStubs.size(); is++) { - // std::vector< edm::Ref< edmNew::DetSetVector< TTCluster< Ref_Phase2TrackerDigi_ > >, TTCluster< Ref_Phase2TrackerDigi_ > > > theseClusters = theseStubs.at(is)->getClusterRefs(); + /// Fill the map associating each TP to a vector of L1 tracks. + /// Do this using the association map of the clusters inside each stub, + /// rather than the stub association map. (CHECK: Why? This wastes CPU!) + for (const TTStubRef& stub : theseStubs) { for (unsigned int ic = 0; ic < 2; ic++) { - std::vector> tempTPs = - TTClusterAssociationMapHandle->findTrackingParticlePtrs(theseStubs.at(is)->clusterRef(ic)); - for (unsigned int itp = 0; itp < tempTPs.size(); itp++) // List of TPs linked to stub clusters + std::vector tempTPs = + ttClusterAssociationMapHandle->findTrackingParticlePtrs(stub->clusterRef(ic)); + for (const TrackingParticlePtr& testTP : tempTPs) // List of TPs linked to stub clusters { - edm::Ptr testTP = tempTPs.at(itp); - if (testTP.isNull()) // No TP linked to this cluster continue; /// Prepare the maps wrt TrackingParticle if (trackingParticleToTrackVectorMap.find(testTP) == trackingParticleToTrackVectorMap.end()) { - std::vector>> trackVector; + std::vector trackVector; trackVector.clear(); trackingParticleToTrackVectorMap.insert(std::make_pair(testTP, trackVector)); } @@ -86,91 +85,90 @@ void TTTrackAssociator::produce(edm::Event& iEvent, cons } /// End of loop over the clusters /// Check if the stub is unknown - if (TTStubAssociationMapHandle->isUnknown(theseStubs.at(is))) + if (ttStubAssociationMapHandle->isUnknown(stub)) ++mayCombinUnknown; } /// End of loop over the stubs - /// If there more than 2 unknown stubs, go to the next track + /// If there are >= 2 unknown stubs, go to the next track /// as this track may be COMBINATORIC or UNKNOWN + /// (One unknown is allowed, if in 2S module). if (mayCombinUnknown >= 2) continue; - /// If we are here, all the stubs are either combinatoric or genuine + /// If we are here, all the stubs on track are either combinatoric or genuine /// and there is no more than one fake stub in the track - /// Loop over all the TrackingParticle which have been found in the track at some point - /// (stored in auxMap) + /// Loop over all the TrackingParticle which have been found in the track + /// (stored in auxMap), to check if any are present in all stubs on Track. std::vector tpInAllStubs; - std::map>::const_iterator iterAuxMap; - for (iterAuxMap = auxMap.begin(); iterAuxMap != auxMap.end(); ++iterAuxMap) { - /// Get all the stubs from this TrackingParticle - std::vector>, TTStub>> - tempStubs = TTStubAssociationMapHandle->findTTStubRefs(iterAuxMap->second); + for (const auto& auxPair : auxMap) { + /// Get all associated stubs of this TrackingParticle + std::vector tempStubs = + ttStubAssociationMapHandle->findTTStubRefs(auxPair.second); + // Count stubs on track that are not related to this TP int nnotfound = 0; - //bool allFound = true; - /// Loop over the stubs - // for ( unsigned int js = 0; js < theseStubs.size() && allFound; js++ ) - for (unsigned int js = 0; js < theseStubs.size(); js++) { + for (const TTStubRef& stub : theseStubs) { /// We want that all the stubs of the track are included in the container of /// all the stubs produced by this particular TrackingParticle which we /// already know is one of the TrackingParticles that released hits /// in this track we are evaluating right now - if (std::find(tempStubs.begin(), tempStubs.end(), theseStubs.at(js)) == tempStubs.end()) { - // allFound = false; + if (std::find(tempStubs.begin(), tempStubs.end(), stub) == tempStubs.end()) { ++nnotfound; } } - /// If the TrackingParticle does not appear in all stubs but one - /// then go to the next track + /// If this TP does not appear in all stubs (allowing one wrong stub) + /// then try next TP. if (nnotfound > 1) - //if (!allFound) continue; /// If we are here, it means that the TrackingParticle - /// generates hits in all stubs but one of the current track + /// generates hits in all stubs (allowing one incorrect one) of the current track /// so put it into the vector - tpInAllStubs.push_back(iterAuxMap->first); + tpInAllStubs.push_back(auxPair.first); } - /// Count how many TrackingParticles we do have + /// Count how many TrackingParticles were associated to all stubs on this track. + /// FIX: Could avoid this by using std::set for tpInAllStubs? std::sort(tpInAllStubs.begin(), tpInAllStubs.end()); tpInAllStubs.erase(std::unique(tpInAllStubs.begin(), tpInAllStubs.end()), tpInAllStubs.end()); unsigned int nTPs = tpInAllStubs.size(); - /// If only one TrackingParticle, GENUINE - /// if different than one, COMBINATORIC + /// If only one TP associated to all stubs (allowing one incorrect) on track: GENUINE or LOOSELY_GENUINE. + /// If 0 or >= 2 TP: COMBINATORIC + /// WARNING: This means if one TP matches all stubs, and another matches all STUBS except + /// one, then the trackToTrackingParticleMap will not be filled. + /// WARNING: This also means that trackToTrackingParticleMap will be filled if + /// one TP matches all stubs, except for an incorrect one in either PS or 2S modules. if (nTPs != 1) continue; - /// Here, the track may only be GENUINE - /// Fill the map + /// Here, the track may only be GENUINE/LOOSELY_GENUINE + /// CHECK: Surely if one incorrect PS stub, it can also be COMBINATORIC? + /// Fill the map associating track to its principle TP. trackToTrackingParticleMap.insert(std::make_pair(tempTrackPtr, auxMap.find(tpInAllStubs.at(0))->second)); } /// End of loop over Tracks - /// Clean the only map that needs cleaning - /// Prepare the output map wrt TrackingParticle - typename std::map, std::vector>>>::iterator - iterMapToClean; - for (iterMapToClean = trackingParticleToTrackVectorMap.begin(); - iterMapToClean != trackingParticleToTrackVectorMap.end(); - ++iterMapToClean) { + /// Remove duplicates from the only output map that needs it. + /// (Map gets multiple entries per track if it has several stubs belonging to same TP). + for (auto& p : trackingParticleToTrackVectorMap) { /// Get the vector of edm::Ptr< TTTrack > - std::vector>> tempVector = iterMapToClean->second; + /// (CHECK: Couldn't this be done by reference, to save CPU?) + std::vector tempVector = p.second; - /// Sort and remove duplicates + /// Sort and remove duplicates std::sort(tempVector.begin(), tempVector.end()); tempVector.erase(std::unique(tempVector.begin(), tempVector.end()), tempVector.end()); - iterMapToClean->second = tempVector; + p.second = tempVector; } /// Also, create the pointer to the TTClusterAssociationMap - edm::RefProd> theStubAssoMap(TTStubAssociationMapHandle); + edm::RefProd> theStubAssoMap(ttStubAssociationMapHandle); /// Put the maps in the association object associationMapForOutput->setTTTrackToTrackingParticleMap(trackToTrackingParticleMap); @@ -179,7 +177,7 @@ void TTTrackAssociator::produce(edm::Event& iEvent, cons associationMapForOutput->setAllowOneFalse2SStub(TTTrackAllowOneFalse2SStub); /// Put output in the event - iEvent.put(std::move(associationMapForOutput), TTTracksInputTags.at(ncont1).instance()); + iEvent.put(std::move(associationMapForOutput), ttTracksInputTags.at(ncont1).instance()); ++ncont1; } /// End of loop over InputTags diff --git a/SimTracker/TrackTriggerAssociation/plugins/TTTrackAssociator.h b/SimTracker/TrackTriggerAssociation/plugins/TTTrackAssociator.h index 5155714c71ed7..65c7d6a2f8f47 100644 --- a/SimTracker/TrackTriggerAssociation/plugins/TTTrackAssociator.h +++ b/SimTracker/TrackTriggerAssociation/plugins/TTTrackAssociator.h @@ -49,12 +49,12 @@ class TTTrackAssociator : public edm::stream::EDProducer<> { private: /// Data members - std::vector TTTracksInputTags; + std::vector ttTracksInputTags; - std::vector > > > TTTracksTokens; + std::vector > > > ttTracksTokens; - edm::EDGetTokenT > TTStubTruthToken; - edm::EDGetTokenT > TTClusterTruthToken; + edm::EDGetTokenT > ttStubTruthToken; + edm::EDGetTokenT > ttClusterTruthToken; bool TTTrackAllowOneFalse2SStub; @@ -75,9 +75,9 @@ class TTTrackAssociator : public edm::stream::EDProducer<> { /// Constructors template TTTrackAssociator::TTTrackAssociator(const edm::ParameterSet& iConfig) { - TTTracksInputTags = iConfig.getParameter >("TTTracks"); - TTClusterTruthToken = consumes >(iConfig.getParameter("TTClusterTruth")); - TTStubTruthToken = consumes >(iConfig.getParameter("TTStubTruth")); + ttTracksInputTags = iConfig.getParameter >("TTTracks"); + ttClusterTruthToken = consumes >(iConfig.getParameter("TTClusterTruth")); + ttStubTruthToken = consumes >(iConfig.getParameter("TTStubTruth")); TTTrackAllowOneFalse2SStub = iConfig.getParameter("TTTrackAllowOneFalse2SStub"); if (TTTrackAllowOneFalse2SStub) { edm::LogInfo("TTTrackAssociator< ") << "Allow track if no more than one 2S stub doesn't match truth."; @@ -85,10 +85,10 @@ TTTrackAssociator::TTTrackAssociator(const edm::ParameterSet& iConfig) { edm::LogInfo("TTTrackAssociator< ") << "All 2S stubs must match truth."; } - for (auto iTag = TTTracksInputTags.begin(); iTag != TTTracksInputTags.end(); iTag++) { - TTTracksTokens.push_back(consumes > >(*iTag)); + for (const auto& iTag : ttTracksInputTags) { + ttTracksTokens.push_back(consumes > >(iTag)); - produces >((*iTag).instance()); + produces >(iTag.instance()); } } diff --git a/SimTracker/TrackTriggerAssociation/src/TTTrackAssociationMap.cc b/SimTracker/TrackTriggerAssociation/src/TTTrackAssociationMap.cc index 8ec629ce68167..c019a9fd29be9 100644 --- a/SimTracker/TrackTriggerAssociation/src/TTTrackAssociationMap.cc +++ b/SimTracker/TrackTriggerAssociation/src/TTTrackAssociationMap.cc @@ -9,34 +9,33 @@ /// Operations template <> -edm::Ptr TTTrackAssociationMap::findTrackingParticlePtr( - edm::Ptr > aTrack) const { +TrackingParticlePtr TTTrackAssociationMap::findTrackingParticlePtr( + TTTrackPtr aTrack) const { if (trackToTrackingParticleMap.find(aTrack) != trackToTrackingParticleMap.end()) { return trackToTrackingParticleMap.find(aTrack)->second; } /// Default: return NULL - edm::Ptr* temp = new edm::Ptr(); + TrackingParticlePtr* temp = new TrackingParticlePtr(); return *temp; } template <> -std::vector > > TTTrackAssociationMap::findTTTrackPtrs( - edm::Ptr aTrackingParticle) const { +std::vector TTTrackAssociationMap::findTTTrackPtrs( + TrackingParticlePtr aTrackingParticle) const { if (trackingParticleToTrackVectorMap.find(aTrackingParticle) != trackingParticleToTrackVectorMap.end()) { return trackingParticleToTrackVectorMap.find(aTrackingParticle)->second; } /// Default: return empty vector - std::vector > > tempVec; + std::vector tempVec; tempVec.clear(); return tempVec; } /// MC truth template <> -bool TTTrackAssociationMap::isLooselyGenuine( - edm::Ptr > aTrack) const { +bool TTTrackAssociationMap::isLooselyGenuine(TTTrackPtr aTrack) const { /// Check if there is a TrackingParticle if ((this->findTrackingParticlePtr(aTrack)).isNull()) return false; @@ -46,16 +45,14 @@ bool TTTrackAssociationMap::isLooselyGenuine( /// MC truth template <> -bool TTTrackAssociationMap::isGenuine(edm::Ptr > aTrack) const { - /// Check if there is a TrackingParticle +bool TTTrackAssociationMap::isGenuine(TTTrackPtr aTrack) const { + /// Check if there is an associated TrackingParticle if ((this->findTrackingParticlePtr(aTrack)).isNull()) return false; - /// Get all the stubs from this TrackingParticle - std::vector >, TTStub > > - TP_Stubs = theStubAssociationMap->findTTStubRefs(this->findTrackingParticlePtr(aTrack)); - std::vector >, TTStub > > - TRK_Stubs = aTrack->getStubRefs(); + /// Get all the stubs from this track & associated TrackingParticle + std::vector TRK_Stubs = aTrack->getStubRefs(); + std::vector TP_Stubs = theStubAssociationMap->findTTStubRefs(this->findTrackingParticlePtr(aTrack)); bool one2SStub = false; for (unsigned int js = 0; js < TRK_Stubs.size(); js++) { @@ -78,8 +75,7 @@ bool TTTrackAssociationMap::isGenuine(edm::Ptr -bool TTTrackAssociationMap::isCombinatoric( - edm::Ptr > aTrack) const { +bool TTTrackAssociationMap::isCombinatoric(TTTrackPtr aTrack) const { /// Defined by exclusion if (this->isLooselyGenuine(aTrack)) return false; @@ -91,12 +87,11 @@ bool TTTrackAssociationMap::isCombinatoric( } template <> -bool TTTrackAssociationMap::isUnknown(edm::Ptr > aTrack) const { - /// UNKNOWN means that more than 2 stubs are unknown +bool TTTrackAssociationMap::isUnknown(TTTrackPtr aTrack) const { + /// UNKNOWN means that >= 2 stubs are unknown int unknownstubs = 0; - std::vector >, TTStub > > - theseStubs = aTrack->getStubRefs(); + std::vector theseStubs = aTrack->getStubRefs(); for (unsigned int i = 0; i < theseStubs.size(); i++) { if (theStubAssociationMap->isUnknown(theseStubs.at(i)) == false) { ++unknownstubs; From d6edc7395e2739aa508f923fc8364a6d9ab6b3b9 Mon Sep 17 00:00:00 2001 From: Ian Tomalin Date: Thu, 17 Dec 2020 11:22:53 +0000 Subject: [PATCH 2/6] tweak comment --- SimTracker/TrackTriggerAssociation/plugins/TTTrackAssociator.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SimTracker/TrackTriggerAssociation/plugins/TTTrackAssociator.cc b/SimTracker/TrackTriggerAssociation/plugins/TTTrackAssociator.cc index 3aa06108556f0..33506d1706993 100644 --- a/SimTracker/TrackTriggerAssociation/plugins/TTTrackAssociator.cc +++ b/SimTracker/TrackTriggerAssociation/plugins/TTTrackAssociator.cc @@ -59,7 +59,7 @@ void TTTrackAssociator::produce(edm::Event& iEvent, cons /// Fill the map associating each TP to a vector of L1 tracks. /// Do this using the association map of the clusters inside each stub, - /// rather than the stub association map. (CHECK: Why? This wastes CPU!) + /// as stub associator misses stub --> all TP map (FIX). for (const TTStubRef& stub : theseStubs) { for (unsigned int ic = 0; ic < 2; ic++) { std::vector tempTPs = From 537abfa695d28e5333a1286be5a00338216d3da3 Mon Sep 17 00:00:00 2001 From: Ian Tomalin Date: Fri, 18 Dec 2020 19:31:13 +0000 Subject: [PATCH 3/6] ran scram code formatter --- .../L1TrackTrigger/interface/TTTypes.h | 19 +++++--- .../interface/TTClusterAssociationMap.h | 43 ++++++++---------- .../interface/TTStubAssociationMap.h | 45 ++++++++----------- .../interface/TTTrackAssociationMap.h | 35 ++++++--------- .../plugins/TTClusterAssociator.cc | 12 ++--- .../plugins/TTStubAssociator.cc | 9 ++-- .../plugins/TTTrackAssociator.cc | 16 +++---- .../src/TTTrackAssociationMap.cc | 5 +-- 8 files changed, 79 insertions(+), 105 deletions(-) diff --git a/DataFormats/L1TrackTrigger/interface/TTTypes.h b/DataFormats/L1TrackTrigger/interface/TTTypes.h index 1c46c4624c01d..cf739f7161253 100644 --- a/DataFormats/L1TrackTrigger/interface/TTTypes.h +++ b/DataFormats/L1TrackTrigger/interface/TTTypes.h @@ -20,13 +20,18 @@ #include "DataFormats/L1TrackTrigger/interface/TTTrack_TrackWord.h" /// Templated aliases -template using TTClusterDetSetVecT = edmNew::DetSetVector >; -template using TTStubDetSetVecT = edmNew::DetSetVector >; - -template using TTClusterRefT = edm::Ref, TTCluster >; -template using TTStubRefT = edm::Ref, TTStub >; - -template using TTTrackPtrT = edm::Ptr >; +template +using TTClusterDetSetVecT = edmNew::DetSetVector >; +template +using TTStubDetSetVecT = edmNew::DetSetVector >; + +template +using TTClusterRefT = edm::Ref, TTCluster >; +template +using TTStubRefT = edm::Ref, TTStub >; + +template +using TTTrackPtrT = edm::Ptr >; /// Specialized aliases typedef edm::Ref, Phase2TrackerDigi> Ref_Phase2TrackerDigi_; diff --git a/SimTracker/TrackTriggerAssociation/interface/TTClusterAssociationMap.h b/SimTracker/TrackTriggerAssociation/interface/TTClusterAssociationMap.h index 143e1e0435640..06252f6bfae07 100644 --- a/SimTracker/TrackTriggerAssociation/interface/TTClusterAssociationMap.h +++ b/SimTracker/TrackTriggerAssociation/interface/TTClusterAssociationMap.h @@ -35,8 +35,10 @@ #include "SimDataFormats/TrackingAnalysis/interface/TrackingParticle.h" // Templated aliases -template using MapClusToVecTP = std::map, std::vector >; -template using MapTPToVecClus = std::map > >; +template +using MapClusToVecTP = std::map, std::vector>; +template +using MapTPToVecClus = std::map>>; template class TTClusterAssociationMap { @@ -49,19 +51,11 @@ class TTClusterAssociationMap { /// Get/set cluster <-> truth association maps - const MapClusToVecTP& getTTClusterToTrackingParticlesMap() const { - return clusterToTrackingParticleVectorMap; - } - const MapTPToVecClus& getTrackingParticleToTTClustersMap() const { - return trackingParticleToClusterVectorMap; - } + const MapClusToVecTP& getTTClusterToTrackingParticlesMap() const { return clusterToTrackingParticleVectorMap; } + const MapTPToVecClus& getTrackingParticleToTTClustersMap() const { return trackingParticleToClusterVectorMap; } - void setTTClusterToTrackingParticlesMap(const MapClusToVecTP& aMap) { - clusterToTrackingParticleVectorMap = aMap; - } - void setTrackingParticleToTTClustersMap(const MapTPToVecClus& aMap) { - trackingParticleToClusterVectorMap = aMap; - } + void setTTClusterToTrackingParticlesMap(const MapClusToVecTP& aMap) { clusterToTrackingParticleVectorMap = aMap; } + void setTrackingParticleToTTClustersMap(const MapTPToVecClus& aMap) { trackingParticleToClusterVectorMap = aMap; } /// Get all TPs associated to a cluster std::vector findTrackingParticlePtrs(TTClusterRefT aCluster) const; @@ -71,11 +65,11 @@ class TTClusterAssociationMap { // Get all clusters associated to TP. std::vector> findTTClusterRefs(TrackingParticlePtr aTrackingParticle) const; - ///--- Get quality of L1 cluster based on truth info. + ///--- Get quality of L1 cluster based on truth info. /// (exactly 1 of following 3 functions is always true) /// Cluster "genuine": i.e. cluster associated to exactly 1 TP. - /// (If other TPs are associated, but have in total < 1% of Pt of main TP, + /// (If other TPs are associated, but have in total < 1% of Pt of main TP, /// or if they are null, then they are neglected here). bool isGenuine(TTClusterRefT aCluster) const; /// Cluster "unknown": i.e. not associated with any TP. @@ -115,25 +109,24 @@ TTClusterAssociationMap::~TTClusterAssociationMap() {} /// Operations template -std::vector< TTClusterRefT > -TTClusterAssociationMap::findTTClusterRefs(TrackingParticlePtr aTrackingParticle) const { +std::vector> TTClusterAssociationMap::findTTClusterRefs( + TrackingParticlePtr aTrackingParticle) const { if (trackingParticleToClusterVectorMap.find(aTrackingParticle) != trackingParticleToClusterVectorMap.end()) { return trackingParticleToClusterVectorMap.find(aTrackingParticle)->second; } - std::vector< TTClusterRefT > tempVector; + std::vector> tempVector; tempVector.clear(); return tempVector; } template -std::vector TTClusterAssociationMap::findTrackingParticlePtrs( - TTClusterRefT aCluster) const { +std::vector TTClusterAssociationMap::findTrackingParticlePtrs(TTClusterRefT aCluster) const { if (clusterToTrackingParticleVectorMap.find(aCluster) != clusterToTrackingParticleVectorMap.end()) { return clusterToTrackingParticleVectorMap.find(aCluster)->second; } - std::vector tempVector; + std::vector tempVector; tempVector.clear(); return tempVector; } @@ -165,7 +158,7 @@ std::vector TTClusterAssociationMap::findTrackingPartic template bool TTClusterAssociationMap::isGenuine(TTClusterRefT aCluster) const { /// Get the TrackingParticles - std::vector theseTrackingParticles = this->findTrackingParticlePtrs(aCluster); + std::vector theseTrackingParticles = this->findTrackingParticlePtrs(aCluster); /// If the vector is empty, then the cluster is UNKNOWN if (theseTrackingParticles.empty()) @@ -223,7 +216,7 @@ bool TTClusterAssociationMap::isGenuine(TTClusterRefT aCluster) const { template bool TTClusterAssociationMap::isUnknown(TTClusterRefT aCluster) const { /// Get the TrackingParticles - std::vector theseTrackingParticles = this->findTrackingParticlePtrs(aCluster); + std::vector theseTrackingParticles = this->findTrackingParticlePtrs(aCluster); /// If the vector is empty, then the cluster is UNKNOWN if (theseTrackingParticles.empty()) @@ -258,7 +251,7 @@ bool TTClusterAssociationMap::isUnknown(TTClusterRefT aCluster) const { template bool TTClusterAssociationMap::isCombinatoric(TTClusterRefT aCluster) const { /// Get the TrackingParticles - std::vector theseTrackingParticles = this->findTrackingParticlePtrs(aCluster); + std::vector theseTrackingParticles = this->findTrackingParticlePtrs(aCluster); /// If the vector is empty, then the cluster is UNKNOWN if (theseTrackingParticles.empty()) diff --git a/SimTracker/TrackTriggerAssociation/interface/TTStubAssociationMap.h b/SimTracker/TrackTriggerAssociation/interface/TTStubAssociationMap.h index 8ac9843da7a87..9a2238cdd2833 100644 --- a/SimTracker/TrackTriggerAssociation/interface/TTStubAssociationMap.h +++ b/SimTracker/TrackTriggerAssociation/interface/TTStubAssociationMap.h @@ -40,8 +40,10 @@ #include "SimTracker/TrackTriggerAssociation/interface/TTClusterAssociationMap.h" // Templated aliases -template using MapStubToTP = std::map, TrackingParticlePtr >; -template using MapTPToVecStub = std::map > >; +template +using MapStubToTP = std::map, TrackingParticlePtr>; +template +using MapTPToVecStub = std::map>>; template class TTStubAssociationMap { @@ -54,22 +56,14 @@ class TTStubAssociationMap { /// Get/set stub <-> truth association maps - const MapStubToTP& getTTStubToTrackingParticleMap() const { - return stubToTrackingParticleMap; - } - const MapTPToVecStub& getTrackingParticleToTTStubsMap() const { - return trackingParticleToStubVectorMap; - } + const MapStubToTP& getTTStubToTrackingParticleMap() const { return stubToTrackingParticleMap; } + const MapTPToVecStub& getTrackingParticleToTTStubsMap() const { return trackingParticleToStubVectorMap; } - void setTTStubToTrackingParticleMap(const MapStubToTP& aMap) { - stubToTrackingParticleMap = aMap; - } - void setTrackingParticleToTTStubsMap(const MapTPToVecStub& aMap) { - trackingParticleToStubVectorMap = aMap; - } + void setTTStubToTrackingParticleMap(const MapStubToTP& aMap) { stubToTrackingParticleMap = aMap; } + void setTrackingParticleToTTStubsMap(const MapTPToVecStub& aMap) { trackingParticleToStubVectorMap = aMap; } /// Set cluster <-> truth association object. - void setTTClusterAssociationMap(edm::RefProd > aCluAssoMap) { + void setTTClusterAssociationMap(edm::RefProd> aCluAssoMap) { theClusterAssociationMap = aCluAssoMap; } @@ -80,7 +74,7 @@ class TTStubAssociationMap { TrackingParticlePtr findTrackingParticlePtr(TTStubRefT aStub) const; /// Get all stubs associated to a TP. - /// (Even if the TP just contributes to one cluster in stub, + /// (Even if the TP just contributes to one cluster in stub, /// and even if their are other such TP, it is still listed here). std::vector> findTTStubRefs(TrackingParticlePtr aTrackingParticle) const; @@ -91,13 +85,13 @@ class TTStubAssociationMap { /// If both clusters are unknown, the stub is "unknown". /// If only one cluster is unknown, the stub is combinatoric. - /// If both clusters are genuine, and are associated to the same (main) TrackingParticle, + /// If both clusters are genuine, and are associated to the same (main) TrackingParticle, /// the stub is "genuine". - /// If both clusters are genuine, but are associated to different (main) TrackingParticles, + /// If both clusters are genuine, but are associated to different (main) TrackingParticles, /// the stub is "combinatoric". - /// If one cluster is combinatoric and the other is genuine/combinatoric, and they both share exactly - /// one TrackingParticle in common, then the stub is "genuine". (The clusters can have other - /// TrackingParticles besides the shared one, as long as these are not shared). If instead the clusters + /// If one cluster is combinatoric and the other is genuine/combinatoric, and they both share exactly + /// one TrackingParticle in common, then the stub is "genuine". (The clusters can have other + /// TrackingParticles besides the shared one, as long as these are not shared). If instead the clusters /// share 0 or ≥2 TrackingParticles in common, then the stub is "combinatoric". bool isGenuine(TTStubRefT aStub) const; @@ -108,7 +102,7 @@ class TTStubAssociationMap { /// Data members MapStubToTP stubToTrackingParticleMap; MapTPToVecStub trackingParticleToStubVectorMap; - edm::RefProd > theClusterAssociationMap; + edm::RefProd> theClusterAssociationMap; }; /// Close class @@ -126,7 +120,7 @@ TTStubAssociationMap::TTStubAssociationMap() { /// Set default data members stubToTrackingParticleMap.clear(); trackingParticleToStubVectorMap.clear(); - edm::RefProd >* aRefProd = new edm::RefProd >(); + edm::RefProd>* aRefProd = new edm::RefProd>(); theClusterAssociationMap = *aRefProd; } @@ -146,13 +140,12 @@ TrackingParticlePtr TTStubAssociationMap::findTrackingParticlePtr(TTStubRefT< } template -std::vector< TTStubRefT > TTStubAssociationMap::findTTStubRefs( - TrackingParticlePtr aTrackingParticle) const { +std::vector> TTStubAssociationMap::findTTStubRefs(TrackingParticlePtr aTrackingParticle) const { if (trackingParticleToStubVectorMap.find(aTrackingParticle) != trackingParticleToStubVectorMap.end()) { return trackingParticleToStubVectorMap.find(aTrackingParticle)->second; } - std::vector< TTStubRefT > tempVector; + std::vector> tempVector; tempVector.clear(); return tempVector; } diff --git a/SimTracker/TrackTriggerAssociation/interface/TTTrackAssociationMap.h b/SimTracker/TrackTriggerAssociation/interface/TTTrackAssociationMap.h index 33cf1838ca23f..257906478c067 100644 --- a/SimTracker/TrackTriggerAssociation/interface/TTTrackAssociationMap.h +++ b/SimTracker/TrackTriggerAssociation/interface/TTTrackAssociationMap.h @@ -37,8 +37,10 @@ #include "SimTracker/TrackTriggerAssociation/interface/TTStubAssociationMap.h" // Templated aliases -template using MapL1TrackToTP = std::map, TrackingParticlePtr >; -template using MapTPToVecL1Track = std::map> >; +template +using MapL1TrackToTP = std::map, TrackingParticlePtr>; +template +using MapTPToVecL1Track = std::map>>; template class TTTrackAssociationMap { @@ -51,22 +53,14 @@ class TTTrackAssociationMap { /// Get/set stub <-> truth association maps - const MapL1TrackToTP& getTTTrackToTrackingParticleMap() const { - return trackToTrackingParticleMap; - } - const MapTPToVecL1Track& getTrackingParticleToTTTracksMap() const { - return trackingParticleToTrackVectorMap; - } + const MapL1TrackToTP& getTTTrackToTrackingParticleMap() const { return trackToTrackingParticleMap; } + const MapTPToVecL1Track& getTrackingParticleToTTTracksMap() const { return trackingParticleToTrackVectorMap; } - void setTTTrackToTrackingParticleMap(const MapL1TrackToTP& aMap) { - trackToTrackingParticleMap = aMap; - } - void setTrackingParticleToTTTracksMap(const MapTPToVecL1Track& aMap) { - trackingParticleToTrackVectorMap = aMap; - } + void setTTTrackToTrackingParticleMap(const MapL1TrackToTP& aMap) { trackToTrackingParticleMap = aMap; } + void setTrackingParticleToTTTracksMap(const MapTPToVecL1Track& aMap) { trackingParticleToTrackVectorMap = aMap; } /// Set stub <-> truth association object. - void setTTStubAssociationMap(edm::RefProd > aStubAssoMap) { + void setTTStubAssociationMap(edm::RefProd> aStubAssoMap) { theStubAssociationMap = aStubAssoMap; } @@ -75,9 +69,9 @@ class TTTrackAssociationMap { TrackingParticlePtr findTrackingParticlePtr(TTTrackPtrT aTrack) const; /// Get all L1 tracks associated to a TP. - /// (Even if the TP just contributes to one cluster in one stub, + /// (Even if the TP just contributes to one cluster in one stub, /// and even if their are other such TP, it is still listed here). - std::vector > findTTTrackPtrs(TrackingParticlePtr aTrackingParticle) const; + std::vector> findTTTrackPtrs(TrackingParticlePtr aTrackingParticle) const; ///--- Get quality of L1 track based on truth info. /// (N.B. "genuine" tracks are used for official L1 track efficiency measurements). @@ -85,7 +79,7 @@ class TTTrackAssociationMap { /// Exactly one (i.e. not 0 or >= 2) unique TP contributes to every stub on the track. /// (even if it is not the principle TP in a stub, or contributes to only one cluster /// in the stub, it still counts). - /// N.B. If cfg param getAllowOneFalse2SStub() is true, then one incorrect stub in + /// N.B. If cfg param getAllowOneFalse2SStub() is true, then one incorrect stub in /// a 2S module is alowed /// ISSUE: a track with 4 stubs can be accepted if only 3 of its stubs are correct! /// ISSUE: isLooselyGenuine() must also be true. So if 2 TPs match track, one with @@ -107,7 +101,7 @@ class TTTrackAssociationMap { /// Data members MapL1TrackToTP trackToTrackingParticleMap; MapTPToVecL1Track trackingParticleToTrackVectorMap; - edm::RefProd > theStubAssociationMap; + edm::RefProd> theStubAssociationMap; bool AllowOneFalse2SStub; @@ -135,8 +129,7 @@ TTTrackAssociationMap::~TTTrackAssociationMap() {} /// Operations template <> -TrackingParticlePtr TTTrackAssociationMap::findTrackingParticlePtr( - TTTrackPtr aTrack) const; +TrackingParticlePtr TTTrackAssociationMap::findTrackingParticlePtr(TTTrackPtr aTrack) const; template <> std::vector TTTrackAssociationMap::findTTTrackPtrs( diff --git a/SimTracker/TrackTriggerAssociation/plugins/TTClusterAssociator.cc b/SimTracker/TrackTriggerAssociation/plugins/TTClusterAssociator.cc index 8c8efbb9b3d36..49e2d6e0b7b39 100644 --- a/SimTracker/TrackTriggerAssociation/plugins/TTClusterAssociator.cc +++ b/SimTracker/TrackTriggerAssociation/plugins/TTClusterAssociator.cc @@ -64,10 +64,8 @@ void TTClusterAssociator::produce(edm::Event& iEvent, co iEvent.getByToken(iTag, TTClusterHandle); /// Prepare the necessary maps - std::map> - clusterToTrackingParticleVectorMap; - std::map > - trackingParticleToClusterVectorMap; + std::map> clusterToTrackingParticleVectorMap; + std::map> trackingParticleToClusterVectorMap; clusterToTrackingParticleVectorMap.clear(); trackingParticleToClusterVectorMap.clear(); @@ -85,8 +83,7 @@ void TTClusterAssociator::produce(edm::Event& iEvent, co for (auto contentIter = clusters.begin(); contentIter != clusters.end(); ++contentIter) { /// Make the reference to be put in the map - TTClusterRef tempCluRef = - edmNew::makeRefTo(TTClusterHandle, contentIter); + TTClusterRef tempCluRef = edmNew::makeRefTo(TTClusterHandle, contentIter); /// Prepare the maps wrt TTCluster if (clusterToTrackingParticleVectorMap.find(tempCluRef) == clusterToTrackingParticleVectorMap.end()) { @@ -176,8 +173,7 @@ void TTClusterAssociator::produce(edm::Event& iEvent, co /// Clean the maps that need cleaning /// Prepare the output map wrt TrackingParticle - std::map>::iterator iterMapToClean; + std::map>::iterator iterMapToClean; for (iterMapToClean = trackingParticleToClusterVectorMap.begin(); iterMapToClean != trackingParticleToClusterVectorMap.end(); ++iterMapToClean) { diff --git a/SimTracker/TrackTriggerAssociation/plugins/TTStubAssociator.cc b/SimTracker/TrackTriggerAssociation/plugins/TTStubAssociator.cc index e57c4f5bcc8d1..bc20438806b6f 100644 --- a/SimTracker/TrackTriggerAssociation/plugins/TTStubAssociator.cc +++ b/SimTracker/TrackTriggerAssociation/plugins/TTStubAssociator.cc @@ -43,8 +43,7 @@ void TTStubAssociator::produce(edm::Event& iEvent, const /// Prepare the necessary maps std::map stubToTrackingParticleMap; - std::map> - trackingParticleToStubVectorMap; + std::map> trackingParticleToStubVectorMap; stubToTrackingParticleMap.clear(); trackingParticleToStubVectorMap.clear(); @@ -72,12 +71,11 @@ void TTStubAssociator::produce(edm::Event& iEvent, const TTStubRef tempStubRef = edmNew::makeRefTo(ttStubHandle, contentIter); /// Fill the inclusive map which is careless of the stub classification - for (unsigned int ic = 0; ic < 2; ic++) { + for (unsigned int ic = 0; ic < 2; ic++) { std::vector tempTPs = ttClusterAssociationMapHandle->findTrackingParticlePtrs(tempStubRef->clusterRef(ic)); for (const TrackingParticlePtr& testTP : tempTPs) { - if (testTP.isNull()) continue; @@ -195,8 +193,7 @@ void TTStubAssociator::produce(edm::Event& iEvent, const /// Clean the only map that needs cleaning /// Prepare the output map wrt TrackingParticle - typename std::map>::iterator iterMapToClean; + typename std::map>::iterator iterMapToClean; for (auto& p : trackingParticleToStubVectorMap) { /// Get the vector of references to TTStub std::vector tempVector = p.second; diff --git a/SimTracker/TrackTriggerAssociation/plugins/TTTrackAssociator.cc b/SimTracker/TrackTriggerAssociation/plugins/TTTrackAssociator.cc index 33506d1706993..c1ed94507751f 100644 --- a/SimTracker/TrackTriggerAssociation/plugins/TTTrackAssociator.cc +++ b/SimTracker/TrackTriggerAssociation/plugins/TTTrackAssociator.cc @@ -37,8 +37,7 @@ void TTTrackAssociator::produce(edm::Event& iEvent, cons /// Prepare the necessary maps std::map trackToTrackingParticleMap; - std::map> - trackingParticleToTrackVectorMap; + std::map> trackingParticleToTrackVectorMap; trackToTrackingParticleMap.clear(); trackingParticleToTrackVectorMap.clear(); @@ -57,7 +56,7 @@ void TTTrackAssociator::produce(edm::Event& iEvent, cons auxMap.clear(); int mayCombinUnknown = 0; - /// Fill the map associating each TP to a vector of L1 tracks. + /// Fill the map associating each TP to a vector of L1 tracks. /// Do this using the association map of the clusters inside each stub, /// as stub associator misses stub --> all TP map (FIX). for (const TTStubRef& stub : theseStubs) { @@ -105,12 +104,11 @@ void TTTrackAssociator::produce(edm::Event& iEvent, cons for (const auto& auxPair : auxMap) { /// Get all associated stubs of this TrackingParticle - std::vector tempStubs = - ttStubAssociationMapHandle->findTTStubRefs(auxPair.second); + std::vector tempStubs = ttStubAssociationMapHandle->findTTStubRefs(auxPair.second); - // Count stubs on track that are not related to this TP + // Count stubs on track that are not related to this TP int nnotfound = 0; - for (const TTStubRef& stub : theseStubs) { + for (const TTStubRef& stub : theseStubs) { /// We want that all the stubs of the track are included in the container of /// all the stubs produced by this particular TrackingParticle which we /// already know is one of the TrackingParticles that released hits @@ -141,7 +139,7 @@ void TTTrackAssociator::produce(edm::Event& iEvent, cons /// If 0 or >= 2 TP: COMBINATORIC /// WARNING: This means if one TP matches all stubs, and another matches all STUBS except /// one, then the trackToTrackingParticleMap will not be filled. - /// WARNING: This also means that trackToTrackingParticleMap will be filled if + /// WARNING: This also means that trackToTrackingParticleMap will be filled if /// one TP matches all stubs, except for an incorrect one in either PS or 2S modules. if (nTPs != 1) continue; @@ -160,7 +158,7 @@ void TTTrackAssociator::produce(edm::Event& iEvent, cons /// (CHECK: Couldn't this be done by reference, to save CPU?) std::vector tempVector = p.second; - /// Sort and remove duplicates + /// Sort and remove duplicates std::sort(tempVector.begin(), tempVector.end()); tempVector.erase(std::unique(tempVector.begin(), tempVector.end()), tempVector.end()); diff --git a/SimTracker/TrackTriggerAssociation/src/TTTrackAssociationMap.cc b/SimTracker/TrackTriggerAssociation/src/TTTrackAssociationMap.cc index c019a9fd29be9..a9ce8d39b180c 100644 --- a/SimTracker/TrackTriggerAssociation/src/TTTrackAssociationMap.cc +++ b/SimTracker/TrackTriggerAssociation/src/TTTrackAssociationMap.cc @@ -9,8 +9,7 @@ /// Operations template <> -TrackingParticlePtr TTTrackAssociationMap::findTrackingParticlePtr( - TTTrackPtr aTrack) const { +TrackingParticlePtr TTTrackAssociationMap::findTrackingParticlePtr(TTTrackPtr aTrack) const { if (trackToTrackingParticleMap.find(aTrack) != trackToTrackingParticleMap.end()) { return trackToTrackingParticleMap.find(aTrack)->second; } @@ -28,7 +27,7 @@ std::vector TTTrackAssociationMap::findTTTra } /// Default: return empty vector - std::vector tempVec; + std::vector tempVec; tempVec.clear(); return tempVec; } From d30458f5f21bd1ae34421fc09bad29cc8379fd37 Mon Sep 17 00:00:00 2001 From: Ian Tomalin Date: Mon, 21 Dec 2020 10:56:20 +0000 Subject: [PATCH 4/6] Removed two unused variables --- .../TrackTriggerAssociation/plugins/TTClusterAssociator.cc | 1 - .../TrackTriggerAssociation/plugins/TTTrackAssociator.cc | 3 --- 2 files changed, 4 deletions(-) diff --git a/SimTracker/TrackTriggerAssociation/plugins/TTClusterAssociator.cc b/SimTracker/TrackTriggerAssociation/plugins/TTClusterAssociator.cc index 49e2d6e0b7b39..779597d0d50dc 100644 --- a/SimTracker/TrackTriggerAssociation/plugins/TTClusterAssociator.cc +++ b/SimTracker/TrackTriggerAssociation/plugins/TTClusterAssociator.cc @@ -33,7 +33,6 @@ void TTClusterAssociator::produce(edm::Event& iEvent, co if (not trackingParticleHandle->empty()) { /// Loop over TrackingParticles - std::vector::const_iterator iterTPart; for (unsigned int tpCnt = 0; tpCnt < trackingParticleHandle->size(); tpCnt++) { /// Make the pointer to the TrackingParticle TrackingParticlePtr tempTPPtr(trackingParticleHandle, tpCnt); diff --git a/SimTracker/TrackTriggerAssociation/plugins/TTTrackAssociator.cc b/SimTracker/TrackTriggerAssociation/plugins/TTTrackAssociator.cc index c1ed94507751f..17a550c39acb6 100644 --- a/SimTracker/TrackTriggerAssociation/plugins/TTTrackAssociator.cc +++ b/SimTracker/TrackTriggerAssociation/plugins/TTTrackAssociator.cc @@ -7,8 +7,6 @@ * */ -// FIX: N.B Code below could surely be more efficiently written? - #include "SimTracker/TrackTriggerAssociation/plugins/TTTrackAssociator.h" /// Implement the producer @@ -43,7 +41,6 @@ void TTTrackAssociator::produce(edm::Event& iEvent, cons // Start the loop on tracks - typename std::vector>::const_iterator inputIter; for (unsigned int jTrk = 0; jTrk < TTTrackHandle->size(); jTrk++) { /// Make the pointer to be put in the map TTTrackPtr tempTrackPtr(TTTrackHandle, jTrk); From 0cae450b6f26d35ee5c7af369e88f73939f6e159 Mon Sep 17 00:00:00 2001 From: Ian Tomalin Date: Thu, 24 Dec 2020 17:58:54 +0000 Subject: [PATCH 5/6] Implemented fixes from code review --- .../interface/TTClusterAssociationMap.h | 83 ++++++++++--------- .../interface/TTStubAssociationMap.h | 66 ++++++++------- .../interface/TTTrackAssociationMap.h | 36 ++++---- .../plugins/TTClusterAssociator.cc | 52 +++++------- .../plugins/TTClusterAssociator.h | 31 +++---- .../plugins/TTStubAssociator.cc | 35 ++++---- .../plugins/TTStubAssociator.h | 29 +++---- .../plugins/TTTrackAssociator.cc | 28 +++---- .../plugins/TTTrackAssociator.h | 20 ++--- .../src/TTTrackAssociationMap.cc | 33 ++++---- 10 files changed, 204 insertions(+), 209 deletions(-) diff --git a/SimTracker/TrackTriggerAssociation/interface/TTClusterAssociationMap.h b/SimTracker/TrackTriggerAssociation/interface/TTClusterAssociationMap.h index 06252f6bfae07..0431889b29853 100644 --- a/SimTracker/TrackTriggerAssociation/interface/TTClusterAssociationMap.h +++ b/SimTracker/TrackTriggerAssociation/interface/TTClusterAssociationMap.h @@ -51,19 +51,20 @@ class TTClusterAssociationMap { /// Get/set cluster <-> truth association maps - const MapClusToVecTP& getTTClusterToTrackingParticlesMap() const { return clusterToTrackingParticleVectorMap; } - const MapTPToVecClus& getTrackingParticleToTTClustersMap() const { return trackingParticleToClusterVectorMap; } + const MapClusToVecTP& getTTClusterToTrackingParticlesMap() const { return clusterToTrackingParticleVectorMap_; } + const MapTPToVecClus& getTrackingParticleToTTClustersMap() const { return trackingParticleToClusterVectorMap_; } - void setTTClusterToTrackingParticlesMap(const MapClusToVecTP& aMap) { clusterToTrackingParticleVectorMap = aMap; } - void setTrackingParticleToTTClustersMap(const MapTPToVecClus& aMap) { trackingParticleToClusterVectorMap = aMap; } + void setTTClusterToTrackingParticlesMap(const MapClusToVecTP& aMap) { clusterToTrackingParticleVectorMap_ = aMap; } + void setTrackingParticleToTTClustersMap(const MapTPToVecClus& aMap) { trackingParticleToClusterVectorMap_ = aMap; } /// Get all TPs associated to a cluster - std::vector findTrackingParticlePtrs(TTClusterRefT aCluster) const; + const std::vector& findTrackingParticlePtrs(TTClusterRefT aCluster) const; + /// Get main TP associated to a cluster. (Non-NULL if isGenuine() below is true). - TrackingParticlePtr findTrackingParticlePtr(TTClusterRefT aCluster) const; + const TrackingParticlePtr& findTrackingParticlePtr(TTClusterRefT aCluster) const; // Get all clusters associated to TP. - std::vector> findTTClusterRefs(TrackingParticlePtr aTrackingParticle) const; + const std::vector>& findTTClusterRefs(TrackingParticlePtr aTrackingParticle) const; ///--- Get quality of L1 cluster based on truth info. /// (exactly 1 of following 3 functions is always true) @@ -79,13 +80,19 @@ class TTClusterAssociationMap { private: /// Data members - MapClusToVecTP clusterToTrackingParticleVectorMap; - MapTPToVecClus trackingParticleToClusterVectorMap; + MapClusToVecTP clusterToTrackingParticleVectorMap_; + MapTPToVecClus trackingParticleToClusterVectorMap_; int nclus; + // Allow functions to return reference to null. + static const TrackingParticlePtr nullTrackingParticlePtr_; + static const std::vector nullVecTrackingParticlePtr_; + static const std::vector> nullVecClusterRef_; + }; /// Close class + /*! \brief Implementation of methods * \details Here, in the header file, the methods which do not depend * on the specific type that can fit the template. @@ -93,13 +100,20 @@ class TTClusterAssociationMap { * in the source file. */ + +// Static constant data members. +template +const TrackingParticlePtr TTClusterAssociationMap::nullTrackingParticlePtr_; +template +const std::vector TTClusterAssociationMap::nullVecTrackingParticlePtr_; +template +const std::vector> TTClusterAssociationMap::nullVecClusterRef_; + /// Default Constructor /// NOTE: to be used with setSomething(...) methods template TTClusterAssociationMap::TTClusterAssociationMap() { /// Set default data members - clusterToTrackingParticleVectorMap.clear(); - trackingParticleToClusterVectorMap.clear(); nclus = 0; } @@ -109,26 +123,31 @@ TTClusterAssociationMap::~TTClusterAssociationMap() {} /// Operations template -std::vector> TTClusterAssociationMap::findTTClusterRefs( +const std::vector>& TTClusterAssociationMap::findTTClusterRefs( TrackingParticlePtr aTrackingParticle) const { - if (trackingParticleToClusterVectorMap.find(aTrackingParticle) != trackingParticleToClusterVectorMap.end()) { - return trackingParticleToClusterVectorMap.find(aTrackingParticle)->second; + if (trackingParticleToClusterVectorMap_.find(aTrackingParticle) != trackingParticleToClusterVectorMap_.end()) { + return trackingParticleToClusterVectorMap_.find(aTrackingParticle)->second; + } else { + return nullVecClusterRef_; } - - std::vector> tempVector; - tempVector.clear(); - return tempVector; } template -std::vector TTClusterAssociationMap::findTrackingParticlePtrs(TTClusterRefT aCluster) const { - if (clusterToTrackingParticleVectorMap.find(aCluster) != clusterToTrackingParticleVectorMap.end()) { - return clusterToTrackingParticleVectorMap.find(aCluster)->second; +const std::vector& TTClusterAssociationMap::findTrackingParticlePtrs(TTClusterRefT aCluster) const { + if (clusterToTrackingParticleVectorMap_.find(aCluster) != clusterToTrackingParticleVectorMap_.end()) { + return clusterToTrackingParticleVectorMap_.find(aCluster)->second; + } else { + return nullVecTrackingParticlePtr_; } +} - std::vector tempVector; - tempVector.clear(); - return tempVector; +template +const TrackingParticlePtr& TTClusterAssociationMap::findTrackingParticlePtr(TTClusterRefT aCluster) const { + if (this->isGenuine(aCluster)) { + return this->findTrackingParticlePtrs(aCluster).at(0); + } else { + return nullTrackingParticlePtr_; + } } /// MC truth @@ -158,7 +177,7 @@ std::vector TTClusterAssociationMap::findTrackingParticl template bool TTClusterAssociationMap::isGenuine(TTClusterRefT aCluster) const { /// Get the TrackingParticles - std::vector theseTrackingParticles = this->findTrackingParticlePtrs(aCluster); + const std::vector& theseTrackingParticles = this->findTrackingParticlePtrs(aCluster); /// If the vector is empty, then the cluster is UNKNOWN if (theseTrackingParticles.empty()) @@ -216,7 +235,7 @@ bool TTClusterAssociationMap::isGenuine(TTClusterRefT aCluster) const { template bool TTClusterAssociationMap::isUnknown(TTClusterRefT aCluster) const { /// Get the TrackingParticles - std::vector theseTrackingParticles = this->findTrackingParticlePtrs(aCluster); + const std::vector& theseTrackingParticles = this->findTrackingParticlePtrs(aCluster); /// If the vector is empty, then the cluster is UNKNOWN if (theseTrackingParticles.empty()) @@ -251,7 +270,7 @@ bool TTClusterAssociationMap::isUnknown(TTClusterRefT aCluster) const { template bool TTClusterAssociationMap::isCombinatoric(TTClusterRefT aCluster) const { /// Get the TrackingParticles - std::vector theseTrackingParticles = this->findTrackingParticlePtrs(aCluster); + const std::vector& theseTrackingParticles = this->findTrackingParticlePtrs(aCluster); /// If the vector is empty, then the cluster is UNKNOWN if (theseTrackingParticles.empty()) @@ -296,14 +315,4 @@ bool TTClusterAssociationMap::isCombinatoric(TTClusterRefT aCluster) const return (goodDifferentTPs > 1); } -template -TrackingParticlePtr TTClusterAssociationMap::findTrackingParticlePtr(TTClusterRefT aCluster) const { - if (this->isGenuine(aCluster)) { - return this->findTrackingParticlePtrs(aCluster).at(0); - } - - TrackingParticlePtr* temp = new TrackingParticlePtr(); - return *temp; -} - #endif diff --git a/SimTracker/TrackTriggerAssociation/interface/TTStubAssociationMap.h b/SimTracker/TrackTriggerAssociation/interface/TTStubAssociationMap.h index 9a2238cdd2833..41cfeb1b98d4a 100644 --- a/SimTracker/TrackTriggerAssociation/interface/TTStubAssociationMap.h +++ b/SimTracker/TrackTriggerAssociation/interface/TTStubAssociationMap.h @@ -56,27 +56,27 @@ class TTStubAssociationMap { /// Get/set stub <-> truth association maps - const MapStubToTP& getTTStubToTrackingParticleMap() const { return stubToTrackingParticleMap; } - const MapTPToVecStub& getTrackingParticleToTTStubsMap() const { return trackingParticleToStubVectorMap; } + const MapStubToTP& getTTStubToTrackingParticleMap() const { return stubToTrackingParticleMap_; } + const MapTPToVecStub& getTrackingParticleToTTStubsMap() const { return trackingParticleToStubVectorMap_; } - void setTTStubToTrackingParticleMap(const MapStubToTP& aMap) { stubToTrackingParticleMap = aMap; } - void setTrackingParticleToTTStubsMap(const MapTPToVecStub& aMap) { trackingParticleToStubVectorMap = aMap; } + void setTTStubToTrackingParticleMap(const MapStubToTP& aMap) { stubToTrackingParticleMap_ = aMap; } + void setTrackingParticleToTTStubsMap(const MapTPToVecStub& aMap) { trackingParticleToStubVectorMap_ = aMap; } /// Set cluster <-> truth association object. void setTTClusterAssociationMap(edm::RefProd> aCluAssoMap) { - theClusterAssociationMap = aCluAssoMap; + theClusterAssociationMap_ = aCluAssoMap; } /// Get principle TP associated to a stub. (Non-NULL if isGenuine() below is true). /// (N.B. There is no function returning all TP associated to a stub). /// (P.S. As this function only returns principle TP, it is not used when constructing /// the TTTrackAssociationMap). - TrackingParticlePtr findTrackingParticlePtr(TTStubRefT aStub) const; + const TrackingParticlePtr& findTrackingParticlePtr(TTStubRefT aStub) const; /// Get all stubs associated to a TP. /// (Even if the TP just contributes to one cluster in stub, /// and even if their are other such TP, it is still listed here). - std::vector> findTTStubRefs(TrackingParticlePtr aTrackingParticle) const; + const std::vector>& findTTStubRefs(TrackingParticlePtr aTrackingParticle) const; ///--- Get quality of stub based on truth info. /// (N.B. Both genuine & combinatoric stubs contribute to "genuine" L1 tracks @@ -100,12 +100,17 @@ class TTStubAssociationMap { private: /// Data members - MapStubToTP stubToTrackingParticleMap; - MapTPToVecStub trackingParticleToStubVectorMap; - edm::RefProd> theClusterAssociationMap; + MapStubToTP stubToTrackingParticleMap_; + MapTPToVecStub trackingParticleToStubVectorMap_; + edm::RefProd> theClusterAssociationMap_; + + // Allow functions to return reference to null. + static const TrackingParticlePtr nullTrackingParticlePtr_; + static const std::vector> nullVecStubRef_; }; /// Close class + /*! \brief Implementation of methods * \details Here, in the header file, the methods which do not depend * on the specific type that can fit the template. @@ -113,15 +118,18 @@ class TTStubAssociationMap { * in the source file. */ + +// Static constant data members. +template +const TrackingParticlePtr TTStubAssociationMap::nullTrackingParticlePtr_; +template +const std::vector> TTStubAssociationMap::nullVecStubRef_; + /// Default Constructor /// NOTE: to be used with setSomething(...) methods template TTStubAssociationMap::TTStubAssociationMap() { /// Set default data members - stubToTrackingParticleMap.clear(); - trackingParticleToStubVectorMap.clear(); - edm::RefProd>* aRefProd = new edm::RefProd>(); - theClusterAssociationMap = *aRefProd; } /// Destructor @@ -130,24 +138,21 @@ TTStubAssociationMap::~TTStubAssociationMap() {} /// Operations template -TrackingParticlePtr TTStubAssociationMap::findTrackingParticlePtr(TTStubRefT aStub) const { - if (stubToTrackingParticleMap.find(aStub) != stubToTrackingParticleMap.end()) { - return stubToTrackingParticleMap.find(aStub)->second; +const TrackingParticlePtr& TTStubAssociationMap::findTrackingParticlePtr(TTStubRefT aStub) const { + if (stubToTrackingParticleMap_.find(aStub) != stubToTrackingParticleMap_.end()) { + return stubToTrackingParticleMap_.find(aStub)->second; + } else { + return nullTrackingParticlePtr_; } - - /// Default: return NULL - return TrackingParticlePtr(); } template -std::vector> TTStubAssociationMap::findTTStubRefs(TrackingParticlePtr aTrackingParticle) const { - if (trackingParticleToStubVectorMap.find(aTrackingParticle) != trackingParticleToStubVectorMap.end()) { - return trackingParticleToStubVectorMap.find(aTrackingParticle)->second; +const std::vector>& TTStubAssociationMap::findTTStubRefs(TrackingParticlePtr aTrackingParticle) const { + if (trackingParticleToStubVectorMap_.find(aTrackingParticle) != trackingParticleToStubVectorMap_.end()) { + return trackingParticleToStubVectorMap_.find(aTrackingParticle)->second; + } else { + return nullVecStubRef_; } - - std::vector> tempVector; - tempVector.clear(); - return tempVector; } /// MC truth @@ -175,15 +180,14 @@ bool TTStubAssociationMap::isCombinatoric(TTStubRefT aStub) const { template bool TTStubAssociationMap::isUnknown(TTStubRefT aStub) const { /// UNKNOWN means that both clusters are unknown - //std::vector< edm::Ref< edmNew::DetSetVector< TTCluster< T > >, TTCluster< T > > > theseClusters = aStub->getClusterRefs(); /// Sanity check - if (theClusterAssociationMap.isNull()) { + if (theClusterAssociationMap_.isNull()) { return true; } - if (theClusterAssociationMap->isUnknown(aStub->clusterRef(0)) && - theClusterAssociationMap->isUnknown(aStub->clusterRef(1))) + if (theClusterAssociationMap_->isUnknown(aStub->clusterRef(0)) && + theClusterAssociationMap_->isUnknown(aStub->clusterRef(1))) return true; return false; diff --git a/SimTracker/TrackTriggerAssociation/interface/TTTrackAssociationMap.h b/SimTracker/TrackTriggerAssociation/interface/TTTrackAssociationMap.h index 257906478c067..a819518eedbb1 100644 --- a/SimTracker/TrackTriggerAssociation/interface/TTTrackAssociationMap.h +++ b/SimTracker/TrackTriggerAssociation/interface/TTTrackAssociationMap.h @@ -53,25 +53,25 @@ class TTTrackAssociationMap { /// Get/set stub <-> truth association maps - const MapL1TrackToTP& getTTTrackToTrackingParticleMap() const { return trackToTrackingParticleMap; } - const MapTPToVecL1Track& getTrackingParticleToTTTracksMap() const { return trackingParticleToTrackVectorMap; } + const MapL1TrackToTP& getTTTrackToTrackingParticleMap() const { return trackToTrackingParticleMap_; } + const MapTPToVecL1Track& getTrackingParticleToTTTracksMap() const { return trackingParticleToTrackVectorMap_; } - void setTTTrackToTrackingParticleMap(const MapL1TrackToTP& aMap) { trackToTrackingParticleMap = aMap; } - void setTrackingParticleToTTTracksMap(const MapTPToVecL1Track& aMap) { trackingParticleToTrackVectorMap = aMap; } + void setTTTrackToTrackingParticleMap(const MapL1TrackToTP& aMap) { trackToTrackingParticleMap_ = aMap; } + void setTrackingParticleToTTTracksMap(const MapTPToVecL1Track& aMap) { trackingParticleToTrackVectorMap_ = aMap; } /// Set stub <-> truth association object. void setTTStubAssociationMap(edm::RefProd> aStubAssoMap) { - theStubAssociationMap = aStubAssoMap; + theStubAssociationMap_ = aStubAssoMap; } /// Get principle TP associated to a L1 track. (Non-NULL if isLooselyGenuine() below is true). /// (N.B. There is no function returning all TP associated to a L1 track). - TrackingParticlePtr findTrackingParticlePtr(TTTrackPtrT aTrack) const; + const TrackingParticlePtr& findTrackingParticlePtr(TTTrackPtrT aTrack) const; /// Get all L1 tracks associated to a TP. /// (Even if the TP just contributes to one cluster in one stub, /// and even if their are other such TP, it is still listed here). - std::vector> findTTTrackPtrs(TrackingParticlePtr aTrackingParticle) const; + const std::vector>& findTTTrackPtrs(TrackingParticlePtr aTrackingParticle) const; ///--- Get quality of L1 track based on truth info. /// (N.B. "genuine" tracks are used for official L1 track efficiency measurements). @@ -99,12 +99,16 @@ class TTTrackAssociationMap { private: /// Data members - MapL1TrackToTP trackToTrackingParticleMap; - MapTPToVecL1Track trackingParticleToTrackVectorMap; - edm::RefProd> theStubAssociationMap; + MapL1TrackToTP trackToTrackingParticleMap_; + MapTPToVecL1Track trackingParticleToTrackVectorMap_; + edm::RefProd> theStubAssociationMap_; bool AllowOneFalse2SStub; + // Allow functions to return reference to null. + static const TrackingParticlePtr nullTrackingParticlePtr_; + static const std::vector nullVecTTTrackPtr_; + }; /// Close class /*! \brief Implementation of methods @@ -114,13 +118,17 @@ class TTTrackAssociationMap { * in the source file. */ +// Static constant data members. +template +const TrackingParticlePtr TTTrackAssociationMap::nullTrackingParticlePtr_; +template +const std::vector TTTrackAssociationMap::nullVecTTTrackPtr_; + /// Default Constructor /// NOTE: to be used with setSomething(...) methods template TTTrackAssociationMap::TTTrackAssociationMap() { /// Set default data members - trackToTrackingParticleMap.clear(); - trackingParticleToTrackVectorMap.clear(); } /// Destructor @@ -129,10 +137,10 @@ TTTrackAssociationMap::~TTTrackAssociationMap() {} /// Operations template <> -TrackingParticlePtr TTTrackAssociationMap::findTrackingParticlePtr(TTTrackPtr aTrack) const; +const TrackingParticlePtr& TTTrackAssociationMap::findTrackingParticlePtr(TTTrackPtr aTrack) const; template <> -std::vector TTTrackAssociationMap::findTTTrackPtrs( +const std::vector& TTTrackAssociationMap::findTTTrackPtrs( TrackingParticlePtr aTrackingParticle) const; /// MC truth diff --git a/SimTracker/TrackTriggerAssociation/plugins/TTClusterAssociator.cc b/SimTracker/TrackTriggerAssociation/plugins/TTClusterAssociator.cc index 779597d0d50dc..6df9b308ea9c4 100644 --- a/SimTracker/TrackTriggerAssociation/plugins/TTClusterAssociator.cc +++ b/SimTracker/TrackTriggerAssociation/plugins/TTClusterAssociator.cc @@ -17,34 +17,32 @@ void TTClusterAssociator::produce(edm::Event& iEvent, co return; /// Get the PixelDigiSimLink - iEvent.getByToken(digisimLinkToken, thePixelDigiSimLinkHandle); + iEvent.getByToken(digisimLinkToken_, thePixelDigiSimLinkHandle_); /// Get the TrackingParticles - iEvent.getByToken(tpToken, trackingParticleHandle); + iEvent.getByToken(tpToken_, trackingParticleHandle_); - // const TrackerTopology* const tTopo = theTrackerTopology.product(); - const TrackerGeometry* const theTrackerGeom = theTrackerGeometry.product(); + // const TrackerTopology* const tTopo = theTrackerTopology_.product(); + const TrackerGeometry* const theTrackerGeom = theTrackerGeometry_.product(); /// Preliminary task: map SimTracks by TrackingParticle /// Prepare the map std::map, TrackingParticlePtr> simTrackUniqueToTPMap; - simTrackUniqueToTPMap.clear(); - if (not trackingParticleHandle->empty()) { + if (not trackingParticleHandle_->empty()) { /// Loop over TrackingParticles - for (unsigned int tpCnt = 0; tpCnt < trackingParticleHandle->size(); tpCnt++) { + for (unsigned int tpCnt = 0; tpCnt < trackingParticleHandle_->size(); tpCnt++) { /// Make the pointer to the TrackingParticle - TrackingParticlePtr tempTPPtr(trackingParticleHandle, tpCnt); + TrackingParticlePtr tempTPPtr(trackingParticleHandle_, tpCnt); /// Get the EncodedEventId EncodedEventId eventId = EncodedEventId(tempTPPtr->eventId()); /// Loop over SimTracks inside TrackingParticle for (const auto& simTrack : tempTPPtr->g4Tracks()) { - /// Build the unique SimTrack Id (which is SimTrack ID + EncodedEventId) - std::pair simTrackUniqueId(simTrack.trackId(), eventId); - simTrackUniqueToTPMap.insert(std::make_pair(simTrackUniqueId, tempTPPtr)); + /// Use the unique SimTrack Id (which is SimTrack ID + EncodedEventId) + simTrackUniqueToTPMap.emplace(std::make_pair(simTrack.trackId(), eventId), tempTPPtr); } } /// End of loop over TrackingParticles } @@ -53,7 +51,7 @@ void TTClusterAssociator::produce(edm::Event& iEvent, co int ncont1 = 0; - for (const auto& iTag : ttClustersTokens) { + for (const auto& iTag : ttClustersTokens_) { /// Prepare output auto associationMapForOutput = std::make_unique>(); @@ -65,8 +63,6 @@ void TTClusterAssociator::produce(edm::Event& iEvent, co /// Prepare the necessary maps std::map> clusterToTrackingParticleVectorMap; std::map> trackingParticleToClusterVectorMap; - clusterToTrackingParticleVectorMap.clear(); - trackingParticleToClusterVectorMap.clear(); /// Loop over the input Clusters for (const auto& gd : theTrackerGeom->dets()) { @@ -87,13 +83,12 @@ void TTClusterAssociator::produce(edm::Event& iEvent, co /// Prepare the maps wrt TTCluster if (clusterToTrackingParticleVectorMap.find(tempCluRef) == clusterToTrackingParticleVectorMap.end()) { std::vector tpVector; - tpVector.clear(); - clusterToTrackingParticleVectorMap.insert(std::make_pair(tempCluRef, tpVector)); + clusterToTrackingParticleVectorMap.emplace(tempCluRef, tpVector); } /// Get the PixelDigiSimLink /// Safety check added after new digitizer (Oct 2014) - if (thePixelDigiSimLinkHandle->find(detid) == thePixelDigiSimLinkHandle->end()) { + if (thePixelDigiSimLinkHandle_->find(detid) == thePixelDigiSimLinkHandle_->end()) { /// Sensor is not found in DigiSimLink. /// Set MC truth to NULL for all hits in this sensor. Period. @@ -102,15 +97,15 @@ void TTClusterAssociator::produce(edm::Event& iEvent, co for (unsigned int i = 0; i < theseHits.size(); i++) { /// No SimLink is found by definition /// Then store NULL MC truth for all the digis - TrackingParticlePtr tempTPPtr; // = new edm::Ptr< TrackingParticle >(); - clusterToTrackingParticleVectorMap.find(tempCluRef)->second.push_back(tempTPPtr); + TrackingParticlePtr tempTPPtr; + clusterToTrackingParticleVectorMap.find(tempCluRef)->second.push_back(tempTPPtr); } /// Go to the next sensor continue; } - edm::DetSet thisDigiSimLink = (*(thePixelDigiSimLinkHandle))[detid]; + edm::DetSet thisDigiSimLink = (*(thePixelDigiSimLinkHandle_))[detid]; edm::DetSet::const_iterator iterSimLink; /// Get the Digis and loop over them @@ -140,22 +135,21 @@ void TTClusterAssociator::produce(edm::Event& iEvent, co if (trackingParticleToClusterVectorMap.find(thisTrackingParticle) == trackingParticleToClusterVectorMap.end()) { std::vector clusterVector; - clusterVector.clear(); - trackingParticleToClusterVectorMap.insert(std::make_pair(thisTrackingParticle, clusterVector)); + trackingParticleToClusterVectorMap.emplace(thisTrackingParticle, clusterVector); } trackingParticleToClusterVectorMap.find(thisTrackingParticle) ->second.push_back(tempCluRef); /// Fill the auxiliary map } else { /// In case no TrackingParticle is found, store a NULL pointer - TrackingParticlePtr tempTPPtr; // = new edm::Ptr< TrackingParticle >(); + TrackingParticlePtr tempTPPtr; clusterToTrackingParticleVectorMap.find(tempCluRef)->second.push_back(tempTPPtr); } } /// End of loop over PixelDigiSimLink } /// End of loop over all the hits composing the Cluster /// Check that the cluster has a non-NULL TP pointer - std::vector theseClusterTrackingParticlePtrs = + const std::vector& theseClusterTrackingParticlePtrs = clusterToTrackingParticleVectorMap.find(tempCluRef)->second; bool allOfThemAreNull = true; for (unsigned int tpi = 0; tpi < theseClusterTrackingParticlePtrs.size() && allOfThemAreNull; tpi++) { @@ -172,17 +166,13 @@ void TTClusterAssociator::produce(edm::Event& iEvent, co /// Clean the maps that need cleaning /// Prepare the output map wrt TrackingParticle - std::map>::iterator iterMapToClean; - for (iterMapToClean = trackingParticleToClusterVectorMap.begin(); - iterMapToClean != trackingParticleToClusterVectorMap.end(); - ++iterMapToClean) { + for (auto& p : trackingParticleToClusterVectorMap) { /// Get the vector of references to TTCluster - std::vector tempVector = iterMapToClean->second; + std::vector& tempVector = p.second; /// Sort and remove duplicates std::sort(tempVector.begin(), tempVector.end()); tempVector.erase(std::unique(tempVector.begin(), tempVector.end()), tempVector.end()); - iterMapToClean->second = tempVector; } /// Put the maps in the association object @@ -190,7 +180,7 @@ void TTClusterAssociator::produce(edm::Event& iEvent, co associationMapForOutput->setTrackingParticleToTTClustersMap(trackingParticleToClusterVectorMap); /// Put output in the event - iEvent.put(std::move(associationMapForOutput), ttClustersInputTags.at(ncont1).instance()); + iEvent.put(std::move(associationMapForOutput), ttClustersInputTags_.at(ncont1).instance()); ++ncont1; diff --git a/SimTracker/TrackTriggerAssociation/plugins/TTClusterAssociator.h b/SimTracker/TrackTriggerAssociation/plugins/TTClusterAssociator.h index 6db01f17149b2..0ee48c37de463 100644 --- a/SimTracker/TrackTriggerAssociation/plugins/TTClusterAssociator.h +++ b/SimTracker/TrackTriggerAssociation/plugins/TTClusterAssociator.h @@ -7,6 +7,7 @@ * * \author Nicola Pozzobon * \date 2013, Jul 19 + * (tidy up: Ian Tomalin, 2020) * */ @@ -52,17 +53,17 @@ class TTClusterAssociator : public edm::stream::EDProducer<> { private: /// Data members - edm::Handle > thePixelDigiSimLinkHandle; - edm::Handle > trackingParticleHandle; + edm::Handle > thePixelDigiSimLinkHandle_; + edm::Handle > trackingParticleHandle_; - std::vector ttClustersInputTags; + std::vector ttClustersInputTags_; - edm::EDGetTokenT > digisimLinkToken; - edm::EDGetTokenT > tpToken; - std::vector > > > ttClustersTokens; + edm::EDGetTokenT > digisimLinkToken_; + edm::EDGetTokenT > tpToken_; + std::vector > > > ttClustersTokens_; - edm::ESHandle theTrackerGeometry; - edm::ESHandle theTrackerTopology; + edm::ESHandle theTrackerGeometry_; + edm::ESHandle theTrackerTopology_; /// Mandatory methods void beginRun(const edm::Run& run, const edm::EventSetup& iSetup) override; @@ -81,14 +82,14 @@ class TTClusterAssociator : public edm::stream::EDProducer<> { /// Constructors template TTClusterAssociator::TTClusterAssociator(const edm::ParameterSet& iConfig) { - digisimLinkToken = + digisimLinkToken_ = consumes >(iConfig.getParameter("digiSimLinks")); - tpToken = consumes >(iConfig.getParameter("trackingParts")); + tpToken_ = consumes >(iConfig.getParameter("trackingParts")); - ttClustersInputTags = iConfig.getParameter >("TTClusters"); + ttClustersInputTags_ = iConfig.getParameter >("TTClusters"); - for (const auto& iTag : ttClustersInputTags) { - ttClustersTokens.push_back(consumes > >(iTag)); + for (const auto& iTag : ttClustersInputTags_) { + ttClustersTokens_.push_back(consumes > >(iTag)); produces >(iTag.instance()); } @@ -102,8 +103,8 @@ TTClusterAssociator::~TTClusterAssociator() {} template void TTClusterAssociator::beginRun(const edm::Run& run, const edm::EventSetup& iSetup) { /// Get the geometry - iSetup.get().get(theTrackerGeometry); - iSetup.get().get(theTrackerTopology); + iSetup.get().get(theTrackerGeometry_); + iSetup.get().get(theTrackerTopology_); /// Print some information when loaded edm::LogInfo("TTClusterAssociator< ") << templateNameFinder() << " > loaded."; diff --git a/SimTracker/TrackTriggerAssociation/plugins/TTStubAssociator.cc b/SimTracker/TrackTriggerAssociation/plugins/TTStubAssociator.cc index bc20438806b6f..a252f3c6e0c94 100644 --- a/SimTracker/TrackTriggerAssociation/plugins/TTStubAssociator.cc +++ b/SimTracker/TrackTriggerAssociation/plugins/TTStubAssociator.cc @@ -17,19 +17,19 @@ void TTStubAssociator::produce(edm::Event& iEvent, const return; /// Exit if the vectors are uncorrectly dimensioned - if (ttClusterTruthInputTags.size() != ttStubsInputTags.size()) { + if (ttClusterTruthInputTags_.size() != ttStubsInputTags_.size()) { edm::LogError("TTStubAsso ") << "E R R O R! the InputTag vectors have different size!"; return; } int ncont1 = 0; - const TrackerGeometry* const theTrackerGeom = theTrackerGeometry.product(); - const TrackerTopology* const tTopo = theTrackerTopology.product(); + const TrackerGeometry* const theTrackerGeom = theTrackerGeometry_.product(); + const TrackerTopology* const tTopo = theTrackerTopology_.product(); /// Loop over the InputTags to handle multiple collections - for (const auto& iTag : ttStubsTokens) { + for (const auto& iTag : ttStubsTokens_) { /// Prepare output auto associationMapForOutput = std::make_unique>(); @@ -39,13 +39,11 @@ void TTStubAssociator::produce(edm::Event& iEvent, const /// Get the Cluster MC truth edm::Handle> ttClusterAssociationMapHandle; - iEvent.getByToken(ttClusterTruthTokens.at(ncont1), ttClusterAssociationMapHandle); + iEvent.getByToken(ttClusterTruthTokens_.at(ncont1), ttClusterAssociationMapHandle); /// Prepare the necessary maps std::map stubToTrackingParticleMap; std::map> trackingParticleToStubVectorMap; - stubToTrackingParticleMap.clear(); - trackingParticleToStubVectorMap.clear(); /// Loop over the input Stubs @@ -72,7 +70,7 @@ void TTStubAssociator::produce(edm::Event& iEvent, const /// Fill the inclusive map which is careless of the stub classification for (unsigned int ic = 0; ic < 2; ic++) { - std::vector tempTPs = + const std::vector& tempTPs = ttClusterAssociationMapHandle->findTrackingParticlePtrs(tempStubRef->clusterRef(ic)); for (const TrackingParticlePtr& testTP : tempTPs) { @@ -82,8 +80,7 @@ void TTStubAssociator::produce(edm::Event& iEvent, const /// Prepare the maps wrt TrackingParticle if (trackingParticleToStubVectorMap.find(testTP) == trackingParticleToStubVectorMap.end()) { std::vector stubVector; - stubVector.clear(); - trackingParticleToStubVectorMap.insert(std::make_pair(testTP, stubVector)); + trackingParticleToStubVectorMap.emplace(testTP, stubVector); } trackingParticleToStubVectorMap.find(testTP)->second.push_back(tempStubRef); /// Fill the auxiliary map } @@ -110,12 +107,12 @@ void TTStubAssociator::produce(edm::Event& iEvent, const if (ttClusterAssociationMapHandle->findTrackingParticlePtr(tempStubRef->clusterRef(0)).get() == ttClusterAssociationMapHandle->findTrackingParticlePtr(tempStubRef->clusterRef(1)).get()) { /// Two genuine clusters with same SimTrack content mean genuine - TrackingParticlePtr testTP = + const TrackingParticlePtr& testTP = ttClusterAssociationMapHandle->findTrackingParticlePtr(tempStubRef->clusterRef(0)); /// Fill the map: by construction, this will always be the first time the /// stub is inserted into the map: no need for "find" - stubToTrackingParticleMap.insert(std::make_pair(tempStubRef, testTP)); + stubToTrackingParticleMap.emplace(tempStubRef, testTP); /// At this point, go to the next Stub continue; @@ -129,9 +126,9 @@ void TTStubAssociator::produce(edm::Event& iEvent, const TrackingParticle* prevTPAddress = nullptr; unsigned int whichTP = 0; - std::vector trackingParticles0 = + const std::vector& trackingParticles0 = ttClusterAssociationMapHandle->findTrackingParticlePtrs(tempStubRef->clusterRef(0)); - std::vector trackingParticles1 = + const std::vector& trackingParticles1 = ttClusterAssociationMapHandle->findTrackingParticlePtrs(tempStubRef->clusterRef(1)); bool escape = false; @@ -180,7 +177,7 @@ void TTStubAssociator::produce(edm::Event& iEvent, const /// Fill the map: by construction, this will always be the first time the /// stub is inserted into the map: no need for "find" - stubToTrackingParticleMap.insert(std::make_pair(tempStubRef, testTP)); + stubToTrackingParticleMap.emplace(tempStubRef, testTP); /// At this point, go to the next Stub continue; @@ -193,17 +190,13 @@ void TTStubAssociator::produce(edm::Event& iEvent, const /// Clean the only map that needs cleaning /// Prepare the output map wrt TrackingParticle - typename std::map>::iterator iterMapToClean; for (auto& p : trackingParticleToStubVectorMap) { /// Get the vector of references to TTStub - std::vector tempVector = p.second; + std::vector& tempVector = p.second; /// Sort and remove duplicates std::sort(tempVector.begin(), tempVector.end()); tempVector.erase(std::unique(tempVector.begin(), tempVector.end()), tempVector.end()); - - /// Put the vector in the output map - p.second = tempVector; } /// Also, create the pointer to the TTClusterAssociationMap @@ -215,7 +208,7 @@ void TTStubAssociator::produce(edm::Event& iEvent, const associationMapForOutput->setTTClusterAssociationMap(theCluAssoMap); /// Put output in the event - iEvent.put(std::move(associationMapForOutput), ttStubsInputTags.at(ncont1).instance()); + iEvent.put(std::move(associationMapForOutput), ttStubsInputTags_.at(ncont1).instance()); ++ncont1; } /// End of loop over InputTags diff --git a/SimTracker/TrackTriggerAssociation/plugins/TTStubAssociator.h b/SimTracker/TrackTriggerAssociation/plugins/TTStubAssociator.h index a905250116406..3fd21a8e37321 100644 --- a/SimTracker/TrackTriggerAssociation/plugins/TTStubAssociator.h +++ b/SimTracker/TrackTriggerAssociation/plugins/TTStubAssociator.h @@ -7,6 +7,7 @@ * * \author Nicola Pozzobon * \date 2013, Jul 19 + * (tidy up: Ian Tomalin, 2020) * */ @@ -53,14 +54,14 @@ class TTStubAssociator : public edm::stream::EDProducer<> { private: /// Data members - std::vector ttStubsInputTags; - std::vector ttClusterTruthInputTags; + std::vector ttStubsInputTags_; + std::vector ttClusterTruthInputTags_; - std::vector > > > ttStubsTokens; - std::vector > > ttClusterTruthTokens; + std::vector > > > ttStubsTokens_; + std::vector > > ttClusterTruthTokens_; - edm::ESHandle theTrackerGeometry; - edm::ESHandle theTrackerTopology; + edm::ESHandle theTrackerGeometry_; + edm::ESHandle theTrackerTopology_; /// Mandatory methods void beginRun(const edm::Run& run, const edm::EventSetup& iSetup) override; @@ -79,15 +80,15 @@ class TTStubAssociator : public edm::stream::EDProducer<> { /// Constructors template TTStubAssociator::TTStubAssociator(const edm::ParameterSet& iConfig) { - ttStubsInputTags = iConfig.getParameter >("TTStubs"); - ttClusterTruthInputTags = iConfig.getParameter >("TTClusterTruth"); + ttStubsInputTags_ = iConfig.getParameter >("TTStubs"); + ttClusterTruthInputTags_ = iConfig.getParameter >("TTClusterTruth"); - for (const auto& iTag : ttClusterTruthInputTags) { - ttClusterTruthTokens.push_back(consumes >(iTag)); + for (const auto& iTag : ttClusterTruthInputTags_) { + ttClusterTruthTokens_.push_back(consumes >(iTag)); } - for (const auto& iTag : ttStubsInputTags) { - ttStubsTokens.push_back(consumes > >(iTag)); + for (const auto& iTag : ttStubsInputTags_) { + ttStubsTokens_.push_back(consumes > >(iTag)); produces >(iTag.instance()); } @@ -103,8 +104,8 @@ void TTStubAssociator::beginRun(const edm::Run& run, const edm::EventSetup& i /// Print some information when loaded edm::LogInfo("TTStubAssociator< ") << templateNameFinder() << " > loaded."; - iSetup.get().get(theTrackerTopology); - iSetup.get().get(theTrackerGeometry); + iSetup.get().get(theTrackerTopology_); + iSetup.get().get(theTrackerGeometry_); } /// End run diff --git a/SimTracker/TrackTriggerAssociation/plugins/TTTrackAssociator.cc b/SimTracker/TrackTriggerAssociation/plugins/TTTrackAssociator.cc index 17a550c39acb6..24e19cc5e7f66 100644 --- a/SimTracker/TrackTriggerAssociation/plugins/TTTrackAssociator.cc +++ b/SimTracker/TrackTriggerAssociation/plugins/TTTrackAssociator.cc @@ -18,14 +18,14 @@ void TTTrackAssociator::produce(edm::Event& iEvent, cons /// Get the Stub and Cluster MC truth edm::Handle> ttClusterAssociationMapHandle; - iEvent.getByToken(ttClusterTruthToken, ttClusterAssociationMapHandle); + iEvent.getByToken(ttClusterTruthToken_, ttClusterAssociationMapHandle); edm::Handle> ttStubAssociationMapHandle; - iEvent.getByToken(ttStubTruthToken, ttStubAssociationMapHandle); + iEvent.getByToken(ttStubTruthToken_, ttStubAssociationMapHandle); int ncont1 = 0; /// Loop over InputTags to handle multiple collections - for (const auto& iTag : ttTracksTokens) { + for (const auto& iTag : ttTracksTokens_) { /// Prepare output auto associationMapForOutput = std::make_unique>(); @@ -36,8 +36,6 @@ void TTTrackAssociator::produce(edm::Event& iEvent, cons /// Prepare the necessary maps std::map trackToTrackingParticleMap; std::map> trackingParticleToTrackVectorMap; - trackToTrackingParticleMap.clear(); - trackingParticleToTrackVectorMap.clear(); // Start the loop on tracks @@ -46,11 +44,10 @@ void TTTrackAssociator::produce(edm::Event& iEvent, cons TTTrackPtr tempTrackPtr(TTTrackHandle, jTrk); /// Get all the stubs of the TTTrack (theseStubs) - std::vector theseStubs = tempTrackPtr->getStubRefs(); + const std::vector& theseStubs = tempTrackPtr->getStubRefs(); /// Auxiliary map to relate TP addresses and TP edm::Ptr std::map auxMap; - auxMap.clear(); int mayCombinUnknown = 0; /// Fill the map associating each TP to a vector of L1 tracks. @@ -58,7 +55,7 @@ void TTTrackAssociator::produce(edm::Event& iEvent, cons /// as stub associator misses stub --> all TP map (FIX). for (const TTStubRef& stub : theseStubs) { for (unsigned int ic = 0; ic < 2; ic++) { - std::vector tempTPs = + const std::vector& tempTPs = ttClusterAssociationMapHandle->findTrackingParticlePtrs(stub->clusterRef(ic)); for (const TrackingParticlePtr& testTP : tempTPs) // List of TPs linked to stub clusters { @@ -68,14 +65,13 @@ void TTTrackAssociator::produce(edm::Event& iEvent, cons /// Prepare the maps wrt TrackingParticle if (trackingParticleToTrackVectorMap.find(testTP) == trackingParticleToTrackVectorMap.end()) { std::vector trackVector; - trackVector.clear(); - trackingParticleToTrackVectorMap.insert(std::make_pair(testTP, trackVector)); + trackingParticleToTrackVectorMap.emplace(testTP, trackVector); } trackingParticleToTrackVectorMap.find(testTP)->second.push_back(tempTrackPtr); /// Fill the auxiliary map /// Fill the other auxiliary map if (auxMap.find(testTP.get()) == auxMap.end()) { - auxMap.insert(std::make_pair(testTP.get(), testTP)); + auxMap.emplace(testTP.get(), testTP); } } } /// End of loop over the clusters @@ -101,7 +97,7 @@ void TTTrackAssociator::produce(edm::Event& iEvent, cons for (const auto& auxPair : auxMap) { /// Get all associated stubs of this TrackingParticle - std::vector tempStubs = ttStubAssociationMapHandle->findTTStubRefs(auxPair.second); + const std::vector& tempStubs = ttStubAssociationMapHandle->findTTStubRefs(auxPair.second); // Count stubs on track that are not related to this TP int nnotfound = 0; @@ -144,7 +140,7 @@ void TTTrackAssociator::produce(edm::Event& iEvent, cons /// Here, the track may only be GENUINE/LOOSELY_GENUINE /// CHECK: Surely if one incorrect PS stub, it can also be COMBINATORIC? /// Fill the map associating track to its principle TP. - trackToTrackingParticleMap.insert(std::make_pair(tempTrackPtr, auxMap.find(tpInAllStubs.at(0))->second)); + trackToTrackingParticleMap.emplace(tempTrackPtr, auxMap.find(tpInAllStubs.at(0))->second); } /// End of loop over Tracks @@ -153,13 +149,11 @@ void TTTrackAssociator::produce(edm::Event& iEvent, cons for (auto& p : trackingParticleToTrackVectorMap) { /// Get the vector of edm::Ptr< TTTrack > /// (CHECK: Couldn't this be done by reference, to save CPU?) - std::vector tempVector = p.second; + std::vector& tempVector = p.second; /// Sort and remove duplicates std::sort(tempVector.begin(), tempVector.end()); tempVector.erase(std::unique(tempVector.begin(), tempVector.end()), tempVector.end()); - - p.second = tempVector; } /// Also, create the pointer to the TTClusterAssociationMap @@ -172,7 +166,7 @@ void TTTrackAssociator::produce(edm::Event& iEvent, cons associationMapForOutput->setAllowOneFalse2SStub(TTTrackAllowOneFalse2SStub); /// Put output in the event - iEvent.put(std::move(associationMapForOutput), ttTracksInputTags.at(ncont1).instance()); + iEvent.put(std::move(associationMapForOutput), ttTracksInputTags_.at(ncont1).instance()); ++ncont1; } /// End of loop over InputTags diff --git a/SimTracker/TrackTriggerAssociation/plugins/TTTrackAssociator.h b/SimTracker/TrackTriggerAssociation/plugins/TTTrackAssociator.h index 65c7d6a2f8f47..a936057ae03c6 100644 --- a/SimTracker/TrackTriggerAssociation/plugins/TTTrackAssociator.h +++ b/SimTracker/TrackTriggerAssociation/plugins/TTTrackAssociator.h @@ -7,6 +7,7 @@ * * \author Nicola Pozzobon * \date 2013, Jul 19 + * (tidy up: Ian Tomalin, 2020) * */ @@ -49,12 +50,11 @@ class TTTrackAssociator : public edm::stream::EDProducer<> { private: /// Data members - std::vector ttTracksInputTags; + std::vector ttTracksInputTags_; - std::vector > > > ttTracksTokens; - - edm::EDGetTokenT > ttStubTruthToken; - edm::EDGetTokenT > ttClusterTruthToken; + std::vector > > > ttTracksTokens_; + edm::EDGetTokenT > ttStubTruthToken_; + edm::EDGetTokenT > ttClusterTruthToken_; bool TTTrackAllowOneFalse2SStub; @@ -75,9 +75,9 @@ class TTTrackAssociator : public edm::stream::EDProducer<> { /// Constructors template TTTrackAssociator::TTTrackAssociator(const edm::ParameterSet& iConfig) { - ttTracksInputTags = iConfig.getParameter >("TTTracks"); - ttClusterTruthToken = consumes >(iConfig.getParameter("TTClusterTruth")); - ttStubTruthToken = consumes >(iConfig.getParameter("TTStubTruth")); + ttTracksInputTags_ = iConfig.getParameter >("TTTracks"); + ttClusterTruthToken_ = consumes >(iConfig.getParameter("TTClusterTruth")); + ttStubTruthToken_ = consumes >(iConfig.getParameter("TTStubTruth")); TTTrackAllowOneFalse2SStub = iConfig.getParameter("TTTrackAllowOneFalse2SStub"); if (TTTrackAllowOneFalse2SStub) { edm::LogInfo("TTTrackAssociator< ") << "Allow track if no more than one 2S stub doesn't match truth."; @@ -85,8 +85,8 @@ TTTrackAssociator::TTTrackAssociator(const edm::ParameterSet& iConfig) { edm::LogInfo("TTTrackAssociator< ") << "All 2S stubs must match truth."; } - for (const auto& iTag : ttTracksInputTags) { - ttTracksTokens.push_back(consumes > >(iTag)); + for (const auto& iTag : ttTracksInputTags_) { + ttTracksTokens_.push_back(consumes > >(iTag)); produces >(iTag.instance()); } diff --git a/SimTracker/TrackTriggerAssociation/src/TTTrackAssociationMap.cc b/SimTracker/TrackTriggerAssociation/src/TTTrackAssociationMap.cc index a9ce8d39b180c..a45b976cba5d6 100644 --- a/SimTracker/TrackTriggerAssociation/src/TTTrackAssociationMap.cc +++ b/SimTracker/TrackTriggerAssociation/src/TTTrackAssociationMap.cc @@ -9,27 +9,22 @@ /// Operations template <> -TrackingParticlePtr TTTrackAssociationMap::findTrackingParticlePtr(TTTrackPtr aTrack) const { - if (trackToTrackingParticleMap.find(aTrack) != trackToTrackingParticleMap.end()) { - return trackToTrackingParticleMap.find(aTrack)->second; +const TrackingParticlePtr& TTTrackAssociationMap::findTrackingParticlePtr(TTTrackPtr aTrack) const { + if (trackToTrackingParticleMap_.find(aTrack) != trackToTrackingParticleMap_.end()) { + return trackToTrackingParticleMap_.find(aTrack)->second; + } else { + return nullTrackingParticlePtr_; } - - /// Default: return NULL - TrackingParticlePtr* temp = new TrackingParticlePtr(); - return *temp; } template <> -std::vector TTTrackAssociationMap::findTTTrackPtrs( +const std::vector& TTTrackAssociationMap::findTTTrackPtrs( TrackingParticlePtr aTrackingParticle) const { - if (trackingParticleToTrackVectorMap.find(aTrackingParticle) != trackingParticleToTrackVectorMap.end()) { - return trackingParticleToTrackVectorMap.find(aTrackingParticle)->second; + if (trackingParticleToTrackVectorMap_.find(aTrackingParticle) != trackingParticleToTrackVectorMap_.end()) { + return trackingParticleToTrackVectorMap_.find(aTrackingParticle)->second; + } else { + return nullVecTTTrackPtr_; } - - /// Default: return empty vector - std::vector tempVec; - tempVec.clear(); - return tempVec; } /// MC truth @@ -50,8 +45,8 @@ bool TTTrackAssociationMap::isGenuine(TTTrackPtr aTrack) return false; /// Get all the stubs from this track & associated TrackingParticle - std::vector TRK_Stubs = aTrack->getStubRefs(); - std::vector TP_Stubs = theStubAssociationMap->findTTStubRefs(this->findTrackingParticlePtr(aTrack)); + const std::vector& TRK_Stubs = aTrack->getStubRefs(); + const std::vector& TP_Stubs = theStubAssociationMap_->findTTStubRefs(this->findTrackingParticlePtr(aTrack)); bool one2SStub = false; for (unsigned int js = 0; js < TRK_Stubs.size(); js++) { @@ -90,9 +85,9 @@ bool TTTrackAssociationMap::isUnknown(TTTrackPtr aTrack) /// UNKNOWN means that >= 2 stubs are unknown int unknownstubs = 0; - std::vector theseStubs = aTrack->getStubRefs(); + const std::vector& theseStubs = aTrack->getStubRefs(); for (unsigned int i = 0; i < theseStubs.size(); i++) { - if (theStubAssociationMap->isUnknown(theseStubs.at(i)) == false) { + if (theStubAssociationMap_->isUnknown(theseStubs.at(i)) == false) { ++unknownstubs; if (unknownstubs >= 2) return false; From c86ecdde9551808801716a129d1853bdae6555cd Mon Sep 17 00:00:00 2001 From: Ian Tomalin Date: Thu, 24 Dec 2020 18:00:40 +0000 Subject: [PATCH 6/6] code formatting --- .../interface/TTClusterAssociationMap.h | 5 ++--- .../interface/TTStubAssociationMap.h | 2 -- .../interface/TTTrackAssociationMap.h | 3 ++- .../TrackTriggerAssociation/plugins/TTClusterAssociator.cc | 2 +- .../TrackTriggerAssociation/src/TTTrackAssociationMap.cc | 6 ++++-- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/SimTracker/TrackTriggerAssociation/interface/TTClusterAssociationMap.h b/SimTracker/TrackTriggerAssociation/interface/TTClusterAssociationMap.h index 0431889b29853..698225829a3bc 100644 --- a/SimTracker/TrackTriggerAssociation/interface/TTClusterAssociationMap.h +++ b/SimTracker/TrackTriggerAssociation/interface/TTClusterAssociationMap.h @@ -92,7 +92,6 @@ class TTClusterAssociationMap { }; /// Close class - /*! \brief Implementation of methods * \details Here, in the header file, the methods which do not depend * on the specific type that can fit the template. @@ -100,7 +99,6 @@ class TTClusterAssociationMap { * in the source file. */ - // Static constant data members. template const TrackingParticlePtr TTClusterAssociationMap::nullTrackingParticlePtr_; @@ -133,7 +131,8 @@ const std::vector>& TTClusterAssociationMap::findTTClusterRe } template -const std::vector& TTClusterAssociationMap::findTrackingParticlePtrs(TTClusterRefT aCluster) const { +const std::vector& TTClusterAssociationMap::findTrackingParticlePtrs( + TTClusterRefT aCluster) const { if (clusterToTrackingParticleVectorMap_.find(aCluster) != clusterToTrackingParticleVectorMap_.end()) { return clusterToTrackingParticleVectorMap_.find(aCluster)->second; } else { diff --git a/SimTracker/TrackTriggerAssociation/interface/TTStubAssociationMap.h b/SimTracker/TrackTriggerAssociation/interface/TTStubAssociationMap.h index 41cfeb1b98d4a..33ffe9daf46e9 100644 --- a/SimTracker/TrackTriggerAssociation/interface/TTStubAssociationMap.h +++ b/SimTracker/TrackTriggerAssociation/interface/TTStubAssociationMap.h @@ -110,7 +110,6 @@ class TTStubAssociationMap { }; /// Close class - /*! \brief Implementation of methods * \details Here, in the header file, the methods which do not depend * on the specific type that can fit the template. @@ -118,7 +117,6 @@ class TTStubAssociationMap { * in the source file. */ - // Static constant data members. template const TrackingParticlePtr TTStubAssociationMap::nullTrackingParticlePtr_; diff --git a/SimTracker/TrackTriggerAssociation/interface/TTTrackAssociationMap.h b/SimTracker/TrackTriggerAssociation/interface/TTTrackAssociationMap.h index a819518eedbb1..f4bb61bc78bb5 100644 --- a/SimTracker/TrackTriggerAssociation/interface/TTTrackAssociationMap.h +++ b/SimTracker/TrackTriggerAssociation/interface/TTTrackAssociationMap.h @@ -137,7 +137,8 @@ TTTrackAssociationMap::~TTTrackAssociationMap() {} /// Operations template <> -const TrackingParticlePtr& TTTrackAssociationMap::findTrackingParticlePtr(TTTrackPtr aTrack) const; +const TrackingParticlePtr& TTTrackAssociationMap::findTrackingParticlePtr( + TTTrackPtr aTrack) const; template <> const std::vector& TTTrackAssociationMap::findTTTrackPtrs( diff --git a/SimTracker/TrackTriggerAssociation/plugins/TTClusterAssociator.cc b/SimTracker/TrackTriggerAssociation/plugins/TTClusterAssociator.cc index 6df9b308ea9c4..82bc5cae2dc20 100644 --- a/SimTracker/TrackTriggerAssociation/plugins/TTClusterAssociator.cc +++ b/SimTracker/TrackTriggerAssociation/plugins/TTClusterAssociator.cc @@ -98,7 +98,7 @@ void TTClusterAssociator::produce(edm::Event& iEvent, co /// No SimLink is found by definition /// Then store NULL MC truth for all the digis TrackingParticlePtr tempTPPtr; - clusterToTrackingParticleVectorMap.find(tempCluRef)->second.push_back(tempTPPtr); + clusterToTrackingParticleVectorMap.find(tempCluRef)->second.push_back(tempTPPtr); } /// Go to the next sensor diff --git a/SimTracker/TrackTriggerAssociation/src/TTTrackAssociationMap.cc b/SimTracker/TrackTriggerAssociation/src/TTTrackAssociationMap.cc index a45b976cba5d6..0b1595a209d7b 100644 --- a/SimTracker/TrackTriggerAssociation/src/TTTrackAssociationMap.cc +++ b/SimTracker/TrackTriggerAssociation/src/TTTrackAssociationMap.cc @@ -9,7 +9,8 @@ /// Operations template <> -const TrackingParticlePtr& TTTrackAssociationMap::findTrackingParticlePtr(TTTrackPtr aTrack) const { +const TrackingParticlePtr& TTTrackAssociationMap::findTrackingParticlePtr( + TTTrackPtr aTrack) const { if (trackToTrackingParticleMap_.find(aTrack) != trackToTrackingParticleMap_.end()) { return trackToTrackingParticleMap_.find(aTrack)->second; } else { @@ -46,7 +47,8 @@ bool TTTrackAssociationMap::isGenuine(TTTrackPtr aTrack) /// Get all the stubs from this track & associated TrackingParticle const std::vector& TRK_Stubs = aTrack->getStubRefs(); - const std::vector& TP_Stubs = theStubAssociationMap_->findTTStubRefs(this->findTrackingParticlePtr(aTrack)); + const std::vector& TP_Stubs = + theStubAssociationMap_->findTTStubRefs(this->findTrackingParticlePtr(aTrack)); bool one2SStub = false; for (unsigned int js = 0; js < TRK_Stubs.size(); js++) {