From 2c499ebe402eb37dd2f63e4db7690b67c4bf02b2 Mon Sep 17 00:00:00 2001
From: Juan Leite <jbaptist@lxplus977.cern.ch>
Date: Wed, 24 Apr 2024 12:24:12 +0200
Subject: [PATCH 01/34] BnoC: PPbarLines

---
 Liv_PPBarLines/hlt1.py                        |  32 +
 Liv_PPBarLines/hlt2.py                        |  57 ++
 Liv_PPBarLines/info.yaml                      | 109 +++
 Liv_PPBarLines/main_Liv_PPBarLines_B0PPbar.py |  32 +
 .../main_Liv_PPBarLines_B0PPbarPPbar.py       |  32 +
 .../main_Liv_PPBarLines_Bs0PPbar.py           |  32 +
 .../main_Liv_PPBarLines_Bs0PPbarPPbar.py      |  32 +
 Liv_PPBarLines/options/Bsd_ppbarlines.py      | 181 +++++
 Liv_PPBarLines/options/tupling.py             | 664 ++++++++++++++++++
 9 files changed, 1171 insertions(+)
 create mode 100644 Liv_PPBarLines/hlt1.py
 create mode 100644 Liv_PPBarLines/hlt2.py
 create mode 100644 Liv_PPBarLines/info.yaml
 create mode 100644 Liv_PPBarLines/main_Liv_PPBarLines_B0PPbar.py
 create mode 100644 Liv_PPBarLines/main_Liv_PPBarLines_B0PPbarPPbar.py
 create mode 100644 Liv_PPBarLines/main_Liv_PPBarLines_Bs0PPbar.py
 create mode 100644 Liv_PPBarLines/main_Liv_PPBarLines_Bs0PPbarPPbar.py
 create mode 100644 Liv_PPBarLines/options/Bsd_ppbarlines.py
 create mode 100644 Liv_PPBarLines/options/tupling.py

diff --git a/Liv_PPBarLines/hlt1.py b/Liv_PPBarLines/hlt1.py
new file mode 100644
index 0000000000..77154c68ae
--- /dev/null
+++ b/Liv_PPBarLines/hlt1.py
@@ -0,0 +1,32 @@
+###############################################################################
+# (c) Copyright 2023 CERN for the benefit of the LHCb Collaboration           #
+#                                                                             #
+# This software is distributed under the terms of the GNU General Public      #
+# Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING".   #
+#                                                                             #
+# In applying this licence, CERN does not waive the privileges and immunities #
+# granted to it by virtue of its status as an Intergovernmental Organization  #
+# or submit itself to any jurisdiction.                                       #
+###############################################################################
+"""
+Configures running HLT1 via Moore.
+"""
+
+from Moore import Options
+from Moore.config import allen_control_flow
+from RecoConf.hlt1_allen import allen_gaudi_config, get_allen_line_names
+from PyConf.application import configure_input, configure
+
+def alg_config(options: Options):
+    """
+    Configures algorithm running of HLT1 via Moore to be passed to Analysis Productions.
+    """
+
+    config = configure_input(options)
+    with allen_gaudi_config.bind(sequence="hlt1_pp_matching_no_ut_1000KHz"):
+        line_names = get_allen_line_names()
+        allen_node = allen_control_flow(options)
+        config.update(configure(options, allen_node))
+
+    return config
+
diff --git a/Liv_PPBarLines/hlt2.py b/Liv_PPBarLines/hlt2.py
new file mode 100644
index 0000000000..8c53befcde
--- /dev/null
+++ b/Liv_PPBarLines/hlt2.py
@@ -0,0 +1,57 @@
+####################################
+# options                          #
+####################################
+
+import Moore
+from Moore import Options, run_moore, config
+from Moore.lines import Hlt2Line
+from RecoConf.reconstruction_objects import reconstruction as reconstruction
+from Moore import options, run_moore
+from RecoConf.global_tools import stateProvider_with_simplified_geom, trackMasterExtrapolator_with_simplified_geom
+from RecoConf.hlt2_global_reco import reconstruction as hlt2_reconstruction, make_light_reco_pr_kf_without_UT
+from RecoConf.hlt2_tracking import (
+    make_TrackBestTrackCreator_tracks,
+    make_PrKalmanFilter_noUT_tracks,
+    make_PrKalmanFilter_Velo_tracks,
+    make_PrKalmanFilter_Seed_tracks,
+)
+from RecoConf.decoders import default_VeloCluster_source
+from RecoConf.event_filters import require_gec
+from Moore.streams import Stream, Streams
+import sys
+
+
+from Hlt2Conf.lines.bnoc import all_lines as ppbar_lines
+
+
+
+################## options ############
+    
+public_tools = [
+    trackMasterExtrapolator_with_simplified_geom(),
+    stateProvider_with_simplified_geom(),
+]
+
+def pass_through_line(name="Hlt2MCPassThroughLine"):
+    """Return a HLT2 line that performs no selection but runs and persists the reconstruction
+    """
+    return Hlt2Line(name=name, prescale=1, algs=[], persistreco=True)
+
+
+def _make_lines():
+    mylines = [builder() for builder in ppbar_lines.values()]
+    mylines += [pass_through_line()]
+    return mylines
+
+def alg_config(options: Options):
+    with reconstruction.bind(from_file=False), hlt2_reconstruction.bind(make_reconstruction=make_light_reco_pr_kf_without_UT),\
+        require_gec.bind(skipUT=True),\
+        default_VeloCluster_source.bind(bank_type="VPRetinaCluster"),\
+        make_TrackBestTrackCreator_tracks.bind(max_ghost_prob=0.7, max_chi2ndof=sys.float_info.max),\
+        make_PrKalmanFilter_Velo_tracks.bind(max_chi2ndof=5.),\
+        make_PrKalmanFilter_noUT_tracks.bind(max_chi2ndof=4.),\
+        make_PrKalmanFilter_Seed_tracks.bind(max_chi2ndof=6.):
+        config = run_moore(options, make_streams=_make_lines, public_tools=public_tools)
+        return config
+
+
diff --git a/Liv_PPBarLines/info.yaml b/Liv_PPBarLines/info.yaml
new file mode 100644
index 0000000000..bc7c0e4424
--- /dev/null
+++ b/Liv_PPBarLines/info.yaml
@@ -0,0 +1,109 @@
+defaults:
+  inform:
+    - juan.baptista.leite@cern.ch
+  wg: BnoC
+
+# 2024
+{%- set polarities = [
+    'Down', 'Up'
+]%}
+
+{%- set mc_datasets = [
+ ( 'B0PPbar', 'Sim10c' , '7.6', 'DIGI', '11102031'),
+ ( 'Bs0PPbar', 'Sim10c' , '7.6', 'DIGI', '13102031'),
+ ( 'B0PPbarPPbar', 'Sim10c' , '7.6', 'DIGI', '11104077'),
+ ( 'Bs0PPbarPPbar', 'Sim10c' , '7.6', 'DIGI', '13104077'),
+]%}
+
+{%- for p in polarities %}
+{%- for sigtype, simul, nu, inptype, evttype in mc_datasets %}
+
+{{sigtype}}_Mag{{p}}_MC_HLT1:
+  application: "Moore/v55r7@x86_64_v3-el9-gcc13+detdesc-opt+g"
+  input: 
+    bk_query: /MC/Dev/Beam6800GeV-expected-2024-Mag{{p}}-Nu{{nu}}-25ns-Pythia8/{{simul}}/{{evttype}}/{{inptype}}
+    dq_flags:
+      - OK
+    n_test_lfns: 1
+  output: MC_HLT1.DST
+  options: 
+    entrypoint: Liv_PPBarLines.hlt1:alg_config
+    extra_options:
+      input_raw_format: 0.5
+      conddb_tag: sim-20231017-vc-md100
+      dddb_tag: dddb-20231017
+      input_type: ROOT
+      output_type: ROOT
+      simulation: True
+      data_type: "Upgrade"
+      evt_max: -1
+      scheduler_legacy_mode: False
+
+{{sigtype}}_Mag{{p}}_MC_HLT2:
+  application: "Moore/v55r6@x86_64_v3-el9-gcc13+detdesc-opt+g"
+  input:
+    job_name: {{sigtype}}_Mag{{p}}_MC_HLT1
+  output: MC_HLT2.DST
+  options:
+    entrypoint: Liv_PPBarLines.hlt2:alg_config
+    extra_options:
+      conddb_tag: sim-20231017-vc-md100
+      dddb_tag: dddb-20231017
+      input_type: "ROOT"
+      output_type: "ROOT"
+      simulation: True
+      data_type: "Upgrade"
+      evt_max: -1
+      output_manifest_file: "HLT2.tck.json"
+      scheduler_legacy_mode: False
+
+ 
+
+{{sigtype}}_2024_Mag{{p}}_MC_Tuple:
+  application: "DaVinci/v64r3@x86_64_v3-el9-gcc13+detdesc-opt+g"
+  input:
+    job_name: {{sigtype}}_Mag{{p}}_MC_HLT2
+  output: MC_{{sigtype}}.ROOT
+  options:
+    entrypoint: Liv_PPBarLines.main_Liv_PPBarLines_{{sigtype}}:main
+    extra_options:
+      input_raw_format: 0.5
+      input_type: ROOT
+      simulation: True
+      data_type: Upgrade
+      conddb_tag: sim-20231017-vc-md100
+      dddb_tag: dddb-20231017
+      input_process: "Hlt2"
+      input_manifest_file: "HLT2.tck.json"
+
+{%- endfor %}
+{%- endfor %}
+
+{%- for p in polarities %}
+{%- for sigtype, simul, nu, inptype, evttype in mc_datasets %}
+{{sigtype}}_2024_Mag{{p}}_Tuple:
+  application: "DaVinci/v64r3"
+  turbo: True
+  input:
+    bk_query: LHCb/Collision24/Beam6800GeV-VeloClosed-MagDown-Excl-UT/Real Data/Sprucing24c1/94000000/BNOC.DST
+    dq_flags:
+      - UNCHECKED
+      - OK
+    n_test_lfns: 1
+  output: RealData_{{sigtype}}.ROOT
+  options:
+    entrypoint: Liv_PPBarLines.main_Liv_PPBarLines_{{sigtype}}:main
+    extra_options:
+      input_raw_format: 0.5
+      input_type: ROOT
+      simulation: False
+      data_type: "Upgrade"
+      event_store: HiveWhiteBoard
+      geometry_version: run3/trunk
+      conditions_version: master
+      input_process: "TurboPass"
+      input_stream: "bnoc"
+      evt_max: -1
+
+{%- endfor %}
+{%- endfor %}
\ No newline at end of file
diff --git a/Liv_PPBarLines/main_Liv_PPBarLines_B0PPbar.py b/Liv_PPBarLines/main_Liv_PPBarLines_B0PPbar.py
new file mode 100644
index 0000000000..e419dcc699
--- /dev/null
+++ b/Liv_PPBarLines/main_Liv_PPBarLines_B0PPbar.py
@@ -0,0 +1,32 @@
+###############################################################################
+# (c) Copyright 2021-2022 CERN for the benefit of the LHCb Collaboration      #
+#                                                                             #
+# This software is distributed under the terms of the GNU General Public      #
+# Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING".   #
+#                                                                             #
+# In applying this licence, CERN does not waive the privileges and immunities #
+# granted to it by virtue of its status as an Intergovernmental Organization  #
+# or submit itself to any jurisdiction.                                       #
+###############################################################################
+
+from .options.Bsd_ppbarlines import *
+
+from DaVinci import Options, make_config
+from PyConf.reading import get_pvs, get_rec_summary
+
+def main(options: Options):
+        
+    # get ODIN and DecReports location
+    pvs = get_pvs()
+    rec_summary = get_rec_summary()
+
+    """ CORREGGERE TUPLES """
+
+    tuples = {    
+        "BdToPpPm" : maketuple_BdToPPbar(options, pvs, rec_summary)
+    }
+        
+    config = make_config(options, tuples)
+
+    return config
+
diff --git a/Liv_PPBarLines/main_Liv_PPBarLines_B0PPbarPPbar.py b/Liv_PPBarLines/main_Liv_PPBarLines_B0PPbarPPbar.py
new file mode 100644
index 0000000000..d68efa29f4
--- /dev/null
+++ b/Liv_PPBarLines/main_Liv_PPBarLines_B0PPbarPPbar.py
@@ -0,0 +1,32 @@
+###############################################################################
+# (c) Copyright 2021-2022 CERN for the benefit of the LHCb Collaboration      #
+#                                                                             #
+# This software is distributed under the terms of the GNU General Public      #
+# Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING".   #
+#                                                                             #
+# In applying this licence, CERN does not waive the privileges and immunities #
+# granted to it by virtue of its status as an Intergovernmental Organization  #
+# or submit itself to any jurisdiction.                                       #
+###############################################################################
+
+from .options.Bsd_ppbarlines import *
+
+from DaVinci import Options, make_config
+from PyConf.reading import get_pvs, get_rec_summary
+
+def main(options: Options):
+        
+    # get ODIN and DecReports location
+    pvs = get_pvs()
+    rec_summary = get_rec_summary()
+
+    """ CORREGGERE TUPLES """
+
+    tuples = {    
+        "BdToPpPmPpPm" : maketuple_BdToPPbarPPbar(options, pvs, rec_summary)
+    }
+        
+    config = make_config(options, tuples)
+
+    return config
+
diff --git a/Liv_PPBarLines/main_Liv_PPBarLines_Bs0PPbar.py b/Liv_PPBarLines/main_Liv_PPBarLines_Bs0PPbar.py
new file mode 100644
index 0000000000..76ecbf2222
--- /dev/null
+++ b/Liv_PPBarLines/main_Liv_PPBarLines_Bs0PPbar.py
@@ -0,0 +1,32 @@
+###############################################################################
+# (c) Copyright 2021-2022 CERN for the benefit of the LHCb Collaboration      #
+#                                                                             #
+# This software is distributed under the terms of the GNU General Public      #
+# Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING".   #
+#                                                                             #
+# In applying this licence, CERN does not waive the privileges and immunities #
+# granted to it by virtue of its status as an Intergovernmental Organization  #
+# or submit itself to any jurisdiction.                                       #
+###############################################################################
+
+from .options.Bsd_ppbarlines import *
+
+from DaVinci import Options, make_config
+from PyConf.reading import get_pvs, get_rec_summary
+
+def main(options: Options):
+        
+    # get ODIN and DecReports location
+    pvs = get_pvs()
+    rec_summary = get_rec_summary()
+
+    """ CORREGGERE TUPLES """
+
+    tuples = {    
+        "Bs0ToPpPm" : maketuple_Bs0ToPPbar(options, pvs, rec_summary)  
+    }
+        
+    config = make_config(options, tuples)
+
+    return config
+
diff --git a/Liv_PPBarLines/main_Liv_PPBarLines_Bs0PPbarPPbar.py b/Liv_PPBarLines/main_Liv_PPBarLines_Bs0PPbarPPbar.py
new file mode 100644
index 0000000000..588eb058cb
--- /dev/null
+++ b/Liv_PPBarLines/main_Liv_PPBarLines_Bs0PPbarPPbar.py
@@ -0,0 +1,32 @@
+###############################################################################
+# (c) Copyright 2021-2022 CERN for the benefit of the LHCb Collaboration      #
+#                                                                             #
+# This software is distributed under the terms of the GNU General Public      #
+# Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING".   #
+#                                                                             #
+# In applying this licence, CERN does not waive the privileges and immunities #
+# granted to it by virtue of its status as an Intergovernmental Organization  #
+# or submit itself to any jurisdiction.                                       #
+###############################################################################
+
+from .options.Bsd_ppbarlines import *
+
+from DaVinci import Options, make_config
+from PyConf.reading import get_pvs, get_rec_summary
+
+def main(options: Options):
+        
+    # get ODIN and DecReports location
+    pvs = get_pvs()
+    rec_summary = get_rec_summary()
+
+    """ CORREGGERE TUPLES """
+
+    tuples = {    
+        "Bs0ToPpPmPpPm" : maketuple_Bs0ToPPbarPPbar(options, pvs, rec_summary)
+    }
+        
+    config = make_config(options, tuples)
+
+    return config
+
diff --git a/Liv_PPBarLines/options/Bsd_ppbarlines.py b/Liv_PPBarLines/options/Bsd_ppbarlines.py
new file mode 100644
index 0000000000..0d119272f1
--- /dev/null
+++ b/Liv_PPBarLines/options/Bsd_ppbarlines.py
@@ -0,0 +1,181 @@
+from .tupling import *
+
+import Functors as F
+from Functors.math import log
+from DaVinci import Options, make_config
+from DaVinci.algorithms import create_lines_filter
+from PyConf.reading import get_particles
+from FunTuple import FunctorCollection
+from PyConf.reading import get_particles, get_pvs
+import FunTuple.functorcollections as FC
+from FunTuple import FunTuple_Particles as Funtuple
+from DecayTreeFitter import DecayTreeFitter
+
+"""
+ BdsToPPbar
+ BdsToPPbarPPbar
+ nb: https://gitlab.cern.ch/lhcb/Moore/-/blob/master/Hlt/Hlt2Conf/python/Hlt2Conf/lines/bnoc/BToPpPm.py?ref_type=heads
+
+ """
+
+# BdsToPPbar
+def maketuple_BdToPPbar(options, pvs, rec_summary):
+    name = "BdToPPbar"
+    turbo_line = "Hlt2BnoC_BdsToPpPm"
+
+    input_data = get_particles(f"/Event/HLT2/{turbo_line}/Particles")
+    myfilter = create_lines_filter(f"LineFilter_{turbo_line}_{{hash}}",[turbo_line],)
+
+    branches = {
+        "B0" : "[B0 -> p+ p~-]CC",
+        "pp"  : "[B0 -> ^p+ p~-]CC",
+        "pm"  : "[B0 -> p+ ^p~-]CC",
+    }
+
+    # DTF_MASS = DecayTreeFitter(
+    #     name='DTF_Bd_Mass_{hash}',
+    #     input_particles=input_data,
+    #     mass_constraints=["B0"])
+
+    # DTF_MASS_PV = DecayTreeFitter(
+    #     'DTF_Bd_Mass_PV_{hash}',
+    #     input_particles=input_data,
+    #     input_pvs=pvs,
+    #     mass_constraints=["B0"])
+
+    basic_variables = make_basic_variables(options, pvs, input_data) 
+    composite_variables = make_composite_variables(options, pvs, input_data) 
+
+    variables = {
+        "B0"   : composite_variables ,
+        "pp"    : basic_variables,
+        "pm"   : basic_variables,
+    }
+
+    mytuple  = Funtuple(name=name, tuple_name="DecayTree", fields=branches, variables = variables,  event_variables=make_hlt2_event_variables(options, pvs, rec_summary), inputs=input_data)
+
+    return [myfilter, mytuple]
+
+
+def maketuple_Bs0ToPPbar(options, pvs, rec_summary):
+    name = "Bs0ToPPbar"
+    turbo_line = "Hlt2BnoC_BdsToPpPm"
+
+    input_data = get_particles(f"/Event/HLT2/{turbo_line}/Particles")
+    myfilter = create_lines_filter(f"LineFilter_{turbo_line}_{{hash}}",[turbo_line])
+
+    branches = {
+        "B0" : "[B_s0 -> p+ p~-]CC",
+        "pp"  : "[B_s0 -> ^p+ p~-]CC",
+        "pm"  : "[B_s0 -> p+ ^p~-]CC",
+    }
+
+    # DTF_MASS = DecayTreeFitter(
+    #     name='DTF_Bs0_Mass_{hash}',
+    #     input_particles=input_data,
+    #     mass_constraints=["B_s0"])
+
+    # DTF_MASS_PV = DecayTreeFitter(
+    #     'DTF_Bs0_Mass_PV_{hash}',
+    #     input_particles=input_data,
+    #     input_pvs=pvs,
+    #     mass_constraints=["B_s0"])
+
+    basic_variables = make_basic_variables(options, pvs, input_data) 
+    composite_variables = make_composite_variables(options, pvs, input_data) 
+
+
+    variables = {
+        "B0"   : composite_variables ,
+        "pp"    : basic_variables,
+        "pm"   : basic_variables,
+    }
+
+    mytuple  = Funtuple(name=name, tuple_name="DecayTree", fields=branches, variables = variables,  event_variables=make_hlt2_event_variables(options, pvs, rec_summary), inputs=input_data)
+
+    return [myfilter, mytuple]
+
+
+# BdsToPPbarPPbar
+def maketuple_BdToPPbarPPbar(options, pvs, rec_summary):
+    name = "BdToPPbarPPbar"
+    turbo_line = "Hlt2BnoC_BdsToPpPmPpPm"
+
+    input_data = get_particles(f"/Event/HLT2/{turbo_line}/Particles")
+    myfilter = create_lines_filter(f"LineFilter_{turbo_line}_{{hash}}",[turbo_line],)
+
+    branches = {
+        "B0" : "[B0 -> p+ p~- p+ p~-]CC",
+        "p1"  : "[B0 -> ^p+ p~- p+ p~-]CC",
+        "pm1"  : "[B0 -> p+ ^p~- p+ p~-]CC",
+        "p2"  : "[B0 ->  p+ p~- ^p+ p~-]CC",
+        "pm2"  : "[B0 -> p+ p~- p+ ^p~-]CC",
+    }
+
+    # DTF_MASS = DecayTreeFitter(
+    #     name='DTF_Bd_Mass_{hash}',
+    #     input_particles=input_data,
+    #     mass_constraints=["B0"])
+
+    # DTF_MASS_PV = DecayTreeFitter(
+    #     'DTF_Bd_Mass_PV_{hash}',
+    #     input_particles=input_data,
+    #     input_pvs=pvs,
+    #     mass_constraints=["B0"])
+
+    basic_variables = make_basic_variables(options, pvs, input_data)
+    composite_variables = make_composite_variables_4body(options, pvs, input_data) 
+    
+    variables = {
+        "B0"   : composite_variables ,
+        "p1"    : basic_variables,
+        "pm1"   : basic_variables,
+        "p2"    : basic_variables,
+        "pm2"   : basic_variables,
+    }   
+
+    mytuple  = Funtuple(name=name, tuple_name="DecayTree", fields=branches, variables = variables,  event_variables=make_hlt2_event_variables(options, pvs, rec_summary), inputs=input_data)
+
+    return [myfilter, mytuple]
+
+
+def maketuple_Bs0ToPPbarPPbar(options, pvs, rec_summary):
+    name = "Bs0ToPPbarPPbar"
+    turbo_line = "Hlt2BnoC_BdsToPpPmPpPm"
+
+    input_data = get_particles(f"/Event/HLT2/{turbo_line}/Particles")
+    myfilter = create_lines_filter(f"LineFilter_{turbo_line}_{{hash}}",[turbo_line],)
+
+    branches = {
+        "B0" : "[B_s0 -> p+ p~- p+ p~-]CC",
+        "p1"  : "[B_s0 -> ^p+ p~- p+ p~-]CC",
+        "pm1"  : "[B_s0 -> p+ ^p~- p+ p~-]CC",
+        "p2"  : "[B_s0 ->  p+ p~- ^p+ p~-]CC",
+        "pm2"  : "[B_s0 -> p+ p~- p+ ^p~-]CC",
+    }
+
+    # DTF_MASS = DecayTreeFitter(
+    #     name='DTF_Bs0_Mass_{hash}',
+    #     input_particles=input_data,
+    #     mass_constraints=["B_s0"])
+
+    # DTF_MASS_PV = DecayTreeFitter(
+    #     'DTF_Bs0_Mass_PV_{hash}',
+    #     input_particles=input_data,
+    #     input_pvs=pvs,
+    #     mass_constraints=["B_s0"])
+
+    basic_variables = make_basic_variables(options, pvs, input_data)
+    composite_variables = make_composite_variables_4body(options, pvs, input_data) 
+    
+    variables = {
+        "B0"   : composite_variables ,
+        "p1"    : basic_variables,
+        "pm1"   : basic_variables,
+        "p2"    : basic_variables,
+        "pm2"   : basic_variables,
+    }   
+
+    mytuple  = Funtuple(name=name, tuple_name="DecayTree", fields=branches, variables = variables,  event_variables=make_hlt2_event_variables(options, pvs, rec_summary), inputs=input_data)
+
+    return [myfilter, mytuple]
diff --git a/Liv_PPBarLines/options/tupling.py b/Liv_PPBarLines/options/tupling.py
new file mode 100644
index 0000000000..6ffc5d07c5
--- /dev/null
+++ b/Liv_PPBarLines/options/tupling.py
@@ -0,0 +1,664 @@
+###############################################################################
+# (c) Copyright 2022 CERN for the benefit of the LHCb Collaboration           #
+#                                                                             #
+# This software is distributed under the terms of the GNU General Public      #
+# Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING".   #
+#                                                                             #
+# In applying this licence, CERN does not waive the privileges and immunities #
+# granted to it by virtue of its status as an Intergovernmental Organization  #
+# or submit itself to any jurisdiction.                                       #
+###############################################################################
+"""Common configuration functions
+
+"""
+
+import Functors as F
+from Functors.math import log
+
+from FunTuple import FunctorCollection
+from FunTuple.functorcollections import (
+    MCHierarchy,
+    MCPromptDecay,
+    Kinematics,
+    SelectionInfo,
+    HltTisTos,
+    MCVertexInfo,
+    MCKinematics,
+    ParticleID, #wrong variables PID_PI = 0, PROBNN_D = nan
+    EventInfo,
+    ParticleIsolation,
+    MCPrimaries,
+)
+
+from DaVinciMCTools import MCTruthAndBkgCat
+from PyConf.Algorithms import ParticleToSubcombinationsAlg
+from DecayTreeFitter import DecayTreeFitter
+
+Hlt1_global_lines = [
+    "Hlt1GECPassthroughDecision",
+    "Hlt1BeamGasDecision",
+    "Hlt1PassthroughDecision",
+    "Hlt1NoBeamDecision",
+    "Hlt1BeamOneDecision",
+    "Hlt1BeamTwoDecision",
+    "Hlt1BothBeamsDecision",
+    "Hlt1ODINLumiDecision",
+    "Hlt1ODINVeloOpenDecision",
+    "Hlt1ODINNoBiasDecision",
+    "Hlt1VeloMicroBiasDecision",
+    "Hlt1RICH1AlignmentDecision",
+    "Hlt1RICH2AlignmentDecision",
+    "Hlt1BeamGasDecision",
+    "Hlt1L02PPiDecision",
+    "Hlt1LowMassNoipDielectron_massSlice1_promptDecision",
+    "Hlt1LowMassNoipDielectron_SS_massSlice1_promptDecision",
+    "Hlt1LowMassNoipDielectron_massSlice2_promptDecision",
+    "Hlt1LowMassNoipDielectron_SS_massSlice2_promptDecision",
+    "Hlt1LowMassNoipDielectron_massSlice3_promptDecision",
+    "Hlt1LowMassNoipDielectron_SS_massSlice3_promptDecision",
+    "Hlt1LowMassNoipDielectron_massSlice4_promptDecision",
+    "Hlt1LowMassNoipDielectron_SS_massSlice4_promptDecision",
+    "Hlt1LowMassNoipDielectron_massSlice1_displacedDecision",
+    "Hlt1LowMassNoipDielectron_SS_massSlice1_displacedDecision",
+    "Hlt1LowMassNoipDielectron_massSlice2_displacedDecision",
+    "Hlt1LowMassNoipDielectron_SS_massSlice2_displacedDecision",
+    "Hlt1LowMassNoipDielectron_massSlice3_displacedDecision",
+    "Hlt1LowMassNoipDielectron_SS_massSlice3_displacedDecision",
+    "Hlt1LowMassNoipDielectron_massSlice4_displacedDecision",
+    "Hlt1LowMassNoipDielectron_SS_massSlice4_displacedDecision",
+]
+Hlt1_1track_lines = [
+    "Hlt1TrackMVADecision",
+    "Hlt1LowPtMuonDecision",
+    "Hlt1SingleHighPtMuonDecision",
+    "Hlt1SingleHighPtMuonNoMuIDDecision",
+    "Hlt1TrackMuonMVADecision",
+    "Hlt1OneMuonTrackLineDecision",
+    "Hlt1TrackElectronMVADecision",
+    "Hlt1SingleHighPtElectronDecision",
+    "Hlt1SingleHighEtDecision",
+]
+Hlt1_lines = Hlt1_1track_lines+[
+    "Hlt1TwoTrackMVACharmXSecDecision",
+    "Hlt1TwoTrackMVADecision",
+    "Hlt1TwoTrackKsDecision",
+    "Hlt1D2KPiDecision",
+    "Hlt1D2KKDecision",
+    "Hlt1D2PiPiDecision",
+    "Hlt1KsToPiPiDecision",
+    "Hlt1LowPtDiMuonDecision",#removed
+    "Hlt1DiMuonNoIPDecision",
+    "Hlt1DiMuonNoIP_ssDecision",
+    "Hlt1DiMuonHighMassDecision",
+    "Hlt1DiMuonLowMassDecision",#replaced by Hlt1DiMuonDisplacedDecision
+    "Hlt1DiMuonSoftDecision",
+    "Hlt1DiMuonDisplacedDecision",
+    "Hlt1TwoKsDecision",
+    "Hlt1D2KPiAlignmentDecision",
+    "Hlt1DiMuonHighMassAlignmentDecision",
+    "Hlt1DisplacedDiMuonAlignmentDecision",
+    "Hlt1DisplacedDielectronDecision",
+    "Hlt1DisplacedLeptonsDecision",#removed
+]
+
+
+Hlt2_lines = [
+    "Hlt2BnoC_BdsToPpPmPpPm",
+    "Hlt2BnoC_BdsToPpPm",
+] 
+
+def make_composite_variables(options, pvs, data, add_truth=True):
+    if not options.simulation:
+        add_truth = False
+    variables = (
+       FunctorCollection(
+           {
+               "MAXPT": F.MAX(F.PT),
+               "MINPT": F.MIN(F.PT),
+               "SUMPT": F.SUM(F.PT),
+               "MAXP": F.MAX(F.P),
+               "MINP": F.MIN(F.P),
+               "BPVDIRA": F.BPVDIRA(pvs),
+               "VCHI2DOF": F.CHI2DOF, #CHI2VXNDOF
+               "BPVFDCHI2": F.BPVFDCHI2(pvs),
+               "BPVFD": F.BPVFD(pvs),
+               "BPVVDRHO": F.BPVVDRHO(pvs),
+               "BPVVDZ": F.BPVVDZ(pvs),
+               "BPVIPCHI2": F.BPVIPCHI2(pvs),
+               "BPVIP": F.BPVIP(pvs),
+               "LOGBPVIPCHI2": log(F.BPVIPCHI2(pvs)),
+               "BPVLTIME": F.BPVLTIME(pvs),
+               "MAXBPVIPCHI2": F.MAX(F.BPVIPCHI2(pvs)), #MAX_
+               "MINBPVIPCHI2": F.MIN(F.BPVIPCHI2(pvs)),
+               "MAXBPVIP": F.MAX(F.BPVIP(pvs)),
+               "MINBPVIP": F.MIN(F.BPVIP(pvs)),
+               "MAXDOCACHI2": F.MAXDOCACHI2,
+               "MAXDOCA": F.MAXDOCA,
+               "MAXSDOCACHI2": F.MAXSDOCACHI2,
+               "MAXSDOCA": F.MAXSDOCA,
+               "M12": F.SUBCOMB(Functor=F.MASS, Indices=(1, 2)),
+               "SDOCA12"     : F.SDOCA(Child1=1,Child2=2),
+               "SDOCACHI212" : F.SDOCACHI2(Child1=1,Child2=2),
+               "DOCA12"      : F.DOCA(Child1=1,Child2=2),
+               "DOCACHI212"  : F.DOCACHI2(Child1=1,Child2=2),
+               "COS12": F.ALV(1, 2),
+               "ETA": F.ETA,
+               "PHI": F.PHI,
+               "END_VX": F.END_VX, #END_
+               "END_VY": F.END_VY,
+               "END_VZ": F.END_VZ,
+               "BPVX": F.BPVX(pvs),
+               "BPVY": F.BPVY(pvs),
+               "BPVZ": F.BPVZ(pvs),
+               "ALLPVFD"     : F.ALLPV_FD(pvs),
+               "ALLPVIP"     : F.ALLPV_IP(pvs),
+               "OBJECT_KEY": F.OBJECT_KEY,
+           }
+       )
+       + Kinematics()
+        #+ ParticleID(extra_info=True) #only for daughters
+    )
+
+    variables += HltTisTos(
+        selection_type="Hlt1", trigger_lines=Hlt1_lines, data=data
+    )
+
+    if add_truth:
+        variables = add_truth_matching_functors(
+            options,
+            variables,
+            data,
+            hierarchy=True,
+            kinematics=True,
+            vertex_info=True,
+            bkgcat=True,
+        )
+
+    return variables
+
+def make_tistoscombinations(options, pvs, data):
+    algo_output = ParticleToSubcombinationsAlg( Input=data )
+    relations = algo_output.OutputRelations
+
+    tistos_variables_extra = HltTisTos(
+        selection_type="Hlt1", trigger_lines=["Hlt1TwoTrackMVADecision"], data=algo_output.OutputParticles
+    )
+    tistos_combinations = {}
+    for k,v in tistos_variables_extra.get_thor_functors().items():
+        tistos_combinations[k + "_SUBCOMB" ] = F.MAP_INPUT_ARRAY( v, relations )
+    tistos_combinations = FunctorCollection( tistos_combinations )
+
+    return tistos_combinations
+
+def make_composite_variables_3body(options, pvs, data, add_truth=True):
+
+    variables = (
+        FunctorCollection(
+            {
+                #13
+                "M13": F.SUBCOMB(Functor=F.MASS, Indices=(1, 3)),
+                "SDOCA13"     : F.SDOCA(Child1=1,Child2=3),
+                "SDOCACHI213" : F.SDOCACHI2(Child1=1,Child2=3),
+                "DOCA13"      : F.DOCA(Child1=1,Child2=3),
+                "DOCACHI213"  : F.DOCACHI2(Child1=1,Child2=3),
+                "COS13": F.ALV(1, 3),
+                #23
+                "M23": F.SUBCOMB(Functor=F.MASS, Indices=(2, 3)),
+                "SDOCA23"     : F.SDOCA(Child1=2,Child2=3),
+                "SDOCACHI223" : F.SDOCACHI2(Child1=2,Child2=3),
+                "DOCA23"      : F.DOCA(Child1=2,Child2=3),
+                "DOCACHI223"  : F.DOCACHI2(Child1=2,Child2=3),
+                "COS23": F.ALV(2, 3),
+            }
+        )
+    )
+    return make_composite_variables(options, pvs, data, add_truth)+make_tistoscombinations(options, pvs, data)+variables
+
+def make_composite_variables_4body(options, pvs, data, add_truth=True):
+
+    variables = (
+        FunctorCollection(
+            {
+                #14
+                "M14": F.SUBCOMB(Functor=F.MASS, Indices=(1, 4)),
+                "SDOCA14"     : F.SDOCA(Child1=1,Child2=4),
+                "SDOCACHI214" : F.SDOCACHI2(Child1=1,Child2=4),
+                "DOCA14"      : F.DOCA(Child1=1,Child2=4),
+                "DOCACHI214"  : F.DOCACHI2(Child1=1,Child2=4),
+                "COS14": F.ALV(1, 4),
+                #24
+                "M24": F.SUBCOMB(Functor=F.MASS, Indices=(2, 4)),
+                "SDOCA24"     : F.SDOCA(Child1=2,Child2=4),
+                "SDOCACHI224" : F.SDOCACHI2(Child1=2,Child2=4),
+                "DOCA24"      : F.DOCA(Child1=2,Child2=4),
+                "DOCACHI224"  : F.DOCACHI2(Child1=2,Child2=4),
+                "COS24": F.ALV(2, 4),
+                #34
+                "M34": F.SUBCOMB(Functor=F.MASS, Indices=(3, 4)),
+                "SDOCA34"     : F.SDOCA(Child1=3,Child2=4),
+                "SDOCACHI234" : F.SDOCACHI2(Child1=3,Child2=4),
+                "DOCA34"      : F.DOCA(Child1=3,Child2=4),
+                "DOCACHI234"  : F.DOCACHI2(Child1=3,Child2=4),
+                "COS34": F.ALV(3, 4),
+            }
+        )
+    )
+    return make_composite_variables_3body(options,pvs, data, add_truth)+variables
+
+def make_DeltaM_variable(options):
+    return FunctorCollection({"DM": F.MASS - F.CHILD(1, F.MASS)})
+
+def make_basic_variables(options, pvs, data, add_truth=True):
+    if not options.simulation:
+        add_truth = False
+    variables = (
+       FunctorCollection(
+           {
+               "TRCHI2DOF": F.CHI2DOF @ F.TRACK,
+               "ETA": F.ETA,
+               "PHI": F.PHI,
+               "TRGHOSTPROB": F.GHOSTPROB,
+               "BPVIPCHI2": F.BPVIPCHI2(pvs),
+               "BPVIP": F.BPVIP(pvs),
+               "BPVX": F.BPVX(pvs),
+               "BPVY": F.BPVY(pvs),
+               "BPVZ": F.BPVZ(pvs),
+               "TX"          : F.TX,
+               "TY"          : F.TY,
+               "MINIPCHI2"   : F.MINIPCHI2(pvs),
+               "MINIP"       : F.MINIP(pvs),
+               "KEY"         : F.VALUE_OR(-1) @ F.OBJECT_KEY @ F.TRACK,
+               "CTB"         : F.POSITION @ F.CLOSESTTOBEAM @ F.TRACK,
+               "ISMUON"      : F.ISMUON,
+               "TRACKPT": F.TRACK_PT,
+               "TRACKHISTORY": F.VALUE_OR(-1) @ F.TRACKHISTORY @ F.TRACK,
+               "QOVERP": F.QOVERP @ F.TRACK,
+               "NDOF": F.VALUE_OR(-1) @ F.NDOF @ F.TRACK,
+               "NFTHITS": F.VALUE_OR(-1) @ F.NFTHITS @ F.TRACK,
+               "NHITS": F.VALUE_OR(-1) @ F.NHITS @ F.TRACK,
+               "NUTHITS": F.VALUE_OR(-1) @ F.NUTHITS @ F.TRACK,
+               "NVPHITS": F.VALUE_OR(-1) @ F.NVPHITS @ F.TRACK,
+               "TRACKHASVELO": F.VALUE_OR(-1) @ F.TRACKHASVELO @ F.TRACK,
+               "TRACKHASUT": F.VALUE_OR(-1) @ F.TRACKHASUT @ F.TRACK,
+               "OBJECT_KEY": F.OBJECT_KEY,
+               "HASBREM": F.HASBREM,
+               "BREMENERGY": F.BREMENERGY,
+               "BREMBENDCORR": F.BREMBENDCORR,
+           }
+       )
+       + Kinematics()
+       + ParticleID(extra_info=True)
+    )
+
+    variables += HltTisTos(
+        selection_type="Hlt1", trigger_lines=Hlt1_1track_lines, data=data
+    )
+
+    if add_truth:
+        variables = add_truth_matching_functors(
+            options,
+            variables,
+            data,
+            hierarchy=True,
+            kinematics=True,
+            vertex_info=True,
+            bkgcat=False,
+        )
+
+    return variables
+
+def make_hlt2_event_variables(options, pvs, rec_summary):
+    # define event level variables
+    evt_variables = EventInfo()
+    evt_variables += SelectionInfo(selection_type="Hlt2", trigger_lines=Hlt2_lines)
+    evt_variables += SelectionInfo(selection_type="Hlt1", trigger_lines=Hlt1_global_lines)
+    evt_variables += FunctorCollection(
+        {
+            "ALLPVX": F.ALLPVX(pvs),
+            "ALLPVY": F.ALLPVY(pvs),
+            "ALLPVZ": F.ALLPVZ(pvs),
+            "nPVs": F.SIZE(pvs),
+            "nTracks": F.VALUE_OR(-1) @ F.RECSUMMARY_INFO(rec_summary, "nTracks"),
+            "nLongTracks": F.VALUE_OR(-1) @ F.RECSUMMARY_INFO(rec_summary, "nLongTracks"),
+            "nMuonTracks": F.VALUE_OR(-1) @ F.RECSUMMARY_INFO(rec_summary, "nMuonTracks"),
+            "nFTClusters": F.VALUE_OR(-1) @ F.RECSUMMARY_INFO(rec_summary, "nFTClusters"),
+            "nVPClusters": F.VALUE_OR(-1) @ F.RECSUMMARY_INFO(rec_summary, "nVPClusters"),
+            "nUTClusters": F.VALUE_OR(-1) @ F.RECSUMMARY_INFO(rec_summary, "nUTClusters"),
+            "nSPDhits": F.VALUE_OR(-1) @ F.RECSUMMARY_INFO(rec_summary, "nSPDhits"),
+            "nEcalClusters": F.VALUE_OR(-1) @ F.RECSUMMARY_INFO(rec_summary, "nEcalClusters"),
+            "nEcalClusters": F.VALUE_OR(-1) @ F.RECSUMMARY_INFO(rec_summary, "nEcalClusters"),
+            "eCalTot": F.VALUE_OR(-1) @ F.RECSUMMARY_INFO(rec_summary, "eCalTot"),
+            "hCalTot": F.VALUE_OR(-1) @ F.RECSUMMARY_INFO(rec_summary, "hCalTot"),
+            "nRich1Hits": F.VALUE_OR(-1) @ F.RECSUMMARY_INFO(rec_summary, "nRich1Hits"),
+            "nRich2Hits": F.VALUE_OR(-1) @ F.RECSUMMARY_INFO(rec_summary, "nRich2Hits"),
+        }
+    )
+    return evt_variables
+
+
+def make_unpack_only_mc_variables():
+    MC_MOTHER_ID = lambda gen: F.VALUE_OR(0) @ F.MC_MOTHER(gen, F.PARTICLE_ID)
+    MC_MOTHER_KEY = lambda gen: F.VALUE_OR(-1) @ F.MC_MOTHER(gen, F.OBJECT_KEY)
+    return (
+        FunctorCollection(
+            {
+                "TRUEID": F.PARTICLE_ID,
+                "MC_MOTHER_ID": MC_MOTHER_ID(1),
+                "MC_MOTHER_KEY": MC_MOTHER_KEY(1),
+                "MC_GD_MOTHER_ID": MC_MOTHER_ID(2),
+                "MC_GD_MOTHER_KEY": MC_MOTHER_KEY(2),
+                "MC_GD_GD_MOTHER_ID": MC_MOTHER_ID(3),
+                "MC_GD_GD_MOTHER_KEY": MC_MOTHER_KEY(3),
+                "TRUEORIGIN_VX": F.ORIGIN_VX,
+                "TRUEORIGIN_VY": F.ORIGIN_VY,
+                "TRUEORIGIN_VZ": F.ORIGIN_VZ,
+                "TRUEEND_VX": F.END_VX,
+                "TRUEEND_VY": F.END_VY,
+                "TRUEEND_VZ": F.END_VZ,
+            }
+        )
+        + Kinematics()
+        + MCPromptDecay()
+    )
+
+
+####
+
+def add_truth_matching_functors(
+    options,
+    variables,
+    data,
+    hierarchy=True,
+    kinematics=True,
+    vertex_info=True,
+    bkgcat=False,
+    prompt_info=True,
+):
+    """Add MC truth matching functors to an existing FunctorCollection.
+
+    Args:
+        options (DaVinci.Options): DaVinci options object.
+        variables (FunctorCollection): FunctorCollection to modify
+        data: data handle
+        hierarchy (bool): Add MCHierarchy info (default True)
+        kinematics (bool): Add MCKinematics info (default True)
+        vertex_info (bool): Add MCVertexInfo (default True)
+        bkgcat (bool): Add TRUEKEY and BKGCAT functors - intended for composite particles (default False)
+        prompt_info (bool): Add MCPromptDecay info (default True)
+
+    Returns:
+        FunctorCollection: modified FunctorCollection with truth matched variables.
+    """
+    assert (
+        options.simulation
+    ), "options.simulation is set to False - it doesn't make sense to add truth matching."
+
+    MCTRUTH = MCTruthAndBkgCat(data)
+
+    if bkgcat:
+        variables += FunctorCollection(
+            {
+                # Important note: specify an invalid value for integer functors if there exists no truth info.
+                #                 The invalid value for floating point functors is set to nan.
+                "TRUEKEY": F.VALUE_OR(-1) @ MCTRUTH(F.OBJECT_KEY),
+                "BKGCAT": MCTRUTH.BkgCat,
+            }
+        )
+    if hierarchy:
+        variables += MCHierarchy(mctruth_alg=MCTRUTH)  # likely to change again!!
+    if vertex_info:
+        variables += MCVertexInfo(mctruth_alg=MCTRUTH)  # likely to change again!!
+    if kinematics:
+        variables += MCKinematics(mctruth_alg=MCTRUTH)  # likely to change again!!
+    if prompt_info:
+        variables += MCPromptDecay(mctruth_alg=MCTRUTH)
+
+    return variables
+
+### DTF variables ###
+
+def make_basic_dtf_variables(options, pvs, data, add_truth=True, DTF=None, pv_constraint=False, mass_constraint=False, particle_name=""):
+    if not options.simulation:
+        add_truth = False
+    variables = ( 
+        FunctorCollection(
+            {
+                "ETA": F.ETA,
+                "PHI": F.PHI,
+                "BPVIPCHI2": F.BPVIPCHI2(pvs),
+                "BPVIP": F.BPVIP(pvs),
+                "TX"          : F.TX,
+                "TY"          : F.TY,
+                "MINIPCHI2"   : F.MINIPCHI2(pvs),
+                "MINIP"       : F.MINIP(pvs),
+            }
+        )
+        + Kinematics()
+        #+ ParticleID(extra_info=True)
+    )
+
+
+    if(mass_constraint):
+        if(pv_constraint): # MASS + PV
+            dtf_variables_mass_pv = FunctorCollection({
+                        'DTF_PV_M'+ particle_name + '_' + k: DTF(v)
+                        for k, v in variables.get_thor_functors().items()
+                    })
+            return dtf_variables_mass_pv
+        else: # MASS
+            dtf_variables_mass = FunctorCollection(
+                {'DTF_M'+ particle_name + '_' + k: DTF(v)
+                 for k, v in variables.get_thor_functors().items()})
+        return dtf_variables_mass
+
+    elif(pv_constraint): # PV
+        dtf_variables_pv = FunctorCollection({
+                'DTF_PV_' + k: DTF(v)
+                for k, v in variables.get_thor_functors().items()
+            })
+        return dtf_variables_pv
+
+    else: # NO MASS/PV
+        dtf_variables = FunctorCollection(
+            {'DTF_' + k: DTF(v)
+             for k, v in variables.get_thor_functors().items()})
+        return dtf_variables
+
+def make_composite_dtf_variables(options, pvs, data, add_truth=True, DTF=None, pv_constraint=False, mass_constraint=False, particle_name=""):
+    if not options.simulation:
+        add_truth = False
+    variables = (
+        FunctorCollection(
+            {
+                "MAXPT": F.MAX(F.PT),
+                "MINPT": F.MIN(F.PT),
+                "SUMPT": F.SUM(F.PT),
+                "MAXP": F.MAX(F.P),
+                "MINP": F.MIN(F.P),
+                "BPVDIRA": F.BPVDIRA(pvs),
+                # "VCHI2DOF": F.CHI2DOF, #CHI2VXNDOF
+                "BPVFDCHI2": F.BPVFDCHI2(pvs),
+                "BPVFD": F.BPVFD(pvs),
+                "BPVVDRHO": F.BPVVDRHO(pvs),
+                "BPVVDZ": F.BPVVDZ(pvs),
+                "BPVIPCHI2": F.BPVIPCHI2(pvs),
+                "BPVIP": F.BPVIP(pvs),
+                "LOGBPVIPCHI2": log(F.BPVIPCHI2(pvs)),
+                "BPVLTIME": F.BPVLTIME(pvs),
+                "MAXBPVIPCHI2": F.MAX(F.BPVIPCHI2(pvs)), #MAX_
+                "MINBPVIPCHI2": F.MIN(F.BPVIPCHI2(pvs)),
+                "MAXBPVIP": F.MAX(F.BPVIP(pvs)),
+                "MINBPVIP": F.MIN(F.BPVIP(pvs)),
+                "M12": F.SUBCOMB(Functor=F.MASS, Indices=(1, 2)),
+                "ETA": F.ETA,
+                "PHI": F.PHI,
+            }
+        )
+        + Kinematics()
+        #+ ParticleID(extra_info=True) #only for daughters
+    )
+
+
+    if(mass_constraint):
+        if(pv_constraint): # MASS + PV
+            dtf_variables_mass_pv = FunctorCollection({
+                        'DTF_PV_M'+ particle_name + '_' + k: DTF(v)
+                        for k, v in variables.get_thor_functors().items()
+                    })
+            return dtf_variables_mass_pv
+        else: # MASS
+            dtf_variables_mass = FunctorCollection(
+                {'DTF_M'+ particle_name + '_' + k: DTF(v)
+                 for k, v in variables.get_thor_functors().items()})
+        return dtf_variables_mass
+
+    elif(pv_constraint): # PV
+        dtf_variables_pv = FunctorCollection({
+                'DTF_PV_' + k: DTF(v)
+                for k, v in variables.get_thor_functors().items()
+            })
+        return dtf_variables_pv
+
+    else: # NO MASS/PV
+        dtf_variables = FunctorCollection(
+            {'DTF_' + k: DTF(v)
+             for k, v in variables.get_thor_functors().items()})
+        return dtf_variables
+
+def make_MC_basic_variables():
+    variables = (
+        FunctorCollection(
+            {
+                "OBJECT_KEY": F.OBJECT_KEY,
+                "ETA": F.ETA,
+                "PHI": F.PHI,
+                "ORIGIN_VX": F.ORIGIN_VX,
+                "ORIGIN_VY": F.ORIGIN_VY,
+                "ORIGIN_VZ": F.ORIGIN_VZ,
+                "FOURMOMENTUM": F.FOURMOMENTUM,
+            }
+        )
+        + Kinematics()
+    )
+
+    return variables
+
+def make_MC_composite_variables():
+    variables = (
+        FunctorCollection(
+            {
+                "END_VX": F.END_VX, #END_
+                "END_VY": F.END_VY,
+                "END_VZ": F.END_VZ,
+                "LTIME": F.MC_LIFETIME,
+                "OBJECT_KEY": F.OBJECT_KEY,
+                "ETA": F.ETA,
+                "PHI": F.PHI,
+                "ORIGIN_VX": F.ORIGIN_VX,
+                "ORIGIN_VY": F.ORIGIN_VY,
+                "ORIGIN_VZ": F.ORIGIN_VZ,
+                "FOURMOMENTUM": F.FOURMOMENTUM,
+            }
+        )
+        + Kinematics()
+    )
+
+    return variables
+
+def make_MC_event_variables(mc_header):
+    # define event level variables
+    evt_variables = EventInfo()
+    evt_variables += MCPrimaries(mc_header=mc_header)
+
+    return evt_variables
+
+def make_top_isolation_variables(hlt2_line, input_data, locations = ["LongTrackIso","NeutralIso"]):
+    from PyConf.reading import get_particles
+    from IsolationTools import VertexAndConeIsolation
+
+    possible_charm_locations = ["LongTrackIso", "TTrackIso", "DownstreamTrackIso", "UpstreamTrackIso", "NeutralIso", "PizIso"]
+    coneangles = [0.25,0.5,1.,1.5,2.]
+    
+    count = 0
+    for location in locations:
+        extra_particles = get_particles(f"/Event/HLT2/{hlt2_line}/{location}/Particles")
+
+        for coneangle in coneangles:
+            top_RTAlg = VertexAndConeIsolation(
+                name=location+"_"+str(coneangle),
+                reference_particles=input_data,
+                related_particles=extra_particles,
+                cut=F.DR2<coneangle)
+            
+            if count == 0:
+                top_iso_variables = ParticleIsolation(isolation_alg=top_RTAlg,array_indx_name='indx')
+            else:
+                top_iso_variables += ParticleIsolation(isolation_alg=top_RTAlg,array_indx_name='indx')
+            count += 1
+                
+
+    return top_iso_variables
+
+def make_basic_isolation_variables(hlt2_line, input_data, locations = ["LongTrackIso","NeutralIso"]):
+    from PyConf.reading import get_particles
+    from IsolationTools import VertexAndConeIsolation
+    from PyConf.Algorithms import ThOrParticleSelection
+
+    basic_code = (F.FILTER(F.ALL) @ F.GET_ALL_BASICS())
+    basic_particles = ThOrParticleSelection(InputParticles=input_data, Functor=basic_code).OutputSelection
+
+    possible_charm_locations = ["LongTrackIso", "TTrackIso", "DownstreamTrackIso", "UpstreamTrackIso", "NeutralIso", "PizIso"]
+    coneangles = [0.25,0.5,1.,1.5,2.]
+    
+    count = 0
+    for location in locations:
+        extra_particles = get_particles(f"/Event/HLT2/{hlt2_line}/{location}/Particles")
+
+        for coneangle in coneangles:
+            basic_RTAlg = VertexAndConeIsolation(
+                name=location+"_"+str(coneangle),
+                reference_particles=basic_particles,
+                related_particles=extra_particles,
+                cut=F.DR2<coneangle)
+            
+            if count == 0:
+                basic_iso_variables = ParticleIsolation(isolation_alg=basic_RTAlg,array_indx_name='indx')
+            else:
+                basic_iso_variables += ParticleIsolation(isolation_alg=basic_RTAlg,array_indx_name='indx')
+            count += 1
+                
+
+    return basic_iso_variables
+
+
+def make_intermediate_isolation_variables(hlt2_line, input_data, locations = ["LongTrackIso","NeutralIso"], composite_ID = "J/psi(1S)"):
+    from PyConf.reading import get_particles
+    from IsolationTools import VertexAndConeIsolation
+    from PyConf.Algorithms import ThOrParticleSelection
+
+    intermediate_code = F.FILTER(F.IS_ABS_ID(composite_ID)) @ F.GET_ALL_DESCENDANTS()
+    intermediate_particles = ThOrParticleSelection(InputParticles=input_data, Functor=intermediate_code).OutputSelection
+
+    possible_charm_locations = ["LongTrackIso", "TTrackIso", "DownstreamTrackIso", "UpstreamTrackIso", "NeutralIso", "PizIso"]
+    coneangles = [0.25,0.5,1.,1.5,2.]
+    
+    count = 0
+    for location in locations:
+        extra_particles = get_particles(f"/Event/HLT2/{hlt2_line}/{location}/Particles")
+
+        for coneangle in coneangles:
+            intermediate_RTAlg = VertexAndConeIsolation(
+                name=location+"_"+str(coneangle),
+                reference_particles=intermediate_particles,
+                related_particles=extra_particles,
+                cut=F.DR2<coneangle)
+            
+            if count == 0:
+                intermediate_iso_variables = ParticleIsolation(isolation_alg=intermediate_RTAlg,array_indx_name='indx')
+            else:
+                intermediate_iso_variables += ParticleIsolation(isolation_alg=intermediate_RTAlg,array_indx_name='indx')
+            count += 1
+                
+
+    return intermediate_iso_variables
+
-- 
GitLab


From 5226acf73870ca6fb7fc3dbba033acbae8d9f894 Mon Sep 17 00:00:00 2001
From: Juan Leite <jbaptist@lxplus977.cern.ch>
Date: Wed, 24 Apr 2024 15:56:29 +0200
Subject: [PATCH 02/34] fix typo on bk_query and Decay desc. of Bs0 channels

---
 Liv_PPBarLines/info.yaml                 | 11 +++++++--
 Liv_PPBarLines/options/Bsd_ppbarlines.py | 29 +++++++++---------------
 Liv_PPBarLines/options/tupling.py        |  2 +-
 3 files changed, 21 insertions(+), 21 deletions(-)

diff --git a/Liv_PPBarLines/info.yaml b/Liv_PPBarLines/info.yaml
index bc7c0e4424..99d2835e07 100644
--- a/Liv_PPBarLines/info.yaml
+++ b/Liv_PPBarLines/info.yaml
@@ -38,6 +38,10 @@ defaults:
       data_type: "Upgrade"
       evt_max: -1
       scheduler_legacy_mode: False
+      compression:
+        algorithm: ZSTD
+        level: 1
+        max_buffer_size: 1048576
 
 {{sigtype}}_Mag{{p}}_MC_HLT2:
   application: "Moore/v55r6@x86_64_v3-el9-gcc13+detdesc-opt+g"
@@ -56,6 +60,10 @@ defaults:
       evt_max: -1
       output_manifest_file: "HLT2.tck.json"
       scheduler_legacy_mode: False
+      compression:
+        algorithm: ZSTD
+        level: 1
+        max_buffer_size: 1048576
 
  
 
@@ -83,9 +91,8 @@ defaults:
 {%- for sigtype, simul, nu, inptype, evttype in mc_datasets %}
 {{sigtype}}_2024_Mag{{p}}_Tuple:
   application: "DaVinci/v64r3"
-  turbo: True
   input:
-    bk_query: LHCb/Collision24/Beam6800GeV-VeloClosed-MagDown-Excl-UT/Real Data/Sprucing24c1/94000000/BNOC.DST
+    bk_query: /LHCb/Collision24/Beam6800GeV-VeloClosed-MagDown-Excl-UT/Real Data/Sprucing24c1/94000000/BNOC.DST
     dq_flags:
       - UNCHECKED
       - OK
diff --git a/Liv_PPBarLines/options/Bsd_ppbarlines.py b/Liv_PPBarLines/options/Bsd_ppbarlines.py
index 0d119272f1..ea0dfb8ba9 100644
--- a/Liv_PPBarLines/options/Bsd_ppbarlines.py
+++ b/Liv_PPBarLines/options/Bsd_ppbarlines.py
@@ -33,18 +33,11 @@ def maketuple_BdToPPbar(options, pvs, rec_summary):
     }
 
     # DTF_MASS = DecayTreeFitter(
-    #     name='DTF_Bd_Mass_{hash}',
-    #     input_particles=input_data,
-    #     mass_constraints=["B0"])
-
-    # DTF_MASS_PV = DecayTreeFitter(
-    #     'DTF_Bd_Mass_PV_{hash}',
-    #     input_particles=input_data,
-    #     input_pvs=pvs,
-    #     mass_constraints=["B0"])
+    #     name='DTF_{hash}',
+    #     input_particles=input_data)
 
     basic_variables = make_basic_variables(options, pvs, input_data) 
-    composite_variables = make_composite_variables(options, pvs, input_data) 
+    composite_variables = make_composite_variables(options, pvs, input_data) # + make_composite_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_MASS, pv_constraint=True)
 
     variables = {
         "B0"   : composite_variables ,
@@ -65,9 +58,9 @@ def maketuple_Bs0ToPPbar(options, pvs, rec_summary):
     myfilter = create_lines_filter(f"LineFilter_{turbo_line}_{{hash}}",[turbo_line])
 
     branches = {
-        "B0" : "[B_s0 -> p+ p~-]CC",
-        "pp"  : "[B_s0 -> ^p+ p~-]CC",
-        "pm"  : "[B_s0 -> p+ ^p~-]CC",
+        "B0" : "[B0 -> p+ p~-]CC",
+        "pp"  : "[B0 -> ^p+ p~-]CC",
+        "pm"  : "[B0 -> p+ ^p~-]CC",
     }
 
     # DTF_MASS = DecayTreeFitter(
@@ -147,11 +140,11 @@ def maketuple_Bs0ToPPbarPPbar(options, pvs, rec_summary):
     myfilter = create_lines_filter(f"LineFilter_{turbo_line}_{{hash}}",[turbo_line],)
 
     branches = {
-        "B0" : "[B_s0 -> p+ p~- p+ p~-]CC",
-        "p1"  : "[B_s0 -> ^p+ p~- p+ p~-]CC",
-        "pm1"  : "[B_s0 -> p+ ^p~- p+ p~-]CC",
-        "p2"  : "[B_s0 ->  p+ p~- ^p+ p~-]CC",
-        "pm2"  : "[B_s0 -> p+ p~- p+ ^p~-]CC",
+        "B0" : "[B0 -> p+ p~- p+ p~-]CC",
+        "p1"  : "[B0 -> ^p+ p~- p+ p~-]CC",
+        "pm1"  : "[B0 -> p+ ^p~- p+ p~-]CC",
+        "p2"  : "[B0 ->  p+ p~- ^p+ p~-]CC",
+        "pm2"  : "[B0 -> p+ p~- p+ ^p~-]CC",
     }
 
     # DTF_MASS = DecayTreeFitter(
diff --git a/Liv_PPBarLines/options/tupling.py b/Liv_PPBarLines/options/tupling.py
index 6ffc5d07c5..d10de6549e 100644
--- a/Liv_PPBarLines/options/tupling.py
+++ b/Liv_PPBarLines/options/tupling.py
@@ -311,7 +311,7 @@ def make_hlt2_event_variables(options, pvs, rec_summary):
     # define event level variables
     evt_variables = EventInfo()
     evt_variables += SelectionInfo(selection_type="Hlt2", trigger_lines=Hlt2_lines)
-    evt_variables += SelectionInfo(selection_type="Hlt1", trigger_lines=Hlt1_global_lines)
+    evt_variables += SelectionInfo(selection_type="Hlt1", trigger_lines=Hlt1_1track_lines)
     evt_variables += FunctorCollection(
         {
             "ALLPVX": F.ALLPVX(pvs),
-- 
GitLab


From 611e70209f960199757d52a13249fcf61a94a0e0 Mon Sep 17 00:00:00 2001
From: Juan Leite <jbaptist@lxplus977.cern.ch>
Date: Wed, 24 Apr 2024 17:12:16 +0200
Subject: [PATCH 03/34] Only MagDown samples for data

---
 Liv_PPBarLines/info.yaml                 |  6 ++-
 Liv_PPBarLines/options/Bsd_ppbarlines.py | 55 ++++++++----------------
 2 files changed, 22 insertions(+), 39 deletions(-)

diff --git a/Liv_PPBarLines/info.yaml b/Liv_PPBarLines/info.yaml
index 99d2835e07..106f1f362d 100644
--- a/Liv_PPBarLines/info.yaml
+++ b/Liv_PPBarLines/info.yaml
@@ -87,12 +87,16 @@ defaults:
 {%- endfor %}
 {%- endfor %}
 
+
+{%- set polarities = [
+    'Down'
+]%}
 {%- for p in polarities %}
 {%- for sigtype, simul, nu, inptype, evttype in mc_datasets %}
 {{sigtype}}_2024_Mag{{p}}_Tuple:
   application: "DaVinci/v64r3"
   input:
-    bk_query: /LHCb/Collision24/Beam6800GeV-VeloClosed-MagDown-Excl-UT/Real Data/Sprucing24c1/94000000/BNOC.DST
+    bk_query: /LHCb/Collision24/Beam6800GeV-VeloClosed-Mag{{p}}-Excl-UT/Real Data/Sprucing24c1/94000000/BNOC.DST
     dq_flags:
       - UNCHECKED
       - OK
diff --git a/Liv_PPBarLines/options/Bsd_ppbarlines.py b/Liv_PPBarLines/options/Bsd_ppbarlines.py
index ea0dfb8ba9..29b51d2b32 100644
--- a/Liv_PPBarLines/options/Bsd_ppbarlines.py
+++ b/Liv_PPBarLines/options/Bsd_ppbarlines.py
@@ -32,12 +32,12 @@ def maketuple_BdToPPbar(options, pvs, rec_summary):
         "pm"  : "[B0 -> p+ ^p~-]CC",
     }
 
-    # DTF_MASS = DecayTreeFitter(
-    #     name='DTF_{hash}',
-    #     input_particles=input_data)
+    DTF_MASS = DecayTreeFitter(
+        name='DTF_{hash}',
+        input_particles=input_data)
 
     basic_variables = make_basic_variables(options, pvs, input_data) 
-    composite_variables = make_composite_variables(options, pvs, input_data) # + make_composite_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_MASS, pv_constraint=True)
+    composite_variables = make_composite_variables(options, pvs, input_data) + make_composite_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_MASS, pv_constraint=True)
 
     variables = {
         "B0"   : composite_variables ,
@@ -62,20 +62,13 @@ def maketuple_Bs0ToPPbar(options, pvs, rec_summary):
         "pp"  : "[B0 -> ^p+ p~-]CC",
         "pm"  : "[B0 -> p+ ^p~-]CC",
     }
-
-    # DTF_MASS = DecayTreeFitter(
-    #     name='DTF_Bs0_Mass_{hash}',
-    #     input_particles=input_data,
-    #     mass_constraints=["B_s0"])
-
-    # DTF_MASS_PV = DecayTreeFitter(
-    #     'DTF_Bs0_Mass_PV_{hash}',
-    #     input_particles=input_data,
-    #     input_pvs=pvs,
-    #     mass_constraints=["B_s0"])
+    
+    DTF_MASS = DecayTreeFitter(
+        name='DTF_{hash}',
+        input_particles=input_data)
 
     basic_variables = make_basic_variables(options, pvs, input_data) 
-    composite_variables = make_composite_variables(options, pvs, input_data) 
+    composite_variables = make_composite_variables(options, pvs, input_data) + make_composite_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_MASS, pv_constraint=True)
 
 
     variables = {
@@ -105,19 +98,12 @@ def maketuple_BdToPPbarPPbar(options, pvs, rec_summary):
         "pm2"  : "[B0 -> p+ p~- p+ ^p~-]CC",
     }
 
-    # DTF_MASS = DecayTreeFitter(
-    #     name='DTF_Bd_Mass_{hash}',
-    #     input_particles=input_data,
-    #     mass_constraints=["B0"])
-
-    # DTF_MASS_PV = DecayTreeFitter(
-    #     'DTF_Bd_Mass_PV_{hash}',
-    #     input_particles=input_data,
-    #     input_pvs=pvs,
-    #     mass_constraints=["B0"])
+    DTF_MASS = DecayTreeFitter(
+        name='DTF_{hash}',
+        input_particles=input_data)
 
     basic_variables = make_basic_variables(options, pvs, input_data)
-    composite_variables = make_composite_variables_4body(options, pvs, input_data) 
+    composite_variables = make_composite_variables_4body(options, pvs, input_data) + make_composite_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_MASS, pv_constraint=True)
     
     variables = {
         "B0"   : composite_variables ,
@@ -147,19 +133,12 @@ def maketuple_Bs0ToPPbarPPbar(options, pvs, rec_summary):
         "pm2"  : "[B0 -> p+ p~- p+ ^p~-]CC",
     }
 
-    # DTF_MASS = DecayTreeFitter(
-    #     name='DTF_Bs0_Mass_{hash}',
-    #     input_particles=input_data,
-    #     mass_constraints=["B_s0"])
-
-    # DTF_MASS_PV = DecayTreeFitter(
-    #     'DTF_Bs0_Mass_PV_{hash}',
-    #     input_particles=input_data,
-    #     input_pvs=pvs,
-    #     mass_constraints=["B_s0"])
+    DTF_MASS = DecayTreeFitter(
+        name='DTF_{hash}',
+        input_particles=input_data)
 
     basic_variables = make_basic_variables(options, pvs, input_data)
-    composite_variables = make_composite_variables_4body(options, pvs, input_data) 
+    composite_variables = make_composite_variables_4body(options, pvs, input_data) + make_composite_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_MASS, pv_constraint=True)
     
     variables = {
         "B0"   : composite_variables ,
-- 
GitLab


From 401ef453a2f8bfe94867a939e11b2481f8a324de Mon Sep 17 00:00:00 2001
From: Juan Leite <jbaptist@lxplus977.cern.ch>
Date: Wed, 24 Apr 2024 19:32:41 +0200
Subject: [PATCH 04/34] adding keep_running; run over all MC and Data.

---
 Liv_PPBarLines/info.yaml | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/Liv_PPBarLines/info.yaml b/Liv_PPBarLines/info.yaml
index 106f1f362d..21ffd9d4cd 100644
--- a/Liv_PPBarLines/info.yaml
+++ b/Liv_PPBarLines/info.yaml
@@ -24,7 +24,6 @@ defaults:
     bk_query: /MC/Dev/Beam6800GeV-expected-2024-Mag{{p}}-Nu{{nu}}-25ns-Pythia8/{{simul}}/{{evttype}}/{{inptype}}
     dq_flags:
       - OK
-    n_test_lfns: 1
   output: MC_HLT1.DST
   options: 
     entrypoint: Liv_PPBarLines.hlt1:alg_config
@@ -44,7 +43,7 @@ defaults:
         max_buffer_size: 1048576
 
 {{sigtype}}_Mag{{p}}_MC_HLT2:
-  application: "Moore/v55r6@x86_64_v3-el9-gcc13+detdesc-opt+g"
+  application: "Moore/v55r7@x86_64_v3-el9-gcc13+detdesc-opt+g"
   input:
     job_name: {{sigtype}}_Mag{{p}}_MC_HLT1
   output: MC_HLT2.DST
@@ -100,7 +99,7 @@ defaults:
     dq_flags:
       - UNCHECKED
       - OK
-    n_test_lfns: 1
+    keep_running: True
   output: RealData_{{sigtype}}.ROOT
   options:
     entrypoint: Liv_PPBarLines.main_Liv_PPBarLines_{{sigtype}}:main
-- 
GitLab


From 79526852e7828b1a13902f949621cfbe788d0902 Mon Sep 17 00:00:00 2001
From: Juan Leite <jbaptist@lxplus959.cern.ch>
Date: Thu, 25 Apr 2024 21:51:27 +0200
Subject: [PATCH 05/34] add mij masses to Tuple

---
 Liv_PPBarLines/info.yaml                 |  1 -
 Liv_PPBarLines/options/Bsd_ppbarlines.py | 12 ++++++------
 Liv_PPBarLines/options/tupling.py        | 18 +++++++++++++++---
 3 files changed, 21 insertions(+), 10 deletions(-)

diff --git a/Liv_PPBarLines/info.yaml b/Liv_PPBarLines/info.yaml
index 21ffd9d4cd..0974dcbdd0 100644
--- a/Liv_PPBarLines/info.yaml
+++ b/Liv_PPBarLines/info.yaml
@@ -114,6 +114,5 @@ defaults:
       input_process: "TurboPass"
       input_stream: "bnoc"
       evt_max: -1
-
 {%- endfor %}
 {%- endfor %}
\ No newline at end of file
diff --git a/Liv_PPBarLines/options/Bsd_ppbarlines.py b/Liv_PPBarLines/options/Bsd_ppbarlines.py
index 29b51d2b32..b20f5003ae 100644
--- a/Liv_PPBarLines/options/Bsd_ppbarlines.py
+++ b/Liv_PPBarLines/options/Bsd_ppbarlines.py
@@ -36,7 +36,7 @@ def maketuple_BdToPPbar(options, pvs, rec_summary):
         name='DTF_{hash}',
         input_particles=input_data)
 
-    basic_variables = make_basic_variables(options, pvs, input_data) 
+    basic_variables = make_basic_variables(options, pvs, input_data) + make_basic_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_MASS, pv_constraint=True)
     composite_variables = make_composite_variables(options, pvs, input_data) + make_composite_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_MASS, pv_constraint=True)
 
     variables = {
@@ -67,7 +67,7 @@ def maketuple_Bs0ToPPbar(options, pvs, rec_summary):
         name='DTF_{hash}',
         input_particles=input_data)
 
-    basic_variables = make_basic_variables(options, pvs, input_data) 
+    basic_variables = make_basic_variables(options, pvs, input_data) + make_basic_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_MASS, pv_constraint=True)
     composite_variables = make_composite_variables(options, pvs, input_data) + make_composite_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_MASS, pv_constraint=True)
 
 
@@ -102,8 +102,8 @@ def maketuple_BdToPPbarPPbar(options, pvs, rec_summary):
         name='DTF_{hash}',
         input_particles=input_data)
 
-    basic_variables = make_basic_variables(options, pvs, input_data)
-    composite_variables = make_composite_variables_4body(options, pvs, input_data) + make_composite_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_MASS, pv_constraint=True)
+    basic_variables = make_basic_variables(options, pvs, input_data) + make_basic_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_MASS, pv_constraint=True)
+    composite_variables = make_composite_variables_4body(options, pvs, input_data) + make_composite_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_MASS, pv_constraint=True, four_body=True)
     
     variables = {
         "B0"   : composite_variables ,
@@ -137,8 +137,8 @@ def maketuple_Bs0ToPPbarPPbar(options, pvs, rec_summary):
         name='DTF_{hash}',
         input_particles=input_data)
 
-    basic_variables = make_basic_variables(options, pvs, input_data)
-    composite_variables = make_composite_variables_4body(options, pvs, input_data) + make_composite_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_MASS, pv_constraint=True)
+    basic_variables = make_basic_variables(options, pvs, input_data) + make_basic_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_MASS, pv_constraint=True)
+    composite_variables = make_composite_variables_4body(options, pvs, input_data) + make_composite_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_MASS, pv_constraint=True, four_body=True)
     
     variables = {
         "B0"   : composite_variables ,
diff --git a/Liv_PPBarLines/options/tupling.py b/Liv_PPBarLines/options/tupling.py
index d10de6549e..cea1544847 100644
--- a/Liv_PPBarLines/options/tupling.py
+++ b/Liv_PPBarLines/options/tupling.py
@@ -113,6 +113,7 @@ def make_composite_variables(options, pvs, data, add_truth=True):
     variables = (
        FunctorCollection(
            {
+               "CHARGE": F.CHARGE,
                "MAXPT": F.MAX(F.PT),
                "MINPT": F.MIN(F.PT),
                "SUMPT": F.SUM(F.PT),
@@ -253,7 +254,8 @@ def make_basic_variables(options, pvs, data, add_truth=True):
         add_truth = False
     variables = (
        FunctorCollection(
-           {
+           { 
+               "CHARGE": F.CHARGE,
                "TRCHI2DOF": F.CHI2DOF @ F.TRACK,
                "ETA": F.ETA,
                "PHI": F.PHI,
@@ -464,7 +466,7 @@ def make_basic_dtf_variables(options, pvs, data, add_truth=True, DTF=None, pv_co
              for k, v in variables.get_thor_functors().items()})
         return dtf_variables
 
-def make_composite_dtf_variables(options, pvs, data, add_truth=True, DTF=None, pv_constraint=False, mass_constraint=False, particle_name=""):
+def make_composite_dtf_variables(options, pvs, data, add_truth=True, DTF=None, pv_constraint=False, mass_constraint=False, particle_name="", four_body=False):
     if not options.simulation:
         add_truth = False
     variables = (
@@ -476,7 +478,6 @@ def make_composite_dtf_variables(options, pvs, data, add_truth=True, DTF=None, p
                 "MAXP": F.MAX(F.P),
                 "MINP": F.MIN(F.P),
                 "BPVDIRA": F.BPVDIRA(pvs),
-                # "VCHI2DOF": F.CHI2DOF, #CHI2VXNDOF
                 "BPVFDCHI2": F.BPVFDCHI2(pvs),
                 "BPVFD": F.BPVFD(pvs),
                 "BPVVDRHO": F.BPVVDRHO(pvs),
@@ -495,8 +496,19 @@ def make_composite_dtf_variables(options, pvs, data, add_truth=True, DTF=None, p
             }
         )
         + Kinematics()
+        
         #+ ParticleID(extra_info=True) #only for daughters
     )
+    
+    if four_body:
+            variables += FunctorCollection(
+                {
+                    "M13": F.SUBCOMB(Functor=F.MASS, Indices=(1, 3)),
+                    "M14": F.SUBCOMB(Functor=F.MASS, Indices=(1, 4)),
+                    "M23": F.SUBCOMB(Functor=F.MASS, Indices=(2, 3)),
+                    "M24": F.SUBCOMB(Functor=F.MASS, Indices=(2, 4)),
+                }
+            )
 
 
     if(mass_constraint):
-- 
GitLab


From c9fba1d5234a0da05b3e9cfadcc5eaeeaf8e5400 Mon Sep 17 00:00:00 2001
From: Juan Leite <jbaptist@lxplus959.cern.ch>
Date: Thu, 25 Apr 2024 23:20:00 +0200
Subject: [PATCH 06/34] fix typo

---
 Liv_PPBarLines/options/Bsd_ppbarlines.py | 188 +++++++++++++++--------
 1 file changed, 125 insertions(+), 63 deletions(-)

diff --git a/Liv_PPBarLines/options/Bsd_ppbarlines.py b/Liv_PPBarLines/options/Bsd_ppbarlines.py
index b20f5003ae..c15e05a298 100644
--- a/Liv_PPBarLines/options/Bsd_ppbarlines.py
+++ b/Liv_PPBarLines/options/Bsd_ppbarlines.py
@@ -10,7 +10,6 @@ from PyConf.reading import get_particles, get_pvs
 import FunTuple.functorcollections as FC
 from FunTuple import FunTuple_Particles as Funtuple
 from DecayTreeFitter import DecayTreeFitter
-
 """
  BdsToPPbar
  BdsToPPbarPPbar
@@ -18,34 +17,51 @@ from DecayTreeFitter import DecayTreeFitter
 
  """
 
+
 # BdsToPPbar
 def maketuple_BdToPPbar(options, pvs, rec_summary):
     name = "BdToPPbar"
     turbo_line = "Hlt2BnoC_BdsToPpPm"
 
     input_data = get_particles(f"/Event/HLT2/{turbo_line}/Particles")
-    myfilter = create_lines_filter(f"LineFilter_{turbo_line}_{{hash}}",[turbo_line],)
+    myfilter = create_lines_filter(
+        f"LineFilter_{turbo_line}_{{hash}}",
+        [turbo_line],
+    )
 
     branches = {
-        "B0" : "[B0 -> p+ p~-]CC",
-        "pp"  : "[B0 -> ^p+ p~-]CC",
-        "pm"  : "[B0 -> p+ ^p~-]CC",
+        "B0": "[B0 -> p+ p~-]CC",
+        "pp": "[B0 -> ^p+ p~-]CC",
+        "pm": "[B0 -> p+ ^p~-]CC",
     }
 
+    DTF_MASS_PV = DecayTreeFitter(
+        name='DTF_{hash}', input_particles=input_data, input_pvs=pvs)
+    
     DTF_MASS = DecayTreeFitter(
-        name='DTF_{hash}',
-        input_particles=input_data)
+        name='DTF_{hash}', input_particles=input_data)
+    
 
-    basic_variables = make_basic_variables(options, pvs, input_data) + make_basic_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_MASS, pv_constraint=True)
-    composite_variables = make_composite_variables(options, pvs, input_data) + make_composite_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_MASS, pv_constraint=True)
+    basic_variables = make_basic_variables(options, pvs, input_data) +\
+                    make_basic_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_MASS, pv_constraint=True) +\
+                    make_basic_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_MASS, pv_constraint=False) 
+    composite_variables = make_composite_variables(options, pvs, input_data) +\
+                    make_composite_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_MASS, pv_constraint=True) +\
+                    make_composite_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_MASS, pv_constraint=False) 
 
     variables = {
-        "B0"   : composite_variables ,
-        "pp"    : basic_variables,
-        "pm"   : basic_variables,
+        "B0": composite_variables,
+        "pp": basic_variables,
+        "pm": basic_variables,
     }
 
-    mytuple  = Funtuple(name=name, tuple_name="DecayTree", fields=branches, variables = variables,  event_variables=make_hlt2_event_variables(options, pvs, rec_summary), inputs=input_data)
+    mytuple = Funtuple(
+        name=name,
+        tuple_name="DecayTree",
+        fields=branches,
+        variables=variables,
+        event_variables=make_hlt2_event_variables(options, pvs, rec_summary),
+        inputs=input_data)
 
     return [myfilter, mytuple]
 
@@ -55,29 +71,42 @@ def maketuple_Bs0ToPPbar(options, pvs, rec_summary):
     turbo_line = "Hlt2BnoC_BdsToPpPm"
 
     input_data = get_particles(f"/Event/HLT2/{turbo_line}/Particles")
-    myfilter = create_lines_filter(f"LineFilter_{turbo_line}_{{hash}}",[turbo_line])
+    myfilter = create_lines_filter(f"LineFilter_{turbo_line}_{{hash}}",
+                                   [turbo_line])
 
     branches = {
-        "B0" : "[B0 -> p+ p~-]CC",
-        "pp"  : "[B0 -> ^p+ p~-]CC",
-        "pm"  : "[B0 -> p+ ^p~-]CC",
+        "B0": "[B0 -> p+ p~-]CC",
+        "pp": "[B0 -> ^p+ p~-]CC",
+        "pm": "[B0 -> p+ ^p~-]CC",
     }
+
+    DTF_MASS_PV = DecayTreeFitter(
+        name='DTF_{hash}', input_particles=input_data, input_pvs=pvs)
     
     DTF_MASS = DecayTreeFitter(
-        name='DTF_{hash}',
-        input_particles=input_data)
-
-    basic_variables = make_basic_variables(options, pvs, input_data) + make_basic_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_MASS, pv_constraint=True)
-    composite_variables = make_composite_variables(options, pvs, input_data) + make_composite_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_MASS, pv_constraint=True)
+        name='DTF_{hash}', input_particles=input_data)
+    
 
+    basic_variables = make_basic_variables(options, pvs, input_data) +\
+                    make_basic_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_MASS, pv_constraint=True) +\
+                    make_basic_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_MASS, pv_constraint=False) 
+    composite_variables = make_composite_variables(options, pvs, input_data) +\
+                    make_composite_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_MASS, pv_constraint=True) +\
+                    make_composite_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_MASS, pv_constraint=False) 
 
     variables = {
-        "B0"   : composite_variables ,
-        "pp"    : basic_variables,
-        "pm"   : basic_variables,
+        "B0": composite_variables,
+        "pp": basic_variables,
+        "pm": basic_variables,
     }
 
-    mytuple  = Funtuple(name=name, tuple_name="DecayTree", fields=branches, variables = variables,  event_variables=make_hlt2_event_variables(options, pvs, rec_summary), inputs=input_data)
+    mytuple = Funtuple(
+        name=name,
+        tuple_name="DecayTree",
+        fields=branches,
+        variables=variables,
+        event_variables=make_hlt2_event_variables(options, pvs, rec_summary),
+        inputs=input_data)
 
     return [myfilter, mytuple]
 
@@ -88,32 +117,48 @@ def maketuple_BdToPPbarPPbar(options, pvs, rec_summary):
     turbo_line = "Hlt2BnoC_BdsToPpPmPpPm"
 
     input_data = get_particles(f"/Event/HLT2/{turbo_line}/Particles")
-    myfilter = create_lines_filter(f"LineFilter_{turbo_line}_{{hash}}",[turbo_line],)
+    myfilter = create_lines_filter(
+        f"LineFilter_{turbo_line}_{{hash}}",
+        [turbo_line],
+    )
 
     branches = {
-        "B0" : "[B0 -> p+ p~- p+ p~-]CC",
-        "p1"  : "[B0 -> ^p+ p~- p+ p~-]CC",
-        "pm1"  : "[B0 -> p+ ^p~- p+ p~-]CC",
-        "p2"  : "[B0 ->  p+ p~- ^p+ p~-]CC",
-        "pm2"  : "[B0 -> p+ p~- p+ ^p~-]CC",
+        "B0": "[B0 -> p+ p~- p+ p~-]CC",
+        "p1": "[B0 -> ^p+ p~- p+ p~-]CC",
+        "pm1": "[B0 -> p+ ^p~- p+ p~-]CC",
+        "p2": "[B0 ->  p+ p~- ^p+ p~-]CC",
+        "pm2": "[B0 -> p+ p~- p+ ^p~-]CC",
     }
 
+    DTF_MASS_PV = DecayTreeFitter(
+        name='DTF_{hash}', input_particles=input_data, input_pvs=pvs)
+    
     DTF_MASS = DecayTreeFitter(
-        name='DTF_{hash}',
-        input_particles=input_data)
-
-    basic_variables = make_basic_variables(options, pvs, input_data) + make_basic_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_MASS, pv_constraint=True)
-    composite_variables = make_composite_variables_4body(options, pvs, input_data) + make_composite_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_MASS, pv_constraint=True, four_body=True)
+        name='DTF_{hash}', input_particles=input_data)
     
+
+    basic_variables = make_basic_variables(options, pvs, input_data) +\
+                    make_basic_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_MASS, pv_constraint=True) +\
+                    make_basic_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_MASS, pv_constraint=False) 
+    composite_variables = make_composite_variables(options, pvs, input_data) +\
+                    make_composite_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_MASS, pv_constraint=True, four_body=True) +\
+                    make_composite_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_MASS, pv_constraint=False, four_body=True) 
+
     variables = {
-        "B0"   : composite_variables ,
-        "p1"    : basic_variables,
-        "pm1"   : basic_variables,
-        "p2"    : basic_variables,
-        "pm2"   : basic_variables,
-    }   
+        "B0": composite_variables,
+        "p1": basic_variables,
+        "pm1": basic_variables,
+        "p2": basic_variables,
+        "pm2": basic_variables,
+    }
 
-    mytuple  = Funtuple(name=name, tuple_name="DecayTree", fields=branches, variables = variables,  event_variables=make_hlt2_event_variables(options, pvs, rec_summary), inputs=input_data)
+    mytuple = Funtuple(
+        name=name,
+        tuple_name="DecayTree",
+        fields=branches,
+        variables=variables,
+        event_variables=make_hlt2_event_variables(options, pvs, rec_summary),
+        inputs=input_data)
 
     return [myfilter, mytuple]
 
@@ -123,31 +168,48 @@ def maketuple_Bs0ToPPbarPPbar(options, pvs, rec_summary):
     turbo_line = "Hlt2BnoC_BdsToPpPmPpPm"
 
     input_data = get_particles(f"/Event/HLT2/{turbo_line}/Particles")
-    myfilter = create_lines_filter(f"LineFilter_{turbo_line}_{{hash}}",[turbo_line],)
+    myfilter = create_lines_filter(
+        f"LineFilter_{turbo_line}_{{hash}}",
+        [turbo_line],
+    )
 
     branches = {
-        "B0" : "[B0 -> p+ p~- p+ p~-]CC",
-        "p1"  : "[B0 -> ^p+ p~- p+ p~-]CC",
-        "pm1"  : "[B0 -> p+ ^p~- p+ p~-]CC",
-        "p2"  : "[B0 ->  p+ p~- ^p+ p~-]CC",
-        "pm2"  : "[B0 -> p+ p~- p+ ^p~-]CC",
+        "B0": "[B0 -> p+ p~- p+ p~-]CC",
+        "p1": "[B0 -> ^p+ p~- p+ p~-]CC",
+        "pm1": "[B0 -> p+ ^p~- p+ p~-]CC",
+        "p2": "[B0 ->  p+ p~- ^p+ p~-]CC",
+        "pm2": "[B0 -> p+ p~- p+ ^p~-]CC",
     }
 
-    DTF_MASS = DecayTreeFitter(
-        name='DTF_{hash}',
-        input_particles=input_data)
 
-    basic_variables = make_basic_variables(options, pvs, input_data) + make_basic_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_MASS, pv_constraint=True)
-    composite_variables = make_composite_variables_4body(options, pvs, input_data) + make_composite_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_MASS, pv_constraint=True, four_body=True)
+    DTF_MASS_PV = DecayTreeFitter(
+        name='DTF_{hash}', input_particles=input_data, input_pvs=pvs)
+    
+    DTF_MASS = DecayTreeFitter(
+        name='DTF_{hash}', input_particles=input_data)
     
+
+    basic_variables = make_basic_variables(options, pvs, input_data) +\
+                    make_basic_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_MASS, pv_constraint=True) +\
+                    make_basic_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_MASS, pv_constraint=False) 
+    composite_variables = make_composite_variables(options, pvs, input_data) +\
+                    make_composite_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_MASS, pv_constraint=True, four_body=True) +\
+                    make_composite_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_MASS, pv_constraint=False, four_body=True) 
+
     variables = {
-        "B0"   : composite_variables ,
-        "p1"    : basic_variables,
-        "pm1"   : basic_variables,
-        "p2"    : basic_variables,
-        "pm2"   : basic_variables,
-    }   
-
-    mytuple  = Funtuple(name=name, tuple_name="DecayTree", fields=branches, variables = variables,  event_variables=make_hlt2_event_variables(options, pvs, rec_summary), inputs=input_data)
+        "B0": composite_variables,
+        "p1": basic_variables,
+        "pm1": basic_variables,
+        "p2": basic_variables,
+        "pm2": basic_variables,
+    }
+
+    mytuple = Funtuple(
+        name=name,
+        tuple_name="DecayTree",
+        fields=branches,
+        variables=variables,
+        event_variables=make_hlt2_event_variables(options, pvs, rec_summary),
+        inputs=input_data)
 
     return [myfilter, mytuple]
-- 
GitLab


From 217d72b0c1d947953e21d120c4a383901efb87c7 Mon Sep 17 00:00:00 2001
From: Juan Leite <jbaptist@lxplus959.cern.ch>
Date: Thu, 25 Apr 2024 23:29:52 +0200
Subject: [PATCH 07/34] remove Duplicated DTF vars

---
 Liv_PPBarLines/options/Bsd_ppbarlines.py | 25 ++++++++----------------
 1 file changed, 8 insertions(+), 17 deletions(-)

diff --git a/Liv_PPBarLines/options/Bsd_ppbarlines.py b/Liv_PPBarLines/options/Bsd_ppbarlines.py
index c15e05a298..87e5d9d74b 100644
--- a/Liv_PPBarLines/options/Bsd_ppbarlines.py
+++ b/Liv_PPBarLines/options/Bsd_ppbarlines.py
@@ -43,11 +43,9 @@ def maketuple_BdToPPbar(options, pvs, rec_summary):
     
 
     basic_variables = make_basic_variables(options, pvs, input_data) +\
-                    make_basic_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_MASS, pv_constraint=True) +\
-                    make_basic_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_MASS, pv_constraint=False) 
+                    make_basic_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_MASS, pv_constraint=True) 
     composite_variables = make_composite_variables(options, pvs, input_data) +\
-                    make_composite_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_MASS, pv_constraint=True) +\
-                    make_composite_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_MASS, pv_constraint=False) 
+                    make_composite_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_MASS, pv_constraint=True) 
 
     variables = {
         "B0": composite_variables,
@@ -88,11 +86,9 @@ def maketuple_Bs0ToPPbar(options, pvs, rec_summary):
     
 
     basic_variables = make_basic_variables(options, pvs, input_data) +\
-                    make_basic_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_MASS, pv_constraint=True) +\
-                    make_basic_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_MASS, pv_constraint=False) 
+                    make_basic_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_MASS, pv_constraint=True)  
     composite_variables = make_composite_variables(options, pvs, input_data) +\
-                    make_composite_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_MASS, pv_constraint=True) +\
-                    make_composite_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_MASS, pv_constraint=False) 
+                    make_composite_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_MASS, pv_constraint=True) 
 
     variables = {
         "B0": composite_variables,
@@ -138,11 +134,9 @@ def maketuple_BdToPPbarPPbar(options, pvs, rec_summary):
     
 
     basic_variables = make_basic_variables(options, pvs, input_data) +\
-                    make_basic_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_MASS, pv_constraint=True) +\
-                    make_basic_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_MASS, pv_constraint=False) 
+                    make_basic_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_MASS, pv_constraint=True) 
     composite_variables = make_composite_variables(options, pvs, input_data) +\
-                    make_composite_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_MASS, pv_constraint=True, four_body=True) +\
-                    make_composite_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_MASS, pv_constraint=False, four_body=True) 
+                    make_composite_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_MASS, pv_constraint=True, four_body=True) 
 
     variables = {
         "B0": composite_variables,
@@ -190,12 +184,9 @@ def maketuple_Bs0ToPPbarPPbar(options, pvs, rec_summary):
     
 
     basic_variables = make_basic_variables(options, pvs, input_data) +\
-                    make_basic_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_MASS, pv_constraint=True) +\
-                    make_basic_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_MASS, pv_constraint=False) 
+                    make_basic_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_MASS, pv_constraint=True) 
     composite_variables = make_composite_variables(options, pvs, input_data) +\
-                    make_composite_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_MASS, pv_constraint=True, four_body=True) +\
-                    make_composite_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_MASS, pv_constraint=False, four_body=True) 
-
+                    make_composite_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_MASS, pv_constraint=True, four_body=True) 
     variables = {
         "B0": composite_variables,
         "p1": basic_variables,
-- 
GitLab


From 46a63d783ab3e1555d1d034ab6df07bea2b82fbd Mon Sep 17 00:00:00 2001
From: Juan Leite <jbaptist@lxplus946.cern.ch>
Date: Sat, 27 Apr 2024 15:41:05 +0200
Subject: [PATCH 08/34] add DTF variables

---
 Liv_PPBarLines/info.yaml          | 18 +++++++++++++--
 Liv_PPBarLines/options/tupling.py | 37 ++++++++++++++++++++++++++-----
 2 files changed, 47 insertions(+), 8 deletions(-)

diff --git a/Liv_PPBarLines/info.yaml b/Liv_PPBarLines/info.yaml
index 0974dcbdd0..f3718d6f31 100644
--- a/Liv_PPBarLines/info.yaml
+++ b/Liv_PPBarLines/info.yaml
@@ -3,6 +3,16 @@ defaults:
     - juan.baptista.leite@cern.ch
   wg: BnoC
 
+
+checks:
+  histogram_M:
+    type: range
+    expression: B0_M
+    limits:
+      min: 4800
+      max: 6000
+ 
+
 # 2024
 {%- set polarities = [
     'Down', 'Up'
@@ -66,10 +76,12 @@ defaults:
 
  
 
-{{sigtype}}_2024_Mag{{p}}_MC_Tuple:
+{{sigtype}}_Mag{{p}}_MC_Tuple:
   application: "DaVinci/v64r3@x86_64_v3-el9-gcc13+detdesc-opt+g"
   input:
     job_name: {{sigtype}}_Mag{{p}}_MC_HLT2
+  checks:
+    - histogram_M
   output: MC_{{sigtype}}.ROOT
   options:
     entrypoint: Liv_PPBarLines.main_Liv_PPBarLines_{{sigtype}}:main
@@ -92,7 +104,7 @@ defaults:
 ]%}
 {%- for p in polarities %}
 {%- for sigtype, simul, nu, inptype, evttype in mc_datasets %}
-{{sigtype}}_2024_Mag{{p}}_Tuple:
+{{sigtype}}_Mag{{p}}_Data_Tuple:
   application: "DaVinci/v64r3"
   input:
     bk_query: /LHCb/Collision24/Beam6800GeV-VeloClosed-Mag{{p}}-Excl-UT/Real Data/Sprucing24c1/94000000/BNOC.DST
@@ -100,6 +112,8 @@ defaults:
       - UNCHECKED
       - OK
     keep_running: True
+  checks:
+    - histogram_M
   output: RealData_{{sigtype}}.ROOT
   options:
     entrypoint: Liv_PPBarLines.main_Liv_PPBarLines_{{sigtype}}:main
diff --git a/Liv_PPBarLines/options/tupling.py b/Liv_PPBarLines/options/tupling.py
index cea1544847..a33f18e252 100644
--- a/Liv_PPBarLines/options/tupling.py
+++ b/Liv_PPBarLines/options/tupling.py
@@ -121,8 +121,11 @@ def make_composite_variables(options, pvs, data, add_truth=True):
                "MINP": F.MIN(F.P),
                "BPVDIRA": F.BPVDIRA(pvs),
                "VCHI2DOF": F.CHI2DOF, #CHI2VXNDOF
+               "VCHI2": F.CHI2,
                "BPVFDCHI2": F.BPVFDCHI2(pvs),
                "BPVFD": F.BPVFD(pvs),
+               "BPVFDIR": F.BPVFDIR(pvs),
+               "BPVFDVEC": F.BPVFDVEC(pvs),
                "BPVVDRHO": F.BPVVDRHO(pvs),
                "BPVVDZ": F.BPVVDZ(pvs),
                "BPVIPCHI2": F.BPVIPCHI2(pvs),
@@ -257,11 +260,14 @@ def make_basic_variables(options, pvs, data, add_truth=True):
            { 
                "CHARGE": F.CHARGE,
                "TRCHI2DOF": F.CHI2DOF @ F.TRACK,
+               "TRCHI2": F.CHI2 @ F.TRACK,
                "ETA": F.ETA,
                "PHI": F.PHI,
                "TRGHOSTPROB": F.GHOSTPROB,
                "BPVIPCHI2": F.BPVIPCHI2(pvs),
                "BPVIP": F.BPVIP(pvs),
+               #"BPVETA": F.BPVETA(pvs),
+               #"BPVDLS": F.BPVDLS(pvs),
                "BPVX": F.BPVX(pvs),
                "BPVY": F.BPVY(pvs),
                "BPVZ": F.BPVZ(pvs),
@@ -433,11 +439,22 @@ def make_basic_dtf_variables(options, pvs, data, add_truth=True, DTF=None, pv_co
                 "TY"          : F.TY,
                 "MINIPCHI2"   : F.MINIPCHI2(pvs),
                 "MINIP"       : F.MINIP(pvs),
+                
             }
         )
         + Kinematics()
         #+ ParticleID(extra_info=True)
     )
+    
+    dtf_extras = FunctorCollection(
+        {
+            "DTF_NITER": DTF.NITER,
+            "DTF_CHI2": DTF.CHI2,
+            "DTF_NDOF": DTF.NDOF,
+            "DTF_CHI2DOF": DTF.CHI2DOF
+        }
+    )
+
 
 
     if(mass_constraint):
@@ -452,7 +469,6 @@ def make_basic_dtf_variables(options, pvs, data, add_truth=True, DTF=None, pv_co
                 {'DTF_M'+ particle_name + '_' + k: DTF(v)
                  for k, v in variables.get_thor_functors().items()})
         return dtf_variables_mass
-
     elif(pv_constraint): # PV
         dtf_variables_pv = FunctorCollection({
                 'DTF_PV_' + k: DTF(v)
@@ -492,7 +508,7 @@ def make_composite_dtf_variables(options, pvs, data, add_truth=True, DTF=None, p
                 "MINBPVIP": F.MIN(F.BPVIP(pvs)),
                 "M12": F.SUBCOMB(Functor=F.MASS, Indices=(1, 2)),
                 "ETA": F.ETA,
-                "PHI": F.PHI,
+                "PHI": F.PHI
             }
         )
         + Kinematics()
@@ -509,6 +525,15 @@ def make_composite_dtf_variables(options, pvs, data, add_truth=True, DTF=None, p
                     "M24": F.SUBCOMB(Functor=F.MASS, Indices=(2, 4)),
                 }
             )
+            
+    dtf_extras = FunctorCollection(
+        {
+            "DTF_NITER": DTF.NITER,
+            "DTF_CHI2": DTF.CHI2,
+            "DTF_NDOF": DTF.NDOF,
+            "DTF_CHI2DOF": DTF.CHI2DOF
+        }
+    )
 
 
     if(mass_constraint):
@@ -517,25 +542,25 @@ def make_composite_dtf_variables(options, pvs, data, add_truth=True, DTF=None, p
                         'DTF_PV_M'+ particle_name + '_' + k: DTF(v)
                         for k, v in variables.get_thor_functors().items()
                     })
-            return dtf_variables_mass_pv
+            return dtf_variables_mass_pv + dtf_extras
         else: # MASS
             dtf_variables_mass = FunctorCollection(
                 {'DTF_M'+ particle_name + '_' + k: DTF(v)
                  for k, v in variables.get_thor_functors().items()})
-        return dtf_variables_mass
+        return dtf_variables_mass + dtf_extras
 
     elif(pv_constraint): # PV
         dtf_variables_pv = FunctorCollection({
                 'DTF_PV_' + k: DTF(v)
                 for k, v in variables.get_thor_functors().items()
             })
-        return dtf_variables_pv
+        return dtf_variables_pv + dtf_extras
 
     else: # NO MASS/PV
         dtf_variables = FunctorCollection(
             {'DTF_' + k: DTF(v)
              for k, v in variables.get_thor_functors().items()})
-        return dtf_variables
+        return dtf_variables + dtf_extras
 
 def make_MC_basic_variables():
     variables = (
-- 
GitLab


From cc61a7ab6874d0bf51a9d25ba04cfa236b88377f Mon Sep 17 00:00:00 2001
From: Juan Leite <jbaptist@lxplus981.cern.ch>
Date: Mon, 29 Apr 2024 18:10:49 +0200
Subject: [PATCH 09/34] Lb0ToLcpLcmN0 neutron lines

---
 Liv_Lb0NeutronLines/Spruce.py                 |  50 ++
 Liv_Lb0NeutronLines/hlt1.py                   |  33 +
 Liv_Lb0NeutronLines/hlt2.py                   |  58 ++
 Liv_Lb0NeutronLines/info.yaml                 | 159 ++++
 Liv_Lb0NeutronLines/main_Liv_BpToLcpLcmKp.py  |  32 +
 Liv_Lb0NeutronLines/main_Liv_Lb0ToLcpLcmN0.py |  32 +
 Liv_Lb0NeutronLines/main_Liv_Lb0ToPpPmN0.py   |  32 +
 .../options/Lb_NeutronLines.py                | 167 +++++
 Liv_Lb0NeutronLines/options/tupling.py        | 708 ++++++++++++++++++
 9 files changed, 1271 insertions(+)
 create mode 100644 Liv_Lb0NeutronLines/Spruce.py
 create mode 100644 Liv_Lb0NeutronLines/hlt1.py
 create mode 100644 Liv_Lb0NeutronLines/hlt2.py
 create mode 100644 Liv_Lb0NeutronLines/info.yaml
 create mode 100644 Liv_Lb0NeutronLines/main_Liv_BpToLcpLcmKp.py
 create mode 100644 Liv_Lb0NeutronLines/main_Liv_Lb0ToLcpLcmN0.py
 create mode 100644 Liv_Lb0NeutronLines/main_Liv_Lb0ToPpPmN0.py
 create mode 100644 Liv_Lb0NeutronLines/options/Lb_NeutronLines.py
 create mode 100644 Liv_Lb0NeutronLines/options/tupling.py

diff --git a/Liv_Lb0NeutronLines/Spruce.py b/Liv_Lb0NeutronLines/Spruce.py
new file mode 100644
index 0000000000..57ccd8fd33
--- /dev/null
+++ b/Liv_Lb0NeutronLines/Spruce.py
@@ -0,0 +1,50 @@
+####################################
+# options                          #
+####################################
+
+import Moore
+from Moore import Options, run_moore, config
+from Moore.lines import Hlt2Line
+from RecoConf.reconstruction_objects import reconstruction as reconstruction
+from Moore import options, run_moore
+from RecoConf.global_tools import stateProvider_with_simplified_geom, trackMasterExtrapolator_with_simplified_geom
+from RecoConf.hlt2_global_reco import reconstruction as hlt2_reconstruction, make_light_reco_pr_kf_without_UT
+from RecoConf.hlt2_tracking import (
+    make_TrackBestTrackCreator_tracks,
+    make_PrKalmanFilter_noUT_tracks,
+    make_PrKalmanFilter_Velo_tracks,
+    make_PrKalmanFilter_Seed_tracks,
+)
+from RecoConf.decoders import default_VeloCluster_source
+from RecoConf.event_filters import require_gec
+from Moore.streams import Stream, Streams
+import sys
+
+
+from Hlt2Conf.lines.b_to_open_charm import sprucing_lines
+
+
+
+################## options ############
+    
+public_tools = [
+    trackMasterExtrapolator_with_simplified_geom(),
+    stateProvider_with_simplified_geom(),
+]
+
+def pass_through_line(name="Hlt2MCPassThroughLine"):
+    """Return a HLT2 line that performs no selection but runs and persists the reconstruction
+    """
+    return Hlt2Line(name=name, prescale=1, algs=[], persistreco=True)
+
+
+def _make_lines():
+    mylines = [builder() for builder in sprucing_lines.values()]
+    return mylines
+
+def alg_config(options: Options):
+    with reconstruction.bind(from_file=True, spruce=True):
+        config = run_moore(options, _make_lines, public_tools)
+    return config
+
+
diff --git a/Liv_Lb0NeutronLines/hlt1.py b/Liv_Lb0NeutronLines/hlt1.py
new file mode 100644
index 0000000000..d987098959
--- /dev/null
+++ b/Liv_Lb0NeutronLines/hlt1.py
@@ -0,0 +1,33 @@
+###############################################################################
+# (c) Copyright 2023 CERN for the benefit of the LHCb Collaboration           #
+#                                                                             #
+# This software is distributed under the terms of the GNU General Public      #
+# Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING".   #
+#                                                                             #
+# In applying this licence, CERN does not waive the privileges and immunities #
+# granted to it by virtue of its status as an Intergovernmental Organization  #
+# or submit itself to any jurisdiction.                                       #
+###############################################################################
+"""
+Configures running HLT1 via Moore.
+"""
+
+from Moore import Options
+from Moore.config import allen_control_flow
+from RecoConf.hlt1_allen import allen_gaudi_config, get_allen_line_names
+from PyConf.application import configure_input, configure
+
+def alg_config(options: Options):
+    """
+    Configures algorithm running of HLT1 via Moore to be passed to Analysis Productions.
+    """
+
+    config = configure_input(options)
+    with allen_gaudi_config.bind(sequence="hlt1_pp_matching_no_ut_1000KHz"):
+    #with allen_gaudi_config.bind(sequence="hlt1_pp_forward_then_matching_no_ut"):
+        line_names = get_allen_line_names()
+        allen_node = allen_control_flow(options)
+        config.update(configure(options, allen_node))
+
+    return config
+
diff --git a/Liv_Lb0NeutronLines/hlt2.py b/Liv_Lb0NeutronLines/hlt2.py
new file mode 100644
index 0000000000..3b7f120900
--- /dev/null
+++ b/Liv_Lb0NeutronLines/hlt2.py
@@ -0,0 +1,58 @@
+####################################
+# options                          #
+####################################
+
+import Moore
+from Moore import Options, run_moore, config
+from Moore.lines import Hlt2Line
+from RecoConf.reconstruction_objects import reconstruction as reconstruction
+from Moore import options, run_moore
+from RecoConf.global_tools import stateProvider_with_simplified_geom, trackMasterExtrapolator_with_simplified_geom
+from RecoConf.hlt2_global_reco import reconstruction as hlt2_reconstruction, make_light_reco_pr_kf_without_UT
+from RecoConf.hlt2_tracking import (
+    make_TrackBestTrackCreator_tracks,
+    make_PrKalmanFilter_noUT_tracks,
+    make_PrKalmanFilter_Velo_tracks,
+    make_PrKalmanFilter_Seed_tracks,
+)
+from RecoConf.decoders import default_VeloCluster_source
+from RecoConf.event_filters import require_gec
+from Moore.streams import Stream, Streams
+import sys
+
+
+from Hlt2Conf.lines.topological_b import threebody_line, twobody_line
+
+
+
+################## options ############
+    
+public_tools = [
+    trackMasterExtrapolator_with_simplified_geom(),
+    stateProvider_with_simplified_geom(),
+]
+
+def pass_through_line(name="Hlt2MCPassThroughLine"):
+    """Return a HLT2 line that performs no selection but runs and persists the reconstruction
+    """
+    return Hlt2Line(name=name, prescale=1, algs=[], persistreco=True)
+
+
+def _make_lines():
+    #mylines = [builder() for builder in all_lines.values()],
+    mylines = [twobody_line(persistreco=True), threebody_line(persistreco=True)]
+    return mylines
+
+
+def alg_config(options: Options):
+    with reconstruction.bind(from_file=False), hlt2_reconstruction.bind(make_reconstruction=make_light_reco_pr_kf_without_UT),\
+        require_gec.bind(skipUT=True),\
+        default_VeloCluster_source.bind(bank_type="VPRetinaCluster"),\
+        make_TrackBestTrackCreator_tracks.bind(max_ghost_prob=0.7, max_chi2ndof=sys.float_info.max),\
+        make_PrKalmanFilter_Velo_tracks.bind(max_chi2ndof=5.),\
+        make_PrKalmanFilter_noUT_tracks.bind(max_chi2ndof=4.),\
+        make_PrKalmanFilter_Seed_tracks.bind(max_chi2ndof=6.):
+        config = run_moore(options, _make_lines, public_tools=public_tools)
+        return config
+
+
diff --git a/Liv_Lb0NeutronLines/info.yaml b/Liv_Lb0NeutronLines/info.yaml
new file mode 100644
index 0000000000..b5fd051fb7
--- /dev/null
+++ b/Liv_Lb0NeutronLines/info.yaml
@@ -0,0 +1,159 @@
+defaults:
+  inform:
+    - juan.baptista.leite@cern.ch
+  wg: B2OC
+
+
+# checks:
+#   histogram_M:
+#     type: range
+#     expression: Lb0_M
+#     limits:
+#       min: 4000
+#       max: 6000
+ 
+
+# 2024
+{%- set polarities = [
+    'Down', 'Up'
+]%}
+
+{%- set mc_datasets = [
+ ('Lb0ToLcpLcmN0', 'Sim10c' , '7.6', 'DIGI', '15196810'),
+ ('BpToLcpLcmKp', 'Sim10c' , '7.6', 'DIGI', '12197003')
+]%}
+
+{%- for p in polarities %}
+{%- for sigtype, simul, nu, inptype, evttype in mc_datasets %}
+
+{{sigtype}}_Mag{{p}}_MC_HLT1:
+  application: "Moore/v55r7@x86_64_v3-el9-gcc13+detdesc-opt+g"
+  input: 
+    bk_query: /MC/Dev/Beam6800GeV-expected-2024-Mag{{p}}-Nu{{nu}}-25ns-Pythia8/{{simul}}/{{evttype}}/{{inptype}}
+    n_test_lfns: 10
+    dq_flags:
+      - OK
+  output: MC_HLT1.DST
+  options: 
+    entrypoint: Liv_Lb0NeutronLines.hlt1:alg_config
+    extra_options:
+      input_raw_format: 0.5
+      conddb_tag: sim-20231017-vc-md100
+      dddb_tag: dddb-20231017
+      input_type: ROOT
+      output_type: ROOT
+      simulation: True
+      data_type: "Upgrade"
+      evt_max: 100000
+      print_freq: 1000
+      scheduler_legacy_mode: False
+      compression:
+        algorithm: ZSTD
+        level: 1
+        max_buffer_size: 1048576
+
+{{sigtype}}_Mag{{p}}_MC_HLT2:
+  application: "Moore/v55r7@x86_64_v3-el9-gcc13+detdesc-opt+g"
+  input:
+    job_name: {{sigtype}}_Mag{{p}}_MC_HLT1
+  output: MC_HLT2.DST
+  options:
+    entrypoint: Liv_Lb0NeutronLines.hlt2:alg_config
+    extra_options:
+      conddb_tag: sim-20231017-vc-md100
+      dddb_tag: dddb-20231017
+      input_type: "ROOT"
+      output_type: "ROOT"
+      simulation: True
+      input_process: "Hlt2"
+      data_type: "Upgrade"
+      evt_max: -1
+      output_manifest_file: "HLT2.tck.json"
+      scheduler_legacy_mode: False
+      compression:
+        algorithm: ZSTD
+        level: 1
+        max_buffer_size: 1048576
+
+{{sigtype}}_Mag{{p}}_MC_SPRUCE:
+  application: "Moore/v55r7@x86_64_v3-el9-gcc13+detdesc-opt+g"
+  input:
+    job_name: {{sigtype}}_Mag{{p}}_MC_HLT2
+  output: MC_SPRUCE.DST
+  options:
+    entrypoint: Liv_Lb0NeutronLines.Spruce:alg_config
+    extra_options:
+      conddb_tag: sim-20231017-vc-md100
+      dddb_tag: dddb-20231017
+      input_type: "ROOT"
+      output_type: "ROOT"
+      simulation: True
+      data_type: "Upgrade"
+      input_process: "Hlt2"
+      evt_max: -1
+      input_manifest_file: "HLT2.tck.json"
+      output_manifest_file: "SPRUCE.tck.json"
+      histo_file: "hlt1_topo_spruce_b2oc_histo.root"
+      scheduler_legacy_mode: False
+      compression:
+        algorithm: ZSTD
+        level: 1
+        max_buffer_size: 1048576
+ 
+
+{{sigtype}}_Mag{{p}}_MC_Tuple:
+  application: "DaVinci/v64r3@x86_64_v3-el9-gcc13+detdesc-opt+g"
+  input:
+    job_name: {{sigtype}}_Mag{{p}}_MC_SPRUCE
+  output: MC_{{sigtype}}.ROOT
+  options:
+    entrypoint: Liv_Lb0NeutronLines.main_Liv_{{sigtype}}:main
+    extra_options:
+      input_raw_format: 0.5
+      input_type: ROOT
+      simulation: True
+      data_type: Upgrade
+      conddb_tag: sim-20231017-vc-md100
+      dddb_tag: dddb-20231017
+      input_process: "Spruce"
+      conditions_version: master
+      geometry_version: run3/trunk
+      lumi: false
+      output_type: ROOT
+      persistreco_version: 1.0
+      write_decoding_keys_to_git: True
+      input_manifest_file: "SPRUCE.tck.json"
+      input_stream: default
+
+{%- endfor %}
+{%- endfor %}
+
+
+{%- set polarities = [
+    'Down'
+]%}
+{%- for p in polarities %}
+{%- for sigtype, simul, nu, inptype, evttype in mc_datasets %}
+{{sigtype}}_Mag{{p}}_Data_Tuple:
+  application: "DaVinci/v64r3"
+  input:
+    bk_query: /LHCb/Collision24/Beam6800GeV-VeloClosed-Mag{{p}}-Excl-UT/Real Data/Sprucing24c1/94000000/B2OC.DST
+    dq_flags:
+      - UNCHECKED
+      - OK
+    keep_running: True
+  output: RealData_{{sigtype}}.ROOT
+  options:
+    entrypoint: Liv_Lb0NeutronLines.main_Liv_{{sigtype}}:main
+    extra_options:
+      input_raw_format: 0.5
+      input_type: ROOT
+      simulation: False
+      data_type: Upgrade
+      geometry_version: trunk
+      conditions_version: master
+      input_process: "Spruce"
+      input_stream: "b2oc"
+      evt_max: 10000
+{%- endfor %}
+{%- endfor %}
\ No newline at end of file
diff --git a/Liv_Lb0NeutronLines/main_Liv_BpToLcpLcmKp.py b/Liv_Lb0NeutronLines/main_Liv_BpToLcpLcmKp.py
new file mode 100644
index 0000000000..62112f2cbf
--- /dev/null
+++ b/Liv_Lb0NeutronLines/main_Liv_BpToLcpLcmKp.py
@@ -0,0 +1,32 @@
+###############################################################################
+# (c) Copyright 2021-2022 CERN for the benefit of the LHCb Collaboration      #
+#                                                                             #
+# This software is distributed under the terms of the GNU General Public      #
+# Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING".   #
+#                                                                             #
+# In applying this licence, CERN does not waive the privileges and immunities #
+# granted to it by virtue of its status as an Intergovernmental Organization  #
+# or submit itself to any jurisdiction.                                       #
+###############################################################################
+
+from .options.Lb_NeutronLines import *
+
+from DaVinci import Options, make_config
+from PyConf.reading import get_pvs, get_rec_summary
+
+def main(options: Options):
+        
+    # get ODIN and DecReports location
+    pvs = get_pvs()
+    rec_summary = get_rec_summary()
+
+    """ CORREGGERE TUPLES """
+
+    tuples = {    
+        "BpToLcpLcmKp" : maketuple_BpToLcpLcmKp(options, pvs, rec_summary)
+    }
+        
+    config = make_config(options, tuples)
+
+    return config
+
diff --git a/Liv_Lb0NeutronLines/main_Liv_Lb0ToLcpLcmN0.py b/Liv_Lb0NeutronLines/main_Liv_Lb0ToLcpLcmN0.py
new file mode 100644
index 0000000000..84eeaaab32
--- /dev/null
+++ b/Liv_Lb0NeutronLines/main_Liv_Lb0ToLcpLcmN0.py
@@ -0,0 +1,32 @@
+###############################################################################
+# (c) Copyright 2021-2022 CERN for the benefit of the LHCb Collaboration      #
+#                                                                             #
+# This software is distributed under the terms of the GNU General Public      #
+# Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING".   #
+#                                                                             #
+# In applying this licence, CERN does not waive the privileges and immunities #
+# granted to it by virtue of its status as an Intergovernmental Organization  #
+# or submit itself to any jurisdiction.                                       #
+###############################################################################
+
+from .options.Lb_NeutronLines import *
+
+from DaVinci import Options, make_config
+from PyConf.reading import get_pvs, get_rec_summary
+
+def main(options: Options):
+        
+    # get ODIN and DecReports location
+    pvs = get_pvs()
+    rec_summary = get_rec_summary()
+
+    """ CORREGGERE TUPLES """
+
+    tuples = {    
+        "Lb0ToLcpLcmN0" : maketuple_Lb0ToLcpLcnN0(options, pvs, rec_summary)
+    }
+        
+    config = make_config(options, tuples)
+
+    return config
+
diff --git a/Liv_Lb0NeutronLines/main_Liv_Lb0ToPpPmN0.py b/Liv_Lb0NeutronLines/main_Liv_Lb0ToPpPmN0.py
new file mode 100644
index 0000000000..ffa97da0e7
--- /dev/null
+++ b/Liv_Lb0NeutronLines/main_Liv_Lb0ToPpPmN0.py
@@ -0,0 +1,32 @@
+###############################################################################
+# (c) Copyright 2021-2022 CERN for the benefit of the LHCb Collaboration      #
+#                                                                             #
+# This software is distributed under the terms of the GNU General Public      #
+# Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING".   #
+#                                                                             #
+# In applying this licence, CERN does not waive the privileges and immunities #
+# granted to it by virtue of its status as an Intergovernmental Organization  #
+# or submit itself to any jurisdiction.                                       #
+###############################################################################
+
+from .options.Lb_NeutronLines import *
+
+from DaVinci import Options, make_config
+from PyConf.reading import get_pvs, get_rec_summary
+
+def main(options: Options):
+        
+    # get ODIN and DecReports location
+    pvs = get_pvs()
+    rec_summary = get_rec_summary()
+
+    """ CORREGGERE TUPLES """
+
+    tuples = {    
+        "Lb0ToPpPmN0" : maketuple_Lb0ToLcpLcnN0(options, pvs, rec_summary)
+    }
+        
+    config = make_config(options, tuples)
+
+    return config
+
diff --git a/Liv_Lb0NeutronLines/options/Lb_NeutronLines.py b/Liv_Lb0NeutronLines/options/Lb_NeutronLines.py
new file mode 100644
index 0000000000..c072f8e821
--- /dev/null
+++ b/Liv_Lb0NeutronLines/options/Lb_NeutronLines.py
@@ -0,0 +1,167 @@
+from .tupling import *
+
+import Functors as F
+from Functors.math import log
+from DaVinci import Options, make_config
+from DaVinci.algorithms import create_lines_filter
+from PyConf.reading import get_particles
+from FunTuple import FunctorCollection
+from PyConf.reading import get_particles, get_pvs
+import FunTuple.functorcollections as FC
+from FunTuple import FunTuple_Particles as Funtuple
+from DecayTreeFitter import DecayTreeFitter
+
+def maketuple_Lb0ToLcpLcnN0(options, pvs, rec_summary):
+
+    name = "Lb0ToLcpLcmN0"
+    turbo_line = "SpruceB2OC_Lb0ToLcpLcmN0"
+    input_data = get_particles(f"/Event/Spruce/{turbo_line}/Particles")
+
+
+    myfilter = create_lines_filter(
+        f"LineFilter_{turbo_line}_{{hash}}",
+        [turbo_line],
+    )
+
+    branches = {
+        "Lb0":"[Lambda_b0 -> (Lambda_c+ -> p+ K- pi+) (Lambda_c~- -> p~- K+ pi-)]CC",
+        "Lcp":"[Lambda_b0 -> ^(Lambda_c+ -> p+ K- pi+) (Lambda_c~- -> p~- K+ pi-)]CC",
+        "Lcm":"[Lambda_b0 -> (Lambda_c+ -> p+ K- pi+) ^(Lambda_c~- -> p~- K+ pi-)]CC",
+        "pp":"[Lambda_b0 -> (Lambda_c+ -> ^p+ K- pi+) (Lambda_c~- -> p~- K+ pi-)]CC",
+        "pm":"[Lambda_b0 -> (Lambda_c+ -> p+ K- pi+) (Lambda_c~- -> ^p~- K+ pi-)]CC",
+        "pip":"[Lambda_b0 -> (Lambda_c+ -> p+ K- ^pi+) (Lambda_c~- -> p~- K+ pi-)]CC",
+        "pim":"[Lambda_b0 -> (Lambda_c+ -> p+ K- pi+) (Lambda_c~- -> p~- K+ ^pi-)]CC",
+        "Kp":"[Lambda_b0 -> (Lambda_c+ -> p+ K- pi+) (Lambda_c~- -> p~- ^K+ pi-)]CC",
+        "Km":"[Lambda_b0 -> (Lambda_c+ -> p+ ^K- pi+) (Lambda_c~- -> p~- K+ pi-)]CC",
+    }
+    
+    
+    DTF_MASS = DecayTreeFitter(
+        name='DTF_{hash}', 
+        input_particles=input_data)
+
+    DTF_BestPV = DecayTreeFitter(
+        name="DTF_BestPV",
+        input_particles=input_data,
+        mass_constraints=["Lambda_b0", "Lambda_c+"],
+        input_pvs=pvs,
+        fit_all_pvs=False,
+    )
+
+    #pv_constraint=False, mass_constraint=False, particle_name=""
+
+    basic_variables = make_basic_variables(options, pvs, input_data) + \
+                    make_basic_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_MASS, pv_constraint=True) + \
+                    make_basic_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_BestPV, pv_constraint=True, mass_constraint=True, particle_name="BpAndLcBestPV")
+
+    composite_variables =  make_composite_variables(options, pvs, input_data) + \
+                    make_composite_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_MASS, pv_constraint=True) + \
+                    make_composite_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_BestPV, pv_constraint=True, mass_constraint=True, particle_name="BpAndLcBestPV")
+    
+    
+    composite_variables_3body = make_composite_variables_3body(options, pvs, input_data) + \
+                    make_composite_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_MASS, pv_constraint=True) + \
+                    make_composite_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_BestPV, pv_constraint=True, mass_constraint=True, particle_name="BpAndLcBestPV")  
+                   
+    variables = {
+        "Lb0": composite_variables,
+        "Lcp": composite_variables_3body,
+        "Lcm": composite_variables_3body,
+        "pp":basic_variables,
+        "pm":basic_variables,
+        "pip":basic_variables,
+        "pim":basic_variables,
+        "Kp":basic_variables,
+        "Km":basic_variables,
+    }
+
+    mytuple = Funtuple(
+        name=name,
+        tuple_name="DecayTree",
+        fields=branches,
+        variables=variables,
+        event_variables=make_hlt2_event_variables(options, pvs, rec_summary),
+        inputs=input_data)
+
+    return [ myfilter, mytuple]
+
+
+def maketuple_BpToLcpLcmKp(options, pvs, rec_summary):
+
+    name = "BuToLcpLcmK"
+    turbo_line = "SpruceB2OC_BuToLcpLcmK_LcpToPKPi"
+    input_data = get_particles(f"/Event/Spruce/{turbo_line}/Particles")
+
+
+    myfilter = create_lines_filter(
+        f"LineFilter_{turbo_line}_{{hash}}",
+        [turbo_line],
+    )
+
+    branches = {
+        "Bp":"[B+ -> (Lambda_c+ -> p+ K- pi+) (Lambda_c~- -> p~- K+ pi-) K+]CC",
+        "Lcp":"[B+ -> ^(Lambda_c+ -> p+ K- pi+) (Lambda_c~- -> p~- K+ pi-) K+]CC",
+        "Lcm":"[B+ -> (Lambda_c+ -> p+ K- pi+) ^(Lambda_c~- -> p~- K+ pi-) K+]CC",
+        "pp":"[B+ -> (Lambda_c+ -> ^p+ K- pi+) (Lambda_c~- -> p~- K+ pi-) K+]CC",
+        "pm":"[B+ -> (Lambda_c+ -> p+ K- pi+) (Lambda_c~- -> ^p~- K+ pi-) K+]CC",
+        "pip":"[B+ -> (Lambda_c+ -> p+ K- ^pi+) (Lambda_c~- -> p~- K+ pi-) K+]CC",
+        "pim":"[B+ -> (Lambda_c+ -> p+ K- pi+) (Lambda_c~- -> p~- K+ ^pi-) K+]CC",
+        "Kp":"[B+ -> (Lambda_c+ -> p+ K- pi+) (Lambda_c~- -> p~- ^K+ pi-) K+]CC",
+        "Km":"[B+ -> (Lambda_c+ -> p+ ^K- pi+) (Lambda_c~- -> p~- K+ pi-) K+]CC",
+        "Kp_ext":"[B+ -> (Lambda_c+ -> p+ K- pi+) (Lambda_c~- -> p~- K+ pi-) ^K+]CC",
+    }
+    
+    
+    DTF_MASS = DecayTreeFitter(
+        name='DTF_{hash}', 
+        input_particles=input_data)
+
+    DTF_BestPV = DecayTreeFitter(
+        name="DTF_BestPV",
+        input_particles=input_data,
+        mass_constraints=["B+", "Lambda_c+"],
+        input_pvs=pvs,
+        fit_all_pvs=False,
+    )
+
+    #pv_constraint=False, mass_constraint=False, particle_name=""
+
+    basic_variables = make_basic_variables(options, pvs, input_data) + \
+                    make_basic_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_MASS, pv_constraint=True) + \
+                    make_basic_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_BestPV, pv_constraint=True, mass_constraint=True, particle_name="BpAndLcBestPV")
+
+    composite_variables =  make_composite_variables(options, pvs, input_data) + \
+                    make_composite_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_MASS, pv_constraint=True) + \
+                    make_composite_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_BestPV, pv_constraint=True, mass_constraint=True, particle_name="BpAndLcBestPV")
+    
+    
+    composite_variables_3body = make_composite_variables_3body(options, pvs, input_data) + \
+                    make_composite_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_MASS, pv_constraint=True) + \
+                    make_composite_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_BestPV, pv_constraint=True, mass_constraint=True, particle_name="BpAndLcBestPV")  
+                   
+
+    variables = {
+        "Bp": composite_variables,
+        "Lcp": composite_variables_3body,
+        "Lcm": composite_variables_3body,
+        "pp": basic_variables,
+        "pm": basic_variables,
+        "pip": basic_variables,
+        "pim": basic_variables,
+        "Kp": basic_variables,
+        "Km": basic_variables,
+        "Kp_ext": basic_variables,
+    }
+
+    mytuple = Funtuple(
+        name=name,
+        tuple_name="DecayTree",
+        fields=branches,
+        variables=variables,
+        event_variables=make_hlt2_event_variables(options, pvs, rec_summary),
+        inputs=input_data)
+
+    return [ myfilter, mytuple]
+
+
+
diff --git a/Liv_Lb0NeutronLines/options/tupling.py b/Liv_Lb0NeutronLines/options/tupling.py
new file mode 100644
index 0000000000..02d5196172
--- /dev/null
+++ b/Liv_Lb0NeutronLines/options/tupling.py
@@ -0,0 +1,708 @@
+###############################################################################
+# (c) Copyright 2022 CERN for the benefit of the LHCb Collaboration           #
+#                                                                             #
+# This software is distributed under the terms of the GNU General Public      #
+# Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING".   #
+#                                                                             #
+# In applying this licence, CERN does not waive the privileges and immunities #
+# granted to it by virtue of its status as an Intergovernmental Organization  #
+# or submit itself to any jurisdiction.                                       #
+###############################################################################
+"""Common configuration functions
+
+"""
+
+import Functors as F
+from Functors.math import log
+
+from FunTuple import FunctorCollection
+from FunTuple.functorcollections import (
+    MCHierarchy,
+    MCPromptDecay,
+    Kinematics,
+    SelectionInfo,
+    HltTisTos,
+    MCVertexInfo,
+    MCKinematics,
+    ParticleID, #wrong variables PID_PI = 0, PROBNN_D = nan
+    EventInfo,
+    ParticleIsolation,
+    MCPrimaries,
+)
+
+from DaVinciMCTools import MCTruthAndBkgCat
+from PyConf.Algorithms import ParticleToSubcombinationsAlg
+from DecayTreeFitter import DecayTreeFitter
+
+Hlt1_global_lines = [
+    "Hlt1GECPassthroughDecision",
+    "Hlt1BeamGasDecision",
+    "Hlt1PassthroughDecision",
+    "Hlt1NoBeamDecision",
+    "Hlt1BeamOneDecision",
+    "Hlt1BeamTwoDecision",
+    "Hlt1BothBeamsDecision",
+    "Hlt1ODINLumiDecision",
+    "Hlt1ODINVeloOpenDecision",
+    "Hlt1ODINNoBiasDecision",
+    "Hlt1VeloMicroBiasDecision",
+    "Hlt1RICH1AlignmentDecision",
+    "Hlt1RICH2AlignmentDecision",
+    "Hlt1BeamGasDecision",
+    "Hlt1L02PPiDecision",
+    "Hlt1LowMassNoipDielectron_massSlice1_promptDecision",
+    "Hlt1LowMassNoipDielectron_SS_massSlice1_promptDecision",
+    "Hlt1LowMassNoipDielectron_massSlice2_promptDecision",
+    "Hlt1LowMassNoipDielectron_SS_massSlice2_promptDecision",
+    "Hlt1LowMassNoipDielectron_massSlice3_promptDecision",
+    "Hlt1LowMassNoipDielectron_SS_massSlice3_promptDecision",
+    "Hlt1LowMassNoipDielectron_massSlice4_promptDecision",
+    "Hlt1LowMassNoipDielectron_SS_massSlice4_promptDecision",
+    "Hlt1LowMassNoipDielectron_massSlice1_displacedDecision",
+    "Hlt1LowMassNoipDielectron_SS_massSlice1_displacedDecision",
+    "Hlt1LowMassNoipDielectron_massSlice2_displacedDecision",
+    "Hlt1LowMassNoipDielectron_SS_massSlice2_displacedDecision",
+    "Hlt1LowMassNoipDielectron_massSlice3_displacedDecision",
+    "Hlt1LowMassNoipDielectron_SS_massSlice3_displacedDecision",
+    "Hlt1LowMassNoipDielectron_massSlice4_displacedDecision",
+    "Hlt1LowMassNoipDielectron_SS_massSlice4_displacedDecision",
+]
+Hlt1_1track_lines = [
+    "Hlt1TrackMVADecision",
+    "Hlt1LowPtMuonDecision",
+    "Hlt1SingleHighPtMuonDecision",
+    "Hlt1SingleHighPtMuonNoMuIDDecision",
+    "Hlt1TrackMuonMVADecision",
+    "Hlt1OneMuonTrackLineDecision",
+    "Hlt1TrackElectronMVADecision",
+    "Hlt1SingleHighPtElectronDecision",
+    "Hlt1SingleHighEtDecision",
+]
+Hlt1_lines = Hlt1_1track_lines+[
+    "Hlt1TwoTrackMVACharmXSecDecision",
+    "Hlt1TwoTrackMVADecision",
+    "Hlt1TwoTrackKsDecision",
+    "Hlt1D2KPiDecision",
+    "Hlt1D2KKDecision",
+    "Hlt1D2PiPiDecision",
+    "Hlt1KsToPiPiDecision",
+    "Hlt1LowPtDiMuonDecision",#removed
+    "Hlt1DiMuonNoIPDecision",
+    "Hlt1DiMuonNoIP_ssDecision",
+    "Hlt1DiMuonHighMassDecision",
+    "Hlt1DiMuonLowMassDecision",#replaced by Hlt1DiMuonDisplacedDecision
+    "Hlt1DiMuonSoftDecision",
+    "Hlt1DiMuonDisplacedDecision",
+    "Hlt1TwoKsDecision",
+    "Hlt1D2KPiAlignmentDecision",
+    "Hlt1DiMuonHighMassAlignmentDecision",
+    "Hlt1DisplacedDiMuonAlignmentDecision",
+    "Hlt1DisplacedDielectronDecision",
+    "Hlt1DisplacedLeptonsDecision",#removed
+]
+
+Spruce_lines = [
+    "SpruceB2OC_Lb0ToLcpLcmN0",
+    "SpruceB2OC_Lb0ToPbarPN0",
+    "SpruceB2OC_BuToLcpLcmK_LcpToPKPi",
+] 
+
+Hlt2_lines = [
+    "Hlt2Topo2BodyDecision",
+    "Hlt2Topo3Body_Decision"
+
+] 
+
+def make_composite_variables(options, pvs, data, add_truth=True):
+    if not options.simulation:
+        add_truth = False
+    variables = (
+       FunctorCollection(
+           {
+               "CHARGE": F.CHARGE,
+               "MAXPT": F.MAX(F.PT),
+               "MINPT": F.MIN(F.PT),
+               "SUMPT": F.SUM(F.PT),
+               "MAXP": F.MAX(F.P),
+               "MINP": F.MIN(F.P),
+               "BPVDIRA": F.BPVDIRA(pvs),
+               "VCHI2DOF": F.CHI2DOF, #CHI2VXNDOF
+               "VCHI2": F.CHI2,
+               "BPVFDCHI2": F.BPVFDCHI2(pvs),
+               "BPVFD": F.BPVFD(pvs),
+               "BPVFDIR": F.BPVFDIR(pvs),
+               "BPVFDVEC": F.BPVFDVEC(pvs),
+               "BPVVDRHO": F.BPVVDRHO(pvs),
+               "BPVVDZ": F.BPVVDZ(pvs),
+               "BPVIPCHI2": F.BPVIPCHI2(pvs),
+               "BPVIP": F.BPVIP(pvs),
+               "LOGBPVIPCHI2": log(F.BPVIPCHI2(pvs)),
+               "BPVLTIME": F.BPVLTIME(pvs),
+               "MAXBPVIPCHI2": F.MAX(F.BPVIPCHI2(pvs)), #MAX_
+               "MINBPVIPCHI2": F.MIN(F.BPVIPCHI2(pvs)),
+               "MAXBPVIP": F.MAX(F.BPVIP(pvs)),
+               "MINBPVIP": F.MIN(F.BPVIP(pvs)),
+               "MAXDOCACHI2": F.MAXDOCACHI2,
+               "MAXDOCA": F.MAXDOCA,
+               "MAXSDOCACHI2": F.MAXSDOCACHI2,
+               "MAXSDOCA": F.MAXSDOCA,
+               "M12": F.SUBCOMB(Functor=F.MASS, Indices=(1, 2)),
+               "SDOCA12"     : F.SDOCA(Child1=1,Child2=2),
+               "SDOCACHI212" : F.SDOCACHI2(Child1=1,Child2=2),
+               "DOCA12"      : F.DOCA(Child1=1,Child2=2),
+               "DOCACHI212"  : F.DOCACHI2(Child1=1,Child2=2),
+               "COS12": F.ALV(1, 2),
+               "ETA": F.ETA,
+               "PHI": F.PHI,
+               "END_VX": F.END_VX, #END_
+               "END_VY": F.END_VY,
+               "END_VZ": F.END_VZ,
+               "BPVX": F.BPVX(pvs),
+               "BPVY": F.BPVY(pvs),
+               "BPVZ": F.BPVZ(pvs),
+               "ALLPVFD"     : F.ALLPV_FD(pvs),
+               "ALLPVIP"     : F.ALLPV_IP(pvs),
+               "OBJECT_KEY": F.OBJECT_KEY,
+           }
+       )
+       + Kinematics()
+        #+ ParticleID(extra_info=True) #only for daughters
+    )
+
+    variables += HltTisTos(
+        selection_type="Hlt1", trigger_lines=Hlt1_lines, data=data
+    )
+
+    if add_truth:
+        variables = add_truth_matching_functors(
+            options,
+            variables,
+            data,
+            hierarchy=True,
+            kinematics=True,
+            vertex_info=True,
+            bkgcat=True,
+        )
+
+    return variables
+
+def make_tistoscombinations(options, pvs, data):
+    algo_output = ParticleToSubcombinationsAlg( Input=data )
+    relations = algo_output.OutputRelations
+
+    tistos_variables_extra = HltTisTos(
+        selection_type="Hlt1", trigger_lines=["Hlt1TwoTrackMVADecision"], data=algo_output.OutputParticles
+    )
+    tistos_combinations = {}
+    for k,v in tistos_variables_extra.get_thor_functors().items():
+        tistos_combinations[k + "_SUBCOMB" ] = F.MAP_INPUT_ARRAY( v, relations )
+    tistos_combinations = FunctorCollection( tistos_combinations )
+
+    return tistos_combinations
+
+def make_composite_variables_3body(options, pvs, data, add_truth=True):
+
+    variables = (
+        FunctorCollection(
+            {
+                #13
+                "M13": F.SUBCOMB(Functor=F.MASS, Indices=(1, 3)),
+                "SDOCA13"     : F.SDOCA(Child1=1,Child2=3),
+                "SDOCACHI213" : F.SDOCACHI2(Child1=1,Child2=3),
+                "DOCA13"      : F.DOCA(Child1=1,Child2=3),
+                "DOCACHI213"  : F.DOCACHI2(Child1=1,Child2=3),
+                "COS13": F.ALV(1, 3),
+                #23
+                "M23": F.SUBCOMB(Functor=F.MASS, Indices=(2, 3)),
+                "SDOCA23"     : F.SDOCA(Child1=2,Child2=3),
+                "SDOCACHI223" : F.SDOCACHI2(Child1=2,Child2=3),
+                "DOCA23"      : F.DOCA(Child1=2,Child2=3),
+                "DOCACHI223"  : F.DOCACHI2(Child1=2,Child2=3),
+                "COS23": F.ALV(2, 3),
+            }
+        )
+    )
+    return make_composite_variables(options, pvs, data, add_truth)+make_tistoscombinations(options, pvs, data)+variables
+
+def make_composite_variables_4body(options, pvs, data, add_truth=True):
+
+    variables = (
+        FunctorCollection(
+            {
+                #14
+                "M14": F.SUBCOMB(Functor=F.MASS, Indices=(1, 4)),
+                "SDOCA14"     : F.SDOCA(Child1=1,Child2=4),
+                "SDOCACHI214" : F.SDOCACHI2(Child1=1,Child2=4),
+                "DOCA14"      : F.DOCA(Child1=1,Child2=4),
+                "DOCACHI214"  : F.DOCACHI2(Child1=1,Child2=4),
+                "COS14": F.ALV(1, 4),
+                #24
+                "M24": F.SUBCOMB(Functor=F.MASS, Indices=(2, 4)),
+                "SDOCA24"     : F.SDOCA(Child1=2,Child2=4),
+                "SDOCACHI224" : F.SDOCACHI2(Child1=2,Child2=4),
+                "DOCA24"      : F.DOCA(Child1=2,Child2=4),
+                "DOCACHI224"  : F.DOCACHI2(Child1=2,Child2=4),
+                "COS24": F.ALV(2, 4),
+                #34
+                "M34": F.SUBCOMB(Functor=F.MASS, Indices=(3, 4)),
+                "SDOCA34"     : F.SDOCA(Child1=3,Child2=4),
+                "SDOCACHI234" : F.SDOCACHI2(Child1=3,Child2=4),
+                "DOCA34"      : F.DOCA(Child1=3,Child2=4),
+                "DOCACHI234"  : F.DOCACHI2(Child1=3,Child2=4),
+                "COS34": F.ALV(3, 4),
+            }
+        )
+    )
+    return make_composite_variables_3body(options,pvs, data, add_truth)+variables
+
+def make_DeltaM_variable(options):
+    return FunctorCollection({"DM": F.MASS - F.CHILD(1, F.MASS)})
+
+def make_basic_variables(options, pvs, data, add_truth=True):
+    if not options.simulation:
+        add_truth = False
+    variables = (
+       FunctorCollection(
+           { 
+               "CHARGE": F.CHARGE,
+               "TRCHI2DOF": F.CHI2DOF @ F.TRACK,
+               "TRCHI2": F.CHI2 @ F.TRACK,
+               "ETA": F.ETA,
+               "PHI": F.PHI,
+               "TRGHOSTPROB": F.GHOSTPROB,
+               "BPVIPCHI2": F.BPVIPCHI2(pvs),
+               "BPVIP": F.BPVIP(pvs),
+               #"BPVETA": F.BPVETA(pvs),
+               #"BPVDLS": F.BPVDLS(pvs),
+               "BPVX": F.BPVX(pvs),
+               "BPVY": F.BPVY(pvs),
+               "BPVZ": F.BPVZ(pvs),
+               "TX"          : F.TX,
+               "TY"          : F.TY,
+               "MINIPCHI2"   : F.MINIPCHI2(pvs),
+               "MINIP"       : F.MINIP(pvs),
+               "KEY"         : F.VALUE_OR(-1) @ F.OBJECT_KEY @ F.TRACK,
+               "CTB"         : F.POSITION @ F.CLOSESTTOBEAM @ F.TRACK,
+               "ISMUON"      : F.ISMUON,
+               "TRACKPT": F.TRACK_PT,
+               "TRACKHISTORY": F.VALUE_OR(-1) @ F.TRACKHISTORY @ F.TRACK,
+               "QOVERP": F.QOVERP @ F.TRACK,
+               "NDOF": F.VALUE_OR(-1) @ F.NDOF @ F.TRACK,
+               "NFTHITS": F.VALUE_OR(-1) @ F.NFTHITS @ F.TRACK,
+               "NHITS": F.VALUE_OR(-1) @ F.NHITS @ F.TRACK,
+               "NUTHITS": F.VALUE_OR(-1) @ F.NUTHITS @ F.TRACK,
+               "NVPHITS": F.VALUE_OR(-1) @ F.NVPHITS @ F.TRACK,
+               "TRACKHASVELO": F.VALUE_OR(-1) @ F.TRACKHASVELO @ F.TRACK,
+               "TRACKHASUT": F.VALUE_OR(-1) @ F.TRACKHASUT @ F.TRACK,
+               "OBJECT_KEY": F.OBJECT_KEY,
+               "HASBREM": F.HASBREM,
+               "BREMENERGY": F.BREMENERGY,
+               "BREMBENDCORR": F.BREMBENDCORR,
+           }
+       )
+       + Kinematics()
+       + ParticleID(extra_info=True)
+    )
+
+    variables += HltTisTos(
+        selection_type="Hlt1", trigger_lines=Hlt1_1track_lines, data=data
+    )
+
+    if add_truth:
+        variables = add_truth_matching_functors(
+            options,
+            variables,
+            data,
+            hierarchy=True,
+            kinematics=True,
+            vertex_info=True,
+            bkgcat=False,
+        )
+
+    return variables
+
+def make_hlt2_event_variables(options, pvs, rec_summary):
+    # define event level variables
+    evt_variables = EventInfo()
+    evt_variables += SelectionInfo(selection_type="Hlt2", trigger_lines=Hlt2_lines)
+    evt_variables += SelectionInfo(selection_type="Spruce", trigger_lines=Spruce_lines)
+    evt_variables += SelectionInfo(selection_type="Hlt1", trigger_lines=Hlt1_1track_lines)
+    evt_variables += FunctorCollection(
+        {
+            "ALLPVX": F.ALLPVX(pvs),
+            "ALLPVY": F.ALLPVY(pvs),
+            "ALLPVZ": F.ALLPVZ(pvs),
+            "nPVs": F.SIZE(pvs),
+            "nTracks": F.VALUE_OR(-1) @ F.RECSUMMARY_INFO(rec_summary, "nTracks"),
+            "nLongTracks": F.VALUE_OR(-1) @ F.RECSUMMARY_INFO(rec_summary, "nLongTracks"),
+            "nMuonTracks": F.VALUE_OR(-1) @ F.RECSUMMARY_INFO(rec_summary, "nMuonTracks"),
+            "nFTClusters": F.VALUE_OR(-1) @ F.RECSUMMARY_INFO(rec_summary, "nFTClusters"),
+            "nVPClusters": F.VALUE_OR(-1) @ F.RECSUMMARY_INFO(rec_summary, "nVPClusters"),
+            "nUTClusters": F.VALUE_OR(-1) @ F.RECSUMMARY_INFO(rec_summary, "nUTClusters"),
+            "nSPDhits": F.VALUE_OR(-1) @ F.RECSUMMARY_INFO(rec_summary, "nSPDhits"),
+            "nEcalClusters": F.VALUE_OR(-1) @ F.RECSUMMARY_INFO(rec_summary, "nEcalClusters"),
+            "nEcalClusters": F.VALUE_OR(-1) @ F.RECSUMMARY_INFO(rec_summary, "nEcalClusters"),
+            "eCalTot": F.VALUE_OR(-1) @ F.RECSUMMARY_INFO(rec_summary, "eCalTot"),
+            "hCalTot": F.VALUE_OR(-1) @ F.RECSUMMARY_INFO(rec_summary, "hCalTot"),
+            "nRich1Hits": F.VALUE_OR(-1) @ F.RECSUMMARY_INFO(rec_summary, "nRich1Hits"),
+            "nRich2Hits": F.VALUE_OR(-1) @ F.RECSUMMARY_INFO(rec_summary, "nRich2Hits"),
+        }
+    )
+    return evt_variables
+
+
+def make_unpack_only_mc_variables():
+    MC_MOTHER_ID = lambda gen: F.VALUE_OR(0) @ F.MC_MOTHER(gen, F.PARTICLE_ID)
+    MC_MOTHER_KEY = lambda gen: F.VALUE_OR(-1) @ F.MC_MOTHER(gen, F.OBJECT_KEY)
+    return (
+        FunctorCollection(
+            {
+                "TRUEID": F.PARTICLE_ID,
+                "MC_MOTHER_ID": MC_MOTHER_ID(1),
+                "MC_MOTHER_KEY": MC_MOTHER_KEY(1),
+                "MC_GD_MOTHER_ID": MC_MOTHER_ID(2),
+                "MC_GD_MOTHER_KEY": MC_MOTHER_KEY(2),
+                "MC_GD_GD_MOTHER_ID": MC_MOTHER_ID(3),
+                "MC_GD_GD_MOTHER_KEY": MC_MOTHER_KEY(3),
+                "TRUEORIGIN_VX": F.ORIGIN_VX,
+                "TRUEORIGIN_VY": F.ORIGIN_VY,
+                "TRUEORIGIN_VZ": F.ORIGIN_VZ,
+                "TRUEEND_VX": F.END_VX,
+                "TRUEEND_VY": F.END_VY,
+                "TRUEEND_VZ": F.END_VZ,
+            }
+        )
+        + Kinematics()
+        + MCPromptDecay()
+    )
+
+
+####
+
+def add_truth_matching_functors(
+    options,
+    variables,
+    data,
+    hierarchy=True,
+    kinematics=True,
+    vertex_info=True,
+    bkgcat=False,
+    prompt_info=True,
+):
+    """Add MC truth matching functors to an existing FunctorCollection.
+
+    Args:
+        options (DaVinci.Options): DaVinci options object.
+        variables (FunctorCollection): FunctorCollection to modify
+        data: data handle
+        hierarchy (bool): Add MCHierarchy info (default True)
+        kinematics (bool): Add MCKinematics info (default True)
+        vertex_info (bool): Add MCVertexInfo (default True)
+        bkgcat (bool): Add TRUEKEY and BKGCAT functors - intended for composite particles (default False)
+        prompt_info (bool): Add MCPromptDecay info (default True)
+
+    Returns:
+        FunctorCollection: modified FunctorCollection with truth matched variables.
+    """
+    assert (
+        options.simulation
+    ), "options.simulation is set to False - it doesn't make sense to add truth matching."
+
+    MCTRUTH = MCTruthAndBkgCat(data)
+
+    if bkgcat:
+        variables += FunctorCollection(
+            {
+                # Important note: specify an invalid value for integer functors if there exists no truth info.
+                #                 The invalid value for floating point functors is set to nan.
+                "TRUEKEY": F.VALUE_OR(-1) @ MCTRUTH(F.OBJECT_KEY),
+                "BKGCAT": MCTRUTH.BkgCat,
+            }
+        )
+    if hierarchy:
+        variables += MCHierarchy(mctruth_alg=MCTRUTH)  # likely to change again!!
+    if vertex_info:
+        variables += MCVertexInfo(mctruth_alg=MCTRUTH)  # likely to change again!!
+    if kinematics:
+        variables += MCKinematics(mctruth_alg=MCTRUTH)  # likely to change again!!
+    if prompt_info:
+        variables += MCPromptDecay(mctruth_alg=MCTRUTH)
+
+    return variables
+
+### DTF variables ###
+
+def make_basic_dtf_variables(options, pvs, data, add_truth=True, DTF=None, pv_constraint=False, mass_constraint=False, particle_name=""):
+    if not options.simulation:
+        add_truth = False
+    variables = ( 
+        FunctorCollection(
+            {
+                "ETA": F.ETA,
+                "PHI": F.PHI,
+                "BPVIPCHI2": F.BPVIPCHI2(pvs),
+                "BPVIP": F.BPVIP(pvs),
+                "TX"          : F.TX,
+                "TY"          : F.TY,
+                "MINIPCHI2"   : F.MINIPCHI2(pvs),
+                "MINIP"       : F.MINIP(pvs),
+                
+            }
+        )
+        + Kinematics()
+        #+ ParticleID(extra_info=True)
+    )
+    
+    dtf_extras = FunctorCollection(
+        {
+            "DTF_NITER": DTF.NITER,
+            "DTF_CHI2": DTF.CHI2,
+            "DTF_NDOF": DTF.NDOF,
+            "DTF_CHI2DOF": DTF.CHI2DOF
+        }
+    )
+
+
+
+    if(mass_constraint):
+        if(pv_constraint): # MASS + PV
+            dtf_variables_mass_pv = FunctorCollection({
+                        'DTF_PV_M'+ particle_name + '_' + k: DTF(v)
+                        for k, v in variables.get_thor_functors().items()
+                    })
+            return dtf_variables_mass_pv
+        else: # MASS
+            dtf_variables_mass = FunctorCollection(
+                {'DTF_M'+ particle_name + '_' + k: DTF(v)
+                 for k, v in variables.get_thor_functors().items()})
+        return dtf_variables_mass
+    elif(pv_constraint): # PV
+        dtf_variables_pv = FunctorCollection({
+                'DTF_PV_' + k: DTF(v)
+                for k, v in variables.get_thor_functors().items()
+            })
+        return dtf_variables_pv
+
+    else: # NO MASS/PV
+        dtf_variables = FunctorCollection(
+            {'DTF_' + k: DTF(v)
+             for k, v in variables.get_thor_functors().items()})
+        return dtf_variables
+
+def make_composite_dtf_variables(options, pvs, data, add_truth=True, DTF=None, pv_constraint=False, mass_constraint=False, particle_name="", four_body=False):
+    if not options.simulation:
+        add_truth = False
+    variables = (
+        FunctorCollection(
+            {
+                "MAXPT": F.MAX(F.PT),
+                "MINPT": F.MIN(F.PT),
+                "SUMPT": F.SUM(F.PT),
+                "MAXP": F.MAX(F.P),
+                "MINP": F.MIN(F.P),
+                "BPVDIRA": F.BPVDIRA(pvs),
+                "BPVFDCHI2": F.BPVFDCHI2(pvs),
+                "BPVFD": F.BPVFD(pvs),
+                "BPVVDRHO": F.BPVVDRHO(pvs),
+                "BPVVDZ": F.BPVVDZ(pvs),
+                "BPVIPCHI2": F.BPVIPCHI2(pvs),
+                "BPVIP": F.BPVIP(pvs),
+                "LOGBPVIPCHI2": log(F.BPVIPCHI2(pvs)),
+                "BPVLTIME": F.BPVLTIME(pvs),
+                "MAXBPVIPCHI2": F.MAX(F.BPVIPCHI2(pvs)), #MAX_
+                "MINBPVIPCHI2": F.MIN(F.BPVIPCHI2(pvs)),
+                "MAXBPVIP": F.MAX(F.BPVIP(pvs)),
+                "MINBPVIP": F.MIN(F.BPVIP(pvs)),
+                "M12": F.SUBCOMB(Functor=F.MASS, Indices=(1, 2)),
+                "ETA": F.ETA,
+                "PHI": F.PHI
+            }
+        )
+        + Kinematics()
+        
+        #+ ParticleID(extra_info=True) #only for daughters
+    )
+    
+    if four_body:
+            variables += FunctorCollection(
+                {
+                    "M13": F.SUBCOMB(Functor=F.MASS, Indices=(1, 3)),
+                    "M14": F.SUBCOMB(Functor=F.MASS, Indices=(1, 4)),
+                    "M23": F.SUBCOMB(Functor=F.MASS, Indices=(2, 3)),
+                    "M24": F.SUBCOMB(Functor=F.MASS, Indices=(2, 4)),
+                }
+            )
+            
+    dtf_extras = FunctorCollection(
+        {
+            "DTF_NITER": DTF.NITER,
+            "DTF_CHI2": DTF.CHI2,
+            "DTF_NDOF": DTF.NDOF,
+            "DTF_CHI2DOF": DTF.CHI2DOF
+        }
+    )
+
+
+    if(mass_constraint):
+        if(pv_constraint): # MASS + PV
+            dtf_variables_mass_pv = FunctorCollection({
+                        'DTF_PV_M'+ particle_name + '_' + k: DTF(v)
+                        for k, v in variables.get_thor_functors().items()
+                    })
+            return dtf_variables_mass_pv + dtf_extras
+        else: # MASS
+            dtf_variables_mass = FunctorCollection(
+                {'DTF_M'+ particle_name + '_' + k: DTF(v)
+                 for k, v in variables.get_thor_functors().items()})
+        return dtf_variables_mass + dtf_extras
+
+    elif(pv_constraint): # PV
+        dtf_variables_pv = FunctorCollection({
+                'DTF_PV_' + k: DTF(v)
+                for k, v in variables.get_thor_functors().items()
+            })
+        return dtf_variables_pv + dtf_extras
+
+    else: # NO MASS/PV
+        dtf_variables = FunctorCollection(
+            {'DTF_' + k: DTF(v)
+             for k, v in variables.get_thor_functors().items()})
+        return dtf_variables + dtf_extras
+
+def make_MC_basic_variables():
+    variables = (
+        FunctorCollection(
+            {
+                "OBJECT_KEY": F.OBJECT_KEY,
+                "ETA": F.ETA,
+                "PHI": F.PHI,
+                "ORIGIN_VX": F.ORIGIN_VX,
+                "ORIGIN_VY": F.ORIGIN_VY,
+                "ORIGIN_VZ": F.ORIGIN_VZ,
+                "FOURMOMENTUM": F.FOURMOMENTUM,
+            }
+        )
+        + Kinematics()
+    )
+
+    return variables
+
+def make_MC_composite_variables():
+    variables = (
+        FunctorCollection(
+            {
+                "END_VX": F.END_VX, #END_
+                "END_VY": F.END_VY,
+                "END_VZ": F.END_VZ,
+                "LTIME": F.MC_LIFETIME,
+                "OBJECT_KEY": F.OBJECT_KEY,
+                "ETA": F.ETA,
+                "PHI": F.PHI,
+                "ORIGIN_VX": F.ORIGIN_VX,
+                "ORIGIN_VY": F.ORIGIN_VY,
+                "ORIGIN_VZ": F.ORIGIN_VZ,
+                "FOURMOMENTUM": F.FOURMOMENTUM,
+            }
+        )
+        + Kinematics()
+    )
+
+    return variables
+
+def make_MC_event_variables(mc_header):
+    # define event level variables
+    evt_variables = EventInfo()
+    evt_variables += MCPrimaries(mc_header=mc_header)
+
+    return evt_variables
+
+def make_top_isolation_variables(hlt2_line, input_data, locations = ["LongTrackIso","NeutralIso"]):
+    from PyConf.reading import get_particles
+    from IsolationTools import VertexAndConeIsolation
+
+    possible_charm_locations = ["LongTrackIso", "TTrackIso", "DownstreamTrackIso", "UpstreamTrackIso", "NeutralIso", "PizIso"]
+    coneangles = [0.25,0.5,1.,1.5,2.]
+    
+    count = 0
+    for location in locations:
+        extra_particles = get_particles(f"/Event/HLT2/{hlt2_line}/{location}/Particles")
+
+        for coneangle in coneangles:
+            top_RTAlg = VertexAndConeIsolation(
+                name=location+"_"+str(coneangle),
+                reference_particles=input_data,
+                related_particles=extra_particles,
+                cut=F.DR2<coneangle)
+            
+            if count == 0:
+                top_iso_variables = ParticleIsolation(isolation_alg=top_RTAlg,array_indx_name='indx')
+            else:
+                top_iso_variables += ParticleIsolation(isolation_alg=top_RTAlg,array_indx_name='indx')
+            count += 1
+                
+
+    return top_iso_variables
+
+def make_basic_isolation_variables(hlt2_line, input_data, locations = ["LongTrackIso","NeutralIso"]):
+    from PyConf.reading import get_particles
+    from IsolationTools import VertexAndConeIsolation
+    from PyConf.Algorithms import ThOrParticleSelection
+
+    basic_code = (F.FILTER(F.ALL) @ F.GET_ALL_BASICS())
+    basic_particles = ThOrParticleSelection(InputParticles=input_data, Functor=basic_code).OutputSelection
+
+    possible_charm_locations = ["LongTrackIso", "TTrackIso", "DownstreamTrackIso", "UpstreamTrackIso", "NeutralIso", "PizIso"]
+    coneangles = [0.25,0.5,1.,1.5,2.]
+    
+    count = 0
+    for location in locations:
+        extra_particles = get_particles(f"/Event/HLT2/{hlt2_line}/{location}/Particles")
+
+        for coneangle in coneangles:
+            basic_RTAlg = VertexAndConeIsolation(
+                name=location+"_"+str(coneangle),
+                reference_particles=basic_particles,
+                related_particles=extra_particles,
+                cut=F.DR2<coneangle)
+            
+            if count == 0:
+                basic_iso_variables = ParticleIsolation(isolation_alg=basic_RTAlg,array_indx_name='indx')
+            else:
+                basic_iso_variables += ParticleIsolation(isolation_alg=basic_RTAlg,array_indx_name='indx')
+            count += 1
+                
+
+    return basic_iso_variables
+
+
+def make_intermediate_isolation_variables(hlt2_line, input_data, locations = ["LongTrackIso","NeutralIso"], composite_ID = "J/psi(1S)"):
+    from PyConf.reading import get_particles
+    from IsolationTools import VertexAndConeIsolation
+    from PyConf.Algorithms import ThOrParticleSelection
+
+    intermediate_code = F.FILTER(F.IS_ABS_ID(composite_ID)) @ F.GET_ALL_DESCENDANTS()
+    intermediate_particles = ThOrParticleSelection(InputParticles=input_data, Functor=intermediate_code).OutputSelection
+
+    possible_charm_locations = ["LongTrackIso", "TTrackIso", "DownstreamTrackIso", "UpstreamTrackIso", "NeutralIso", "PizIso"]
+    coneangles = [0.25,0.5,1.,1.5,2.]
+    
+    count = 0
+    for location in locations:
+        extra_particles = get_particles(f"/Event/HLT2/{hlt2_line}/{location}/Particles")
+
+        for coneangle in coneangles:
+            intermediate_RTAlg = VertexAndConeIsolation(
+                name=location+"_"+str(coneangle),
+                reference_particles=intermediate_particles,
+                related_particles=extra_particles,
+                cut=F.DR2<coneangle)
+            
+            if count == 0:
+                intermediate_iso_variables = ParticleIsolation(isolation_alg=intermediate_RTAlg,array_indx_name='indx')
+            else:
+                intermediate_iso_variables += ParticleIsolation(isolation_alg=intermediate_RTAlg,array_indx_name='indx')
+            count += 1
+                
+
+    return intermediate_iso_variables
+
-- 
GitLab


From ad0508d5df52552c2e6a4b47ef188b481acd4ac2 Mon Sep 17 00:00:00 2001
From: Juan Leite <jbaptist@lxplus981.cern.ch>
Date: Mon, 29 Apr 2024 18:14:13 +0200
Subject: [PATCH 10/34] remove evt max

---
 Liv_Lb0NeutronLines/info.yaml | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/Liv_Lb0NeutronLines/info.yaml b/Liv_Lb0NeutronLines/info.yaml
index b5fd051fb7..ff84223f05 100644
--- a/Liv_Lb0NeutronLines/info.yaml
+++ b/Liv_Lb0NeutronLines/info.yaml
@@ -44,7 +44,7 @@ defaults:
       output_type: ROOT
       simulation: True
       data_type: "Upgrade"
-      evt_max: 100000
+      evt_max: -1
       print_freq: 1000
       scheduler_legacy_mode: False
       compression:
@@ -154,6 +154,6 @@ defaults:
       conditions_version: master
       input_process: "Spruce"
       input_stream: "b2oc"
-      evt_max: 10000
+      evt_max: -1
 {%- endfor %}
 {%- endfor %}
\ No newline at end of file
-- 
GitLab


From ed632654162ae03568de7a950b14d1ce593c7abf Mon Sep 17 00:00:00 2001
From: Juan Leite <jbaptist@lxplus981.cern.ch>
Date: Mon, 29 Apr 2024 18:20:43 +0200
Subject: [PATCH 11/34] removing ppbar lines folder

---
 Liv_Lb0NeutronLines/info.yaml                 |   2 +-
 Liv_PPBarLines/hlt1.py                        |  32 -
 Liv_PPBarLines/hlt2.py                        |  57 --
 Liv_PPBarLines/info.yaml                      | 132 ----
 Liv_PPBarLines/main_Liv_PPBarLines_B0PPbar.py |  32 -
 .../main_Liv_PPBarLines_B0PPbarPPbar.py       |  32 -
 .../main_Liv_PPBarLines_Bs0PPbar.py           |  32 -
 .../main_Liv_PPBarLines_Bs0PPbarPPbar.py      |  32 -
 Liv_PPBarLines/options/Bsd_ppbarlines.py      | 206 -----
 Liv_PPBarLines/options/tupling.py             | 701 ------------------
 10 files changed, 1 insertion(+), 1257 deletions(-)
 delete mode 100644 Liv_PPBarLines/hlt1.py
 delete mode 100644 Liv_PPBarLines/hlt2.py
 delete mode 100644 Liv_PPBarLines/info.yaml
 delete mode 100644 Liv_PPBarLines/main_Liv_PPBarLines_B0PPbar.py
 delete mode 100644 Liv_PPBarLines/main_Liv_PPBarLines_B0PPbarPPbar.py
 delete mode 100644 Liv_PPBarLines/main_Liv_PPBarLines_Bs0PPbar.py
 delete mode 100644 Liv_PPBarLines/main_Liv_PPBarLines_Bs0PPbarPPbar.py
 delete mode 100644 Liv_PPBarLines/options/Bsd_ppbarlines.py
 delete mode 100644 Liv_PPBarLines/options/tupling.py

diff --git a/Liv_Lb0NeutronLines/info.yaml b/Liv_Lb0NeutronLines/info.yaml
index ff84223f05..2a2ccb3db0 100644
--- a/Liv_Lb0NeutronLines/info.yaml
+++ b/Liv_Lb0NeutronLines/info.yaml
@@ -156,4 +156,4 @@ defaults:
       input_stream: "b2oc"
       evt_max: -1
 {%- endfor %}
-{%- endfor %}
\ No newline at end of file
+{%- endfor %}
diff --git a/Liv_PPBarLines/hlt1.py b/Liv_PPBarLines/hlt1.py
deleted file mode 100644
index 77154c68ae..0000000000
--- a/Liv_PPBarLines/hlt1.py
+++ /dev/null
@@ -1,32 +0,0 @@
-###############################################################################
-# (c) Copyright 2023 CERN for the benefit of the LHCb Collaboration           #
-#                                                                             #
-# This software is distributed under the terms of the GNU General Public      #
-# Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING".   #
-#                                                                             #
-# In applying this licence, CERN does not waive the privileges and immunities #
-# granted to it by virtue of its status as an Intergovernmental Organization  #
-# or submit itself to any jurisdiction.                                       #
-###############################################################################
-"""
-Configures running HLT1 via Moore.
-"""
-
-from Moore import Options
-from Moore.config import allen_control_flow
-from RecoConf.hlt1_allen import allen_gaudi_config, get_allen_line_names
-from PyConf.application import configure_input, configure
-
-def alg_config(options: Options):
-    """
-    Configures algorithm running of HLT1 via Moore to be passed to Analysis Productions.
-    """
-
-    config = configure_input(options)
-    with allen_gaudi_config.bind(sequence="hlt1_pp_matching_no_ut_1000KHz"):
-        line_names = get_allen_line_names()
-        allen_node = allen_control_flow(options)
-        config.update(configure(options, allen_node))
-
-    return config
-
diff --git a/Liv_PPBarLines/hlt2.py b/Liv_PPBarLines/hlt2.py
deleted file mode 100644
index 8c53befcde..0000000000
--- a/Liv_PPBarLines/hlt2.py
+++ /dev/null
@@ -1,57 +0,0 @@
-####################################
-# options                          #
-####################################
-
-import Moore
-from Moore import Options, run_moore, config
-from Moore.lines import Hlt2Line
-from RecoConf.reconstruction_objects import reconstruction as reconstruction
-from Moore import options, run_moore
-from RecoConf.global_tools import stateProvider_with_simplified_geom, trackMasterExtrapolator_with_simplified_geom
-from RecoConf.hlt2_global_reco import reconstruction as hlt2_reconstruction, make_light_reco_pr_kf_without_UT
-from RecoConf.hlt2_tracking import (
-    make_TrackBestTrackCreator_tracks,
-    make_PrKalmanFilter_noUT_tracks,
-    make_PrKalmanFilter_Velo_tracks,
-    make_PrKalmanFilter_Seed_tracks,
-)
-from RecoConf.decoders import default_VeloCluster_source
-from RecoConf.event_filters import require_gec
-from Moore.streams import Stream, Streams
-import sys
-
-
-from Hlt2Conf.lines.bnoc import all_lines as ppbar_lines
-
-
-
-################## options ############
-    
-public_tools = [
-    trackMasterExtrapolator_with_simplified_geom(),
-    stateProvider_with_simplified_geom(),
-]
-
-def pass_through_line(name="Hlt2MCPassThroughLine"):
-    """Return a HLT2 line that performs no selection but runs and persists the reconstruction
-    """
-    return Hlt2Line(name=name, prescale=1, algs=[], persistreco=True)
-
-
-def _make_lines():
-    mylines = [builder() for builder in ppbar_lines.values()]
-    mylines += [pass_through_line()]
-    return mylines
-
-def alg_config(options: Options):
-    with reconstruction.bind(from_file=False), hlt2_reconstruction.bind(make_reconstruction=make_light_reco_pr_kf_without_UT),\
-        require_gec.bind(skipUT=True),\
-        default_VeloCluster_source.bind(bank_type="VPRetinaCluster"),\
-        make_TrackBestTrackCreator_tracks.bind(max_ghost_prob=0.7, max_chi2ndof=sys.float_info.max),\
-        make_PrKalmanFilter_Velo_tracks.bind(max_chi2ndof=5.),\
-        make_PrKalmanFilter_noUT_tracks.bind(max_chi2ndof=4.),\
-        make_PrKalmanFilter_Seed_tracks.bind(max_chi2ndof=6.):
-        config = run_moore(options, make_streams=_make_lines, public_tools=public_tools)
-        return config
-
-
diff --git a/Liv_PPBarLines/info.yaml b/Liv_PPBarLines/info.yaml
deleted file mode 100644
index f3718d6f31..0000000000
--- a/Liv_PPBarLines/info.yaml
+++ /dev/null
@@ -1,132 +0,0 @@
-defaults:
-  inform:
-    - juan.baptista.leite@cern.ch
-  wg: BnoC
-
-
-checks:
-  histogram_M:
-    type: range
-    expression: B0_M
-    limits:
-      min: 4800
-      max: 6000
- 
-
-# 2024
-{%- set polarities = [
-    'Down', 'Up'
-]%}
-
-{%- set mc_datasets = [
- ( 'B0PPbar', 'Sim10c' , '7.6', 'DIGI', '11102031'),
- ( 'Bs0PPbar', 'Sim10c' , '7.6', 'DIGI', '13102031'),
- ( 'B0PPbarPPbar', 'Sim10c' , '7.6', 'DIGI', '11104077'),
- ( 'Bs0PPbarPPbar', 'Sim10c' , '7.6', 'DIGI', '13104077'),
-]%}
-
-{%- for p in polarities %}
-{%- for sigtype, simul, nu, inptype, evttype in mc_datasets %}
-
-{{sigtype}}_Mag{{p}}_MC_HLT1:
-  application: "Moore/v55r7@x86_64_v3-el9-gcc13+detdesc-opt+g"
-  input: 
-    bk_query: /MC/Dev/Beam6800GeV-expected-2024-Mag{{p}}-Nu{{nu}}-25ns-Pythia8/{{simul}}/{{evttype}}/{{inptype}}
-    dq_flags:
-      - OK
-  output: MC_HLT1.DST
-  options: 
-    entrypoint: Liv_PPBarLines.hlt1:alg_config
-    extra_options:
-      input_raw_format: 0.5
-      conddb_tag: sim-20231017-vc-md100
-      dddb_tag: dddb-20231017
-      input_type: ROOT
-      output_type: ROOT
-      simulation: True
-      data_type: "Upgrade"
-      evt_max: -1
-      scheduler_legacy_mode: False
-      compression:
-        algorithm: ZSTD
-        level: 1
-        max_buffer_size: 1048576
-
-{{sigtype}}_Mag{{p}}_MC_HLT2:
-  application: "Moore/v55r7@x86_64_v3-el9-gcc13+detdesc-opt+g"
-  input:
-    job_name: {{sigtype}}_Mag{{p}}_MC_HLT1
-  output: MC_HLT2.DST
-  options:
-    entrypoint: Liv_PPBarLines.hlt2:alg_config
-    extra_options:
-      conddb_tag: sim-20231017-vc-md100
-      dddb_tag: dddb-20231017
-      input_type: "ROOT"
-      output_type: "ROOT"
-      simulation: True
-      data_type: "Upgrade"
-      evt_max: -1
-      output_manifest_file: "HLT2.tck.json"
-      scheduler_legacy_mode: False
-      compression:
-        algorithm: ZSTD
-        level: 1
-        max_buffer_size: 1048576
-
- 
-
-{{sigtype}}_Mag{{p}}_MC_Tuple:
-  application: "DaVinci/v64r3@x86_64_v3-el9-gcc13+detdesc-opt+g"
-  input:
-    job_name: {{sigtype}}_Mag{{p}}_MC_HLT2
-  checks:
-    - histogram_M
-  output: MC_{{sigtype}}.ROOT
-  options:
-    entrypoint: Liv_PPBarLines.main_Liv_PPBarLines_{{sigtype}}:main
-    extra_options:
-      input_raw_format: 0.5
-      input_type: ROOT
-      simulation: True
-      data_type: Upgrade
-      conddb_tag: sim-20231017-vc-md100
-      dddb_tag: dddb-20231017
-      input_process: "Hlt2"
-      input_manifest_file: "HLT2.tck.json"
-
-{%- endfor %}
-{%- endfor %}
-
-
-{%- set polarities = [
-    'Down'
-]%}
-{%- for p in polarities %}
-{%- for sigtype, simul, nu, inptype, evttype in mc_datasets %}
-{{sigtype}}_Mag{{p}}_Data_Tuple:
-  application: "DaVinci/v64r3"
-  input:
-    bk_query: /LHCb/Collision24/Beam6800GeV-VeloClosed-Mag{{p}}-Excl-UT/Real Data/Sprucing24c1/94000000/BNOC.DST
-    dq_flags:
-      - UNCHECKED
-      - OK
-    keep_running: True
-  checks:
-    - histogram_M
-  output: RealData_{{sigtype}}.ROOT
-  options:
-    entrypoint: Liv_PPBarLines.main_Liv_PPBarLines_{{sigtype}}:main
-    extra_options:
-      input_raw_format: 0.5
-      input_type: ROOT
-      simulation: False
-      data_type: "Upgrade"
-      event_store: HiveWhiteBoard
-      geometry_version: run3/trunk
-      conditions_version: master
-      input_process: "TurboPass"
-      input_stream: "bnoc"
-      evt_max: -1
-{%- endfor %}
-{%- endfor %}
\ No newline at end of file
diff --git a/Liv_PPBarLines/main_Liv_PPBarLines_B0PPbar.py b/Liv_PPBarLines/main_Liv_PPBarLines_B0PPbar.py
deleted file mode 100644
index e419dcc699..0000000000
--- a/Liv_PPBarLines/main_Liv_PPBarLines_B0PPbar.py
+++ /dev/null
@@ -1,32 +0,0 @@
-###############################################################################
-# (c) Copyright 2021-2022 CERN for the benefit of the LHCb Collaboration      #
-#                                                                             #
-# This software is distributed under the terms of the GNU General Public      #
-# Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING".   #
-#                                                                             #
-# In applying this licence, CERN does not waive the privileges and immunities #
-# granted to it by virtue of its status as an Intergovernmental Organization  #
-# or submit itself to any jurisdiction.                                       #
-###############################################################################
-
-from .options.Bsd_ppbarlines import *
-
-from DaVinci import Options, make_config
-from PyConf.reading import get_pvs, get_rec_summary
-
-def main(options: Options):
-        
-    # get ODIN and DecReports location
-    pvs = get_pvs()
-    rec_summary = get_rec_summary()
-
-    """ CORREGGERE TUPLES """
-
-    tuples = {    
-        "BdToPpPm" : maketuple_BdToPPbar(options, pvs, rec_summary)
-    }
-        
-    config = make_config(options, tuples)
-
-    return config
-
diff --git a/Liv_PPBarLines/main_Liv_PPBarLines_B0PPbarPPbar.py b/Liv_PPBarLines/main_Liv_PPBarLines_B0PPbarPPbar.py
deleted file mode 100644
index d68efa29f4..0000000000
--- a/Liv_PPBarLines/main_Liv_PPBarLines_B0PPbarPPbar.py
+++ /dev/null
@@ -1,32 +0,0 @@
-###############################################################################
-# (c) Copyright 2021-2022 CERN for the benefit of the LHCb Collaboration      #
-#                                                                             #
-# This software is distributed under the terms of the GNU General Public      #
-# Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING".   #
-#                                                                             #
-# In applying this licence, CERN does not waive the privileges and immunities #
-# granted to it by virtue of its status as an Intergovernmental Organization  #
-# or submit itself to any jurisdiction.                                       #
-###############################################################################
-
-from .options.Bsd_ppbarlines import *
-
-from DaVinci import Options, make_config
-from PyConf.reading import get_pvs, get_rec_summary
-
-def main(options: Options):
-        
-    # get ODIN and DecReports location
-    pvs = get_pvs()
-    rec_summary = get_rec_summary()
-
-    """ CORREGGERE TUPLES """
-
-    tuples = {    
-        "BdToPpPmPpPm" : maketuple_BdToPPbarPPbar(options, pvs, rec_summary)
-    }
-        
-    config = make_config(options, tuples)
-
-    return config
-
diff --git a/Liv_PPBarLines/main_Liv_PPBarLines_Bs0PPbar.py b/Liv_PPBarLines/main_Liv_PPBarLines_Bs0PPbar.py
deleted file mode 100644
index 76ecbf2222..0000000000
--- a/Liv_PPBarLines/main_Liv_PPBarLines_Bs0PPbar.py
+++ /dev/null
@@ -1,32 +0,0 @@
-###############################################################################
-# (c) Copyright 2021-2022 CERN for the benefit of the LHCb Collaboration      #
-#                                                                             #
-# This software is distributed under the terms of the GNU General Public      #
-# Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING".   #
-#                                                                             #
-# In applying this licence, CERN does not waive the privileges and immunities #
-# granted to it by virtue of its status as an Intergovernmental Organization  #
-# or submit itself to any jurisdiction.                                       #
-###############################################################################
-
-from .options.Bsd_ppbarlines import *
-
-from DaVinci import Options, make_config
-from PyConf.reading import get_pvs, get_rec_summary
-
-def main(options: Options):
-        
-    # get ODIN and DecReports location
-    pvs = get_pvs()
-    rec_summary = get_rec_summary()
-
-    """ CORREGGERE TUPLES """
-
-    tuples = {    
-        "Bs0ToPpPm" : maketuple_Bs0ToPPbar(options, pvs, rec_summary)  
-    }
-        
-    config = make_config(options, tuples)
-
-    return config
-
diff --git a/Liv_PPBarLines/main_Liv_PPBarLines_Bs0PPbarPPbar.py b/Liv_PPBarLines/main_Liv_PPBarLines_Bs0PPbarPPbar.py
deleted file mode 100644
index 588eb058cb..0000000000
--- a/Liv_PPBarLines/main_Liv_PPBarLines_Bs0PPbarPPbar.py
+++ /dev/null
@@ -1,32 +0,0 @@
-###############################################################################
-# (c) Copyright 2021-2022 CERN for the benefit of the LHCb Collaboration      #
-#                                                                             #
-# This software is distributed under the terms of the GNU General Public      #
-# Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING".   #
-#                                                                             #
-# In applying this licence, CERN does not waive the privileges and immunities #
-# granted to it by virtue of its status as an Intergovernmental Organization  #
-# or submit itself to any jurisdiction.                                       #
-###############################################################################
-
-from .options.Bsd_ppbarlines import *
-
-from DaVinci import Options, make_config
-from PyConf.reading import get_pvs, get_rec_summary
-
-def main(options: Options):
-        
-    # get ODIN and DecReports location
-    pvs = get_pvs()
-    rec_summary = get_rec_summary()
-
-    """ CORREGGERE TUPLES """
-
-    tuples = {    
-        "Bs0ToPpPmPpPm" : maketuple_Bs0ToPPbarPPbar(options, pvs, rec_summary)
-    }
-        
-    config = make_config(options, tuples)
-
-    return config
-
diff --git a/Liv_PPBarLines/options/Bsd_ppbarlines.py b/Liv_PPBarLines/options/Bsd_ppbarlines.py
deleted file mode 100644
index 87e5d9d74b..0000000000
--- a/Liv_PPBarLines/options/Bsd_ppbarlines.py
+++ /dev/null
@@ -1,206 +0,0 @@
-from .tupling import *
-
-import Functors as F
-from Functors.math import log
-from DaVinci import Options, make_config
-from DaVinci.algorithms import create_lines_filter
-from PyConf.reading import get_particles
-from FunTuple import FunctorCollection
-from PyConf.reading import get_particles, get_pvs
-import FunTuple.functorcollections as FC
-from FunTuple import FunTuple_Particles as Funtuple
-from DecayTreeFitter import DecayTreeFitter
-"""
- BdsToPPbar
- BdsToPPbarPPbar
- nb: https://gitlab.cern.ch/lhcb/Moore/-/blob/master/Hlt/Hlt2Conf/python/Hlt2Conf/lines/bnoc/BToPpPm.py?ref_type=heads
-
- """
-
-
-# BdsToPPbar
-def maketuple_BdToPPbar(options, pvs, rec_summary):
-    name = "BdToPPbar"
-    turbo_line = "Hlt2BnoC_BdsToPpPm"
-
-    input_data = get_particles(f"/Event/HLT2/{turbo_line}/Particles")
-    myfilter = create_lines_filter(
-        f"LineFilter_{turbo_line}_{{hash}}",
-        [turbo_line],
-    )
-
-    branches = {
-        "B0": "[B0 -> p+ p~-]CC",
-        "pp": "[B0 -> ^p+ p~-]CC",
-        "pm": "[B0 -> p+ ^p~-]CC",
-    }
-
-    DTF_MASS_PV = DecayTreeFitter(
-        name='DTF_{hash}', input_particles=input_data, input_pvs=pvs)
-    
-    DTF_MASS = DecayTreeFitter(
-        name='DTF_{hash}', input_particles=input_data)
-    
-
-    basic_variables = make_basic_variables(options, pvs, input_data) +\
-                    make_basic_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_MASS, pv_constraint=True) 
-    composite_variables = make_composite_variables(options, pvs, input_data) +\
-                    make_composite_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_MASS, pv_constraint=True) 
-
-    variables = {
-        "B0": composite_variables,
-        "pp": basic_variables,
-        "pm": basic_variables,
-    }
-
-    mytuple = Funtuple(
-        name=name,
-        tuple_name="DecayTree",
-        fields=branches,
-        variables=variables,
-        event_variables=make_hlt2_event_variables(options, pvs, rec_summary),
-        inputs=input_data)
-
-    return [myfilter, mytuple]
-
-
-def maketuple_Bs0ToPPbar(options, pvs, rec_summary):
-    name = "Bs0ToPPbar"
-    turbo_line = "Hlt2BnoC_BdsToPpPm"
-
-    input_data = get_particles(f"/Event/HLT2/{turbo_line}/Particles")
-    myfilter = create_lines_filter(f"LineFilter_{turbo_line}_{{hash}}",
-                                   [turbo_line])
-
-    branches = {
-        "B0": "[B0 -> p+ p~-]CC",
-        "pp": "[B0 -> ^p+ p~-]CC",
-        "pm": "[B0 -> p+ ^p~-]CC",
-    }
-
-    DTF_MASS_PV = DecayTreeFitter(
-        name='DTF_{hash}', input_particles=input_data, input_pvs=pvs)
-    
-    DTF_MASS = DecayTreeFitter(
-        name='DTF_{hash}', input_particles=input_data)
-    
-
-    basic_variables = make_basic_variables(options, pvs, input_data) +\
-                    make_basic_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_MASS, pv_constraint=True)  
-    composite_variables = make_composite_variables(options, pvs, input_data) +\
-                    make_composite_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_MASS, pv_constraint=True) 
-
-    variables = {
-        "B0": composite_variables,
-        "pp": basic_variables,
-        "pm": basic_variables,
-    }
-
-    mytuple = Funtuple(
-        name=name,
-        tuple_name="DecayTree",
-        fields=branches,
-        variables=variables,
-        event_variables=make_hlt2_event_variables(options, pvs, rec_summary),
-        inputs=input_data)
-
-    return [myfilter, mytuple]
-
-
-# BdsToPPbarPPbar
-def maketuple_BdToPPbarPPbar(options, pvs, rec_summary):
-    name = "BdToPPbarPPbar"
-    turbo_line = "Hlt2BnoC_BdsToPpPmPpPm"
-
-    input_data = get_particles(f"/Event/HLT2/{turbo_line}/Particles")
-    myfilter = create_lines_filter(
-        f"LineFilter_{turbo_line}_{{hash}}",
-        [turbo_line],
-    )
-
-    branches = {
-        "B0": "[B0 -> p+ p~- p+ p~-]CC",
-        "p1": "[B0 -> ^p+ p~- p+ p~-]CC",
-        "pm1": "[B0 -> p+ ^p~- p+ p~-]CC",
-        "p2": "[B0 ->  p+ p~- ^p+ p~-]CC",
-        "pm2": "[B0 -> p+ p~- p+ ^p~-]CC",
-    }
-
-    DTF_MASS_PV = DecayTreeFitter(
-        name='DTF_{hash}', input_particles=input_data, input_pvs=pvs)
-    
-    DTF_MASS = DecayTreeFitter(
-        name='DTF_{hash}', input_particles=input_data)
-    
-
-    basic_variables = make_basic_variables(options, pvs, input_data) +\
-                    make_basic_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_MASS, pv_constraint=True) 
-    composite_variables = make_composite_variables(options, pvs, input_data) +\
-                    make_composite_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_MASS, pv_constraint=True, four_body=True) 
-
-    variables = {
-        "B0": composite_variables,
-        "p1": basic_variables,
-        "pm1": basic_variables,
-        "p2": basic_variables,
-        "pm2": basic_variables,
-    }
-
-    mytuple = Funtuple(
-        name=name,
-        tuple_name="DecayTree",
-        fields=branches,
-        variables=variables,
-        event_variables=make_hlt2_event_variables(options, pvs, rec_summary),
-        inputs=input_data)
-
-    return [myfilter, mytuple]
-
-
-def maketuple_Bs0ToPPbarPPbar(options, pvs, rec_summary):
-    name = "Bs0ToPPbarPPbar"
-    turbo_line = "Hlt2BnoC_BdsToPpPmPpPm"
-
-    input_data = get_particles(f"/Event/HLT2/{turbo_line}/Particles")
-    myfilter = create_lines_filter(
-        f"LineFilter_{turbo_line}_{{hash}}",
-        [turbo_line],
-    )
-
-    branches = {
-        "B0": "[B0 -> p+ p~- p+ p~-]CC",
-        "p1": "[B0 -> ^p+ p~- p+ p~-]CC",
-        "pm1": "[B0 -> p+ ^p~- p+ p~-]CC",
-        "p2": "[B0 ->  p+ p~- ^p+ p~-]CC",
-        "pm2": "[B0 -> p+ p~- p+ ^p~-]CC",
-    }
-
-
-    DTF_MASS_PV = DecayTreeFitter(
-        name='DTF_{hash}', input_particles=input_data, input_pvs=pvs)
-    
-    DTF_MASS = DecayTreeFitter(
-        name='DTF_{hash}', input_particles=input_data)
-    
-
-    basic_variables = make_basic_variables(options, pvs, input_data) +\
-                    make_basic_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_MASS, pv_constraint=True) 
-    composite_variables = make_composite_variables(options, pvs, input_data) +\
-                    make_composite_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_MASS, pv_constraint=True, four_body=True) 
-    variables = {
-        "B0": composite_variables,
-        "p1": basic_variables,
-        "pm1": basic_variables,
-        "p2": basic_variables,
-        "pm2": basic_variables,
-    }
-
-    mytuple = Funtuple(
-        name=name,
-        tuple_name="DecayTree",
-        fields=branches,
-        variables=variables,
-        event_variables=make_hlt2_event_variables(options, pvs, rec_summary),
-        inputs=input_data)
-
-    return [myfilter, mytuple]
diff --git a/Liv_PPBarLines/options/tupling.py b/Liv_PPBarLines/options/tupling.py
deleted file mode 100644
index a33f18e252..0000000000
--- a/Liv_PPBarLines/options/tupling.py
+++ /dev/null
@@ -1,701 +0,0 @@
-###############################################################################
-# (c) Copyright 2022 CERN for the benefit of the LHCb Collaboration           #
-#                                                                             #
-# This software is distributed under the terms of the GNU General Public      #
-# Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING".   #
-#                                                                             #
-# In applying this licence, CERN does not waive the privileges and immunities #
-# granted to it by virtue of its status as an Intergovernmental Organization  #
-# or submit itself to any jurisdiction.                                       #
-###############################################################################
-"""Common configuration functions
-
-"""
-
-import Functors as F
-from Functors.math import log
-
-from FunTuple import FunctorCollection
-from FunTuple.functorcollections import (
-    MCHierarchy,
-    MCPromptDecay,
-    Kinematics,
-    SelectionInfo,
-    HltTisTos,
-    MCVertexInfo,
-    MCKinematics,
-    ParticleID, #wrong variables PID_PI = 0, PROBNN_D = nan
-    EventInfo,
-    ParticleIsolation,
-    MCPrimaries,
-)
-
-from DaVinciMCTools import MCTruthAndBkgCat
-from PyConf.Algorithms import ParticleToSubcombinationsAlg
-from DecayTreeFitter import DecayTreeFitter
-
-Hlt1_global_lines = [
-    "Hlt1GECPassthroughDecision",
-    "Hlt1BeamGasDecision",
-    "Hlt1PassthroughDecision",
-    "Hlt1NoBeamDecision",
-    "Hlt1BeamOneDecision",
-    "Hlt1BeamTwoDecision",
-    "Hlt1BothBeamsDecision",
-    "Hlt1ODINLumiDecision",
-    "Hlt1ODINVeloOpenDecision",
-    "Hlt1ODINNoBiasDecision",
-    "Hlt1VeloMicroBiasDecision",
-    "Hlt1RICH1AlignmentDecision",
-    "Hlt1RICH2AlignmentDecision",
-    "Hlt1BeamGasDecision",
-    "Hlt1L02PPiDecision",
-    "Hlt1LowMassNoipDielectron_massSlice1_promptDecision",
-    "Hlt1LowMassNoipDielectron_SS_massSlice1_promptDecision",
-    "Hlt1LowMassNoipDielectron_massSlice2_promptDecision",
-    "Hlt1LowMassNoipDielectron_SS_massSlice2_promptDecision",
-    "Hlt1LowMassNoipDielectron_massSlice3_promptDecision",
-    "Hlt1LowMassNoipDielectron_SS_massSlice3_promptDecision",
-    "Hlt1LowMassNoipDielectron_massSlice4_promptDecision",
-    "Hlt1LowMassNoipDielectron_SS_massSlice4_promptDecision",
-    "Hlt1LowMassNoipDielectron_massSlice1_displacedDecision",
-    "Hlt1LowMassNoipDielectron_SS_massSlice1_displacedDecision",
-    "Hlt1LowMassNoipDielectron_massSlice2_displacedDecision",
-    "Hlt1LowMassNoipDielectron_SS_massSlice2_displacedDecision",
-    "Hlt1LowMassNoipDielectron_massSlice3_displacedDecision",
-    "Hlt1LowMassNoipDielectron_SS_massSlice3_displacedDecision",
-    "Hlt1LowMassNoipDielectron_massSlice4_displacedDecision",
-    "Hlt1LowMassNoipDielectron_SS_massSlice4_displacedDecision",
-]
-Hlt1_1track_lines = [
-    "Hlt1TrackMVADecision",
-    "Hlt1LowPtMuonDecision",
-    "Hlt1SingleHighPtMuonDecision",
-    "Hlt1SingleHighPtMuonNoMuIDDecision",
-    "Hlt1TrackMuonMVADecision",
-    "Hlt1OneMuonTrackLineDecision",
-    "Hlt1TrackElectronMVADecision",
-    "Hlt1SingleHighPtElectronDecision",
-    "Hlt1SingleHighEtDecision",
-]
-Hlt1_lines = Hlt1_1track_lines+[
-    "Hlt1TwoTrackMVACharmXSecDecision",
-    "Hlt1TwoTrackMVADecision",
-    "Hlt1TwoTrackKsDecision",
-    "Hlt1D2KPiDecision",
-    "Hlt1D2KKDecision",
-    "Hlt1D2PiPiDecision",
-    "Hlt1KsToPiPiDecision",
-    "Hlt1LowPtDiMuonDecision",#removed
-    "Hlt1DiMuonNoIPDecision",
-    "Hlt1DiMuonNoIP_ssDecision",
-    "Hlt1DiMuonHighMassDecision",
-    "Hlt1DiMuonLowMassDecision",#replaced by Hlt1DiMuonDisplacedDecision
-    "Hlt1DiMuonSoftDecision",
-    "Hlt1DiMuonDisplacedDecision",
-    "Hlt1TwoKsDecision",
-    "Hlt1D2KPiAlignmentDecision",
-    "Hlt1DiMuonHighMassAlignmentDecision",
-    "Hlt1DisplacedDiMuonAlignmentDecision",
-    "Hlt1DisplacedDielectronDecision",
-    "Hlt1DisplacedLeptonsDecision",#removed
-]
-
-
-Hlt2_lines = [
-    "Hlt2BnoC_BdsToPpPmPpPm",
-    "Hlt2BnoC_BdsToPpPm",
-] 
-
-def make_composite_variables(options, pvs, data, add_truth=True):
-    if not options.simulation:
-        add_truth = False
-    variables = (
-       FunctorCollection(
-           {
-               "CHARGE": F.CHARGE,
-               "MAXPT": F.MAX(F.PT),
-               "MINPT": F.MIN(F.PT),
-               "SUMPT": F.SUM(F.PT),
-               "MAXP": F.MAX(F.P),
-               "MINP": F.MIN(F.P),
-               "BPVDIRA": F.BPVDIRA(pvs),
-               "VCHI2DOF": F.CHI2DOF, #CHI2VXNDOF
-               "VCHI2": F.CHI2,
-               "BPVFDCHI2": F.BPVFDCHI2(pvs),
-               "BPVFD": F.BPVFD(pvs),
-               "BPVFDIR": F.BPVFDIR(pvs),
-               "BPVFDVEC": F.BPVFDVEC(pvs),
-               "BPVVDRHO": F.BPVVDRHO(pvs),
-               "BPVVDZ": F.BPVVDZ(pvs),
-               "BPVIPCHI2": F.BPVIPCHI2(pvs),
-               "BPVIP": F.BPVIP(pvs),
-               "LOGBPVIPCHI2": log(F.BPVIPCHI2(pvs)),
-               "BPVLTIME": F.BPVLTIME(pvs),
-               "MAXBPVIPCHI2": F.MAX(F.BPVIPCHI2(pvs)), #MAX_
-               "MINBPVIPCHI2": F.MIN(F.BPVIPCHI2(pvs)),
-               "MAXBPVIP": F.MAX(F.BPVIP(pvs)),
-               "MINBPVIP": F.MIN(F.BPVIP(pvs)),
-               "MAXDOCACHI2": F.MAXDOCACHI2,
-               "MAXDOCA": F.MAXDOCA,
-               "MAXSDOCACHI2": F.MAXSDOCACHI2,
-               "MAXSDOCA": F.MAXSDOCA,
-               "M12": F.SUBCOMB(Functor=F.MASS, Indices=(1, 2)),
-               "SDOCA12"     : F.SDOCA(Child1=1,Child2=2),
-               "SDOCACHI212" : F.SDOCACHI2(Child1=1,Child2=2),
-               "DOCA12"      : F.DOCA(Child1=1,Child2=2),
-               "DOCACHI212"  : F.DOCACHI2(Child1=1,Child2=2),
-               "COS12": F.ALV(1, 2),
-               "ETA": F.ETA,
-               "PHI": F.PHI,
-               "END_VX": F.END_VX, #END_
-               "END_VY": F.END_VY,
-               "END_VZ": F.END_VZ,
-               "BPVX": F.BPVX(pvs),
-               "BPVY": F.BPVY(pvs),
-               "BPVZ": F.BPVZ(pvs),
-               "ALLPVFD"     : F.ALLPV_FD(pvs),
-               "ALLPVIP"     : F.ALLPV_IP(pvs),
-               "OBJECT_KEY": F.OBJECT_KEY,
-           }
-       )
-       + Kinematics()
-        #+ ParticleID(extra_info=True) #only for daughters
-    )
-
-    variables += HltTisTos(
-        selection_type="Hlt1", trigger_lines=Hlt1_lines, data=data
-    )
-
-    if add_truth:
-        variables = add_truth_matching_functors(
-            options,
-            variables,
-            data,
-            hierarchy=True,
-            kinematics=True,
-            vertex_info=True,
-            bkgcat=True,
-        )
-
-    return variables
-
-def make_tistoscombinations(options, pvs, data):
-    algo_output = ParticleToSubcombinationsAlg( Input=data )
-    relations = algo_output.OutputRelations
-
-    tistos_variables_extra = HltTisTos(
-        selection_type="Hlt1", trigger_lines=["Hlt1TwoTrackMVADecision"], data=algo_output.OutputParticles
-    )
-    tistos_combinations = {}
-    for k,v in tistos_variables_extra.get_thor_functors().items():
-        tistos_combinations[k + "_SUBCOMB" ] = F.MAP_INPUT_ARRAY( v, relations )
-    tistos_combinations = FunctorCollection( tistos_combinations )
-
-    return tistos_combinations
-
-def make_composite_variables_3body(options, pvs, data, add_truth=True):
-
-    variables = (
-        FunctorCollection(
-            {
-                #13
-                "M13": F.SUBCOMB(Functor=F.MASS, Indices=(1, 3)),
-                "SDOCA13"     : F.SDOCA(Child1=1,Child2=3),
-                "SDOCACHI213" : F.SDOCACHI2(Child1=1,Child2=3),
-                "DOCA13"      : F.DOCA(Child1=1,Child2=3),
-                "DOCACHI213"  : F.DOCACHI2(Child1=1,Child2=3),
-                "COS13": F.ALV(1, 3),
-                #23
-                "M23": F.SUBCOMB(Functor=F.MASS, Indices=(2, 3)),
-                "SDOCA23"     : F.SDOCA(Child1=2,Child2=3),
-                "SDOCACHI223" : F.SDOCACHI2(Child1=2,Child2=3),
-                "DOCA23"      : F.DOCA(Child1=2,Child2=3),
-                "DOCACHI223"  : F.DOCACHI2(Child1=2,Child2=3),
-                "COS23": F.ALV(2, 3),
-            }
-        )
-    )
-    return make_composite_variables(options, pvs, data, add_truth)+make_tistoscombinations(options, pvs, data)+variables
-
-def make_composite_variables_4body(options, pvs, data, add_truth=True):
-
-    variables = (
-        FunctorCollection(
-            {
-                #14
-                "M14": F.SUBCOMB(Functor=F.MASS, Indices=(1, 4)),
-                "SDOCA14"     : F.SDOCA(Child1=1,Child2=4),
-                "SDOCACHI214" : F.SDOCACHI2(Child1=1,Child2=4),
-                "DOCA14"      : F.DOCA(Child1=1,Child2=4),
-                "DOCACHI214"  : F.DOCACHI2(Child1=1,Child2=4),
-                "COS14": F.ALV(1, 4),
-                #24
-                "M24": F.SUBCOMB(Functor=F.MASS, Indices=(2, 4)),
-                "SDOCA24"     : F.SDOCA(Child1=2,Child2=4),
-                "SDOCACHI224" : F.SDOCACHI2(Child1=2,Child2=4),
-                "DOCA24"      : F.DOCA(Child1=2,Child2=4),
-                "DOCACHI224"  : F.DOCACHI2(Child1=2,Child2=4),
-                "COS24": F.ALV(2, 4),
-                #34
-                "M34": F.SUBCOMB(Functor=F.MASS, Indices=(3, 4)),
-                "SDOCA34"     : F.SDOCA(Child1=3,Child2=4),
-                "SDOCACHI234" : F.SDOCACHI2(Child1=3,Child2=4),
-                "DOCA34"      : F.DOCA(Child1=3,Child2=4),
-                "DOCACHI234"  : F.DOCACHI2(Child1=3,Child2=4),
-                "COS34": F.ALV(3, 4),
-            }
-        )
-    )
-    return make_composite_variables_3body(options,pvs, data, add_truth)+variables
-
-def make_DeltaM_variable(options):
-    return FunctorCollection({"DM": F.MASS - F.CHILD(1, F.MASS)})
-
-def make_basic_variables(options, pvs, data, add_truth=True):
-    if not options.simulation:
-        add_truth = False
-    variables = (
-       FunctorCollection(
-           { 
-               "CHARGE": F.CHARGE,
-               "TRCHI2DOF": F.CHI2DOF @ F.TRACK,
-               "TRCHI2": F.CHI2 @ F.TRACK,
-               "ETA": F.ETA,
-               "PHI": F.PHI,
-               "TRGHOSTPROB": F.GHOSTPROB,
-               "BPVIPCHI2": F.BPVIPCHI2(pvs),
-               "BPVIP": F.BPVIP(pvs),
-               #"BPVETA": F.BPVETA(pvs),
-               #"BPVDLS": F.BPVDLS(pvs),
-               "BPVX": F.BPVX(pvs),
-               "BPVY": F.BPVY(pvs),
-               "BPVZ": F.BPVZ(pvs),
-               "TX"          : F.TX,
-               "TY"          : F.TY,
-               "MINIPCHI2"   : F.MINIPCHI2(pvs),
-               "MINIP"       : F.MINIP(pvs),
-               "KEY"         : F.VALUE_OR(-1) @ F.OBJECT_KEY @ F.TRACK,
-               "CTB"         : F.POSITION @ F.CLOSESTTOBEAM @ F.TRACK,
-               "ISMUON"      : F.ISMUON,
-               "TRACKPT": F.TRACK_PT,
-               "TRACKHISTORY": F.VALUE_OR(-1) @ F.TRACKHISTORY @ F.TRACK,
-               "QOVERP": F.QOVERP @ F.TRACK,
-               "NDOF": F.VALUE_OR(-1) @ F.NDOF @ F.TRACK,
-               "NFTHITS": F.VALUE_OR(-1) @ F.NFTHITS @ F.TRACK,
-               "NHITS": F.VALUE_OR(-1) @ F.NHITS @ F.TRACK,
-               "NUTHITS": F.VALUE_OR(-1) @ F.NUTHITS @ F.TRACK,
-               "NVPHITS": F.VALUE_OR(-1) @ F.NVPHITS @ F.TRACK,
-               "TRACKHASVELO": F.VALUE_OR(-1) @ F.TRACKHASVELO @ F.TRACK,
-               "TRACKHASUT": F.VALUE_OR(-1) @ F.TRACKHASUT @ F.TRACK,
-               "OBJECT_KEY": F.OBJECT_KEY,
-               "HASBREM": F.HASBREM,
-               "BREMENERGY": F.BREMENERGY,
-               "BREMBENDCORR": F.BREMBENDCORR,
-           }
-       )
-       + Kinematics()
-       + ParticleID(extra_info=True)
-    )
-
-    variables += HltTisTos(
-        selection_type="Hlt1", trigger_lines=Hlt1_1track_lines, data=data
-    )
-
-    if add_truth:
-        variables = add_truth_matching_functors(
-            options,
-            variables,
-            data,
-            hierarchy=True,
-            kinematics=True,
-            vertex_info=True,
-            bkgcat=False,
-        )
-
-    return variables
-
-def make_hlt2_event_variables(options, pvs, rec_summary):
-    # define event level variables
-    evt_variables = EventInfo()
-    evt_variables += SelectionInfo(selection_type="Hlt2", trigger_lines=Hlt2_lines)
-    evt_variables += SelectionInfo(selection_type="Hlt1", trigger_lines=Hlt1_1track_lines)
-    evt_variables += FunctorCollection(
-        {
-            "ALLPVX": F.ALLPVX(pvs),
-            "ALLPVY": F.ALLPVY(pvs),
-            "ALLPVZ": F.ALLPVZ(pvs),
-            "nPVs": F.SIZE(pvs),
-            "nTracks": F.VALUE_OR(-1) @ F.RECSUMMARY_INFO(rec_summary, "nTracks"),
-            "nLongTracks": F.VALUE_OR(-1) @ F.RECSUMMARY_INFO(rec_summary, "nLongTracks"),
-            "nMuonTracks": F.VALUE_OR(-1) @ F.RECSUMMARY_INFO(rec_summary, "nMuonTracks"),
-            "nFTClusters": F.VALUE_OR(-1) @ F.RECSUMMARY_INFO(rec_summary, "nFTClusters"),
-            "nVPClusters": F.VALUE_OR(-1) @ F.RECSUMMARY_INFO(rec_summary, "nVPClusters"),
-            "nUTClusters": F.VALUE_OR(-1) @ F.RECSUMMARY_INFO(rec_summary, "nUTClusters"),
-            "nSPDhits": F.VALUE_OR(-1) @ F.RECSUMMARY_INFO(rec_summary, "nSPDhits"),
-            "nEcalClusters": F.VALUE_OR(-1) @ F.RECSUMMARY_INFO(rec_summary, "nEcalClusters"),
-            "nEcalClusters": F.VALUE_OR(-1) @ F.RECSUMMARY_INFO(rec_summary, "nEcalClusters"),
-            "eCalTot": F.VALUE_OR(-1) @ F.RECSUMMARY_INFO(rec_summary, "eCalTot"),
-            "hCalTot": F.VALUE_OR(-1) @ F.RECSUMMARY_INFO(rec_summary, "hCalTot"),
-            "nRich1Hits": F.VALUE_OR(-1) @ F.RECSUMMARY_INFO(rec_summary, "nRich1Hits"),
-            "nRich2Hits": F.VALUE_OR(-1) @ F.RECSUMMARY_INFO(rec_summary, "nRich2Hits"),
-        }
-    )
-    return evt_variables
-
-
-def make_unpack_only_mc_variables():
-    MC_MOTHER_ID = lambda gen: F.VALUE_OR(0) @ F.MC_MOTHER(gen, F.PARTICLE_ID)
-    MC_MOTHER_KEY = lambda gen: F.VALUE_OR(-1) @ F.MC_MOTHER(gen, F.OBJECT_KEY)
-    return (
-        FunctorCollection(
-            {
-                "TRUEID": F.PARTICLE_ID,
-                "MC_MOTHER_ID": MC_MOTHER_ID(1),
-                "MC_MOTHER_KEY": MC_MOTHER_KEY(1),
-                "MC_GD_MOTHER_ID": MC_MOTHER_ID(2),
-                "MC_GD_MOTHER_KEY": MC_MOTHER_KEY(2),
-                "MC_GD_GD_MOTHER_ID": MC_MOTHER_ID(3),
-                "MC_GD_GD_MOTHER_KEY": MC_MOTHER_KEY(3),
-                "TRUEORIGIN_VX": F.ORIGIN_VX,
-                "TRUEORIGIN_VY": F.ORIGIN_VY,
-                "TRUEORIGIN_VZ": F.ORIGIN_VZ,
-                "TRUEEND_VX": F.END_VX,
-                "TRUEEND_VY": F.END_VY,
-                "TRUEEND_VZ": F.END_VZ,
-            }
-        )
-        + Kinematics()
-        + MCPromptDecay()
-    )
-
-
-####
-
-def add_truth_matching_functors(
-    options,
-    variables,
-    data,
-    hierarchy=True,
-    kinematics=True,
-    vertex_info=True,
-    bkgcat=False,
-    prompt_info=True,
-):
-    """Add MC truth matching functors to an existing FunctorCollection.
-
-    Args:
-        options (DaVinci.Options): DaVinci options object.
-        variables (FunctorCollection): FunctorCollection to modify
-        data: data handle
-        hierarchy (bool): Add MCHierarchy info (default True)
-        kinematics (bool): Add MCKinematics info (default True)
-        vertex_info (bool): Add MCVertexInfo (default True)
-        bkgcat (bool): Add TRUEKEY and BKGCAT functors - intended for composite particles (default False)
-        prompt_info (bool): Add MCPromptDecay info (default True)
-
-    Returns:
-        FunctorCollection: modified FunctorCollection with truth matched variables.
-    """
-    assert (
-        options.simulation
-    ), "options.simulation is set to False - it doesn't make sense to add truth matching."
-
-    MCTRUTH = MCTruthAndBkgCat(data)
-
-    if bkgcat:
-        variables += FunctorCollection(
-            {
-                # Important note: specify an invalid value for integer functors if there exists no truth info.
-                #                 The invalid value for floating point functors is set to nan.
-                "TRUEKEY": F.VALUE_OR(-1) @ MCTRUTH(F.OBJECT_KEY),
-                "BKGCAT": MCTRUTH.BkgCat,
-            }
-        )
-    if hierarchy:
-        variables += MCHierarchy(mctruth_alg=MCTRUTH)  # likely to change again!!
-    if vertex_info:
-        variables += MCVertexInfo(mctruth_alg=MCTRUTH)  # likely to change again!!
-    if kinematics:
-        variables += MCKinematics(mctruth_alg=MCTRUTH)  # likely to change again!!
-    if prompt_info:
-        variables += MCPromptDecay(mctruth_alg=MCTRUTH)
-
-    return variables
-
-### DTF variables ###
-
-def make_basic_dtf_variables(options, pvs, data, add_truth=True, DTF=None, pv_constraint=False, mass_constraint=False, particle_name=""):
-    if not options.simulation:
-        add_truth = False
-    variables = ( 
-        FunctorCollection(
-            {
-                "ETA": F.ETA,
-                "PHI": F.PHI,
-                "BPVIPCHI2": F.BPVIPCHI2(pvs),
-                "BPVIP": F.BPVIP(pvs),
-                "TX"          : F.TX,
-                "TY"          : F.TY,
-                "MINIPCHI2"   : F.MINIPCHI2(pvs),
-                "MINIP"       : F.MINIP(pvs),
-                
-            }
-        )
-        + Kinematics()
-        #+ ParticleID(extra_info=True)
-    )
-    
-    dtf_extras = FunctorCollection(
-        {
-            "DTF_NITER": DTF.NITER,
-            "DTF_CHI2": DTF.CHI2,
-            "DTF_NDOF": DTF.NDOF,
-            "DTF_CHI2DOF": DTF.CHI2DOF
-        }
-    )
-
-
-
-    if(mass_constraint):
-        if(pv_constraint): # MASS + PV
-            dtf_variables_mass_pv = FunctorCollection({
-                        'DTF_PV_M'+ particle_name + '_' + k: DTF(v)
-                        for k, v in variables.get_thor_functors().items()
-                    })
-            return dtf_variables_mass_pv
-        else: # MASS
-            dtf_variables_mass = FunctorCollection(
-                {'DTF_M'+ particle_name + '_' + k: DTF(v)
-                 for k, v in variables.get_thor_functors().items()})
-        return dtf_variables_mass
-    elif(pv_constraint): # PV
-        dtf_variables_pv = FunctorCollection({
-                'DTF_PV_' + k: DTF(v)
-                for k, v in variables.get_thor_functors().items()
-            })
-        return dtf_variables_pv
-
-    else: # NO MASS/PV
-        dtf_variables = FunctorCollection(
-            {'DTF_' + k: DTF(v)
-             for k, v in variables.get_thor_functors().items()})
-        return dtf_variables
-
-def make_composite_dtf_variables(options, pvs, data, add_truth=True, DTF=None, pv_constraint=False, mass_constraint=False, particle_name="", four_body=False):
-    if not options.simulation:
-        add_truth = False
-    variables = (
-        FunctorCollection(
-            {
-                "MAXPT": F.MAX(F.PT),
-                "MINPT": F.MIN(F.PT),
-                "SUMPT": F.SUM(F.PT),
-                "MAXP": F.MAX(F.P),
-                "MINP": F.MIN(F.P),
-                "BPVDIRA": F.BPVDIRA(pvs),
-                "BPVFDCHI2": F.BPVFDCHI2(pvs),
-                "BPVFD": F.BPVFD(pvs),
-                "BPVVDRHO": F.BPVVDRHO(pvs),
-                "BPVVDZ": F.BPVVDZ(pvs),
-                "BPVIPCHI2": F.BPVIPCHI2(pvs),
-                "BPVIP": F.BPVIP(pvs),
-                "LOGBPVIPCHI2": log(F.BPVIPCHI2(pvs)),
-                "BPVLTIME": F.BPVLTIME(pvs),
-                "MAXBPVIPCHI2": F.MAX(F.BPVIPCHI2(pvs)), #MAX_
-                "MINBPVIPCHI2": F.MIN(F.BPVIPCHI2(pvs)),
-                "MAXBPVIP": F.MAX(F.BPVIP(pvs)),
-                "MINBPVIP": F.MIN(F.BPVIP(pvs)),
-                "M12": F.SUBCOMB(Functor=F.MASS, Indices=(1, 2)),
-                "ETA": F.ETA,
-                "PHI": F.PHI
-            }
-        )
-        + Kinematics()
-        
-        #+ ParticleID(extra_info=True) #only for daughters
-    )
-    
-    if four_body:
-            variables += FunctorCollection(
-                {
-                    "M13": F.SUBCOMB(Functor=F.MASS, Indices=(1, 3)),
-                    "M14": F.SUBCOMB(Functor=F.MASS, Indices=(1, 4)),
-                    "M23": F.SUBCOMB(Functor=F.MASS, Indices=(2, 3)),
-                    "M24": F.SUBCOMB(Functor=F.MASS, Indices=(2, 4)),
-                }
-            )
-            
-    dtf_extras = FunctorCollection(
-        {
-            "DTF_NITER": DTF.NITER,
-            "DTF_CHI2": DTF.CHI2,
-            "DTF_NDOF": DTF.NDOF,
-            "DTF_CHI2DOF": DTF.CHI2DOF
-        }
-    )
-
-
-    if(mass_constraint):
-        if(pv_constraint): # MASS + PV
-            dtf_variables_mass_pv = FunctorCollection({
-                        'DTF_PV_M'+ particle_name + '_' + k: DTF(v)
-                        for k, v in variables.get_thor_functors().items()
-                    })
-            return dtf_variables_mass_pv + dtf_extras
-        else: # MASS
-            dtf_variables_mass = FunctorCollection(
-                {'DTF_M'+ particle_name + '_' + k: DTF(v)
-                 for k, v in variables.get_thor_functors().items()})
-        return dtf_variables_mass + dtf_extras
-
-    elif(pv_constraint): # PV
-        dtf_variables_pv = FunctorCollection({
-                'DTF_PV_' + k: DTF(v)
-                for k, v in variables.get_thor_functors().items()
-            })
-        return dtf_variables_pv + dtf_extras
-
-    else: # NO MASS/PV
-        dtf_variables = FunctorCollection(
-            {'DTF_' + k: DTF(v)
-             for k, v in variables.get_thor_functors().items()})
-        return dtf_variables + dtf_extras
-
-def make_MC_basic_variables():
-    variables = (
-        FunctorCollection(
-            {
-                "OBJECT_KEY": F.OBJECT_KEY,
-                "ETA": F.ETA,
-                "PHI": F.PHI,
-                "ORIGIN_VX": F.ORIGIN_VX,
-                "ORIGIN_VY": F.ORIGIN_VY,
-                "ORIGIN_VZ": F.ORIGIN_VZ,
-                "FOURMOMENTUM": F.FOURMOMENTUM,
-            }
-        )
-        + Kinematics()
-    )
-
-    return variables
-
-def make_MC_composite_variables():
-    variables = (
-        FunctorCollection(
-            {
-                "END_VX": F.END_VX, #END_
-                "END_VY": F.END_VY,
-                "END_VZ": F.END_VZ,
-                "LTIME": F.MC_LIFETIME,
-                "OBJECT_KEY": F.OBJECT_KEY,
-                "ETA": F.ETA,
-                "PHI": F.PHI,
-                "ORIGIN_VX": F.ORIGIN_VX,
-                "ORIGIN_VY": F.ORIGIN_VY,
-                "ORIGIN_VZ": F.ORIGIN_VZ,
-                "FOURMOMENTUM": F.FOURMOMENTUM,
-            }
-        )
-        + Kinematics()
-    )
-
-    return variables
-
-def make_MC_event_variables(mc_header):
-    # define event level variables
-    evt_variables = EventInfo()
-    evt_variables += MCPrimaries(mc_header=mc_header)
-
-    return evt_variables
-
-def make_top_isolation_variables(hlt2_line, input_data, locations = ["LongTrackIso","NeutralIso"]):
-    from PyConf.reading import get_particles
-    from IsolationTools import VertexAndConeIsolation
-
-    possible_charm_locations = ["LongTrackIso", "TTrackIso", "DownstreamTrackIso", "UpstreamTrackIso", "NeutralIso", "PizIso"]
-    coneangles = [0.25,0.5,1.,1.5,2.]
-    
-    count = 0
-    for location in locations:
-        extra_particles = get_particles(f"/Event/HLT2/{hlt2_line}/{location}/Particles")
-
-        for coneangle in coneangles:
-            top_RTAlg = VertexAndConeIsolation(
-                name=location+"_"+str(coneangle),
-                reference_particles=input_data,
-                related_particles=extra_particles,
-                cut=F.DR2<coneangle)
-            
-            if count == 0:
-                top_iso_variables = ParticleIsolation(isolation_alg=top_RTAlg,array_indx_name='indx')
-            else:
-                top_iso_variables += ParticleIsolation(isolation_alg=top_RTAlg,array_indx_name='indx')
-            count += 1
-                
-
-    return top_iso_variables
-
-def make_basic_isolation_variables(hlt2_line, input_data, locations = ["LongTrackIso","NeutralIso"]):
-    from PyConf.reading import get_particles
-    from IsolationTools import VertexAndConeIsolation
-    from PyConf.Algorithms import ThOrParticleSelection
-
-    basic_code = (F.FILTER(F.ALL) @ F.GET_ALL_BASICS())
-    basic_particles = ThOrParticleSelection(InputParticles=input_data, Functor=basic_code).OutputSelection
-
-    possible_charm_locations = ["LongTrackIso", "TTrackIso", "DownstreamTrackIso", "UpstreamTrackIso", "NeutralIso", "PizIso"]
-    coneangles = [0.25,0.5,1.,1.5,2.]
-    
-    count = 0
-    for location in locations:
-        extra_particles = get_particles(f"/Event/HLT2/{hlt2_line}/{location}/Particles")
-
-        for coneangle in coneangles:
-            basic_RTAlg = VertexAndConeIsolation(
-                name=location+"_"+str(coneangle),
-                reference_particles=basic_particles,
-                related_particles=extra_particles,
-                cut=F.DR2<coneangle)
-            
-            if count == 0:
-                basic_iso_variables = ParticleIsolation(isolation_alg=basic_RTAlg,array_indx_name='indx')
-            else:
-                basic_iso_variables += ParticleIsolation(isolation_alg=basic_RTAlg,array_indx_name='indx')
-            count += 1
-                
-
-    return basic_iso_variables
-
-
-def make_intermediate_isolation_variables(hlt2_line, input_data, locations = ["LongTrackIso","NeutralIso"], composite_ID = "J/psi(1S)"):
-    from PyConf.reading import get_particles
-    from IsolationTools import VertexAndConeIsolation
-    from PyConf.Algorithms import ThOrParticleSelection
-
-    intermediate_code = F.FILTER(F.IS_ABS_ID(composite_ID)) @ F.GET_ALL_DESCENDANTS()
-    intermediate_particles = ThOrParticleSelection(InputParticles=input_data, Functor=intermediate_code).OutputSelection
-
-    possible_charm_locations = ["LongTrackIso", "TTrackIso", "DownstreamTrackIso", "UpstreamTrackIso", "NeutralIso", "PizIso"]
-    coneangles = [0.25,0.5,1.,1.5,2.]
-    
-    count = 0
-    for location in locations:
-        extra_particles = get_particles(f"/Event/HLT2/{hlt2_line}/{location}/Particles")
-
-        for coneangle in coneangles:
-            intermediate_RTAlg = VertexAndConeIsolation(
-                name=location+"_"+str(coneangle),
-                reference_particles=intermediate_particles,
-                related_particles=extra_particles,
-                cut=F.DR2<coneangle)
-            
-            if count == 0:
-                intermediate_iso_variables = ParticleIsolation(isolation_alg=intermediate_RTAlg,array_indx_name='indx')
-            else:
-                intermediate_iso_variables += ParticleIsolation(isolation_alg=intermediate_RTAlg,array_indx_name='indx')
-            count += 1
-                
-
-    return intermediate_iso_variables
-
-- 
GitLab


From 8be1e9008658cd106a95bd9a5fadf1db438049b8 Mon Sep 17 00:00:00 2001
From: Juan Leite <jbaptist@lxplus981.cern.ch>
Date: Mon, 29 Apr 2024 18:26:34 +0200
Subject: [PATCH 12/34] three-body combination masses

---
 Liv_Lb0NeutronLines/options/Lb_NeutronLines.py | 10 +++++-----
 Liv_Lb0NeutronLines/options/tupling.py         |  6 ++----
 2 files changed, 7 insertions(+), 9 deletions(-)

diff --git a/Liv_Lb0NeutronLines/options/Lb_NeutronLines.py b/Liv_Lb0NeutronLines/options/Lb_NeutronLines.py
index c072f8e821..87c2756766 100644
--- a/Liv_Lb0NeutronLines/options/Lb_NeutronLines.py
+++ b/Liv_Lb0NeutronLines/options/Lb_NeutronLines.py
@@ -60,8 +60,8 @@ def maketuple_Lb0ToLcpLcnN0(options, pvs, rec_summary):
     
     
     composite_variables_3body = make_composite_variables_3body(options, pvs, input_data) + \
-                    make_composite_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_MASS, pv_constraint=True) + \
-                    make_composite_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_BestPV, pv_constraint=True, mass_constraint=True, particle_name="BpAndLcBestPV")  
+                    make_composite_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_MASS, pv_constraint=True, three_body=True) + \
+                    make_composite_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_BestPV, pv_constraint=True, mass_constraint=True, particle_name="BpAndLcBestPV", three_body=True)  
                    
     variables = {
         "Lb0": composite_variables,
@@ -136,12 +136,12 @@ def maketuple_BpToLcpLcmKp(options, pvs, rec_summary):
     
     
     composite_variables_3body = make_composite_variables_3body(options, pvs, input_data) + \
-                    make_composite_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_MASS, pv_constraint=True) + \
-                    make_composite_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_BestPV, pv_constraint=True, mass_constraint=True, particle_name="BpAndLcBestPV")  
+                    make_composite_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_MASS, pv_constraint=True, three_body=True) + \
+                    make_composite_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_BestPV, pv_constraint=True, mass_constraint=True, particle_name="BpAndLcBestPV", three_body=True)  
                    
 
     variables = {
-        "Bp": composite_variables,
+        "Bp": composite_variables_3body,
         "Lcp": composite_variables_3body,
         "Lcm": composite_variables_3body,
         "pp": basic_variables,
diff --git a/Liv_Lb0NeutronLines/options/tupling.py b/Liv_Lb0NeutronLines/options/tupling.py
index 02d5196172..5ff2857e64 100644
--- a/Liv_Lb0NeutronLines/options/tupling.py
+++ b/Liv_Lb0NeutronLines/options/tupling.py
@@ -489,7 +489,7 @@ def make_basic_dtf_variables(options, pvs, data, add_truth=True, DTF=None, pv_co
              for k, v in variables.get_thor_functors().items()})
         return dtf_variables
 
-def make_composite_dtf_variables(options, pvs, data, add_truth=True, DTF=None, pv_constraint=False, mass_constraint=False, particle_name="", four_body=False):
+def make_composite_dtf_variables(options, pvs, data, add_truth=True, DTF=None, pv_constraint=False, mass_constraint=False, particle_name="", three_body=False):
     if not options.simulation:
         add_truth = False
     variables = (
@@ -523,13 +523,11 @@ def make_composite_dtf_variables(options, pvs, data, add_truth=True, DTF=None, p
         #+ ParticleID(extra_info=True) #only for daughters
     )
     
-    if four_body:
+    if three_body:
             variables += FunctorCollection(
                 {
                     "M13": F.SUBCOMB(Functor=F.MASS, Indices=(1, 3)),
-                    "M14": F.SUBCOMB(Functor=F.MASS, Indices=(1, 4)),
                     "M23": F.SUBCOMB(Functor=F.MASS, Indices=(2, 3)),
-                    "M24": F.SUBCOMB(Functor=F.MASS, Indices=(2, 4)),
                 }
             )
             
-- 
GitLab


From 70dfab169e64ecc36816019de83780650004c30b Mon Sep 17 00:00:00 2001
From: Juan Leite <jbaptist@lxplus973.cern.ch>
Date: Wed, 8 May 2024 12:31:08 +0200
Subject: [PATCH 13/34] save commit

---
 Liv_Lb0NeutronLines/Spruce.py                 | 36 ++++++++++++-----
 Liv_Lb0NeutronLines/hlt1.py                   | 34 +++-------------
 Liv_Lb0NeutronLines/hlt2.py                   | 39 ++++++++++++++-----
 Liv_Lb0NeutronLines/info.yaml                 |  4 +-
 .../options/Lb_NeutronLines.py                | 18 ++++-----
 Liv_Lb0NeutronLines/options/tupling.py        |  2 +
 6 files changed, 75 insertions(+), 58 deletions(-)

diff --git a/Liv_Lb0NeutronLines/Spruce.py b/Liv_Lb0NeutronLines/Spruce.py
index 57ccd8fd33..80ff745cc8 100644
--- a/Liv_Lb0NeutronLines/Spruce.py
+++ b/Liv_Lb0NeutronLines/Spruce.py
@@ -15,10 +15,12 @@ from RecoConf.hlt2_tracking import (
     make_PrKalmanFilter_Velo_tracks,
     make_PrKalmanFilter_Seed_tracks,
 )
+from PyConf.reading import get_particles, upfront_reconstruction as upfront_spruce
 from RecoConf.decoders import default_VeloCluster_source
 from RecoConf.event_filters import require_gec
-from Moore.streams import Stream, Streams
+from Moore.streams import DETECTORS, Stream, Streams
 import sys
+from Moore.lines import SpruceLine
 
 
 from Hlt2Conf.lines.b_to_open_charm import sprucing_lines
@@ -32,19 +34,35 @@ public_tools = [
     stateProvider_with_simplified_geom(),
 ]
 
-def pass_through_line(name="Hlt2MCPassThroughLine"):
-    """Return a HLT2 line that performs no selection but runs and persists the reconstruction
+def pass_through_line(name="SprucePassThrough"):
+    """Return a Spruce line that performs no selection but runs and persists the reconstruction
     """
-    return Hlt2Line(name=name, prescale=1, algs=[], persistreco=True)
+    return SpruceLine(
+        name=name, prescale=1, algs=upfront_spruce(), persistreco=True)
+
+
+def make_full_streams():
+    lines = [builder() for builder in sprucing_lines.values()]
+    lines += [pass_through_line(name="SprucePassThrough__exclusive")]
+    streams = [Stream(lines=lines, detectors=[])]
+    return Streams(streams=streams)
 
 
-def _make_lines():
-    mylines = [builder() for builder in sprucing_lines.values()]
-    return mylines
 
 def alg_config(options: Options):
+    public_tools = [stateProvider_with_simplified_geom()]
     with reconstruction.bind(from_file=True, spruce=True):
-        config = run_moore(options, _make_lines, public_tools)
-    return config
+        return run_moore(options, make_full_streams, public_tools=public_tools)
+
+
+
+# def _make_lines():
+#     mylines = [builder() for builder in sprucing_lines.values()]
+#     return mylines
+
+# def alg_config(options: Options):
+#     with reconstruction.bind(from_file=True, spruce=True):
+#         config = run_moore(options, _make_lines, public_tools)
+#     return config
 
 
diff --git a/Liv_Lb0NeutronLines/hlt1.py b/Liv_Lb0NeutronLines/hlt1.py
index d987098959..7d04cf6537 100644
--- a/Liv_Lb0NeutronLines/hlt1.py
+++ b/Liv_Lb0NeutronLines/hlt1.py
@@ -1,33 +1,11 @@
-###############################################################################
-# (c) Copyright 2023 CERN for the benefit of the LHCb Collaboration           #
-#                                                                             #
-# This software is distributed under the terms of the GNU General Public      #
-# Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING".   #
-#                                                                             #
-# In applying this licence, CERN does not waive the privileges and immunities #
-# granted to it by virtue of its status as an Intergovernmental Organization  #
-# or submit itself to any jurisdiction.                                       #
-###############################################################################
 """
-Configures running HLT1 via Moore.
+Stolen verbatim from Hlt/Hlt1Conf/options/hlt1_pp_expected_24_without_UT.py from v55r7
 """
-
 from Moore import Options
-from Moore.config import allen_control_flow
-from RecoConf.hlt1_allen import allen_gaudi_config, get_allen_line_names
-from PyConf.application import configure_input, configure
-
-def alg_config(options: Options):
-    """
-    Configures algorithm running of HLT1 via Moore to be passed to Analysis Productions.
-    """
+from Moore.config import run_allen
+from RecoConf.hlt1_allen import allen_gaudi_config as allen_sequence
 
-    config = configure_input(options)
-    with allen_gaudi_config.bind(sequence="hlt1_pp_matching_no_ut_1000KHz"):
-    #with allen_gaudi_config.bind(sequence="hlt1_pp_forward_then_matching_no_ut"):
-        line_names = get_allen_line_names()
-        allen_node = allen_control_flow(options)
-        config.update(configure(options, allen_node))
-
-    return config
 
+def alg_config(options: Options):
+    with allen_sequence.bind(sequence="hlt1_pp_matching_no_ut_1000KHz"):
+        return run_allen(options)
diff --git a/Liv_Lb0NeutronLines/hlt2.py b/Liv_Lb0NeutronLines/hlt2.py
index 3b7f120900..393ce2f846 100644
--- a/Liv_Lb0NeutronLines/hlt2.py
+++ b/Liv_Lb0NeutronLines/hlt2.py
@@ -15,13 +15,15 @@ from RecoConf.hlt2_tracking import (
     make_PrKalmanFilter_Velo_tracks,
     make_PrKalmanFilter_Seed_tracks,
 )
+from RecoConf.protoparticles import make_charged_protoparticles
+from Hlt2Conf.settings.defaults import get_default_hlt1_filter_code_for_hlt2
 from RecoConf.decoders import default_VeloCluster_source
 from RecoConf.event_filters import require_gec
-from Moore.streams import Stream, Streams
+from Moore.streams import Stream, Streams, DETECTORS
 import sys
 
 
-from Hlt2Conf.lines.topological_b import threebody_line, twobody_line
+from Hlt2Conf.lines.topological_b import all_lines as topo_lines
 
 
 
@@ -37,22 +39,39 @@ def pass_through_line(name="Hlt2MCPassThroughLine"):
     """
     return Hlt2Line(name=name, prescale=1, algs=[], persistreco=True)
 
+def _make_streams():
+    """Use some QEE lines for the sake of example."""
+    lines = [
+        builder(persistreco=True) for line_dict in [topo_lines]
+        for builder in line_dict.values()
+    ]
+    lines += [pass_through_line()]
 
-def _make_lines():
-    #mylines = [builder() for builder in all_lines.values()],
-    mylines = [twobody_line(persistreco=True), threebody_line(persistreco=True)]
-    return mylines
+    streams = [
+        Stream(lines=lines, routing_bit=98, detectors=DETECTORS)
+    ]
+    return Streams(streams=streams)
 
 
-def alg_config(options: Options):
+# def _make_lines():
+#     #mylines = [builder() for builder in all_lines.values()],
+#     mylines = [twobody_line(persistreco=True), threebody_line(persistreco=True)]
+#     return mylines
+
+
+def make_streams(real_make_streams=_make_streams):
     with reconstruction.bind(from_file=False), hlt2_reconstruction.bind(make_reconstruction=make_light_reco_pr_kf_without_UT),\
         require_gec.bind(skipUT=True),\
+        make_charged_protoparticles.bind(fill_probnn_defaults=True),\
         default_VeloCluster_source.bind(bank_type="VPRetinaCluster"),\
         make_TrackBestTrackCreator_tracks.bind(max_ghost_prob=0.7, max_chi2ndof=sys.float_info.max),\
         make_PrKalmanFilter_Velo_tracks.bind(max_chi2ndof=5.),\
         make_PrKalmanFilter_noUT_tracks.bind(max_chi2ndof=4.),\
-        make_PrKalmanFilter_Seed_tracks.bind(max_chi2ndof=6.):
-        config = run_moore(options, _make_lines, public_tools=public_tools)
-        return config
+        make_PrKalmanFilter_Seed_tracks.bind(max_chi2ndof=6.),\
+        get_default_hlt1_filter_code_for_hlt2.bind(code=r"Hlt1(?!PassthroughLargeEvent).*Decision"):
+        return real_make_streams()
 
+def alg_config(options: Options):
+    config = run_moore(options, make_streams=make_streams, public_tools=[])
+    return config
 
diff --git a/Liv_Lb0NeutronLines/info.yaml b/Liv_Lb0NeutronLines/info.yaml
index 2a2ccb3db0..a4bd5ca39b 100644
--- a/Liv_Lb0NeutronLines/info.yaml
+++ b/Liv_Lb0NeutronLines/info.yaml
@@ -44,7 +44,7 @@ defaults:
       output_type: ROOT
       simulation: True
       data_type: "Upgrade"
-      evt_max: -1
+      evt_max: 10000
       print_freq: 1000
       scheduler_legacy_mode: False
       compression:
@@ -154,6 +154,6 @@ defaults:
       conditions_version: master
       input_process: "Spruce"
       input_stream: "b2oc"
-      evt_max: -1
+      evt_max: 10000
 {%- endfor %}
 {%- endfor %}
diff --git a/Liv_Lb0NeutronLines/options/Lb_NeutronLines.py b/Liv_Lb0NeutronLines/options/Lb_NeutronLines.py
index 87c2756766..3762c04957 100644
--- a/Liv_Lb0NeutronLines/options/Lb_NeutronLines.py
+++ b/Liv_Lb0NeutronLines/options/Lb_NeutronLines.py
@@ -126,18 +126,18 @@ def maketuple_BpToLcpLcmKp(options, pvs, rec_summary):
 
     #pv_constraint=False, mass_constraint=False, particle_name=""
 
-    basic_variables = make_basic_variables(options, pvs, input_data) + \
-                    make_basic_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_MASS, pv_constraint=True) + \
-                    make_basic_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_BestPV, pv_constraint=True, mass_constraint=True, particle_name="BpAndLcBestPV")
+    basic_variables = make_basic_variables(options, pvs, input_data) 
+                   # make_basic_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_MASS, pv_constraint=True) + \
+                   # make_basic_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_BestPV, pv_constraint=True, mass_constraint=True, particle_name="BpAndLcBestPV")
 
-    composite_variables =  make_composite_variables(options, pvs, input_data) + \
-                    make_composite_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_MASS, pv_constraint=True) + \
-                    make_composite_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_BestPV, pv_constraint=True, mass_constraint=True, particle_name="BpAndLcBestPV")
+    composite_variables =  make_composite_variables(options, pvs, input_data) 
+                   # make_composite_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_MASS, pv_constraint=True) + \
+                   # make_composite_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_BestPV, pv_constraint=True, mass_constraint=True, particle_name="BpAndLcBestPV")
     
     
-    composite_variables_3body = make_composite_variables_3body(options, pvs, input_data) + \
-                    make_composite_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_MASS, pv_constraint=True, three_body=True) + \
-                    make_composite_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_BestPV, pv_constraint=True, mass_constraint=True, particle_name="BpAndLcBestPV", three_body=True)  
+    composite_variables_3body = make_composite_variables_3body(options, pvs, input_data) 
+                    #make_composite_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_MASS, pv_constraint=True, three_body=True) + \
+                    #make_composite_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_BestPV, pv_constraint=True, mass_constraint=True, particle_name="BpAndLcBestPV", three_body=True)  
                    
 
     variables = {
diff --git a/Liv_Lb0NeutronLines/options/tupling.py b/Liv_Lb0NeutronLines/options/tupling.py
index 5ff2857e64..a275923af8 100644
--- a/Liv_Lb0NeutronLines/options/tupling.py
+++ b/Liv_Lb0NeutronLines/options/tupling.py
@@ -135,6 +135,8 @@ def make_composite_variables(options, pvs, data, add_truth=True):
                "BPVVDRHO": F.BPVVDRHO(pvs),
                "BPVVDZ": F.BPVVDZ(pvs),
                "BPVIPCHI2": F.BPVIPCHI2(pvs),
+               "MINIPCHI2"   : F.MINIPCHI2(pvs),
+               "MINIP"       : F.MINIP(pvs),
                "BPVIP": F.BPVIP(pvs),
                "LOGBPVIPCHI2": log(F.BPVIPCHI2(pvs)),
                "BPVLTIME": F.BPVLTIME(pvs),
-- 
GitLab


From a353a5acadb7f0ca90d0eef0490d3360cdd1f6a2 Mon Sep 17 00:00:00 2001
From: Juan Leite <jbaptist@lxplus958.cern.ch>
Date: Fri, 9 Aug 2024 14:00:13 +0200
Subject: [PATCH 14/34] update hlt2 prod

---
 Liv_Lb0NeutronLines/hlt2.py                   |  33 ++---
 Liv_Lb0NeutronLines/info.yaml                 |  61 +++------
 Liv_Lb0NeutronLines/main_Liv_Lb0ToLcpLcmN0.py |   2 +-
 ...eutronLines.py => Lb_NeutronLines_HLT2.py} |  37 +++---
 Liv_Lb0NeutronLines/options/tupling.py        | 117 +++++++++++++-----
 5 files changed, 135 insertions(+), 115 deletions(-)
 rename Liv_Lb0NeutronLines/options/{Lb_NeutronLines.py => Lb_NeutronLines_HLT2.py} (79%)

diff --git a/Liv_Lb0NeutronLines/hlt2.py b/Liv_Lb0NeutronLines/hlt2.py
index 393ce2f846..9c88df33fd 100644
--- a/Liv_Lb0NeutronLines/hlt2.py
+++ b/Liv_Lb0NeutronLines/hlt2.py
@@ -8,7 +8,7 @@ from Moore.lines import Hlt2Line
 from RecoConf.reconstruction_objects import reconstruction as reconstruction
 from Moore import options, run_moore
 from RecoConf.global_tools import stateProvider_with_simplified_geom, trackMasterExtrapolator_with_simplified_geom
-from RecoConf.hlt2_global_reco import reconstruction as hlt2_reconstruction, make_light_reco_pr_kf_without_UT
+from RecoConf.hlt2_global_reco import reconstruction as hlt2_reconstruction, make_light_reco_pr_kf
 from RecoConf.hlt2_tracking import (
     make_TrackBestTrackCreator_tracks,
     make_PrKalmanFilter_noUT_tracks,
@@ -23,7 +23,7 @@ from Moore.streams import Stream, Streams, DETECTORS
 import sys
 
 
-from Hlt2Conf.lines.topological_b import all_lines as topo_lines
+from Hlt2Conf.lines.b_to_open_charm import all_lines 
 
 
 
@@ -39,36 +39,29 @@ def pass_through_line(name="Hlt2MCPassThroughLine"):
     """
     return Hlt2Line(name=name, prescale=1, algs=[], persistreco=True)
 
-def _make_streams():
-    """Use some QEE lines for the sake of example."""
-    lines = [
-        builder(persistreco=True) for line_dict in [topo_lines]
-        for builder in line_dict.values()
-    ]
+def make_streams():
+    lines = [builder() for builder in all_lines.values()]
     lines += [pass_through_line()]
-
     streams = [
-        Stream(lines=lines, routing_bit=98, detectors=DETECTORS)
+        Stream(
+            lines=lines,
+            routing_bit=98,
+            detectors=DETECTORS)
     ]
     return Streams(streams=streams)
 
 
+
 # def _make_lines():
 #     #mylines = [builder() for builder in all_lines.values()],
 #     mylines = [twobody_line(persistreco=True), threebody_line(persistreco=True)]
 #     return mylines
 
 
-def make_streams(real_make_streams=_make_streams):
-    with reconstruction.bind(from_file=False), hlt2_reconstruction.bind(make_reconstruction=make_light_reco_pr_kf_without_UT),\
-        require_gec.bind(skipUT=True),\
-        make_charged_protoparticles.bind(fill_probnn_defaults=True),\
-        default_VeloCluster_source.bind(bank_type="VPRetinaCluster"),\
-        make_TrackBestTrackCreator_tracks.bind(max_ghost_prob=0.7, max_chi2ndof=sys.float_info.max),\
-        make_PrKalmanFilter_Velo_tracks.bind(max_chi2ndof=5.),\
-        make_PrKalmanFilter_noUT_tracks.bind(max_chi2ndof=4.),\
-        make_PrKalmanFilter_Seed_tracks.bind(max_chi2ndof=6.),\
-        get_default_hlt1_filter_code_for_hlt2.bind(code=r"Hlt1(?!PassthroughLargeEvent).*Decision"):
+def make_streams(real_make_streams=make_streams):
+    with reconstruction.bind(from_file=False), \
+        hlt2_reconstruction.bind(make_reconstruction=make_light_reco_pr_kf):
+    
         return real_make_streams()
 
 def alg_config(options: Options):
diff --git a/Liv_Lb0NeutronLines/info.yaml b/Liv_Lb0NeutronLines/info.yaml
index a4bd5ca39b..d42cd6e051 100644
--- a/Liv_Lb0NeutronLines/info.yaml
+++ b/Liv_Lb0NeutronLines/info.yaml
@@ -27,7 +27,7 @@ defaults:
 {%- for sigtype, simul, nu, inptype, evttype in mc_datasets %}
 
 {{sigtype}}_Mag{{p}}_MC_HLT1:
-  application: "Moore/v55r7@x86_64_v3-el9-gcc13+detdesc-opt+g"
+  application: "Moore/v55r10p2@x86_64_v3-el9-gcc13+detdesc-opt+g"
   input: 
     bk_query: /MC/Dev/Beam6800GeV-expected-2024-Mag{{p}}-Nu{{nu}}-25ns-Pythia8/{{simul}}/{{evttype}}/{{inptype}}
     n_test_lfns: 10
@@ -44,8 +44,8 @@ defaults:
       output_type: ROOT
       simulation: True
       data_type: "Upgrade"
-      evt_max: 10000
-      print_freq: 1000
+      evt_max: 1000
+      print_freq: 100
       scheduler_legacy_mode: False
       compression:
         algorithm: ZSTD
@@ -53,10 +53,10 @@ defaults:
         max_buffer_size: 1048576
 
 {{sigtype}}_Mag{{p}}_MC_HLT2:
-  application: "Moore/v55r7@x86_64_v3-el9-gcc13+detdesc-opt+g"
+  application: "Moore/v55r10p2@x86_64_v3-el9-gcc13+detdesc-opt+g"
   input:
     job_name: {{sigtype}}_Mag{{p}}_MC_HLT1
-  output: MC_HLT2.DST
+  output: MC_HLT2_full.DST
   options:
     entrypoint: Liv_Lb0NeutronLines.hlt2:alg_config
     extra_options:
@@ -66,6 +66,7 @@ defaults:
       output_type: "ROOT"
       simulation: True
       input_process: "Hlt2"
+      persistreco_version: 0.0
       data_type: "Upgrade"
       evt_max: -1
       output_manifest_file: "HLT2.tck.json"
@@ -74,37 +75,11 @@ defaults:
         algorithm: ZSTD
         level: 1
         max_buffer_size: 1048576
-
-{{sigtype}}_Mag{{p}}_MC_SPRUCE:
-  application: "Moore/v55r7@x86_64_v3-el9-gcc13+detdesc-opt+g"
-  input:
-    job_name: {{sigtype}}_Mag{{p}}_MC_HLT2
-  output: MC_SPRUCE.DST
-  options:
-    entrypoint: Liv_Lb0NeutronLines.Spruce:alg_config
-    extra_options:
-      conddb_tag: sim-20231017-vc-md100
-      dddb_tag: dddb-20231017
-      input_type: "ROOT"
-      output_type: "ROOT"
-      simulation: True
-      data_type: "Upgrade"
-      input_process: "Hlt2"
-      evt_max: -1
-      input_manifest_file: "HLT2.tck.json"
-      output_manifest_file: "SPRUCE.tck.json"
-      histo_file: "hlt1_topo_spruce_b2oc_histo.root"
-      scheduler_legacy_mode: False
-      compression:
-        algorithm: ZSTD
-        level: 1
-        max_buffer_size: 1048576
- 
-
+        
 {{sigtype}}_Mag{{p}}_MC_Tuple:
-  application: "DaVinci/v64r3@x86_64_v3-el9-gcc13+detdesc-opt+g"
+  application: "DaVinci/v64r8@x86_64_v2-el9-clang16+detdesc-opt"
   input:
-    job_name: {{sigtype}}_Mag{{p}}_MC_SPRUCE
+    job_name: {{sigtype}}_Mag{{p}}_MC_HLT2
   output: MC_{{sigtype}}.ROOT
   options:
     entrypoint: Liv_Lb0NeutronLines.main_Liv_{{sigtype}}:main
@@ -115,14 +90,14 @@ defaults:
       data_type: Upgrade
       conddb_tag: sim-20231017-vc-md100
       dddb_tag: dddb-20231017
-      input_process: "Spruce"
+      input_process: "Hlt2"
       conditions_version: master
       geometry_version: run3/trunk
       lumi: false
       output_type: ROOT
       persistreco_version: 1.0
       write_decoding_keys_to_git: True
-      input_manifest_file: "SPRUCE.tck.json"
+      input_manifest_file: "HLT2.tck.json"
       input_stream: default
 
 {%- endfor %}
@@ -135,13 +110,13 @@ defaults:
 {%- for p in polarities %}
 {%- for sigtype, simul, nu, inptype, evttype in mc_datasets %}
 {{sigtype}}_Mag{{p}}_Data_Tuple:
-  application: "DaVinci/v64r3"
+  application: "DaVinci/v64r8@x86_64_v2-el9-clang16-opt"
   input:
-    bk_query: /LHCb/Collision24/Beam6800GeV-VeloClosed-Mag{{p}}-Excl-UT/Real Data/Sprucing24c1/94000000/B2OC.DST
+    bk_query: /LHCb/Collision24/Beam6800GeV-VeloClosed-MagDown/Real Data/Sprucing24c2/94000000/B2OC.DST
     dq_flags:
       - UNCHECKED
       - OK
-    keep_running: True
+    keep_running: False
   output: RealData_{{sigtype}}.ROOT
   options:
     entrypoint: Liv_Lb0NeutronLines.main_Liv_{{sigtype}}:main
@@ -150,10 +125,12 @@ defaults:
       input_type: ROOT
       simulation: False
       data_type: Upgrade
-      geometry_version: trunk
+      geometry_version: run3/trunk
       conditions_version: master
-      input_process: "Spruce"
+      input_process: "TurboPass"
       input_stream: "b2oc"
-      evt_max: 10000
+      evt_max: 50000
+      print_freq: 1000
+      #first_evt: 1
 {%- endfor %}
 {%- endfor %}
diff --git a/Liv_Lb0NeutronLines/main_Liv_Lb0ToLcpLcmN0.py b/Liv_Lb0NeutronLines/main_Liv_Lb0ToLcpLcmN0.py
index 84eeaaab32..9cf6e161d9 100644
--- a/Liv_Lb0NeutronLines/main_Liv_Lb0ToLcpLcmN0.py
+++ b/Liv_Lb0NeutronLines/main_Liv_Lb0ToLcpLcmN0.py
@@ -9,7 +9,7 @@
 # or submit itself to any jurisdiction.                                       #
 ###############################################################################
 
-from .options.Lb_NeutronLines import *
+from .options.Lb_NeutronLines_HLT2 import *
 
 from DaVinci import Options, make_config
 from PyConf.reading import get_pvs, get_rec_summary
diff --git a/Liv_Lb0NeutronLines/options/Lb_NeutronLines.py b/Liv_Lb0NeutronLines/options/Lb_NeutronLines_HLT2.py
similarity index 79%
rename from Liv_Lb0NeutronLines/options/Lb_NeutronLines.py
rename to Liv_Lb0NeutronLines/options/Lb_NeutronLines_HLT2.py
index 3762c04957..34e2345678 100644
--- a/Liv_Lb0NeutronLines/options/Lb_NeutronLines.py
+++ b/Liv_Lb0NeutronLines/options/Lb_NeutronLines_HLT2.py
@@ -14,8 +14,8 @@ from DecayTreeFitter import DecayTreeFitter
 def maketuple_Lb0ToLcpLcnN0(options, pvs, rec_summary):
 
     name = "Lb0ToLcpLcmN0"
-    turbo_line = "SpruceB2OC_Lb0ToLcpLcmN0"
-    input_data = get_particles(f"/Event/Spruce/{turbo_line}/Particles")
+    turbo_line = "Hlt2B2OC_Lb0ToLcpLcmN0"
+    input_data = get_particles(f"/Event/HLT2/{turbo_line}/Particles")
 
 
     myfilter = create_lines_filter(
@@ -48,23 +48,23 @@ def maketuple_Lb0ToLcpLcnN0(options, pvs, rec_summary):
         fit_all_pvs=False,
     )
 
-    #pv_constraint=False, mass_constraint=False, particle_name=""
-
-    basic_variables = make_basic_variables(options, pvs, input_data) + \
-                    make_basic_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_MASS, pv_constraint=True) + \
-                    make_basic_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_BestPV, pv_constraint=True, mass_constraint=True, particle_name="BpAndLcBestPV")
+    basic_variables = make_basic_variables(options, pvs, input_data) #+ \
+                    #make_basic_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_MASS, pv_constraint=True) + \
+                    #make_basic_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_BestPV, pv_constraint=True, mass_constraint=True, particle_name="BpAndLcBestPV")
 
-    composite_variables =  make_composite_variables(options, pvs, input_data) + \
-                    make_composite_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_MASS, pv_constraint=True) + \
-                    make_composite_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_BestPV, pv_constraint=True, mass_constraint=True, particle_name="BpAndLcBestPV")
+    composite_variables =  make_composite_variables(options, pvs, input_data) #+ \
+                    #make_composite_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_MASS, pv_constraint=True) + \
+                    #make_composite_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_BestPV, pv_constraint=True, mass_constraint=True, particle_name="BpAndLcBestPV")
     
     
-    composite_variables_3body = make_composite_variables_3body(options, pvs, input_data) + \
-                    make_composite_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_MASS, pv_constraint=True, three_body=True) + \
-                    make_composite_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_BestPV, pv_constraint=True, mass_constraint=True, particle_name="BpAndLcBestPV", three_body=True)  
-                   
+    composite_variables_3body = make_composite_variables_3body(options, pvs, input_data) #+ \
+                    #make_composite_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_MASS, pv_constraint=True, three_body=True) + \
+                    #make_composite_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_BestPV, pv_constraint=True, mass_constraint=True, particle_name="BpAndLcBestPV", three_body=True)  
+
+    MVA_variables = make_MVA_variables()
+
     variables = {
-        "Lb0": composite_variables,
+        "Lb0": composite_variables  + MVA_variables,
         "Lcp": composite_variables_3body,
         "Lcm": composite_variables_3body,
         "pp":basic_variables,
@@ -89,8 +89,8 @@ def maketuple_Lb0ToLcpLcnN0(options, pvs, rec_summary):
 def maketuple_BpToLcpLcmKp(options, pvs, rec_summary):
 
     name = "BuToLcpLcmK"
-    turbo_line = "SpruceB2OC_BuToLcpLcmK_LcpToPKPi"
-    input_data = get_particles(f"/Event/Spruce/{turbo_line}/Particles")
+    turbo_line = "Hlt2B2OC_BuToLcpLcmK_LcpToPKPi"
+    input_data = get_particles(f"/Event/HLT2/{turbo_line}/Particles")
 
 
     myfilter = create_lines_filter(
@@ -139,9 +139,10 @@ def maketuple_BpToLcpLcmKp(options, pvs, rec_summary):
                     #make_composite_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_MASS, pv_constraint=True, three_body=True) + \
                     #make_composite_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_BestPV, pv_constraint=True, mass_constraint=True, particle_name="BpAndLcBestPV", three_body=True)  
                    
+    MVA_variables = make_MVA_variables()
 
     variables = {
-        "Bp": composite_variables_3body,
+        "Bp": composite_variables_3body + MVA_variables,
         "Lcp": composite_variables_3body,
         "Lcm": composite_variables_3body,
         "pp": basic_variables,
diff --git a/Liv_Lb0NeutronLines/options/tupling.py b/Liv_Lb0NeutronLines/options/tupling.py
index a275923af8..2928987b23 100644
--- a/Liv_Lb0NeutronLines/options/tupling.py
+++ b/Liv_Lb0NeutronLines/options/tupling.py
@@ -14,6 +14,8 @@
 
 import Functors as F
 from Functors.math import log
+import Functors.math as fmath
+from PyConf.reading import get_pvs
 
 from FunTuple import FunctorCollection
 from FunTuple.functorcollections import (
@@ -101,17 +103,79 @@ Hlt1_lines = Hlt1_1track_lines+[
     "Hlt1DisplacedLeptonsDecision",#removed
 ]
 
-Spruce_lines = [
-    "SpruceB2OC_Lb0ToLcpLcmN0",
-    "SpruceB2OC_Lb0ToPbarPN0",
-    "SpruceB2OC_BuToLcpLcmK_LcpToPKPi",
-] 
-
 Hlt2_lines = [
     "Hlt2Topo2BodyDecision",
-    "Hlt2Topo3Body_Decision"
+    "Hlt2Topo3Body_Decision",
+    "Hlt2B2OC_Lb0ToLcpLcmN0",
+    "Hlt2B2OC_BuToLcpLcmK_LcpToPKPi",
+]
+
+def make_MVA_variables():
+
+    pvs = get_pvs()
 
-] 
+    variables = (
+
+        FunctorCollection(
+           {
+                "MVA": F.MVA(
+                MVAType="SigmaNet",
+                Config={
+                    "File":
+                    "paramfile://data/Hlt2B2OC_B_SigmaNet_Run3-v2.json",
+                    "Name":
+                    "B2OC_SigmaNet_Generic",
+                    "Lambda":
+                    "2.0",
+                    "NLayers":
+                    "3",
+                    "InputSize":
+                    "6",
+                    "Monotone_Constraints":
+                    "[1,-1,-1,-1,-1,-1]",
+                    "Variables":
+                    "log_B_PT,B_ETA,log_B_DIRA,log_B_ENDVERTEX_CHI2,log_B_IPCHI2_OWNPV,log_B_IP_OWNPV",
+                },
+                Inputs={
+                    "log_B_PT": fmath.log(F.PT),
+                    "B_ETA": F.ETA,
+                    "log_B_DIRA": fmath.log(1. +1.e-6 - F.BPVDIRA(pvs)),
+                    "log_B_ENDVERTEX_CHI2": fmath.log(F.CHI2DOF),
+                    "log_B_IPCHI2_OWNPV": fmath.log(F.BPVIPCHI2(pvs)),
+                    "log_B_IP_OWNPV": fmath.log(F.BPVIP(pvs)),
+                }),
+            "MVAold": F.MVA(
+                MVAType="SigmaNet",
+                Config={
+                    "File":
+                    "paramfile://data/Hlt2B2OC_B_SigmaNet_Run3-v1.json",
+                    "Name":
+                    "B2OC_SigmaNet_Generic",
+                    "Lambda":
+                    "2.0",
+                    "NLayers":
+                    "3",
+                    "InputSize":
+                    "6",
+                    "Monotone_Constraints":
+                    "[1,-1,-1,-1,-1,-1]",
+                    "Variables":
+                    "log_B_PT,B_ETA,log_B_DIRA,log_B_ENDVERTEX_CHI2,log_B_IPCHI2_OWNPV,log_B_IP_OWNPV",
+                },
+                Inputs={
+                    "log_B_PT": fmath.log(F.PT),
+                    "B_ETA": F.ETA,
+                    "log_B_DIRA": fmath.log(1. - F.BPVDIRA(pvs)),
+                    "log_B_ENDVERTEX_CHI2": fmath.log(F.CHI2DOF),
+                    "log_B_IPCHI2_OWNPV": fmath.log(F.BPVIPCHI2(pvs)),
+                    "log_B_IP_OWNPV": fmath.log(F.BPVIP(pvs)),
+                }),
+
+           })
+    )
+    
+    return variables
+    
 
 def make_composite_variables(options, pvs, data, add_truth=True):
     if not options.simulation:
@@ -119,56 +183,52 @@ def make_composite_variables(options, pvs, data, add_truth=True):
     variables = (
        FunctorCollection(
            {
+               "ID": F.PARTICLE_ID,
                "CHARGE": F.CHARGE,
+               "M12": F.SUBCOMB(Functor=F.MASS, Indices=(1, 2)),
                "MAXPT": F.MAX(F.PT),
                "MINPT": F.MIN(F.PT),
                "SUMPT": F.SUM(F.PT),
                "MAXP": F.MAX(F.P),
                "MINP": F.MIN(F.P),
+               "SUMP": F.SUM(F.P),
                "BPVDIRA": F.BPVDIRA(pvs),
-               "VCHI2DOF": F.CHI2DOF, #CHI2VXNDOF
-               "VCHI2": F.CHI2,
                "BPVFDCHI2": F.BPVFDCHI2(pvs),
                "BPVFD": F.BPVFD(pvs),
                "BPVFDIR": F.BPVFDIR(pvs),
                "BPVFDVEC": F.BPVFDVEC(pvs),
                "BPVVDRHO": F.BPVVDRHO(pvs),
                "BPVVDZ": F.BPVVDZ(pvs),
+               "BPVX": F.BPVX(pvs),
+               "BPVY": F.BPVY(pvs),
+               "BPVZ": F.BPVZ(pvs),
                "BPVIPCHI2": F.BPVIPCHI2(pvs),
+               "BPVIP": F.BPVIP(pvs),
                "MINIPCHI2"   : F.MINIPCHI2(pvs),
                "MINIP"       : F.MINIP(pvs),
-               "BPVIP": F.BPVIP(pvs),
-               "LOGBPVIPCHI2": log(F.BPVIPCHI2(pvs)),
                "BPVLTIME": F.BPVLTIME(pvs),
+               "VCHI2DOF": F.CHI2DOF, #CHI2VXNDOF
+               "VCHI2": F.CHI2,
+               "LOGBPVIPCHI2": log(F.BPVIPCHI2(pvs)),
                "MAXBPVIPCHI2": F.MAX(F.BPVIPCHI2(pvs)), #MAX_
                "MINBPVIPCHI2": F.MIN(F.BPVIPCHI2(pvs)),
                "MAXBPVIP": F.MAX(F.BPVIP(pvs)),
                "MINBPVIP": F.MIN(F.BPVIP(pvs)),
                "MAXDOCACHI2": F.MAXDOCACHI2,
                "MAXDOCA": F.MAXDOCA,
-               "MAXSDOCACHI2": F.MAXSDOCACHI2,
-               "MAXSDOCA": F.MAXSDOCA,
-               "M12": F.SUBCOMB(Functor=F.MASS, Indices=(1, 2)),
-               "SDOCA12"     : F.SDOCA(Child1=1,Child2=2),
-               "SDOCACHI212" : F.SDOCACHI2(Child1=1,Child2=2),
                "DOCA12"      : F.DOCA(Child1=1,Child2=2),
                "DOCACHI212"  : F.DOCACHI2(Child1=1,Child2=2),
-               "COS12": F.ALV(1, 2),
                "ETA": F.ETA,
                "PHI": F.PHI,
                "END_VX": F.END_VX, #END_
                "END_VY": F.END_VY,
                "END_VZ": F.END_VZ,
-               "BPVX": F.BPVX(pvs),
-               "BPVY": F.BPVY(pvs),
-               "BPVZ": F.BPVZ(pvs),
+               "END_VCHI2DOF": F.CHI2DOF @ F.ENDVERTEX,
                "ALLPVFD"     : F.ALLPV_FD(pvs),
                "ALLPVIP"     : F.ALLPV_IP(pvs),
-               "OBJECT_KEY": F.OBJECT_KEY,
            }
        )
        + Kinematics()
-        #+ ParticleID(extra_info=True) #only for daughters
     )
 
     variables += HltTisTos(
@@ -209,15 +269,11 @@ def make_composite_variables_3body(options, pvs, data, add_truth=True):
             {
                 #13
                 "M13": F.SUBCOMB(Functor=F.MASS, Indices=(1, 3)),
-                "SDOCA13"     : F.SDOCA(Child1=1,Child2=3),
-                "SDOCACHI213" : F.SDOCACHI2(Child1=1,Child2=3),
                 "DOCA13"      : F.DOCA(Child1=1,Child2=3),
                 "DOCACHI213"  : F.DOCACHI2(Child1=1,Child2=3),
                 "COS13": F.ALV(1, 3),
                 #23
                 "M23": F.SUBCOMB(Functor=F.MASS, Indices=(2, 3)),
-                "SDOCA23"     : F.SDOCA(Child1=2,Child2=3),
-                "SDOCACHI223" : F.SDOCACHI2(Child1=2,Child2=3),
                 "DOCA23"      : F.DOCA(Child1=2,Child2=3),
                 "DOCACHI223"  : F.DOCACHI2(Child1=2,Child2=3),
                 "COS23": F.ALV(2, 3),
@@ -233,22 +289,16 @@ def make_composite_variables_4body(options, pvs, data, add_truth=True):
             {
                 #14
                 "M14": F.SUBCOMB(Functor=F.MASS, Indices=(1, 4)),
-                "SDOCA14"     : F.SDOCA(Child1=1,Child2=4),
-                "SDOCACHI214" : F.SDOCACHI2(Child1=1,Child2=4),
                 "DOCA14"      : F.DOCA(Child1=1,Child2=4),
                 "DOCACHI214"  : F.DOCACHI2(Child1=1,Child2=4),
                 "COS14": F.ALV(1, 4),
                 #24
                 "M24": F.SUBCOMB(Functor=F.MASS, Indices=(2, 4)),
-                "SDOCA24"     : F.SDOCA(Child1=2,Child2=4),
-                "SDOCACHI224" : F.SDOCACHI2(Child1=2,Child2=4),
                 "DOCA24"      : F.DOCA(Child1=2,Child2=4),
                 "DOCACHI224"  : F.DOCACHI2(Child1=2,Child2=4),
                 "COS24": F.ALV(2, 4),
                 #34
                 "M34": F.SUBCOMB(Functor=F.MASS, Indices=(3, 4)),
-                "SDOCA34"     : F.SDOCA(Child1=3,Child2=4),
-                "SDOCACHI234" : F.SDOCACHI2(Child1=3,Child2=4),
                 "DOCA34"      : F.DOCA(Child1=3,Child2=4),
                 "DOCACHI234"  : F.DOCACHI2(Child1=3,Child2=4),
                 "COS34": F.ALV(3, 4),
@@ -327,7 +377,6 @@ def make_hlt2_event_variables(options, pvs, rec_summary):
     # define event level variables
     evt_variables = EventInfo()
     evt_variables += SelectionInfo(selection_type="Hlt2", trigger_lines=Hlt2_lines)
-    evt_variables += SelectionInfo(selection_type="Spruce", trigger_lines=Spruce_lines)
     evt_variables += SelectionInfo(selection_type="Hlt1", trigger_lines=Hlt1_1track_lines)
     evt_variables += FunctorCollection(
         {
-- 
GitLab


From c88533237ce04babfdbe5d61bfa819e056ad09cf Mon Sep 17 00:00:00 2001
From: Juan Leite <jbaptist@lxplus958.cern.ch>
Date: Fri, 9 Aug 2024 14:15:04 +0200
Subject: [PATCH 15/34] fix import ; remove evt_max

---
 Liv_Lb0NeutronLines/info.yaml                | 10 +++++-----
 Liv_Lb0NeutronLines/main_Liv_BpToLcpLcmKp.py |  2 +-
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/Liv_Lb0NeutronLines/info.yaml b/Liv_Lb0NeutronLines/info.yaml
index d42cd6e051..fa3bf7d99b 100644
--- a/Liv_Lb0NeutronLines/info.yaml
+++ b/Liv_Lb0NeutronLines/info.yaml
@@ -30,7 +30,7 @@ defaults:
   application: "Moore/v55r10p2@x86_64_v3-el9-gcc13+detdesc-opt+g"
   input: 
     bk_query: /MC/Dev/Beam6800GeV-expected-2024-Mag{{p}}-Nu{{nu}}-25ns-Pythia8/{{simul}}/{{evttype}}/{{inptype}}
-    n_test_lfns: 10
+    # n_test_lfns: 10
     dq_flags:
       - OK
   output: MC_HLT1.DST
@@ -44,8 +44,8 @@ defaults:
       output_type: ROOT
       simulation: True
       data_type: "Upgrade"
-      evt_max: 1000
-      print_freq: 100
+      # evt_max: 1000
+      # print_freq: 100
       scheduler_legacy_mode: False
       compression:
         algorithm: ZSTD
@@ -129,8 +129,8 @@ defaults:
       conditions_version: master
       input_process: "TurboPass"
       input_stream: "b2oc"
-      evt_max: 50000
-      print_freq: 1000
+      # evt_max: 50000
+      # print_freq: 1000
       #first_evt: 1
 {%- endfor %}
 {%- endfor %}
diff --git a/Liv_Lb0NeutronLines/main_Liv_BpToLcpLcmKp.py b/Liv_Lb0NeutronLines/main_Liv_BpToLcpLcmKp.py
index 62112f2cbf..e0c4c999ad 100644
--- a/Liv_Lb0NeutronLines/main_Liv_BpToLcpLcmKp.py
+++ b/Liv_Lb0NeutronLines/main_Liv_BpToLcpLcmKp.py
@@ -9,7 +9,7 @@
 # or submit itself to any jurisdiction.                                       #
 ###############################################################################
 
-from .options.Lb_NeutronLines import *
+from .options.Lb_NeutronLines_HLT2 import *
 
 from DaVinci import Options, make_config
 from PyConf.reading import get_pvs, get_rec_summary
-- 
GitLab


From 5357a4146b0a31398c4013bbe43cb1e2fce0969c Mon Sep 17 00:00:00 2001
From: Juan Leite <jbaptist@lxplus958.cern.ch>
Date: Fri, 9 Aug 2024 14:35:31 +0200
Subject: [PATCH 16/34] Fix platform Moore

---
 Liv_Lb0NeutronLines/info.yaml | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/Liv_Lb0NeutronLines/info.yaml b/Liv_Lb0NeutronLines/info.yaml
index fa3bf7d99b..3abebcebcd 100644
--- a/Liv_Lb0NeutronLines/info.yaml
+++ b/Liv_Lb0NeutronLines/info.yaml
@@ -27,7 +27,7 @@ defaults:
 {%- for sigtype, simul, nu, inptype, evttype in mc_datasets %}
 
 {{sigtype}}_Mag{{p}}_MC_HLT1:
-  application: "Moore/v55r10p2@x86_64_v3-el9-gcc13+detdesc-opt+g"
+  application: "Moore/v55r11p2@x86_64_v2-el9-gcc13+detdesc-opt"
   input: 
     bk_query: /MC/Dev/Beam6800GeV-expected-2024-Mag{{p}}-Nu{{nu}}-25ns-Pythia8/{{simul}}/{{evttype}}/{{inptype}}
     # n_test_lfns: 10
@@ -53,7 +53,7 @@ defaults:
         max_buffer_size: 1048576
 
 {{sigtype}}_Mag{{p}}_MC_HLT2:
-  application: "Moore/v55r10p2@x86_64_v3-el9-gcc13+detdesc-opt+g"
+  application: "Moore/v55r11p2@x86_64_v2-el9-gcc13+detdesc-opt"
   input:
     job_name: {{sigtype}}_Mag{{p}}_MC_HLT1
   output: MC_HLT2_full.DST
-- 
GitLab


From 0ca9170e65ae7f1d60b6510fd80b566b4589f2a5 Mon Sep 17 00:00:00 2001
From: Juan Leite <jbaptist@lxplus958.cern.ch>
Date: Sat, 10 Aug 2024 23:53:12 +0200
Subject: [PATCH 17/34] including polarity Up

---
 Liv_Lb0NeutronLines/info.yaml | 161 +++++++++++++++++-----------------
 1 file changed, 81 insertions(+), 80 deletions(-)

diff --git a/Liv_Lb0NeutronLines/info.yaml b/Liv_Lb0NeutronLines/info.yaml
index 3abebcebcd..02bb4a293e 100644
--- a/Liv_Lb0NeutronLines/info.yaml
+++ b/Liv_Lb0NeutronLines/info.yaml
@@ -14,98 +14,99 @@ defaults:
  
 
 # 2024
-{%- set polarities = [
-    'Down', 'Up'
-]%}
+# {%- set polarities = [
+#     'Down', 'Up'
+# ]%}
 
 {%- set mc_datasets = [
  ('Lb0ToLcpLcmN0', 'Sim10c' , '7.6', 'DIGI', '15196810'),
  ('BpToLcpLcmKp', 'Sim10c' , '7.6', 'DIGI', '12197003')
 ]%}
 
-{%- for p in polarities %}
-{%- for sigtype, simul, nu, inptype, evttype in mc_datasets %}
+# {%- for p in polarities %}
+# {%- for sigtype, simul, nu, inptype, evttype in mc_datasets %}
 
-{{sigtype}}_Mag{{p}}_MC_HLT1:
-  application: "Moore/v55r11p2@x86_64_v2-el9-gcc13+detdesc-opt"
-  input: 
-    bk_query: /MC/Dev/Beam6800GeV-expected-2024-Mag{{p}}-Nu{{nu}}-25ns-Pythia8/{{simul}}/{{evttype}}/{{inptype}}
-    # n_test_lfns: 10
-    dq_flags:
-      - OK
-  output: MC_HLT1.DST
-  options: 
-    entrypoint: Liv_Lb0NeutronLines.hlt1:alg_config
-    extra_options:
-      input_raw_format: 0.5
-      conddb_tag: sim-20231017-vc-md100
-      dddb_tag: dddb-20231017
-      input_type: ROOT
-      output_type: ROOT
-      simulation: True
-      data_type: "Upgrade"
-      # evt_max: 1000
-      # print_freq: 100
-      scheduler_legacy_mode: False
-      compression:
-        algorithm: ZSTD
-        level: 1
-        max_buffer_size: 1048576
+# {{sigtype}}_Mag{{p}}_MC_HLT1:
+#   application: "Moore/v55r11p2@x86_64_v2-el9-gcc13+detdesc-opt"
+#   input: 
+#     bk_query: /MC/Dev/Beam6800GeV-expected-2024-Mag{{p}}-Nu{{nu}}-25ns-Pythia8/{{simul}}/{{evttype}}/{{inptype}}
+#     # n_test_lfns: 10
+#     dq_flags:
+#       - OK
+#   output: MC_HLT1.DST
+#   options: 
+#     entrypoint: Liv_Lb0NeutronLines.hlt1:alg_config
+#     extra_options:
+#       input_raw_format: 0.5
+#       conddb_tag: sim-20231017-vc-md100
+#       dddb_tag: dddb-20231017
+#       input_type: ROOT
+#       output_type: ROOT
+#       simulation: True
+#       data_type: "Upgrade"
+#       evt_max: 100
+#       # print_freq: 100
+#       scheduler_legacy_mode: False
+#       compression:
+#         algorithm: ZSTD
+#         level: 1
+#         max_buffer_size: 1048576
 
-{{sigtype}}_Mag{{p}}_MC_HLT2:
-  application: "Moore/v55r11p2@x86_64_v2-el9-gcc13+detdesc-opt"
-  input:
-    job_name: {{sigtype}}_Mag{{p}}_MC_HLT1
-  output: MC_HLT2_full.DST
-  options:
-    entrypoint: Liv_Lb0NeutronLines.hlt2:alg_config
-    extra_options:
-      conddb_tag: sim-20231017-vc-md100
-      dddb_tag: dddb-20231017
-      input_type: "ROOT"
-      output_type: "ROOT"
-      simulation: True
-      input_process: "Hlt2"
-      persistreco_version: 0.0
-      data_type: "Upgrade"
-      evt_max: -1
-      output_manifest_file: "HLT2.tck.json"
-      scheduler_legacy_mode: False
-      compression:
-        algorithm: ZSTD
-        level: 1
-        max_buffer_size: 1048576
+# {{sigtype}}_Mag{{p}}_MC_HLT2:
+#   application: "Moore/v55r11p2@x86_64_v2-el9-gcc13+detdesc-opt"
+#   input:
+#     job_name: {{sigtype}}_Mag{{p}}_MC_HLT1
+#   output: MC_HLT2_full.DST
+#   options:
+#     entrypoint: Liv_Lb0NeutronLines.hlt2:alg_config
+#     extra_options:
+#       conddb_tag: sim-20231017-vc-md100
+#       dddb_tag: dddb-20231017
+#       input_type: "ROOT"
+#       output_type: "ROOT"
+#       simulation: True
+#       input_process: "Hlt2"
+#       persistreco_version: 0.0
+#       data_type: "Upgrade"
+#       evt_max: -1
+#       output_manifest_file: "HLT2.tck.json"
+#       scheduler_legacy_mode: False
+#       compression:
+#         algorithm: ZSTD
+#         level: 1
+#         max_buffer_size: 1048576
         
-{{sigtype}}_Mag{{p}}_MC_Tuple:
-  application: "DaVinci/v64r8@x86_64_v2-el9-clang16+detdesc-opt"
-  input:
-    job_name: {{sigtype}}_Mag{{p}}_MC_HLT2
-  output: MC_{{sigtype}}.ROOT
-  options:
-    entrypoint: Liv_Lb0NeutronLines.main_Liv_{{sigtype}}:main
-    extra_options:
-      input_raw_format: 0.5
-      input_type: ROOT
-      simulation: True
-      data_type: Upgrade
-      conddb_tag: sim-20231017-vc-md100
-      dddb_tag: dddb-20231017
-      input_process: "Hlt2"
-      conditions_version: master
-      geometry_version: run3/trunk
-      lumi: false
-      output_type: ROOT
-      persistreco_version: 1.0
-      write_decoding_keys_to_git: True
-      input_manifest_file: "HLT2.tck.json"
-      input_stream: default
+# {{sigtype}}_Mag{{p}}_MC_Tuple:
+#   application: "DaVinci/v64r8@x86_64_v2-el9-clang16+detdesc-opt"
+#   input:
+#     job_name: {{sigtype}}_Mag{{p}}_MC_HLT2
+#   output: MC_{{sigtype}}.ROOT
+#   options:
+#     entrypoint: Liv_Lb0NeutronLines.main_Liv_{{sigtype}}:main
+#     extra_options:
+#       input_raw_format: 0.5
+#       input_type: ROOT
+#       simulation: True
+#       data_type: Upgrade
+#       conddb_tag: sim-20231017-vc-md100
+#       dddb_tag: dddb-20231017
+#       input_process: "Hlt2"
+#       conditions_version: master
+#       geometry_version: run3/trunk
+#       lumi: false
+#       output_type: ROOT
+#       persistreco_version: 1.0
+#       write_decoding_keys_to_git: True
+#       input_manifest_file: "HLT2.tck.json"
+#       input_stream: default
 
-{%- endfor %}
-{%- endfor %}
+# {%- endfor %}
+# {%- endfor %}
 
 
 {%- set polarities = [
-    'Down'
+    #'Down', 'Up'
+    'Up'
 ]%}
 {%- for p in polarities %}
 {%- for sigtype, simul, nu, inptype, evttype in mc_datasets %}
@@ -129,7 +130,7 @@ defaults:
       conditions_version: master
       input_process: "TurboPass"
       input_stream: "b2oc"
-      # evt_max: 50000
+      # evt_max: 10000
       # print_freq: 1000
       #first_evt: 1
 {%- endfor %}
-- 
GitLab


From b28ba09d5e7c8462733578392a064f45ee55c529 Mon Sep 17 00:00:00 2001
From: Juan Leite <jbaptist@lxplus958.cern.ch>
Date: Sat, 10 Aug 2024 23:56:49 +0200
Subject: [PATCH 18/34] remove comment

---
 Liv_Lb0NeutronLines/info.yaml | 1 -
 1 file changed, 1 deletion(-)

diff --git a/Liv_Lb0NeutronLines/info.yaml b/Liv_Lb0NeutronLines/info.yaml
index 02bb4a293e..83661331a4 100644
--- a/Liv_Lb0NeutronLines/info.yaml
+++ b/Liv_Lb0NeutronLines/info.yaml
@@ -105,7 +105,6 @@ defaults:
 
 
 {%- set polarities = [
-    #'Down', 'Up'
     'Up'
 ]%}
 {%- for p in polarities %}
-- 
GitLab


From da455cff5afb53b40321c3f0334547d343bf8f8b Mon Sep 17 00:00:00 2001
From: Juan Leite <jbaptist@lxplus958.cern.ch>
Date: Sat, 10 Aug 2024 23:59:39 +0200
Subject: [PATCH 19/34] fixing jinja

---
 Liv_Lb0NeutronLines/info.yaml | 92 -----------------------------------
 1 file changed, 92 deletions(-)

diff --git a/Liv_Lb0NeutronLines/info.yaml b/Liv_Lb0NeutronLines/info.yaml
index 83661331a4..053bc47d2c 100644
--- a/Liv_Lb0NeutronLines/info.yaml
+++ b/Liv_Lb0NeutronLines/info.yaml
@@ -4,104 +4,12 @@ defaults:
   wg: B2OC
 
 
-# checks:
-#   histogram_M:
-#     type: range
-#     expression: Lb0_M
-#     limits:
-#       min: 4000
-#       max: 6000
- 
-
-# 2024
-# {%- set polarities = [
-#     'Down', 'Up'
-# ]%}
 
 {%- set mc_datasets = [
  ('Lb0ToLcpLcmN0', 'Sim10c' , '7.6', 'DIGI', '15196810'),
  ('BpToLcpLcmKp', 'Sim10c' , '7.6', 'DIGI', '12197003')
 ]%}
 
-# {%- for p in polarities %}
-# {%- for sigtype, simul, nu, inptype, evttype in mc_datasets %}
-
-# {{sigtype}}_Mag{{p}}_MC_HLT1:
-#   application: "Moore/v55r11p2@x86_64_v2-el9-gcc13+detdesc-opt"
-#   input: 
-#     bk_query: /MC/Dev/Beam6800GeV-expected-2024-Mag{{p}}-Nu{{nu}}-25ns-Pythia8/{{simul}}/{{evttype}}/{{inptype}}
-#     # n_test_lfns: 10
-#     dq_flags:
-#       - OK
-#   output: MC_HLT1.DST
-#   options: 
-#     entrypoint: Liv_Lb0NeutronLines.hlt1:alg_config
-#     extra_options:
-#       input_raw_format: 0.5
-#       conddb_tag: sim-20231017-vc-md100
-#       dddb_tag: dddb-20231017
-#       input_type: ROOT
-#       output_type: ROOT
-#       simulation: True
-#       data_type: "Upgrade"
-#       evt_max: 100
-#       # print_freq: 100
-#       scheduler_legacy_mode: False
-#       compression:
-#         algorithm: ZSTD
-#         level: 1
-#         max_buffer_size: 1048576
-
-# {{sigtype}}_Mag{{p}}_MC_HLT2:
-#   application: "Moore/v55r11p2@x86_64_v2-el9-gcc13+detdesc-opt"
-#   input:
-#     job_name: {{sigtype}}_Mag{{p}}_MC_HLT1
-#   output: MC_HLT2_full.DST
-#   options:
-#     entrypoint: Liv_Lb0NeutronLines.hlt2:alg_config
-#     extra_options:
-#       conddb_tag: sim-20231017-vc-md100
-#       dddb_tag: dddb-20231017
-#       input_type: "ROOT"
-#       output_type: "ROOT"
-#       simulation: True
-#       input_process: "Hlt2"
-#       persistreco_version: 0.0
-#       data_type: "Upgrade"
-#       evt_max: -1
-#       output_manifest_file: "HLT2.tck.json"
-#       scheduler_legacy_mode: False
-#       compression:
-#         algorithm: ZSTD
-#         level: 1
-#         max_buffer_size: 1048576
-        
-# {{sigtype}}_Mag{{p}}_MC_Tuple:
-#   application: "DaVinci/v64r8@x86_64_v2-el9-clang16+detdesc-opt"
-#   input:
-#     job_name: {{sigtype}}_Mag{{p}}_MC_HLT2
-#   output: MC_{{sigtype}}.ROOT
-#   options:
-#     entrypoint: Liv_Lb0NeutronLines.main_Liv_{{sigtype}}:main
-#     extra_options:
-#       input_raw_format: 0.5
-#       input_type: ROOT
-#       simulation: True
-#       data_type: Upgrade
-#       conddb_tag: sim-20231017-vc-md100
-#       dddb_tag: dddb-20231017
-#       input_process: "Hlt2"
-#       conditions_version: master
-#       geometry_version: run3/trunk
-#       lumi: false
-#       output_type: ROOT
-#       persistreco_version: 1.0
-#       write_decoding_keys_to_git: True
-#       input_manifest_file: "HLT2.tck.json"
-#       input_stream: default
-
-# {%- endfor %}
-# {%- endfor %}
 
 
 {%- set polarities = [
-- 
GitLab


From e5f7d5539fda3b61228112a2294cd4e73a94ed5f Mon Sep 17 00:00:00 2001
From: Juan Leite <jbaptist@lxplus928.cern.ch>
Date: Sat, 17 Aug 2024 20:28:13 +0200
Subject: [PATCH 20/34] First Commit

---
 Liv_Lb0NeutronLines/Spruce.py                 |  68 -----
 Liv_Lb0NeutronLines/info.yaml                 | 253 +++++++++++++++++-
 .../main_Liv_BpToLcpLcmKp_Spruce.py           |  32 +++
 .../main_Liv_Lb0ToLcpLcmN0_Spruce.py          |  32 +++
 .../options/Lb_NeutronLines_HLT2.py           | 120 +++++----
 .../options/Lb_NeutronLines_Spruce.py         | 194 ++++++++++++++
 Liv_Lb0NeutronLines/options/tupling.py        | 186 +++++++------
 7 files changed, 669 insertions(+), 216 deletions(-)
 delete mode 100644 Liv_Lb0NeutronLines/Spruce.py
 create mode 100644 Liv_Lb0NeutronLines/main_Liv_BpToLcpLcmKp_Spruce.py
 create mode 100644 Liv_Lb0NeutronLines/main_Liv_Lb0ToLcpLcmN0_Spruce.py
 create mode 100644 Liv_Lb0NeutronLines/options/Lb_NeutronLines_Spruce.py

diff --git a/Liv_Lb0NeutronLines/Spruce.py b/Liv_Lb0NeutronLines/Spruce.py
deleted file mode 100644
index 80ff745cc8..0000000000
--- a/Liv_Lb0NeutronLines/Spruce.py
+++ /dev/null
@@ -1,68 +0,0 @@
-####################################
-# options                          #
-####################################
-
-import Moore
-from Moore import Options, run_moore, config
-from Moore.lines import Hlt2Line
-from RecoConf.reconstruction_objects import reconstruction as reconstruction
-from Moore import options, run_moore
-from RecoConf.global_tools import stateProvider_with_simplified_geom, trackMasterExtrapolator_with_simplified_geom
-from RecoConf.hlt2_global_reco import reconstruction as hlt2_reconstruction, make_light_reco_pr_kf_without_UT
-from RecoConf.hlt2_tracking import (
-    make_TrackBestTrackCreator_tracks,
-    make_PrKalmanFilter_noUT_tracks,
-    make_PrKalmanFilter_Velo_tracks,
-    make_PrKalmanFilter_Seed_tracks,
-)
-from PyConf.reading import get_particles, upfront_reconstruction as upfront_spruce
-from RecoConf.decoders import default_VeloCluster_source
-from RecoConf.event_filters import require_gec
-from Moore.streams import DETECTORS, Stream, Streams
-import sys
-from Moore.lines import SpruceLine
-
-
-from Hlt2Conf.lines.b_to_open_charm import sprucing_lines
-
-
-
-################## options ############
-    
-public_tools = [
-    trackMasterExtrapolator_with_simplified_geom(),
-    stateProvider_with_simplified_geom(),
-]
-
-def pass_through_line(name="SprucePassThrough"):
-    """Return a Spruce line that performs no selection but runs and persists the reconstruction
-    """
-    return SpruceLine(
-        name=name, prescale=1, algs=upfront_spruce(), persistreco=True)
-
-
-def make_full_streams():
-    lines = [builder() for builder in sprucing_lines.values()]
-    lines += [pass_through_line(name="SprucePassThrough__exclusive")]
-    streams = [Stream(lines=lines, detectors=[])]
-    return Streams(streams=streams)
-
-
-
-def alg_config(options: Options):
-    public_tools = [stateProvider_with_simplified_geom()]
-    with reconstruction.bind(from_file=True, spruce=True):
-        return run_moore(options, make_full_streams, public_tools=public_tools)
-
-
-
-# def _make_lines():
-#     mylines = [builder() for builder in sprucing_lines.values()]
-#     return mylines
-
-# def alg_config(options: Options):
-#     with reconstruction.bind(from_file=True, spruce=True):
-#         config = run_moore(options, _make_lines, public_tools)
-#     return config
-
-
diff --git a/Liv_Lb0NeutronLines/info.yaml b/Liv_Lb0NeutronLines/info.yaml
index 053bc47d2c..c0310c3b6d 100644
--- a/Liv_Lb0NeutronLines/info.yaml
+++ b/Liv_Lb0NeutronLines/info.yaml
@@ -4,6 +4,12 @@ defaults:
   wg: B2OC
 
 
+###### HLT2 Lines ############
+
+# 2024
+{%- set polarities = [
+    'Down', 'Up'
+]%}
 
 {%- set mc_datasets = [
  ('Lb0ToLcpLcmN0', 'Sim10c' , '7.6', 'DIGI', '15196810'),
@@ -11,20 +17,162 @@ defaults:
 ]%}
 
 
+{%- for p in polarities %}
+{%- for sigtype, simul, nu, inptype, evttype in mc_datasets %}
 
-{%- set polarities = [
-    'Up'
+{{sigtype}}_Mag{{p}}_MC_HLT1:
+  application: "Moore/v55r11p2@x86_64_v2-el9-gcc13+detdesc-opt"
+  input: 
+    bk_query: /MC/Dev/Beam6800GeV-expected-2024-Mag{{p}}-Nu{{nu}}-25ns-Pythia8/{{simul}}/{{evttype}}/{{inptype}}
+    # n_test_lfns: 10
+    dq_flags:
+      - OK
+  output: MC_HLT1.DST
+  options: 
+    entrypoint: Liv_Lb0NeutronLines.hlt1:alg_config
+    extra_options:
+      input_raw_format: 0.5
+      conddb_tag: sim-20231017-vc-md100
+      dddb_tag: dddb-20231017
+      input_type: ROOT
+      output_type: ROOT
+      simulation: True
+      data_type: "Upgrade"
+      # evt_max: 1000
+      # print_freq: 100
+      scheduler_legacy_mode: False
+      compression:
+        algorithm: ZSTD
+        level: 1
+        max_buffer_size: 1048576
+
+{{sigtype}}_Mag{{p}}_MC_HLT2:
+  application: "Moore/v55r11p2@x86_64_v2-el9-gcc13+detdesc-opt"
+  input:
+    job_name: {{sigtype}}_Mag{{p}}_MC_HLT1
+  output: MC_HLT2_full.DST
+  options:
+    entrypoint: Liv_Lb0NeutronLines.hlt2:alg_config
+    extra_options:
+      conddb_tag: sim-20231017-vc-md100
+      dddb_tag: dddb-20231017
+      input_type: "ROOT"
+      output_type: "ROOT"
+      simulation: True
+      input_process: "Hlt2"
+      persistreco_version: 0.0
+      data_type: "Upgrade"
+      evt_max: -1
+      output_manifest_file: "HLT2.tck.json"
+      scheduler_legacy_mode: False
+      compression:
+        algorithm: ZSTD
+        level: 1
+        max_buffer_size: 1048576
+        
+{{sigtype}}_Mag{{p}}_MC_Tuple:
+  application: "DaVinci/v64r8@x86_64_v2-el9-clang16+detdesc-opt"
+  input:
+    job_name: {{sigtype}}_Mag{{p}}_MC_HLT2
+  output: MC_{{sigtype}}.ROOT
+  options:
+    entrypoint: Liv_Lb0NeutronLines.main_Liv_{{sigtype}}:main
+    extra_options:
+      input_raw_format: 0.5
+      input_type: ROOT
+      simulation: True
+      data_type: Upgrade
+      conddb_tag: sim-20231017-vc-md100
+      dddb_tag: dddb-20231017
+      input_process: "Hlt2"
+      conditions_version: master
+      geometry_version: run3/trunk
+      lumi: false
+      output_type: ROOT
+      persistreco_version: 1.0
+      write_decoding_keys_to_git: True
+      input_manifest_file: "HLT2.tck.json"
+      input_stream: default
+
+{%- endfor %}
+{%- endfor %}
+
+###################
+## DATA:
+###################
+
+{%- for p in polarities %}
+{%- for sigtype, simul, nu, inptype, evttype in mc_datasets %}
+{{sigtype}}_Mag{{p}}_Data_Hlt2_Spc2_Tuple:
+  application: "DaVinci/v64r8@x86_64_v2-el9-clang16-opt"
+  input:
+    bk_query: /LHCb/Collision24/Beam6800GeV-VeloClosed-Mag{{p}}/Real Data/Sprucing24c2/94000000/B2OC.DST
+    dq_flags:
+      - UNCHECKED
+      - OK
+    keep_running: True
+  output: RealData_{{sigtype}}.ROOT
+  options:
+    entrypoint: Liv_Lb0NeutronLines.main_Liv_{{sigtype}}:main
+    extra_options:
+      input_raw_format: 0.5
+      input_type: ROOT
+      simulation: False
+      data_type: Upgrade
+      geometry_version: run3/trunk
+      conditions_version: master
+      input_process: "TurboPass"
+      input_stream: "b2oc"
+      evt_max: 50000
+      # print_freq: 1000
+      #first_evt: 1
+{%- endfor %}
+{%- endfor %}
+
+
+{%- for p in polarities %}
+{%- for sigtype, simul, nu, inptype, evttype in mc_datasets %}
+{{sigtype}}_Mag{{p}}_Data_Hlt2_ExclUT_Spc2_Tuple:
+  application: "DaVinci/v64r8@x86_64_v2-el9-clang16-opt"
+  input:
+    bk_query: /LHCb/Collision24/Beam6800GeV-VeloClosed-Mag{{p}}-Excl-UT/Real Data/Sprucing24c2/94000000/B2OC.DST
+    dq_flags:
+      - UNCHECKED
+      - OK
+    keep_running: True
+  output: RealData_{{sigtype}}.ROOT
+  options:
+    entrypoint: Liv_Lb0NeutronLines.main_Liv_{{sigtype}}:main
+    extra_options:
+      input_raw_format: 0.5
+      input_type: ROOT
+      simulation: False
+      data_type: Upgrade
+      geometry_version: run3/trunk
+      conditions_version: master
+      input_process: "TurboPass"
+      input_stream: "b2oc"
+      evt_max: 50000
+      # print_freq: 1000
+      #first_evt: 1
+{%- endfor %}
+{%- endfor %}
+
+# I don't have HLT2 24c1 for Lb0 channels here
+{%- set mc_datasets = [
+ ('BpToLcpLcmKp', '' , '', '', '')
 ]%}
+
 {%- for p in polarities %}
 {%- for sigtype, simul, nu, inptype, evttype in mc_datasets %}
-{{sigtype}}_Mag{{p}}_Data_Tuple:
+{{sigtype}}_Mag{{p}}_Data_Hlt2_ExclUT_Spc1_Tuple:
   application: "DaVinci/v64r8@x86_64_v2-el9-clang16-opt"
   input:
-    bk_query: /LHCb/Collision24/Beam6800GeV-VeloClosed-MagDown/Real Data/Sprucing24c2/94000000/B2OC.DST
+    bk_query: /LHCb/Collision24/Beam6800GeV-VeloClosed-Mag{{p}}-Excl-UT/Real Data/Sprucing24c1/94000000/B2OC.DST
     dq_flags:
       - UNCHECKED
       - OK
-    keep_running: False
+    keep_running: True
   output: RealData_{{sigtype}}.ROOT
   options:
     entrypoint: Liv_Lb0NeutronLines.main_Liv_{{sigtype}}:main
@@ -37,8 +185,101 @@ defaults:
       conditions_version: master
       input_process: "TurboPass"
       input_stream: "b2oc"
-      # evt_max: 10000
+      evt_max: 50000
+      # print_freq: 1000
+      #first_evt: 1
+{%- endfor %}
+{%- endfor %}
+
+###### Sprucing Lines ############
+
+{%- set mc_datasets = [
+ ('Lb0ToLcpLcmN0', '' , '', '', ''),
+ ('BpToLcpLcmKp', '' , '', '', '')
+]%}
+
+
+{%- for p in polarities %} 
+{%- for sigtype, simul, nu, inptype, evttype in mc_datasets %}
+{{sigtype}}_Mag{{p}}_Data_Spruce_Spc2_Tuple:
+  application: "DaVinci/v64r8@x86_64_v2-el9-clang16-opt"
+  input:
+    bk_query: /LHCb/Collision24/Beam6800GeV-VeloClosed-Mag{{p}}/Real Data/Sprucing24c2/94000000/B2OC.DST
+    dq_flags:
+      - UNCHECKED
+      - OK
+    keep_running: True
+  output: RealData_{{sigtype}}.ROOT
+  options:
+    entrypoint: Liv_Lb0NeutronLines.main_Liv_{{sigtype}}_Spruce:main
+    extra_options:
+      input_raw_format: 0.5
+      input_type: ROOT
+      simulation: False
+      data_type: Upgrade
+      geometry_version: run3/trunk
+      conditions_version: master
+      input_process: "Spruce"
+      input_stream: "b2oc"
+      evt_max: 50000
       # print_freq: 1000
       #first_evt: 1
 {%- endfor %}
 {%- endfor %}
+
+# -------------------------------Why there is no MagUp?
+# {%- for p in polarities %}
+# {%- for sigtype, simul, nu, inptype, evttype in mc_datasets %}
+# {{sigtype}}_Mag{{p}}_Data_Spruce_ExclUT_Spc2_Tuple:
+#   application: "DaVinci/v64r8@x86_64_v2-el9-clang16-opt"
+#   input:
+#     bk_query: /LHCb/Collision24/Beam6800GeV-VeloClosed-Mag{{p}}-Excl-UT/Real Data/Sprucing24c2/94000000/B2OC.DST
+#     dq_flags:
+#       - UNCHECKED
+#       - OK
+#     keep_running: True
+#   output: RealData_{{sigtype}}.ROOT
+#   options:
+#     entrypoint: Liv_Lb0NeutronLines.main_Liv_{{sigtype}}_Spruce:main
+#     extra_options:
+#       input_raw_format: 0.5
+#       input_type: ROOT
+#       simulation: False
+#       data_type: Upgrade
+#       geometry_version: run3/trunk
+#       conditions_version: master
+#       input_process: "Spruce"
+#       input_stream: "b2oc"
+#       evt_max: 50000
+#       # print_freq: 1000
+#       #first_evt: 1
+# {%- endfor %}
+# {%- endfor %}
+
+{%- for p in polarities %}
+{%- for sigtype, simul, nu, inptype, evttype in mc_datasets %}
+{{sigtype}}_Mag{{p}}_Data_Spruce_ExclUT_Spc1_Tuple:
+  application: "DaVinci/v64r8@x86_64_v2-el9-clang16-opt"
+  input:
+    bk_query: /LHCb/Collision24/Beam6800GeV-VeloClosed-Mag{{p}}-Excl-UT/Real Data/Sprucing24c1/94000000/B2OC.DST
+    dq_flags:
+      - UNCHECKED
+      - OK
+    keep_running: True
+  output: RealData_{{sigtype}}.ROOT
+  options:
+    entrypoint: Liv_Lb0NeutronLines.main_Liv_{{sigtype}}_Spruce:main
+    extra_options:
+      input_raw_format: 0.5
+      input_type: ROOT
+      simulation: False
+      data_type: Upgrade
+      geometry_version: run3/trunk
+      conditions_version: master
+      input_process: "Spruce"
+      input_stream: "b2oc"
+      # evt_max: 50000
+      # print_freq: 1000
+      #first_evt: 1
+{%- endfor %}
+{%- endfor %}
\ No newline at end of file
diff --git a/Liv_Lb0NeutronLines/main_Liv_BpToLcpLcmKp_Spruce.py b/Liv_Lb0NeutronLines/main_Liv_BpToLcpLcmKp_Spruce.py
new file mode 100644
index 0000000000..e58d39a826
--- /dev/null
+++ b/Liv_Lb0NeutronLines/main_Liv_BpToLcpLcmKp_Spruce.py
@@ -0,0 +1,32 @@
+###############################################################################
+# (c) Copyright 2021-2022 CERN for the benefit of the LHCb Collaboration      #
+#                                                                             #
+# This software is distributed under the terms of the GNU General Public      #
+# Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING".   #
+#                                                                             #
+# In applying this licence, CERN does not waive the privileges and immunities #
+# granted to it by virtue of its status as an Intergovernmental Organization  #
+# or submit itself to any jurisdiction.                                       #
+###############################################################################
+
+from .options.Lb_NeutronLines_Spruce import *
+
+from DaVinci import Options, make_config
+from PyConf.reading import get_pvs, get_rec_summary
+
+def main(options: Options):
+        
+    # get ODIN and DecReports location
+    pvs = get_pvs()
+    rec_summary = get_rec_summary()
+
+    """ CORREGGERE TUPLES """
+
+    tuples = {    
+        "BpToLcpLcmKp" : maketuple_BpToLcpLcmKp(options, pvs, rec_summary)
+    }
+        
+    config = make_config(options, tuples)
+
+    return config
+
diff --git a/Liv_Lb0NeutronLines/main_Liv_Lb0ToLcpLcmN0_Spruce.py b/Liv_Lb0NeutronLines/main_Liv_Lb0ToLcpLcmN0_Spruce.py
new file mode 100644
index 0000000000..8fa00a3470
--- /dev/null
+++ b/Liv_Lb0NeutronLines/main_Liv_Lb0ToLcpLcmN0_Spruce.py
@@ -0,0 +1,32 @@
+###############################################################################
+# (c) Copyright 2021-2022 CERN for the benefit of the LHCb Collaboration      #
+#                                                                             #
+# This software is distributed under the terms of the GNU General Public      #
+# Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING".   #
+#                                                                             #
+# In applying this licence, CERN does not waive the privileges and immunities #
+# granted to it by virtue of its status as an Intergovernmental Organization  #
+# or submit itself to any jurisdiction.                                       #
+###############################################################################
+
+from .options.Lb_NeutronLines_Spruce import *
+
+from DaVinci import Options, make_config
+from PyConf.reading import get_pvs, get_rec_summary
+
+def main(options: Options):
+        
+    # get ODIN and DecReports location
+    pvs = get_pvs()
+    rec_summary = get_rec_summary()
+
+    """ CORREGGERE TUPLES """
+
+    tuples = {    
+        "Lb0ToLcpLcmN0" : maketuple_Lb0ToLcpLcnN0(options, pvs, rec_summary)
+    }
+        
+    config = make_config(options, tuples)
+
+    return config
+
diff --git a/Liv_Lb0NeutronLines/options/Lb_NeutronLines_HLT2.py b/Liv_Lb0NeutronLines/options/Lb_NeutronLines_HLT2.py
index 34e2345678..9fe36d734f 100644
--- a/Liv_Lb0NeutronLines/options/Lb_NeutronLines_HLT2.py
+++ b/Liv_Lb0NeutronLines/options/Lb_NeutronLines_HLT2.py
@@ -6,7 +6,8 @@ from DaVinci import Options, make_config
 from DaVinci.algorithms import create_lines_filter
 from PyConf.reading import get_particles
 from FunTuple import FunctorCollection
-from PyConf.reading import get_particles, get_pvs
+from PyConf.reading import get_particles, get_pvs, get_extended_pvs
+from PyConf.Algorithms import ParticleUnbiasedPVAdder
 import FunTuple.functorcollections as FC
 from FunTuple import FunTuple_Particles as Funtuple
 from DecayTreeFitter import DecayTreeFitter
@@ -38,35 +39,31 @@ def maketuple_Lb0ToLcpLcnN0(options, pvs, rec_summary):
     
     DTF_MASS = DecayTreeFitter(
         name='DTF_{hash}', 
-        input_particles=input_data)
+        input_particles=input_data,
+        mass_constraints=["Lambda_c+"],)
 
-    DTF_BestPV = DecayTreeFitter(
-        name="DTF_BestPV",
+    DTF_MASS_OWNPV = DecayTreeFitter(
+        name='DTF_{hash}', 
         input_particles=input_data,
-        mass_constraints=["Lambda_b0", "Lambda_c+"],
-        input_pvs=pvs,
-        fit_all_pvs=False,
-    )
+        mass_constraints=["Lambda_c+"],
+        constrain_to_ownpv=True,)
 
-    basic_variables = make_basic_variables(options, pvs, input_data) #+ \
-                    #make_basic_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_MASS, pv_constraint=True) + \
-                    #make_basic_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_BestPV, pv_constraint=True, mass_constraint=True, particle_name="BpAndLcBestPV")
+    basic_variables = make_basic_variables(options, pvs, input_data) 
 
-    composite_variables =  make_composite_variables(options, pvs, input_data) #+ \
-                    #make_composite_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_MASS, pv_constraint=True) + \
-                    #make_composite_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_BestPV, pv_constraint=True, mass_constraint=True, particle_name="BpAndLcBestPV")
-    
+    composite_variables =  make_composite_variables(options, pvs, input_data) 
     
-    composite_variables_3body = make_composite_variables_3body(options, pvs, input_data) #+ \
-                    #make_composite_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_MASS, pv_constraint=True, three_body=True) + \
-                    #make_composite_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_BestPV, pv_constraint=True, mass_constraint=True, particle_name="BpAndLcBestPV", three_body=True)  
-
-    MVA_variables = make_MVA_variables()
+    composite_variables_3body = make_composite_variables_3body(options, pvs, input_data) 
 
+    DTF_TwoBody = make_composite_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_MASS, pv_constraint=False, mass_constraint=True, particle_name="", three_body=False) +\
+               make_composite_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_MASS_OWNPV, pv_constraint=False, three_body=False, mass_constraint=True,particle_name="_OWNPV") #same as BEST
+    
+    DTF_ThreeBody = make_composite_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_MASS, pv_constraint=False, mass_constraint=True, particle_name="", three_body=True) +\
+               make_composite_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_MASS_OWNPV, pv_constraint=False, three_body=True, mass_constraint=True,particle_name="_OWNPV") #same as BEST
+    
     variables = {
-        "Lb0": composite_variables  + MVA_variables,
-        "Lcp": composite_variables_3body,
-        "Lcm": composite_variables_3body,
+        "Lb0": composite_variables + DTF_TwoBody,
+        "Lcp": composite_variables_3body + DTF_ThreeBody,
+        "Lcm": composite_variables_3body + DTF_ThreeBody,
         "pp":basic_variables,
         "pm":basic_variables,
         "pip":basic_variables,
@@ -81,9 +78,10 @@ def maketuple_Lb0ToLcpLcnN0(options, pvs, rec_summary):
         fields=branches,
         variables=variables,
         event_variables=make_hlt2_event_variables(options, pvs, rec_summary),
-        inputs=input_data)
+        inputs=input_data,
+        store_multiple_cand_info=True)
 
-    return [ myfilter, mytuple]
+    return [myfilter, mytuple]
 
 
 def maketuple_BpToLcpLcmKp(options, pvs, rec_summary):
@@ -111,34 +109,35 @@ def maketuple_BpToLcpLcmKp(options, pvs, rec_summary):
         "Kp_ext":"[B+ -> (Lambda_c+ -> p+ K- pi+) (Lambda_c~- -> p~- K+ pi-) ^K+]CC",
     }
     
-    
     DTF_MASS = DecayTreeFitter(
         name='DTF_{hash}', 
-        input_particles=input_data)
+        input_particles=input_data,
+        mass_constraints=["Lambda_c+"],)
 
-    DTF_BestPV = DecayTreeFitter(
-        name="DTF_BestPV",
+    DTF_MASS_OWNPV = DecayTreeFitter(
+        name='DTF_{hash}', 
         input_particles=input_data,
-        mass_constraints=["B+", "Lambda_c+"],
-        input_pvs=pvs,
-        fit_all_pvs=False,
-    )
+        mass_constraints=["Lambda_c+"],
+        constrain_to_ownpv=True,)
+
 
-    #pv_constraint=False, mass_constraint=False, particle_name=""
+    # B_Data_unbiasedpv = ParticleUnbiasedPVAdder(
+    #     InputParticles=input_data, PrimaryVertices=get_extended_pvs()
+    # ).OutputParticles
+
+    # DTF_UnbiasedPV = DecayTreeFitter(
+    #     name="DTF_UnbiasedPV",
+    #     input_particles=B_Data_unbiasedpv,
+    #     mass_constraints=["Lambda_c+"],
+    #     constrain_to_ownpv=True,
+    # )
 
     basic_variables = make_basic_variables(options, pvs, input_data) 
-                   # make_basic_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_MASS, pv_constraint=True) + \
-                   # make_basic_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_BestPV, pv_constraint=True, mass_constraint=True, particle_name="BpAndLcBestPV")
 
-    composite_variables =  make_composite_variables(options, pvs, input_data) 
-                   # make_composite_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_MASS, pv_constraint=True) + \
-                   # make_composite_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_BestPV, pv_constraint=True, mass_constraint=True, particle_name="BpAndLcBestPV")
-    
+    composite_variables_3body = make_composite_variables_3body(options, pvs, input_data) +\
+        make_composite_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_MASS, pv_constraint=False, three_body=True, mass_constraint=True,particle_name="") +\
+        make_composite_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_MASS_OWNPV, pv_constraint=False, three_body=True, mass_constraint=True,particle_name="_OWNPV") #same as BEST
     
-    composite_variables_3body = make_composite_variables_3body(options, pvs, input_data) 
-                    #make_composite_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_MASS, pv_constraint=True, three_body=True) + \
-                    #make_composite_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_BestPV, pv_constraint=True, mass_constraint=True, particle_name="BpAndLcBestPV", three_body=True)  
-                   
     MVA_variables = make_MVA_variables()
 
     variables = {
@@ -154,15 +153,42 @@ def maketuple_BpToLcpLcmKp(options, pvs, rec_summary):
         "Kp_ext": basic_variables,
     }
 
+    # composite_variables_3body = make_composite_variables_3body(options, pvs, input_data) +\
+    #     make_composite_dtf_variables(options, get_extended_pvs(), input_data, add_truth=True, DTF=DTF_UnbiasedPV, pv_constraint=False, three_body=True, mass_constraint=True,particle_name="_UnbiasedPV")
+
+
+    # variablesUnbiased = {
+    #     "Bp": composite_variables_3body + MVA_variables,
+    #     "Lcp": composite_variables_3body,
+    #     "Lcm": composite_variables_3body,
+    #     "pp": basic_variables,
+    #     "pm": basic_variables,
+    #     "pip": basic_variables,
+    #     "pim": basic_variables,
+    #     "Kp": basic_variables,
+    #     "Km": basic_variables,
+    #     "Kp_ext": basic_variables,
+    # }
+
     mytuple = Funtuple(
         name=name,
         tuple_name="DecayTree",
         fields=branches,
         variables=variables,
         event_variables=make_hlt2_event_variables(options, pvs, rec_summary),
-        inputs=input_data)
-
-    return [ myfilter, mytuple]
+        inputs=input_data,
+        store_multiple_cand_info=True)
+    
+    # mytupleUnbiased = Funtuple(
+    #     name=name+"_Unbiased",
+    #     tuple_name="DecayTree",
+    #     fields=branches,
+    #     variables=variablesUnbiased,
+    #     event_variables=make_hlt2_event_variables(options, pvs, rec_summary),
+    #     inputs=B_Data_unbiasedpv,
+    #     store_multiple_cand_info=True)
+
+    return [myfilter, mytuple]
 
 
 
diff --git a/Liv_Lb0NeutronLines/options/Lb_NeutronLines_Spruce.py b/Liv_Lb0NeutronLines/options/Lb_NeutronLines_Spruce.py
new file mode 100644
index 0000000000..278a99d630
--- /dev/null
+++ b/Liv_Lb0NeutronLines/options/Lb_NeutronLines_Spruce.py
@@ -0,0 +1,194 @@
+from .tupling import *
+
+import Functors as F
+from Functors.math import log
+from DaVinci import Options, make_config
+from DaVinci.algorithms import create_lines_filter
+from PyConf.reading import get_particles
+from FunTuple import FunctorCollection
+from PyConf.reading import get_particles, get_pvs, get_extended_pvs
+from PyConf.Algorithms import ParticleUnbiasedPVAdder
+import FunTuple.functorcollections as FC
+from FunTuple import FunTuple_Particles as Funtuple
+from DecayTreeFitter import DecayTreeFitter
+
+def maketuple_Lb0ToLcpLcnN0(options, pvs, rec_summary):
+
+    name = "Lb0ToLcpLcmN0"
+    turbo_line = "SpruceB2OC_Lb0ToLcpLcmN0"
+    input_data = get_particles(f"/Event/Spruce/{turbo_line}/Particles")
+
+
+    myfilter = create_lines_filter(
+        f"LineFilter_{turbo_line}_{{hash}}",
+        [turbo_line],
+    )
+
+    branches = {
+        "Lb0":"[Lambda_b0 -> (Lambda_c+ -> p+ K- pi+) (Lambda_c~- -> p~- K+ pi-)]CC",
+        "Lcp":"[Lambda_b0 -> ^(Lambda_c+ -> p+ K- pi+) (Lambda_c~- -> p~- K+ pi-)]CC",
+        "Lcm":"[Lambda_b0 -> (Lambda_c+ -> p+ K- pi+) ^(Lambda_c~- -> p~- K+ pi-)]CC",
+        "pp":"[Lambda_b0 -> (Lambda_c+ -> ^p+ K- pi+) (Lambda_c~- -> p~- K+ pi-)]CC",
+        "pm":"[Lambda_b0 -> (Lambda_c+ -> p+ K- pi+) (Lambda_c~- -> ^p~- K+ pi-)]CC",
+        "pip":"[Lambda_b0 -> (Lambda_c+ -> p+ K- ^pi+) (Lambda_c~- -> p~- K+ pi-)]CC",
+        "pim":"[Lambda_b0 -> (Lambda_c+ -> p+ K- pi+) (Lambda_c~- -> p~- K+ ^pi-)]CC",
+        "Kp":"[Lambda_b0 -> (Lambda_c+ -> p+ K- pi+) (Lambda_c~- -> p~- ^K+ pi-)]CC",
+        "Km":"[Lambda_b0 -> (Lambda_c+ -> p+ ^K- pi+) (Lambda_c~- -> p~- K+ pi-)]CC",
+    }
+    
+    
+    DTF_MASS = DecayTreeFitter(
+        name='DTF_{hash}', 
+        input_particles=input_data,
+        mass_constraints=["Lambda_c+"],)
+
+    DTF_MASS_OWNPV = DecayTreeFitter(
+        name='DTF_{hash}', 
+        input_particles=input_data,
+        mass_constraints=["Lambda_c+"],
+        constrain_to_ownpv=True,)
+
+    basic_variables = make_basic_variables(options, pvs, input_data) 
+
+    composite_variables =  make_composite_variables(options, pvs, input_data) 
+    
+    composite_variables_3body = make_composite_variables_3body(options, pvs, input_data) 
+
+    DTF_TwoBody = make_composite_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_MASS, pv_constraint=False, mass_constraint=True, particle_name="", three_body=False) +\
+               make_composite_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_MASS_OWNPV, pv_constraint=False, three_body=False, mass_constraint=True,particle_name="_OWNPV") #same as BEST
+    
+    DTF_ThreeBody = make_composite_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_MASS, pv_constraint=False, mass_constraint=True, particle_name="", three_body=True) +\
+               make_composite_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_MASS_OWNPV, pv_constraint=False, three_body=True, mass_constraint=True,particle_name="_OWNPV") #same as BEST
+    
+    variables = {
+        "Lb0": composite_variables + DTF_TwoBody,
+        "Lcp": composite_variables_3body + DTF_ThreeBody,
+        "Lcm": composite_variables_3body + DTF_ThreeBody,
+        "pp":basic_variables,
+        "pm":basic_variables,
+        "pip":basic_variables,
+        "pim":basic_variables,
+        "Kp":basic_variables,
+        "Km":basic_variables,
+    }
+
+    mytuple = Funtuple(
+        name=name,
+        tuple_name="DecayTree",
+        fields=branches,
+        variables=variables,
+        event_variables=make_hlt2_event_variables(options, pvs, rec_summary),
+        inputs=input_data,
+        store_multiple_cand_info=True)
+
+    return [myfilter, mytuple]
+
+
+def maketuple_BpToLcpLcmKp(options, pvs, rec_summary):
+
+    name = "BuToLcpLcmK"
+    turbo_line = "SpruceB2OC_BuToLcpLcmK_LcpToPKPi"
+    input_data = get_particles(f"/Event/Spruce/{turbo_line}/Particles")
+
+
+    myfilter = create_lines_filter(
+        f"LineFilter_{turbo_line}_{{hash}}",
+        [turbo_line],
+    )
+
+    branches = {
+        "Bp":"[B+ -> (Lambda_c+ -> p+ K- pi+) (Lambda_c~- -> p~- K+ pi-) K+]CC",
+        "Lcp":"[B+ -> ^(Lambda_c+ -> p+ K- pi+) (Lambda_c~- -> p~- K+ pi-) K+]CC",
+        "Lcm":"[B+ -> (Lambda_c+ -> p+ K- pi+) ^(Lambda_c~- -> p~- K+ pi-) K+]CC",
+        "pp":"[B+ -> (Lambda_c+ -> ^p+ K- pi+) (Lambda_c~- -> p~- K+ pi-) K+]CC",
+        "pm":"[B+ -> (Lambda_c+ -> p+ K- pi+) (Lambda_c~- -> ^p~- K+ pi-) K+]CC",
+        "pip":"[B+ -> (Lambda_c+ -> p+ K- ^pi+) (Lambda_c~- -> p~- K+ pi-) K+]CC",
+        "pim":"[B+ -> (Lambda_c+ -> p+ K- pi+) (Lambda_c~- -> p~- K+ ^pi-) K+]CC",
+        "Kp":"[B+ -> (Lambda_c+ -> p+ K- pi+) (Lambda_c~- -> p~- ^K+ pi-) K+]CC",
+        "Km":"[B+ -> (Lambda_c+ -> p+ ^K- pi+) (Lambda_c~- -> p~- K+ pi-) K+]CC",
+        "Kp_ext":"[B+ -> (Lambda_c+ -> p+ K- pi+) (Lambda_c~- -> p~- K+ pi-) ^K+]CC",
+    }
+    
+    DTF_MASS = DecayTreeFitter(
+        name='DTF_{hash}', 
+        input_particles=input_data,
+        mass_constraints=["Lambda_c+"],)
+
+    DTF_MASS_OWNPV = DecayTreeFitter(
+        name='DTF_{hash}', 
+        input_particles=input_data,
+        mass_constraints=["Lambda_c+"],
+        constrain_to_ownpv=True,)
+
+
+    # B_Data_unbiasedpv = ParticleUnbiasedPVAdder(
+    #     InputParticles=input_data, PrimaryVertices=get_extended_pvs()
+    # ).OutputParticles
+
+    # DTF_UnbiasedPV = DecayTreeFitter(
+    #     name="DTF_UnbiasedPV",
+    #     input_particles=B_Data_unbiasedpv,
+    #     mass_constraints=["Lambda_c+"],
+    #     constrain_to_ownpv=True,
+    # )
+
+    basic_variables = make_basic_variables(options, pvs, input_data) 
+
+    composite_variables_3body = make_composite_variables_3body(options, pvs, input_data) +\
+        make_composite_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_MASS, pv_constraint=False, three_body=True, mass_constraint=True,particle_name="") +\
+        make_composite_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_MASS_OWNPV, pv_constraint=False, three_body=True, mass_constraint=True,particle_name="_OWNPV") #same as BEST
+    
+    MVA_variables = make_MVA_variables()
+
+    variables = {
+        "Bp": composite_variables_3body + MVA_variables,
+        "Lcp": composite_variables_3body,
+        "Lcm": composite_variables_3body,
+        "pp": basic_variables,
+        "pm": basic_variables,
+        "pip": basic_variables,
+        "pim": basic_variables,
+        "Kp": basic_variables,
+        "Km": basic_variables,
+        "Kp_ext": basic_variables,
+    }
+
+    # composite_variables_3body = make_composite_variables_3body(options, pvs, input_data) +\
+    #     make_composite_dtf_variables(options, get_extended_pvs(), input_data, add_truth=True, DTF=DTF_UnbiasedPV, pv_constraint=False, three_body=True, mass_constraint=True,particle_name="_UnbiasedPV")
+
+
+    # variablesUnbiased = {
+    #     "Bp": composite_variables_3body + MVA_variables,
+    #     "Lcp": composite_variables_3body,
+    #     "Lcm": composite_variables_3body,
+    #     "pp": basic_variables,
+    #     "pm": basic_variables,
+    #     "pip": basic_variables,
+    #     "pim": basic_variables,
+    #     "Kp": basic_variables,
+    #     "Km": basic_variables,
+    #     "Kp_ext": basic_variables,
+    # }
+
+    mytuple = Funtuple(
+        name=name,
+        tuple_name="DecayTree",
+        fields=branches,
+        variables=variables,
+        event_variables=make_hlt2_event_variables(options, pvs, rec_summary),
+        inputs=input_data,
+        store_multiple_cand_info=True)
+    
+    # mytupleUnbiased = Funtuple(
+    #     name=name+"_Unbiased",
+    #     tuple_name="DecayTree",
+    #     fields=branches,
+    #     variables=variablesUnbiased,
+    #     event_variables=make_hlt2_event_variables(options, pvs, rec_summary),
+    #     inputs=B_Data_unbiasedpv,
+    #     store_multiple_cand_info=True)
+
+    return [myfilter, mytuple]
+
+
+
diff --git a/Liv_Lb0NeutronLines/options/tupling.py b/Liv_Lb0NeutronLines/options/tupling.py
index 2928987b23..13ebf15ded 100644
--- a/Liv_Lb0NeutronLines/options/tupling.py
+++ b/Liv_Lb0NeutronLines/options/tupling.py
@@ -71,36 +71,33 @@ Hlt1_global_lines = [
 ]
 Hlt1_1track_lines = [
     "Hlt1TrackMVADecision",
-    "Hlt1LowPtMuonDecision",
-    "Hlt1SingleHighPtMuonDecision",
-    "Hlt1SingleHighPtMuonNoMuIDDecision",
-    "Hlt1TrackMuonMVADecision",
-    "Hlt1OneMuonTrackLineDecision",
-    "Hlt1TrackElectronMVADecision",
-    "Hlt1SingleHighPtElectronDecision",
-    "Hlt1SingleHighEtDecision",
+    # "Hlt1LowPtMuonDecision",
+    # "Hlt1SingleHighPtMuonDecision",
+    # "Hlt1SingleHighPtMuonNoMuIDDecision",
+    # "Hlt1TrackMuonMVADecision",
+    # "Hlt1OneMuonTrackLineDecision",
+    # "Hlt1TrackElectronMVADecision",
+    # "Hlt1SingleHighPtElectronDecision",
+    # "Hlt1SingleHighEtDecision",
 ]
 Hlt1_lines = Hlt1_1track_lines+[
-    "Hlt1TwoTrackMVACharmXSecDecision",
+    # "Hlt1TwoTrackMVACharmXSecDecision",
     "Hlt1TwoTrackMVADecision",
-    "Hlt1TwoTrackKsDecision",
-    "Hlt1D2KPiDecision",
-    "Hlt1D2KKDecision",
-    "Hlt1D2PiPiDecision",
-    "Hlt1KsToPiPiDecision",
-    "Hlt1LowPtDiMuonDecision",#removed
-    "Hlt1DiMuonNoIPDecision",
-    "Hlt1DiMuonNoIP_ssDecision",
-    "Hlt1DiMuonHighMassDecision",
-    "Hlt1DiMuonLowMassDecision",#replaced by Hlt1DiMuonDisplacedDecision
-    "Hlt1DiMuonSoftDecision",
-    "Hlt1DiMuonDisplacedDecision",
-    "Hlt1TwoKsDecision",
-    "Hlt1D2KPiAlignmentDecision",
-    "Hlt1DiMuonHighMassAlignmentDecision",
-    "Hlt1DisplacedDiMuonAlignmentDecision",
-    "Hlt1DisplacedDielectronDecision",
-    "Hlt1DisplacedLeptonsDecision",#removed
+    # "Hlt1TwoTrackKsDecision",
+    # "Hlt1D2KPiDecision",
+    # "Hlt1D2KKDecision",
+    # "Hlt1D2PiPiDecision",
+    # "Hlt1KsToPiPiDecision",
+    # "Hlt1DiMuonNoIPDecision",
+    # "Hlt1DiMuonNoIP_ssDecision",
+    # "Hlt1DiMuonHighMassDecision",
+    # "Hlt1DiMuonSoftDecision",
+    # "Hlt1DiMuonDisplacedDecision",
+    # "Hlt1TwoKsDecision",
+    # "Hlt1D2KPiAlignmentDecision",
+    # "Hlt1DiMuonHighMassAlignmentDecision",
+    # "Hlt1DisplacedDiMuonAlignmentDecision",
+    # "Hlt1DisplacedDielectronDecision",
 ]
 
 Hlt2_lines = [
@@ -108,6 +105,8 @@ Hlt2_lines = [
     "Hlt2Topo3Body_Decision",
     "Hlt2B2OC_Lb0ToLcpLcmN0",
     "Hlt2B2OC_BuToLcpLcmK_LcpToPKPi",
+    "SpruceB2OC_Lb0ToLcpLcmN0",
+    "SpruceB2OC_BuToLcpLcmK_LcpToPKPi"
 ]
 
 def make_MVA_variables():
@@ -177,7 +176,7 @@ def make_MVA_variables():
     return variables
     
 
-def make_composite_variables(options, pvs, data, add_truth=True):
+def make_composite_variables(options, pvs, data, add_truth=True, add_tistos= True):
     if not options.simulation:
         add_truth = False
     variables = (
@@ -185,6 +184,7 @@ def make_composite_variables(options, pvs, data, add_truth=True):
            {
                "ID": F.PARTICLE_ID,
                "CHARGE": F.CHARGE,
+               "VCHI2DOF": F.CHI2DOF, #CHI2VXNDOF,
                "M12": F.SUBCOMB(Functor=F.MASS, Indices=(1, 2)),
                "MAXPT": F.MAX(F.PT),
                "MINPT": F.MIN(F.PT),
@@ -195,45 +195,39 @@ def make_composite_variables(options, pvs, data, add_truth=True):
                "BPVDIRA": F.BPVDIRA(pvs),
                "BPVFDCHI2": F.BPVFDCHI2(pvs),
                "BPVFD": F.BPVFD(pvs),
-               "BPVFDIR": F.BPVFDIR(pvs),
-               "BPVFDVEC": F.BPVFDVEC(pvs),
                "BPVVDRHO": F.BPVVDRHO(pvs),
-               "BPVVDZ": F.BPVVDZ(pvs),
                "BPVX": F.BPVX(pvs),
                "BPVY": F.BPVY(pvs),
                "BPVZ": F.BPVZ(pvs),
                "BPVIPCHI2": F.BPVIPCHI2(pvs),
+               "LOGBPVIPCHI2": log(F.BPVIPCHI2(pvs)),
                "BPVIP": F.BPVIP(pvs),
                "MINIPCHI2"   : F.MINIPCHI2(pvs),
                "MINIP"       : F.MINIP(pvs),
                "BPVLTIME": F.BPVLTIME(pvs),
-               "VCHI2DOF": F.CHI2DOF, #CHI2VXNDOF
-               "VCHI2": F.CHI2,
-               "LOGBPVIPCHI2": log(F.BPVIPCHI2(pvs)),
                "MAXBPVIPCHI2": F.MAX(F.BPVIPCHI2(pvs)), #MAX_
                "MINBPVIPCHI2": F.MIN(F.BPVIPCHI2(pvs)),
                "MAXBPVIP": F.MAX(F.BPVIP(pvs)),
                "MINBPVIP": F.MIN(F.BPVIP(pvs)),
                "MAXDOCACHI2": F.MAXDOCACHI2,
                "MAXDOCA": F.MAXDOCA,
-               "DOCA12"      : F.DOCA(Child1=1,Child2=2),
-               "DOCACHI212"  : F.DOCACHI2(Child1=1,Child2=2),
+               "DOCA_12"      : F.DOCA(Child1=1,Child2=2),
+               "DOCACHI2_12"  : F.DOCACHI2(Child1=1,Child2=2),
                "ETA": F.ETA,
                "PHI": F.PHI,
                "END_VX": F.END_VX, #END_
                "END_VY": F.END_VY,
                "END_VZ": F.END_VZ,
                "END_VCHI2DOF": F.CHI2DOF @ F.ENDVERTEX,
-               "ALLPVFD"     : F.ALLPV_FD(pvs),
-               "ALLPVIP"     : F.ALLPV_IP(pvs),
            }
        )
        + Kinematics()
     )
 
-    variables += HltTisTos(
-        selection_type="Hlt1", trigger_lines=Hlt1_lines, data=data
-    )
+    if add_tistos:
+        variables += HltTisTos(
+            selection_type="Hlt1", trigger_lines=Hlt1_lines, data=data
+        )
 
     if add_truth:
         variables = add_truth_matching_functors(
@@ -262,7 +256,7 @@ def make_tistoscombinations(options, pvs, data):
 
     return tistos_combinations
 
-def make_composite_variables_3body(options, pvs, data, add_truth=True):
+def make_composite_variables_3body(options, pvs, data, add_truth=True, add_tistos= True):
 
     variables = (
         FunctorCollection(
@@ -280,7 +274,14 @@ def make_composite_variables_3body(options, pvs, data, add_truth=True):
             }
         )
     )
-    return make_composite_variables(options, pvs, data, add_truth)+make_tistoscombinations(options, pvs, data)+variables
+
+    variables += make_composite_variables(options, pvs, data, add_truth, add_tistos)
+
+    if add_tistos:
+        variables += make_tistoscombinations(options, pvs, data)
+
+
+    return variables
 
 def make_composite_variables_4body(options, pvs, data, add_truth=True):
 
@@ -310,55 +311,42 @@ def make_composite_variables_4body(options, pvs, data, add_truth=True):
 def make_DeltaM_variable(options):
     return FunctorCollection({"DM": F.MASS - F.CHILD(1, F.MASS)})
 
-def make_basic_variables(options, pvs, data, add_truth=True):
+def make_basic_variables(options, pvs, data, add_truth=True, add_tistos=False):
     if not options.simulation:
         add_truth = False
     variables = (
        FunctorCollection(
            { 
+               "ID": F.PARTICLE_ID,
                "CHARGE": F.CHARGE,
                "TRCHI2DOF": F.CHI2DOF @ F.TRACK,
-               "TRCHI2": F.CHI2 @ F.TRACK,
+               "VCHI2DOF": F.CHI2DOF,
+               "TRGHOSTPROB": F.GHOSTPROB,
+               "TX"          : F.TX,
+               "TY"          : F.TY,
+               "QOVERP": F.QOVERP @ F.TRACK,
                "ETA": F.ETA,
                "PHI": F.PHI,
-               "TRGHOSTPROB": F.GHOSTPROB,
                "BPVIPCHI2": F.BPVIPCHI2(pvs),
                "BPVIP": F.BPVIP(pvs),
-               #"BPVETA": F.BPVETA(pvs),
-               #"BPVDLS": F.BPVDLS(pvs),
-               "BPVX": F.BPVX(pvs),
-               "BPVY": F.BPVY(pvs),
-               "BPVZ": F.BPVZ(pvs),
-               "TX"          : F.TX,
-               "TY"          : F.TY,
                "MINIPCHI2"   : F.MINIPCHI2(pvs),
                "MINIP"       : F.MINIP(pvs),
-               "KEY"         : F.VALUE_OR(-1) @ F.OBJECT_KEY @ F.TRACK,
-               "CTB"         : F.POSITION @ F.CLOSESTTOBEAM @ F.TRACK,
                "ISMUON"      : F.ISMUON,
-               "TRACKPT": F.TRACK_PT,
-               "TRACKHISTORY": F.VALUE_OR(-1) @ F.TRACKHISTORY @ F.TRACK,
-               "QOVERP": F.QOVERP @ F.TRACK,
-               "NDOF": F.VALUE_OR(-1) @ F.NDOF @ F.TRACK,
                "NFTHITS": F.VALUE_OR(-1) @ F.NFTHITS @ F.TRACK,
                "NHITS": F.VALUE_OR(-1) @ F.NHITS @ F.TRACK,
                "NUTHITS": F.VALUE_OR(-1) @ F.NUTHITS @ F.TRACK,
                "NVPHITS": F.VALUE_OR(-1) @ F.NVPHITS @ F.TRACK,
                "TRACKHASVELO": F.VALUE_OR(-1) @ F.TRACKHASVELO @ F.TRACK,
-               "TRACKHASUT": F.VALUE_OR(-1) @ F.TRACKHASUT @ F.TRACK,
-               "OBJECT_KEY": F.OBJECT_KEY,
-               "HASBREM": F.HASBREM,
-               "BREMENERGY": F.BREMENERGY,
-               "BREMBENDCORR": F.BREMBENDCORR,
+    
            }
        )
        + Kinematics()
        + ParticleID(extra_info=True)
     )
-
-    variables += HltTisTos(
-        selection_type="Hlt1", trigger_lines=Hlt1_1track_lines, data=data
-    )
+    if add_tistos:
+        variables += HltTisTos(
+            selection_type="Hlt1", trigger_lines=Hlt1_1track_lines, data=data
+        )
 
     if add_truth:
         variables = add_truth_matching_functors(
@@ -377,14 +365,14 @@ def make_hlt2_event_variables(options, pvs, rec_summary):
     # define event level variables
     evt_variables = EventInfo()
     evt_variables += SelectionInfo(selection_type="Hlt2", trigger_lines=Hlt2_lines)
-    evt_variables += SelectionInfo(selection_type="Hlt1", trigger_lines=Hlt1_1track_lines)
+    evt_variables += SelectionInfo(selection_type="Hlt1", trigger_lines=Hlt1_lines)
     evt_variables += FunctorCollection(
         {
             "ALLPVX": F.ALLPVX(pvs),
             "ALLPVY": F.ALLPVY(pvs),
             "ALLPVZ": F.ALLPVZ(pvs),
             "nPVs": F.SIZE(pvs),
-            "nTracks": F.VALUE_OR(-1) @ F.RECSUMMARY_INFO(rec_summary, "nTracks"),
+            "nTracks": F.VALUE_OR(-1) @ F.RECSUMMARY_INFO(rec_summary, "nTracks"),# but always 0 ...
             "nLongTracks": F.VALUE_OR(-1) @ F.RECSUMMARY_INFO(rec_summary, "nLongTracks"),
             "nMuonTracks": F.VALUE_OR(-1) @ F.RECSUMMARY_INFO(rec_summary, "nMuonTracks"),
             "nFTClusters": F.VALUE_OR(-1) @ F.RECSUMMARY_INFO(rec_summary, "nFTClusters"),
@@ -546,30 +534,30 @@ def make_composite_dtf_variables(options, pvs, data, add_truth=True, DTF=None, p
     variables = (
         FunctorCollection(
             {
-                "MAXPT": F.MAX(F.PT),
-                "MINPT": F.MIN(F.PT),
-                "SUMPT": F.SUM(F.PT),
-                "MAXP": F.MAX(F.P),
-                "MINP": F.MIN(F.P),
-                "BPVDIRA": F.BPVDIRA(pvs),
-                "BPVFDCHI2": F.BPVFDCHI2(pvs),
-                "BPVFD": F.BPVFD(pvs),
-                "BPVVDRHO": F.BPVVDRHO(pvs),
-                "BPVVDZ": F.BPVVDZ(pvs),
-                "BPVIPCHI2": F.BPVIPCHI2(pvs),
-                "BPVIP": F.BPVIP(pvs),
-                "LOGBPVIPCHI2": log(F.BPVIPCHI2(pvs)),
-                "BPVLTIME": F.BPVLTIME(pvs),
-                "MAXBPVIPCHI2": F.MAX(F.BPVIPCHI2(pvs)), #MAX_
-                "MINBPVIPCHI2": F.MIN(F.BPVIPCHI2(pvs)),
-                "MAXBPVIP": F.MAX(F.BPVIP(pvs)),
-                "MINBPVIP": F.MIN(F.BPVIP(pvs)),
+                # "MAXPT": F.MAX(F.PT),
+                # "MINPT": F.MIN(F.PT),
+                # "SUMPT": F.SUM(F.PT),
+                # "MAXP": F.MAX(F.P),
+                # "MINP": F.MIN(F.P),
+                # "BPVDIRA": F.BPVDIRA(pvs),
+                # "BPVFDCHI2": F.BPVFDCHI2(pvs),
+                #"BPVFD": F.BPVFD(pvs),
+                # "BPVVDRHO": F.BPVVDRHO(pvs),
+                # "BPVVDZ": F.BPVVDZ(pvs),
+                # "BPVIPCHI2": F.BPVIPCHI2(pvs),
+                # "BPVIP": F.BPVIP(pvs),
+                # "LOGBPVIPCHI2": log(F.BPVIPCHI2(pvs)),
+                #"BPVLTIME": F.BPVLTIME(pvs),
+                # "MAXBPVIPCHI2": F.MAX(F.BPVIPCHI2(pvs)), #MAX_
+                # "MINBPVIPCHI2": F.MIN(F.BPVIPCHI2(pvs)),
+                # "MAXBPVIP": F.MAX(F.BPVIP(pvs)),
+                # "MINBPVIP": F.MIN(F.BPVIP(pvs)),
                 "M12": F.SUBCOMB(Functor=F.MASS, Indices=(1, 2)),
-                "ETA": F.ETA,
-                "PHI": F.PHI
+                # "ETA": F.ETA,
+                # "PHI": F.PHI
             }
         )
-        + Kinematics()
+        # + Kinematics()
         
         #+ ParticleID(extra_info=True) #only for daughters
     )
@@ -584,10 +572,18 @@ def make_composite_dtf_variables(options, pvs, data, add_truth=True, DTF=None, p
             
     dtf_extras = FunctorCollection(
         {
-            "DTF_NITER": DTF.NITER,
-            "DTF_CHI2": DTF.CHI2,
-            "DTF_NDOF": DTF.NDOF,
-            "DTF_CHI2DOF": DTF.CHI2DOF
+            "DTF"+particle_name+"_NITER": DTF.NITER,
+            "DTF"+particle_name+"_CHI2": DTF.CHI2,
+            "DTF"+particle_name+"_NDOF": DTF.NDOF,
+            "DTF"+particle_name+"_CHI2DOF": DTF.CHI2DOF,
+            "DTF"+particle_name+"_M": DTF.MASS,
+            "DTF"+particle_name+"_MERR": DTF.MASSERR,
+            "DTF"+particle_name+"_MERR": DTF.MASSERR,
+            "DTF"+particle_name+"_FD": DTF.FD,
+            "DTF"+particle_name+"_FDERR": DTF.FDERR,
+            "DTF"+particle_name+"_CTAU": DTF.CTAU,
+            "DTF"+particle_name+"_CTAUERR": DTF.CTAUERR,
+
         }
     )
 
-- 
GitLab


From 6d8d960f70aad6c3b783c846c6eb33e4d2e40951 Mon Sep 17 00:00:00 2001
From: Juan Leite <jbaptist@lxplus928.cern.ch>
Date: Sat, 17 Aug 2024 20:33:49 +0200
Subject: [PATCH 21/34] adding MCORR

---
 Liv_Lb0NeutronLines/options/tupling.py | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/Liv_Lb0NeutronLines/options/tupling.py b/Liv_Lb0NeutronLines/options/tupling.py
index 13ebf15ded..a0bd39d8a8 100644
--- a/Liv_Lb0NeutronLines/options/tupling.py
+++ b/Liv_Lb0NeutronLines/options/tupling.py
@@ -185,6 +185,8 @@ def make_composite_variables(options, pvs, data, add_truth=True, add_tistos= Tru
                "ID": F.PARTICLE_ID,
                "CHARGE": F.CHARGE,
                "VCHI2DOF": F.CHI2DOF, #CHI2VXNDOF,
+               "MCORR": F.BPVCORRM(pvs),#"MCorr": F.BPVCORRM(939.56542052), for lb0
+               "MCORRERR": F.BPVCORRMERR(pvs),
                "M12": F.SUBCOMB(Functor=F.MASS, Indices=(1, 2)),
                "MAXPT": F.MAX(F.PT),
                "MINPT": F.MIN(F.PT),
@@ -552,6 +554,8 @@ def make_composite_dtf_variables(options, pvs, data, add_truth=True, DTF=None, p
                 # "MINBPVIPCHI2": F.MIN(F.BPVIPCHI2(pvs)),
                 # "MAXBPVIP": F.MAX(F.BPVIP(pvs)),
                 # "MINBPVIP": F.MIN(F.BPVIP(pvs)),
+                "MCORR": F.BPVCORRM(pvs), #"MCorr": F.BPVCORRM(939.56542052), for lb0
+                "MCORRERR": F.BPVCORRMERR(pvs),
                 "M12": F.SUBCOMB(Functor=F.MASS, Indices=(1, 2)),
                 # "ETA": F.ETA,
                 # "PHI": F.PHI
-- 
GitLab


From b8f718a5e0c0662d54095f31940ebabc2ec3849d Mon Sep 17 00:00:00 2001
From: Juan Leite <jbaptist@lxplus928.cern.ch>
Date: Sat, 17 Aug 2024 20:37:19 +0200
Subject: [PATCH 22/34] Remove MC

---
 Liv_Lb0NeutronLines/info.yaml | 150 +++++++++++++++++-----------------
 1 file changed, 75 insertions(+), 75 deletions(-)

diff --git a/Liv_Lb0NeutronLines/info.yaml b/Liv_Lb0NeutronLines/info.yaml
index c0310c3b6d..aeb16aad69 100644
--- a/Liv_Lb0NeutronLines/info.yaml
+++ b/Liv_Lb0NeutronLines/info.yaml
@@ -17,85 +17,85 @@ defaults:
 ]%}
 
 
-{%- for p in polarities %}
-{%- for sigtype, simul, nu, inptype, evttype in mc_datasets %}
+# {%- for p in polarities %}
+# {%- for sigtype, simul, nu, inptype, evttype in mc_datasets %}
 
-{{sigtype}}_Mag{{p}}_MC_HLT1:
-  application: "Moore/v55r11p2@x86_64_v2-el9-gcc13+detdesc-opt"
-  input: 
-    bk_query: /MC/Dev/Beam6800GeV-expected-2024-Mag{{p}}-Nu{{nu}}-25ns-Pythia8/{{simul}}/{{evttype}}/{{inptype}}
-    # n_test_lfns: 10
-    dq_flags:
-      - OK
-  output: MC_HLT1.DST
-  options: 
-    entrypoint: Liv_Lb0NeutronLines.hlt1:alg_config
-    extra_options:
-      input_raw_format: 0.5
-      conddb_tag: sim-20231017-vc-md100
-      dddb_tag: dddb-20231017
-      input_type: ROOT
-      output_type: ROOT
-      simulation: True
-      data_type: "Upgrade"
-      # evt_max: 1000
-      # print_freq: 100
-      scheduler_legacy_mode: False
-      compression:
-        algorithm: ZSTD
-        level: 1
-        max_buffer_size: 1048576
+# {{sigtype}}_Mag{{p}}_MC_HLT1:
+#   application: "Moore/v55r11p2@x86_64_v2-el9-gcc13+detdesc-opt"
+#   input: 
+#     bk_query: /MC/Dev/Beam6800GeV-expected-2024-Mag{{p}}-Nu{{nu}}-25ns-Pythia8/{{simul}}/{{evttype}}/{{inptype}}
+#     # n_test_lfns: 10
+#     dq_flags:
+#       - OK
+#   output: MC_HLT1.DST
+#   options: 
+#     entrypoint: Liv_Lb0NeutronLines.hlt1:alg_config
+#     extra_options:
+#       input_raw_format: 0.5
+#       conddb_tag: sim-20231017-vc-md100
+#       dddb_tag: dddb-20231017
+#       input_type: ROOT
+#       output_type: ROOT
+#       simulation: True
+#       data_type: "Upgrade"
+#       # evt_max: 1000
+#       # print_freq: 100
+#       scheduler_legacy_mode: False
+#       compression:
+#         algorithm: ZSTD
+#         level: 1
+#         max_buffer_size: 1048576
 
-{{sigtype}}_Mag{{p}}_MC_HLT2:
-  application: "Moore/v55r11p2@x86_64_v2-el9-gcc13+detdesc-opt"
-  input:
-    job_name: {{sigtype}}_Mag{{p}}_MC_HLT1
-  output: MC_HLT2_full.DST
-  options:
-    entrypoint: Liv_Lb0NeutronLines.hlt2:alg_config
-    extra_options:
-      conddb_tag: sim-20231017-vc-md100
-      dddb_tag: dddb-20231017
-      input_type: "ROOT"
-      output_type: "ROOT"
-      simulation: True
-      input_process: "Hlt2"
-      persistreco_version: 0.0
-      data_type: "Upgrade"
-      evt_max: -1
-      output_manifest_file: "HLT2.tck.json"
-      scheduler_legacy_mode: False
-      compression:
-        algorithm: ZSTD
-        level: 1
-        max_buffer_size: 1048576
+# {{sigtype}}_Mag{{p}}_MC_HLT2:
+#   application: "Moore/v55r11p2@x86_64_v2-el9-gcc13+detdesc-opt"
+#   input:
+#     job_name: {{sigtype}}_Mag{{p}}_MC_HLT1
+#   output: MC_HLT2_full.DST
+#   options:
+#     entrypoint: Liv_Lb0NeutronLines.hlt2:alg_config
+#     extra_options:
+#       conddb_tag: sim-20231017-vc-md100
+#       dddb_tag: dddb-20231017
+#       input_type: "ROOT"
+#       output_type: "ROOT"
+#       simulation: True
+#       input_process: "Hlt2"
+#       persistreco_version: 0.0
+#       data_type: "Upgrade"
+#       evt_max: -1
+#       output_manifest_file: "HLT2.tck.json"
+#       scheduler_legacy_mode: False
+#       compression:
+#         algorithm: ZSTD
+#         level: 1
+#         max_buffer_size: 1048576
         
-{{sigtype}}_Mag{{p}}_MC_Tuple:
-  application: "DaVinci/v64r8@x86_64_v2-el9-clang16+detdesc-opt"
-  input:
-    job_name: {{sigtype}}_Mag{{p}}_MC_HLT2
-  output: MC_{{sigtype}}.ROOT
-  options:
-    entrypoint: Liv_Lb0NeutronLines.main_Liv_{{sigtype}}:main
-    extra_options:
-      input_raw_format: 0.5
-      input_type: ROOT
-      simulation: True
-      data_type: Upgrade
-      conddb_tag: sim-20231017-vc-md100
-      dddb_tag: dddb-20231017
-      input_process: "Hlt2"
-      conditions_version: master
-      geometry_version: run3/trunk
-      lumi: false
-      output_type: ROOT
-      persistreco_version: 1.0
-      write_decoding_keys_to_git: True
-      input_manifest_file: "HLT2.tck.json"
-      input_stream: default
+# {{sigtype}}_Mag{{p}}_MC_Tuple:
+#   application: "DaVinci/v64r8@x86_64_v2-el9-clang16+detdesc-opt"
+#   input:
+#     job_name: {{sigtype}}_Mag{{p}}_MC_HLT2
+#   output: MC_{{sigtype}}.ROOT
+#   options:
+#     entrypoint: Liv_Lb0NeutronLines.main_Liv_{{sigtype}}:main
+#     extra_options:
+#       input_raw_format: 0.5
+#       input_type: ROOT
+#       simulation: True
+#       data_type: Upgrade
+#       conddb_tag: sim-20231017-vc-md100
+#       dddb_tag: dddb-20231017
+#       input_process: "Hlt2"
+#       conditions_version: master
+#       geometry_version: run3/trunk
+#       lumi: false
+#       output_type: ROOT
+#       persistreco_version: 1.0
+#       write_decoding_keys_to_git: True
+#       input_manifest_file: "HLT2.tck.json"
+#       input_stream: default
 
-{%- endfor %}
-{%- endfor %}
+# {%- endfor %}
+# {%- endfor %}
 
 ###################
 ## DATA:
-- 
GitLab


From 725ec44f040324890054265c5e007f4d92bd5823 Mon Sep 17 00:00:00 2001
From: Juan Leite <jbaptist@lxplus928.cern.ch>
Date: Sat, 17 Aug 2024 20:41:45 +0200
Subject: [PATCH 23/34] Remove Excl-UT MagUp

---
 Liv_Lb0NeutronLines/info.yaml | 55 ++++++++++++++++++-----------------
 1 file changed, 28 insertions(+), 27 deletions(-)

diff --git a/Liv_Lb0NeutronLines/info.yaml b/Liv_Lb0NeutronLines/info.yaml
index aeb16aad69..ecd484e316 100644
--- a/Liv_Lb0NeutronLines/info.yaml
+++ b/Liv_Lb0NeutronLines/info.yaml
@@ -130,33 +130,34 @@ defaults:
 {%- endfor %}
 
 
-{%- for p in polarities %}
-{%- for sigtype, simul, nu, inptype, evttype in mc_datasets %}
-{{sigtype}}_Mag{{p}}_Data_Hlt2_ExclUT_Spc2_Tuple:
-  application: "DaVinci/v64r8@x86_64_v2-el9-clang16-opt"
-  input:
-    bk_query: /LHCb/Collision24/Beam6800GeV-VeloClosed-Mag{{p}}-Excl-UT/Real Data/Sprucing24c2/94000000/B2OC.DST
-    dq_flags:
-      - UNCHECKED
-      - OK
-    keep_running: True
-  output: RealData_{{sigtype}}.ROOT
-  options:
-    entrypoint: Liv_Lb0NeutronLines.main_Liv_{{sigtype}}:main
-    extra_options:
-      input_raw_format: 0.5
-      input_type: ROOT
-      simulation: False
-      data_type: Upgrade
-      geometry_version: run3/trunk
-      conditions_version: master
-      input_process: "TurboPass"
-      input_stream: "b2oc"
-      evt_max: 50000
-      # print_freq: 1000
-      #first_evt: 1
-{%- endfor %}
-{%- endfor %}
+# -------------------------------Why there is no MagUp?
+# {%- for p in polarities %}
+# {%- for sigtype, simul, nu, inptype, evttype in mc_datasets %}
+# {{sigtype}}_Mag{{p}}_Data_Hlt2_ExclUT_Spc2_Tuple:
+#   application: "DaVinci/v64r8@x86_64_v2-el9-clang16-opt"
+#   input:
+#     bk_query: /LHCb/Collision24/Beam6800GeV-VeloClosed-Mag{{p}}-Excl-UT/Real Data/Sprucing24c2/94000000/B2OC.DST
+#     dq_flags:
+#       - UNCHECKED
+#       - OK
+#     keep_running: True
+#   output: RealData_{{sigtype}}.ROOT
+#   options:
+#     entrypoint: Liv_Lb0NeutronLines.main_Liv_{{sigtype}}:main
+#     extra_options:
+#       input_raw_format: 0.5
+#       input_type: ROOT
+#       simulation: False
+#       data_type: Upgrade
+#       geometry_version: run3/trunk
+#       conditions_version: master
+#       input_process: "TurboPass"
+#       input_stream: "b2oc"
+#       evt_max: 50000
+#       # print_freq: 1000
+#       #first_evt: 1
+# {%- endfor %}
+# {%- endfor %}
 
 # I don't have HLT2 24c1 for Lb0 channels here
 {%- set mc_datasets = [
-- 
GitLab


From 2e3939e0c6b85962630ee9e5e4808dc71ba85a66 Mon Sep 17 00:00:00 2001
From: Juan Leite <jbaptist@lxplus928.cern.ch>
Date: Sat, 17 Aug 2024 20:53:40 +0200
Subject: [PATCH 24/34] comment all evt_max

---
 Liv_Lb0NeutronLines/info.yaml | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/Liv_Lb0NeutronLines/info.yaml b/Liv_Lb0NeutronLines/info.yaml
index ecd484e316..43cd02a9a1 100644
--- a/Liv_Lb0NeutronLines/info.yaml
+++ b/Liv_Lb0NeutronLines/info.yaml
@@ -123,7 +123,7 @@ defaults:
       conditions_version: master
       input_process: "TurboPass"
       input_stream: "b2oc"
-      evt_max: 50000
+      # evt_max: 50000
       # print_freq: 1000
       #first_evt: 1
 {%- endfor %}
@@ -186,7 +186,7 @@ defaults:
       conditions_version: master
       input_process: "TurboPass"
       input_stream: "b2oc"
-      evt_max: 50000
+      # evt_max: 50000
       # print_freq: 1000
       #first_evt: 1
 {%- endfor %}
@@ -222,7 +222,7 @@ defaults:
       conditions_version: master
       input_process: "Spruce"
       input_stream: "b2oc"
-      evt_max: 50000
+      # evt_max: 50000
       # print_freq: 1000
       #first_evt: 1
 {%- endfor %}
-- 
GitLab


From 218beebc00d4445f5964b657a72a378aca2afb6f Mon Sep 17 00:00:00 2001
From: Juan Leite <jbaptist@lxplus974.cern.ch>
Date: Wed, 21 Aug 2024 21:13:05 +0200
Subject: [PATCH 25/34] add Lb0->ppbar channel

---
 Liv_Lb0NeutronLines/hlt1.py                   |  13 +-
 Liv_Lb0NeutronLines/hlt2.py                   |  96 +-
 Liv_Lb0NeutronLines/info.yaml                 | 224 ++---
 Liv_Lb0NeutronLines/main_Liv_Lb0ToPpPmN0.py   |   4 +-
 .../main_Liv_Lb0ToPpPmN0_Spuce.py             |  32 +
 .../options/Lb_NeutronLines_HLT2.py           | 206 ++--
 .../options/Lb_NeutronLines_Spruce.py         | 198 ++--
 Liv_Lb0NeutronLines/options/tupling.py        | 938 ++++++++++--------
 8 files changed, 877 insertions(+), 834 deletions(-)
 create mode 100644 Liv_Lb0NeutronLines/main_Liv_Lb0ToPpPmN0_Spuce.py

diff --git a/Liv_Lb0NeutronLines/hlt1.py b/Liv_Lb0NeutronLines/hlt1.py
index 7d04cf6537..8765323b88 100644
--- a/Liv_Lb0NeutronLines/hlt1.py
+++ b/Liv_Lb0NeutronLines/hlt1.py
@@ -1,11 +1,14 @@
 """
-Stolen verbatim from Hlt/Hlt1Conf/options/hlt1_pp_expected_24_without_UT.py from v55r7
+Stolen verbatim from Hlt/Hlt1Conf/options/hlt1_pp_expected_24_without_UT.py from https://gitlab.cern.ch/lhcb/Moore/-/merge_requests/3620/diffs
+ - Added @cburr's AgeLimit to reduce memory consumption
 """
 from Moore import Options
-from Moore.config import run_allen
-from RecoConf.hlt1_allen import allen_gaudi_config as allen_sequence
+from Moore.production import hlt1
 
 
 def alg_config(options: Options):
-    with allen_sequence.bind(sequence="hlt1_pp_matching_no_ut_1000KHz"):
-        return run_allen(options)
+    config = hlt1(options, "--sequence=hlt1_pp_matching_no_ut_1000KHz",
+                  "--flagging")
+    # Will be the default in releases including https://gitlab.cern.ch/lhcb/LHCb/-/merge_requests/4641
+    config["Gaudi::IODataManager/IODataManager"].AgeLimit = 0
+    return config
diff --git a/Liv_Lb0NeutronLines/hlt2.py b/Liv_Lb0NeutronLines/hlt2.py
index 9c88df33fd..dd304ca2d9 100644
--- a/Liv_Lb0NeutronLines/hlt2.py
+++ b/Liv_Lb0NeutronLines/hlt2.py
@@ -1,70 +1,36 @@
-####################################
-# options                          #
-####################################
-
-import Moore
-from Moore import Options, run_moore, config
-from Moore.lines import Hlt2Line
-from RecoConf.reconstruction_objects import reconstruction as reconstruction
-from Moore import options, run_moore
-from RecoConf.global_tools import stateProvider_with_simplified_geom, trackMasterExtrapolator_with_simplified_geom
-from RecoConf.hlt2_global_reco import reconstruction as hlt2_reconstruction, make_light_reco_pr_kf
-from RecoConf.hlt2_tracking import (
-    make_TrackBestTrackCreator_tracks,
-    make_PrKalmanFilter_noUT_tracks,
-    make_PrKalmanFilter_Velo_tracks,
-    make_PrKalmanFilter_Seed_tracks,
-)
-from RecoConf.protoparticles import make_charged_protoparticles
-from Hlt2Conf.settings.defaults import get_default_hlt1_filter_code_for_hlt2
-from RecoConf.decoders import default_VeloCluster_source
-from RecoConf.event_filters import require_gec
-from Moore.streams import Stream, Streams, DETECTORS
-import sys
-
-
-from Hlt2Conf.lines.b_to_open_charm import all_lines 
-
-
-
-################## options ############
-    
-public_tools = [
-    trackMasterExtrapolator_with_simplified_geom(),
-    stateProvider_with_simplified_geom(),
-]
-
-def pass_through_line(name="Hlt2MCPassThroughLine"):
-    """Return a HLT2 line that performs no selection but runs and persists the reconstruction
-    """
-    return Hlt2Line(name=name, prescale=1, algs=[], persistreco=True)
-
-def make_streams():
-    lines = [builder() for builder in all_lines.values()]
-    lines += [pass_through_line()]
-    streams = [
-        Stream(
-            lines=lines,
-            routing_bit=98,
-            detectors=DETECTORS)
+"""
+Stolen and adapted from Hlt/Hlt2Conf/options/hlt2_pp_expected_24_without_UT.py from v55r11.
+ - Added @cburr's AgeLimit to reduce memory consumption
+"""
+from Moore import Options
+from RecoConf.reconstruction_objects import reconstruction
+
+from Hlt2Conf.lines.mc.mc_lines import MC_HLT2_PASSTHROUGH_LINE_NAME
+from Hlt2Conf.lines.b_to_open_charm import all_lines
+
+
+def _make_regex():
+    """Use some QEE lines for the sake of example."""
+    # Here we 'brute-force' this regex via a regex of each individual line name we want to consider.
+    # A neater format is possible via knowing how the lines are named but this feels almost less robust.
+    lnames = [
+        linename for line_dict in [all_lines] for linename in line_dict.keys()
     ]
-    return Streams(streams=streams)
-
-
+    lnames.append(MC_HLT2_PASSTHROUGH_LINE_NAME)
+    return f"({'|'.join(lnames)})"
 
-# def _make_lines():
-#     #mylines = [builder() for builder in all_lines.values()],
-#     mylines = [twobody_line(persistreco=True), threebody_line(persistreco=True)]
-#     return mylines
-
-
-def make_streams(real_make_streams=make_streams):
-    with reconstruction.bind(from_file=False), \
-        hlt2_reconstruction.bind(make_reconstruction=make_light_reco_pr_kf):
-    
-        return real_make_streams()
 
 def alg_config(options: Options):
-    config = run_moore(options, make_streams=make_streams, public_tools=[])
+    with reconstruction.bind(from_file=False):
+        from Moore.production import hlt2
+        # Rather than processing via Moore:run_moore, using Moore.production:hlt2 emulates MC centralised processing.
+        hlt2_extra_args = [
+            '--flagging',  # prescales+postscales removed + passthrough_line added
+            '--settings=hlt2_pp_2024',  # Decides which settings to create the streams from
+            f'--lines-regex={_make_regex()}',  # Filters the settings to only run the lines you wish
+        ]
+        # instantiates public_tools and run_moore
+        config = hlt2(options, *hlt2_extra_args)
+    # Will be the default in releases including https://gitlab.cern.ch/lhcb/LHCb/-/merge_requests/4641
+    config["Gaudi::IODataManager/IODataManager"].AgeLimit = 0
     return config
-
diff --git a/Liv_Lb0NeutronLines/info.yaml b/Liv_Lb0NeutronLines/info.yaml
index 43cd02a9a1..5e3f80df6d 100644
--- a/Liv_Lb0NeutronLines/info.yaml
+++ b/Liv_Lb0NeutronLines/info.yaml
@@ -13,92 +13,93 @@ defaults:
 
 {%- set mc_datasets = [
  ('Lb0ToLcpLcmN0', 'Sim10c' , '7.6', 'DIGI', '15196810'),
- ('BpToLcpLcmKp', 'Sim10c' , '7.6', 'DIGI', '12197003')
+ ('BpToLcpLcmKp', 'Sim10c' , '7.6', 'DIGI', '12197003'),
+ ('Lb0ToPbarPN0','Sim10c','7.6','DIGI','15102831'),
 ]%}
 
 
-# {%- for p in polarities %}
-# {%- for sigtype, simul, nu, inptype, evttype in mc_datasets %}
-
-# {{sigtype}}_Mag{{p}}_MC_HLT1:
-#   application: "Moore/v55r11p2@x86_64_v2-el9-gcc13+detdesc-opt"
-#   input: 
-#     bk_query: /MC/Dev/Beam6800GeV-expected-2024-Mag{{p}}-Nu{{nu}}-25ns-Pythia8/{{simul}}/{{evttype}}/{{inptype}}
-#     # n_test_lfns: 10
-#     dq_flags:
-#       - OK
-#   output: MC_HLT1.DST
-#   options: 
-#     entrypoint: Liv_Lb0NeutronLines.hlt1:alg_config
-#     extra_options:
-#       input_raw_format: 0.5
-#       conddb_tag: sim-20231017-vc-md100
-#       dddb_tag: dddb-20231017
-#       input_type: ROOT
-#       output_type: ROOT
-#       simulation: True
-#       data_type: "Upgrade"
-#       # evt_max: 1000
-#       # print_freq: 100
-#       scheduler_legacy_mode: False
-#       compression:
-#         algorithm: ZSTD
-#         level: 1
-#         max_buffer_size: 1048576
+{%- for p in polarities %}
+{%- for sigtype, simul, nu, inptype, evttype in mc_datasets %}
 
-# {{sigtype}}_Mag{{p}}_MC_HLT2:
-#   application: "Moore/v55r11p2@x86_64_v2-el9-gcc13+detdesc-opt"
-#   input:
-#     job_name: {{sigtype}}_Mag{{p}}_MC_HLT1
-#   output: MC_HLT2_full.DST
-#   options:
-#     entrypoint: Liv_Lb0NeutronLines.hlt2:alg_config
-#     extra_options:
-#       conddb_tag: sim-20231017-vc-md100
-#       dddb_tag: dddb-20231017
-#       input_type: "ROOT"
-#       output_type: "ROOT"
-#       simulation: True
-#       input_process: "Hlt2"
-#       persistreco_version: 0.0
-#       data_type: "Upgrade"
-#       evt_max: -1
-#       output_manifest_file: "HLT2.tck.json"
-#       scheduler_legacy_mode: False
-#       compression:
-#         algorithm: ZSTD
-#         level: 1
-#         max_buffer_size: 1048576
+{{sigtype}}_Mag{{p}}_MC_HLT1:
+  application: "Moore/v55r11p2@x86_64_v2-el9-gcc13+detdesc-opt"
+  input: 
+    bk_query: /MC/Dev/Beam6800GeV-expected-2024-Mag{{p}}-Nu{{nu}}-25ns-Pythia8/{{simul}}/{{evttype}}/{{inptype}}
+    n_test_lfns: 10
+    dq_flags:
+      - OK
+  output: MC_HLT1.DST
+  options: 
+    entrypoint: Liv_Lb0NeutronLines.hlt1:alg_config
+    extra_options:
+      input_raw_format: 0.5
+      conddb_tag: sim-20231017-vc-md100
+      dddb_tag: dddb-20231017
+      input_type: ROOT
+      output_type: ROOT
+      simulation: True
+      data_type: "Upgrade"
+      # evt_max: 1000
+      print_freq: 100
+      scheduler_legacy_mode: False
+      compression:
+        algorithm: ZSTD
+        level: 1
+        max_buffer_size: 1048576
+
+{{sigtype}}_Mag{{p}}_MC_HLT2:
+  application: "Moore/v55r11p2@x86_64_v2-el9-gcc13+detdesc-opt"
+  input:
+    job_name: {{sigtype}}_Mag{{p}}_MC_HLT1
+  output: MC_HLT2_full.DST
+  options:
+    entrypoint: Liv_Lb0NeutronLines.hlt2:alg_config
+    extra_options:
+      conddb_tag: sim-20231017-vc-md100
+      dddb_tag: dddb-20231017
+      input_type: "ROOT"
+      output_type: "ROOT"
+      simulation: True
+      input_process: "Hlt2"
+      persistreco_version: 0.0
+      data_type: "Upgrade"
+      evt_max: -1
+      output_manifest_file: "HLT2.tck.json"
+      scheduler_legacy_mode: False
+      compression:
+        algorithm: ZSTD
+        level: 1
+        max_buffer_size: 1048576
         
-# {{sigtype}}_Mag{{p}}_MC_Tuple:
-#   application: "DaVinci/v64r8@x86_64_v2-el9-clang16+detdesc-opt"
-#   input:
-#     job_name: {{sigtype}}_Mag{{p}}_MC_HLT2
-#   output: MC_{{sigtype}}.ROOT
-#   options:
-#     entrypoint: Liv_Lb0NeutronLines.main_Liv_{{sigtype}}:main
-#     extra_options:
-#       input_raw_format: 0.5
-#       input_type: ROOT
-#       simulation: True
-#       data_type: Upgrade
-#       conddb_tag: sim-20231017-vc-md100
-#       dddb_tag: dddb-20231017
-#       input_process: "Hlt2"
-#       conditions_version: master
-#       geometry_version: run3/trunk
-#       lumi: false
-#       output_type: ROOT
-#       persistreco_version: 1.0
-#       write_decoding_keys_to_git: True
-#       input_manifest_file: "HLT2.tck.json"
-#       input_stream: default
+{{sigtype}}_Mag{{p}}_MC_Tuple:
+  application: "DaVinci/v64r8@x86_64_v2-el9-clang16+detdesc-opt"
+  input:
+    job_name: {{sigtype}}_Mag{{p}}_MC_HLT2
+  output: MC_{{sigtype}}.ROOT
+  options:
+    entrypoint: Liv_Lb0NeutronLines.main_Liv_{{sigtype}}:main
+    extra_options:
+      input_raw_format: 0.5
+      input_type: ROOT
+      simulation: True
+      data_type: Upgrade
+      conddb_tag: sim-20231017-vc-md100
+      dddb_tag: dddb-20231017
+      input_process: "Hlt2"
+      conditions_version: master
+      lumi: false
+      output_type: ROOT
+      persistreco_version: 0.0
+      write_decoding_keys_to_git: True
+      input_manifest_file: "HLT2.tck.json"
+      input_stream: default
 
-# {%- endfor %}
-# {%- endfor %}
+
+{%- endfor %}
+{%- endfor %}
 
 ###################
-## DATA:
+## HLT2:
 ###################
 
 {%- for p in polarities %}
@@ -111,6 +112,7 @@ defaults:
       - UNCHECKED
       - OK
     keep_running: True
+    #n_test_lfns: 1
   output: RealData_{{sigtype}}.ROOT
   options:
     entrypoint: Liv_Lb0NeutronLines.main_Liv_{{sigtype}}:main
@@ -130,35 +132,6 @@ defaults:
 {%- endfor %}
 
 
-# -------------------------------Why there is no MagUp?
-# {%- for p in polarities %}
-# {%- for sigtype, simul, nu, inptype, evttype in mc_datasets %}
-# {{sigtype}}_Mag{{p}}_Data_Hlt2_ExclUT_Spc2_Tuple:
-#   application: "DaVinci/v64r8@x86_64_v2-el9-clang16-opt"
-#   input:
-#     bk_query: /LHCb/Collision24/Beam6800GeV-VeloClosed-Mag{{p}}-Excl-UT/Real Data/Sprucing24c2/94000000/B2OC.DST
-#     dq_flags:
-#       - UNCHECKED
-#       - OK
-#     keep_running: True
-#   output: RealData_{{sigtype}}.ROOT
-#   options:
-#     entrypoint: Liv_Lb0NeutronLines.main_Liv_{{sigtype}}:main
-#     extra_options:
-#       input_raw_format: 0.5
-#       input_type: ROOT
-#       simulation: False
-#       data_type: Upgrade
-#       geometry_version: run3/trunk
-#       conditions_version: master
-#       input_process: "TurboPass"
-#       input_stream: "b2oc"
-#       evt_max: 50000
-#       # print_freq: 1000
-#       #first_evt: 1
-# {%- endfor %}
-# {%- endfor %}
-
 # I don't have HLT2 24c1 for Lb0 channels here
 {%- set mc_datasets = [
  ('BpToLcpLcmKp', '' , '', '', '')
@@ -196,7 +169,8 @@ defaults:
 
 {%- set mc_datasets = [
  ('Lb0ToLcpLcmN0', '' , '', '', ''),
- ('BpToLcpLcmKp', '' , '', '', '')
+ ('BpToLcpLcmKp', '' , '', '', ''),
+ ('Lb0ToPbarPN0','' , '', '', ''),
 ]%}
 
 
@@ -210,6 +184,7 @@ defaults:
       - UNCHECKED
       - OK
     keep_running: True
+    n_test_lfns: 1
   output: RealData_{{sigtype}}.ROOT
   options:
     entrypoint: Liv_Lb0NeutronLines.main_Liv_{{sigtype}}_Spruce:main
@@ -228,35 +203,6 @@ defaults:
 {%- endfor %}
 {%- endfor %}
 
-# -------------------------------Why there is no MagUp?
-# {%- for p in polarities %}
-# {%- for sigtype, simul, nu, inptype, evttype in mc_datasets %}
-# {{sigtype}}_Mag{{p}}_Data_Spruce_ExclUT_Spc2_Tuple:
-#   application: "DaVinci/v64r8@x86_64_v2-el9-clang16-opt"
-#   input:
-#     bk_query: /LHCb/Collision24/Beam6800GeV-VeloClosed-Mag{{p}}-Excl-UT/Real Data/Sprucing24c2/94000000/B2OC.DST
-#     dq_flags:
-#       - UNCHECKED
-#       - OK
-#     keep_running: True
-#   output: RealData_{{sigtype}}.ROOT
-#   options:
-#     entrypoint: Liv_Lb0NeutronLines.main_Liv_{{sigtype}}_Spruce:main
-#     extra_options:
-#       input_raw_format: 0.5
-#       input_type: ROOT
-#       simulation: False
-#       data_type: Upgrade
-#       geometry_version: run3/trunk
-#       conditions_version: master
-#       input_process: "Spruce"
-#       input_stream: "b2oc"
-#       evt_max: 50000
-#       # print_freq: 1000
-#       #first_evt: 1
-# {%- endfor %}
-# {%- endfor %}
-
 {%- for p in polarities %}
 {%- for sigtype, simul, nu, inptype, evttype in mc_datasets %}
 {{sigtype}}_Mag{{p}}_Data_Spruce_ExclUT_Spc1_Tuple:
@@ -277,8 +223,8 @@ defaults:
       data_type: Upgrade
       geometry_version: run3/trunk
       conditions_version: master
-      input_process: "Spruce"
-      input_stream: "b2oc"
+      input_process: Spruce
+      input_stream: b2oc
       # evt_max: 50000
       # print_freq: 1000
       #first_evt: 1
diff --git a/Liv_Lb0NeutronLines/main_Liv_Lb0ToPpPmN0.py b/Liv_Lb0NeutronLines/main_Liv_Lb0ToPpPmN0.py
index ffa97da0e7..65a044e77d 100644
--- a/Liv_Lb0NeutronLines/main_Liv_Lb0ToPpPmN0.py
+++ b/Liv_Lb0NeutronLines/main_Liv_Lb0ToPpPmN0.py
@@ -9,7 +9,7 @@
 # or submit itself to any jurisdiction.                                       #
 ###############################################################################
 
-from .options.Lb_NeutronLines import *
+from .options.Lb_NeutronLines_HLT2 import *
 
 from DaVinci import Options, make_config
 from PyConf.reading import get_pvs, get_rec_summary
@@ -23,7 +23,7 @@ def main(options: Options):
     """ CORREGGERE TUPLES """
 
     tuples = {    
-        "Lb0ToPpPmN0" : maketuple_Lb0ToLcpLcnN0(options, pvs, rec_summary)
+        "Lb0ToPpPmN0" : maketuple_Lb0ToPpPmN0(options, pvs, rec_summary)
     }
         
     config = make_config(options, tuples)
diff --git a/Liv_Lb0NeutronLines/main_Liv_Lb0ToPpPmN0_Spuce.py b/Liv_Lb0NeutronLines/main_Liv_Lb0ToPpPmN0_Spuce.py
new file mode 100644
index 0000000000..c7acf2a6d8
--- /dev/null
+++ b/Liv_Lb0NeutronLines/main_Liv_Lb0ToPpPmN0_Spuce.py
@@ -0,0 +1,32 @@
+###############################################################################
+# (c) Copyright 2021-2022 CERN for the benefit of the LHCb Collaboration      #
+#                                                                             #
+# This software is distributed under the terms of the GNU General Public      #
+# Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING".   #
+#                                                                             #
+# In applying this licence, CERN does not waive the privileges and immunities #
+# granted to it by virtue of its status as an Intergovernmental Organization  #
+# or submit itself to any jurisdiction.                                       #
+###############################################################################
+
+from .options.Lb_NeutronLines_Spruce import *
+
+from DaVinci import Options, make_config
+from PyConf.reading import get_pvs, get_rec_summary
+
+def main(options: Options):
+        
+    # get ODIN and DecReports location
+    pvs = get_pvs()
+    rec_summary = get_rec_summary()
+
+    """ CORREGGERE TUPLES """
+
+    tuples = {    
+        "Lb0ToPpPmN0" : maketuple_Lb0ToPpPmN0(options, pvs, rec_summary)
+    }
+        
+    config = make_config(options, tuples)
+
+    return config
+
diff --git a/Liv_Lb0NeutronLines/options/Lb_NeutronLines_HLT2.py b/Liv_Lb0NeutronLines/options/Lb_NeutronLines_HLT2.py
index 9fe36d734f..23ee7c6afc 100644
--- a/Liv_Lb0NeutronLines/options/Lb_NeutronLines_HLT2.py
+++ b/Liv_Lb0NeutronLines/options/Lb_NeutronLines_HLT2.py
@@ -12,64 +12,74 @@ import FunTuple.functorcollections as FC
 from FunTuple import FunTuple_Particles as Funtuple
 from DecayTreeFitter import DecayTreeFitter
 
+
 def maketuple_Lb0ToLcpLcnN0(options, pvs, rec_summary):
 
     name = "Lb0ToLcpLcmN0"
     turbo_line = "Hlt2B2OC_Lb0ToLcpLcmN0"
     input_data = get_particles(f"/Event/HLT2/{turbo_line}/Particles")
 
-
     myfilter = create_lines_filter(
         f"LineFilter_{turbo_line}_{{hash}}",
         [turbo_line],
     )
 
     branches = {
-        "Lb0":"[Lambda_b0 -> (Lambda_c+ -> p+ K- pi+) (Lambda_c~- -> p~- K+ pi-)]CC",
-        "Lcp":"[Lambda_b0 -> ^(Lambda_c+ -> p+ K- pi+) (Lambda_c~- -> p~- K+ pi-)]CC",
-        "Lcm":"[Lambda_b0 -> (Lambda_c+ -> p+ K- pi+) ^(Lambda_c~- -> p~- K+ pi-)]CC",
-        "pp":"[Lambda_b0 -> (Lambda_c+ -> ^p+ K- pi+) (Lambda_c~- -> p~- K+ pi-)]CC",
-        "pm":"[Lambda_b0 -> (Lambda_c+ -> p+ K- pi+) (Lambda_c~- -> ^p~- K+ pi-)]CC",
-        "pip":"[Lambda_b0 -> (Lambda_c+ -> p+ K- ^pi+) (Lambda_c~- -> p~- K+ pi-)]CC",
-        "pim":"[Lambda_b0 -> (Lambda_c+ -> p+ K- pi+) (Lambda_c~- -> p~- K+ ^pi-)]CC",
-        "Kp":"[Lambda_b0 -> (Lambda_c+ -> p+ K- pi+) (Lambda_c~- -> p~- ^K+ pi-)]CC",
-        "Km":"[Lambda_b0 -> (Lambda_c+ -> p+ ^K- pi+) (Lambda_c~- -> p~- K+ pi-)]CC",
+        "Lb0":
+        "[Lambda_b0 -> (Lambda_c+ -> p+ K- pi+) (Lambda_c~- -> p~- K+ pi-)]CC",
+        "Lcp":
+        "[Lambda_b0 -> ^(Lambda_c+ -> p+ K- pi+) (Lambda_c~- -> p~- K+ pi-)]CC",
+        "Lcm":
+        "[Lambda_b0 -> (Lambda_c+ -> p+ K- pi+) ^(Lambda_c~- -> p~- K+ pi-)]CC",
+        "pp":
+        "[Lambda_b0 -> (Lambda_c+ -> ^p+ K- pi+) (Lambda_c~- -> p~- K+ pi-)]CC",
+        "pm":
+        "[Lambda_b0 -> (Lambda_c+ -> p+ K- pi+) (Lambda_c~- -> ^p~- K+ pi-)]CC",
+        "pip":
+        "[Lambda_b0 -> (Lambda_c+ -> p+ K- ^pi+) (Lambda_c~- -> p~- K+ pi-)]CC",
+        "pim":
+        "[Lambda_b0 -> (Lambda_c+ -> p+ K- pi+) (Lambda_c~- -> p~- K+ ^pi-)]CC",
+        "Kp":
+        "[Lambda_b0 -> (Lambda_c+ -> p+ K- pi+) (Lambda_c~- -> p~- ^K+ pi-)]CC",
+        "Km":
+        "[Lambda_b0 -> (Lambda_c+ -> p+ ^K- pi+) (Lambda_c~- -> p~- K+ pi-)]CC",
     }
-    
-    
+
     DTF_MASS = DecayTreeFitter(
-        name='DTF_{hash}', 
+        name='DTF_{hash}',
         input_particles=input_data,
-        mass_constraints=["Lambda_c+"],)
+        mass_constraints=["Lambda_b0", "Lambda_c+"],
+    )
 
     DTF_MASS_OWNPV = DecayTreeFitter(
-        name='DTF_{hash}', 
+        name='DTF_{hash}',
         input_particles=input_data,
-        mass_constraints=["Lambda_c+"],
-        constrain_to_ownpv=True,)
+        mass_constraints=["Lambda_b0", "Lambda_c+"],
+        constrain_to_ownpv=True,
+    )
+
+    basic_variables = make_basic_variables(
+        options, pvs, input_data, add_tistos=False)
 
-    basic_variables = make_basic_variables(options, pvs, input_data) 
+    composite_variables = make_composite_variables(
+        options, pvs, input_data, add_tistos=True)
 
-    composite_variables =  make_composite_variables(options, pvs, input_data) 
-    
-    composite_variables_3body = make_composite_variables_3body(options, pvs, input_data) 
+    composite_variables_3body = make_composite_variables_3body(
+        options, pvs, input_data, add_tistos=False)
 
     DTF_TwoBody = make_composite_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_MASS, pv_constraint=False, mass_constraint=True, particle_name="", three_body=False) +\
                make_composite_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_MASS_OWNPV, pv_constraint=False, three_body=False, mass_constraint=True,particle_name="_OWNPV") #same as BEST
-    
-    DTF_ThreeBody = make_composite_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_MASS, pv_constraint=False, mass_constraint=True, particle_name="", three_body=True) +\
-               make_composite_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_MASS_OWNPV, pv_constraint=False, three_body=True, mass_constraint=True,particle_name="_OWNPV") #same as BEST
-    
+
     variables = {
         "Lb0": composite_variables + DTF_TwoBody,
-        "Lcp": composite_variables_3body + DTF_ThreeBody,
-        "Lcm": composite_variables_3body + DTF_ThreeBody,
-        "pp":basic_variables,
-        "pm":basic_variables,
-        "pip":basic_variables,
-        "pim":basic_variables,
-        "Kp":basic_variables,
-        "Km":basic_variables,
+        "Lcp": composite_variables_3body,
+        "Lcm": composite_variables_3body,
+        "pp": basic_variables,
+        "pm": basic_variables,
+        "pip": basic_variables,
+        "pim": basic_variables,
+        "Kp": basic_variables,
+        "Km": basic_variables,
     }
 
     mytuple = Funtuple(
@@ -90,58 +100,59 @@ def maketuple_BpToLcpLcmKp(options, pvs, rec_summary):
     turbo_line = "Hlt2B2OC_BuToLcpLcmK_LcpToPKPi"
     input_data = get_particles(f"/Event/HLT2/{turbo_line}/Particles")
 
-
     myfilter = create_lines_filter(
         f"LineFilter_{turbo_line}_{{hash}}",
         [turbo_line],
     )
 
     branches = {
-        "Bp":"[B+ -> (Lambda_c+ -> p+ K- pi+) (Lambda_c~- -> p~- K+ pi-) K+]CC",
-        "Lcp":"[B+ -> ^(Lambda_c+ -> p+ K- pi+) (Lambda_c~- -> p~- K+ pi-) K+]CC",
-        "Lcm":"[B+ -> (Lambda_c+ -> p+ K- pi+) ^(Lambda_c~- -> p~- K+ pi-) K+]CC",
-        "pp":"[B+ -> (Lambda_c+ -> ^p+ K- pi+) (Lambda_c~- -> p~- K+ pi-) K+]CC",
-        "pm":"[B+ -> (Lambda_c+ -> p+ K- pi+) (Lambda_c~- -> ^p~- K+ pi-) K+]CC",
-        "pip":"[B+ -> (Lambda_c+ -> p+ K- ^pi+) (Lambda_c~- -> p~- K+ pi-) K+]CC",
-        "pim":"[B+ -> (Lambda_c+ -> p+ K- pi+) (Lambda_c~- -> p~- K+ ^pi-) K+]CC",
-        "Kp":"[B+ -> (Lambda_c+ -> p+ K- pi+) (Lambda_c~- -> p~- ^K+ pi-) K+]CC",
-        "Km":"[B+ -> (Lambda_c+ -> p+ ^K- pi+) (Lambda_c~- -> p~- K+ pi-) K+]CC",
-        "Kp_ext":"[B+ -> (Lambda_c+ -> p+ K- pi+) (Lambda_c~- -> p~- K+ pi-) ^K+]CC",
+        "Bp":
+        "[B+ -> (Lambda_c+ -> p+ K- pi+) (Lambda_c~- -> p~- K+ pi-) K+]CC",
+        "Lcp":
+        "[B+ -> ^(Lambda_c+ -> p+ K- pi+) (Lambda_c~- -> p~- K+ pi-) K+]CC",
+        "Lcm":
+        "[B+ -> (Lambda_c+ -> p+ K- pi+) ^(Lambda_c~- -> p~- K+ pi-) K+]CC",
+        "pp":
+        "[B+ -> (Lambda_c+ -> ^p+ K- pi+) (Lambda_c~- -> p~- K+ pi-) K+]CC",
+        "pm":
+        "[B+ -> (Lambda_c+ -> p+ K- pi+) (Lambda_c~- -> ^p~- K+ pi-) K+]CC",
+        "pip":
+        "[B+ -> (Lambda_c+ -> p+ K- ^pi+) (Lambda_c~- -> p~- K+ pi-) K+]CC",
+        "pim":
+        "[B+ -> (Lambda_c+ -> p+ K- pi+) (Lambda_c~- -> p~- K+ ^pi-) K+]CC",
+        "Kp":
+        "[B+ -> (Lambda_c+ -> p+ K- pi+) (Lambda_c~- -> p~- ^K+ pi-) K+]CC",
+        "Km":
+        "[B+ -> (Lambda_c+ -> p+ ^K- pi+) (Lambda_c~- -> p~- K+ pi-) K+]CC",
+        "Kp_ext":
+        "[B+ -> (Lambda_c+ -> p+ K- pi+) (Lambda_c~- -> p~- K+ pi-) ^K+]CC",
     }
-    
+
     DTF_MASS = DecayTreeFitter(
-        name='DTF_{hash}', 
+        name='DTF_{hash}',
         input_particles=input_data,
-        mass_constraints=["Lambda_c+"],)
+        mass_constraints=["B+", "Lambda_c+"],
+    )
 
     DTF_MASS_OWNPV = DecayTreeFitter(
-        name='DTF_{hash}', 
+        name='DTF_{hash}',
         input_particles=input_data,
-        mass_constraints=["Lambda_c+"],
-        constrain_to_ownpv=True,)
-
-
-    # B_Data_unbiasedpv = ParticleUnbiasedPVAdder(
-    #     InputParticles=input_data, PrimaryVertices=get_extended_pvs()
-    # ).OutputParticles
+        mass_constraints=["B+", "Lambda_c+"],
+        constrain_to_ownpv=True,
+    )
 
-    # DTF_UnbiasedPV = DecayTreeFitter(
-    #     name="DTF_UnbiasedPV",
-    #     input_particles=B_Data_unbiasedpv,
-    #     mass_constraints=["Lambda_c+"],
-    #     constrain_to_ownpv=True,
-    # )
+    basic_variables = make_basic_variables(options, pvs, input_data)
 
-    basic_variables = make_basic_variables(options, pvs, input_data) 
+    composite_variables_3body = make_composite_variables_3body(
+        options, pvs, input_data)
 
-    composite_variables_3body = make_composite_variables_3body(options, pvs, input_data) +\
-        make_composite_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_MASS, pv_constraint=False, three_body=True, mass_constraint=True,particle_name="") +\
+    DTFVars = make_composite_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_MASS, pv_constraint=False, three_body=True, mass_constraint=True,particle_name="") +\
         make_composite_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_MASS_OWNPV, pv_constraint=False, three_body=True, mass_constraint=True,particle_name="_OWNPV") #same as BEST
-    
+
     MVA_variables = make_MVA_variables()
 
     variables = {
-        "Bp": composite_variables_3body + MVA_variables,
+        "Bp": composite_variables_3body + DTFVars + MVA_variables,
         "Lcp": composite_variables_3body,
         "Lcm": composite_variables_3body,
         "pp": basic_variables,
@@ -153,23 +164,6 @@ def maketuple_BpToLcpLcmKp(options, pvs, rec_summary):
         "Kp_ext": basic_variables,
     }
 
-    # composite_variables_3body = make_composite_variables_3body(options, pvs, input_data) +\
-    #     make_composite_dtf_variables(options, get_extended_pvs(), input_data, add_truth=True, DTF=DTF_UnbiasedPV, pv_constraint=False, three_body=True, mass_constraint=True,particle_name="_UnbiasedPV")
-
-
-    # variablesUnbiased = {
-    #     "Bp": composite_variables_3body + MVA_variables,
-    #     "Lcp": composite_variables_3body,
-    #     "Lcm": composite_variables_3body,
-    #     "pp": basic_variables,
-    #     "pm": basic_variables,
-    #     "pip": basic_variables,
-    #     "pim": basic_variables,
-    #     "Kp": basic_variables,
-    #     "Km": basic_variables,
-    #     "Kp_ext": basic_variables,
-    # }
-
     mytuple = Funtuple(
         name=name,
         tuple_name="DecayTree",
@@ -178,17 +172,45 @@ def maketuple_BpToLcpLcmKp(options, pvs, rec_summary):
         event_variables=make_hlt2_event_variables(options, pvs, rec_summary),
         inputs=input_data,
         store_multiple_cand_info=True)
-    
-    # mytupleUnbiased = Funtuple(
-    #     name=name+"_Unbiased",
-    #     tuple_name="DecayTree",
-    #     fields=branches,
-    #     variables=variablesUnbiased,
-    #     event_variables=make_hlt2_event_variables(options, pvs, rec_summary),
-    #     inputs=B_Data_unbiasedpv,
-    #     store_multiple_cand_info=True)
 
     return [myfilter, mytuple]
 
 
+def maketuple_Lb0ToPpPmN0(options, pvs, rec_summary):
 
+    name = "Lb0ToPbarPN0"
+    turbo_line = "Hlt2B2OC_Lb0ToPbarPN0"
+    input_data = get_particles(f"/Event/HLT2/{turbo_line}/Particles")
+
+    myfilter = create_lines_filter(
+        f"LineFilter_{turbo_line}_{{hash}}",
+        [turbo_line],
+    )
+
+    branches = {
+        "Lb0": "[Lambda_b0 -> p+ p~-]CC",
+        "pp": "[Lambda_b0 -> ^p+ p~-]CC",
+        "pm": "[Lambda_b0 -> p+ ^p~-]CC",
+    }
+
+    basic_variables = make_basic_variables(
+        options, pvs, input_data, add_tistos=False)
+    composite_variables = make_composite_variables(
+        options, pvs, input_data, add_tistos=True)
+
+    variables = {
+        "Lb0": composite_variables,
+        "pp": basic_variables,
+        "pm": basic_variables,
+    }
+
+    mytuple = Funtuple(
+        name=name,
+        tuple_name="DecayTree",
+        fields=branches,
+        variables=variables,
+        event_variables=make_hlt2_event_variables(options, pvs, rec_summary),
+        inputs=input_data,
+        store_multiple_cand_info=True)
+
+    return [myfilter, mytuple]
diff --git a/Liv_Lb0NeutronLines/options/Lb_NeutronLines_Spruce.py b/Liv_Lb0NeutronLines/options/Lb_NeutronLines_Spruce.py
index 278a99d630..ea2eb5f197 100644
--- a/Liv_Lb0NeutronLines/options/Lb_NeutronLines_Spruce.py
+++ b/Liv_Lb0NeutronLines/options/Lb_NeutronLines_Spruce.py
@@ -12,64 +12,70 @@ import FunTuple.functorcollections as FC
 from FunTuple import FunTuple_Particles as Funtuple
 from DecayTreeFitter import DecayTreeFitter
 
+
 def maketuple_Lb0ToLcpLcnN0(options, pvs, rec_summary):
 
     name = "Lb0ToLcpLcmN0"
     turbo_line = "SpruceB2OC_Lb0ToLcpLcmN0"
     input_data = get_particles(f"/Event/Spruce/{turbo_line}/Particles")
 
-
     myfilter = create_lines_filter(
         f"LineFilter_{turbo_line}_{{hash}}",
         [turbo_line],
     )
 
     branches = {
-        "Lb0":"[Lambda_b0 -> (Lambda_c+ -> p+ K- pi+) (Lambda_c~- -> p~- K+ pi-)]CC",
-        "Lcp":"[Lambda_b0 -> ^(Lambda_c+ -> p+ K- pi+) (Lambda_c~- -> p~- K+ pi-)]CC",
-        "Lcm":"[Lambda_b0 -> (Lambda_c+ -> p+ K- pi+) ^(Lambda_c~- -> p~- K+ pi-)]CC",
-        "pp":"[Lambda_b0 -> (Lambda_c+ -> ^p+ K- pi+) (Lambda_c~- -> p~- K+ pi-)]CC",
-        "pm":"[Lambda_b0 -> (Lambda_c+ -> p+ K- pi+) (Lambda_c~- -> ^p~- K+ pi-)]CC",
-        "pip":"[Lambda_b0 -> (Lambda_c+ -> p+ K- ^pi+) (Lambda_c~- -> p~- K+ pi-)]CC",
-        "pim":"[Lambda_b0 -> (Lambda_c+ -> p+ K- pi+) (Lambda_c~- -> p~- K+ ^pi-)]CC",
-        "Kp":"[Lambda_b0 -> (Lambda_c+ -> p+ K- pi+) (Lambda_c~- -> p~- ^K+ pi-)]CC",
-        "Km":"[Lambda_b0 -> (Lambda_c+ -> p+ ^K- pi+) (Lambda_c~- -> p~- K+ pi-)]CC",
+        "Lb0":
+        "[Lambda_b0 -> (Lambda_c+ -> p+ K- pi+) (Lambda_c~- -> p~- K+ pi-)]CC",
+        "Lcp":
+        "[Lambda_b0 -> ^(Lambda_c+ -> p+ K- pi+) (Lambda_c~- -> p~- K+ pi-)]CC",
+        "Lcm":
+        "[Lambda_b0 -> (Lambda_c+ -> p+ K- pi+) ^(Lambda_c~- -> p~- K+ pi-)]CC",
+        "pp":
+        "[Lambda_b0 -> (Lambda_c+ -> ^p+ K- pi+) (Lambda_c~- -> p~- K+ pi-)]CC",
+        "pm":
+        "[Lambda_b0 -> (Lambda_c+ -> p+ K- pi+) (Lambda_c~- -> ^p~- K+ pi-)]CC",
+        "pip":
+        "[Lambda_b0 -> (Lambda_c+ -> p+ K- ^pi+) (Lambda_c~- -> p~- K+ pi-)]CC",
+        "pim":
+        "[Lambda_b0 -> (Lambda_c+ -> p+ K- pi+) (Lambda_c~- -> p~- K+ ^pi-)]CC",
+        "Kp":
+        "[Lambda_b0 -> (Lambda_c+ -> p+ K- pi+) (Lambda_c~- -> p~- ^K+ pi-)]CC",
+        "Km":
+        "[Lambda_b0 -> (Lambda_c+ -> p+ ^K- pi+) (Lambda_c~- -> p~- K+ pi-)]CC",
     }
-    
-    
+
     DTF_MASS = DecayTreeFitter(
-        name='DTF_{hash}', 
+        name='DTF_{hash}',
         input_particles=input_data,
-        mass_constraints=["Lambda_c+"],)
+        mass_constraints=["Lambda_b0", "Lambda_c+"],
+    )
 
     DTF_MASS_OWNPV = DecayTreeFitter(
-        name='DTF_{hash}', 
+        name='DTF_{hash}',
         input_particles=input_data,
-        mass_constraints=["Lambda_c+"],
-        constrain_to_ownpv=True,)
-
-    basic_variables = make_basic_variables(options, pvs, input_data) 
+        mass_constraints=["Lambda_b0", "Lambda_c+"],
+        constrain_to_ownpv=True,
+    )
 
-    composite_variables =  make_composite_variables(options, pvs, input_data) 
-    
-    composite_variables_3body = make_composite_variables_3body(options, pvs, input_data) 
+    basic_variables = make_basic_variables(options, pvs, input_data)
+    composite_variables = make_composite_variables(options, pvs, input_data)
+    composite_variables_3body = make_composite_variables_3body(
+        options, pvs, input_data)
 
     DTF_TwoBody = make_composite_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_MASS, pv_constraint=False, mass_constraint=True, particle_name="", three_body=False) +\
                make_composite_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_MASS_OWNPV, pv_constraint=False, three_body=False, mass_constraint=True,particle_name="_OWNPV") #same as BEST
-    
-    DTF_ThreeBody = make_composite_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_MASS, pv_constraint=False, mass_constraint=True, particle_name="", three_body=True) +\
-               make_composite_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_MASS_OWNPV, pv_constraint=False, three_body=True, mass_constraint=True,particle_name="_OWNPV") #same as BEST
-    
+
     variables = {
         "Lb0": composite_variables + DTF_TwoBody,
-        "Lcp": composite_variables_3body + DTF_ThreeBody,
-        "Lcm": composite_variables_3body + DTF_ThreeBody,
-        "pp":basic_variables,
-        "pm":basic_variables,
-        "pip":basic_variables,
-        "pim":basic_variables,
-        "Kp":basic_variables,
-        "Km":basic_variables,
+        "Lcp": composite_variables_3body,
+        "Lcm": composite_variables_3body,
+        "pp": basic_variables,
+        "pm": basic_variables,
+        "pip": basic_variables,
+        "pim": basic_variables,
+        "Kp": basic_variables,
+        "Km": basic_variables,
     }
 
     mytuple = Funtuple(
@@ -90,54 +96,53 @@ def maketuple_BpToLcpLcmKp(options, pvs, rec_summary):
     turbo_line = "SpruceB2OC_BuToLcpLcmK_LcpToPKPi"
     input_data = get_particles(f"/Event/Spruce/{turbo_line}/Particles")
 
-
     myfilter = create_lines_filter(
         f"LineFilter_{turbo_line}_{{hash}}",
         [turbo_line],
     )
 
     branches = {
-        "Bp":"[B+ -> (Lambda_c+ -> p+ K- pi+) (Lambda_c~- -> p~- K+ pi-) K+]CC",
-        "Lcp":"[B+ -> ^(Lambda_c+ -> p+ K- pi+) (Lambda_c~- -> p~- K+ pi-) K+]CC",
-        "Lcm":"[B+ -> (Lambda_c+ -> p+ K- pi+) ^(Lambda_c~- -> p~- K+ pi-) K+]CC",
-        "pp":"[B+ -> (Lambda_c+ -> ^p+ K- pi+) (Lambda_c~- -> p~- K+ pi-) K+]CC",
-        "pm":"[B+ -> (Lambda_c+ -> p+ K- pi+) (Lambda_c~- -> ^p~- K+ pi-) K+]CC",
-        "pip":"[B+ -> (Lambda_c+ -> p+ K- ^pi+) (Lambda_c~- -> p~- K+ pi-) K+]CC",
-        "pim":"[B+ -> (Lambda_c+ -> p+ K- pi+) (Lambda_c~- -> p~- K+ ^pi-) K+]CC",
-        "Kp":"[B+ -> (Lambda_c+ -> p+ K- pi+) (Lambda_c~- -> p~- ^K+ pi-) K+]CC",
-        "Km":"[B+ -> (Lambda_c+ -> p+ ^K- pi+) (Lambda_c~- -> p~- K+ pi-) K+]CC",
-        "Kp_ext":"[B+ -> (Lambda_c+ -> p+ K- pi+) (Lambda_c~- -> p~- K+ pi-) ^K+]CC",
+        "Bp":
+        "[B+ -> (Lambda_c+ -> p+ K- pi+) (Lambda_c~- -> p~- K+ pi-) K+]CC",
+        "Lcp":
+        "[B+ -> ^(Lambda_c+ -> p+ K- pi+) (Lambda_c~- -> p~- K+ pi-) K+]CC",
+        "Lcm":
+        "[B+ -> (Lambda_c+ -> p+ K- pi+) ^(Lambda_c~- -> p~- K+ pi-) K+]CC",
+        "pp":
+        "[B+ -> (Lambda_c+ -> ^p+ K- pi+) (Lambda_c~- -> p~- K+ pi-) K+]CC",
+        "pm":
+        "[B+ -> (Lambda_c+ -> p+ K- pi+) (Lambda_c~- -> ^p~- K+ pi-) K+]CC",
+        "pip":
+        "[B+ -> (Lambda_c+ -> p+ K- ^pi+) (Lambda_c~- -> p~- K+ pi-) K+]CC",
+        "pim":
+        "[B+ -> (Lambda_c+ -> p+ K- pi+) (Lambda_c~- -> p~- K+ ^pi-) K+]CC",
+        "Kp":
+        "[B+ -> (Lambda_c+ -> p+ K- pi+) (Lambda_c~- -> p~- ^K+ pi-) K+]CC",
+        "Km":
+        "[B+ -> (Lambda_c+ -> p+ ^K- pi+) (Lambda_c~- -> p~- K+ pi-) K+]CC",
+        "Kp_ext":
+        "[B+ -> (Lambda_c+ -> p+ K- pi+) (Lambda_c~- -> p~- K+ pi-) ^K+]CC",
     }
-    
+
     DTF_MASS = DecayTreeFitter(
-        name='DTF_{hash}', 
+        name='DTF_{hash}',
         input_particles=input_data,
-        mass_constraints=["Lambda_c+"],)
+        mass_constraints=["B+", "Lambda_c+"],
+    )
 
     DTF_MASS_OWNPV = DecayTreeFitter(
-        name='DTF_{hash}', 
+        name='DTF_{hash}',
         input_particles=input_data,
-        mass_constraints=["Lambda_c+"],
-        constrain_to_ownpv=True,)
-
-
-    # B_Data_unbiasedpv = ParticleUnbiasedPVAdder(
-    #     InputParticles=input_data, PrimaryVertices=get_extended_pvs()
-    # ).OutputParticles
-
-    # DTF_UnbiasedPV = DecayTreeFitter(
-    #     name="DTF_UnbiasedPV",
-    #     input_particles=B_Data_unbiasedpv,
-    #     mass_constraints=["Lambda_c+"],
-    #     constrain_to_ownpv=True,
-    # )
+        mass_constraints=["B+", "Lambda_c+"],
+        constrain_to_ownpv=True,
+    )
 
-    basic_variables = make_basic_variables(options, pvs, input_data) 
+    basic_variables = make_basic_variables(options, pvs, input_data)
 
     composite_variables_3body = make_composite_variables_3body(options, pvs, input_data) +\
         make_composite_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_MASS, pv_constraint=False, three_body=True, mass_constraint=True,particle_name="") +\
         make_composite_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_MASS_OWNPV, pv_constraint=False, three_body=True, mass_constraint=True,particle_name="_OWNPV") #same as BEST
-    
+
     MVA_variables = make_MVA_variables()
 
     variables = {
@@ -153,23 +158,6 @@ def maketuple_BpToLcpLcmKp(options, pvs, rec_summary):
         "Kp_ext": basic_variables,
     }
 
-    # composite_variables_3body = make_composite_variables_3body(options, pvs, input_data) +\
-    #     make_composite_dtf_variables(options, get_extended_pvs(), input_data, add_truth=True, DTF=DTF_UnbiasedPV, pv_constraint=False, three_body=True, mass_constraint=True,particle_name="_UnbiasedPV")
-
-
-    # variablesUnbiased = {
-    #     "Bp": composite_variables_3body + MVA_variables,
-    #     "Lcp": composite_variables_3body,
-    #     "Lcm": composite_variables_3body,
-    #     "pp": basic_variables,
-    #     "pm": basic_variables,
-    #     "pip": basic_variables,
-    #     "pim": basic_variables,
-    #     "Kp": basic_variables,
-    #     "Km": basic_variables,
-    #     "Kp_ext": basic_variables,
-    # }
-
     mytuple = Funtuple(
         name=name,
         tuple_name="DecayTree",
@@ -178,17 +166,45 @@ def maketuple_BpToLcpLcmKp(options, pvs, rec_summary):
         event_variables=make_hlt2_event_variables(options, pvs, rec_summary),
         inputs=input_data,
         store_multiple_cand_info=True)
-    
-    # mytupleUnbiased = Funtuple(
-    #     name=name+"_Unbiased",
-    #     tuple_name="DecayTree",
-    #     fields=branches,
-    #     variables=variablesUnbiased,
-    #     event_variables=make_hlt2_event_variables(options, pvs, rec_summary),
-    #     inputs=B_Data_unbiasedpv,
-    #     store_multiple_cand_info=True)
 
     return [myfilter, mytuple]
 
 
+def maketuple_Lb0ToPpPmN0(options, pvs, rec_summary):
 
+    name = "Lb0ToPbarPN0"
+    turbo_line = "SpruceB2OC_Lb0ToPbarPN0"
+    input_data = get_particles(f"/Event/HLT2/{turbo_line}/Particles")
+
+    myfilter = create_lines_filter(
+        f"LineFilter_{turbo_line}_{{hash}}",
+        [turbo_line],
+    )
+
+    branches = {
+        "Lb0": "[Lambda_b0 -> p+ p~-]CC",
+        "pp": "[Lambda_b0 -> ^p+ p~-]CC",
+        "pm": "[Lambda_b0 -> p+ ^p~-]CC",
+    }
+
+    basic_variables = make_basic_variables(
+        options, pvs, input_data, add_tistos=False)
+    composite_variables = make_composite_variables(
+        options, pvs, input_data, add_tistos=True)
+
+    variables = {
+        "Lb0": composite_variables,
+        "pp": basic_variables,
+        "pm": basic_variables,
+    }
+
+    mytuple = Funtuple(
+        name=name,
+        tuple_name="DecayTree",
+        fields=branches,
+        variables=variables,
+        event_variables=make_hlt2_event_variables(options, pvs, rec_summary),
+        inputs=input_data,
+        store_multiple_cand_info=True)
+
+    return [myfilter, mytuple]
diff --git a/Liv_Lb0NeutronLines/options/tupling.py b/Liv_Lb0NeutronLines/options/tupling.py
index a0bd39d8a8..479db2b863 100644
--- a/Liv_Lb0NeutronLines/options/tupling.py
+++ b/Liv_Lb0NeutronLines/options/tupling.py
@@ -26,7 +26,7 @@ from FunTuple.functorcollections import (
     HltTisTos,
     MCVertexInfo,
     MCKinematics,
-    ParticleID, #wrong variables PID_PI = 0, PROBNN_D = nan
+    ParticleID,  #wrong variables PID_PI = 0, PROBNN_D = nan
     EventInfo,
     ParticleIsolation,
     MCPrimaries,
@@ -80,7 +80,7 @@ Hlt1_1track_lines = [
     # "Hlt1SingleHighPtElectronDecision",
     # "Hlt1SingleHighEtDecision",
 ]
-Hlt1_lines = Hlt1_1track_lines+[
+Hlt1_lines = Hlt1_1track_lines + [
     # "Hlt1TwoTrackMVACharmXSecDecision",
     "Hlt1TwoTrackMVADecision",
     # "Hlt1TwoTrackKsDecision",
@@ -101,135 +101,134 @@ Hlt1_lines = Hlt1_1track_lines+[
 ]
 
 Hlt2_lines = [
-    "Hlt2Topo2BodyDecision",
-    "Hlt2Topo3Body_Decision",
-    "Hlt2B2OC_Lb0ToLcpLcmN0",
-    "Hlt2B2OC_BuToLcpLcmK_LcpToPKPi",
-    "SpruceB2OC_Lb0ToLcpLcmN0",
-    "SpruceB2OC_BuToLcpLcmK_LcpToPKPi"
+    "Hlt2Topo2BodyDecision", "Hlt2Topo3BodyDecision",
+    "Hlt2B2OC_Lb0ToLcpLcmN0Decision", "Hlt2B2OC_BuToLcpLcmK_LcpToPKPiDecision",
+    "Hlt2B2OC_Lb0ToPbarPN0", "SpruceB2OC_Lb0ToLcpLcmN0Decision",
+    "SpruceB2OC_BuToLcpLcmK_LcpToPKPiDecision", "SpruceB2OC_Lb0ToPbarPN0"
 ]
 
+
 def make_MVA_variables():
 
     pvs = get_pvs()
 
-    variables = (
+    variables = (FunctorCollection({
+        "MVA":
+        F.MVA(
+            MVAType="SigmaNet",
+            Config={
+                "File":
+                "paramfile://data/Hlt2B2OC_B_SigmaNet_Run3-v2.json",
+                "Name":
+                "B2OC_SigmaNet_Generic",
+                "Lambda":
+                "2.0",
+                "NLayers":
+                "3",
+                "InputSize":
+                "6",
+                "Monotone_Constraints":
+                "[1,-1,-1,-1,-1,-1]",
+                "Variables":
+                "log_B_PT,B_ETA,log_B_DIRA,log_B_ENDVERTEX_CHI2,log_B_IPCHI2_OWNPV,log_B_IP_OWNPV",
+            },
+            Inputs={
+                "log_B_PT": fmath.log(F.PT),
+                "B_ETA": F.ETA,
+                "log_B_DIRA": fmath.log(1. + 1.e-6 - F.BPVDIRA(pvs)),
+                "log_B_ENDVERTEX_CHI2": fmath.log(F.CHI2DOF),
+                "log_B_IPCHI2_OWNPV": fmath.log(F.BPVIPCHI2(pvs)),
+                "log_B_IP_OWNPV": fmath.log(F.BPVIP(pvs)),
+            }),
+        "MVAold":
+        F.MVA(
+            MVAType="SigmaNet",
+            Config={
+                "File":
+                "paramfile://data/Hlt2B2OC_B_SigmaNet_Run3-v1.json",
+                "Name":
+                "B2OC_SigmaNet_Generic",
+                "Lambda":
+                "2.0",
+                "NLayers":
+                "3",
+                "InputSize":
+                "6",
+                "Monotone_Constraints":
+                "[1,-1,-1,-1,-1,-1]",
+                "Variables":
+                "log_B_PT,B_ETA,log_B_DIRA,log_B_ENDVERTEX_CHI2,log_B_IPCHI2_OWNPV,log_B_IP_OWNPV",
+            },
+            Inputs={
+                "log_B_PT": fmath.log(F.PT),
+                "B_ETA": F.ETA,
+                "log_B_DIRA": fmath.log(1. - F.BPVDIRA(pvs)),
+                "log_B_ENDVERTEX_CHI2": fmath.log(F.CHI2DOF),
+                "log_B_IPCHI2_OWNPV": fmath.log(F.BPVIPCHI2(pvs)),
+                "log_B_IP_OWNPV": fmath.log(F.BPVIP(pvs)),
+            }),
+    }))
 
-        FunctorCollection(
-           {
-                "MVA": F.MVA(
-                MVAType="SigmaNet",
-                Config={
-                    "File":
-                    "paramfile://data/Hlt2B2OC_B_SigmaNet_Run3-v2.json",
-                    "Name":
-                    "B2OC_SigmaNet_Generic",
-                    "Lambda":
-                    "2.0",
-                    "NLayers":
-                    "3",
-                    "InputSize":
-                    "6",
-                    "Monotone_Constraints":
-                    "[1,-1,-1,-1,-1,-1]",
-                    "Variables":
-                    "log_B_PT,B_ETA,log_B_DIRA,log_B_ENDVERTEX_CHI2,log_B_IPCHI2_OWNPV,log_B_IP_OWNPV",
-                },
-                Inputs={
-                    "log_B_PT": fmath.log(F.PT),
-                    "B_ETA": F.ETA,
-                    "log_B_DIRA": fmath.log(1. +1.e-6 - F.BPVDIRA(pvs)),
-                    "log_B_ENDVERTEX_CHI2": fmath.log(F.CHI2DOF),
-                    "log_B_IPCHI2_OWNPV": fmath.log(F.BPVIPCHI2(pvs)),
-                    "log_B_IP_OWNPV": fmath.log(F.BPVIP(pvs)),
-                }),
-            "MVAold": F.MVA(
-                MVAType="SigmaNet",
-                Config={
-                    "File":
-                    "paramfile://data/Hlt2B2OC_B_SigmaNet_Run3-v1.json",
-                    "Name":
-                    "B2OC_SigmaNet_Generic",
-                    "Lambda":
-                    "2.0",
-                    "NLayers":
-                    "3",
-                    "InputSize":
-                    "6",
-                    "Monotone_Constraints":
-                    "[1,-1,-1,-1,-1,-1]",
-                    "Variables":
-                    "log_B_PT,B_ETA,log_B_DIRA,log_B_ENDVERTEX_CHI2,log_B_IPCHI2_OWNPV,log_B_IP_OWNPV",
-                },
-                Inputs={
-                    "log_B_PT": fmath.log(F.PT),
-                    "B_ETA": F.ETA,
-                    "log_B_DIRA": fmath.log(1. - F.BPVDIRA(pvs)),
-                    "log_B_ENDVERTEX_CHI2": fmath.log(F.CHI2DOF),
-                    "log_B_IPCHI2_OWNPV": fmath.log(F.BPVIPCHI2(pvs)),
-                    "log_B_IP_OWNPV": fmath.log(F.BPVIP(pvs)),
-                }),
-
-           })
-    )
-    
     return variables
-    
 
-def make_composite_variables(options, pvs, data, add_truth=True, add_tistos= True):
+
+def make_composite_variables(options,
+                             pvs,
+                             data,
+                             add_truth=True,
+                             add_tistos=True):
     if not options.simulation:
         add_truth = False
     variables = (
-       FunctorCollection(
-           {
-               "ID": F.PARTICLE_ID,
-               "CHARGE": F.CHARGE,
-               "VCHI2DOF": F.CHI2DOF, #CHI2VXNDOF,
-               "MCORR": F.BPVCORRM(pvs),#"MCorr": F.BPVCORRM(939.56542052), for lb0
-               "MCORRERR": F.BPVCORRMERR(pvs),
-               "M12": F.SUBCOMB(Functor=F.MASS, Indices=(1, 2)),
-               "MAXPT": F.MAX(F.PT),
-               "MINPT": F.MIN(F.PT),
-               "SUMPT": F.SUM(F.PT),
-               "MAXP": F.MAX(F.P),
-               "MINP": F.MIN(F.P),
-               "SUMP": F.SUM(F.P),
-               "BPVDIRA": F.BPVDIRA(pvs),
-               "BPVFDCHI2": F.BPVFDCHI2(pvs),
-               "BPVFD": F.BPVFD(pvs),
-               "BPVVDRHO": F.BPVVDRHO(pvs),
-               "BPVX": F.BPVX(pvs),
-               "BPVY": F.BPVY(pvs),
-               "BPVZ": F.BPVZ(pvs),
-               "BPVIPCHI2": F.BPVIPCHI2(pvs),
-               "LOGBPVIPCHI2": log(F.BPVIPCHI2(pvs)),
-               "BPVIP": F.BPVIP(pvs),
-               "MINIPCHI2"   : F.MINIPCHI2(pvs),
-               "MINIP"       : F.MINIP(pvs),
-               "BPVLTIME": F.BPVLTIME(pvs),
-               "MAXBPVIPCHI2": F.MAX(F.BPVIPCHI2(pvs)), #MAX_
-               "MINBPVIPCHI2": F.MIN(F.BPVIPCHI2(pvs)),
-               "MAXBPVIP": F.MAX(F.BPVIP(pvs)),
-               "MINBPVIP": F.MIN(F.BPVIP(pvs)),
-               "MAXDOCACHI2": F.MAXDOCACHI2,
-               "MAXDOCA": F.MAXDOCA,
-               "DOCA_12"      : F.DOCA(Child1=1,Child2=2),
-               "DOCACHI2_12"  : F.DOCACHI2(Child1=1,Child2=2),
-               "ETA": F.ETA,
-               "PHI": F.PHI,
-               "END_VX": F.END_VX, #END_
-               "END_VY": F.END_VY,
-               "END_VZ": F.END_VZ,
-               "END_VCHI2DOF": F.CHI2DOF @ F.ENDVERTEX,
-           }
-       )
-       + Kinematics()
-    )
+        FunctorCollection({
+            "ID": F.PARTICLE_ID,
+            "CHARGE": F.CHARGE,
+            "VCHI2DOF": F.CHI2DOF,  #CHI2VXNDOF,
+            "MCORR":
+            F.BPVCORRM(pvs),  #"MCorr": F.BPVCORRM(939.56542052), for lb0
+            "MCORRERR": F.BPVCORRMERR(pvs),
+            "M12": F.SUBCOMB(Functor=F.MASS, Indices=(1, 2)),
+            "MAXPT": F.MAX(F.PT),
+            "MINPT": F.MIN(F.PT),
+            "SUMPT": F.SUM(F.PT),
+            "MAXP": F.MAX(F.P),
+            "MINP": F.MIN(F.P),
+            "SUMP": F.SUM(F.P),
+            "BPVDIRA": F.BPVDIRA(pvs),
+            "BPVFDCHI2": F.BPVFDCHI2(pvs),
+            "BPVFD": F.BPVFD(pvs),
+            "BPVVDRHO": F.BPVVDRHO(pvs),
+            "BPVX": F.BPVX(pvs),
+            "BPVY": F.BPVY(pvs),
+            "BPVZ": F.BPVZ(pvs),
+            "BPVIPCHI2": F.BPVIPCHI2(pvs),
+            "LOGBPVIPCHI2": log(F.BPVIPCHI2(pvs)),
+            "BPVIP": F.BPVIP(pvs),
+            "MINIPCHI2": F.MINIPCHI2(pvs),
+            "MINIP": F.MINIP(pvs),
+            "BPVLTIME": F.BPVLTIME(pvs),
+            "MAXBPVIPCHI2": F.MAX(F.BPVIPCHI2(pvs)),  #MAX_
+            "MINBPVIPCHI2": F.MIN(F.BPVIPCHI2(pvs)),
+            "MAXBPVIP": F.MAX(F.BPVIP(pvs)),
+            "MINBPVIP": F.MIN(F.BPVIP(pvs)),
+            "MAXDOCACHI2": F.MAXDOCACHI2,
+            "MAXDOCA": F.MAXDOCA,
+            "DOCA_12": F.DOCA(Child1=1, Child2=2),
+            "DOCACHI2_12": F.DOCACHI2(Child1=1, Child2=2),
+            "ETA": F.ETA,
+            "PHI": F.PHI,
+            "END_VX": F.END_VX,  #END_
+            "END_VY": F.END_VY,
+            "END_VZ": F.END_VZ,
+            "END_VCHI2DOF": F.CHI2DOF @ F.ENDVERTEX,
+        }) + Kinematics())
 
     if add_tistos:
         variables += HltTisTos(
-            selection_type="Hlt1", trigger_lines=Hlt1_lines, data=data
-        )
+            selection_type="Hlt1", trigger_lines=Hlt1_lines, data=data)
+        # variables += HltTisTos(
+        #     selection_type="Hlt2", trigger_lines=[x for x in Hlt2_lines if x.startswith("Hlt2")], data=data
+        # )
 
     if add_truth:
         variables = add_truth_matching_functors(
@@ -244,111 +243,112 @@ def make_composite_variables(options, pvs, data, add_truth=True, add_tistos= Tru
 
     return variables
 
+
 def make_tistoscombinations(options, pvs, data):
-    algo_output = ParticleToSubcombinationsAlg( Input=data )
+    algo_output = ParticleToSubcombinationsAlg(Input=data)
     relations = algo_output.OutputRelations
 
     tistos_variables_extra = HltTisTos(
-        selection_type="Hlt1", trigger_lines=["Hlt1TwoTrackMVADecision"], data=algo_output.OutputParticles
-    )
+        selection_type="Hlt1",
+        trigger_lines=["Hlt1TwoTrackMVADecision"],
+        data=algo_output.OutputParticles)
     tistos_combinations = {}
-    for k,v in tistos_variables_extra.get_thor_functors().items():
-        tistos_combinations[k + "_SUBCOMB" ] = F.MAP_INPUT_ARRAY( v, relations )
-    tistos_combinations = FunctorCollection( tistos_combinations )
+    for k, v in tistos_variables_extra.get_thor_functors().items():
+        tistos_combinations[k + "_SUBCOMB"] = F.MAP_INPUT_ARRAY(v, relations)
+    tistos_combinations = FunctorCollection(tistos_combinations)
 
     return tistos_combinations
 
-def make_composite_variables_3body(options, pvs, data, add_truth=True, add_tistos= True):
 
-    variables = (
-        FunctorCollection(
-            {
-                #13
-                "M13": F.SUBCOMB(Functor=F.MASS, Indices=(1, 3)),
-                "DOCA13"      : F.DOCA(Child1=1,Child2=3),
-                "DOCACHI213"  : F.DOCACHI2(Child1=1,Child2=3),
-                "COS13": F.ALV(1, 3),
-                #23
-                "M23": F.SUBCOMB(Functor=F.MASS, Indices=(2, 3)),
-                "DOCA23"      : F.DOCA(Child1=2,Child2=3),
-                "DOCACHI223"  : F.DOCACHI2(Child1=2,Child2=3),
-                "COS23": F.ALV(2, 3),
-            }
-        )
-    )
+def make_composite_variables_3body(options,
+                                   pvs,
+                                   data,
+                                   add_truth=True,
+                                   add_tistos=True):
 
-    variables += make_composite_variables(options, pvs, data, add_truth, add_tistos)
+    variables = (
+        FunctorCollection({
+            #13
+            "M13": F.SUBCOMB(Functor=F.MASS, Indices=(1, 3)),
+            "DOCA13": F.DOCA(Child1=1, Child2=3),
+            "DOCACHI213": F.DOCACHI2(Child1=1, Child2=3),
+            "COS13": F.ALV(1, 3),
+            #23
+            "M23": F.SUBCOMB(Functor=F.MASS, Indices=(2, 3)),
+            "DOCA23": F.DOCA(Child1=2, Child2=3),
+            "DOCACHI223": F.DOCACHI2(Child1=2, Child2=3),
+            "COS23": F.ALV(2, 3),
+        }))
+
+    variables += make_composite_variables(options, pvs, data, add_truth,
+                                          add_tistos)
 
     if add_tistos:
         variables += make_tistoscombinations(options, pvs, data)
 
-
     return variables
 
+
 def make_composite_variables_4body(options, pvs, data, add_truth=True):
 
     variables = (
-        FunctorCollection(
-            {
-                #14
-                "M14": F.SUBCOMB(Functor=F.MASS, Indices=(1, 4)),
-                "DOCA14"      : F.DOCA(Child1=1,Child2=4),
-                "DOCACHI214"  : F.DOCACHI2(Child1=1,Child2=4),
-                "COS14": F.ALV(1, 4),
-                #24
-                "M24": F.SUBCOMB(Functor=F.MASS, Indices=(2, 4)),
-                "DOCA24"      : F.DOCA(Child1=2,Child2=4),
-                "DOCACHI224"  : F.DOCACHI2(Child1=2,Child2=4),
-                "COS24": F.ALV(2, 4),
-                #34
-                "M34": F.SUBCOMB(Functor=F.MASS, Indices=(3, 4)),
-                "DOCA34"      : F.DOCA(Child1=3,Child2=4),
-                "DOCACHI234"  : F.DOCACHI2(Child1=3,Child2=4),
-                "COS34": F.ALV(3, 4),
-            }
-        )
-    )
-    return make_composite_variables_3body(options,pvs, data, add_truth)+variables
+        FunctorCollection({
+            #14
+            "M14": F.SUBCOMB(Functor=F.MASS, Indices=(1, 4)),
+            "DOCA14": F.DOCA(Child1=1, Child2=4),
+            "DOCACHI214": F.DOCACHI2(Child1=1, Child2=4),
+            "COS14": F.ALV(1, 4),
+            #24
+            "M24": F.SUBCOMB(Functor=F.MASS, Indices=(2, 4)),
+            "DOCA24": F.DOCA(Child1=2, Child2=4),
+            "DOCACHI224": F.DOCACHI2(Child1=2, Child2=4),
+            "COS24": F.ALV(2, 4),
+            #34
+            "M34": F.SUBCOMB(Functor=F.MASS, Indices=(3, 4)),
+            "DOCA34": F.DOCA(Child1=3, Child2=4),
+            "DOCACHI234": F.DOCACHI2(Child1=3, Child2=4),
+            "COS34": F.ALV(3, 4),
+        }))
+    return make_composite_variables_3body(options, pvs, data,
+                                          add_truth) + variables
+
 
 def make_DeltaM_variable(options):
     return FunctorCollection({"DM": F.MASS - F.CHILD(1, F.MASS)})
 
-def make_basic_variables(options, pvs, data, add_truth=True, add_tistos=False):
+
+def make_basic_variables(options, pvs, data, add_truth=True, add_tistos=True):
     if not options.simulation:
         add_truth = False
-    variables = (
-       FunctorCollection(
-           { 
-               "ID": F.PARTICLE_ID,
-               "CHARGE": F.CHARGE,
-               "TRCHI2DOF": F.CHI2DOF @ F.TRACK,
-               "VCHI2DOF": F.CHI2DOF,
-               "TRGHOSTPROB": F.GHOSTPROB,
-               "TX"          : F.TX,
-               "TY"          : F.TY,
-               "QOVERP": F.QOVERP @ F.TRACK,
-               "ETA": F.ETA,
-               "PHI": F.PHI,
-               "BPVIPCHI2": F.BPVIPCHI2(pvs),
-               "BPVIP": F.BPVIP(pvs),
-               "MINIPCHI2"   : F.MINIPCHI2(pvs),
-               "MINIP"       : F.MINIP(pvs),
-               "ISMUON"      : F.ISMUON,
-               "NFTHITS": F.VALUE_OR(-1) @ F.NFTHITS @ F.TRACK,
-               "NHITS": F.VALUE_OR(-1) @ F.NHITS @ F.TRACK,
-               "NUTHITS": F.VALUE_OR(-1) @ F.NUTHITS @ F.TRACK,
-               "NVPHITS": F.VALUE_OR(-1) @ F.NVPHITS @ F.TRACK,
-               "TRACKHASVELO": F.VALUE_OR(-1) @ F.TRACKHASVELO @ F.TRACK,
-    
-           }
-       )
-       + Kinematics()
-       + ParticleID(extra_info=True)
-    )
+    variables = (FunctorCollection(
+        {
+            "ID": F.PARTICLE_ID,
+            "CHARGE": F.CHARGE,
+            "TRCHI2DOF": F.CHI2DOF @ F.TRACK,
+            "VCHI2DOF": F.CHI2DOF,
+            "TRGHOSTPROB": F.GHOSTPROB,
+            "TX": F.TX,
+            "TY": F.TY,
+            "QOVERP": F.QOVERP @ F.TRACK,
+            "ETA": F.ETA,
+            "PHI": F.PHI,
+            "BPVIPCHI2": F.BPVIPCHI2(pvs),
+            "BPVIP": F.BPVIP(pvs),
+            "MINIPCHI2": F.MINIPCHI2(pvs),
+            "MINIP": F.MINIP(pvs),
+            "ISMUON": F.ISMUON,
+            "NFTHITS": F.VALUE_OR(-1) @ F.NFTHITS @ F.TRACK,
+            "NHITS": F.VALUE_OR(-1) @ F.NHITS @ F.TRACK,
+            "NUTHITS": F.VALUE_OR(-1) @ F.NUTHITS @ F.TRACK,
+            "NVPHITS": F.VALUE_OR(-1) @ F.NVPHITS @ F.TRACK,
+            "TRACKHASVELO": F.VALUE_OR(-1) @ F.TRACKHASVELO @ F.TRACK,
+        }) + Kinematics() + ParticleID(extra_info=True))
     if add_tistos:
         variables += HltTisTos(
-            selection_type="Hlt1", trigger_lines=Hlt1_1track_lines, data=data
-        )
+            selection_type="Hlt1", trigger_lines=Hlt1_1track_lines, data=data)
+        # variables += HltTisTos(
+        #     selection_type="Hlt2", trigger_lines=[ x for x in Hlt2_lines if x.startswith("Hlt2") ], data=data
+        # )
 
     if add_truth:
         variables = add_truth_matching_functors(
@@ -363,72 +363,86 @@ def make_basic_variables(options, pvs, data, add_truth=True, add_tistos=False):
 
     return variables
 
+
 def make_hlt2_event_variables(options, pvs, rec_summary):
     # define event level variables
     evt_variables = EventInfo()
-    evt_variables += SelectionInfo(selection_type="Hlt2", trigger_lines=Hlt2_lines)
-    evt_variables += SelectionInfo(selection_type="Hlt1", trigger_lines=Hlt1_lines)
-    evt_variables += FunctorCollection(
-        {
-            "ALLPVX": F.ALLPVX(pvs),
-            "ALLPVY": F.ALLPVY(pvs),
-            "ALLPVZ": F.ALLPVZ(pvs),
-            "nPVs": F.SIZE(pvs),
-            "nTracks": F.VALUE_OR(-1) @ F.RECSUMMARY_INFO(rec_summary, "nTracks"),# but always 0 ...
-            "nLongTracks": F.VALUE_OR(-1) @ F.RECSUMMARY_INFO(rec_summary, "nLongTracks"),
-            "nMuonTracks": F.VALUE_OR(-1) @ F.RECSUMMARY_INFO(rec_summary, "nMuonTracks"),
-            "nFTClusters": F.VALUE_OR(-1) @ F.RECSUMMARY_INFO(rec_summary, "nFTClusters"),
-            "nVPClusters": F.VALUE_OR(-1) @ F.RECSUMMARY_INFO(rec_summary, "nVPClusters"),
-            "nUTClusters": F.VALUE_OR(-1) @ F.RECSUMMARY_INFO(rec_summary, "nUTClusters"),
-            "nSPDhits": F.VALUE_OR(-1) @ F.RECSUMMARY_INFO(rec_summary, "nSPDhits"),
-            "nEcalClusters": F.VALUE_OR(-1) @ F.RECSUMMARY_INFO(rec_summary, "nEcalClusters"),
-            "nEcalClusters": F.VALUE_OR(-1) @ F.RECSUMMARY_INFO(rec_summary, "nEcalClusters"),
-            "eCalTot": F.VALUE_OR(-1) @ F.RECSUMMARY_INFO(rec_summary, "eCalTot"),
-            "hCalTot": F.VALUE_OR(-1) @ F.RECSUMMARY_INFO(rec_summary, "hCalTot"),
-            "nRich1Hits": F.VALUE_OR(-1) @ F.RECSUMMARY_INFO(rec_summary, "nRich1Hits"),
-            "nRich2Hits": F.VALUE_OR(-1) @ F.RECSUMMARY_INFO(rec_summary, "nRich2Hits"),
-        }
-    )
+    evt_variables += SelectionInfo(
+        selection_type="Hlt2", trigger_lines=Hlt2_lines)
+    evt_variables += SelectionInfo(
+        selection_type="Hlt1", trigger_lines=Hlt1_lines)
+    evt_variables += FunctorCollection({
+        "ALLPVX":
+        F.ALLPVX(pvs),
+        "ALLPVY":
+        F.ALLPVY(pvs),
+        "ALLPVZ":
+        F.ALLPVZ(pvs),
+        "nPVs":
+        F.SIZE(pvs),
+        "nTracks":
+        F.VALUE_OR(-1) @ F.RECSUMMARY_INFO(rec_summary,
+                                           "nTracks"),  # but always 0 ...
+        "nLongTracks":
+        F.VALUE_OR(-1) @ F.RECSUMMARY_INFO(rec_summary, "nLongTracks"),
+        "nMuonTracks":
+        F.VALUE_OR(-1) @ F.RECSUMMARY_INFO(rec_summary, "nMuonTracks"),
+        "nFTClusters":
+        F.VALUE_OR(-1) @ F.RECSUMMARY_INFO(rec_summary, "nFTClusters"),
+        "nVPClusters":
+        F.VALUE_OR(-1) @ F.RECSUMMARY_INFO(rec_summary, "nVPClusters"),
+        "nUTClusters":
+        F.VALUE_OR(-1) @ F.RECSUMMARY_INFO(rec_summary, "nUTClusters"),
+        "nSPDhits":
+        F.VALUE_OR(-1) @ F.RECSUMMARY_INFO(rec_summary, "nSPDhits"),
+        "nEcalClusters":
+        F.VALUE_OR(-1) @ F.RECSUMMARY_INFO(rec_summary, "nEcalClusters"),
+        "nEcalClusters":
+        F.VALUE_OR(-1) @ F.RECSUMMARY_INFO(rec_summary, "nEcalClusters"),
+        "eCalTot":
+        F.VALUE_OR(-1) @ F.RECSUMMARY_INFO(rec_summary, "eCalTot"),
+        "hCalTot":
+        F.VALUE_OR(-1) @ F.RECSUMMARY_INFO(rec_summary, "hCalTot"),
+        "nRich1Hits":
+        F.VALUE_OR(-1) @ F.RECSUMMARY_INFO(rec_summary, "nRich1Hits"),
+        "nRich2Hits":
+        F.VALUE_OR(-1) @ F.RECSUMMARY_INFO(rec_summary, "nRich2Hits"),
+    })
     return evt_variables
 
 
 def make_unpack_only_mc_variables():
     MC_MOTHER_ID = lambda gen: F.VALUE_OR(0) @ F.MC_MOTHER(gen, F.PARTICLE_ID)
     MC_MOTHER_KEY = lambda gen: F.VALUE_OR(-1) @ F.MC_MOTHER(gen, F.OBJECT_KEY)
-    return (
-        FunctorCollection(
-            {
-                "TRUEID": F.PARTICLE_ID,
-                "MC_MOTHER_ID": MC_MOTHER_ID(1),
-                "MC_MOTHER_KEY": MC_MOTHER_KEY(1),
-                "MC_GD_MOTHER_ID": MC_MOTHER_ID(2),
-                "MC_GD_MOTHER_KEY": MC_MOTHER_KEY(2),
-                "MC_GD_GD_MOTHER_ID": MC_MOTHER_ID(3),
-                "MC_GD_GD_MOTHER_KEY": MC_MOTHER_KEY(3),
-                "TRUEORIGIN_VX": F.ORIGIN_VX,
-                "TRUEORIGIN_VY": F.ORIGIN_VY,
-                "TRUEORIGIN_VZ": F.ORIGIN_VZ,
-                "TRUEEND_VX": F.END_VX,
-                "TRUEEND_VY": F.END_VY,
-                "TRUEEND_VZ": F.END_VZ,
-            }
-        )
-        + Kinematics()
-        + MCPromptDecay()
-    )
+    return (FunctorCollection({
+        "TRUEID": F.PARTICLE_ID,
+        "MC_MOTHER_ID": MC_MOTHER_ID(1),
+        "MC_MOTHER_KEY": MC_MOTHER_KEY(1),
+        "MC_GD_MOTHER_ID": MC_MOTHER_ID(2),
+        "MC_GD_MOTHER_KEY": MC_MOTHER_KEY(2),
+        "MC_GD_GD_MOTHER_ID": MC_MOTHER_ID(3),
+        "MC_GD_GD_MOTHER_KEY": MC_MOTHER_KEY(3),
+        "TRUEORIGIN_VX": F.ORIGIN_VX,
+        "TRUEORIGIN_VY": F.ORIGIN_VY,
+        "TRUEORIGIN_VZ": F.ORIGIN_VZ,
+        "TRUEEND_VX": F.END_VX,
+        "TRUEEND_VY": F.END_VY,
+        "TRUEEND_VZ": F.END_VZ,
+    }) + Kinematics() + MCPromptDecay())
 
 
 ####
 
+
 def add_truth_matching_functors(
-    options,
-    variables,
-    data,
-    hierarchy=True,
-    kinematics=True,
-    vertex_info=True,
-    bkgcat=False,
-    prompt_info=True,
+        options,
+        variables,
+        data,
+        hierarchy=True,
+        kinematics=True,
+        vertex_info=True,
+        bkgcat=False,
+        prompt_info=True,
 ):
     """Add MC truth matching functors to an existing FunctorCollection.
 
@@ -452,212 +466,229 @@ def add_truth_matching_functors(
     MCTRUTH = MCTruthAndBkgCat(data)
 
     if bkgcat:
-        variables += FunctorCollection(
-            {
-                # Important note: specify an invalid value for integer functors if there exists no truth info.
-                #                 The invalid value for floating point functors is set to nan.
-                "TRUEKEY": F.VALUE_OR(-1) @ MCTRUTH(F.OBJECT_KEY),
-                "BKGCAT": MCTRUTH.BkgCat,
-            }
-        )
+        variables += FunctorCollection({
+            # Important note: specify an invalid value for integer functors if there exists no truth info.
+            #                 The invalid value for floating point functors is set to nan.
+            "TRUEKEY":
+            F.VALUE_OR(-1) @ MCTRUTH(F.OBJECT_KEY),
+            "BKGCAT":
+            MCTRUTH.BkgCat,
+        })
     if hierarchy:
-        variables += MCHierarchy(mctruth_alg=MCTRUTH)  # likely to change again!!
+        variables += MCHierarchy(
+            mctruth_alg=MCTRUTH)  # likely to change again!!
     if vertex_info:
-        variables += MCVertexInfo(mctruth_alg=MCTRUTH)  # likely to change again!!
+        variables += MCVertexInfo(
+            mctruth_alg=MCTRUTH)  # likely to change again!!
     if kinematics:
-        variables += MCKinematics(mctruth_alg=MCTRUTH)  # likely to change again!!
+        variables += MCKinematics(
+            mctruth_alg=MCTRUTH)  # likely to change again!!
     if prompt_info:
         variables += MCPromptDecay(mctruth_alg=MCTRUTH)
 
     return variables
 
+
 ### DTF variables ###
 
-def make_basic_dtf_variables(options, pvs, data, add_truth=True, DTF=None, pv_constraint=False, mass_constraint=False, particle_name=""):
+
+def make_basic_dtf_variables(options,
+                             pvs,
+                             data,
+                             add_truth=True,
+                             DTF=None,
+                             pv_constraint=False,
+                             mass_constraint=False,
+                             particle_name=""):
     if not options.simulation:
         add_truth = False
-    variables = ( 
-        FunctorCollection(
-            {
-                "ETA": F.ETA,
-                "PHI": F.PHI,
-                "BPVIPCHI2": F.BPVIPCHI2(pvs),
-                "BPVIP": F.BPVIP(pvs),
-                "TX"          : F.TX,
-                "TY"          : F.TY,
-                "MINIPCHI2"   : F.MINIPCHI2(pvs),
-                "MINIP"       : F.MINIP(pvs),
-                
-            }
-        )
-        + Kinematics()
+    variables = (
+        FunctorCollection({
+            "ETA": F.ETA,
+            "PHI": F.PHI,
+            "BPVIPCHI2": F.BPVIPCHI2(pvs),
+            "BPVIP": F.BPVIP(pvs),
+            "TX": F.TX,
+            "TY": F.TY,
+            "MINIPCHI2": F.MINIPCHI2(pvs),
+            "MINIP": F.MINIP(pvs),
+        }) + Kinematics()
         #+ ParticleID(extra_info=True)
     )
-    
-    dtf_extras = FunctorCollection(
-        {
-            "DTF_NITER": DTF.NITER,
-            "DTF_CHI2": DTF.CHI2,
-            "DTF_NDOF": DTF.NDOF,
-            "DTF_CHI2DOF": DTF.CHI2DOF
-        }
-    )
 
+    dtf_extras = FunctorCollection({
+        "DTF_NITER": DTF.NITER,
+        "DTF_CHI2": DTF.CHI2,
+        "DTF_NDOF": DTF.NDOF,
+        "DTF_CHI2DOF": DTF.CHI2DOF
+    })
 
-
-    if(mass_constraint):
-        if(pv_constraint): # MASS + PV
+    if (mass_constraint):
+        if (pv_constraint):  # MASS + PV
             dtf_variables_mass_pv = FunctorCollection({
-                        'DTF_PV_M'+ particle_name + '_' + k: DTF(v)
-                        for k, v in variables.get_thor_functors().items()
-                    })
+                'DTF_PV_M' + particle_name + '_' + k: DTF(v)
+                for k, v in variables.get_thor_functors().items()
+            })
             return dtf_variables_mass_pv
-        else: # MASS
-            dtf_variables_mass = FunctorCollection(
-                {'DTF_M'+ particle_name + '_' + k: DTF(v)
-                 for k, v in variables.get_thor_functors().items()})
-        return dtf_variables_mass
-    elif(pv_constraint): # PV
-        dtf_variables_pv = FunctorCollection({
-                'DTF_PV_' + k: DTF(v)
+        else:  # MASS
+            dtf_variables_mass = FunctorCollection({
+                'DTF_M' + particle_name + '_' + k: DTF(v)
                 for k, v in variables.get_thor_functors().items()
             })
+        return dtf_variables_mass
+    elif (pv_constraint):  # PV
+        dtf_variables_pv = FunctorCollection({
+            'DTF_PV_' + k: DTF(v)
+            for k, v in variables.get_thor_functors().items()
+        })
         return dtf_variables_pv
 
-    else: # NO MASS/PV
-        dtf_variables = FunctorCollection(
-            {'DTF_' + k: DTF(v)
-             for k, v in variables.get_thor_functors().items()})
+    else:  # NO MASS/PV
+        dtf_variables = FunctorCollection({
+            'DTF_' + k: DTF(v)
+            for k, v in variables.get_thor_functors().items()
+        })
         return dtf_variables
 
-def make_composite_dtf_variables(options, pvs, data, add_truth=True, DTF=None, pv_constraint=False, mass_constraint=False, particle_name="", three_body=False):
+
+def make_composite_dtf_variables(options,
+                                 pvs,
+                                 data,
+                                 add_truth=True,
+                                 DTF=None,
+                                 pv_constraint=False,
+                                 mass_constraint=False,
+                                 particle_name="",
+                                 three_body=False):
     if not options.simulation:
         add_truth = False
     variables = (
-        FunctorCollection(
-            {
-                # "MAXPT": F.MAX(F.PT),
-                # "MINPT": F.MIN(F.PT),
-                # "SUMPT": F.SUM(F.PT),
-                # "MAXP": F.MAX(F.P),
-                # "MINP": F.MIN(F.P),
-                # "BPVDIRA": F.BPVDIRA(pvs),
-                # "BPVFDCHI2": F.BPVFDCHI2(pvs),
-                #"BPVFD": F.BPVFD(pvs),
-                # "BPVVDRHO": F.BPVVDRHO(pvs),
-                # "BPVVDZ": F.BPVVDZ(pvs),
-                # "BPVIPCHI2": F.BPVIPCHI2(pvs),
-                # "BPVIP": F.BPVIP(pvs),
-                # "LOGBPVIPCHI2": log(F.BPVIPCHI2(pvs)),
-                #"BPVLTIME": F.BPVLTIME(pvs),
-                # "MAXBPVIPCHI2": F.MAX(F.BPVIPCHI2(pvs)), #MAX_
-                # "MINBPVIPCHI2": F.MIN(F.BPVIPCHI2(pvs)),
-                # "MAXBPVIP": F.MAX(F.BPVIP(pvs)),
-                # "MINBPVIP": F.MIN(F.BPVIP(pvs)),
-                "MCORR": F.BPVCORRM(pvs), #"MCorr": F.BPVCORRM(939.56542052), for lb0
-                "MCORRERR": F.BPVCORRMERR(pvs),
-                "M12": F.SUBCOMB(Functor=F.MASS, Indices=(1, 2)),
-                # "ETA": F.ETA,
-                # "PHI": F.PHI
-            }
-        )
+        FunctorCollection({
+            # "MAXPT": F.MAX(F.PT),
+            # "MINPT": F.MIN(F.PT),
+            # "SUMPT": F.SUM(F.PT),
+            # "MAXP": F.MAX(F.P),
+            # "MINP": F.MIN(F.P),
+            # "BPVDIRA": F.BPVDIRA(pvs),
+            # "BPVFDCHI2": F.BPVFDCHI2(pvs),
+            #"BPVFD": F.BPVFD(pvs),
+            # "BPVVDRHO": F.BPVVDRHO(pvs),
+            # "BPVVDZ": F.BPVVDZ(pvs),
+            # "BPVIPCHI2": F.BPVIPCHI2(pvs),
+            # "BPVIP": F.BPVIP(pvs),
+            # "LOGBPVIPCHI2": log(F.BPVIPCHI2(pvs)),
+            #"BPVLTIME": F.BPVLTIME(pvs),
+            # "MAXBPVIPCHI2": F.MAX(F.BPVIPCHI2(pvs)), #MAX_
+            # "MINBPVIPCHI2": F.MIN(F.BPVIPCHI2(pvs)),
+            # "MAXBPVIP": F.MAX(F.BPVIP(pvs)),
+            # "MINBPVIP": F.MIN(F.BPVIP(pvs)),
+            "MCORR":
+            F.BPVCORRM(pvs),  #"MCorr": F.BPVCORRM(939.56542052), for lb0
+            "MCORRERR": F.BPVCORRMERR(pvs),
+            "M12": F.SUBCOMB(Functor=F.MASS, Indices=(1, 2)),
+            # "ETA": F.ETA,
+            # "PHI": F.PHI
+        })
         # + Kinematics()
-        
+
         #+ ParticleID(extra_info=True) #only for daughters
     )
-    
-    if three_body:
-            variables += FunctorCollection(
-                {
-                    "M13": F.SUBCOMB(Functor=F.MASS, Indices=(1, 3)),
-                    "M23": F.SUBCOMB(Functor=F.MASS, Indices=(2, 3)),
-                }
-            )
-            
-    dtf_extras = FunctorCollection(
-        {
-            "DTF"+particle_name+"_NITER": DTF.NITER,
-            "DTF"+particle_name+"_CHI2": DTF.CHI2,
-            "DTF"+particle_name+"_NDOF": DTF.NDOF,
-            "DTF"+particle_name+"_CHI2DOF": DTF.CHI2DOF,
-            "DTF"+particle_name+"_M": DTF.MASS,
-            "DTF"+particle_name+"_MERR": DTF.MASSERR,
-            "DTF"+particle_name+"_MERR": DTF.MASSERR,
-            "DTF"+particle_name+"_FD": DTF.FD,
-            "DTF"+particle_name+"_FDERR": DTF.FDERR,
-            "DTF"+particle_name+"_CTAU": DTF.CTAU,
-            "DTF"+particle_name+"_CTAUERR": DTF.CTAUERR,
-
-        }
-    )
-
 
-    if(mass_constraint):
-        if(pv_constraint): # MASS + PV
+    if three_body:
+        variables += FunctorCollection({
+            "M13":
+            F.SUBCOMB(Functor=F.MASS, Indices=(1, 3)),
+            "M23":
+            F.SUBCOMB(Functor=F.MASS, Indices=(2, 3)),
+        })
+
+    dtf_extras = FunctorCollection({
+        "DTF" + particle_name + "_NITER":
+        DTF.NITER,
+        "DTF" + particle_name + "_CHI2":
+        DTF.CHI2,
+        "DTF" + particle_name + "_NDOF":
+        DTF.NDOF,
+        "DTF" + particle_name + "_CHI2DOF":
+        DTF.CHI2DOF,
+        "DTF" + particle_name + "_M":
+        DTF.MASS,
+        "DTF" + particle_name + "_MERR":
+        DTF.MASSERR,
+        "DTF" + particle_name + "_MERR":
+        DTF.MASSERR,
+        "DTF" + particle_name + "_FD":
+        DTF.FD,
+        "DTF" + particle_name + "_FDERR":
+        DTF.FDERR,
+        "DTF" + particle_name + "_CTAU":
+        DTF.CTAU,
+        "DTF" + particle_name + "_CTAUERR":
+        DTF.CTAUERR,
+    })
+
+    if (mass_constraint):
+        if (pv_constraint):  # MASS + PV
             dtf_variables_mass_pv = FunctorCollection({
-                        'DTF_PV_M'+ particle_name + '_' + k: DTF(v)
-                        for k, v in variables.get_thor_functors().items()
-                    })
+                'DTF_PV_M' + particle_name + '_' + k: DTF(v)
+                for k, v in variables.get_thor_functors().items()
+            })
             return dtf_variables_mass_pv + dtf_extras
-        else: # MASS
-            dtf_variables_mass = FunctorCollection(
-                {'DTF_M'+ particle_name + '_' + k: DTF(v)
-                 for k, v in variables.get_thor_functors().items()})
+        else:  # MASS
+            dtf_variables_mass = FunctorCollection({
+                'DTF_M' + particle_name + '_' + k: DTF(v)
+                for k, v in variables.get_thor_functors().items()
+            })
         return dtf_variables_mass + dtf_extras
 
-    elif(pv_constraint): # PV
+    elif (pv_constraint):  # PV
         dtf_variables_pv = FunctorCollection({
-                'DTF_PV_' + k: DTF(v)
-                for k, v in variables.get_thor_functors().items()
-            })
+            'DTF_PV_' + k: DTF(v)
+            for k, v in variables.get_thor_functors().items()
+        })
         return dtf_variables_pv + dtf_extras
 
-    else: # NO MASS/PV
-        dtf_variables = FunctorCollection(
-            {'DTF_' + k: DTF(v)
-             for k, v in variables.get_thor_functors().items()})
+    else:  # NO MASS/PV
+        dtf_variables = FunctorCollection({
+            'DTF_' + k: DTF(v)
+            for k, v in variables.get_thor_functors().items()
+        })
         return dtf_variables + dtf_extras
 
+
 def make_MC_basic_variables():
-    variables = (
-        FunctorCollection(
-            {
-                "OBJECT_KEY": F.OBJECT_KEY,
-                "ETA": F.ETA,
-                "PHI": F.PHI,
-                "ORIGIN_VX": F.ORIGIN_VX,
-                "ORIGIN_VY": F.ORIGIN_VY,
-                "ORIGIN_VZ": F.ORIGIN_VZ,
-                "FOURMOMENTUM": F.FOURMOMENTUM,
-            }
-        )
-        + Kinematics()
-    )
+    variables = (FunctorCollection({
+        "OBJECT_KEY": F.OBJECT_KEY,
+        "ETA": F.ETA,
+        "PHI": F.PHI,
+        "ORIGIN_VX": F.ORIGIN_VX,
+        "ORIGIN_VY": F.ORIGIN_VY,
+        "ORIGIN_VZ": F.ORIGIN_VZ,
+        "FOURMOMENTUM": F.FOURMOMENTUM,
+    }) + Kinematics())
 
     return variables
 
+
 def make_MC_composite_variables():
     variables = (
-        FunctorCollection(
-            {
-                "END_VX": F.END_VX, #END_
-                "END_VY": F.END_VY,
-                "END_VZ": F.END_VZ,
-                "LTIME": F.MC_LIFETIME,
-                "OBJECT_KEY": F.OBJECT_KEY,
-                "ETA": F.ETA,
-                "PHI": F.PHI,
-                "ORIGIN_VX": F.ORIGIN_VX,
-                "ORIGIN_VY": F.ORIGIN_VY,
-                "ORIGIN_VZ": F.ORIGIN_VZ,
-                "FOURMOMENTUM": F.FOURMOMENTUM,
-            }
-        )
-        + Kinematics()
-    )
+        FunctorCollection({
+            "END_VX": F.END_VX,  #END_
+            "END_VY": F.END_VY,
+            "END_VZ": F.END_VZ,
+            "LTIME": F.MC_LIFETIME,
+            "OBJECT_KEY": F.OBJECT_KEY,
+            "ETA": F.ETA,
+            "PHI": F.PHI,
+            "ORIGIN_VX": F.ORIGIN_VX,
+            "ORIGIN_VY": F.ORIGIN_VY,
+            "ORIGIN_VZ": F.ORIGIN_VZ,
+            "FOURMOMENTUM": F.FOURMOMENTUM,
+        }) + Kinematics())
 
     return variables
 
+
 def make_MC_event_variables(mc_header):
     # define event level variables
     evt_variables = EventInfo()
@@ -665,93 +696,120 @@ def make_MC_event_variables(mc_header):
 
     return evt_variables
 
-def make_top_isolation_variables(hlt2_line, input_data, locations = ["LongTrackIso","NeutralIso"]):
+
+def make_top_isolation_variables(hlt2_line,
+                                 input_data,
+                                 locations=["LongTrackIso", "NeutralIso"]):
     from PyConf.reading import get_particles
     from IsolationTools import VertexAndConeIsolation
 
-    possible_charm_locations = ["LongTrackIso", "TTrackIso", "DownstreamTrackIso", "UpstreamTrackIso", "NeutralIso", "PizIso"]
-    coneangles = [0.25,0.5,1.,1.5,2.]
-    
+    possible_charm_locations = [
+        "LongTrackIso", "TTrackIso", "DownstreamTrackIso", "UpstreamTrackIso",
+        "NeutralIso", "PizIso"
+    ]
+    coneangles = [0.25, 0.5, 1., 1.5, 2.]
+
     count = 0
     for location in locations:
-        extra_particles = get_particles(f"/Event/HLT2/{hlt2_line}/{location}/Particles")
+        extra_particles = get_particles(
+            f"/Event/HLT2/{hlt2_line}/{location}/Particles")
 
         for coneangle in coneangles:
             top_RTAlg = VertexAndConeIsolation(
-                name=location+"_"+str(coneangle),
+                name=location + "_" + str(coneangle),
                 reference_particles=input_data,
                 related_particles=extra_particles,
-                cut=F.DR2<coneangle)
-            
+                cut=F.DR2 < coneangle)
+
             if count == 0:
-                top_iso_variables = ParticleIsolation(isolation_alg=top_RTAlg,array_indx_name='indx')
+                top_iso_variables = ParticleIsolation(
+                    isolation_alg=top_RTAlg, array_indx_name='indx')
             else:
-                top_iso_variables += ParticleIsolation(isolation_alg=top_RTAlg,array_indx_name='indx')
+                top_iso_variables += ParticleIsolation(
+                    isolation_alg=top_RTAlg, array_indx_name='indx')
             count += 1
-                
 
     return top_iso_variables
 
-def make_basic_isolation_variables(hlt2_line, input_data, locations = ["LongTrackIso","NeutralIso"]):
+
+def make_basic_isolation_variables(hlt2_line,
+                                   input_data,
+                                   locations=["LongTrackIso", "NeutralIso"]):
     from PyConf.reading import get_particles
     from IsolationTools import VertexAndConeIsolation
     from PyConf.Algorithms import ThOrParticleSelection
 
     basic_code = (F.FILTER(F.ALL) @ F.GET_ALL_BASICS())
-    basic_particles = ThOrParticleSelection(InputParticles=input_data, Functor=basic_code).OutputSelection
+    basic_particles = ThOrParticleSelection(
+        InputParticles=input_data, Functor=basic_code).OutputSelection
+
+    possible_charm_locations = [
+        "LongTrackIso", "TTrackIso", "DownstreamTrackIso", "UpstreamTrackIso",
+        "NeutralIso", "PizIso"
+    ]
+    coneangles = [0.25, 0.5, 1., 1.5, 2.]
 
-    possible_charm_locations = ["LongTrackIso", "TTrackIso", "DownstreamTrackIso", "UpstreamTrackIso", "NeutralIso", "PizIso"]
-    coneangles = [0.25,0.5,1.,1.5,2.]
-    
     count = 0
     for location in locations:
-        extra_particles = get_particles(f"/Event/HLT2/{hlt2_line}/{location}/Particles")
+        extra_particles = get_particles(
+            f"/Event/HLT2/{hlt2_line}/{location}/Particles")
 
         for coneangle in coneangles:
             basic_RTAlg = VertexAndConeIsolation(
-                name=location+"_"+str(coneangle),
+                name=location + "_" + str(coneangle),
                 reference_particles=basic_particles,
                 related_particles=extra_particles,
-                cut=F.DR2<coneangle)
-            
+                cut=F.DR2 < coneangle)
+
             if count == 0:
-                basic_iso_variables = ParticleIsolation(isolation_alg=basic_RTAlg,array_indx_name='indx')
+                basic_iso_variables = ParticleIsolation(
+                    isolation_alg=basic_RTAlg, array_indx_name='indx')
             else:
-                basic_iso_variables += ParticleIsolation(isolation_alg=basic_RTAlg,array_indx_name='indx')
+                basic_iso_variables += ParticleIsolation(
+                    isolation_alg=basic_RTAlg, array_indx_name='indx')
             count += 1
-                
 
     return basic_iso_variables
 
 
-def make_intermediate_isolation_variables(hlt2_line, input_data, locations = ["LongTrackIso","NeutralIso"], composite_ID = "J/psi(1S)"):
+def make_intermediate_isolation_variables(
+        hlt2_line,
+        input_data,
+        locations=["LongTrackIso", "NeutralIso"],
+        composite_ID="J/psi(1S)"):
     from PyConf.reading import get_particles
     from IsolationTools import VertexAndConeIsolation
     from PyConf.Algorithms import ThOrParticleSelection
 
-    intermediate_code = F.FILTER(F.IS_ABS_ID(composite_ID)) @ F.GET_ALL_DESCENDANTS()
-    intermediate_particles = ThOrParticleSelection(InputParticles=input_data, Functor=intermediate_code).OutputSelection
+    intermediate_code = F.FILTER(
+        F.IS_ABS_ID(composite_ID)) @ F.GET_ALL_DESCENDANTS()
+    intermediate_particles = ThOrParticleSelection(
+        InputParticles=input_data, Functor=intermediate_code).OutputSelection
+
+    possible_charm_locations = [
+        "LongTrackIso", "TTrackIso", "DownstreamTrackIso", "UpstreamTrackIso",
+        "NeutralIso", "PizIso"
+    ]
+    coneangles = [0.25, 0.5, 1., 1.5, 2.]
 
-    possible_charm_locations = ["LongTrackIso", "TTrackIso", "DownstreamTrackIso", "UpstreamTrackIso", "NeutralIso", "PizIso"]
-    coneangles = [0.25,0.5,1.,1.5,2.]
-    
     count = 0
     for location in locations:
-        extra_particles = get_particles(f"/Event/HLT2/{hlt2_line}/{location}/Particles")
+        extra_particles = get_particles(
+            f"/Event/HLT2/{hlt2_line}/{location}/Particles")
 
         for coneangle in coneangles:
             intermediate_RTAlg = VertexAndConeIsolation(
-                name=location+"_"+str(coneangle),
+                name=location + "_" + str(coneangle),
                 reference_particles=intermediate_particles,
                 related_particles=extra_particles,
-                cut=F.DR2<coneangle)
-            
+                cut=F.DR2 < coneangle)
+
             if count == 0:
-                intermediate_iso_variables = ParticleIsolation(isolation_alg=intermediate_RTAlg,array_indx_name='indx')
+                intermediate_iso_variables = ParticleIsolation(
+                    isolation_alg=intermediate_RTAlg, array_indx_name='indx')
             else:
-                intermediate_iso_variables += ParticleIsolation(isolation_alg=intermediate_RTAlg,array_indx_name='indx')
+                intermediate_iso_variables += ParticleIsolation(
+                    isolation_alg=intermediate_RTAlg, array_indx_name='indx')
             count += 1
-                
 
     return intermediate_iso_variables
-
-- 
GitLab


From 4985a2fd66826b9e109d4136a38ef5163555280d Mon Sep 17 00:00:00 2001
From: Juan Leite <jbaptist@lxplus974.cern.ch>
Date: Wed, 21 Aug 2024 21:59:12 +0200
Subject: [PATCH 26/34] fix errors

---
 Liv_Lb0NeutronLines/info.yaml                 | 30 ++++++-------------
 ...b0ToPpPmN0.py => main_Liv_Lb0ToPbarPN0.py} |  0
 ...puce.py => main_Liv_Lb0ToPbarPN0_Spuce.py} |  0
 3 files changed, 9 insertions(+), 21 deletions(-)
 rename Liv_Lb0NeutronLines/{main_Liv_Lb0ToPpPmN0.py => main_Liv_Lb0ToPbarPN0.py} (100%)
 rename Liv_Lb0NeutronLines/{main_Liv_Lb0ToPpPmN0_Spuce.py => main_Liv_Lb0ToPbarPN0_Spuce.py} (100%)

diff --git a/Liv_Lb0NeutronLines/info.yaml b/Liv_Lb0NeutronLines/info.yaml
index 5e3f80df6d..f360045a21 100644
--- a/Liv_Lb0NeutronLines/info.yaml
+++ b/Liv_Lb0NeutronLines/info.yaml
@@ -3,8 +3,9 @@ defaults:
     - juan.baptista.leite@cern.ch
   wg: B2OC
 
-
-###### HLT2 Lines ############
+###################
+## MC HLT2:
+###################
 
 # 2024
 {%- set polarities = [
@@ -25,7 +26,6 @@ defaults:
   application: "Moore/v55r11p2@x86_64_v2-el9-gcc13+detdesc-opt"
   input: 
     bk_query: /MC/Dev/Beam6800GeV-expected-2024-Mag{{p}}-Nu{{nu}}-25ns-Pythia8/{{simul}}/{{evttype}}/{{inptype}}
-    n_test_lfns: 10
     dq_flags:
       - OK
   output: MC_HLT1.DST
@@ -39,8 +39,6 @@ defaults:
       output_type: ROOT
       simulation: True
       data_type: "Upgrade"
-      # evt_max: 1000
-      print_freq: 100
       scheduler_legacy_mode: False
       compression:
         algorithm: ZSTD
@@ -98,8 +96,9 @@ defaults:
 {%- endfor %}
 {%- endfor %}
 
+
 ###################
-## HLT2:
+## Data HLT2:
 ###################
 
 {%- for p in polarities %}
@@ -112,7 +111,6 @@ defaults:
       - UNCHECKED
       - OK
     keep_running: True
-    #n_test_lfns: 1
   output: RealData_{{sigtype}}.ROOT
   options:
     entrypoint: Liv_Lb0NeutronLines.main_Liv_{{sigtype}}:main
@@ -125,9 +123,7 @@ defaults:
       conditions_version: master
       input_process: "TurboPass"
       input_stream: "b2oc"
-      # evt_max: 50000
-      # print_freq: 1000
-      #first_evt: 1
+      evt_max: 10000
 {%- endfor %}
 {%- endfor %}
 
@@ -159,13 +155,12 @@ defaults:
       conditions_version: master
       input_process: "TurboPass"
       input_stream: "b2oc"
-      # evt_max: 50000
-      # print_freq: 1000
-      #first_evt: 1
 {%- endfor %}
 {%- endfor %}
 
-###### Sprucing Lines ############
+###################
+## Data Spruce:
+###################
 
 {%- set mc_datasets = [
  ('Lb0ToLcpLcmN0', '' , '', '', ''),
@@ -184,7 +179,6 @@ defaults:
       - UNCHECKED
       - OK
     keep_running: True
-    n_test_lfns: 1
   output: RealData_{{sigtype}}.ROOT
   options:
     entrypoint: Liv_Lb0NeutronLines.main_Liv_{{sigtype}}_Spruce:main
@@ -197,9 +191,6 @@ defaults:
       conditions_version: master
       input_process: "Spruce"
       input_stream: "b2oc"
-      # evt_max: 50000
-      # print_freq: 1000
-      #first_evt: 1
 {%- endfor %}
 {%- endfor %}
 
@@ -225,8 +216,5 @@ defaults:
       conditions_version: master
       input_process: Spruce
       input_stream: b2oc
-      # evt_max: 50000
-      # print_freq: 1000
-      #first_evt: 1
 {%- endfor %}
 {%- endfor %}
\ No newline at end of file
diff --git a/Liv_Lb0NeutronLines/main_Liv_Lb0ToPpPmN0.py b/Liv_Lb0NeutronLines/main_Liv_Lb0ToPbarPN0.py
similarity index 100%
rename from Liv_Lb0NeutronLines/main_Liv_Lb0ToPpPmN0.py
rename to Liv_Lb0NeutronLines/main_Liv_Lb0ToPbarPN0.py
diff --git a/Liv_Lb0NeutronLines/main_Liv_Lb0ToPpPmN0_Spuce.py b/Liv_Lb0NeutronLines/main_Liv_Lb0ToPbarPN0_Spuce.py
similarity index 100%
rename from Liv_Lb0NeutronLines/main_Liv_Lb0ToPpPmN0_Spuce.py
rename to Liv_Lb0NeutronLines/main_Liv_Lb0ToPbarPN0_Spuce.py
-- 
GitLab


From 6861724568c7ade845cf413cd13d8f6ad7f9fdf8 Mon Sep 17 00:00:00 2001
From: Juan Leite <jbaptist@lxplus974.cern.ch>
Date: Wed, 21 Aug 2024 22:04:59 +0200
Subject: [PATCH 27/34] remove evt_max

---
 Liv_Lb0NeutronLines/info.yaml | 1 -
 1 file changed, 1 deletion(-)

diff --git a/Liv_Lb0NeutronLines/info.yaml b/Liv_Lb0NeutronLines/info.yaml
index f360045a21..d3bffcc4f8 100644
--- a/Liv_Lb0NeutronLines/info.yaml
+++ b/Liv_Lb0NeutronLines/info.yaml
@@ -123,7 +123,6 @@ defaults:
       conditions_version: master
       input_process: "TurboPass"
       input_stream: "b2oc"
-      evt_max: 10000
 {%- endfor %}
 {%- endfor %}
 
-- 
GitLab


From 5a23ecf29bd35d4576a22e11c5cae96498d616cc Mon Sep 17 00:00:00 2001
From: Juan Leite <jbaptist@lxplus974.cern.ch>
Date: Wed, 21 Aug 2024 22:50:28 +0200
Subject: [PATCH 28/34] fix file name

---
 Liv_Lb0NeutronLines/info.yaml                                   | 2 +-
 ...iv_Lb0ToPbarPN0_Spuce.py => main_Liv_Lb0ToPbarPN0_Spruce.py} | 0
 2 files changed, 1 insertion(+), 1 deletion(-)
 rename Liv_Lb0NeutronLines/{main_Liv_Lb0ToPbarPN0_Spuce.py => main_Liv_Lb0ToPbarPN0_Spruce.py} (100%)

diff --git a/Liv_Lb0NeutronLines/info.yaml b/Liv_Lb0NeutronLines/info.yaml
index d3bffcc4f8..56fc579916 100644
--- a/Liv_Lb0NeutronLines/info.yaml
+++ b/Liv_Lb0NeutronLines/info.yaml
@@ -188,7 +188,7 @@ defaults:
       data_type: Upgrade
       geometry_version: run3/trunk
       conditions_version: master
-      input_process: "Spruce"
+      input_process: Spruce
       input_stream: "b2oc"
 {%- endfor %}
 {%- endfor %}
diff --git a/Liv_Lb0NeutronLines/main_Liv_Lb0ToPbarPN0_Spuce.py b/Liv_Lb0NeutronLines/main_Liv_Lb0ToPbarPN0_Spruce.py
similarity index 100%
rename from Liv_Lb0NeutronLines/main_Liv_Lb0ToPbarPN0_Spuce.py
rename to Liv_Lb0NeutronLines/main_Liv_Lb0ToPbarPN0_Spruce.py
-- 
GitLab


From fb1299897e20f7aa5ea94391a3f24bf23c5f291a Mon Sep 17 00:00:00 2001
From: Shuqi Sheng <shuqi.sheng@cern.ch>
Date: Thu, 22 Aug 2024 05:19:44 +0200
Subject: [PATCH 29/34] Change BKK path

---
 Liv_Lb0NeutronLines/info.yaml | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/Liv_Lb0NeutronLines/info.yaml b/Liv_Lb0NeutronLines/info.yaml
index 56fc579916..5c96bfb2b6 100644
--- a/Liv_Lb0NeutronLines/info.yaml
+++ b/Liv_Lb0NeutronLines/info.yaml
@@ -1,6 +1,7 @@
 defaults:
   inform:
     - juan.baptista.leite@cern.ch
+    - shuqi.sheng@cern.ch
   wg: B2OC
 
 ###################
@@ -106,7 +107,7 @@ defaults:
 {{sigtype}}_Mag{{p}}_Data_Hlt2_Spc2_Tuple:
   application: "DaVinci/v64r8@x86_64_v2-el9-clang16-opt"
   input:
-    bk_query: /LHCb/Collision24/Beam6800GeV-VeloClosed-Mag{{p}}/Real Data/Sprucing24c2/94000000/B2OC.DST
+    bk_query: /LHCb/Collision24/Beam6800GeV-VeloClosed-Mag{{p}}/Real Data/Sprucing24c2/90000000/B2OC.DST
     dq_flags:
       - UNCHECKED
       - OK
@@ -198,7 +199,7 @@ defaults:
 {{sigtype}}_Mag{{p}}_Data_Spruce_ExclUT_Spc1_Tuple:
   application: "DaVinci/v64r8@x86_64_v2-el9-clang16-opt"
   input:
-    bk_query: /LHCb/Collision24/Beam6800GeV-VeloClosed-Mag{{p}}-Excl-UT/Real Data/Sprucing24c1/94000000/B2OC.DST
+    bk_query: /LHCb/Collision24/Beam6800GeV-VeloClosed-Mag{{p}}-Excl-UT/Real Data/Sprucing24c1/90000000/B2OC.DST
     dq_flags:
       - UNCHECKED
       - OK
@@ -216,4 +217,4 @@ defaults:
       input_process: Spruce
       input_stream: b2oc
 {%- endfor %}
-{%- endfor %}
\ No newline at end of file
+{%- endfor %}
-- 
GitLab


From 66e493b39dfbc501cb437d2ce62b0bbf546450a0 Mon Sep 17 00:00:00 2001
From: Juan Leite <juan.baptista.leite@cern.ch>
Date: Thu, 22 Aug 2024 07:19:32 +0200
Subject: [PATCH 30/34] change  Spruce bk_query

---
 Liv_Lb0NeutronLines/info.yaml | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/Liv_Lb0NeutronLines/info.yaml b/Liv_Lb0NeutronLines/info.yaml
index 5c96bfb2b6..45e6d566ca 100644
--- a/Liv_Lb0NeutronLines/info.yaml
+++ b/Liv_Lb0NeutronLines/info.yaml
@@ -107,7 +107,7 @@ defaults:
 {{sigtype}}_Mag{{p}}_Data_Hlt2_Spc2_Tuple:
   application: "DaVinci/v64r8@x86_64_v2-el9-clang16-opt"
   input:
-    bk_query: /LHCb/Collision24/Beam6800GeV-VeloClosed-Mag{{p}}/Real Data/Sprucing24c2/90000000/B2OC.DST
+    bk_query: /LHCb/Collision24/Beam6800GeV-VeloClosed-Mag{{p}}/Real Data/Sprucing24c2/94000000/B2OC.DST
     dq_flags:
       - UNCHECKED
       - OK
@@ -199,7 +199,7 @@ defaults:
 {{sigtype}}_Mag{{p}}_Data_Spruce_ExclUT_Spc1_Tuple:
   application: "DaVinci/v64r8@x86_64_v2-el9-clang16-opt"
   input:
-    bk_query: /LHCb/Collision24/Beam6800GeV-VeloClosed-Mag{{p}}-Excl-UT/Real Data/Sprucing24c1/90000000/B2OC.DST
+    bk_query: /LHCb/Collision24/Beam6800GeV-VeloClosed-Mag{{p}}-Excl-UT/Real Data/Sprucing24c1/94000000/B2OC.DST
     dq_flags:
       - UNCHECKED
       - OK
-- 
GitLab


From a5ea919460d4e5daa0fa8c680cd1392dfc288568 Mon Sep 17 00:00:00 2001
From: Juan Leite <juan.baptista.leite@cern.ch>
Date: Thu, 22 Aug 2024 07:27:38 +0200
Subject: [PATCH 31/34] HLT2 Turbo, Spruce Full

---
 Liv_Lb0NeutronLines/info.yaml | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/Liv_Lb0NeutronLines/info.yaml b/Liv_Lb0NeutronLines/info.yaml
index 45e6d566ca..b4d0eedf14 100644
--- a/Liv_Lb0NeutronLines/info.yaml
+++ b/Liv_Lb0NeutronLines/info.yaml
@@ -174,7 +174,7 @@ defaults:
 {{sigtype}}_Mag{{p}}_Data_Spruce_Spc2_Tuple:
   application: "DaVinci/v64r8@x86_64_v2-el9-clang16-opt"
   input:
-    bk_query: /LHCb/Collision24/Beam6800GeV-VeloClosed-Mag{{p}}/Real Data/Sprucing24c2/94000000/B2OC.DST
+    bk_query: /LHCb/Collision24/Beam6800GeV-VeloClosed-Mag{{p}}/Real Data/Sprucing24c2/90000000/B2OC.DST
     dq_flags:
       - UNCHECKED
       - OK
@@ -199,7 +199,7 @@ defaults:
 {{sigtype}}_Mag{{p}}_Data_Spruce_ExclUT_Spc1_Tuple:
   application: "DaVinci/v64r8@x86_64_v2-el9-clang16-opt"
   input:
-    bk_query: /LHCb/Collision24/Beam6800GeV-VeloClosed-Mag{{p}}-Excl-UT/Real Data/Sprucing24c1/94000000/B2OC.DST
+    bk_query: /LHCb/Collision24/Beam6800GeV-VeloClosed-Mag{{p}}-Excl-UT/Real Data/Sprucing24c1/90000000/B2OC.DST
     dq_flags:
       - UNCHECKED
       - OK
-- 
GitLab


From b3dc9365b00c66b33501f7ee338dc6174cd98d7d Mon Sep 17 00:00:00 2001
From: Juan Leite <jbaptist@lxplus951.cern.ch>
Date: Thu, 22 Aug 2024 08:40:33 +0200
Subject: [PATCH 32/34] fix pipeline

---
 Liv_Lb0NeutronLines/info.yaml                  |  1 +
 .../options/Lb_NeutronLines_HLT2.py            | 16 ++++++++--------
 .../options/Lb_NeutronLines_Spruce.py          | 18 +++++++++---------
 3 files changed, 18 insertions(+), 17 deletions(-)

diff --git a/Liv_Lb0NeutronLines/info.yaml b/Liv_Lb0NeutronLines/info.yaml
index b4d0eedf14..f0ea93def3 100644
--- a/Liv_Lb0NeutronLines/info.yaml
+++ b/Liv_Lb0NeutronLines/info.yaml
@@ -191,6 +191,7 @@ defaults:
       conditions_version: master
       input_process: Spruce
       input_stream: "b2oc"
+      evt_max: 10000
 {%- endfor %}
 {%- endfor %}
 
diff --git a/Liv_Lb0NeutronLines/options/Lb_NeutronLines_HLT2.py b/Liv_Lb0NeutronLines/options/Lb_NeutronLines_HLT2.py
index 23ee7c6afc..94b99244cf 100644
--- a/Liv_Lb0NeutronLines/options/Lb_NeutronLines_HLT2.py
+++ b/Liv_Lb0NeutronLines/options/Lb_NeutronLines_HLT2.py
@@ -48,13 +48,13 @@ def maketuple_Lb0ToLcpLcnN0(options, pvs, rec_summary):
     DTF_MASS = DecayTreeFitter(
         name='DTF_{hash}',
         input_particles=input_data,
-        mass_constraints=["Lambda_b0", "Lambda_c+"],
+        mass_constraints=["Lambda_c+"],
     )
 
     DTF_MASS_OWNPV = DecayTreeFitter(
         name='DTF_{hash}',
         input_particles=input_data,
-        mass_constraints=["Lambda_b0", "Lambda_c+"],
+        mass_constraints=["Lambda_c+"],
         constrain_to_ownpv=True,
     )
 
@@ -67,8 +67,8 @@ def maketuple_Lb0ToLcpLcnN0(options, pvs, rec_summary):
     composite_variables_3body = make_composite_variables_3body(
         options, pvs, input_data, add_tistos=False)
 
-    DTF_TwoBody = make_composite_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_MASS, pv_constraint=False, mass_constraint=True, particle_name="", three_body=False) +\
-               make_composite_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_MASS_OWNPV, pv_constraint=False, three_body=False, mass_constraint=True,particle_name="_OWNPV") #same as BEST
+    DTF_TwoBody = make_composite_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_MASS, pv_constraint=False, mass_constraint=True, particle_name="_Lc", three_body=False) +\
+               make_composite_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_MASS_OWNPV, pv_constraint=True, three_body=False, mass_constraint=True,particle_name="_Lc") #same as BEST
 
     variables = {
         "Lb0": composite_variables + DTF_TwoBody,
@@ -131,13 +131,13 @@ def maketuple_BpToLcpLcmKp(options, pvs, rec_summary):
     DTF_MASS = DecayTreeFitter(
         name='DTF_{hash}',
         input_particles=input_data,
-        mass_constraints=["B+", "Lambda_c+"],
+        mass_constraints=["Lambda_c+"],
     )
 
     DTF_MASS_OWNPV = DecayTreeFitter(
         name='DTF_{hash}',
         input_particles=input_data,
-        mass_constraints=["B+", "Lambda_c+"],
+        mass_constraints=["Lambda_c+"],
         constrain_to_ownpv=True,
     )
 
@@ -146,8 +146,8 @@ def maketuple_BpToLcpLcmKp(options, pvs, rec_summary):
     composite_variables_3body = make_composite_variables_3body(
         options, pvs, input_data)
 
-    DTFVars = make_composite_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_MASS, pv_constraint=False, three_body=True, mass_constraint=True,particle_name="") +\
-        make_composite_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_MASS_OWNPV, pv_constraint=False, three_body=True, mass_constraint=True,particle_name="_OWNPV") #same as BEST
+    DTFVars = make_composite_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_MASS, pv_constraint=False, three_body=True, mass_constraint=True,particle_name="_Lc") +\
+        make_composite_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_MASS_OWNPV, pv_constraint=True, three_body=True, mass_constraint=True,particle_name="_Lc") #same as BEST
 
     MVA_variables = make_MVA_variables()
 
diff --git a/Liv_Lb0NeutronLines/options/Lb_NeutronLines_Spruce.py b/Liv_Lb0NeutronLines/options/Lb_NeutronLines_Spruce.py
index ea2eb5f197..a0504dfbe2 100644
--- a/Liv_Lb0NeutronLines/options/Lb_NeutronLines_Spruce.py
+++ b/Liv_Lb0NeutronLines/options/Lb_NeutronLines_Spruce.py
@@ -48,13 +48,13 @@ def maketuple_Lb0ToLcpLcnN0(options, pvs, rec_summary):
     DTF_MASS = DecayTreeFitter(
         name='DTF_{hash}',
         input_particles=input_data,
-        mass_constraints=["Lambda_b0", "Lambda_c+"],
+        mass_constraints=["Lambda_c+"],
     )
 
     DTF_MASS_OWNPV = DecayTreeFitter(
         name='DTF_{hash}',
         input_particles=input_data,
-        mass_constraints=["Lambda_b0", "Lambda_c+"],
+        mass_constraints=["Lambda_c+"],
         constrain_to_ownpv=True,
     )
 
@@ -63,8 +63,8 @@ def maketuple_Lb0ToLcpLcnN0(options, pvs, rec_summary):
     composite_variables_3body = make_composite_variables_3body(
         options, pvs, input_data)
 
-    DTF_TwoBody = make_composite_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_MASS, pv_constraint=False, mass_constraint=True, particle_name="", three_body=False) +\
-               make_composite_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_MASS_OWNPV, pv_constraint=False, three_body=False, mass_constraint=True,particle_name="_OWNPV") #same as BEST
+    DTF_TwoBody = make_composite_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_MASS, pv_constraint=False, mass_constraint=True, particle_name="_Lc", three_body=False) +\
+               make_composite_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_MASS_OWNPV, pv_constraint=True, three_body=False, mass_constraint=True,particle_name="_Lc") #same as BEST
 
     variables = {
         "Lb0": composite_variables + DTF_TwoBody,
@@ -127,21 +127,21 @@ def maketuple_BpToLcpLcmKp(options, pvs, rec_summary):
     DTF_MASS = DecayTreeFitter(
         name='DTF_{hash}',
         input_particles=input_data,
-        mass_constraints=["B+", "Lambda_c+"],
+        mass_constraints=["Lambda_c+"],
     )
 
     DTF_MASS_OWNPV = DecayTreeFitter(
         name='DTF_{hash}',
         input_particles=input_data,
-        mass_constraints=["B+", "Lambda_c+"],
+        mass_constraints=["Lambda_c+"],
         constrain_to_ownpv=True,
     )
 
     basic_variables = make_basic_variables(options, pvs, input_data)
 
     composite_variables_3body = make_composite_variables_3body(options, pvs, input_data) +\
-        make_composite_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_MASS, pv_constraint=False, three_body=True, mass_constraint=True,particle_name="") +\
-        make_composite_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_MASS_OWNPV, pv_constraint=False, three_body=True, mass_constraint=True,particle_name="_OWNPV") #same as BEST
+        make_composite_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_MASS, pv_constraint=False, three_body=True, mass_constraint=True,particle_name="_Lc") +\
+        make_composite_dtf_variables(options, pvs, input_data, add_truth=True, DTF=DTF_MASS_OWNPV, pv_constraint=True, three_body=True, mass_constraint=True,particle_name="_Lc") #same as BEST
 
     MVA_variables = make_MVA_variables()
 
@@ -174,7 +174,7 @@ def maketuple_Lb0ToPpPmN0(options, pvs, rec_summary):
 
     name = "Lb0ToPbarPN0"
     turbo_line = "SpruceB2OC_Lb0ToPbarPN0"
-    input_data = get_particles(f"/Event/HLT2/{turbo_line}/Particles")
+    input_data = get_particles(f"/Event/Spruce/{turbo_line}/Particles")
 
     myfilter = create_lines_filter(
         f"LineFilter_{turbo_line}_{{hash}}",
-- 
GitLab


From ca30d9b77265ca51c7ce714a9e22d20b828178c9 Mon Sep 17 00:00:00 2001
From: Juan Leite <jbaptist@lxplus951.cern.ch>
Date: Thu, 22 Aug 2024 08:54:18 +0200
Subject: [PATCH 33/34] =?UTF-8?q?remove=20evt=5Fmax=20(=20=C2=AC=E2=A4=99?=
 =?UTF-8?q?=C2=AC=20)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 Liv_Lb0NeutronLines/info.yaml | 1 -
 1 file changed, 1 deletion(-)

diff --git a/Liv_Lb0NeutronLines/info.yaml b/Liv_Lb0NeutronLines/info.yaml
index f0ea93def3..b4d0eedf14 100644
--- a/Liv_Lb0NeutronLines/info.yaml
+++ b/Liv_Lb0NeutronLines/info.yaml
@@ -191,7 +191,6 @@ defaults:
       conditions_version: master
       input_process: Spruce
       input_stream: "b2oc"
-      evt_max: 10000
 {%- endfor %}
 {%- endfor %}
 
-- 
GitLab


From b72316f87999f709010bcdc298c9df19e1039548 Mon Sep 17 00:00:00 2001
From: Juan Leite <jbaptist@lxplus951.cern.ch>
Date: Thu, 22 Aug 2024 13:00:59 +0200
Subject: [PATCH 34/34] comment MC

---
 Liv_Lb0NeutronLines/info.yaml          | 150 ++++++++++++-------------
 Liv_Lb0NeutronLines/options/tupling.py |  68 ++++++-----
 2 files changed, 117 insertions(+), 101 deletions(-)

diff --git a/Liv_Lb0NeutronLines/info.yaml b/Liv_Lb0NeutronLines/info.yaml
index b4d0eedf14..4435551a2c 100644
--- a/Liv_Lb0NeutronLines/info.yaml
+++ b/Liv_Lb0NeutronLines/info.yaml
@@ -20,82 +20,82 @@ defaults:
 ]%}
 
 
-{%- for p in polarities %}
-{%- for sigtype, simul, nu, inptype, evttype in mc_datasets %}
-
-{{sigtype}}_Mag{{p}}_MC_HLT1:
-  application: "Moore/v55r11p2@x86_64_v2-el9-gcc13+detdesc-opt"
-  input: 
-    bk_query: /MC/Dev/Beam6800GeV-expected-2024-Mag{{p}}-Nu{{nu}}-25ns-Pythia8/{{simul}}/{{evttype}}/{{inptype}}
-    dq_flags:
-      - OK
-  output: MC_HLT1.DST
-  options: 
-    entrypoint: Liv_Lb0NeutronLines.hlt1:alg_config
-    extra_options:
-      input_raw_format: 0.5
-      conddb_tag: sim-20231017-vc-md100
-      dddb_tag: dddb-20231017
-      input_type: ROOT
-      output_type: ROOT
-      simulation: True
-      data_type: "Upgrade"
-      scheduler_legacy_mode: False
-      compression:
-        algorithm: ZSTD
-        level: 1
-        max_buffer_size: 1048576
-
-{{sigtype}}_Mag{{p}}_MC_HLT2:
-  application: "Moore/v55r11p2@x86_64_v2-el9-gcc13+detdesc-opt"
-  input:
-    job_name: {{sigtype}}_Mag{{p}}_MC_HLT1
-  output: MC_HLT2_full.DST
-  options:
-    entrypoint: Liv_Lb0NeutronLines.hlt2:alg_config
-    extra_options:
-      conddb_tag: sim-20231017-vc-md100
-      dddb_tag: dddb-20231017
-      input_type: "ROOT"
-      output_type: "ROOT"
-      simulation: True
-      input_process: "Hlt2"
-      persistreco_version: 0.0
-      data_type: "Upgrade"
-      evt_max: -1
-      output_manifest_file: "HLT2.tck.json"
-      scheduler_legacy_mode: False
-      compression:
-        algorithm: ZSTD
-        level: 1
-        max_buffer_size: 1048576
+# {%- for p in polarities %}
+# {%- for sigtype, simul, nu, inptype, evttype in mc_datasets %}
+
+# {{sigtype}}_Mag{{p}}_MC_HLT1:
+#   application: "Moore/v55r11p2@x86_64_v2-el9-gcc13+detdesc-opt"
+#   input: 
+#     bk_query: /MC/Dev/Beam6800GeV-expected-2024-Mag{{p}}-Nu{{nu}}-25ns-Pythia8/{{simul}}/{{evttype}}/{{inptype}}
+#     dq_flags:
+#       - OK
+#   output: MC_HLT1.DST
+#   options: 
+#     entrypoint: Liv_Lb0NeutronLines.hlt1:alg_config
+#     extra_options:
+#       input_raw_format: 0.5
+#       conddb_tag: sim-20231017-vc-md100
+#       dddb_tag: dddb-20231017
+#       input_type: ROOT
+#       output_type: ROOT
+#       simulation: True
+#       data_type: "Upgrade"
+#       scheduler_legacy_mode: False
+#       compression:
+#         algorithm: ZSTD
+#         level: 1
+#         max_buffer_size: 1048576
+
+# {{sigtype}}_Mag{{p}}_MC_HLT2:
+#   application: "Moore/v55r11p2@x86_64_v2-el9-gcc13+detdesc-opt"
+#   input:
+#     job_name: {{sigtype}}_Mag{{p}}_MC_HLT1
+#   output: MC_HLT2_full.DST
+#   options:
+#     entrypoint: Liv_Lb0NeutronLines.hlt2:alg_config
+#     extra_options:
+#       conddb_tag: sim-20231017-vc-md100
+#       dddb_tag: dddb-20231017
+#       input_type: "ROOT"
+#       output_type: "ROOT"
+#       simulation: True
+#       input_process: "Hlt2"
+#       persistreco_version: 0.0
+#       data_type: "Upgrade"
+#       evt_max: -1
+#       output_manifest_file: "HLT2.tck.json"
+#       scheduler_legacy_mode: False
+#       compression:
+#         algorithm: ZSTD
+#         level: 1
+#         max_buffer_size: 1048576
         
-{{sigtype}}_Mag{{p}}_MC_Tuple:
-  application: "DaVinci/v64r8@x86_64_v2-el9-clang16+detdesc-opt"
-  input:
-    job_name: {{sigtype}}_Mag{{p}}_MC_HLT2
-  output: MC_{{sigtype}}.ROOT
-  options:
-    entrypoint: Liv_Lb0NeutronLines.main_Liv_{{sigtype}}:main
-    extra_options:
-      input_raw_format: 0.5
-      input_type: ROOT
-      simulation: True
-      data_type: Upgrade
-      conddb_tag: sim-20231017-vc-md100
-      dddb_tag: dddb-20231017
-      input_process: "Hlt2"
-      conditions_version: master
-      lumi: false
-      output_type: ROOT
-      persistreco_version: 0.0
-      write_decoding_keys_to_git: True
-      input_manifest_file: "HLT2.tck.json"
-      input_stream: default
-
-
-{%- endfor %}
-{%- endfor %}
+# {{sigtype}}_Mag{{p}}_MC_Tuple:
+#   application: "DaVinci/v64r8@x86_64_v2-el9-clang16+detdesc-opt"
+#   input:
+#     job_name: {{sigtype}}_Mag{{p}}_MC_HLT2
+#   output: MC_{{sigtype}}.ROOT
+#   options:
+#     entrypoint: Liv_Lb0NeutronLines.main_Liv_{{sigtype}}:main
+#     extra_options:
+#       input_raw_format: 0.5
+#       input_type: ROOT
+#       simulation: True
+#       data_type: Upgrade
+#       conddb_tag: sim-20231017-vc-md100
+#       dddb_tag: dddb-20231017
+#       input_process: "Hlt2"
+#       conditions_version: master
+#       lumi: false
+#       output_type: ROOT
+#       persistreco_version: 0.0
+#       write_decoding_keys_to_git: True
+#       input_manifest_file: "HLT2.tck.json"
+#       input_stream: default
+
+
+# {%- endfor %}
+# {%- endfor %}
 
 
 ###################
diff --git a/Liv_Lb0NeutronLines/options/tupling.py b/Liv_Lb0NeutronLines/options/tupling.py
index 479db2b863..c0ec073625 100644
--- a/Liv_Lb0NeutronLines/options/tupling.py
+++ b/Liv_Lb0NeutronLines/options/tupling.py
@@ -103,8 +103,8 @@ Hlt1_lines = Hlt1_1track_lines + [
 Hlt2_lines = [
     "Hlt2Topo2BodyDecision", "Hlt2Topo3BodyDecision",
     "Hlt2B2OC_Lb0ToLcpLcmN0Decision", "Hlt2B2OC_BuToLcpLcmK_LcpToPKPiDecision",
-    "Hlt2B2OC_Lb0ToPbarPN0", "SpruceB2OC_Lb0ToLcpLcmN0Decision",
-    "SpruceB2OC_BuToLcpLcmK_LcpToPKPiDecision", "SpruceB2OC_Lb0ToPbarPN0"
+    "Hlt2B2OC_Lb0ToPbarPN0Decision", "SpruceB2OC_Lb0ToLcpLcmN0Decision",
+    "SpruceB2OC_BuToLcpLcmK_LcpToPKPiDecision", "SpruceB2OC_Lb0ToPbarPN0Decision",
 ]
 
 
@@ -602,39 +602,35 @@ def make_composite_dtf_variables(options,
             F.SUBCOMB(Functor=F.MASS, Indices=(2, 3)),
         })
 
-    dtf_extras = FunctorCollection({
-        "DTF" + particle_name + "_NITER":
-        DTF.NITER,
-        "DTF" + particle_name + "_CHI2":
-        DTF.CHI2,
-        "DTF" + particle_name + "_NDOF":
-        DTF.NDOF,
-        "DTF" + particle_name + "_CHI2DOF":
-        DTF.CHI2DOF,
-        "DTF" + particle_name + "_M":
-        DTF.MASS,
-        "DTF" + particle_name + "_MERR":
-        DTF.MASSERR,
-        "DTF" + particle_name + "_MERR":
-        DTF.MASSERR,
-        "DTF" + particle_name + "_FD":
-        DTF.FD,
-        "DTF" + particle_name + "_FDERR":
-        DTF.FDERR,
-        "DTF" + particle_name + "_CTAU":
-        DTF.CTAU,
-        "DTF" + particle_name + "_CTAUERR":
-        DTF.CTAUERR,
-    })
 
     if (mass_constraint):
         if (pv_constraint):  # MASS + PV
+            dtf_extras = FunctorCollection({
+                "DTF_PV_M" + particle_name + "_NITER":
+                DTF.NITER,
+                "DTF_PV_M" + particle_name + "_CHI2DOF" :
+                DTF.CHI2DOF,
+                "DTF_PV_M" + particle_name + "_M":
+                DTF.MASS,
+                "DTF_PV_M" + particle_name + "_MASSERR":
+                DTF.MASSERR,
+            })
             dtf_variables_mass_pv = FunctorCollection({
                 'DTF_PV_M' + particle_name + '_' + k: DTF(v)
                 for k, v in variables.get_thor_functors().items()
             })
             return dtf_variables_mass_pv + dtf_extras
         else:  # MASS
+            dtf_extras = FunctorCollection({
+                "DTF_M" + particle_name + "_NITER":
+                DTF.NITER,
+                "DTF_M" + particle_name + "_CHI2DOF" :
+                DTF.CHI2DOF,
+                "DTF_M" + particle_name + "_M":
+                DTF.MASS,
+                "DTF_M" + particle_name + "_MASSERR":
+                DTF.MASSERR,
+            })
             dtf_variables_mass = FunctorCollection({
                 'DTF_M' + particle_name + '_' + k: DTF(v)
                 for k, v in variables.get_thor_functors().items()
@@ -642,6 +638,16 @@ def make_composite_dtf_variables(options,
         return dtf_variables_mass + dtf_extras
 
     elif (pv_constraint):  # PV
+        dtf_extras = FunctorCollection({
+                "DTF_PV" + particle_name + "_NITER":
+                DTF.NITER,
+                "DTF_PV" + particle_name + "_CHI2DOF" :
+                DTF.CHI2DOF,
+                "DTF_PV" + particle_name + "_M":
+                DTF.MASS,
+                "DTF_PV" + particle_name + "_MASSERR":
+                DTF.MASSERR,
+            })
         dtf_variables_pv = FunctorCollection({
             'DTF_PV_' + k: DTF(v)
             for k, v in variables.get_thor_functors().items()
@@ -649,6 +655,16 @@ def make_composite_dtf_variables(options,
         return dtf_variables_pv + dtf_extras
 
     else:  # NO MASS/PV
+        dtf_extras = FunctorCollection({
+                "DTF" + particle_name + "_NITER":
+                DTF.NITER,
+                "DTF" + particle_name + "_CHI2DOF" :
+                DTF.CHI2DOF,
+                "DTF" + particle_name + "_M":
+                DTF.MASS,
+                "DTF" + particle_name + "_MASSERR":
+                DTF.MASSERR,
+            })
         dtf_variables = FunctorCollection({
             'DTF_' + k: DTF(v)
             for k, v in variables.get_thor_functors().items()
-- 
GitLab