Skip to content

Commit cefa052

Browse files
committed
Fix technical issues
1 parent ad9db9b commit cefa052

File tree

2 files changed

+30
-14
lines changed

2 files changed

+30
-14
lines changed

machine_learning_hep/analysis/analyzer_jets.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ def __init__(self, datap, case, typean, period):
117117
for param, symbol in zip(
118118
("mean", "sigma", "significance", "chi2"),
119119
("#it{#mu}", "#it{#sigma}", "significance", "#it{#chi}^{2}"),
120-
strict=False,
120+
strict=True,
121121
)
122122
}
123123
for level in self.fit_levels
@@ -703,7 +703,7 @@ def _subtract_sideband(self, hist, var, mcordata, ipt):
703703
hx = project_hist(fh_sideband, (0,), {}) if get_dim(fh_sideband) > 1 else fh_sideband
704704
for iptjet in bins_ptjet:
705705
if iptjet and hx.GetBinContent(iptjet) <= 0:
706-
continue
706+
continue
707707
rws = self.roo_ws.get((mcordata, iptjet, ipt))
708708
if not rws:
709709
self.logger.error("Falling back to incl. roows for %s-iptjet%i-ipt%i", mcordata, iptjet, ipt)
@@ -1060,7 +1060,6 @@ def _extract_signal(self, hist, var, mcordata, ipt):
10601060
# hres.Sumw2() # TODO: check if we should do this here
10611061
return hres
10621062

1063-
10641063
def estimate_feeddown(self):
10651064
"""Estimate feeddown from legacy Run 2 trees or gen-only simulation"""
10661065
match self.cfg("fd_input", "tree"):
@@ -1096,7 +1095,9 @@ def estimate_feeddown(self):
10961095
colname = col_mapping.get(var, f"{var}_jet")
10971096
if f"{colname}" not in df:
10981097
if var is not None:
1099-
self.logger.error("No feeddown information for %s (%s), cannot estimate feeddown", var, colname)
1098+
self.logger.error(
1099+
"No feeddown information for %s (%s), cannot estimate feeddown", var, colname
1100+
)
11001101
# print(df.info(), flush=True)
11011102
continue
11021103

@@ -1109,7 +1110,9 @@ def estimate_feeddown(self):
11091110
bins_obs[var],
11101111
)
11111112
fill_hist_fast(h3_fd_gen_orig[var], df[["pt_jet", "pt_cand", f"{colname}"]])
1112-
self._save_hist(project_hist(h3_fd_gen_orig[var], [0, 2], {}), f"fd/h_ptjet-{var}_feeddown_gen_noeffscaling.png")
1113+
self._save_hist(
1114+
project_hist(h3_fd_gen_orig[var], [0, 2], {}), f"fd/h_ptjet-{var}_feeddown_gen_noeffscaling.png"
1115+
)
11131116

11141117
case "sim":
11151118
# TODO: recover cross section
@@ -1121,8 +1124,11 @@ def estimate_feeddown(self):
11211124
if fh := rfile.Get(f"h_mass-ptjet-pthf{label}"):
11221125
h3_fd_gen_orig[var] = project_hist(fh, list(range(1, get_dim(fh))), {})
11231126
ensure_sumw2(h3_fd_gen_orig[var])
1124-
self._save_hist(project_hist(h3_fd_gen_orig[var], [0, 2], {}), f"fd/h_ptjet-{var}_feeddown_genonly_noeffscaling.png")
1125-
powheg_xsection_scale_factor = 1. # FIXME: retrieve cross section
1127+
self._save_hist(
1128+
project_hist(h3_fd_gen_orig[var], [0, 2], {}),
1129+
f"fd/h_ptjet-{var}_feeddown_genonly_noeffscaling.png",
1130+
)
1131+
powheg_xsection_scale_factor = 1.0 # FIXME: retrieve cross section
11261132

11271133
case fd_input:
11281134
self.logger.critical("Invalid feeddown input %s", fd_input)

machine_learning_hep/processer_jet.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,10 @@ def __init__(
8383
self.s_evtsel = datap["analysis"][self.typean]["evtsel"]
8484

8585
# bins: 2d array [[low, high], ...]
86-
self.bins_skimming = np.array(list(zip(self.lpt_anbinmin, self.lpt_anbinmax)), "d") # TODO: replace with cfg
87-
self.bins_analysis = np.array(list(zip(self.lpt_finbinmin, self.lpt_finbinmax)), "d")
86+
self.bins_skimming = np.array(
87+
list(zip(self.lpt_anbinmin, self.lpt_anbinmax, strict=True)), "d"
88+
) # TODO: replace with cfg
89+
self.bins_analysis = np.array(list(zip(self.lpt_finbinmin, self.lpt_finbinmax, strict=True)), "d")
8890

8991
# skimming bins in overlap with the analysis range
9092
self.active_bins_skim = [
@@ -143,7 +145,7 @@ def _verify_variables(self, dfi):
143145
for idx, row in df.iterrows():
144146
isSoftDropped = False
145147
nsd = 0
146-
for zg, theta in zip(row["zg_array"], row["fTheta"]):
148+
for zg, theta in zip(row["zg_array"], row["fTheta"], strict=True):
147149
if zg >= self.cfg("zcut", 0.1):
148150
if not isSoftDropped:
149151
df.loc[idx, "zg"] = zg
@@ -178,7 +180,12 @@ def _calculate_variables(self, df, verify=False): # pylint: disable=invalid-nam
178180
df["zg"] = df["zg_array"].apply(lambda ar: next((zg for zg in ar if zg >= zcut), -0.1))
179181
if "rg" in observables:
180182
df["rg"] = df[["zg_array", "fTheta"]].apply(
181-
(lambda ar: next((rg for (zg, rg) in zip(ar.zg_array, ar.fTheta) if zg >= zcut), -0.1)), axis=1
183+
(
184+
lambda ar: next(
185+
(rg for (zg, rg) in zip(ar.zg_array, ar.fTheta, strict=True) if zg >= zcut), -0.1
186+
)
187+
),
188+
axis=1,
182189
)
183190
if "nsd" in observables:
184191
df["nsd"] = df["zg_array"].apply(lambda ar: len([zg for zg in ar if zg >= zcut]))
@@ -232,7 +239,7 @@ def process_histomass_single(self, index):
232239
self.logger.info("Processing (histomass) %s", self.l_evtorig[index])
233240

234241
print(f"Opening file {self.l_histomass[index]}", flush=True)
235-
with TFile.Open(self.l_histomass[index], "recreate") as rfile:
242+
with TFile.Open(self.l_histomass[index], "recreate") as _:
236243
dfevtorig = read_df(self.l_evtorig[index])
237244
histonorm = TH1F("histonorm", "histonorm", 4, 0, 4)
238245
histonorm.SetBinContent(1, len(dfquery(dfevtorig, self.s_evtsel)))
@@ -256,7 +263,7 @@ def process_histomass_single(self, index):
256263
get_axis(histonorm, 0).SetBinLabel(4, "N_{BC}^{TVX}")
257264
histonorm.Write()
258265

259-
if self.datatype != 'fd':
266+
if self.datatype != "fd":
260267
df = pd.concat(read_df(self.mptfiles_recosk[bin][index]) for bin in self.active_bins_skim)
261268
else:
262269
df = pd.concat(read_df(self.mptfiles_gensk[bin][index]) for bin in self.active_bins_skim)
@@ -489,7 +496,10 @@ def process_efficiency_single(self, index):
489496
}
490497

491498
for cat in cats:
492-
print(f"Filling histograms for {cat}: {dfgen[cat].info()}, {dfdet[cat].info()}, {dfmatch[cat].info()}", flush=True)
499+
print(
500+
f"Filling histograms for {cat}: {dfgen[cat].info()}, {dfdet[cat].info()}, {dfmatch[cat].info()}",
501+
flush=True,
502+
)
493503
fill_hist(h_eff[(cat, "gen")], dfgen[cat][["fJetPt_gen", "fPt_gen"]])
494504
fill_hist(h_eff[(cat, "det")], dfdet[cat][["fJetPt", "fPt"]])
495505
if cat in dfmatch and dfmatch[cat] is not None:

0 commit comments

Comments
 (0)