Belle II Software  release-08-01-10
KoralWInputModule.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 /* Own header. */
10 #include <generators/modules/koralwinput/KoralWInputModule.h>
11 
12 /* Basf2 headers. */
13 #include <framework/datastore/StoreArray.h>
14 #include <framework/logging/Logger.h>
15 #include <framework/utilities/FileSystem.h>
16 
17 #include <Math/Vector3D.h>
18 
19 using namespace std;
20 using namespace Belle2;
21 
22 
23 REG_MODULE(KoralWInput);
24 
25 
26 KoralWInputModule::KoralWInputModule() : GeneratorBaseModule(), m_initial(BeamParameters::c_smearVertex)
27 {
28  //Set module properties
29  setDescription("Generates four fermion final state events with KoralW.");
30 
31  //Parameter definition
32  addParam("DataPath", m_dataPath, "The path to the KoralW input data files.",
33  FileSystem::findFile("/data/generators/koralw"));
34  addParam("UserDataFile", m_userDataFile, "The filename of the user KoralW input data file.",
35  FileSystem::findFile("/data/generators/koralw/KoralW_eeee.data"));
36 
37 }
38 
40 {
41 }
42 
44 {
45  StoreArray<MCParticle> mcparticle;
46  mcparticle.registerInDataStore();
47  // Initialize the InitialParticleGeneration utility
50  // Initialize the KoralW generator
53  m_initialized = true;
54 }
55 
57 {
58  // Check if KoralW is properly initialized.
59  if (not m_initialized)
60  B2FATAL("KorlalW is not properly initialized.");
61  // Check if the BeamParameters have changed: if they do, abort the job, otherwise cross section calculation is a nightmare,
62  // but be lenient with the first event: BeamParameters may be changed because of some basf2 black magic.
63  if (m_beamParams.hasChanged() and not m_firstEvent)
64  B2FATAL("BeamParameters have changed within a job, this is not supported for KoralW.");
65  m_firstEvent = false;
66  const MCInitialParticles& initial = m_initial.generate();
67 
68  // true boost
69  ROOT::Math::LorentzRotation boost = initial.getCMSToLab();
70 
71  // vertex
72  ROOT::Math::XYZVector vertex = initial.getVertex();
73  m_mcGraph.clear();
74  m_generator.generateEvent(m_mcGraph, vertex, boost);
76 }
77 
79 {
80  if (m_initialized) {
81  m_generator.term();
82  B2RESULT("Total cross section: " << m_generator.getCrossSection() << " pb +- " << m_generator.getCrossSectionError() << " pb");
83  }
84 }
This class contains the nominal beam parameters and the parameters used for smearing of the primary v...
static std::string findFile(const std::string &path, bool silent=false)
Search for given file or directory in local or central release directory, and return absolute path if...
Definition: FileSystem.cc:148
The base module for generator modules, which sets the generator information as EventExtraInfo.
const BeamParameters & getBeamParameters() const
Return reference to nominal beam parameters.
virtual ~KoralWInputModule()
Destructor.
bool m_firstEvent
Flag for keeping track of the first call of the event() method.
DBObjPtr< BeamParameters > m_beamParams
BeamParameter database object.
bool m_initialized
True if generator has been initialized.
KoralW m_generator
The KoralW generator.
void terminate() override
Method is called at the end of the event processing.
void generatorInitialize() override
Initializes the module.
MCParticleGraph m_mcGraph
The MCParticle graph object.
InitialParticleGeneration m_initial
InitialParticleGeneration utility.
std::string m_userDataFile
The filename of the user KoralW input data file.
std::string m_dataPath
The path to the KoralW input data files.
void generatorEvent() override
Method is called for each event.
void generateEvent(MCParticleGraph &mcGraph, ROOT::Math::XYZVector vertex, ROOT::Math::LorentzRotation boost)
Generates one single event.
Definition: KoralW.cc:107
void setCMSEnergy(double cmsEnergy)
Sets the CMS energy.
Definition: KoralW.h:51
void term()
Terminates the generator.
Definition: KoralW.cc:122
void init(const std::string &dataPath, const std::string &userDataFile)
Initializes the generator.
Definition: KoralW.cc:71
double getCrossSection()
Returns the total cross section of the generated process.
Definition: KoralW.h:75
double getCrossSectionError()
Returns the error on the total cross section of the generated process.
Definition: KoralW.h:80
This class contains the initial state for the given event.
const ROOT::Math::XYZVector & getVertex() const
Get the position of the collision.
const ROOT::Math::LorentzRotation & getCMSToLab() const
Return the LorentzRotation to convert from CMS to lab frame.
double getMass() const
Get the invariant mass of the collision (= energy in CMS)
@ 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.
void setDescription(const std::string &description)
Sets the description of the module.
Definition: Module.cc:214
bool registerInDataStore(DataStore::EStoreFlags storeFlags=DataStore::c_WriteOut)
Register the object/array in the DataStore.
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 initialize()
function to be executed on initialize()
MCInitialParticles & generate()
Generate a new event.
void clear()
Reset particles and decay information to make the class reusable.
Abstract base class for different kinds of events.