Belle II Software development
ParticleWeightingKeyMap Class Reference

Class for handling KeyMap. More...

#include <ParticleWeightingKeyMap.h>

Public Member Functions

 ParticleWeightingKeyMap ()
 Constructor.
 
void addAxis (const std::string &name)
 Add axis.
 
int addKey (NDBin bin, int key_ID)
 Adding predefined ID to the table.
 
double addKey (NDBin bin)
 Adding predefined ID to the table.
 
double getKey (std::map< std::string, double > values) const
 Get global bin ID for given observable values.
 
std::vector< std::string > getNames () const
 Get vector of names ParticleWeightingKeyMap.
 
void printKeyMap () const
 Print content of the key map.
 

Private Attributes

std::map< std::string, ParticleWeightingAxis * > m_axes
 Axes mapped with their names.
 
std::vector< MultiDimBinm_bins
 Vector of keys.
 
const int m_outOfRangeBin = -1
 We assign unique bin ID for out-of-range bin.
 

Detailed Description

Class for handling KeyMap.

Definition at line 37 of file ParticleWeightingKeyMap.h.

Constructor & Destructor Documentation

◆ ParticleWeightingKeyMap()

Constructor.

Definition at line 58 of file ParticleWeightingKeyMap.h.

58{}

Member Function Documentation

◆ addAxis()

void addAxis ( const std::string &  name)

Add axis.

Definition at line 16 of file ParticleWeightingKeyMap.cc.

17{
18 auto* axis = new ParticleWeightingAxis();;
19 axis->setName(name);
20 // Note: map is sorted by keys (C++ standards)
21 m_axes.insert(std::make_pair(name, axis));
22}
Class for handling LookUp tables.
std::map< std::string, ParticleWeightingAxis * > m_axes
Axes mapped with their names.

◆ addKey() [1/2]

double addKey ( NDBin  bin)

Adding predefined ID to the table.

Parameters
bincontains bin ranges and names of the variables
Returns
added key ID

Definition at line 67 of file ParticleWeightingKeyMap.cc.

68{
69 return this->addKey(std::move(bin), m_bins.size());
70}
std::vector< MultiDimBin > m_bins
Vector of keys.
int addKey(NDBin bin, int key_ID)
Adding predefined ID to the table.

◆ addKey() [2/2]

int addKey ( NDBin  bin,
int  key_ID 
)

Adding predefined ID to the table.

Parameters
bincontains bin ranges and names of the variables
key_IDpredefined bin ID
Returns
added key ID

Definition at line 25 of file ParticleWeightingKeyMap.cc.

26{
27 // Note: it is only possible to add axes to an empty key map
28 if (key_ID == m_outOfRangeBin) {
29 B2FATAL("You are trying create bin with ID identical to out-of-range Bin : " << m_outOfRangeBin);
30 return -1;
31 }
32
33 if (m_axes.size() == 0) {
34 for (const auto& i_1dbin : bin) {
35 this->addAxis(i_1dbin.first);
36 }
37 }
38
39 if (bin.size() != m_axes.size()) {
40 B2FATAL("Inconsistent dimensionality of added bin");
41 return -1;
42 }
43
44 std::vector<int> bin_id_collection;
45 for (auto i_axis : m_axes) {
46 auto it = bin.find(i_axis.first);
47 if (it != bin.end()) {
48 bin_id_collection.push_back(i_axis.second->addBin(it->second));
49 } else {
50 B2FATAL("Names of bin and existing axes don't match");
51 return -1;
52 }
53 }
54
55 for (auto i_bin : m_bins) {
56 if (std::equal(i_bin.first.begin(), i_bin.first.end(), bin_id_collection.begin())) {
57 B2FATAL("You tried to overwrite existing bin " + std::to_string(i_bin.second) + " with new ID " + std::to_string(key_ID));
58 return -1;
59 }
60 }
61
62 m_bins.emplace_back(bin_id_collection, key_ID);
63 return key_ID;
64}
const int m_outOfRangeBin
We assign unique bin ID for out-of-range bin.
void addAxis(const std::string &name)
Add axis.

◆ getKey()

double getKey ( std::map< std::string, double >  values) const

Get global bin ID for given observable values.

Parameters
valuesmap of axis names and corresponding values
Returns
global ID

Definition at line 73 of file ParticleWeightingKeyMap.cc.

74{
75 if (values.size() != m_axes.size()) {
76 B2FATAL("Inconsistent dimensionality of requested value map");
77 return -1;
78 }
79 std::vector<int> bin_id_collection;
80 for (auto i_axis : m_axes) {
81 auto it = values.find(i_axis.first);
82 if (it != values.end()) {
83 bin_id_collection.push_back(i_axis.second->findBin(it->second));
84 } else {
85 B2FATAL("Names of bin and existing axes don't match");
86 return -1;
87 }
88 }
89 for (auto i_bin : m_bins) {
90 if (std::equal(i_bin.first.begin(), i_bin.first.end(), bin_id_collection.begin())) {
91 return i_bin.second;
92 }
93 }
94 return m_outOfRangeBin;
95}

◆ getNames()

std::vector< std::string > getNames ( ) const

Get vector of names ParticleWeightingKeyMap.

Returns
vector of axes names

Definition at line 98 of file ParticleWeightingKeyMap.cc.

99{
100 std::vector<std::string> names;
101 for (const auto& i_axis : m_axes) {
102 names.push_back(i_axis.first);
103 }
104 return names;
105}

◆ printKeyMap()

void printKeyMap ( ) const

Print content of the key map.

Definition at line 108 of file ParticleWeightingKeyMap.cc.

109{
110 std::string axes_names = "";
111 for (auto i_axis : m_axes) {
112 axes_names += "'" + i_axis.first + "' bin;";
113 i_axis.second->printAxis();
114 }
115 B2INFO("Bin map \n <" + axes_names + "> : <global ID>");
116 for (const auto& i_bin : m_bins) {
117 std::string binIDs = "";
118 for (auto i_binid : i_bin.first) {
119 binIDs += std::to_string(i_binid) + "; ";
120 }
121 B2INFO(binIDs + " : " + std::to_string(i_bin.second));
122 }
123
124}

Member Data Documentation

◆ m_axes

std::map<std::string, ParticleWeightingAxis*> m_axes
private

Axes mapped with their names.

Definition at line 42 of file ParticleWeightingKeyMap.h.

◆ m_bins

std::vector<MultiDimBin> m_bins
private

Vector of keys.

Definition at line 46 of file ParticleWeightingKeyMap.h.

◆ m_outOfRangeBin

const int m_outOfRangeBin = -1
private

We assign unique bin ID for out-of-range bin.

Definition at line 51 of file ParticleWeightingKeyMap.h.


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