Skip to content

Commit d40ed93

Browse files
alcalivaBenedikt Volkel
authored andcommitted
pythia8 for pp with pt>ptLeading and random strange hadron (#1646)
(cherry picked from commit 2c71e9b)
1 parent 2b869af commit d40ed93

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_strangeness.C
3+
funcName = generateHighPtAndStrangeHadron(5.0)
4+
5+
[GeneratorPythia8]
6+
config=${O2_ROOT}/share/Generators/egconfig/pythia8_inel.cfg
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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 nK0 = tree->Scan("MCTrack.GetPdgCode()", "TMath::Abs(MCTrack.GetPdgCode()) == 310");
19+
auto nLambda = tree->Scan("MCTrack.GetPdgCode()", "TMath::Abs(MCTrack.GetPdgCode()) == 3122");
20+
auto nXi = tree->Scan("MCTrack.GetPdgCode()", "TMath::Abs(MCTrack.GetPdgCode()) == 3312");
21+
auto nOmega = tree->Scan("MCTrack.GetPdgCode()", "TMath::Abs(MCTrack.GetPdgCode()) == 3334");
22+
auto nStr = nK0+nLambda+nXi+nOmega;
23+
24+
if (nStr == 0) {
25+
std::cerr << "No event of interest\n";
26+
return 1;
27+
}
28+
return 0;
29+
}
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
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
21+
/// one strange hadron extracted randomly (K0, Lambda, Xi, Omega)
22+
23+
class GeneratorPythia8HighPtStrangeness : public o2::eventgen::GeneratorPythia8 {
24+
public:
25+
/// Constructor
26+
GeneratorPythia8HighPtStrangeness(double pt_leading = 5.0)
27+
: o2::eventgen::GeneratorPythia8()
28+
{
29+
fmt::printf(">> Pythia8 generator: ptLeading > %.1f GeV/c\n", pt_leading);
30+
mPt_leading = pt_leading;
31+
}
32+
/// Destructor
33+
~GeneratorPythia8HighPtStrangeness() = default;
34+
35+
bool Init() override {
36+
addSubGenerator(0,"Pythia8 events containing high pt particle + strange hadrons");
37+
return o2::eventgen::GeneratorPythia8::Init();
38+
}
39+
40+
protected:
41+
bool generateEvent() override {
42+
fmt::printf(">> Generating event %d\n", mGeneratedEvents);
43+
44+
bool genOk = false;
45+
int localCounter{0};
46+
while (!genOk) {
47+
if (GeneratorPythia8::generateEvent()) {
48+
genOk = selectEvent(mPythia.event);
49+
}
50+
localCounter++;
51+
}
52+
fmt::printf(">> Generation of event of interest successful after %i iterations\n",localCounter);
53+
std::cout << std::endl << std::endl;
54+
notifySubGenerator(0);
55+
56+
mGeneratedEvents++;
57+
58+
return true;
59+
}
60+
61+
bool selectEvent(Pythia8::Event &event) {
62+
63+
int pdg_of_interest[7] = {310, 3122, -3122, 3312, -3312, 3334, -3334};
64+
int partIndex = static_cast<int>(gRandom->Uniform(0,7));
65+
66+
bool contains_particle_of_interest = false;
67+
double pt_max{0};
68+
for (auto iPart{0}; iPart < event.size(); ++iPart) {
69+
if (std::abs(event[iPart].eta()) > 0.8) {
70+
continue;
71+
}
72+
73+
if (event[iPart].status() <= 0) {
74+
continue;
75+
}
76+
77+
if (event[iPart].id() == pdg_of_interest[partIndex])
78+
contains_particle_of_interest = true;
79+
80+
if ((!event[iPart].isNeutral()) && event[iPart].pT() > pt_max)
81+
pt_max = event[iPart].pT();
82+
}
83+
84+
if (pt_max < mPt_leading)
85+
return false;
86+
87+
return contains_particle_of_interest;
88+
}
89+
90+
private:
91+
double mPt_leading = 5.0;
92+
uint64_t mGeneratedEvents = 0;
93+
};
94+
95+
///___________________________________________________________
96+
FairGenerator *generateHighPtAndStrangeHadron(double pt_leading = 5.0) {
97+
98+
auto myGenerator = new GeneratorPythia8HighPtStrangeness(pt_leading);
99+
auto seed = (gRandom->TRandom::GetSeed() % 900000000);
100+
myGenerator->readString("Random:setSeed on");
101+
myGenerator->readString("Random:seed " + std::to_string(seed));
102+
return myGenerator;
103+
}
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_strangeness.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)