Skip to content

Commit 903362d

Browse files
authored
Pythia8 events with pt>ptLeading and PDG of interest (#1638)
1 parent 54c9470 commit 903362d

File tree

4 files changed

+166
-0
lines changed

4 files changed

+166
-0
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[GeneratorExternal]
2+
fileName = ${O2DPG_ROOT}/MC/config/PWGLF/pythia8/generator_pythia8_highpt.C
3+
funcName = generateHighPt(-2212,5.0)
4+
5+
[GeneratorPythia8]
6+
config=${O2_ROOT}/share/Generators/egconfig/pythia8_inel.cfg
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
int External() {
2+
std::string path{"o2sim_Kine.root"};
3+
4+
TFile file(path.c_str(), "READ");
5+
if (file.IsZombie()) {
6+
std::cerr << "Cannot open ROOT file " << path << "\n";
7+
return 1;
8+
}
9+
10+
auto tree = (TTree *)file.Get("o2sim");
11+
if (!tree) {
12+
std::cerr << "Cannot find tree o2sim in file " << path << "\n";
13+
return 1;
14+
}
15+
std::vector<o2::MCTrack> *tracks{};
16+
tree->SetBranchAddress("MCTrack", &tracks);
17+
18+
auto nEvents = tree->GetEntries();
19+
auto nSelected = tree->Scan("MCTrack.GetPdgCode()", "MCTrack.GetPdgCode() == -2212");
20+
if (nSelected == 0) {
21+
std::cerr << "No event of interest\n";
22+
return 1;
23+
}
24+
return 0;
25+
}
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
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+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/bin/bash
2+
3+
4+
# make sure O2DPG + O2 is loaded
5+
[ ! "${O2DPG_ROOT}" ] && echo "Error: This needs O2DPG loaded" && exit 1
6+
[ ! "${O2_ROOT}" ] && echo "Error: This needs O2 loaded" && exit 1
7+
8+
# ----------- LOAD UTILITY FUNCTIONS --------------------------
9+
. ${O2_ROOT}/share/scripts/jobutils.sh
10+
11+
# ----------- START ACTUAL JOB -----------------------------
12+
13+
NWORKERS=${NWORKERS:-8}
14+
MODULES="--skipModules ZDC"
15+
SIMENGINE=${SIMENGINE:-TGeant4}
16+
NSIGEVENTS=${NSIGEVENTS:-1}
17+
NTIMEFRAMES=${NTIMEFRAMES:-1}
18+
INTRATE=${INTRATE:-500000}
19+
SYSTEM=${SYSTEM:-pp}
20+
ENERGY=${ENERGY:-13600}
21+
[[ ${SPLITID} != "" ]] && SEED="-seed ${SPLITID}" || SEED=""
22+
23+
# create workflow
24+
${O2DPG_ROOT}/MC/bin/o2dpg_sim_workflow.py -eCM ${ENERGY} -col ${SYSTEM} -gen external -j ${NWORKERS} -ns ${NSIGEVENTS} -tf ${NTIMEFRAMES} -interactionRate ${INTRATE} -confKey "Diamond.width[0]=0.005;Diamond.width[1]=0.005;Diamond.width[2]=6." -e ${SIMENGINE} ${SEED} -mod "--skipModules ZDC" \
25+
-ini $O2DPG_ROOT/MC/config/PWGLF/ini/GeneratorLF_HighPt.ini
26+
27+
# run workflow
28+
${O2DPG_ROOT}/MC/bin/o2_dpg_workflow_runner.py -f workflow.json -tt aod --cpu-limit 32

0 commit comments

Comments
 (0)