Skip to content

Commit

Permalink
Draft for prior
Browse files Browse the repository at this point in the history
  • Loading branch information
qgp committed Sep 5, 2024
1 parent 21c4c68 commit a5898a6
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
15 changes: 11 additions & 4 deletions machine_learning_hep/analysis/analyzer_jets.py
Original file line number Diff line number Diff line change
Expand Up @@ -1051,9 +1051,11 @@ def _build_effkine(self, h_nocuts, h_cuts):
h_cuts.Divide(h_nocuts)
return h_cuts

def _build_response_matrix(self, h_response, h_eff = None):

def _build_response_matrix(self, h_response, h_eff = None, frac_flat = 0.):
rm = ROOT.RooUnfoldResponse(
project_hist(h_response, [0, 1], {}), project_hist(h_response, [2, 3], {}))
h_gen = project_hist(h_response, [2, 3], {})
for hbin in itertools.product(
enumerate(get_axis(h_response, 0).GetXbins(), 1),
enumerate(get_axis(h_response, 1).GetXbins(), 1),
Expand All @@ -1066,8 +1068,12 @@ def _build_response_matrix(self, h_response, h_eff = None):
if np.isclose(eff, 0.):
self.logger.error('efficiency 0 for %s', hbin[4])
continue
for _ in range(int(n)):
rm.Fill(hbin[0][1], hbin[1][1], hbin[2][1], hbin[3][1], 1./eff)
if (cnt_gen := h_gen.GetBinContent(hbin[2][0], hbin[3][0])) > 0.:
fac = 1.
if frac_flat > 0.:
fac += frac_flat * (1. / cnt_gen - 1.)
for _ in range(int(n)):
rm.Fill(hbin[0][1], hbin[1][1], hbin[2][1], hbin[3][1], 1./eff * fac)
# rm.Mresponse().Print()
return rm

Expand Down Expand Up @@ -1096,7 +1102,8 @@ def _unfold(self, hist, var, mcordata):
self.logger.error('Response matrix for %s not available, cannot unfold', var + suffix)
return []
response_matrix_pr = self._build_response_matrix(
h_response, self.hcandeff['pr'] if mcordata == 'data' else None)
h_response, self.hcandeff['pr'] if mcordata == 'data' else None,
self.cfg('unfolding_frac_flat', 0.))
self._save_hist(response_matrix_pr.Hresponse(),
f'uf/h_ptjet-{var}-responsematrix_pr_lin_{mcordata}.png', 'colz')

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,8 @@ D0Jet_pp:

unfolding_iterations: 8 # used, maximum iteration
unfolding_iterations_sel: 4 # used, selected iteration # systematics
# unfolding_frac_flat: .1

closure:
pure_signal: false
# exclude_feeddown_det: 'ismcsignal==1 & ismcprompt==1'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,7 @@ LcJet_pp:

unfolding_iterations: 8 # used, maximum iteration
unfolding_iterations_sel: 5 # used, selected iteration # systematics
# unfolding_frac_flat: .1

fd_folding_method: 3d
fd_root: '/data2/vkucera/powheg/trees_powheg_fd_F05_R05.root'
Expand Down

0 comments on commit a5898a6

Please sign in to comment.