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 <iostream>
5 #include <cassert>
6 
8 
9 EcalScDetId EcalScDetId::hashedIndex2DetId[kSizeForDenseIndexing];
10 
11 
13 }
14 
15 EcalScDetId::EcalScDetId(uint32_t rawid) : DetId(rawid) {
16 }
17 
18 EcalScDetId::EcalScDetId(int ix, int iy, int iz) : DetId(Ecal,EcalEndcap)
19 {
20  if(!validDetId(ix,iy,iz))
21  {
22  throw cms::Exception("InvalidDetId") << "EcalScDetId: Cannot create object. Indexes out of bounds \n"
23  << "x = " << ix << " y = " << iy << " z = " << iz;
24  }
25  const int scBit = 1<<15; //bit set to 1 to distinguish from crystal id (EEDetId)
26  // and for a reasonale behaviour of DetId ccomparison operators.
27  id_|=(iy&0x7f)|((ix&0x7f)<<7)|((iz>0)?(1<<14):(0))|scBit;
28 }
29 
31  if (!gen.null() && (gen.det()!=Ecal || gen.subdetId()!=EcalEndcap)) {
32  throw cms::Exception("InvalidDetId");
33  }
34  id_=gen.rawId();
35 }
36 
38  if (!gen.null() && ( gen.det()!=Ecal || gen.subdetId()!=EcalEndcap )) {
39  throw cms::Exception("InvalidDetId");
40  }
41  id_=gen.rawId();
42  return *this;
43 }
44 
46  const int xMiddle = IX_MAX/2; //y = 0 between xMiddle and xMiddle+1
47  const int yMiddle = IY_MAX/2; //x = 0 between yMiddle and yMiddle+1
48  if (iy()>yMiddle){// y>0
49  if(ix()>xMiddle) // A y
50  return 1; // |
51  else // Q2 | Q1
52  return 2; // |
53  } else{// y<0 // ----------o---------> x
54  if(ix()>xMiddle) // |
55  return 4; // Q3 | Q4
56  else // |
57  return 3;
58  }
59  //Should never be reached
60  return -1;
61 }
62 
63 bool EcalScDetId::validDetId(int iX, int iY, int iZ) {
64  static const char endcapMap[401] = {
65  " XXXXXX "
66  " XXXXXXXXXXXX "
67  " XXXXXXXXXXXXXX "
68  " XXXXXXXXXXXXXXXX "
69  " XXXXXXXXXXXXXXXXXX "
70  " XXXXXXXXXXXXXXXXXX " // Z
71  " XXXXXXXXXXXXXXXXXX " // x-----> X
72  "XXXXXXXXXXXXXXXXXXXX" // |
73  "XXXXXXXXX XXXXXXXXX" // |
74  "XXXXXXXX XXXXXXXX"//_ // |
75  "XXXXXXXX XXXXXXXX" // V Y
76  "XXXXXXXXX XXXXXXXXX"
77  "XXXXXXXXXXXXXXXXXXXX"
78  " XXXXXXXXXXXXXXXXXX "
79  " XXXXXXXXXXXXXXXXXX "
80  " XXXXXXXXXXXXXXXXXX "
81  " XXXXXXXXXXXXXXXX "
82  " XXXXXXXXXXXXXX "
83  " XXXXXXXXXXXX "
84  " XXXXXX "};
85 
86  return abs(iZ)==1 && endcapMap[iX-1+(iY-1)*20]!=' ';
87 }
88 
89 std::ostream& operator<<(std::ostream& s,const EcalScDetId& id) {
90  return s << "(EE iz " << ((id.zside()>0)?("+ "):("- ")) << " ix " << id.ix() << " , iy " << id.iy() << ')';
91 }
92 
94  static bool initialized = false;
95  if(initialized) return;
96  int hashedIndex = -1;
97  for(int iZ = -1; iZ <= +1; iZ+=2){
98  for(int iY = IY_MIN; iY <= IY_MAX; ++iY){
99  for(int iX = IX_MIN; iX <= IX_MAX; ++iX){
100  if(validDetId(iX,iY,iZ)){
101  xyz2HashedIndex[iX-IX_MIN][iY-IY_MIN][iZ>0?1:0] = ++hashedIndex;
102  assert((unsigned)hashedIndex < sizeof(hashedIndex2DetId)/sizeof(hashedIndex2DetId[0]));
104  }
105  }
106  }
107  }
108  initialized = true;
109 }
static bool validDetId(int ix, int iy, int iz)
Definition: EcalScDetId.cc:63
EcalScDetId & operator=(const DetId &id)
Definition: EcalScDetId.cc:37
#define abs(x)
Definition: mlp_lapack.h:159
static EcalScDetId hashedIndex2DetId[kSizeForDenseIndexing]
Definition: EcalScDetId.h:203
static const int IY_MIN
Definition: EcalScDetId.h:153
std::ostream & operator<<(std::ostream &out, const ALILine &li)
Definition: ALILine.cc:187
uint32_t rawId() const
get the raw id
Definition: DetId.h:45
static const int IX_MIN
Definition: EcalScDetId.h:149
int ix() const
Definition: EcalScDetId.h:72
static const int IY_MAX
Definition: EcalScDetId.h:161
static const int nEndcaps
Definition: EcalScDetId.h:195
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:39
int hashedIndex() const
Definition: EcalScDetId.h:109
int iy() const
Definition: EcalScDetId.h:78
Definition: DetId.h:20
static void checkHashedIndexMap()
Definition: EcalScDetId.cc:93
uint32_t id_
Definition: DetId.h:57
bool null() const
is this a null id ?
Definition: DetId.h:47
static const int IX_MAX
Definition: EcalScDetId.h:157
Detector det() const
get the detector field from this detid
Definition: DetId.h:37
int iquadrant() const
Definition: EcalScDetId.cc:45
static short xyz2HashedIndex[IX_MAX][IY_MAX][nEndcaps]
Definition: EcalScDetId.h:199