Belle II Software  release-05-02-19
KoralWInputModule.cc
1 /**************************************************************************
2  * Belle II detector background library *
3  * Copyright(C) 2011 Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Andreas Moll *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 /* Own header. */
12 #include <generators/modules/koralwinput/KoralWInputModule.h>
13 
14 /* Belle 2 headers. */
15 #include <framework/datastore/StoreArray.h>
16 #include <framework/logging/Logger.h>
17 #include <framework/utilities/FileSystem.h>
18 
19 using namespace std;
20 using namespace Belle2;
21 
22 
23 REG_MODULE(KoralWInput)
24 
25 
26 KoralWInputModule::KoralWInputModule() : Module(), 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 KoralWInputModule::~KoralWInputModule()
39 {
40 }
41 
42 void KoralWInputModule::initialize()
43 {
44  StoreArray<MCParticle> mcparticle;
45  mcparticle.registerInDataStore();
46 
47  //Beam Parameters, initial particle - KORALW cannot handle beam energy spread
48  m_initial.initialize();
49 }
50 
51 void KoralWInputModule::event()
52 {
53  // Check if the BeamParameters have changed (if they do, abort the job! otherwise cross section calculation will be a nightmare.)
54  if (m_beamParams.hasChanged()) {
55  if (!m_initialized) {
56  initializeGenerator();
57  } else {
58  B2FATAL("KoralWInputModule::event(): BeamParameters have changed within a job, this is not supported for KORALW!");
59  }
60  }
61 
62  // initial particle from beam parameters
63  const MCInitialParticles& initial = m_initial.generate();
64 
65  // true boost
66  TLorentzRotation boost = initial.getCMSToLab();
67 
68  // vertex
69  TVector3 vertex = initial.getVertex();
70 
71  m_mcGraph.clear();
72  m_generator.generateEvent(m_mcGraph, vertex, boost);
73  m_mcGraph.generateList("", MCParticleGraph::c_setDecayInfo | MCParticleGraph::c_checkCyclic);
74 }
75 
76 void KoralWInputModule::terminate()
77 {
78  m_generator.term();
79 
80  B2RESULT("Total cross section: " << m_generator.getCrossSection() << " pb +- " << m_generator.getCrossSectionError() << " pb");
81 }
82 
83 void KoralWInputModule::initializeGenerator()
84 {
85  const BeamParameters& nominal = m_initial.getBeamParameters();
86  double ecm = nominal.getMass();
87  m_generator.setCMSEnergy(ecm);
88 
89  m_generator.init(m_dataPath, m_userDataFile);
90 
91  m_initialized = true;
92 }
REG_MODULE
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:652
Belle2::KoralWInputModule
The KoralW Generator module.
Definition: KoralWInputModule.h:42
Belle2::Module
Base class for Modules.
Definition: Module.h:74
Belle2::MCInitialParticles
This class contains the initial state for the given event.
Definition: MCInitialParticles.h:35
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::MCInitialParticles::getVertex
const TVector3 & getVertex() const
Get the position of the collision.
Definition: MCInitialParticles.h:143
Belle2::MCInitialParticles::getCMSToLab
const TLorentzRotation & getCMSToLab() const
Return the LorentzRotation to convert from CMS to lab frame.
Definition: MCInitialParticles.h:161
Belle2::StoreArray< MCParticle >
Belle2::BeamParameters
This class contains the nominal beam parameters and the parameters used for smearing of the primary v...
Definition: BeamParameters.h:33