Skip to content

Commit e6655b5

Browse files
authored
Update and rename MC/config/PWGHF/trigger/selectNonHfe.C to MC/config/PWGHF/external/generator/selectNonHfe.C
Add Boxgen with Minimum bias
1 parent f289b78 commit e6655b5

2 files changed

Lines changed: 123 additions & 41 deletions

File tree

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
2+
#if !defined(__CLING__) || defined(__ROOTCLING__)
3+
#include "FairGenerator.h"
4+
#include "FairPrimaryGenerator.h"
5+
#include "Generators/GeneratorPythia8.h"
6+
#include "TRandom3.h"
7+
#include "TParticlePDG.h"
8+
#include "TDatabasePDG.h"
9+
#include "TMath.h"
10+
#include <fairlogger/Logger.h>
11+
#include <cmath>
12+
#include <vector>
13+
#endif
14+
15+
#include "Pythia8/Pythia.h"
16+
17+
class GeneratorPythia8Box : public o2::eventgen::GeneratorPythia8
18+
{
19+
public:
20+
21+
GeneratorPythia8Box(std::vector<int> pdgList, int nInject = 3,
22+
float ptMin = 0.1, float ptMax = 50.0,
23+
float etaMin = -0.8, float etaMax = 0.8)
24+
: mPdgList(pdgList), nParticles(nInject),
25+
genMinPt(ptMin), genMaxPt(ptMax),
26+
genMinEta(etaMin), genMaxEta(etaMax)
27+
{
28+
// Initialize dedicated Pythia instance for injection/decay only
29+
// Reuses same config as main Pythia; beam settings are ignored by moreDecays()
30+
auto& param = o2::eventgen::GeneratorPythia8Param::Instance();
31+
std::string cfg = gSystem->ExpandPathName(param.config.c_str());
32+
if (!mPythiaGun.readFile(cfg, true)) {
33+
LOG(fatal) << "Failed to read config for mPythiaGun: " << cfg;
34+
}
35+
if (!mPythiaGun.init()) {
36+
LOG(fatal) << "Failed to init mPythiaGun";
37+
}
38+
}
39+
40+
~GeneratorPythia8Box() = default;
41+
42+
bool Init() override
43+
{
44+
return o2::eventgen::GeneratorPythia8::Init();
45+
}
46+
47+
protected:
48+
49+
// ── generateEvent: MB + injection ──
50+
Bool_t generateEvent() override
51+
{
52+
bool hasElectron = false;
53+
54+
while (!hasElectron) {
55+
// ===== 1. Generate minimum-bias event =====
56+
if (!mPythia.next()) continue;
57+
58+
// ===== 2. Inject π⁰/η into separate gun, decay only them =====
59+
mPythiaGun.event.reset();
60+
for (int i = 0; i < nParticles; ++i) {
61+
int pdg = mPdgList[gRandom->Integer(mPdgList.size())];
62+
auto* pPDG = TDatabasePDG::Instance()->GetParticle(pdg);
63+
if (!pPDG) continue;
64+
double mass = pPDG->Mass();
65+
66+
double pt = gRandom->Uniform(genMinPt, genMaxPt);
67+
double eta = gRandom->Uniform(genMinEta, genMaxEta);
68+
double phi = gRandom->Uniform(0., TMath::TwoPi());
69+
double px = pt * cos(phi);
70+
double py = pt * sin(phi);
71+
double pz = pt * sinh(eta);
72+
double e = sqrt(px * px + py * py + pz * pz + mass * mass);
73+
74+
mPythiaGun.event.append(pdg, 11, 0, 0, px, py, pz, e, mass);
75+
}
76+
77+
mPythiaGun.moreDecays();
78+
79+
// ===== 3. Check for electron from injection in acceptance =====
80+
for (int i = 0; i < mPythiaGun.event.size(); ++i) {
81+
auto& part = mPythiaGun.event[i];
82+
if (std::abs(part.id()) == 11 && part.isFinal()) {
83+
if (part.pT() > 0.1 && std::abs(part.eta()) < 1.2) {
84+
hasElectron = true;
85+
break;
86+
}
87+
}
88+
}
89+
}
90+
91+
// ===== 4. Copy injection products to MB event with index offset =====
92+
int offset = mPythia.event.size();
93+
94+
for (int i = 0; i < mPythiaGun.event.size(); ++i) {
95+
auto part = mPythiaGun.event[i];
96+
if (part.id() == 90) continue; // skip system placeholder
97+
if (!part.isFinal() && part.id() != 111 && part.id() != 221) continue;
98+
99+
if (part.mother1() > 0) part.mother1(part.mother1() + offset - 1);
100+
if (part.mother2() > 0) part.mother2(part.mother2() + offset - 1);
101+
if (part.daughter1() > 0) part.daughter1(part.daughter1() + offset - 1);
102+
if (part.daughter2() > 0) part.daughter2(part.daughter2() + offset - 1);
103+
104+
mPythia.event.append(part);
105+
}
106+
107+
return true;
108+
}
109+
110+
private:
111+
std::vector<int> mPdgList;
112+
double genMinPt, genMaxPt;
113+
double genMinEta, genMaxEta;
114+
int nParticles;
115+
116+
Pythia8::Pythia mPythiaGun;
117+
};
118+
119+
FairGenerator *generatePythia8Box(float ptMin = 0.1, float ptMax = 50.0)
120+
{
121+
std::vector<int> pdgList = {111, 221};
122+
return new GeneratorPythia8Box(pdgList, 3, ptMin, ptMax, -0.8, 0.8);
123+
}

‎MC/config/PWGHF/trigger/selectNonHfe.C‎

Lines changed: 0 additions & 41 deletions
This file was deleted.

0 commit comments

Comments
 (0)