9 #include <framework/dataobjects/BackgroundInfo.h>
10 #include <framework/logging/Logger.h>
12 #include <unordered_set>
22 B2ERROR(
"BackgroundInfo: objects cannot be merged (different method)");
26 std::unordered_set<int> bgThis;
27 for (
const auto& bg : m_backgrounds) {
28 int key = bg.tag * 16 + bg.fileType;
31 std::unordered_set<int> bgOther;
33 int key = bg.tag * 16 + bg.fileType;
36 if (bgOther != bgThis) {
37 B2ERROR(
"BackgroundInfo: objects cannot be merged (different backgrounds)");
41 auto compThis = m_components;
42 std::sort(compThis.begin(), compThis.end());
44 std::sort(compOther.begin(), compOther.end());
45 if (compOther != compThis) {
46 B2ERROR(
"BackgroundInfo: objects cannot be merged (different components)");
51 B2ERROR(
"BackgroundInfo: objects cannot be merged (different minTime)");
56 B2ERROR(
"BackgroundInfo: objects cannot be merged (different maxTime)");
61 B2ERROR(
"BackgroundInfo: objects cannot be merged (different minTimeECL)");
66 B2ERROR(
"BackgroundInfo: objects cannot be merged (different maxTimeECL)");
71 B2ERROR(
"BackgroundInfo: objects cannot be merged (different minTimePXD)");
76 B2ERROR(
"BackgroundInfo: objects cannot be merged (different maxTimePXD)");
81 B2ERROR(
"BackgroundInfo: objects cannot be merged (different wrapAround)");
86 B2ERROR(
"BackgroundInfo: objects cannot be merged (different maxEdepECL)");
99 if (otherObj->getMethod() == c_Unknown and otherObj->getBackgrounds().empty())
102 if (m_method == c_Unknown and m_backgrounds.empty()) {
107 if (!canBeMerged(otherObj))
throw BackgroundInfoNotMergeable();
109 for (
const auto& otherBg : otherObj->getBackgrounds()) {
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();
119 bg.reused += otherBg.reused;
124 if (!added) m_backgrounds.push_back(otherBg);
129 void BackgroundInfo::clear()
132 for (
auto& bg : m_backgrounds) {
139 void BackgroundInfo::print()
const
143 cout <<
"Method: BG mixing" << endl;
147 cout <<
"Method: BG overlay" << endl;
151 cout <<
"Method: unknown" << endl;
157 void BackgroundInfo::printForMixing()
const
159 cout <<
"Components: ";
160 if (m_components.empty()) {
163 for (
const auto& component : m_components) cout << component <<
" ";
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";
173 cout <<
"Wrapping around: ";
181 cout <<
"ECL deposited energy cut: " << m_maxEdepECL <<
" GeV" << endl;
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";
193 for (
const auto& fileName : bkg.fileNames) cout <<
" " << fileName << endl;
200 void BackgroundInfo::printForOverlay()
const
202 cout <<
"Components: ";
203 if (m_components.empty()) {
206 for (
const auto& component : m_components) cout << component <<
" ";
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";
217 for (
const auto& fileName : bkg.fileNames) cout <<
" " << fileName << endl;
This class stores the information about what background was mixed or overlayed.
double getMaxTime() const
Returns upper edge of the narrow time window.
double getMaxTimeECL() const
Returns upper edge of ECL time window.
const std::vector< BackgroundDescr > & getBackgrounds() const
Returns 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.
bool getWrapAround() const
Returns wrap-around flag.
double getMaxTimePXD() const
Returns upper edge of PXD time window.
double getMinTimePXD() const
Returns lower edge of PXD time window.
double getMinTimeECL() const
Returns lower edge of ECL time window.
const std::vector< std::string > & getComponents() const
Returns included components.
double getMinTime() const
Returns lower edge of the narrow time window.
Abstract base class for objects that can be merged.
std::vector< std::vector< double > > merge(std::vector< std::vector< std::vector< double >>> toMerge)
merge { vector<double> a, vector<double> b} into {a, b}
Abstract base class for different kinds of events.