ATLAS Offline Software
BinUtility.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 // BinUtility.h, (c) ATLAS Detector software
8 
9 #ifndef TRKDETDESCRUTILS_GENERICBINUTILITY1D_H
10 #define TRKDETDESCRUTILS_GENERICBINUTILITY1D_H
11 
12 // Gaudi
13 #include "GaudiKernel/GaudiException.h"
14 // Eigen
16 // Trk
19 
20 #include <vector>
21 
22 class MsgStream;
23 
24 namespace Trk {
25 
38 class BinUtility final
39 {
40 
41 public:
44  : m_binningData()
45  {
46  m_binningData.reserve(3);
47  }
48 
50  BinUtility(size_t bins, float min, float max, BinningOption opt = open, BinningValue value = binR, float sStep = 0.)
51  : m_binningData()
52  {
53  m_binningData.reserve(3);
54  std::vector<float> bValues;
55  float step = (max - min) / bins;
56  for (size_t ib = 0; ib <= bins; ++ib)
57  bValues.push_back(min + ib * step);
58  m_binningData.emplace_back(Trk::equidistant, opt, value, bins, min, max, step, sStep, bValues);
59  }
60 
62  BinUtility(size_t subbins, float substep, float min, float max, BinningOption opt = open, BinningValue value = binR)
63  : m_binningData()
64  {
65  m_binningData.reserve(3);
66  std::vector<float> bValues;
67  float step = (max - min) / (subbins + 1);
68  bValues.push_back(min);
69  for (size_t isb = 1; isb <= subbins; ++isb) {
70  bValues.push_back(min + isb * step - substep);
71  bValues.push_back(min + isb * step);
72  }
73  bValues.push_back(max);
74  m_binningData.emplace_back(Trk::biequidistant, opt, value, 2 * subbins + 1, min, max, step, substep, bValues);
75  }
76 
78  BinUtility(std::vector<float>& bValues, BinningOption opt = closed, BinningValue value = binPhi)
79  : m_binningData()
80  {
81  m_binningData.reserve(3);
82  size_t nBins = opt == 0 ? bValues.size() - 1 : bValues.size();
83 
84  m_binningData.emplace_back(Trk::arbitrary,
85  opt,
86  value,
87  nBins,
88  bValues[0],
89  bValues.back(),
90  (bValues.back() - bValues[0]) / (nBins),
91  0.,
92  bValues);
93  }
94 
96  BinUtility(float phiRef, std::vector<std::pair<int, float>>& bValues)
97  : m_binningData()
98  {
99  m_binningData.reserve(3);
100  m_binningData.emplace_back(Trk::open, phiRef, bValues);
101  }
102 
104  BinUtility(const BinUtility& sbu)
106  {}
107 
110  {
111  if (this != &sbu)
113  return (*this);
114  }
115 
118  {
119  const std::vector<BinningData>& bData = gbu.binningData();
120  if (m_binningData.size() + bData.size() > 3)
121  throw GaudiException("BinUtility does not support dim > 3", "FATAL", StatusCode::FAILURE);
122  m_binningData.insert(m_binningData.end(), bData.begin(), bData.end());
123  return (*this);
124  }
125 
128 
130  BinUtility* clone() const { return new BinUtility(*this); }
131 
133  const std::vector<BinningData>& binningData() const { return m_binningData; }
134 
136  size_t bin(const Amg::Vector3D& position, size_t ba = 0) const
137  {
138  if (ba >= m_binningData.size())
139  throw GaudiException("BinUtility", "dimension out of bounds", StatusCode::FAILURE);
140  size_t bEval = m_binningData[ba].searchGlobal(position);
141  return (bEval > bins(ba) - 1 ? bins(ba) - 1 : bEval); // ST additional protection : DEBUG source
142  }
143 
145  size_t entry(const Amg::Vector3D& position, size_t ba = 0) const
146  {
147  if (ba >= m_binningData.size())
148  throw GaudiException("BinUtility", "dimension out of bounds", StatusCode::FAILURE);
149  return m_binningData[ba].entry(position);
150  }
151 
153  size_t next(const Amg::Vector3D& position, const Amg::Vector3D& direction, size_t ba = 0) const
154  {
155  if (ba >= m_binningData.size())
156  throw GaudiException("BinUtility", "dimension out of bounds", StatusCode::FAILURE);
157  return m_binningData[ba].next(position, direction);
158  }
159 
161  std::pair<size_t, float> distanceToNext(const Amg::Vector3D& position,
162  const Amg::Vector3D& direction,
163  size_t ba = 0) const
164  {
165  if (ba >= m_binningData.size())
166  throw GaudiException("BinUtility", "dimension out of bounds", StatusCode::FAILURE);
167  return m_binningData[ba].distanceToNext(position, direction);
168  }
169 
171  LayerOrder orderDirection(const Amg::Vector3D& position, const Amg::Vector3D& direction, size_t ba = 0) const
172  {
173  if (ba >= m_binningData.size())
174  throw GaudiException("BinUtility", "dimension out of bounds", StatusCode::FAILURE);
175  return m_binningData[ba].orderDirection(position, direction);
176  }
177 
182  size_t bin(const Amg::Vector2D& lposition, size_t ba = 0) const
183  {
184  if (ba >= m_binningData.size())
185  throw GaudiException("BinUtility", "dimension out of bounds", StatusCode::FAILURE);
186  return m_binningData[ba].searchLocal(lposition);
187  }
188 
190  bool inside(const Amg::Vector3D& position) const
191  {
192  std::vector<BinningData>::const_iterator bdIter = m_binningData.begin();
193  for (; bdIter != m_binningData.end(); ++bdIter) {
194  if (!(*bdIter).inside(position))
195  return false;
196  }
197  return true;
198  }
199 
201  bool inside(const Amg::Vector2D& lposition) const
202  {
203  return true;
204  std::vector<BinningData>::const_iterator bdIter = m_binningData.begin();
205  for (; bdIter != m_binningData.end(); ++bdIter)
206  if (!(*bdIter).inside(lposition))
207  return false;
208  return true;
209  }
210 
212  size_t dimensions() const { return m_binningData.size(); }
213 
215  size_t max(size_t ba = 0) const
216  {
217  if (ba >= m_binningData.size())
218  return 0;
219  return (m_binningData[ba].bins - 1);
220  }
221 
223  size_t bins(size_t ba = 0) const
224  {
225  if (ba >= m_binningData.size())
226  return 0;
227  return (m_binningData[ba].bins);
228  }
229 
231  BinningValue binningValue(size_t ba = 0) const
232  {
233  if (ba >= m_binningData.size())
234  throw GaudiException("BinUtility", "dimension out of bounds", StatusCode::FAILURE);
235  return (m_binningData[ba].binvalue);
236  }
237 
239  float binPosition(size_t bin, float pos, size_t ba = 0) const
240  {
241  if (ba >= m_binningData.size())
242  throw GaudiException("BinUtility", "dimension out of bounds", StatusCode::FAILURE);
243  return (m_binningData[ba].binPosition(bin, pos));
244  }
245 
247  void clear() { m_binningData.clear(); }
248 
250  MsgStream& dump(MsgStream& sl) const
251  {
252  sl << "BinUtility for " << m_binningData.size() << "-dimensional array:" << endmsg;
253  std::vector<BinningData>::const_iterator bdIter = m_binningData.begin();
254  for (size_t ibd = 0; bdIter != m_binningData.end(); ++bdIter, ++ibd) {
255  sl << "dimension : " << ibd << endmsg << endmsg;
256  sl << " - type : " << size_t((*bdIter).type) << endmsg;
257  sl << " - option : " << size_t((*bdIter).option) << endmsg;
258  sl << " - value : " << size_t((*bdIter).binvalue) << endmsg;
259  sl << " - bins : " << (*bdIter).bins << endmsg;
260  sl << " - min/max : " << (*bdIter).min << " / " << (*bdIter).max << endmsg;
261  sl << " - step/sub : " << (*bdIter).step << " / " << (*bdIter).subStep << endmsg;
262  sl << " - boundaries : | ";
263  std::vector<float>::const_iterator bIter = (*bdIter).boundaries.begin();
264  for (; bIter != (*bdIter).boundaries.end(); ++bIter)
265  sl << (*bIter) << " | ";
266  sl << endmsg;
267  }
268  return sl;
269  }
270 
272  std::ostream& dump(std::ostream& sl) const
273  {
274  sl << "BinUtility for " << m_binningData.size() << "-dimensional array:" << std::endl;
275  std::vector<BinningData>::const_iterator bdIter = m_binningData.begin();
276  for (size_t ibd = 0; bdIter != m_binningData.end(); ++bdIter, ++ibd) {
277  sl << "dimension : " << ibd << std::endl;
278  sl << " - type : " << size_t((*bdIter).type) << std::endl;
279  sl << " - option : " << size_t((*bdIter).option) << std::endl;
280  sl << " - value : " << size_t((*bdIter).binvalue) << std::endl;
281  sl << " - bins : " << (*bdIter).bins << std::endl;
282  sl << " - min/max : " << (*bdIter).min << " / " << (*bdIter).max << std::endl;
283  sl << " - step/sub : " << (*bdIter).step << " / " << (*bdIter).subStep << std::endl;
284  sl << " - boundaries : | ";
285  std::vector<float>::const_iterator bIter = (*bdIter).boundaries.begin();
286  for (; bIter != (*bdIter).boundaries.end(); ++bIter)
287  sl << (*bIter) << " | ";
288  sl << std::endl;
289  }
290  return sl;
291  }
292 
293 private:
294  std::vector<BinningData> m_binningData;
295 };
296 
298 MsgStream&
299 operator<<(MsgStream& sl, const BinUtility& bgen);
300 std::ostream&
301 operator<<(std::ostream& sl, const BinUtility& bgen);
302 
303 } // end of namespace Trk
304 
305 #endif // TRKDETDESCRUTILS_GENERICBINUTILITY1D_H
Trk::BinUtility::BinUtility
BinUtility(size_t subbins, float substep, float min, float max, BinningOption opt=open, BinningValue value=binR)
Constructor for bi-equidistant.
Definition: BinUtility.h:62
Trk::BinUtility::entry
size_t entry(const Amg::Vector3D &position, size_t ba=0) const
Bin from a 3D vector (already in binning frame)
Definition: BinUtility.h:145
Trk::BinUtility::dimensions
size_t dimensions() const
First bin maximal value.
Definition: BinUtility.h:212
Trk::LayerOrder
LayerOrder
Definition: BinningData.h:31
Trk::equidistant
@ equidistant
Definition: BinningType.h:32
Trk::BinUtility::orderDirection
LayerOrder orderDirection(const Amg::Vector3D &position, const Amg::Vector3D &direction, size_t ba=0) const
Return the oder direciton for fast interlinking.
Definition: BinUtility.h:171
make_coralServer_rep.opt
opt
Definition: make_coralServer_rep.py:19
Trk::BinUtility::max
size_t max(size_t ba=0) const
First bin maximal value.
Definition: BinUtility.h:215
Amg::Vector2D
Eigen::Matrix< double, 2, 1 > Vector2D
Definition: GeoPrimitives.h:48
Trk::BinUtility::distanceToNext
std::pair< size_t, float > distanceToNext(const Amg::Vector3D &position, const Amg::Vector3D &direction, size_t ba=0) const
Distance estimate to next bin
Definition: BinUtility.h:161
bin
Definition: BinsDiffFromStripMedian.h:43
PlotCalibFromCool.ib
ib
Definition: PlotCalibFromCool.py:419
BinningType.h
Trk::biequidistant
@ biequidistant
Definition: BinningType.h:33
Trk::closed
@ closed
Definition: BinningType.h:41
athena.value
value
Definition: athena.py:124
Trk::BinUtility::operator=
BinUtility & operator=(const BinUtility &sbu)
Assignment operator Constructor.
Definition: BinUtility.h:109
Trk::BinUtility::BinUtility
BinUtility(float phiRef, std::vector< std::pair< int, float >> &bValues)
Constructor for binH.
Definition: BinUtility.h:96
Trk::BinUtility::clear
void clear()
Clear the data.
Definition: BinUtility.h:247
Trk::BinUtility::operator+=
BinUtility & operator+=(const BinUtility &gbu)
Operator++ to make multidimensional BinUtility.
Definition: BinUtility.h:117
Trk::BinUtility::bins
size_t bins(size_t ba=0) const
Number of bins.
Definition: BinUtility.h:223
Trk::BinUtility::BinUtility
BinUtility(size_t bins, float min, float max, BinningOption opt=open, BinningValue value=binR, float sStep=0.)
Constructor for equidistant - the substep is for phi binning offsets
Definition: BinUtility.h:50
Trk::BinUtility::BinUtility
BinUtility(std::vector< float > &bValues, BinningOption opt=closed, BinningValue value=binPhi)
Constructor for arbitrary.
Definition: BinUtility.h:78
Trk::arbitrary
@ arbitrary
Definition: BinningType.h:34
GeoPrimitives.h
Trk::BinUtility::BinUtility
BinUtility()
Constructor for equidistant.
Definition: BinUtility.h:43
Trk::BinningValue
BinningValue
how to take the global / local position
Definition: BinningType.h:46
Trk::BinUtility::BinUtility
BinUtility(const BinUtility &sbu)
Copy constructor.
Definition: BinUtility.h:104
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
Trk::BinUtility::dump
MsgStream & dump(MsgStream &sl) const
Output Method for MsgStream, to be overloaded by child classes.
Definition: BinUtility.h:250
Trk::BinUtility::inside
bool inside(const Amg::Vector2D &lposition) const
Check if bin is inside from Vector3D.
Definition: BinUtility.h:201
Trk::BinUtility::bin
size_t bin(const Amg::Vector2D &lposition, size_t ba=0) const
Bin from a 2D vector (following local parameters defintitions)
Definition: BinUtility.h:182
Trk::BinUtility::dump
std::ostream & dump(std::ostream &sl) const
Output Method for std::ostream, to be overloaded by child classes.
Definition: BinUtility.h:272
Trk::BinUtility::binningValue
BinningValue binningValue(size_t ba=0) const
The type/value of the binning.
Definition: BinUtility.h:231
min
#define min(a, b)
Definition: cfImp.cxx:40
Trk::BinUtility
Definition: BinUtility.h:39
Trk
Ensure that the ATLAS eigen extensions are properly loaded.
Definition: FakeTrackBuilder.h:9
dumpTgcDigiJitter.nBins
list nBins
Definition: dumpTgcDigiJitter.py:29
Trk::BinUtility::inside
bool inside(const Amg::Vector3D &position) const
Check if bin is inside from Vector3D.
Definition: BinUtility.h:190
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
python.LumiBlobConversion.pos
pos
Definition: LumiBlobConversion.py:18
Trk::open
@ open
Definition: BinningType.h:40
Trk::binR
@ binR
Definition: BinningType.h:50
Trk::operator<<
MsgStream & operator<<(MsgStream &sl, const AlignModule &alignModule)
overload of << operator for MsgStream for debug output
Definition: AlignModule.cxx:204
Trk::BinUtility::m_binningData
std::vector< BinningData > m_binningData
Definition: BinUtility.h:294
Trk::BinUtility::clone
BinUtility * clone() const
Implizit Constructor.
Definition: BinUtility.h:130
LArCellBinning.step
step
Definition: LArCellBinning.py:158
BinningData.h
Trk::BinUtility::binPosition
float binPosition(size_t bin, float pos, size_t ba=0) const
bin->BinningValue navigation : pos=+-1.
Definition: BinUtility.h:239
Trk::BinUtility::bin
size_t bin(const Amg::Vector3D &position, size_t ba=0) const
Bin from a 3D vector (already in binning frame)
Definition: BinUtility.h:136
Trk::BinUtility::binningData
const std::vector< BinningData > & binningData() const
return the binning data
Definition: BinUtility.h:133
Trk::BinUtility::next
size_t next(const Amg::Vector3D &position, const Amg::Vector3D &direction, size_t ba=0) const
Bin from a 3D vector (already in binning frame)
Definition: BinUtility.h:153
Trk::BinningOption
BinningOption
enum BinValue
Definition: BinningType.h:39
Trk::BinUtility::~BinUtility
~BinUtility()
Destructor.
Definition: BinUtility.h:127
Trk::binPhi
@ binPhi
Definition: BinningType.h:51