CMS 3D CMS Logo

L1CaloGeometry.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: L1Geometry
4 // Class : L1CaloGeometry
5 //
6 // Implementation:
7 // <Notes on implementation>
8 //
9 // Original Author: Werner Sun
10 // Created: Mon Oct 23 21:52:36 EDT 2006
11 // $Id: L1CaloGeometry.cc,v 1.4 2009/09/28 22:59:14 wsun Exp $
12 //
13 
14 // system include files
15 #include <cmath>
16 
17 // user include files
19 
20 //
21 // constants, enums and typedefs
22 //
23 
24 //
25 // static data member definitions
26 //
27 
28 // double L1CaloGeometry::m_gctEmJetPhiOffset =
29 // -M_PI / L1CaloGeometry::kNumberGctEmJetPhiBins ;
30 // double L1CaloGeometry::m_gctEtSumPhiOffset = 0. ;
31 
32 // double L1CaloGeometry::m_gctEmJetPhiBinWidth =
33 // 2. * M_PI / L1CaloGeometry::kNumberGctEmJetPhiBins ;
34 // double L1CaloGeometry::m_gctEtSumPhiBinWidth =
35 // 2. * M_PI / L1CaloGeometry::kNumberGctEtSumPhiBins ;
36 
37 // double L1CaloGeometry::m_gctEtaBinBoundaries[
38 // kNumberGctCentralEtaBinsPerHalf + kNumberGctForwardEtaBinsPerHalf + 1 ] = {
39 // 0.0000,
40 // 0.3480,
41 // 0.6950,
42 // 1.0440,
43 // 1.3920,
44 // 1.7400,
45 // 2.1720,
46 // 3.0000,
47 // 3.5000,
48 // 4.0000,
49 // 4.5000,
50 // 5.0000 } ;
51 
52 //
53 // constructors and destructor
54 //
56  : m_version(kOrig), // if version is not in CondDB, set it to kOrig
57  m_numberGctEmJetPhiBins(0),
58  m_numberGctEtSumPhiBins(0),
59  m_numberGctHtSumPhiBins(0),
60  m_numberGctCentralEtaBinsPerHalf(0),
61  m_numberGctForwardEtaBinsPerHalf(0),
62  m_etaSignBitOffset(0),
63  m_gctEtaBinBoundaries(),
64  m_etaBinsPerHalf(0),
65  m_gctEmJetPhiBinWidth(0.),
66  m_gctEtSumPhiBinWidth(0.),
67  m_gctHtSumPhiBinWidth(0.),
68  m_gctEmJetPhiOffset(0.),
69  m_gctEtSumPhiOffset(0.),
70  m_gctHtSumPhiOffset(0.) {}
71 
73  double gctEmJetPhiBinOffset,
74  unsigned int numberGctEtSumPhiBins,
75  double gctEtSumPhiBinOffset,
76  unsigned int numberGctHtSumPhiBins,
77  double gctHtSumPhiBinOffset,
78  unsigned int numberGctCentralEtaBinsPerHalf,
79  unsigned int numberGctForwardEtaBinsPerHalf,
80  unsigned int etaSignBitOffset,
81  const std::vector<double>& gctEtaBinBoundaries)
83  m_numberGctEmJetPhiBins(numberGctEmJetPhiBins),
84  m_numberGctEtSumPhiBins(numberGctEtSumPhiBins),
85  m_numberGctHtSumPhiBins(numberGctHtSumPhiBins),
86  m_numberGctCentralEtaBinsPerHalf(numberGctCentralEtaBinsPerHalf),
87  m_numberGctForwardEtaBinsPerHalf(numberGctForwardEtaBinsPerHalf),
88  m_etaSignBitOffset(etaSignBitOffset),
89  m_gctEtaBinBoundaries(gctEtaBinBoundaries) {
91 
95 
96  m_gctEmJetPhiOffset = gctEmJetPhiBinOffset * m_gctEmJetPhiBinWidth;
97  m_gctEtSumPhiOffset = gctEtSumPhiBinOffset * m_gctEtSumPhiBinWidth;
98  m_gctHtSumPhiOffset = gctHtSumPhiBinOffset * m_gctHtSumPhiBinWidth;
99 }
100 
101 // L1CaloGeometry::L1CaloGeometry(const L1CaloGeometry& rhs)
102 // {
103 // // do actual copying here;
104 // }
105 
107 
108 //
109 // assignment operators
110 //
111 // const L1CaloGeometry& L1CaloGeometry::operator=(const L1CaloGeometry& rhs)
112 // {
113 // //An exception safe implementation is
114 // L1CaloGeometry temp(rhs);
115 // swap(rhs);
116 //
117 // return *this;
118 // }
119 
120 //
121 // member functions
122 //
123 
124 //
125 // const member functions
126 //
127 
129  int etaIndex;
130  double etaSign = 1.;
131  if (globalEtaIndex < m_etaBinsPerHalf) {
132  etaIndex = m_etaBinsPerHalf - globalEtaIndex - 1;
133  etaSign = -1.;
134  } else {
135  etaIndex = globalEtaIndex - m_etaBinsPerHalf;
136  }
137 
138  return 0.5 * etaSign * (m_gctEtaBinBoundaries[etaIndex] + m_gctEtaBinBoundaries[etaIndex + 1]);
139 }
140 
142  int etaIndex;
143  double etaSign = 1.;
144  if (globalEtaIndex < m_etaBinsPerHalf) {
145  etaIndex = m_etaBinsPerHalf - globalEtaIndex - 1;
146  etaSign = -1.;
147  } else {
148  etaIndex = globalEtaIndex - m_etaBinsPerHalf;
149  }
150 
151  return (etaSign > 0. ? m_gctEtaBinBoundaries[etaIndex] : -m_gctEtaBinBoundaries[etaIndex + 1]);
152 }
153 
155  int etaIndex;
156  double etaSign = 1.;
157  if (globalEtaIndex < m_etaBinsPerHalf) {
158  etaIndex = m_etaBinsPerHalf - globalEtaIndex - 1;
159  etaSign = -1.;
160  } else {
161  etaIndex = globalEtaIndex - m_etaBinsPerHalf;
162  }
163 
164  return (etaSign > 0. ? m_gctEtaBinBoundaries[etaIndex + 1] : -m_gctEtaBinBoundaries[etaIndex]);
165 }
166 
167 double L1CaloGeometry::etaBinCenter(unsigned int etaIndex, bool central) const {
168  // Central/tau jets and EM have etaIndex = 0-6 for eta = 0-3.
169  // Forward jets have etaIndex = 0-3 for eta = 3-5.
170  double etaSign = 1.;
171 
172  // Check sign BEFORE shifting forward jet bin index.
173  if (etaIndex >= m_etaSignBitOffset) {
174  etaSign = -1.;
175  etaIndex -= m_etaSignBitOffset;
176  }
177 
178  // Shift forward jet bin index AFTER checking sign bit.
179  if (!central) {
181  }
182 
183  return 0.5 * etaSign * (m_gctEtaBinBoundaries[etaIndex] + m_gctEtaBinBoundaries[etaIndex + 1]);
184 }
185 
186 double L1CaloGeometry::etaBinLowEdge(unsigned int etaIndex, bool central) const {
187  // Central/tau jets and EM have etaIndex = 0-6 for eta = 0-3.
188  // Forward jets have etaIndex = 0-3 for eta = 3-5.
189  double etaSign = 1.;
190 
191  // Check sign BEFORE shifting forward jet bin index.
192  if (etaIndex >= m_etaSignBitOffset) {
193  etaSign = -1.;
194  etaIndex -= m_etaSignBitOffset;
195  }
196 
197  // Shift forward jet bin index AFTER checking sign bit.
198  if (!central) {
200  }
201 
202  return (etaSign > 0. ? m_gctEtaBinBoundaries[etaIndex] : -m_gctEtaBinBoundaries[etaIndex + 1]);
203 }
204 
205 double L1CaloGeometry::etaBinHighEdge(unsigned int etaIndex, bool central) const {
206  // Central/tau jets and EM have etaIndex = 0-6 for eta = 0-3.
207  // Forward jets have etaIndex = 0-3 for eta = 3-5.
208  double etaSign = 1.;
209 
210  // Check sign BEFORE shifting forward jet bin index.
211  if (etaIndex >= m_etaSignBitOffset) {
212  etaSign = -1.;
213  etaIndex -= m_etaSignBitOffset;
214  }
215 
216  // Shift forward jet bin index AFTER checking sign bit.
217  if (!central) {
219  }
220 
221  return (etaSign > 0. ? m_gctEtaBinBoundaries[etaIndex + 1] : -m_gctEtaBinBoundaries[etaIndex]);
222 }
223 
224 double L1CaloGeometry::emJetPhiBinCenter(unsigned int phiIndex) const {
225  return ((double)phiIndex + 0.5) * m_gctEmJetPhiBinWidth + m_gctEmJetPhiOffset;
226 }
227 
228 double L1CaloGeometry::emJetPhiBinLowEdge(unsigned int phiIndex) const {
229  return ((double)phiIndex) * m_gctEmJetPhiBinWidth + m_gctEmJetPhiOffset;
230 }
231 
232 double L1CaloGeometry::emJetPhiBinHighEdge(unsigned int phiIndex) const {
233  return ((double)phiIndex + 1.) * m_gctEmJetPhiBinWidth + m_gctEmJetPhiOffset;
234 }
235 
236 double L1CaloGeometry::etSumPhiBinCenter(unsigned int phiIndex) const {
237  return ((double)phiIndex + 0.5) * m_gctEtSumPhiBinWidth + m_gctEtSumPhiOffset;
238 }
239 
240 double L1CaloGeometry::etSumPhiBinLowEdge(unsigned int phiIndex) const {
241  return ((double)phiIndex) * m_gctEtSumPhiBinWidth + m_gctEtSumPhiOffset;
242 }
243 
244 double L1CaloGeometry::etSumPhiBinHighEdge(unsigned int phiIndex) const {
245  return ((double)phiIndex + 1.) * m_gctEtSumPhiBinWidth + m_gctEtSumPhiOffset;
246 }
247 
248 double L1CaloGeometry::htSumPhiBinCenter(unsigned int phiIndex) const {
249  if (m_version == kOrig) {
250  return ((double)phiIndex + 0.5) * m_gctEtSumPhiBinWidth * 4. + m_gctEtSumPhiOffset;
251  } else {
252  return ((double)phiIndex + 0.5) * m_gctHtSumPhiBinWidth + m_gctHtSumPhiOffset;
253  }
254 }
255 
256 double L1CaloGeometry::htSumPhiBinLowEdge(unsigned int phiIndex) const {
257  if (m_version == kOrig) {
258  return ((double)phiIndex) * m_gctEtSumPhiBinWidth * 4. + m_gctEtSumPhiOffset;
259  } else {
260  return ((double)phiIndex) * m_gctHtSumPhiBinWidth + m_gctHtSumPhiOffset;
261  }
262 }
263 
264 double L1CaloGeometry::htSumPhiBinHighEdge(unsigned int phiIndex) const {
265  if (m_version == kOrig) {
266  return ((double)phiIndex + 1.) * m_gctEtSumPhiBinWidth * 4. + m_gctEtSumPhiOffset;
267  } else {
268  return ((double)phiIndex + 1.) * m_gctHtSumPhiBinWidth + m_gctHtSumPhiOffset;
269  }
270 }
271 
272 unsigned int L1CaloGeometry::etaIndex(const double& etaValue) const {
273  unsigned int etaIndex = 0;
274 
275  for (unsigned int i = 0; i < m_numberGctCentralEtaBinsPerHalf; ++i) {
276  if (fabs(etaValue) >= m_gctEtaBinBoundaries[i]) {
277  etaIndex = i;
278  }
279  }
280 
281  for (unsigned int i = 0; i < m_numberGctForwardEtaBinsPerHalf; ++i) {
282  if (fabs(etaValue) >= m_gctEtaBinBoundaries[i + m_numberGctCentralEtaBinsPerHalf]) {
283  etaIndex = i;
284  }
285  }
286 
287  if (etaValue < 0.) {
288  etaIndex += m_etaSignBitOffset;
289  }
290 
291  return etaIndex;
292 }
293 
294 unsigned int L1CaloGeometry::globalEtaIndex(const double& etaValue) const {
295  unsigned int etaIndex = 0;
296 
297  if (etaValue < 0.) {
298  for (unsigned int i = m_etaBinsPerHalf; i > 0; --i) {
299  if (fabs(etaValue) < m_gctEtaBinBoundaries[i]) {
300  etaIndex = m_etaBinsPerHalf - i;
301  }
302  }
303  } else {
304  for (unsigned int i = 0; i < m_etaBinsPerHalf; ++i) {
305  if (etaValue >= m_gctEtaBinBoundaries[i]) {
306  etaIndex = i + m_etaBinsPerHalf;
307  }
308  }
309  }
310 
311  return etaIndex;
312 }
313 
314 unsigned int L1CaloGeometry::emJetPhiIndex(const double& phiValue) const {
315  double phiAdjusted = phiValue - m_gctEmJetPhiOffset;
316 
317  // Check phiValue is between m_gctEmJetPhiOffset and m_gctEmJetPhiOffset+2pi
318  if (phiAdjusted < 0.) {
319  do {
320  phiAdjusted += 2. * M_PI;
321  } while (phiAdjusted < 0.);
322  } else if (phiAdjusted > 2. * M_PI) {
323  do {
324  phiAdjusted -= 2. * M_PI;
325  } while (phiAdjusted > 2. * M_PI);
326  }
327 
328  return ((int)(phiAdjusted / m_gctEmJetPhiBinWidth));
329 }
330 
331 unsigned int L1CaloGeometry::etSumPhiIndex(const double& phiValue) const {
332  double phiAdjusted = phiValue - m_gctEtSumPhiOffset;
333 
334  // Check phiValue is between m_gctEtSumPhiOffset and m_gctEtSumPhiOffset+2pi
335  if (phiAdjusted < 0.) {
336  do {
337  phiAdjusted += 2. * M_PI;
338  } while (phiAdjusted < 0.);
339  } else if (phiAdjusted > 2. * M_PI) {
340  do {
341  phiAdjusted -= 2. * M_PI;
342  } while (phiAdjusted > 2. * M_PI);
343  }
344 
345  return ((int)(phiAdjusted / m_gctEtSumPhiBinWidth));
346 }
347 
348 unsigned int L1CaloGeometry::htSumPhiIndex(const double& phiValue) const {
349  double phiAdjusted = phiValue - m_gctEtSumPhiOffset;
350 
351  // Check phiValue is between m_gctEtSumPhiOffset and m_gctEtSumPhiOffset+2pi
352  if (phiAdjusted < 0.) {
353  do {
354  phiAdjusted += 2. * M_PI;
355  } while (phiAdjusted < 0.);
356  } else if (phiAdjusted > 2. * M_PI) {
357  do {
358  phiAdjusted -= 2. * M_PI;
359  } while (phiAdjusted > 2. * M_PI);
360  }
361 
362  if (m_version == kOrig) {
363  return ((int)(phiAdjusted / (m_gctEtSumPhiBinWidth * 4.)));
364  } else {
365  return ((int)(phiAdjusted / m_gctHtSumPhiBinWidth));
366  }
367 }
368 
370  if (m_version == kOrig) {
371  return m_numberGctEtSumPhiBins / 4;
372  } else {
374  }
375 }
376 
377 std::ostream& operator<<(std::ostream& os, const L1CaloGeometry& obj) {
378  os << "L1CaloGeometry:" << std::endl;
379 
380  os << "Central/tau eta bins: low / center / high" << std::endl;
381  for (unsigned int i = 0; i < obj.numberGctCentralEtaBinsPerHalf(); ++i) {
382  os << " bin " << i << ": " << obj.etaBinLowEdge(i) << " / " << obj.etaBinCenter(i) << " / "
383  << obj.etaBinHighEdge(i) << std::endl;
384  }
385 
386  os << "Forward eta bins: low / center / high" << std::endl;
387  for (unsigned int i = 0; i < obj.numberGctForwardEtaBinsPerHalf(); ++i) {
388  os << " bin " << i << ": " << obj.etaBinLowEdge(i, false) << " / " << obj.etaBinCenter(i, false) << " / "
389  << obj.etaBinHighEdge(i, false) << std::endl;
390  }
391 
392  os << "Global eta bins: low / center / high" << std::endl;
393  for (unsigned int i = 0; i < obj.numberGctCentralEtaBinsPerHalf() + obj.numberGctForwardEtaBinsPerHalf(); ++i) {
394  os << " bin " << i << ": " << obj.globalEtaBinLowEdge(i) << " / " << obj.globalEtaBinCenter(i) << " / "
395  << obj.globalEtaBinHighEdge(i) << std::endl;
396  }
397 
398  os << "EM/jet phi bins: low / center / high" << std::endl;
399  for (unsigned int i = 0; i < obj.numberGctEmJetPhiBins(); ++i) {
400  os << " bin " << i << ": " << obj.emJetPhiBinLowEdge(i) << " / " << obj.emJetPhiBinCenter(i) << " / "
401  << obj.emJetPhiBinHighEdge(i) << std::endl;
402  }
403 
404  os << "Et sum phi bins: low / center / high" << std::endl;
405  for (unsigned int i = 0; i < obj.numberGctEtSumPhiBins(); ++i) {
406  os << " bin " << i << ": " << obj.etSumPhiBinLowEdge(i) << " / " << obj.etSumPhiBinCenter(i) << " / "
407  << obj.etSumPhiBinHighEdge(i) << std::endl;
408  }
409 
410  os << "Ht sum phi bins: low / center / high" << std::endl;
411  for (unsigned int i = 0; i < obj.numberGctHtSumPhiBins(); ++i) {
412  os << " bin " << i << ": " << obj.htSumPhiBinLowEdge(i) << " / " << obj.htSumPhiBinCenter(i) << " / "
413  << obj.htSumPhiBinHighEdge(i) << std::endl;
414  }
415 
416  return os;
417 }
418 
419 //
420 // static member functions
421 //
double globalEtaBinLowEdge(unsigned int globalEtaIndex) const
unsigned int numberGctForwardEtaBinsPerHalf() const
double etaBinHighEdge(unsigned int etaIndex, bool central=true) const
unsigned int numberGctHtSumPhiBins() const
double etaBinLowEdge(unsigned int etaIndex, bool central=true) const
double htSumPhiBinLowEdge(unsigned int phiIndex) const
unsigned int numberGctEtSumPhiBins() const
unsigned int m_numberGctEtSumPhiBins
virtual ~L1CaloGeometry()
double m_gctEmJetPhiBinWidth
unsigned int numberGctEmJetPhiBins() const
double m_gctEtSumPhiOffset
double etaBinCenter(unsigned int etaIndex, bool central=true) const
unsigned int numberGctCentralEtaBinsPerHalf() const
unsigned int htSumPhiIndex(const double &phiValue) const
double m_gctHtSumPhiOffset
std::ostream & operator<<(std::ostream &os, const L1CaloGeometry &obj)
unsigned int m_numberGctCentralEtaBinsPerHalf
unsigned int m_version
std::vector< double > m_gctEtaBinBoundaries
unsigned int m_numberGctEmJetPhiBins
double m_gctEmJetPhiOffset
double htSumPhiBinCenter(unsigned int phiIndex) const
unsigned int etSumPhiIndex(const double &phiValue) const
double m_gctHtSumPhiBinWidth
double m_gctEtSumPhiBinWidth
unsigned int emJetPhiIndex(const double &phiValue) const
#define M_PI
double globalEtaBinCenter(unsigned int globalEtaIndex) const
double globalEtaBinHighEdge(unsigned int globalEtaIndex) const
double etSumPhiBinLowEdge(unsigned int phiIndex) const
unsigned int m_etaSignBitOffset
unsigned int m_etaBinsPerHalf
unsigned int m_numberGctHtSumPhiBins
unsigned int etaSignBitOffset() const
unsigned int m_numberGctForwardEtaBinsPerHalf
double emJetPhiBinCenter(unsigned int phiIndex) const
double emJetPhiBinLowEdge(unsigned int phiIndex) const
double htSumPhiBinHighEdge(unsigned int phiIndex) const
unsigned int globalEtaIndex(const double &etaValue) const
double etSumPhiBinCenter(unsigned int phiIndex) const
double emJetPhiBinHighEdge(unsigned int phiIndex) const
double etSumPhiBinHighEdge(unsigned int phiIndex) const
unsigned int etaIndex(const double &etaValue) const