Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #ifndef ECALDETID_ESDETID_H
0002 #define ECALDETID_ESDETID_H
0003 
0004 #include <iosfwd>
0005 #include "DataFormats/DetId/interface/DetId.h"
0006 #include "DataFormats/EcalDetId/interface/EcalSubdetector.h"
0007 #include "FWCore/Utilities/interface/Exception.h"
0008 
0009 /** \class ESDetId
0010 
0011    Det id for a preshower (endcap) strip
0012     
0013 */
0014 
0015 class ESDetId : public DetId {
0016 public:
0017   enum { Subdet = EcalPreshower };
0018   /** Constructor of a null id */
0019   ESDetId() {}
0020   /** Constructor from a raw value */
0021   ESDetId(uint32_t rawid) : DetId(rawid) {}
0022 
0023   /// constructor from strip, ix, iy, plane, and iz
0024   ESDetId(int strip, int ixs, int iys, int plane, int iz, bool doverify = false) : DetId(Ecal, EcalPreshower) {
0025     id_ |= (strip & 0x3F) | ((ixs & 0x3F) << 6) | ((iys & 0x3F) << 12) | (((plane - 1) & 0x1) << 18) |
0026            ((iz > 0) ? (1 << 19) : (0));
0027     if (doverify)
0028       verify(strip, ixs, iys, plane, iz);
0029   }
0030 
0031   /** constructor from a generic DetId */
0032   ESDetId(const DetId& id);
0033   /** assignment from a generic DetId */
0034   ESDetId& operator=(const DetId& id);
0035 
0036   /// get the subdetector
0037   EcalSubdetector subdet() const { return EcalSubdetector(subdetId()); }
0038   /** get the zside */
0039   int zside() const { return (id_ & 0x80000) ? (1) : (-1); }
0040   /** get the plane */
0041   int plane() const { return ((id_ >> 18) & 0x1) + 1; }
0042   /** get the sensor ix */
0043   int six() const { return (id_ >> 6) & 0x3F; }
0044   /** get the sensor iy */
0045   int siy() const { return (id_ >> 12) & 0x3F; }
0046   /** get the strip */
0047   int strip() const { return (id_ & 0x3F); }
0048   /// get a compact index for arrays [TODO: NEEDS WORK]
0049   int hashedIndex() const;
0050 
0051   uint32_t denseIndex() const { return hashedIndex(); }
0052 
0053   static bool validDenseIndex(uint32_t din) { return validHashIndex(din); }
0054 
0055   static ESDetId detIdFromDenseIndex(uint32_t din) { return unhashIndex(din); }
0056 
0057   /// get a DetId from a compact index for arrays
0058   static ESDetId unhashIndex(int hi);
0059   static bool validHashIndex(int hi) { return (hi < kSizeForDenseIndexing); }
0060   /// check if a valid index combination
0061   static bool validDetId(int istrip, int ixs, int iys, int iplane, int iz);
0062   static void verify(int istrip, int ixs, int iys, int iplane, int iz);
0063 
0064   static const int IX_MIN = 1;
0065   static const int IY_MIN = 1;
0066   static const int IX_MAX = 40;
0067   static const int IY_MAX = 40;
0068   static const int ISTRIP_MIN = 1;
0069   static const int ISTRIP_MAX = 32;
0070   static const int PLANE_MIN = 1;
0071   static const int PLANE_MAX = 2;
0072   static const int IZ_NUM = 2;
0073 
0074 private:
0075   enum {
0076     kXYMAX = 1072,
0077     kXYMIN = 1,
0078     kXMAX = 40,
0079     kYMAX = 40,
0080     kXMIN = 1,
0081     kYMIN = 1,
0082     // now normalize to A-D notation for ease of use
0083     kNa = IZ_NUM,
0084     kNb = PLANE_MAX - PLANE_MIN + 1,
0085     kNc = kXYMAX - kXYMIN + 1,
0086     kNd = ISTRIP_MAX - ISTRIP_MIN + 1,
0087     kLd = kNd,
0088     kLc = kLd * kNc,
0089     kLb = kLc * kNb,
0090     kLa = kLb * kNa
0091   };
0092 
0093   static const unsigned short hxy1[kXMAX][kYMAX];
0094   static const unsigned short hx1[kXYMAX];
0095   static const unsigned short hy1[kXYMAX];
0096 
0097   static const unsigned short hxy2[kXMAX][kYMAX];
0098   static const unsigned short hx2[kXYMAX];
0099   static const unsigned short hy2[kXYMAX];
0100 
0101 public:
0102   static constexpr int kSizeForDenseIndexing = kLa;
0103 };
0104 
0105 std::ostream& operator<<(std::ostream&, const ESDetId& id);
0106 
0107 inline ESDetId::ESDetId(const DetId& gen) : DetId(gen) {
0108 #ifdef EDM_ML_DEBUG
0109   if (!gen.null() && (gen.det() != Ecal || gen.subdetId() != EcalPreshower)) {
0110     throw cms::Exception("InvalidDetId");
0111   }
0112 #endif
0113 }
0114 
0115 inline ESDetId& ESDetId::operator=(const DetId& gen) {
0116 #ifdef EDM_ML_DEBUG
0117   if (!gen.null() && (gen.det() != Ecal || gen.subdetId() != EcalPreshower)) {
0118     throw cms::Exception("InvalidDetId");
0119   }
0120 #endif
0121   id_ = gen.rawId();
0122   return *this;
0123 }
0124 
0125 #endif