Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-04-01 23:54:10

0001 #ifndef __L1Trigger_VertexFinder_RecoVertex_h__
0002 #define __L1Trigger_VertexFinder_RecoVertex_h__
0003 
0004 #include "DataFormats/L1Trigger/interface/Vertex.h"
0005 #include "L1Trigger/VertexFinder/interface/L1TrackTruthMatched.h"
0006 #include "L1Trigger/VertexFinder/interface/TP.h"
0007 
0008 #include <numeric>
0009 #include <set>
0010 #include <vector>
0011 
0012 namespace l1tVertexFinder {
0013 
0014   template <typename T = L1Track>
0015   class RecoVertex {
0016   public:
0017     /// Basic constructor
0018     RecoVertex(const double z0 = -999.);
0019     /// Conversion from RecoVertex<L1Track> RecoVertex<T>
0020     RecoVertex(RecoVertex<L1Track>& vertex,
0021                std::map<const edm::Ptr<TTTrack<Ref_Phase2TrackerDigi_>>, const T*> trackAssociationMap);
0022     /// Conversion from l1t::Vertex to l1tVertexFinder::RecoVertex
0023     RecoVertex(const l1t::Vertex& vertex,
0024                std::map<const edm::Ptr<TTTrack<Ref_Phase2TrackerDigi_>>, const T*> trackAssociationMap);
0025     /// Basic destructor
0026     ~RecoVertex() {}
0027 
0028     /// Operators
0029     RecoVertex& operator+=(const RecoVertex& rhs) {
0030       this->tracks_.insert(std::end(this->tracks_), std::begin(rhs.tracks()), std::end(rhs.tracks()));
0031       return *this;
0032     }
0033 
0034     /// Clear track vector
0035     void clear() { tracks_.clear(); }
0036     /// Compute vertex parameters
0037     //void computeParameters(unsigned int weightedmean = false, double highPtThreshold = 50., int highPtBehavior = -1);
0038     /// Contain high-pT track?
0039     bool hasHighPt() const { return highPt_; }
0040     /// highest track pT in the vertex
0041     double highestPt() const { return highestPt_; }
0042     /// Assign fitted track to this vertex
0043     void insert(const T* fitTrack) { tracks_.push_back(fitTrack); }
0044     /// Set primary vertex tag
0045     void isPrimary(bool is) { pv_ = is; }
0046     /// Number of high-pT tracks (pT > 10 GeV)
0047     unsigned int numHighPtTracks() const { return numHighPtTracks_; }
0048     /// Number of tracks originating from this vertex
0049     unsigned int numTracks() const { return tracks_.size(); }
0050     /// Number of true particles assigned to this vertex
0051     unsigned int numTrueTracks() const { return trueTracks_.size(); }
0052     /// True if primary vertex
0053     bool primaryVertex() const { return pv_; }
0054     /// Sum of fitted tracks transverse momentum [GeV]
0055     double pt() const { return pT_; }
0056     /// Tracks in the vertex
0057     const std::vector<const T*>& tracks() const { return tracks_; }
0058     /// Tracking particles asociated to the vertex
0059     const std::set<const TP*>& trueTracks() const { return trueTracks_; }
0060     /// set the pT [GeV] of the vertex
0061     void setPt(double pt) { pT_ = pt; }
0062     /// Set z0 position [cm]
0063     void setZ0(double z) { z0_ = z; }
0064     /// Set the vertex parameters
0065     void setParameters(double pt,
0066                        double z0,
0067                        double width = -999.,
0068                        bool highPt = false,
0069                        unsigned int nHighPt = -999,
0070                        double highestPt = -999.,
0071                        bool pv = false);
0072     /// Get the equivalent l1t::Vertex
0073     l1t::Vertex vertex() const;
0074     /// Vertex z0 position [cm]
0075     double z0() const { return z0_; }
0076     /// Vertex z0 width [cm]
0077     double z0width() const { return z0width_; }
0078 
0079   private:
0080     double z0_;
0081     double z0width_;
0082     double pT_;
0083     double highestPt_;
0084     std::vector<const T*> tracks_;
0085     std::set<const TP*> trueTracks_;
0086     bool pv_;
0087     bool highPt_;
0088     unsigned int numHighPtTracks_;
0089   };
0090 
0091   using RecoVertexWithTP = RecoVertex<L1TrackTruthMatched>;
0092 
0093   template <typename T>
0094   RecoVertex<T>::RecoVertex(const double z0) : z0_(z0) {
0095     z0width_ = -999.;
0096     pT_ = -999.;
0097     highestPt_ = -999.;
0098     pv_ = false;
0099     highPt_ = false;
0100     numHighPtTracks_ = 0;
0101     clear();
0102   }
0103 
0104   template <typename T>
0105   RecoVertex<T>::RecoVertex(RecoVertex<L1Track>& vertex,
0106                             std::map<const edm::Ptr<TTTrack<Ref_Phase2TrackerDigi_>>, const T*> trackAssociationMap) {
0107     z0_ = vertex.z0();
0108     z0width_ = vertex.z0width();
0109     pT_ = vertex.pt();
0110     highestPt_ = vertex.highestPt();
0111     pv_ = vertex.primaryVertex();
0112     highPt_ = vertex.hasHighPt();
0113     numHighPtTracks_ = vertex.numHighPtTracks();
0114     clear();
0115 
0116     // loop over base fitted tracks in reco vertex and find the corresponding TP
0117     // track using the TTTrack - L1TrackTruthMatched map from above
0118     for (const auto& trackIt : vertex.tracks()) {
0119       // using insert ensures that true tracks are also stored in vertex object
0120       insert(trackAssociationMap[trackIt->getTTTrackPtr()]);
0121     }
0122   }
0123 
0124   template <typename T>
0125   RecoVertex<T>::RecoVertex(const l1t::Vertex& vertex,
0126                             std::map<const edm::Ptr<TTTrack<Ref_Phase2TrackerDigi_>>, const T*> trackAssociationMap) {
0127     z0_ = vertex.z0();
0128     z0width_ = -999.;
0129     pT_ = vertex.pt();
0130     highestPt_ = -999.;
0131     pv_ = false;
0132     highPt_ = false;
0133     numHighPtTracks_ = 0;
0134     clear();
0135 
0136     // populate vertex with tracks and TP track using the
0137     // TTTrack - L1TrackTruthMatched map from above
0138     for (const auto& track : vertex.tracks()) {
0139       // using insert ensures that true tracks are also stored in vertex object
0140       insert(trackAssociationMap.at(track));
0141     }
0142   }
0143 
0144   template <typename T>
0145   void RecoVertex<T>::setParameters(
0146       double pt, double z0, double width, bool highPt, unsigned int nHighPt, double highestPt, bool pv) {
0147     pT_ = pt;
0148     z0_ = z0;
0149     z0width_ = width;
0150     highPt_ = highPt;
0151     numHighPtTracks_ = nHighPt;
0152     highestPt_ = highestPt;
0153     pv_ = pv;
0154   }
0155 
0156   template <typename T>
0157   l1t::Vertex RecoVertex<T>::vertex() const {
0158     std::vector<edm::Ptr<l1t::Vertex::Track_t>> tracks;
0159     tracks.reserve(tracks_.size());
0160     for (const auto& t : tracks_) {
0161       tracks.push_back(t->getTTTrackPtr());
0162     }
0163     return l1t::Vertex(pT_, z0_, tracks);
0164   }
0165 
0166   // Template specializations
0167   template <>
0168   RecoVertexWithTP& RecoVertexWithTP::operator+=(const RecoVertexWithTP& rhs);
0169 
0170   template <>
0171   void RecoVertexWithTP::clear();
0172 
0173   template <>
0174   void RecoVertexWithTP::insert(const L1TrackTruthMatched* fitTrack);
0175 
0176 }  // namespace l1tVertexFinder
0177 
0178 #endif