|
| 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 "fastjet/ClusterSequence.hh" |
| 13 | +#include <cmath> |
| 14 | +#include <fstream> |
| 15 | +#include <string> |
| 16 | +#include <vector> |
| 17 | + |
| 18 | +using namespace Pythia8; |
| 19 | +using namespace fastjet; |
| 20 | +#endif |
| 21 | + |
| 22 | +/// Pythia8 event generator for pp collisions |
| 23 | +/// Selection of events with Xi or Omega inside jets with pt > 10 GeV |
| 24 | + |
| 25 | +class GeneratorPythia8StrangeInJet : public o2::eventgen::GeneratorPythia8 { |
| 26 | +public: |
| 27 | + /// Constructor |
| 28 | + GeneratorPythia8StrangeInJet(double ptJetThreshold = 10.0, double jetR = 0.4, int gapSize = 4) |
| 29 | + : o2::eventgen::GeneratorPythia8(), |
| 30 | + mPtJetThreshold(ptJetThreshold), |
| 31 | + mJetR(jetR), |
| 32 | + mGapSize(gapSize) |
| 33 | + { |
| 34 | + fmt::printf( |
| 35 | + ">> Pythia8 generator: Xi/Omega inside jets with ptJet > %.1f GeV, R = %.1f, gap = %d\n", |
| 36 | + ptJetThreshold, jetR, gapSize); |
| 37 | + } |
| 38 | + |
| 39 | + ~GeneratorPythia8StrangeInJet() = default; |
| 40 | + |
| 41 | + bool Init() override { |
| 42 | + addSubGenerator(0, "Pythia8 events with Xi/Omega inside jets"); |
| 43 | + return o2::eventgen::GeneratorPythia8::Init(); |
| 44 | + } |
| 45 | + |
| 46 | +protected: |
| 47 | + bool generateEvent() override { |
| 48 | + fmt::printf(">> Generating event %lu\n", mGeneratedEvents); |
| 49 | + |
| 50 | + bool genOk = false; |
| 51 | + int localCounter{0}; |
| 52 | + |
| 53 | + // Accept mGapSize events unconditionally, then one triggered event |
| 54 | + if (mGeneratedEvents % (mGapSize + 1) < mGapSize) { |
| 55 | + genOk = GeneratorPythia8::generateEvent(); |
| 56 | + fmt::printf(">> Gap-trigger accepted event (no strangeness check)\n"); |
| 57 | + } else { |
| 58 | + while (!genOk) { |
| 59 | + if (GeneratorPythia8::generateEvent()) { |
| 60 | + genOk = selectEvent(mPythia.event); |
| 61 | + } |
| 62 | + localCounter++; |
| 63 | + } |
| 64 | + fmt::printf(">> Event accepted after %d iterations (Xi/Omega in jet)\n", |
| 65 | + localCounter); |
| 66 | + } |
| 67 | + |
| 68 | + notifySubGenerator(0); |
| 69 | + mGeneratedEvents++; |
| 70 | + return true; |
| 71 | + } |
| 72 | + |
| 73 | + bool selectEvent(Pythia8::Event &event) { |
| 74 | + const std::vector<int> pdgXiOmega = {3312, -3312, 3334, -3334}; |
| 75 | + |
| 76 | + std::vector<PseudoJet> fjParticles; |
| 77 | + |
| 78 | + for (int i = 0; i < event.size(); ++i) { |
| 79 | + const auto &p = event[i]; |
| 80 | + |
| 81 | + // --- Jet input selection --- |
| 82 | + if (!p.isFinal()) continue; |
| 83 | + if (!p.isPrimary()) continue; |
| 84 | + if (!p.isCharged()) continue; |
| 85 | + if (std::abs(p.eta()) > 0.8) continue; |
| 86 | + |
| 87 | + PseudoJet pj(p.px(), p.py(), p.pz(), p.e()); |
| 88 | + pj.set_user_index(i); // map back to Pythia index |
| 89 | + fjParticles.push_back(pj); |
| 90 | + } |
| 91 | + |
| 92 | + if (fjParticles.empty()) return false; |
| 93 | + |
| 94 | + JetDefinition jetDef(antikt_algorithm, mJetR); |
| 95 | + ClusterSequence cs(fjParticles, jetDef); |
| 96 | + auto jets = sorted_by_pt(cs.inclusive_jets(mPtJetThreshold)); |
| 97 | + |
| 98 | + for (const auto &jet : jets) { |
| 99 | + for (const auto &c : jet.constituents()) { |
| 100 | + int idx = c.user_index(); |
| 101 | + int pdg = event[idx].id(); |
| 102 | + if (std::find(pdgXiOmega.begin(), pdgXiOmega.end(), pdg) != pdgXiOmega.end()) { |
| 103 | + fmt::printf( |
| 104 | + ">> Accepted jet: pt = %.2f, eta = %.2f, phi = %.2f, contains PDG %d\n", |
| 105 | + jet.pt(), jet.eta(), jet.phi(), pdg); |
| 106 | + return true; |
| 107 | + } |
| 108 | + } |
| 109 | + } |
| 110 | + return false; |
| 111 | + } |
| 112 | + |
| 113 | +private: |
| 114 | + double mPtJetThreshold{10.0}; |
| 115 | + double mJetR{0.4}; |
| 116 | + int mGapSize{4}; |
| 117 | + uint64_t mGeneratedEvents{0}; |
| 118 | +}; |
0 commit comments