ATLAS Offline Software
CaloTowerContainer.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 /********************************************************************
6 
7 NAME: CaloTowerContainer.cxx
8 PACKAGE: offline/Calorimeter/CaloRec
9 
10 AUTHORS: S. Rajagopalan
11 CREATED: Oct 29, 2000
12 
13 PURPOSE:
14 
15 Updated: Jan 3, 2001 (HM)
16  QA.
17 
18 Updated: Feb 5, 2001 (HMa)
19  Moved from LArClusterRec to CaloRec.
20 
21 
22 ********************************************************************/
23 
24 // INCLUDE HEADER FILES:
25 
26 #include "CaloEvent/CaloTowerContainer.h"
27 #include "CaloEvent/CaloTower.h"
28 #include "CaloEvent/CaloTowerSeg.h"
30 #ifdef CALOTOWERCONTAINER_USES_DATAPOOL
31 #include "AthAllocators/DataPool.h"
32 #endif
33 
34 #include <utility>
35 #include <vector>
36 #include <algorithm>
37 #include <iostream>
38 #include <stdexcept>
39 
40 
42 // Constructors/Destructor //
44 
45 
48 { }
49 
51  bool noTowers /*= false*/)
52  : Base(SG::VIEW_ELEMENTS),
53  m_towerSeg(theSegmentation)
54 {
55  if (!noTowers)
56  init();
57 }
58 
59 #ifdef CALOTOWERCONTAINER_USES_DATAPOOL
62  Base(other),
63  m_towerSeg (other.m_towerSeg),
64  m_caloRegions (other.m_caloRegions)
65 {
66 }
67 #else
70  Base(other.m_towers.size(), SG::VIEW_ELEMENTS),
71  m_towerSeg (other.m_towerSeg),
72  m_caloRegions (other.m_caloRegions),
73  m_towers (other.m_towers)
74 {
75  setTowers();
76 }
77 #endif
78 
81 {
82  if (this != &other) {
83  m_towerSeg = other.m_towerSeg;
84  m_caloRegions = other.m_caloRegions;
85 #ifdef CALOTOWERCONTAINER_USES_DATAPOOL
87 #else
88  m_towers = other.m_towers;
89  setTowers();
90 #endif
91  }
92  return *this;
93 }
94 
96 {
97  if (this != &other) {
98  Base::swap (other);
99  std::swap (m_towerSeg, other.m_towerSeg);
100  m_caloRegions.swap (other.m_caloRegions);
101 #ifndef CALOTOWERCONTAINER_USES_DATAPOOL
102  m_towers.swap (other.m_towers);
103 #endif
104  }
105 }
106 
108 {
109  // pre-size the container
112  index_t phiBins = (index_t)m_towerSeg.nphi();
113 #ifdef CALOTOWERCONTAINER_USES_DATAPOOL
114  Base::resize (etaBins * phiBins);
115 #else
116  this->m_towers.resize (etaBins * phiBins);
117  setTowers();
118 #endif
119 
120 
121  // get the eta/phi segmentation
122  double deltaEta = m_towerSeg.deta();
123  double minEta = m_towerSeg.etamin() + deltaEta / 2.;
124  double deltaPhi = m_towerSeg.dphi();
125  double minPhi = CaloPhiRange::fix (m_towerSeg.phimin() + deltaPhi / 2.);
126 
127 #ifdef CALOTOWERCONTAINER_USES_DATAPOOL
128  DataPool<CaloTower> towersPool (etaBins * phiBins);
129 #endif
130 
131  // insert empty towers
132  // NOTE: eta/phi indexing is 1-based.
133  for (index_t etaIndex = 1; etaIndex <= etaBins; ++etaIndex) {
134  double theEta = minEta + (etaIndex-1) * deltaEta;
135  for (index_t phiIndex = 1; phiIndex <= phiBins; ++phiIndex) {
136  double thePhi = CaloPhiRange::fix (minPhi + (phiIndex-1) * deltaPhi);
137  index_t towerIndex = this->getTowerIndex(etaIndex,phiIndex);
138 #ifdef CALOTOWERCONTAINER_USES_DATAPOOL
139  CaloTower& tower = *towersPool.nextElementPtr();
140  Base::operator[] (towerIndex) = &tower;
141  tower.removeCells();
142  tower.setE(0);
143 #else
144  CaloTower& tower = m_towers[towerIndex];
145 #endif
146  tower.setEta (theEta);
147  tower.setPhi (thePhi);
148  }
149  }
150 }
151 
152 #ifndef CALOTOWERCONTAINER_USES_DATAPOOL
153 void CaloTowerContainer::setTowers()
154 {
155  assert (m_towers.size() == m_towerSeg.neta() * m_towerSeg.nphi() ||
156  m_towers.empty());
157  Base::resize (m_towers.size());
158  for (size_t i = 0; i < m_towers.size(); i++)
159  Base::operator[](i) = &m_towers[i];
160 }
161 #endif
162 
164 
166 // Included Calorimeter Modules //
168 
170 {
171  unsigned int intCalo = theCalo ;
172  if ( std::find(m_caloRegions.begin(),m_caloRegions.end(),intCalo)
173  == m_caloRegions.end() )
174  {
175  m_caloRegions.push_back(intCalo);
176  }
177 }
178 
179 size_t
180 CaloTowerContainer::getCalos(std::vector<CaloCell_ID::SUBCALO>& theCalos) const
181 {
182  theCalos.resize(m_caloRegions.size());
183  std::vector<unsigned int>::size_type i;
184  for(i=0;i<m_caloRegions.size();++i)
185  theCalos[i] = (CaloCell_ID::SUBCALO) m_caloRegions[i];
186 
187 // std::copy(m_caloRegions.begin(),m_caloRegions.end(),theCalos.begin());
188  return theCalos.size();
189 }
190 
192 // Tower Binning //
194 
195 // all inlined, see .h file
196 
198 // Kinematics Access //
200 
201 // energy by index
203 {
204  const CaloTower* t = this->getTower(etaIndex,phiIndex);
205  return t ? t->e() : 0;
206 }
207 // energy in (eta,phi)
208 double CaloTowerContainer::energy(double theEta, double thePhi) const
209 {
210  const CaloTower* t = this->getTower(theEta, thePhi);
211  return t ? t->e() : 0;
212 }
213 
214 // et by index
216 {
217  const CaloTower* t = this->getTower(etaIndex, phiIndex);
218  return t ? t->et() : 0;
219 }
220 
221 
222 // et in (eta,phi)
223 double CaloTowerContainer::et(double theEta, double thePhi) const
224 {
225  const CaloTower* t = this->getTower(theEta, thePhi);
226  return t ? t->et() : 0;
227 }
228 
229 
231 // Tower Access & Container Management //
233 
234 // returns both indices at once
236  index_t& etaIndex,
237  index_t& phiIndex) const
238 {
239  return aTower != nullptr
240  ? this->getTowerIndices(aTower->eta(),aTower->phi(),etaIndex,phiIndex)
241  : false;
242 }
243 bool CaloTowerContainer::getTowerIndices(double theEta, double thePhi,
244  index_t& etaIndex,
245  index_t& phiIndex) const
246 {
247  etaIndex = this->getTowerEtaIndex(theEta);
248  phiIndex = this->getTowerPhiIndex(thePhi);
249  return ( etaIndex != m_outOfRange && phiIndex != m_outOfRange );
250 }
251 
252 // returns CaloTower pointer by index
254  index_t phiIndex) const
255 
256 {
257  index_t theIndex = this->getTowerIndex(etaIndex,phiIndex);
258  return theIndex != m_outOfRange
259 #ifdef CALOTOWERCONTAINER_USES_DATAPOOL
260  ? Base::operator[](theIndex)
261 #else
262  ? &m_towers[theIndex]
263 #endif
264  : (const CaloTower*)nullptr;
265 }
267 {
268  index_t theIndex = this->getTowerIndex(etaIndex,phiIndex);
269  return theIndex != m_outOfRange
270 #ifdef CALOTOWERCONTAINER_USES_DATAPOOL
271  ? Base::operator[](theIndex)
272 #else
273  ? &m_towers[theIndex]
274 #endif
275  : (CaloTower*)nullptr;
276 }
278  double thePhi) const
279 {
280  index_t etaIndex = m_outOfRange;
282  return this->getTowerIndices(theEta,thePhi,etaIndex,phiIndex)
283  ? (this->operator[])(this->getTowerIndex(etaIndex,phiIndex))
284  : (const CaloTower*)nullptr;
285 }
286 CaloTower* CaloTowerContainer::getTower(double theEta, double thePhi)
287 {
288  index_t etaIndex = m_outOfRange;
290  return this->getTowerIndices(theEta,thePhi,etaIndex,phiIndex)
291  ? (this->operator[])(this->getTowerIndex(etaIndex,phiIndex))
292  : (CaloTower*)nullptr;
293 }
294 
295 
297 {
298  if (m_towerSeg.neta() > 0 || m_towerSeg.nphi() > 0)
299  throw std::runtime_error ("Bad call to CaloTowerContainer::clear");
300  Base::clear (p);
301 }
302 
304  iterator first,
305  iterator last)
306 {
307  if (m_towerSeg.neta() > 0 || m_towerSeg.nphi() > 0 ||
309  {
310  throw std::runtime_error ("Bad call to CaloTowerContainer::insert");
311  }
312  Base::insert (position.base(), first.base(), last.base());
313 }
314 
316 {
317  if (m_towerSeg.neta() > 0 || m_towerSeg.nphi() > 0 ||
319  {
320  throw std::runtime_error ("Bad call to CaloTowerContainer::push_back");
321  }
322  Base::push_back (pElem);
323 }
324 
325 
CaloTowerContainer::et
double et(double theEta, double thePhi) const
Return the tower transverse energy at a given grid position.
Definition: CaloTowerContainer.cxx:223
CaloTowerContainer::getTower
CaloTower * getTower(index_t eta, index_t phi)
Returns a pointer to a tower with given indices.
Definition: CaloTowerContainer.cxx:266
CaloTowerContainer::push_back
void push_back(value_type pElem)
Definition: CaloTowerContainer.cxx:315
python.PerfMonSerializer.p
def p
Definition: PerfMonSerializer.py:743
SG
Forward declaration.
Definition: CaloCellPacker_400_500.h:32
P4EEtaPhiM::setEta
virtual void setEta(double theEta)
set eta data member
Definition: P4EEtaPhiM.h:117
find
std::string find(const std::string &s)
return a remapped string
Definition: hcg.cxx:135
SG::VIEW_ELEMENTS
@ VIEW_ELEMENTS
this data object is a view, it does not own its elmts
Definition: OwnershipPolicy.h:18
CaloTowerContainer::operator=
CaloTowerContainer & operator=(const CaloTowerContainer &other)
Assignment.
Definition: CaloTowerContainer.cxx:80
xAOD::deltaPhi
setSAddress setEtaMS setDirPhiMS setDirZMS setBarrelRadius setEndcapAlpha setEndcapRadius setInterceptInner setEtaMap setEtaBin setIsTgcFailure setDeltaPt deltaPhi
Definition: L2StandAloneMuon_v1.cxx:160
ConvertOldUJHistosToNewHistos.etaBins
list etaBins
Definition: ConvertOldUJHistosToNewHistos.py:145
CaloEnergyCluster::removeCells
void removeCells()
Remove all cells without kinematic update.
Definition: CaloEnergyCluster.cxx:189
CaloTowerContainer::insert
void insert(iterator position, iterator first, iterator last)
Definition: CaloTowerContainer.cxx:303
CaloTowerContainer::iterator
Iterator class for which the reference type is not an lvalue.
Definition: Calorimeter/CaloEvent/CaloEvent/CaloTowerContainer.h:466
CaloTowerSeg::neta
index_t neta() const
Retrieve number of bins.
Definition: CaloTowerSeg.h:423
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
CaloTowerSeg.h
CaloTowerSeg::deta
double deta() const
Retrieve bin size .
Definition: CaloTowerSeg.h:433
DataVector< CaloTower >::operator=
DataVector & operator=(const DataVector &rhs)
Assignment operator.
CaloTowerContainer::init
void init()
Initializes the CaloTowerContainer.
Definition: CaloTowerContainer.cxx:107
CaloTowerContainer::m_caloRegions
std::vector< unsigned int > m_caloRegions
Vector of calorimeter regions contributing to the tower signals.
Definition: Calorimeter/CaloEvent/CaloEvent/CaloTowerContainer.h:520
CaloTowerContainer::getTowerIndex
index_t getTowerIndex(const CaloTower *aTower) const
Returns the combined index of a tower on the grid.
Definition: Calorimeter/CaloEvent/CaloEvent/CaloTowerContainer.h:598
CaloTowerSeg::nphi
index_t nphi() const
Retrieve number of bins.
Definition: CaloTowerSeg.h:428
CaloCell_ID.h
SG::OwnershipPolicy
OwnershipPolicy
describes the possible element ownership policies (see e.g. DataVector)
Definition: OwnershipPolicy.h:16
CaloTowerContainer::CaloTowerContainer
CaloTowerContainer()
Default constructor.
Definition: CaloTowerContainer.cxx:46
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
CaloTowerSeg::phimin
double phimin() const
Retrieve lower boundary value range.
Definition: CaloTowerSeg.h:453
CaloTowerContainer
Storable container class for CaloTower.
Definition: Calorimeter/CaloEvent/CaloEvent/CaloTowerContainer.h:77
CaloTower::phi
virtual double phi() const override final
get phi data member
Definition: Calorimeter/CaloEvent/CaloEvent/CaloTower.h:144
P4Helpers::deltaEta
double deltaEta(const I4Momentum &p1, const I4Momentum &p2)
Computes efficiently .
Definition: P4Helpers.h:53
CaloTowerSeg::dphi
double dphi() const
Retrieve bin size .
Definition: CaloTowerSeg.h:438
lumiFormat.i
int i
Definition: lumiFormat.py:92
CaloCell_Base_ID::SUBCALO
SUBCALO
enumeration of sub calorimeters
Definition: CaloCell_Base_ID.h:46
Base
CaloTowerContainer::getTowerIndices
bool getTowerIndices(const CaloTower *aTower, index_t &indexEta, index_t &indexPhi) const
Returns both and indices for a given tower.
Definition: CaloTowerContainer.cxx:235
CaloTowerContainer::getTowerEtaIndex
index_t getTowerEtaIndex(const CaloTower *aTower) const
Returns the index for a given tower.
Definition: Calorimeter/CaloEvent/CaloEvent/CaloTowerContainer.h:616
DataVector< CaloTower >::swap
void swap(DataVector &rhs)
Swap this collection with another.
DataVector< CaloTower >::insert
iterator insert(iterator position, value_type pElem)
Add a new element to the collection.
DataVector< CaloTower >
WriteCalibToCool.swap
swap
Definition: WriteCalibToCool.py:94
DataPool::nextElementPtr
pointer nextElementPtr()
obtain the next available element in pool by pointer pool is resized if its limit has been reached On...
CaloPhiRange::fix
static double fix(double phi)
Definition: CaloPhiRange.cxx:14
DataVector< CaloTower >::operator[]
const CaloTower * operator[](size_type n) const
Access an element, as an rvalue.
DataVector< CaloTower >::clear
void clear()
Erase all the elements in the collection.
DataPool.h
CaloTowerContainer::getCalos
size_t getCalos(std::vector< CaloCell_ID::SUBCALO > &theCalos) const
Retrieve the list of used calorimeters.
Definition: CaloTowerContainer.cxx:180
CaloTower
Data class for calorimeter cell towers.
Definition: Calorimeter/CaloEvent/CaloEvent/CaloTower.h:55
P4EEtaPhiM::setPhi
virtual void setPhi(double thePhi)
set phi data member
Definition: P4EEtaPhiM.h:120
DataVector< CaloTower >::resize
void resize(size_type sz)
Resizes the collection to the specified number of elements.
DataVector< CaloTower >::push_back
value_type push_back(value_type pElem)
Add an element to the end of the collection.
CaloTowerContainer::~CaloTowerContainer
virtual ~CaloTowerContainer()
Destructor.
CaloTowerSeg::etamin
double etamin() const
Retrieve lower boundary value range.
Definition: CaloTowerSeg.h:443
eflowRec::phiIndex
unsigned int phiIndex(float phi, float binsize)
calculate phi index for a given phi
Definition: EtaPhiLUT.cxx:23
CaloTowerContainer::index_t
size_t index_t
Tower map index type.
Definition: Calorimeter/CaloEvent/CaloEvent/CaloTowerContainer.h:82
InDetDD::other
@ other
Definition: InDetDD_Defs.h:16
CaloTowerContainer::clear
void clear()
INavigable4Momentum
Definition: INavigable4Momentum.h:21
CaloTowerContainer::m_towerSeg
CaloTowerSeg m_towerSeg
Tower grid descriptor.
Definition: Calorimeter/CaloEvent/CaloEvent/CaloTowerContainer.h:517
DeMoScan.first
bool first
Definition: DeMoScan.py:534
CaloTowerContainer::swap
void swap(CaloTowerContainer &other)
Swap.
Definition: CaloTowerContainer.cxx:95
CaloTowerContainer::energy
double energy(double theEta, double thePhi) const
Return the tower energy at a given grid position.
Definition: CaloTowerContainer.cxx:208
DataPool
a typed memory pool that saves time spent allocation small object. This is typically used by containe...
Definition: DataPool.h:47
P4EEtaPhiM::setE
virtual void setE(double theE)
set energy data member
Definition: P4EEtaPhiM.h:114
DataVector< CaloTower >::ownPolicy
SG::OwnershipPolicy ownPolicy() const
Return the ownership policy setting for this container.
CaloTowerContainer::m_outOfRange
static const index_t m_outOfRange
Index overflow indicator.
Definition: Calorimeter/CaloEvent/CaloEvent/CaloTowerContainer.h:530
CaloTowerSeg
Data object stores CaloTower segmentation.
Definition: CaloTowerSeg.h:37
CaloTowerContainer::getTowerPhiIndex
index_t getTowerPhiIndex(const CaloTower *aTower) const
Returns the index for a given tower.
Definition: Calorimeter/CaloEvent/CaloEvent/CaloTowerContainer.h:633
CaloTowerContainer::setCalo
void setCalo(const CaloCell_ID::SUBCALO &nCalo)
Adds a calorimeter index to the tower.
Definition: CaloTowerContainer.cxx:169
CaloTower::eta
virtual double eta() const override final
get eta data member
Definition: Calorimeter/CaloEvent/CaloEvent/CaloTower.h:141