Skip to content

Commit c64a8f8

Browse files
committed
Update JSON template script for Hybrid generator
1 parent dbbf327 commit c64a8f8

File tree

1 file changed

+122
-75
lines changed

1 file changed

+122
-75
lines changed

MC/bin/o2_hybrid_gen.py

Lines changed: 122 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -3,107 +3,154 @@
33
# This script creates a template JSON file for the configuration of the hybrid generator
44
# The generators to be used are passed as a list of strings via the --gen flag, while the
55
# output filename is set using --output. All the generators available in O2sim are supported.
6+
# Alternatively the --iniFile flag can be used to specify external generators that are configured
7+
# with ini files. The --clone flag allows the user to create multiple instances of the generator list,
8+
# which is a useful feature when running multi-threaded event pool. This can be enabled via setting
9+
# the --mode flag to 'parallel', which is set "sequential" by default.
610
# Example:
7-
# $O2DPG_ROOT/MC/bin/o2_hybrid_gen.py --gen pythia8 boxgen external extkinO2 hepmc pythia8hf \
8-
# --output config.json
11+
# $O2DPG_ROOT/MC/bin/o2_hybrid_gen.py --gen pythia8 boxgen external extkinO2 hepmc pythia8hf --clone 2 \
12+
# --output config.json --mode parallel --iniFile /path/to/file0.ini /path/to/file1.ini
913

1014
import argparse
1115
import json
1216

1317
def main():
1418
parser = argparse.ArgumentParser(description='Create a JSON file from command line flags.')
15-
parser.add_argument('--gen', type=str, nargs='+', required=True, help='List of generators to be used')
19+
parser.add_argument('--gen', type=str, nargs='+', help='List of generators to be used')
20+
parser.add_argument('--iniFile', type=str, nargs='+', help='List of external generators configured with ini files')
21+
parser.add_argument('--mode', type=str, help='Run generator in sequential or parallel mode for quicker event generation (multi-threading)')
1622
parser.add_argument('--output', type=str, required=True, help='Output JSON file path')
23+
parser.add_argument('--clone', type=int, help='Number of clones to make of the generator list')
1724

1825
args = parser.parse_args()
1926

27+
# Check if the mode is valid
28+
mode = "sequential"
29+
if args.mode not in ["sequential", "parallel"]:
30+
print(f"Mode {args.mode} not valid. Please use 'seq' or 'par'")
31+
print("Setting sequential mode as default")
32+
else:
33+
print(f"Running in {args.mode} mode")
34+
mode = args.mode
35+
2036
# put in a list all the elementes in the gen flag
2137
noConfGen = ["pythia8pp", "pythia8hf", "pythia8hi", "pythia8powheg"]
2238
gens = []
23-
for gen in args.gen:
24-
if gen == "pythia8":
25-
gens.append({
26-
'name': 'pythia8',
27-
'config': {
28-
"config": "$O2_ROOT/share/Generators/egconfig/pythia8_inel.cfg",
29-
"hooksFileName": "",
30-
"hooksFuncName": "",
31-
"includePartonEvent": False,
32-
"particleFilter": "",
33-
"verbose": 0
34-
}
35-
})
36-
elif gen == "external":
39+
if args.gen is None and args.iniFile is None:
40+
print("No generators specified")
41+
exit(1)
42+
if args.gen:
43+
print(f"Generators to be used: {args.gen}")
44+
for gen in args.gen:
45+
if gen == "pythia8":
46+
gens.append({
47+
'name': 'pythia8',
48+
'config': {
49+
"config": "$O2_ROOT/share/Generators/egconfig/pythia8_inel.cfg",
50+
"hooksFileName": "",
51+
"hooksFuncName": "",
52+
"includePartonEvent": False,
53+
"particleFilter": "",
54+
"verbose": 0
55+
}
56+
})
57+
elif gen == "external":
58+
gens.append({
59+
'name': 'external',
60+
'config': {
61+
"fileName": "${O2DPG_ROOT}/MC/config/PWGDQ/external/generator/GeneratorParamPromptJpsiToElectronEvtGen_pp13TeV.C",
62+
"funcName": "GeneratorParamPromptJpsiToElectronEvtGen_pp13TeV()",
63+
"iniFile": ""
64+
}
65+
})
66+
elif gen == "extkinO2":
67+
gens.append({
68+
'name': 'extkinO2',
69+
'config': {
70+
"skipNonTrackable": True,
71+
"continueMode": False,
72+
"roundRobin": False,
73+
"randomize": False,
74+
"rngseed": 0,
75+
"randomphi": False,
76+
"fileName": "/path/to/filename.root"
77+
}
78+
})
79+
elif gen == "hepmc":
80+
gens.append({
81+
"name": "hepmc",
82+
"config": {
83+
"configcmd": {
84+
"fileNames": "",
85+
"cmd": ""
86+
},
87+
"confighepmc": {
88+
"version": 2,
89+
"eventsToSkip": 0,
90+
"fileName": "/path/to/filename.hepmc",
91+
"prune": False
92+
}
93+
}
94+
})
95+
elif gen == "boxgen":
96+
gens.append({
97+
"name": "boxgen",
98+
"config": {
99+
"pdg": 13,
100+
"number": 1,
101+
"eta": [
102+
-4,
103+
-2.5
104+
],
105+
"prange": [
106+
0.1,
107+
5
108+
],
109+
"phirange": [
110+
0,
111+
360
112+
]
113+
}
114+
})
115+
elif gen in noConfGen:
116+
gens.append({
117+
"name": gen,
118+
"config": ""
119+
})
120+
else:
121+
print(f"Generator {gen} not found in the list of available generators")
122+
exit(1)
123+
124+
if args.iniFile:
125+
print(f"External generators to be used: {args.iniFile}")
126+
for ini in args.iniFile:
127+
if ".ini" != ini[-4:]:
128+
print(f"File {ini} is not an ini file")
129+
exit(1)
37130
gens.append({
38131
'name': 'external',
39132
'config': {
40-
"fileName": "${O2DPG_ROOT}/MC/config/PWGDQ/external/generator/GeneratorParamPromptJpsiToElectronEvtGen_pp13TeV.C",
41-
"funcName": "GeneratorParamPromptJpsiToElectronEvtGen_pp13TeV()"
42-
}
43-
})
44-
elif gen == "extkinO2":
45-
gens.append({
46-
'name': 'extkinO2',
47-
'config': {
48-
"skipNonTrackable": True,
49-
"continueMode": False,
50-
"roundRobin": False,
51-
"randomize": False,
52-
"rngseed": 0,
53-
"randomphi": False,
54-
"fileName": "/path/to/filename.root"
133+
"fileName": "",
134+
"funcName": "",
135+
"iniFile": ini
55136
}
56137
})
57-
elif gen == "hepmc":
58-
gens.append({
59-
"name": "hepmc",
60-
"config": {
61-
"configcmd": {
62-
"fileNames": "",
63-
"cmd": ""
64-
},
65-
"confighepmc": {
66-
"version": 2,
67-
"eventsToSkip": 0,
68-
"fileName": "/path/to/filename.hepmc",
69-
"prune": False
70-
}
71-
}
72-
})
73-
elif gen == "boxgen":
74-
gens.append({
75-
"name": "boxgen",
76-
"config": {
77-
"pdg": 13,
78-
"number": 1,
79-
"eta": [
80-
-4,
81-
-2.5
82-
],
83-
"prange": [
84-
0.1,
85-
5
86-
],
87-
"phirange": [
88-
0,
89-
360
90-
]
91-
}
92-
})
93-
elif gen in noConfGen:
94-
gens.append({
95-
"name": gen,
96-
"config": ""
97-
})
138+
139+
if args.clone:
140+
if args.clone < 2:
141+
print("The cloning value must be greater than 1")
142+
print("Skipping procedure...")
98143
else:
99-
print(f"Generator {gen} not found in the list of available generators")
100-
exit(1)
144+
print(f"Cloning the generator list {args.clone} times")
145+
gens = gens * args.clone
146+
101147

102148
# fill fractions with 1 for each generator
103149
fractions = [1] * len(gens)
104150

105151
# Put gens and fractions in the data dictionary
106152
data = {
153+
"mode": mode,
107154
"generators": gens,
108155
"fractions": fractions
109156
}

0 commit comments

Comments
 (0)