MaCh3  2.2.3
Reference Guide
Public Member Functions | Public Attributes | List of all members
SampleBinningInfo Struct Reference

KS: Small struct storying info about used binning. More...

#include <Samples/SampleStructs.h>

Collaboration diagram for SampleBinningInfo:
[legend]

Public Member Functions

int GetBin (const int xBin, const int yBin) const
 Get linear bin index from 2D bin indices. More...
 
int GetBinSafe (const int xBin, const int yBin) const
 Get linear bin index from 2D bin indices with additional checks. More...
 
int GetBinGlobal (const int xBin, const int yBin) const
 Calculates the global bin number for a given 2D bin, accounting for multiple binning samples. More...
 
int FindXBin (const double XVar, const int NomXBin) const
 DB Find the relevant bin in the PDF for each event. More...
 
void InitialiseLookUpSingleDimension (std::vector< BinShiftLookup > &BinLookup, const std::vector< double > &BinEdges, const size_t TotBins)
 Initializes lookup arrays for efficient bin migration in a single dimension. More...
 
void InitialiseBinMigrationLookUp ()
 Initialise special lookup arrays allowing to more efficiently perform bin-migration These arrays store the lower and upper edges of each bin and their neighboring bins. More...
 

Public Attributes

std::vector< double > XBinEdges
 Vector to hold x-axis bin-edges. More...
 
std::vector< double > YBinEdges
 Vector to hold y-axis bin-edges. More...
 
size_t nXBins = M3::_BAD_INT_
 Number of X axis bins in the histogram used for likelihood calculation. More...
 
size_t nYBins = M3::_BAD_INT_
 Number of Y axis bins in the histogram used for likelihood calculation. More...
 
size_t nBins = M3::_BAD_INT_
 Number of total bins. More...
 
size_t GlobalOffset = M3::_BAD_INT_
 If you have binning for multiple samples and trying to define 1D vector let's. More...
 
std::vector< BinShiftLookupxBinLookup
 Bin lookups for X axis only. More...
 

Detailed Description

KS: Small struct storying info about used binning.

Definition at line 183 of file SampleStructs.h.

Member Function Documentation

◆ FindXBin()

int SampleBinningInfo::FindXBin ( const double  XVar,
const int  NomXBin 
) const
inline

DB Find the relevant bin in the PDF for each event.

Definition at line 231 of file SampleStructs.h.

231  {
232  // KS: Get reference to avoid repeated indexing and help with performance
233  const auto& xBin = xBinLookup[NomXBin];
234 
235  //DB Check to see if momentum shift has moved bins
236  //DB - First , check to see if the event is outside of the binning range and skip event if it is
237  if (XVar < XBinEdges[0] || XVar >= XBinEdges[nXBins]) {
238  return -1;
239  }
240  //DB - Second, check to see if the event is still in the nominal bin
241  else if (XVar < xBin.upper_binedge && XVar >= xBin.lower_binedge) {
242  return NomXBin;
243  }
244  //DB - Thirdly, check the adjacent bins first as Eb+CC+EScale shifts aren't likely to move an Erec more than 1bin width
245  //Shifted down one bin from the event bin at nominal
246  else if (XVar < xBin.lower_binedge && XVar >= xBin.lower_lower_binedge) {
247  return NomXBin-1;
248  }
249  //Shifted up one bin from the event bin at nominal
250  else if (XVar < xBin.upper_upper_binedge && XVar >= xBin.upper_binedge) {
251  return NomXBin+1;
252  }
253  //DB - If we end up in this loop, the event has been shifted outside of its nominal bin, but is still within the allowed binning range
254  else {
255  // KS: Perform binary search to find correct bin. We already checked if isn't outside of bounds
256  return static_cast<int>(std::distance(XBinEdges.begin(), std::upper_bound(XBinEdges.begin(), XBinEdges.end(), XVar)) - 1);
257  }
258  }
std::vector< BinShiftLookup > xBinLookup
Bin lookups for X axis only.
size_t nXBins
Number of X axis bins in the histogram used for likelihood calculation.
std::vector< double > XBinEdges
Vector to hold x-axis bin-edges.

◆ GetBin()

int SampleBinningInfo::GetBin ( const int  xBin,
const int  yBin 
) const
inline

Get linear bin index from 2D bin indices.

Parameters
xBinThe bin index along the X axis (0-based)
yBinThe bin index along the Y axis (0-based)
Returns
The linear bin index corresponding to (xBin, yBin)

Definition at line 205 of file SampleStructs.h.

205  {
206  return static_cast<int>(yBin * nXBins + xBin);
207  }

◆ GetBinGlobal()

int SampleBinningInfo::GetBinGlobal ( const int  xBin,
const int  yBin 
) const
inline

Calculates the global bin number for a given 2D bin, accounting for multiple binning samples.

Parameters
xBinThe bin index along the X axis (0-based)
yBinThe bin index along the Y axis (0-based)

Definition at line 226 of file SampleStructs.h.

226  {
227  return static_cast<int>(GlobalOffset + GetBin(xBin, yBin));
228  }
int GetBin(const int xBin, const int yBin) const
Get linear bin index from 2D bin indices.
size_t GlobalOffset
If you have binning for multiple samples and trying to define 1D vector let's.

◆ GetBinSafe()

int SampleBinningInfo::GetBinSafe ( const int  xBin,
const int  yBin 
) const
inline

Get linear bin index from 2D bin indices with additional checks.

Parameters
xBinThe bin index along the X axis (0-based)
yBinThe bin index along the Y axis (0-based)
Returns
The linear bin index corresponding to (xBin, yBin)
Warning
this performs additional checks so do not use in parts of code used during fit

Definition at line 214 of file SampleStructs.h.

214  {
215  if (xBin < 0 || yBin < 0 || static_cast<size_t>(xBin) >= nXBins || static_cast<size_t>(yBin) >= nYBins) {
216  MACH3LOG_ERROR("GetBinSafe: Bin indices out of range: xBin={}, yBin={}, max xBin={}, max yBin={}",
217  xBin, yBin, nXBins - 1, nYBins - 1);
218  throw MaCh3Exception(__FILE__, __LINE__);
219  }
220  return GetBin(xBin, yBin);
221  }
#define MACH3LOG_ERROR
Definition: MaCh3Logger.h:27
Custom exception class for MaCh3 errors.
size_t nYBins
Number of Y axis bins in the histogram used for likelihood calculation.

◆ InitialiseBinMigrationLookUp()

void SampleBinningInfo::InitialiseBinMigrationLookUp ( )
inline

Initialise special lookup arrays allowing to more efficiently perform bin-migration These arrays store the lower and upper edges of each bin and their neighboring bins.

Todo:
KS: This could be expanded easily for Y axis

Definition at line 294 of file SampleStructs.h.

294  {
297  }
void InitialiseLookUpSingleDimension(std::vector< BinShiftLookup > &BinLookup, const std::vector< double > &BinEdges, const size_t TotBins)
Initializes lookup arrays for efficient bin migration in a single dimension.

◆ InitialiseLookUpSingleDimension()

void SampleBinningInfo::InitialiseLookUpSingleDimension ( std::vector< BinShiftLookup > &  BinLookup,
const std::vector< double > &  BinEdges,
const size_t  TotBins 
)
inline

Initializes lookup arrays for efficient bin migration in a single dimension.

Parameters
BinLookupReference to the BinShiftLookup struct to be initialized.
BinEdgesVector of bin edges defining the bin boundaries.
TotBinsNumber of bins in the dimension.

Definition at line 264 of file SampleStructs.h.

264  {
265  BinLookup.resize(TotBins);
266  //Set rw_pdf_bin and upper_binedge and lower_binedge for each skmc_base
267  for(size_t bin_i = 0; bin_i < TotBins; bin_i++){
268  double low_lower_edge = M3::_DEFAULT_RETURN_VAL_;
269  double low_edge = BinEdges[bin_i];
270  double upper_edge = BinEdges[bin_i+1];
271  double upper_upper_edge = M3::_DEFAULT_RETURN_VAL_;
272 
273  if (bin_i == 0) {
274  low_lower_edge = BinEdges[0];
275  } else {
276  low_lower_edge = BinEdges[bin_i-1];
277  }
278 
279  if (bin_i + 2 < TotBins) {
280  upper_upper_edge = BinEdges[bin_i + 2];
281  } else if (bin_i + 1 < TotBins) {
282  upper_upper_edge = BinEdges[bin_i + 1];
283  }
284 
285  BinLookup[bin_i].lower_binedge = low_edge;
286  BinLookup[bin_i].upper_binedge = upper_edge;
287  BinLookup[bin_i].lower_lower_binedge = low_lower_edge;
288  BinLookup[bin_i].upper_upper_binedge = upper_upper_edge;
289  }
290  }
constexpr static const double _DEFAULT_RETURN_VAL_
Definition: Core.h:49

Member Data Documentation

◆ GlobalOffset

size_t SampleBinningInfo::GlobalOffset = M3::_BAD_INT_

If you have binning for multiple samples and trying to define 1D vector let's.

Definition at line 197 of file SampleStructs.h.

◆ nBins

size_t SampleBinningInfo::nBins = M3::_BAD_INT_

Number of total bins.

Definition at line 195 of file SampleStructs.h.

◆ nXBins

size_t SampleBinningInfo::nXBins = M3::_BAD_INT_

Number of X axis bins in the histogram used for likelihood calculation.

Definition at line 191 of file SampleStructs.h.

◆ nYBins

size_t SampleBinningInfo::nYBins = M3::_BAD_INT_

Number of Y axis bins in the histogram used for likelihood calculation.

Definition at line 193 of file SampleStructs.h.

◆ XBinEdges

std::vector<double> SampleBinningInfo::XBinEdges

Vector to hold x-axis bin-edges.

Definition at line 186 of file SampleStructs.h.

◆ xBinLookup

std::vector<BinShiftLookup> SampleBinningInfo::xBinLookup

Bin lookups for X axis only.

Definition at line 199 of file SampleStructs.h.

◆ YBinEdges

std::vector<double> SampleBinningInfo::YBinEdges

Vector to hold y-axis bin-edges.

Definition at line 188 of file SampleStructs.h.


The documentation for this struct was generated from the following file: