Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-08-09 23:47:42

0001 /*! \class   TTStubAssociationMap
0002  *  \brief   Stores association of Truth Particles (TP) to L1 Track-Trigger Stubs
0003  *
0004  *  \details Contains two maps. One associates each stub to its principle TP.
0005  *           (i.e. Not to all TP that contributed to it). 
0006  *           The other associates each TP to a vector of all stubs 
0007  *           it contributed to. The two maps are therefore not
0008  *           forward-backward symmetric.
0009  *
0010  *           (The template structure is used to accomodate types
0011  *           other than PixelDigis, in case they are needed in future). 
0012  *
0013  *  \author Nicola Pozzobon
0014  *  \date   2013, Jul 19
0015  *  (tidy up: Ian Tomalin, 2020)
0016  */
0017 
0018 #ifndef SimDataFormats_Associations_TTStubAssociationMap_h
0019 #define SimDataFormats_Associations_TTStubAssociationMap_h
0020 
0021 #include "DataFormats/Common/interface/Ref.h"
0022 #include "DataFormats/Common/interface/RefProd.h"
0023 #include "DataFormats/Common/interface/Ptr.h"
0024 #include "DataFormats/L1TrackTrigger/interface/TTTypes.h"
0025 #include "SimDataFormats/TrackingAnalysis/interface/TrackingParticleFwd.h"
0026 #include "DataFormats/Common/interface/DetSet.h"
0027 #include "DataFormats/Common/interface/DetSetVector.h"
0028 #include "DataFormats/Common/interface/DetSetVectorNew.h"
0029 #include "DataFormats/DetId/interface/DetId.h"
0030 #include "DataFormats/Phase2TrackerDigi/interface/Phase2TrackerDigi.h"
0031 #include "DataFormats/GeometryCommonDetAlgo/interface/MeasurementPoint.h"
0032 #include "DataFormats/GeometryVector/interface/GlobalPoint.h"  /// NOTE: this is needed even if it seems not
0033 #include "DataFormats/L1TrackTrigger/interface/TTStub.h"
0034 #include "SimDataFormats/Track/interface/SimTrack.h"
0035 #include "SimDataFormats/Track/interface/SimTrackContainer.h"
0036 #include "SimDataFormats/EncodedEventId/interface/EncodedEventId.h"
0037 #include "SimDataFormats/TrackingAnalysis/interface/TrackingParticle.h"
0038 #include "SimDataFormats/Associations/interface/TTClusterAssociationMap.h"
0039 
0040 // Templated aliases
0041 template <typename T>
0042 using MapStubToTP = std::map<TTStubRefT<T>, TrackingParticlePtr>;
0043 template <typename T>
0044 using MapTPToVecStub = std::map<TrackingParticlePtr, std::vector<TTStubRefT<T>>>;
0045 
0046 template <typename T>
0047 class TTStubAssociationMap {
0048 public:
0049   /// Constructors
0050   TTStubAssociationMap();
0051 
0052   /// Destructor
0053   ~TTStubAssociationMap();
0054 
0055   /// Get/set stub <-> truth association maps
0056 
0057   const MapStubToTP<T>& getTTStubToTrackingParticleMap() const { return stubToTrackingParticleMap_; }
0058   const MapTPToVecStub<T>& getTrackingParticleToTTStubsMap() const { return trackingParticleToStubVectorMap_; }
0059 
0060   void setTTStubToTrackingParticleMap(const MapStubToTP<T>& aMap) { stubToTrackingParticleMap_ = aMap; }
0061   void setTrackingParticleToTTStubsMap(const MapTPToVecStub<T>& aMap) { trackingParticleToStubVectorMap_ = aMap; }
0062 
0063   /// Set cluster <-> truth association object.
0064   void setTTClusterAssociationMap(edm::RefProd<TTClusterAssociationMap<T>> aCluAssoMap) {
0065     theClusterAssociationMap_ = aCluAssoMap;
0066   }
0067 
0068   /// Get principle TP associated to a stub. (Non-NULL if isGenuine() below is true).
0069   /// (N.B. There is no function returning all TP associated to a stub).
0070   /// (P.S. As this function only returns principle TP, it is not used when constructing
0071   ///  the TTTrackAssociationMap).
0072   const TrackingParticlePtr& findTrackingParticlePtr(TTStubRefT<T> aStub) const;
0073 
0074   /// Get all stubs associated to a TP.
0075   /// (Even if the TP just contributes to one cluster in stub,
0076   /// and even if their are other such TP, it is still listed here).
0077   const std::vector<TTStubRefT<T>>& findTTStubRefs(TrackingParticlePtr aTrackingParticle) const;
0078 
0079   ///--- Get quality of stub based on truth info.
0080   /// (N.B. Both genuine & combinatoric stubs contribute to "genuine" L1 tracks
0081   ///  associated by TTTrackAssociationMap).
0082   /// (exactly 1 of following 3 functions is always true)
0083 
0084   /// If both clusters are unknown, the stub is "unknown".
0085   /// If only one cluster is unknown, the stub is combinatoric.
0086   /// If both clusters are genuine, and are associated to the same (main) TrackingParticle,
0087   /// the stub is "genuine".
0088   /// If both clusters are genuine, but are associated to different (main) TrackingParticles,
0089   /// the stub is "combinatoric".
0090   /// If one cluster is combinatoric and the other is genuine/combinatoric, and they both share exactly
0091   /// one TrackingParticle in common, then the stub is "genuine". (The clusters can have other
0092   /// TrackingParticles besides the shared one, as long as these are not shared). If instead the clusters
0093   /// share 0 or ≥2 TrackingParticles in common, then the stub is "combinatoric".
0094 
0095   bool isGenuine(TTStubRefT<T> aStub) const;
0096   bool isCombinatoric(TTStubRefT<T> aStub) const;
0097   bool isUnknown(TTStubRefT<T> aStub) const;
0098 
0099 private:
0100   /// Data members
0101   MapStubToTP<T> stubToTrackingParticleMap_;
0102   MapTPToVecStub<T> trackingParticleToStubVectorMap_;
0103   edm::RefProd<TTClusterAssociationMap<T>> theClusterAssociationMap_;
0104 
0105   // Allow functions to return reference to null.
0106   static const TrackingParticlePtr nullTrackingParticlePtr_;
0107   static const std::vector<TTStubRefT<T>> nullVecStubRef_;
0108 
0109 };  /// Close class
0110 
0111 /*! \brief   Implementation of methods
0112  *  \details Here, in the header file, the methods which do not depend
0113  *           on the specific type <T> that can fit the template.
0114  *           Other methods, with type-specific features, are implemented
0115  *           in the source file.
0116  */
0117 
0118 // Static constant data members.
0119 template <typename T>
0120 const TrackingParticlePtr TTStubAssociationMap<T>::nullTrackingParticlePtr_;
0121 template <typename T>
0122 const std::vector<TTStubRefT<T>> TTStubAssociationMap<T>::nullVecStubRef_;
0123 
0124 /// Default Constructor
0125 /// NOTE: to be used with setSomething(...) methods
0126 template <typename T>
0127 TTStubAssociationMap<T>::TTStubAssociationMap() {
0128   /// Set default data members
0129 }
0130 
0131 /// Destructor
0132 template <typename T>
0133 TTStubAssociationMap<T>::~TTStubAssociationMap() {}
0134 
0135 /// Operations
0136 template <typename T>
0137 const TrackingParticlePtr& TTStubAssociationMap<T>::findTrackingParticlePtr(TTStubRefT<T> aStub) const {
0138   if (stubToTrackingParticleMap_.find(aStub) != stubToTrackingParticleMap_.end()) {
0139     return stubToTrackingParticleMap_.find(aStub)->second;
0140   } else {
0141     return nullTrackingParticlePtr_;
0142   }
0143 }
0144 
0145 template <typename T>
0146 const std::vector<TTStubRefT<T>>& TTStubAssociationMap<T>::findTTStubRefs(TrackingParticlePtr aTrackingParticle) const {
0147   if (trackingParticleToStubVectorMap_.find(aTrackingParticle) != trackingParticleToStubVectorMap_.end()) {
0148     return trackingParticleToStubVectorMap_.find(aTrackingParticle)->second;
0149   } else {
0150     return nullVecStubRef_;
0151   }
0152 }
0153 
0154 /// MC truth
0155 template <typename T>
0156 bool TTStubAssociationMap<T>::isGenuine(TTStubRefT<T> aStub) const {
0157   /// Check if there is a SimTrack
0158   if ((this->findTrackingParticlePtr(aStub)).isNull())
0159     return false;
0160 
0161   return true;
0162 }
0163 
0164 template <typename T>
0165 bool TTStubAssociationMap<T>::isCombinatoric(TTStubRefT<T> aStub) const {
0166   /// Defined by exclusion
0167   if (this->isGenuine(aStub))
0168     return false;
0169 
0170   if (this->isUnknown(aStub))
0171     return false;
0172 
0173   return true;
0174 }
0175 
0176 template <typename T>
0177 bool TTStubAssociationMap<T>::isUnknown(TTStubRefT<T> aStub) const {
0178   /// UNKNOWN means that both clusters are unknown
0179 
0180   /// Sanity check
0181   if (theClusterAssociationMap_.isNull()) {
0182     return true;
0183   }
0184 
0185   if (theClusterAssociationMap_->isUnknown(aStub->clusterRef(0)) &&
0186       theClusterAssociationMap_->isUnknown(aStub->clusterRef(1)))
0187     return true;
0188 
0189   return false;
0190 }
0191 
0192 #endif