ATLAS Offline Software
CaloBinDescriptor.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #ifndef CALOEVENT_CALOBINDESCRIPTOR_H
6 #define CALOEVENT_CALOBINDESCRIPTOR_H
7 
8 #include <vector>
9 
10 template<typename T>
12 {
13  public:
14 
16  CaloBinDescriptor() { m_bins.clear(); };
18  explicit CaloBinDescriptor(const CaloBinDescriptor& theBins);
30  CaloBinDescriptor(const std::vector<T>& theBins);
44  CaloBinDescriptor(size_t nBins, const T& lowerLimit, const T& upperLimit);
47 
52  size_t getNumberOfBins() const;
54  T lowerBound() const;
56  T upperBound() const;
57 
66  T lowerBinEdge(size_t theIndex) const;
75  T upperBinEdge(size_t theIndex) const;
84  T binWidth(size_t theIndex) const;
85 
87  const std::vector<T>& getBinning() const;
88 
97  size_t getIndex(const T& theData) const;
98 
105  bool outOfRange(size_t theIndex) const;
107  size_t outOfRangeMarker() const;
108 
109  private:
110 
115  std::vector<T> m_bins;
116 
118  static const size_t m_outOfRange;
119 };
120 
121 template<typename T>
123  : m_bins (theBins.m_bins)
124 {
125 }
126 
127 template<typename T>
130 {
131  if (this != &theBins)
132  m_bins = theBins.m_bins;
133  return *this;
134 }
135 
136 template<typename T>
137 const size_t CaloBinDescriptor<T>::m_outOfRange = size_t(-1);
138 
139 template<typename T>
140 CaloBinDescriptor<T>::CaloBinDescriptor(const std::vector<T>& theBins)
141  : m_bins (theBins)
142 {
143 }
144 
145 template<typename T>
147  const T& upperEdge)
148 {
149  if ( lowerEdge < upperEdge && nBins > 0 )
150  {
151  double fBin =lowerEdge;
152  double dBin = ( upperEdge - lowerEdge ) / (double)nBins;
153  while ( fBin <= ( upperEdge + dBin/2. ) )
154  {
155  m_bins.push_back(fBin);
156  fBin += dBin;
157  }
158  }
159  else
160  {
161  m_bins.clear();
162  }
163 }
164 
165 template<typename T>
167 {
168  return m_bins.size()-1;
169 }
170 
171 template<typename T>
173 {
174  return m_bins.size() > 0 ? *(m_bins.begin()) : 0.;
175 }
176 
177 template<typename T>
179 {
180  return m_bins.size() > 0 ? *(--(m_bins.end())) : 0.;
181 }
182 
183 template<typename T>
184 inline T CaloBinDescriptor<T>::lowerBinEdge(size_t theIndex) const
185 {
186  return theIndex < m_bins.size()-2 ? m_bins[theIndex] : 0.;
187 }
188 
189 template<typename T>
190 inline T CaloBinDescriptor<T>::upperBinEdge(size_t theIndex) const
191 {
192  return theIndex < m_bins.size()-1 ? m_bins[theIndex+1] : 0;
193 }
194 
195 template<typename T>
196 inline T CaloBinDescriptor<T>::binWidth(size_t theIndex) const
197 {
198  return theIndex < m_bins.size()-2
199  ? m_bins[theIndex+1] - m_bins[theIndex]
200  : 0.;
201 }
202 
203 template<typename T>
204 inline const std::vector<T>& CaloBinDescriptor<T>::getBinning() const
205 {
206  return m_bins;
207 }
208 
209 template<typename T>
210 size_t CaloBinDescriptor<T>::getIndex(const T& theData) const
211 {
212  size_t theIndex = 0;
213  while ( theIndex < this->getNumberOfBins() && theData > m_bins[theIndex] )
214  {
215  theIndex++;
216  }
217  return theIndex < this->getNumberOfBins() ? theIndex : m_outOfRange;
218 }
219 
220 template<typename T>
221 inline bool CaloBinDescriptor<T>::outOfRange(size_t theIndex) const
222 {
223  return theIndex != m_outOfRange
224  ? theIndex < this->getNumberOfBins()
225  : true;
226 }
227 
228 template<typename T>
230 {
231  return m_outOfRange;
232 }
233 
249 #endif
CaloBinDescriptor::outOfRangeMarker
size_t outOfRangeMarker() const
Returns the value of the out-of-range marker.
Definition: CaloBinDescriptor.h:229
CaloBinDescriptor::upperBinEdge
T upperBinEdge(size_t theIndex) const
Retrieve the upper bin edge of a given bin.
Definition: CaloBinDescriptor.h:190
CaloBinDescriptor::operator=
CaloBinDescriptor & operator=(const CaloBinDescriptor &theBins)
Assignment.
Definition: CaloBinDescriptor.h:129
CaloBinDescriptor::binWidth
T binWidth(size_t theIndex) const
Retrieve the bin width of a given bin.
Definition: CaloBinDescriptor.h:196
CaloBinDescriptor::outOfRange
bool outOfRange(size_t theIndex) const
Tests if given index is out of valid range.
Definition: CaloBinDescriptor.h:221
CaloBinDescriptor::CaloBinDescriptor
CaloBinDescriptor(const CaloBinDescriptor &theBins)
Explicit copy constructor.
Definition: CaloBinDescriptor.h:122
CaloBinDescriptor::getIndex
size_t getIndex(const T &theData) const
Get the index for a iven value.
Definition: CaloBinDescriptor.h:210
CaloBinDescriptor::m_bins
std::vector< T > m_bins
Bin store.
Definition: CaloBinDescriptor.h:115
CaloBinDescriptor::CaloBinDescriptor
CaloBinDescriptor(size_t nBins, const T &lowerLimit, const T &upperLimit)
Construct with regular bins.
Definition: CaloBinDescriptor.h:146
CaloBinDescriptor::CaloBinDescriptor
CaloBinDescriptor()
Default constructor generates empty bin descriptor.
Definition: CaloBinDescriptor.h:16
CaloBinDescriptor
Data object containing bin descriptions.
Definition: CaloBinDescriptor.h:12
CaloBinDescriptor::getBinning
const std::vector< T > & getBinning() const
Direct Access to the vector describing the binning.
Definition: CaloBinDescriptor.h:204
CaloBinDescriptor::lowerBound
T lowerBound() const
Retrieve the lower value range boundary.
Definition: CaloBinDescriptor.h:172
CaloBinDescriptor::~CaloBinDescriptor
~CaloBinDescriptor()
Default constructor.
Definition: CaloBinDescriptor.h:46
CaloBinDescriptor::lowerBinEdge
T lowerBinEdge(size_t theIndex) const
Retrieve the lower bin edge of a given bin.
Definition: CaloBinDescriptor.h:184
dumpTgcDigiJitter.nBins
list nBins
Definition: dumpTgcDigiJitter.py:29
CaloBinDescriptor::upperBound
T upperBound() const
Retrieve the upper value range boundary.
Definition: CaloBinDescriptor.h:178
CaloBinDescriptor::m_outOfRange
static const size_t m_outOfRange
Out-of-range marker (convention)
Definition: CaloBinDescriptor.h:118
CaloBinDescriptor::CaloBinDescriptor
CaloBinDescriptor(const std::vector< T > &theBins)
Construct with variable sized bins.
Definition: CaloBinDescriptor.h:140
CaloBinDescriptor::getNumberOfBins
size_t getNumberOfBins() const
Retrieve the number of bins.
Definition: CaloBinDescriptor.h:166
TSU::T
unsigned long long T
Definition: L1TopoDataTypes.h:35