ATLAS Offline Software
Loading...
Searching...
No Matches
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-2025 CERN for the benefit of the ATLAS collaboration
5*/
6
7#ifndef CALOEVENT_CALOTOWERSEG_H
8#define CALOEVENT_CALOTOWERSEG_H
9/********************************************************************
10
11NAME: CaloTowerSeg
12PACKAGE: offline/Calorimeter/CaloRec
13
14AUTHORS: S. Rajagopalan
15CREATED: Oct, 2000
16 Originally it is LArTowerSeg in LArClusterRec
17 Moved to CaloRec on Feb 5, 2001 by H.Ma
18
19PURPOSE:
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
25MODIFIED: 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
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
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
247
248
249 private:
252
258 };
259
260
316 template <class TOWER_ITERATOR>
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;
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
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
433inline double CaloTowerSeg::deta() const
434{
435 return m_deta;
436}
437
438inline double CaloTowerSeg::dphi() const
439{
440 return m_dphi;
441}
442
443inline double CaloTowerSeg::etamin() const
444{
445 return m_etamin;
446}
447
448inline double CaloTowerSeg::etamax() const
449{
450 return m_etamax;
451}
452
453inline double CaloTowerSeg::phimin() const
454{
455 return m_phimin;
456}
457
458inline double CaloTowerSeg::phimax() const
459{
460 return m_phimax;
461}
462
463inline 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
470inline 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
481inline 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.
516inline double CaloTowerSeg::eta(index_t etaInd) const
517{
518 return m_etamin + (etaInd-0.5) * m_deta ;
519}
520
521inline 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
536inline
539{
540 return m_etamin;
541}
542
543
547inline
550{
551 return m_etamax;
552}
553
554
558inline
561{
562 return m_phimin;
563}
564
565
569inline
572{
573 return m_phimax;
574}
575
576
580inline
582{
583 return m_etamax - m_etamin + 1;
584}
585
586
590inline
592{
593 return neta() * nphi();
594}
595
596
597//************************************************************************
598
599
606template <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 // Should never happen, but check explicitly to prevent a coverity warning.
627 if (itower == outOfRange) std::abort();
628
629 beg += itower;
630 return SubSegIterator (beg,
631 subseg.nphi(),
632 parent.nphi() - subseg.nphi() + 1,
633 phipos);
634}
635
636
653template <class TOWER_ITERATOR>
654// cppcheck-suppress uninitMemberVar ; get bogus cppcheck warnings here.
656 (const TOWER_ITERATOR& it,
657 size_t nphi,
658 size_t nphi_skip,
659 size_t phipos)
660 : TOWER_ITERATOR (it),
661 m_nphi (nphi),
662 m_nphi_skip (nphi_skip),
663 m_phipos (phipos),
664 m_phipos2 (0),
665 m_itower (0)
666{
667}
668
669
677template <class TOWER_ITERATOR>
678inline
681{
682 // Advance phi position.
683 ++m_phipos;
684 if (m_phipos < m_nphi) {
685 // Not to the gap yet; just advance underlying iterator.
686 TOWER_ITERATOR::operator++();
687 }
688 else {
689 // At the gap. Skip ahead by the size of the gap,
690 // and reset the phi position.
691 m_phipos = 0;
692 TOWER_ITERATOR::operator+= (m_nphi_skip);
693 }
694
695 // Bump the tower index counter when we wrap around in phi.
696 if (++m_phipos2 >= m_nphi) {
697 m_phipos2 = 0;
698 m_itower += m_nphi;
699 }
700
701 return *this;
702}
703
704
710template <class TOWER_ITERATOR>
711inline
712size_t
717
718
719//************************************************************************
720
721
742#endif
Scalar eta() const
pseudorapidity method
Scalar phi() const
phi method
CaloPhiRange class declaration.
This class defines the phi convention for Calorimeters.
Iterator over a rectangular window of towers.
size_t itower() const
The tower index to which the iterator is referring.
SubSegIterator & operator++()
Advance to the next tower in the window.
SubSegIterator(const TOWER_ITERATOR &it, size_t nphi, size_t nphi_skip, size_t phipos)
Constructor.
static SubSegIterator make(TOWER_ITERATOR beg, const SubSeg &subseg)
Construct a new iterator for iterating over a window.
A rectangular window within the segmentation.
const CaloTowerSeg & m_parent
Segmentation of which this is a part.
index_t etamax() const
Upper eta index (inclusive).
size_t nphi() const
The number of towers in the phi direction in this window.
size_t size() const
The number of towers in this window.
index_t etamin() const
Lower eta index.
index_t m_etamin
Inclusive indices. m_phimax < m_phimin indicates phi wraparound.
const CaloTowerSeg & parent() const
index_t phimin() const
Lower phi index.
size_t neta() const
The number of towers in the eta direction in this window.
index_t phimax() const
Upper phi index (inclusive). phimax<phimin indicates phi wraparound.
CaloTowerSeg::index_t index_t
SubSeg(const CaloTowerSeg &parent, index_t etamin, index_t etamax, index_t phimin, index_t phimax)
Constructor.
CaloTowerSeg segmentation() const
Return a new segmentation object corresponding to this window.
index_t nphi() const
Retrieve number of bins.
double m_phimax
Upper boundary value range.
size_t index_t
Type for eta, phi indices.
CaloTowerSeg()
Default constructor.
double phimin() const
Retrieve lower boundary value range.
index_t etaphi(index_t etaInd, index_t phiInd) const
Returns combined continous index from , indices.
index_t neta() const
Retrieve number of bins.
bool inbound(index_t etaInd, index_t phiInd) const
Check index range in and .
double deta() const
Retrieve bin size .
static const CaloPhiRange s_range
double dphi() const
Retrieve bin size .
index_t phiIndex(double phiVal) const
Returns index for a given value.
SubSeg subseg(double eta, double deta, double phi, double dphi) const
Return a window within the current segmentation.
static const index_t outOfRange
Used to flag out-of-range indices.
double phimax() const
Retrieve upper boundary value range.
double phi(index_t phiInd) const
Returns value for a given index.
double m_etamax
Upper boundary value range.
double etamin() const
Retrieve lower boundary value range.
double etamax() const
Retrieve upper boundary value range.
index_t m_neta
Number of bins.
index_t m_nphi
Number of bins.
double m_etamin
Lower boundary value range.
CaloTowerSeg(index_t neta, index_t nphi, double etamin, double etamax, double phimin=s_range.phi_min(), double phimax=s_range.phi_max())
Constructor.
double eta(index_t etaInd) const
Returns value for a given index.
index_t etaIndex(double etaVal) const
Returns index for a given value.
double m_deta
Bin size .
~CaloTowerSeg()
Destructor.
friend class CaloTowerSegCnv_p1
double m_dphi
Bin size .
double m_phimin
Lower boundary value range.