ATLAS Offline Software
Loading...
Searching...
No Matches
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
7NAME: CaloTowerContainer.cxx
8PACKAGE: offline/Calorimeter/CaloRec
9
10AUTHORS: S. Rajagopalan
11CREATED: Oct 29, 2000
12
13PURPOSE:
14
15Updated: Jan 3, 2001 (HM)
16 QA.
17
18Updated: 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"
30#ifdef CALOTOWERCONTAINER_USES_DATAPOOL
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
47 : Base(SG::VIEW_ELEMENTS)
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),
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
86 Base::operator= (other);
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
111 index_t etaBins = (index_t)m_towerSeg.neta();
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
153void 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
179size_t
180CaloTowerContainer::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
202double CaloTowerContainer::energy(index_t etaIndex, index_t phiIndex) const
203{
204 const CaloTower* t = this->getTower(etaIndex,phiIndex);
205 return t ? t->e() : 0;
206}
207// energy in (eta,phi)
208double 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
215double CaloTowerContainer::et(index_t etaIndex, index_t phiIndex) const
216{
217 const CaloTower* t = this->getTower(etaIndex, phiIndex);
218 return t ? t->et() : 0;
219}
220
221
222// et in (eta,phi)
223double 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}
243bool 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;
281 index_t phiIndex = m_outOfRange;
282 return this->getTowerIndices(theEta,thePhi,etaIndex,phiIndex)
283 ? (this->operator[])(this->getTowerIndex(etaIndex,phiIndex))
284 : (const CaloTower*)nullptr;
285}
286CaloTower* CaloTowerContainer::getTower(double theEta, double thePhi)
287{
288 index_t etaIndex = m_outOfRange;
289 index_t phiIndex = 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
Scalar deltaPhi(const MatrixBase< Derived > &vec) const
H5Mergers.
CaloCell_Base_ID::SUBCALO SUBCALO
Definition CaloCell_ID.h:50
void removeCells()
Remove all cells without kinematic update.
static double fix(double phi)
Iterator class for which the reference type is not an lvalue.
Storable container class for CaloTower.
double et(double theEta, double thePhi) const
Return the tower transverse energy at a given grid position.
CaloTowerContainer()
Default constructor.
index_t getTowerIndex(const CaloTower *aTower) const
Returns the combined index of a tower on the grid.
CaloTowerContainer & operator=(const CaloTowerContainer &other)
Assignment.
double energy(double theEta, double thePhi) const
Return the tower energy at a given grid position.
CaloTower * getTower(index_t eta, index_t phi)
Returns a pointer to a tower with given indices.
void setCalo(const CaloCell_ID::SUBCALO &nCalo)
Adds a calorimeter index to the tower.
size_t getCalos(std::vector< CaloCell_ID::SUBCALO > &theCalos) const
Retrieve the list of used calorimeters.
static const index_t m_outOfRange
Index overflow indicator.
void init()
Initializes the CaloTowerContainer.
index_t getTowerEtaIndex(const CaloTower *aTower) const
Returns the index for a given tower.
std::vector< unsigned int > m_caloRegions
Vector of calorimeter regions contributing to the tower signals.
virtual ~CaloTowerContainer()
Destructor.
void swap(CaloTowerContainer &other)
Swap.
index_t getTowerPhiIndex(const CaloTower *aTower) const
Returns the index for a given tower.
void insert(iterator position, iterator first, iterator last)
void push_back(value_type pElem)
bool getTowerIndices(const CaloTower *aTower, index_t &indexEta, index_t &indexPhi) const
Returns both and indices for a given tower.
Data object stores CaloTower segmentation.
index_t nphi() const
Retrieve number of bins.
index_t neta() const
Retrieve number of bins.
Data class for calorimeter cell towers.
virtual double phi() const override final
get phi data member
virtual double eta() const override final
get eta data member
a typed memory pool that saves time spent allocation small object.
Definition DataPool.h:63
pointer nextElementPtr()
obtain the next available element in pool by pointer pool is resized if its limit has been reached On...
Derived DataVector<T>.
Definition DataVector.h:795
void resize(size_type sz)
const CaloTower * operator[](size_type n) const
void swap(DataVector &rhs)
value_type push_back(value_type pElem)
iterator insert(iterator position, value_type pElem)
DataVector(SG::OwnershipPolicy ownPolicy=SG::OWN_ELEMENTS, SG::IndexTrackingPolicy trackIndices=SG::DEFAULT_TRACK_INDICES)
SG::OwnershipPolicy ownPolicy() const
size_type size() const noexcept
DataVector & operator=(const DataVector &rhs)
virtual void setEta(double theEta)
set eta data member
Definition P4EEtaPhiM.h:117
virtual void setE(double theE)
set energy data member
Definition P4EEtaPhiM.h:114
virtual void setPhi(double thePhi)
set phi data member
Definition P4EEtaPhiM.h:120
Forward declaration.
OwnershipPolicy
@ VIEW_ELEMENTS
this data object is a view, it does not own its elmts
void swap(ElementLinkVector< DOBJ > &lhs, ElementLinkVector< DOBJ > &rhs)