Skip to content
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
10 changes: 5 additions & 5 deletions Analysis/HistTupleProducer.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,8 @@ def createHistTuple(
histTupleDef.analysis_setup(setup)
isData = dataset_name == "data"

if type(setup.global_params["variables"]) == list:
variables = setup.global_params["variables"]
elif type(setup.global_params["variables"]) == dict:
variables = setup.global_params["variables"].keys()
binned_variables = setup.histTuple_plot_vars
fullres_variables = setup.histTuple_fullres_vars

norm_uncertainties = set()
if setup.global_params["compute_rel_weights"]:
Expand All @@ -97,7 +95,7 @@ def createHistTuple(

print("Defining binnings for variables")
flatten_vars = set()
for var in variables:
for var in binned_variables:
if isinstance(var, dict) and "vars" in var:
for v in var["vars"]:
flatten_vars.add(v)
Expand Down Expand Up @@ -143,6 +141,8 @@ def createHistTuple(
)

dfw = histTupleDef.GetDfw(df, setup, dataset_name)
for var in fullres_variables:
dfw.colToSave.append(var)

selection_tags = setup.global_params.get("histTuple_selectors", [])
selection_flags = []
Expand Down
12 changes: 6 additions & 6 deletions Analysis/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def workflow_requires(self):
var_produced_by = self.setup.var_producer_map

flatten_vars = set()
for var in self.global_params["variables"]:
for var in self.setup.histTuple_vars:
if isinstance(var, dict) and "vars" in var:
for v in var["vars"]:
flatten_vars.add(v)
Expand Down Expand Up @@ -286,7 +286,7 @@ def _build_branch_map(self):
datasets_to_consider.append("data")

flatten_vars = set()
for var in self.global_params["variables"]:
for var in self.setup.histTuple_vars:
if isinstance(var, dict) and "vars" in var:
for v in var["vars"]:
flatten_vars.add(v)
Expand Down Expand Up @@ -519,7 +519,7 @@ def bundle_flavours(self):

@property
def active_variables(self):
all_vars = _dedup_variables(self.global_params["variables"])
all_vars = _dedup_variables(self.setup.histTuple_plot_vars)
if not self.variables:
return all_vars
selected = {v.strip() for v in self.variables.split(",") if v.strip()}
Expand Down Expand Up @@ -751,7 +751,7 @@ def bundle_flavours(self):

@property
def active_variables(self):
all_vars = _dedup_variables(self.global_params["variables"])
all_vars = _dedup_variables(self.setup.histTuple_plot_vars)
if not self.variables:
return all_vars
selected = {v.strip() for v in self.variables.split(",") if v.strip()}
Expand Down Expand Up @@ -1275,7 +1275,7 @@ def bundle_flavours(self):

@property
def active_variables(self):
all_vars = _dedup_variables(self.global_params["variables"])
all_vars = _dedup_variables(self.setup.histTuple_plot_vars)
if not self.variables:
return all_vars
selected = {v.strip() for v in self.variables.split(",") if v.strip()}
Expand Down Expand Up @@ -1364,7 +1364,7 @@ def create_branch_map(self):
customisations=self.customisations,
).create_branch_map()
var_dict = {}
for var in self.global_params["variables"]:
for var in self.setup.histTuple_plot_vars:
var_name = var if isinstance(var, str) else var["name"]
var_dict[var_name] = var
for k, (_, (var, _, _)) in enumerate(merge_map.items()):
Expand Down
33 changes: 33 additions & 0 deletions Common/Setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,39 @@ def __init__(
else:
processes[key] = item

self.histTuple_flavor = self.global_params["histTuple_flavor"]
print(f"Using histTuple flavor {self.histTuple_flavor}")
self.histTuple_plot_vars = self.global_params["histTuple_flavors"][
self.histTuple_flavor
]["variables"]
self.histTuple_fullres_vars = self.global_params["histTuple_flavors"][
self.histTuple_flavor
]["fullResolution_variables"]

# Safety check that the fullres or the plotvars do not have duplicates
plotvar_dict = {}
for var in self.histTuple_plot_vars:
var_name = var["name"] if isinstance(var, dict) else var
if var_name in plotvar_dict:
raise RuntimeError(f"Duplicated plot variable name {var_name}")
plotvar_dict[var_name] = var

fullresvar_dict = {}
for var in self.histTuple_plot_vars:
var_name = var["name"] if isinstance(var, dict) else var
if var_name in fullresvar_dict:
raise RuntimeError(
f"Duplicated full resolution variable name {var_name}"
)
fullresvar_dict[var_name] = var

# Now a merged list removing the duplicates
var_set = set()
for var in list(plotvar_dict.values()) + list(fullresvar_dict.values()):
var_name = var["name"] if isinstance(var, dict) else var
var_set.add(var_name)
self.histTuple_vars = list(var_set)

def collect_base_processes(p_name, parent_name=None):
if p_name not in processes:
if parent_name is not None:
Expand Down
Loading