Skip to content

Commit f3e6ad3

Browse files
authored
Extend analysis tools and LUT creation routine (#86)
- Configure analysis workflows from config file - Update workflows - Add option for nuclei when creating AODs - Extend LUT creator, add possibility to set path, particles and outputpath
1 parent a365645 commit f3e6ad3

File tree

6 files changed

+191
-102
lines changed

6 files changed

+191
-102
lines changed

examples/aod/createO2tables.C

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ const char* inputFileAccMuonPID = "muonAccEffPID.root";
5757

5858
// Simulation parameters
5959
const bool do_vertexing = true;
60+
const bool enable_nuclei = false;
6061

6162
int createO2tables(const char* inputFile = "delphes.root",
6263
const char* outputFile = "AODRun5.root",
@@ -98,6 +99,10 @@ int createO2tables(const char* inputFile = "delphes.root",
9899
smearer.loadTable(211, "lutCovm.pi.dat");
99100
smearer.loadTable(321, "lutCovm.ka.dat");
100101
smearer.loadTable(2212, "lutCovm.pr.dat");
102+
if (enable_nuclei) {
103+
smearer.loadTable(1000010020, "lutCovm.de.dat");
104+
smearer.loadTable(1000020030, "lutCovm.he3.dat");
105+
}
101106

102107
// TOF layer
103108
o2::delphes::TOFLayer tof_layer;
@@ -356,7 +361,7 @@ int createO2tables(const char* inputFile = "delphes.root",
356361
std::array<float, 2> ftzero;
357362

358363
forward_tof_layer.eventTime(ftof_tracks, ftzero);
359-
for (int i = 0; i < ftof_tracks.size(); i++) {
364+
for (unsigned int i = 0; i < ftof_tracks.size(); i++) {
360365
auto track = ftof_tracks[i];
361366
ftof.fIndexCollisions = ftof_tracks_indices[i].first;
362367
ftof.fIndexTracks = ftof_tracks_indices[i].second; // Index in the Track table

examples/scripts/common.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import argparse
88
import multiprocessing
99
import sys
10+
import os
1011
try:
1112
import tqdm
1213
except ImportError as e:
@@ -79,3 +80,26 @@ def run_in_parallel(processes, job_runner, job_arguments, job_message):
7980
r = list(tqdm.tqdm(pool.imap(job_runner, job_arguments),
8081
total=len(job_arguments),
8182
bar_format='{l_bar}{bar:10}{r_bar}{bar:-10b}'))
83+
84+
85+
def run_cmd(cmd, comment="", check_status=True):
86+
"""
87+
Function to run a command in bash, allows to check the status of the command and to log the command output
88+
"""
89+
verbose_msg("Running", f"'{cmd}'", bcolors.BOKBLUE + comment)
90+
try:
91+
to_run = cmd
92+
if check_status:
93+
to_run = f"{cmd} && echo OK"
94+
content = os.popen(to_run).read()
95+
if content:
96+
content = content.strip()
97+
for i in content.strip().split("\n"):
98+
verbose_msg("++", i)
99+
if "Encountered error" in content:
100+
warning_msg("Error encountered runtime error in", cmd)
101+
if check_status:
102+
if "OK" not in content and "root" not in cmd:
103+
fatal_msg("Command", cmd, "does not have the OK tag", content)
104+
except:
105+
fatal_msg("Error while running", f"'{cmd}'")

examples/scripts/createO2tables.py

Lines changed: 22 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -11,30 +11,7 @@
1111
import glob
1212
import random
1313
from datetime import datetime
14-
from common import bcolors, msg, fatal_msg, verbose_msg, run_in_parallel, set_verbose_mode, get_default_parser, warning_msg
15-
16-
17-
def run_cmd(cmd, comment="", check_status=True):
18-
"""
19-
Function to run a command in bash, allows to check the status of the command and to log the command output
20-
"""
21-
verbose_msg("Running", f"'{cmd}'", bcolors.BOKBLUE + comment)
22-
try:
23-
to_run = cmd
24-
if check_status:
25-
to_run = f"{cmd} && echo OK"
26-
content = os.popen(to_run).read()
27-
if content:
28-
content = content.strip()
29-
for i in content.strip().split("\n"):
30-
verbose_msg("++", i)
31-
if "Encountered error" in content:
32-
warning_msg("Error encountered runtime error in", cmd)
33-
if check_status:
34-
if "OK" not in content and "root" not in cmd:
35-
fatal_msg("Command", cmd, "does not have the OK tag", content)
36-
except:
37-
fatal_msg("Error while running", f"'{cmd}'")
14+
from common import bcolors, msg, fatal_msg, verbose_msg, run_in_parallel, set_verbose_mode, get_default_parser, run_cmd
3815

3916

4017
def process_run(run_number):
@@ -60,7 +37,8 @@ def main(configuration_file,
6037
clean_delphes_files,
6138
create_luts,
6239
turn_off_vertexing,
63-
append_production):
40+
append_production,
41+
use_nuclei):
6442
arguments = locals() # List of arguments to put into the log
6543
parser = configparser.RawConfigParser()
6644
parser.read(configuration_file)
@@ -125,6 +103,9 @@ def do_copy(in_file, out_file=".", in_path=None):
125103

126104
lut_path = opt("lut_path")
127105
lut_tag = opt("lut_tag")
106+
lut_particles = ["el", "mu", "pi", "ka", "pr"]
107+
if use_nuclei:
108+
lut_particles += ["de", "he3"]
128109
if create_luts:
129110
# Creating LUTs
130111
minimum_track_radius = opt("minimum_track_radius")
@@ -135,12 +116,13 @@ def do_copy(in_file, out_file=".", in_path=None):
135116
else:
136117
# Fetching LUTs
137118
verbose_msg(f"Fetching LUTs with tag {lut_tag} from path {lut_path}")
138-
for i in ["el", "mu", "pi", "ka", "pr"]:
119+
for i in lut_particles:
139120
lut_bg = "{}kG".format(bField).replace(".", "")
140-
do_copy(f"lutCovm.{i}.{lut_bg}.{lut_tag}.dat", f"lutCovm.{i}.dat", in_path=lut_path)
121+
do_copy(f"lutCovm.{i}.{lut_bg}.{lut_tag}.dat",
122+
f"lutCovm.{i}.dat", in_path=lut_path)
141123

142124
# Checking that we actually have LUTs
143-
for i in ["el", "mu", "pi", "ka", "pr"]:
125+
for i in lut_particles:
144126
i = f"lutCovm.{i}.dat"
145127
if not os.path.isfile(i):
146128
fatal_msg("Did not find LUT file", i)
@@ -236,6 +218,9 @@ def set_config(config_file, config, value):
236218
if turn_off_vertexing:
237219
set_config("createO2tables.C",
238220
"const bool do_vertexing = ", "false\;/")
221+
if use_nuclei:
222+
set_config("createO2tables.C",
223+
"const bool enable_nuclei = ", "true\;/")
239224
else: # Check that the geometry file for the vertexing is there
240225
if not os.path.isfile("o2sim_grp.root") or not os.path.isfile("o2sim_geometry.root"):
241226
run_cmd("mkdir tmpo2sim && cd tmpo2sim && o2-sim -m PIPE ITS MFT -g boxgen -n 1 -j 1 --configKeyValues 'BoxGun.number=1' && cp o2sim_grp.root .. && cp o2sim_geometry.root .. && cd .. && rm -r tmpo2sim")
@@ -359,7 +344,10 @@ def copy_and_link(file_name):
359344
log_file=aod_log_file,
360345
check_status=True)
361346
# Check that there were no O2 errors
362-
write_to_runner(f"if grep -q \"\[ERROR\]\" {aod_log_file}; then echo \": got some errors in '{aod_log_file}'\" && exit 1; fi")
347+
write_to_runner(
348+
f"if grep -q \"\[ERROR\]\" {aod_log_file}; then echo \": got some errors in '{aod_log_file}'\" && exit 1; fi")
349+
write_to_runner(
350+
f"if grep -q \"\[FATAL\]\" {aod_log_file}; then echo \": got some fatals in '{aod_log_file}'\" && exit 1; fi")
363351
# Rename the temporary AODs to standard AODs
364352
write_to_runner(f"mv tmp_{aod_file} {aod_file}", check_status=True)
365353
if not clean_delphes_files:
@@ -481,6 +469,9 @@ def write_config(entry, prefix=""):
481469
parser.add_argument("--append", "-a",
482470
action="store_true",
483471
help="Option to append the results instead of starting over by shifting the AOD indexing. N.B. the user is responsible of the compatibility between appended AODs. Only works in conjuction by specifying an output path (option '-o')")
472+
parser.add_argument("--nuclei",
473+
action="store_true",
474+
help="Option use nuclei LUTs")
484475
parser.add_argument("--use-preexisting-luts", "-l",
485476
action="store_true",
486477
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.")
@@ -501,4 +492,5 @@ def write_config(entry, prefix=""):
501492
qa=args.qa,
502493
create_luts=not args.use_preexisting_luts,
503494
turn_off_vertexing=args.no_vertexing,
504-
append_production=args.append)
495+
append_production=args.append,
496+
use_nuclei=args.nuclei)

examples/scripts/create_luts.sh

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,36 @@ if [[ $* == *"-h"* ]]; then
55
echo "1) tag of the LUT writer [default]"
66
echo "2) Magnetic field in T [0.5]"
77
echo "3) Minimum radius of the track in cm [100]"
8+
echo "4) Path where the LUT writers are located [\$DELPHESO2_ROOT/lut/]"
9+
echo "5) Output path where to write the LUTs [.]"
10+
echo "6) Particles to consider [\"0 1 2 3 4\"]"
811
exit 0
912
fi
1013

1114
WHAT=default
1215
FIELD=0.5
1316
RMIN=100.
17+
OUT_PATH=.
18+
WRITER_PATH=$DELPHESO2_ROOT/lut/
19+
PARTICLES="0 1 2 3 4"
1420

1521
[ -z "$1" ] || WHAT=$1
1622
[ -z "$2" ] || FIELD=$2
1723
[ -z "$3" ] || RMIN=$3
24+
[ -z "$4" ] || WRITER_PATH=$4
25+
[ -z "$5" ] || OUT_PATH=$5
26+
[ -z "$6" ] || PARTICLES=$6
1827

19-
cp "$DELPHESO2_ROOT/lut/lutWrite.$WHAT.cc" . || { echo "cannot find lut writer: $DELPHESO2_ROOT/lut/lutWrite.$WHAT.cc" ; exit 1; }
20-
cp "$DELPHESO2_ROOT/lut/DetectorK/DetectorK.cxx" .
21-
cp "$DELPHESO2_ROOT/lut/DetectorK/DetectorK.h" .
22-
cp -r "$DELPHESO2_ROOT/lut/fwdRes" .
23-
cp "$DELPHESO2_ROOT/lut/lutWrite.cc" .
24-
cp "$DELPHESO2_ROOT/lut/lutCovm.hh" .
28+
cp "${WRITER_PATH}/lutWrite.$WHAT.cc" . || { echo "cannot find lut writer: ${WRITER_PATH}/lutWrite.$WHAT.cc" ; exit 1; }
29+
cp "${WRITER_PATH}/DetectorK/DetectorK.cxx" .
30+
cp "${WRITER_PATH}/DetectorK/DetectorK.h" .
31+
cp -r "${WRITER_PATH}/fwdRes" .
32+
cp "${WRITER_PATH}/lutWrite.cc" .
33+
cp "${WRITER_PATH}/lutCovm.hh" .
2534

2635
echo " --- creating LUTs: config = $WHAT, field = $FIELD T, min tracking radius = $RMIN cm"
2736

28-
for i in 0 1 2 3 4; do
37+
for i in $PARTICLES; do
2938
root -l -b <<EOF
3039
.L DetectorK.cxx+
3140
.L lutWrite.${WHAT}.cc
@@ -39,19 +48,22 @@ for i in 0 1 2 3 4; do
3948
const TString pn[7] = {"el", "mu", "pi", "ka", "pr", "de", "he3"};
4049
const int pc[7] = {11, 13, 211, 321, 2212, 1000010020, 1000020030 };
4150
const float field = ${FIELD}f;
42-
const float rmin = ${RMIN}f;
51+
const float rmin = ${RMIN};
4352
const int i = ${i};
44-
lutWrite_${WHAT}("lutCovm." + pn[i] + ".dat", pc[i], field, rmin);
53+
lutWrite_${WHAT}("${OUT_PATH}/lutCovm." + pn[i] + ".dat", pc[i], field, rmin);
4554
4655
EOF
4756
done
4857

4958
# Checking that the output LUTs are OK
5059
NullSize=""
51-
for i in el mu pi ka pr; do
52-
if [[ ! -s lutCovm.$i.dat ]]; then
60+
P=(el mu pi ka pr de he3)
61+
for i in $PARTICLES; do
62+
if [[ ! -s lutCovm.${P[$i]}.dat ]]; then
5363
echo "${i} has zero size"
5464
NullSize="${NullSize} ${i}"
65+
else
66+
echo "lutCovm.${P[$i]}.dat is ok"
5567
fi
5668
done
5769

0 commit comments

Comments
 (0)