Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-10-16 05:03:56

0001 #ifndef GEOMETRY_CALOTOPOLOGY_HCALTOPOLOGY_H
0002 #define GEOMETRY_CALOTOPOLOGY_HCALTOPOLOGY_H 1
0003 
0004 #include <vector>
0005 #include <map>
0006 #include "DataFormats/HcalDetId/interface/HcalDetId.h"
0007 #include "DataFormats/HcalDetId/interface/HcalCalibDetId.h"
0008 #include "DataFormats/HcalDetId/interface/HcalTrigTowerDetId.h"
0009 #include "Geometry/CaloTopology/interface/CaloSubdetectorTopology.h"
0010 #include "Geometry/HcalCommonData/interface/HcalTopologyMode.h"
0011 #include "Geometry/HcalCommonData/interface/HcalDDDRecConstants.h"
0012 
0013 /** \class HcalTopology
0014 
0015    The HcalTopology class contains a set of constants which represent
0016    the topology (tower relationship) of the CMS HCAL as built.  These
0017    constants can be used to determine neighbor relationships and
0018    existence of cells.
0019 
0020    For use with limited setups (testbeam, cosmic stands, etc), the
0021    topology can be limited by creating a rejection list -- a list of
0022    cells which would normally exist in the full CMS HCAL, but are not
0023    present for the specified topology.
0024     
0025 */
0026 class HcalTopology : public CaloSubdetectorTopology {
0027 public:
0028   HcalTopology(const HcalDDDRecConstants* hcons, const bool mergePosition = false);
0029 
0030   HcalTopologyMode::Mode mode() const { return mode_; }
0031   HcalTopologyMode::TriggerMode triggerMode() const { return triggerMode_; }
0032   /** Add a cell to exclusion list */
0033   void exclude(const HcalDetId& id);
0034   /** Exclude an entire subdetector */
0035   void excludeSubdetector(HcalSubdetector subdet);
0036   /** Exclude an eta/phi/depth range for a given subdetector */
0037   int exclude(HcalSubdetector subdet, int ieta1, int ieta2, int iphi1, int iphi2, int depth1 = 1, int depth2 = 4);
0038 
0039   static std::string producerTag() { return "HCAL"; }
0040 
0041   /// return a linear packed id
0042   unsigned int detId2denseId(const DetId& id) const override;
0043   /// return a linear packed id
0044   DetId denseId2detId(unsigned int /*denseid*/) const override;
0045   /// return a count of valid cells (for dense indexing use)
0046   unsigned int ncells() const override;
0047   unsigned int ncells(int subdet) const;
0048   /// return a version which identifies the given topology
0049   int topoVersion() const override;
0050 
0051   /** Is this a valid cell id? */
0052   bool valid(const DetId& id) const override;
0053   /** Is this a valid cell id? */
0054   bool validHcal(const HcalDetId& id) const;
0055   bool validDetId(HcalSubdetector subdet, int ieta, int iphi, int depth) const;
0056   bool validHT(const HcalTrigTowerDetId& id) const;
0057   bool validCalib(const HcalCalibDetId& id) const;
0058   /** Is this a valid cell in context of Plan1 */
0059   bool validHcal(const HcalDetId& id, const unsigned int flag) const;
0060   /** Flag=0 for unmerged Id's; =1 for for merged Id's; =2 for either */
0061 
0062   /** Get the neighbors of the given cell in east direction*/
0063   std::vector<DetId> east(const DetId& id) const override;
0064   /** Get the neighbors of the given cell in west direction*/
0065   std::vector<DetId> west(const DetId& id) const override;
0066   /** Get the neighbors of the given cell in north direction*/
0067   std::vector<DetId> north(const DetId& id) const override;
0068   /** Get the neighbors of the given cell in south direction*/
0069   std::vector<DetId> south(const DetId& id) const override;
0070   /** Get the neighbors of the given cell in up direction (outward)*/
0071   std::vector<DetId> up(const DetId& id) const override;
0072   /** Get the neighbors of the given cell in down direction (inward)*/
0073   std::vector<DetId> down(const DetId& id) const override;
0074 
0075   /** Get the neighbors of the given cell with higher (signed) ieta */
0076   int incIEta(const HcalDetId& id, HcalDetId neighbors[2]) const;
0077   /** Get the neighbors of the given cell with lower (signed) ieta */
0078   int decIEta(const HcalDetId& id, HcalDetId neighbors[2]) const;
0079   /** Get the neighbor (if present) of the given cell with higher iphi */
0080   bool incIPhi(const HcalDetId& id, HcalDetId& neighbor) const;
0081   /** Get the neighbor (if present) of the given cell with lower iphi */
0082   bool decIPhi(const HcalDetId& id, HcalDetId& neighbor) const;
0083   /** Get the detector behind this one */
0084   bool incrementDepth(HcalDetId& id) const;
0085   /** Get the detector in front of this one */
0086   bool decrementDepth(HcalDetId& id) const;
0087 
0088   int firstHBRing() const { return firstHBRing_; }
0089   int lastHBRing() const { return lastHBRing_; }
0090   int firstHERing() const { return firstHERing_; }
0091   int lastHERing() const { return lastHERing_; }
0092   int lastHBHERing() const { return std::max(lastHBRing_, lastHERing_); }
0093   int firstHFRing() const { return firstHFRing_; }
0094   int lastHFRing() const { return lastHFRing_; }
0095   int firstHORing() const { return firstHORing_; }
0096   int lastHORing() const { return lastHORing_; }
0097 
0098   int firstHEDoublePhiRing() const { return firstHEDoublePhiRing_; }
0099   int firstHEQuadPhiRing() const { return firstHEQuadPhiRing_; }
0100   int firstHFQuadPhiRing() const { return firstHFQuadPhiRing_; }
0101   int firstHETripleDepthRing() const { return firstHETripleDepthRing_; }
0102   int singlePhiBins() const { return singlePhiBins_; }
0103   int doublePhiBins() const { return doublePhiBins_; }
0104 
0105   /// finds the number of depth bins and which is the number to start with
0106   void depthBinInformation(
0107       HcalSubdetector subdet, int etaRing, int iphi, int zside, int& nDepthBins, int& startingBin) const;
0108   bool mergedDepth29(HcalDetId id) const { return hcons_->mergedDepthList29(id.ieta(), id.iphi(), id.depth()); }
0109   std::vector<int> mergedDepthList29(HcalDetId id) const { return hcons_->mergedDepthList29(id.ieta(), id.iphi()); }
0110 
0111   /// how many phi segments in this ring
0112   int nPhiBins(int etaRing) const;
0113   int nPhiBins(HcalSubdetector subdet, int etaRing) const;
0114 
0115   /// eta and phi index from eta, phi values
0116   int etaRing(HcalSubdetector subdet, double eta) const;
0117   int phiBin(HcalSubdetector subdet, int etaRing, double phi) const;
0118 
0119   /// for each of the ~17 depth segments, specify which readout bin they belong to
0120   /// if the ring is not found, the first one with a lower ring will be returned.
0121   void getDepthSegmentation(const unsigned ring, std::vector<int>& readoutDepths, const bool flag = false) const;
0122   void setDepthSegmentation(const unsigned ring, const std::vector<int>& readoutDepths, const bool flag);
0123   /// returns the boundaries of the depth segmentation, so that the first
0124   /// result is the first segment, and the second result is the first one
0125   /// of the next segment.  Used for calculating physical bounds.
0126   std::pair<int, int> segmentBoundaries(const unsigned ring, const unsigned depth, const bool flag = false) const;
0127   int getPhiZOne(std::vector<std::pair<int, int> >& phiz) const { return hcons_->getPhiZOne(phiz); }
0128 
0129   unsigned int getHBSize() const { return HBSize_; }
0130   unsigned int getHESize() const { return HESize_; }
0131   unsigned int getHOSize() const { return HOSize_; }
0132   unsigned int getHFSize() const { return HFSize_; }
0133   unsigned int getHTSize() const { return HTSize_; }
0134   unsigned int getCALIBSize() const { return CALIBSize_; }
0135 
0136   int maxDepthHB() const { return maxDepthHB_; }
0137   int maxDepthHE() const { return maxDepthHE_; }
0138   int maxDepth(void) const;
0139   int maxDepth(HcalSubdetector subdet) const;
0140   double etaMax(HcalSubdetector subdet) const;
0141   std::pair<double, double> etaRange(HcalSubdetector subdet, int ieta) const;
0142 
0143   /// return a linear packed id from HB
0144   unsigned int detId2denseIdHB(const DetId& id) const;
0145   /// return a linear packed id from HE
0146   unsigned int detId2denseIdHE(const DetId& id) const;
0147   /// return a linear packed id from HO
0148   unsigned int detId2denseIdHO(const DetId& id) const;
0149   /// return a linear packed id from HF
0150   unsigned int detId2denseIdHF(const DetId& id) const;
0151   /// return a linear packed id from HT
0152   unsigned int detId2denseIdHT(const DetId& id) const;
0153   /// return a linear packed id from CALIB
0154   unsigned int detId2denseIdCALIB(const DetId& id) const;
0155   /// return a Calib DetId from linear packed id
0156   HcalCalibDetId denseId2detIdCALIB(const unsigned int& id) const;
0157 
0158   unsigned int getNumberOfShapes() const { return numberOfShapes_; }
0159   bool isBH() const { return ((hcons_ == nullptr) ? false : hcons_->isBH()); }
0160 
0161   const HcalDDDRecConstants* dddConstants() const { return hcons_; }
0162   bool withSpecialRBXHBHE() const { return hcons_->withSpecialRBXHBHE(); }
0163   HcalDetId mergedDepthDetId(const HcalDetId& id) const { return hcons_->mergedDepthDetId(id); }
0164   bool getMergePositionFlag() const { return mergePosition_; }
0165   void unmergeDepthDetId(const HcalDetId& id, std::vector<HcalDetId>& ids) const { hcons_->unmergeDepthDetId(id, ids); }
0166   // Returns the DetId of the front Id if it is a merged RecHit in "Plan 1"
0167   HcalDetId idFront(const HcalDetId& id) const { return hcons_->idFront(id); }
0168   HcalDetId idBack(const HcalDetId& id) const { return hcons_->idBack(id); }
0169 
0170 private:
0171   bool phase1() const { return ((mode_ == HcalTopologyMode::LHC) || (mode_ == HcalTopologyMode::H2HE)); }
0172   bool phase1A() const {
0173     return ((mode_ == HcalTopologyMode::LHC) || (mode_ == HcalTopologyMode::Run2A) || (mode_ == HcalTopologyMode::H2) ||
0174             (mode_ == HcalTopologyMode::H2HE));
0175   }
0176   bool phase1B() const {
0177     return ((mode_ == HcalTopologyMode::Run2B) || (mode_ == HcalTopologyMode::Run2C) ||
0178             (mode_ == HcalTopologyMode::Run3) || (mode_ == HcalTopologyMode::SLHC));
0179   }
0180   bool phase2() const { return ((mode_ == HcalTopologyMode::Run4)); }
0181   /** Get the neighbors of the given cell with higher absolute ieta */
0182   int incAIEta(const HcalDetId& id, HcalDetId neighbors[2]) const;
0183   /** Get the neighbors of the given cell with lower absolute ieta */
0184   int decAIEta(const HcalDetId& id, HcalDetId neighbors[2]) const;
0185 
0186   /** Is this a valid cell id, ignoring the exclusion list */
0187   bool validDetIdPreLS1(const HcalDetId& id) const;
0188   bool validRaw(const HcalDetId& id, const bool debug = false) const;
0189   unsigned int detId2denseIdPreLS1(const DetId& id) const;
0190   bool isExcluded(const HcalDetId& id) const;
0191 
0192   const HcalDDDRecConstants* hcons_;
0193   bool mergePosition_;
0194   std::vector<HcalDetId> exclusionList_;
0195   bool excludeHB_, excludeHE_, excludeHO_, excludeHF_;
0196 
0197   HcalTopologyMode::Mode mode_;
0198   HcalTopologyMode::TriggerMode triggerMode_;
0199 
0200   int firstHBRing_, lastHBRing_;
0201   int firstHERing_, lastHERing_;
0202   int firstHFRing_, lastHFRing_;
0203   int firstHORing_, lastHORing_;
0204 
0205   std::vector<HcalDDDRecConstants::HcalEtaBin> etaBinsHB_, etaBinsHE_;
0206   int nEtaHB_, nEtaHE_;
0207 
0208   int firstHEDoublePhiRing_, firstHEQuadPhiRing_, firstHFQuadPhiRing_;
0209   int firstHETripleDepthRing_;
0210   int singlePhiBins_, doublePhiBins_;
0211   int maxDepthHB_, maxDepthHE_, maxDepthHF_;
0212   int etaHE2HF_, etaHF2HE_;
0213   int maxEta_, maxPhiHE_;
0214 
0215   unsigned int HBSize_;
0216   unsigned int HESize_;
0217   unsigned int HOSize_;
0218   unsigned int HFSize_;
0219   unsigned int HTSize_;
0220   unsigned int CALIBSize_;
0221   unsigned int numberOfShapes_;
0222 
0223   std::vector<double> etaTable, etaTableHF, dPhiTable, dPhiTableHF;
0224   std::vector<double> phioff;
0225   std::vector<int> unitPhi, unitPhiHF;
0226 
0227   int topoVersion_;
0228 
0229   // index is ring;
0230   typedef std::map<unsigned, std::vector<int> > SegmentationMap;
0231   SegmentationMap depthSegmentation_;
0232   SegmentationMap depthSegmentationOne_;
0233 
0234   static constexpr int kHBhalf = 1296, kHEhalf = 1296, kHOhalf = 1080, kHFhalf = 864, kHThalf = 2088, kZDChalf = 11,
0235                        kCASTORhalf = 224, kCALIBhalf = 693, kHThalfPhase1 = 2520,
0236                        kHcalhalf = kHBhalf + kHEhalf + kHOhalf + kHFhalf;
0237   static constexpr int kHBhalfPostLS2 = 4536, kHEhalfPostLS2 = 3384, kHFhalfPostLS2 = 1728;
0238   static constexpr int kHcalhalfPostLS2 = kHBhalfPostLS2 + kHEhalfPostLS2 + kHOhalf + kHFhalfPostLS2;
0239   static constexpr int kSizeForDenseIndexingPreLS1 = 2 * kHcalhalf;
0240   static constexpr int kSizeForDenseIndexingPostLS2 = 2 * kHcalhalfPostLS2;
0241   static constexpr int kHBSizePreLS1 = 2 * kHBhalf;
0242   static constexpr int kHESizePreLS1 = 2 * kHEhalf;
0243   static constexpr int kHOSizePreLS1 = 2 * kHOhalf;
0244   static constexpr int kHFSizePreLS1 = 2 * kHFhalf;
0245   static constexpr int kHTSizePreLS1 = 2 * kHThalf;
0246   static constexpr int kHTSizePhase1 = 2 * kHThalfPhase1;
0247   static constexpr int kCALIBSizePreLS1 = 2 * kCALIBhalf;
0248   static constexpr int kHBSizePostLS2 = 2 * kHBhalfPostLS2;
0249   static constexpr int kHESizePostLS2 = 2 * kHEhalfPostLS2;
0250   static constexpr int kHFSizePostLS2 = 2 * kHFhalfPostLS2;
0251   static constexpr int minMaxDepth_ = 4;
0252   static constexpr unsigned int minPhi_ = 1, maxPhi_ = 72;
0253   static constexpr unsigned int kOffCalibHB_ = 0;
0254   static constexpr unsigned int nchanCalibHB_ = 3, nEtaCalibHB_ = 2;
0255   static constexpr unsigned int mPhiCalibHB_ = 4, kPhiCalibHB_ = maxPhi_ / mPhiCalibHB_;
0256   static constexpr int chanCalibHB_[nchanCalibHB_] = {0, 1, 2};
0257   static constexpr int etaCalibHB_[nEtaCalibHB_] = {-1, 1};
0258   static constexpr unsigned int kchanCalibHB_ = nchanCalibHB_ * kPhiCalibHB_;
0259   static constexpr unsigned int nCalibHB_ = kchanCalibHB_ * nEtaCalibHB_;
0260   static constexpr unsigned int kOffCalibHE1_ = kOffCalibHB_ + nCalibHB_;
0261   static constexpr unsigned int nchanCalibHE1_ = 6, nEtaCalibHE_ = 2;
0262   static constexpr unsigned int mPhiCalibHE_ = 4, kPhiCalibHE_ = maxPhi_ / mPhiCalibHE_;
0263   static constexpr int chanCalibHE1_[nchanCalibHE1_] = {0, 1, 3, 4, 5, 6};
0264   static constexpr int etaCalibHE_[nEtaCalibHE_] = {-1, 1};
0265   static constexpr unsigned int kchanCalibHE1_ = nchanCalibHE1_ * kPhiCalibHE_;
0266   static constexpr unsigned int nCalibHE1_ = kchanCalibHE1_ * nEtaCalibHE_;
0267   static constexpr unsigned int kOffCalibHF1_ = kOffCalibHE1_ + nCalibHE1_;
0268   static constexpr unsigned int nchanCalibHF1_ = 3, nEtaCalibHF_ = 2;
0269   static constexpr unsigned int mPhiCalibHF1_ = 18, kPhiCalibHF1_ = maxPhi_ / mPhiCalibHF1_;
0270   static constexpr int chanCalibHF1_[nchanCalibHF1_] = {0, 1, 8};
0271   static constexpr int etaCalibHF_[nEtaCalibHF_] = {-1, 1};
0272   static constexpr unsigned int kchanCalibHF1_ = nchanCalibHF1_ * kPhiCalibHF1_;
0273   static constexpr unsigned int nCalibHF1_ = kchanCalibHF1_ * nEtaCalibHF_;
0274   static constexpr unsigned int kOffCalibHO1_ = kOffCalibHF1_ + nCalibHF1_;
0275   static constexpr unsigned int nchanCalibHO_ = 2, nEtaCalibHO_ = 5;
0276   static constexpr int chanCalibHOs_ = 7;
0277   static constexpr int chanCalibHO_[nchanCalibHO_] = {0, 1};
0278   static constexpr int etaCalibHO_[nEtaCalibHO_] = {-2, -1, 0, 1, 2};
0279   static constexpr int phiCalibHO_[nEtaCalibHO_] = {59, 47, 53, 47, 47};
0280   static constexpr unsigned int mPhiCalibHO0_ = 6, mPhiCalibHO1_ = 12;
0281   static constexpr unsigned int kPhiCalibHO0_ = maxPhi_ / mPhiCalibHO0_;
0282   static constexpr unsigned int kPhiCalibHO1_ = maxPhi_ / mPhiCalibHO1_;
0283   static constexpr unsigned int kPhiCalibHO2_ = 4 * kPhiCalibHO1_ + kPhiCalibHO0_;
0284   static constexpr unsigned int nCalibHO1_ = kPhiCalibHO2_ * nchanCalibHO_;
0285   static constexpr unsigned int kOffCalibHO2_ = kOffCalibHO1_ + nCalibHO1_;
0286   static constexpr unsigned int nCalibHO2_ = nEtaCalibHO_;
0287   static constexpr unsigned int kOffCalibHE2_ = kOffCalibHO2_ + nCalibHO2_;
0288   static constexpr int chanCalibHE2_ = 2;
0289   static constexpr unsigned int kchanCalibHE2_ = kPhiCalibHE_;
0290   static constexpr unsigned int nCalibHE2_ = kchanCalibHE2_ * nEtaCalibHE_;
0291   static constexpr unsigned int kOffCalibHF2_ = kOffCalibHE2_ + nCalibHE2_;
0292   static constexpr int chanCalibHF2_ = 9, phiCalibHF2_ = 1;
0293   static constexpr unsigned int kchanCalibHF2_ = 1;
0294   static constexpr unsigned int nCalibHF2_ = nEtaCalibHF_;
0295   static constexpr unsigned int kOffCalibHOX_ = kOffCalibHF2_ + nCalibHF2_;
0296   static constexpr unsigned int nEtaCalibHOX_ = 2;
0297   static constexpr int etaCalibHOX_[nEtaCalibHOX_] = {4, 15};
0298   static constexpr unsigned int mPhiCalibHOX_[nEtaCalibHOX_] = {2, 1};
0299   static constexpr unsigned int nPhiCalibHOX_[nEtaCalibHOX_] = {36, 72};
0300   static constexpr int nCalibHOX_ = 2 * (nPhiCalibHOX_[0] + nPhiCalibHOX_[1]);
0301   static constexpr int phiCalibHOX1_ = 4, phiCalibHOX2_ = 12, phiCalibHOX3_ = 6;
0302   static constexpr unsigned int kOffCalibHBX_ = kOffCalibHOX_ + nCalibHOX_;
0303   static constexpr unsigned int nEtaCalibHBX_ = 1, mPhiCalibHBX_ = 1;
0304   static constexpr int etaCalibHBX_ = 16;
0305   static constexpr unsigned int kPhiCalibHBX_ = maxPhi_ / mPhiCalibHBX_;
0306   static constexpr unsigned int nCalibHBX_ = 2 * kPhiCalibHBX_ * nEtaCalibHBX_;
0307   static constexpr unsigned int kOffCalibHEX_ = kOffCalibHBX_ + nCalibHBX_;
0308   static constexpr unsigned int nEtaCalibHEX_ = 2, mPhiCalibHEX_ = 2;
0309   static constexpr int etaCalibHEX_[nEtaCalibHEX_] = {25, 27};
0310   static constexpr unsigned int kPhiCalibHEX_ = maxPhi_ / mPhiCalibHEX_;
0311   static constexpr unsigned int nCalibHEX_ = 2 * kPhiCalibHEX_ * nEtaCalibHEX_;
0312   static constexpr unsigned int kOffCalibHFX_ = kOffCalibHEX_ + nCalibHEX_;
0313 };
0314 
0315 #endif