diff --git a/hbt/config/hist_hooks.py b/hbt/config/hist_hooks.py index 4b5d940..0d65cc5 100644 --- a/hbt/config/hist_hooks.py +++ b/hbt/config/hist_hooks.py @@ -1,29 +1,30 @@ import order as od +import hist -def create_regions(id, regions, mc_hist, data_hist, cat_name, cat_parent): +def create_regions(cat_id, regions, mc_hist, data_hist, cat_name, cat_parent): if "os" in cat_name: - if "non_iso" in cat_name: + if "noniso" not in cat_name: regions[cat_parent]["A"] = {} - regions[cat_parent]["A"]["mc"] = mc_hist.counts()[id] - regions[cat_parent]["A"]["data"] = data_hist.counts()[id] - print("...created region A for category " + cat_parent) + regions[cat_parent]["A"]["mc"] = mc_hist[{"category": hist.loc(cat_id)}] + regions[cat_parent]["A"]["data"] = data_hist[{"category": hist.loc(cat_id)}] + print("... created region A for category " + cat_parent) else: regions[cat_parent]["B"] = {} - regions[cat_parent]["B"]["mc"] = mc_hist.counts()[id] - regions[cat_parent]["B"]["data"] = data_hist.counts()[id] - print("...created region B for category " + cat_parent) + regions[cat_parent]["B"]["mc"] = mc_hist[{"category": hist.loc(cat_id)}] + regions[cat_parent]["B"]["data"] = data_hist[{"category": hist.loc(cat_id)}] + print("... created region B for category " + cat_parent) elif "ss" in cat_name: - if "non_iso" in cat_name: + if "noniso" not in cat_name: regions[cat_parent]["C"] = {} - regions[cat_parent]["C"]["mc"] = mc_hist.counts()[id] - regions[cat_parent]["C"]["data"] = data_hist.counts()[id] - print("...created region C for category " + cat_parent) + regions[cat_parent]["C"]["mc"] = mc_hist[{"category": hist.loc(cat_id)}] + regions[cat_parent]["C"]["data"] = data_hist[{"category": hist.loc(cat_id)}] + print("... created region C for category " + cat_parent) else: regions[cat_parent]["D"] = {} - regions[cat_parent]["D"]["mc"] = mc_hist.counts()[id] - regions[cat_parent]["D"]["data"] = data_hist.counts()[id] - print("...created region D for category " + cat_parent) + regions[cat_parent]["D"]["mc"] = mc_hist[{"category": hist.loc(cat_id)}] + regions[cat_parent]["D"]["data"] = data_hist[{"category": hist.loc(cat_id)}] + print("... created region D for category " + cat_parent) def add_hooks(cfg: od.Config): @@ -39,33 +40,35 @@ def ana_ABCD(task, hists): data_hist = sum(data_hists[1:], data_hists[0].copy()) # check if the number of categories is multiple of 4 - index = mc_hist.axes[0].size - if index % 4 != 0: + cat_count = mc_hist.axes[0].size + if cat_count % 4 != 0: raise ValueError("Number of categories is not a multiple of 4") # initialise regions dictionary regions = {} - for id in range(index): - # get corresponding category number, name and parent category - cat_id = mc_hist.axes[0].value(id) + for index in range(cat_count): + # get corresponding category id, name and parent category + cat_id = mc_hist.axes[0].value(index) cat_name = cfg.get_category(cat_id).name cat_parent = cat_name.partition("_")[0] + print("... processing category " + cat_name) # define ABCD regions if cat_parent not in regions: regions[cat_parent] = {} - create_regions(id, regions, mc_hist, data_hist, cat_name, cat_parent) + create_regions(cat_id, regions, mc_hist, data_hist, cat_name, cat_parent) else: - create_regions(id, regions, mc_hist, data_hist, cat_name, cat_parent) + create_regions(cat_id, regions, mc_hist, data_hist, cat_name, cat_parent) from IPython import embed embed() quit() + # calculate rate factor #C_rate = regions[cat_parent] - hists[cfg.processes.n.qcd] = mc_hist * 0.5 + #hists[cfg.processes.n.qcd] = B*(D/C) # calculate rate factor # C_rate =