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>
44 setDescription(
"Input for BG overlay, either in form of Digits or raw data. For run-dependent MC (experiments 1 to 999) "
45 "the overlay samples corresponding to the simulated run are automatically selected from the input list "
46 "at each beginRun(), enabling production of multiple runs in a single job. "
47 "This feature can be turned off by setting ignoreRunNumbers to True.");
51 "List of files with measured beam background ");
53 "Name added to default branch names",
string(
"_beamBG"));
56 "If True, skip the check on the experiment number consistency between the basf2 process and the beam background files; "
57 "for experiments 1 to 999 ignore also run numbers. "
58 "By default, it is set to false, since the check should be skipped only by experts.",
61 "If True, ignore run numbers in case of run-dependend MC (experiments 1 to 999).",
72 B2WARNING(R
"RAW(The BGOverlayInput module will skip the check on the experiment number
73 consistency between the basf2 process and the beam background files.
74 It will also ignore run numbers in case of run-dependent MC.
76 This should be done only if you are extremely sure about what you are doing.
78 Be aware that you are not protected by the possible usage of beam background
79 files not suitabile for the experiment number you selected.)RAW");
85 B2FATAL(
"No valid files specified!");
95 const std::set<std::string>& branchNames = fileInfo.getBranchNames(
true);
96 if (branchNames.count(
"BackgroundMetaData")) {
97 B2FATAL(
"The BG sample used is aimed for BG mixing, not for BG overlay."
98 <<
LogVar(
"File name", fileName));
101 const FileMetaData& fileMetaData = fileInfo.getFileMetaData();
104 B2FATAL(
"The BG sample used is aimed for a different experiment number. Please check what you are doing."
105 <<
LogVar(
"File name", fileName)
106 <<
LogVar(
"Experiment number of the basf2 process", experiment)
113 }
catch (
const std::invalid_argument& e) {
114 B2FATAL(
"One of the BG files can not be opened."
115 <<
LogVar(
"File name", fileName));
116 }
catch (
const std::runtime_error& e) {
117 B2FATAL(
"Something went wrong with one of the BG files."
118 <<
LogVar(
"File name", fileName)
119 <<
LogVar(
"Issue", e.what()));
126 m_tree->AddFile(fileName.c_str());
134 B2ERROR(
"No branches found to be registered and connected");
150 B2INFO(
"BGOverlayInput: run-independent overlay starting with event " <<
m_firstEvent <<
" of " <<
m_numEvents);
161 m_index = bkgInfo->appendBackgroundDescr(descr);
173 std::vector<std::string> inputFileNames;
175 auto status =
m_tree->AddFile(fileName.c_str());
176 if (status > 0) inputFileNames.push_back(fileName);
178 if (inputFileNames.empty()) B2FATAL(
"No overlay files for run " << run);
194 descr.fileNames = inputFileNames;
196 descr.runNumber = run;
198 m_index = bkgInfo->appendBackgroundDescr(descr);
207 entry->resetForGetEntry();
211 B2INFO(
"BGOverlayInput: events for BG overlay will be reused");
212 bkgInfo->incrementReusedCounter(
m_index);
224 entry->ptr = entry->object;
226 entry->recoverFromNullObject();
254 const std::set<std::string> objPtrNames = {
"Belle2::ECLWaveforms",
"Belle2::PXDInjectionBGTiming",
"Belle2::EventLevelTriggerTimeInfo",
258 const TObjArray* branches =
m_tree->GetListOfBranches();
259 if (!branches)
return false;
261 for (
int jj = 0; jj < branches->GetEntriesFast(); jj++) {
262 TBranch* branch =
static_cast<TBranch*
>(branches->At(jj));
263 if (!branch)
continue;
264 const std::string branchName = branch->GetName();
266 TObject* objectPtr = 0;
267 branch->SetAddress(&objectPtr);
269 std::string objName = branch->GetClassName();
271 if (objName ==
"TClonesArray") {
272 TClass* objClass = (
static_cast<TClonesArray*
>(objectPtr))->GetClass();
273 branch->ResetAddress();
276 const std::string className = objClass->GetName();
277 if (className.find(
"Belle2::") == std::string::npos) {
292 }
else if (objPtrNames.find(objName) != objPtrNames.end()) {
293 std::string name = branchName;
297 branch->ResetAddress();
309 branch->ResetAddress();
326 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.