Belle II Software  release-06-02-00
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 #include <generators/modules/evtgeninput/EvtGenInputModule.h>
10 #include <generators/evtgen/EvtGenInterface.h>
11 #include <mdst/dataobjects/MCParticleGraph.h>
12 #include <framework/utilities/FileSystem.h>
13 
14 #include <framework/datastore/StoreArray.h>
15 
16 using namespace std;
17 using namespace Belle2;
18 
19 //-----------------------------------------------------------------
20 // Register the Module
21 //-----------------------------------------------------------------
22 REG_MODULE(EvtGenInput)
23 
24 //-----------------------------------------------------------------
25 // Implementation
26 //-----------------------------------------------------------------
27 
29  m_initial(BeamParameters::c_smearALL)
30 {
31  //Set module properties
32  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.");
33  setPropertyFlags(c_Input);
34 
35  //Parameter definition
36  addParam("userDECFile", m_userDECFileName, "user DECfile name", string(""));
37  addParam("DECFile", m_DECFileName, "global DECfile to be used",
38  FileSystem::findFile("decfiles/dec/DECAY_BELLE2.DEC", true));
39  addParam("ParentParticle", m_parentParticle, "Parent Particle Name", string("Upsilon(4S)"));
40  addParam("InclusiveType", m_inclusiveType, "inclusive decay type (0: generic, 1: inclusive, 2: inclusive (charge conjugate)", 0);
41  addParam("CoherentMixing", m_coherentMixing, "decay the neutral B meson pairs coherently or non-coherently", true);
42  addParam("InclusiveParticle", m_inclusiveParticle, "Inclusive Particle Name", string(""));
43  addParam("maxTries", m_maxTries, "Number of tries to generate a parent "
44  "particle from the beam energies which fits inside the mass window "
45  "before giving up", 100000);
46 
47  m_PrimaryVertex = TVector3(0., 0., 0.);
48 
49 }
50 
51 
52 void EvtGenInputModule::initialize()
53 {
54  const std::string defaultDecFile = FileSystem::findFile("decfiles/dec/DECAY_BELLE2.DEC", true);
55  if (m_DECFileName.empty()) {
56  B2ERROR("No global decay file defined, please make sure the parameter 'DECFile' is set correctly");
57  return;
58  }
59  if (defaultDecFile.empty()) {
60  B2WARNING("Cannot find default decay file");
61  } else if (defaultDecFile != m_DECFileName) {
62  B2INFO("Using non-standard DECAY file \"" << m_DECFileName << "\"");
63  }
64  //Initialize MCParticle collection
65  StoreArray<MCParticle> mcparticle;
66  mcparticle.registerInDataStore();
67 
68  //initial particle for beam parameters
69  m_initial.initialize();
70 
71 }
72 
73 
74 void EvtGenInputModule::beginRun()
75 {
76 
77 }
78 
79 TLorentzVector EvtGenInputModule::createBeamParticle(double minMass, double maxMass)
80 {
81  // try to generate the 4 momentum a m_maxTries amount of times before we give up
82  for (int i = 0; i < m_maxTries; ++i) {
83  const MCInitialParticles& initial = m_initial.generate();
84 
85  // check if we fullfill the mass window
86  if (initial.getMass() >= minMass && initial.getMass() < maxMass) {
87 
88  TLorentzVector beam = initial.getLER() + initial.getHER();
89  m_PrimaryVertex = initial.getVertex();
90  return beam;
91  }
92  }
93 
94  //Apparently the beam energies don't match the particle mass we want to generate
95  B2FATAL("Could not create parent particle within mass window: "
96  << "minMass=" << minMass << " GeV, "
97  << "maxMass=" << maxMass << " GeV");
98 
99  //This will never be reached so return empty to avoid warning
100  return TLorentzVector(0, 0, 0, 0);
101 }
102 
103 void EvtGenInputModule::event()
104 {
105  B2DEBUG(10, "Starting event generation");
106 
107  // Check if the BeamParameters have changed (if they do, abort the job! otherwise cross section calculation will be a nightmare.)
108  if (m_beamParams.hasChanged()) {
109  if (!m_initialized) {
110  initializeGenerator();
111  } else {
112  B2FATAL("EvtGenInputModule::event(): BeamParameters have changed within a job, this is not supported for EvtGen!");
113  }
114  }
115 
116  TLorentzVector pParentParticle;
117 
118  //Initialize the beam energy for each event separatly
119  if (EvtPDL::getStdHep(m_parentId) == 10022) {
120  //virtual photon (vpho), no mass window, we accept everything
121  pParentParticle = createBeamParticle();
122  } else {
123  //everything else needs to be in the mass window
124  pParentParticle = createBeamParticle(EvtPDL::getMinMass(m_parentId),
125  EvtPDL::getMaxMass(m_parentId));
126  }
127  //end initialization
128 
129  //clear existing MCParticles
130  mpg.clear();
131 
132  //generate event.
133  int nPart = m_Ievtgen.simulateEvent(mpg, pParentParticle, m_PrimaryVertex,
134  m_inclusiveType, m_inclusiveParticle);
135 
136  B2DEBUG(10, "EvtGen: generated event with " << nPart << " particles.");
137 }
138 
139 void EvtGenInputModule::initializeGenerator()
140 {
141 
142  //setup the DECAY files:
143  m_Ievtgen.setup(m_DECFileName, m_parentParticle, m_userDECFileName, m_coherentMixing);
144 
145  if (m_inclusiveType == 0) m_inclusiveParticle = "";
146  if (m_inclusiveType != 0 && EvtPDL::getId(m_inclusiveParticle).getId() == -1) {
147  B2ERROR("User Specified Inclusive Particle '" << m_inclusiveParticle
148  << "' does not exist");
149  }
150  m_parentId = EvtPDL::getId(m_parentParticle);
151  if (m_parentId.getId() == -1) {
152  B2ERROR("User specified parent particle '" << m_parentParticle
153  << "' does not exist");
154  }
155 
156  m_initialized = true;
157 
158 }
This class contains the nominal beam parameters and the parameters used for smearing of the primary v...
The EvtGenInput module.
This class contains the initial state for the given event.
const TLorentzVector & getLER() const
Get 4vector of the low energy beam.
const TVector3 & getVertex() const
Get the position of the collision.
const TLorentzVector & getHER() const
Get 4vector of the high energy beam.
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
@ c_Input
Input Process.
Abstract base class for different kinds of events.