Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-03-17 10:51:34

0001 #ifndef DataFormats_TrackReco_TrackExtraBase_h
0002 #define DataFormats_TrackReco_TrackExtraBase_h
0003 
0004 /** \class reco::TrackExtraBase TrackExtraBase.h DataFormats/TrackReco/interface/TrackExtraBase.h
0005  *
0006  * Basic extension of a reconstructed Track.
0007  * Contains references to the hits assigned to the track.
0008  *
0009  * If you access the hits, check if they are valid or not. (Invalid hits are dummy hits
0010  * created in layers crossed by the track, where no physical hit was found).
0011  *
0012  * \author Luca Lista, INFN
0013  *
0014  *
0015  */
0016 
0017 #include "DataFormats/TrackingRecHit/interface/TrackingRecHitFwd.h"
0018 #include "DataFormats/TrajectoryState/interface/LocalTrajectoryParameters.h"
0019 
0020 namespace reco {
0021 
0022   class TrackExtraBase {
0023   public:
0024     using TrajParams = std::vector<LocalTrajectoryParameters>;
0025     using Chi2sFive = std::vector<unsigned char>;
0026 
0027     /// default constructor
0028     TrackExtraBase() : m_firstHit((unsigned int)-1), m_nHits(0) {}
0029 
0030     void setHits(TrackingRecHitRefProd const& prod, unsigned firstH, unsigned int nH) {
0031       m_hitCollection.pushBackItem(prod.refCore(), true);
0032       m_firstHit = firstH;
0033       m_nHits = nH;
0034     }
0035 
0036     void setTrajParams(TrajParams tmps, Chi2sFive chi2s) {
0037       m_trajParams = std::move(tmps);
0038       m_chi2sX5 = std::move(chi2s);
0039     }
0040 
0041     unsigned int firstRecHit() const { return m_firstHit; }
0042 
0043     /// number of RecHits
0044     unsigned int recHitsSize() const { return m_nHits; }
0045 
0046     /// accessor to RecHits
0047     auto recHits() const { return TrackingRecHitRange(recHitsBegin(), recHitsEnd()); }
0048 
0049     /// first iterator over RecHits
0050     trackingRecHit_iterator recHitsBegin() const { return recHitsProduct().data().begin() + firstRecHit(); }
0051 
0052     /// last iterator over RecHits
0053     trackingRecHit_iterator recHitsEnd() const { return recHitsBegin() + recHitsSize(); }
0054 
0055     /// get a ref to i-th recHit
0056     TrackingRecHitRef recHitRef(unsigned int i) const {
0057       //Another thread might change the RefCore at the same time.
0058       // By using a copy we will be safe.
0059       edm::RefCore hitCollection(m_hitCollection);
0060       if (hitCollection.productPtr()) {
0061         TrackingRecHitRef::finder_type finder;
0062         TrackingRecHitRef::value_type const* item =
0063             finder(*(static_cast<TrackingRecHitRef::product_type const*>(hitCollection.productPtr())), m_firstHit + i);
0064         return TrackingRecHitRef(hitCollection.id(), item, m_firstHit + i);
0065       }
0066       return TrackingRecHitRef(hitCollection, m_firstHit + i);
0067     }
0068 
0069     /// get i-th recHit
0070     TrackingRecHitRef recHit(unsigned int i) const { return recHitRef(i); }
0071 
0072     TrackingRecHitCollection const& recHitsProduct() const {
0073       return *edm::getProduct<TrackingRecHitCollection>(m_hitCollection);
0074     }
0075 
0076     TrajParams const& trajParams() const { return m_trajParams; }
0077     Chi2sFive const& chi2sX5() const { return m_chi2sX5; }
0078 
0079   private:
0080     edm::RefCore m_hitCollection;
0081     unsigned int m_firstHit;
0082     unsigned int m_nHits;
0083     TrajParams m_trajParams;
0084     Chi2sFive m_chi2sX5;  // chi2 * 5  chopped at 255  (max chi2 is 51)
0085   };
0086 
0087 }  // namespace reco
0088 
0089 #endif  // DataFormats_TrackReco_TrackExtraBase_h