ATLAS Offline Software
CaloTowerSeg.h
Go to the documentation of this file.
1 // This file's extension implies that it's C, but it's really -*- C++ -*-.
2 
3 /*
4  Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
5 */
6 
7 #ifndef CALOEVENT_CALOTOWERSEG_H
8 #define CALOEVENT_CALOTOWERSEG_H
9 /********************************************************************
10 
11 NAME: CaloTowerSeg
12 PACKAGE: offline/Calorimeter/CaloRec
13 
14 AUTHORS: S. Rajagopalan
15 CREATED: Oct, 2000
16  Originally it is LArTowerSeg in LArClusterRec
17  Moved to CaloRec on Feb 5, 2001 by H.Ma
18 
19 PURPOSE:
20  Store segmentation for the tower configuration.
21  Constructor takes segmentation parameters.
22  Public methods for accessing the limits, and tower sizes,
23  and check bounds.
24 
25 MODIFIED: indices now unsigned integers; ranges [1,size]
26 
27 ********************************************************************/
28 
29 // INCLUDE HEADER FILES:
30 
31 #include <cmath>
32 #include <cstdlib>
33 
35 
37 {
38  public:
39 
41  typedef size_t index_t;
42 
44  static const index_t outOfRange = static_cast<index_t> (-1);
45 
46 
51  CaloTowerSeg():
52  m_neta(0),m_nphi(0),
53  m_etamin(0.),m_etamax(0.),
54  m_phimin(0.),m_phimax(0.),
55  m_deta(0),m_dphi(0)
56  {}
57 
76  double phimin=s_range.phi_min(),
77  double phimax=s_range.phi_max()):
81  {
84  };
85 
87  ~CaloTowerSeg ()
88  {
89 
90  };
91 
92  // Use implicit copy ctor and assignment.
93 
94 
96  index_t neta() const;
98  index_t nphi() const;
100  double deta() const;
102  double dphi() const;
104  double etamin() const;
106  double etamax() const;
108  double phimin() const;
110  double phimax() const;
111 
120  bool inbound(index_t etaInd,index_t phiInd) const;
131  bool inbound(double etaVal,double phiVal) const;
132 
142  index_t etaphi(index_t etaInd,index_t phiInd) const;
143 
151  double eta(index_t etaInd) const;
159  index_t etaIndex(double etaVal) const;
168  index_t etaIndex(index_t comInd) const;
169 
177  double phi(index_t phiInd) const;
185  index_t phiIndex(double phiVal) const;
195  index_t phiIndex(index_t comInd) const;
196 
197 
201  class SubSeg
202  {
203  public:
205 
215  SubSeg (const CaloTowerSeg& parent,
218 
220  index_t etamin() const;
221 
223  index_t etamax() const;
224 
226  index_t phimin() const;
227 
229  index_t phimax() const;
230 
232  size_t neta() const;
233 
235  size_t nphi() const;
236 
238  size_t size() const;
239 
240  const CaloTowerSeg& parent() const { return m_parent; }
241 
242 
246  CaloTowerSeg segmentation() const;
247 
248 
249  private:
251  const CaloTowerSeg& m_parent;
252 
258  };
259 
260 
316  template <class TOWER_ITERATOR>
317  class SubSegIterator
318  : public TOWER_ITERATOR
319  {
320  public:
327  static
328  SubSegIterator make (TOWER_ITERATOR beg, const SubSeg& subseg);
329 
330 
347  SubSegIterator (const TOWER_ITERATOR& it,
348  size_t nphi,
349  size_t nphi_skip,
350  size_t phipos);
351 
352 
361 
362 
368  size_t itower() const;
369 
370 
371  private:
372  size_t m_nphi;
373  size_t m_nphi_skip;
374  size_t m_phipos;
375  size_t m_phipos2;
376  size_t m_itower;
377  };
378 
379 
380 
385  SubSeg subseg (double eta, double deta, double phi, double dphi) const;
386 
387 
388  private:
389  friend class CaloTowerSegCnv_p1;
390 
391 
392  // --------------------------
393  // Segmentation parameters
394  // ------------------------
395 
397  index_t m_neta;
399  index_t m_nphi;
400 
402  double m_etamin;
404  double m_etamax;
406  double m_phimin;
408  double m_phimax;
409 
411  double m_deta;
413  double m_dphi;
414 
415  // Can get rid of this when we move to the new CaloDetDescr
416  // in which all CaloPhiRange methods are static.
417  static const CaloPhiRange s_range;
418 };
419 
420 // ----------------------------------------
421 // returns parameters
422 // ----------------------------------------
424 {
425  return m_neta;
426 }
427 
429 {
430  return m_nphi;
431 }
432 
433 inline double CaloTowerSeg::deta() const
434 {
435  return m_deta;
436 }
437 
438 inline double CaloTowerSeg::dphi() const
439 {
440  return m_dphi;
441 }
442 
443 inline double CaloTowerSeg::etamin() const
444 {
445  return m_etamin;
446 }
447 
448 inline double CaloTowerSeg::etamax() const
449 {
450  return m_etamax;
451 }
452 
453 inline double CaloTowerSeg::phimin() const
454 {
455  return m_phimin;
456 }
457 
458 inline double CaloTowerSeg::phimax() const
459 {
460  return m_phimax;
461 }
462 
463 inline bool CaloTowerSeg::inbound(index_t etaInd, index_t phiInd) const
464 {
465  return
466  etaInd >= 1 && etaInd <= m_neta &&
467  phiInd >= 1 && phiInd <= m_nphi;
468 }
469 
470 inline bool CaloTowerSeg::inbound(double etaVal, double phiVal) const
471 {
472  if ( ! ( etaVal >= m_etamin && etaVal <= m_etamax ) ) return false;
473  if (m_phimax > m_phimin)
474  return phiVal >= m_phimin && phiVal <= m_phimax;
475  else
476  return phiVal <= m_phimax || phiVal >= m_phimin;
477 }
478 
479 
480 // combined index
481 inline size_t CaloTowerSeg::etaphi(index_t etaInd,index_t phiInd) const
482 {
483  return this->inbound(etaInd,phiInd)
484  ? (etaInd-1) * m_nphi + (phiInd-1)
485  : outOfRange;
486 }
487 
488 // individual indices
490 {
491  return ( etaVal >= m_etamin && etaVal <= m_etamax )
492  ? (index_t)floor( ( etaVal - m_etamin ) / m_deta ) + 1
493  : outOfRange;
494 }
496 {
497  return (index_t)(comInd/m_nphi) + 1;
498 }
500 {
501  if (m_phimax > m_phimin)
502  return ( phiVal >= m_phimin && phiVal <= m_phimax )
503  ? (index_t)floor( ( phiVal - m_phimin ) / m_dphi ) + 1
504  : outOfRange;
505  else
506  return ( phiVal >= m_phimin || phiVal <= m_phimax )
507  ? (index_t)floor( s_range.diff ( phiVal, m_phimin ) / m_dphi ) + 1
508  : outOfRange;
509 }
511 {
512  return (index_t)(comInd % m_nphi) + 1;
513 }
514 
515 // index to real space conversion.
516 inline double CaloTowerSeg::eta(index_t etaInd) const
517 {
518  return m_etamin + (etaInd-0.5) * m_deta ;
519 }
520 
521 inline double CaloTowerSeg::phi(index_t phiInd) const
522 {
523  double ret = m_phimin + (phiInd-0.5) * m_dphi;
524  if (m_phimin > m_phimax)
525  ret = s_range.fix (ret);
526  return ret;
527 }
528 
529 
530 //************************************************************************
531 
532 
536 inline
539 {
540  return m_etamin;
541 }
542 
543 
547 inline
550 {
551  return m_etamax;
552 }
553 
554 
558 inline
561 {
562  return m_phimin;
563 }
564 
565 
569 inline
572 {
573  return m_phimax;
574 }
575 
576 
580 inline
582 {
583  return m_etamax - m_etamin + 1;
584 }
585 
586 
590 inline
592 {
593  return neta() * nphi();
594 }
595 
596 
597 //************************************************************************
598 
599 
606 template <class TOWER_ITERATOR>
609  (TOWER_ITERATOR beg, const SubSeg& subseg)
610 {
611  const CaloTowerSeg& parent = subseg.parent();
612  size_t itower;
613  size_t phipos;
614 
615  if (subseg.phimax() < subseg.phimin()) {
616  // phi wraparound case
617  itower = parent.etaphi (subseg.etamin(), 1);
618  phipos = subseg.nphi() - subseg.phimax();
619  }
620  else {
621  // no phi wrapping
622  itower = parent.etaphi (subseg.etamin(), subseg.phimin());
623  phipos = 0;
624  }
625 
626  beg += itower;
627  return SubSegIterator (beg,
628  subseg.nphi(),
629  parent.nphi() - subseg.nphi() + 1,
630  phipos);
631 }
632 
633 
650 template <class TOWER_ITERATOR>
651 // cppcheck-suppress uninitMemberVar ; get bogus cppcheck warnings here.
653  (const TOWER_ITERATOR& it,
654  size_t nphi,
655  size_t nphi_skip,
656  size_t phipos)
657  : TOWER_ITERATOR (it),
658  m_nphi (nphi),
659  m_nphi_skip (nphi_skip),
660  m_phipos (phipos),
661  m_phipos2 (0),
662  m_itower (0)
663 {
664 }
665 
666 
674 template <class TOWER_ITERATOR>
675 inline
678 {
679  // Advance phi position.
680  ++m_phipos;
681  if (m_phipos < m_nphi) {
682  // Not to the gap yet; just advance underlying iterator.
684  }
685  else {
686  // At the gap. Skip ahead by the size of the gap,
687  // and reset the phi position.
688  m_phipos = 0;
689  TOWER_ITERATOR::operator+= (m_nphi_skip);
690  }
691 
692  // Bump the tower index counter when we wrap around in phi.
693  if (++m_phipos2 >= m_nphi) {
694  m_phipos2 = 0;
695  m_itower += m_nphi;
696  }
697 
698  return *this;
699 }
700 
701 
707 template <class TOWER_ITERATOR>
708 inline
709 size_t
711 {
712  return m_itower + m_phipos;
713 }
714 
715 
716 //************************************************************************
717 
718 
739 #endif
CaloTowerSeg::SubSegIterator
Iterator over a rectangular window of towers.
Definition: CaloTowerSeg.h:337
CaloTowerSeg::inbound
bool inbound(index_t etaInd, index_t phiInd) const
Check index range in and .
Definition: CaloTowerSeg.h:463
CaloTowerSeg::eta
double eta(index_t etaInd) const
Returns value for a given index.
Definition: CaloTowerSeg.h:516
CaloTowerSeg::SubSeg::phimin
index_t phimin() const
Lower phi index.
Definition: CaloTowerSeg.h:560
CaloPhiRange
This class defines the phi convention for Calorimeters.
Definition: CaloPhiRange.h:28
CaloTowerSeg::SubSeg::parent
const CaloTowerSeg & parent() const
Definition: CaloTowerSeg.h:258
CaloTowerSeg::SubSeg::m_phimin
index_t m_phimin
Definition: CaloTowerSeg.h:274
CaloTowerSeg::SubSeg::etamax
index_t etamax() const
Upper eta index (inclusive).
Definition: CaloTowerSeg.h:549
CaloTowerSeg::SubSegIterator::make
static SubSegIterator make(TOWER_ITERATOR beg, const SubSeg &subseg)
Construct a new iterator for iterating over a window.
Definition: CaloTowerSeg.h:609
CaloTowerSeg::SubSegIterator::m_phipos2
size_t m_phipos2
Definition: CaloTowerSeg.h:393
skel.it
it
Definition: skel.GENtoEVGEN.py:423
CaloTowerSeg::m_etamin
double m_etamin
Lower boundary value range.
Definition: CaloTowerSeg.h:420
CaloTowerSeg::neta
index_t neta() const
Retrieve number of bins.
Definition: CaloTowerSeg.h:423
CaloTowerSeg::m_etamax
double m_etamax
Upper boundary value range.
Definition: CaloTowerSeg.h:422
CaloTowerSeg::SubSeg::etamin
index_t etamin() const
Lower eta index.
Definition: CaloTowerSeg.h:538
CaloTowerSeg::SubSegIterator::m_itower
size_t m_itower
Definition: CaloTowerSeg.h:394
CaloTowerSeg::SubSeg::index_t
CaloTowerSeg::index_t index_t
Definition: CaloTowerSeg.h:222
CaloTowerSeg::CaloTowerSeg
CaloTowerSeg()
Default constructor.
Definition: CaloTowerSeg.h:69
CaloTowerSeg::deta
double deta() const
Retrieve bin size .
Definition: CaloTowerSeg.h:433
CaloPhiRange::phi_min
static double phi_min()
Definition: CaloPhiRange.h:49
CaloTowerSeg::SubSegIterator::m_phipos
size_t m_phipos
Definition: CaloTowerSeg.h:392
CaloTowerSeg::nphi
index_t nphi() const
Retrieve number of bins.
Definition: CaloTowerSeg.h:428
CaloTowerSeg::m_dphi
double m_dphi
Bin size .
Definition: CaloTowerSeg.h:431
CaloTowerSeg::SubSeg
A rectangular window within the segmentation.
Definition: CaloTowerSeg.h:220
CaloTowerSeg::SubSeg::SubSeg
SubSeg(const CaloTowerSeg &parent, index_t etamin, index_t etamax, index_t phimin, index_t phimax)
Constructor.
Definition: CaloTowerSeg.cxx:57
CaloTowerSeg::phimin
double phimin() const
Retrieve lower boundary value range.
Definition: CaloTowerSeg.h:453
CaloTowerSeg::m_deta
double m_deta
Bin size .
Definition: CaloTowerSeg.h:429
CaloTowerSeg::dphi
double dphi() const
Retrieve bin size .
Definition: CaloTowerSeg.h:438
CaloTowerSeg::SubSeg::m_phimax
index_t m_phimax
Definition: CaloTowerSeg.h:275
CaloPhiRange::phi_max
static double phi_max()
Definition: CaloPhiRange.h:52
ret
T ret(T t)
Definition: rootspy.cxx:260
CaloTowerSeg::phi
double phi(index_t phiInd) const
Returns value for a given index.
Definition: CaloTowerSeg.h:521
CaloTowerSeg::SubSegIterator::operator++
SubSegIterator & operator++()
Advance to the next tower in the window.
Definition: CaloTowerSeg.h:677
test_pyathena.parent
parent
Definition: test_pyathena.py:15
CaloTowerSeg::SubSegIterator::itower
size_t itower() const
The tower index to which the iterator is referring.
Definition: CaloTowerSeg.h:710
CaloTowerSeg::index_t
size_t index_t
Type for eta, phi indices.
Definition: CaloTowerSeg.h:59
CaloPhiRange.h
CaloPhiRange class declaration.
CaloTowerSeg::phimax
double phimax() const
Retrieve upper boundary value range.
Definition: CaloTowerSeg.h:458
CaloPhiRange::fix
static double fix(double phi)
Definition: CaloPhiRange.cxx:14
CaloTowerSeg::SubSegIterator::m_nphi
size_t m_nphi
Definition: CaloTowerSeg.h:390
CaloTowerSeg::m_nphi
index_t m_nphi
Number of bins.
Definition: CaloTowerSeg.h:417
LVL1TGCTrigger::operator++
TGCHBChip operator++(TGCHBChip &rs, int)
Definition: TGCHighPtBoard.h:28
CaloTowerSeg::etamax
double etamax() const
Retrieve upper boundary value range.
Definition: CaloTowerSeg.h:448
WriteBchToCool.beg
beg
Definition: WriteBchToCool.py:69
CaloTowerSeg::phiIndex
index_t phiIndex(double phiVal) const
Returns index for a given value.
Definition: CaloTowerSeg.h:499
CaloTowerSeg::etaphi
index_t etaphi(index_t etaInd, index_t phiInd) const
Returns combined continous index from , indices.
Definition: CaloTowerSeg.h:481
CaloTowerSeg::SubSeg::phimax
index_t phimax() const
Upper phi index (inclusive). phimax<phimin indicates phi wraparound.
Definition: CaloTowerSeg.h:571
CaloTowerSeg::SubSeg::segmentation
CaloTowerSeg segmentation() const
Return a new segmentation object corresponding to this window.
Definition: CaloTowerSeg.cxx:85
CaloTowerSeg::etamin
double etamin() const
Retrieve lower boundary value range.
Definition: CaloTowerSeg.h:443
CaloTowerSeg::s_range
static const CaloPhiRange s_range
Definition: CaloTowerSeg.h:435
CaloTowerSeg::~CaloTowerSeg
~CaloTowerSeg()
Destructor.
Definition: CaloTowerSeg.h:105
CaloTowerSeg::SubSegIterator::m_nphi_skip
size_t m_nphi_skip
Definition: CaloTowerSeg.h:391
CaloTowerSeg::SubSeg::m_parent
const CaloTowerSeg & m_parent
Segmentation of which this is a part.
Definition: CaloTowerSeg.h:269
CaloTowerSeg::outOfRange
static const index_t outOfRange
Used to flag out-of-range indices.
Definition: CaloTowerSeg.h:62
CaloTowerSeg
Data object stores CaloTower segmentation.
Definition: CaloTowerSeg.h:37
CaloTowerSeg::SubSeg::size
size_t size() const
The number of towers in this window.
Definition: CaloTowerSeg.h:591
CaloTowerSeg::SubSeg::m_etamax
index_t m_etamax
Definition: CaloTowerSeg.h:273
CaloTowerSeg::m_phimax
double m_phimax
Upper boundary value range.
Definition: CaloTowerSeg.h:426
CaloTowerSeg::SubSeg::m_etamin
index_t m_etamin
Inclusive indices. m_phimax < m_phimin indicates phi wraparound.
Definition: CaloTowerSeg.h:272
CaloTowerSeg::etaIndex
index_t etaIndex(double etaVal) const
Returns index for a given value.
Definition: CaloTowerSeg.h:489
CaloTowerSeg::SubSegIterator::SubSegIterator
SubSegIterator(const TOWER_ITERATOR &it, size_t nphi, size_t nphi_skip, size_t phipos)
Constructor.
Definition: CaloTowerSeg.h:653
CaloTowerSeg::m_phimin
double m_phimin
Lower boundary value range.
Definition: CaloTowerSeg.h:424
CaloTowerSegCnv_p1
Definition: CaloTowerSegCnv_p1.h:15
CaloPhiRange::diff
static double diff(double phi1, double phi2)
simple phi1 - phi2 calculation, but result is fixed to respect range.
Definition: CaloPhiRange.cxx:22
CaloTowerSeg::subseg
SubSeg subseg(double eta, double deta, double phi, double dphi) const
Return a window within the current segmentation.
Definition: CaloTowerSeg.cxx:23
CaloTowerSeg::m_neta
index_t m_neta
Number of bins.
Definition: CaloTowerSeg.h:415
CaloTowerSeg::SubSeg::nphi
size_t nphi() const
The number of towers in the phi direction in this window.
Definition: CaloTowerSeg.cxx:72
CaloTowerSeg::SubSeg::neta
size_t neta() const
The number of towers in the eta direction in this window.
Definition: CaloTowerSeg.h:581