From 8806b53532d56007f6cf86b2abf0f94b48331d41 Mon Sep 17 00:00:00 2001
From: KaiHabermann <kai.habermann@gmx.net>
Date: Mon, 27 Jan 2025 14:49:53 +0100
Subject: [PATCH 01/42] Lets see what happens

---
 Lb2LcD0K_2024_eo_spruce/Lb2LcD0K.py | 176 ++++++++++
 Lb2LcD0K_2024_eo_spruce/commons.py  | 477 ++++++++++++++++++++++++++++
 Lb2LcD0K_2024_eo_spruce/info.yaml   |  33 ++
 3 files changed, 686 insertions(+)
 create mode 100644 Lb2LcD0K_2024_eo_spruce/Lb2LcD0K.py
 create mode 100644 Lb2LcD0K_2024_eo_spruce/commons.py
 create mode 100644 Lb2LcD0K_2024_eo_spruce/info.yaml

diff --git a/Lb2LcD0K_2024_eo_spruce/Lb2LcD0K.py b/Lb2LcD0K_2024_eo_spruce/Lb2LcD0K.py
new file mode 100644
index 0000000000..5f0960a0c6
--- /dev/null
+++ b/Lb2LcD0K_2024_eo_spruce/Lb2LcD0K.py
@@ -0,0 +1,176 @@
+from Gaudi.Configuration import INFO, DEBUG
+import Functors as F
+import FunTuple.functorcollections as FC
+from DaVinci import Options, make_config
+from DaVinci.algorithms import create_lines_filter
+from FunTuple import FunctorCollection
+from FunTuple import FunTuple_Particles as Funtuple
+from PyConf.reading import get_particles, get_pvs
+from RecoConf.event_filters import require_pvs
+from DaVinciTools import SubstitutePID
+from PyConf.Algorithms import ParticleContainerMerger
+from DecayTreeFitter import DecayTreeFitter
+
+
+def main(options: Options):
+        
+    user_algorithms = {}
+    line = f"SpruceBandQ_Lb0ToD0barLcpKm"
+    data = get_particles(f"/Event/Spruce/{line}/Particles")
+
+    # Checking it for the same line that our input data lies in is good practice - 
+    # probably it will be just a passthrough but it speeds up the way, the events are accessed
+    # later by the FunTuple
+    line_prefilter = create_lines_filter(name=f"PreFilter_Lb0ToD0barLcpKm", lines=[f"{line}"])
+
+
+    
+
+
+    # Get primary vertices for the event
+    # Essential for calculating displacement-based variables and performing fits
+    pvs = get_pvs()
+    
+    # fields = {
+    #     "B":         "[B0 ->  (D_s- -> (K+ || pi+)  (K- || pi-) (pi- || K-)) (KS0-> pi+ pi-) pi+]CC",
+    #     "Ds":        "[B0 ->  ^(D_s- -> (K+ || pi+)  (K- || pi-) (pi- || K-)) (KS0-> pi+ pi-) pi+]CC",
+    #     "KS0":       "[B0 ->  (D_s- -> (K+ || pi+)  (K- || pi-) (pi- || K-)) ^(KS0-> pi+ pi-) pi+]CC",
+    #     "PiPrompt":  "[B0 ->  (D_s- -> (K+ || pi+)  (K- || pi-) (pi- || K-)) (KS0-> pi+ pi-) ^pi+]CC",
+    #     "Pi_1_KS0" : "[B0 ->  (D_s- -> (K+ || pi+)  (K- || pi-) (pi- || K-)) (KS0-> ^pi+ pi-) pi+]CC",
+    #     "Pi_2_KS0" : "[B0 ->  (D_s- -> (K+ || pi+)  (K- || pi-) (pi- || K-)) (KS0-> pi+ ^pi-) pi+]CC",
+    #     "H1":        "[B0 ->  (D_s- -> ^(K+ || pi+)  (K- || pi-) (pi- || K-)) (KS0-> pi+ pi-) pi+]CC",
+    #     "H2":        "[B0 ->  (D_s- -> (K+ || pi+)  ^(K- || pi-) (pi- || K-)) (KS0-> pi+ pi-) pi+]CC",
+    #     "H3":        "[B0 ->  (D_s- -> (K+ || pi+)  (K- || pi-) ^(pi- || K-)) (KS0-> pi+ pi-) pi+]CC",
+    # }
+    
+    fields = {
+        "Lb":        "[[Lambda_b0]CC -> ( Lambda_c+ -> p K- pi+ ) (D0 -> K- pi+) K-]CC",
+        "Lc":        "[[Lambda_b0]CC -> ^( Lambda_c+ -> p K- pi+ ) (D0 -> K- pi+) K-]CC",
+        "D0":        "[[Lambda_b0]CC -> ( Lambda_c+ -> p K- pi+ ) ^(D0 -> K- pi+) K-]CC",
+        "K":        "[[Lambda_b0]CC -> ( Lambda_c+ -> p K- pi+ ) (D0 -> K- pi+) ^K-]CC",
+        "Lc_p":        "[[Lambda_b0]CC -> ( Lambda_c+ -> ^p K- pi+ ) (D0 -> K- pi+) K-]CC",
+        "Lc_K":        "[[Lambda_b0]CC -> ( Lambda_c+ -> p ^K- pi+ ) (D0 -> K- pi+) K-]CC",
+        "Lc_pi":        "[[Lambda_b0]CC -> ( Lambda_c+ -> p K- ^pi+ ) (D0 -> K- pi+) K-]CC",
+        "D0_K":        "[[Lambda_b0]CC -> ( Lambda_c+ -> p K- pi+ ) (D0 -> ^K- pi+) K-]CC",
+        "D0_pi":        "[[Lambda_b0]CC -> ( Lambda_c+ -> p K- pi+ ) (D0 -> K- ^pi+) K-]CC",
+
+    }
+    
+    all_vars = FC.Kinematics()
+    
+    # Create the ntuple configuration
+    # This defines how the output ROOT ntuple will be structured
+    # Original decays + Swapped decays (Merged)
+    
+    evt_variables = FC.EventInfo()
+    
+    composite_variables = FunctorCollection({
+        "ID": F.PARTICLE_ID,
+        "VTXCHI2NDOF": F.CHI2DOF,         # Vertex fit χ²/ndf   I think it was this one before: "VFASPF(VCHI2/VDOF)"
+        "END_VX": F.END_VX,               # x-coordinate of decay vertex
+        "END_VY": F.END_VY,               # y-coordinate of decay vertex
+        "END_VZ": F.END_VZ,               # z-coordinate of decay vertex
+        #"END_CHI2": it was present before
+        #"END_NDOF": it was present before
+        #"END_COV": it was present before
+        # Errors?
+        # OWNPV values
+        "OWNPV_X": F.OWNPVX,      
+        "OWNPV_Y": F.OWNPVY,           
+        "OWNPV_Z": F.OWNPVZ,          
+        # Errors?
+        "OWNPV_DIRA": F.OWNPVDIRA,        # Direction angle cosine wrt own PV
+        "OWNPV_FD": F.OWNPVFD,            # Flight distance wrt own PV
+        "OWNPV_FDCHI2": F.OWNPVFDCHI2,    # Flight distance χ² wrt own PV
+        "OWNPV_IP": F.OWNPVIP,
+        "OWNPV_IPCHI2": F.OWNPVIPCHI2,
+        #"OWNPV_CHI2": it was present before
+        #"OWNPV_NDOF": it was present before
+        #"OWNPV_COV": it was present before
+        # "OWNPV_VDRHO": F.OWNPVVDRHO,      # Radial flight distance wrt own PV
+        # "OWNPV_VDZ": F.OWNPVVDZ,          # z-direction flight distance
+        # "OWNPV_LTIME": F.OWNPVLTIME,      # Proper lifetime
+        # "OWNPV_DLS": F.OWNPVDLS,          # Decay length significance
+        # DOCA
+        # "MAX_OWNPVIPCHI2": F.MAX(F.OWNPVIPCHI2),  # Max IP χ² of daughters
+        # "MIN_OWNPVIPCHI2": F.MIN(F.OWNPVIPCHI2),  # Min IP χ² of daughters
+        # "SUM_OWNPVIPCHI2": F.SUM(F.OWNPVIPCHI2),  # Sum of daughters' IP χ²
+        "MAXDOCA": F.MAXDOCA,              # Maximum DOCA between any daughters
+        #MINDOCA: F.MINDOCA,
+        "BPVDIRA": F.BPVDIRA(pvs),
+        "BPVIPCHI2": F.BPVIPCHI2(pvs),
+        "BPVLTIME": F.BPVLTIME(pvs),
+        "BPVFDCHI2": F.BPVFDCHI2(pvs),
+        "MIPCHI2DV": F.MINIPCHI2(pvs),
+        #"ptasy": used to be "RELINFO('/Event/Bhadron/Phys/B02DKsPiLLD2HHHCFPIDBeauty2CharmLine/P2ConeVar1','CONEPTASYM',-1000.)"
+    })
+    
+    Lc_variables = FunctorCollection({
+        "ID": F.PARTICLE_ID,
+        "VTXCHI2NDOF": F.CHI2DOF,         # Vertex fit χ²/ndf   I think it was this one before: "VFASPF(VCHI2/VDOF)"
+        # "END_VX": F.END_VX,               # x-coordinate of decay vertex
+        # "END_VY": F.END_VY,               # y-coordinate of decay vertex
+        # "END_VZ": F.END_VZ,               # z-coordinate of decay vertex
+        "OWNPV_X": F.OWNPVX,      
+        "OWNPV_Y": F.OWNPVY,           
+        "OWNPV_Z": F.OWNPVZ,          
+        # Errors?
+        "OWNPV_IP": F.OWNPVIP,
+        "OWNPV_IPCHI2": F.OWNPVIPCHI2,
+        "MAXDOCA": F.MAXDOCA,              # Maximum DOCA between any daughters
+        "BPVIPCHI2": F.BPVIPCHI2(pvs),
+        "MIPCHI2DV": F.MINIPCHI2(pvs),
+    })
+
+    children_variables = FunctorCollection({
+        # OWNPV values
+        "OWNPV_X": F.OWNPVX,      
+        "OWNPV_Y": F.OWNPVY,              
+        "OWNPV_Z": F.OWNPVZ,            
+        # Errors?
+        #"OWNPV_DIRA": F.OWNPVDIRA,        # Direction angle cosine wrt own PV - cannot use it (does not have a decay vertex)
+        #"OWNPV_FD": F.OWNPVFD,            # Flight distance wrt own PV - cannot use it (does not have a decay vertex)
+        #"OWNPV_FDCHI2": F.OWNPVFDCHI2,    # Flight distance χ² wrt own PV - cannot use it (does not have a decay vertex)
+        "OWNPV_IP": F.OWNPVIP, 
+        "OWNPV_IPCHI2": F.OWNPVIPCHI2,
+        #"COS_THETA": - is this just DIRA?
+        "BPVIPCHI2": F.BPVIPCHI2(pvs),
+        "CHI2": F.CHI2,
+        "CHI2DOF": F.CHI2DOF,
+        "TRACKTYPE": F.VALUE_OR(-1) @ F.TRACKTYPE @ F.TRACK,
+    })
+    
+    children_variables += FC.ParticleID()
+    
+    variables = {"ALL": all_vars,
+                "Lb": composite_variables,
+                "Lc": Lc_variables,
+                "D0": composite_variables,
+                "K": composite_variables,
+                "Lc_K": children_variables,
+                "Lc_p": children_variables,
+                "Lc_pi": children_variables,
+                "D0_K": children_variables,
+                "D0_pi": children_variables}
+
+    funtuple = Funtuple(
+        name = line,
+        tuple_name = "DecayTree",
+        fields = fields,
+        variables = variables,
+        inputs=data,
+        OutputLevel=INFO,
+        event_variables=evt_variables,  # This additional event variables argument
+        store_multiple_cand_info = True
+        # store_run_event_numbers=True,
+        # run_full_counter_mode = True
+    )
+    
+    # Combine all algorithms in the correct order
+    # Without proper ordering, the prefilter wouldn't work correctly
+    # First we run the prefilter, then an additional further constraint that each candidate has a primary vertex, then run funtuple.
+    user_algorithms.update({line: [line_prefilter, require_pvs(pvs), funtuple]})
+    
+    # Create and return the final DaVinci configuration
+    # This generates the configuration that DaVinci will execute
+    return make_config(options, user_algorithms)
diff --git a/Lb2LcD0K_2024_eo_spruce/commons.py b/Lb2LcD0K_2024_eo_spruce/commons.py
new file mode 100644
index 0000000000..aaa1a2b303
--- /dev/null
+++ b/Lb2LcD0K_2024_eo_spruce/commons.py
@@ -0,0 +1,477 @@
+##############################################################################
+# (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
+import Functors.math as fmath
+
+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,
+    LHCInfo,
+    ParticleIsolation,
+    MCPrimaries,
+    MCReconstructed,
+    MCReconstructible,
+    NeutralCaloInfo
+)
+
+from IsolationTools import VertexAndConeIsolation
+
+from DaVinciMCTools import MCTruthAndBkgCat, MCReconstructed, MCReconstructible
+from PyConf.Algorithms import ParticleToSubcombinationsAlg
+from DecayTreeFitter import DecayTreeFitter
+
+Hlt1_global_lines = [
+    "Hlt1ODINLumiDecision",  # 33 kHz
+    "Hlt1TrackMVADecision",
+    "Hlt1TwoTrackMVADecision",
+]
+Hlt1_1track_lines = [
+    "Hlt1TrackMVADecision",       #  y
+    "Hlt1TrackMuonMVADecision",   # tis
+    "Hlt1OneMuonTrackLineDecision", #tis
+    "Hlt1TrackElectronMVADecision", #tis
+]
+Hlt1_lines = Hlt1_1track_lines+[
+    "Hlt1D2KshhDecision",
+    "Hlt1TwoTrackMVACharmXSecDecision",
+    "Hlt1TwoTrackMVADecision",      # y-D0
+    "Hlt1TwoTrackKsDecision",       #tis 
+    "Hlt1D2KPiDecision",            # y-D0
+    "Hlt1D2KKDecision",             # y-D0
+    "Hlt1D2PiPiDecision",           #
+    "Hlt1DiMuonHighMassDecision",   # tis
+    "Hlt1DiElectronDisplaced",  # 25 kHz
+    "Hlt1DiMuonDisplaced",  # 38 kHz
+    "Hlt1DiPhotonHighMass",  # 77 kHz
+]
+
+
+Hlt2_lines = []        
+
+def Kinematics() -> FunctorCollection:
+    kinematics = {
+        "M": F.MASS,
+        "PX": F.PX,
+        "PY": F.PY,
+        "PZ": F.PZ,
+        "PT": F.PT,
+        "P": F.P,
+        "ETA": F.ETA,
+        "PHI": F.PHI,
+        "E" : F.ENERGY
+    }
+    return FunctorCollection(kinematics)
+
+# pi0 = F.CHILD(2, ...) of D0
+# pi- = F.CHILD(1, F.CHILD(1, ...)) of D0
+# pi+ = F.CHILD(1, F.CHILD(2, ...)) of D0
+
+def Dalitz_var12():
+    cross_product = ( (F.CHILD(1, F.CHILD(1, F.ENERGY))) * (F.CHILD(1, F.CHILD(2, F.ENERGY))) - 
+                    (F.CHILD(1, F.CHILD(1, F.PX))) * (F.CHILD(1, F.CHILD(2, F.PX))) - 
+                    (F.CHILD(1, F.CHILD(1, F.PY))) * (F.CHILD(1, F.CHILD(2, F.PY))) - 
+                    (F.CHILD(1, F.CHILD(1, F.PZ))) * (F.CHILD(1, F.CHILD(2, F.PZ))) )
+
+    return fmath.pow(F.CHILD(1, F.CHILD(1, F.MASS)), 2) + fmath.pow(F.CHILD(1, F.CHILD(2, F.MASS)), 2) + 2 * cross_product
+
+def Dalitz_var13():
+    cross_product = ( (F.CHILD(2, F.ENERGY)) * (F.CHILD(1, F.CHILD(2, F.ENERGY))) - 
+                    (F.CHILD(2, F.PX)) * (F.CHILD(1, F.CHILD(2, F.PX))) - 
+                    (F.CHILD(2, F.PY)) * (F.CHILD(1, F.CHILD(2, F.PY))) - 
+                    (F.CHILD(2, F.PZ)) * (F.CHILD(1, F.CHILD(2, F.PZ))) )
+
+    return fmath.pow(F.CHILD(2, F.MASS), 2) + fmath.pow(F.CHILD(1, F.CHILD(2, F.MASS)), 2) + 2 * cross_product
+
+def Dalitz_var23():
+    cross_product = ( (F.CHILD(2, F.ENERGY)) * (F.CHILD(1, F.CHILD(1, F.ENERGY))) - 
+                    (F.CHILD(2, F.PX)) * (F.CHILD(1, F.CHILD(1, F.PX))) - 
+                    (F.CHILD(2, F.PY)) * (F.CHILD(1, F.CHILD(1, F.PY))) - 
+                    (F.CHILD(2, F.PZ)) * (F.CHILD(1, F.CHILD(1, F.PZ))) )
+
+    return fmath.pow(F.CHILD(2, F.MASS), 2) + fmath.pow(F.CHILD(1, F.CHILD(1, F.MASS)), 2) + 2 * cross_product
+
+
+def make_composite_variables(options, pvs, data, particle, add_Hlt1TisTos=True):
+
+    variables = (
+        FunctorCollection(
+            {
+            # Endvertex-related info
+            "VCHI2DOF": F.CHI2DOF,  # Equal to SDOCACHI2 (2-track vertex -> 1 dof)
+            "MAXSDOCA": F.MAXSDOCA(), #MAXSDOCA == SDOCA(1,2)
+            "MAXDOCA": F.MAXDOCA(),
+            "MAXDOCACHI2": F.MAXDOCACHI2(),
+            "END_VX": F.END_VX,
+            "END_VY": F.END_VY,
+            "END_VZ": F.END_VZ,
+            "END_VX_ERR":F.SQRT @ F.CALL(0,0) @ F.POS_COV_MATRIX @ F.ENDVERTEX,
+            "END_VY_ERR":F.SQRT @ F.CALL(1,1) @ F.POS_COV_MATRIX @ F.ENDVERTEX,
+            "END_VZ_ERR":F.SQRT @ F.CALL(2,2) @ F.POS_COV_MATRIX @ F.ENDVERTEX,
+            "Q" : F.CHARGE
+            }
+        )
+        + Kinematics()
+        #+ ParticleID(extra_info=True) #only for daughters
+    )
+
+    if add_Hlt1TisTos:
+        variables += HltTisTos(
+            selection_type="Hlt1", trigger_lines=Hlt1_lines, data=data
+        )
+    
+    if particle == "D0":
+        variables += FunctorCollection({
+            # PV-related info
+            "OWNPVX": F.OWNPVX,
+            "OWNPVY": F.OWNPVY,
+            "OWNPVZ": F.OWNPVZ,
+            # FD/DIRA
+            "OWNPVDIRA": F.OWNPVDIRA,  # TODO needed for D*?
+            "OWNPVFD": F.OWNPVFD,  # TODO needed for D*? (can even be negative)
+            "OWNPVVDRHO": F.OWNPVVDRHO,  # TODO redundant
+            "OWNPVFDCHI2": F.OWNPVFDCHI2,  # TODO needed for D*?
+            "ALLPV_FD[nPVs]": F.ALLPV_FD(pvs),  # TODO redundant
+            "ALLPV_FDCHI2[nPVs]": F.MAP(F.VALUE_OR(F.NaN) @ F.VTX_FDCHI2).bind(F.TES(pvs), F.FORWARDARGS),
+            # IP/IPCHI2
+            "OWNPVIP": F.OWNPVIP,
+            "OWNPVIPCHI2": F.OWNPVIPCHI2,
+            "ALLPV_IP[nPVs]": F.ALLPV_IP(pvs),
+            "ALLPV_IPCHI2[nPVs]": F.MAP(F.VALUE_OR(F.NaN) @ F.IPCHI2).bind(F.TES(pvs), F.FORWARDARGS),
+            "OWNPVLTIME": F.OWNPVLTIME,
+            "OBJECT_KEY": F.OBJECT_KEY,  # For analysis of multiple candidates
+            "DALITZ_M12" : Dalitz_var12(),
+            "DALITZ_M13" : Dalitz_var13(), 
+            "DALITZ_M23" : Dalitz_var23()
+        })
+    elif particle == "Dst":
+        variables += FunctorCollection({"DM": F.MASS - F.CHILD(1, F.MASS)})
+
+
+    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_DeltaM_variable(options):
+    return FunctorCollection({"DM": F.MASS - F.CHILD(1, F.MASS)})
+
+
+
+def make_basic_variables(options, pvs, data, particle, hlt2_line, islong=False):
+
+    variables = (
+        FunctorCollection(
+            {
+                # Identifier
+                "OBJECT_KEY": F.OBJECT_KEY,
+                # Track fit quality
+                "TRCHI2DOF": F.VALUE_OR(-1) @ F.CHI2DOF @ F.TRACK,    
+                "TRGHOSTPROB": F.GHOSTPROB,     
+                "MINIPCHI2"   : F.MINIPCHI2(pvs),  
+                "MINIP"       : F.MINIP(pvs),       
+                "ISMUON"      : F.ISMUON,      
+                "NDOF": F.VALUE_OR(-1) @ F.NDOF @ F.TRACK,       
+                "NFTHITS": F.VALUE_OR(-1) @ F.NFTHITS @ F.TRACK,    
+                "NUTHITS": F.VALUE_OR(-1) @ F.NUTHITS @ F.TRACK,  
+                "NVPHITS": F.VALUE_OR(-1) @ F.NVPHITS @ F.TRACK,  
+                # For measuring the detection asymmetries in the T-stations
+                "X_TStationsBeg": F.POSITION_X @ F.EXTRAPOLATE_TRACK(7_500.) @ F.TRACK,
+                "Y_TStationsBeg": F.POSITION_Y @ F.EXTRAPOLATE_TRACK(7_500.) @ F.TRACK,
+                "X_TStationsEnd": F.POSITION_X @ F.EXTRAPOLATE_TRACK(9_410.) @ F.TRACK,
+                "Y_TStationsEnd": F.POSITION_Y @ F.EXTRAPOLATE_TRACK(9_410.) @ F.TRACK,
+                "Q" : F.CHARGE
+            }
+        )
+        + Kinematics()
+        + ParticleID(extra_info=True)  
+    )
+
+    if islong:
+        variables += FunctorCollection({
+            "CTBX": F.VALUE_OR(F.NaN) @ F.X_COORDINATE @ F.POSITION @ F.CLOSESTTOBEAM @ F.TRACK,#X_COORDINATE @ POSITION @ CLOSESTTOBEAM @ TRACK
+            "CTBY": F.VALUE_OR(F.NaN) @ F.Y_COORDINATE @ F.POSITION @ F.CLOSESTTOBEAM @ F.TRACK,
+            "CTBZ": F.VALUE_OR(F.NaN) @ F.Z_COORDINATE @ F.POSITION @ F.CLOSESTTOBEAM @ F.TRACK,
+        })
+    
+    if particle == "gamma1" or particle == "gamma2":
+        variables += FunctorCollection({
+            "CALO_CELLID_ROW" : F.CALOCELLID_ROW @ F._CALO_NEUTRAL_ID,
+            "CALO_CELLID_COLUMN" : F.CALOCELLID_COLUMN @ F._CALO_NEUTRAL_ID,
+            "CALO_CELLID_AREA" : F.CALOCELLID_AREA @ F._CALO_NEUTRAL_ID
+        })
+    
+    if particle == "pi0":
+        if hlt2_line[-1] == "M":
+            variables += FunctorCollection({
+            "CALO_CELLID_ROW" : F.CALOCELLID_ROW @ F._CALO_NEUTRAL_ID,
+            "CALO_CELLID_COLUMN" : F.CALOCELLID_COLUMN @ F._CALO_NEUTRAL_ID,
+            "CALO_CELLID_AREA" : F.CALOCELLID_AREA @ F._CALO_NEUTRAL_ID
+        })
+    
+    if not (particle == "pi0" or particle == "gamma1" or particle == "gamma2"):
+            variables += FunctorCollection({
+                "OWNPVIP": F.OWNPVIP,
+                "OWNPVIPCHI2": F.OWNPVIPCHI2,
+        })
+            
+    variables += HltTisTos(
+        selection_type="Hlt1", trigger_lines=Hlt1_1track_lines, data=data
+    )
+    
+
+    return variables
+
+def make_hlt2_event_variables(options, pvs, rec_summary):
+    # define event level variables
+    evt_variables = EventInfo()
+    if not options.simulation:
+        evt_variables += LHCInfo() #FillNumber
+    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),    
+            "ALLPVNDOF": F.MAP(F.VALUE_OR(-1) @ F.NDOF) @ F.TES(pvs),  
+            "ALLPVCHI2": F.MAP(F.VALUE_OR(-1) @ F.CHI2) @ F.TES(pvs),  
+            "nPVs": F.SIZE(pvs),                    
+            # No 3D vectors allowed, hence we save the value of each element of the covariance matrix
+            "ALLPV_COV00[nPVs]": F.MAP(F.VALUE_OR(F.NaN) @ F.CALL(0, 0) @ F.POS_COV_MATRIX) @ F.TES(pvs),
+            "ALLPV_COV01[nPVs]": F.MAP(F.VALUE_OR(F.NaN) @ F.CALL(0, 1) @ F.POS_COV_MATRIX) @ F.TES(pvs),
+            "ALLPV_COV02[nPVs]": F.MAP(F.VALUE_OR(F.NaN) @ F.CALL(0, 2) @ F.POS_COV_MATRIX) @ F.TES(pvs),
+            "ALLPV_COV10[nPVs]": F.MAP(F.VALUE_OR(F.NaN) @ F.CALL(1, 0) @ F.POS_COV_MATRIX) @ F.TES(pvs),
+            "ALLPV_COV11[nPVs]": F.MAP(F.VALUE_OR(F.NaN) @ F.CALL(1, 1) @ F.POS_COV_MATRIX) @ F.TES(pvs),
+            "ALLPV_COV12[nPVs]": F.MAP(F.VALUE_OR(F.NaN) @ F.CALL(1, 2) @ F.POS_COV_MATRIX) @ F.TES(pvs),
+            "ALLPV_COV20[nPVs]": F.MAP(F.VALUE_OR(F.NaN) @ F.CALL(2, 0) @ F.POS_COV_MATRIX) @ F.TES(pvs),
+            "ALLPV_COV21[nPVs]": F.MAP(F.VALUE_OR(F.NaN) @ F.CALL(2, 1) @ F.POS_COV_MATRIX) @ F.TES(pvs),
+            "ALLPV_COV22[nPVs]": F.MAP(F.VALUE_OR(F.NaN) @ F.CALL(2, 2) @ F.POS_COV_MATRIX) @ F.TES(pvs),
+            "nTracks": F.VALUE_OR(-1) @ F.RECSUMMARY_INFO(rec_summary, "nTracks"),
+            "nLongTracks": F.VALUE_OR(-1) @ F.RECSUMMARY_INFO(rec_summary, "nLongTracks"),  
+            "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"),  
+            "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
+
+
+
+### DTF variables ###
+
+def make_basic_dtf_variables(options, pvs, data, DTF=None, pv_constraint=False, mass_constraint=False, particle_constraint="", islong=False):
+    variables = Kinematics() 
+
+    if islong:
+        variables += FunctorCollection({
+            "CTBX": F.VALUE_OR(F.NaN) @ F.X_COORDINATE @ F.POSITION @ F.CLOSESTTOBEAM @ F.TRACK,#X_COORDINATE @ POSITION @ CLOSESTTOBEAM @ TRACK
+            "CTBY": F.VALUE_OR(F.NaN) @ F.Y_COORDINATE @ F.POSITION @ F.CLOSESTTOBEAM @ F.TRACK,
+            "CTBZ": F.VALUE_OR(F.NaN) @ F.Z_COORDINATE @ F.POSITION @ F.CLOSESTTOBEAM @ F.TRACK,
+        })
+    
+    if(mass_constraint):
+        if(pv_constraint): # MASS + PV
+            dtf_variables_mass_pv = FunctorCollection({
+                        'DTF_PV_M'+ particle_constraint + '_' + 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_constraint + '_' + 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, particle, DTF=None, pv_constraint=False, mass_constraint=False, particle_constraint=""):
+    variables = Kinematics()
+    
+    if particle == "Dst":
+        variables += FunctorCollection({"DM": F.MASS - F.CHILD(1, F.MASS)})
+    
+    if particle == "D0":
+        variables += FunctorCollection({
+            "DALITZ_M12" : Dalitz_var12(),
+            "DALITZ_M13" : Dalitz_var13(), 
+            "DALITZ_M23" : Dalitz_var23()
+        })
+
+    addstring = "DTF"
+    if(pv_constraint):
+            addstring += '_PV'
+    if(mass_constraint):
+            addstring += '_M'
+    addstring += particle_constraint
+
+    DTF_chi2ndof = FunctorCollection(
+            {
+                addstring+"_DTFCHI2": DTF.CHI2,   
+                addstring+"_DTFNDOF": DTF.NDOF,   
+                addstring+"_CTAU": DTF.CTAU,      
+                addstring+"_CTAUERR": DTF.CTAUERR, 
+                addstring+"_MERR": DTF.MASSERR,     
+            }
+    )
+
+    if(mass_constraint):
+        if(pv_constraint): # MASS + PV
+            dtf_variables_mass_pv = FunctorCollection({
+                        'DTF_PV_M'+ particle_constraint + '_' + k: DTF(v)
+                        for k, v in variables.get_thor_functors().items()
+                    })
+            return dtf_variables_mass_pv+DTF_chi2ndof
+        else: # MASS
+            dtf_variables_mass = FunctorCollection(
+                {'DTF_M'+ particle_constraint + '_' + k: DTF(v)
+                 for k, v in variables.get_thor_functors().items()})
+        return dtf_variables_mass+DTF_chi2ndof
+
+    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_chi2ndof
+
+    else: # NO MASS/PV
+        dtf_variables = FunctorCollection(
+            {'DTF_' + k: DTF(v)
+             for k, v in variables.get_thor_functors().items()})
+        return dtf_variables+DTF_chi2ndof
+
+
+def ParticleIsolation(
+    *,
+    isolation_alg: VertexAndConeIsolation,
+    array_indx_name: str,
+    sumcone_invalid_value=F.NaN,
+) -> FunctorCollection:
+    
+    prefix = "HEAD"
+    if isolation_alg.name:
+        prefix += f"_{isolation_alg.name}"
+
+    ParticleIsolationVariables = {
+        f"{prefix}_CMULT": isolation_alg.MULT,
+        f"{prefix}_PASY": isolation_alg.PASY,
+        f"{prefix}_PTASY": isolation_alg.PTASY,
+        f"{prefix}_PXASY": isolation_alg.PXASY,
+        f"{prefix}_PYASY": isolation_alg.PYASY,
+        f"{prefix}_PZASY": isolation_alg.PZASY,
+    }
+    return FunctorCollection(ParticleIsolationVariables)
+
+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]
+    
+    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
diff --git a/Lb2LcD0K_2024_eo_spruce/info.yaml b/Lb2LcD0K_2024_eo_spruce/info.yaml
new file mode 100644
index 0000000000..e72e3c57f5
--- /dev/null
+++ b/Lb2LcD0K_2024_eo_spruce/info.yaml
@@ -0,0 +1,33 @@
+defaults:
+  application: DaVinci/v64r13
+  output: DATA.ROOT
+  options:
+    entrypoint: Lb2LcD0K:main
+    extra_options:
+      input_type: ROOT
+      # input_raw_format: 0.5
+      simulation: false
+      data_type: "Upgrade"
+      geometry_version: run3/2024.Q1.2-v00.00 # checked using transformation monitor in DIRAC
+      conditions_version: master
+      input_process: "Spruce"
+      input_stream: "bandq"
+  inform:
+    - kai.habermann@cern.ch
+  wg: BandQ
+
+{%- set datasets = [
+  ('Sprucing24r1', '-Excl-UT', 'Down'),
+  ('Sprucing24r1', '-Excl-UT', 'Up'),
+  ('Sprucing24r1', '', 'Down'),
+  ('Sprucing24r1', '', 'Up'),
+]%}
+{%- for version, condition, polarity in datasets %}
+BdToDsstmKsPi_{{ version }}_{{ polarity }}{{ condition }}:
+  input:
+    bk_query: "/validation/Collision24/Beam6800GeV-VeloClosed-Mag{{ polarity }}{{ condition }}/Real Data/{{ version }}/90000000/BANDQ.DST"
+    dq_flags:
+      - UNCHECKED
+      - OK
+    n_test_lfns: 5 
+{%- endfor %}
\ No newline at end of file
-- 
GitLab


From 0d59f4c9acae9507239cc65744829745fd0c2ae2 Mon Sep 17 00:00:00 2001
From: KaiHabermann <kai.habermann@gmx.net>
Date: Mon, 27 Jan 2025 15:34:37 +0100
Subject: [PATCH 02/42] Retrigger pieline

---
 Lb2LcD0K_2024_eo_spruce/Lb2LcD0K.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Lb2LcD0K_2024_eo_spruce/Lb2LcD0K.py b/Lb2LcD0K_2024_eo_spruce/Lb2LcD0K.py
index 5f0960a0c6..f3cbce9df5 100644
--- a/Lb2LcD0K_2024_eo_spruce/Lb2LcD0K.py
+++ b/Lb2LcD0K_2024_eo_spruce/Lb2LcD0K.py
@@ -11,7 +11,7 @@ from DaVinciTools import SubstitutePID
 from PyConf.Algorithms import ParticleContainerMerger
 from DecayTreeFitter import DecayTreeFitter
 
-
+ 
 def main(options: Options):
         
     user_algorithms = {}
-- 
GitLab


From 54c1c20c521813a28935247ddc68c3fb85ced7fc Mon Sep 17 00:00:00 2001
From: KaiHabermann <kai.habermann@gmx.net>
Date: Mon, 27 Jan 2025 15:47:38 +0100
Subject: [PATCH 03/42] Correkt BK

---
 Lb2LcD0K_2024_eo_spruce/info.yaml | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/Lb2LcD0K_2024_eo_spruce/info.yaml b/Lb2LcD0K_2024_eo_spruce/info.yaml
index e72e3c57f5..1f71f08ce4 100644
--- a/Lb2LcD0K_2024_eo_spruce/info.yaml
+++ b/Lb2LcD0K_2024_eo_spruce/info.yaml
@@ -17,15 +17,15 @@ defaults:
   wg: BandQ
 
 {%- set datasets = [
-  ('Sprucing24r1', '-Excl-UT', 'Down'),
-  ('Sprucing24r1', '-Excl-UT', 'Up'),
-  ('Sprucing24r1', '', 'Down'),
-  ('Sprucing24r1', '', 'Up'),
+  ('Sprucing24c2', '-Excl-UT', 'Down'),
+  ('Sprucing24c2', '-Excl-UT', 'Up'),
+  ('Sprucing24c2', '', 'Down'),
+  ('Sprucing24c2', '', 'Up'),
 ]%}
 {%- for version, condition, polarity in datasets %}
 BdToDsstmKsPi_{{ version }}_{{ polarity }}{{ condition }}:
   input:
-    bk_query: "/validation/Collision24/Beam6800GeV-VeloClosed-Mag{{ polarity }}{{ condition }}/Real Data/{{ version }}/90000000/BANDQ.DST"
+    bk_query: "/LHCb/Collision24/Beam6800GeV-VeloClosed-Mag{{ polarity }}{{ condition }}/Real Data/{{ version }}/90000000/BANDQ.DST"
     dq_flags:
       - UNCHECKED
       - OK
-- 
GitLab


From 9e5fd8612abd313d76f734d7a41f267ada522f1d Mon Sep 17 00:00:00 2001
From: KaiHabermann <kai.habermann@gmx.net>
Date: Mon, 27 Jan 2025 16:05:45 +0100
Subject: [PATCH 04/42] Make package

---
 Lb2LcD0K_2024_eo_spruce/__init__.py | 0
 Lb2LcD0K_2024_eo_spruce/info.yaml   | 2 +-
 2 files changed, 1 insertion(+), 1 deletion(-)
 create mode 100644 Lb2LcD0K_2024_eo_spruce/__init__.py

diff --git a/Lb2LcD0K_2024_eo_spruce/__init__.py b/Lb2LcD0K_2024_eo_spruce/__init__.py
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/Lb2LcD0K_2024_eo_spruce/info.yaml b/Lb2LcD0K_2024_eo_spruce/info.yaml
index 1f71f08ce4..e875190803 100644
--- a/Lb2LcD0K_2024_eo_spruce/info.yaml
+++ b/Lb2LcD0K_2024_eo_spruce/info.yaml
@@ -2,7 +2,7 @@ defaults:
   application: DaVinci/v64r13
   output: DATA.ROOT
   options:
-    entrypoint: Lb2LcD0K:main
+    entrypoint: Lb2LcD0K_2024_eo_spruce.Lb2LcD0K:main
     extra_options:
       input_type: ROOT
       # input_raw_format: 0.5
-- 
GitLab


From 2a92165c6c9c41dc4e5254f9c92bcc26ed06a42f Mon Sep 17 00:00:00 2001
From: KaiHabermann <kai.habermann@gmx.net>
Date: Mon, 27 Jan 2025 16:52:33 +0100
Subject: [PATCH 05/42] Fix proton

---
 Lb2LcD0K_2024_eo_spruce/Lb2LcD0K.py | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/Lb2LcD0K_2024_eo_spruce/Lb2LcD0K.py b/Lb2LcD0K_2024_eo_spruce/Lb2LcD0K.py
index f3cbce9df5..cbf94e91d2 100644
--- a/Lb2LcD0K_2024_eo_spruce/Lb2LcD0K.py
+++ b/Lb2LcD0K_2024_eo_spruce/Lb2LcD0K.py
@@ -44,15 +44,15 @@ def main(options: Options):
     # }
     
     fields = {
-        "Lb":        "[[Lambda_b0]CC -> ( Lambda_c+ -> p K- pi+ ) (D0 -> K- pi+) K-]CC",
-        "Lc":        "[[Lambda_b0]CC -> ^( Lambda_c+ -> p K- pi+ ) (D0 -> K- pi+) K-]CC",
-        "D0":        "[[Lambda_b0]CC -> ( Lambda_c+ -> p K- pi+ ) ^(D0 -> K- pi+) K-]CC",
-        "K":        "[[Lambda_b0]CC -> ( Lambda_c+ -> p K- pi+ ) (D0 -> K- pi+) ^K-]CC",
-        "Lc_p":        "[[Lambda_b0]CC -> ( Lambda_c+ -> ^p K- pi+ ) (D0 -> K- pi+) K-]CC",
-        "Lc_K":        "[[Lambda_b0]CC -> ( Lambda_c+ -> p ^K- pi+ ) (D0 -> K- pi+) K-]CC",
-        "Lc_pi":        "[[Lambda_b0]CC -> ( Lambda_c+ -> p K- ^pi+ ) (D0 -> K- pi+) K-]CC",
-        "D0_K":        "[[Lambda_b0]CC -> ( Lambda_c+ -> p K- pi+ ) (D0 -> ^K- pi+) K-]CC",
-        "D0_pi":        "[[Lambda_b0]CC -> ( Lambda_c+ -> p K- pi+ ) (D0 -> K- ^pi+) K-]CC",
+        "Lb":        "[[Lambda_b0]CC -> ( Lambda_c+ -> p+ K- pi+ ) (D0 -> K- pi+) K-]CC",
+        "Lc":        "[[Lambda_b0]CC -> ^( Lambda_c+ -> p+ K- pi+ ) (D0 -> K- pi+) K-]CC",
+        "D0":        "[[Lambda_b0]CC -> ( Lambda_c+ -> p+ K- pi+ ) ^(D0 -> K- pi+) K-]CC",
+        "K":        "[[Lambda_b0]CC -> ( Lambda_c+ -> p+ K- pi+ ) (D0 -> K- pi+) ^K-]CC",
+        "Lc_p":        "[[Lambda_b0]CC -> ( Lambda_c+ -> ^p+ K- pi+ ) (D0 -> K- pi+) K-]CC",
+        "Lc_K":        "[[Lambda_b0]CC -> ( Lambda_c+ -> p+ ^K- pi+ ) (D0 -> K- pi+) K-]CC",
+        "Lc_pi":        "[[Lambda_b0]CC -> ( Lambda_c+ -> p+ K- ^pi+ ) (D0 -> K- pi+) K-]CC",
+        "D0_K":        "[[Lambda_b0]CC -> ( Lambda_c+ -> p+ K- pi+ ) (D0 -> ^K- pi+) K-]CC",
+        "D0_pi":        "[[Lambda_b0]CC -> ( Lambda_c+ -> p+ K- pi+ ) (D0 -> K- ^pi+) K-]CC",
 
     }
     
-- 
GitLab


From 6a6a0e2233050d52aee7a1bba4ca136e6f02b291 Mon Sep 17 00:00:00 2001
From: KaiHabermann <kai.habermann@gmx.net>
Date: Mon, 27 Jan 2025 18:08:45 +0100
Subject: [PATCH 06/42] Deactivate prefilter

---
 Lb2LcD0K_2024_eo_spruce/Lb2LcD0K.py | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/Lb2LcD0K_2024_eo_spruce/Lb2LcD0K.py b/Lb2LcD0K_2024_eo_spruce/Lb2LcD0K.py
index cbf94e91d2..c7bf6fce2c 100644
--- a/Lb2LcD0K_2024_eo_spruce/Lb2LcD0K.py
+++ b/Lb2LcD0K_2024_eo_spruce/Lb2LcD0K.py
@@ -169,7 +169,8 @@ def main(options: Options):
     # Combine all algorithms in the correct order
     # Without proper ordering, the prefilter wouldn't work correctly
     # First we run the prefilter, then an additional further constraint that each candidate has a primary vertex, then run funtuple.
-    user_algorithms.update({line: [line_prefilter, require_pvs(pvs), funtuple]})
+    # user_algorithms.update({line: [line_prefilter, require_pvs(pvs), funtuple]})
+    user_algorithms.update({line: [require_pvs(pvs), funtuple]})
     
     # Create and return the final DaVinci configuration
     # This generates the configuration that DaVinci will execute
-- 
GitLab


From c5375770fdd0591db9e591c9c95c09a4922e2351 Mon Sep 17 00:00:00 2001
From: KaiHabermann <kai.habermann@gmx.net>
Date: Tue, 28 Jan 2025 11:07:03 +0100
Subject: [PATCH 07/42] ...

---
 Lb2LcD0K_2024_eo_spruce/Lb2LcD0K.py | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/Lb2LcD0K_2024_eo_spruce/Lb2LcD0K.py b/Lb2LcD0K_2024_eo_spruce/Lb2LcD0K.py
index c7bf6fce2c..48c735a828 100644
--- a/Lb2LcD0K_2024_eo_spruce/Lb2LcD0K.py
+++ b/Lb2LcD0K_2024_eo_spruce/Lb2LcD0K.py
@@ -170,7 +170,9 @@ def main(options: Options):
     # Without proper ordering, the prefilter wouldn't work correctly
     # First we run the prefilter, then an additional further constraint that each candidate has a primary vertex, then run funtuple.
     # user_algorithms.update({line: [line_prefilter, require_pvs(pvs), funtuple]})
-    user_algorithms.update({line: [require_pvs(pvs), funtuple]})
+
+    user_algorithms.update({line: [line_prefilter, funtuple]})
+    # user_algorithms.update({line: [require_pvs(pvs), funtuple]})
     
     # Create and return the final DaVinci configuration
     # This generates the configuration that DaVinci will execute
-- 
GitLab


From 9d50db61b05c63acbb4c017b9ac5cad31c5c0844 Mon Sep 17 00:00:00 2001
From: KaiHabermann <kai.habermann@gmx.net>
Date: Tue, 28 Jan 2025 12:53:13 +0100
Subject: [PATCH 08/42] Fixed spruce version

---
 Lb2LcD0K_2024_eo_spruce/info.yaml | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/Lb2LcD0K_2024_eo_spruce/info.yaml b/Lb2LcD0K_2024_eo_spruce/info.yaml
index e875190803..725f1708ea 100644
--- a/Lb2LcD0K_2024_eo_spruce/info.yaml
+++ b/Lb2LcD0K_2024_eo_spruce/info.yaml
@@ -17,10 +17,10 @@ defaults:
   wg: BandQ
 
 {%- set datasets = [
-  ('Sprucing24c2', '-Excl-UT', 'Down'),
-  ('Sprucing24c2', '-Excl-UT', 'Up'),
-  ('Sprucing24c2', '', 'Down'),
-  ('Sprucing24c2', '', 'Up'),
+  ('Sprucing24r1', '-Excl-UT', 'Down'),
+  ('Sprucing24r1', '-Excl-UT', 'Up'),
+  ('Sprucing24r1', '', 'Down'),
+  ('Sprucing24r1', '', 'Up'),
 ]%}
 {%- for version, condition, polarity in datasets %}
 BdToDsstmKsPi_{{ version }}_{{ polarity }}{{ condition }}:
@@ -29,5 +29,5 @@ BdToDsstmKsPi_{{ version }}_{{ polarity }}{{ condition }}:
     dq_flags:
       - UNCHECKED
       - OK
-    n_test_lfns: 5 
+    n_test_lfns: 1 
 {%- endfor %}
\ No newline at end of file
-- 
GitLab


From bbc5b5a459909d1ee8f419470340bc4f3087e297 Mon Sep 17 00:00:00 2001
From: KaiHabermann <kai.habermann@gmx.net>
Date: Tue, 28 Jan 2025 13:25:37 +0100
Subject: [PATCH 09/42] next try

---
 Lb2LcD0K_2024_eo_spruce/Lb2LcD0K.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/Lb2LcD0K_2024_eo_spruce/Lb2LcD0K.py b/Lb2LcD0K_2024_eo_spruce/Lb2LcD0K.py
index 48c735a828..676a178bf0 100644
--- a/Lb2LcD0K_2024_eo_spruce/Lb2LcD0K.py
+++ b/Lb2LcD0K_2024_eo_spruce/Lb2LcD0K.py
@@ -169,9 +169,9 @@ def main(options: Options):
     # Combine all algorithms in the correct order
     # Without proper ordering, the prefilter wouldn't work correctly
     # First we run the prefilter, then an additional further constraint that each candidate has a primary vertex, then run funtuple.
-    # user_algorithms.update({line: [line_prefilter, require_pvs(pvs), funtuple]})
+    user_algorithms.update({line: [line_prefilter, require_pvs(pvs), funtuple]})
 
-    user_algorithms.update({line: [line_prefilter, funtuple]})
+    # user_algorithms.update({line: [line_prefilter, funtuple]})
     # user_algorithms.update({line: [require_pvs(pvs), funtuple]})
     
     # Create and return the final DaVinci configuration
-- 
GitLab


From 52f255722732472be070dc3525245a5f382fc6ca Mon Sep 17 00:00:00 2001
From: KaiHabermann <kai.habermann@gmx.net>
Date: Tue, 28 Jan 2025 13:50:19 +0100
Subject: [PATCH 10/42] Error in descriptor

---
 Lb2LcD0K_2024_eo_spruce/Lb2LcD0K.py | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/Lb2LcD0K_2024_eo_spruce/Lb2LcD0K.py b/Lb2LcD0K_2024_eo_spruce/Lb2LcD0K.py
index 676a178bf0..997c567971 100644
--- a/Lb2LcD0K_2024_eo_spruce/Lb2LcD0K.py
+++ b/Lb2LcD0K_2024_eo_spruce/Lb2LcD0K.py
@@ -44,15 +44,15 @@ def main(options: Options):
     # }
     
     fields = {
-        "Lb":        "[[Lambda_b0]CC -> ( Lambda_c+ -> p+ K- pi+ ) (D0 -> K- pi+) K-]CC",
-        "Lc":        "[[Lambda_b0]CC -> ^( Lambda_c+ -> p+ K- pi+ ) (D0 -> K- pi+) K-]CC",
-        "D0":        "[[Lambda_b0]CC -> ( Lambda_c+ -> p+ K- pi+ ) ^(D0 -> K- pi+) K-]CC",
-        "K":        "[[Lambda_b0]CC -> ( Lambda_c+ -> p+ K- pi+ ) (D0 -> K- pi+) ^K-]CC",
-        "Lc_p":        "[[Lambda_b0]CC -> ( Lambda_c+ -> ^p+ K- pi+ ) (D0 -> K- pi+) K-]CC",
-        "Lc_K":        "[[Lambda_b0]CC -> ( Lambda_c+ -> p+ ^K- pi+ ) (D0 -> K- pi+) K-]CC",
-        "Lc_pi":        "[[Lambda_b0]CC -> ( Lambda_c+ -> p+ K- ^pi+ ) (D0 -> K- pi+) K-]CC",
-        "D0_K":        "[[Lambda_b0]CC -> ( Lambda_c+ -> p+ K- pi+ ) (D0 -> ^K- pi+) K-]CC",
-        "D0_pi":        "[[Lambda_b0]CC -> ( Lambda_c+ -> p+ K- pi+ ) (D0 -> K- ^pi+) K-]CC",
+        "Lb":        "[[Lambda_b0]CC -> ( Lambda_c+ -> p+ K- pi+ ) (D~0 -> K- pi+) K-]CC",
+        "Lc":        "[[Lambda_b0]CC -> ^( Lambda_c+ -> p+ K- pi+ ) (D~0 -> K- pi+) K-]CC",
+        "D0":        "[[Lambda_b0]CC -> ( Lambda_c+ -> p+ K- pi+ ) ^(D~0 -> K- pi+) K-]CC",
+        "K":        "[[Lambda_b0]CC -> ( Lambda_c+ -> p+ K- pi+ ) (D~0 -> K- pi+) ^K-]CC",
+        "Lc_p":        "[[Lambda_b0]CC -> ( Lambda_c+ -> ^p+ K- pi+ ) (D~0 -> K- pi+) K-]CC",
+        "Lc_K":        "[[Lambda_b0]CC -> ( Lambda_c+ -> p+ ^K- pi+ ) (D~0 -> K- pi+) K-]CC",
+        "Lc_pi":        "[[Lambda_b0]CC -> ( Lambda_c+ -> p+ K- ^pi+ ) (D~0 -> K- pi+) K-]CC",
+        "D0_K":        "[[Lambda_b0]CC -> ( Lambda_c+ -> p+ K- pi+ ) (D~0 -> ^K- pi+) K-]CC",
+        "D0_pi":        "[[Lambda_b0]CC -> ( Lambda_c+ -> p+ K- pi+ ) (D~0 -> K- ^pi+) K-]CC",
 
     }
     
-- 
GitLab


From 48cb5868367c5df0ad54aee07b944ddf3c6cfa71 Mon Sep 17 00:00:00 2001
From: KaiHabermann <kai.habermann@gmx.net>
Date: Tue, 28 Jan 2025 14:09:46 +0100
Subject: [PATCH 11/42] Maybe like this?

---
 Lb2LcD0K_2024_eo_spruce/Lb2LcD0K.py | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/Lb2LcD0K_2024_eo_spruce/Lb2LcD0K.py b/Lb2LcD0K_2024_eo_spruce/Lb2LcD0K.py
index 997c567971..0189ca2b2c 100644
--- a/Lb2LcD0K_2024_eo_spruce/Lb2LcD0K.py
+++ b/Lb2LcD0K_2024_eo_spruce/Lb2LcD0K.py
@@ -44,15 +44,15 @@ def main(options: Options):
     # }
     
     fields = {
-        "Lb":        "[[Lambda_b0]CC -> ( Lambda_c+ -> p+ K- pi+ ) (D~0 -> K- pi+) K-]CC",
-        "Lc":        "[[Lambda_b0]CC -> ^( Lambda_c+ -> p+ K- pi+ ) (D~0 -> K- pi+) K-]CC",
-        "D0":        "[[Lambda_b0]CC -> ( Lambda_c+ -> p+ K- pi+ ) ^(D~0 -> K- pi+) K-]CC",
-        "K":        "[[Lambda_b0]CC -> ( Lambda_c+ -> p+ K- pi+ ) (D~0 -> K- pi+) ^K-]CC",
-        "Lc_p":        "[[Lambda_b0]CC -> ( Lambda_c+ -> ^p+ K- pi+ ) (D~0 -> K- pi+) K-]CC",
-        "Lc_K":        "[[Lambda_b0]CC -> ( Lambda_c+ -> p+ ^K- pi+ ) (D~0 -> K- pi+) K-]CC",
-        "Lc_pi":        "[[Lambda_b0]CC -> ( Lambda_c+ -> p+ K- ^pi+ ) (D~0 -> K- pi+) K-]CC",
-        "D0_K":        "[[Lambda_b0]CC -> ( Lambda_c+ -> p+ K- pi+ ) (D~0 -> ^K- pi+) K-]CC",
-        "D0_pi":        "[[Lambda_b0]CC -> ( Lambda_c+ -> p+ K- pi+ ) (D~0 -> K- ^pi+) K-]CC",
+        "Lb":        "[[Lambda_b0]CC -> ( Lambda_c+ -> p+ K- pi+ ) (D~0 -> K+ pi-) K-]CC",
+        "Lc":        "[[Lambda_b0]CC -> ^( Lambda_c+ -> p+ K- pi+ ) (D~0 -> K+ pi-) K-]CC",
+        "D0":        "[[Lambda_b0]CC -> ( Lambda_c+ -> p+ K- pi+ ) ^(D~0 -> K+ pi-) K-]CC",
+        "K":        "[[Lambda_b0]CC -> ( Lambda_c+ -> p+ K- pi+ ) (D~0 -> K+ pi-) ^K-]CC",
+        "Lc_p":        "[[Lambda_b0]CC -> ( Lambda_c+ -> ^p+ K- pi+ ) (D~0 -> K+ pi-) K-]CC",
+        "Lc_K":        "[[Lambda_b0]CC -> ( Lambda_c+ -> p+ ^K- pi+ ) (D~0 -> K+ pi-) K-]CC",
+        "Lc_pi":        "[[Lambda_b0]CC -> ( Lambda_c+ -> p+ K- ^pi+ ) (D~0 -> K+ pi-) K-]CC",
+        "D0_K":        "[[Lambda_b0]CC -> ( Lambda_c+ -> p+ K- pi+ ) (D~0 -> ^K+ pi-) K-]CC",
+        "D0_pi":        "[[Lambda_b0]CC -> ( Lambda_c+ -> p+ K- pi+ ) (D~0 -> K+ ^pi-) K-]CC",
 
     }
     
-- 
GitLab


From baad31b44f8f69fb5a95db42b59b6923fd547810 Mon Sep 17 00:00:00 2001
From: KaiHabermann <kai.habermann@gmx.net>
Date: Tue, 28 Jan 2025 14:33:58 +0100
Subject: [PATCH 12/42] I dont get it

---
 Lb2LcD0K_2024_eo_spruce/Lb2LcD0K.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Lb2LcD0K_2024_eo_spruce/Lb2LcD0K.py b/Lb2LcD0K_2024_eo_spruce/Lb2LcD0K.py
index 0189ca2b2c..4d27e826e0 100644
--- a/Lb2LcD0K_2024_eo_spruce/Lb2LcD0K.py
+++ b/Lb2LcD0K_2024_eo_spruce/Lb2LcD0K.py
@@ -159,7 +159,7 @@ def main(options: Options):
         fields = fields,
         variables = variables,
         inputs=data,
-        OutputLevel=INFO,
+        OutputLevel=DEBUG,
         event_variables=evt_variables,  # This additional event variables argument
         store_multiple_cand_info = True
         # store_run_event_numbers=True,
-- 
GitLab


From 4102fbe5c3aee6c48a2b859f7e83a33e6a3039ea Mon Sep 17 00:00:00 2001
From: KaiHabermann <kai.habermann@gmx.net>
Date: Tue, 28 Jan 2025 14:50:00 +0100
Subject: [PATCH 13/42] K do no decay

---
 Lb2LcD0K_2024_eo_spruce/Lb2LcD0K.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Lb2LcD0K_2024_eo_spruce/Lb2LcD0K.py b/Lb2LcD0K_2024_eo_spruce/Lb2LcD0K.py
index 4d27e826e0..dc8ab39e88 100644
--- a/Lb2LcD0K_2024_eo_spruce/Lb2LcD0K.py
+++ b/Lb2LcD0K_2024_eo_spruce/Lb2LcD0K.py
@@ -146,7 +146,7 @@ def main(options: Options):
                 "Lb": composite_variables,
                 "Lc": Lc_variables,
                 "D0": composite_variables,
-                "K": composite_variables,
+                "K": children_variables,
                 "Lc_K": children_variables,
                 "Lc_p": children_variables,
                 "Lc_pi": children_variables,
-- 
GitLab


From 4d47220aac78c12cfd64d619549aebf20869c17e Mon Sep 17 00:00:00 2001
From: KaiHabermann <kai.habermann@gmx.net>
Date: Tue, 28 Jan 2025 15:24:47 +0100
Subject: [PATCH 14/42] Remove debug flag

---
 Lb2LcD0K_2024_eo_spruce/Lb2LcD0K.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Lb2LcD0K_2024_eo_spruce/Lb2LcD0K.py b/Lb2LcD0K_2024_eo_spruce/Lb2LcD0K.py
index dc8ab39e88..26e22c566d 100644
--- a/Lb2LcD0K_2024_eo_spruce/Lb2LcD0K.py
+++ b/Lb2LcD0K_2024_eo_spruce/Lb2LcD0K.py
@@ -159,7 +159,7 @@ def main(options: Options):
         fields = fields,
         variables = variables,
         inputs=data,
-        OutputLevel=DEBUG,
+        OutputLevel=INFO,
         event_variables=evt_variables,  # This additional event variables argument
         store_multiple_cand_info = True
         # store_run_event_numbers=True,
-- 
GitLab


From 9386f6f1735485fc2cbad8684aa1c47b2de4b29b Mon Sep 17 00:00:00 2001
From: KaiHabermann <kai.habermann@gmx.net>
Date: Fri, 31 Jan 2025 11:31:06 +0100
Subject: [PATCH 15/42] Added dtf

---
 Lb2LcD0K_2024_eo_spruce/Lb2LcD0K.py | 42 +++++++++++++++++++++++++++--
 1 file changed, 40 insertions(+), 2 deletions(-)

diff --git a/Lb2LcD0K_2024_eo_spruce/Lb2LcD0K.py b/Lb2LcD0K_2024_eo_spruce/Lb2LcD0K.py
index 26e22c566d..686a80acb5 100644
--- a/Lb2LcD0K_2024_eo_spruce/Lb2LcD0K.py
+++ b/Lb2LcD0K_2024_eo_spruce/Lb2LcD0K.py
@@ -57,7 +57,7 @@ def main(options: Options):
     }
     
     all_vars = FC.Kinematics()
-    
+
     # Create the ntuple configuration
     # This defines how the output ROOT ntuple will be structured
     # Original decays + Swapped decays (Merged)
@@ -141,6 +141,41 @@ def main(options: Options):
     })
     
     children_variables += FC.ParticleID()
+
+    dtf_vars = {
+        "P": F.P,
+        "PT": F.PT,
+        "ETA": F.ETA,
+        "PHI": F.PHI,
+        "M": F.MASS,
+        "E": F.E,
+        "PX": F.PX,
+        "PY": F.PY,
+        "PZ": F.PZ,
+        "CHI2DOF": F.CHI2DOF,
+    }
+
+
+    DTF_Lb_fixed = DecayTreeFitter(
+        name="DTF_Lb_fixed",
+        input_particles=data,
+        mass_constraints=["Lambda_b0", "D~0", "Lambda_c+"],)
+
+
+    DTF_Lb_free = DecayTreeFitter(
+        name="DTF_Lb_free",
+        input_particles=data,
+        mass_constraints=["D~0", "Lambda_c+"],)
+
+    dft_vars_Lb_fixed = {
+        k: DTF_Lb_fixed(v)
+        for k, v in dtf_vars.items()
+    }
+
+    dft_vars_Lb_free = {
+        k: DTF_Lb_free(v)
+        for k, v in dtf_vars.items()
+    }
     
     variables = {"ALL": all_vars,
                 "Lb": composite_variables,
@@ -151,7 +186,10 @@ def main(options: Options):
                 "Lc_p": children_variables,
                 "Lc_pi": children_variables,
                 "D0_K": children_variables,
-                "D0_pi": children_variables}
+                "D0_pi": children_variables,
+                "DTF_Lb_fixed": dft_vars_Lb_fixed,
+                "DTF_Lb_free": dft_vars_Lb_free,
+                }
 
     funtuple = Funtuple(
         name = line,
-- 
GitLab


From 08d0eee433a0e143a07e3355336dde0bd9756a13 Mon Sep 17 00:00:00 2001
From: KaiHabermann <kai.habermann@gmx.net>
Date: Fri, 31 Jan 2025 11:46:53 +0100
Subject: [PATCH 16/42] New Log level

---
 Lb2LcD0K_2024_eo_spruce/Lb2LcD0K.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Lb2LcD0K_2024_eo_spruce/Lb2LcD0K.py b/Lb2LcD0K_2024_eo_spruce/Lb2LcD0K.py
index 686a80acb5..7eca63f4b7 100644
--- a/Lb2LcD0K_2024_eo_spruce/Lb2LcD0K.py
+++ b/Lb2LcD0K_2024_eo_spruce/Lb2LcD0K.py
@@ -197,7 +197,7 @@ def main(options: Options):
         fields = fields,
         variables = variables,
         inputs=data,
-        OutputLevel=INFO,
+        OutputLevel=DEBUG,
         event_variables=evt_variables,  # This additional event variables argument
         store_multiple_cand_info = True
         # store_run_event_numbers=True,
-- 
GitLab


From 714414ad6349876d04e16e9df93ea262a8874539 Mon Sep 17 00:00:00 2001
From: KaiHabermann <kai.habermann@gmx.net>
Date: Fri, 31 Jan 2025 11:53:17 +0100
Subject: [PATCH 17/42] Smallfix

---
 Lb2LcD0K_2024_eo_spruce/Lb2LcD0K.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Lb2LcD0K_2024_eo_spruce/Lb2LcD0K.py b/Lb2LcD0K_2024_eo_spruce/Lb2LcD0K.py
index 7eca63f4b7..c26fb6754a 100644
--- a/Lb2LcD0K_2024_eo_spruce/Lb2LcD0K.py
+++ b/Lb2LcD0K_2024_eo_spruce/Lb2LcD0K.py
@@ -148,7 +148,7 @@ def main(options: Options):
         "ETA": F.ETA,
         "PHI": F.PHI,
         "M": F.MASS,
-        "E": F.E,
+        "E": F.ENERGY,
         "PX": F.PX,
         "PY": F.PY,
         "PZ": F.PZ,
-- 
GitLab


From 07718c640e61ed207a5760cf5d3275d2427e835a Mon Sep 17 00:00:00 2001
From: KaiHabermann <kai.habermann@gmx.net>
Date: Fri, 31 Jan 2025 11:57:00 +0100
Subject: [PATCH 18/42] Info log level

---
 Lb2LcD0K_2024_eo_spruce/Lb2LcD0K.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Lb2LcD0K_2024_eo_spruce/Lb2LcD0K.py b/Lb2LcD0K_2024_eo_spruce/Lb2LcD0K.py
index c26fb6754a..0c87294751 100644
--- a/Lb2LcD0K_2024_eo_spruce/Lb2LcD0K.py
+++ b/Lb2LcD0K_2024_eo_spruce/Lb2LcD0K.py
@@ -197,7 +197,7 @@ def main(options: Options):
         fields = fields,
         variables = variables,
         inputs=data,
-        OutputLevel=DEBUG,
+        OutputLevel=INFO,
         event_variables=evt_variables,  # This additional event variables argument
         store_multiple_cand_info = True
         # store_run_event_numbers=True,
-- 
GitLab


From 31149baf98add929c25d5e3c85c365224587fda3 Mon Sep 17 00:00:00 2001
From: KaiHabermann <kai.habermann@gmx.net>
Date: Fri, 31 Jan 2025 12:01:02 +0100
Subject: [PATCH 19/42] Like this?

---
 Lb2LcD0K_2024_eo_spruce/Lb2LcD0K.py | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/Lb2LcD0K_2024_eo_spruce/Lb2LcD0K.py b/Lb2LcD0K_2024_eo_spruce/Lb2LcD0K.py
index 0c87294751..8f88e1718b 100644
--- a/Lb2LcD0K_2024_eo_spruce/Lb2LcD0K.py
+++ b/Lb2LcD0K_2024_eo_spruce/Lb2LcD0K.py
@@ -168,14 +168,18 @@ def main(options: Options):
         mass_constraints=["D~0", "Lambda_c+"],)
 
     dft_vars_Lb_fixed = {
-        k: DTF_Lb_fixed(v)
+        f"dft_vars_Lb_fixed_{k}": DTF_Lb_fixed(v)
         for k, v in dtf_vars.items()
     }
 
     dft_vars_Lb_free = {
-        k: DTF_Lb_free(v)
+        f"DTF_Lb_free_{k}": DTF_Lb_free(v)
         for k, v in dtf_vars.items()
     }
+
+    Lc_variables += dft_vars_Lb_fixed + dft_vars_Lb_free
+    composite_variables += dft_vars_Lb_free + dft_vars_Lb_fixed
+
     
     variables = {"ALL": all_vars,
                 "Lb": composite_variables,
@@ -186,9 +190,7 @@ def main(options: Options):
                 "Lc_p": children_variables,
                 "Lc_pi": children_variables,
                 "D0_K": children_variables,
-                "D0_pi": children_variables,
-                "DTF_Lb_fixed": dft_vars_Lb_fixed,
-                "DTF_Lb_free": dft_vars_Lb_free,
+                "D0_pi": children_variables
                 }
 
     funtuple = Funtuple(
-- 
GitLab


From c572b42e419f2845367da64819960f4156f64748 Mon Sep 17 00:00:00 2001
From: KaiHabermann <kai.habermann@gmx.net>
Date: Fri, 31 Jan 2025 12:06:58 +0100
Subject: [PATCH 20/42] Dicts and stuff

---
 Lb2LcD0K_2024_eo_spruce/Lb2LcD0K.py | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/Lb2LcD0K_2024_eo_spruce/Lb2LcD0K.py b/Lb2LcD0K_2024_eo_spruce/Lb2LcD0K.py
index 8f88e1718b..02c168b2a0 100644
--- a/Lb2LcD0K_2024_eo_spruce/Lb2LcD0K.py
+++ b/Lb2LcD0K_2024_eo_spruce/Lb2LcD0K.py
@@ -177,9 +177,10 @@ def main(options: Options):
         for k, v in dtf_vars.items()
     }
 
-    Lc_variables += dft_vars_Lb_fixed + dft_vars_Lb_free
-    composite_variables += dft_vars_Lb_free + dft_vars_Lb_fixed
-
+    Lc_variables.update(dft_vars_Lb_fixed)
+    Lc_variables.update(dft_vars_Lb_free)
+    composite_variables.update(dft_vars_Lb_fixed)
+    composite_variables.update(dft_vars_Lb_free)
     
     variables = {"ALL": all_vars,
                 "Lb": composite_variables,
-- 
GitLab


From 08ec601de965fc84adcf67424275f10ef1d37984 Mon Sep 17 00:00:00 2001
From: KaiHabermann <kai.habermann@gmx.net>
Date: Fri, 31 Jan 2025 14:29:35 +0100
Subject: [PATCH 21/42] Fix Names

---
 Lb2LcD0K_2024_eo_spruce/Lb2LcD0K.py | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/Lb2LcD0K_2024_eo_spruce/Lb2LcD0K.py b/Lb2LcD0K_2024_eo_spruce/Lb2LcD0K.py
index 02c168b2a0..8de94b9954 100644
--- a/Lb2LcD0K_2024_eo_spruce/Lb2LcD0K.py
+++ b/Lb2LcD0K_2024_eo_spruce/Lb2LcD0K.py
@@ -167,20 +167,20 @@ def main(options: Options):
         input_particles=data,
         mass_constraints=["D~0", "Lambda_c+"],)
 
-    dft_vars_Lb_fixed = {
-        f"dft_vars_Lb_fixed_{k}": DTF_Lb_fixed(v)
+    dtf_vars_Lb_fixed = {
+        f"DTF_Lb_fixed_{k}": DTF_Lb_fixed(v)
         for k, v in dtf_vars.items()
     }
 
-    dft_vars_Lb_free = {
+    dtf_vars_Lb_free = {
         f"DTF_Lb_free_{k}": DTF_Lb_free(v)
         for k, v in dtf_vars.items()
     }
 
-    Lc_variables.update(dft_vars_Lb_fixed)
-    Lc_variables.update(dft_vars_Lb_free)
-    composite_variables.update(dft_vars_Lb_fixed)
-    composite_variables.update(dft_vars_Lb_free)
+    Lc_variables.update(dtf_vars_Lb_fixed)
+    Lc_variables.update(dtf_vars_Lb_free)
+    composite_variables.update(dtf_vars_Lb_fixed)
+    composite_variables.update(dtf_vars_Lb_free)
     
     variables = {"ALL": all_vars,
                 "Lb": composite_variables,
-- 
GitLab


From ddccb05e216d7ec4b59070aa4c89e377a5c5deac Mon Sep 17 00:00:00 2001
From: KaiHabermann <kai.habermann@gmx.net>
Date: Fri, 7 Feb 2025 13:13:36 +0100
Subject: [PATCH 22/42] Constrain to pvs

---
 Lb2LcD0K_2024_eo_spruce/Lb2LcD0K.py | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/Lb2LcD0K_2024_eo_spruce/Lb2LcD0K.py b/Lb2LcD0K_2024_eo_spruce/Lb2LcD0K.py
index 8de94b9954..c138a37387 100644
--- a/Lb2LcD0K_2024_eo_spruce/Lb2LcD0K.py
+++ b/Lb2LcD0K_2024_eo_spruce/Lb2LcD0K.py
@@ -159,13 +159,16 @@ def main(options: Options):
     DTF_Lb_fixed = DecayTreeFitter(
         name="DTF_Lb_fixed",
         input_particles=data,
-        mass_constraints=["Lambda_b0", "D~0", "Lambda_c+"],)
+        mass_constraints=["Lambda_b0", "D~0", "Lambda_c+"],
+        input_pvs=pvs,)
 
 
     DTF_Lb_free = DecayTreeFitter(
         name="DTF_Lb_free",
         input_particles=data,
-        mass_constraints=["D~0", "Lambda_c+"],)
+        mass_constraints=["D~0", "Lambda_c+"],
+        input_pvs=pvs,
+        )
 
     dtf_vars_Lb_fixed = {
         f"DTF_Lb_fixed_{k}": DTF_Lb_fixed(v)
-- 
GitLab


From edacade969911531f24e4919cc9944876184c942 Mon Sep 17 00:00:00 2001
From: Kai Habermann <kai.habermann@gmx.net>
Date: Tue, 18 Mar 2025 07:48:20 +0100
Subject: [PATCH 23/42] First bookkeeping path for mc

---
 Lb2LcD0K_2024_eo_spruce/info.yaml | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/Lb2LcD0K_2024_eo_spruce/info.yaml b/Lb2LcD0K_2024_eo_spruce/info.yaml
index 725f1708ea..20f3dc1565 100644
--- a/Lb2LcD0K_2024_eo_spruce/info.yaml
+++ b/Lb2LcD0K_2024_eo_spruce/info.yaml
@@ -17,17 +17,18 @@ defaults:
   wg: BandQ
 
 {%- set datasets = [
-  ('Sprucing24r1', '-Excl-UT', 'Down'),
-  ('Sprucing24r1', '-Excl-UT', 'Up'),
-  ('Sprucing24r1', '', 'Down'),
-  ('Sprucing24r1', '', 'Up'),
+  ('2024.W31.34', 'Down', 'Nu6.3', 'HLT1_2024.W31.34_noUT/HLT2-2024.W31.34'),
 ]%}
-{%- for version, condition, polarity in datasets %}
+
+{%- for block, polarity, nu, hlt in datasets %}
 BdToDsstmKsPi_{{ version }}_{{ polarity }}{{ condition }}:
   input:
-    bk_query: "/LHCb/Collision24/Beam6800GeV-VeloClosed-Mag{{ polarity }}{{ condition }}/Real Data/{{ version }}/90000000/BANDQ.DST"
+    bk_query: "/MC/2024/Beam6800GeV-2024.{{block}}-Mag{{polarity}}-{{nu}}-25ns-Pythia8/Sim10e/{{hlt}}/15396000/HLT2.DST"
     dq_flags:
       - UNCHECKED
       - OK
     n_test_lfns: 1 
-{%- endfor %}
\ No newline at end of file
+{%- endfor %}
+
+
+# MC/2024/15396000/Beam6800GeV-2024.W31.34-MagUp-Nu6.3-25ns-Pythia8/Sim10e/HLT1_2024.W31.34_noUT/HLT2-2024.W31.34/HLT2.DST
\ No newline at end of file
-- 
GitLab


From 53e8fd32f11935f0ec04e7d19bcc0c0ac1246cc9 Mon Sep 17 00:00:00 2001
From: Kai Habermann <kai.habermann@gmx.net>
Date: Tue, 18 Mar 2025 07:49:50 +0100
Subject: [PATCH 24/42] Set sim = true

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

diff --git a/Lb2LcD0K_2024_eo_spruce/info.yaml b/Lb2LcD0K_2024_eo_spruce/info.yaml
index 20f3dc1565..abb031b4aa 100644
--- a/Lb2LcD0K_2024_eo_spruce/info.yaml
+++ b/Lb2LcD0K_2024_eo_spruce/info.yaml
@@ -6,11 +6,11 @@ defaults:
     extra_options:
       input_type: ROOT
       # input_raw_format: 0.5
-      simulation: false
+      simulation: true
       data_type: "Upgrade"
       geometry_version: run3/2024.Q1.2-v00.00 # checked using transformation monitor in DIRAC
       conditions_version: master
-      input_process: "Spruce"
+      input_process: "Hlt2"
       input_stream: "bandq"
   inform:
     - kai.habermann@cern.ch
-- 
GitLab


From a63ffea1014f4dfd24943ad6a6890a9b1d9cd454 Mon Sep 17 00:00:00 2001
From: Kai Habermann <kai.habermann@gmx.net>
Date: Tue, 18 Mar 2025 07:52:27 +0100
Subject: [PATCH 25/42] Rename

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

diff --git a/Lb2LcD0K_2024_eo_spruce/info.yaml b/Lb2LcD0K_2024_eo_spruce/info.yaml
index abb031b4aa..719f3a227a 100644
--- a/Lb2LcD0K_2024_eo_spruce/info.yaml
+++ b/Lb2LcD0K_2024_eo_spruce/info.yaml
@@ -1,6 +1,6 @@
 defaults:
   application: DaVinci/v64r13
-  output: DATA.ROOT
+  output: MC.ROOT
   options:
     entrypoint: Lb2LcD0K_2024_eo_spruce.Lb2LcD0K:main
     extra_options:
@@ -21,7 +21,7 @@ defaults:
 ]%}
 
 {%- for block, polarity, nu, hlt in datasets %}
-BdToDsstmKsPi_{{ version }}_{{ polarity }}{{ condition }}:
+Lb_LcDoK_MC_2024_{{block}}_{{polarity}}:
   input:
     bk_query: "/MC/2024/Beam6800GeV-2024.{{block}}-Mag{{polarity}}-{{nu}}-25ns-Pythia8/Sim10e/{{hlt}}/15396000/HLT2.DST"
     dq_flags:
-- 
GitLab


From 3b8a979b4497bd8cc82821aa1f131add58b7b7f4 Mon Sep 17 00:00:00 2001
From: Kai Habermann <kai.habermann@gmx.net>
Date: Tue, 18 Mar 2025 07:54:36 +0100
Subject: [PATCH 26/42] cvbfdsgdsag

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

diff --git a/Lb2LcD0K_2024_eo_spruce/info.yaml b/Lb2LcD0K_2024_eo_spruce/info.yaml
index 719f3a227a..4ab4868bd5 100644
--- a/Lb2LcD0K_2024_eo_spruce/info.yaml
+++ b/Lb2LcD0K_2024_eo_spruce/info.yaml
@@ -31,4 +31,3 @@ Lb_LcDoK_MC_2024_{{block}}_{{polarity}}:
 {%- endfor %}
 
 
-# MC/2024/15396000/Beam6800GeV-2024.W31.34-MagUp-Nu6.3-25ns-Pythia8/Sim10e/HLT1_2024.W31.34_noUT/HLT2-2024.W31.34/HLT2.DST
\ No newline at end of file
-- 
GitLab


From ab0f3bbbeba168b911388b375cb4c7192fcbae11 Mon Sep 17 00:00:00 2001
From: Kai Habermann <kai.habermann@gmx.net>
Date: Tue, 18 Mar 2025 07:56:35 +0100
Subject: [PATCH 27/42] ...

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

diff --git a/Lb2LcD0K_2024_eo_spruce/info.yaml b/Lb2LcD0K_2024_eo_spruce/info.yaml
index 4ab4868bd5..df2f390f97 100644
--- a/Lb2LcD0K_2024_eo_spruce/info.yaml
+++ b/Lb2LcD0K_2024_eo_spruce/info.yaml
@@ -17,11 +17,11 @@ defaults:
   wg: BandQ
 
 {%- set datasets = [
-  ('2024.W31.34', 'Down', 'Nu6.3', 'HLT1_2024.W31.34_noUT/HLT2-2024.W31.34'),
+  ('2024.W31.34', 'Down', 'Nu6.3', 'HLT1_2024.W31.34_noUT/HLT2-2024.W31.34', '1'),
 ]%}
 
-{%- for block, polarity, nu, hlt in datasets %}
-Lb_LcDoK_MC_2024_{{block}}_{{polarity}}:
+{%- for block, polarity, nu, hlt, num in datasets %}
+Lb_LcDoK_MC_2024_{{num}}:
   input:
     bk_query: "/MC/2024/Beam6800GeV-2024.{{block}}-Mag{{polarity}}-{{nu}}-25ns-Pythia8/Sim10e/{{hlt}}/15396000/HLT2.DST"
     dq_flags:
-- 
GitLab


From 51bf0de981904d9017ea355513ffa7ed54503fcf Mon Sep 17 00:00:00 2001
From: KaiHabermann <kai.habermann@gmx.net>
Date: Tue, 18 Mar 2025 14:19:14 +0100
Subject: [PATCH 28/42] ...

---
 Lb2LcD0K_2024_eo_spruce/info.yaml | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/Lb2LcD0K_2024_eo_spruce/info.yaml b/Lb2LcD0K_2024_eo_spruce/info.yaml
index df2f390f97..d4ddd2f9a5 100644
--- a/Lb2LcD0K_2024_eo_spruce/info.yaml
+++ b/Lb2LcD0K_2024_eo_spruce/info.yaml
@@ -24,9 +24,6 @@ defaults:
 Lb_LcDoK_MC_2024_{{num}}:
   input:
     bk_query: "/MC/2024/Beam6800GeV-2024.{{block}}-Mag{{polarity}}-{{nu}}-25ns-Pythia8/Sim10e/{{hlt}}/15396000/HLT2.DST"
-    dq_flags:
-      - UNCHECKED
-      - OK
     n_test_lfns: 1 
 {%- endfor %}
 
-- 
GitLab


From c281bd17bfbe72c877d554ca89fbf63b4f5d1f04 Mon Sep 17 00:00:00 2001
From: Kai Habermann <kai.habermann@gmx.net>
Date: Tue, 18 Mar 2025 14:22:34 +0100
Subject: [PATCH 29/42] ...

---
 Lb2LcD0K_2024_eo_spruce/info.yaml | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/Lb2LcD0K_2024_eo_spruce/info.yaml b/Lb2LcD0K_2024_eo_spruce/info.yaml
index d4ddd2f9a5..b6d5bca67c 100644
--- a/Lb2LcD0K_2024_eo_spruce/info.yaml
+++ b/Lb2LcD0K_2024_eo_spruce/info.yaml
@@ -23,7 +23,8 @@ defaults:
 {%- for block, polarity, nu, hlt, num in datasets %}
 Lb_LcDoK_MC_2024_{{num}}:
   input:
-    bk_query: "/MC/2024/Beam6800GeV-2024.{{block}}-Mag{{polarity}}-{{nu}}-25ns-Pythia8/Sim10e/{{hlt}}/15396000/HLT2.DST"
+    # bk_query: "/MC/2024/Beam6800GeV-2024.{{block}}-Mag{{polarity}}-{{nu}}-25ns-Pythia8/Sim10e/{{hlt}}/15396000/HLT2.DST"
+    bk_query: "MC/2024/15396000/Beam6800GeV-2024.W31.34-MagUp-Nu6.3-25ns-Pythia8/Sim10e/HLT1_2024.W31.34_noUT/HLT2-2024.W31.34/HLT2.DST"
     n_test_lfns: 1 
 {%- endfor %}
 
-- 
GitLab


From ab30c5381448cd29a771956817819498a0787143 Mon Sep 17 00:00:00 2001
From: Kai Habermann <kai.habermann@gmx.net>
Date: Tue, 18 Mar 2025 14:23:57 +0100
Subject: [PATCH 30/42] ...

---
 Lb2LcD0K_2024_eo_spruce/info.yaml | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/Lb2LcD0K_2024_eo_spruce/info.yaml b/Lb2LcD0K_2024_eo_spruce/info.yaml
index b6d5bca67c..de9c110b04 100644
--- a/Lb2LcD0K_2024_eo_spruce/info.yaml
+++ b/Lb2LcD0K_2024_eo_spruce/info.yaml
@@ -23,8 +23,7 @@ defaults:
 {%- for block, polarity, nu, hlt, num in datasets %}
 Lb_LcDoK_MC_2024_{{num}}:
   input:
-    # bk_query: "/MC/2024/Beam6800GeV-2024.{{block}}-Mag{{polarity}}-{{nu}}-25ns-Pythia8/Sim10e/{{hlt}}/15396000/HLT2.DST"
-    bk_query: "MC/2024/15396000/Beam6800GeV-2024.W31.34-MagUp-Nu6.3-25ns-Pythia8/Sim10e/HLT1_2024.W31.34_noUT/HLT2-2024.W31.34/HLT2.DST"
+    bk_query: "/MC/2024/Beam6800GeV-{{block}}-Mag{{polarity}}-{{nu}}-25ns-Pythia8/Sim10e/{{hlt}}/15396000/HLT2.DST"
     n_test_lfns: 1 
 {%- endfor %}
 
-- 
GitLab


From 6d896426a3b0fed73ff5b4b6a38e55331a7594c9 Mon Sep 17 00:00:00 2001
From: Kai Habermann <kai.habermann@gmx.net>
Date: Tue, 18 Mar 2025 14:40:36 +0100
Subject: [PATCH 31/42] db tags

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

diff --git a/Lb2LcD0K_2024_eo_spruce/info.yaml b/Lb2LcD0K_2024_eo_spruce/info.yaml
index de9c110b04..f5d296959f 100644
--- a/Lb2LcD0K_2024_eo_spruce/info.yaml
+++ b/Lb2LcD0K_2024_eo_spruce/info.yaml
@@ -17,14 +17,18 @@ defaults:
   wg: BandQ
 
 {%- set datasets = [
-  ('2024.W31.34', 'Down', 'Nu6.3', 'HLT1_2024.W31.34_noUT/HLT2-2024.W31.34', '1'),
+  ('W31.34', 'Down', 'Nu6.3', 'HLT1_2024.W31.34_noUT/HLT2-2024.W31.34', 'dddb-20240427', 'sim10-2024.Q1.2-v1.1-mu100', '1'),
 ]%}
 
-{%- for block, polarity, nu, hlt, num in datasets %}
+{%- for block, polarity, nu, hlt, dddb, conddb, num in datasets %}
 Lb_LcDoK_MC_2024_{{num}}:
   input:
-    bk_query: "/MC/2024/Beam6800GeV-{{block}}-Mag{{polarity}}-{{nu}}-25ns-Pythia8/Sim10e/{{hlt}}/15396000/HLT2.DST"
+    bk_query: "/MC/2024/Beam6800GeV-2024.{{block}}-Mag{{polarity}}-{{nu}}-25ns-Pythia8/Sim10e/{{hlt}}/15396000/HLT2.DST"
     n_test_lfns: 1 
+    extra_options:
+      dddb_tag: {{ dddb }}
+      conddb_tag: {{ conddb }}
+
 {%- endfor %}
 
 
-- 
GitLab


From c3df142575abdc535adf8c7a64ee17e10d403c5f Mon Sep 17 00:00:00 2001
From: Kai Habermann <kai.habermann@gmx.net>
Date: Tue, 18 Mar 2025 14:41:32 +0100
Subject: [PATCH 32/42] MagUp

---
 Lb2LcD0K_2024_eo_spruce/info.yaml | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/Lb2LcD0K_2024_eo_spruce/info.yaml b/Lb2LcD0K_2024_eo_spruce/info.yaml
index f5d296959f..ff11afa8ef 100644
--- a/Lb2LcD0K_2024_eo_spruce/info.yaml
+++ b/Lb2LcD0K_2024_eo_spruce/info.yaml
@@ -18,10 +18,11 @@ defaults:
 
 {%- set datasets = [
   ('W31.34', 'Down', 'Nu6.3', 'HLT1_2024.W31.34_noUT/HLT2-2024.W31.34', 'dddb-20240427', 'sim10-2024.Q1.2-v1.1-mu100', '1'),
+  ('W31.34', 'Up', 'Nu6.3', 'HLT1_2024.W31.34_noUT/HLT2-2024.W31.34', 'dddb-20240427', 'sim10-2024.Q1.2-v1.1-mu100', '1'),
 ]%}
 
 {%- for block, polarity, nu, hlt, dddb, conddb, num in datasets %}
-Lb_LcDoK_MC_2024_{{num}}:
+Lb_LcDoK_MC_2024_{{num}}_{{polarity}}:
   input:
     bk_query: "/MC/2024/Beam6800GeV-2024.{{block}}-Mag{{polarity}}-{{nu}}-25ns-Pythia8/Sim10e/{{hlt}}/15396000/HLT2.DST"
     n_test_lfns: 1 
-- 
GitLab


From fb88c72f3061eae08a4e9aef3bcaae29d94bb52b Mon Sep 17 00:00:00 2001
From: Kai Habermann <kai.habermann@gmx.net>
Date: Tue, 18 Mar 2025 14:50:05 +0100
Subject: [PATCH 33/42] Correct now?

---
 Lb2LcD0K_2024_eo_spruce/info.yaml | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/Lb2LcD0K_2024_eo_spruce/info.yaml b/Lb2LcD0K_2024_eo_spruce/info.yaml
index ff11afa8ef..4ccd83f8cb 100644
--- a/Lb2LcD0K_2024_eo_spruce/info.yaml
+++ b/Lb2LcD0K_2024_eo_spruce/info.yaml
@@ -18,17 +18,20 @@ defaults:
 
 {%- set datasets = [
   ('W31.34', 'Down', 'Nu6.3', 'HLT1_2024.W31.34_noUT/HLT2-2024.W31.34', 'dddb-20240427', 'sim10-2024.Q1.2-v1.1-mu100', '1'),
-  ('W31.34', 'Up', 'Nu6.3', 'HLT1_2024.W31.34_noUT/HLT2-2024.W31.34', 'dddb-20240427', 'sim10-2024.Q1.2-v1.1-mu100', '1'),
+  ('W35.37', 'Up', 'Nu6.3', 'HLT2-2024.W35.39', 'dddb-20240427', 'sim10-2024.Q1.2-v1.1-mu100', '2'),
+  ('W37.39', 'Down', 'Nu6.3', 'HLT2-2024.W35.39', 'dddb-20240427', 'sim10-2024.Q1.2-v1.1-md100', '3'),
+  ('W40.42', 'Down', 'Nu6.3', 'HLT2-2024.W40.42', 'dddb-20240427', 'sim10-2024.Q1.2-v1.1-mu100', '4'),
+  ('W40.42', 'Up', 'Nu6.3', 'HLT2-2024.W40.42', 'dddb-20240427', 'sim10-2024.Q1.2-v1.1-mu100', '4')
 ]%}
-
 {%- for block, polarity, nu, hlt, dddb, conddb, num in datasets %}
 Lb_LcDoK_MC_2024_{{num}}_{{polarity}}:
   input:
     bk_query: "/MC/2024/Beam6800GeV-2024.{{block}}-Mag{{polarity}}-{{nu}}-25ns-Pythia8/Sim10e/{{hlt}}/15396000/HLT2.DST"
     n_test_lfns: 1 
-    extra_options:
-      dddb_tag: {{ dddb }}
-      conddb_tag: {{ conddb }}
+    options:
+      extra_options:
+        dddb_tag: {{ dddb }}
+        conddb_tag: {{ conddb }}
 
 {%- endfor %}
 
-- 
GitLab


From b36d9d58f2f2b78612376ba6f1c69716e5278fc3 Mon Sep 17 00:00:00 2001
From: Kai Habermann <kai.habermann@gmx.net>
Date: Tue, 18 Mar 2025 14:53:27 +0100
Subject: [PATCH 34/42] ....

---
 Lb2LcD0K_2024_eo_spruce/info.yaml | 21 +++++++++------------
 1 file changed, 9 insertions(+), 12 deletions(-)

diff --git a/Lb2LcD0K_2024_eo_spruce/info.yaml b/Lb2LcD0K_2024_eo_spruce/info.yaml
index 4ccd83f8cb..3d8a69b83f 100644
--- a/Lb2LcD0K_2024_eo_spruce/info.yaml
+++ b/Lb2LcD0K_2024_eo_spruce/info.yaml
@@ -1,17 +1,6 @@
 defaults:
   application: DaVinci/v64r13
   output: MC.ROOT
-  options:
-    entrypoint: Lb2LcD0K_2024_eo_spruce.Lb2LcD0K:main
-    extra_options:
-      input_type: ROOT
-      # input_raw_format: 0.5
-      simulation: true
-      data_type: "Upgrade"
-      geometry_version: run3/2024.Q1.2-v00.00 # checked using transformation monitor in DIRAC
-      conditions_version: master
-      input_process: "Hlt2"
-      input_stream: "bandq"
   inform:
     - kai.habermann@cern.ch
   wg: BandQ
@@ -29,10 +18,18 @@ Lb_LcDoK_MC_2024_{{num}}_{{polarity}}:
     bk_query: "/MC/2024/Beam6800GeV-2024.{{block}}-Mag{{polarity}}-{{nu}}-25ns-Pythia8/Sim10e/{{hlt}}/15396000/HLT2.DST"
     n_test_lfns: 1 
     options:
+      entrypoint: Lb2LcD0K_2024_eo_spruce.Lb2LcD0K:main
       extra_options:
+        input_type: ROOT
+        # input_raw_format: 0.5
+        simulation: true
+        data_type: "Upgrade"
+        geometry_version: run3/2024.Q1.2-v00.00 # checked using transformation monitor in DIRAC
+        conditions_version: master
+        input_process: "Hlt2"
+        input_stream: "bandq"
         dddb_tag: {{ dddb }}
         conddb_tag: {{ conddb }}
-
 {%- endfor %}
 
 
-- 
GitLab


From 018040dfd3de4cd9dc63782cdca961a6813a0b05 Mon Sep 17 00:00:00 2001
From: Kai Habermann <kai.habermann@gmx.net>
Date: Tue, 18 Mar 2025 14:56:30 +0100
Subject: [PATCH 35/42] dfsa

---
 Lb2LcD0K_2024_eo_spruce/info.yaml | 26 +++++++++++++-------------
 1 file changed, 13 insertions(+), 13 deletions(-)

diff --git a/Lb2LcD0K_2024_eo_spruce/info.yaml b/Lb2LcD0K_2024_eo_spruce/info.yaml
index 3d8a69b83f..d3f2c1d96a 100644
--- a/Lb2LcD0K_2024_eo_spruce/info.yaml
+++ b/Lb2LcD0K_2024_eo_spruce/info.yaml
@@ -17,19 +17,19 @@ Lb_LcDoK_MC_2024_{{num}}_{{polarity}}:
   input:
     bk_query: "/MC/2024/Beam6800GeV-2024.{{block}}-Mag{{polarity}}-{{nu}}-25ns-Pythia8/Sim10e/{{hlt}}/15396000/HLT2.DST"
     n_test_lfns: 1 
-    options:
-      entrypoint: Lb2LcD0K_2024_eo_spruce.Lb2LcD0K:main
-      extra_options:
-        input_type: ROOT
-        # input_raw_format: 0.5
-        simulation: true
-        data_type: "Upgrade"
-        geometry_version: run3/2024.Q1.2-v00.00 # checked using transformation monitor in DIRAC
-        conditions_version: master
-        input_process: "Hlt2"
-        input_stream: "bandq"
-        dddb_tag: {{ dddb }}
-        conddb_tag: {{ conddb }}
+  options:
+    entrypoint: Lb2LcD0K_2024_eo_spruce.Lb2LcD0K:main
+    extra_options:
+      input_type: ROOT
+      # input_raw_format: 0.5
+      simulation: true
+      data_type: "Upgrade"
+      geometry_version: run3/2024.Q1.2-v00.00 # checked using transformation monitor in DIRAC
+      conditions_version: master
+      input_process: "Hlt2"
+      input_stream: "bandq"
+      dddb_tag: {{ dddb }}
+      conddb_tag: {{ conddb }}
 {%- endfor %}
 
 
-- 
GitLab


From 3a1b9416d4ca8071c1b43c56635c43ff179751f1 Mon Sep 17 00:00:00 2001
From: Kai Habermann <kai.habermann@gmx.net>
Date: Tue, 18 Mar 2025 14:59:50 +0100
Subject: [PATCH 36/42] Nu

---
 Lb2LcD0K_2024_eo_spruce/info.yaml | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/Lb2LcD0K_2024_eo_spruce/info.yaml b/Lb2LcD0K_2024_eo_spruce/info.yaml
index d3f2c1d96a..a94e42d736 100644
--- a/Lb2LcD0K_2024_eo_spruce/info.yaml
+++ b/Lb2LcD0K_2024_eo_spruce/info.yaml
@@ -9,25 +9,27 @@ defaults:
   ('W31.34', 'Down', 'Nu6.3', 'HLT1_2024.W31.34_noUT/HLT2-2024.W31.34', 'dddb-20240427', 'sim10-2024.Q1.2-v1.1-mu100', '1'),
   ('W35.37', 'Up', 'Nu6.3', 'HLT2-2024.W35.39', 'dddb-20240427', 'sim10-2024.Q1.2-v1.1-mu100', '2'),
   ('W37.39', 'Down', 'Nu6.3', 'HLT2-2024.W35.39', 'dddb-20240427', 'sim10-2024.Q1.2-v1.1-md100', '3'),
-  ('W40.42', 'Down', 'Nu6.3', 'HLT2-2024.W40.42', 'dddb-20240427', 'sim10-2024.Q1.2-v1.1-mu100', '4'),
-  ('W40.42', 'Up', 'Nu6.3', 'HLT2-2024.W40.42', 'dddb-20240427', 'sim10-2024.Q1.2-v1.1-mu100', '4')
+  ('W40.42', 'Down', 'Nu6.7', 'HLT2-2024.W40.42', 'dddb-20240427', 'sim10-2024.Q1.2-v1.1-mu100', '4'),
+  ('W40.42', 'Up', 'Nu6.7', 'HLT2-2024.W40.42', 'dddb-20240427', 'sim10-2024.Q1.2-v1.1-mu100', '4')
 ]%}
 {%- for block, polarity, nu, hlt, dddb, conddb, num in datasets %}
 Lb_LcDoK_MC_2024_{{num}}_{{polarity}}:
   input:
     bk_query: "/MC/2024/Beam6800GeV-2024.{{block}}-Mag{{polarity}}-{{nu}}-25ns-Pythia8/Sim10e/{{hlt}}/15396000/HLT2.DST"
-    n_test_lfns: 1 
+    dq_flags:
+      - OK
+    keep_running: true
+    n_test_lfns: 1
+
   options:
     entrypoint: Lb2LcD0K_2024_eo_spruce.Lb2LcD0K:main
     extra_options:
       input_type: ROOT
-      # input_raw_format: 0.5
       simulation: true
       data_type: "Upgrade"
       geometry_version: run3/2024.Q1.2-v00.00 # checked using transformation monitor in DIRAC
       conditions_version: master
       input_process: "Hlt2"
-      input_stream: "bandq"
       dddb_tag: {{ dddb }}
       conddb_tag: {{ conddb }}
 {%- endfor %}
-- 
GitLab


From cb535414a0f3f0ba1cde6398ec19ec1a334454e6 Mon Sep 17 00:00:00 2001
From: Kai Habermann <kai.habermann@gmx.net>
Date: Tue, 18 Mar 2025 15:01:41 +0100
Subject: [PATCH 37/42] ffffffuuu

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

diff --git a/Lb2LcD0K_2024_eo_spruce/info.yaml b/Lb2LcD0K_2024_eo_spruce/info.yaml
index a94e42d736..8de250fcfc 100644
--- a/Lb2LcD0K_2024_eo_spruce/info.yaml
+++ b/Lb2LcD0K_2024_eo_spruce/info.yaml
@@ -9,8 +9,8 @@ defaults:
   ('W31.34', 'Down', 'Nu6.3', 'HLT1_2024.W31.34_noUT/HLT2-2024.W31.34', 'dddb-20240427', 'sim10-2024.Q1.2-v1.1-mu100', '1'),
   ('W35.37', 'Up', 'Nu6.3', 'HLT2-2024.W35.39', 'dddb-20240427', 'sim10-2024.Q1.2-v1.1-mu100', '2'),
   ('W37.39', 'Down', 'Nu6.3', 'HLT2-2024.W35.39', 'dddb-20240427', 'sim10-2024.Q1.2-v1.1-md100', '3'),
-  ('W40.42', 'Down', 'Nu6.7', 'HLT2-2024.W40.42', 'dddb-20240427', 'sim10-2024.Q1.2-v1.1-mu100', '4'),
-  ('W40.42', 'Up', 'Nu6.7', 'HLT2-2024.W40.42', 'dddb-20240427', 'sim10-2024.Q1.2-v1.1-mu100', '4')
+  ('W40.42', 'Down', 'Nu7.6', 'HLT2-2024.W40.42', 'dddb-20240427', 'sim10-2024.Q1.2-v1.1-mu100', '4'),
+  ('W40.42', 'Up', 'Nu7.6', 'HLT2-2024.W40.42', 'dddb-20240427', 'sim10-2024.Q1.2-v1.1-mu100', '4')
 ]%}
 {%- for block, polarity, nu, hlt, dddb, conddb, num in datasets %}
 Lb_LcDoK_MC_2024_{{num}}_{{polarity}}:
-- 
GitLab


From 60e399ce3ad248c9d2f65d85d44ca8fe4d5ffc3d Mon Sep 17 00:00:00 2001
From: Kai Habermann <kai.habermann@gmx.net>
Date: Tue, 18 Mar 2025 15:04:56 +0100
Subject: [PATCH 38/42] ...

---
 Lb2LcD0K_2024_eo_spruce/info.yaml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Lb2LcD0K_2024_eo_spruce/info.yaml b/Lb2LcD0K_2024_eo_spruce/info.yaml
index 8de250fcfc..e6c2787399 100644
--- a/Lb2LcD0K_2024_eo_spruce/info.yaml
+++ b/Lb2LcD0K_2024_eo_spruce/info.yaml
@@ -6,7 +6,7 @@ defaults:
   wg: BandQ
 
 {%- set datasets = [
-  ('W31.34', 'Down', 'Nu6.3', 'HLT1_2024.W31.34_noUT/HLT2-2024.W31.34', 'dddb-20240427', 'sim10-2024.Q1.2-v1.1-mu100', '1'),
+  ('W31.34', 'Up', 'Nu6.3', 'HLT1_2024.W31.34_noUT/HLT2-2024.W31.34', 'dddb-20240427', 'sim10-2024.Q1.2-v1.1-mu100', '1'),
   ('W35.37', 'Up', 'Nu6.3', 'HLT2-2024.W35.39', 'dddb-20240427', 'sim10-2024.Q1.2-v1.1-mu100', '2'),
   ('W37.39', 'Down', 'Nu6.3', 'HLT2-2024.W35.39', 'dddb-20240427', 'sim10-2024.Q1.2-v1.1-md100', '3'),
   ('W40.42', 'Down', 'Nu7.6', 'HLT2-2024.W40.42', 'dddb-20240427', 'sim10-2024.Q1.2-v1.1-mu100', '4'),
-- 
GitLab


From 0724fb67318064c10665e27742ffa6fe9bb2b9e6 Mon Sep 17 00:00:00 2001
From: KaiHabermann <kai.habermann@gmx.net>
Date: Tue, 18 Mar 2025 15:52:25 +0100
Subject: [PATCH 39/42] I dont get this :8

---
 Lb2LcD0K_2024_eo_spruce/info.yaml | 1 +
 1 file changed, 1 insertion(+)

diff --git a/Lb2LcD0K_2024_eo_spruce/info.yaml b/Lb2LcD0K_2024_eo_spruce/info.yaml
index e6c2787399..d62cf04dcf 100644
--- a/Lb2LcD0K_2024_eo_spruce/info.yaml
+++ b/Lb2LcD0K_2024_eo_spruce/info.yaml
@@ -31,6 +31,7 @@ Lb_LcDoK_MC_2024_{{num}}_{{polarity}}:
       conditions_version: master
       input_process: "Hlt2"
       dddb_tag: {{ dddb }}
+      input_raw_format: 0.5
       conddb_tag: {{ conddb }}
 {%- endfor %}
 
-- 
GitLab


From 11b1e637959016602d99966dca5132e1064c4bcb Mon Sep 17 00:00:00 2001
From: KaiHabermann <kai.habermann@gmx.net>
Date: Fri, 21 Mar 2025 11:28:20 +0100
Subject: [PATCH 40/42] Not sure this is enough

---
 Lb2LcD0K_2024_eo_spruce/Lb2LcD0K.py | 27 ++++++++++++++++++++++++++-
 Lb2LcD0K_2024_eo_spruce/info.yaml   |  1 +
 2 files changed, 27 insertions(+), 1 deletion(-)

diff --git a/Lb2LcD0K_2024_eo_spruce/Lb2LcD0K.py b/Lb2LcD0K_2024_eo_spruce/Lb2LcD0K.py
index c138a37387..9072529f00 100644
--- a/Lb2LcD0K_2024_eo_spruce/Lb2LcD0K.py
+++ b/Lb2LcD0K_2024_eo_spruce/Lb2LcD0K.py
@@ -10,6 +10,8 @@ from RecoConf.event_filters import require_pvs
 from DaVinciTools import SubstitutePID
 from PyConf.Algorithms import ParticleContainerMerger
 from DecayTreeFitter import DecayTreeFitter
+from DaVinciMCTools import MCTruthAndBkgCat
+from FunTuple.functorcollections import MCHierarchy, MCPrimaries, MCPromptDecay, Kinematics, SelectionInfo, HltTisTos, MCVertexInfo, MCKinematics, ParticleID, EventInfo
 
  
 def main(options: Options):
@@ -184,8 +186,31 @@ def main(options: Options):
     Lc_variables.update(dtf_vars_Lb_free)
     composite_variables.update(dtf_vars_Lb_fixed)
     composite_variables.update(dtf_vars_Lb_free)
+    mc_truth = MCTruthAndBkgCat(data, name = f"MCTruthAndBkgCat_" )
+
     
-    variables = {"ALL": all_vars,
+    def extra_info(mctruth):
+        return FunctorCollection({
+            "TRUEKEY": F.VALUE_OR(-1) @ mctruth(F.OBJECT_KEY),
+            "TRUEEID": F.VALUE_OR(0) @ mctruth(F.PARTICLE_ID),
+            "TRUEORIGIN_VZ" : F.VALUE_OR(-1000) @ mctruth(F.ORIGIN_VZ),
+            "TRUEORIGIN_VX" : F.VALUE_OR(-1000) @ mctruth(F.ORIGIN_VX),
+            "TRUEORIGIN_VY" : F.VALUE_OR(-1000) @ mctruth(F.ORIGIN_VY),
+            "TRUEEND_VZ" : F.VALUE_OR(-1000) @ mctruth(F.END_VZ),
+            "TRUEEND_VX" : F.VALUE_OR(-1000) @ mctruth(F.END_VX),
+            "TRUEEND_VY" : F.VALUE_OR(-1000) @ mctruth(F.END_VY),
+            "TRUEENERGY": F.VALUE_OR(-1e6) @ mctruth(F.ENERGY),
+            "TRUEP":  F.VALUE_OR(-1e6) @ mctruth(F.P),
+            "TRUEFOURMOMENTUM": mctruth(F.FOURMOMENTUM),
+            "TRUE_PX" : F.VALUE_OR(-1e6) @ mctruth(F.PX),
+            "TRUE_PY" : F.VALUE_OR(-1e6) @ mctruth(F.PY),
+            "TRUE_PZ" : F.VALUE_OR(-1e6) @ mctruth(F.PZ),
+            "TRUE_MASS" : F.VALUE_OR(-1) @ mctruth(F.MASS),
+            "MC_LIFETIME" : F.VALUE_OR(-1) @ mctruth(F.MC_LIFETIME),
+            "BKGCAT": mctruth.BkgCat
+        })
+
+    variables = {"ALL": all_vars + extra_info(mc_truth),
                 "Lb": composite_variables,
                 "Lc": Lc_variables,
                 "D0": composite_variables,
diff --git a/Lb2LcD0K_2024_eo_spruce/info.yaml b/Lb2LcD0K_2024_eo_spruce/info.yaml
index d62cf04dcf..cfb7a45ebf 100644
--- a/Lb2LcD0K_2024_eo_spruce/info.yaml
+++ b/Lb2LcD0K_2024_eo_spruce/info.yaml
@@ -30,6 +30,7 @@ Lb_LcDoK_MC_2024_{{num}}_{{polarity}}:
       geometry_version: run3/2024.Q1.2-v00.00 # checked using transformation monitor in DIRAC
       conditions_version: master
       input_process: "Hlt2"
+      process: "Spruce"
       dddb_tag: {{ dddb }}
       input_raw_format: 0.5
       conddb_tag: {{ conddb }}
-- 
GitLab


From 323574392c6a3bfc5a8a4a1fbce8eae09e32bfaa Mon Sep 17 00:00:00 2001
From: KaiHabermann <kai.habermann@gmx.net>
Date: Fri, 21 Mar 2025 13:16:47 +0100
Subject: [PATCH 41/42] ...

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

diff --git a/Lb2LcD0K_2024_eo_spruce/info.yaml b/Lb2LcD0K_2024_eo_spruce/info.yaml
index cfb7a45ebf..c5f13ea429 100644
--- a/Lb2LcD0K_2024_eo_spruce/info.yaml
+++ b/Lb2LcD0K_2024_eo_spruce/info.yaml
@@ -29,10 +29,9 @@ Lb_LcDoK_MC_2024_{{num}}_{{polarity}}:
       data_type: "Upgrade"
       geometry_version: run3/2024.Q1.2-v00.00 # checked using transformation monitor in DIRAC
       conditions_version: master
-      input_process: "Hlt2"
-      process: "Spruce"
+      input_process: "Spruce"
+      # process: "Spruce"
       dddb_tag: {{ dddb }}
-      input_raw_format: 0.5
       conddb_tag: {{ conddb }}
 {%- endfor %}
 
-- 
GitLab


From 51018d8488e00ffe7538aca4f8367a6321ab5a7a Mon Sep 17 00:00:00 2001
From: KaiHabermann <kai.habermann@gmx.net>
Date: Fri, 21 Mar 2025 14:45:38 +0100
Subject: [PATCH 42/42] ...

---
 Lb2LcD0K_2024_eo_spruce/Lb2LcD0K.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Lb2LcD0K_2024_eo_spruce/Lb2LcD0K.py b/Lb2LcD0K_2024_eo_spruce/Lb2LcD0K.py
index 9072529f00..510defbfb1 100644
--- a/Lb2LcD0K_2024_eo_spruce/Lb2LcD0K.py
+++ b/Lb2LcD0K_2024_eo_spruce/Lb2LcD0K.py
@@ -228,7 +228,7 @@ def main(options: Options):
         fields = fields,
         variables = variables,
         inputs=data,
-        OutputLevel=INFO,
+        OutputLevel=DEBUG,
         event_variables=evt_variables,  # This additional event variables argument
         store_multiple_cand_info = True
         # store_run_event_numbers=True,
-- 
GitLab