Skip to content

Commit 977e9fa

Browse files
authored
Creating LUT before running AOD creation (#52)
- Other minor improvements: - check status of the command ran - add input arguments to summary file - add possibility to use the persistent LUTs - update gitignore
1 parent 9045189 commit 977e9fa

File tree

5 files changed

+95
-53
lines changed

5 files changed

+95
-53
lines changed

examples/aod/createO2tables.C

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -134,22 +134,11 @@ void createO2tables(const char* inputFile = "delphes.root",
134134

135135
// smearer
136136
o2::delphes::TrackSmearer smearer;
137-
if (Bz == 0.2) {
138-
smearer.loadTable(11, "lutCovm.el.2kG.dat");
139-
smearer.loadTable(13, "lutCovm.mu.2kG.dat");
140-
smearer.loadTable(211, "lutCovm.pi.2kG.dat");
141-
smearer.loadTable(321, "lutCovm.ka.2kG.dat");
142-
smearer.loadTable(2212, "lutCovm.pr.2kG.dat");
143-
} else if (Bz == 0.5) {
144-
smearer.loadTable(11, "lutCovm.el.5kG.dat");
145-
smearer.loadTable(13, "lutCovm.mu.5kG.dat");
146-
smearer.loadTable(211, "lutCovm.pi.5kG.dat");
147-
smearer.loadTable(321, "lutCovm.ka.5kG.dat");
148-
smearer.loadTable(2212, "lutCovm.pr.5kG.dat");
149-
} else {
150-
std::cout << " --- invalid Bz field: " << Bz << std::endl;
151-
return;
152-
}
137+
smearer.loadTable(11, "lutCovm.el.dat");
138+
smearer.loadTable(13, "lutCovm.mu.dat");
139+
smearer.loadTable(211, "lutCovm.pi.dat");
140+
smearer.loadTable(321, "lutCovm.ka.dat");
141+
smearer.loadTable(2212, "lutCovm.pr.dat");
153142

154143
// TOF layer
155144
o2::delphes::TOFLayer toflayer;

examples/scripts/.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,8 @@ tmpscript*.sh
1414
runner*.sh
1515
*.pyc
1616
__pycache__
17+
DetectorK.*
18+
create_libs.C
19+
create_luts.C
20+
fwdRes/fwdRes.C
21+
lutWrite*.cc

examples/scripts/clean.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,6 @@ rm dpl-config.json imgui.ini
1313
rm *.hepmc
1414
rm runner*.sh
1515
rm tmpscript*.sh
16+
rm lutWrite*.cc
17+
rm DetectorK.*
18+
rm -r fwdRes

examples/scripts/createO2tables.py

Lines changed: 79 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,30 @@ def fatal_msg(*args):
4848
raise ValueError("Fatal Error!")
4949

5050

51-
def run_cmd(cmd, comment=""):
51+
def run_cmd(cmd, comment="", check_status=True):
52+
"""
53+
Function to run a command in bash, allows to check the status of the command and to log the command output
54+
"""
5255
verbose_msg("Running", f"'{cmd}'", bcolors.BOKBLUE + comment)
5356
try:
54-
content = os.popen(cmd).read()
57+
to_run = cmd
58+
if check_status:
59+
to_run = f"{cmd} && echo OK"
60+
content = os.popen(to_run).read()
5561
if content:
62+
content = content.strip()
5663
verbose_msg("++", content.strip())
5764
if "Encountered error" in content:
5865
msg("[WARNING] Error encountered runtime in",
5966
cmd, color=bcolors.BWARNING)
67+
if check_status:
68+
if "OK" not in content and "root" not in cmd:
69+
msg("Error:\n",
70+
content, color=bcolors.FAIL)
71+
raise RuntimeError(
72+
"Command", cmd, "does not have the OK tag", content)
6073
except:
61-
fatal_msg("Error while running", cmd)
74+
fatal_msg("Error while running", f"'{cmd}'")
6275

6376

6477
def process_run(run_number):
@@ -82,14 +95,27 @@ def main(configuration_file,
8295
verbose,
8396
qa,
8497
output_path,
85-
clean_delphes_files):
98+
clean_delphes_files,
99+
create_luts):
86100
global verbose_mode
87101
verbose_mode = verbose
88102
parser = configparser.RawConfigParser()
89103
parser.read(configuration_file)
90104

91-
run_cmd("./clean.sh &> /dev/null")
92-
running_options = {} # Dictionary of fetched options
105+
run_cmd("./clean.sh &> /dev/null", check_status=False)
106+
# Dictionary of fetched options
107+
running_options = {
108+
"ARG configuration_file": configuration_file,
109+
"ARG config_entry": config_entry,
110+
"ARG njobs": njobs,
111+
"ARG nruns": nruns,
112+
"ARG nevents": nevents,
113+
"ARG verbose": verbose,
114+
"ARG qa": qa,
115+
"ARG output_path": output_path,
116+
"ARG clean_delphes_files": clean_delphes_files,
117+
"ARG create_luts": create_luts
118+
}
93119

94120
def opt(entry, require=True):
95121
try:
@@ -104,8 +130,8 @@ def opt(entry, require=True):
104130
return o
105131
except:
106132
if require:
107-
fatal_msg("Missing entry", entry,
108-
"in file", configuration_file)
133+
fatal_msg("Missing entry", f"'{entry}'",
134+
"in configuration file", f"'{configuration_file}'")
109135
return None
110136

111137
# Config from the config file
@@ -141,18 +167,32 @@ def do_copy(in_file, out_file):
141167
verbose_msg("Copying", in_file, "to", out_file)
142168
shutil.copy2(in_file, out_file)
143169

170+
# Fetching the propagation card
144171
do_copy(os.path.join(opt("card_path"),
145172
opt("propagate_card")),
146173
"propagate.tcl")
147174

148175
lut_path = opt("lut_path")
149176
lut_tag = opt("lut_tag")
150-
lut_particles = ["el", "mu", "pi", "ka", "pr"]
151-
for i in lut_particles:
152-
lut_bg = "{}kG".format(bField).replace(".", "")
153-
lut_n = f"lutCovm.{i}.{lut_bg}"
154-
do_copy(os.path.join(lut_path, f"{lut_n}.{lut_tag}.dat"),
155-
f"{lut_n}.dat")
177+
if create_luts:
178+
# Creating LUTs
179+
verbose_msg("Creating LUTs")
180+
lut_path = os.path.join(lut_path, "create_luts.sh")
181+
run_cmd(f"{lut_path} {lut_tag} {float(bField)*0.1} {radius} 2>&1",
182+
f"Creating the lookup tables with tag {lut_tag} from {lut_path} script")
183+
else:
184+
# Fetching LUTs
185+
verbose_msg(f"Fetching LUTs with tag {lut_tag} from path {lut_path}")
186+
for i in ["el", "mu", "pi", "ka", "pr"]:
187+
lut_bg = "{}kG".format(bField).replace(".", "")
188+
do_copy(os.path.join(lut_path, f"lutCovm.{i}.{lut_bg}.{lut_tag}.dat"),
189+
f"lutCovm.{i}.dat")
190+
191+
# Checking that we actually have LUTs
192+
for i in ["el", "mu", "pi", "ka", "pr"]:
193+
i = f"lutCovm.{i}.dat"
194+
if not os.path.isfile(i):
195+
fatal_msg("Did not find LUT file", i)
156196

157197
custom_gen = opt("custom_gen", require=False)
158198
if custom_gen is None:
@@ -171,17 +211,18 @@ def check_duplicate(option_name):
171211

172212
# Printing configuration
173213
msg(" --- running createO2tables.py", color=bcolors.HEADER)
174-
msg(" njobs = ", njobs)
175-
msg(" nruns = ", nruns)
176-
msg(" nevents = ", nevents)
214+
msg(" njobs = ", njobs)
215+
msg(" nruns = ", nruns)
216+
msg(" nevents = ", nevents)
217+
msg(" lut path = ", lut_path)
177218
msg(" --- with detector configuration", color=bcolors.HEADER)
178-
msg(" bField = ", bField, "\t[kG]")
179-
msg(" sigmaT = ", sigmaT, "\t[ns]")
180-
msg(" sigmaT0 = ", sigmaT0, "\t[ns]")
181-
msg(" radius = ", radius, "\t[cm]")
182-
msg(" length = ", length, "\t[cm]")
183-
msg(" LUT = ", lut_tag)
184-
msg(" etaMax = ", etaMax)
219+
msg(" bField = ", bField, "\t[kG]")
220+
msg(" sigmaT = ", sigmaT, "\t[ns]")
221+
msg(" sigmaT0 = ", sigmaT0, "\t[ns]")
222+
msg(" radius = ", radius, "\t[cm]")
223+
msg(" length = ", length, "\t[cm]")
224+
msg(" LUT = ", lut_tag)
225+
msg(" etaMax = ", etaMax)
185226

186227
aod_path = opt("aod_path")
187228
do_copy(os.path.join(aod_path, "createO2tables.h"), ".")
@@ -315,7 +356,7 @@ def copy_and_link(file_name):
315356
run_cmd("root -l -b -q 'createO2tables.C+(\"\")' &> /dev/null 2>&1",
316357
comment="to compile the table creator only once, before running")
317358
if not os.path.isfile("createO2tables_C.so"):
318-
run_cmd("root -l -b -q 'createO2tables.C+(\"\")'",
359+
run_cmd("root -l -b -q 'createO2tables.C+(\"\")' 2>&1",
319360
comment="to compile with full log")
320361
fatal_msg("'createO2tables.C' did not compile!")
321362
total_processing_time = time.time()
@@ -345,19 +386,19 @@ def copy_and_link(file_name):
345386
f.write(f"Finished at {dt_string}\n")
346387
f.write(f"Took {total_processing_time} seconds\n")
347388

348-
def write_config(entry):
349-
f.write(f"{entry[0]} = {entry[1]}\n")
389+
def write_config(entry, prefix=""):
390+
f.write(prefix + entry.strip("ARG ") +
391+
f" = {running_options[entry]}\n")
350392

351393
f.write("\n## Configuration ##\n")
352-
write_config(["- configuration_file", configuration_file])
353-
write_config(["- config_entry", config_entry])
354-
write_config(["- njobs", njobs])
355-
write_config(["- nruns", nruns])
356-
write_config(["- nevents", nevents])
394+
for i in running_options:
395+
if "ARG" in i:
396+
write_config(i, prefix=" - ")
357397

358398
f.write("\n## Options ##\n")
359399
for i in running_options:
360-
write_config([i, running_options[i]])
400+
if "ARG" not in i:
401+
write_config(i, prefix=" * ")
361402

362403
run_cmd("echo >> " + summaryfile)
363404
run_cmd("echo + DelphesO2 Version + >> " + summaryfile)
@@ -397,6 +438,9 @@ def write_config(entry):
397438
parser.add_argument("--clean-delphes", "-c",
398439
action="store_true",
399440
help="Option to clean the delphes files in output and keep only the AODs, by default everything is kept.")
441+
parser.add_argument("--use-preexisting-luts", "-l",
442+
action="store_true",
443+
help="Option to use preexisting LUTs instead of creating new ones, in this case LUTs with the requested tag are fetched from the LUT path. By default new LUTs are created at each run.")
400444
args = parser.parse_args()
401445
main(configuration_file=args.configuration_file,
402446
config_entry=args.entry,
@@ -406,4 +450,5 @@ def write_config(entry):
406450
verbose=args.verbose,
407451
output_path=args.output_path,
408452
clean_delphes_files=args.clean_delphes,
409-
qa=args.qa)
453+
qa=args.qa,
454+
create_luts=not args.use_preexisting_luts)

examples/scripts/default_configfile.ini

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ card_path = $DELPHESO2_ROOT/examples/cards/
2626
# path to the propagation card (tcl format)
2727
propagate_card = propagate.2kG.tcl
2828

29-
# path to the LUTs
30-
lut_path = $DELPHESO2_ROOT/examples/smearing/luts/
29+
# path to the LUT creation script or to the LUTs in case the creation is not required
30+
lut_path = $DELPHESO2_ROOT/examples/scripts/
3131

3232
# tag of the LUTs to use in simulation
33-
lut_tag = 20cm.scenario3
33+
lut_tag = scenario3
3434

3535
# path of the DELPHES aod utilities
3636
aod_path = $DELPHESO2_ROOT/examples/aod/

0 commit comments

Comments
 (0)