Belle II Software light-2406-ragdoll
BackgroundInfo Class Reference

This class stores the information about what background was mixed or overlayed. More...

#include <BackgroundInfo.h>

Inheritance diagram for BackgroundInfo:
Collaboration diagram for BackgroundInfo:

Classes

struct  BackgroundDescr
 Structure for background description. More...
 

Public Types

enum  EMethod {
  c_Unknown = 0 ,
  c_Mixing = 1 ,
  c_Overlay = 2
}
 enum for methods used to add BG More...
 

Public Member Functions

 BELLE2_DEFINE_EXCEPTION (BackgroundInfoNotMergeable, "BackgroundInfo: objects cannot be merged")
 Exception definition.
 
 BackgroundInfo ()
 Default constructor.
 
 ~BackgroundInfo ()
 Destructor.
 
void setMethod (EMethod method)
 Set method that is used to add BG.
 
unsigned appendBackgroundDescr (const BackgroundDescr &bgDescr)
 Append background description of a sample.
 
void setComponents (const std::vector< std::string > &components)
 Set components included.
 
void setMinTime (double minTime)
 Set lower edge of the narrow time window.
 
void setMaxTime (double maxTime)
 Set upper edge of the narrow time window.
 
void setMinTimeECL (double minTimeECL)
 Set lower edge of ECL time window.
 
void setMaxTimeECL (double maxTimeECL)
 Set upper edge of ECL time window.
 
void setMinTimePXD (double minTimePXD)
 Set lower edge of PXD time window.
 
void setMaxTimePXD (double maxTimePXD)
 Set upper edge of PXD time window.
 
void setWrapAround (bool wrapAround)
 Set wrap-around flag.
 
void setMaxEdepECL (double maxEdepECL)
 Set maximal alowed energy deposited in ECL to use BG events.
 
void setExtensionName (const std::string &name)
 Set name that is added to default branch names of background collections Used primarily to pass this name from BGOverlayInput to BGOverlayExecutor module.
 
void incrementReusedCounter (unsigned index)
 Increments sample reused counter.
 
EMethod getMethod () const
 Returns method enum used to add BG.
 
const std::vector< BackgroundDescr > & getBackgrounds () const
 Returns background descriptions.
 
const std::vector< std::string > & getComponents () const
 Returns included components.
 
double getMinTime () const
 Returns lower edge of the narrow time window.
 
double getMaxTime () const
 Returns upper edge of the narrow time window.
 
double getMinTimeECL () const
 Returns lower edge of ECL time window.
 
double getMaxTimeECL () const
 Returns upper edge of ECL time window.
 
double getMinTimePXD () const
 Returns lower edge of PXD time window.
 
double getMaxTimePXD () const
 Returns upper edge of PXD time window.
 
bool getWrapAround () const
 Returns wrap-around flag.
 
double getMaxEdepECL () const
 Returns maximal alowed energy deposited in ECL to use BG events.
 
const std::string & getExtensionName () const
 Returns name added to default branch names of background collections Used primarily to pass this name from BGOverlayInput to BGOverlayExecutor module.
 
virtual void merge (const Mergeable *other) override
 Implementation of abstract class function.
 
virtual void clear () override
 Implementation of abstract class function.
 
void print () const
 Print the info.
 
virtual void removeSideEffects ()
 An ugly little method that is called before event() for input and worker processes.
 
virtual Long64_t Merge (TCollection *hlist)
 Allow merging using TFileMerger if saved directly to a file.
 
virtual void Reset ()
 Root-like Reset function for "template compatibility" with ROOT objects.
 
virtual void SetDirectory (TDirectory *)
 Root-like SetDirectory function for "template compatibility" with ROOT objects.
 

Private Member Functions

bool canBeMerged (const BackgroundInfo *other)
 Checks if other object can be merged with this object.
 
void printForMixing () const
 Print info when BG mixing is used.
 
void printForOverlay () const
 Print info when BG overlay is used.
 
 ClassDefOverride (BackgroundInfo, 5)
 Class definition.
 
 ClassDef (Mergeable, 0)
 Abstract base class for objects that can be merged.
 

Private Attributes

EMethod m_method = c_Unknown
 method
 
std::vector< BackgroundDescrm_backgrounds
 background descriptions
 
std::vector< std::string > m_components
 detector components included
 
double m_minTime = 0
 minimal time shift of background event
 
double m_maxTime = 0
 maximal time shift of background event
 
double m_minTimeECL = 0
 minimal time shift of background event for ECL
 
double m_maxTimeECL = 0
 maximal time shift of background event for ECL
 
double m_minTimePXD = 0
 minimal time shift of background event for PXD
 
double m_maxTimePXD = 0
 maximal time shift of background event for PXD
 
bool m_wrapAround = false
 wrap around events in the tail after maxTime
 
double m_maxEdepECL = 0
 maximal allowed deposited energy in ECL
 
std::string m_extensionName
 name added to default branch names of background
 

Detailed Description

This class stores the information about what background was mixed or overlayed.

Definition at line 26 of file BackgroundInfo.h.

Member Enumeration Documentation

◆ EMethod

enum EMethod

enum for methods used to add BG

Enumerator
c_Unknown 

unknown

c_Mixing 

BG mixing.

c_Overlay 

BG overlay.

Definition at line 39 of file BackgroundInfo.h.

39 {c_Unknown = 0,
40 c_Mixing = 1,
41 c_Overlay = 2
42 };

Constructor & Destructor Documentation

◆ BackgroundInfo()

BackgroundInfo ( )
inline

Default constructor.

Definition at line 63 of file BackgroundInfo.h.

64 {}

◆ ~BackgroundInfo()

~BackgroundInfo ( )
inline

Destructor.

Definition at line 69 of file BackgroundInfo.h.

69{}

Member Function Documentation

◆ appendBackgroundDescr()

unsigned appendBackgroundDescr ( const BackgroundDescr bgDescr)
inline

Append background description of a sample.

Parameters
bgDescrdescription
Returns
index of appended element in std::vector

Definition at line 82 of file BackgroundInfo.h.

83 {
84 m_backgrounds.push_back(bgDescr);
85 return m_backgrounds.size() - 1;
86 }
std::vector< BackgroundDescr > m_backgrounds
background descriptions

◆ canBeMerged()

bool canBeMerged ( const BackgroundInfo other)
private

Checks if other object can be merged with this object.

Parameters
otherobject to be merged with this object
Returns
true, if can be merged

Definition at line 18 of file BackgroundInfo.cc.

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}
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 m_minTimePXD
minimal time shift of background event for PXD
double m_maxTime
maximal time shift of background event
double m_minTime
minimal time shift of background event
bool m_wrapAround
wrap around events in the tail after maxTime
double m_maxTimePXD
maximal time shift of background event for PXD
double m_minTimeECL
minimal time shift of background event for ECL

◆ clear()

void clear ( )
overridevirtual

Implementation of abstract class function.

Implements Mergeable.

Definition at line 130 of file BackgroundInfo.cc.

131{
132
133 for (auto& bg : m_backgrounds) {
134 bg.reused = 0;
135 }
136
137}

◆ getBackgrounds()

const std::vector< BackgroundDescr > & getBackgrounds ( ) const
inline

Returns background descriptions.

Returns
descriptions

Definition at line 171 of file BackgroundInfo.h.

171{return m_backgrounds;}

◆ getComponents()

const std::vector< std::string > & getComponents ( ) const
inline

Returns included components.

Returns
vector of component names

Definition at line 177 of file BackgroundInfo.h.

177{return m_components;}

◆ getExtensionName()

const std::string & getExtensionName ( ) const
inline

Returns name added to default branch names of background collections Used primarily to pass this name from BGOverlayInput to BGOverlayExecutor module.

Returns
extension name

Definition at line 232 of file BackgroundInfo.h.

232{return m_extensionName;}
std::string m_extensionName
name added to default branch names of background

◆ getMaxEdepECL()

double getMaxEdepECL ( ) const
inline

Returns maximal alowed energy deposited in ECL to use BG events.

Returns
energy cut [GeV]

Definition at line 225 of file BackgroundInfo.h.

225{return m_maxEdepECL;}

◆ getMaxTime()

double getMaxTime ( ) const
inline

Returns upper edge of the narrow time window.

Returns
upper edge

Definition at line 189 of file BackgroundInfo.h.

189{return m_maxTime;}

◆ getMaxTimeECL()

double getMaxTimeECL ( ) const
inline

Returns upper edge of ECL time window.

Returns
upper edge

Definition at line 201 of file BackgroundInfo.h.

201{return m_maxTimeECL;}

◆ getMaxTimePXD()

double getMaxTimePXD ( ) const
inline

Returns upper edge of PXD time window.

Returns
upper edge

Definition at line 213 of file BackgroundInfo.h.

213{return m_maxTimePXD;}

◆ getMethod()

EMethod getMethod ( ) const
inline

Returns method enum used to add BG.

Returns
method

Definition at line 165 of file BackgroundInfo.h.

165{return m_method;}

◆ getMinTime()

double getMinTime ( ) const
inline

Returns lower edge of the narrow time window.

Returns
lower edge

Definition at line 183 of file BackgroundInfo.h.

183{return m_minTime;}

◆ getMinTimeECL()

double getMinTimeECL ( ) const
inline

Returns lower edge of ECL time window.

Returns
lower edge

Definition at line 195 of file BackgroundInfo.h.

195{return m_minTimeECL;}

◆ getMinTimePXD()

double getMinTimePXD ( ) const
inline

Returns lower edge of PXD time window.

Returns
lower edge

Definition at line 207 of file BackgroundInfo.h.

207{return m_minTimePXD;}

◆ getWrapAround()

bool getWrapAround ( ) const
inline

Returns wrap-around flag.

Returns
flag

Definition at line 219 of file BackgroundInfo.h.

219{return m_wrapAround;}

◆ incrementReusedCounter()

void incrementReusedCounter ( unsigned  index)
inline

Increments sample reused counter.

Parameters
indexelement index in std::vector

Definition at line 156 of file BackgroundInfo.h.

157 {
158 if (index < m_backgrounds.size()) m_backgrounds[index].reused++;
159 }

◆ merge()

void merge ( const Mergeable other)
overridevirtual

Implementation of abstract class function.

Implements Mergeable.

Definition at line 94 of file BackgroundInfo.cc.

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.runNumber != bg.runNumber) continue;
115 if (otherBg.fileNames == bg.fileNames) {
116 if (otherBg.scaleFactor != bg.scaleFactor) {
117 B2ERROR("BackgroundInfo: objects cannot be merged (different scaleFactor)");
118 throw BackgroundInfoNotMergeable();
119 }
120 bg.reused += otherBg.reused;
121 added = true;
122 break;
123 }
124 }
125 if (!added) m_backgrounds.push_back(otherBg);
126 }
127
128}
This class stores the information about what background was mixed or overlayed.
bool canBeMerged(const BackgroundInfo *other)
Checks if other object can be merged with this object.

◆ Merge()

Long64_t Merge ( TCollection *  hlist)
virtualinherited

Allow merging using TFileMerger if saved directly to a file.

Note
dictionaries containing your Mergeable class need to be loaded, so 'hadd' will not work currently.

Definition at line 14 of file Mergeable.cc.

15{
16 Long64_t nMerged = 0;
17 if (hlist) {
18 const Mergeable* xh = nullptr;
19 TIter nxh(hlist);
20 while ((xh = dynamic_cast<Mergeable*>(nxh()))) {
21 // Add xh to me
22 merge(xh);
23 ++nMerged;
24 }
25 }
26 return nMerged;
27}
Abstract base class for objects that can be merged.
Definition: Mergeable.h:31
virtual void merge(const Mergeable *other)=0
Merge object 'other' into this one.

◆ print()

void print ( ) const

Print the info.

Definition at line 140 of file BackgroundInfo.cc.

141{
142 switch (m_method) {
143 case c_Mixing:
144 cout << "Method: BG mixing" << endl;
146 break;
147 case c_Overlay:
148 cout << "Method: BG overlay" << endl;
150 break;
151 default:
152 cout << "Method: unknown" << endl;
154 }
155}
void printForOverlay() const
Print info when BG overlay is used.
void printForMixing() const
Print info when BG mixing is used.

◆ printForMixing()

void printForMixing ( ) const
private

Print info when BG mixing is used.

Definition at line 158 of file BackgroundInfo.cc.

159{
160 cout << "Components: ";
161 if (m_components.empty()) {
162 cout << "all ";
163 } else {
164 for (const auto& component : m_components) cout << component << " ";
165 }
166 cout << endl;
167
168 cout << "Time window: ";
169 cout << "PXD [" << m_minTimePXD << ", " << m_maxTimePXD << "] ns, ";
170 cout << "ECL [" << m_minTimeECL << ", " << m_maxTimeECL << "] ns, ";
171 cout << "other components [" << m_minTime << ", " << m_maxTime << "] ns";
172 cout << endl;
173
174 cout << "Wrapping around: ";
175 if (m_wrapAround) {
176 cout << "enabled";
177 } else {
178 cout << "disabled";
179 }
180 cout << endl;
181
182 cout << "ECL deposited energy cut: " << m_maxEdepECL << " GeV" << endl;
183
184 cout << "Samples: " << endl;
185 for (const auto& bkg : m_backgrounds) {
186 cout << " " << bkg.type << endl;
187 cout << " equivalent time: " << bkg.realTime / 1000000 << " ms";
188 cout << ", events: " << bkg.numEvents;
189 cout << ", scale factor: " << bkg.scaleFactor;
190 cout << ", rate: " << bkg.rate << " GHz";
191 cout << ", re-used: " << bkg.reused << " times";
192 cout << endl;
193
194 for (const auto& fileName : bkg.fileNames) cout << " " << fileName << endl;
195 cout << endl;
196
197 }
198
199}

◆ printForOverlay()

void printForOverlay ( ) const
private

Print info when BG overlay is used.

Definition at line 201 of file BackgroundInfo.cc.

202{
203 cout << "Components: ";
204 if (m_components.empty()) {
205 cout << "all ";
206 } else {
207 for (const auto& component : m_components) cout << component << " ";
208 }
209 cout << endl;
210
211 cout << "Samples: " << endl;
212 for (const auto& bkg : m_backgrounds) {
213 cout << " " << bkg.type << endl;
214 cout << " run number: " << bkg.runNumber << endl;
215 cout << " events: " << bkg.numEvents;
216 cout << ", re-used: " << bkg.reused << " times";
217 cout << endl;
218
219 for (const auto& fileName : bkg.fileNames) cout << " " << fileName << endl;
220 cout << endl;
221 }
222}

◆ removeSideEffects()

virtual void removeSideEffects ( )
inlinevirtualinherited

An ugly little method that is called before event() for input and worker processes.

Main use case is to detach any attached TFile from this object. In the output process, it can stay attached (and grow as much as it likes).

Reimplemented in RootMergeable< T >.

Definition at line 58 of file Mergeable.h.

58{}

◆ Reset()

virtual void Reset ( )
inlinevirtualinherited

Root-like Reset function for "template compatibility" with ROOT objects.

Alias for clear().

Definition at line 66 of file Mergeable.h.

66{clear();}
virtual void clear()=0
Clear content of this object (e.g.

◆ setComponents()

void setComponents ( const std::vector< std::string > &  components)
inline

Set components included.

Parameters
componentsvector of component names

Definition at line 92 of file BackgroundInfo.h.

93 {
94 m_components = components;
95 }

◆ SetDirectory()

virtual void SetDirectory ( TDirectory *  )
inlinevirtualinherited

Root-like SetDirectory function for "template compatibility" with ROOT objects.

Does nothing.

Definition at line 68 of file Mergeable.h.

68{}

◆ setExtensionName()

void setExtensionName ( const std::string &  name)
inline

Set name that is added to default branch names of background collections Used primarily to pass this name from BGOverlayInput to BGOverlayExecutor module.

Parameters
nameextension name

Definition at line 150 of file BackgroundInfo.h.

150{m_extensionName = name;}

◆ setMaxEdepECL()

void setMaxEdepECL ( double  maxEdepECL)
inline

Set maximal alowed energy deposited in ECL to use BG events.

Parameters
maxEdepECLenergy cut [GeV]

Definition at line 143 of file BackgroundInfo.h.

143{m_maxEdepECL = maxEdepECL;}

◆ setMaxTime()

void setMaxTime ( double  maxTime)
inline

Set upper edge of the narrow time window.

Parameters
maxTimeupper edge

Definition at line 107 of file BackgroundInfo.h.

107{m_maxTime = maxTime;}

◆ setMaxTimeECL()

void setMaxTimeECL ( double  maxTimeECL)
inline

Set upper edge of ECL time window.

Parameters
maxTimeECLupper edge

Definition at line 119 of file BackgroundInfo.h.

119{m_maxTimeECL = maxTimeECL;}

◆ setMaxTimePXD()

void setMaxTimePXD ( double  maxTimePXD)
inline

Set upper edge of PXD time window.

Parameters
maxTimePXDupper edge

Definition at line 131 of file BackgroundInfo.h.

131{m_maxTimePXD = maxTimePXD;}

◆ setMethod()

void setMethod ( EMethod  method)
inline

Set method that is used to add BG.

Parameters
methodenum for method

Definition at line 75 of file BackgroundInfo.h.

75{m_method = method;}

◆ setMinTime()

void setMinTime ( double  minTime)
inline

Set lower edge of the narrow time window.

Parameters
minTimelower edge

Definition at line 101 of file BackgroundInfo.h.

101{m_minTime = minTime;}

◆ setMinTimeECL()

void setMinTimeECL ( double  minTimeECL)
inline

Set lower edge of ECL time window.

Parameters
minTimeECLlower edge

Definition at line 113 of file BackgroundInfo.h.

113{m_minTimeECL = minTimeECL;}

◆ setMinTimePXD()

void setMinTimePXD ( double  minTimePXD)
inline

Set lower edge of PXD time window.

Parameters
minTimePXDlower edge

Definition at line 125 of file BackgroundInfo.h.

125{m_minTimePXD = minTimePXD;}

◆ setWrapAround()

void setWrapAround ( bool  wrapAround)
inline

Set wrap-around flag.

Parameters
wrapAroundflag

Definition at line 137 of file BackgroundInfo.h.

137{m_wrapAround = wrapAround;}

Member Data Documentation

◆ m_backgrounds

std::vector<BackgroundDescr> m_backgrounds
private

background descriptions

Definition at line 269 of file BackgroundInfo.h.

◆ m_components

std::vector<std::string> m_components
private

detector components included

Definition at line 270 of file BackgroundInfo.h.

◆ m_extensionName

std::string m_extensionName
private

name added to default branch names of background

Definition at line 279 of file BackgroundInfo.h.

◆ m_maxEdepECL

double m_maxEdepECL = 0
private

maximal allowed deposited energy in ECL

Definition at line 278 of file BackgroundInfo.h.

◆ m_maxTime

double m_maxTime = 0
private

maximal time shift of background event

Definition at line 272 of file BackgroundInfo.h.

◆ m_maxTimeECL

double m_maxTimeECL = 0
private

maximal time shift of background event for ECL

Definition at line 274 of file BackgroundInfo.h.

◆ m_maxTimePXD

double m_maxTimePXD = 0
private

maximal time shift of background event for PXD

Definition at line 276 of file BackgroundInfo.h.

◆ m_method

EMethod m_method = c_Unknown
private

method

Definition at line 268 of file BackgroundInfo.h.

◆ m_minTime

double m_minTime = 0
private

minimal time shift of background event

Definition at line 271 of file BackgroundInfo.h.

◆ m_minTimeECL

double m_minTimeECL = 0
private

minimal time shift of background event for ECL

Definition at line 273 of file BackgroundInfo.h.

◆ m_minTimePXD

double m_minTimePXD = 0
private

minimal time shift of background event for PXD

Definition at line 275 of file BackgroundInfo.h.

◆ m_wrapAround

bool m_wrapAround = false
private

wrap around events in the tail after maxTime

Definition at line 277 of file BackgroundInfo.h.


The documentation for this class was generated from the following files: