ATLAS Offline Software
Public Member Functions | Private Attributes | List of all members
MuonCalib::DataBin Class Reference

#include <DataBin.h>

Collaboration diagram for MuonCalib::DataBin:

Public Member Functions

 DataBin (void)
 Default constructor. Give a bin with 0 content and no extensions. More...
 
 DataBin (const std::vector< DataPoint > &points, const double &epsilon)
 Constructor. More...
 
 DataBin (const Amg::VectorX &lower_boundaries, const Amg::VectorX &upper_boundaries)
 Constructor. More...
 
double density (void) const
 get the data point density in the bin More...
 
const Amg::VectorXcentreOfBin (void) const
 get the centre of the bin More...
 
const Amg::VectorXlowerBinBoundaries (void) const
 get the lower boundaries of the bin More...
 
const Amg::VectorXupperbinBoundaries (void) const
 get the upper boundaries of the bin More...
 
const Amg::VectorXcentreOfGravity (void) const
 get the centre of gravity of the data points More...
 
const Amg::VectorXstandardDeviations (void) const
 get the standard deviations of the data points from the centre of gravity in all dimensions More...
 
unsigned int numberOfDataPoints (void) const
 get the number of data points More...
 
const std::vector< DataPoint > & dataPoints (void) const
 get the data points filling this bin More...
 
DataBinsplitBin (const unsigned int &ref_coord)
 divide the bin into two of equal content; splitting is done along the coordinate ref_coord; the method resize the current bin and return the other half (at least 4 points are required for splitting) More...
 
bool addPoint (const DataPoint &point)
 add the data point to the bin if possible; returns true if the point can be added, false otherwise More...
 
void addPointAndResize (const DataPoint &point, const double &epsilon)
 add the data point to the bin; the bin will be resized if the point does not fit into the bin; the upper bin boundaries are shifted by epsilon to create a half-open intervall containing all data points More...
 
void setPoints (const std::vector< DataPoint > &points)
 fill the bin with the given points; the use of this method is highly discouraged, it is needed for the splitting whithout changing the bin boundaries More...
 

Private Attributes

std::vector< DataPointm_points
 
Amg::VectorX m_bin_centre
 
Amg::VectorX m_lower_boundaries
 
Amg::VectorX m_upper_boundaries
 
Amg::VectorX m_centre_of_gravity
 
Amg::VectorX m_standard_deviations
 

Detailed Description

Definition at line 37 of file DataBin.h.

Constructor & Destructor Documentation

◆ DataBin() [1/3]

DataBin::DataBin ( void  )

Default constructor. Give a bin with 0 content and no extensions.

Definition at line 23 of file DataBin.cxx.

23  {
24 }

◆ DataBin() [2/3]

DataBin::DataBin ( const std::vector< DataPoint > &  points,
const double &  epsilon 
)

Constructor.

Parameters
pointsData points occupying the bin.
epsilonThe upper bin boundaries are shifted by epsilon to create a half-open intervall containing all data points.

Definition at line 32 of file DataBin.cxx.

32  {
33 
34  for (unsigned int k=0; k<points.size(); k++) {
35  addPointAndResize(points[k], epsilon);
36  }
37 
38 }

◆ DataBin() [3/3]

DataBin::DataBin ( const Amg::VectorX lower_boundaries,
const Amg::VectorX upper_boundaries 
)

Constructor.

Create an empty bin with the given boundaries.

Parameters
lower_boundariesLower boundaries of the bin.
upper_boundariesUpper boundaries of the bin.

Definition at line 46 of file DataBin.cxx.

47  {
48 
50 // CHECK WHETHER BOUNDARIES DIMENSIONS ARE CONSISTENT //
52 
53  if (lower_boundaries.rows()!=upper_boundaries.rows()) {
54  throw std::runtime_error(Form("File: %s, Line: %d\nDataBin::DataBin - Dimensions of lower and upper bin boundaries disagree.", __FILE__, __LINE__));
55  }
56 
58 // COPY THE BOUNDARIES AND CALCULATE THE BIN CENTRE //
60 
61  m_lower_boundaries = lower_boundaries;
62  m_upper_boundaries = upper_boundaries;
63 
65 
66 }

Member Function Documentation

◆ addPoint()

bool DataBin::addPoint ( const DataPoint point)

add the data point to the bin if possible; returns true if the point can be added, false otherwise

Definition at line 246 of file DataBin.cxx.

246  {
247 
248 // check whether the point can be added //
249  for (int k=0; k<point.dataVector().rows(); k++) {
250  if (point.dataVector()[k]<m_lower_boundaries[k] ||
251  point.dataVector()[k]>=m_upper_boundaries[k]) {
252  return false;
253  }
254  }
255 
256 // add the point //
257  m_points.push_back(point);
258 
259 // recalculate the centre of gravity and the standard deviations //
262  for (int k=0; k<m_centre_of_gravity.rows(); k++) {
263  m_centre_of_gravity[k] = 0.0;
264  m_standard_deviations[k] = 0.0;
265  for (unsigned int l=0; l<m_points.size(); l++) {
267  m_points[l].dataVector()[k];
268  }
270  static_cast<double>(m_points.size());
271  for (unsigned int l=0; l<m_points.size(); l++) {
273  std::pow(m_points[l].dataVector()[k]-m_centre_of_gravity[k], 2);
274  }
275  if (m_points.size()>2) {
277  static_cast<double>(m_points.size()-1);
278  } else {
280  static_cast<double>(m_points.size());
281  }
283  }
284 
285  return true;
286 
287 }

◆ addPointAndResize()

void DataBin::addPointAndResize ( const DataPoint point,
const double &  epsilon 
)

add the data point to the bin; the bin will be resized if the point does not fit into the bin; the upper bin boundaries are shifted by epsilon to create a half-open intervall containing all data points

Definition at line 295 of file DataBin.cxx.

295  {
296 
297 // add the point //
298  m_points.push_back(point);
299 
300 // recalculate the centre of gravity and the standard deviations //
303  for (int k=0; k<m_centre_of_gravity.rows(); k++) {
304  m_centre_of_gravity[k] = 0.0;
305  m_standard_deviations[k] = 0.0;
306  for (unsigned int l=0; l<m_points.size(); l++) {
308  m_points[l].dataVector()[k];
309  }
311  static_cast<double>(m_points.size());
312  for (unsigned int l=0; l<m_points.size(); l++) {
314  std::pow(m_points[l].dataVector()[k]-m_centre_of_gravity[k], 2);
315  }
316  if (m_points.size()>2) {
318  static_cast<double>(m_points.size()-1);
319  } else {
321  static_cast<double>(m_points.size());
322  }
324  }
325 
326 // determine the bin boundaries //
327  if (m_points.size()==1) {
328  m_lower_boundaries = point.dataVector();
329  m_upper_boundaries = point.dataVector();
330  for (int k=0; k<m_lower_boundaries.rows(); k++) {
331  m_lower_boundaries[k]=point.dataVector()[k];
332  m_upper_boundaries[k]=point.dataVector()[k]+epsilon;
333  }
334  } else {
335  for (int k=0; k<m_lower_boundaries.rows(); k++) {
336  if (m_lower_boundaries[k]<point.dataVector()[k]) {
337  m_lower_boundaries[k]=point.dataVector()[k];
338  }
339  if (m_upper_boundaries[k]>=point.dataVector()[k]) {
340  m_upper_boundaries[k]=point.dataVector()[k]+epsilon;
341  }
342  }
343  }
344 
345 // calculate bin centre //
347 
348  return;
349 
350 }

◆ centreOfBin()

const Amg::VectorX & DataBin::centreOfBin ( void  ) const

get the centre of the bin

Definition at line 90 of file DataBin.cxx.

90  {
91 
92  return m_bin_centre;
93 
94 }

◆ centreOfGravity()

const Amg::VectorX & DataBin::centreOfGravity ( void  ) const

get the centre of gravity of the data points

Definition at line 126 of file DataBin.cxx.

126  {
127 
128  return m_centre_of_gravity;
129 
130 }

◆ dataPoints()

const std::vector< DataPoint > & DataBin::dataPoints ( void  ) const

get the data points filling this bin

Definition at line 162 of file DataBin.cxx.

162  {
163 
164  return m_points;
165 
166 }

◆ density()

double DataBin::density ( void  ) const

get the data point density in the bin

Definition at line 74 of file DataBin.cxx.

74  {
75 
76  double volume(1.0);
77  for (int k=0; k<m_lower_boundaries.cols(); k++) {
78  volume = volume*(m_upper_boundaries[k]-m_lower_boundaries[k]);
79  }
80  return m_points.size()/volume;
81 
82 }

◆ lowerBinBoundaries()

const Amg::VectorX & DataBin::lowerBinBoundaries ( void  ) const

get the lower boundaries of the bin

Definition at line 102 of file DataBin.cxx.

102  {
103 
104  return m_lower_boundaries;
105 
106 }

◆ numberOfDataPoints()

unsigned int DataBin::numberOfDataPoints ( void  ) const

get the number of data points

Definition at line 150 of file DataBin.cxx.

150  {
151 
152  return m_points.size();
153 
154 }

◆ setPoints()

void DataBin::setPoints ( const std::vector< DataPoint > &  points)

fill the bin with the given points; the use of this method is highly discouraged, it is needed for the splitting whithout changing the bin boundaries

Definition at line 358 of file DataBin.cxx.

358  {
359 
360  m_points = points;
361 
362  if (m_points.empty()) {
363  return;
364  }
365 
366 // recalculate the centre of gravity and the standard deviations //
367  m_centre_of_gravity = m_points[0].dataVector();
368  m_standard_deviations = m_points[0].dataVector();
369  for (int k=0; k<m_centre_of_gravity.rows(); k++) {
370  m_centre_of_gravity[k] = 0.0;
371  m_standard_deviations[k] = 0.0;
372  for (unsigned int l=0; l<m_points.size(); l++) {
374  m_points[l].dataVector()[k];
375  }
377  static_cast<double>(m_points.size());
378  for (unsigned int l=0; l<m_points.size(); l++) {
380  std::pow(m_points[l].dataVector()[k]-m_centre_of_gravity[k], 2);
381  }
382  if (m_points.size()>2) {
384  static_cast<double>(m_points.size()-1);
385  } else {
387  static_cast<double>(m_points.size());
388  }
390  }
391 
392  return;
393 
394 }

◆ splitBin()

DataBin * DataBin::splitBin ( const unsigned int &  ref_coord)

divide the bin into two of equal content; splitting is done along the coordinate ref_coord; the method resize the current bin and return the other half (at least 4 points are required for splitting)

Definition at line 174 of file DataBin.cxx.

174  {
175 
177 // CHECK WHETHER THE REFERENCE COORDINATE IS IN THE ALLOWED RANGE //
179 
180  if (ref_coord>=static_cast<unsigned int >(m_bin_centre.rows())) {
181  throw std::runtime_error(Form("File: %s, Line: %d\nDataBin::splitBin - Reference coordinate out of range!", __FILE__, __LINE__));
182  }
183 
185 // CHECK WHETHER THERE ARE AT LEAST 4 DATA POINTS //
187 
188  if (m_points.size()<4) {
189  throw std::runtime_error(Form("File: %s, Line: %d\nDataBin::splitBin - Less than 4 points in the bin!", __FILE__, __LINE__));
190  }
191 
193 // SORT THE DATA POINTS ALONG THE SELECTED COORDINATE AXIS //
195 
196  for (unsigned int k=0; k<m_points.size(); k++) {
197  m_points[k].setReferenceComponent(ref_coord);
198  }
199 
200  sort(m_points.begin(), m_points.end());
201 
203 // MAKE TWO NEW BINS //
205 
206 // event dividing the splitting position //
207  unsigned int k_split((m_points.size()/2)+m_points.size()%2);
208 
209 // bin 1 data //
210  Amg::VectorX bin_1_low = m_lower_boundaries;
211  Amg::VectorX bin_1_up = m_upper_boundaries;
212  bin_1_up[ref_coord] = (m_points[k_split]).dataVector()[ref_coord];
213  std::vector<DataPoint> bin_1_points(k_split);
214  for (unsigned k=0; k<k_split; k++) {
215  bin_1_points[k] = m_points[k];
216  }
217 
218 // bin 2 data //
219  Amg::VectorX bin_2_low = m_lower_boundaries;
220  bin_2_low[ref_coord] = (m_points[k_split]).dataVector()[ref_coord];
221  Amg::VectorX bin_2_up = m_upper_boundaries;
222  std::vector<DataPoint> bin_2_points(m_points.size()-k_split);
223  for (unsigned int k=k_split; k<m_points.size(); k++) {
224  bin_2_points[k-k_split] = m_points[k];
225  }
226 
227 // create the second bin //
228  DataBin *bin_2 = new DataBin(bin_2_low, bin_2_up);
229  bin_2->setPoints(bin_2_points);
230 
231 // resize the current bin //
232  m_lower_boundaries = bin_1_low;
233  m_upper_boundaries = bin_2_up;
234  setPoints(bin_1_points);
235 
236  return bin_2;
237 
238 }

◆ standardDeviations()

const Amg::VectorX & DataBin::standardDeviations ( void  ) const

get the standard deviations of the data points from the centre of gravity in all dimensions

Definition at line 138 of file DataBin.cxx.

138  {
139 
140  return m_standard_deviations;
141 
142 }

◆ upperbinBoundaries()

const Amg::VectorX & DataBin::upperbinBoundaries ( void  ) const

get the upper boundaries of the bin

Definition at line 114 of file DataBin.cxx.

114  {
115 
116  return m_upper_boundaries;
117 
118 }

Member Data Documentation

◆ m_bin_centre

Amg::VectorX MuonCalib::DataBin::m_bin_centre
private

Definition at line 108 of file DataBin.h.

◆ m_centre_of_gravity

Amg::VectorX MuonCalib::DataBin::m_centre_of_gravity
private

Definition at line 111 of file DataBin.h.

◆ m_lower_boundaries

Amg::VectorX MuonCalib::DataBin::m_lower_boundaries
private

Definition at line 109 of file DataBin.h.

◆ m_points

std::vector<DataPoint> MuonCalib::DataBin::m_points
private

Definition at line 107 of file DataBin.h.

◆ m_standard_deviations

Amg::VectorX MuonCalib::DataBin::m_standard_deviations
private

Definition at line 113 of file DataBin.h.

◆ m_upper_boundaries

Amg::VectorX MuonCalib::DataBin::m_upper_boundaries
private

Definition at line 110 of file DataBin.h.


The documentation for this class was generated from the following files:
MuonCalib::DataBin::m_bin_centre
Amg::VectorX m_bin_centre
Definition: DataBin.h:108
Amg::VectorX
Eigen::Matrix< double, Eigen::Dynamic, 1 > VectorX
Dynamic Vector - dynamic allocation.
Definition: EventPrimitives.h:32
MuonCalib::DataBin::m_upper_boundaries
Amg::VectorX m_upper_boundaries
Definition: DataBin.h:110
conifer::pow
constexpr int pow(int x)
Definition: conifer.h:20
MuonCalib::DataBin::m_centre_of_gravity
Amg::VectorX m_centre_of_gravity
Definition: DataBin.h:111
MuonCalib::DataBin::addPointAndResize
void addPointAndResize(const DataPoint &point, const double &epsilon)
add the data point to the bin; the bin will be resized if the point does not fit into the bin; the up...
Definition: DataBin.cxx:295
UploadAMITag.l
list l
Definition: UploadAMITag.larcaf.py:158
std::sort
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.
Definition: DVL_algorithms.h:554
MuonCalib::DataBin::DataBin
DataBin(void)
Default constructor. Give a bin with 0 content and no extensions.
Definition: DataBin.cxx:23
beamspotnt.rows
list rows
Definition: bin/beamspotnt.py:1112
MuonCalib::DataBin
Definition: DataBin.h:37
MuonCalib::DataBin::setPoints
void setPoints(const std::vector< DataPoint > &points)
fill the bin with the given points; the use of this method is highly discouraged, it is needed for th...
Definition: DataBin.cxx:358
MuonCalib::DataPoint::dataVector
const Amg::VectorX & dataVector(void) const
get the data vector
Definition: DataPoint.cxx:75
MuonCalib::DataBin::m_standard_deviations
Amg::VectorX m_standard_deviations
Definition: DataBin.h:113
MuonCalib::DataBin::m_points
std::vector< DataPoint > m_points
Definition: DataBin.h:107
MuonCalib::DataBin::m_lower_boundaries
Amg::VectorX m_lower_boundaries
Definition: DataBin.h:109
fitman.k
k
Definition: fitman.py:528