|
1 | | -#include "Ditto.h" |
2 | | - |
3 | | -#include <algorithm> |
4 | | -#include <cstdint> |
5 | | -#include <cstdlib> |
6 | | -#include <stdexcept> |
7 | | - |
8 | | -#if !defined(__CLING__) || defined(__ROOTCLING__) |
9 | | - |
10 | | -#include <SimulationDataFormat/MCGenProperties.h> |
11 | | - |
| 1 | +#include <Ditto/Ditto.h> |
12 | 2 | #include <Generators/GeneratorPythia8.h> |
13 | | -#include <Pythia8/Pythia.h> |
14 | 3 |
|
15 | 4 | #include <FairGenerator.h> |
16 | | -#include <FairPrimaryGenerator.h> |
17 | 5 |
|
18 | | -#endif |
| 6 | +#include <cstdint> |
| 7 | +#include <cstdlib> |
| 8 | +#include <stdexcept> |
| 9 | +#include <string> |
19 | 10 |
|
20 | 11 | // Ditto event generator |
21 | | - |
22 | 12 | class GeneratorDittoMC : public o2::eventgen::GeneratorPythia8 |
23 | 13 | { |
24 | 14 | public: |
25 | 15 | /// Constructor |
26 | | - GeneratorDittoMC(const TString& tuneFile) : mGenerator(makeConfig(tuneFile)) |
| 16 | + explicit GeneratorDittoMC(const TString& tuneFile) : mGenerator(makeConfig(tuneFile)) |
27 | 17 | { |
| 18 | + // We use the Pythia8 event only as the container passed to the O2 |
| 19 | + // GeneratorPythia8 machinery. Particle production is handled by Ditto. |
28 | 20 | mPythia.readString("ProcessLevel:all = off"); |
29 | 21 | } |
30 | 22 |
|
| 23 | + /// Generate one Ditto event and export it to the Pythia8 event record. |
31 | 24 | bool generateEvent() override |
32 | 25 | { |
33 | 26 | mGenerator.generate(); |
34 | 27 | mGenerator.loadParticles(mPythia.event, true); |
35 | 28 | return true; |
36 | 29 | } |
37 | 30 |
|
38 | | - /// Destructor |
39 | | - ~GeneratorDittoMC() = default; |
| 31 | + /// Destructor |
| 32 | + ~GeneratorDittoMC() override = default; |
40 | 33 |
|
41 | 34 | private: |
| 35 | + /// Build the Ditto runtime configuration. |
42 | 36 | static Ditto::Config makeConfig(const TString& tuneFile) |
43 | 37 | { |
44 | | - Ditto::Config config; |
45 | 38 | if (tuneFile.IsNull()) { |
46 | | - throw std::runtime_error("DITTO_TUNE_FILE must point to a Ditto tune file"); |
| 39 | + throw std::runtime_error("Ditto tune file must be specified"); |
| 40 | + } |
| 41 | + |
| 42 | + Ditto::Config config; |
| 43 | + config.mTuneFile = tuneFile.Data(); |
| 44 | + |
| 45 | + // Use the Grid process ID as the Ditto seed when available. |
| 46 | + // Outside the Grid, seed 0 is used. |
| 47 | + if (const char* alienProcId = std::getenv("ALIEN_PROC_ID")) { |
| 48 | + config.mSeed = static_cast<std::uint64_t>(std::strtoull(alienProcId, nullptr, 10)); |
| 49 | + } else { |
| 50 | + config.mSeed = static_cast<std::uint64_t>(std::time(nullptr)); |
47 | 51 | } |
48 | | - config.tuneFile = tuneFile; |
49 | 52 |
|
50 | | - const char* alienProcId = std::getenv("ALIEN_PROC_ID"); |
51 | | - config.seed = alienProcId ? static_cast<std::uint64_t>(std::atoll(alienProcId)) : 0; |
52 | | - Printf("Using Ditto tune: %s and seed: %lu\n", config.tuneFile.c_str(), config.seed); |
| 53 | + Printf("Using Ditto tune: %s and seed: %llu", config.mTuneFile.c_str(), static_cast<unsigned long long>(config.mSeed)); |
| 54 | + |
53 | 55 | return config; |
54 | 56 | } |
55 | 57 |
|
|
0 commit comments