Belle II Software  release-06-00-14
EvtGenDecayModule.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 /* External headers. */
10 #include <EvtGenBase/EvtPDL.hh>
11 #include <EvtGenBase/EvtDecayTable.hh>
12 
13 /* Belle 2 headers. */
14 #include <framework/datastore/StoreArray.h>
15 #include <framework/utilities/FileSystem.h>
16 #include <generators/modules/evtgendecay/EvtGenDecayModule.h>
17 
18 using namespace Belle2;
19 
20 REG_MODULE(EvtGenDecay)
21 
23 {
24  setDescription("This module decays unstable particles using EvtGen. The "
25  "event should be already generated by another generator. "
26  "If you need to generate full event with EvtGen, then use "
27  "the module 'EvtGenInput'.");
28  addParam("DecFile", m_DecFile, "EvtGen decay file (DECAY.DEC)",
30  "decfiles/dec/DECAY_BELLE2.DEC", true));
31  addParam("UserDecFile", m_UserDecFile, "User EvtGen decay file",
32  std::string(""));
33  addParam("MCParticleColName", m_MCParticleColName,
34  "MCParticle collection name.", std::string(""));
35  m_Initialized = false;
36 }
37 
39 {
40 }
41 
43 {
45  mcParticles.isRequired();
46  const std::string defaultDecFile =
47  FileSystem::findFile("decfiles/dec/DECAY_BELLE2.DEC", true);
48  if (m_DecFile.empty()) {
49  B2ERROR("No global decay file defined, please make sure "
50  "the parameter 'DecFile' is set correctly.");
51  return;
52  }
53  if (defaultDecFile.empty()) {
54  B2WARNING("Cannot find default decay file");
55  } else if (defaultDecFile != m_DecFile) {
56  B2INFO("Using non-standard DECAY file \"" << m_DecFile << "\"");
57  }
58 }
59 
61 {
62 }
63 
65 {
66  int i, n;
67  if (m_BeamParameters.hasChanged()) {
68  if (!m_Initialized) {
70  } else {
71  B2FATAL("EvtGenDecayModule::event(): BeamParameters have changed within "
72  "a job, this is not supported for EvtGen!");
73  }
74  }
75  m_Graph.clear();
77  n = m_Graph.size();
78  for (i = 0; i < n; i++) {
79  bool decay = true;
80  MCParticleGraph::GraphParticle* graphParticle = &m_Graph[i];
81 
82  if (graphParticle->isInitial())
83  decay = false;
84  else if (graphParticle->getNDaughters() > 0)
85  decay = false;
86  else if (m_DecayableParticles.find(graphParticle->getPDG()) ==
88  decay = false;
89  if (decay)
90  m_EvtGenInterface.simulateDecay(m_Graph, *graphParticle);
91  }
96 }
97 
99 {
100 }
101 
103 {
104 }
105 
107 {
108  int i, n;
109  EvtId id;
110  EvtDecayTable* decayTable;
112  decayTable = EvtDecayTable::getInstance();
113  n = EvtPDL::entries();
114  for (i = 0; i < n; i++) {
115  id = EvtPDL::getEntry(i);
116  if (decayTable->getNModes(id) > 0)
117  m_DecayableParticles.insert(EvtPDL::getStdHep(id));
118  }
119 }
120 
This module decays unstable particles using EvtGen.
virtual void initialize() override
Initialization.
virtual void event() override
This method is called for each event.
virtual void endRun() override
This method is called if the current run ends.
virtual void terminate() override
This method is called at the end of the event processing.
bool m_Initialized
Whether the generator is initialized or not.
std::string m_DecFile
Decay file.
virtual void beginRun() override
This method is called when entering a new run.
DBObjPtr< BeamParameters > m_BeamParameters
Beam parameters.
std::string m_UserDecFile
User decay file.
MCParticleGraph m_Graph
MCParticle graph.
std::string m_MCParticleColName
MCParticle collection name.
EvtGenInterface m_EvtGenInterface
Evtgen interface.
std::set< int > m_DecayableParticles
Monte-Carlo codes of particles that can be decayed by EvtGen.
virtual ~EvtGenDecayModule()
Destructor.
void initializeGenerator()
Generator initialization.
int simulateDecay(MCParticleGraph &graph, MCParticleGraph::GraphParticle &parent)
Simulate a particle decay.
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:145
Class to represent Particle data in graph.
@ c_checkCyclic
Check for cyclic dependencies.
@ c_clearParticles
Clear the particle list before adding the graph.
@ c_setDecayInfo
Set decay time and vertex.
size_t size() const
Return the number of particles in the graph.
void loadList(const std::string &name="")
Load the MCParticle list given by name into the Graph.
void generateList(const std::string &name="", int options=c_setNothing)
Generates the MCParticle list and stores it in the StoreArray with the given name.
int getNDaughters() const
Return number of daughter MCParticles.
Definition: MCParticle.cc:65
int getPDG() const
Return PDG code of particle.
Definition: MCParticle.h:112
Base class for Modules.
Definition: Module.h:72
bool isRequired(const std::string &name="")
Ensure this array/object has been registered previously.
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:650
bool isInitial() const
Check if particle is an initial particle such as ISR.
Definition: MCParticle.h:572
void clear()
Reset particles and decay information to make the class reusable.
Abstract base class for different kinds of events.