Belle II Software  release-08-01-10
ParticleWeightingAxis.cc
1 /**************************************************************************
2  * basf2 (Belle II Analysis Software Framework) *
3  * Author: The Belle II Collaboration *
4  * *
5  * See git log for contributors and copyright holders. *
6  * This file is licensed under LGPL-3.0, see LICENSE.md. *
7  **************************************************************************/
8 
9 #include <analysis/dbobjects/ParticleWeightingAxis.h>
10 #include <framework/logging/Logger.h>
11 
12 using namespace Belle2;
13 
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 }
44 
45 
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 }
60 
61 
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 }
71 
72 
73 int ParticleWeightingAxis::findBin(double value) const
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 }
82 
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 }
void printAxis() const
Prints axis information to the B2INFO stream.
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.
int addBin(ParticleWeightingBinLimits *bin)
Check if bin exists and creates it if not.
Just pair of numbers - min and max values of bin border.
double second() const
Highest bin border.
double first() const
Lowest bin border.
Abstract base class for different kinds of events.