Skip to content

Commit 9a84e1a

Browse files
committed
Manual fixes of py and C files
1 parent c8e68c0 commit 9a84e1a

File tree

10 files changed

+126
-139
lines changed

10 files changed

+126
-139
lines changed

machine_learning_hep/scripts-dhadrons/adjusting-run2-run3/add_pt_bins.py

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,35 +28,39 @@ def main():
2828
hist = fin.Get(args.histname)
2929
hist.SetDirectory(0)
3030
first_bin = 1
31-
#last_bin = hist.GetXaxis().FindBin(12.0)
31+
# last_bin = hist.GetXaxis().FindBin(12.0)
3232
last_bin = hist.GetNbinsX()
3333
bins = [0.0]
34-
#bins = []
34+
# bins = []
3535
empty_bins = len(bins)
3636
for binn in range(first_bin, last_bin + 1):
3737
bins.append(hist.GetBinLowEdge(binn))
38-
#last_bins = [24.0, 25.0]
38+
# last_bins = [24.0, 25.0]
3939
last_bins = [24.0]
4040
bins += last_bins
4141
print(f"Hist bins {bins}")
4242
hist2 = TH1F(args.histname, "", len(bins) - 1, array('d', bins))
4343
for binn in range(empty_bins, last_bin + 1):
4444
hist2.SetBinContent(binn + 1, hist.GetBinContent(binn + 1 - empty_bins))
4545
hist2.SetBinError(binn + 1, hist.GetBinError(binn + 1 - empty_bins))
46-
print(f"Setting bin {binn + 1} low edge {hist2.GetBinLowEdge(binn + 1)} up edge {hist2.GetXaxis().GetBinUpEdge(binn + 1)} content to content from bin {binn + 1 - empty_bins}: {hist2.GetBinContent(binn + 1)}")
46+
print(f"Setting bin {binn + 1} low edge {hist2.GetBinLowEdge(binn + 1)} " \
47+
f"up edge {hist2.GetXaxis().GetBinUpEdge(binn + 1)} content to content " \
48+
f"from bin {binn + 1 - empty_bins}: {hist2.GetBinContent(binn + 1)}")
4749
# Formula for merging 2 bins. For example, to compare with less granular Run 2 results.
48-
#last_bin = hist2.GetNbinsX()
49-
#width_combined = hist.GetBinWidth(hist.GetNbinsX() -1) + hist.GetBinWidth(hist.GetNbinsX())
50-
#hist2.SetBinContent(last_bin,
51-
# ((hist.GetBinContent(hist.GetNbinsX() - 1) * hist.GetBinWidth(hist.GetNbinsX() - 1) +\
52-
# hist.GetBinContent(hist.GetNbinsX()) * hist.GetBinWidth(hist.GetNbinsX())) /\
53-
# width_combined))
54-
#hist2.SetBinError(last_bin,
55-
# math.sqrt((hist.GetBinError(hist.GetNbinsX() - 1) * hist.GetBinWidth(hist.GetNbinsX() - 1) /\
56-
# width_combined) **2 +\
57-
# (hist.GetBinError(hist.GetNbinsX()) * hist.GetBinWidth(hist.GetNbinsX()) /\
58-
# width_combined) ** 2))
59-
#print(f"Setting bin {last_bin} low edge {hist2.GetBinLowEdge(last_bin)} up edge {hist2.GetXaxis().GetBinUpEdge(last_bin)} content to content from bins {hist.GetNbinsX()-1}, {hist.GetNbinsX()}: {hist2.GetBinContent(last_bin)}")
50+
# last_bin = hist2.GetNbinsX()
51+
# width_combined = hist.GetBinWidth(hist.GetNbinsX() -1) + hist.GetBinWidth(hist.GetNbinsX())
52+
# hist2.SetBinContent(last_bin,
53+
# ((hist.GetBinContent(hist.GetNbinsX() - 1) * hist.GetBinWidth(hist.GetNbinsX() - 1) +\
54+
# hist.GetBinContent(hist.GetNbinsX()) * hist.GetBinWidth(hist.GetNbinsX())) /\
55+
# width_combined))
56+
# hist2.SetBinError(last_bin,
57+
# math.sqrt((hist.GetBinError(hist.GetNbinsX() - 1) * hist.GetBinWidth(hist.GetNbinsX() - 1) /\
58+
# width_combined) **2 +\
59+
# (hist.GetBinError(hist.GetNbinsX()) * hist.GetBinWidth(hist.GetNbinsX()) /\
60+
# width_combined) ** 2))
61+
# print(f"Setting bin {last_bin} low edge {hist2.GetBinLowEdge(last_bin)} " \
62+
# f"up edge {hist2.GetXaxis().GetBinUpEdge(last_bin)} content to content " \
63+
# f"from bins {hist.GetNbinsX()-1}, {hist.GetNbinsX()}: {hist2.GetBinContent(last_bin)}")
6064
hist2.SetMarkerSize(hist.GetMarkerSize())
6165
hist2.SetMarkerColor(hist.GetMarkerColor())
6266
hist2.SetMarkerStyle(hist.GetMarkerStyle())

machine_learning_hep/scripts-dhadrons/adjusting-run2-run3/modify_crosssec_run2.py

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -52,23 +52,12 @@ def main():
5252
bin1 = merge_bins[ind]
5353
bin2 = merge_bins[ind] + 1
5454
weight_sum = hist.GetBinWidth(bin1) + hist.GetBinWidth(bin2)
55-
average = hist.GetBinContent(bin1) * hist.GetBinWidth(bin1) + hist.GetBinContent(bin2) * hist.GetBinWidth(bin2)
56-
print(f"bin {bin1} width {hist.GetBinWidth(bin1)} bin2 {bin2} width {hist.GetBinWidth(bin2)}")
57-
print(f"weight sum: {weight_sum} average: {hist.GetBinContent(bin1) * hist.GetBinWidth(bin1)} + "
58-
f"{hist.GetBinContent(bin2) + hist.GetBinWidth(bin2)} average: {average}")
55+
average = hist.GetBinContent(bin1) * hist.GetBinWidth(bin1) +\
56+
hist.GetBinContent(bin2) * hist.GetBinWidth(bin2)
5957
hist2.SetBinContent(binn,
6058
(hist.GetBinContent(bin1) * hist.GetBinWidth(bin1) +\
6159
hist.GetBinContent(bin2) * hist.GetBinWidth(bin2)) /\
6260
weight_sum)
63-
print(f"bin {bin1} error {hist.GetBinError(bin1)} bin2 {hist.GetBinError(bin2)}\n"\
64-
f"scaled: {hist.GetBinWidth(bin1) * hist.GetBinError(bin1)}, "\
65-
f"{hist.GetBinWidth(bin2) * hist.GetBinError(bin2)}\n"\
66-
f"divided: {(hist.GetBinWidth(bin1) * hist.GetBinError(bin1)) / weight_sum}, "\
67-
f"{(hist.GetBinWidth(bin2) * hist.GetBinError(bin2)) / weight_sum}\n"\
68-
f"power: {((hist.GetBinWidth(bin1) * hist.GetBinError(bin1)) / weight_sum)**2.}, "\
69-
f"{((hist.GetBinWidth(bin2) * hist.GetBinError(bin2)) / weight_sum)**2.}\n"\
70-
f"sum: {((hist.GetBinWidth(bin1) * hist.GetBinError(bin1)) / weight_sum)**2. + ((hist.GetBinWidth(bin2) * hist.GetBinError(bin2)) / weight_sum)**2.}\n"\
71-
f"sqrt: {math.sqrt(((hist.GetBinWidth(bin1) * hist.GetBinError(bin1)) / weight_sum)**2. + ((hist.GetBinWidth(bin2) * hist.GetBinError(bin2)) / weight_sum)**2.)}\n")
7261
hist2.SetBinError(binn, math.sqrt(((hist.GetBinWidth(bin1) * hist.GetBinError(bin1)) / weight_sum) ** 2. +\
7362
((hist.GetBinWidth(bin2) * hist.GetBinError(bin2)) / weight_sum) ** 2.))
7463
ind += 1

machine_learning_hep/scripts-dhadrons/adjusting-run2-run3/remove_high_pt.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,21 @@ def main():
2727

2828
with TFile(args.filename) as fin, TFile(args.outname, "recreate") as fout:
2929
objnames = fin.GetListOfKeys()
30-
print(f"objnames : {objnames}")
3130
histnames = [key.GetName() for key in fin.GetListOfKeys() if args.histname in key.GetName()]
32-
print(f"histnames: {histnames}")
3331
for histname in histnames:
3432
hist = fin.Get(histname)
3533
hist.SetDirectory(0)
3634
last_bin = hist.GetXaxis().FindBin(args.maxval)
3735
bins = []
3836
for binn in range(1, last_bin + 1):
3937
bins.append(hist.GetBinLowEdge(binn))
40-
print(f"Hist bins {bins}")
4138
hist2 = TH1F(histname, "", len(bins) - 1, array('d', bins))
4239
for binn in range(1, last_bin + 1):
43-
hist2.SetBinContent(binn + 1, hist.GetBinContent(binn + 1))
44-
hist2.SetBinError(binn + 1, hist.GetBinError(binn + 1))
45-
#print(f"Setting bin {binn + 1} low edge {hist2.GetBinLowEdge(binn + 1)} up edge {hist2.GetXaxis().GetBinUpEdge(binn + 1)} content to content from bin {binn + 1}: {hist2.GetBinContent(binn + 1)}")
40+
hist2.SetBinContent(binn, hist.GetBinContent(binn))
41+
hist2.SetBinError(binn, hist.GetBinError(binn))
42+
print(f"Setting bin {binn} low edge {hist2.GetBinLowEdge(binn)} " \
43+
f"up edge {hist2.GetXaxis().GetBinUpEdge(binn)} content to content " \
44+
f"from bin {binn}: {hist2.GetBinContent(binn)}")
4645
hist2.SetMarkerSize(hist.GetMarkerSize())
4746
hist2.SetMarkerColor(hist.GetMarkerColor())
4847
hist2.SetMarkerStyle(hist.GetMarkerStyle())

machine_learning_hep/scripts-dhadrons/debugging/plot_prompt_fraction_vs_crosssec_configs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def main():
7979

8080
hists.append(hist)
8181

82-
margin = 0.1
82+
# margin = 0.1
8383
print(f"Hist maxy: {maxy} miny: {miny}")
8484
for hist in hists:
8585
#hist.GetYaxis().SetRangeUser(miny - margin * miny, maxy + margin * maxy)

machine_learning_hep/scripts-dhadrons/merging/merge_histomass.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ def main():
2929

3030
with TFile(args.outfile[0], "RECREATE") as fout:
3131
for name in args.histname:
32-
hist_list = []
3332
for ind, filename in enumerate(args.infile):
3433
fin = TFile(filename)
3534
list_hists = [key.GetName() for key in fin.GetListOfKeys() \

machine_learning_hep/scripts-dhadrons/merging/merge_histos.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,28 +24,24 @@ def main():
2424
if len(args.outfile) != 1:
2525
raise ValueError("Provide exactly 1 output file")
2626

27-
print(f"filenames {args.infile}")
28-
2927
with TFile(args.outfile[0], "RECREATE") as fout:
3028
fins = [TFile(filename) for filename in args.infile]
3129

3230
histname = args.histname
3331
if args.histname is None:
3432
histname = [key.GetName() for key in fins[0].GetListOfKeys()]
3533

36-
print(f"histnames {histname}")
37-
3834
def get_hist(fin, histname):
3935
fin.cd()
4036
return fin.Get(histname)
4137

4238
for name in histname:
4339
hist_list = [get_hist(fin, name) for fin in fins]
44-
print(f"{name} hist list length: {len(hist_list)}")
4540
if any(cls in hist_list[0].ClassName() for cls in ("TH1", "TGraph")):
4641
hist = hist_list[-1].Clone()
4742
for ind, hist_tmp in enumerate(hist_list):
48-
print(f"hist {name} bin {ind+1} pt [{hist.GetBinLowEdge(ind + 1)}, {hist.GetBinLowEdge(ind + 2)}) " \
43+
print(f"hist {name} bin {ind+1} pt [{hist.GetBinLowEdge(ind + 1)}, " \
44+
f"{hist.GetBinLowEdge(ind + 2)}) " \
4945
f"content {hist_tmp.GetBinContent(ind + 1)}")
5046
hist.SetBinContent(ind+1, hist_tmp.GetBinContent(ind+1))
5147
hist.SetBinError(ind+1, hist_tmp.GetBinError(ind+1))

machine_learning_hep/scripts-dhadrons/multitrial/multitrial.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@ def plot_yields_trials(yields, yields_err, trials, cfg, pt_string, plot_pt_strin
109109
facecolor="orange", edgecolor="none", alpha=0.3)
110110
plot_trial_line(ax, central_trial_ind)
111111
plot_text_box(ax, plot_pt_string)
112-
fig.savefig(f'{cfg["outdir"]}/{cfg["outfile"]}_yields_trials_{pt_string}.png',
113-
bbox_inches='tight')
112+
fig.savefig(f"{cfg["outdir"]}/{cfg["outfile"]}_yields_trials_{pt_string}.png",
113+
bbox_inches="tight")
114114
plt.close()
115115

116116

@@ -120,8 +120,8 @@ def plot_chis(chis, cfg, pt_string, plot_pt_string):
120120
ax.scatter(x_axis, chis, c="b", marker="o")
121121
set_ax_limits(ax, pt_string, chis)
122122
plot_text_box(ax, plot_pt_string)
123-
fig.savefig(f'{cfg["outdir"]}/{cfg["outfile"]}_chis_{pt_string}.png',
124-
bbox_inches='tight')
123+
fig.savefig(f"{cfg["outdir"]}/{cfg["outfile"]}_chis_{pt_string}.png",
124+
bbox_inches="tight")
125125
plt.close()
126126

127127

@@ -145,7 +145,7 @@ def plot_yields_distr(yields, cfg, pt_string, plot_pt_string, central_trial_ind,
145145
f"std dev: {std_dev:.2f}\n"\
146146
f"RMSE: {rmse:.2f}\n"\
147147
f"#trials: {len(yields)}")
148-
plt.savefig(f'{cfg["outdir"]}/{cfg["outfile"]}_distr_{pt_string}.png', bbox_inches='tight')
148+
plt.savefig(f"{cfg["outdir"]}/{cfg["outfile"]}_distr_{pt_string}.png", bbox_inches="tight")
149149
plt.close()
150150

151151

@@ -177,7 +177,7 @@ def main():
177177
except: # pylint: disable=bare-except
178178
pass
179179

180-
with open(f'{cfg["outdir"]}/{cfg["outfile"]}_trials_{pt_string}.txt',
180+
with open(f"{cfg["outdir"]}/{cfg["outfile"]}_trials_{pt_string}.txt",
181181
"w", encoding="utf-8") as ftext:
182182
for trial in trials[pt_string]:
183183
ftext.write(f"{trial}\n")

machine_learning_hep/scripts-dhadrons/preliminary-plots/DrawCutVarFit.C

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,13 @@ void DrawCutVarFit(bool isPreliminary = kTRUE)
7272
new TFile("/data8/majak/systematics/230824/CutVarLc_pp13TeV_LHC24d3_default.root",
7373
"read");
7474
hRawYieldsVsCutPt =
75-
std::reinterpret_cast<TH1F*>CutVarFile->Get(Form("hRawYieldVsCut_pt%d_%d", binMin, binMax));
75+
std::reinterpret_cast<TH1F*> CutVarFile->Get(Form("hRawYieldVsCut_pt%d_%d", binMin, binMax));
7676
hRawYieldPromptVsCut =
77-
std::reinterpret_cast<TH1F*>CutVarFile->Get(Form("hRawYieldPromptVsCut_pt%d_%d", binMin, binMax));
77+
std::reinterpret_cast<TH1F*> CutVarFile->Get(Form("hRawYieldPromptVsCut_pt%d_%d", binMin, binMax));
7878
hRawYieldFDVsCut =
79-
std::reinterpret_cast<TH1F*>CutVarFile->Get(Form("hRawYieldNonPromptVsCut_pt%d_%d", binMin, binMax));
79+
std::reinterpret_cast<TH1F*> CutVarFile->Get(Form("hRawYieldNonPromptVsCut_pt%d_%d", binMin, binMax));
8080
hRawYieldsVsCutReSum =
81-
std::reinterpret_cast<TH1F*>CutVarFile->Get(Form("hRawYieldSumVsCut_pt%d_%d", binMin, binMax));
81+
std::reinterpret_cast<TH1F*> CutVarFile->Get(Form("hRawYieldSumVsCut_pt%d_%d", binMin, binMax));
8282

8383
SetStyleHisto(hRawYieldsVsCutPt);
8484
SetStyleHisto(hRawYieldPromptVsCut);

0 commit comments

Comments
 (0)