Belle II Software  release-05-01-25
ParticleWeightingLookUpTable.cc
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2018 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Ilya Komarov *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 #include <analysis/dbobjects/ParticleWeightingLookUpTable.h>
12 #include <framework/logging/Logger.h>
13 
14 #include <utility>
15 
16 using namespace Belle2;
17 
19 {
20  int id = m_WeightMap.size();
21  this->addEntry(std::move(entryValue), std::move(bin), id);
22 }
23 
24 void ParticleWeightingLookUpTable::addEntry(WeightInfo entryValue, NDBin bin, int key_ID)
25 {
26  int id = m_KeyMap.addKey(std::move(bin), key_ID);
27  entryValue.insert(std::make_pair("binID", id));
28  m_WeightMap.insert(std::make_pair(id, entryValue));
29 }
30 
31 
33 {
34  m_WeightMap.insert(std::make_pair(m_OutOfRangeBinID, entryValue));
35 }
36 
37 
38 std::vector<std::string> ParticleWeightingLookUpTable::getAxesNames() const
39 {
40  return m_KeyMap.getNames();
41 }
42 
43 WeightInfo ParticleWeightingLookUpTable::getInfo(std::map<std::string, double> values) const
44 {
45  int id = m_KeyMap.getKey(std::move(values));
46  auto it = m_WeightMap.find(id);
47  if (it != m_WeightMap.end()) {
48  return m_WeightMap.at(id);
49  } else {
50  B2FATAL("Attampt to acccess undeclared bin");
51  return m_WeightMap.at(m_OutOfRangeBinID);
52  }
53 }
54 
56 {
58  B2INFO("Printing the table");
59  for (const auto& entry : m_WeightMap) {
60  int key_ID = entry.first;
61  WeightInfo info = entry.second;
62  std::string bin_info = "";
63  std::string bin_id = "";
64  for (const auto& line : info) {
65  bin_info += line.first + " " + std::to_string(line.second) + " ; ";
66  }
67  if (key_ID == m_OutOfRangeBinID) {
68  bin_id += "Out of range bin " + std::to_string(key_ID) + " : ";
69  } else {
70  bin_id += "Bin " + std::to_string(key_ID) + " : ";
71  }
72  B2INFO(bin_id + bin_info);
73  }
74 }
Belle2::WeightInfo
std::map< std::string, double > WeightInfo
Weight information: a line from the weight lookup table.
Definition: ParticleWeightingLookUpTable.h:31
Belle2::ParticleWeightingLookUpTable::getAxesNames
std::vector< std::string > getAxesNames() const
Get axes names.
Definition: ParticleWeightingLookUpTable.cc:38
Belle2::ParticleWeightingKeyMap::getKey
double getKey(std::map< std::string, double > values) const
Get global bin ID for given observable values.
Definition: ParticleWeightingKeyMap.cc:75
Belle2::ParticleWeightingLookUpTable::addEntry
void addEntry(WeightInfo entryValue, NDBin bin)
Adds entry to the LookUp table and also adds entry to key table if needed.
Definition: ParticleWeightingLookUpTable.cc:18
Belle2::ParticleWeightingLookUpTable::m_WeightMap
WeightMap m_WeightMap
Collection of weight infos for global bins.
Definition: ParticleWeightingLookUpTable.h:44
Belle2::ParticleWeightingLookUpTable::defineOutOfRangeWeight
void defineOutOfRangeWeight(const WeightInfo &entryValue)
Define reweight info for particles out of range.
Definition: ParticleWeightingLookUpTable.cc:32
Belle2::ParticleWeightingKeyMap::getNames
std::vector< std::string > getNames() const
Get vector of names ParticleWeightingKeyMap.
Definition: ParticleWeightingKeyMap.cc:100
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::ParticleWeightingLookUpTable::m_OutOfRangeBinID
const int m_OutOfRangeBinID
out-of-range bin ID
Definition: ParticleWeightingLookUpTable.h:47
Belle2::NDBin
std::map< std::string, ParticleWeightingBinLimits * > NDBin
N-dim bin: pairs of bin limits with name of the axis variable.
Definition: ParticleWeightingKeyMap.h:42
Belle2::ParticleWeightingLookUpTable::printParticleWeightingLookUpTable
void printParticleWeightingLookUpTable() const
Print content of LookUpTable.
Definition: ParticleWeightingLookUpTable.cc:55
Belle2::ParticleWeightingKeyMap::addKey
int addKey(NDBin bin, int key_ID)
Adding predefined ID to the table.
Definition: ParticleWeightingKeyMap.cc:27
Belle2::ParticleWeightingLookUpTable::getInfo
WeightInfo getInfo(std::map< std::string, double > values) const
Get axes names.
Definition: ParticleWeightingLookUpTable.cc:43
Belle2::ParticleWeightingLookUpTable::m_KeyMap
ParticleWeightingKeyMap m_KeyMap
LookUp table matches bins of the key map with the LookUp info.
Definition: ParticleWeightingLookUpTable.h:43
Belle2::ParticleWeightingKeyMap::printKeyMap
void printKeyMap() const
Print content of the key map.
Definition: ParticleWeightingKeyMap.cc:110