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 18 of file ParticleWeightingKeyMap.cc.

19{
20 auto* axis = new ParticleWeightingAxis();;
21 axis->setName(name);
22 // Note: map is sorted by keys (C++ standards)
23 m_axes.insert(std::make_pair(name, axis));
24}
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 69 of file ParticleWeightingKeyMap.cc.

70{
71 return this->addKey(std::move(bin), m_bins.size());
72}
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 27 of file ParticleWeightingKeyMap.cc.

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

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

◆ getNames()

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

Get vector of names ParticleWeightingKeyMap.

Returns
vector of axes names

Definition at line 100 of file ParticleWeightingKeyMap.cc.

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

◆ printKeyMap()

void printKeyMap ( ) const

Print content of the key map.

Definition at line 110 of file ParticleWeightingKeyMap.cc.

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

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: