Skip to content

Commit 952ab74

Browse files
authored
Install root files for AOD making (#85)
- Add extra features and checks for AOD making - Add helper for LUT creation tool - Add check on created LUTs - Linearize LUT maker script - Fix empty LUTs for negative particles
1 parent 7d849b5 commit 952ab74

File tree

4 files changed

+69
-49
lines changed

4 files changed

+69
-49
lines changed

examples/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ file(GLOB SMEARING
2929
file(GLOB AOD
3030
aod/*.C
3131
aod/*.h
32+
aod/*.root
3233
)
3334

3435
install(FILES ${PYTHIA8} DESTINATION examples/pythia8)

examples/scripts/createO2tables.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -109,15 +109,16 @@ def opt(entry, require=True):
109109
barrel_half_length = opt("barrel_half_length")
110110

111111
# copy relevant files in the working directory
112-
def do_copy(in_file, out_file):
112+
def do_copy(in_file, out_file=".", in_path=None):
113+
"""Function to copy files"""
114+
if in_path is not None:
115+
in_file = os.path.join(in_path, in_file)
113116
in_file = os.path.expanduser(os.path.expandvars(in_file))
114117
verbose_msg("Copying", in_file, "to", out_file)
115118
shutil.copy2(in_file, out_file)
116119

117120
# Fetching the propagation card
118-
do_copy(os.path.join(opt("card_path"),
119-
opt("propagate_card")),
120-
"propagate.tcl")
121+
do_copy(opt("propagate_card"), "propagate.tcl", in_path=opt("card_path"))
121122

122123
lut_path = opt("lut_path")
123124
lut_tag = opt("lut_tag")
@@ -133,8 +134,7 @@ def do_copy(in_file, out_file):
133134
verbose_msg(f"Fetching LUTs with tag {lut_tag} from path {lut_path}")
134135
for i in ["el", "mu", "pi", "ka", "pr"]:
135136
lut_bg = "{}kG".format(bField).replace(".", "")
136-
do_copy(os.path.join(lut_path, f"lutCovm.{i}.{lut_bg}.{lut_tag}.dat"),
137-
f"lutCovm.{i}.dat")
137+
do_copy(f"lutCovm.{i}.{lut_bg}.{lut_tag}.dat", f"lutCovm.{i}.dat", in_path=lut_path)
138138

139139
# Checking that we actually have LUTs
140140
for i in ["el", "mu", "pi", "ka", "pr"]:
@@ -150,7 +150,7 @@ def do_copy(in_file, out_file):
150150
config_entry, "in your configuration file", configuration_file)
151151
generators = opt("generators").split(" ")
152152
for i in generators:
153-
do_copy(i, ".")
153+
do_copy(i)
154154
msg("Using pythia with configuration", generators)
155155
else:
156156
def check_duplicate(option_name):
@@ -201,11 +201,11 @@ def check_duplicate(option_name):
201201
msg(" etaMax =", etaMax)
202202

203203
aod_path = opt("aod_path")
204-
do_copy(os.path.join(aod_path, "createO2tables.h"), ".")
205-
do_copy(os.path.join(aod_path, "createO2tables.C"), ".")
206-
do_copy("../aod/muonAccEffPID.root", ".")
204+
do_copy("createO2tables.h", in_path=aod_path)
205+
do_copy("createO2tables.C", in_path=aod_path)
206+
do_copy("muonAccEffPID.root", in_path=aod_path)
207207
if qa:
208-
do_copy("diagnostic_tools/dpl-config_std.json", ".")
208+
do_copy("diagnostic_tools/dpl-config_std.json")
209209

210210
def set_config(config_file, config, value):
211211
config = config.strip()
@@ -355,8 +355,10 @@ def copy_and_link(file_name):
355355
write_to_runner(f"root -l -b -q 'createO2tables.C+(\"{delphes_file}\", \"tmp_{aod_file}\", 0)'",
356356
log_file=aod_log_file,
357357
check_status=True)
358-
write_to_runner(f"mv tmp_{aod_file} {aod_file}",
359-
check_status=True)
358+
# Check that there were no O2 errors
359+
write_to_runner(f"if grep -q \"\[ERROR\]\" {aod_log_file}; then echo \": got some errors in '{aod_log_file}'\" && exit 1; fi")
360+
# Rename the temporary AODs to standard AODs
361+
write_to_runner(f"mv tmp_{aod_file} {aod_file}", check_status=True)
360362
if not clean_delphes_files:
361363
copy_and_link(delphes_file)
362364
if hepmc_file is not None:

examples/scripts/create_luts.sh

Lines changed: 51 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
#! /usr/bin/env bash
22

3+
if [[ $* == *"-h"* ]]; then
4+
echo "Script to generate LUTs from LUT writer, arguments:"
5+
echo "1) tag of the LUT writer [default]"
6+
echo "2) Magnetic field in T [0.5]"
7+
echo "3) Minimum radius of the track in cm [100]"
8+
exit 0
9+
fi
10+
311
WHAT=default
412
FIELD=0.5
513
RMIN=100.
@@ -8,37 +16,46 @@ RMIN=100.
816
[ -z "$2" ] || FIELD=$2
917
[ -z "$3" ] || RMIN=$3
1018

11-
cp $DELPHESO2_ROOT/lut/lutWrite.$WHAT.cc . || { echo "cannot find lut writer: $DELPHESO2_ROOT/lut/lutWrite.$WHAT.cc" ; exit 1; }
12-
cp $DELPHESO2_ROOT/lut/DetectorK/DetectorK.cxx .
13-
cp $DELPHESO2_ROOT/lut/DetectorK/DetectorK.h .
14-
cp -r $DELPHESO2_ROOT/lut/fwdRes .
15-
cp $DELPHESO2_ROOT/lut/lutWrite.cc .
16-
17-
echo " --- creating LUTs: config = $WHAT, field = $FIELD T, min tracking radius = $RMIN cm"
18-
19-
prepare_libs_macro() {
20-
echo "void create_libs() {"
21-
echo " gROOT->ProcessLine(\".L DetectorK.cxx+\");"
22-
echo "}"
23-
}
24-
25-
prepare_luts_macro() {
26-
27-
echo "R__LOAD_LIBRARY(DetectorK_cxx.so)"
28-
echo "#include \"lutWrite.$WHAT.cc\""
29-
echo "void create_luts() {"
30-
echo " lutWrite_$WHAT(\"lutCovm.el.dat\", 11, $FIELD, $RMIN);"
31-
echo " lutWrite_$WHAT(\"lutCovm.mu.dat\", 13, $FIELD, $RMIN);"
32-
echo " lutWrite_$WHAT(\"lutCovm.pi.dat\", 211, $FIELD, $RMIN);"
33-
echo " lutWrite_$WHAT(\"lutCovm.ka.dat\", 321, $FIELD, $RMIN);"
34-
echo " lutWrite_$WHAT(\"lutCovm.pr.dat\", 2212, $FIELD, $RMIN);"
35-
echo "}"
36-
37-
}
38-
39-
prepare_libs_macro > create_libs.C
40-
root -b -q -l create_libs.C
41-
42-
prepare_luts_macro > create_luts.C
43-
root -b -q -l create_luts.C
44-
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" .
25+
26+
echo " --- creating LUTs: config = $WHAT, field = $FIELD T, min tracking radius = $RMIN cm"
27+
28+
for i in 0 1 2 3 4; do
29+
root -l -b <<EOF
30+
.L DetectorK.cxx+
31+
.L lutWrite.${WHAT}.cc
32+
33+
TDatabasePDG::Instance()->AddParticle("deuteron", "deuteron", 1.8756134, kTRUE, 0.0, 3, "Nucleus", 1000010020);
34+
TDatabasePDG::Instance()->AddAntiParticle("anti-deuteron", -1000010020);
35+
36+
TDatabasePDG::Instance()->AddParticle("helium3", "helium3", 2.80839160743, kTRUE, 0.0, 6, "Nucleus", 1000020030);
37+
TDatabasePDG::Instance()->AddAntiParticle("anti-helium3", -1000020030);
38+
39+
const TString pn[7] = {"el", "mu", "pi", "ka", "pr", "de", "he3"};
40+
const int pc[7] = {11, 13, 211, 321, 2212, 1000010020, 1000020030 };
41+
const float field = ${FIELD}f;
42+
const float rmin = ${RMIN}f;
43+
const int i = ${i};
44+
lutWrite_${WHAT}("lutCovm." + pn[i] + ".dat", pc[i], field, rmin);
45+
46+
EOF
47+
done
48+
49+
# Checking that the output LUTs are OK
50+
NullSize=""
51+
for i in el mu pi ka pr; do
52+
if [[ ! -s lutCovm.$i.dat ]]; then
53+
echo "${i} has zero size"
54+
NullSize="${NullSize} ${i}"
55+
fi
56+
done
57+
58+
if [[ ! -z $NullSize ]]; then
59+
echo "Created null sized LUTs!!"
60+
exit 1
61+
fi

src/lutWrite.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@ lutWrite(const char *filename = "lutCovm.dat", int pdg = 211, float field = 0.2,
6060
// pid
6161
lutHeader.pdg = pdg;
6262
lutHeader.mass = TDatabasePDG::Instance()->GetParticle(pdg)->Mass();
63-
const int q = TDatabasePDG::Instance()->GetParticle(pdg)->Charge() / 3;
63+
const int q = std::abs(TDatabasePDG::Instance()->GetParticle(pdg)->Charge()) / 3;
6464
if (q <= 0) {
65-
Printf("Negative or null charge for %i. Fix the charge!", pdg);
65+
Printf("Negative or null charge (%f) for pdg code %i. Fix the charge!", TDatabasePDG::Instance()->GetParticle(pdg)->Charge(), pdg);
6666
return;
6767
}
6868
lutHeader.field = field;

0 commit comments

Comments
 (0)