Belle II Software development
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 <analysis/dbobjects/ParticleWeightingBinLimits.h>
11#include <framework/logging/Logger.h>
12
13using namespace Belle2;
14
16{
17 for (auto i_bin : m_unnamedAxis) {
23 if ((bin->first() >= i_bin.second->first()) and (bin->first() < i_bin.second->second())) {
24 return true;
25 }
31 if ((bin->second() > i_bin.second->first()) and (bin->second() <= i_bin.second->second())) {
32 return true;
33 }
39 if ((bin->first() < i_bin.second->first()) and (bin->second() > i_bin.second->second())) {
40 return true;
41 }
42 }
43 return false;
44}
45
46
48{
49 int existing_id = this->findBin(bin);
50 if (existing_id != m_outOfRangeBinID) {
51 return existing_id;
52 }
53 if (this->isOverlappingBin(bin)) {
54 B2FATAL("Attempting to add overlapping or existing bin");
55 } else {
56 int id = m_unnamedAxis.size() + 1;
57 m_unnamedAxis.insert(std::make_pair(id, bin));
58 return id;
59 }
60}
61
62
64{
65 for (auto i_bin : m_unnamedAxis) {
66 if ((bin->first() == i_bin.second->first()) and (bin->second() == i_bin.second->second())) {
67 return i_bin.first;
68 }
69 }
70 return m_outOfRangeBinID;
71}
72
73
74int ParticleWeightingAxis::findBin(double value) const
75{
76 for (auto i_bin : m_unnamedAxis) {
77 if ((value >= i_bin.second->first()) and (value < i_bin.second->second())) {
78 return i_bin.first;
79 }
80 }
81 return m_outOfRangeBinID;
82}
83
85{
86 B2INFO("Printing axis " + m_axisName);
87 int len = 10;
88 std::string id_cells = "";
89 std::string bin_cells = "";
90 for (auto i_entry : m_unnamedAxis) {
91 std::string i_id = std::to_string(i_entry.first);
92 int i_id_len = i_id.size();
93 std::string i_ll = std::to_string(i_entry.second->first());
94 int i_ll_len = i_ll.size();
95 std::string i_ul = std::to_string(i_entry.second->second());
96 int i_ul_len = i_ul.size();
97 id_cells += "|" + std::string(len, ' ') + i_id + std::string(std::max(1, len - i_id_len + 1), ' ') + "|";
98 bin_cells += "|" + i_ll + std::string(std::max(1, len - i_ll_len), ' ') + "|" + i_ul + std::string(std::max(1, len - i_ul_len),
99 ' ') + "|";
100 }
101 B2INFO(id_cells);
102 B2INFO(bin_cells);
103}
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.
Abstract base class for different kinds of events.