Skip to content

Commit b50d3de

Browse files
authored
Enable usage of Graniitti MC generator in O2 simulations (#1818)
* Enable usage of Graniitti MC generator * Update GeneratorUpcgen.C * Update makeGraniittiConfig.py
1 parent 73425a3 commit b50d3de

File tree

5 files changed

+390
-1
lines changed

5 files changed

+390
-1
lines changed
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
namespace o2 {
2+
namespace eventgen {
3+
class GeneratorGraniitti_class : public Generator {
4+
public:
5+
GeneratorGraniitti_class() { };
6+
~GeneratorGraniitti_class() = default;
7+
bool setJsonFile(std::string fname) {
8+
jsonFile = fname;
9+
// check if jsonFile exists
10+
if (gSystem->AccessPathName(jsonFile.c_str())) {
11+
return false;
12+
}
13+
14+
return setHepMCFile();
15+
}
16+
17+
bool setHepMCFile() {
18+
// item "OUTPUT" defines the hepmcFile
19+
// find
20+
// "OUTPUT" : hepmcFile
21+
std::string cmd = "grep \"OUTPUT\" "+jsonFile;
22+
auto res = gSystem->GetFromPipe(cmd.c_str());
23+
auto lines = res.Tokenize("\n");
24+
if (lines->GetEntries() != 1) {
25+
return false;
26+
}
27+
28+
auto parts = ((TObjString*)lines->At(0))->GetString().Tokenize(":");
29+
if (parts->GetEntries() != 2) {
30+
return false;
31+
}
32+
33+
auto fname = ((TObjString*)parts->At(1))->GetString();
34+
hepmcFile = std::string(gSystem->Getenv("PWD"))+"/"+(std::string)fname.ReplaceAll("\"", "").ReplaceAll(",", "").ReplaceAll(" ", "")+".hepmc3";
35+
return true;
36+
}
37+
38+
bool createHepMCFile() {
39+
// run graniitti with
40+
// jsonFile as input
41+
auto cmd = "$Graniitti_ROOT/bin/gr -i " + jsonFile;
42+
std::cout << "Generating events ...";
43+
auto res = gSystem->GetFromPipe(cmd.c_str());
44+
std::cout << "done!\n";
45+
46+
// check res to be ok
47+
48+
return true;
49+
}
50+
51+
void openHepMCFile() {
52+
reader = new o2::eventgen::GeneratorHepMC();
53+
reader->setFileNames(hepmcFile);
54+
if (!reader->Init())
55+
{
56+
std::cout << "GenerateEvent: Graniitti class/object not properly initialized"
57+
<< std::endl;
58+
}
59+
};
60+
61+
bool generateEvent() override {
62+
return reader->generateEvent();
63+
};
64+
65+
bool importParticles() override {
66+
mParticles.clear();
67+
if (!reader->importParticles()) {
68+
return false;
69+
}
70+
printParticles();
71+
72+
return true;
73+
};
74+
75+
void printParticles()
76+
{
77+
std::cout << "\n\n";
78+
for (auto& particle : reader->getParticles())
79+
particle.Print();
80+
}
81+
82+
private:
83+
o2::eventgen::GeneratorHepMC *reader = 0x0;
84+
std::string jsonFile;
85+
std::string hepmcFile;
86+
87+
};
88+
89+
} // namespace eventgen
90+
} // namespace o2
91+
92+
FairGenerator* GeneratorGraniitti(std::string jsonFile) {
93+
94+
// create generator
95+
auto gen = new o2::eventgen::GeneratorGraniitti_class();
96+
if (gen->setJsonFile(jsonFile)) {
97+
if (gen->createHepMCFile()) {
98+
// preparing reader
99+
gen->openHepMCFile();
100+
}
101+
}
102+
103+
return gen;
104+
}

MC/config/PWGUD/external/generator/GeneratorUpcgen.C

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
R__LOAD_LIBRARY(libUpcgenlib.so)
2-
R__ADD_INCLUDE_PATH($upcgen_ROOT/include)
2+
R__ADD_INCLUDE_PATH($Upcgen_ROOT/include)
33

44
#include "UpcGenerator.h"
55

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)