diff --git a/MC/config/ALICE3/ini/ditto_pp_136tev.ini b/MC/config/ALICE3/ini/ditto_pp_136tev.ini new file mode 100644 index 000000000..e44eb26f7 --- /dev/null +++ b/MC/config/ALICE3/ini/ditto_pp_136tev.ini @@ -0,0 +1,3 @@ +[GeneratorExternal] +fileName=${O2DPG_MC_CONFIG_ROOT}/MC/config/ALICE3/pythia8/generator_DittoMC.C +funcName=generator_DittoMC("https://github.com/njacazio/DittoMC/releases/download/v1.0.0/Ditto_tune_pythia8_inel_136tev.root") diff --git a/MC/config/ALICE3/ini/tests/ditto_pp_136tev.C b/MC/config/ALICE3/ini/tests/ditto_pp_136tev.C new file mode 120000 index 000000000..4103e578f --- /dev/null +++ b/MC/config/ALICE3/ini/tests/ditto_pp_136tev.C @@ -0,0 +1 @@ +pythia8_pp_ropes.C \ No newline at end of file diff --git a/MC/config/ALICE3/pythia8/generator_DittoMC.C b/MC/config/ALICE3/pythia8/generator_DittoMC.C new file mode 100644 index 000000000..27fd8b66d --- /dev/null +++ b/MC/config/ALICE3/pythia8/generator_DittoMC.C @@ -0,0 +1,64 @@ +#include +#include + +#include + +#include +#include +#include +#include + +// Ditto event generator +class GeneratorDittoMC : public o2::eventgen::GeneratorPythia8 +{ + public: + /// Constructor + explicit GeneratorDittoMC(const TString& tuneFile) : mGenerator(makeConfig(tuneFile)) + { + // We use the Pythia8 event only as the container passed to the O2 + // GeneratorPythia8 machinery. Particle production is handled by Ditto. + mPythia.readString("ProcessLevel:all = off"); + } + + /// Generate one Ditto event and export it to the Pythia8 event record. + bool generateEvent() override + { + mGenerator.generate(); + mGenerator.loadParticles(mPythia.event, true); + return true; + } + + /// Destructor + ~GeneratorDittoMC() override = default; + + private: + /// Build the Ditto runtime configuration. + static Ditto::Config makeConfig(const TString& tuneFile) + { + if (tuneFile.IsNull()) { + throw std::runtime_error("Ditto tune file must be specified"); + } + + Ditto::Config config; + config.mTuneFile = tuneFile.Data(); + + // Use the Grid process ID as the Ditto seed when available. + // Outside the Grid, seed 0 is used. + if (const char* alienProcId = std::getenv("ALIEN_PROC_ID")) { + config.mSeed = static_cast(std::strtoull(alienProcId, nullptr, 10)); + } else { + config.mSeed = static_cast(std::time(nullptr)); + } + + Printf("Using Ditto tune: %s and seed: %llu", config.mTuneFile.c_str(), static_cast(config.mSeed)); + + return config; + } + + Ditto::Generator mGenerator; +}; + +FairGenerator* generator_DittoMC(const TString& tuneFile) +{ + return new GeneratorDittoMC(tuneFile); +}