Skip to content

Commit 738aac2

Browse files
committed
Multitrial script fixed and working
1 parent abd50b9 commit 738aac2

File tree

2 files changed

+21
-10
lines changed

2 files changed

+21
-10
lines changed
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
{
2-
"file_pattern": "/data8/majak/d2h-fitter/0125/results_multitrial*/fits.root",
3-
"dir_pattern": "results_multitrial",
2+
"file_pattern": "/data8/majak/d2h-fitter/0125/results_nonprompt*/fits.root",
3+
"dir_pattern": "results_nonprompt-",
44
"histoname": "hRawYields",
55
"pt_bins_min": [0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 12, 16],
66
"pt_bins_max": [1, 2, 3, 4, 5, 6, 7, 8, 10, 12, 16, 24],
77
"x_axis": "Trial #",
88
"y_axis": "Raw yield",
9-
"central_trial": "central",
9+
"central_trial": "cheb",
1010
"outdir": "/data8/majak/multitrial",
1111
"outfile": "result"
1212
}

PWGHF/D2H/Macros/multitrial.py

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
# pylint: disable=missing-function-docstring, invalid-name
2+
"""
3+
file: multitrial.py
4+
brief: Plot multitrial systematics based on multiple fit trials, one file per trial.
5+
usage: python3 multitrial.py config_multitrial.json
6+
author: Maja Karwowska <[email protected]>, Warsaw University of Technology
7+
"""
18
import argparse
29
import glob
310
import json
@@ -21,10 +28,11 @@ def get_yields(cfg):
2128
for filename in filenames:
2229
with TFile.Open(filename) as fin:
2330
hist = fin.Get(cfg["histoname"])
24-
dirname = re.search(cfg["dir_pattern"], filename).group(0)
25-
trial_name = re.split("_", dirname)[-1]
31+
dirname = re.split("/", filename)[-2]
32+
trial_name = dirname.replace(cfg["dir_pattern"], "")
2633
trials.append(trial_name)
27-
for ind, (pt_bin_min, pt_bin_max) in enumerate(zip(cfg["pt_bins_min"], cfg["pt_bins_max"])):
34+
for ind, (pt_bin_min, pt_bin_max) in enumerate(zip(cfg["pt_bins_min"],
35+
cfg["pt_bins_max"])):
2836
yields[f"{pt_bin_min}_{pt_bin_max}"].append(hist.GetBinContent(ind + 1))
2937
yields_err[f"{pt_bin_min}_{pt_bin_max}"].append(hist.GetBinError(ind + 1))
3038
print(f"final yields:\n{yields}\ntrials:\n{trials}\nyields error:\n{yields_err}")
@@ -48,14 +56,16 @@ def plot_yields_trials(yields, yields_err, trials, cfg, pt_string):
4856
c="m", linestyle="-", linewidth=4.0)
4957
#ax.set_xticks(ax.get_xticks()[::50])
5058
plt.savefig(f'{cfg["outdir"]}/{cfg["outfile"]}_yields_trials_{pt_string}.png')
59+
plt.close()
5160

5261

5362
def plot_yields_distr(yields, cfg, pt_string):
5463
plt.figure(figsize=(20, 15))
5564
ax = plt.subplot(1, 1, 1)
5665
ax.set_xlabel(cfg["y_axis"])
57-
plt.hist(yields, c="b", linewidth=4.0)
66+
plt.hist(yields[pt_string], color="b", linewidth=4.0)
5867
plt.savefig(f'{cfg["outdir"]}/{cfg["outfile"]}_distr_{pt_string}.png')
68+
plt.close()
5969

6070

6171
def main():
@@ -75,9 +85,10 @@ def main():
7585
plot_yields_trials(yields, yields_err, trials, cfg, pt_string)
7686
plot_yields_distr(yields, cfg, pt_string)
7787

78-
with open(f'{cfg["outdir"]}/{cfg["outfile"]}_trials_{pt_bin_min}_{pt_bin_max}.txt', "w") as ftext:
79-
for trial in trials:
80-
f.write(f"{trial}\n")
88+
with open(f'{cfg["outdir"]}/{cfg["outfile"]}_trials.txt',
89+
"w", encoding="utf-8") as ftext:
90+
for trial in trials:
91+
ftext.write(f"{trial}\n")
8192

8293

8394
if __name__ == "__main__":

0 commit comments

Comments
 (0)