Skip to content

Commit 1ce8e05

Browse files
committed
Script for hybrid JSON template generation
1 parent f71a6b9 commit 1ce8e05

File tree

1 file changed

+112
-0
lines changed

1 file changed

+112
-0
lines changed

MC/bin/o2_hybrid_gen.py

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
#!/usr/bin/env python3
2+
3+
import argparse
4+
import json
5+
6+
def main():
7+
parser = argparse.ArgumentParser(description='Create a JSON file from command line flags.')
8+
parser.add_argument('--gen', type=str, nargs='+', required=True, help='List of generators to be used')
9+
parser.add_argument('--output', type=str, required=True, help='Output JSON file path')
10+
11+
args = parser.parse_args()
12+
13+
# put in a list all the elementes in the gen flag
14+
noConfGen = ["pythia8pp", "pythia8hf", "pythia8hi", "pythia8powheg"]
15+
gens = []
16+
for gen in args.gen:
17+
# if gen is equal to pythia8, then get the Pythia8GenConfig struct from GeneratorPythia8Param.h
18+
if gen == "pythia8":
19+
gens.append({
20+
'name': 'pythia8',
21+
'config': {
22+
"config": "$O2_ROOT/share/Generators/egconfig/pythia8_inel.cfg",
23+
"hooksFileName": "",
24+
"hooksFuncName": "",
25+
"includePartonEvent": False,
26+
"particleFilter": "",
27+
"verbose": 0
28+
}
29+
})
30+
elif gen == "external":
31+
gens.append({
32+
'name': 'external',
33+
'config': {
34+
"fileName": "${O2DPG_ROOT}/MC/config/PWGDQ/external/generator/GeneratorParamPromptJpsiToElectronEvtGen_pp13TeV.C",
35+
"funcName": "GeneratorParamPromptJpsiToElectronEvtGen_pp13TeV()"
36+
}
37+
})
38+
elif gen == "extkinO2":
39+
gens.append({
40+
'name': 'extkinO2',
41+
'config': {
42+
"skipNonTrackable": True,
43+
"continueMode": False,
44+
"roundRobin": False,
45+
"randomize": False,
46+
"rngseed": 0,
47+
"randomphi": False,
48+
"fileName": "/path/to/filename.root"
49+
}
50+
})
51+
elif gen == "hepmc":
52+
gens.append({
53+
"name": "hepmc",
54+
"config": {
55+
"configcmd": {
56+
"fileNames": "",
57+
"cmd": ""
58+
},
59+
"confighepmc": {
60+
"version": 2,
61+
"eventsToSkip": 0,
62+
"fileName": "/path/to/filename.hepmc",
63+
"prune": False
64+
}
65+
}
66+
})
67+
elif gen == "boxgen":
68+
gens.append({
69+
"name": "boxgen",
70+
"config": {
71+
"pdg": 13,
72+
"number": 1,
73+
"eta": [
74+
-4,
75+
-2.5
76+
],
77+
"prange": [
78+
0.1,
79+
5
80+
],
81+
"phirange": [
82+
0,
83+
360
84+
]
85+
}
86+
})
87+
elif gen in noConfGen:
88+
gens.append({
89+
"name": gen,
90+
"config": ""
91+
})
92+
else:
93+
print(f"Generator {gen} not found in the list of available generators")
94+
exit(1)
95+
96+
# fill fractions with 1 for each generator
97+
fractions = [1] * len(gens)
98+
99+
# Put gens and fractions in the data dictionary
100+
data = {
101+
"generators": gens,
102+
"fractions": fractions
103+
}
104+
105+
# Write the data dictionary to a JSON file
106+
with open(args.output, 'w') as f:
107+
json.dump(data, f, indent=2)
108+
109+
print(f"JSON file created at {args.output}")
110+
111+
if __name__ == "__main__":
112+
main()

0 commit comments

Comments
 (0)