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
15#include <TF1.h>
16
17using namespace std;
18using namespace Belle2;
19
20REG_MODULE(LHEInput);
21
23 m_nInitial(0),
24 m_nVirtual(0),
25 m_evtNum(-1)
26{
27 //Set module properties
28 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.");
30
31 //Parameter definition
32 addParam("inputFileList", m_inputFileNames, "List of names of LHE files");
33 addParam("createEventMetaData", m_createEventMetaData,
34 "Boolean to indicate whether the event numbers from input file should be used.", false);
35 addParam("runNum", m_runNum, "Run number", -1);
36 addParam("expNum", m_expNum, "Experiment number", -1);
37 addParam("skipEvents", m_skipEventNumber, "Skip this number of events before starting.", 0);
38 addParam("useWeights", m_useWeights, "Set to 'true' to if generator weights should be propagated (not implemented yet).", false);
39 addParam("nInitialParticles", m_nInitial, "Number of MCParticles at the beginning of the events that should be flagged c_Initial.",
40 0);
41 addParam("nVirtualParticles", m_nVirtual,
42 "Number of MCParticles at the beginning of the events that should be flagged c_IsVirtual.", 0);
43 addParam("wrongSignPz", m_wrongSignPz, "Boolean to signal that directions of HER and LER were switched", true);
44 addParam("meanDecayLength", m_meanDecayLength,
45 "Mean decay length(mean lifetime * c) between displaced vertex to IP in the CM frame, default to be zero, unit in cm", 0.);
46 addParam("Rmin", m_Rmin, "Minimum of distance between displaced vertex to IP in CM frame", 0.);
47 addParam("Rmax", m_Rmax, "Maximum of distance between displaced vertex to IP in CM frame", 1000000.);
48 addParam("pdg_displaced", m_pdg_displaced, "PDG code of the displaced particle being studied", 9000008);
49}
50
52{
54 if (m_expNum < 0 or m_runNum < 0)
55 B2FATAL("The exp. and run numbers are not properly initialized: please set the 'expNum' and 'runNum' parameters of the LHEInput module.");
56
58 B2INFO("LHEInput acts as input module for this process. This means the exp., run and event numbers will be set by this module.");
59 }
60
61 m_iFile = 0;
62 if (m_inputFileNames.size() == 0) {
63 //something is wrong with the file list.
64 B2FATAL("Invalid list of input files, no entries found.");
65 } else {
66 //let's start with the first file:
68 }
69 try {
70 B2INFO("Opening first file: " << m_inputFileName);
73 } catch (runtime_error& e) {
74 B2FATAL(e.what());
75 }
79
80 //pass displaced vertex to LHEReader
85 //print out warning information if default R range is change
86 if (m_Rmin != 0 || m_Rmax != 1000000) {
87 TF1 fr("fr", "exp(-x/[0])", 0, 1000000);
88 double factor;
89 factor = fr.Integral(m_Rmin, m_Rmax) / fr.Integral(0, 1000000);
90 B2WARNING("Default range of R is changed, new range is from " << m_Rmin << "cm to " << m_Rmax <<
91 " cm. This will change the cross section by a factor of " << factor);
92 }
93
94 //Initialize MCParticle collection
95 StoreArray<MCParticle> mcparticle;
96 mcparticle.registerInDataStore();
97}
98
100{
101 if (!m_eventMetaData)
102 m_eventMetaData.create();
103 try {
104 m_pg.clear();
105 double weight = 1;
106 int id = m_lhe.getEvent(m_pg, weight);
108 if (id > -1) {
109 m_evtNum = id;
110 } else {
111 id = ++m_evtNum;
112 }
113 m_eventMetaData->setExperiment(m_expNum);
114 m_eventMetaData->setRun(m_runNum);
115 m_eventMetaData->setEvent(id);
116 }
117 if (m_useWeights)
118 m_eventMetaData->setGeneratedWeight(weight);
120 } catch (LHEReader::LHEEmptyEventError&) {
121 B2DEBUG(100, "Reached end of LHE file.");
123 m_iFile++;
124 if (m_iFile < m_inputFileNames.size()) {
125 try {
127 B2INFO("Opening next file: " << m_inputFileName);
129 } catch (runtime_error& e) {
130 B2FATAL(e.what());
131 }
132 } else {
133 m_eventMetaData->setEndOfData();
134 B2DEBUG(100, "Reached end of all LHE files.");
135 }
136 } catch (runtime_error& e) {
137 B2ERROR(e.what());
138 }
139}
@ 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.
double m_Rmin
Minimum of distance between displaced vertex to IP.
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.
double m_Rmax
Maximum of distance between dispalced vertex to IP.
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_pdg_displaced
PDG code of the displaced particle .
double m_meanDecayLength
Mean lifetime*c of displaced particle, default to be zero.
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.
bool skipEvents(int n)
Skips a given number of events.
Definition: LHEReader.cc:112
void setVirtualIndex(int index)
Set the maximum index of particles in each event that must be set as c_IsVirtual (1-based).
Definition: LHEReader.h:100
double m_Rmin
Minimum of vertex distance to IP.
Definition: LHEReader.h:104
int m_pdgDisplaced
PDG code of the displaced particle being studied.
Definition: LHEReader.h:106
void setInitialIndex(int index)
Set the maximum index of particles in each event that must be set as c_Initial (1-based).
Definition: LHEReader.h:94
double m_Rmax
Maximum of vertex distance to IP.
Definition: LHEReader.h:105
void open(const std::string &filename)
Opens an ascii file and prepares it for reading.
Definition: LHEReader.cc:28
void closeCurrentInputFile()
Closes the current input file to allow opening the next one.
Definition: LHEReader.h:73
int getEvent(MCParticleGraph &graph, double &weight)
Reads the next event and stores the result in the given MCParticle graph.
Definition: LHEReader.cc:36
bool m_wrongSignPz
Bool to indicate that HER and LER were swapped.
Definition: LHEReader.h:102
double m_meanDecayLength
Mean lifetime*c of displaced particle.
Definition: LHEReader.h:103
@ 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.