CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 
12 
14 }
15 
16 EcalScDetId::EcalScDetId(uint32_t rawid) : DetId(rawid) {
17 }
18 
19 EcalScDetId::EcalScDetId(int ix, int iy, int iz) : DetId(Ecal,EcalEndcap)
20 {
21  if(!validDetId(ix,iy,iz))
22  {
23  throw cms::Exception("InvalidDetId") << "EcalScDetId: Cannot create object. Indexes out of bounds \n"
24  << "x = " << ix << " y = " << iy << " z = " << iz;
25  }
26  const int scBit = 1<<15; //bit set to 1 to distinguish from crystal id (EEDetId)
27  // and for a reasonale behaviour of DetId ccomparison operators.
28  id_|=(iy&0x7f)|((ix&0x7f)<<7)|((iz>0)?(1<<14):(0))|scBit;
29 }
30 
32  if (!gen.null() && (gen.det()!=Ecal || gen.subdetId()!=EcalEndcap)) {
33  throw cms::Exception("InvalidDetId");
34  }
35  id_=gen.rawId();
36 }
37 
39  if (!gen.null() && ( gen.det()!=Ecal || gen.subdetId()!=EcalEndcap )) {
40  throw cms::Exception("InvalidDetId");
41  }
42  id_=gen.rawId();
43  return *this;
44 }
45 
47  const int xMiddle = IX_MAX/2; //y = 0 between xMiddle and xMiddle+1
48  const int yMiddle = IY_MAX/2; //x = 0 between yMiddle and yMiddle+1
49  if (iy()>yMiddle){// y>0
50  if(ix()>xMiddle) // A y
51  return 1; // |
52  else // Q2 | Q1
53  return 2; // |
54  } else{// y<0 // ----------o---------> x
55  if(ix()>xMiddle) // |
56  return 4; // Q3 | Q4
57  else // |
58  return 3;
59  }
60  //Should never be reached
61  return -1;
62 }
63 
64 bool EcalScDetId::validDetId(int iX, int iY, int iZ) {
65  static const char endcapMap[401] = {
66  " XXXXXX "
67  " XXXXXXXXXXXX "
68  " XXXXXXXXXXXXXX "
69  " XXXXXXXXXXXXXXXX "
70  " XXXXXXXXXXXXXXXXXX "
71  " XXXXXXXXXXXXXXXXXX " // Z
72  " XXXXXXXXXXXXXXXXXX " // x-----> X
73  "XXXXXXXXXXXXXXXXXXXX" // |
74  "XXXXXXXXX XXXXXXXXX" // |
75  "XXXXXXXX XXXXXXXX"//_ // |
76  "XXXXXXXX XXXXXXXX" // V Y
77  "XXXXXXXXX XXXXXXXXX"
78  "XXXXXXXXXXXXXXXXXXXX"
79  " XXXXXXXXXXXXXXXXXX "
80  " XXXXXXXXXXXXXXXXXX "
81  " XXXXXXXXXXXXXXXXXX "
82  " XXXXXXXXXXXXXXXX "
83  " XXXXXXXXXXXXXX "
84  " XXXXXXXXXXXX "
85  " XXXXXX "};
86 
87  return abs(iZ)==1 && endcapMap[iX-1+(iY-1)*20]!=' ';
88 }
89 
90 std::ostream& operator<<(std::ostream& s,const EcalScDetId& id) {
91  return s << "(EE iz " << ((id.zside()>0)?("+ "):("- ")) << " ix " << id.ix() << " , iy " << id.iy() << ')';
92 }
93 
94 //NOTE: When looping is possible in constexpr, this should be changed to one
95 static std::once_flag initializedFlag;
97  std::call_once(initializedFlag, []()
98  {
99  int hashedIndex = -1;
100  for(int iZ = -1; iZ <= +1; iZ+=2){
101  for(int iY = IY_MIN; iY <= IY_MAX; ++iY){
102  for(int iX = IX_MIN; iX <= IX_MAX; ++iX){
103  if(validDetId(iX,iY,iZ)){
104  xyz2HashedIndex[iX-IX_MIN][iY-IY_MIN][iZ>0?1:0] = ++hashedIndex;
105  assert((unsigned)hashedIndex < sizeof(hashedIndex2DetId)/sizeof(hashedIndex2DetId[0]));
107  }
108  }
109  }
110  }
111  });
112 }
static bool validDetId(int ix, int iy, int iz)
Definition: EcalScDetId.cc:64
EcalScDetId & operator=(const DetId &id)
Definition: EcalScDetId.cc:38
static EcalScDetId hashedIndex2DetId[kSizeForDenseIndexing]
Definition: EcalScDetId.h:202
static std::once_flag initializedFlag
Definition: EcalScDetId.cc:95
static const int IY_MIN
Definition: EcalScDetId.h:152
std::ostream & operator<<(std::ostream &out, const ALILine &li)
Definition: ALILine.cc:187
uint32_t rawId() const
get the raw id
Definition: DetId.h:43
static const int IX_MIN
Definition: EcalScDetId.h:148
int ix() const
Definition: EcalScDetId.h:71
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
static const int IY_MAX
Definition: EcalScDetId.h:160
static const int nEndcaps
Definition: EcalScDetId.h:194
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:37
int hashedIndex() const
Definition: EcalScDetId.h:108
int iy() const
Definition: EcalScDetId.h:77
Definition: DetId.h:18
static void checkHashedIndexMap()
Definition: EcalScDetId.cc:96
uint32_t id_
Definition: DetId.h:55
bool null() const
is this a null id ?
Definition: DetId.h:45
static const int IX_MAX
Definition: EcalScDetId.h:156
Detector det() const
get the detector field from this detid
Definition: DetId.h:35
int iquadrant() const
Definition: EcalScDetId.cc:46
static short xyz2HashedIndex[IX_MAX][IY_MAX][nEndcaps]
Definition: EcalScDetId.h:198