Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:07:42

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