Belle II Software  release-05-01-25
ParticleWeightingAxis.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/ParticleWeightingAxis.h>
12 #include <framework/logging/Logger.h>
13 
14 using namespace Belle2;
15 
17 {
18  for (auto i_bin : m_unnamedAxis) {
24  if ((bin->first() >= i_bin.second->first()) and (bin->first() < i_bin.second->second())) {
25  return true;
26  }
32  if ((bin->second() > i_bin.second->first()) and (bin->second() <= i_bin.second->second())) {
33  return true;
34  }
40  if ((bin->first() < i_bin.second->first()) and (bin->second() > i_bin.second->second())) {
41  return true;
42  }
43  }
44  return false;
45 }
46 
47 
49 {
50  int existing_id = this->findBin(bin);
51  if (existing_id != m_outOfRangeBinID) {
52  return existing_id;
53  }
54  if (this->isOverlappingBin(bin)) {
55  B2FATAL("Attepting to add overlapping or existing bin");
56  } else {
57  int id = m_unnamedAxis.size() + 1;
58  m_unnamedAxis.insert(std::make_pair(id, bin));
59  return id;
60  }
61 }
62 
63 
65 {
66  for (auto i_bin : m_unnamedAxis) {
67  if ((bin->first() == i_bin.second->first()) and (bin->second() == i_bin.second->second())) {
68  return i_bin.first;
69  }
70  }
71  return m_outOfRangeBinID;
72 }
73 
74 
76 {
77  for (auto i_bin : m_unnamedAxis) {
78  if ((value >= i_bin.second->first()) and (value < i_bin.second->second())) {
79  return i_bin.first;
80  }
81  }
82  return m_outOfRangeBinID;
83 }
84 
86 {
87  B2INFO("Printing axis " + m_axisName);
88  int len = 10;
89  std::string id_cells = "";
90  std::string bin_cells = "";
91  for (auto i_entry : m_unnamedAxis) {
92  std::string i_id = std::to_string(i_entry.first);
93  int i_id_len = i_id.size();
94  std::string i_ll = std::to_string(i_entry.second->first());
95  int i_ll_len = i_ll.size();
96  std::string i_ul = std::to_string(i_entry.second->second());
97  int i_ul_len = i_ul.size();
98  id_cells += "|" + std::string(len, ' ') + i_id + std::string(std::max(1, len - i_id_len + 1), ' ') + "|";
99  bin_cells += "|" + i_ll + std::string(std::max(1, len - i_ll_len), ' ') + "|" + i_ul + std::string(std::max(1, len - i_ul_len),
100  ' ') + "|";
101  }
102  B2INFO(id_cells);
103  B2INFO(bin_cells);
104 }
Belle2::ParticleWeightingBinLimits
Just pair of numbers - min and max values of bin border.
Definition: ParticleWeightingBinLimits.h:31
Belle2::ParticleWeightingAxis::addBin
int addBin(ParticleWeightingBinLimits *bin)
Check if bin exists and creates it if not.
Definition: ParticleWeightingAxis.cc:48
Belle2::ParticleWeightingAxis::isOverlappingBin
bool isOverlappingBin(ParticleWeightingBinLimits *bin)
Return TRUE if bin exisits or overlaps with existing.
Definition: ParticleWeightingAxis.cc:16
Belle2::ParticleWeightingAxis::m_axisName
std::string m_axisName
Axis name.
Definition: ParticleWeightingAxis.h:40
Belle2::ParticleWeightingAxis::m_unnamedAxis
BinMap m_unnamedAxis
Named axis with bins.
Definition: ParticleWeightingAxis.h:38
Belle2::ParticleWeightingBinLimits::second
double second()
Highest bin border.
Definition: ParticleWeightingBinLimits.h:73
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::ParticleWeightingAxis::m_outOfRangeBinID
const int m_outOfRangeBinID
ID of out-of-range bin.
Definition: ParticleWeightingAxis.h:42
Belle2::ParticleWeightingAxis::findBin
int findBin(ParticleWeightingBinLimits *bin)
Returns id of bin with given bin limits Returns out-of-range binID if can't find.
Definition: ParticleWeightingAxis.cc:64
Belle2::ParticleWeightingAxis::printAxis
void printAxis()
Prints axis information to the B2INFO stream.
Definition: ParticleWeightingAxis.cc:85
Belle2::ParticleWeightingBinLimits::first
double first()
Lowest bin border.
Definition: ParticleWeightingBinLimits.h:64