|
| 1 | +#if !defined(__CLING__) || defined(__ROOTCLING__) |
| 2 | +#include "FairGenerator.h" |
| 3 | +#include "FairPrimaryGenerator.h" |
| 4 | +#include "Generators/GeneratorPythia8.h" |
| 5 | +#include "Pythia8/Pythia.h" |
| 6 | +#include "TDatabasePDG.h" |
| 7 | +#include "TMath.h" |
| 8 | +#include "TParticlePDG.h" |
| 9 | +#include "TRandom3.h" |
| 10 | +#include "TSystem.h" |
| 11 | +#include "fairlogger/Logger.h" |
| 12 | +#include <cmath> |
| 13 | +#include <fstream> |
| 14 | +#include <string> |
| 15 | +#include <vector> |
| 16 | +using namespace Pythia8; |
| 17 | +#endif |
| 18 | + |
| 19 | +/// Pythia8 event generator for pp collisions |
| 20 | +/// Selection of events with leading particle (pt>ptThreshold) and containing at |
| 21 | +/// least one particle of interest (default PDG = -2212) |
| 22 | + |
| 23 | +class GeneratorPythia8HighPt : public o2::eventgen::GeneratorPythia8 { |
| 24 | +public: |
| 25 | + /// Constructor |
| 26 | + GeneratorPythia8HighPt(int pdg_of_interest = -2212, double pt_leading = 5.0) |
| 27 | + : o2::eventgen::GeneratorPythia8() |
| 28 | + { |
| 29 | + fmt::printf(">> Pythia8 generator: PDG of interest = %d, ptLeading > %.1f GeV/c\n", pdg_of_interest, pt_leading); |
| 30 | + mPdg_of_interest = pdg_of_interest; |
| 31 | + mPt_leading = pt_leading; |
| 32 | + } |
| 33 | + /// Destructor |
| 34 | + ~GeneratorPythia8HighPt() = default; |
| 35 | + |
| 36 | + bool Init() override { |
| 37 | + addSubGenerator(0,"Pythia8 with particle of interest and high pt particle"); |
| 38 | + return o2::eventgen::GeneratorPythia8::Init(); |
| 39 | + } |
| 40 | + |
| 41 | +protected: |
| 42 | + bool generateEvent() override { |
| 43 | + fmt::printf(">> Generating event %d\n", mGeneratedEvents); |
| 44 | + |
| 45 | + bool genOk = false; |
| 46 | + int localCounter{0}; |
| 47 | + while (!genOk) { |
| 48 | + if (GeneratorPythia8::generateEvent()) { |
| 49 | + genOk = selectEvent(mPythia.event); |
| 50 | + } |
| 51 | + localCounter++; |
| 52 | + } |
| 53 | + fmt::printf(">> Generation of event of interest successful after %i iterations\n",localCounter); |
| 54 | + std::cout << std::endl << std::endl; |
| 55 | + notifySubGenerator(0); |
| 56 | + |
| 57 | + mGeneratedEvents++; |
| 58 | + |
| 59 | + return true; |
| 60 | + } |
| 61 | + |
| 62 | + bool selectEvent(Pythia8::Event &event) { |
| 63 | + |
| 64 | + bool contains_particle_of_interest = false; |
| 65 | + bool has_leading_particle = false; |
| 66 | + |
| 67 | + double pt_max{0}; |
| 68 | + |
| 69 | + for (auto iPart{0}; iPart < event.size(); ++iPart) { |
| 70 | + if (std::abs(event[iPart].eta()) > 0.8) { |
| 71 | + continue; |
| 72 | + } |
| 73 | + |
| 74 | + if (event[iPart].status() <= 0) { |
| 75 | + continue; |
| 76 | + } |
| 77 | + |
| 78 | + if (event[iPart].id() == mPdg_of_interest) |
| 79 | + contains_particle_of_interest = true; |
| 80 | + |
| 81 | + if ((!event[iPart].isNeutral()) && event[iPart].pT() > pt_max) |
| 82 | + pt_max = event[iPart].pT(); |
| 83 | + } |
| 84 | + |
| 85 | + if (pt_max > mPt_leading) |
| 86 | + has_leading_particle = true; |
| 87 | + |
| 88 | + if (has_leading_particle && contains_particle_of_interest) |
| 89 | + return true; |
| 90 | + return false; |
| 91 | + } |
| 92 | + |
| 93 | +private: |
| 94 | + int mPdg_of_interest = -2212; |
| 95 | + double mPt_leading = 5.0; |
| 96 | + uint64_t mGeneratedEvents = 0; |
| 97 | +}; |
| 98 | + |
| 99 | +///___________________________________________________________ |
| 100 | +FairGenerator *generateHighPt(int pdg_of_interest = -2212, double pt_leading = 5.0) { |
| 101 | + |
| 102 | + auto myGenerator = new GeneratorPythia8HighPt(pdg_of_interest, pt_leading); |
| 103 | + auto seed = (gRandom->TRandom::GetSeed() % 900000000); |
| 104 | + myGenerator->readString("Random:setSeed on"); |
| 105 | + myGenerator->readString("Random:seed " + std::to_string(seed)); |
| 106 | + return myGenerator; |
| 107 | +} |
0 commit comments