11 #include <framework/dataobjects/BackgroundInfo.h>
12 #include <framework/logging/Logger.h>
14 #include <unordered_set>
24 B2ERROR(
"BackgroundInfo: objects cannot be merged (different method)");
28 std::unordered_set<int> bgThis;
29 for (
const auto& bg : m_backgrounds) {
30 int key = bg.tag * 16 + bg.fileType;
33 std::unordered_set<int> bgOther;
35 int key = bg.tag * 16 + bg.fileType;
38 if (bgOther != bgThis) {
39 B2ERROR(
"BackgroundInfo: objects cannot be merged (different backgrounds)");
43 auto compThis = m_components;
44 std::sort(compThis.begin(), compThis.end());
46 std::sort(compOther.begin(), compOther.end());
47 if (compOther != compThis) {
48 B2ERROR(
"BackgroundInfo: objects cannot be merged (different components)");
53 B2ERROR(
"BackgroundInfo: objects cannot be merged (different minTime)");
58 B2ERROR(
"BackgroundInfo: objects cannot be merged (different maxTime)");
63 B2ERROR(
"BackgroundInfo: objects cannot be merged (different minTimeECL)");
68 B2ERROR(
"BackgroundInfo: objects cannot be merged (different maxTimeECL)");
73 B2ERROR(
"BackgroundInfo: objects cannot be merged (different minTimePXD)");
78 B2ERROR(
"BackgroundInfo: objects cannot be merged (different maxTimePXD)");
83 B2ERROR(
"BackgroundInfo: objects cannot be merged (different wrapAround)");
88 B2ERROR(
"BackgroundInfo: objects cannot be merged (different maxEdepECL)");
101 if (otherObj->getMethod() == c_Unknown and otherObj->getBackgrounds().empty())
104 if (m_method == c_Unknown and m_backgrounds.empty()) {
109 if (!canBeMerged(otherObj))
throw BackgroundInfoNotMergeable();
111 for (
const auto& otherBg : otherObj->getBackgrounds()) {
113 for (
auto& bg : m_backgrounds) {
114 if (otherBg.tag != bg.tag)
continue;
115 if (otherBg.fileType != bg.fileType)
continue;
116 if (otherBg.fileNames == bg.fileNames) {
117 if (otherBg.scaleFactor != bg.scaleFactor) {
118 B2ERROR(
"BackgroundInfo: objects cannot be merged (different scaleFactor)");
119 throw BackgroundInfoNotMergeable();
121 bg.reused += otherBg.reused;
126 if (!added) m_backgrounds.push_back(otherBg);
131 void BackgroundInfo::clear()
134 for (
auto& bg : m_backgrounds) {
141 void BackgroundInfo::print()
const
145 cout <<
"Method: BG mixing" << endl;
149 cout <<
"Method: BG overlay" << endl;
153 cout <<
"Method: unknown" << endl;
159 void BackgroundInfo::printForMixing()
const
161 cout <<
"Components: ";
162 if (m_components.empty()) {
165 for (
const auto& component : m_components) cout << component <<
" ";
169 cout <<
"Time window: ";
170 cout <<
"PXD [" << m_minTimePXD <<
", " << m_maxTimePXD <<
"] ns, ";
171 cout <<
"ECL [" << m_minTimeECL <<
", " << m_maxTimeECL <<
"] ns, ";
172 cout <<
"other components [" << m_minTime <<
", " << m_maxTime <<
"] ns";
175 cout <<
"Wrapping around: ";
183 cout <<
"ECL deposited energy cut: " << m_maxEdepECL <<
" GeV" << endl;
185 cout <<
"Samples: " << endl;
186 for (
const auto& bkg : m_backgrounds) {
187 cout <<
" " << bkg.type << endl;
188 cout <<
" equivalent time: " << bkg.realTime / 1000000 <<
" ms";
189 cout <<
", events: " << bkg.numEvents;
190 cout <<
", scale factor: " << bkg.scaleFactor;
191 cout <<
", rate: " << bkg.rate <<
" GHz";
192 cout <<
", re-used: " << bkg.reused <<
" times";
195 for (
const auto& fileName : bkg.fileNames) cout <<
" " << fileName << endl;
202 void BackgroundInfo::printForOverlay()
const
204 cout <<
"Components: ";
205 if (m_components.empty()) {
208 for (
const auto& component : m_components) cout << component <<
" ";
212 cout <<
"Samples: " << endl;
213 for (
const auto& bkg : m_backgrounds) {
214 cout <<
" " << bkg.type << endl;
215 cout <<
" events: " << bkg.numEvents;
216 cout <<
", re-used: " << bkg.reused <<
" times";
219 for (
const auto& fileName : bkg.fileNames) cout <<
" " << fileName << endl;