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();
100 B2FATAL(
"The BG sample used is aimed for a different experiment number. Please check what you are doing."
101 <<
LogVar(
"File name", fileName)
102 <<
LogVar(
"Experiment number of the basf2 process", experiment)
109 }
catch (
const std::invalid_argument& e) {
110 B2FATAL(
"One of the BG files can not be opened."
111 <<
LogVar(
"File name", fileName));
112 }
catch (
const std::runtime_error& e) {
113 B2FATAL(
"Something went wrong with one of the BG files."
114 <<
LogVar(
"File name", fileName)
115 <<
LogVar(
"Issue", e.what()));
122 m_tree->AddFile(fileName.c_str());
130 B2ERROR(
"No branches found to be registered and connected");
146 B2INFO(
"BGOverlayInput: run-independent overlay starting with event " <<
m_firstEvent <<
" of " <<
m_numEvents);
157 m_index = bkgInfo->appendBackgroundDescr(descr);
169 std::vector<std::string> inputFileNames;
171 auto status =
m_tree->AddFile(fileName.c_str());
172 if (status > 0) inputFileNames.push_back(fileName);
174 if (inputFileNames.empty()) B2FATAL(
"No overlay files for run " << run);
190 descr.fileNames = inputFileNames;
192 descr.runNumber = run;
194 m_index = bkgInfo->appendBackgroundDescr(descr);
203 entry->resetForGetEntry();
207 B2INFO(
"BGOverlayInput: events for BG overlay will be reused");
208 bkgInfo->incrementReusedCounter(
m_index);
220 entry->ptr = entry->object;
222 entry->recoverFromNullObject();
246 const std::set<std::string> objPtrNames = {
"Belle2::ECLWaveforms",
"Belle2::PXDInjectionBGTiming",
"Belle2::EventLevelTriggerTimeInfo",
247 "Belle2::TRGSummary",
"Belle2::TOPInjectionVeto"
250 const TObjArray* branches =
m_tree->GetListOfBranches();
251 if (!branches)
return false;
253 for (
int jj = 0; jj < branches->GetEntriesFast(); jj++) {
254 TBranch* branch =
static_cast<TBranch*
>(branches->At(jj));
255 if (!branch)
continue;
256 const std::string branchName = branch->GetName();
258 TObject* objectPtr = 0;
259 branch->SetAddress(&objectPtr);
261 std::string objName = branch->GetClassName();
263 if (objName ==
"TClonesArray") {
264 TClass* objClass = (
static_cast<TClonesArray*
>(objectPtr))->GetClass();
265 branch->ResetAddress();
268 const std::string className = objClass->GetName();
269 if (className.find(
"Belle2::") == std::string::npos) {
284 }
else if (objPtrNames.find(objName) != objPtrNames.end()) {
285 std::string name = branchName;
288 auto currentStoreFlags = storeFlags;
289 if (objName ==
"Belle2::EventLevelTriggerTimeInfo") {
294 false, currentStoreFlags);
295 branch->ResetAddress();
307 branch->ResetAddress();
324 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.