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