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).",
68 B2WARNING(R
"RAW(The BGOverlayInput module will skip the check on the experiment number
69 consistency between the basf2 process and the beam background files.
70 It will also ignore run numbers in case of run-dependent MC.
72 This should be done only if you are extremely sure about what you are doing.
74 Be aware that you are not protected by the possible usage of beam background
75 files not suitabile for the experiment number you selected.)RAW");
81 B2FATAL(
"No valid files specified!");
91 const std::set<std::string>& branchNames = fileInfo.getBranchNames(
true);
92 if (branchNames.count(
"BackgroundMetaData")) {
93 B2FATAL(
"The BG sample used is aimed for BG mixing, not for BG overlay."
94 <<
LogVar(
"File name", fileName));
97 const FileMetaData& fileMetaData = fileInfo.getFileMetaData();
99 B2WARNING(
"BG file is empty: skipping."
100 <<
LogVar(
"FileName", fileName));
106 B2FATAL(
"The BG sample used is aimed for a different experiment number. Please check what you are doing."
107 <<
LogVar(
"File name", fileName)
108 <<
LogVar(
"Experiment number of the basf2 process", experiment)
115 }
catch (
const std::invalid_argument& e) {
116 B2FATAL(
"One of the BG files can not be opened."
117 <<
LogVar(
"File name", fileName));
118 }
catch (
const std::runtime_error& e) {
119 B2FATAL(
"Something went wrong with one of the BG files."
120 <<
LogVar(
"File name", fileName)
121 <<
LogVar(
"Issue", e.what()));
128 m_tree->AddFile(fileName.c_str());
136 B2ERROR(
"No branches found to be registered and connected");
152 B2INFO(
"BGOverlayInput: run-independent overlay starting with event " <<
m_firstEvent <<
" of " <<
m_numEvents);
163 m_index = bkgInfo->appendBackgroundDescr(descr);
175 std::vector<std::string> inputFileNames;
177 auto status =
m_tree->AddFile(fileName.c_str());
178 if (status > 0) inputFileNames.push_back(fileName);
180 if (inputFileNames.empty()) B2FATAL(
"No overlay files for run " << run);
196 descr.fileNames = inputFileNames;
198 descr.runNumber = run;
200 m_index = bkgInfo->appendBackgroundDescr(descr);
209 entry->resetForGetEntry();
213 B2INFO(
"BGOverlayInput: events for BG overlay will be reused");
214 bkgInfo->incrementReusedCounter(
m_index);
226 entry->ptr = entry->object;
228 entry->recoverFromNullObject();
252 const std::set<std::string> objPtrNames = {
"Belle2::ECLWaveforms",
"Belle2::PXDInjectionBGTiming",
"Belle2::EventLevelTriggerTimeInfo",
253 "Belle2::TRGSummary",
"Belle2::TOPInjectionVeto"
256 const TObjArray* branches =
m_tree->GetListOfBranches();
257 if (!branches)
return false;
259 for (
int jj = 0; jj < branches->GetEntriesFast(); jj++) {
260 TBranch* branch =
static_cast<TBranch*
>(branches->At(jj));
261 if (!branch)
continue;
262 const std::string branchName = branch->GetName();
264 TObject* objectPtr = 0;
265 branch->SetAddress(&objectPtr);
267 std::string objName = branch->GetClassName();
269 if (objName ==
"TClonesArray") {
270 TClass* objClass = (
static_cast<TClonesArray*
>(objectPtr))->GetClass();
271 branch->ResetAddress();
274 const std::string className = objClass->GetName();
275 if (className.find(
"Belle2::") == std::string::npos) {
290 }
else if (objPtrNames.find(objName) != objPtrNames.end()) {
291 std::string name = branchName;
294 auto currentStoreFlags = storeFlags;
295 if (objName ==
"Belle2::EventLevelTriggerTimeInfo") {
300 false, currentStoreFlags);
301 branch->ResetAddress();
313 branch->ResetAddress();
330 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...
Belle2::StoreEntry StoreEntry
Wraps a stored array/object, stored under unique (name, durability) key.
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.