diff --git a/MC/config/PWGHF/external/generator/selectNonHfe.C b/MC/config/PWGHF/external/generator/selectNonHfe.C index 7c685c585..7dd325335 100644 --- a/MC/config/PWGHF/external/generator/selectNonHfe.C +++ b/MC/config/PWGHF/external/generator/selectNonHfe.C @@ -1,10 +1,3 @@ -/// Select π⁰ and η within a given rapidity window for enhancement -/// pdgPartForAccCut: PDG of the particle to select (111=π⁰, 221=η) -/// minNb: minimum number of such particles per event for enhancement - -//// authors: Rashi Gupta (rashi.gupta@cern.ch) -/// authors: Ravindra Singh (ravindra.singh@cern.ch) - #if !defined(__CLING__) || defined(__ROOTCLING__) #include "FairGenerator.h" @@ -14,83 +7,117 @@ #include "TParticlePDG.h" #include "TDatabasePDG.h" #include "TMath.h" +#include #include #include #endif #include "Pythia8/Pythia.h" -using namespace Pythia8; class GeneratorPythia8Box : public o2::eventgen::GeneratorPythia8 { public: - - GeneratorPythia8Box(std::vector pdgList, int nInject = 3, float ptMin = 0.1, float ptMax = 50.0, float etaMin = -0.8, float etaMax = 0.8) - : mPdgList(pdgList), nParticles(nInject), genMinPt(ptMin), genMaxPt(ptMax), genMinEta(etaMin), genMaxEta(etaMax) + + GeneratorPythia8Box(std::vector pdgList, int nInject = 3, + float ptMin = 0.1, float ptMax = 50.0, + float etaMin = -0.8, float etaMax = 0.8) + : mPdgList(pdgList), nParticles(nInject), + genMinPt(ptMin), genMaxPt(ptMax), + genMinEta(etaMin), genMaxEta(etaMax) { + // Initialize dedicated Pythia instance for injection/decay only + // Reuses same config as main Pythia; beam settings are ignored by moreDecays() + auto& param = o2::eventgen::GeneratorPythia8Param::Instance(); + std::string cfg = gSystem->ExpandPathName(param.config.c_str()); + if (!mPythiaGun.readFile(cfg, true)) { + LOG(fatal) << "Failed to read config for mPythiaGun: " << cfg; + } + if (!mPythiaGun.init()) { + LOG(fatal) << "Failed to init mPythiaGun"; + } } ~GeneratorPythia8Box() = default; -Bool_t generateEvent() override -{ - bool hasElectron = false; - - while (!hasElectron) { - mPythia.event.reset(); + bool Init() override + { + return o2::eventgen::GeneratorPythia8::Init(); + } - for (int i{0}; i < nParticles; ++i) - { - int currentPdg = mPdgList[gRandom->Integer(mPdgList.size())]; - double mass = TDatabasePDG::Instance()->GetParticle(currentPdg)->Mass(); +protected: - const double pt = gRandom->Uniform(genMinPt, genMaxPt); - const double eta = gRandom->Uniform(genMinEta, genMaxEta); - const double phi = gRandom->Uniform(0, TMath::TwoPi()); + // ── generateEvent: MB + injection ── + Bool_t generateEvent() override + { + bool hasElectron = false; + + while (!hasElectron) { + // ===== 1. Generate minimum-bias event ===== + if (!mPythia.next()) continue; + + // ===== 2. Inject π⁰/η into separate gun, decay only them ===== + mPythiaGun.event.reset(); + for (int i = 0; i < nParticles; ++i) { + int pdg = mPdgList[gRandom->Integer(mPdgList.size())]; + auto* pPDG = TDatabasePDG::Instance()->GetParticle(pdg); + if (!pPDG) continue; + double mass = pPDG->Mass(); + + double pt = gRandom->Uniform(genMinPt, genMaxPt); + double eta = gRandom->Uniform(genMinEta, genMaxEta); + double phi = gRandom->Uniform(0., TMath::TwoPi()); + double px = pt * cos(phi); + double py = pt * sin(phi); + double pz = pt * sinh(eta); + double e = sqrt(px * px + py * py + pz * pz + mass * mass); + + mPythiaGun.event.append(pdg, 11, 0, 0, px, py, pz, e, mass); + } - const double px{pt * std::cos(phi)}; - const double py{pt * std::sin(phi)}; - const double pz{pt * std::sinh(eta)}; - const double et{std::hypot(std::hypot(pt, pz), mass)}; + mPythiaGun.moreDecays(); - - mPythia.event.append(currentPdg, 11, 0, 0, px, py, pz, et, mass); + // ===== 3. Check for electron from injection in acceptance ===== + for (int i = 0; i < mPythiaGun.event.size(); ++i) { + auto& part = mPythiaGun.event[i]; + if (std::abs(part.id()) == 11 && part.isFinal()) { + if (part.pT() > 0.1 && std::abs(part.eta()) < 1.2) { + hasElectron = true; + break; + } + } + } } - - if (!mPythia.next()) continue; + // ===== 4. Copy injection products to MB event with index offset ===== + int offset = mPythia.event.size(); - - for (int i = 0; i < mPythia.event.size(); ++i) { - if (std::abs(mPythia.event[i].id()) == 11) { - - - double childPt = mPythia.event[i].pT(); - double childEta = mPythia.event[i].eta(); - - if (childPt > 0.1 && std::abs(childEta) < 1.2) { - hasElectron = true; // Mil gaya! - break; - } - } + for (int i = 0; i < mPythiaGun.event.size(); ++i) { + auto part = mPythiaGun.event[i]; + if (part.id() == 90) continue; // skip system placeholder + if (!part.isFinal() && part.id() != 111 && part.id() != 221) continue; + + if (part.mother1() > 0) part.mother1(part.mother1() + offset - 1); + if (part.mother2() > 0) part.mother2(part.mother2() + offset - 1); + if (part.daughter1() > 0) part.daughter1(part.daughter1() + offset - 1); + if (part.daughter2() > 0) part.daughter2(part.daughter2() + offset - 1); + + mPythia.event.append(part); } - - } - return true; -} + return true; + } private: std::vector mPdgList; double genMinPt, genMaxPt; double genMinEta, genMaxEta; int nParticles; + + Pythia8::Pythia mPythiaGun; }; - FairGenerator *generatePythia8Box(float ptMin = 0.1, float ptMax = 50.0) { - std::vector pdgList = {111, 221}; return new GeneratorPythia8Box(pdgList, 3, ptMin, ptMax, -0.8, 0.8); -} +} \ No newline at end of file diff --git a/MC/config/PWGHF/hybrid/GeneratorHF_Non_Hfe.json b/MC/config/PWGHF/hybrid/GeneratorHF_Non_Hfe.json index c729060bb..e69de29bb 100644 --- a/MC/config/PWGHF/hybrid/GeneratorHF_Non_Hfe.json +++ b/MC/config/PWGHF/hybrid/GeneratorHF_Non_Hfe.json @@ -1,40 +0,0 @@ -{ - "generators": [ - { - "name": "pythia8", - "config": { - "config": "${O2DPG_MC_CONFIG_ROOT}/MC/config/common/pythia8/generator/pythia8_NonHfe.cfg" - }, - "triggers": { - "mode": "or", - "specs": [ - { - "macro": "${O2DPG_MC_CONFIG_ROOT}/MC/config/PWGHF/trigger/selectNonHfe.C", - "function": "selectPionEtaWithinAcc(\"111;221\",-1.5,1.5,1)" - } - ] - } - }, - { - "name": "boxgen", - "config": { - "pdg": 111, - "prange[0]": 0.1, - "prange[1]": 50.0, - "eta[0]": -0.8, - "eta[1]": 0.8 - } - }, - { - "name": "boxgen", - "config": { - "pdg": 221, - "prange[0]": 0.1, - "prange[1]": 50.0, - "eta[0]": -0.8, - "eta[1]": 0.8 - } - } - ], - "fractions": [1, 1, 1] -} diff --git a/MC/config/PWGHF/ini/GeneratorHF_Non_Hfe.ini b/MC/config/PWGHF/ini/GeneratorHF_Non_Hfe.ini index f5455e34d..7ace23bea 100644 --- a/MC/config/PWGHF/ini/GeneratorHF_Non_Hfe.ini +++ b/MC/config/PWGHF/ini/GeneratorHF_Non_Hfe.ini @@ -1,7 +1,7 @@ -#### This configuration uses the Box generator to trigger π⁰/η production within the specified rapidity window [GeneratorExternal] fileName=${O2DPG_MC_CONFIG_ROOT}/MC/config/PWGHF/external/generator/selectNonHfe.C -funcName = generatePythia8Box(0.1, 50.0) +funcName=generatePythia8Box(0.1,50.0) + [GeneratorPythia8] config=${O2DPG_MC_CONFIG_ROOT}/MC/config/PWGHF/pythia8/generator/pythia8_NonHfe.cfg -includePartonEvent=true +includePartonEvent=true \ No newline at end of file diff --git a/MC/config/PWGHF/pythia8/generator/pythia8_NonHfe.cfg b/MC/config/PWGHF/pythia8/generator/pythia8_NonHfe.cfg index 3feaa6585..f16d04171 100644 --- a/MC/config/PWGHF/pythia8/generator/pythia8_NonHfe.cfg +++ b/MC/config/PWGHF/pythia8/generator/pythia8_NonHfe.cfg @@ -9,8 +9,8 @@ Beams:eCM 13600. # GeV ### processes -ProcessLevel:all = off +SoftQCD:inelastic = on ### decays ParticleDecays:limitTau0 on ParticleDecays:tau0Max 10.