CMS 3D CMS Logo

EcalScDetId.cc
Go to the documentation of this file.
3 
4 #include <ostream>
5 #include <cassert>
6 #include <mutex>
7 
9 
10 EcalScDetId EcalScDetId::hashedIndex2DetId[kSizeForDenseIndexing];
11 
13 
14 EcalScDetId::EcalScDetId(uint32_t rawid) : DetId(rawid) {}
15 
16 EcalScDetId::EcalScDetId(int ix, int iy, int iz) : DetId(Ecal, EcalEndcap) {
17  if (!validDetId(ix, iy, iz)) {
18  throw cms::Exception("InvalidDetId") << "EcalScDetId: Cannot create object. Indexes out of bounds \n"
19  << "x = " << ix << " y = " << iy << " z = " << iz;
20  }
21  const int scBit = 1 << 15; //bit set to 1 to distinguish from crystal id (EEDetId)
22  // and for a reasonale behaviour of DetId ccomparison operators.
23  id_ |= (iy & 0x7f) | ((ix & 0x7f) << 7) | ((iz > 0) ? (1 << 14) : (0)) | scBit;
24 }
25 
27  if (!gen.null() && (gen.det() != Ecal || gen.subdetId() != EcalEndcap)) {
28  throw cms::Exception("InvalidDetId");
29  }
30  id_ = gen.rawId();
31 }
32 
34  if (!gen.null() && (gen.det() != Ecal || gen.subdetId() != EcalEndcap)) {
35  throw cms::Exception("InvalidDetId");
36  }
37  id_ = gen.rawId();
38  return *this;
39 }
40 
42  const int xMiddle = IX_MAX / 2; //y = 0 between xMiddle and xMiddle+1
43  const int yMiddle = IY_MAX / 2; //x = 0 between yMiddle and yMiddle+1
44  if (iy() > yMiddle) { // y>0
45  if (ix() > xMiddle) // A y
46  return 1; // |
47  else // Q2 | Q1
48  return 2; // |
49  } else { // y<0 // ----------o---------> x
50  if (ix() > xMiddle) // |
51  return 4; // Q3 | Q4
52  else // |
53  return 3;
54  }
55  //Should never be reached
56  return -1;
57 }
58 
59 bool EcalScDetId::validDetId(int iX, int iY, int iZ) {
60  static const char endcapMap[401] = {
61  " XXXXXX "
62  " XXXXXXXXXXXX "
63  " XXXXXXXXXXXXXX "
64  " XXXXXXXXXXXXXXXX "
65  " XXXXXXXXXXXXXXXXXX "
66  " XXXXXXXXXXXXXXXXXX " // Z
67  " XXXXXXXXXXXXXXXXXX " // x-----> X
68  "XXXXXXXXXXXXXXXXXXXX" // |
69  "XXXXXXXXX XXXXXXXXX" // |
70  "XXXXXXXX XXXXXXXX" //_ // |
71  "XXXXXXXX XXXXXXXX" // V Y
72  "XXXXXXXXX XXXXXXXXX"
73  "XXXXXXXXXXXXXXXXXXXX"
74  " XXXXXXXXXXXXXXXXXX "
75  " XXXXXXXXXXXXXXXXXX "
76  " XXXXXXXXXXXXXXXXXX "
77  " XXXXXXXXXXXXXXXX "
78  " XXXXXXXXXXXXXX "
79  " XXXXXXXXXXXX "
80  " XXXXXX "};
81 
82  return abs(iZ) == 1 && endcapMap[iX - 1 + (iY - 1) * 20] != ' ';
83 }
84 
85 std::ostream& operator<<(std::ostream& s, const EcalScDetId& id) {
86  return s << "(EE iz " << ((id.zside() > 0) ? ("+ ") : ("- ")) << " ix " << id.ix() << " , iy " << id.iy() << ')';
87 }
88 
89 //NOTE: When looping is possible in constexpr, this should be changed to one
90 static std::once_flag initializedFlag;
92  std::call_once(initializedFlag, []() {
93  int hashedIndex = -1;
94  for (int iZ = -1; iZ <= +1; iZ += 2) {
95  for (int iY = IY_MIN; iY <= IY_MAX; ++iY) {
96  for (int iX = IX_MIN; iX <= IX_MAX; ++iX) {
97  if (validDetId(iX, iY, iZ)) {
98  xyz2HashedIndex[iX - IX_MIN][iY - IY_MIN][iZ > 0 ? 1 : 0] = ++hashedIndex;
99  assert((unsigned)hashedIndex < sizeof(hashedIndex2DetId) / sizeof(hashedIndex2DetId[0]));
101  }
102  }
103  }
104  }
105  });
106 }
static bool validDetId(int ix, int iy, int iz)
Definition: EcalScDetId.cc:59
EcalScDetId & operator=(const DetId &id)
Definition: EcalScDetId.cc:33
static EcalScDetId hashedIndex2DetId[kSizeForDenseIndexing]
Definition: EcalScDetId.h:200
static std::once_flag initializedFlag
Definition: EcalScDetId.cc:90
static const int IY_MIN
Definition: EcalScDetId.h:151
assert(be >=bs)
static const int IX_MIN
Definition: EcalScDetId.h:147
int hashedIndex() const
Definition: EcalScDetId.h:106
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
int iy() const
Definition: EcalScDetId.h:76
static const int IY_MAX
Definition: EcalScDetId.h:159
static const int nEndcaps
Definition: EcalScDetId.h:192
std::ostream & operator<<(std::ostream &s, const EcalScDetId &id)
Definition: EcalScDetId.cc:85
ALPAKA_FN_ACC ALPAKA_FN_INLINE uint32_t ix(uint32_t id)
Definition: DetId.h:17
static void checkHashedIndexMap()
Definition: EcalScDetId.cc:91
uint32_t id_
Definition: DetId.h:69
static const int IX_MAX
Definition: EcalScDetId.h:155
ALPAKA_FN_ACC ALPAKA_FN_INLINE uint32_t iy(uint32_t id)
int iquadrant() const
Definition: EcalScDetId.cc:41
int ix() const
Definition: EcalScDetId.h:70
static short xyz2HashedIndex[IX_MAX][IY_MAX][nEndcaps]
Definition: EcalScDetId.h:196