Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:04:03

0001 #ifndef ECALDETID_EBDETID_H
0002 #define ECALDETID_EBDETID_H
0003 
0004 #include <iosfwd>
0005 #include <cmath>
0006 #include <cstdlib>
0007 #include "DataFormats/DetId/interface/DetId.h"
0008 #include "DataFormats/EcalDetId/interface/EcalSubdetector.h"
0009 #include "DataFormats/EcalDetId/interface/EcalTrigTowerDetId.h"
0010 
0011 /** \class EBDetId
0012  *  Crystal identifier class for the ECAL barrel
0013  *
0014  *
0015  */
0016 
0017 class EBDetId : public DetId {
0018 public:
0019   enum { Subdet = EcalBarrel };
0020   /** Constructor of a null id */
0021   EBDetId() {}
0022   /** Constructor from a raw value */
0023   EBDetId(uint32_t rawid) : DetId(rawid) {}
0024   /** Constructor from crystal ieta and iphi 
0025       or from SM# and crystal# */
0026   // fast
0027   EBDetId(int crystal_ieta, int crystal_iphi) : DetId(Ecal, EcalBarrel) {
0028     id_ |= ((crystal_ieta > 0) ? (0x10000 | (crystal_ieta << 9)) : ((-crystal_ieta) << 9)) | (crystal_iphi & 0x1FF);
0029   }
0030   // slow
0031   EBDetId(int index1, int index2, int mode);
0032   /** Constructor from a generic cell id */
0033   EBDetId(const DetId& id) : DetId(id) {}
0034   /** Assignment operator from cell id */
0035   EBDetId& operator=(const DetId& id) {
0036     id_ = id.rawId();
0037     return *this;
0038   }
0039 
0040   /// get the subdetector .i.e EcalBarrel (what else?)
0041   // EcalSubdetector subdet() const { return EcalSubdetector(subdetId()); }
0042   static EcalSubdetector subdet() { return EcalBarrel; }
0043 
0044   /// get the z-side of the crystal (1/-1)
0045   int zside() const { return (id_ & 0x10000) ? (1) : (-1); }
0046   /// get the absolute value of the crystal ieta
0047   int ietaAbs() const { return (id_ >> 9) & 0x7F; }
0048   /// get the crystal ieta
0049   int ieta() const { return zside() * ietaAbs(); }
0050   /// get the crystal iphi
0051   int iphi() const { return id_ & 0x1FF; }
0052   /// get the HCAL/trigger ieta of this crystal
0053   int tower_ieta() const { return ((ietaAbs() - 1) / 5 + 1) * zside(); }
0054   /// get the HCAL/trigger iphi of this crystal
0055   int tower_iphi() const;
0056   /// get the HCAL/trigger iphi of this crystal
0057   EcalTrigTowerDetId tower() const { return EcalTrigTowerDetId(zside(), EcalBarrel, abs(tower_ieta()), tower_iphi()); }
0058   /// get the ECAL/SM id
0059   int ism() const {
0060     int id = (iphi() - 1) / kCrystalsInPhi + 1;
0061     return positiveZ() ? id : id + 18;
0062   }
0063   /// get the number of module inside the SM (1-4)
0064   int im() const {
0065     int ii = (ietaAbs() - 26);
0066     return ii < 0 ? 1 : (ii / 20 + 2);
0067   }
0068   /// get ECAL/crystal number inside SM
0069   int ic() const;
0070   /// get the crystal ieta in the SM convention (1-85)
0071   int ietaSM() const { return ietaAbs(); }
0072   /// get the crystal iphi (1-20)
0073   int iphiSM() const { return ((ic() - 1) % kCrystalsInPhi) + 1; }
0074 
0075   // is z positive?
0076   bool positiveZ() const { return id_ & 0x10000; }
0077   // crystal number in eta-phi grid
0078   int numberByEtaPhi() const { return (MAX_IETA + (positiveZ() ? ietaAbs() - 1 : -ietaAbs())) * MAX_IPHI + iphi() - 1; }
0079   // index numbering crystal by SM
0080   int numberBySM() const;
0081   /// get a compact index for arrays
0082   int hashedIndex() const { return numberByEtaPhi(); }
0083 
0084   uint32_t denseIndex() const { return hashedIndex(); }
0085 
0086   /** returns a new EBDetId offset by nrStepsEta and nrStepsPhi (can be negative), 
0087     * returns EBDetId(0) if invalid */
0088   EBDetId offsetBy(int nrStepsEta, int nrStepsPhi) const;
0089 
0090   /** returns a new EBDetId on the other zside of barrel (ie iEta*-1), 
0091     * returns EBDetId(0) if invalid (shouldnt happen) */
0092   EBDetId switchZSide() const;
0093 
0094   /** following are static member functions of the above two functions
0095     * which take and return a DetId, returns DetId(0) if invalid 
0096     */
0097   static DetId offsetBy(const DetId startId, int nrStepsEta, int nrStepsPhi);
0098   static DetId switchZSide(const DetId startId);
0099 
0100   /** return an approximate values of eta (~0.15% precise)
0101    */
0102   float approxEta() const { return ieta() * crystalUnitToEta; }
0103   static float approxEta(const DetId id);
0104 
0105   static bool validDenseIndex(uint32_t din) { return (din < kSizeForDenseIndexing); }
0106 
0107   static EBDetId detIdFromDenseIndex(uint32_t di) { return unhashIndex(di); }
0108 
0109   /// get a DetId from a compact index for arrays
0110   static EBDetId unhashIndex(int hi) {
0111     const int pseudo_eta = hi / MAX_IPHI - MAX_IETA;
0112     return (validHashIndex(hi) ? EBDetId(pseudo_eta < 0 ? pseudo_eta : pseudo_eta + 1, hi % MAX_IPHI + 1) : EBDetId());
0113   }
0114 
0115   static bool validHashIndex(int i) { return !(i < MIN_HASH || i > MAX_HASH); }
0116 
0117   /// check if a valid index combination
0118   static bool validDetId(int i, int j) {
0119     return i != 0 && (std::abs(i) <= MAX_IETA) && (j >= MIN_IPHI) && (j <= MAX_IPHI);
0120   }
0121 
0122   static bool isNextToBoundary(EBDetId id);
0123 
0124   static bool isNextToEtaBoundary(EBDetId id);
0125 
0126   static bool isNextToPhiBoundary(EBDetId id);
0127 
0128   //return the distance in eta units between two EBDetId
0129   static int distanceEta(const EBDetId& a, const EBDetId& b);
0130   //return the distance in phi units between two EBDetId
0131   static int distancePhi(const EBDetId& a, const EBDetId& b);
0132 
0133   /// range constants
0134   static const int MIN_IETA = 1;
0135   static const int MIN_IPHI = 1;
0136   static const int MAX_IETA = 85;
0137   static const int MAX_IPHI = 360;
0138   static const int kChannelsPerCard = 5;
0139   static const int kTowersInPhi = 4;  // per SM
0140   static const int kModulesPerSM = 4;
0141   static const int kModuleBoundaries[4];
0142   static const int kCrystalsInPhi = 20;  // per SM
0143   static const int kCrystalsInEta = 85;  // per SM
0144   static const int kCrystalsPerSM = 1700;
0145   static const int MIN_SM = 1;
0146   static const int MAX_SM = 36;
0147   static const int MIN_C = 1;
0148   static const int MAX_C = kCrystalsPerSM;
0149   static const int MIN_HASH = 0;  // always 0 ...
0150   static const int MAX_HASH = 2 * MAX_IPHI * MAX_IETA - 1;
0151 
0152   // eta coverage of one crystal (approximate)
0153   static const float crystalUnitToEta;
0154 
0155   static constexpr int kSizeForDenseIndexing = MAX_HASH + 1;
0156 
0157   // function modes for (int, int) constructor
0158   static const int ETAPHIMODE = 0;
0159   static const int SMCRYSTALMODE = 1;
0160 };
0161 
0162 std::ostream& operator<<(std::ostream& s, const EBDetId& id);
0163 
0164 #endif