Skip to content

Commit

Permalink
add hist objects
Browse files Browse the repository at this point in the history
  • Loading branch information
aalvesan committed Jul 12, 2024
1 parent bd72451 commit 27d3cbf
Showing 1 changed file with 26 additions and 23 deletions.
49 changes: 26 additions & 23 deletions hbt/config/hist_hooks.py
Original file line number Diff line number Diff line change
@@ -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):
Expand All @@ -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 =
Expand Down

0 comments on commit 27d3cbf

Please sign in to comment.