CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EBDetId.cc
Go to the documentation of this file.
3 
4 //#include <iostream>
5 #include <algorithm>
6 const int EBDetId::kModuleBoundaries[4] = { 25, 45, 65, 85 };
7 
8 // pi / 180.
9 const float EBDetId::crystalUnitToEta = 0.017453292519943295;
10 
11 EBDetId
13 {
14  const int pseudo_eta = hi/MAX_IPHI - MAX_IETA;
15  return ( validHashIndex( hi ) ?
16  EBDetId(pseudo_eta<0 ? pseudo_eta : pseudo_eta+1, hi%MAX_IPHI+1) :
17  EBDetId() ) ;
18 }
19 
20 EBDetId::EBDetId(int index1, int index2, int mode)
21  : DetId(Ecal,EcalBarrel)
22 {
23  int crystal_ieta;
24  int crystal_iphi;
25  if (mode == ETAPHIMODE) {
26  crystal_ieta = index1;
27  crystal_iphi = index2;
28  } else if (mode == SMCRYSTALMODE) {
29  int SM = index1;
30  int crystal = index2;
31  int i = (int) floor((crystal-1) / kCrystalsInPhi);
32  int j = ((crystal-1) - (kCrystalsInPhi*i));
33  if (SM <= 18) {
34  crystal_ieta = i + 1;
35  crystal_iphi = ((SM-1) * kCrystalsInPhi) + (kCrystalsInPhi-j);
36  } else {
37  crystal_ieta = -(i+1);
38  crystal_iphi = ((SM-19) * kCrystalsInPhi) + j+1;
39  }
40  } else {
41  throw cms::Exception("InvalidDetId") << "EBDetId: Cannot create object. Unknown mode for (int, int) constructor.";
42  }
43 
44  if ( !validDetId(crystal_ieta, crystal_iphi) ) {
45  // std::cout << "crystal_eta " << crystal_ieta << "crystal_phi " << crystal_iphi << std::endl;
46  throw cms::Exception("InvalidDetId") << "EBDetId: Cannot create object. Indexes out of bounds \n"
47  << "eta = " << crystal_ieta << " phi = " << crystal_iphi;
48  }
49  id_|=((crystal_ieta>0)?(0x10000|(crystal_ieta<<9)):((-crystal_ieta)<<9))|(crystal_iphi&0x1FF);
50 }
51 
52 EBDetId::EBDetId(const DetId& gen) {
53  if (!gen.null() && ( gen.det()!=Ecal || gen.subdetId()!=EcalBarrel )) {
54  throw cms::Exception("InvalidDetId");
55  }
56  id_=gen.rawId();
57 }
58 
59 bool EBDetId::validDetId(int i, int j) {
60 
61  bool valid = true;
62  if (i < -MAX_IETA || i == 0 || i > MAX_IETA ||
63  j < MIN_IPHI || j > MAX_IPHI) {
64  valid = false;
65  }
66  return valid;
67 
68 }
69 
71  if (!gen.null() && ( gen.det()!=Ecal || gen.subdetId()!=EcalBarrel )) {
72  throw cms::Exception("InvalidDetId");
73  }
74  id_=gen.rawId();
75  return *this;
76 }
77 
78 //New SM numbering scheme. Avoids discontinuity in phi crossing \eta=0
79 int EBDetId::ism() const {
80  int id = ( iphi() - 1 ) / kCrystalsInPhi + 1;
81  if ( zside() < 0 ) id += 18;
82  return id;
83 }
84 
85 int EBDetId::im() const {
86  for (int i=0; i < 4 ; i++)
87  if ( ietaAbs() <= kModuleBoundaries[i] )
88  return i+1;
89  //Shold never be reached!
90  return -1;
91 }
92 
93 //Following TB 2004 numbering scheme
94 int EBDetId::ic() const {
95  int ie = ietaAbs() -1;
96  int ip;
97  if (zside() < 0) {
98  ip = (( iphi() -1 ) % kCrystalsInPhi ) + 1;
99  } else {
100  ip = kCrystalsInPhi - ((iphi() -1 ) % kCrystalsInPhi );
101  }
102 
103  return (ie * kCrystalsInPhi) + ip;
104 }
105 
106 //Maintains SM crystals in bunch of 1700 indices
107 int EBDetId::numberBySM() const {
108  return (ism()-1) * kCrystalsPerSM + ic() -1;
109 }
110 
111 EBDetId EBDetId::offsetBy(int nrStepsEta, int nrStepsPhi ) const
112 {
113  int newEta = ieta()+nrStepsEta;
114  if( newEta*ieta() <= 0 ) {
115  if( ieta() < 0 ) {
116  newEta++;
117  } else if ( ieta() > 0 ) {
118  newEta--;
119  }
120  }
121  int newPhi = iphi() + nrStepsPhi;
122  while ( newPhi>360 ) newPhi -= 360;
123  while ( newPhi<=0 ) newPhi += 360;
124 
125  if( validDetId( newEta, newPhi ) ) {
126  return EBDetId( newEta, newPhi);
127  } else {
128  return EBDetId(0);
129  }
130 }
131 
133 {
134  int newEta = ieta()*-1;
135  if( validDetId( newEta, iphi() ) ) {
136  return EBDetId( newEta, iphi() );
137  } else {
138  return EBDetId(0);
139  }
140 }
141 
142 
143 DetId EBDetId::offsetBy(const DetId startId, int nrStepsEta, int nrStepsPhi )
144 {
145  if( startId.det() == DetId::Ecal && startId.subdetId() == EcalBarrel ) {
146  EBDetId ebStartId(startId);
147  return ebStartId.offsetBy( nrStepsEta, nrStepsPhi ).rawId();
148  } else {
149  return DetId(0);
150  }
151 }
152 
154 {
155  if( startId.det() == DetId::Ecal && startId.subdetId() == EcalBarrel ) {
156  EBDetId ebStartId(startId);
157  return ebStartId.switchZSide().rawId();
158  } else {
159  return DetId(0);
160  }
161 }
162 
163 //corrects for HB/EB differing iphi=1
164 int EBDetId::tower_iphi() const {
165  int iphi_simple=((iphi()-1)/5)+1;
166  iphi_simple-=2;
167  return ((iphi_simple<=0)?(iphi_simple+72):(iphi_simple));
168 }
169 
170 
172  return isNextToEtaBoundary( id ) || isNextToPhiBoundary( id );
173 }
174 
176  int ieta = id.ietaSM();
177  return ieta == 1 || std::binary_search( kModuleBoundaries, kModuleBoundaries + 4, ieta ) || ieta == 85;
178 }
179 
181  int iphi = id.iphiSM();
182  return iphi == 1 || iphi == 20;
183 }
184 
186 {
187  if (a.ieta() * b.ieta() > 0)
188  return abs(a.ieta()-b.ieta());
189  else
190  return abs(a.ieta()-b.ieta())-1;
191 }
192 
194 {
195  if (abs(a.iphi() -b.iphi()) > 180)
196  return abs(a.iphi() - b.iphi()) - 180;
197  else
198  return abs(a.iphi()-b.iphi());
199 }
200 
201 float EBDetId::approxEta( const DetId id ) {
202  if( id.subdetId() == EcalBarrel ) {
203  EBDetId ebId( id );
204  return ebId.approxEta();
205  } else {
206  return 0;
207  }
208 }
209 
210 std::ostream& operator<<(std::ostream& s,const EBDetId& id) {
211  return s << "(EB ieta " << id.ieta() << ", iphi" << id.iphi()
212  << " ; ism " << id.ism() << " , ic " << id.ic() << ')';
213 }
214 
float approxEta() const
Definition: EBDetId.h:93
static bool validDetId(int i, int j)
check if a valid index combination
Definition: EBDetId.cc:59
int i
Definition: DBlmapReader.cc:9
static bool isNextToEtaBoundary(EBDetId id)
Definition: EBDetId.cc:175
int tower_iphi() const
get the HCAL/trigger iphi of this crystal
Definition: EBDetId.cc:164
EBDetId switchZSide() const
Definition: EBDetId.cc:132
#define abs(x)
Definition: mlp_lapack.h:159
int numberBySM() const
Definition: EBDetId.cc:107
static const int kCrystalsPerSM
Definition: EBDetId.h:130
DetId()
Create an empty or null id (also for persistence)
Definition: DetId.h:28
std::ostream & operator<<(std::ostream &out, const ALILine &li)
Definition: ALILine.cc:187
EBDetId()
Definition: EBDetId.h:24
int ism() const
get the ECAL/SM id
Definition: EBDetId.cc:79
int iphi() const
get the crystal iphi
Definition: EBDetId.h:46
uint32_t rawId() const
get the raw id
Definition: DetId.h:45
int im() const
get the number of module inside the SM (1-4)
Definition: EBDetId.cc:85
static const int kCrystalsInPhi
Definition: EBDetId.h:128
static int distanceEta(const EBDetId &a, const EBDetId &b)
Definition: EBDetId.cc:185
static bool isNextToBoundary(EBDetId id)
Definition: EBDetId.cc:171
static int distancePhi(const EBDetId &a, const EBDetId &b)
Definition: EBDetId.cc:193
static bool isNextToPhiBoundary(EBDetId id)
Definition: EBDetId.cc:180
int j
Definition: DBlmapReader.cc:9
static const int kModuleBoundaries[4]
Definition: EBDetId.h:127
static const float crystalUnitToEta
Definition: EBDetId.h:139
EBDetId offsetBy(int nrStepsEta, int nrStepsPhi) const
Definition: EBDetId.cc:111
int ieta() const
get the crystal ieta
Definition: EBDetId.h:44
EBDetId & operator=(const DetId &id)
Definition: EBDetId.cc:70
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:39
static const int ETAPHIMODE
Definition: EBDetId.h:145
int ic() const
get ECAL/crystal number inside SM
Definition: EBDetId.cc:94
Definition: DetId.h:20
static const int MAX_IPHI
Definition: EBDetId.h:123
uint32_t id_
Definition: DetId.h:57
static EBDetId unhashIndex(int hi)
get a DetId from a compact index for arrays
Definition: EBDetId.cc:12
bool null() const
is this a null id ?
Definition: DetId.h:47
static const int MAX_IETA
Definition: EBDetId.h:122
int mode
Definition: AMPTWrapper.h:139
double b
Definition: hdecay.h:120
static bool validHashIndex(int i)
Definition: EBDetId.h:103
double a
Definition: hdecay.h:121
string s
Definition: asciidump.py:422
static const int SMCRYSTALMODE
Definition: EBDetId.h:146
Detector det() const
get the detector field from this detid
Definition: DetId.h:37
int ietaAbs() const
get the absolute value of the crystal ieta
Definition: EBDetId.h:42
int zside() const
get the z-side of the crystal (1/-1)
Definition: EBDetId.h:40