Skip to content

Commit

Permalink
Miscellanous fixes (#956)
Browse files Browse the repository at this point in the history
* Set no-ml default config properly for MultiClass

* Missing prefix for results all data

* Detect not found MC histos in fitter

* Do not load tensorflow et al. in apply() until we really want ML

* Fix pylint
  • Loading branch information
saganatt authored Oct 18, 2024
1 parent 87ee464 commit 57c5c2d
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 7 deletions.
5 changes: 4 additions & 1 deletion machine_learning_hep/analysis/analyzerdhadrons.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def __init__(self, datap, case, typean, period):
self.d_resultsallpmc = self.d_prefix_mc + dp["mc"]["results"][period] \
if period is not None \
else self.d_prefix_mc + dp["mc"]["resultsallp"]
self.d_resultsallpdata = + dp["data"]["results"][period] \
self.d_resultsallpdata = self.d_prefix_data + dp["data"]["results"][period] \
if period is not None \
else self.d_prefix_data + dp["data"]["resultsallp"]

Expand Down Expand Up @@ -330,17 +330,20 @@ def makenormyields(self): # pylint: disable=import-outside-toplevel, too-many-b
hbkg.Write()
fileoutbkgscaled.Close()

output_prompt = []
hf_pt_spectrum(self.p_anahpt,
self.p_br,
self.p_inputfonllpred,
self.p_fd_method,
None,
fileouteff,
namehistoeffprompt,
namehistoefffeed,
yield_filename,
nameyield,
selnorm,
self.p_sigmamb,
output_prompt,
fileoutcross)

fileoutcrosstot = TFile.Open("%s/finalcross%s%stot.root" %
Expand Down
13 changes: 9 additions & 4 deletions machine_learning_hep/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,13 @@ def update_config(database: dict, run_config: dict, database_overwrite=None): #
database["mlapplication"][keys[0]][keys[1]][:] = \
[f"{path}_std" for path in database["mlapplication"][keys[0]][keys[1]]]
# ...set the ML working point all to 0
# except for MultiClassification, where bkg cut of 1 is the loosest one
for k in data_mc:
database["mlapplication"]["probcutpresel"][k][:] = \
[0] * len(database["mlapplication"]["probcutpresel"][k])
database["mlapplication"]["probcutoptimal"][:] \
= [0] * len(database["mlapplication"]["probcutoptimal"])
database["mlapplication"]["probcutpresel"][k] = \
[[1 if i == 0 and database["ml"]["mltype"] == "MultiClassification" else 0 \
for i in range(len(pcut))] \
for pcut in database["mlapplication"]["probcutpresel"][k]]
database["mlapplication"]["probcutoptimal"] = \
[[1 if i == 0 and database["ml"]["mltype"] == "MultiClassification" else 0 \
for i in range(len(pcut))] \
for pcut in database["mlapplication"]["probcutoptimal"]]
6 changes: 6 additions & 0 deletions machine_learning_hep/fitting/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,9 +347,15 @@ def get_histograms(self, ibin1, ibin2, get_data=True, get_mc=False, get_reflecti
histo_reflections = None
if get_mc:
histo_mc = file_mc.Get("hmass_sig" + suffix)
if not histo_mc:
file_mc.ls()
raise ValueError("Did not find", "hmass_sig" + suffix)
histo_mc.SetDirectory(0)
if get_reflections:
histo_reflections = file_mc.Get("hmass_refl" + suffix)
if not histo_reflections:
file_mc.ls()
raise ValueError("Did not find", "hmass_refl" + suffix)
histo_reflections.SetDirectory(0)
file_mc.Close()

Expand Down
4 changes: 2 additions & 2 deletions machine_learning_hep/processer.py
Original file line number Diff line number Diff line change
Expand Up @@ -457,8 +457,6 @@ def skim(self, file_index):
write_df(dfgensk, self.mptfiles_gensk[ipt][file_index])

def applymodel(self, file_index):
from machine_learning_hep.models import \
apply # pylint: disable=import-error, import-outside-toplevel
for ipt in range(self.p_nptbins):
if os.path.exists(self.mptfiles_recoskmldec[ipt][file_index]):
if os.stat(self.mptfiles_recoskmldec[ipt][file_index]).st_size != 0:
Expand All @@ -467,6 +465,8 @@ def applymodel(self, file_index):
if self.p_mask_values:
mask_df(dfrecosk, self.p_mask_values)
if self.doml is True:
from machine_learning_hep.models import \
apply # pylint: disable=import-error, import-outside-toplevel
if os.path.isfile(self.lpt_model[ipt]) is False:
print("Model file not present in bin %d" % ipt)
with openfile(self.lpt_model[ipt], 'rb') as mod_file:
Expand Down

0 comments on commit 57c5c2d

Please sign in to comment.