Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 // -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: t; tab-width: 8; -*-
0002 //
0003 // \author Philippe Gras (CEA/Saclay). Code adapted from EEDetId.
0004 //
0005 #ifndef EcalDetId_EcalScDetId_h
0006 #define EcalDetId_EcalScDetId_h
0007 
0008 #include <iosfwd>
0009 #include "DataFormats/DetId/interface/DetId.h"
0010 #include "DataFormats/EcalDetId/interface/EcalSubdetector.h"
0011 #include "FWCore/Utilities/interface/thread_safety_macros.h"
0012 
0013 /** \class EcalScDetId
0014  *  Supercrystal identifier class for the ECAL endcap.
0015  *  <P>Note: internal representation of ScDetId:
0016  *  \verbatim
0017  *  31              .               15              .              0
0018  *  |-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-|-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-| 
0019  *  |  det  |sudet|         0       |1|z|     ix      |     iy      |
0020  *  +-------+-----+-----------------+-+-+-------------+-------------+
0021  *  \endverbatim
0022  */
0023 
0024 class EcalScDetId : public DetId {
0025 public:
0026   /** Constructor of a null id
0027    */
0028   EcalScDetId();
0029 
0030   /** Constructor from a raw value
0031    * @param rawid det ID number of the supecrystal, as defined in this class
0032    * description.
0033    */
0034   EcalScDetId(uint32_t rawid);
0035 
0036   /** Constructor from supercrystal ix,iy,iz (iz=+1/-1)
0037    * ix x-index runs from 1 to 20 along x-axis of standard CMS coordinates
0038    * iy y-index runs from 1 to 20 along y-axis of standard CMS coordinates
0039    * iz z-index (also called "z-side") is -1 for EE- and +1 for EE+
0040    * @param ix x-index
0041    * @param iy y-index
0042    * @param iz z-side /z-index: -1 for EE-, +1 for EE+
0043    */
0044   EcalScDetId(int ix, int iy, int iz);
0045 
0046   /** Constructor from a raw value
0047    * @param id det ID number
0048    */
0049   EcalScDetId(const DetId& id);
0050 
0051   /** Assignment operator
0052    * @param id source det id
0053    */
0054   EcalScDetId& operator=(const DetId& id);
0055 
0056   /** Gets the subdetector
0057    * @return subdetectot ID, that is EcalEndcap
0058    */
0059   EcalSubdetector subdet() const { return EcalSubdetector(subdetId()); }
0060 
0061   /** Gets the z-side of the crystal (1/-1)
0062    * @return -1 for EE-, +1 for EE+
0063    */
0064   int zside() const { return (id_ & 0x4000) ? (1) : (-1); }
0065 
0066   /** Gets the crystal x-index.
0067    * @see EcalDetId(int, int, int) for x-index definition
0068    * @return x-index
0069    */
0070   int ix() const { return (id_ >> 7) & 0x7F; }
0071 
0072   /** Get the crystal y-index
0073    * @see EcalDetId(int, int, int) for y-index definition.
0074    * @return y-index
0075    */
0076   int iy() const { return id_ & 0x7F; }
0077 
0078   /** Gets the quadrant of the DetId.
0079    *
0080    * Quadrant number definition for EE+, x and y in std CMS coordinates:
0081    *
0082    * \verbatim
0083    *                 A y
0084    *                 |
0085    *          Q2     |    Q1
0086    *                 |
0087    *       ----------o---------> x
0088    *                 |
0089    *          Q3     |    Q4
0090    *                 |
0091    * \endverbatim
0092    * This method will return the same quadrant number independently of
0093    * z: that is two supercrystals which are face to face will be considered
0094    * will have the same quadrant number. It is not clear it is the correct
0095    * or usual definition.
0096    * @see EEDetId::iquadrant()
0097    * @return quadrant number, from 1 to 4.
0098    * @deprecated This method might be withdraw in a future release
0099    */
0100   int iquadrant() const;
0101 
0102   /** Gets a compact index for arrays. Index runs from 0 to 623.
0103    * They are ordered by increasing z (EE- then EE+), then for
0104    * same z by increasing y. then for same z and y by increasing x
0105    */
0106   int hashedIndex() const {
0107     checkHashedIndexMap();
0108     if (!validDetId(ix(), iy(), zside()))
0109       return -1;
0110     return xyz2HashedIndex[ix() - IX_MIN][iy() - IY_MIN][zside() > 0 ? 1 : 0];
0111   }
0112 
0113   /** Gets EcalScDetId from hasedIndex as defined by hashedIndex method
0114    * @param hi hashed index
0115    * @return the EcalScDetId. If hi is invalid return a null EcalScDetId.
0116    */
0117   static EcalScDetId unhashIndex(int hi) {
0118     checkHashedIndexMap();
0119     if (hi < 0 || hi >= kSizeForDenseIndexing)
0120       return EcalScDetId();
0121     return hashedIndex2DetId[hi];
0122   }
0123 
0124   /** Same as hashed index.
0125    * @return the dense/hashed index
0126    */
0127   uint32_t denseIndex() const { return hashedIndex(); }
0128 
0129   /** Validates a hashed index.
0130    * @param din hashed index to validate
0131    * @return true if the index is valid, false if it is invalid.
0132    */
0133   static bool validDenseIndex(uint32_t din) { return din < kSizeForDenseIndexing; }
0134 
0135   /** Validates a hashed index.
0136    * @param hi hashed index to validate
0137    * @return true if the index is valid, false if it is invalid.
0138    */
0139   static bool validHashIndex(int hi) { return validDenseIndex(hi); }
0140 
0141   /** Number of supercrystals per endcap
0142    */
0143   static const int SC_PER_EE_CNT = 312;
0144 
0145   /** Lower bound of EE supercrystal x-index
0146    */
0147   static const int IX_MIN = 1;
0148 
0149   /** Lower bound of EE supercrystal y-index
0150    */
0151   static const int IY_MIN = 1;
0152 
0153   /** Upper bound of EE crystal y-index
0154    */
0155   static const int IX_MAX = 20;
0156 
0157   /** Upper bound of EE crystal y-index
0158    */
0159   static const int IY_MAX = 20;
0160 
0161   /** Lower bound for hashed/dense index
0162    */
0163   static const int IHASHED_MIN = 0;
0164 
0165   /** Upper bound for hashed/dense index
0166    */
0167   static const int IHASHED_MAX = SC_PER_EE_CNT * 2 - 1;
0168 
0169   /** Checks validity of a crystal (x,y.z) index triplet.
0170    * @param ix supercrystal x-index
0171    * @param iy supercrystal y-index
0172    * @param iz supercrystal z-index (aka z-side)
0173    * @see EEDetId(int, int, int) for index definition
0174    * @return true if valid, false otherwise
0175    */
0176   static bool validDetId(int ix, int iy, int iz);
0177 
0178 private:
0179   /** Initializes x,y,z <-> hashed index map if not yet done.
0180    */
0181   static void checkHashedIndexMap();
0182 
0183   //fields
0184 public:
0185   enum {
0186     /** Number of dense supercrystal indices.
0187      */
0188     kSizeForDenseIndexing = SC_PER_EE_CNT * 2
0189   };
0190 
0191 private:
0192   static const int nEndcaps = 2;
0193 
0194   /** Map of z,x,y index to hashed index. See hashedIndex/
0195    */
0196   CMS_THREAD_SAFE static short xyz2HashedIndex[IX_MAX][IY_MAX][nEndcaps];
0197 
0198   /** Map of hased index to x,y,z. See hashedIndex/
0199    */
0200   CMS_THREAD_SAFE static EcalScDetId hashedIndex2DetId[kSizeForDenseIndexing];
0201 
0202   /*The two arrays are thread safe since they are filled safely using std::call_once and
0203     then only read and never modified.
0204    */
0205 };
0206 
0207 std::ostream& operator<<(std::ostream& s, const EcalScDetId& id);
0208 
0209 #endif  //EcalDetId_EcalScDetId_h not defined