Belle II Software  release-06-00-14
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 /* Belle 2 headers. */
13 #include <framework/datastore/StoreArray.h>
14 #include <framework/logging/Logger.h>
15 #include <framework/utilities/FileSystem.h>
16 
17 using namespace std;
18 using namespace Belle2;
19 
20 
21 REG_MODULE(KoralWInput)
22 
23 
24 KoralWInputModule::KoralWInputModule() : Module(), m_initial(BeamParameters::c_smearVertex)
25 {
26  //Set module properties
27  setDescription("Generates four fermion final state events with KoralW.");
28 
29  //Parameter definition
30  addParam("DataPath", m_dataPath, "The path to the KoralW input data files.",
31  FileSystem::findFile("/data/generators/koralw"));
32  addParam("UserDataFile", m_userDataFile, "The filename of the user KoralW input data file.",
33  FileSystem::findFile("/data/generators/koralw/KoralW_eeee.data"));
34 }
35 
36 KoralWInputModule::~KoralWInputModule()
37 {
38 }
39 
40 void KoralWInputModule::initialize()
41 {
42  StoreArray<MCParticle> mcparticle;
43  mcparticle.registerInDataStore();
44  // Initialize the InitialParticleGeneration utility
45  m_initial.initialize();
46  const BeamParameters& beams = m_initial.getBeamParameters();
47  // Initialize the KoralW generator
48  m_generator.setCMSEnergy(beams.getMass());
49  m_generator.init(m_dataPath, m_userDataFile);
50  m_initialized = true;
51 }
52 
53 void KoralWInputModule::event()
54 {
55  // Check if KoralW is properly initialized.
56  if (not m_initialized)
57  B2FATAL("KorlalW is not properly initialized.");
58  // Check if the BeamParameters have changed: if they do, abort the job, otherwise cross section calculation is a nightmare,
59  // but be lenient with the first event: BeamParameters may be changed because of some basf2 black magic.
60  if (m_beamParams.hasChanged() and not m_firstEvent)
61  B2FATAL("BeamParameters have changed within a job, this is not supported for KoralW.");
62  m_firstEvent = false;
63  const MCInitialParticles& initial = m_initial.generate();
64  TLorentzRotation boost = initial.getCMSToLab();
65  TVector3 vertex = initial.getVertex();
66  m_mcGraph.clear();
67  m_generator.generateEvent(m_mcGraph, vertex, boost);
68  m_mcGraph.generateList("", MCParticleGraph::c_setDecayInfo | MCParticleGraph::c_checkCyclic);
69 }
70 
71 void KoralWInputModule::terminate()
72 {
73  if (m_initialized) {
74  m_generator.term();
75  B2RESULT("Total cross section: " << m_generator.getCrossSection() << " pb +- " << m_generator.getCrossSectionError() << " pb");
76  }
77 }
This class contains the nominal beam parameters and the parameters used for smearing of the primary v...
The KoralW Generator module.
This class contains the initial state for the given event.
const TLorentzRotation & getCMSToLab() const
Return the LorentzRotation to convert from CMS to lab frame.
const TVector3 & getVertex() const
Get the position of the collision.
double getMass() const
Get the invariant mass of the collision (= energy in CMS)
Base class for Modules.
Definition: Module.h:72
bool registerInDataStore(DataStore::EStoreFlags storeFlags=DataStore::c_WriteOut)
Register the object/array in the DataStore.
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:650
Abstract base class for different kinds of events.