Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-06-22 02:23:23

0001 #ifndef DeDxHitInfo_H
0002 #define DeDxHitInfo_H
0003 #include <vector>
0004 
0005 #include "DataFormats/DetId/interface/DetId.h"
0006 #include "DataFormats/SiStripDetId/interface/SiStripDetId.h"
0007 #include "DataFormats/SiStripCluster/interface/SiStripCluster.h"
0008 #include "DataFormats/SiPixelCluster/interface/SiPixelCluster.h"
0009 #include "DataFormats/GeometryVector/interface/LocalPoint.h"
0010 #include "DataFormats/Common/interface/Association.h"
0011 #include "DataFormats/Common/interface/RefVector.h"
0012 
0013 namespace reco {
0014   class DeDxHitInfo {
0015   public:
0016     class DeDxHitInfoContainer {
0017     public:
0018       DeDxHitInfoContainer() : charge_(0.0f), pathlength_(0.0f) {}
0019       DeDxHitInfoContainer(
0020           const float charge, const float pathlength, const DetId& detId, const LocalPoint& pos, const uint8_t& type)
0021           : charge_(charge), pathlength_(pathlength), detId_(detId), pos_(pos), type_(type) {}
0022 
0023       float charge() const { return charge_; }
0024       float pathlength() const { return pathlength_; }
0025       const DetId& detId() const { return detId_; }
0026       const LocalPoint& pos() const { return pos_; }
0027       const uint8_t& type() const { return type_; }
0028 
0029     private:
0030       //! total cluster charge
0031       float charge_;
0032       //! path length inside a module
0033       float pathlength_;
0034       DetId detId_;
0035       //! hit position
0036       LocalPoint pos_;
0037       uint8_t type_;
0038     };
0039 
0040     static constexpr int Complete = 0, Compatible = 1, Calibration = 2;
0041     typedef std::vector<DeDxHitInfo::DeDxHitInfoContainer> DeDxHitInfoContainerCollection;
0042 
0043   public:
0044     DeDxHitInfo() {}
0045     size_t size() const { return infos_.size(); }
0046     float charge(size_t i) const { return infos_[i].charge(); }
0047     float pathlength(size_t i) const { return infos_[i].pathlength(); }
0048     DetId detId(size_t i) const { return infos_[i].detId(); }
0049     const LocalPoint pos(size_t i) const { return infos_[i].pos(); }
0050     const uint8_t type(size_t i) const { return infos_[i].type(); }
0051     const SiPixelCluster* pixelCluster(size_t i) const {
0052       size_t P = 0;
0053       bool isPixel = false;
0054       bool isFirst = true;
0055       for (size_t j = 0; j <= i && j < infos_.size(); j++) {
0056         if (detId(j).subdetId() < SiStripDetId::TIB) {
0057           if (isFirst)
0058             isFirst = false;
0059           else
0060             P++;
0061           isPixel = true;
0062         } else {
0063           isPixel = false;
0064         }
0065       }
0066       if (isPixel && pixelClusters_.size() > P) {
0067         return &(pixelClusters_[P]);
0068       }
0069       return nullptr;
0070     }
0071     const SiStripCluster* stripCluster(size_t i) const {
0072       size_t S = 0;
0073       bool isStrip = false;
0074       bool isFirst = true;
0075       for (size_t j = 0; j <= i && j < infos_.size(); j++) {
0076         if (detId(j).subdetId() >= SiStripDetId::TIB) {
0077           if (isFirst) {
0078             isFirst = false;
0079           } else
0080             S++;
0081           isStrip = true;
0082         } else {
0083           isStrip = false;
0084         }
0085       }
0086       if (isStrip && stripClusters_.size() > S) {
0087         return &(stripClusters_[S]);
0088       }
0089       return nullptr;
0090     }
0091     const std::vector<SiStripCluster>& stripClusters() const { return stripClusters_; }
0092     const std::vector<SiPixelCluster>& pixelClusters() const { return pixelClusters_; }
0093 
0094     void addHit(const float charge,
0095                 const float pathlength,
0096                 const DetId& detId,
0097                 const LocalPoint& pos,
0098                 const uint8_t& type,
0099                 const SiStripCluster& stripCluster) {
0100       infos_.push_back(DeDxHitInfoContainer(charge, pathlength, detId, pos, type));
0101       stripClusters_.push_back(stripCluster);
0102     }
0103     void addHit(const float charge,
0104                 const float pathlength,
0105                 const DetId& detId,
0106                 const LocalPoint& pos,
0107                 const uint8_t& type,
0108                 const SiPixelCluster& pixelCluster) {
0109       infos_.push_back(DeDxHitInfoContainer(charge, pathlength, detId, pos, type));
0110       pixelClusters_.push_back(pixelCluster);
0111     }
0112 
0113   private:
0114     std::vector<DeDxHitInfoContainer> infos_;
0115     std::vector<SiStripCluster> stripClusters_;
0116     std::vector<SiPixelCluster> pixelClusters_;
0117   };
0118 
0119   typedef std::vector<DeDxHitInfo> DeDxHitInfoCollection;
0120   typedef edm::Ref<DeDxHitInfoCollection> DeDxHitInfoRef;
0121   typedef edm::RefProd<DeDxHitInfoCollection> DeDxHitInfoRefProd;
0122   typedef edm::RefVector<DeDxHitInfoCollection> DeDxHitInfoRefVector;
0123   typedef edm::Association<DeDxHitInfoCollection> DeDxHitInfoAss;
0124 }  // namespace reco
0125 
0126 #endif