Belle II Software  release-08-01-10
EvtGenInputModule.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/evtgeninput/EvtGenInputModule.h>
11 
12 /* Generators headers. */
13 #include <generators/evtgen/EvtGenInterface.h>
14 #include <generators/evtgen/EvtGenUtilities.h>
15 
16 /* Basf2 headers. */
17 #include <framework/utilities/FileSystem.h>
18 #include <framework/datastore/StoreArray.h>
19 #include <mdst/dataobjects/MCParticleGraph.h>
20 
21 using namespace std;
22 using namespace Belle2;
23 
24 //-----------------------------------------------------------------
25 // Register the Module
26 //-----------------------------------------------------------------
27 REG_MODULE(EvtGenInput);
28 
29 //-----------------------------------------------------------------
30 // Implementation
31 //-----------------------------------------------------------------
32 
33 EvtGenInputModule::EvtGenInputModule() : GeneratorBaseModule(),
34  m_initial(BeamParameters::c_smearALL)
35 {
36  //Set module properties
37  setDescription("EvtGenInput module. The module is served as an interface for EvtGen Event Generator so that the EvtGen generator can store the generated particles into MCParticles. The users need to provide their own decay mode based on the standard DECAY.DEC.");
39 
40  //Parameter definition
41  addParam("userDECFile", m_userDECFileName, "user DECfile name", string(""));
42  addParam("DECFile", m_DECFileName, "global DECfile to be used",
43  FileSystem::findFile("decfiles/dec/DECAY_BELLE2.DEC", true));
44  addParam("ParentParticle", m_parentParticle, "Parent Particle Name", string("Upsilon(4S)"));
45  addParam("InclusiveType", m_inclusiveType, "inclusive decay type (0: generic, 1: inclusive, 2: inclusive (charge conjugate)", 0);
46  addParam("CoherentMixing", m_coherentMixing, "decay the neutral B meson pairs coherently or non-coherently", true);
47  addParam("InclusiveParticle", m_inclusiveParticle, "Inclusive Particle Name", string(""));
48  addParam("maxTries", m_maxTries, "Number of tries to generate a parent "
49  "particle from the beam energies which fits inside the mass window "
50  "before giving up", 100000);
51 }
52 
53 
55 {
56  StoreArray<MCParticle> mcparticle;
57  mcparticle.registerInDataStore();
58  generators::checkEvtGenDecayFile(m_DECFileName);
59  // Initial particle for beam parameters.
61 }
62 
63 
65 {
66 
67 }
68 
70 {
71  // try to generate the 4 momentum a m_maxTries amount of times before we give up
72  for (int i = 0; i < m_maxTries; ++i) {
73  const MCInitialParticles& initial = m_initial.generate();
74 
75  // check if we fullfill the mass window
76  if (initial.getMass() >= minMass && initial.getMass() < maxMass) {
77  return initial;
78  }
79  }
80 
81  //Apparently the beam energies don't match the particle mass we want to generate
82  B2FATAL("Could not create parent particle within mass window: "
83  << "minMass=" << minMass << " GeV, "
84  << "maxMass=" << maxMass << " GeV");
85 
86  //This will never be reached, only used to avoid warning
87  return m_initial.generate();
88 }
89 
90 
91 // Add colliding electron/positron to the event graph
92 static void addInitialParticle(MCParticleGraph& mpg, int pdg, ROOT::Math::PxPyPzEVector p4)
93 {
95 
97  part.setMass(Const::electronMass);
98  part.setPDG(pdg);
99 
100  part.set4Vector(p4);
101 
102  part.setProductionVertex(0, 0, 0);
103  part.setProductionTime(0);
104  part.setValidVertex(false);
105 }
106 
107 
108 
109 
110 
112 {
113  B2DEBUG(10, "Starting event generation");
114 
115  // Check if the BeamParameters have changed (if they do, abort the job! otherwise cross section calculation will be a nightmare.)
116  if (m_beamParams.hasChanged()) {
117  if (!m_initialized) {
119  } else {
120  B2FATAL("EvtGenInputModule::event(): BeamParameters have changed within a job, this is not supported for EvtGen!");
121  }
122  }
123 
124  MCInitialParticles initial;
125 
126  //Initialize the beam energy for each event separatly
127  if (EvtPDL::getStdHep(m_parentId) == 10022) {
128  //virtual photon (vpho), no mass window, we accept everything
129  initial = createBeamParticle();
130  } else {
131  //everything else needs to be in the mass window
132  initial = createBeamParticle(EvtPDL::getMinMass(m_parentId),
133  EvtPDL::getMaxMass(m_parentId));
134  }
135 
136  ROOT::Math::PxPyPzEVector pParentParticle = initial.getLER() + initial.getHER();
137  ROOT::Math::XYZVector primaryVertex = initial.getVertex();
138 
139  //end initialization
140 
141  //clear existing MCParticles
142  mpg.clear();
143 
144  // add colliding electron & positron to the event list
145  addInitialParticle(mpg, 11, initial.getHER());
146  addInitialParticle(mpg, -11, initial.getLER());
147 
148  //generate event.
149  int nPart = m_Ievtgen.simulateEvent(mpg, pParentParticle, primaryVertex,
151 
152  B2DEBUG(10, "EvtGen: generated event with " << nPart << " particles.");
153 }
154 
156 {
157 
158  //setup the DECAY files:
160 
161  if (m_inclusiveType == 0) m_inclusiveParticle = "";
162  if (m_inclusiveType != 0 && EvtPDL::getId(m_inclusiveParticle).getId() == -1) {
163  B2ERROR("User Specified Inclusive Particle '" << m_inclusiveParticle
164  << "' does not exist");
165  }
166  m_parentId = EvtPDL::getId(m_parentParticle);
167  if (m_parentId.getId() == -1) {
168  B2ERROR("User specified parent particle '" << m_parentParticle
169  << "' does not exist");
170  }
171 
172  m_initialized = true;
173 
174 }
This class contains the nominal beam parameters and the parameters used for smearing of the primary v...
static const double electronMass
electron mass
Definition: Const.h:676
std::string m_parentParticle
Standard input parent particle.
EvtGenInterface m_Ievtgen
An instance of the EvtGen Interface.
bool m_coherentMixing
Decay the B's in coherent or incoherent mode.
DBObjPtr< BeamParameters > m_beamParams
BeamParameter.
bool m_initialized
True if generator has been initialized.
std::string m_userDECFileName
Standard input user decay file.
MCInitialParticles createBeamParticle(double minMass=0.0, double maxMass=std::numeric_limits< double >::infinity())
Create a "beam particle" from LER and HER direction, energy and energy spread and make sure it's insi...
int m_maxTries
Maximum number of tries for generating the parent particle.
virtual void generatorInitialize() override
Initializes the module.
std::string m_DECFileName
Standard input decay file.
virtual void beginRun() override
Method is called for each run.
std::string m_inclusiveParticle
inclusive Particle
int m_inclusiveType
Inclusive type 0 : generic, 1 : m_inclusiveParticle inclusive, 2 : m_inclusiveParticle + c....
InitialParticleGeneration m_initial
initial particle used by BeamParameter class
MCParticleGraph mpg
An instance of the MCParticle graph.
EvtId m_parentId
EvtGen Id of the parent particle we want to generate.
void initializeGenerator()
Method is called to initialize the generator.
virtual void generatorEvent() override
Method is called for each event.
int simulateEvent(MCParticleGraph &graph, ROOT::Math::PxPyPzEVector pParentParticle, ROOT::Math::XYZVector pPrimaryVertex, int inclusiveType, const std::string &inclusiveParticle)
Generate a single event.
int setup(const std::string &decayFileName, const std::string &parentParticle, const std::string &userFileName=std::string(""), bool coherentMixing=true)
Setup evtgen with the given decay files
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.
This class contains the initial state for the given event.
const ROOT::Math::PxPyPzEVector & getLER() const
Get 4vector of the low energy beam.
const ROOT::Math::PxPyPzEVector & getHER() const
Get 4vector of the high energy beam.
const ROOT::Math::XYZVector & getVertex() const
Get the position of the collision.
double getMass() const
Get the invariant mass of the collision (= energy in CMS)
Class to represent Particle data in graph.
Class to build, validate and sort a particle decay chain.
@ c_Initial
bit 5: Particle is initial such as e+ or e- and not going to Geant4
Definition: MCParticle.h:57
@ c_PrimaryParticle
bit 0: Particle is primary particle.
Definition: MCParticle.h:47
@ c_StableInGenerator
bit 1: Particle is stable, i.e., not decaying in the generator.
Definition: MCParticle.h:49
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.
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.
GraphParticle & addParticle()
Add new particle to the graph.
Abstract base class for different kinds of events.