Belle II Software development
ParticleWeightingAxis Class Reference

Class for handling LookUp tables. More...

#include <ParticleWeightingAxis.h>

Public Member Functions

 ParticleWeightingAxis ()
 Constructor.
 
std::string getName () const
 Returns name of an axis.
 
void setName (const std::string &name)
 Sets name of an axis.
 
int addBin (ParticleWeightingBinLimits *bin)
 Check if bin exists and creates it if not.
 
int findBin (ParticleWeightingBinLimits *bin) const
 Returns id of bin with given bin limits Returns out-of-range binID if can't find.
 
int findBin (double value) const
 Returns id of bin containing value.
 
void printAxis () const
 Prints axis information to the B2INFO stream.
 

Private Member Functions

bool isOverlappingBin (ParticleWeightingBinLimits *bin)
 Return TRUE if bin exists or overlaps with existing.
 

Private Attributes

BinMap m_unnamedAxis
 Named axis with bins.
 
std::string m_axisName
 Axis name.
 
const int m_outOfRangeBinID = -1
 ID of out-of-range bin.
 

Detailed Description

Class for handling LookUp tables.

Definition at line 26 of file ParticleWeightingAxis.h.

Constructor & Destructor Documentation

◆ ParticleWeightingAxis()

Constructor.

Definition at line 46 of file ParticleWeightingAxis.h.

46{}

Member Function Documentation

◆ addBin()

int addBin ( ParticleWeightingBinLimits bin)

Check if bin exists and creates it if not.

Returns bin ID Issues fatal error in case of overlapping bins.

Parameters
binbin limits
Returns
key ID

Definition at line 46 of file ParticleWeightingAxis.cc.

47{
48 int existing_id = this->findBin(bin);
49 if (existing_id != m_outOfRangeBinID) {
50 return existing_id;
51 }
52 if (this->isOverlappingBin(bin)) {
53 B2FATAL("Attempting to add overlapping or existing bin");
54 } else {
55 int id = m_unnamedAxis.size() + 1;
56 m_unnamedAxis.insert(std::make_pair(id, bin));
57 return id;
58 }
59}
int findBin(ParticleWeightingBinLimits *bin) const
Returns id of bin with given bin limits Returns out-of-range binID if can't find.
BinMap m_unnamedAxis
Named axis with bins.
const int m_outOfRangeBinID
ID of out-of-range bin.
bool isOverlappingBin(ParticleWeightingBinLimits *bin)
Return TRUE if bin exists or overlaps with existing.

◆ findBin() [1/2]

int findBin ( double  value) const

Returns id of bin containing value.

Parameters
valuevalue
Returns
key ID

Definition at line 73 of file ParticleWeightingAxis.cc.

74{
75 for (auto i_bin : m_unnamedAxis) {
76 if ((value >= i_bin.second->first()) and (value < i_bin.second->second())) {
77 return i_bin.first;
78 }
79 }
80 return m_outOfRangeBinID;
81}

◆ findBin() [2/2]

int findBin ( ParticleWeightingBinLimits bin) const

Returns id of bin with given bin limits Returns out-of-range binID if can't find.

Parameters
binbin limits
Returns
key ID

Definition at line 62 of file ParticleWeightingAxis.cc.

63{
64 for (auto i_bin : m_unnamedAxis) {
65 if ((bin->first() == i_bin.second->first()) and (bin->second() == i_bin.second->second())) {
66 return i_bin.first;
67 }
68 }
69 return m_outOfRangeBinID;
70}
double second() const
Highest bin border.
double first() const
Lowest bin border.

◆ getName()

std::string getName ( ) const
inline

Returns name of an axis.

Definition at line 51 of file ParticleWeightingAxis.h.

51{ return m_axisName;}

◆ isOverlappingBin()

bool isOverlappingBin ( ParticleWeightingBinLimits bin)
private

Return TRUE if bin exists or overlaps with existing.

Parameters
bin- tested bin
Returns
is this bin overlapping with existing bins or not

Checking if lower border is within some bin existing binning: | | new binning: | |

Checking if upper border is within some bin existing binning: | | new binning: | |

Checking if new bin covers existing bin completely existing binning: | | new binning: | |

Definition at line 14 of file ParticleWeightingAxis.cc.

15{
16 for (auto i_bin : m_unnamedAxis) {
22 if ((bin->first() >= i_bin.second->first()) and (bin->first() < i_bin.second->second())) {
23 return true;
24 }
30 if ((bin->second() > i_bin.second->first()) and (bin->second() <= i_bin.second->second())) {
31 return true;
32 }
38 if ((bin->first() < i_bin.second->first()) and (bin->second() > i_bin.second->second())) {
39 return true;
40 }
41 }
42 return false;
43}

◆ printAxis()

void printAxis ( ) const

Prints axis information to the B2INFO stream.

Definition at line 83 of file ParticleWeightingAxis.cc.

84{
85 B2INFO("Printing axis " + m_axisName);
86 int len = 10;
87 std::string id_cells = "";
88 std::string bin_cells = "";
89 for (auto i_entry : m_unnamedAxis) {
90 std::string i_id = std::to_string(i_entry.first);
91 int i_id_len = i_id.size();
92 std::string i_ll = std::to_string(i_entry.second->first());
93 int i_ll_len = i_ll.size();
94 std::string i_ul = std::to_string(i_entry.second->second());
95 int i_ul_len = i_ul.size();
96 id_cells += "|" + std::string(len, ' ') + i_id + std::string(std::max(1, len - i_id_len + 1), ' ') + "|";
97 bin_cells += "|" + i_ll + std::string(std::max(1, len - i_ll_len), ' ') + "|" + i_ul + std::string(std::max(1, len - i_ul_len),
98 ' ') + "|";
99 }
100 B2INFO(id_cells);
101 B2INFO(bin_cells);
102}

◆ setName()

void setName ( const std::string &  name)
inline

Sets name of an axis.

Parameters
nameaxis name

Definition at line 57 of file ParticleWeightingAxis.h.

57{ m_axisName = name;}

Member Data Documentation

◆ m_axisName

std::string m_axisName
private

Axis name.

Definition at line 30 of file ParticleWeightingAxis.h.

◆ m_outOfRangeBinID

const int m_outOfRangeBinID = -1
private

ID of out-of-range bin.

Definition at line 32 of file ParticleWeightingAxis.h.

◆ m_unnamedAxis

BinMap m_unnamedAxis
private

Named axis with bins.

Definition at line 28 of file ParticleWeightingAxis.h.


The documentation for this class was generated from the following files: