From 2ad097b9ee41255b90b0116ebb81a061e98ebfec Mon Sep 17 00:00:00 2001
From: Sascha Stahl <sascha.stahl@cern.ch>
Date: Fri, 11 Mar 2022 11:05:56 +0100
Subject: [PATCH] Remove special field EVENT, add parameter event_variables to
 FunTuple

---
 Phys/FunTuple/python/FunTuple/common_util.py | 11 +----------
 Phys/FunTuple/python/FunTuple/functions.py   |  9 +++++++--
 2 files changed, 8 insertions(+), 12 deletions(-)

diff --git a/Phys/FunTuple/python/FunTuple/common_util.py b/Phys/FunTuple/python/FunTuple/common_util.py
index d64a22108..a1bc2ce70 100644
--- a/Phys/FunTuple/python/FunTuple/common_util.py
+++ b/Phys/FunTuple/python/FunTuple/common_util.py
@@ -65,11 +65,9 @@ def conduct_checks_and_transform(name, tuple_name, fields, variables, loki_pream
     ]
 
     #get the FunctorCollections for the special field name "ALL" (used to add to other field names)
-    #and get the dictionary of FunctorCollections for special field name "EVENT"
     #and the list of variables keys without ALL (used later for checks)
     variables_all = None
     variables_keys_wo_ALL = []
-    thor_functor_dict_event_info = {}
     for vk in variables_keys:
         if vk == 'ALL':
             variables_all = variables[vk]
@@ -77,13 +75,6 @@ def conduct_checks_and_transform(name, tuple_name, fields, variables, loki_pream
                 raise TypeError(
                     f"The value of variables['{vk}'], for field name '{vk}', is not of type FunctorCollection but of type '{type(variables_all)}'. Please check!"
                     ) from None
-        elif vk == 'EVENT':
-            funct_coll_evt = variables[vk]
-            if not isinstance(funct_coll_evt, FunctorCollection):
-                raise TypeError(
-                    f"The value of variables['{vk}'], for field name '{vk}', is not of type FunctorCollection but of type '{type(funct_coll_evt)}'. Please check!"
-                    ) from None
-            thor_functor_dict_event_info = funct_coll_evt.get_thor_functors()
         else:
             variables_keys_wo_ALL += [vk]
 
@@ -143,6 +134,6 @@ def conduct_checks_and_transform(name, tuple_name, fields, variables, loki_pream
     #pack the output
     output_args = (field_names_prefix, decay_descriptors, loki_functors,
                    loki_functor_field_names, thor_functors,
-                   thor_functor_field_names, thor_functor_dict_event_info)
+                   thor_functor_field_names)
 
     return output_args
diff --git a/Phys/FunTuple/python/FunTuple/functions.py b/Phys/FunTuple/python/FunTuple/functions.py
index 941f8c294..9071758fc 100644
--- a/Phys/FunTuple/python/FunTuple/functions.py
+++ b/Phys/FunTuple/python/FunTuple/functions.py
@@ -12,6 +12,7 @@
 from PyConf.Algorithms import FunTupleBase_Particles
 from PyConf.Algorithms import FunTupleBase_MCParticles
 from .common_util import conduct_checks_and_transform
+from .FunctorCollection import FunctorCollection
 
 
 def FunTuple_Particles(name,
@@ -19,6 +20,7 @@ def FunTuple_Particles(name,
                        fields,
                        variables,
                        inputs,
+                       event_variables=FunctorCollection(),
                        loki_preamble=[],
                        run_full_counter_mode=True,
                        **kwargs):
@@ -28,6 +30,7 @@ def FunTuple_Particles(name,
             tuple_name (string): Name of the TTree.
             fields (dict): Dictionary of {field (branch) name : decay descriptor}. The field name is used in naming the variable in the ntuple and decay descriptor in finding the candidates.
             variables (dict): Dictionary of {variable name: Functor code}. The variable name is used in naming the variable in nTuple (for a given field) and functor code used to retrive LoKi or ThOr functors.
+            event_variables (FunctorCollection): FunctorCollection of {variable name: Functor code} for event quantities to be added to every candidate.
             inputs (PyConf DataHandle): Input location of LHCb::Particles to run over.
             loki_preamble (string): A LoKi preamble that renames a complex functor built out of base functors that could be used as Functor code in "variables" dictionary above.
             run_full_counter_mode (bool): A boolean to set counters and monitor each of the fields.
@@ -44,7 +47,7 @@ def FunTuple_Particles(name,
     loki_functor_field_names = output_args[3]
     thor_functors = output_args[4]
     thor_functor_field_names = output_args[5]
-    thor_functor_dict_event_info = output_args[6]
+    thor_functor_dict_event_info = event_variables.get_thor_functors()
     return FunTupleBase_Particles(
         name=name,
         tuple_name=tuple_name,
@@ -66,6 +69,7 @@ def FunTuple_MCParticles(name,
                          fields,
                          variables,
                          inputs,
+                         event_variables=FunctorCollection(),
                          loki_preamble=[],
                          run_full_counter_mode=True,
                          **kwargs):
@@ -75,6 +79,7 @@ def FunTuple_MCParticles(name,
             tuple_name (string): Name of the TTree.
             fields (dict): Dictionary of {field (branch) name : decay descriptor}. The field name is used in naming the variable in the ntuple and decay descriptor in finding the candidates.
             variables (dict): Dictionary of {variable name: Functor code}. The variable name is used in naming the variable in nTuple (for a given field) and functor code used to retrive LoKi or ThOr functors.
+            event_variables (FunctorCollection): FunctorCollection of {variable name: Functor code} for event quantities to be added to every candidate.
             inputs (PyConf DataHandle): Input location of LHCb::MCParticles to run over.
             loki_preamble (string): A LoKi preamble that renames a complex functor built out of base functors that could be used as Functor code in "variables" dictionary above.
             run_full_counter_mode (bool): A boolean to set counters and monitor each of the fields.
@@ -92,7 +97,7 @@ def FunTuple_MCParticles(name,
     loki_functor_field_names = output_args[3]
     thor_functors = output_args[4]
     thor_functor_field_names = output_args[5]
-    thor_functor_dict_event_info = output_args[6]
+    thor_functor_dict_event_info = event_variables.get_thor_functors()
     return FunTupleBase_MCParticles(
         name=name,
         tuple_name=tuple_name,
-- 
GitLab