Belle II Software development
LHEInputModule.cc
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8
9#include <generators/modules/LHEInputModule.h>
10
11#include <framework/logging/Logger.h>
12#include <framework/datastore/DataStore.h>
13#include <framework/datastore/StoreArray.h>
14
15using namespace std;
16using namespace Belle2;
17
18REG_MODULE(LHEInput);
19
21 m_nInitial(0),
22 m_nVirtual(0),
23 m_evtNum(-1)
24{
25 //Set module properties
26 setDescription("LHE file input. This module loads an event record from LHE format and store the content into the MCParticle collection. LHE format is a standard event record format to contain an event record in a Monte Carlo-independent format.");
28
29 //Parameter definition
30 addParam("inputFileList", m_inputFileNames, "List of names of LHE files");
31 addParam("createEventMetaData", m_createEventMetaData,
32 "Boolean to indicate whether the event numbers from input file should be used.", false);
33 addParam("runNum", m_runNum, "Run number", -1);
34 addParam("expNum", m_expNum, "Experiment number", -1);
35 addParam("skipEvents", m_skipEventNumber, "Skip this number of events before starting.", 0);
36 addParam("useWeights", m_useWeights, "Set to 'true' to if generator weights should be propagated.", false);
37 addParam("nInitialParticles", m_nInitial, "Number of MCParticles at the beginning of the events that should be flagged c_Initial.",
38 0);
39 addParam("nVirtualParticles", m_nVirtual,
40 "Number of MCParticles at the beginning of the events that should be flagged c_IsVirtual.", 0);
41 addParam("wrongSignPz", m_wrongSignPz, "Boolean to signal that directions of HER and LER were switched", true);
42}
43
45{
47 if (m_expNum < 0 or m_runNum < 0)
48 B2FATAL("The exp. and run numbers are not properly initialized: please set the 'expNum' and 'runNum' parameters of the LHEInput module.");
49
51 B2INFO("LHEInput acts as input module for this process. This means the exp., run and event numbers will be set by this module.");
52 }
53
54 m_iFile = 0;
55 if (m_inputFileNames.size() == 0) {
56 //something is wrong with the file list.
57 B2FATAL("Invalid list of input files, no entries found.");
58 } else {
59 //let's start with the first file:
61 }
62 try {
63 B2INFO("Opening first file: " << m_inputFileName);
65 m_lhe.skipEvents(m_skipEventNumber);
66 } catch (runtime_error& e) {
67 B2FATAL(e.what());
68 }
69 m_lhe.setInitialIndex(m_nInitial);
70 m_lhe.setVirtualIndex(m_nInitial + m_nVirtual);
71 m_lhe.m_wrongSignPz = m_wrongSignPz;
72
73 //Initialize MCParticle collection
74 StoreArray<MCParticle> mcparticle;
75 mcparticle.registerInDataStore();
76}
77
79{
80 if (!m_eventMetaData)
81 m_eventMetaData.create();
82 try {
83 m_pg.clear();
84 double weight = 1;
85 int id = m_lhe.getEvent(m_pg, weight);
87 if (id > -1) {
88 m_evtNum = id;
89 } else {
90 id = ++m_evtNum;
91 }
92 m_eventMetaData->setExperiment(m_expNum);
94 m_eventMetaData->setEvent(id);
95 }
96 if (m_useWeights)
97 m_eventMetaData->setGeneratedWeight(weight);
99 } catch (LHEReader::LHEEmptyEventError&) {
100 B2DEBUG(100, "Reached end of LHE file.");
101 m_lhe.closeCurrentInputFile();
102 m_iFile++;
103 if (m_iFile < m_inputFileNames.size()) {
104 try {
106 B2INFO("Opening next file: " << m_inputFileName);
108 } catch (runtime_error& e) {
109 B2FATAL(e.what());
110 }
111 } else {
112 m_eventMetaData->setEndOfData();
113 B2DEBUG(100, "Reached end of all LHE files.");
114 }
115 } catch (runtime_error& e) {
116 B2ERROR(e.what());
117 }
118}
@ c_ErrorIfAlreadyRegistered
If the object/array was already registered, produce an error (aborting initialisation).
Definition DataStore.h:72
bool m_useWeights
Parameter to switch on/off weight propagation.
int m_skipEventNumber
The number of events which should be skipped at the start of reading.
int m_evtNum
Event number to start from if the reader handles EventMetaData.
virtual void initialize() override
Initializes the module.
virtual void event() override
Method is called for each event.
LHEReader m_lhe
An instance of the LHE reader.
std::string m_inputFileName
The Name of the current input LHE file.
int m_nInitial
The number of particles in each event that should be flagges with c_Initial.
int m_expNum
Experiment number.
std::vector< std::string > m_inputFileNames
The list of filenames of input LHEfile.
StoreObjPtr< EventMetaData > m_eventMetaData
Event meta data.
LHEInputModule()
Constructor.
bool m_createEventMetaData
Parameter to create EventMetaData and set event info.
MCParticleGraph m_pg
The MCParticle graph object.
bool m_wrongSignPz
Parameter to signal that direction of LER and HER was switched.
int m_nVirtual
The number of particles in each event that should be flagged with c_IsVirtual.
uint m_iFile
Index of the current LHE input file.
int m_runNum
Run number.
@ c_checkCyclic
Check for cyclic dependencies.
@ c_setDecayInfo
Set decay time and vertex.
void setDescription(const std::string &description)
Sets the description of the module.
Definition Module.cc:214
void setPropertyFlags(unsigned int propertyFlags)
Sets the flags for the module properties.
Definition Module.cc:208
Module()
Constructor.
Definition Module.cc:30
@ c_Input
This module is an input module (reads data).
Definition Module.h:78
bool registerInDataStore(DataStore::EStoreFlags storeFlags=DataStore::c_WriteOut)
Register the object/array in the DataStore.
Accessor to arrays stored in the data store.
Definition StoreArray.h:113
void addParam(const std::string &name, T &paramVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
Definition Module.h:559
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition Module.h:649
Abstract base class for different kinds of events.
STL namespace.