ATLAS Offline Software
CaloSum.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 #include "CaloEvent/CaloCell.h"
9 #include "CaloEvent/CaloSum.h"
10 
11 #include <vector>
12 #include <algorithm>
13 
15 // Constructors and Destructor //
17 
18 CaloSum::CaloSum() : m_defaultRanges(true)
19  , m_numberOfSums(0)
20  , m_varType(UnknownType)
21  , m_binDescriptor(size_t(0),0.,0.) {}
22 
23 
25  const CaloBinDescriptor<double>& theBins,
26  size_t numberOfSums)
27  : m_defaultRanges(true)
28  , m_numberOfSums(numberOfSums)
29  , m_varType(varType)
30  , m_binDescriptor(theBins)
31 {
32  this->setUp();
33 }
34 //
35 //CaloSum::CaloSum(CaloVarType varType,
36 // const CaloBinDescriptor<double>& theBins,
37 // const std::vector<CaloRegion>& theRegions,
38 // size_t numberOfSums)
39 // : m_defaultRanges(true)
40 // , m_numberOfSums(numberOfSums)
41 // , m_varType(varType)
42 // , m_caloBinDescriptor(theBins)
43 //{
44 // this->setUp();
45 //}
46 
48 = default;
49 
51 // Configuration //
53 
54 bool CaloSum::setRegion(const CaloRegion& theRegion,
55  double etaLow,
56  double etaHigh)
57 {
58  std::vector<double> lowEtas; lowEtas.push_back(etaLow);
59  std::vector<double> highEtas; highEtas.push_back(etaHigh);
60  return this->setRegion(theRegion,lowEtas,highEtas);
61 }
62 
63 //
64 //bool CaloSum::setRegion(const std::vector<CaloSum::CaloRegion>& theRegions,
65 // const std::vector<double>& etaLow,
66 // const std::vector<double>& etaHigh)
67 //{
68 // //check internal state
69 // if ( m_defaultRanges )
70 // {
71 // m_defaultRanges = false;
72 // m_regionRanges.clear();
73 // }
74 // // check input
75 // if ( theRegions.size() != etaLow.size() ||
76 // theRegions.size() != etaHigh.size() )
77 // {
78 // return false;
79 // }
80 //
81 // unsigned int i = 0;
82 // bool bailOut = false;
83 // while ( ! bailOut && i<theRegions.size() )
84 // {
85 // std::vector<double> lowEtas = etaLow[i];
86 // std::vector<double> highEtas = etaHigh[i];
87 // bailOut = ! this->setRegion(theRegions[i],lowEtas,highEtas);
88 // i++;
89 // }
90 //
91 // return ! bailOut;
92 //}
93 
94 bool CaloSum::setRegion(const CaloRegion& theRegion,
95  const std::vector<double>& lowEtas,
96  const std::vector<double>& highEtas)
97 {
98  // check matching vectors
99  if ( lowEtas.size() != highEtas.size() || lowEtas.empty() )
100  {
101  return false;
102  }
103  // check on defaults
104  if ( m_defaultRanges )
105  {
106  m_regionRanges.clear();
107  m_defaultRanges = false;
108  }
109 
110  // store eta ranges
111  for (unsigned int i=0; i<lowEtas.size(); i++ )
112  {
113  range_t theRange(lowEtas[i],highEtas[i]);
114  (m_regionRanges[theRegion]).push_back(theRange);
115  }
116  return !m_regionRanges.empty();
117 }
118 
120 {
121  return m_varType;
122 }
123 
125 {
126  range_map_t::const_iterator fRegion = m_regionRanges.begin();
127  bool isFound = false;
128  while ( ! isFound && fRegion != m_regionRanges.end() )
129  {
130  range_cont_t::const_iterator fRange = ((*fRegion).second).begin();
131  while ( ! isFound && fRange != ((*fRegion).second).end() )
132  {
133  double lowEdge = (*fRange).first;
134  double highEdge = (*fRange).second;
135  isFound = ( lowEdge <= theEta && theEta < highEdge );
136  ++fRange;
137  }
138  ++fRegion;
139  }
140  return isFound ? (*(--fRegion)).first : UnknownRegion ;
141 }
142 
143 bool CaloSum::getRange(const CaloRegion& theRegion,
144  std::vector<double>& lowEtas,
145  std::vector<double>& highEtas) const
146 {
147  range_map_t::const_iterator fRegion = m_regionRanges.find(theRegion);
148  if ( fRegion != m_regionRanges.end() )
149  {
150  lowEtas.resize(((*fRegion).second).size());
151  highEtas.resize(((*fRegion).second).size());
152  for ( unsigned int i=0; i<((*fRegion).second).size(); i++ )
153  {
154  lowEtas[i] = (((*fRegion).second)[i]).first;
155  highEtas[i] = (((*fRegion).second)[i]).second;
156  }
157  return true;
158  }
159  else
160  {
161  return false;
162  }
163 }
164 //
165 //bool CaloSum::getRange(double theEta,
166 // std::vector<double>& lowEtas,
167 // std::vector<double>& highEtas)
168 //{
169 // CaloRegion theRegion = this->getRegion(theEta);
170 // return this->getRange(theRegion,lowEtas,highEtas);
171 //}
172 
174 {
176 }
177 
179 {
180  // return m_sumStore.size() > 0
181  // ? ((m_sumStore.begin()).second).size()
182  // : 0;
183  return m_numberOfSums;
184 }
185 
186 bool CaloSum::getVariableRange(double& lowerLimit, double& upperLimit) const
187 {
188  lowerLimit = m_binDescriptor.lowerBound();
189  upperLimit = m_binDescriptor.upperBound();
190  return lowerLimit < upperLimit;
191 }
192 
193 bool CaloSum::getBinEdges(size_t theIndex,
194  double& lowerLimit,
195  double& upperLimit) const
196 {
197  lowerLimit = m_binDescriptor.lowerBinEdge(theIndex);
198  upperLimit = m_binDescriptor.upperBinEdge(theIndex);
199  return lowerLimit < upperLimit;
200 }
201 
202 bool CaloSum::getBinCenter(size_t theIndex, double& binCenter) const
203 {
204  double lowEdge, highEdge;
205  if ( this->getBinEdges(theIndex,lowEdge,highEdge) )
206  {
207  binCenter = ( highEdge + lowEdge ) / 2.;
208  return true;
209  }
210  else
211  {
212  return false;
213  }
214 }
215 
217 {
218  return m_binDescriptor;
219 }
220 
222 // Data Accumulation //
224 
225 // extract everything from CaloCell
226 bool CaloSum::add(const CaloCell* theCell,
227  double theBinnedVariable,
228  double theSummedVariable)
229 {
230  std::vector<double> theSums; theSums.push_back(theSummedVariable);
231  return this->add(theCell,theBinnedVariable,theSums);
232 }
233 
234 bool CaloSum::add(const CaloCell* theCell,
235  double theBinnedVariable,
236  const std::vector<double>& theSummedVariables)
237 {
238  // get sampling
239  CaloSampling::CaloSample theSampling = theCell->caloDDE()->getSampling();
240  // add up
241  return this->add(theSampling,theCell->eta(),theBinnedVariable,
242  theSummedVariables);
243 }
244 
245 // regions defined by eta ranges (explicit indices)
246 bool CaloSum::add(const CaloSampling::CaloSample& theSampling,
247  double theEta,
248  double theBinnedVariable,
249  double theSummedVariable)
250 {
251  std::vector<double> theSums; theSums.push_back(theSummedVariable);
252  return this->add(theSampling,theEta,theBinnedVariable,theSums);
253 }
254 
255 bool CaloSum::add(const CaloSampling::CaloSample& theSampling,
256  double theEta,
257  double theBinnedVariable,
258  const std::vector<double>& theSummedVariables)
259 {
260  // find bin
261  size_t theIndex = m_binDescriptor.getIndex(theBinnedVariable);
262  if ( m_binDescriptor.outOfRange(theIndex) )
263  {
264  return false;
265  }
266  // get key
267  key_t theKey = this->getKey(theEta,theSampling);
268  // find in map and generate new if not found
269  store_iter_t theAllocator = m_sumStore.find(theKey);
270  if ( theAllocator == m_sumStore.end() )
271  {
272  data_t theDataVector;
273  theDataVector.resize(m_numberOfSums,0.);
274  bin_t theBinVector;
275  theBinVector.resize(m_binDescriptor.getNumberOfBins(),
276  theDataVector);
277  m_sumStore[theKey] = theBinVector;
278  theAllocator = m_sumStore.find(theKey);
279  }
280  // sum up
281  size_t theSize =
282  (((*theAllocator).second)[theIndex]).size() <= theSummedVariables.size()
283  ? (((*theAllocator).second)[theIndex]).size()
284  : theSummedVariables.size();
285  for ( unsigned int i=0; i<theSize; i++ )
286  {
287  (((*theAllocator).second)[theIndex])[i] += theSummedVariables[i];
288  }
289 
290  return true;
291 }
292 
294 // Data Access //
296 
298 {
299  return m_sumStore.begin();
300 }
301 
303 {
304  return m_sumStore.end();
305 }
306 
309 {
310  return ((*theIterator).first).first;
311 }
312 
315 {
316  return ((*theIterator).first).second;
317 }
318 
320  size_t theIndex,
321  std::vector<double>& theSums) const
322 {
323  // check index range
324  if ( m_binDescriptor.outOfRange(theIndex) )
325  {
326  return false;
327  }
328  // check sum vector
329  theSums.resize( (((*theIterator).second)[theIndex]).size(), 0. );
330  std::copy( (((*theIterator).second)[theIndex]).begin(),
331  (((*theIterator).second)[theIndex]).end(),
332  theSums.begin());
333  return !theSums.empty();
334 }
335 
337  double theBinnedVariable,
338  std::vector<double>& theSums) const
339 {
340  return this->getSums(theIterator,
341  m_binDescriptor.getIndex(theBinnedVariable),
342  theSums);
343 }
344 
345 bool CaloSum::getSums(const CaloRegion& theRegion,
346  const CaloSampling::CaloSample& theSampling,
347  size_t theIndex,
348  std::vector<double>& theSums) const
349 {
350  // check basics
351  if ( m_binDescriptor.outOfRange(theIndex) )
352  {
353  return false;
354  }
355  // find element
356  key_t theKey = CaloSum::getKey(theRegion,theSampling);
357  store_const_iter_t theAccessor = m_sumStore.find(theKey);
358  if ( theAccessor != m_sumStore.end() )
359  {
360  theSums.resize((((*theAccessor).second)[theIndex]).size(),0.);
361  std::copy((((*theAccessor).second)[theIndex]).begin(),
362  (((*theAccessor).second)[theIndex]).end(),
363  theSums.begin());
364  return !theSums.empty();
365  }
366  return false;
367 }
368 
369 bool CaloSum::getSums(const CaloRegion& theRegion,
370  const CaloSampling::CaloSample& theSampling,
371  double theBinnedVariable,
372  std::vector<double>& theSums) const
373 {
374  return this->getSums(theRegion,
375  theSampling,
376  m_binDescriptor.getIndex(theBinnedVariable),
377  theSums);
378 }
379 //
380 //bool CaloSum::getSums(const CaloSampling::CaloSample& theSampling,
381 // double theEta,
382 // size_t theIndex,
383 // std::vector<double>& theSums) const
384 //{
385 // CaloRegion theRegion = this->getRegion(theEta);
386 // return this->getSums(theRegion,theSampling,theIndex,theSums);
387 //}
388 
389 bool CaloSum::contains(const CaloRegion& theRegion) const
390 {
391  bool found = false;
392  store_const_iter_t firstEntry = m_sumStore.begin();
393  store_const_iter_t lastEntry = m_sumStore.end();
394  while ( firstEntry != lastEntry && ! found )
395  {
396  found = ((*firstEntry).first).first == theRegion;
397  ++firstEntry;
398  }
399  return found;
400 }
401 
402 bool CaloSum::contains(const CaloSampling::CaloSample& theSampling) const
403 {
404  bool found = false;
405  store_const_iter_t firstEntry = m_sumStore.begin();
406  store_const_iter_t lastEntry = m_sumStore.end();
407  while ( firstEntry != lastEntry && ! found )
408  {
409  found = ((*firstEntry).first).second == theSampling;
410  ++firstEntry;
411  }
412  return found;
413 }
414 
415 bool CaloSum::contains(const CaloRegion& theRegion,
416  const CaloSampling::CaloSample& theSampling) const
417 {
418  return
419  m_sumStore.find(CaloSum::getKey(theRegion,theSampling)) !=
420  m_sumStore.end();
421 }
422 
424 // Private Helpers //
426 
428 {
429  // pre-defined ranges
430  range_t centralRange(-0.8,0.8);
431  (m_regionRanges[Central]).push_back(centralRange);
432  range_t endCapPos(0.8,2.5);
433  range_t endCapNeg(-2.5,-0.8);
434  (m_regionRanges[EndCap]).push_back(endCapPos);
435  (m_regionRanges[EndCap]).push_back(endCapNeg);
436  range_t forwardPos(2.5,5.0);
437  range_t forwardNeg(-5.0,-2.5);
438  (m_regionRanges[Forward]).push_back(forwardPos);
439  (m_regionRanges[Forward]).push_back(forwardNeg);
440  return true;
441 }
442 
444  const CaloSampling::CaloSample& theSampling)
445 
446 {
447  return key_t(theRegion,theSampling);
448 }
449 
451  const CaloSampling::CaloSample& theSampling)
452  const
453 {
454  CaloRegion theRegion = this->getRegion(theEta);
455  return this->getKey(theRegion,theSampling);
456 }
457 
CaloSum::Central
@ Central
Central region indicator.
Definition: CaloSum.h:24
python.SystemOfUnits.second
int second
Definition: SystemOfUnits.py:120
CaloSum::getNumberOfSums
virtual size_t getNumberOfSums() const
Returns number of sums in each bin.
Definition: CaloSum.cxx:178
CaloBinDescriptor::upperBinEdge
T upperBinEdge(size_t theIndex) const
Retrieve the upper bin edge of a given bin.
Definition: CaloBinDescriptor.h:190
CaloSum::data_t
std::vector< double > data_t
Data type for parallel running sums in a bin.
Definition: CaloSum.h:47
CaloBinDescriptor.h
CaloBinDescriptor::outOfRange
bool outOfRange(size_t theIndex) const
Tests if given index is out of valid range.
Definition: CaloBinDescriptor.h:221
CaloSum::m_regionRanges
range_map_t m_regionRanges
Store for region ranges.
Definition: CaloSum.h:496
CaloSum.h
CaloLCWConfig.theKey
string theKey
Definition: CaloLCWConfig.py:68
CaloSum::Forward
@ Forward
Forward region indicator.
Definition: CaloSum.h:26
CaloSum::EndCap
@ EndCap
Central region indicator.
Definition: CaloSum.h:25
CaloSum::CaloSum
CaloSum()
Default constructor.
Definition: CaloSum.cxx:18
CaloSum::key_t
std::pair< CaloRegion, CaloSampling::CaloSample > key_t
Key type for compressed storage.
Definition: CaloSum.h:44
CaloSum::getBinCenter
virtual bool getBinCenter(size_t theIndex, double &binCenter) const
Returns bin center.
Definition: CaloSum.cxx:202
CaloSum::getRange
virtual bool getRange(const CaloRegion &theRegion, std::vector< double > &lowEtas, std::vector< double > &highEtas) const
Returns eta range(s) for a given region.
Definition: CaloSum.cxx:143
CaloBinDescriptor::getIndex
size_t getIndex(const T &theData) const
Get the index for a iven value.
Definition: CaloBinDescriptor.h:210
CaloSum::store_iter_t
store_t::iterator store_iter_t
Store iterator type.
Definition: CaloSum.h:63
CaloSum::getSums
bool getSums(const_iterator &theIterator, size_t theBinIndex, std::vector< double > &theSums) const
Returns sums for a given iterator.
Definition: CaloSum.cxx:319
CaloCell.h
CaloSum::m_sumStore
store_t m_sumStore
Store for sums.
Definition: CaloSum.h:499
CaloSum::end
const_iterator end() const
Store end iterator.
Definition: CaloSum.cxx:302
CaloSum::begin
const_iterator begin() const
Store begin iterator.
Definition: CaloSum.cxx:297
CaloBinDescriptor< double >
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
CaloSum::range_t
std::pair< double, double > range_t
Range type.
Definition: CaloSum.h:68
CaloSum::getBinDescriptor
virtual const CaloBinDescriptor< double > & getBinDescriptor() const
Returns reference to complete bin descriptor.
Definition: CaloSum.cxx:216
CaloBinDescriptor::lowerBound
T lowerBound() const
Retrieve the lower value range boundary.
Definition: CaloBinDescriptor.h:172
lumiFormat.i
int i
Definition: lumiFormat.py:92
CaloSampling::CaloSample
CaloSample
Definition: Calorimeter/CaloGeoHelpers/CaloGeoHelpers/CaloSampling.h:22
CaloCell::caloDDE
const CaloDetDescrElement * caloDDE() const
get pointer to CaloDetDescrElement (data member)
Definition: CaloCell.h:305
CaloBinDescriptor::lowerBinEdge
T lowerBinEdge(size_t theIndex) const
Retrieve the lower bin edge of a given bin.
Definition: CaloBinDescriptor.h:184
CaloSum::setUp
bool setUp()
Set up defaults.
Definition: CaloSum.cxx:427
CaloSum::setRegion
virtual bool setRegion(const CaloSum::CaloRegion &theRegion, double etaLow, double etaHigh)
Configure regions.
Definition: CaloSum.cxx:54
CaloSum::getVariableRange
virtual bool getVariableRange(double &lowLimit, double &highLimit) const
Returs lower and upper limit of binned variable range.
Definition: CaloSum.cxx:186
CaloSum::UnknownRegion
@ UnknownRegion
Unknown region.
Definition: CaloSum.h:29
CaloSum::m_defaultRanges
bool m_defaultRanges
Process flow control: indicates default range overwrite.
Definition: CaloSum.h:484
CaloBinDescriptor::upperBound
T upperBound() const
Retrieve the upper value range boundary.
Definition: CaloBinDescriptor.h:178
CaloSum::m_varType
CaloVarType m_varType
Binned variable type.
Definition: CaloSum.h:490
CaloSum::getBinEdges
virtual bool getBinEdges(size_t theIndex, double &lowEdge, double &highEdge) const
Returns bin edges for a given bin.
Definition: CaloSum.cxx:193
G4AtlasPhysicsOption::UnknownType
@ UnknownType
Definition: IPhysicsOptionTool.h:26
CaloSum::contains
virtual bool contains(const CaloSum::CaloRegion &theRegion) const
Returns sums for a given sampling, eta, and index.
Definition: CaloSum.cxx:389
CaloSum::bin_t
std::vector< data_t > bin_t
Bin type.
Definition: CaloSum.h:54
CaloCell
Data object for each calorimeter readout cell.
Definition: CaloCell.h:57
CondAlgsOpts.found
int found
Definition: CondAlgsOpts.py:101
CaloDetDescrElement::getSampling
CaloCell_ID::CaloSample getSampling() const
cell sampling
Definition: Calorimeter/CaloDetDescr/CaloDetDescr/CaloDetDescrElement.h:395
DeMoScan.first
bool first
Definition: DeMoScan.py:534
CaloSum::CaloVarType
CaloVarType
Binned variable type.
Definition: CaloSum.h:34
CaloSum::store_const_iter_t
store_t::const_iterator store_const_iter_t
Store const iterator type.
Definition: CaloSum.h:65
CaloSum::m_binDescriptor
CaloBinDescriptor< double > m_binDescriptor
Bin descriptor.
Definition: CaloSum.h:493
CaloSum::~CaloSum
virtual ~CaloSum()
Useful constructor.
CaloBinDescriptor::getNumberOfBins
size_t getNumberOfBins() const
Retrieve the number of bins.
Definition: CaloBinDescriptor.h:166
CaloSum::add
virtual bool add(const CaloCell *theCell, double theBinnedVariable, const std::vector< double > &theSummedVariables)
Add to sums.
Definition: CaloSum.cxx:234
calibdata.copy
bool copy
Definition: calibdata.py:27
CaloSum::getVarType
virtual CaloVarType getVarType() const
Returns binned variable type.
Definition: CaloSum.cxx:119
CaloSum::getRegion
virtual CaloRegion getRegion(double theEta) const
Retrieve region for a given eta.
Definition: CaloSum.cxx:124
CaloSum::CaloRegion
CaloRegion
Region indicator implementation.
Definition: CaloSum.h:23
CaloSum::getNumberOfBins
virtual size_t getNumberOfBins() const
Returns number of bins.
Definition: CaloSum.cxx:173
CaloSum::getSampling
static CaloSampling::CaloSample getSampling(const_iterator &theIterator)
Returns sampling for a given iterator.
Definition: CaloSum.cxx:314
CaloCell::eta
virtual double eta() const override final
get eta (through CaloDetDescrElement)
Definition: CaloCell.h:366
CaloSum::const_iterator
store_const_iter_t const_iterator
Store iterator type.
Definition: CaloSum.h:123
CaloSum::m_numberOfSums
size_t m_numberOfSums
Store size: number of sums.
Definition: CaloSum.h:487
CaloSum::getKey
static key_t getKey(const CaloRegion &theRegion, const CaloSampling::CaloSample &theSample)
Translate into key.
Definition: CaloSum.cxx:443