CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
HcalDetId.cc
Go to the documentation of this file.
3 #include <ostream>
4 
6 
8 }
9 
10 HcalDetId::HcalDetId(uint32_t rawid) : DetId(rawid) {
11 }
12 
13 HcalDetId::HcalDetId(HcalSubdetector subdet, int tower_ieta, int tower_iphi, int depth) : DetId(Hcal,subdet) {
14  // (no checking at this point!)
15  id_ |= ((depth&0x1F)<<14) |
16  ((tower_ieta>0)?(0x2000|(tower_ieta<<7)):((-tower_ieta)<<7)) |
17  (tower_iphi&0x7F);
18 }
19 
21  if (!gen.null()) {
23  if (gen.det()!=Hcal ||
24  (subdet!=HcalBarrel && subdet!=HcalEndcap &&
25  subdet!=HcalOuter && subdet!=HcalForward ))
26  {
27  throw cms::Exception("Invalid DetId") << "Cannot initialize HcalDetId from " << std::hex << gen.rawId() << std::dec;
28  }
29  }
30  id_=gen.rawId();
31 }
32 
34  if (!gen.null()) {
36  if (gen.det()!=Hcal ||
37  (subdet!=HcalBarrel && subdet!=HcalEndcap &&
38  subdet!=HcalOuter && subdet!=HcalForward ))
39  {
40  throw cms::Exception("Invalid DetId") << "Cannot assign HcalDetId from " << std::hex << gen.rawId() << std::dec;
41  }
42  }
43  id_=gen.rawId();
44  return (*this);
45 }
46 
48  int simple_iphi=((iphi()-1)*5)+1;
49  simple_iphi+=10;
50  return ((simple_iphi>360)?(simple_iphi-360):(simple_iphi));
51 }
52 
54  int simple_iphi=((iphi()-1)*5)+5;
55  simple_iphi+=10;
56  return ((simple_iphi>360)?(simple_iphi-360):(simple_iphi));
57 }
58 
59 std::ostream& operator<<(std::ostream& s,const HcalDetId& id) {
60  switch (id.subdet()) {
61  case(HcalBarrel) : return s << "(HB " << id.ieta() << ',' << id.iphi() << ',' << id.depth() << ')';
62  case(HcalEndcap) : return s << "(HE " << id.ieta() << ',' << id.iphi() << ',' << id.depth() << ')';
63  case(HcalForward) : return s << "(HF " << id.ieta() << ',' << id.iphi() << ',' << id.depth() << ')';
64  case(HcalOuter) : return s << "(HO " << id.ieta() << ',' << id.iphi() << ')';
65  default : return s << id.rawId();
66  }
67 }
68 
69 bool
71  int ies,
72  int ip,
73  int dp )
74 {
75  const int ie ( abs( ies ) ) ;
76 
77  return ( ( ip >= 1 ) &&
78  ( ip <= 72 ) &&
79  ( dp >= 1 ) &&
80  ( ie >= 1 ) &&
81  ( ( ( sd == HcalBarrel ) &&
82  ( ( ( ie <= 14 ) &&
83  ( dp == 1 ) ) ||
84  ( ( ( ie == 15 ) || ( ie == 16 ) ) &&
85  ( dp <= 2 ) ) ) ) ||
86  ( ( sd == HcalEndcap ) &&
87  ( ( ( ie == 16 ) &&
88  ( dp == 3 ) ) ||
89  ( ( ie == 17 ) &&
90  ( dp == 1 ) ) ||
91  ( ( ie >= 18 ) &&
92  ( ie <= 20 ) &&
93  ( dp <= 2 ) ) ||
94  ( ( ie >= 21 ) &&
95  ( ie <= 26 ) &&
96  ( dp <= 2 ) &&
97  ( ip%2 == 1 ) ) ||
98  ( ( ie >= 27 ) &&
99  ( ie <= 28 ) &&
100  ( dp <= 3 ) &&
101  ( ip%2 == 1 ) ) ||
102  ( ( ie == 29 ) &&
103  ( dp <= 2 ) &&
104  ( ip%2 == 1 ) ) ) ) ||
105  ( ( sd == HcalOuter ) &&
106  ( ie <= 15 ) &&
107  ( dp == 4 ) ) ||
108  ( ( sd == HcalForward ) &&
109  ( dp <= 2 ) &&
110  ( ( ( ie >= 29 ) &&
111  ( ie <= 39 ) &&
112  ( ip%2 == 1 ) ) ||
113  ( ( ie >= 40 ) &&
114  ( ie <= 41 ) &&
115  ( ip%4 == 3 ) ) ) ) ) ) ;
116 }
117 
118 int
120 {
121  const HcalSubdetector sd ( subdet() ) ;
122  const int ip ( iphi() ) ;
123  const int ie ( ietaAbs() ) ;
124  const int dp ( depth() ) ;
125  const int zn ( zside() < 0 ? 1 : 0 ) ;
126 
127  // HB valid DetIds: phi=1-72,eta=1-14,depth=1; phi=1-72,eta=15-16,depth=1-2
128 
129  // HE valid DetIds: phi=1-72,eta=16-17,depth=1; phi=1-72,eta=18-20,depth=1-2;
130  // phi=1-71(in steps of 2),eta=21-26,depth=1-2; phi=1-71(in steps of 2),eta=27-28,depth=1-3
131  // phi=1-71(in steps of 2),eta=29,depth=1-2
132 
133  // HO valid DetIds: phi=1-72,eta=1-15,depth=4!
134 
135  // HF valid DetIds: phi=1-71(in steps of 2),eta=29-39,depth=1-2; phi=3-71(in steps of 4),eta=40-41,depth=1-2
136 
137  return ( ( sd == HcalBarrel ) ?
138  ( ip - 1 )*18 + dp - 1 + ie - ( ie<16 ? 1 : 0 ) + zn*kHBhalf :
139  ( ( sd == HcalEndcap ) ?
140  2*kHBhalf + ( ip - 1 )*8 + ( ip/2 )*20 +
141  ( ( ie==16 || ie==17 ) ? ie - 16 :
142  ( ( ie>=18 && ie<=20 ) ? 2 + 2*( ie - 18 ) + dp - 1 :
143  ( ( ie>=21 && ie<=26 ) ? 8 + 2*( ie - 21 ) + dp - 1 :
144  ( ( ie>=27 && ie<=28 ) ? 20 + 3*( ie - 27 ) + dp - 1 :
145  26 + 2*( ie - 29 ) + dp - 1 ) ) ) ) + zn*kHEhalf :
146  ( ( sd == HcalOuter ) ?
147  2*kHBhalf + 2*kHEhalf + ( ip - 1 )*15 + ( ie - 1 ) + zn*kHOhalf :
148  ( ( sd == HcalForward ) ?
149  2*kHBhalf + 2*kHEhalf + 2*kHOhalf +
150  ( ( ip - 1 )/4 )*4 + ( ( ip - 1 )/2 )*22 +
151  2*( ie - 29 ) + ( dp - 1 ) + zn*kHFhalf : -1 ) ) ) ) ;
152 }
153 
154 HcalDetId
156 {
157  if( validDenseIndex( di ) )
158  {
160  int ie ( 0 ) ;
161  int ip ( 0 ) ;
162  int dp ( 0 ) ;
163  int in ( di ) ;
164  int iz ( 1 ) ;
165  if( in > 2*( kHBhalf + kHEhalf + kHOhalf ) - 1 )
166  {
167  sd = HcalForward ;
168  in -= 2*( kHBhalf + kHEhalf + kHOhalf ) ;
169  iz = ( in<kHFhalf ? 1 : -1 ) ;
170  in %= kHFhalf ;
171  ip = 4*( in/48 ) ;
172  in %= 48 ;
173  ip += 1 + ( in>21 ? 2 : 0 ) ;
174  if( 3 == ip%4 ) in -= 22 ;
175  ie = 29 + in/2 ;
176  dp = 1 + in%2 ;
177  }
178  else
179  {
180  if( in > 2*( kHBhalf + kHEhalf ) - 1 )
181  {
182  sd = HcalOuter ;
183  in -= 2*( kHBhalf + kHEhalf ) ;
184  iz = ( in<kHOhalf ? 1 : -1 ) ;
185  in %= kHOhalf ;
186  dp = 4 ;
187  ip = 1 + in/15 ;
188  ie = 1 + ( in - 15*( ip - 1 ) ) ;
189  }
190  else
191  {
192  if( in > 2*kHBhalf - 1 )
193  {
194  sd = HcalEndcap ;
195  in -= 2*kHBhalf ;
196  iz = ( in<kHEhalf ? 1 : -1 ) ;
197  in %= kHEhalf ;
198  ip = 2*( in/36 ) ;
199  in %= 36 ;
200  ip += 1 + in/28 ;
201  if( 0 == ip%2 ) in %= 28 ;
202  ie = 15 + ( in<2 ? 1 + in : 2 +
203  ( in<20 ? 1 + ( in - 2 )/2 : 9 +
204  ( in<26 ? 1 + ( in - 20 )/3 : 3 ) ) ) ;
205  dp = ( in<1 ? 3 :
206  ( in<2 ? 1 :
207  ( in<20 ? 1 + ( in - 2 )%2 :
208  ( in<26 ? 1 + ( in - 20 )%3 :
209  ( 1 + ( in - 26 )%2 ) ) ) ) ) ;
210  }
211  else // barrel
212  {
213  iz = ( di<kHBhalf ? 1 : -1 ) ;
214  in %= kHBhalf ;
215  ip = in/18 + 1 ;
216  in %= 18 ;
217  if( in < 14 )
218  {
219  dp = 1 ;
220  ie = in + 1 ;
221  }
222  else
223  {
224  in %= 14 ;
225  dp = 1 + in%2 ;
226  ie = 15 + in/2 ;
227  }
228  }
229  }
230  }
231  return HcalDetId( sd, iz*int(ie), ip, dp ) ;
232  }
233  else
234  {
235  return HcalDetId() ;
236  }
237 }
static const HcalDetId Undefined
Definition: HcalDetId.h:66
HcalDetId & operator=(const DetId &id)
Definition: HcalDetId.cc:33
HcalSubdetector subdet() const
get the subdetector
Definition: HcalDetId.h:32
int zside() const
get the z-side of the cell (1/-1)
Definition: HcalDetId.h:34
int crystal_iphi_low() const
get the smallest crystal_iphi of the crystal in front of this tower (HB and HE tower 17 only) ...
Definition: HcalDetId.cc:47
#define abs(x)
Definition: mlp_lapack.h:159
std::ostream & operator<<(std::ostream &out, const ALILine &li)
Definition: ALILine.cc:187
static bool validDetId(HcalSubdetector subdet, int tower_ieta, int tower_iphi, int depth)
Definition: HcalDetId.cc:70
uint32_t rawId() const
get the raw id
Definition: DetId.h:45
HcalDetId()
Definition: HcalDetId.cc:7
int depth() const
get the tower depth
Definition: HcalDetId.h:42
static HcalDetId detIdFromDenseIndex(uint32_t di)
Definition: HcalDetId.cc:155
HcalSubdetector
Definition: HcalAssistant.h:32
static bool validDenseIndex(uint32_t din)
Definition: HcalDetId.h:62
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:39
int ietaAbs() const
get the absolute value of the cell ieta
Definition: HcalDetId.h:36
int iphi() const
get the cell iphi
Definition: HcalDetId.h:40
Definition: DetId.h:20
double sd
uint32_t id_
Definition: DetId.h:57
bool null() const
is this a null id ?
Definition: DetId.h:47
int crystal_iphi_high() const
get the largest crystal_iphi of the crystal in front of this tower (HB and HE tower 17 only) ...
Definition: HcalDetId.cc:53
Detector det() const
get the detector field from this detid
Definition: DetId.h:37
int hashed_index() const
Definition: HcalDetId.cc:119