Skip to content

Commit 73ba164

Browse files
authored
Add box generation for pythia + examples + fixes (#62)
* Add box generation for pythia + examples + fixes - Add seed to gun executable - Nuclei can be now be injected - Checking output of custom gen running - Checking that configuration entry has the generator entry - Update default config file with more examples * Allow gun of nuclei * Update AOD writer for nuclei
1 parent 8ff6738 commit 73ba164

6 files changed

Lines changed: 199 additions & 8 deletions

File tree

examples/aod/createO2tables.C

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ R__LOAD_LIBRARY(libDelphesO2)
1010
#include "TChain.h"
1111
#include "TClonesArray.h"
1212
#include "TRandom3.h"
13+
#include "TDatabasePDG.h"
1314

1415
// Delphes includes
1516
#include "ExRootAnalysis/ExRootTreeReader.h"
@@ -121,6 +122,9 @@ int createO2tables(const char* inputFile = "delphes.root",
121122
return 0;
122123
}
123124

125+
TDatabasePDG::Instance()->AddParticle("deuteron", "deuteron", 1.8756134, kTRUE, 0.0, 1, "Nucleus", 1000010020);
126+
TDatabasePDG::Instance()->AddAntiParticle("anti-deuteron", -1000010020);
127+
124128
if (do_vertexing) {
125129
o2::base::GeometryManager::loadGeometry();
126130
o2::base::Propagator::initFieldFromGRP("o2sim_grp.root");
@@ -494,7 +498,7 @@ int createO2tables(const char* inputFile = "delphes.root",
494498
FillTree(kEventsExtra);
495499
}
496500

497-
Printf("Writing tables for %i events", eventextra.fStart[kEvents]);
501+
Printf("Writing tables for %i events", eventextra.fStart[kEvents] + 1);
498502
TString out_dir = outputFile;
499503
out_dir.ReplaceAll(".root", "");
500504
out_dir.ReplaceAll("AODRun5.", "");

examples/scripts/createO2tables.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,9 @@ def do_copy(in_file, out_file):
192192

193193
custom_gen = opt("custom_gen", require=False)
194194
if custom_gen is None:
195+
# Checking that the generators are defined
196+
if opt("generators", require=False) is None:
197+
fatal_msg("Did not find any generator configuration corresponding to the entry", config_entry, "in your configuration file", configuration_file)
195198
generators = opt("generators").split(" ")
196199
for i in generators:
197200
do_copy(i, ".")
@@ -324,9 +327,9 @@ def copy_and_link(file_name):
324327
hepmc_file = f"hepmcfile.{run_number}.hepmc"
325328
custom_gen_option = f" --output {hepmc_file} --nevents {nevents} --seed {mc_seed}"
326329
write_to_runner(custom_gen + custom_gen_option,
327-
log_file=gen_log_file)
330+
log_file=gen_log_file, check_status=True)
328331
write_to_runner(f"DelphesHepMC propagate.tcl {delphes_file} {hepmc_file}",
329-
log_file=delphes_log_file)
332+
log_file=delphes_log_file, check_status=True)
330333
else: # Using DelphesPythia
331334
# copy generator configuration
332335
generator_cfg = f"generator.{run_number}.cfg"

examples/scripts/default_configfile.ini

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ sigmat = 0.020
1717
sigmat0 = 0.20
1818
## RICH
1919

20-
# radius [cm] used to compute the acceptance in eta (together with the detector length)
20+
# radius of the TOF/RICH [cm]
2121
radius = 100.
2222

23-
# half length [cm] used to compute the acceptance in eta (together with the detector radius)
23+
# half length of the TOF/RICH [cm]
2424
length = 200.
2525

2626
# path to the propagation card
@@ -66,6 +66,9 @@ generators = $O2DPG_ROOT/MC/config/common/pythia8/generator/pythia8_KrKr.cfg
6666
[GUN]
6767
custom_gen = rpythia8-gun --pdg 421 --px 1. --py 0. --pz 0. --xProd 0. --yProd 0. --zProd 0. --config $DELPHESO2_ROOT/examples/pythia8/decays/force_hadronic_D.cfg --decay
6868

69+
[BOX_deuteron]
70+
custom_gen = rpythia8-box --pdg 1000010020 --etamin -2. --etamax 2. --phimin 0. --phimax 3.14 --pmin 100 --pmax 1000 --xProd 0. --yProd 0. --zProd 0. --config $DELPHESO2_ROOT/examples/pythia8/decays/force_hadronic_D.cfg --decay --npart 100
71+
6972
[GUN_Lc_pKpi]
7073
custom_gen = rpythia8-gun --pdg 4122 --px 1. --py 0. --pz 0. --xProd 1. --yProd 0. --zProd 0. --config $O2DPG_ROOT/MC/config/PWGHF/pythia8/decayer/force_hadronic_D_forceLcChannel1.cfg --decay
7174

rpythia8/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,9 @@ target_link_libraries(rpythia8-gun
1919
${HepMC_LIBRARIES} ${Boost_LIBRARIES})
2020
install(TARGETS rpythia8-gun RUNTIME DESTINATION bin)
2121

22+
add_executable(rpythia8-box rpythia8-box.cc)
23+
target_link_libraries(rpythia8-box
24+
${Pythia_LIBRARIES}
25+
${HepMC_LIBRARIES} ${Boost_LIBRARIES})
26+
install(TARGETS rpythia8-box RUNTIME DESTINATION bin)
27+

rpythia8/rpythia8-box.cc

Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
#include <boost/program_options.hpp>
2+
#include <stdlib.h>
3+
#include <string>
4+
#include <time.h>
5+
6+
#include "Pythia8/Pythia.h"
7+
#include "Pythia8Plugins/HepMC2.h"
8+
9+
using namespace Pythia8;
10+
11+
int main(int argc, char **argv)
12+
{
13+
14+
int nevents, pdg, seed;
15+
std::string config, output, background_config;
16+
double eta_min, phi_min, p_min;
17+
double eta_max, phi_max, p_max;
18+
int npart;
19+
double xProd, yProd, zProd;
20+
bool verbose, decay;
21+
22+
/** process arguments **/
23+
namespace po = boost::program_options;
24+
po::options_description desc("Options");
25+
try {
26+
desc.add_options()
27+
("help", "Print help messages")
28+
("nevents,n", po::value<int>(&nevents)->default_value(10), "Number of events to be generated")
29+
("pdg,p", po::value<int>(&pdg)->required(), "PDG code of the particle")
30+
("npart", po::value<int>(&npart)->default_value(1), "Number of particles per event in a box")
31+
("etamin", po::value<double>(&eta_min)->default_value(0.), "Minimum eta")
32+
("etamax", po::value<double>(&eta_max)->default_value(0.), "Maximum eta")
33+
("phimin", po::value<double>(&phi_min)->default_value(0.), "Minimum phi")
34+
("phimax", po::value<double>(&phi_max)->default_value(0.), "Maximum phi")
35+
("pmin", po::value<double>(&p_min)->default_value(0.), "Minimum momentum")
36+
("pmax", po::value<double>(&p_max)->default_value(0.), "Maximum momentum")
37+
("xProd", po::value<double>(&xProd)->default_value(0.), "Production vertex in the x-direction")
38+
("yProd", po::value<double>(&yProd)->default_value(0.), "Production vertex in the y-direction")
39+
("zProd", po::value<double>(&zProd)->default_value(0.), "Production vertex in the z-direction")
40+
("config,c", po::value<std::string>(&config), "Configuration file")
41+
("background-config", po::value<std::string>(&background_config), "Background configuration file")
42+
("output,o", po::value<std::string>(&output)->default_value("pythia-gun.hepmc"), "Output HepMC file")
43+
("decay,D", po::bool_switch(&decay)->default_value(false), "Decay particle at production vertex")
44+
("verbose,V", po::bool_switch(&verbose)->default_value(false), "Verbose event listing")
45+
("seed", po::value<int>(&seed)->default_value(1), "initial seed")
46+
;
47+
48+
po::variables_map vm;
49+
po::store(po::parse_command_line(argc, argv, desc), vm);
50+
po::notify(vm);
51+
52+
if (vm.count("help")) {
53+
std::cout << desc << std::endl;
54+
return 1;
55+
}
56+
}
57+
catch(std::exception& e) {
58+
std::cerr << "Error: " << e.what() << std::endl;
59+
std::cout << desc << std::endl;
60+
return 1;
61+
}
62+
63+
HepMC::Pythia8ToHepMC ToHepMC;
64+
HepMC::IO_GenEvent ascii_io(output, std::ios::out);
65+
66+
// pythia
67+
Pythia pythia;
68+
69+
// check valid pdg code
70+
if (!pythia.particleData.isLepton(pdg) &&
71+
!pythia.particleData.isHadron(pdg) &&
72+
!pythia.particleData.isResonance(pdg)) {
73+
if (abs(pdg) < 1000000000) {
74+
std::cout << "Error: invalid PDG code \"" << pdg << "\"" << std::endl;
75+
return 1;
76+
} else {
77+
std::cout << "PDG code \"" << pdg << "\" stands for a nucleous" << std::endl;
78+
}
79+
}
80+
81+
// config
82+
pythia.readString("ProcessLevel:all = off");
83+
// pythia.readString("SoftQCD:elastic on");
84+
if (!config.empty() && !pythia.readFile(config)) {
85+
std::cout << "Error: could not read config file \"" << config << "\"" << std::endl;
86+
return 1;
87+
}
88+
89+
std::cout<<"Random:seed =" + std::to_string(seed)<<std::endl;
90+
pythia.readString("Random:setSeed = on");
91+
pythia.readString("Random:seed =" + std::to_string(seed));
92+
// init
93+
pythia.init();
94+
const double m = pythia.particleData.m0(pdg);
95+
96+
// the particle
97+
Particle particle;
98+
particle.id(pdg);
99+
particle.status(11);
100+
particle.m(m);
101+
particle.xProd(xProd);
102+
particle.yProd(yProd);
103+
particle.zProd(zProd);
104+
105+
// background interface
106+
Pythia8::Pythia *pythia_bkg = nullptr;
107+
if (!background_config.empty()) {
108+
std::cout << "Background: configure from " << background_config << std::endl;
109+
pythia_bkg = new Pythia8::Pythia;
110+
if (!pythia_bkg->readFile(background_config)) {
111+
std::cout << "Error: could not read config file \"" << background_config << "\"" << std::endl;
112+
return 1;
113+
}
114+
pythia_bkg->init();
115+
}
116+
117+
118+
119+
// event loop
120+
double eta, phi, p, pt, pl, e;
121+
srand (time(NULL));
122+
for (int iev = 0; iev < nevents; ++iev) {
123+
124+
// reset, add particle and decay
125+
pythia.event.reset();
126+
for(int ipart = 0; ipart < npart; ipart++){
127+
eta = eta_min + static_cast<float>(rand()) / (static_cast<float>(RAND_MAX / (eta_max - eta_min)));
128+
phi = phi_min + static_cast<float>(rand()) / (static_cast<float>(RAND_MAX / (phi_max - phi_min)));
129+
p = p_min + static_cast<float>(rand()) / (static_cast<float>(RAND_MAX / (p_max - p_min)));
130+
e = exp(2. * eta);
131+
pl = p * (e - 1.) / (1. + e);
132+
pt = sqrt(p * p - pl * pl);
133+
particle.e(sqrt(p * p + m * m));
134+
particle.px(pt * cos(phi));
135+
particle.py(pt * sin(phi));
136+
particle.pz(pl);
137+
pythia.event.append(particle);
138+
if (decay) pythia.moreDecays();
139+
pythia.next();
140+
}
141+
142+
// print verbose
143+
if (verbose) pythia.event.list(1);
144+
145+
// background
146+
if (pythia_bkg) {
147+
pythia_bkg->next();
148+
pythia.event += pythia_bkg->event;
149+
}
150+
151+
// write HepMC
152+
HepMC::GenEvent *hepmcevt = new HepMC::GenEvent();
153+
ToHepMC.fill_next_event(pythia, hepmcevt);
154+
ascii_io << hepmcevt;
155+
delete hepmcevt;
156+
}
157+
158+
// print statistics
159+
pythia.stat();
160+
if (pythia_bkg) {
161+
pythia_bkg->stat();
162+
delete pythia_bkg;
163+
}
164+
165+
return 0;
166+
167+
}

rpythia8/rpythia8-gun.cc

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ using namespace Pythia8;
99
int main(int argc, char **argv)
1010
{
1111

12-
int nevents, pdg;
12+
int nevents, pdg, seed;
1313
std::string config, output, background_config;
1414
double px, py, pz;
1515
double xProd, yProd, zProd;
@@ -34,6 +34,7 @@ int main(int argc, char **argv)
3434
("output,o", po::value<std::string>(&output)->default_value("pythia-gun.hepmc"), "Output HepMC file")
3535
("decay,D", po::bool_switch(&decay)->default_value(false), "Decay particle at production vertex")
3636
("verbose,V", po::bool_switch(&verbose)->default_value(false), "Verbose event listing")
37+
("seed", po::value<int>(&seed)->default_value(1), "initial seed")
3738
;
3839

3940
po::variables_map vm;
@@ -61,8 +62,12 @@ int main(int argc, char **argv)
6162
if (!pythia.particleData.isLepton(pdg) &&
6263
!pythia.particleData.isHadron(pdg) &&
6364
!pythia.particleData.isResonance(pdg)) {
64-
std::cout << "Error: invalid PDG code \"" << pdg << "\"" << std::endl;
65-
return 1;
65+
if (abs(pdg) < 1000000000) {
66+
std::cout << "Error: invalid PDG code \"" << pdg << "\"" << std::endl;
67+
return 1;
68+
} else {
69+
std::cout << "PDG code \"" << pdg << "\" stands for a nucleous" << std::endl;
70+
}
6671
}
6772

6873
// config
@@ -73,6 +78,9 @@ int main(int argc, char **argv)
7378
return 1;
7479
}
7580

81+
std::cout<<"Random:seed =" + std::to_string(seed)<<std::endl;
82+
pythia.readString("Random:setSeed = on");
83+
pythia.readString("Random:seed =" + std::to_string(seed));
7684
// init
7785
pythia.init();
7886
double m = pythia.particleData.m0(pdg);

0 commit comments

Comments
 (0)