Skip to content

Commit 2e0d070

Browse files
njacaziogconesab
authored andcommitted
Add injection scheme for nuclei
- Add multiple injector macro based on preexisting - Initialization via input file or arguments
1 parent c32e0ce commit 2e0d070

File tree

6 files changed

+233
-7
lines changed

6 files changed

+233
-7
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[GeneratorExternal]
2+
fileName=/tmp/inj/generator_pythia8_longlived_multiple.C
3+
; funcName=generateLongLivedMultiple({{1000010020, 10, 0.2, 10}, {-1000010020, 10, 0.2, 10}, {1000010030, 10, 0.2, 10}, {-1000010030, 10, 0.2, 10}, {1000020030, 10, 0.2, 10}, {-1000020030, 10, 0.2, 10}})
4+
# Deuteron Anti-Deuteron Triton Anti-Triton Helium3 Anti-Helium3
5+
funcName=generateLongLivedMultiple("${O2DPG_ROOT}/MC/config/PWGLF/pythia8/generator/particlelist.gun")
6+
7+
[GeneratorPythia8]
8+
config=${O2_ROOT}/share/Generators/egconfig/pythia8_inel.cfg
9+
10+
[DecayerPythia8]
11+
config[0]=${O2DPG_ROOT}/MC/config/common/pythia8/decayer/base.cfg
12+
config[1]=${O2DPG_ROOT}/MC/config/PWGLF/pythia8/generator/nuclei.cfg
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
### particle definition
2+
### id:all = name antiName spinType chargeType colType m0 mWidth mMin mMax tau0
3+
4+
### deuteron
5+
1000010020:all = deuteron deuteron_bar 0 3 0 1.8756134 0. 0. 0. 0.
6+
1000010020:mayDecay = off
7+
8+
### triton
9+
1000010030:all = triton triton_bar 0 3 0 2.8089218 0. 0. 0. 0.
10+
1000010030:mayDecay = off
11+
12+
### helium-3
13+
1000020030:all = helium3 helium3_bar 0 6 0 2.80923 0. 0. 0. 0.
14+
1000020030:mayDecay = off
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# PDG N ptMin ptMax
2+
1000010020 10 0.2 10
3+
-1000010020 10 0.2 10
4+
1000010030 10 0.2 10
5+
-1000010030 10 0.2 10
6+
1000020030 10 0.2 10
7+
-1000020030 10 0.2 10

MC/config/PWGLF/pythia8/generator_pythia8_longlived.C

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,16 @@ public:
2525
void setRandomizePDGsign(bool val) { randomizePDGsign = val; }
2626

2727
/// get mass from TParticlePDG
28-
double getMass(int input_pdg)
28+
static double getMass(int input_pdg)
2929
{
3030
double mass = 0;
3131
if (TDatabasePDG::Instance())
3232
{
3333
TParticlePDG *particle = TDatabasePDG::Instance()->GetParticle(input_pdg);
34-
if (particle)
35-
{
34+
if (particle) {
3635
mass = particle->Mass();
37-
}
38-
else
39-
{
40-
std::cout << "===> Unknown particle requested, mass set to 0" << std::endl;
36+
} else {
37+
std::cout << "===> Unknown particle requested with PDG " << input_pdg << ", mass set to 0" << std::endl;
4138
}
4239
}
4340
return mass;
Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
///
2+
/// \file generator_pythia8_longlived_multiple.C
3+
/// \author Nicolò Jacazio nicolo.jacazio@cern.ch
4+
/// \brief Implementation of a gun generator for multiple particles, built on generator_pythia8_longlived.C
5+
/// usage:
6+
/// o2-sim -g external --configKeyValues 'GeneratorExternal.fileName=generator_pythia8_longlived_multiple.C;GeneratorExternal.funcName=generateLongLivedMultiple({1010010030}, {10}, {0.5}, {10})'
7+
/// or:
8+
/// o2-sim -g external --configKeyValues 'GeneratorExternal.fileName=generator_pythia8_longlived_multiple.C;GeneratorExternal.funcName=generateLongLivedMultiple({{1010010030, 10, 0.5, 10}})'
9+
///
10+
11+
#include "generator_pythia8_longlived.C"
12+
#include "TSystem.h"
13+
#include <fstream>
14+
15+
using namespace Pythia8;
16+
17+
class GeneratorPythia8LongLivedGunMultiple : public GeneratorPythia8LongLivedGun
18+
{
19+
public:
20+
/// constructor
21+
GeneratorPythia8LongLivedGunMultiple() : GeneratorPythia8LongLivedGun{0}
22+
{
23+
}
24+
25+
/// Destructor
26+
~GeneratorPythia8LongLivedGunMultiple() = default;
27+
28+
//__________________________________________________________________
29+
Bool_t importParticles() override
30+
{
31+
GeneratorPythia8::importParticles();
32+
for (const ConfigContainer& cfg : gunConfigs) {
33+
for (int i{0}; i < cfg.nInject; ++i) {
34+
const double pt = gRandom->Uniform(cfg.ptMin, cfg.ptMax);
35+
const double eta = gRandom->Uniform(cfg.etaMin, cfg.etaMax);
36+
const double phi = gRandom->Uniform(0, TMath::TwoPi());
37+
const double px{pt * std::cos(phi)};
38+
const double py{pt * std::sin(phi)};
39+
const double pz{pt * std::sinh(eta)};
40+
const double et{std::hypot(std::hypot(pt, pz), cfg.mass)};
41+
mParticles.push_back(TParticle(cfg.pdg, 1, -1, -1, -1, -1, px, py, pz, et, 0., 0., 0., 0.));
42+
}
43+
}
44+
return true;
45+
}
46+
47+
struct ConfigContainer {
48+
ConfigContainer(int input_pdg = 0, int n = 1, float p = 1, float P = 10) : pdg{input_pdg},
49+
nInject{n},
50+
ptMin{p},
51+
ptMax{P}
52+
{
53+
mass = GeneratorPythia8LongLivedGun::getMass(pdg);
54+
};
55+
ConfigContainer(TObjArray* arr) : ConfigContainer(atoi(arr->At(0)->GetName()),
56+
atoi(arr->At(1)->GetName()),
57+
atof(arr->At(2)->GetName()),
58+
atof(arr->At(3)->GetName())){};
59+
60+
int pdg = 0;
61+
int nInject = 1;
62+
float ptMin = 1;
63+
float ptMax = 10;
64+
float etaMin = -1.f;
65+
float etaMax = 1.f;
66+
double mass = 0.f;
67+
void print() const
68+
{
69+
Printf("int pdg = %i", pdg);
70+
Printf("int nInject = %i", nInject);
71+
Printf("float ptMin = %f", ptMin);
72+
Printf("float ptMax = %f", ptMax);
73+
Printf("float etaMin = %f", etaMin);
74+
Printf("float etaMax = %f", etaMax);
75+
Printf("double mass = %f", mass);
76+
}
77+
};
78+
79+
//__________________________________________________________________
80+
ConfigContainer addGun(int input_pdg, int nInject = 1, float ptMin = 1, float ptMax = 10)
81+
{
82+
ConfigContainer cfg{input_pdg, nInject, ptMin, ptMax};
83+
gunConfigs.push_back(cfg);
84+
return cfg;
85+
}
86+
87+
//__________________________________________________________________
88+
ConfigContainer addGun(ConfigContainer cfg) { return addGun(cfg.pdg, cfg.nInject, cfg.ptMin, cfg.ptMax); }
89+
90+
private:
91+
std::vector<ConfigContainer> gunConfigs; // List of gun configurations to use
92+
};
93+
94+
///___________________________________________________________
95+
/// Create generator via arrays of entries
96+
FairGenerator* generateLongLivedMultiple(std::vector<int> PDGs, std::vector<int> nInject, std::vector<float> ptMin, std::vector<float> ptMax)
97+
{
98+
const std::vector<unsigned long> entries = {PDGs.size(), nInject.size(), ptMin.size(), ptMax.size()};
99+
if (!std::equal(entries.begin() + 1, entries.end(), entries.begin())) {
100+
Printf("Not equal number of entries, check configuration");
101+
return nullptr;
102+
}
103+
GeneratorPythia8LongLivedGunMultiple* multiGun = new GeneratorPythia8LongLivedGunMultiple();
104+
for (unsigned long i = 0; i < entries[0]; i++) {
105+
multiGun->addGun(PDGs[i], nInject[i], ptMin[i], ptMax[i]);
106+
}
107+
return multiGun;
108+
}
109+
110+
///___________________________________________________________
111+
/// Create generator via an array of configurations
112+
FairGenerator* generateLongLivedMultiple(std::vector<GeneratorPythia8LongLivedGunMultiple::ConfigContainer> cfg)
113+
{
114+
if (cfg.size() == 1) {
115+
return new GeneratorPythia8LongLivedGun(cfg[0].pdg, cfg[0].nInject, cfg[0].ptMin, cfg[0].ptMax);
116+
}
117+
GeneratorPythia8LongLivedGunMultiple* multiGun = new GeneratorPythia8LongLivedGunMultiple();
118+
for (const auto& c : cfg) {
119+
Printf("Adding gun");
120+
c.print();
121+
multiGun->addGun(c);
122+
}
123+
return multiGun;
124+
}
125+
126+
///___________________________________________________________
127+
/// Create generator via input file
128+
FairGenerator* generateLongLivedMultiple(std::string configuration = "${O2DPG_ROOT}/MC/config/PWGLF/pythia8/generator/particlelist.gun")
129+
{
130+
configuration = gSystem->ExpandPathName(configuration.c_str());
131+
Printf("Using configuration file '%s'", configuration.c_str());
132+
std::ifstream inputFile(configuration.c_str(), ios::in);
133+
std::vector<GeneratorPythia8LongLivedGunMultiple::ConfigContainer> cfgVec;
134+
if (inputFile.is_open()) {
135+
std::string l;
136+
int n = 0;
137+
while (getline(inputFile, l)) {
138+
TString line = l;
139+
line.Strip(TString::kBoth, ' ');
140+
141+
std::cout << n++ << " " << line << endl;
142+
if (line.BeginsWith("#")) {
143+
std::cout << "Skipping\n";
144+
continue;
145+
}
146+
147+
GeneratorPythia8LongLivedGunMultiple::ConfigContainer cfg(line.Tokenize(" "));
148+
cfgVec.push_back(cfg);
149+
}
150+
} else {
151+
Printf("ERROR: can't open '%s'", configuration.c_str());
152+
return nullptr;
153+
}
154+
return generateLongLivedMultiple(cfgVec);
155+
}
156+
157+
///___________________________________________________________
158+
void generator_pythia8_longlived_multiple()
159+
{
160+
Printf("Compiled correctly!");
161+
}

MC/run/PWGLF/run_DeTrHeInjected.sh

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/bin/bash
2+
3+
#
4+
# A example workflow MC->RECO->AOD for a simple pp min bias
5+
# production, targetting test beam conditions.
6+
7+
# make sure O2DPG + O2 is loaded
8+
[ ! "${O2DPG_ROOT}" ] && echo "Error: This needs O2DPG loaded" && exit 1
9+
[ ! "${O2_ROOT}" ] && echo "Error: This needs O2 loaded" && exit 1
10+
11+
# ----------- LOAD UTILITY FUNCTIONS --------------------------
12+
. ${O2_ROOT}/share/scripts/jobutils.sh
13+
14+
# ----------- START ACTUAL JOB -----------------------------
15+
16+
NWORKERS=${NWORKERS:-8}
17+
MODULES="--skipModules ZDC"
18+
SIMENGINE=${SIMENGINE:-TGeant3}
19+
NSIGEVENTS=${NSIGEVENTS:-1}
20+
NBKGEVENTS=${NBKGEVENTS:-1}
21+
NTIMEFRAMES=${NTIMEFRAMES:-1}
22+
INTRATE=${INTRATE:-50000}
23+
SYSTEM=${SYSTEM:-pp}
24+
ENERGY=${ENERGY:-900}
25+
[[ ${SPLITID} != "" ]] && SEED="-seed ${SPLITID}" || SEED=""
26+
27+
echo $MODULES
28+
29+
# create workflow
30+
${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[2]=6." -e ${SIMENGINE} ${SEED} -mod "${MODULES}" \
31+
-ini ${O2DPG_ROOT}/MC/config/PWGLF/ini/GeneratorLFDeTrHe_${SYSTEM}.ini
32+
33+
# run workflow
34+
# allow increased timeframe parallelism with --cpu-limit 32
35+
${O2DPG_ROOT}/MC/bin/o2_dpg_workflow_runner.py -f workflow.json -tt aod --cpu-limit 32

0 commit comments

Comments
 (0)