Belle II Software development
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
21using namespace std;
22using namespace Belle2;
23
24//-----------------------------------------------------------------
25// Register the Module
26//-----------------------------------------------------------------
27REG_MODULE(EvtGenInput);
28
29//-----------------------------------------------------------------
30// Implementation
31//-----------------------------------------------------------------
32
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 (minMass <= initial.getMass() && initial.getMass() < maxMass)
77 return initial;
78 }
79
80 //Apparently the beam energies don't match the particle mass we want to generate
81 B2FATAL("Could not create parent particle within mass window: "
82 << "minMass=" << minMass << " GeV, "
83 << "maxMass=" << maxMass << " GeV");
84
85 //This will never be reached so return empty to avoid warning
86 return MCInitialParticles();
87}
88
89
90
91
92
94{
95 B2DEBUG(10, "Starting event generation");
96
97 // Check if the BeamParameters have changed (if they do, abort the job! otherwise cross section calculation will be a nightmare.)
98 if (m_beamParams.hasChanged()) {
99 if (!m_initialized) {
101 } else {
102 B2FATAL("EvtGenInputModule::event(): BeamParameters have changed within a job, this is not supported for EvtGen!");
103 }
104 }
105
106 MCInitialParticles initial;
107
108 //Initialize the beam energy for each event separatly
109 if (EvtPDL::getStdHep(m_parentId) == 10022) {
110 //virtual photon (vpho), no mass window, we accept everything
111 initial = createBeamParticle();
112 } else {
113 //everything else needs to be in the mass window
114 initial = createBeamParticle(EvtPDL::getMinMass(m_parentId),
115 EvtPDL::getMaxMass(m_parentId));
116 }
117
118 //end initialization
119
120
121 //generate event.
123
124 B2DEBUG(10, "EvtGen: generated event with " << nPart << " particles.");
125}
126
128{
129
130 //setup the DECAY files:
132
134 if (m_inclusiveType != 0 && EvtPDL::getId(m_inclusiveParticle).getId() == -1) {
135 B2ERROR("User Specified Inclusive Particle '" << m_inclusiveParticle
136 << "' does not exist");
137 }
138 m_parentId = EvtPDL::getId(m_parentParticle);
139 if (m_parentId.getId() == -1) {
140 B2ERROR("User specified parent particle '" << m_parentParticle
141 << "' does not exist");
142 }
143
144 m_initialized = true;
145
146}
This class contains the nominal beam parameters and the parameters used for smearing of the primary v...
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
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(MCInitialParticles initial, 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:151
The base module for generator modules, which sets the generator information as EventExtraInfo.
This class contains the initial state for the given event.
double getMass() const
Get the invariant mass of the collision (= energy in CMS)
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 initialize()
function to be executed on initialize()
MCInitialParticles & generate()
Generate a new event.
Abstract base class for different kinds of events.
STL namespace.