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

KS: Struct storing all information required for sample binning. More...

#include <Samples/SampleStructs.h>

Collaboration diagram for SampleBinningInfo:
[legend]

Public Member Functions

void InitUniform (const std::vector< std::vector< double >> &InputEdges)
 Initialise Uniform Binning. More...
 
void CheckBinsDoNotOverlap (const std::vector< BinInfo > &TestedBins) const
 Check that non-uniform bin extents do not overlap. More...
 
void CheckBinsHaveNoGaps (const std::vector< BinInfo > &TestedBins, const std::vector< double > &MinVal, const std::vector< double > &MaxVal, size_t ValidationBinsPerDim=100) const
 Check that non-uniform bins fully cover the bounding box (no gaps) More...
 
void InitialiseGridMapping ()
 Initialise Non-Uniform Binning. More...
 
void InitNonUniform (const std::vector< std::vector< std::vector< double >>> &InputBins)
 Initialise Non-Uniform Binning. More...
 
int GetBinSafe (const std::vector< int > &BinIndices) const
 Get linear bin index from ND bin indices with additional checks. More...
 
int GetBin (const std::vector< int > &BinIndices) const
 Convert N-dimensional bin indices to a linear bin index. More...
 
int FindBin (const int Dimension, const double Var, const int NomBin) const
 DB Find the relevant bin in the PDF for each event. More...
 
int FindBin (const double KinVar, const int NomBin, const int N_Bins, const std::vector< double > &Bin_Edges, const std::vector< BinShiftLookup > &Bin_Lookup) const
 DB Find the relevant bin in the PDF for each event. More...
 
void InitialiseLookUpSingleDimension (std::vector< BinShiftLookup > &Bin_Lookup, const std::vector< double > &Bin_Edges, const int TotBins)
 Initializes lookup arrays for efficient bin migration in a single dimension. More...
 
void InitialiseStrides (const int Dimension)
 Initialise stride factors for linear bin index calculation. More...
 
void InitialiseBinMigrationLookUp (const int Dimension)
 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< std::vector< double > > BinEdges
 Vector to hold N-axis bin-edges. More...
 
std::vector< int > AxisNBins
 Number of N-axis bins in the histogram used for likelihood calculation. More...
 
int nBins = M3::_BAD_INT_
 Number of total bins. More...
 
int GlobalOffset = M3::_BAD_INT_
 If you have binning for multiple samples and trying to define 1D vector let's. More...
 
std::vector< std::vector< BinShiftLookup > > BinLookup
 Bin lookups for all dimensions. More...
 
std::vector< int > Strides
 Stride factors for converting N-dimensional bin indices to a linear index. More...
 
bool Uniform = true
 Tells whether to use inform binning grid or non-uniform. More...
 
std::vector< BinInfoBins
 Bins used only for non-uniform. More...
 
std::vector< std::vector< int > > BinGridMapping
 This grid tells what bins are associated with with what BinEdges of Grid Binnins. More...
 

Detailed Description

KS: Struct storing all information required for sample binning.

This struct encapsulates the full binning definition for a single analysis sample. It stores the bin edges, number of bins per dimension, stride factors, and lookup tables required to efficiently map multi-dimensional kinematic variables to linear bin indices.

Author
Kamil Skwarczynski

Definition at line 240 of file SampleStructs.h.

Member Function Documentation

◆ CheckBinsDoNotOverlap()

void SampleBinningInfo::CheckBinsDoNotOverlap ( const std::vector< BinInfo > &  TestedBins) const
inline

Check that non-uniform bin extents do not overlap.

Definition at line 300 of file SampleStructs.h.

300  {
301  if (TestedBins.empty()) return;
302 
303  const size_t ExtentDim = TestedBins[0].Extent.size();
304 
305  for (size_t i = 0; i < TestedBins.size(); ++i) {
306  for (size_t j = i + 1; j < TestedBins.size(); ++j) {
307  bool OverlapsInAllDims = true;
308 
309  for (size_t iDim = 0; iDim < ExtentDim; ++iDim) {
310  const double a_lo = TestedBins[i].Extent[iDim][0];
311  const double a_hi = TestedBins[i].Extent[iDim][1];
312  const double b_lo = TestedBins[j].Extent[iDim][0];
313  const double b_hi = TestedBins[j].Extent[iDim][1];
314 
315  // [low, high) overlap check
316  if (!(a_lo < b_hi && b_lo < a_hi)) {
317  OverlapsInAllDims = false;
318  break;
319  }
320  }
321 
322  if (OverlapsInAllDims) {
323  MACH3LOG_ERROR("Overlapping non-uniform bins detected: Bin {} and Bin {}", i, j);
324  for (size_t iDim = 0; iDim < ExtentDim; ++iDim) {
325  MACH3LOG_ERROR(" Dim {}: Bin {} [{}, {}), Bin {} [{}, {})",
326  iDim,
327  i, TestedBins[i].Extent[iDim][0], TestedBins[i].Extent[iDim][1],
328  j, TestedBins[j].Extent[iDim][0], TestedBins[j].Extent[iDim][1]);
329  }
330  throw MaCh3Exception(__FILE__, __LINE__);
331  }
332  }
333  }
334  }
#define MACH3LOG_ERROR
Definition: MaCh3Logger.h:37
Custom exception class used throughout MaCh3.

◆ CheckBinsHaveNoGaps()

void SampleBinningInfo::CheckBinsHaveNoGaps ( const std::vector< BinInfo > &  TestedBins,
const std::vector< double > &  MinVal,
const std::vector< double > &  MaxVal,
size_t  ValidationBinsPerDim = 100 
) const
inline

Check that non-uniform bins fully cover the bounding box (no gaps)

The idea is:

  1. Build a Cartesian test grid from all bin edges (TestGridEdges)
  2. For every N-dimensional grid cell, test its midpoint
  3. If any midpoint is not inside at least one bin, a gap exists

Definition at line 342 of file SampleStructs.h.

345  {
346  bool gap_found = false;
347  if (TestedBins.empty()) return;
348  const size_t Dim = TestedBins[0].Extent.size();
349  if (MinVal.size() != Dim || MaxVal.size() != Dim) {
350  MACH3LOG_ERROR("MinVal/MaxVal size does not match dimension of bins");
351  throw MaCh3Exception(__FILE__, __LINE__);
352  }
353 
354  // Build a fine validation grid from the provided min/max
355  std::vector<std::vector<double>> TestGridEdges(Dim);
356  for (size_t d = 0; d < Dim; ++d) {
357  TestGridEdges[d].resize(ValidationBinsPerDim + 1);
358  const double width = (MaxVal[d] - MinVal[d]) / static_cast<double>(ValidationBinsPerDim);
359  for (size_t i = 0; i <= ValidationBinsPerDim; ++i)
360  TestGridEdges[d][i] = MinVal[d] + static_cast<double>(i) * width;
361  }
362  // Precompute midpoints of each test cell
363  std::vector<size_t> indices(Dim, 0);
364 
365  std::function<void(size_t)> scan = [&](size_t d) {
366  if (gap_found) return; // stop recursion
367 
368  // Base case: we have selected a cell in every dimension
369  if (d == Dim) {
370  std::vector<double> point(Dim);
371 
372  // Compute the midpoint of the current N-D grid cell
373  for (size_t i = 0; i < Dim; ++i) {
374  const double lo = TestGridEdges[i][indices[i]];
375  const double hi = TestGridEdges[i][indices[i] + 1];
376  point[i] = 0.5 * (lo + hi);
377  }
378 
379  // Check coverage
380  for (const auto& bin : TestedBins) {
381  if (bin.IsEventInside(point)) {
382  return; // covered
383  }
384  }
385 
386  // Not covered by any bin → gap
387  MACH3LOG_WARN("Gap detected in non-uniform binning at point [{:.2f}]", fmt::join(point, ", "));
388  gap_found = true;
389  return;
390  }
391 
392  for (size_t i = 0; i + 1 < TestGridEdges[d].size(); ++i) {
393  indices[d] = i;
394  scan(d + 1);
395  }
396  };
397  // Start recursion at dimension 0
398  scan(0);
399  }
#define MACH3LOG_WARN
Definition: MaCh3Logger.h:36

◆ FindBin() [1/2]

int SampleBinningInfo::FindBin ( const double  KinVar,
const int  NomBin,
const int  N_Bins,
const std::vector< double > &  Bin_Edges,
const std::vector< BinShiftLookup > &  Bin_Lookup 
) const
inline

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

Parameters
KinVarThe value of the kinematic variable for the event.
NomBinThe nominal bin index where the event would fall without any shifts.
N_BinsThe total number of bins in this dimension.
Bin_EdgesVector of bin edge values (size = N_Bins + 1).
Bin_LookupVector of BinShiftLookup structs providing precomputed lower and upper edges for the nominal bin and its neighbors to efficiently handle shifted events

Definition at line 585 of file SampleStructs.h.

589  {
590  //DB Check to see if momentum shift has moved bins
591  //DB - First , check to see if the event is outside of the binning range and skip event if it is
592  if (KinVar < Bin_Edges[0] || KinVar >= Bin_Edges[N_Bins]) {
593  return M3::UnderOverFlowBin;
594  }
595  // KS: If NomBin is UnderOverFlowBin we must do binary search :(
596  if(NomBin > M3::UnderOverFlowBin) {
597  // KS: Get reference to avoid repeated indexing and help with performance
598  const BinShiftLookup& _restrict_ Bin = Bin_Lookup[NomBin];
599  const double lower = Bin.lower_binedge;
600  const double upper = Bin.upper_binedge;
601  const double lower_lower = Bin.lower_lower_binedge;
602  const double upper_upper = Bin.upper_upper_binedge;
603 
604  //DB - Second, check to see if the event is still in the nominal bin
605  if (KinVar < upper && KinVar >= lower) {
606  return NomBin;
607  }
608  //DB - Thirdly, check the adjacent bins first as Eb+CC+EScale shifts aren't likely to move an Erec more than 1bin width
609  //Shifted down one bin from the event bin at nominal
610  if (KinVar < lower && KinVar >= lower_lower) {
611  return NomBin-1;
612  }
613  //Shifted up one bin from the event bin at nominal
614  if (KinVar < upper_upper && KinVar >= upper) {
615  return NomBin+1;
616  }
617  }
618  //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
619  // KS: Perform binary search to find correct bin. We already checked if isn't outside of bounds
620  return static_cast<int>(std::distance(Bin_Edges.begin(), std::upper_bound(Bin_Edges.begin(), Bin_Edges.end(), KinVar)) - 1);
621  }
#define _restrict_
KS: Using restrict limits the effects of pointer aliasing, aiding optimizations. While reading I foun...
Definition: Core.h:108
constexpr static const int UnderOverFlowBin
Mark bin which is overflow or underflow in MaCh3 binning.
Definition: Core.h:91
KS: Store bin lookups allowing to quickly find bin after migration.

◆ FindBin() [2/2]

int SampleBinningInfo::FindBin ( const int  Dimension,
const double  Var,
const int  NomBin 
) const
inline

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

Definition at line 573 of file SampleStructs.h.

573  {
574  return FindBin(Var, NomBin, AxisNBins[Dimension], BinEdges[Dimension], BinLookup[Dimension]);
575  }
std::vector< std::vector< double > > BinEdges
Vector to hold N-axis bin-edges.
int FindBin(const int Dimension, const double Var, const int NomBin) const
DB Find the relevant bin in the PDF for each event.
std::vector< int > AxisNBins
Number of N-axis bins in the histogram used for likelihood calculation.
std::vector< std::vector< BinShiftLookup > > BinLookup
Bin lookups for all dimensions.

◆ GetBin()

int SampleBinningInfo::GetBin ( const std::vector< int > &  BinIndices) const
inline

Convert N-dimensional bin indices to a linear bin index.

Parameters
BinIndicesVector of bin indices along each dimension

Mapping follows row-major order:

  • 1D: xBin
  • 2D: yBin * nXBins + xBin
  • 3D: zBin * nXBins * nYBins + yBin * nXBins + xBin

Definition at line 564 of file SampleStructs.h.

564  {
565  int BinNumber = 0;
566  for(size_t i = 0; i < BinIndices.size(); ++i) {
567  BinNumber += BinIndices[i]*Strides[i];
568  }
569  return BinNumber;
570  }
std::vector< int > Strides
Stride factors for converting N-dimensional bin indices to a linear index.

◆ GetBinSafe()

int SampleBinningInfo::GetBinSafe ( const std::vector< int > &  BinIndices) const
inline

Get linear bin index from ND bin indices with additional checks.

Parameters
BinIndicesVector of bin indices along each dimension
Warning
this performs additional checks so do not use in parts of code used during fit

Definition at line 546 of file SampleStructs.h.

546  {
547  for(int iDim = 0; iDim < static_cast<int>(BinIndices.size()); iDim++){
548  if (BinIndices[iDim] < 0 || BinIndices[iDim] >= AxisNBins[iDim]) {
549  MACH3LOG_ERROR("{}: Bin indices out of range: Dim = {}, Bin={}, max Ndim Bin={}",
550  __func__, iDim, BinIndices[iDim], AxisNBins[iDim]);
551  throw MaCh3Exception(__FILE__, __LINE__);
552  }
553  }
554  return GetBin(BinIndices);
555  }
int GetBin(const std::vector< int > &BinIndices) const
Convert N-dimensional bin indices to a linear bin index.

◆ InitialiseBinMigrationLookUp()

void SampleBinningInfo::InitialiseBinMigrationLookUp ( const int  Dimension)
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.

Definition at line 676 of file SampleStructs.h.

676  {
677  BinLookup.resize(Dimension);
678  for (int i = 0; i < Dimension; ++i) {
680  }
681 
682  InitialiseStrides(Dimension);
683  }
void InitialiseLookUpSingleDimension(std::vector< BinShiftLookup > &Bin_Lookup, const std::vector< double > &Bin_Edges, const int TotBins)
Initializes lookup arrays for efficient bin migration in a single dimension.
void InitialiseStrides(const int Dimension)
Initialise stride factors for linear bin index calculation.

◆ InitialiseGridMapping()

void SampleBinningInfo::InitialiseGridMapping ( )
inline

Initialise Non-Uniform Binning.

Definition at line 402 of file SampleStructs.h.

402  {
403  const size_t Dim = BinEdges.size();
404 
405  // Compute total number of "mega bins"
406  int NGridBins = 1;
407  for (size_t d = 0; d < Dim; ++d) {
408  NGridBins *= AxisNBins[d];
409  }
410  BinGridMapping.resize(NGridBins);
411 
412  // Helper: convert linear index to multi-dimensional index
413  std::vector<int> MultiIndex(Dim, 0);
414 
415  std::function<void(size_t, int)> scan;
416  scan = [&](size_t d, int LinearIndex) {
417  if (d == Dim) {
418  // Compute the edges of the current mega-bin
419  std::vector<std::array<double, 2>> CellEdges(Dim);
420  for (size_t i = 0; i < Dim; ++i) {
421  CellEdges[i][0] = BinEdges[i][MultiIndex[i]];
422  CellEdges[i][1] = BinEdges[i][MultiIndex[i] + 1];
423  }
424 
425  // Check overlap with all non-uniform bins
426  for (size_t iBin = 0; iBin < Bins.size(); ++iBin) {
427  auto& bin = Bins[iBin];
428  bool overlap = true;
429  for (size_t i = 0; i < Dim; ++i) {
430  const double a_lo = bin.Extent[i][0];
431  const double a_hi = bin.Extent[i][1];
432  const double b_lo = CellEdges[i][0];
433  const double b_hi = CellEdges[i][1];
434  if (!(a_hi > b_lo && a_lo < b_hi)) { // overlap condition
435  overlap = false;
436  break;
437  }
438  }
439  if (overlap) {
440  BinGridMapping[LinearIndex].push_back(static_cast<int>(iBin));
441 
442  // Debug statement: show both small bin extent AND mega-bin edges
443  std::vector<std::string> bin_extent_str(Dim);
444  std::vector<std::string> mega_edges_str(Dim);
445 
446  for (size_t i = 0; i < Dim; ++i) {
447  bin_extent_str[i] = fmt::format("[{:.3f}, {:.3f}]", bin.Extent[i][0], bin.Extent[i][1]);
448  mega_edges_str[i] = fmt::format("[{:.3f}, {:.3f}]", CellEdges[i][0], CellEdges[i][1]);
449  }
450 
451  MACH3LOG_DEBUG("MegaBin {} (multi-index [{}], edges {}) assigned Bin {} with extents {}",
452  LinearIndex, fmt::join(MultiIndex, ","), fmt::join(mega_edges_str, ", "),
453  iBin, fmt::join(bin_extent_str, ", "));
454  }
455  }
456  return;
457  }
458 
459  // Loop over all bins along this dimension
460  for (int i = 0; i < AxisNBins[d]; ++i) {
461  MultiIndex[d] = i;
462  int NewLinearIndex = LinearIndex;
463  if (d > 0) {
464  int stride = 1;
465  for (size_t s = 0; s < d; ++s) stride *= AxisNBins[s];
466  NewLinearIndex += i * stride;
467  } else {
468  NewLinearIndex = i;
469  }
470  scan(d + 1, NewLinearIndex);
471  }
472  };
473  // Start the recursive scan over all dimensions, beginning at dimension 0 with linear index 0
474  scan(0, 0);
475  }
#define MACH3LOG_DEBUG
Definition: MaCh3Logger.h:34
std::vector< BinInfo > Bins
Bins used only for non-uniform.
std::vector< std::vector< int > > BinGridMapping
This grid tells what bins are associated with with what BinEdges of Grid Binnins.

◆ InitialiseLookUpSingleDimension()

void SampleBinningInfo::InitialiseLookUpSingleDimension ( std::vector< BinShiftLookup > &  Bin_Lookup,
const std::vector< double > &  Bin_Edges,
const int  TotBins 
)
inline

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

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

Definition at line 627 of file SampleStructs.h.

627  {
628  Bin_Lookup.resize(TotBins);
629  //Set rw_pdf_bin and upper_binedge and lower_binedge for each skmc_base
630  for(int bin_i = 0; bin_i < TotBins; bin_i++){
631  double low_lower_edge = M3::_DEFAULT_RETURN_VAL_;
632  double low_edge = Bin_Edges[bin_i];
633  double upper_edge = Bin_Edges[bin_i+1];
634  double upper_upper_edge = M3::_DEFAULT_RETURN_VAL_;
635 
636  if (bin_i == 0) {
637  low_lower_edge = Bin_Edges[0];
638  } else {
639  low_lower_edge = Bin_Edges[bin_i-1];
640  }
641 
642  if (bin_i + 2 < TotBins) {
643  upper_upper_edge = Bin_Edges[bin_i + 2];
644  } else if (bin_i + 1 < TotBins) {
645  upper_upper_edge = Bin_Edges[bin_i + 1];
646  }
647 
648  Bin_Lookup[bin_i].lower_binedge = low_edge;
649  Bin_Lookup[bin_i].upper_binedge = upper_edge;
650  Bin_Lookup[bin_i].lower_lower_binedge = low_lower_edge;
651  Bin_Lookup[bin_i].upper_upper_binedge = upper_upper_edge;
652  }
653  }
constexpr static const double _DEFAULT_RETURN_VAL_
Definition: Core.h:56

◆ InitialiseStrides()

void SampleBinningInfo::InitialiseStrides ( const int  Dimension)
inline

Initialise stride factors for linear bin index calculation.

Strides define how N-dimensional bin indices are converted into a single linear bin index using row-major ordering.

For example:

  • 1D: stride[0] = 1
  • 2D: stride[1] = nXBins
  • 3D: stride[2] = nXBins * nYBins

Definition at line 664 of file SampleStructs.h.

664  {
665  Strides.resize(Dimension);
666  int stride = 1;
667  for (int i = 0; i < Dimension; ++i) {
668  Strides[i] = stride;
669  // Multiply stride by the number of bins in this axis
670  stride *= AxisNBins[i];
671  }
672  }

◆ InitNonUniform()

void SampleBinningInfo::InitNonUniform ( const std::vector< std::vector< std::vector< double >>> &  InputBins)
inline

Initialise Non-Uniform Binning.

Todo:
KS: Now we create "Large Bins" automatically, in future we can expand to add more user control

prepare special histograms used for event migration

Lastly GridMap

Definition at line 478 of file SampleStructs.h.

478  {
479  Uniform = false;
480  nBins = 0;
481  Bins.resize(InputBins.size());
482 
483  size_t ExtentDim = InputBins[0].size();
484  if (ExtentDim == 1) {
485  MACH3LOG_ERROR("Trying to initialise Non-Uniform binning for single dimension, this is silly...");
486  throw MaCh3Exception(__FILE__, __LINE__);
487  }
488  for(size_t iBin = 0; iBin < InputBins.size(); iBin++) {
489  const auto& NewExtent = InputBins[iBin];
490  if (NewExtent.size() != ExtentDim) {
491  MACH3LOG_ERROR("Dimension of Bin {} is {}, while others have {}", iBin, NewExtent.size(), ExtentDim);
492  throw MaCh3Exception(__FILE__, __LINE__);
493  }
494 
495  BinInfo NewBin;
496  for (const auto& extent : NewExtent) {
497  if (extent.size() != 2) {
498  MACH3LOG_ERROR("Extent size is not 2 for Bin {}", iBin);
499  throw MaCh3Exception(__FILE__, __LINE__);
500  }
501  NewBin.Extent.push_back({extent[0], extent[1]});
502  MACH3LOG_DEBUG("Adding extent for Bin {} Dim {}: [{:.2f}, {:.2f}]",
503  iBin, NewBin.Extent.size()-1, NewBin.Extent.back()[0], NewBin.Extent.back()[1]);
504  }
505  Bins[iBin] = std::move(NewBin);
506  nBins++;
507  }
508  // Ensure we do not have weird overlaps
511  constexpr int BinsPerDimension = 10;
512  // Now we create huge map, which will allow to easily find non uniform bins
513  BinEdges.resize(ExtentDim);
514  AxisNBins.resize(ExtentDim);
515  std::vector<double> MinVal(ExtentDim), MaxVal(ExtentDim);
516  for (size_t iDim = 0; iDim < ExtentDim; iDim++) {
517  MinVal[iDim] = std::numeric_limits<double>::max();
518  MaxVal[iDim] = std::numeric_limits<double>::lowest();
519 
520  // Find min and max for this dimension
521  for (const auto& bin : Bins) {
522  MinVal[iDim] = std::min(MinVal[iDim], bin.Extent[iDim][0]);
523  MaxVal[iDim] = std::max(MaxVal[iDim], bin.Extent[iDim][1]);
524  }
525 
526  MACH3LOG_DEBUG("Mapping binning: Dim {} Min = {:.2f}, Max = {:.2f}", iDim, MinVal[iDim], MaxVal[iDim]);
527  BinEdges[iDim].resize(BinsPerDimension + 1);
528  double BinWidth = (MaxVal[iDim] - MinVal[iDim]) / static_cast<double>(BinsPerDimension);
529  for (size_t iEdge = 0; iEdge <= BinsPerDimension; iEdge++) {
530  BinEdges[iDim][iEdge] = MinVal[iDim] + static_cast<double>(iEdge) * BinWidth;
531  }
532  AxisNBins[iDim] = BinsPerDimension;
533  MACH3LOG_DEBUG("Mapping binning: Dim {} BinEdges = [{:.2f}]", iDim, fmt::join(BinEdges[iDim], ", "));
534  }
535  CheckBinsHaveNoGaps(Bins, MinVal, MaxVal, 200);
536  GlobalOffset = 0;
538  InitialiseBinMigrationLookUp(static_cast<int>(BinEdges.size()));
541  }
KS: This hold bin extents in N-Dimensions allowing to check if Bin falls into.
std::vector< std::array< double, 2 > > Extent
int GlobalOffset
If you have binning for multiple samples and trying to define 1D vector let's.
void InitialiseBinMigrationLookUp(const int Dimension)
Initialise special lookup arrays allowing to more efficiently perform bin-migration These arrays stor...
void InitialiseGridMapping()
Initialise Non-Uniform Binning.
void CheckBinsDoNotOverlap(const std::vector< BinInfo > &TestedBins) const
Check that non-uniform bin extents do not overlap.
bool Uniform
Tells whether to use inform binning grid or non-uniform.
int nBins
Number of total bins.
void CheckBinsHaveNoGaps(const std::vector< BinInfo > &TestedBins, const std::vector< double > &MinVal, const std::vector< double > &MaxVal, size_t ValidationBinsPerDim=100) const
Check that non-uniform bins fully cover the bounding box (no gaps)

◆ InitUniform()

void SampleBinningInfo::InitUniform ( const std::vector< std::vector< double >> &  InputEdges)
inline

Initialise Uniform Binning.

The outer vector loops over dimensions and the inner vector specifies

Lastly prepare special histograms used for event migration

Definition at line 265 of file SampleStructs.h.

265  {
266  BinEdges = InputEdges;
267  Uniform = true;
268  AxisNBins.resize(BinEdges.size());
269 
270  nBins = 1;
271  for(size_t iDim = 0; iDim < BinEdges.size(); iDim++)
272  {
273  const auto& Edges = BinEdges[iDim];
274  if (!std::is_sorted(Edges.begin(), Edges.end())) {
275  MACH3LOG_ERROR("Bin edges for Dim {} must be in increasing order in sample config. Bin edges passed: [{}]",
276  iDim, fmt::join(Edges, ", "));
277  throw MaCh3Exception(__FILE__, __LINE__);
278  }
279 
280  //Sanity check that some binning has been specified
281  if(BinEdges[iDim].size() == 0){
282  MACH3LOG_ERROR("No binning specified for Dim {} of sample binning, please add some binning to the sample config", iDim);
283  MACH3LOG_ERROR("Please ensure BinEdges are correctly configured for all dimensions");
284  throw MaCh3Exception(__FILE__, __LINE__);
285  }
286 
287  // Set the number of bins for this dimension
288  AxisNBins[iDim] = static_cast<int>(BinEdges[iDim].size()) - 1;
289  // Update total number of bins
290  nBins *= AxisNBins[iDim];
291 
292  MACH3LOG_INFO("{}-Dim Binning: [{:.2f}]", iDim, fmt::join(BinEdges[iDim], ", "));
293  }
294  GlobalOffset = 0;
296  InitialiseBinMigrationLookUp(static_cast<int>(BinEdges.size()));
297  }
#define MACH3LOG_INFO
Definition: MaCh3Logger.h:35

Member Data Documentation

◆ AxisNBins

std::vector<int> SampleBinningInfo::AxisNBins

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

Definition at line 245 of file SampleStructs.h.

◆ BinEdges

std::vector<std::vector<double> > SampleBinningInfo::BinEdges

Vector to hold N-axis bin-edges.

Definition at line 243 of file SampleStructs.h.

◆ BinGridMapping

std::vector<std::vector<int> > SampleBinningInfo::BinGridMapping

This grid tells what bins are associated with with what BinEdges of Grid Binnins.

Definition at line 260 of file SampleStructs.h.

◆ BinLookup

std::vector<std::vector<BinShiftLookup> > SampleBinningInfo::BinLookup

Bin lookups for all dimensions.

Definition at line 252 of file SampleStructs.h.

◆ Bins

std::vector<BinInfo> SampleBinningInfo::Bins

Bins used only for non-uniform.

Definition at line 258 of file SampleStructs.h.

◆ GlobalOffset

int SampleBinningInfo::GlobalOffset = M3::_BAD_INT_

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

Definition at line 250 of file SampleStructs.h.

◆ nBins

int SampleBinningInfo::nBins = M3::_BAD_INT_

Number of total bins.

Definition at line 248 of file SampleStructs.h.

◆ Strides

std::vector<int> SampleBinningInfo::Strides

Stride factors for converting N-dimensional bin indices to a linear index.

Definition at line 254 of file SampleStructs.h.

◆ Uniform

bool SampleBinningInfo::Uniform = true

Tells whether to use inform binning grid or non-uniform.

Definition at line 256 of file SampleStructs.h.


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