Belle II Software light-2405-quaxo
BackgroundInfo.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 <framework/dataobjects/BackgroundInfo.h>
10#include <framework/logging/Logger.h>
11#include <iostream>
12#include <unordered_set>
13
14using namespace std;
15using namespace Belle2;
16
17
19{
20
21 if (otherObj->getMethod() != m_method) {
22 B2ERROR("BackgroundInfo: objects cannot be merged (different method)");
23 return false;
24 }
25
26 std::unordered_set<int> bgThis;
27 for (const auto& bg : m_backgrounds) {
28 int key = bg.tag * 16 + bg.fileType;
29 bgThis.emplace(key);
30 }
31 std::unordered_set<int> bgOther;
32 for (const auto& bg : otherObj->getBackgrounds()) {
33 int key = bg.tag * 16 + bg.fileType;
34 bgOther.emplace(key);
35 }
36 if (bgOther != bgThis) {
37 B2ERROR("BackgroundInfo: objects cannot be merged (different backgrounds)");
38 return false;
39 }
40
41 auto compThis = m_components;
42 std::sort(compThis.begin(), compThis.end());
43 auto compOther = otherObj->getComponents();
44 std::sort(compOther.begin(), compOther.end());
45 if (compOther != compThis) {
46 B2ERROR("BackgroundInfo: objects cannot be merged (different components)");
47 return false;
48 }
49
50 if (otherObj->getMinTime() != m_minTime) {
51 B2ERROR("BackgroundInfo: objects cannot be merged (different minTime)");
52 return false;
53 }
54
55 if (otherObj->getMaxTime() != m_maxTime) {
56 B2ERROR("BackgroundInfo: objects cannot be merged (different maxTime)");
57 return false;
58 }
59
60 if (otherObj->getMinTimeECL() != m_minTimeECL) {
61 B2ERROR("BackgroundInfo: objects cannot be merged (different minTimeECL)");
62 return false;
63 }
64
65 if (otherObj->getMaxTimeECL() != m_maxTimeECL) {
66 B2ERROR("BackgroundInfo: objects cannot be merged (different maxTimeECL)");
67 return false;
68 }
69
70 if (otherObj->getMinTimePXD() != m_minTimePXD) {
71 B2ERROR("BackgroundInfo: objects cannot be merged (different minTimePXD)");
72 return false;
73 }
74
75 if (otherObj->getMaxTimePXD() != m_maxTimePXD) {
76 B2ERROR("BackgroundInfo: objects cannot be merged (different maxTimePXD)");
77 return false;
78 }
79
80 if (otherObj->getWrapAround() != m_wrapAround) {
81 B2ERROR("BackgroundInfo: objects cannot be merged (different wrapAround)");
82 return false;
83 }
84
85 if (otherObj->getMaxEdepECL() != m_maxEdepECL) {
86 B2ERROR("BackgroundInfo: objects cannot be merged (different maxEdepECL)");
87 return false;
88 }
89
90 return true;
91}
92
93
95{
96
97 auto otherObj = static_cast<const BackgroundInfo*>(other);
98
99 if (otherObj->getMethod() == c_Unknown and otherObj->getBackgrounds().empty())
100 return; // no merge for empty object
101
102 if (m_method == c_Unknown and m_backgrounds.empty()) { // empty, replace it with other
103 *this = *otherObj;
104 return;
105 }
106
107 if (!canBeMerged(otherObj)) throw BackgroundInfoNotMergeable();
108
109 for (const auto& otherBg : otherObj->getBackgrounds()) {
110 bool added{false};
111 for (auto& bg : m_backgrounds) {
112 if (otherBg.tag != bg.tag) continue;
113 if (otherBg.fileType != bg.fileType) continue;
114 if (otherBg.fileNames == bg.fileNames) {
115 if (otherBg.scaleFactor != bg.scaleFactor) {
116 B2ERROR("BackgroundInfo: objects cannot be merged (different scaleFactor)");
117 throw BackgroundInfoNotMergeable();
118 }
119 bg.reused += otherBg.reused;
120 added = true;
121 break;
122 }
123 }
124 if (!added) m_backgrounds.push_back(otherBg);
125 }
126
127}
128
130{
131
132 for (auto& bg : m_backgrounds) {
133 bg.reused = 0;
134 }
135
136}
137
138
140{
141 switch (m_method) {
142 case c_Mixing:
143 cout << "Method: BG mixing" << endl;
145 break;
146 case c_Overlay:
147 cout << "Method: BG overlay" << endl;
149 break;
150 default:
151 cout << "Method: unknown" << endl;
153 }
154}
155
156
158{
159 cout << "Components: ";
160 if (m_components.empty()) {
161 cout << "all ";
162 } else {
163 for (const auto& component : m_components) cout << component << " ";
164 }
165 cout << endl;
166
167 cout << "Time window: ";
168 cout << "PXD [" << m_minTimePXD << ", " << m_maxTimePXD << "] ns, ";
169 cout << "ECL [" << m_minTimeECL << ", " << m_maxTimeECL << "] ns, ";
170 cout << "other components [" << m_minTime << ", " << m_maxTime << "] ns";
171 cout << endl;
172
173 cout << "Wrapping around: ";
174 if (m_wrapAround) {
175 cout << "enabled";
176 } else {
177 cout << "disabled";
178 }
179 cout << endl;
180
181 cout << "ECL deposited energy cut: " << m_maxEdepECL << " GeV" << endl;
182
183 cout << "Samples: " << endl;
184 for (const auto& bkg : m_backgrounds) {
185 cout << " " << bkg.type << endl;
186 cout << " equivalent time: " << bkg.realTime / 1000000 << " ms";
187 cout << ", events: " << bkg.numEvents;
188 cout << ", scale factor: " << bkg.scaleFactor;
189 cout << ", rate: " << bkg.rate << " GHz";
190 cout << ", re-used: " << bkg.reused << " times";
191 cout << endl;
192
193 for (const auto& fileName : bkg.fileNames) cout << " " << fileName << endl;
194 cout << endl;
195
196 }
197
198}
199
201{
202 cout << "Components: ";
203 if (m_components.empty()) {
204 cout << "all ";
205 } else {
206 for (const auto& component : m_components) cout << component << " ";
207 }
208 cout << endl;
209
210 cout << "Samples: " << endl;
211 for (const auto& bkg : m_backgrounds) {
212 cout << " " << bkg.type << endl;
213 cout << " events: " << bkg.numEvents;
214 cout << ", re-used: " << bkg.reused << " times";
215 cout << endl;
216
217 for (const auto& fileName : bkg.fileNames) cout << " " << fileName << endl;
218 cout << endl;
219 }
220}
221
This class stores the information about what background was mixed or overlayed.
double m_maxEdepECL
maximal allowed deposited energy in ECL
double m_maxTimeECL
maximal time shift of background event for ECL
std::vector< std::string > m_components
detector components included
double getMaxTime() const
Returns upper edge of the narrow time window.
void printForOverlay() const
Print info when BG overlay is used.
double m_minTimePXD
minimal time shift of background event for PXD
double getMaxTimeECL() const
Returns upper edge of ECL time window.
std::vector< BackgroundDescr > m_backgrounds
background descriptions
double getMaxEdepECL() const
Returns maximal alowed energy deposited in ECL to use BG events.
EMethod getMethod() const
Returns method enum used to add BG.
double m_maxTime
maximal time shift of background event
bool getWrapAround() const
Returns wrap-around flag.
double m_minTime
minimal time shift of background event
bool m_wrapAround
wrap around events in the tail after maxTime
double getMaxTimePXD() const
Returns upper edge of PXD time window.
double m_maxTimePXD
maximal time shift of background event for PXD
void printForMixing() const
Print info when BG mixing is used.
double getMinTimePXD() const
Returns lower edge of PXD time window.
virtual void merge(const Mergeable *other) override
Implementation of abstract class function.
const std::vector< std::string > & getComponents() const
Returns included components.
bool canBeMerged(const BackgroundInfo *other)
Checks if other object can be merged with this object.
const std::vector< BackgroundDescr > & getBackgrounds() const
Returns background descriptions.
void print() const
Print the info.
double getMinTimeECL() const
Returns lower edge of ECL time window.
double m_minTimeECL
minimal time shift of background event for ECL
virtual void clear() override
Implementation of abstract class function.
double getMinTime() const
Returns lower edge of the narrow time window.
Abstract base class for objects that can be merged.
Definition: Mergeable.h:31
Abstract base class for different kinds of events.
Definition: ClusterUtils.h:24
STL namespace.