Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-07-18 23:17:37

0001 #ifndef DataFormats_EgammaReco_ElectronSeed_h
0002 #define DataFormats_EgammaReco_ElectronSeed_h
0003 
0004 //********************************************************************
0005 //
0006 // A verson of reco::ElectronSeed which can have N hits as part of the
0007 // 2017 upgrade of E/gamma pixel matching for the phaseI pixels
0008 //
0009 // author: S. Harper (RAL), 2017
0010 //
0011 //notes:
0012 // While it is technically named ElectronSeed, it is effectively a new class
0013 // However to simplify things, the name ElectronSeed was kept
0014 // (trust me it was simplier...)
0015 //
0016 // Noticed that h/e values never seem to used anywhere and they are a
0017 // mild pain to propagate in the new framework so they were removed
0018 //
0019 // infinities are used to mark invalid unset values to maintain
0020 // compatibilty with the orginal ElectronSeed class
0021 //
0022 //description:
0023 // An ElectronSeed is a TrajectorySeed with E/gamma specific information
0024 // A TrajectorySeed has a series of hits associated with it
0025 // (accessed by TrajectorySeed::nHits(), TrajectorySeed::recHits())
0026 // and ElectronSeed stores which of those hits match well to a supercluster
0027 // together with the matching parameters (this is known as EcalDriven).
0028 // ElectronSeeds can be TrackerDriven in which case the matching is not done.
0029 // It used to be fixed to two matched hits, now this is an arbitary number
0030 // Its designed with pixel matching with mind but tries to be generally
0031 // applicable to strips as well.
0032 // It is worth noting that due to different ways ElectronSeeds can be created
0033 // they do not always have all parameters filled
0034 //
0035 //********************************************************************
0036 
0037 #include "DataFormats/EgammaReco/interface/ElectronSeedFwd.h"
0038 #include "DataFormats/CaloRecHit/interface/CaloClusterFwd.h"
0039 #include "DataFormats/TrajectorySeed/interface/TrajectorySeed.h"
0040 #include "DataFormats/TrajectoryState/interface/TrackCharge.h"
0041 #include "DataFormats/TrackingRecHit/interface/TrackingRecHit.h"
0042 #include "DataFormats/TrackReco/interface/TrackFwd.h"
0043 #include "DataFormats/Common/interface/RefToBase.h"
0044 #include "DataFormats/Common/interface/Ref.h"
0045 
0046 #include <vector>
0047 #include <limits>
0048 
0049 namespace reco {
0050 
0051   class ElectronSeed : public TrajectorySeed {
0052   public:
0053     struct PMVars {
0054       float dRZPos;
0055       float dRZNeg;
0056       float dPhiPos;
0057       float dPhiNeg;
0058       int detId;          //this is already stored as the hit is stored in traj seed but a useful sanity check
0059       int layerOrDiskNr;  //redundant as stored in detId but its a huge pain to hence why its saved here
0060 
0061       PMVars();
0062 
0063       void setDPhi(float pos, float neg);
0064       void setDRZ(float pos, float neg);
0065       void setDet(int iDetId, int iLayerOrDiskNr);
0066     };
0067 
0068     typedef edm::RefToBase<CaloCluster> CaloClusterRef;
0069     typedef edm::Ref<TrackCollection> CtfTrackRef;
0070 
0071     static std::string const& name() {
0072       static std::string const name_("ElectronSeed");
0073       return name_;
0074     }
0075 
0076     //! Construction of base attributes
0077     ElectronSeed();
0078     ElectronSeed(const TrajectorySeed&);
0079     ElectronSeed(PTrajectoryStateOnDet& pts, RecHitContainer& rh, PropagationDirection& dir);
0080     ElectronSeed* clone() const override { return new ElectronSeed(*this); }
0081     ~ElectronSeed() override;
0082 
0083     //! Set additional info
0084     void setCtfTrack(const CtfTrackRef&);
0085     void setCaloCluster(const CaloClusterRef& clus) {
0086       caloCluster_ = clus;
0087       isEcalDriven_ = true;
0088     }
0089     void addHitInfo(const PMVars& hitVars) { hitInfo_.push_back(hitVars); }
0090     void setNrLayersAlongTraj(int val) { nrLayersAlongTraj_ = val; }
0091     //! Accessors
0092     const CtfTrackRef& ctfTrack() const { return ctfTrack_; }
0093     const CaloClusterRef& caloCluster() const { return caloCluster_; }
0094 
0095     //! Utility
0096     TrackCharge getCharge() const { return startingState().parameters().charge(); }
0097 
0098     bool isEcalDriven() const { return isEcalDriven_; }
0099     bool isTrackerDriven() const { return isTrackerDriven_; }
0100 
0101     const std::vector<PMVars>& hitInfo() const { return hitInfo_; }
0102     float dPhiNeg(size_t hitNr) const { return getVal(hitNr, &PMVars::dPhiNeg); }
0103     float dPhiPos(size_t hitNr) const { return getVal(hitNr, &PMVars::dPhiPos); }
0104     float dPhiBest(size_t hitNr) const { return bestVal(dPhiNeg(hitNr), dPhiPos(hitNr)); }
0105     float dRZPos(size_t hitNr) const { return getVal(hitNr, &PMVars::dRZPos); }
0106     float dRZNeg(size_t hitNr) const { return getVal(hitNr, &PMVars::dRZNeg); }
0107     float dRZBest(size_t hitNr) const { return bestVal(dRZNeg(hitNr), dRZPos(hitNr)); }
0108     int detId(size_t hitNr) const { return hitNr < hitInfo_.size() ? hitInfo_[hitNr].detId : 0; }
0109     int subDet(size_t hitNr) const { return DetId(detId(hitNr)).subdetId(); }
0110     int layerOrDiskNr(size_t hitNr) const { return getVal(hitNr, &PMVars::layerOrDiskNr); }
0111     int nrLayersAlongTraj() const { return nrLayersAlongTraj_; }
0112 
0113     unsigned int hitsMask() const;
0114     void initTwoHitSeed(const unsigned char hitMask);
0115     void setNegAttributes(const float dRZ2 = std::numeric_limits<float>::max(),
0116                           const float dPhi2 = std::numeric_limits<float>::max(),
0117                           const float dRZ1 = std::numeric_limits<float>::max(),
0118                           const float dPhi1 = std::numeric_limits<float>::max());
0119     void setPosAttributes(const float dRZ2 = std::numeric_limits<float>::max(),
0120                           const float dPhi2 = std::numeric_limits<float>::max(),
0121                           const float dRZ1 = std::numeric_limits<float>::max(),
0122                           const float dPhi1 = std::numeric_limits<float>::max());
0123 
0124     //this is a backwards compatible function designed to
0125     //convert old format ElectronSeeds to the new format
0126     //only public due to root io rules, not intended for any other use
0127     //also in theory not necessary to part of this class
0128     static std::vector<PMVars> createHitInfo(const float dPhi1Pos,
0129                                              const float dPhi1Neg,
0130                                              const float dRZ1Pos,
0131                                              const float dRZ1Neg,
0132                                              const float dPhi2Pos,
0133                                              const float dPhi2Neg,
0134                                              const float dRZ2Pos,
0135                                              const float dRZ2Neg,
0136                                              const char hitMask,
0137                                              TrajectorySeed::RecHitRange const& recHits);
0138 
0139   private:
0140     static float bestVal(float val1, float val2) { return std::abs(val1) < std::abs(val2) ? val1 : val2; }
0141     template <typename T>
0142     T getVal(unsigned int hitNr, T PMVars::*val) const {
0143       return hitNr < hitInfo_.size() ? hitInfo_[hitNr].*val : std::numeric_limits<T>::max();
0144     }
0145     static std::vector<unsigned int> hitNrsFromMask(unsigned int hitMask);
0146 
0147   private:
0148     CtfTrackRef ctfTrack_;
0149     CaloClusterRef caloCluster_;
0150     std::vector<PMVars> hitInfo_;
0151     int nrLayersAlongTraj_;
0152 
0153     bool isEcalDriven_;
0154     bool isTrackerDriven_;
0155   };
0156 }  // namespace reco
0157 
0158 #endif