Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft implementation for prior variation #941

Merged
merged 1 commit into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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