Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 23:31:28

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