Skip to content

Commit 7d9e713

Browse files
committed
Enable usage of Graniitti MC generator
1 parent dee46f6 commit 7d9e713

File tree

4 files changed

+391
-0
lines changed

4 files changed

+391
-0
lines changed
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
// usage: o2-sim -n 100 -g external --configKeyValues 'GeneratorExternal.fileName=GeneratorGraniitti.C;GeneratorExternal.funcName=GeneratorGraniitti("kDiTau")'
2+
3+
namespace o2 {
4+
namespace eventgen {
5+
class GeneratorGraniitti_class : public Generator {
6+
public:
7+
GeneratorGraniitti_class() { };
8+
~GeneratorGraniitti_class() = default;
9+
bool setJsonFile(std::string fname) {
10+
jsonFile = fname;
11+
// check if jsonFile exists
12+
if (gSystem->AccessPathName(jsonFile.c_str())) {
13+
return false;
14+
}
15+
16+
return setHepMCFile();
17+
}
18+
19+
bool setHepMCFile() {
20+
// item "OUTPUT" defines the hepmcFile
21+
// find
22+
// "OUTPUT" : hepmcFile
23+
std::string cmd = "grep \"OUTPUT\" "+jsonFile;
24+
auto res = gSystem->GetFromPipe(cmd.c_str());
25+
auto lines = res.Tokenize("\n");
26+
if (lines->GetEntries() != 1) {
27+
return false;
28+
}
29+
30+
auto parts = ((TObjString*)lines->At(0))->GetString().Tokenize(":");
31+
if (parts->GetEntries() != 2) {
32+
return false;
33+
}
34+
35+
auto fname = ((TObjString*)parts->At(1))->GetString();
36+
hepmcFile =(std::string)fname.ReplaceAll("\"", "").ReplaceAll(",", "") + ".hepmc3";
37+
return true;
38+
}
39+
40+
bool createHepMCFile() {
41+
// run graniitti with
42+
// jsonFile as input
43+
auto cmd = "$Graniitti_ROOT/bin/gr -i " + jsonFile;
44+
std::cout << "Generating events ...";
45+
auto res = gSystem->GetFromPipe(cmd.c_str());
46+
std::cout << "done!\n";
47+
48+
// check res to be ok
49+
50+
return true;
51+
}
52+
53+
void openHepMCFile() {
54+
reader = new o2::eventgen::GeneratorHepMC();
55+
reader->setFileNames(hepmcFile);
56+
if (!reader->Init())
57+
{
58+
std::cout << "GenerateEvent: Graniitti class/object not properly initialized"
59+
<< std::endl;
60+
}
61+
};
62+
63+
bool generateEvent() override {
64+
return reader->generateEvent();
65+
};
66+
67+
bool importParticles() override {
68+
mParticles.clear();
69+
if (!reader->importParticles()) {
70+
return false;
71+
}
72+
printParticles();
73+
74+
return true;
75+
};
76+
77+
void printParticles()
78+
{
79+
std::cout << "\n\n";
80+
for (auto& particle : reader->getParticles())
81+
particle.Print();
82+
}
83+
84+
private:
85+
o2::eventgen::GeneratorHepMC *reader = 0x0;
86+
std::string jsonFile;
87+
std::string hepmcFile;
88+
89+
};
90+
91+
} // namespace eventgen
92+
} // namespace o2
93+
94+
FairGenerator* GeneratorGraniitti(std::string jsonFile) {
95+
96+
// create generator
97+
auto gen = new o2::eventgen::GeneratorGraniitti_class();
98+
if (gen->setJsonFile(jsonFile)) {
99+
if (gen->createHepMCFile()) {
100+
// preparing reader
101+
gen->openHepMCFile();
102+
}
103+
}
104+
105+
return gen;
106+
}
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
#! /usr/bin/env python3
2+
3+
### @author: Paul Buehler
4+
### @email: paul.buhler@cern.ch
5+
6+
import argparse
7+
import os
8+
import subprocess
9+
10+
def createJson(args):
11+
templateFile = os.getenv("O2DPG_ROOT")+"/MC/config/PWGUD/templates/ALICE_Graniitti.temp"
12+
jsonFile = "ALICE_Graniitti.json"
13+
processes = {
14+
"kCon_pipi" : {
15+
"OUTPUT" : "ALICE_Con_pipi",
16+
"ENERGY" : 13600,
17+
"PROCESS" : "PP[RES+CON]<C> -> pi+ pi-",
18+
"RES" : ""
19+
},
20+
"kConRes_pipi" : {
21+
"OUTPUT" : "ALICE_Con_pipi",
22+
"ENERGY" : 13600,
23+
"PROCESS" : "PP[RES+CON]<C> -> pi+ pi-",
24+
"RES" : '["f0_500", "rho_770", "f0_980", "phi_1020", "f2_1270", "f0_1500", "f2_1525", "f0_1710", "f2_2150"]'
25+
},
26+
"kCon_KK" : {
27+
"OUTPUT" : "ALICE_Con_pipi",
28+
"ENERGY" : 13600,
29+
"PROCESS" : "PP[RES+CON]<C> -> pi+ pi-",
30+
"RES" : ""
31+
},
32+
"kConRes_KK" : {
33+
"OUTPUT" : "ALICE_Con_pipi",
34+
"ENERGY" : 13600,
35+
"PROCESS" : "PP[RES+CON]<C> -> pi+ pi-",
36+
"RES" : '["f0_500", "rho_770", "f0_980", "phi_1020", "f2_1270", "f0_1500", "f2_1525", "f0_1710", "f2_2150"]'
37+
}
38+
}
39+
40+
# is process defined?
41+
if not args.process in processes.keys():
42+
print("FATAL ERROR: ")
43+
print(" Process ", args.process)
44+
print(" is not defined!")
45+
exit()
46+
procdefs = processes[args.process]
47+
48+
# copy templateFile to jsonFile
49+
cmd = "cp "+templateFile+" "+jsonFile
50+
if subprocess.call(cmd, shell=True) > 0:
51+
print("FATAL ERROR: ")
52+
print(" ", templateFile)
53+
print(" can not be copied to")
54+
print(" ", jsonFile)
55+
exit()
56+
57+
# update jsonFile
58+
stat = 0
59+
# OUTPUT
60+
nl = ' "OUTPUT" : "' + procdefs["OUTPUT"] + '",'
61+
cmd = "sed -i '/\"OUTPUT\"/c\\" + nl + "' " + jsonFile
62+
stat = stat + subprocess.call(cmd, shell=True)
63+
# NEVENTS
64+
nl = ' "NEVENTS" : ' + args.nEvents + ','
65+
cmd = "sed -i '/\"NEVENTS\"/c\\" + nl + "' " + jsonFile
66+
stat = stat + subprocess.call(cmd, shell=True)
67+
# ENERGY
68+
beamEne = str(int(args.eCM)/2)
69+
nl = ' "ENERGY" : [' + beamEne + ', ' + beamEne + '],'
70+
cmd = "sed -i '/\"ENERGY\"/c\\" + nl + "' " + jsonFile
71+
stat = stat + subprocess.call(cmd, shell=True)
72+
# PROCESS
73+
nl = ' "PROCESS" : "' + procdefs["PROCESS"] + '",'
74+
cmd = "sed -i '/\"PROCESS\"/c\\" + nl + "' " + jsonFile
75+
stat = stat + subprocess.call(cmd, shell=True)
76+
# RES
77+
if procdefs["RES"] == "":
78+
nl = ' "//RES" :'
79+
else:
80+
nl = ' "RES" : ' + procdefs["RES"] + ','
81+
cmd = "sed -i '/\"RES\"/c\\" + nl + "' " + jsonFile
82+
stat = stat + subprocess.call(cmd, shell=True)
83+
84+
return jsonFile
85+
86+
# main
87+
88+
parser = argparse.ArgumentParser(description='Make Graniitti configuration',
89+
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
90+
91+
parser.add_argument('--process',default=None, choices=['kCon_pipi', 'kConRes_pipi', 'kCon_KK', 'kConRes_KK'],
92+
help='Process to switch on')
93+
94+
parser.add_argument('--nEvents', default='100',
95+
help='Number of events to generate per TF')
96+
97+
parser.add_argument('--eCM', type=float, default='13600',
98+
help='Centre-of-mass energy')
99+
100+
parser.add_argument('--rapidity', default='cent', choices=['cent_eta', 'muon_eta'],
101+
help='Rapidity to select')
102+
103+
parser.add_argument('--output', default='GenGraniitti.ini',
104+
help='Where to write the configuration')
105+
106+
args = parser.parse_args()
107+
108+
### prepare the json configuration file for graniitti
109+
jsonFile = createJson(args)
110+
111+
### open output file
112+
fout = open(args.output, 'w')
113+
114+
### Generator
115+
fout.write('[GeneratorExternal] \n')
116+
fout.write('fileName = ${O2DPG_ROOT}/MC/config/PWGUD/external/generator/GeneratorGraniitti.C \n')
117+
fout.write('funcName = GeneratorGraniitti("%s") \n' % ("../"+jsonFile))
118+
119+
###Trigger
120+
fout.write('[TriggerExternal] \n')
121+
fout.write('fileName = ${O2DPG_ROOT}/MC/config/PWGUD/trigger/selectParticlesInAcceptance.C \n')
122+
if args.rapidity == 'cent_rap':
123+
fout.write('funcName = selectMotherPartInAcc(-0.9,0.9) \n')
124+
if args.rapidity == 'muon_rap':
125+
fout.write('funcName = selectMotherPartInAcc(-4.0,-2.5) \n')
126+
if args.rapidity == 'cent_eta':
127+
fout.write('funcName = selectDaughterPartInAcc(-0.95,0.95) \n')
128+
if args.rapidity == 'muon_eta':
129+
fout.write('funcName = selectDaughterPartInAcc(-4.05,-2.45) \n')
130+
131+
### close outout file
132+
fout.close()
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
// JSON(5) + single line/multiline comments allowed, trailing comma allowed
2+
//
3+
// The format is strictly upper/lower case sensitive.
4+
//
5+
// mikael.mieskolainen@cern.ch, 2021
6+
{
7+
8+
// ----------------------------------------------------------------------
9+
// GENERAL setup
10+
11+
"GENERALPARAM" : {
12+
13+
"OUTPUT" :
14+
"FORMAT" : "hepmc3", // hepmc3, hepmc2, hepevt
15+
"CORES" : 0, // Number of CPU threads (0 for automatic)
16+
"NEVENTS" :
17+
"INTEGRATOR" : "VEGAS", // Integrator (VEGAS, FLAT)
18+
"WEIGHTED" : false, // Weighted events (default false)
19+
"MODELPARAM" : "TUNE0" // General model tune
20+
},
21+
22+
// ----------------------------------------------------------------------
23+
// Process setup
24+
25+
"PROCESSPARAM" : {
26+
27+
"BEAM" : ["p+","p+"], // Beam PDG-ID / Name
28+
"ENERGY" :
29+
"PROCESS" :
30+
"RES" :
31+
"POMLOOP" : false, // Eikonal Pomeron loop screening
32+
"NSTARS" : 0, // N* excitation (0 = elastic, 1 = single, 2 = double)
33+
"LHAPDF" : "CT10nlo", // LHAPDF parton distribution set
34+
"HIST" : 0, // On-the-flight histograms (0 = off,1,2)
35+
"RNDSEED" : 0, // Random seed (uint)
36+
},
37+
38+
// ----------------------------------------------------------------------
39+
// Monte Carlo integrator setup
40+
41+
"INTEGRALPARAM" : {
42+
43+
// Loop integration
44+
"POMLOOP" : {
45+
"ND" : 0, // Integral discretization [larger -> more discrete] (0 gives default discretization) (int)
46+
},
47+
48+
// VEGAS integrator
49+
"VEGAS" : {
50+
51+
"BINS" : 512, // Maximum number of bins per dimension (NOTE: EVEN NUMBER)
52+
"LAMBDA" : 1.25, // Regularization parameter
53+
"NCALL" : 40000, // Number of function calls per iteration (5000 .. 50000 or more)
54+
"ITER" : 50, // Number of initialization iteration (10 or more)
55+
"CHI2MAX" : 10.0, // Maximum Chi^2 in initialization
56+
"PRECISION" : 0.05, // Integral relative precision target
57+
58+
"DEBUG" : -1 // Debug output (default -1)
59+
},
60+
61+
// FLAT integrator
62+
"FLAT" : {
63+
64+
"PRECISION" : 0.01, // Integral relative precision
65+
"MIN_EVENTS" : 1000000 // Minimum number of events to be sampled
66+
}
67+
},
68+
69+
70+
// ----------------------------------------------------------------------
71+
// Generation cuts
72+
73+
"GENCUTS" : {
74+
75+
"<C>" : {
76+
"Rap" : [-1.0, 1.0] // Rapidity boundaries of the final states (<C> class)
77+
},
78+
"<F>" : {
79+
"Rap" : [-2.0, 2.0], // Rapidity boundaries of the system (<F> class)
80+
"M" : [ 0.0, 5.0]
81+
},
82+
"<Q>" : {
83+
"Xi" : [0.0, 0.05] // Invariant scale M^2/s (forward excitation)
84+
}
85+
},
86+
87+
88+
// ----------------------------------------------------------------------
89+
// Central system fiducial cuts
90+
// All central system particles need to fullfill the conditions
91+
92+
"FIDCUTS" : {
93+
94+
"active" : false,
95+
96+
// Central system final states
97+
"PARTICLE" : {
98+
99+
"Eta" : [-1.0, 1.0], // Pseudorapidity
100+
"Rap" : [-10.0, 10.0], // Rapidity
101+
"Pt" : [0.1, 100000.0], // Transverse momentum
102+
"Et" : [0.0, 100000.0] // Transverse energy
103+
},
104+
105+
// Central system
106+
"SYSTEM" : {
107+
108+
"M" : [0.0, 100000.0], // Mass
109+
"Rap" : [-10.0, 10.0], // Rapidity
110+
"Pt" : [0.0, 100000.0] // Transverse momentum
111+
},
112+
113+
// Forward system
114+
"FORWARD" : {
115+
"M" : [0.0, 100000.0], // Mass
116+
"t" : [0.0, 100000.0], // Forward protons/N* Mandelstam t (absolute value) (GeV^2)
117+
},
118+
119+
// Custom user cuts (default false, otherwise identifier ID)
120+
"USERCUTS" : false
121+
}
122+
123+
}

MC/run/PWGUD/runGraniittiANCHOR.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Run as: ${O2DPG_ROOT}/GRID/utils/grid_submit.sh --script ./runGraniittiANCHOR.sh --jobname SLtest --outputspec "*.log@disk=1","*.root@disk=2" --packagespec "VO_ALICE@O2sim::v20240626-1" --wait --fetch-output --asuser pbuhler --local
2+
3+
export ALIEN_JDL_LPMANCHORPASSNAME=apass4
4+
export ALIEN_JDL_MCANCHOR=apass4
5+
export ALIEN_JDL_COLLISIONSYSTEM=pp
6+
export ALIEN_JDL_CPULIMIT=8
7+
export ALIEN_JDL_LPMPASSNAME=apass4
8+
export ALIEN_JDL_LPMRUNNUMBER=535084
9+
export ALIEN_JDL_LPMPRODUCTIONTYPE=MC
10+
export ALIEN_JDL_LPMINTERACTIONTYPE=PbPb
11+
export ALIEN_JDL_LPMPRODUCTIONTAG=MyPass2Test
12+
export ALIEN_JDL_LPMANCHORRUN=535084
13+
export ALIEN_JDL_LPMANCHORPRODUCTION=LHC23f
14+
export ALIEN_JDL_LPMANCHORYEAR=2023
15+
16+
export NTIMEFRAMES=2
17+
export NSIGEVENTS=100
18+
export NBKGEVENTS=1
19+
export SPLITID=20
20+
export PRODSPLIT=100
21+
export CYCLE=30
22+
export ALIEN_PROC_ID=2963436952
23+
24+
25+
#export ALIEN_JDL_ANCHOR_SIM_OPTIONS="-gen external -ini ${PWD}/GenGraniitti.ini --embedding -nb ${NBKGEVENTS} -colBkg PbPb -genBkg pythia8 -procBkg heavy_ion"
26+
27+
${O2DPG_ROOT}/MC/config/PWGUD/ini/makeGraniittiConfig.py --process kConRes_pipi --eCM 13600 --nEvents 300 --rapidity cent_eta
28+
export ALIEN_JDL_ANCHOR_SIM_OPTIONS="-gen external -ini ${PWD}/GenGraniitti.ini"
29+
30+
${O2DPG_ROOT}/MC/run/ANCHOR/anchorMC.sh

0 commit comments

Comments
 (0)