10#include <background/modules/BGOverlayInput/BGOverlayInputModule.h>
13#include <framework/dataobjects/BackgroundInfo.h>
14#include <framework/dataobjects/BackgroundMetaData.h>
15#include <framework/dataobjects/FileMetaData.h>
16#include <framework/io/RootFileInfo.h>
17#include <framework/io/RootIOUtilities.h>
18#include <framework/logging/Logger.h>
21#include <TClonesArray.h>
45 setDescription(
"Input for BG overlay, either in form of Digits or raw data. For run-dependent MC (experiments 1 to 999) "
46 "the overlay samples corresponding to the simulated run are automatically selected from the input list "
47 "at each beginRun(), enabling production of multiple runs in a single job. "
48 "This feature can be turned off by setting ignoreRunNumbers to True.");
52 "List of files with measured beam background ");
54 "Name added to default branch names",
string(
"_beamBG"));
57 "If True, skip the check on the experiment number consistency between the basf2 process and the beam background files; "
58 "for experiments 1 to 999 ignore also run numbers. "
59 "By default, it is set to false, since the check should be skipped only by experts.",
62 "If True, ignore run numbers in case of run-dependend MC (experiments 1 to 999).",
73 B2WARNING(R
"RAW(The BGOverlayInput module will skip the check on the experiment number
74 consistency between the basf2 process and the beam background files.
75 It will also ingnore run numbers in case of run-dependent MC.
77 This should be done only if you are extremely sure about what you are doing.
79 Be aware that you are not protected by the possible usage of beam background
80 files not suitabile for the experiment number you selected.)RAW");
86 B2FATAL(
"No valid files specified!");
96 const std::set<std::string>& branchNames = fileInfo.getBranchNames(
true);
97 if (branchNames.count(
"BackgroundMetaData")) {
98 B2FATAL(
"The BG sample used is aimed for BG mixing, not for BG overlay."
99 <<
LogVar(
"File name", fileName));
102 const FileMetaData& fileMetaData = fileInfo.getFileMetaData();
105 B2FATAL(
"The BG sample used is aimed for a different experiment number. Please check what you are doing."
106 <<
LogVar(
"File name", fileName)
107 <<
LogVar(
"Experiment number of the basf2 process", experiment)
114 }
catch (
const std::invalid_argument& e) {
115 B2FATAL(
"One of the BG files can not be opened."
116 <<
LogVar(
"File name", fileName));
117 }
catch (
const std::runtime_error& e) {
118 B2FATAL(
"Something went wrong with one of the BG files."
119 <<
LogVar(
"File name", fileName)
120 <<
LogVar(
"Issue", e.what()));
127 m_tree->AddFile(fileName.c_str());
135 B2ERROR(
"No branches found to be registered and connected");
151 B2INFO(
"BGOverlayInput: run-independent overlay starting with event " <<
m_firstEvent <<
" of " <<
m_numEvents);
162 m_index = bkgInfo->appendBackgroundDescr(descr);
174 std::vector<std::string> inputFileNames;
176 auto status =
m_tree->AddFile(fileName.c_str());
177 if (status > 0) inputFileNames.push_back(fileName);
179 if (inputFileNames.empty()) B2FATAL(
"No overlay files for run " << run);
195 descr.fileNames = inputFileNames;
197 descr.runNumber = run;
199 m_index = bkgInfo->appendBackgroundDescr(descr);
208 entry->resetForGetEntry();
212 B2INFO(
"BGOverlayInput: events for BG overlay will be re-used");
213 bkgInfo->incrementReusedCounter(
m_index);
225 entry->ptr = entry->object;
227 entry->recoverFromNullObject();
255 const std::set<std::string> objPtrNames = {
"Belle2::ECLWaveforms",
"Belle2::PXDInjectionBGTiming",
"Belle2::EventLevelTriggerTimeInfo",
259 const TObjArray* branches =
m_tree->GetListOfBranches();
260 if (!branches)
return false;
262 for (
int jj = 0; jj < branches->GetEntriesFast(); jj++) {
263 TBranch* branch =
static_cast<TBranch*
>(branches->At(jj));
264 if (!branch)
continue;
265 const std::string branchName = branch->GetName();
267 TObject* objectPtr = 0;
268 branch->SetAddress(&objectPtr);
270 std::string objName = branch->GetClassName();
272 if (objName ==
"TClonesArray") {
273 TClass* objClass = (
static_cast<TClonesArray*
>(objectPtr))->GetClass();
274 branch->ResetAddress();
277 const std::string className = objClass->GetName();
278 if (className.find(
"Belle2::") == std::string::npos) {
293 }
else if (objPtrNames.find(objName) != objPtrNames.end()) {
294 std::string name = branchName;
298 branch->ResetAddress();
310 branch->ResetAddress();
327 m_tree->SetBranchStatus(branchName.c_str(), 0);
@ c_DontWriteOut
Object/array should be NOT saved by output modules.
@ c_ErrorIfAlreadyRegistered
If the object/array was already registered, produce an error (aborting initialisation).
StoreEntryMap & getStoreEntryMap(EDurability durability)
Get a reference to the object/array map.
@ c_Persistent
Object is available during entire execution time.
@ c_Event
Different object in each event, all objects/arrays are invalidated after event() function has been ca...
static DataStore & Instance()
Instance of singleton Store.
bool registerEntry(const std::string &name, EDurability durability, TClass *objClass, bool array, EStoreFlags storeFlags)
Register an entry in the DataStore map.
void setDescription(const std::string &description)
Sets the description of the module.
Helper class to factorize some necessary tasks when working with Belle2 output files.
bool registerInDataStore(DataStore::EStoreFlags storeFlags=DataStore::c_WriteOut)
Register the object/array in the DataStore.
bool create(bool replace=false)
Create a default object in the data store.
Type-safe access to single objects in the data store.
Class to store variables with their name which were sent to the logging service.
void addParam(const std::string &name, T ¶mVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
const std::string c_treeNames[]
Names of trees.
std::vector< std::string > expandWordExpansions(const std::vector< std::string > &filenames)
Performs wildcard expansion using wordexp(), returns matches.
Abstract base class for different kinds of events.
Structure for background description.
Wraps a stored array/object, stored under unique (name, durability) key.