11 #include <generators/kkmc/KKGenInterface.h>
12 #include <generators/modules/kkgeninput/KKGenInputModule.h>
13 #include <mdst/dataobjects/MCParticleGraph.h>
14 #include <framework/utilities/FileSystem.h>
16 #include <framework/datastore/DataStore.h>
17 #include <framework/datastore/StoreArray.h>
18 #include <framework/dataobjects/EventMetaData.h>
19 #include <framework/datastore/StoreObjPtr.h>
21 #include <framework/logging/Logger.h>
22 #include <framework/utilities/IOIntercept.h>
24 #include <boost/filesystem.hpp>
43 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.");
47 addParam(
"KKdefaultFile", m_KKdefaultFileName,
"default KKMC setting filename",
48 FileSystem::findFile(
"/data/generators/kkmc/KK2f_defaults.dat"));
49 addParam(
"tauinputFile", m_tauinputFileName,
"user-defined tau/mu/q-pairs generation setting",
50 FileSystem::findFile(
"/data/generators/kkmc/KK2f_defaults.dat"));
51 addParam(
"taudecaytableFile", m_taudecaytableFileName,
"tau-decay-table file name",
52 FileSystem::findFile(
"/data/generators/kkmc/tau.input.dat"));
53 addParam(
"kkmcoutputfilename", m_KKMCOutputFileName,
"KKMC output filename",
string(
""));
57 void KKGenInputModule::initialize()
61 mcparticle.registerInDataStore();
64 m_initial.initialize();
68 void KKGenInputModule::beginRun()
73 void KKGenInputModule::event()
77 if (m_beamParams.hasChanged()) {
79 initializeGenerator();
81 B2FATAL(
"KKGenInputModule::event(): BeamParameters have changed within a job, this is not supported for KKMC!");
92 int nPart = m_Ikkgen.simulateEvent(mpg, vertex);
95 for (
int i = 0; i < nPart; ++i) {
99 sprintf(buf,
"IntC: %3d %4u %8d %4d %4d %4d %9.4f %9.4f %9.4f %9.4f",
100 p->getIndex(), p->getStatus(), p->getPDG(), moID,
101 p->getFirstDaughter(), p->getLastDaughter(),
102 p->get4Vector().Px(), p->get4Vector().Py(),
103 p->get4Vector().Pz(), p->get4Vector().E());
107 B2DEBUG(150,
"Generated event " << eventMetaDataPtr->getEvent() <<
" with " << nPart <<
" particles.");
110 void KKGenInputModule::terminate()
116 void KKGenInputModule::initializeGenerator()
120 if (m_KKMCOutputFileName.empty()) {
121 m_KKMCOutputFileName = boost::filesystem::unique_path(
"KKMC-%%%%%%%%%%.txt").native();
122 B2DEBUG(150,
"Using KKMC output file " << m_KKMCOutputFileName);
124 if (FileSystem::fileExists(m_KKMCOutputFileName)) {
125 auto uniqueOutputFileName = boost::filesystem::unique_path(m_KKMCOutputFileName +
"-%%%%%%%%%%").native();
126 B2WARNING(
"The KKMC output file " << m_KKMCOutputFileName <<
" already exists. Using " << uniqueOutputFileName <<
" instead.");
127 m_KKMCOutputFileName = uniqueOutputFileName;
129 fp = fopen(m_KKMCOutputFileName.c_str(),
"w");
132 remove(m_KKMCOutputFileName.c_str());
134 B2FATAL(
"KKGenInputModule::initializeGenerator(): Failed to open KKMC output file!");
137 B2DEBUG(150,
"m_KKdefaultFileName: " << m_KKdefaultFileName);
138 B2DEBUG(150,
"m_tauinputFileName: " << m_tauinputFileName);
139 B2DEBUG(150,
"m_taudecaytableFileName: " << m_taudecaytableFileName);
140 B2DEBUG(150,
"m_KKMCOutputFileName: " << m_KKMCOutputFileName);
143 if (!m_tauinputFileName.empty() && !FileSystem::fileExists(m_tauinputFileName)) {
144 B2FATAL(
"KKGenInputModule::initializeGenerator(): " << m_tauinputFileName <<
" not found!");
146 if (!m_taudecaytableFileName.empty() && !FileSystem::fileExists(m_taudecaytableFileName)) {
147 B2FATAL(
"KKGenInputModule::initializeGenerator(): " << m_taudecaytableFileName <<
" not found!");
151 initLogCapture.
start();
152 m_Ikkgen.setup(m_KKdefaultFileName, m_tauinputFileName,
153 m_taudecaytableFileName, m_KKMCOutputFileName);
156 TLorentzVector v_ler = initial.
getLER();
157 TLorentzVector v_her = initial.
getHER();
160 m_Ikkgen.set_beam_info(v_ler, 0.0, v_her, 0.0);
163 m_initialized =
true;
165 B2DEBUG(150,
"KKGenInputModule::initializeGenerator(): Finished initialising the KKGen Input Module. ");