diff --git a/Analysis/HistTupleProducer.py b/Analysis/HistTupleProducer.py index e7c61b2a..be290854 100644 --- a/Analysis/HistTupleProducer.py +++ b/Analysis/HistTupleProducer.py @@ -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"]: @@ -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) @@ -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 = [] diff --git a/Analysis/tasks.py b/Analysis/tasks.py index a949ebc1..bed8326b 100644 --- a/Analysis/tasks.py +++ b/Analysis/tasks.py @@ -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) @@ -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) @@ -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()} @@ -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()} @@ -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()} @@ -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()): diff --git a/Common/Setup.py b/Common/Setup.py index 8e18a146..8030b00f 100644 --- a/Common/Setup.py +++ b/Common/Setup.py @@ -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: