Skip to content

Commit

Permalink
Add protection against division by zero
Browse files Browse the repository at this point in the history
  • Loading branch information
vkucera committed Sep 5, 2024
1 parent da03289 commit a3342eb
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions machine_learning_hep/analysis/analyzer_jets.py
Original file line number Diff line number Diff line change
Expand Up @@ -815,6 +815,9 @@ def _analyze(self, method = 'sidesub'):
c = TCanvas()
for i, h in enumerate(fh_unfolded):
hproj = project_hist(h, [1], {0: (j+1, j+1)})
empty = hproj.Integral() < 1.e-7
if empty:
self.logger.error("Projection %s is empty.", string_range_ptjet(range_ptjet))
self._save_hist(
hproj,
f'uf/h_{var}_{method}_unfolded_{mcordata}_' +
Expand All @@ -826,15 +829,16 @@ def _analyze(self, method = 'sidesub'):
f'uf/h_{var}_{method}_unfolded_{mcordata}_' +
f'{string_range_ptjet(range_ptjet)}_sel.png')
# Save also the self-normalised version.
hproj_sel = hproj.Clone(f"{hproj.GetName()}_selfnorm")
hproj_sel.Scale(1. / hproj_sel.Integral(), "width")
self.logger.debug("Final histogram: %s, jet pT %g to %g",
var, range_ptjet[0], range_ptjet[1])
# self.logger.debug(print_histogram(hproj_sel))
self._save_hist(
hproj_sel,
f'uf/h_{var}_{method}_unfolded_{mcordata}_' +
f'{string_range_ptjet(range_ptjet)}_sel_selfnorm.png')
if not empty:
hproj_sel = hproj.Clone(f"{hproj.GetName()}_selfnorm")
hproj_sel.Scale(1. / hproj_sel.Integral(), "width")
self.logger.debug("Final histogram: %s, jet pT %g to %g",
var, range_ptjet[0], range_ptjet[1])
# self.logger.debug(print_histogram(hproj_sel))
self._save_hist(
hproj_sel,
f'uf/h_{var}_{method}_unfolded_{mcordata}_' +
f'{string_range_ptjet(range_ptjet)}_sel_selfnorm.png')
c.cd()
hcopy = hproj.DrawCopy('same' if i > 0 else '')
hcopy.SetLineColor(i+1)
Expand Down

0 comments on commit a3342eb

Please sign in to comment.