Skip to content
Open
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
10 changes: 10 additions & 0 deletions config/binning_example_2d.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"combined_bins": [
{"y_bin": [0, 250], "x_bins": [0.0, 0.5, 0.7, 0.8, 0.85, 0.9, 0.91, 0.92, 0.93, 0.94, 0.95, 0.96, 0.97, 0.98, 0.99, 1.0]},
{"y_bin": [250, 275], "x_bins": [0.0, 0.5, 0.7, 0.8, 0.85, 0.9, 0.91, 0.92, 0.93, 0.94, 0.95, 0.96, 0.97, 0.98, 0.99, 1.0]},
{"y_bin": [275, 300], "x_bins": [0.0, 0.5, 0.7, 0.8, 0.85, 0.9, 0.91, 0.92, 0.93, 0.94, 0.95, 0.96, 0.97, 0.98, 0.99, 1.0]},
{"y_bin": [300, 325], "x_bins": [0.0, 0.5, 0.7, 0.8, 0.85, 0.9, 0.91, 0.92, 0.93, 0.94, 0.95, 0.96, 0.97, 0.98, 0.99, 1.0]},
{"y_bin": [325, 350], "x_bins": [0.0, 0.5, 0.7, 0.8, 0.85, 0.9, 0.91, 0.92, 0.93, 0.94, 0.95, 0.96, 0.97, 0.98, 0.99, 1.0]},
{"y_bin": [350, 500], "x_bins": [0.0, 0.5, 0.7, 0.8, 0.85, 0.9, 0.91, 0.92, 0.93, 0.94, 0.95, 0.96, 0.97, 0.98, 0.99, 1.0]}
]
}
36 changes: 23 additions & 13 deletions dc_make/binner.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import json
from StatInference.common.tools import listToVector, rebinAndFill, importROOT
import FLAF.Common.HistHelper as HistHelper
ROOT = importROOT()

class Binner:
def __init__(self, hist_bins):
self.hist_bins = []
self.linearize = False
if type(hist_bins) == str:
#Load json
with open(hist_bins) as f:
Expand All @@ -15,8 +17,14 @@ def __init__(self, hist_bins):
})
elif hist_bins is not None:
raise RuntimeError("Incompatible hist_bins format")
for entry in self.hist_bins:
entry['bins'] = listToVector(entry['bins'], 'double')

# Loaded the string, now what is the object?
if type(self.hist_bins) == dict:
if "combined_bins" in self.hist_bins:
self.linearize = True
else:
for entry in self.hist_bins:
entry['bins'] = listToVector(entry['bins'], 'double')

def applyBinning(self, era, channel, category, model_params, hist):
if len(self.hist_bins) == 0:
Expand All @@ -30,16 +38,18 @@ def entry_passes(entry):
for param_key, param_value in model_params.items():
if not (param_key not in entry or param_value in entry[param_key]): return False
return True

for entry in self.hist_bins:
# print(entry)
if entry_passes(entry): new_binning.append(entry['bins'])
if len(new_binning) <= 0:
raise RuntimeError(f"No binning found for era/channel/category/params {era}/{channel}/{category}/{model_params}")
if len(new_binning) >= 2:
raise RuntimeError(f"Multiple binnings found for era/channel/category/params {era}/{channel}/{category}/{model_params}")

new_hist = ROOT.TH1F(hist.GetName(), hist.GetTitle(), len(new_binning[0]) - 1,new_binning[0].data())
rebinAndFill(new_hist, hist)

if self.linearize:
new_hist = HistHelper.RebinHisto(hist, self.hist_bins, hist.GetTitle())
else:
for entry in self.hist_bins:
# print(entry)
if entry_passes(entry): new_binning.append(entry['bins'])
if len(new_binning) <= 0:
raise RuntimeError(f"No binning found for era/channel/category/params {era}/{channel}/{category}/{model_params}")
if len(new_binning) >= 2:
raise RuntimeError(f"Multiple binnings found for era/channel/category/params {era}/{channel}/{category}/{model_params}")
new_hist = ROOT.TH1F(hist.GetName(), hist.GetTitle(), len(new_binning[0]) - 1,new_binning[0].data())
rebinAndFill(new_hist, hist)
return new_hist

4 changes: 2 additions & 2 deletions dc_make/maker.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,14 +178,14 @@ def getShape(self, process, era, channel, category, model_params, unc_name=None,
for subp in process.subprocesses:
hist_name = f"{channel}/{category}/{subp}"
if unc_name and unc_scale:
hist_name += f"_{unc_name}{unc_scale}"
hist_name += f"_{unc_name}_{unc_scale}"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we directly switch to __{unc_name}__{unc_scale}?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you are requesting that the internal (histogram) version have two _, then this is actually a request in the FLAF space. The output of data cards should be a shape with {Process}_{unc_name}{unc_scale}

subhist = file.Get(hist_name)
if subhist == None:
raise RuntimeError(f"Cannot find histogram {hist_name} in {file.GetName()}")
hists.append(self.hist_binner.applyBinning(era, channel, category, model_params, subhist))
else:
if unc_name and unc_scale:
hist_name += f"_{unc_name}{unc_scale}"
hist_name += f"_{unc_name}_{unc_scale}"
hist = file.Get(hist_name)
if hist == None:
raise RuntimeError(f"Cannot find histogram {hist_name} in {file.GetName()}")
Expand Down