|
| 1 | +#if !defined(__CLING__) || defined(__ROOTCLING__) |
| 2 | + |
| 3 | +#include "FairGenerator.h" |
| 4 | +#include "Generators/GeneratorPythia8.h" |
| 5 | +#include "Pythia8/Pythia.h" |
| 6 | +#include "TRandom.h" |
| 7 | +#include "fairlogger/Logger.h" |
| 8 | + |
| 9 | +#include <cmath> |
| 10 | +#include <cstdint> |
| 11 | +#include <string> |
| 12 | + |
| 13 | +#endif // !defined(__CLING__) || defined(__ROOTCLING__) |
| 14 | + |
| 15 | +/// PYTHIA8 event generator with antideuteron injection. |
| 16 | +/// Events are generated until a final-state antiproton within the specified etaMax is found. |
| 17 | +/// The antiproton is then replaced by an antideuteron with twice its momentum. |
| 18 | + |
| 19 | +class GeneratorPythia8AntideuteronInjection |
| 20 | + : public o2::eventgen::GeneratorPythia8 { |
| 21 | + |
| 22 | + public: |
| 23 | + |
| 24 | + GeneratorPythia8AntideuteronInjection(double etaMax = 0.8) |
| 25 | + : o2::eventgen::GeneratorPythia8(), |
| 26 | + mEtaMax(etaMax) {} |
| 27 | + |
| 28 | + ~GeneratorPythia8AntideuteronInjection() override = default; |
| 29 | + |
| 30 | + bool Init() override { |
| 31 | + addSubGenerator(0, "Pythia8 events with antideuterons"); |
| 32 | + return o2::eventgen::GeneratorPythia8::Init(); |
| 33 | + } |
| 34 | + |
| 35 | + protected: |
| 36 | + |
| 37 | + |
| 38 | + bool generateEvent() override { |
| 39 | + constexpr int maxAttempts = 10000; |
| 40 | + for (int attempt = 0; attempt < maxAttempts; ++attempt) { |
| 41 | + if (!GeneratorPythia8::generateEvent()) { |
| 42 | + return false; |
| 43 | + } |
| 44 | + |
| 45 | + if (EventHasAntideuteron(mPythia.event)) { |
| 46 | + LOG(debug) << ">> An antideuteron was formed!"; |
| 47 | + |
| 48 | + notifySubGenerator(0); |
| 49 | + ++mGeneratedEvents; |
| 50 | + |
| 51 | + return true; |
| 52 | + } |
| 53 | + } |
| 54 | + |
| 55 | + LOG(error) << "Failed to generate an antideuteron after " << maxAttempts << " attempts"; |
| 56 | + return false; |
| 57 | + } |
| 58 | + |
| 59 | + bool EventHasAntideuteron(Pythia8::Event& event) { |
| 60 | + |
| 61 | + const double md = 1.87561294257; // Deuteron mass in GeV/c^2 |
| 62 | + const int pdgAntid = -1000010020; // Antideuteron PDG code |
| 63 | + |
| 64 | + for (int iPart = 0; iPart < event.size(); ++iPart) { |
| 65 | + |
| 66 | + if (!event[iPart].isFinal()) { |
| 67 | + continue; |
| 68 | + } |
| 69 | + |
| 70 | + if (std::abs(event[iPart].eta()) > mEtaMax) { |
| 71 | + continue; |
| 72 | + } |
| 73 | + |
| 74 | + if (event[iPart].id() != -2212) { |
| 75 | + continue; |
| 76 | + } |
| 77 | + |
| 78 | + double px = 2.0 * event[iPart].px(); |
| 79 | + double py = 2.0 * event[iPart].py(); |
| 80 | + double pz = 2.0 * event[iPart].pz(); |
| 81 | + double energy = std::sqrt(md * md + px * px + py * py + pz * pz); |
| 82 | + |
| 83 | + // Remove antiproton from final state |
| 84 | + event[iPart].statusNeg(); |
| 85 | + |
| 86 | + // Add antideuteron |
| 87 | + const int iAntid = event.size(); |
| 88 | + event.append(pdgAntid, 121, iPart, 0, 0, 0, 0, 0, px, py, pz, energy, md); |
| 89 | + // Update daughter indices |
| 90 | + event[iPart].daughter1(iAntid); |
| 91 | + event[iPart].daughter2(iAntid); |
| 92 | + return true; |
| 93 | + } |
| 94 | + return false; |
| 95 | + } |
| 96 | + |
| 97 | + private: |
| 98 | + |
| 99 | + double mEtaMax = 0.8; |
| 100 | + uint64_t mGeneratedEvents = 0; |
| 101 | +}; |
| 102 | + |
| 103 | +/// Generator factory |
| 104 | + |
| 105 | +FairGenerator* generateAntideuterons(double etaMax = 0.8) { |
| 106 | + |
| 107 | + auto* myGenerator = new GeneratorPythia8AntideuteronInjection(etaMax); |
| 108 | + auto seed = gRandom->TRandom::GetSeed() % 900000000; |
| 109 | + |
| 110 | + myGenerator->readString("Random:setSeed = on"); |
| 111 | + myGenerator->readString("Random:seed = " + std::to_string(seed)); |
| 112 | + |
| 113 | + return myGenerator; |
| 114 | +} |
0 commit comments