9 #include <generators/kkmc/KKGenInterface.h>
10 #include <generators/modules/kkgeninput/KKGenInputModule.h>
11 #include <mdst/dataobjects/MCParticleGraph.h>
12 #include <framework/utilities/FileSystem.h>
14 #include <framework/datastore/DataStore.h>
15 #include <framework/datastore/StoreArray.h>
16 #include <framework/dataobjects/EventMetaData.h>
17 #include <framework/datastore/StoreObjPtr.h>
19 #include <framework/logging/Logger.h>
20 #include <framework/utilities/IOIntercept.h>
22 #include <boost/filesystem.hpp>
41 setDescription(
"KKGenInput module. This an interface for KK2f Event Generator for basf2. The generated events are stored into MCParticles. You can find an expample of its decay file (tau_decaytable.dat) for tau-pair events at ${BELLE2_RELEASE_DIR}/data/generators/kkmc. On the other hand, when you like to generate mu-pair events, ${BELLE2_RELEASE_DIR}/data/generators/kkmc/mu.input.dat should be set to tauinputFile in your steering file.");
45 addParam(
"KKdefaultFile", m_KKdefaultFileName,
"default KKMC setting filename",
46 FileSystem::findFile(
"/data/generators/kkmc/KK2f_defaults.dat"));
47 addParam(
"tauinputFile", m_tauinputFileName,
"user-defined tau/mu/q-pairs generation setting",
48 FileSystem::findFile(
"/data/generators/kkmc/KK2f_defaults.dat"));
49 addParam(
"taudecaytableFile", m_taudecaytableFileName,
"tau-decay-table file name",
50 FileSystem::findFile(
"/data/generators/kkmc/tau.input.dat"));
51 addParam(
"kkmcoutputfilename", m_KKMCOutputFileName,
"KKMC output filename",
string(
""));
55 void KKGenInputModule::initialize()
62 m_initial.initialize();
66 void KKGenInputModule::beginRun()
71 void KKGenInputModule::event()
75 if (m_beamParams.hasChanged()) {
77 initializeGenerator();
79 B2FATAL(
"KKGenInputModule::event(): BeamParameters have changed within a job, this is not supported for KKMC!");
90 int nPart = m_Ikkgen.simulateEvent(mpg, vertex);
93 for (
int i = 0; i < nPart; ++i) {
97 sprintf(buf,
"IntC: %3d %4u %8d %4d %4d %4d %9.4f %9.4f %9.4f %9.4f",
98 p->getIndex(), p->getStatus(), p->getPDG(), moID,
99 p->getFirstDaughter(), p->getLastDaughter(),
100 p->get4Vector().Px(), p->get4Vector().Py(),
101 p->get4Vector().Pz(), p->get4Vector().E());
105 B2DEBUG(150,
"Generated event " << eventMetaDataPtr->getEvent() <<
" with " << nPart <<
" particles.");
108 void KKGenInputModule::terminate()
114 void KKGenInputModule::initializeGenerator()
118 if (m_KKMCOutputFileName.empty()) {
119 m_KKMCOutputFileName = boost::filesystem::unique_path(
"KKMC-%%%%%%%%%%.txt").native();
120 B2DEBUG(150,
"Using KKMC output file " << m_KKMCOutputFileName);
122 if (FileSystem::fileExists(m_KKMCOutputFileName)) {
123 auto uniqueOutputFileName = boost::filesystem::unique_path(m_KKMCOutputFileName +
"-%%%%%%%%%%").native();
124 B2WARNING(
"The KKMC output file " << m_KKMCOutputFileName <<
" already exists. Using " << uniqueOutputFileName <<
" instead.");
125 m_KKMCOutputFileName = uniqueOutputFileName;
127 fp = fopen(m_KKMCOutputFileName.c_str(),
"w");
130 remove(m_KKMCOutputFileName.c_str());
132 B2FATAL(
"KKGenInputModule::initializeGenerator(): Failed to open KKMC output file!");
135 B2DEBUG(150,
"m_KKdefaultFileName: " << m_KKdefaultFileName);
136 B2DEBUG(150,
"m_tauinputFileName: " << m_tauinputFileName);
137 B2DEBUG(150,
"m_taudecaytableFileName: " << m_taudecaytableFileName);
138 B2DEBUG(150,
"m_KKMCOutputFileName: " << m_KKMCOutputFileName);
141 if (!m_tauinputFileName.empty() && !FileSystem::fileExists(m_tauinputFileName)) {
142 B2FATAL(
"KKGenInputModule::initializeGenerator(): " << m_tauinputFileName <<
" not found!");
144 if (!m_taudecaytableFileName.empty() && !FileSystem::fileExists(m_taudecaytableFileName)) {
145 B2FATAL(
"KKGenInputModule::initializeGenerator(): " << m_taudecaytableFileName <<
" not found!");
149 initLogCapture.
start();
150 m_Ikkgen.setup(m_KKdefaultFileName, m_tauinputFileName,
151 m_taudecaytableFileName, m_KKMCOutputFileName);
154 TLorentzVector v_ler = initial.
getLER();
155 TLorentzVector v_her = initial.
getHER();
158 m_Ikkgen.set_beam_info(v_ler, 0.0, v_her, 0.0);
161 m_initialized =
true;
163 B2DEBUG(150,
"KKGenInputModule::initializeGenerator(): Finished initialising the KKGen Input Module. ");
This class contains the nominal beam parameters and the parameters used for smearing of the primary v...
bool start()
Start intercepting the output.
Capture stdout and stderr and convert into log messages.
bool finish()
Finish the capture and emit the message if output has appeard on stdout or stderr.
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.
Class to represent Particle data in graph.
bool registerInDataStore(DataStore::EStoreFlags storeFlags=DataStore::c_WriteOut)
Register the object/array in the DataStore.
Type-safe access to single objects in the data store.
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Abstract base class for different kinds of events.