Belle II Software development
HepevtInputModule.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/HepevtInputModule.h>
10
11#include <framework/logging/Logger.h>
12#include <framework/datastore/DataStore.h>
13#include <framework/datastore/StoreArray.h>
14#include <framework/dataobjects/EventMetaData.h>
15#include <framework/datastore/StoreObjPtr.h>
16
17using namespace std;
18using namespace Belle2;
19
20REG_MODULE(HepevtInput);
21
23{
24 //Set module properties
25 setDescription("HepEvt file input. This module loads an event record from HEPEVT format and store the content into the MCParticle collection. HEPEVT format is a standard event record format to contain an event record in a Monte Carlo-independent format.");
27
28 //Parameter definition
29 addParam("inputFileList", m_inputFileNames, "List of names of Hepevt files");
30 addParam("createEventMetaData", m_createEventMetaData,
31 "Boolean to indicate whether the event numbers from input file should be used.", false);
32 addParam("runNum", m_runNum, "Run number", -1);
33 addParam("expNum", m_expNum, "Experiment number", -1);
34 addParam("skipEvents", m_skipEventNumber, "Skip this number of events before starting.", 0);
35 addParam("useWeights", m_useWeights, "Set to 'true' to if generator weights should be propagated.", false);
36 addParam("nVirtualParticles", m_nVirtual, "Number of particles at the beginning of the events that should be made virtual.", 0);
37 addParam("wrongSignPz", m_wrongSignPz, "Boolean to signal that directions of HER and LER were switched", false);
38}
39
41{
43 if (m_expNum < 0 or m_runNum < 0)
44 B2FATAL("The exp. and run numbers are not properly initialized: please set the 'expNum' and 'runNum' parameters of the HepevtInput module.");
45
47 B2INFO("HepevtInput acts as input module for this process. This means the exp., run and event numbers will be set by this module.");
48 }
49
50 m_iFile = 0;
51 if (m_inputFileNames.size() == 0) {
52 //something is wrong with the file list.
53 B2FATAL("Invalid list of input files, no entries found.");
54 } else {
55 //let's start with the first file:
57 }
58 try {
59 B2INFO("Opening first file: " << m_inputFileName);
62 } catch (runtime_error& e) {
63 B2FATAL(e.what());
64 }
67
68 //Initialize MCParticle collection
69 StoreArray<MCParticle> mcparticle;
70 mcparticle.registerInDataStore();
71}
72
73
75{
76 if (!m_eventMetaData)
77 m_eventMetaData.create();
78 try {
79 mpg.clear();
80 double weight = 1;
81 int id = m_hepevt.getEvent(mpg, weight);
83 if (id > -1) {
84 m_evtNum = id;
85 } else {
86 id = ++m_evtNum;
87 }
88 m_eventMetaData->setExperiment(m_expNum);
90 m_eventMetaData->setEvent(id);
91 }
92 if (m_useWeights)
93 m_eventMetaData->setGeneratedWeight(weight);
95 } catch (HepevtReader::HepEvtEmptyEventError&) {
96 B2DEBUG(100, "Reached end of HepEvt file.");
98 m_iFile++;
99 if (m_iFile < m_inputFileNames.size()) {
100 try {
102 B2INFO("Opening next file: " << m_inputFileName);
104 } catch (runtime_error& e) {
105 B2FATAL(e.what());
106 }
107 } else {
108 m_eventMetaData->setEndOfData();
109 B2DEBUG(100, "Reached end of all HepEvt files.");
110 }
111 } catch (runtime_error& e) {
112 B2ERROR(e.what());
113 }
114}
@ 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
The event number is needed if the reader handles EventMetaData.
virtual void initialize() override
Initializes the module.
virtual void event() override
Method is called for each event.
std::string m_inputFileName
The Name of the current input HepEvt file.
int m_expNum
The experiment number that should be used if the reader handles EventMetaData.
std::vector< std::string > m_inputFileNames
The list of filenames of input HepEvtfile.
StoreObjPtr< EventMetaData > m_eventMetaData
Event meta data.
HepevtReader m_hepevt
An instance of the HepEvt reader.
bool m_createEventMetaData
Parameter to allow the module to create EventMetaData and set event info
bool m_wrongSignPz
Parameter to signal that direction of LER and HER was switched.
MCParticleGraph mpg
The MCParticle graph object.
int m_nVirtual
The number of particles in each event that should be made virtual.
uint m_iFile
Index of the current HepEvt input file.
int m_runNum
The run number that should be used if the reader handles EventMetaData.
bool skipEvents(int n)
Skips a given number of events.
Definition: HepevtReader.cc:79
void open(const std::string &filename)
Opens an ascii file and prepares it for reading.
Definition: HepevtReader.cc:27
void closeCurrentInputFile()
Closes the current input file to allow opening the next one.
Definition: HepevtReader.h:71
int getEvent(MCParticleGraph &graph, double &weight)
Reads the next event and stores the result in the given MCParticle graph.
Definition: HepevtReader.cc:35
bool m_wrongSignPz
Bool to indicate that HER and LER were swapped.
Definition: HepevtReader.h:89
int m_nVirtual
The number of particles in each event with a set Virtual flag.
Definition: HepevtReader.h:88
@ c_checkCyclic
Check for cyclic dependencies.
@ c_setDecayInfo
Set decay time and vertex.
void generateList(const std::string &name="", int options=c_setNothing)
Generates the MCParticle list and stores it in the StoreArray with the given name.
Base class for Modules.
Definition: Module.h:72
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
@ 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:560
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:650
void clear()
Reset particles and decay information to make the class reusable.
Abstract base class for different kinds of events.
STL namespace.