From 62f5883fdfe717455d83c0b236295192d40d398d Mon Sep 17 00:00:00 2001
From: Edoardo Mariani <edoardo.mariani@cern.ch>
Date: Mon, 6 Jan 2025 12:23:19 +0100
Subject: [PATCH 01/18] Add new directory

---
 bd2kkks_data/.gitkeep | 0
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 bd2kkks_data/.gitkeep

diff --git a/bd2kkks_data/.gitkeep b/bd2kkks_data/.gitkeep
new file mode 100644
index 0000000000..e69de29bb2
-- 
GitLab


From d47e64e7ef40e14021c2b637552983ce68305043 Mon Sep 17 00:00:00 2001
From: Edoardo Mariani <edoardo.mariani@cern.ch>
Date: Mon, 6 Jan 2025 12:24:28 +0100
Subject: [PATCH 02/18] Add new file

---
 bd2kkks_data/info.yaml | 71 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 71 insertions(+)
 create mode 100644 bd2kkks_data/info.yaml

diff --git a/bd2kkks_data/info.yaml b/bd2kkks_data/info.yaml
new file mode 100644
index 0000000000..cea995efab
--- /dev/null
+++ b/bd2kkks_data/info.yaml
@@ -0,0 +1,71 @@
+defaults:
+    application: DaVinci/v46r10
+    wg: BnoC
+    automatically_configure: yes
+    turbo: no
+    inform:
+        - edoardo.mariani@cern.ch
+    output: B2hhKS_MC.root
+
+
+#{%- set MCdatasets = [
+#  (2011, 3500, '0x40760037', '14c', '', '21r1p2', 'B2KSHH.STRIP.DST'),
+#  (2012, 4000, '0x4097003d', '14c', '21r0p2', 'B2KSHH.STRIP.DST'),
+#  (2012, 4000, '0x409f0045', '14c', '21r0p2', 'B2KSHH.STRIP.DST'),
+#  (15, 6500, '0x411400a2',  '15a', '24r2', 'B2KSHH.STRIP.DST'),
+#  (16, 6500, '0x6139160F', '16', '28r2', 'B2KSHH.STRIP.DST'),
+# (17, 6500, '0x62661709',  '17', '29r2p1', 'B2KSHH.STRIP.DST'),
+#  (18, 6500, '0x617d18a4', '18', '34r0p1', 'B2KSHH.STRIP.DST'),
+#]%}
+
+{%- set MCdatasets = [
+  (2011, 3500,  'Nu2-Pythia8/Sim09h/Trig0x40760037/Reco14c/Stripping21r1p2Filtered', 'B2KSHH.STRIP.DST'),
+  (2012, 4000,  'Nu2.5-Pythia8/Sim09j/Trig0x4097003d/Reco14c/Stripping21r0p2Filtered', 'B2KSHH.STRIP.DST'),
+  (2012, 4000, 'Nu2.5-Pythia8/Sim09j/Trig0x409f0045/Reco14c/Stripping21r0p2Filtered', 'B2KSHH.STRIP.DST'),
+  (15, 6500,  'Nu1.6-25ns-Pythia8/Sim09h/Trig0x411400a2/Reco15a/Turbo02/Stripping24r2Filtered', 'B2KSHH.STRIP.DST'),
+  (16, 6500,  'Nu1.6-25ns-Pythia8/Sim09h/Trig0x6139160F/Reco16/Turbo03a/Stripping28r2Filtered', 'B2KSHH.STRIP.DST'),
+  (17, 6500,  'Nu1.6-25ns-Pythia8/Sim09h/Trig0x62661709/Reco17/Turbo04a-WithTurcal/Stripping29r2p1Filtered', 'B2KSHH.STRIP.DST'),
+  (18, 6500,  'Nu1.6-25ns-Pythia8/Sim09h/Trig0x617d18a4/Reco18/Turbo05-WithTurcal/Stripping34r0p1Filtered', 'B2KSHH.STRIP.DST'),
+]%}
+
+
+
+{%- set evttypes = [
+    (11104117, 'Bd2KKKS'),
+    (11304165, 'Bd2KpiKS'),
+    (11104127, 'Bd2pipiKS'),
+    (13104136, 'Bs2KKKS'),
+    (13304106, 'Bs2KpiKS'),
+    (13104126, 'Bs2pipiKS'),
+]%}
+
+#Run2
+#KSreco determines the stripping line
+{%- for KSreco in ['DD', 'LL'] %}
+
+{%- for year, energy, recostrip, format in MCdatasets %}
+  {%- for polarity in ['MagDown', 'MagUp'] %}
+    {%- for etNumber, et in evttypes %}
+
+MC_20{{year}}_{{polarity}}_{{KSreco}}_{et}:
+    input:
+      bk_query: /MC/{{year}}/Beam{{energy}}GeV-{{year}}-{{polarity}}-{{recostrip}}/{etNumber}/{{format}}
+    options:
+      - B2hhKS_MC_opt_{{KSreco}}.py
+    checks:
+      - B2KKKS_check    
+
+  {%- endfor %}
+{%- endfor %}
+{%- endfor %}
+
+#put only compulsory fields for checks
+checks: 
+    B2KKKS_check:
+#meaning i am plotting an histogram of some chosen variable
+        type: range                     
+        tree_pattern: Bd2KKKS/DecayTree
+        expression : 'B0_M'
+        limits:
+            min: 4500
+            max: 6000
-- 
GitLab


From 732411628a27b239afddeb5fe17c19c3102eb70a Mon Sep 17 00:00:00 2001
From: Edoardo Mariani <edoardo.mariani@cern.ch>
Date: Mon, 6 Jan 2025 12:26:51 +0100
Subject: [PATCH 03/18] Add new file

---
 bd2kkks_data/B2hhKS_MC_opt_DD.py | 1042 ++++++++++++++++++++++++++++++
 1 file changed, 1042 insertions(+)
 create mode 100644 bd2kkks_data/B2hhKS_MC_opt_DD.py

diff --git a/bd2kkks_data/B2hhKS_MC_opt_DD.py b/bd2kkks_data/B2hhKS_MC_opt_DD.py
new file mode 100644
index 0000000000..2d2efbf2ce
--- /dev/null
+++ b/bd2kkks_data/B2hhKS_MC_opt_DD.py
@@ -0,0 +1,1042 @@
+from GaudiConf import IOHelper
+from Configurables import DaVinci, DecayTreeTuple, SubstitutePID
+from PhysSelPython.Wrappers import Selection, SelectionSequence, DataOnDemand
+from DecayTreeTuple.Configuration import *
+
+
+#libraries for flavour tagging
+from Configurables import BTaggingTool
+from FlavourTagging.Tunings import applyTuning as applyFTTuning
+
+#extract the parameters
+DaVinci().EvtMax = -1
+year = DaVinci().DataType    #should be a string
+if year in ["2015", "2016", "2017", "2018"]:
+    line = 'B2KShh_DD_Run2_OS_Line'             #DD and LL still to parametrize
+else:
+    line = 'B2KShh_DD_Run1_OS_Line'
+
+format = DaVinci().InputType   #DST or MDST
+
+
+# Stream and stripping line we want to use
+
+#stream = 'AllStreams'
+#if (filter == 'STRIP'):
+stream = 'B2KSHH.Strip'     #B2KSHH.Strip
+tesLoc = '/Event/{0}/Phys/{1}/Particles'.format(stream, line)
+
+
+# get the selection(s) created by the stripping
+strippingSels = [DataOnDemand(Location=tesLoc)]
+
+# configure an algorithm to substitute the two pions in the B0 decays with two kaons
+
+subs = SubstitutePID(
+    'MakepiK',
+    Code= "DECTREE('B0 -> pi+ pi- KS0')",
+   # note that SubstitutePID can't handle automatic CC
+    Substitutions = {
+        'B0 -> ^pi+ pi- KS0': 'K+'}
+)
+subsB = SubstitutePID(
+    'MakeKK',
+    Code= "DECTREE('B0 -> K+ pi- KS0')",
+   # note that SubstitutePID can't handle automatic CC
+    Substitutions = {
+        'B0 -> K+ ^pi- KS0': 'K-'}
+)
+
+
+#second type fo substitution
+# B0 -> pi+ K- KS
+subs_pi_minus_K = SubstitutePID(
+	'Make_piminus_K',
+	Code= "DECTREE('B0 -> pi+ pi- KS0')",
+	Substitutions={
+		 'B0 -> pi+ ^pi- KS0': 'K-'}
+)
+
+
+# B0 -> K+ pi- KS
+subs_pi_plus_K = SubstitutePID(
+        'Make_piplus_K',
+        Code= "DECTREE('B0 -> pi+ pi- KS0')",
+        Substitutions={
+                 'B0 -> ^pi+ pi- KS0': 'K+'}
+)
+
+
+# B0 -> pi+ p- KS
+subs_pipKS = SubstitutePID(
+        'Make_piminus_p',
+        Code= "DECTREE('B0 -> pi+ pi- KS0')",
+        Substitutions={
+                 'B0 -> pi+ ^pi- KS0': 'p~-'}
+)
+
+
+# B0 -> p pi- KS
+subs_ppiKS = SubstitutePID(
+        'Make_piplus_p',
+        Code= "DECTREE('B0 -> pi+ pi- KS0')",
+        Substitutions={
+                 'B0 -> ^pi+ pi- KS0': 'p+'}
+)
+
+
+
+
+#B0 -> p+ K- KS0
+subs_pi_plus_p = SubstitutePID(
+        'Make_pi_plus_p',
+        Code = "DECTREE('B0 -> pi+ K- KS0')",
+        Substitutions={
+                'B0 -> ^pi+ K- KS0': 'p+'}
+)
+
+#B0-> K+ p- KS0
+subs_pi_minus_p = SubstitutePID(
+        'Make_pi_minus_p',
+        Code = "DECTREE('B0 -> K+ pi- KS0')",
+        Substitutions={
+               'B0 -> K+ ^pi- KS0': 'p~-'}
+)
+	
+
+#KKKS
+# create a selection using the substitution algorithm
+selSub = Selection(
+    'selSubA',
+    Algorithm=subs,
+    RequiredSelections=strippingSels
+)
+selSubB = Selection(
+    'selSubB',
+    Algorithm=subsB,
+    RequiredSelections=[selSub]
+)
+
+#other mass hypothesis
+#second type of selection using substitution algo
+selSub_pi_minus_K = Selection(
+	'selSub_pi_minus_K',
+	Algorithm=subs_pi_minus_K,
+	RequiredSelections=strippingSels
+)
+
+selSub_pi_plus_K = Selection(
+        'selSub_pi_plus_K',
+        Algorithm=subs_pi_plus_K,
+        RequiredSelections=strippingSels
+)
+
+
+selSub_pipKS = Selection(
+        'selSub_pipKS',
+        Algorithm=subs_pipKS,
+        RequiredSelections=strippingSels
+)
+
+selSub_ppiKS = Selection(
+        'selSub_ppiKS',
+        Algorithm=subs_ppiKS,
+        RequiredSelections=strippingSels
+)
+
+#double subs
+selSub_pi_plus_p = Selection(
+	'selSub_pi_plus_p',
+	Algorithm= subs_pi_plus_p,
+	RequiredSelections=[selSub_pi_minus_K]
+)
+
+selSub_pi_minus_p = Selection(
+        'selSub_pi_minus_p',
+        Algorithm= subs_pi_minus_p,
+        RequiredSelections=[selSub_pi_plus_K]
+)
+
+
+# in order to add the selection into the program make a sequence
+selSeq = SelectionSequence('SelSeq', TopSelection=selSubB)
+
+selSeq_piKKS = SelectionSequence('SelSeq1', TopSelection= selSub_pi_minus_K)
+selSeq_KpiKS = SelectionSequence('SelSeq2', TopSelection= selSub_pi_plus_K)
+#selSeq_pipiKS= SelectionSequence('SelSeq3', TopSelection = selSub_2pi_2K)   #commented before
+selSeq_pipKS = SelectionSequence('SelSeq4', TopSelection = selSub_pipKS)
+selSeq_ppiKS = SelectionSequence('SelSeq5', TopSelection = selSub_ppiKS)
+selSeq_pKKS = SelectionSequence('SelSeq6', TopSelection= selSub_pi_plus_p)
+selSeq_KpKS = SelectionSequence('SelSeq7', TopSelection = selSub_pi_minus_p)
+
+
+# Create an ntuple
+dtt = DecayTreeTuple('Bd2KKKS')
+dtt.Inputs = [selSeq.outputLocation()]
+#dtt.Decay = 'B0 -> ^K+ ^K- ^KS0'
+dtt.Decay = 'B0 -> ^K+ ^K- ^(KS0 -> ^pi+ ^pi-)'
+
+dtt_piKKS = DecayTreeTuple('Bd2piKKS')
+dtt_piKKS.Inputs = [selSeq_piKKS.outputLocation()]
+dtt_piKKS.Decay = 'B0 -> ^pi+ ^K- ^(KS0 -> ^pi+ ^pi-)'
+
+dtt_KpiKS = DecayTreeTuple('Bd2KpiKS')
+dtt_KpiKS.Inputs = [selSeq_KpiKS.outputLocation()]
+dtt_KpiKS.Decay = 'B0 -> ^K+ ^pi- ^(KS0 -> ^pi+ ^pi-)'
+
+dtt_pipKS = DecayTreeTuple('Bd2pipKS')
+dtt_pipKS.Inputs = [selSeq_pipKS.outputLocation()]
+dtt_pipKS.Decay = 'B0 -> ^pi+ ^p~- ^(KS0 -> ^pi+ ^pi-)'
+
+dtt_ppiKS = DecayTreeTuple('Bd2ppiKS')
+dtt_ppiKS.Inputs = [selSeq_ppiKS.outputLocation()]
+dtt_ppiKS.Decay = 'B0 -> ^p+ ^pi- ^(KS0 -> ^pi+ ^pi-)'
+
+
+dtt_pKKS = DecayTreeTuple('Bd2pKKS')
+dtt_pKKS.Inputs = [selSeq_pKKS.outputLocation()]
+dtt_pKKS.Decay = 'B0 -> ^p+ ^K- ^(KS0 -> ^pi+ ^pi-)'
+
+dtt_KpKS = DecayTreeTuple('Bd2KpKS')
+dtt_KpKS.Inputs	= [selSeq_KpKS.outputLocation()]
+dtt_KpKS.Decay = 'B0 -> ^K+ ^p~- ^(KS0 -> ^pi+ ^pi-)'
+
+
+#the standard one, directly from the Stripping line
+#Tutte parti tolte è perchè faccio così in modo più efficiente
+
+dtt_pipiKS = DecayTreeTuple('Bd2pipiKS')
+dtt_pipiKS.Inputs =  [tesLoc]                        #dtt_pipiKS.Inputs =  ['/Event/{0}/Phys/{1}/Particles'.format(stream, line)]      
+dtt_pipiKS.Decay = 'B0 -> ^pi+ ^pi- ^(KS0 -> ^pi+ ^pi-)'
+
+
+
+
+#DEFINITION OF BRANCHES
+
+dtt.addBranches({
+        'B': 'B0 -> K+ K- (KS0-> pi+ pi-)',
+        'h1' : 'B0 -> ^K+ K- (KS0 -> pi+ pi-)',
+        'h2': 'B0 -> K+ ^K- (KS0 -> pi+ pi-)',
+        'KS': 'B0 -> K+ K- ^(KS0 -> pi+ pi-)',
+        'KSpip': 'B0 -> K+ K- (KS0 -> ^pi+ pi-)',	 #pi+ dauther of the KS
+        'KSpim': 'B0 -> K+ K- (KS0 -> pi+ ^pi-)'         #pi- daughter of the KS
+        })
+
+
+dtt_piKKS.addBranches({
+	'B': 'B0 -> pi+ K- (KS0 -> pi+ pi-)',
+	'h1': 'B0 -> ^pi+ K- (KS0 -> pi+ pi-)',
+	'h2': 'B0 -> pi+ ^K- (KS0 -> pi+ pi-)',
+	'KS': 'B0 -> pi+ K- ^(KS0 -> pi+ pi-)',
+    'KSpip': 'B0 -> pi+ K- (KS0 -> ^pi+ pi-)',
+    'KSpim': 'B0 -> pi+ K- (KS0 -> pi+ ^pi-)'
+})
+
+
+dtt_KpiKS.addBranches({
+    'B': 'B0 -> K+ pi- (KS0 -> pi+ pi-)',
+    'h1': 'B0 -> ^K+ pi- (KS0 -> pi+ pi-)',
+    'h2': 'B0 -> K+ ^pi- (KS0 -> pi+ pi-)',
+    'KS': 'B0 -> K+ pi- ^(KS0 -> pi+ pi-)',
+    'KSpip': 'B0 -> K+ pi- (KS0  -> ^pi+ pi-)',
+    'KSpim': 'B0 -> K+ pi- (KS0 -> pi+ ^pi-)'
+
+})
+
+
+dtt_pipiKS.addBranches({
+	'B': 'B0 -> pi+ pi- (KS0 -> pi+ pi-)',
+	'h1': 'B0 -> ^pi+ pi- (KS0 -> pi+ pi-)',
+	'h2': 'B0 -> pi+ ^pi- (KS0 -> pi+ pi-)',
+	'KS': 'B0 -> pi+ pi- ^(KS0 -> pi+ pi-)',
+    'KSpip': 'B0 -> pi+ pi- (KS0 -> ^pi+ pi-)',
+    'KSpim': 'B0 -> pi+ pi- (KS0 -> pi+ ^pi-)'
+})
+
+
+dtt_pipKS.addBranches({
+    'B': 'B0 -> pi+ p~- (KS0 -> pi+ pi-)',
+    'h1': 'B0 -> ^pi+ p~- (KS0 -> pi+ pi-)',
+    'h2': 'B0 -> pi+ ^p~- (KS0 -> pi+ pi-)',
+    'KS': 'B0 -> pi+ p~- ^(KS0 -> pi+ pi-)',
+    'KSpip': 'B0 -> pi+ p~- (KS0 -> ^pi+ pi-)',
+    'KSpim': 'B0 -> pi+ p~- (KS0 -> pi+ ^pi-)'
+})
+
+
+
+dtt_ppiKS.addBranches({
+    'B': 'B0 -> p+ pi- (KS0 -> pi+ pi-)',
+    'h1': 'B0 -> ^p+ pi- (KS0 -> pi+ pi-)',
+    'h2': 'B0 -> p+ ^pi- (KS0 -> pi+ pi-)',
+    'KS': 'B0 -> p+ pi- ^(KS0 -> pi+ pi-)',
+    'KSpip': 'B0 -> p+ pi- (KS0 -> ^pi+ pi-)',
+    'KSpim': 'B0 -> p+ pi- (KS0 -> pi+ ^pi-)'
+})
+
+dtt_pKKS.addBranches({
+    'B': 'B0 -> p+ K- (KS0 -> pi+ pi-)',
+    'h1': 'B0 -> ^p+ K- (KS0 -> pi+ pi-)',
+    'h2': 'B0 -> p+ ^K- (KS0 -> pi+ pi-)',
+    'KS': 'B0 -> p+ K- ^(KS0 -> pi+ pi-)',
+    'KSpip': 'B0 -> p+ K- (KS0 -> ^pi+ pi-)',
+    'KSpim': 'B0 -> p+ K- (KS0 -> pi+ ^pi-)'
+})
+
+dtt_KpKS.addBranches({
+    'B': 'B0 -> K+ p~- (KS0 -> pi+ pi-)',
+    'h1': 'B0 -> ^K+ p~- (KS0 -> pi+ pi-)',
+    'h2': 'B0 -> K+ ^p~- (KS0 -> pi+ pi-)',
+    'KS': 'B0 -> K+ p~- ^(KS0 -> pi+ pi-)',
+    'KSpip': 'B0 -> K+ p~- (KS0 -> ^pi+ pi-)',
+    'KSpim': 'B0 -> K+ p~- (KS0 -> pi+ ^pi-)'
+})
+
+#BACK TO THE MAIN dtt
+
+track_tool = dtt.addTupleTool('TupleToolTrackInfo')
+Ntracks_tool = dtt.addTupleTool('TupleToolRecoStats')   #to add nTracks variables
+time_tool = dtt.B.addTupleTool('TupleToolPropertime')   #add decay time information branch
+Trigger_tool = dtt.addTupleTool('TupleToolTrigger')
+Trigger_tool.Verbose =True    #necessario per far stampare tutti i tipi di trigger che mi servonos
+TRUEMC_tool= dtt.addTupleTool('TupleToolMCTruth')
+
+
+track_tool_pipiKS = dtt_pipiKS.addTupleTool('TupleToolTrackInfo')  #to have the TRACK info also on the pipiKS of stripping
+Ntracks_tool_pipiKS = dtt_pipiKS.addTupleTool('TupleToolRecoStats')   #to add nTracks variables
+time_tool_pipiKS = dtt_pipiKS.B.addTupleTool('TupleToolPropertime')   #add decay time information branch
+Trigger_tool_pipiKS = dtt_pipiKS.addTupleTool('TupleToolTrigger')
+Trigger_tool_pipiKS.Verbose =True    #necessario per far stampare tutti i tipi di trigger che mi servonos
+TRUEMC_tool_pipiKS= dtt_pipiKS.addTupleTool('TupleToolMCTruth')
+
+track_tool_piKKS = dtt_piKKS.addTupleTool('TupleToolTrackInfo')  #to have the TRACK info also on the pipiKS of stripping
+Ntracks_tool_piKKS = dtt_piKKS.addTupleTool('TupleToolRecoStats')   #to add nTracks variables
+time_tool_piKKS = dtt_piKKS.B.addTupleTool('TupleToolPropertime')   #add decay time information branch
+Trigger_tool_piKKS = dtt_piKKS.addTupleTool('TupleToolTrigger')
+Trigger_tool_piKKS.Verbose =True    #necessario per far stampare tutti i tipi di trigger che mi servonos
+TRUEMC_tool_piKKS= dtt_piKKS.addTupleTool('TupleToolMCTruth')
+
+
+track_tool_KpiKS = dtt_KpiKS.addTupleTool('TupleToolTrackInfo')  #to have the TRACK info also on the pipiKS of stripping
+Ntracks_tool_KpiKS = dtt_KpiKS.addTupleTool('TupleToolRecoStats')   #to add nTracks variables
+time_tool_KpiKS = dtt_KpiKS.B.addTupleTool('TupleToolPropertime')   #add decay time information branch
+Trigger_tool_KpiKS = dtt_KpiKS.addTupleTool('TupleToolTrigger')
+Trigger_tool_KpiKS.Verbose =True    #necessario per far stampare tutti i tipi di trigger che mi servonos
+TRUEMC_tool_KpiKS= dtt_KpiKS.addTupleTool('TupleToolMCTruth')
+
+
+#GETTING VARIABLES WITH LOKI FUNCTORS
+#I use LoKi for ETA as it was not present
+
+#now I have put the pipiKS dtt instead of the standard one (dtt)
+B0_hybrid = dtt.addTupleTool('LoKi::Hybrid::TupleTool/LoKi_B0')
+B0_hybrid.Variables = {
+        'ETA': 'ETA'
+}
+
+B0_hybrid_pipiKS = dtt_pipiKS.addTupleTool('LoKi::Hybrid::TupleTool/LoKi_B0')
+B0_hybrid_pipiKS.Variables = {
+        'ETA': 'ETA'
+}
+
+B0_hybrid_piKKS = dtt_piKKS.addTupleTool('LoKi::Hybrid::TupleTool/LoKi_B0')
+B0_hybrid_piKKS.Variables = {
+        'ETA': 'ETA'
+}
+
+B0_hybrid_KpiKS = dtt_KpiKS.addTupleTool('LoKi::Hybrid::TupleTool/LoKi_B0')
+B0_hybrid_KpiKS.Variables = {
+        'ETA': 'ETA'
+}
+
+
+#DTF variables
+
+KSPV_DTF = dtt.B.addTupleTool('TupleToolDecayTreeFitter/KSPV')   #KSPV
+dtt.B.KSPV.constrainToOriginVertex = True
+dtt.B.KSPV.Verbose=True    #adds variables for the daughters also (KS0)
+dtt.B.KSPV.daughtersToConstrain = ['KS0']
+
+#Constrain only on KS seems to be useless
+#constrain B mass, KS mass, PV : variable useful for MC
+
+BdKSPV_DTF =dtt.B.addTupleTool('TupleToolDecayTreeFitter/BdKSPV')  #BdKSPV
+dtt.B.BdKSPV.constrainToOriginVertex = True
+dtt.B.BdKSPV.Verbose=True
+dtt.B.BdKSPV.daughtersToConstrain = ['B0','KS0']
+
+BsKSPV_DTF =dtt.B.addTupleTool('TupleToolDecayTreeFitter/BsKSPV')   #BsKSPV
+dtt.B.BsKSPV.constrainToOriginVertex = True
+dtt.B.BsKSPV.Verbose=True
+dtt.B.BsKSPV.daughtersToConstrain = ['B_s0','KS0']
+dtt.B.BsKSPV.Substitutions = {
+    '^(B0 -> K+ K- KS0)': 'B_s0',
+    '^(B~0 -> K+ K- KS0)': 'B_s~0'
+}
+
+
+
+#DTF for pipiKS branch
+KSPV_DTF_pipiKS = dtt_pipiKS.B.addTupleTool('TupleToolDecayTreeFitter/KSPV')
+dtt_pipiKS.B.KSPV.constrainToOriginVertex = True
+dtt_pipiKS.B.KSPV.Verbose=True
+dtt_pipiKS.B.KSPV.daughtersToConstrain = ['KS0']
+
+BdKSPV_DTF_pipiKS =dtt_pipiKS.B.addTupleTool('TupleToolDecayTreeFitter/BdKSPV')
+dtt_pipiKS.B.BdKSPV.constrainToOriginVertex = False
+dtt_pipiKS.B.BdKSPV.Verbose=True
+dtt_pipiKS.B.BdKSPV.daughtersToConstrain = ['B0','KS0']
+
+BsKSPV_DTF_pipiKS =dtt_pipiKS.B.addTupleTool('TupleToolDecayTreeFitter/BsKSPV')
+dtt_pipiKS.B.BsKSPV.constrainToOriginVertex = False
+dtt_pipiKS.B.BsKSPV.Verbose=True
+dtt_pipiKS.B.BsKSPV.daughtersToConstrain = ['B_s0','KS0']
+dtt_pipiKS.B.BsKSPV.Substitutions = {
+    '^(B0 -> pi+ pi- KS0)': 'B_s0',
+    '^(B~0 -> pi+ pi- KS0)': 'B_s~0'
+}
+
+
+#DTF for piKKS branch
+KSPV_DTF_piKKS = dtt_piKKS.B.addTupleTool('TupleToolDecayTreeFitter/KSPV')
+dtt_piKKS.B.KSPV.constrainToOriginVertex = True
+dtt_piKKS.B.KSPV.Verbose=True
+dtt_piKKS.B.KSPV.daughtersToConstrain = ['KS0']
+
+BdKSPV_DTF_piKKS =dtt_piKKS.B.addTupleTool('TupleToolDecayTreeFitter/BdKSPV')
+dtt_piKKS.B.BdKSPV.constrainToOriginVertex = False
+dtt_piKKS.B.BdKSPV.Verbose=True
+dtt_piKKS.B.BdKSPV.daughtersToConstrain = ['B0','KS0']
+
+BsKSPV_DTF_piKKS =dtt_piKKS.B.addTupleTool('TupleToolDecayTreeFitter/BsKSPV')
+dtt_piKKS.B.BsKSPV.constrainToOriginVertex = False
+dtt_piKKS.B.BsKSPV.Verbose=True
+dtt_piKKS.B.BsKSPV.daughtersToConstrain = ['B_s0','KS0']
+dtt_piKKS.B.BsKSPV.Substitutions = {
+    '^(B0 -> pi+ K- KS0)': 'B_s0',
+    '^(B~0 -> pi+ K- KS0)': 'B_s~0'
+}
+
+
+#DTF for KpiKS branch
+KSPV_DTF_KpiKS = dtt_KpiKS.B.addTupleTool('TupleToolDecayTreeFitter/KSPV')
+dtt_KpiKS.B.KSPV.constrainToOriginVertex = True
+dtt_KpiKS.B.KSPV.Verbose=True
+dtt_KpiKS.B.KSPV.daughtersToConstrain = ['KS0']
+
+BdKSPV_DTF_KpiKS =dtt_KpiKS.B.addTupleTool('TupleToolDecayTreeFitter/BdKSPV')
+dtt_KpiKS.B.BdKSPV.constrainToOriginVertex = False
+dtt_KpiKS.B.BdKSPV.Verbose=True
+dtt_KpiKS.B.BdKSPV.daughtersToConstrain = ['B0','KS0']
+
+BsKSPV_DTF_KpiKS =dtt_KpiKS.B.addTupleTool('TupleToolDecayTreeFitter/BsKSPV')
+dtt_KpiKS.B.BsKSPV.constrainToOriginVertex = False
+dtt_KpiKS.B.BsKSPV.Verbose=True
+dtt_KpiKS.B.BsKSPV.daughtersToConstrain = ['B_s0','KS0']
+dtt_KpiKS.B.BsKSPV.Substitutions = {
+    '^(B0 -> K+ pi- KS0)': 'B_s0',
+    '^(B~0 -> K+ pi- KS0)': 'B_s~0'
+}
+
+
+#DTF for pKKS branch
+KSPV_DTF_pKKS = dtt_pKKS.B.addTupleTool('TupleToolDecayTreeFitter/KSPV')
+dtt_pKKS.B.KSPV.constrainToOriginVertex = True
+dtt_pKKS.B.KSPV.Verbose=True
+dtt_pKKS.B.KSPV.daughtersToConstrain = ['KS0']
+
+BdKSPV_DTF_pKKS =dtt_pKKS.B.addTupleTool('TupleToolDecayTreeFitter/BdKSPV')
+dtt_pKKS.B.BdKSPV.constrainToOriginVertex = False
+dtt_pKKS.B.BdKSPV.Verbose=True
+dtt_pKKS.B.BdKSPV.daughtersToConstrain = ['B0','KS0']
+
+BsKSPV_DTF_pKKS =dtt_pKKS.B.addTupleTool('TupleToolDecayTreeFitter/BsKSPV')
+dtt_pKKS.B.BsKSPV.constrainToOriginVertex = False
+dtt_pKKS.B.BsKSPV.Verbose=True
+dtt_pKKS.B.BsKSPV.daughtersToConstrain = ['B_s0','KS0']
+dtt_pKKS.B.BsKSPV.Substitutions = {
+    '^(B0 -> p+ K- KS0)': 'B_s0',
+    '^(B~0 -> p+ K- KS0)': 'B_s~0'
+}
+
+#DTF for KpKS branch
+KSPV_DTF_KpKS = dtt_KpKS.B.addTupleTool('TupleToolDecayTreeFitter/KSPV')
+dtt_KpKS.B.KSPV.constrainToOriginVertex = True
+dtt_KpKS.B.KSPV.Verbose=True
+dtt_KpKS.B.KSPV.daughtersToConstrain = ['KS0']
+
+BdKSPV_DTF_KpKS =dtt_KpKS.B.addTupleTool('TupleToolDecayTreeFitter/BdKSPV')
+dtt_KpKS.B.BdKSPV.constrainToOriginVertex = False
+dtt_KpKS.B.BdKSPV.Verbose=True
+dtt_KpKS.B.BdKSPV.daughtersToConstrain = ['B0','KS0']
+
+BsKSPV_DTF_KpKS =dtt_KpKS.B.addTupleTool('TupleToolDecayTreeFitter/BsKSPV')
+dtt_KpKS.B.BsKSPV.constrainToOriginVertex = False
+dtt_KpKS.B.BsKSPV.Verbose=True
+dtt_KpKS.B.BsKSPV.daughtersToConstrain = ['B_s0','KS0']
+dtt_KpKS.B.BsKSPV.Substitutions = {
+    '^(B0 -> K+ p~- KS0)': 'B_s0',
+    '^(B~0 -> K+ p~- KS0)': 'B_s~0'
+}
+
+
+#DTF for pipKS branch
+KSPV_DTF_pipKS = dtt_pipKS.B.addTupleTool('TupleToolDecayTreeFitter/KSPV')
+dtt_pipKS.B.KSPV.constrainToOriginVertex = True
+dtt_pipKS.B.KSPV.Verbose=True
+dtt_pipKS.B.KSPV.daughtersToConstrain = ['KS0']
+
+BdKSPV_DTF_pipKS =dtt_pipKS.B.addTupleTool('TupleToolDecayTreeFitter/BdKSPV')
+dtt_pipKS.B.BdKSPV.constrainToOriginVertex = False
+dtt_pipKS.B.BdKSPV.Verbose=True
+dtt_pipKS.B.BdKSPV.daughtersToConstrain = ['B0','KS0']
+
+BsKSPV_DTF_pipKS =dtt_pipKS.B.addTupleTool('TupleToolDecayTreeFitter/BsKSPV')
+dtt_pipKS.B.BsKSPV.constrainToOriginVertex = False
+dtt_pipKS.B.BsKSPV.Verbose=True
+dtt_pipKS.B.BsKSPV.daughtersToConstrain = ['B_s0','KS0']
+dtt_pipKS.B.BsKSPV.Substitutions = {
+    '^(B0 -> pi+ p~- KS0)': 'B_s0',
+    '^(B~0 -> pi+ p~- KS0)': 'B_s~0'
+}
+
+#DTF for ppiKS branch
+KSPV_DTF_ppiKS = dtt_ppiKS.B.addTupleTool('TupleToolDecayTreeFitter/KSPV')
+dtt_ppiKS.B.KSPV.constrainToOriginVertex = True
+dtt_ppiKS.B.KSPV.Verbose=True
+dtt_ppiKS.B.KSPV.daughtersToConstrain = ['KS0']
+
+BdKSPV_DTF_ppiKS =dtt_ppiKS.B.addTupleTool('TupleToolDecayTreeFitter/BdKSPV')
+dtt_ppiKS.B.BdKSPV.constrainToOriginVertex = False
+dtt_ppiKS.B.BdKSPV.Verbose=True
+dtt_ppiKS.B.BdKSPV.daughtersToConstrain = ['B0','KS0']
+
+BsKSPV_DTF_ppiKS =dtt_ppiKS.B.addTupleTool('TupleToolDecayTreeFitter/BsKSPV')
+dtt_ppiKS.B.BsKSPV.constrainToOriginVertex = False
+dtt_ppiKS.B.BsKSPV.Verbose=True
+dtt_ppiKS.B.BsKSPV.daughtersToConstrain = ['B_s0','KS0']
+dtt_ppiKS.B.BsKSPV.Substitutions = {
+    '^(B0 -> p+ pi- KS0)': 'B_s0',
+    '^(B~0 -> p+ pi- KS0)': 'B_s~0'
+}
+
+
+
+
+#Way I am retrieving DecayTreeFitter variables for just-B0-mass-constraints
+#preamble common to all the branches
+
+preamble_BdKSPV = [   #only LoKi functors where i perform some operations
+    
+    "M_BdKSPV = DTF_FUN(M, True, strings(['B0', 'KS0']))",
+    "P_BdKSPV = DTF_FUN(P, True, strings(['B0', 'KS0']))",
+    "PT_BdKSPV = DTF_FUN(PT, True, strings(['B0', 'KS0']))",
+    "PX_BdKSPV = DTF_FUN(PX, True, strings(['B0', 'KS0']))",
+    "PY_BdKSPV = DTF_FUN(PY, True, strings(['B0', 'KS0']))",
+    "PZ_BdKSPV = DTF_FUN(PZ, True, strings(['B0', 'KS0']))",
+    "PE_BdKSPV = DTF_FUN(E, True, strings(['B0', 'KS0']))",
+    
+    "h1_M_BdKSPV = DTF_FUN(CHILD(M,1), True, strings(['B0', 'KS0']))",
+    "h1_P_BdKSPV = DTF_FUN(CHILD(P,1), True, strings(['B0', 'KS0']))",
+    "h1_PX_BdKSPV = DTF_FUN(CHILD(PX,1), True, strings(['B0', 'KS0']))",
+    "h1_PY_BdKSPV = DTF_FUN(CHILD(PY,1), True, strings(['B0', 'KS0']))",
+    "h1_PZ_BdKSPV = DTF_FUN(CHILD(PZ,1), True, strings(['B0', 'KS0']))",
+    "h1_PE_BdKSPV = DTF_FUN(CHILD(E,1), True, strings(['B0', 'KS0']))",
+    
+    "h2_M_BdKSPV = DTF_FUN(CHILD(M,2), True, strings(['B0', 'KS0']))",
+    "h2_P_BdKSPV = DTF_FUN(CHILD(P,2), True, strings(['B0', 'KS0']))",
+    "h2_PX_BdKSPV = DTF_FUN(CHILD(PX,2), True, strings(['B0', 'KS0']))",
+    "h2_PY_BdKSPV = DTF_FUN(CHILD(PY,2), True, strings(['B0', 'KS0']))",
+    "h2_PZ_BdKSPV = DTF_FUN(CHILD(PZ,2), True, strings(['B0', 'KS0']))",
+    "h2_PE_BdKSPV = DTF_FUN(CHILD(E,2), True, strings(['B0', 'KS0']))",
+    
+    "KS_M_BdKSPV = DTF_FUN(CHILD(M,3), True, strings(['B0', 'KS0']))",
+    "KS_P_BdKSPV = DTF_FUN(CHILD(P,3), True, strings(['B0', 'KS0']))",
+    "KS_PX_BdKSPV = DTF_FUN(CHILD(PX,3), True, strings(['B0', 'KS0']))",
+    "KS_PY_BdKSPV = DTF_FUN(CHILD(PY,3), True, strings(['B0', 'KS0']))",
+    "KS_PZ_BdKSPV = DTF_FUN(CHILD(PZ,3), True, strings(['B0', 'KS0']))",
+    "KS_PE_BdKSPV = DTF_FUN(CHILD(E,3), True, strings(['B0', 'KS0']))",
+    
+    "M12_BdKSPV = DTF_FUN(M12, True, strings(['B0', 'KS0']))**2",
+    "M13_BdKSPV = DTF_FUN(M13,True, strings(['B0', 'KS0']))**2",
+    "M23_BdKSPV = DTF_FUN(M23, True, strings(['B0', 'KS0']))**2",
+]
+
+preamble_KSPV = [
+    
+    "M_KSPV = DTF_FUN(M, True, 'KS0')",
+    "P_KSPV = DTF_FUN(P, True, 'KS0')",
+    "PT_KSPV = DTF_FUN(PT, True, 'KS0')",
+    "PX_KSPV = DTF_FUN(PX, True, 'KS0')",
+    "PY_KSPV = DTF_FUN(PY, True, 'KS0')",
+    "PZ_KSPV = DTF_FUN(PZ, True, 'KS0')",
+    "PE_KSPV = DTF_FUN(E, True, 'KS0')",
+    
+    "h1_M_KSPV = DTF_FUN(CHILD(M,1), True, 'KS0')",
+    "h1_P_KSPV = DTF_FUN(CHILD(P,1), True, 'KS0')",
+    "h1_PX_KSPV = DTF_FUN(CHILD(PX,1), True, 'KS0')",
+    "h1_PY_KSPV = DTF_FUN(CHILD(PY,1), True, 'KS0')",
+    "h1_PZ_KSPV = DTF_FUN(CHILD(PZ,1), True, 'KS0')",
+    "h1_PE_KSPV = DTF_FUN(CHILD(E,1), True, 'KS0')",
+    
+    "h2_M_KSPV = DTF_FUN(CHILD(M,2), True, 'KS0')",
+    "h2_P_KSPV = DTF_FUN(CHILD(P,2), True, 'KS0')",
+    "h2_PX_KSPV = DTF_FUN(CHILD(PX,2), True, 'KS0')",
+    "h2_PY_KSPV = DTF_FUN(CHILD(PY,2), True, 'KS0')",
+    "h2_PZ_KSPV = DTF_FUN(CHILD(PZ,2), True, 'KS0')",
+    "h2_PE_KSPV = DTF_FUN(CHILD(E,2), True, 'KS0')",
+    
+    "KS_M_KSPV = DTF_FUN(CHILD(M,3), True, 'KS0')",
+    "KS_P_KSPV = DTF_FUN(CHILD(P,3), True, 'KS0')",
+    "KS_PX_KSPV = DTF_FUN(CHILD(PX,3), True, 'KS0')",
+    "KS_PY_KSPV = DTF_FUN(CHILD(PY,3), True, 'KS0')",
+    "KS_PZ_KSPV = DTF_FUN(CHILD(PZ,3), True, 'KS0')",
+    "KS_PE_KSPV = DTF_FUN(CHILD(E,3), True, 'KS0')",
+    
+    "M12_KSPV = DTF_FUN(M12, True, 'KS0')**2",
+    "M13_KSPV = DTF_FUN(M13, True, 'KS0')**2",
+    "M23_KSPV = DTF_FUN(M23, True, 'KS0')**2",
+]
+
+preamble_BsKSPV = [   #only LoKi functors where i perform some operations
+    "masses = LoKi.AuxDTFBase.MASSES" ,"constr = masses()" ,"constr ['B0'] = 5.36692 * GeV ",
+    
+    "M_BsKSPV = DTF_FUN(M, True, strings(['B0', 'KS0']), constr)",
+    "P_BsKSPV = DTF_FUN(P, True, strings(['B0', 'KS0']), constr)",
+    "PT_BsKSPV = DTF_FUN(PT, True, strings(['B0', 'KS0']), constr)",
+    "PX_BsKSPV = DTF_FUN(PX, True, strings(['B0', 'KS0']), constr)",
+    "PY_BsKSPV = DTF_FUN(PY, True, strings(['B0', 'KS0']), constr)",
+    "PZ_BsKSPV = DTF_FUN(PZ, True, strings(['B0', 'KS0']), constr)",
+    "PE_BsKSPV = DTF_FUN(E, True, strings(['B0', 'KS0']), constr )",
+    
+    "h1_M_BsKSPV = DTF_FUN(CHILD(M,1), True, strings(['B0', 'KS0']), constr)",
+    "h1_P_BsKSPV = DTF_FUN(CHILD(P,1), True, strings(['B0', 'KS0']), constr)",
+    "h1_PX_BsKSPV = DTF_FUN(CHILD(PX,1), True, strings(['B0', 'KS0']), constr)",
+    "h1_PY_BsKSPV = DTF_FUN(CHILD(PY,1), True, strings(['B0', 'KS0']), constr)",
+    "h1_PZ_BsKSPV = DTF_FUN(CHILD(PZ,1), True, strings(['B0', 'KS0']), constr)",
+    "h1_PE_BsKSPV = DTF_FUN(CHILD(E,1), True, strings(['B0', 'KS0']), constr)",
+    
+    "h2_M_BsKSPV = DTF_FUN(CHILD(M,2), True, strings(['B0', 'KS0']), constr)",
+    "h2_P_BsKSPV = DTF_FUN(CHILD(P,2), True, strings(['B0', 'KS0']), constr)",
+    "h2_PX_BsKSPV = DTF_FUN(CHILD(PX,2), True, strings(['B0', 'KS0']), constr)",
+    "h2_PY_BsKSPV = DTF_FUN(CHILD(PY,2), True, strings(['B0', 'KS0']), constr)",
+    "h2_PZ_BsKSPV = DTF_FUN(CHILD(PZ,2), True, strings(['B0', 'KS0']), constr)",
+    "h2_PE_BsKSPV = DTF_FUN(CHILD(E,2), True, strings(['B0', 'KS0']), constr)",
+    
+    "KS_M_BsKSPV = DTF_FUN(CHILD(M,3), True, strings(['B0', 'KS0']), constr)",
+    "KS_P_BsKSPV = DTF_FUN(CHILD(P,3), True, strings(['B0', 'KS0']), constr)",
+    "KS_PX_BsKSPV = DTF_FUN(CHILD(PX,3), True, strings(['B0', 'KS0']), constr)",
+    "KS_PY_BsKSPV = DTF_FUN(CHILD(PY,3), True, strings(['B0', 'KS0']), constr)",
+    "KS_PZ_BsKSPV = DTF_FUN(CHILD(PZ,3), True, strings(['B0', 'KS0']), constr)",
+    "KS_PE_BsKSPV = DTF_FUN(CHILD(E,3), True, strings(['B0', 'KS0']), constr)",
+    
+    "M12_BsKSPV = DTF_FUN(M12, True, strings(['B0', 'KS0']), constr)**2",
+    "M13_BsKSPV = DTF_FUN(M13,True, strings(['B0', 'KS0']), constr)**2",
+    "M23_BsKSPV = DTF_FUN(M23, True, strings(['B0', 'KS0']), constr)**2",
+]
+
+
+
+
+preamble_BdKSPV_list = ["M_BdKSPV", "P_BdKSPV", "PT_BdKSPV", "PX_BdKSPV", "PY_BdKSPV", "PZ_BdKSPV", "PE_BdKSPV",
+                       "h1_M_BdKSPV", "h1_P_BdKSPV", "h1_PX_BdKSPV", "h1_PY_BdKSPV", "h1_PZ_BdKSPV", "h1_PE_BdKSPV",
+                       "h2_M_BdKSPV", "h2_P_BdKSPV", "h2_PX_BdKSPV", "h2_PY_BdKSPV", "h2_PZ_BdKSPV", "h2_PE_BdKSPV",
+                       "KS_M_BdKSPV", "KS_P_BdKSPV", "KS_PX_BdKSPV", "KS_PY_BdKSPV", "KS_PZ_BdKSPV", "KS_PE_BdKSPV",
+                       "M12_BdKSPV", "M13_BdKSPV", "M23_BdKSPV"]
+preamble_KSPV_list = ["M_KSPV", "P_KSPV", "PT_KSPV", "PX_KSPV", "PY_KSPV", "PZ_KSPV", "PE_KSPV",
+                       "h1_M_KSPV", "h1_P_KSPV", "h1_PX_KSPV", "h1_PY_KSPV", "h1_PZ_KSPV", "h1_PE_KSPV",
+                       "h2_M_KSPV", "h2_P_KSPV", "h2_PX_KSPV", "h2_PY_KSPV", "h2_PZ_KSPV", "h2_PE_KSPV",
+                       "KS_M_KSPV", "KS_P_KSPV", "KS_PX_KSPV", "KS_PY_KSPV", "KS_PZ_KSPV", "KS_PE_KSPV",
+                       "M12_KSPV", "M13_KSPV", "M23_KSPV" ]
+preamble_BsKSPV_list = ["M_BsKSPV", "P_BsKSPV", "PT_BsKSPV", "PX_BsKSPV", "PY_BsKSPV", "PZ_BsKSPV", "PE_BsKSPV",
+                        "h1_M_BsKSPV","h1_P_BsKSPV", "h1_PX_BsKSPV", "h1_PY_BsKSPV", "h1_PZ_BsKSPV", "h1_PE_BsKSPV",
+                        "h2_M_BsKSPV", "h2_P_BsKSPV", "h2_PX_BsKSPV", "h2_PY_BsKSPV", "h2_PZ_BsKSPV", "h2_PE_BsKSPV",
+                        "KS_M_BsKSPV", "KS_P_BsKSPV", "KS_PX_BsKSPV", "KS_PY_BsKSPV", "KS_PZ_BsKSPV", "KS_PE_BsKSPV",
+                        "M12_BsKSPV", "M13_BsKSPV", "M23_BsKSPV"]
+
+variable_DTF_list = ["M", "P", "PT", "PX", "PY", "PZ", "PE",
+                     "h1_M", "h1_P", "h1_PX", "h1_PY", "h1_PZ", "h1_PE",
+                     "h2_M", "h2_P", "h2_PX", "h2_PY", "h2_PZ", "h2_PE",
+                     "KS_M", "KS_P", "KS_PX", "KS_PY", "KS_PZ", "KS_PE" ,
+                     "m12Sq", "m13Sq", "m23Sq"]
+
+
+suffixes_Bd2hhKS = ["Bd2KKKS", "Bd2pipiKS", "Bd2piKKS", "Bd2KpiKS", "Bd2pKKS", "Bd2KpKS", "Bd2pipKS", "Bd2ppiKS"]
+suffixes_hhKS = ["KKKS", "pipiKS", "piKKS", "KpiKS", "pKKS", "KpKS", "pipKS", "ppiKS"]
+suffixes_Bs2hhKS = ["Bs2KKKS", "Bs2pipiKS", "Bs2piKKS", "Bs2KpiKS", "Bs2pKKS", "Bs2KpKS", "Bs2pipKS", "Bs2ppiKS"]
+
+# Dictionary to hold all the dictionaries with different suffixes  -- for Bd2KKKS
+dicts_Bd2hhKS = {}
+string_dict_Bd2hhKS = dict(zip(variable_DTF_list, preamble_BdKSPV_list))    #associate variable name and preamble "function"
+
+# Dictionary to hold all the dictionaries with different suffixes  -- for KKKS
+dicts_hhKS = {}
+string_dict_hhKS = dict(zip(variable_DTF_list, preamble_KSPV_list))
+
+dicts_Bs2hhKS = {}
+string_dict_Bs2hhKS = dict(zip(variable_DTF_list, preamble_BsKSPV_list))
+
+
+
+
+#modify dictionaries to have the right suffix
+for suffix in suffixes_Bd2hhKS:
+    # Create a new dictionary with keys having suffixes
+    new_dict = {f"{key}_{suffix}": val for key, val in string_dict_Bd2hhKS.items()}
+    dicts_Bd2hhKS[suffix] = new_dict
+
+for suffix in suffixes_hhKS:
+#    # Create a new dictionary with keys having suffixes
+    new_dict = {f"{key}_{suffix}": val for key, val in string_dict_hhKS.items()}
+    dicts_hhKS[suffix] = new_dict
+
+#modify dictionaries to have the right suffix
+for suffix in suffixes_Bs2hhKS:
+    # Create a new dictionary with keys having suffixes
+    new_dict = {f"{key}_{suffix}": val for key, val in string_dict_Bs2hhKS.items()}
+    dicts_Bs2hhKS[suffix] = new_dict
+
+
+
+#Bd2hhKS
+
+B0_Bd2KKKS = dtt.B.addTupleTool("LoKi::Hybrid::TupleTool/B0_Bd2KKKS")
+B0_Bd2KKKS.Preambulo = preamble_BdKSPV
+B0_Bd2KKKS.Variables = dicts_Bd2hhKS["Bd2KKKS"]
+
+B0_Bd2pipiKS = dtt_pipiKS.B.addTupleTool("LoKi::Hybrid::TupleTool/B0_Bd2pipiKS")
+B0_Bd2pipiKS.Preambulo=preamble_BdKSPV
+B0_Bd2pipiKS.Variables = dicts_Bd2hhKS["Bd2pipiKS"]
+
+B0_Bd2piKKS = dtt_piKKS.B.addTupleTool("LoKi::Hybrid::TupleTool/B0_Bd2piKKS")
+B0_Bd2piKKS.Preambulo=preamble_BdKSPV
+B0_Bd2piKKS.Variables = dicts_Bd2hhKS["Bd2piKKS"]
+
+B0_Bd2KpiKS = dtt_KpiKS.B.addTupleTool("LoKi::Hybrid::TupleTool/B0_Bd2KpiKS")
+B0_Bd2KpiKS.Preambulo=preamble_BdKSPV
+B0_Bd2KpiKS.Variables = dicts_Bd2hhKS["Bd2KpiKS"]
+
+B0_Bd2pKKS = dtt_pKKS.B.addTupleTool("LoKi::Hybrid::TupleTool/B0_Bd2pKKS")
+B0_Bd2pKKS.Preambulo=preamble_BdKSPV
+B0_Bd2pKKS.Variables = dicts_Bd2hhKS["Bd2pKKS"]
+
+B0_Bd2KpKS = dtt_KpKS.B.addTupleTool("LoKi::Hybrid::TupleTool/B0_Bd2KpKS")
+B0_Bd2KpKS.Preambulo=preamble_BdKSPV
+B0_Bd2KpKS.Variables = dicts_Bd2hhKS["Bd2KpKS"]
+
+B0_Bd2pipKS = dtt_pipKS.B.addTupleTool("LoKi::Hybrid::TupleTool/B0_Bd2pipKS")
+B0_Bd2pipKS.Preambulo = preamble_BdKSPV
+B0_Bd2pipKS.Variables = dicts_Bd2hhKS["Bd2pipKS"]
+
+B0_Bd2ppiKS = dtt_ppiKS.B.addTupleTool("LoKi::Hybrid::TupleTool/B0_Bd2ppiKS")
+B0_Bd2ppiKS.Preambulo = preamble_BdKSPV
+B0_Bd2ppiKS.Variables = dicts_Bd2hhKS["Bd2ppiKS"]
+
+
+#Bd2hhKS
+B0_KKKS = dtt.B.addTupleTool("LoKi::Hybrid::TupleTool/B0_KKKS")
+B0_KKKS.Preambulo = preamble_KSPV
+B0_KKKS.Variables = dicts_hhKS["KKKS"]
+
+B0_pipiKS = dtt_pipiKS.B.addTupleTool("LoKi::Hybrid::TupleTool/B0_pipiKS")
+B0_pipiKS.Preambulo = preamble_KSPV
+B0_pipiKS.Variables = dicts_hhKS["pipiKS"]
+
+B0_piKKS = dtt_piKKS.B.addTupleTool("LoKi::Hybrid::TupleTool/B0_piKKS")
+B0_piKKS.Preambulo = preamble_KSPV
+B0_piKKS.Variables = dicts_hhKS["piKKS"]
+
+B0_KpiKS = dtt_KpiKS.B.addTupleTool("LoKi::Hybrid::TupleTool/B0_KpiKS")
+B0_KpiKS.Preambulo = preamble_KSPV
+B0_KpiKS.Variables = dicts_hhKS["KpiKS"]
+
+B0_pKKS = dtt_pKKS.B.addTupleTool("LoKi::Hybrid::TupleTool/B0_pKKS")
+B0_pKKS.Preambulo = preamble_KSPV
+B0_pKKS.Variables = dicts_hhKS["pKKS"]
+
+B0_KpKS = dtt_KpKS.B.addTupleTool("LoKi::Hybrid::TupleTool/B0_KpKS")
+B0_KpKS.Preambulo = preamble_KSPV
+B0_KpKS.Variables = dicts_hhKS["KpKS"]
+
+B0_pipKS = dtt_pipKS.B.addTupleTool("LoKi::Hybrid::TupleTool/B0_pipKS")
+B0_pipKS.Preambulo = preamble_BdKSPV
+B0_pipKS.Variables = dicts_hhKS["pipKS"]
+
+B0_ppiKS = dtt_ppiKS.B.addTupleTool("LoKi::Hybrid::TupleTool/B0_ppiKS")
+B0_ppiKS.Preambulo = preamble_BdKSPV
+B0_ppiKS.Variables = dicts_hhKS["ppiKS"]
+
+#Bs2KShh variables
+
+B0_Bs2KKKS = dtt.B.addTupleTool("LoKi::Hybrid::TupleTool/B0_Bs2KKKS")
+B0_Bs2KKKS.Preambulo = preamble_BsKSPV
+B0_Bs2KKKS.Variables = dicts_Bs2hhKS["Bs2KKKS"]
+
+B0_Bs2pipiKS = dtt_pipiKS.B.addTupleTool("LoKi::Hybrid::TupleTool/B0_Bs2pipiKS")
+B0_Bs2pipiKS.Preambulo=preamble_BsKSPV
+B0_Bs2pipiKS.Variables = dicts_Bs2hhKS["Bs2pipiKS"]
+
+B0_Bs2piKKS = dtt_piKKS.B.addTupleTool("LoKi::Hybrid::TupleTool/B0_Bs2piKKS")
+B0_Bs2piKKS.Preambulo=preamble_BsKSPV
+B0_Bs2piKKS.Variables = dicts_Bs2hhKS["Bs2piKKS"]
+
+B0_Bs2KpiKS = dtt_KpiKS.B.addTupleTool("LoKi::Hybrid::TupleTool/B0_Bs2KpiKS")
+B0_Bs2KpiKS.Preambulo=preamble_BsKSPV
+B0_Bs2KpiKS.Variables = dicts_Bs2hhKS["Bs2KpiKS"]
+
+B0_Bs2pKKS = dtt_pKKS.B.addTupleTool("LoKi::Hybrid::TupleTool/B0_Bs2pKKS")
+B0_Bs2pKKS.Preambulo=preamble_BsKSPV
+B0_Bs2pKKS.Variables = dicts_Bs2hhKS["Bs2pKKS"]
+
+B0_Bs2KpKS = dtt_KpKS.B.addTupleTool("LoKi::Hybrid::TupleTool/B0_Bs2KpKS")
+B0_Bs2KpKS.Preambulo=preamble_BsKSPV
+B0_Bs2KpKS.Variables = dicts_Bs2hhKS["Bs2KpKS"]
+
+B0_Bs2pipKS = dtt_pipKS.B.addTupleTool("LoKi::Hybrid::TupleTool/B0_Bs2pipKS")
+B0_Bs2pipKS.Preambulo = preamble_BsKSPV
+B0_Bs2pipKS.Variables = dicts_Bs2hhKS["Bs2pipKS"]
+
+B0_Bs2ppiKS = dtt_ppiKS.B.addTupleTool("LoKi::Hybrid::TupleTool/B0_Bs2ppiKS")
+B0_Bs2ppiKS.Preambulo = preamble_BsKSPV
+B0_Bs2ppiKS.Variables = dicts_Bs2hhKS["Bs2ppiKS"]
+
+
+#VTX and CONE ISOLATION from Stripping
+B0_iso = dtt_pipiKS.B.addTupleTool('LoKi::Hybrid::TupleTool/B0_iso')
+KS_coneiso = dtt_pipiKS.B.addTupleTool('LoKi::Hybrid::TupleTool/KS_coneiso')  #attach to KS to me
+
+infoloc_vtxiso = '/Event/{0}/Phys/{1}/VtxIsolationVar_B'.format(stream, line)      #'/Event/Bhadron/Phys/B2KShh_DD_Run2_OS_Line/VtxIsolationVar_B'
+
+B0_iso.Variables = {
+        "VTXISODCHI2ONETRACK"     : "RELINFO('%s','VTXISODCHI2ONETRACK',-13.)"%infoloc_vtxiso,
+        "VTXISODCHI2MASSONETRACK" : "RELINFO('%s','VTXISODCHI2MASSONETRACK',-13.)"%infoloc_vtxiso,
+        "VTXISODCHI2TWOTRACK"     : "RELINFO('%s','VTXISODCHI2TWOTRACK',-13.)"%infoloc_vtxiso,
+        "VTXISODCHI2MASSTWOTRACK" : "RELINFO('%s','VTXISODCHI2MASSTWOTRACK',-13.)"%infoloc_vtxiso,
+        "VTXISONUMVTX"            : "RELINFO('%s','VTXISONUMVTX',-13.)"%infoloc_vtxiso
+}
+
+#cone isolation and asymm from TES location
+#B0_coneiso = dtt_pipiKS.addTupleTool('LoKi::Hybrid::TupleTool/B0_coneiso')
+cone_values = ["10", "15", "17", "20"]
+
+for XX in cone_values:
+
+    infoloc_coneiso = '/Event/{0}/Phys/{1}/ConeVar{2}_B'.format(stream, line, XX)
+    infoloc_coneiso_KS = '/Event/{0}/Phys/{1}/ConeVar{2}_KS'.format(stream, line, XX)
+
+    B0_iso.Variables.update({
+       f"CONEPXASYM_{XX}"    : "RELINFO('%s', 'CONEPXASYM', -13.)"%infoloc_coneiso,
+       f"CONEPYASYM_{XX}"    : "RELINFO('%s', 'CONEPYASYM', -13.)"%infoloc_coneiso,
+       f"CONEPZASYM_{XX}"    : "RELINFO('%s', 'CONEPZASYM', -13.)"%infoloc_coneiso,
+       f"CONEPASYM_{XX}"     : "RELINFO('%s', 'CONEPASYM', -13.)"%infoloc_coneiso,
+       f"CONEPTASYM_{XX}"    : "RELINFO('%s', 'CONEPTASYM', -13.)"%infoloc_coneiso,
+       f"CONEDELTAETA_{XX}"  : "RELINFO('%s', 'CONEDELTAETA', -13.)"%infoloc_coneiso,
+       f"CONEDELTAPHI_{XX}"  : "RELINFO('%s', 'CONEDELTAPHI', -13.)"%infoloc_coneiso,
+
+    })
+
+    KS_coneiso.Variables.update({
+       f"KS_CONEPXASYM_{XX}"    : "RELINFO('%s', 'CONEPXASYM', -13.)"%infoloc_coneiso_KS,
+       f"KS_CONEPYASYM_{XX}"    : "RELINFO('%s', 'CONEPYASYM', -13.)"%infoloc_coneiso_KS,
+       f"KS_CONEPZASYM_{XX}"    : "RELINFO('%s', 'CONEPZASYM', -13.)"%infoloc_coneiso_KS,
+       f"KS_CONEPASYM_{XX}"     : "RELINFO('%s', 'CONEPASYM', -13.)"%infoloc_coneiso_KS,
+       f"KS_CONEPTASYM_{XX}"    : "RELINFO('%s', 'CONEPTASYM', -13.)"%infoloc_coneiso_KS,
+       f"KS_CONEDELTAETA_{XX}"  : "RELINFO('%s', 'CONEDELTAETA', -13.)"%infoloc_coneiso_KS,
+       f"KS_CONEDELTAPHI_{XX}"  : "RELINFO('%s', 'CONEDELTAPHI', -13.)"%infoloc_coneiso_KS,
+
+    })
+
+
+
+#GETTING THE TRIGGER LINES
+#add to Trigger_tool
+triggerList_base = [
+    #L0 TCKsh getL0Channels(0x11741801)
+    "L0MuonDecision",
+    "L0DiMuonDecision",
+    "L0HadronDecision",
+    "L0ElectronDecision",
+    "L0PhotonDecision"
+]
+
+
+trigger_L0_add = []
+trigger_Hlt1_add = []
+trigger_Hlt2_add = []
+
+#year is something that is passed from the Ganga job
+
+if year in ['2015', '2016', '2017', '2018']:
+    trigger_Hlt1_add = [ "Hlt1TrackMVADecision", "Hlt1TwoTrackMVADecision"]
+    trigger_Hlt2_add = ["Hlt2Topo2BodyDecision", "Hlt2Topo3BodyDecision", "Hlt2Topo4BodyDecision"]     #Hlt2 lines TCKsh getHlt2(0x21751801)
+    if year in ['2018', '2017']:
+        trigger_L0_add = ["L0MuonEWDecision"]
+    if year in ['2016', '2015']:
+        trigger_L0_add = ["L0MuonEWDecision",  "L0JetElDecision", "L0JetPhDecision"   ]
+
+if year in ['2012b', '2012a', '2011']:
+    trigger_Hlt1_add = ["Hlt1TrackAllL0Decision"]
+    
+    if year in ['2012b', '2012a']:
+        trigger_Hlt2_add = ["Hlt2Topo2BodyBBDTDecision", "Hlt2Topo3BodyBBDTDecision", "Hlt2Topo4BodyBBDTDecision"]
+    if year in ['2011']:
+        trigger_Hlt2_add = ["Hlt2Topo2BodyBBDTDecision", "Hlt2Topo3BodyBBDTDecision", "Hlt2Topo4BodyBBDTDecision", "Hlt2Topo2BodySimpleDecision", "Hlt2Topo3BodySimpleDecision", "Hlt2Topo4BodySimpleDecision"]
+
+
+triggerList = triggerList_base + trigger_L0_add + trigger_Hlt1_add + trigger_Hlt2_add
+print(triggerList)
+
+Trigger_tool.TriggerList = triggerList      # add these trigger information to trigger tuple tool
+#TISTOS_tool.TriggerList = triggerList       # add these TISTOS to the trigger info
+
+#cose che devono essere associate a una particella
+dtt.B.addTupleTool('TupleToolTISTOS')
+dtt.B.TupleToolTISTOS.VerboseL0 = True
+dtt.B.TupleToolTISTOS.VerboseHlt1 = True
+dtt.B.TupleToolTISTOS.VerboseHlt2 = True
+dtt.B.TupleToolTISTOS.FillL0 = True
+dtt.B.TupleToolTISTOS.FillHlt1 = True
+dtt.B.TupleToolTISTOS.FillHlt2 = True
+dtt.B.TupleToolTISTOS.TriggerList = triggerList
+
+#add Geometry tuple tool in verbose mode
+#I want MINIPCHI2 for charged particles
+dtt.B.addTupleTool('TupleToolGeometry')
+dtt.B.TupleToolGeometry.Verbose= True
+
+dtt.h1.addTupleTool('TupleToolGeometry')
+dtt.h1.TupleToolGeometry.Verbose = True
+dtt.h2.addTupleTool('TupleToolGeometry')
+dtt.h2.TupleToolGeometry.Verbose= True
+dtt.KSpip.addTupleTool('TupleToolGeometry')
+dtt.KSpip.TupleToolGeometry.Verbose = True
+dtt.KSpim.addTupleTool('TupleToolGeometry')
+dtt.KSpim.TupleToolGeometry.Verbose = True
+
+#pipiKS
+dtt_pipiKS.B.addTupleTool('TupleToolTISTOS')
+dtt_pipiKS.B.TupleToolTISTOS.VerboseL0 = True
+dtt_pipiKS.B.TupleToolTISTOS.VerboseHlt1 = True
+dtt_pipiKS.B.TupleToolTISTOS.VerboseHlt2 = True
+dtt_pipiKS.B.TupleToolTISTOS.FillL0 = True
+dtt_pipiKS.B.TupleToolTISTOS.FillHlt1 = True
+dtt_pipiKS.B.TupleToolTISTOS.FillHlt2 = True
+dtt_pipiKS.B.TupleToolTISTOS.TriggerList = triggerList
+
+dtt_pipiKS.B.addTupleTool('TupleToolGeometry')
+dtt_pipiKS.B.TupleToolGeometry.Verbose= True
+dtt_pipiKS.h1.addTupleTool('TupleToolGeometry')
+dtt_pipiKS.h1.TupleToolGeometry.Verbose = True
+dtt_pipiKS.h2.addTupleTool('TupleToolGeometry')
+dtt_pipiKS.h2.TupleToolGeometry.Verbose= True
+dtt_pipiKS.KSpip.addTupleTool('TupleToolGeometry')
+dtt_pipiKS.KSpip.TupleToolGeometry.Verbose = True
+dtt_pipiKS.KSpim.addTupleTool('TupleToolGeometry')
+dtt_pipiKS.KSpim.TupleToolGeometry.Verbose = True
+
+
+#piKKS
+dtt_piKKS.B.addTupleTool('TupleToolTISTOS')
+dtt_piKKS.B.TupleToolTISTOS.VerboseL0 = True
+dtt_piKKS.B.TupleToolTISTOS.VerboseHlt1 = True
+dtt_piKKS.B.TupleToolTISTOS.VerboseHlt2 = True
+dtt_piKKS.B.TupleToolTISTOS.FillL0 = True
+dtt_piKKS.B.TupleToolTISTOS.FillHlt1 = True
+dtt_piKKS.B.TupleToolTISTOS.FillHlt2 = True
+dtt_piKKS.B.TupleToolTISTOS.TriggerList = triggerList
+
+#add Geometry tuple tool in verbose mode
+dtt_piKKS.B.addTupleTool('TupleToolGeometry')
+dtt_piKKS.B.TupleToolGeometry.Verbose= True
+dtt_piKKS.h1.addTupleTool('TupleToolGeometry')
+dtt_piKKS.h1.TupleToolGeometry.Verbose = True
+dtt_piKKS.h2.addTupleTool('TupleToolGeometry')
+dtt_piKKS.h2.TupleToolGeometry.Verbose= True
+dtt_piKKS.KSpip.addTupleTool('TupleToolGeometry')
+dtt_piKKS.KSpip.TupleToolGeometry.Verbose = True
+dtt_piKKS.KSpim.addTupleTool('TupleToolGeometry')
+dtt_piKKS.KSpim.TupleToolGeometry.Verbose = True
+
+
+#KpiKS
+dtt_KpiKS.B.addTupleTool('TupleToolTISTOS')
+dtt_KpiKS.B.TupleToolTISTOS.VerboseL0 = True
+dtt_KpiKS.B.TupleToolTISTOS.VerboseHlt1 = True
+dtt_KpiKS.B.TupleToolTISTOS.VerboseHlt2 = True
+dtt_KpiKS.B.TupleToolTISTOS.FillL0 = True
+dtt_KpiKS.B.TupleToolTISTOS.FillHlt1 = True
+dtt_KpiKS.B.TupleToolTISTOS.FillHlt2 = True
+dtt_KpiKS.B.TupleToolTISTOS.TriggerList = triggerList
+
+#add Geometry tuple tool in verbose mode
+dtt_KpiKS.B.addTupleTool('TupleToolGeometry')
+dtt_KpiKS.B.TupleToolGeometry.Verbose= True
+dtt_KpiKS.h1.addTupleTool('TupleToolGeometry')
+dtt_KpiKS.h1.TupleToolGeometry.Verbose = True
+dtt_KpiKS.h2.addTupleTool('TupleToolGeometry')
+dtt_KpiKS.h2.TupleToolGeometry.Verbose= True
+dtt_KpiKS.KSpip.addTupleTool('TupleToolGeometry')
+dtt_KpiKS.KSpip.TupleToolGeometry.Verbose = True
+dtt_KpiKS.KSpim.addTupleTool('TupleToolGeometry')
+dtt_KpiKS.KSpim.TupleToolGeometry.Verbose = True
+
+
+
+#tupleTool for B tagging
+
+tt_tagging = dtt.addTupleTool("TupleToolTagging")
+tt_tagging.Verbose = True
+tt_tagging.AddMVAFeatureInfo = True # Writes out all MVA features for the final tag
+tt_tagging.AddTagPartsInfo = False  # If True: Writes out all features of all tagging
+                                    # particles used in the selection
+
+btagtool = tt_tagging.addTool(BTaggingTool, name = "MyBTaggingTool")     #BTaggingTool, same as for the other version
+     #adding for 2019 part
+tt_tagging.allConfigurables["ToolSvc.InclusiveTagger"].setProp("ClassifierVersion", "IFT_Bd_v140521")   #line inspired from Thomas
+applyFTTuning(btagtool, tuning_version="Summer2019Optimisation_v1_Run2")   #new tuning version
+tt_tagging.TaggingToolName = btagtool.getFullName()
+
+
+
+
+
+# Configure DaVinci
+
+# add our new selection and the tuple into the sequencer
+seq = GaudiSequencer('MyTupleSeq')
+seq.Members += [selSeq.sequence()]
+seq.Members += [selSeq_piKKS.sequence()]
+seq.Members += [selSeq_KpiKS.sequence()]
+#seq.Members += [selSeq_pipiKS.sequence()]  #commented before
+seq.Members += [selSeq_pipKS.sequence()]
+seq.Members += [selSeq_ppiKS.sequence()]
+seq.Members += [selSeq_pKKS.sequence()]
+seq.Members += [selSeq_KpKS.sequence()]
+
+seq.Members += [dtt]
+seq.Members += [dtt_piKKS]
+seq.Members += [dtt_KpiKS]
+seq.Members += [dtt_pipKS]
+seq.Members += [dtt_ppiKS]
+seq.Members += [dtt_pKKS]
+seq.Members += [dtt_KpKS]
+seq.Members += [dtt_pipiKS]
+#seq.Members += [dtt_standard]
+DaVinci().appendToMainSequence([seq])
+
+
+#DaVinci().InputType = 'DST'
+#DaVinci().TupleFile = 'BdKKKS_2018_Do_DD.root'
+#DaVinci().PrintFreq = 1000
+#DaVinci().DataType = '2018'
+#DaVinci().Simulation = True
+# Only ask for luminosity information when not using simulated data
+#DaVinci().Lumi = not DaVinci().Simulation
+#DaVinci().EvtMax = -1
+#DaVinci().CondDBtag = 'sim-20190430-vc-md100'
+#DaVinci().DDDBtag = 'dddb-20170721-3'
+
+
+
+
-- 
GitLab


From 57e35a27f99756a527eed10f03f7c0cf3c193d2e Mon Sep 17 00:00:00 2001
From: Edoardo Mariani <edoardo.mariani@cern.ch>
Date: Mon, 6 Jan 2025 12:28:30 +0100
Subject: [PATCH 04/18] Add new file

---
 bd2kkks_data/B2hhKS_MC_opt_LL.py | 1037 ++++++++++++++++++++++++++++++
 1 file changed, 1037 insertions(+)
 create mode 100644 bd2kkks_data/B2hhKS_MC_opt_LL.py

diff --git a/bd2kkks_data/B2hhKS_MC_opt_LL.py b/bd2kkks_data/B2hhKS_MC_opt_LL.py
new file mode 100644
index 0000000000..091dbd63e6
--- /dev/null
+++ b/bd2kkks_data/B2hhKS_MC_opt_LL.py
@@ -0,0 +1,1037 @@
+from GaudiConf import IOHelper
+from Configurables import DaVinci, DecayTreeTuple, SubstitutePID
+from PhysSelPython.Wrappers import Selection, SelectionSequence, DataOnDemand
+from DecayTreeTuple.Configuration import *
+
+
+#libraries for flavour tagging
+from Configurables import BTaggingTool
+from FlavourTagging.Tunings import applyTuning as applyFTTuning
+
+#extract the parameters
+DaVinci().EvtMax = -1
+year = DaVinci().DataType    #should be a string
+if year in ["2015", "2016", "2017", "2018"]:
+    line = 'B2KShh_LL_Run2_OS_Line'             #DD and LL still to parametrize
+else:
+    line = 'B2KShh_LL_Run1_OS_Line'
+
+format = DaVinci().InputType   #DST or MDST
+
+
+# Stream and stripping line we want to use
+stream = 'B2KSHH.Strip'     #B2KSHH.Strip
+tesLoc = '/Event/{0}/Phys/{1}/Particles'.format(stream, line)
+
+
+# get the selection(s) created by the stripping
+strippingSels = [DataOnDemand(Location=tesLoc)]
+
+# configure an algorithm to substitute the two pions in the B0 decays with two kaons
+
+subs = SubstitutePID(
+    'MakepiK',
+    Code= "DECTREE('B0 -> pi+ pi- KS0')",
+   # note that SubstitutePID can't handle automatic CC
+    Substitutions = {
+        'B0 -> ^pi+ pi- KS0': 'K+'}
+)
+subsB = SubstitutePID(
+    'MakeKK',
+    Code= "DECTREE('B0 -> K+ pi- KS0')",
+   # note that SubstitutePID can't handle automatic CC
+    Substitutions = {
+        'B0 -> K+ ^pi- KS0': 'K-'}
+)
+
+
+#second type fo substitution
+# B0 -> pi+ K- KS
+subs_pi_minus_K = SubstitutePID(
+	'Make_piminus_K',
+	Code= "DECTREE('B0 -> pi+ pi- KS0')",
+	Substitutions={
+		 'B0 -> pi+ ^pi- KS0': 'K-'}
+)
+
+
+# B0 -> K+ pi- KS
+subs_pi_plus_K = SubstitutePID(
+        'Make_piplus_K',
+        Code= "DECTREE('B0 -> pi+ pi- KS0')",
+        Substitutions={
+                 'B0 -> ^pi+ pi- KS0': 'K+'}
+)
+
+
+# B0 -> pi+ p- KS
+subs_pipKS = SubstitutePID(
+        'Make_piminus_p',
+        Code= "DECTREE('B0 -> pi+ pi- KS0')",
+        Substitutions={
+                 'B0 -> pi+ ^pi- KS0': 'p~-'}
+)
+
+
+# B0 -> p pi- KS
+subs_ppiKS = SubstitutePID(
+        'Make_piplus_p',
+        Code= "DECTREE('B0 -> pi+ pi- KS0')",
+        Substitutions={
+                 'B0 -> ^pi+ pi- KS0': 'p+'}
+)
+
+
+
+
+#B0 -> p+ K- KS0
+subs_pi_plus_p = SubstitutePID(
+        'Make_pi_plus_p',
+        Code = "DECTREE('B0 -> pi+ K- KS0')",
+        Substitutions={
+                'B0 -> ^pi+ K- KS0': 'p+'}
+)
+
+#B0-> K+ p- KS0
+subs_pi_minus_p = SubstitutePID(
+        'Make_pi_minus_p',
+        Code = "DECTREE('B0 -> K+ pi- KS0')",
+        Substitutions={
+               'B0 -> K+ ^pi- KS0': 'p~-'}
+)
+	
+
+#KKKS
+# create a selection using the substitution algorithm
+selSub = Selection(
+    'selSubA',
+    Algorithm=subs,
+    RequiredSelections=strippingSels
+)
+selSubB = Selection(
+    'selSubB',
+    Algorithm=subsB,
+    RequiredSelections=[selSub]
+)
+
+#other mass hypothesis
+#second type of selection using substitution algo
+selSub_pi_minus_K = Selection(
+	'selSub_pi_minus_K',
+	Algorithm=subs_pi_minus_K,
+	RequiredSelections=strippingSels
+)
+
+selSub_pi_plus_K = Selection(
+        'selSub_pi_plus_K',
+        Algorithm=subs_pi_plus_K,
+        RequiredSelections=strippingSels
+)
+
+
+selSub_pipKS = Selection(
+        'selSub_pipKS',
+        Algorithm=subs_pipKS,
+        RequiredSelections=strippingSels
+)
+
+selSub_ppiKS = Selection(
+        'selSub_ppiKS',
+        Algorithm=subs_ppiKS,
+        RequiredSelections=strippingSels
+)
+
+#double subs
+selSub_pi_plus_p = Selection(
+	'selSub_pi_plus_p',
+	Algorithm= subs_pi_plus_p,
+	RequiredSelections=[selSub_pi_minus_K]
+)
+
+selSub_pi_minus_p = Selection(
+        'selSub_pi_minus_p',
+        Algorithm= subs_pi_minus_p,
+        RequiredSelections=[selSub_pi_plus_K]
+)
+
+
+# in order to add the selection into the program make a sequence
+selSeq = SelectionSequence('SelSeq', TopSelection=selSubB)
+
+selSeq_piKKS = SelectionSequence('SelSeq1', TopSelection= selSub_pi_minus_K)
+selSeq_KpiKS = SelectionSequence('SelSeq2', TopSelection= selSub_pi_plus_K)
+#selSeq_pipiKS= SelectionSequence('SelSeq3', TopSelection = selSub_2pi_2K)   #commented before
+selSeq_pipKS = SelectionSequence('SelSeq4', TopSelection = selSub_pipKS)
+selSeq_ppiKS = SelectionSequence('SelSeq5', TopSelection = selSub_ppiKS)
+selSeq_pKKS = SelectionSequence('SelSeq6', TopSelection= selSub_pi_plus_p)
+selSeq_KpKS = SelectionSequence('SelSeq7', TopSelection = selSub_pi_minus_p)
+
+
+# Create an ntuple
+dtt = DecayTreeTuple('Bd2KKKS')
+dtt.Inputs = [selSeq.outputLocation()]
+#dtt.Decay = 'B0 -> ^K+ ^K- ^KS0'
+dtt.Decay = 'B0 -> ^K+ ^K- ^(KS0 -> ^pi+ ^pi-)'
+
+dtt_piKKS = DecayTreeTuple('Bd2piKKS')
+dtt_piKKS.Inputs = [selSeq_piKKS.outputLocation()]
+dtt_piKKS.Decay = 'B0 -> ^pi+ ^K- ^(KS0 -> ^pi+ ^pi-)'
+
+dtt_KpiKS = DecayTreeTuple('Bd2KpiKS')
+dtt_KpiKS.Inputs = [selSeq_KpiKS.outputLocation()]
+dtt_KpiKS.Decay = 'B0 -> ^K+ ^pi- ^(KS0 -> ^pi+ ^pi-)'
+
+dtt_pipKS = DecayTreeTuple('Bd2pipKS')
+dtt_pipKS.Inputs = [selSeq_pipKS.outputLocation()]
+dtt_pipKS.Decay = 'B0 -> ^pi+ ^p~- ^(KS0 -> ^pi+ ^pi-)'
+
+dtt_ppiKS = DecayTreeTuple('Bd2ppiKS')
+dtt_ppiKS.Inputs = [selSeq_ppiKS.outputLocation()]
+dtt_ppiKS.Decay = 'B0 -> ^p+ ^pi- ^(KS0 -> ^pi+ ^pi-)'
+
+
+dtt_pKKS = DecayTreeTuple('Bd2pKKS')
+dtt_pKKS.Inputs = [selSeq_pKKS.outputLocation()]
+dtt_pKKS.Decay = 'B0 -> ^p+ ^K- ^(KS0 -> ^pi+ ^pi-)'
+
+dtt_KpKS = DecayTreeTuple('Bd2KpKS')
+dtt_KpKS.Inputs	= [selSeq_KpKS.outputLocation()]
+dtt_KpKS.Decay = 'B0 -> ^K+ ^p~- ^(KS0 -> ^pi+ ^pi-)'
+
+
+#the standard one, directly from the Stripping line
+#Tutte parti tolte è perchè faccio così in modo più efficiente
+
+dtt_pipiKS = DecayTreeTuple('Bd2pipiKS')
+dtt_pipiKS.Inputs =  [tesLoc]                        #dtt_pipiKS.Inputs =  ['/Event/{0}/Phys/{1}/Particles'.format(stream, line)]      
+dtt_pipiKS.Decay = 'B0 -> ^pi+ ^pi- ^(KS0 -> ^pi+ ^pi-)'
+
+
+
+
+#DEFINITION OF BRANCHES
+
+dtt.addBranches({
+        'B': 'B0 -> K+ K- (KS0-> pi+ pi-)',
+        'h1' : 'B0 -> ^K+ K- (KS0 -> pi+ pi-)',
+        'h2': 'B0 -> K+ ^K- (KS0 -> pi+ pi-)',
+        'KS': 'B0 -> K+ K- ^(KS0 -> pi+ pi-)',
+        'KSpip': 'B0 -> K+ K- (KS0 -> ^pi+ pi-)',	 #pi+ dauther of the KS
+        'KSpim': 'B0 -> K+ K- (KS0 -> pi+ ^pi-)'         #pi- daughter of the KS
+        })
+
+
+dtt_piKKS.addBranches({
+	'B': 'B0 -> pi+ K- (KS0 -> pi+ pi-)',
+	'h1': 'B0 -> ^pi+ K- (KS0 -> pi+ pi-)',
+	'h2': 'B0 -> pi+ ^K- (KS0 -> pi+ pi-)',
+	'KS': 'B0 -> pi+ K- ^(KS0 -> pi+ pi-)',
+    'KSpip': 'B0 -> pi+ K- (KS0 -> ^pi+ pi-)',
+    'KSpim': 'B0 -> pi+ K- (KS0 -> pi+ ^pi-)'
+})
+
+
+dtt_KpiKS.addBranches({
+    'B': 'B0 -> K+ pi- (KS0 -> pi+ pi-)',
+    'h1': 'B0 -> ^K+ pi- (KS0 -> pi+ pi-)',
+    'h2': 'B0 -> K+ ^pi- (KS0 -> pi+ pi-)',
+    'KS': 'B0 -> K+ pi- ^(KS0 -> pi+ pi-)',
+    'KSpip': 'B0 -> K+ pi- (KS0  -> ^pi+ pi-)',
+    'KSpim': 'B0 -> K+ pi- (KS0 -> pi+ ^pi-)'
+
+})
+
+
+dtt_pipiKS.addBranches({
+	'B': 'B0 -> pi+ pi- (KS0 -> pi+ pi-)',
+	'h1': 'B0 -> ^pi+ pi- (KS0 -> pi+ pi-)',
+	'h2': 'B0 -> pi+ ^pi- (KS0 -> pi+ pi-)',
+	'KS': 'B0 -> pi+ pi- ^(KS0 -> pi+ pi-)',
+    'KSpip': 'B0 -> pi+ pi- (KS0 -> ^pi+ pi-)',
+    'KSpim': 'B0 -> pi+ pi- (KS0 -> pi+ ^pi-)'
+})
+
+
+dtt_pipKS.addBranches({
+    'B': 'B0 -> pi+ p~- (KS0 -> pi+ pi-)',
+    'h1': 'B0 -> ^pi+ p~- (KS0 -> pi+ pi-)',
+    'h2': 'B0 -> pi+ ^p~- (KS0 -> pi+ pi-)',
+    'KS': 'B0 -> pi+ p~- ^(KS0 -> pi+ pi-)',
+    'KSpip': 'B0 -> pi+ p~- (KS0 -> ^pi+ pi-)',
+    'KSpim': 'B0 -> pi+ p~- (KS0 -> pi+ ^pi-)'
+})
+
+
+
+dtt_ppiKS.addBranches({
+    'B': 'B0 -> p+ pi- (KS0 -> pi+ pi-)',
+    'h1': 'B0 -> ^p+ pi- (KS0 -> pi+ pi-)',
+    'h2': 'B0 -> p+ ^pi- (KS0 -> pi+ pi-)',
+    'KS': 'B0 -> p+ pi- ^(KS0 -> pi+ pi-)',
+    'KSpip': 'B0 -> p+ pi- (KS0 -> ^pi+ pi-)',
+    'KSpim': 'B0 -> p+ pi- (KS0 -> pi+ ^pi-)'
+})
+
+dtt_pKKS.addBranches({
+    'B': 'B0 -> p+ K- (KS0 -> pi+ pi-)',
+    'h1': 'B0 -> ^p+ K- (KS0 -> pi+ pi-)',
+    'h2': 'B0 -> p+ ^K- (KS0 -> pi+ pi-)',
+    'KS': 'B0 -> p+ K- ^(KS0 -> pi+ pi-)',
+    'KSpip': 'B0 -> p+ K- (KS0 -> ^pi+ pi-)',
+    'KSpim': 'B0 -> p+ K- (KS0 -> pi+ ^pi-)'
+})
+
+dtt_KpKS.addBranches({
+    'B': 'B0 -> K+ p~- (KS0 -> pi+ pi-)',
+    'h1': 'B0 -> ^K+ p~- (KS0 -> pi+ pi-)',
+    'h2': 'B0 -> K+ ^p~- (KS0 -> pi+ pi-)',
+    'KS': 'B0 -> K+ p~- ^(KS0 -> pi+ pi-)',
+    'KSpip': 'B0 -> K+ p~- (KS0 -> ^pi+ pi-)',
+    'KSpim': 'B0 -> K+ p~- (KS0 -> pi+ ^pi-)'
+})
+
+#BACK TO THE MAIN dtt
+
+track_tool = dtt.addTupleTool('TupleToolTrackInfo')
+Ntracks_tool = dtt.addTupleTool('TupleToolRecoStats')   #to add nTracks variables
+time_tool = dtt.B.addTupleTool('TupleToolPropertime')   #add decay time information branch
+Trigger_tool = dtt.addTupleTool('TupleToolTrigger')
+Trigger_tool.Verbose =True    #necessario per far stampare tutti i tipi di trigger che mi servonos
+TRUEMC_tool= dtt.addTupleTool('TupleToolMCTruth')
+
+
+track_tool_pipiKS = dtt_pipiKS.addTupleTool('TupleToolTrackInfo')  #to have the TRACK info also on the pipiKS of stripping
+Ntracks_tool_pipiKS = dtt_pipiKS.addTupleTool('TupleToolRecoStats')   #to add nTracks variables
+time_tool_pipiKS = dtt_pipiKS.B.addTupleTool('TupleToolPropertime')   #add decay time information branch
+Trigger_tool_pipiKS = dtt_pipiKS.addTupleTool('TupleToolTrigger')
+Trigger_tool_pipiKS.Verbose =True    #necessario per far stampare tutti i tipi di trigger che mi servonos
+TRUEMC_tool_pipiKS= dtt_pipiKS.addTupleTool('TupleToolMCTruth')
+
+track_tool_piKKS = dtt_piKKS.addTupleTool('TupleToolTrackInfo')  #to have the TRACK info also on the pipiKS of stripping
+Ntracks_tool_piKKS = dtt_piKKS.addTupleTool('TupleToolRecoStats')   #to add nTracks variables
+time_tool_piKKS = dtt_piKKS.B.addTupleTool('TupleToolPropertime')   #add decay time information branch
+Trigger_tool_piKKS = dtt_piKKS.addTupleTool('TupleToolTrigger')
+Trigger_tool_piKKS.Verbose =True    #necessario per far stampare tutti i tipi di trigger che mi servonos
+TRUEMC_tool_piKKS= dtt_piKKS.addTupleTool('TupleToolMCTruth')
+
+
+track_tool_KpiKS = dtt_KpiKS.addTupleTool('TupleToolTrackInfo')  #to have the TRACK info also on the pipiKS of stripping
+Ntracks_tool_KpiKS = dtt_KpiKS.addTupleTool('TupleToolRecoStats')   #to add nTracks variables
+time_tool_KpiKS = dtt_KpiKS.B.addTupleTool('TupleToolPropertime')   #add decay time information branch
+Trigger_tool_KpiKS = dtt_KpiKS.addTupleTool('TupleToolTrigger')
+Trigger_tool_KpiKS.Verbose =True    #necessario per far stampare tutti i tipi di trigger che mi servonos
+TRUEMC_tool_KpiKS= dtt_KpiKS.addTupleTool('TupleToolMCTruth')
+
+
+#GETTING VARIABLES WITH LOKI FUNCTORS
+#I use LoKi for ETA as it was not present
+
+#now I have put the pipiKS dtt instead of the standard one (dtt)
+B0_hybrid = dtt.addTupleTool('LoKi::Hybrid::TupleTool/LoKi_B0')
+B0_hybrid.Variables = {
+        'ETA': 'ETA'
+}
+
+B0_hybrid_pipiKS = dtt_pipiKS.addTupleTool('LoKi::Hybrid::TupleTool/LoKi_B0')
+B0_hybrid_pipiKS.Variables = {
+        'ETA': 'ETA'
+}
+
+B0_hybrid_piKKS = dtt_piKKS.addTupleTool('LoKi::Hybrid::TupleTool/LoKi_B0')
+B0_hybrid_piKKS.Variables = {
+        'ETA': 'ETA'
+}
+
+B0_hybrid_KpiKS = dtt_KpiKS.addTupleTool('LoKi::Hybrid::TupleTool/LoKi_B0')
+B0_hybrid_KpiKS.Variables = {
+        'ETA': 'ETA'
+}
+
+
+#DTF variables
+
+KSPV_DTF = dtt.B.addTupleTool('TupleToolDecayTreeFitter/KSPV')   #KSPV
+dtt.B.KSPV.constrainToOriginVertex = True
+dtt.B.KSPV.Verbose=True    #adds variables for the daughters also (KS0)
+dtt.B.KSPV.daughtersToConstrain = ['KS0']
+
+#Constrain only on KS seems to be useless
+#constrain B mass, KS mass, PV : variable useful for MC
+
+BdKSPV_DTF =dtt.B.addTupleTool('TupleToolDecayTreeFitter/BdKSPV')  #BdKSPV
+dtt.B.BdKSPV.constrainToOriginVertex = True
+dtt.B.BdKSPV.Verbose=True
+dtt.B.BdKSPV.daughtersToConstrain = ['B0','KS0']
+
+BsKSPV_DTF =dtt.B.addTupleTool('TupleToolDecayTreeFitter/BsKSPV')   #BsKSPV
+dtt.B.BsKSPV.constrainToOriginVertex = True
+dtt.B.BsKSPV.Verbose=True
+dtt.B.BsKSPV.daughtersToConstrain = ['B_s0','KS0']
+dtt.B.BsKSPV.Substitutions = {
+    '^(B0 -> K+ K- KS0)': 'B_s0',
+    '^(B~0 -> K+ K- KS0)': 'B_s~0'
+}
+
+
+
+#DTF for pipiKS branch
+KSPV_DTF_pipiKS = dtt_pipiKS.B.addTupleTool('TupleToolDecayTreeFitter/KSPV')
+dtt_pipiKS.B.KSPV.constrainToOriginVertex = True
+dtt_pipiKS.B.KSPV.Verbose=True
+dtt_pipiKS.B.KSPV.daughtersToConstrain = ['KS0']
+
+BdKSPV_DTF_pipiKS =dtt_pipiKS.B.addTupleTool('TupleToolDecayTreeFitter/BdKSPV')
+dtt_pipiKS.B.BdKSPV.constrainToOriginVertex = False
+dtt_pipiKS.B.BdKSPV.Verbose=True
+dtt_pipiKS.B.BdKSPV.daughtersToConstrain = ['B0','KS0']
+
+BsKSPV_DTF_pipiKS =dtt_pipiKS.B.addTupleTool('TupleToolDecayTreeFitter/BsKSPV')
+dtt_pipiKS.B.BsKSPV.constrainToOriginVertex = False
+dtt_pipiKS.B.BsKSPV.Verbose=True
+dtt_pipiKS.B.BsKSPV.daughtersToConstrain = ['B_s0','KS0']
+dtt_pipiKS.B.BsKSPV.Substitutions = {
+    '^(B0 -> pi+ pi- KS0)': 'B_s0',
+    '^(B~0 -> pi+ pi- KS0)': 'B_s~0'
+}
+
+
+#DTF for piKKS branch
+KSPV_DTF_piKKS = dtt_piKKS.B.addTupleTool('TupleToolDecayTreeFitter/KSPV')
+dtt_piKKS.B.KSPV.constrainToOriginVertex = True
+dtt_piKKS.B.KSPV.Verbose=True
+dtt_piKKS.B.KSPV.daughtersToConstrain = ['KS0']
+
+BdKSPV_DTF_piKKS =dtt_piKKS.B.addTupleTool('TupleToolDecayTreeFitter/BdKSPV')
+dtt_piKKS.B.BdKSPV.constrainToOriginVertex = False
+dtt_piKKS.B.BdKSPV.Verbose=True
+dtt_piKKS.B.BdKSPV.daughtersToConstrain = ['B0','KS0']
+
+BsKSPV_DTF_piKKS =dtt_piKKS.B.addTupleTool('TupleToolDecayTreeFitter/BsKSPV')
+dtt_piKKS.B.BsKSPV.constrainToOriginVertex = False
+dtt_piKKS.B.BsKSPV.Verbose=True
+dtt_piKKS.B.BsKSPV.daughtersToConstrain = ['B_s0','KS0']
+dtt_piKKS.B.BsKSPV.Substitutions = {
+    '^(B0 -> pi+ K- KS0)': 'B_s0',
+    '^(B~0 -> pi+ K- KS0)': 'B_s~0'
+}
+
+
+#DTF for KpiKS branch
+KSPV_DTF_KpiKS = dtt_KpiKS.B.addTupleTool('TupleToolDecayTreeFitter/KSPV')
+dtt_KpiKS.B.KSPV.constrainToOriginVertex = True
+dtt_KpiKS.B.KSPV.Verbose=True
+dtt_KpiKS.B.KSPV.daughtersToConstrain = ['KS0']
+
+BdKSPV_DTF_KpiKS =dtt_KpiKS.B.addTupleTool('TupleToolDecayTreeFitter/BdKSPV')
+dtt_KpiKS.B.BdKSPV.constrainToOriginVertex = False
+dtt_KpiKS.B.BdKSPV.Verbose=True
+dtt_KpiKS.B.BdKSPV.daughtersToConstrain = ['B0','KS0']
+
+BsKSPV_DTF_KpiKS =dtt_KpiKS.B.addTupleTool('TupleToolDecayTreeFitter/BsKSPV')
+dtt_KpiKS.B.BsKSPV.constrainToOriginVertex = False
+dtt_KpiKS.B.BsKSPV.Verbose=True
+dtt_KpiKS.B.BsKSPV.daughtersToConstrain = ['B_s0','KS0']
+dtt_KpiKS.B.BsKSPV.Substitutions = {
+    '^(B0 -> K+ pi- KS0)': 'B_s0',
+    '^(B~0 -> K+ pi- KS0)': 'B_s~0'
+}
+
+
+#DTF for pKKS branch
+KSPV_DTF_pKKS = dtt_pKKS.B.addTupleTool('TupleToolDecayTreeFitter/KSPV')
+dtt_pKKS.B.KSPV.constrainToOriginVertex = True
+dtt_pKKS.B.KSPV.Verbose=True
+dtt_pKKS.B.KSPV.daughtersToConstrain = ['KS0']
+
+BdKSPV_DTF_pKKS =dtt_pKKS.B.addTupleTool('TupleToolDecayTreeFitter/BdKSPV')
+dtt_pKKS.B.BdKSPV.constrainToOriginVertex = False
+dtt_pKKS.B.BdKSPV.Verbose=True
+dtt_pKKS.B.BdKSPV.daughtersToConstrain = ['B0','KS0']
+
+BsKSPV_DTF_pKKS =dtt_pKKS.B.addTupleTool('TupleToolDecayTreeFitter/BsKSPV')
+dtt_pKKS.B.BsKSPV.constrainToOriginVertex = False
+dtt_pKKS.B.BsKSPV.Verbose=True
+dtt_pKKS.B.BsKSPV.daughtersToConstrain = ['B_s0','KS0']
+dtt_pKKS.B.BsKSPV.Substitutions = {
+    '^(B0 -> p+ K- KS0)': 'B_s0',
+    '^(B~0 -> p+ K- KS0)': 'B_s~0'
+}
+
+#DTF for KpKS branch
+KSPV_DTF_KpKS = dtt_KpKS.B.addTupleTool('TupleToolDecayTreeFitter/KSPV')
+dtt_KpKS.B.KSPV.constrainToOriginVertex = True
+dtt_KpKS.B.KSPV.Verbose=True
+dtt_KpKS.B.KSPV.daughtersToConstrain = ['KS0']
+
+BdKSPV_DTF_KpKS =dtt_KpKS.B.addTupleTool('TupleToolDecayTreeFitter/BdKSPV')
+dtt_KpKS.B.BdKSPV.constrainToOriginVertex = False
+dtt_KpKS.B.BdKSPV.Verbose=True
+dtt_KpKS.B.BdKSPV.daughtersToConstrain = ['B0','KS0']
+
+BsKSPV_DTF_KpKS =dtt_KpKS.B.addTupleTool('TupleToolDecayTreeFitter/BsKSPV')
+dtt_KpKS.B.BsKSPV.constrainToOriginVertex = False
+dtt_KpKS.B.BsKSPV.Verbose=True
+dtt_KpKS.B.BsKSPV.daughtersToConstrain = ['B_s0','KS0']
+dtt_KpKS.B.BsKSPV.Substitutions = {
+    '^(B0 -> K+ p~- KS0)': 'B_s0',
+    '^(B~0 -> K+ p~- KS0)': 'B_s~0'
+}
+
+
+#DTF for pipKS branch
+KSPV_DTF_pipKS = dtt_pipKS.B.addTupleTool('TupleToolDecayTreeFitter/KSPV')
+dtt_pipKS.B.KSPV.constrainToOriginVertex = True
+dtt_pipKS.B.KSPV.Verbose=True
+dtt_pipKS.B.KSPV.daughtersToConstrain = ['KS0']
+
+BdKSPV_DTF_pipKS =dtt_pipKS.B.addTupleTool('TupleToolDecayTreeFitter/BdKSPV')
+dtt_pipKS.B.BdKSPV.constrainToOriginVertex = False
+dtt_pipKS.B.BdKSPV.Verbose=True
+dtt_pipKS.B.BdKSPV.daughtersToConstrain = ['B0','KS0']
+
+BsKSPV_DTF_pipKS =dtt_pipKS.B.addTupleTool('TupleToolDecayTreeFitter/BsKSPV')
+dtt_pipKS.B.BsKSPV.constrainToOriginVertex = False
+dtt_pipKS.B.BsKSPV.Verbose=True
+dtt_pipKS.B.BsKSPV.daughtersToConstrain = ['B_s0','KS0']
+dtt_pipKS.B.BsKSPV.Substitutions = {
+    '^(B0 -> pi+ p~- KS0)': 'B_s0',
+    '^(B~0 -> pi+ p~- KS0)': 'B_s~0'
+}
+
+#DTF for ppiKS branch
+KSPV_DTF_ppiKS = dtt_ppiKS.B.addTupleTool('TupleToolDecayTreeFitter/KSPV')
+dtt_ppiKS.B.KSPV.constrainToOriginVertex = True
+dtt_ppiKS.B.KSPV.Verbose=True
+dtt_ppiKS.B.KSPV.daughtersToConstrain = ['KS0']
+
+BdKSPV_DTF_ppiKS =dtt_ppiKS.B.addTupleTool('TupleToolDecayTreeFitter/BdKSPV')
+dtt_ppiKS.B.BdKSPV.constrainToOriginVertex = False
+dtt_ppiKS.B.BdKSPV.Verbose=True
+dtt_ppiKS.B.BdKSPV.daughtersToConstrain = ['B0','KS0']
+
+BsKSPV_DTF_ppiKS =dtt_ppiKS.B.addTupleTool('TupleToolDecayTreeFitter/BsKSPV')
+dtt_ppiKS.B.BsKSPV.constrainToOriginVertex = False
+dtt_ppiKS.B.BsKSPV.Verbose=True
+dtt_ppiKS.B.BsKSPV.daughtersToConstrain = ['B_s0','KS0']
+dtt_ppiKS.B.BsKSPV.Substitutions = {
+    '^(B0 -> p+ pi- KS0)': 'B_s0',
+    '^(B~0 -> p+ pi- KS0)': 'B_s~0'
+}
+
+
+
+
+#Way I am retrieving DecayTreeFitter variables for just-B0-mass-constraints
+#preamble common to all the branches
+
+preamble_BdKSPV = [   #only LoKi functors where i perform some operations
+    
+    "M_BdKSPV = DTF_FUN(M, True, strings(['B0', 'KS0']))",
+    "P_BdKSPV = DTF_FUN(P, True, strings(['B0', 'KS0']))",
+    "PT_BdKSPV = DTF_FUN(PT, True, strings(['B0', 'KS0']))",
+    "PX_BdKSPV = DTF_FUN(PX, True, strings(['B0', 'KS0']))",
+    "PY_BdKSPV = DTF_FUN(PY, True, strings(['B0', 'KS0']))",
+    "PZ_BdKSPV = DTF_FUN(PZ, True, strings(['B0', 'KS0']))",
+    "PE_BdKSPV = DTF_FUN(E, True, strings(['B0', 'KS0']))",
+    
+    "h1_M_BdKSPV = DTF_FUN(CHILD(M,1), True, strings(['B0', 'KS0']))",
+    "h1_P_BdKSPV = DTF_FUN(CHILD(P,1), True, strings(['B0', 'KS0']))",
+    "h1_PX_BdKSPV = DTF_FUN(CHILD(PX,1), True, strings(['B0', 'KS0']))",
+    "h1_PY_BdKSPV = DTF_FUN(CHILD(PY,1), True, strings(['B0', 'KS0']))",
+    "h1_PZ_BdKSPV = DTF_FUN(CHILD(PZ,1), True, strings(['B0', 'KS0']))",
+    "h1_PE_BdKSPV = DTF_FUN(CHILD(E,1), True, strings(['B0', 'KS0']))",
+    
+    "h2_M_BdKSPV = DTF_FUN(CHILD(M,2), True, strings(['B0', 'KS0']))",
+    "h2_P_BdKSPV = DTF_FUN(CHILD(P,2), True, strings(['B0', 'KS0']))",
+    "h2_PX_BdKSPV = DTF_FUN(CHILD(PX,2), True, strings(['B0', 'KS0']))",
+    "h2_PY_BdKSPV = DTF_FUN(CHILD(PY,2), True, strings(['B0', 'KS0']))",
+    "h2_PZ_BdKSPV = DTF_FUN(CHILD(PZ,2), True, strings(['B0', 'KS0']))",
+    "h2_PE_BdKSPV = DTF_FUN(CHILD(E,2), True, strings(['B0', 'KS0']))",
+    
+    "KS_M_BdKSPV = DTF_FUN(CHILD(M,3), True, strings(['B0', 'KS0']))",
+    "KS_P_BdKSPV = DTF_FUN(CHILD(P,3), True, strings(['B0', 'KS0']))",
+    "KS_PX_BdKSPV = DTF_FUN(CHILD(PX,3), True, strings(['B0', 'KS0']))",
+    "KS_PY_BdKSPV = DTF_FUN(CHILD(PY,3), True, strings(['B0', 'KS0']))",
+    "KS_PZ_BdKSPV = DTF_FUN(CHILD(PZ,3), True, strings(['B0', 'KS0']))",
+    "KS_PE_BdKSPV = DTF_FUN(CHILD(E,3), True, strings(['B0', 'KS0']))",
+    
+    "M12_BdKSPV = DTF_FUN(M12, True, strings(['B0', 'KS0']))**2",
+    "M13_BdKSPV = DTF_FUN(M13,True, strings(['B0', 'KS0']))**2",
+    "M23_BdKSPV = DTF_FUN(M23, True, strings(['B0', 'KS0']))**2",
+]
+
+preamble_KSPV = [
+    
+    "M_KSPV = DTF_FUN(M, True, 'KS0')",
+    "P_KSPV = DTF_FUN(P, True, 'KS0')",
+    "PT_KSPV = DTF_FUN(PT, True, 'KS0')",
+    "PX_KSPV = DTF_FUN(PX, True, 'KS0')",
+    "PY_KSPV = DTF_FUN(PY, True, 'KS0')",
+    "PZ_KSPV = DTF_FUN(PZ, True, 'KS0')",
+    "PE_KSPV = DTF_FUN(E, True, 'KS0')",
+    
+    "h1_M_KSPV = DTF_FUN(CHILD(M,1), True, 'KS0')",
+    "h1_P_KSPV = DTF_FUN(CHILD(P,1), True, 'KS0')",
+    "h1_PX_KSPV = DTF_FUN(CHILD(PX,1), True, 'KS0')",
+    "h1_PY_KSPV = DTF_FUN(CHILD(PY,1), True, 'KS0')",
+    "h1_PZ_KSPV = DTF_FUN(CHILD(PZ,1), True, 'KS0')",
+    "h1_PE_KSPV = DTF_FUN(CHILD(E,1), True, 'KS0')",
+    
+    "h2_M_KSPV = DTF_FUN(CHILD(M,2), True, 'KS0')",
+    "h2_P_KSPV = DTF_FUN(CHILD(P,2), True, 'KS0')",
+    "h2_PX_KSPV = DTF_FUN(CHILD(PX,2), True, 'KS0')",
+    "h2_PY_KSPV = DTF_FUN(CHILD(PY,2), True, 'KS0')",
+    "h2_PZ_KSPV = DTF_FUN(CHILD(PZ,2), True, 'KS0')",
+    "h2_PE_KSPV = DTF_FUN(CHILD(E,2), True, 'KS0')",
+    
+    "KS_M_KSPV = DTF_FUN(CHILD(M,3), True, 'KS0')",
+    "KS_P_KSPV = DTF_FUN(CHILD(P,3), True, 'KS0')",
+    "KS_PX_KSPV = DTF_FUN(CHILD(PX,3), True, 'KS0')",
+    "KS_PY_KSPV = DTF_FUN(CHILD(PY,3), True, 'KS0')",
+    "KS_PZ_KSPV = DTF_FUN(CHILD(PZ,3), True, 'KS0')",
+    "KS_PE_KSPV = DTF_FUN(CHILD(E,3), True, 'KS0')",
+    
+    "M12_KSPV = DTF_FUN(M12, True, 'KS0')**2",
+    "M13_KSPV = DTF_FUN(M13, True, 'KS0')**2",
+    "M23_KSPV = DTF_FUN(M23, True, 'KS0')**2",
+]
+
+preamble_BsKSPV = [   #only LoKi functors where i perform some operations
+    "masses = LoKi.AuxDTFBase.MASSES" ,"constr = masses()" ,"constr ['B0'] = 5.36692 * GeV ",
+    
+    "M_BsKSPV = DTF_FUN(M, True, strings(['B0', 'KS0']), constr)",
+    "P_BsKSPV = DTF_FUN(P, True, strings(['B0', 'KS0']), constr)",
+    "PT_BsKSPV = DTF_FUN(PT, True, strings(['B0', 'KS0']), constr)",
+    "PX_BsKSPV = DTF_FUN(PX, True, strings(['B0', 'KS0']), constr)",
+    "PY_BsKSPV = DTF_FUN(PY, True, strings(['B0', 'KS0']), constr)",
+    "PZ_BsKSPV = DTF_FUN(PZ, True, strings(['B0', 'KS0']), constr)",
+    "PE_BsKSPV = DTF_FUN(E, True, strings(['B0', 'KS0']), constr )",
+    
+    "h1_M_BsKSPV = DTF_FUN(CHILD(M,1), True, strings(['B0', 'KS0']), constr)",
+    "h1_P_BsKSPV = DTF_FUN(CHILD(P,1), True, strings(['B0', 'KS0']), constr)",
+    "h1_PX_BsKSPV = DTF_FUN(CHILD(PX,1), True, strings(['B0', 'KS0']), constr)",
+    "h1_PY_BsKSPV = DTF_FUN(CHILD(PY,1), True, strings(['B0', 'KS0']), constr)",
+    "h1_PZ_BsKSPV = DTF_FUN(CHILD(PZ,1), True, strings(['B0', 'KS0']), constr)",
+    "h1_PE_BsKSPV = DTF_FUN(CHILD(E,1), True, strings(['B0', 'KS0']), constr)",
+    
+    "h2_M_BsKSPV = DTF_FUN(CHILD(M,2), True, strings(['B0', 'KS0']), constr)",
+    "h2_P_BsKSPV = DTF_FUN(CHILD(P,2), True, strings(['B0', 'KS0']), constr)",
+    "h2_PX_BsKSPV = DTF_FUN(CHILD(PX,2), True, strings(['B0', 'KS0']), constr)",
+    "h2_PY_BsKSPV = DTF_FUN(CHILD(PY,2), True, strings(['B0', 'KS0']), constr)",
+    "h2_PZ_BsKSPV = DTF_FUN(CHILD(PZ,2), True, strings(['B0', 'KS0']), constr)",
+    "h2_PE_BsKSPV = DTF_FUN(CHILD(E,2), True, strings(['B0', 'KS0']), constr)",
+    
+    "KS_M_BsKSPV = DTF_FUN(CHILD(M,3), True, strings(['B0', 'KS0']), constr)",
+    "KS_P_BsKSPV = DTF_FUN(CHILD(P,3), True, strings(['B0', 'KS0']), constr)",
+    "KS_PX_BsKSPV = DTF_FUN(CHILD(PX,3), True, strings(['B0', 'KS0']), constr)",
+    "KS_PY_BsKSPV = DTF_FUN(CHILD(PY,3), True, strings(['B0', 'KS0']), constr)",
+    "KS_PZ_BsKSPV = DTF_FUN(CHILD(PZ,3), True, strings(['B0', 'KS0']), constr)",
+    "KS_PE_BsKSPV = DTF_FUN(CHILD(E,3), True, strings(['B0', 'KS0']), constr)",
+    
+    "M12_BsKSPV = DTF_FUN(M12, True, strings(['B0', 'KS0']), constr)**2",
+    "M13_BsKSPV = DTF_FUN(M13,True, strings(['B0', 'KS0']), constr)**2",
+    "M23_BsKSPV = DTF_FUN(M23, True, strings(['B0', 'KS0']), constr)**2",
+]
+
+
+
+
+preamble_BdKSPV_list = ["M_BdKSPV", "P_BdKSPV", "PT_BdKSPV", "PX_BdKSPV", "PY_BdKSPV", "PZ_BdKSPV", "PE_BdKSPV",
+                       "h1_M_BdKSPV", "h1_P_BdKSPV", "h1_PX_BdKSPV", "h1_PY_BdKSPV", "h1_PZ_BdKSPV", "h1_PE_BdKSPV",
+                       "h2_M_BdKSPV", "h2_P_BdKSPV", "h2_PX_BdKSPV", "h2_PY_BdKSPV", "h2_PZ_BdKSPV", "h2_PE_BdKSPV",
+                       "KS_M_BdKSPV", "KS_P_BdKSPV", "KS_PX_BdKSPV", "KS_PY_BdKSPV", "KS_PZ_BdKSPV", "KS_PE_BdKSPV",
+                       "M12_BdKSPV", "M13_BdKSPV", "M23_BdKSPV"]
+preamble_KSPV_list = ["M_KSPV", "P_KSPV", "PT_KSPV", "PX_KSPV", "PY_KSPV", "PZ_KSPV", "PE_KSPV",
+                       "h1_M_KSPV", "h1_P_KSPV", "h1_PX_KSPV", "h1_PY_KSPV", "h1_PZ_KSPV", "h1_PE_KSPV",
+                       "h2_M_KSPV", "h2_P_KSPV", "h2_PX_KSPV", "h2_PY_KSPV", "h2_PZ_KSPV", "h2_PE_KSPV",
+                       "KS_M_KSPV", "KS_P_KSPV", "KS_PX_KSPV", "KS_PY_KSPV", "KS_PZ_KSPV", "KS_PE_KSPV",
+                       "M12_KSPV", "M13_KSPV", "M23_KSPV" ]
+preamble_BsKSPV_list = ["M_BsKSPV", "P_BsKSPV", "PT_BsKSPV", "PX_BsKSPV", "PY_BsKSPV", "PZ_BsKSPV", "PE_BsKSPV",
+                        "h1_M_BsKSPV","h1_P_BsKSPV", "h1_PX_BsKSPV", "h1_PY_BsKSPV", "h1_PZ_BsKSPV", "h1_PE_BsKSPV",
+                        "h2_M_BsKSPV", "h2_P_BsKSPV", "h2_PX_BsKSPV", "h2_PY_BsKSPV", "h2_PZ_BsKSPV", "h2_PE_BsKSPV",
+                        "KS_M_BsKSPV", "KS_P_BsKSPV", "KS_PX_BsKSPV", "KS_PY_BsKSPV", "KS_PZ_BsKSPV", "KS_PE_BsKSPV",
+                        "M12_BsKSPV", "M13_BsKSPV", "M23_BsKSPV"]
+
+variable_DTF_list = ["M", "P", "PT", "PX", "PY", "PZ", "PE",
+                     "h1_M", "h1_P", "h1_PX", "h1_PY", "h1_PZ", "h1_PE",
+                     "h2_M", "h2_P", "h2_PX", "h2_PY", "h2_PZ", "h2_PE",
+                     "KS_M", "KS_P", "KS_PX", "KS_PY", "KS_PZ", "KS_PE" ,
+                     "m12Sq", "m13Sq", "m23Sq"]
+
+
+suffixes_Bd2hhKS = ["Bd2KKKS", "Bd2pipiKS", "Bd2piKKS", "Bd2KpiKS", "Bd2pKKS", "Bd2KpKS", "Bd2pipKS", "Bd2ppiKS"]
+suffixes_hhKS = ["KKKS", "pipiKS", "piKKS", "KpiKS", "pKKS", "KpKS", "pipKS", "ppiKS"]
+suffixes_Bs2hhKS = ["Bs2KKKS", "Bs2pipiKS", "Bs2piKKS", "Bs2KpiKS", "Bs2pKKS", "Bs2KpKS", "Bs2pipKS", "Bs2ppiKS"]
+
+# Dictionary to hold all the dictionaries with different suffixes  -- for Bd2KKKS
+dicts_Bd2hhKS = {}
+string_dict_Bd2hhKS = dict(zip(variable_DTF_list, preamble_BdKSPV_list))    #associate variable name and preamble "function"
+
+# Dictionary to hold all the dictionaries with different suffixes  -- for KKKS
+dicts_hhKS = {}
+string_dict_hhKS = dict(zip(variable_DTF_list, preamble_KSPV_list))
+
+dicts_Bs2hhKS = {}
+string_dict_Bs2hhKS = dict(zip(variable_DTF_list, preamble_BsKSPV_list))
+
+
+
+
+#modify dictionaries to have the right suffix
+for suffix in suffixes_Bd2hhKS:
+    # Create a new dictionary with keys having suffixes
+    new_dict = {f"{key}_{suffix}": val for key, val in string_dict_Bd2hhKS.items()}
+    dicts_Bd2hhKS[suffix] = new_dict
+
+for suffix in suffixes_hhKS:
+#    # Create a new dictionary with keys having suffixes
+    new_dict = {f"{key}_{suffix}": val for key, val in string_dict_hhKS.items()}
+    dicts_hhKS[suffix] = new_dict
+
+#modify dictionaries to have the right suffix
+for suffix in suffixes_Bs2hhKS:
+    # Create a new dictionary with keys having suffixes
+    new_dict = {f"{key}_{suffix}": val for key, val in string_dict_Bs2hhKS.items()}
+    dicts_Bs2hhKS[suffix] = new_dict
+
+
+
+#Bd2hhKS
+
+B0_Bd2KKKS = dtt.B.addTupleTool("LoKi::Hybrid::TupleTool/B0_Bd2KKKS")
+B0_Bd2KKKS.Preambulo = preamble_BdKSPV
+B0_Bd2KKKS.Variables = dicts_Bd2hhKS["Bd2KKKS"]
+
+B0_Bd2pipiKS = dtt_pipiKS.B.addTupleTool("LoKi::Hybrid::TupleTool/B0_Bd2pipiKS")
+B0_Bd2pipiKS.Preambulo=preamble_BdKSPV
+B0_Bd2pipiKS.Variables = dicts_Bd2hhKS["Bd2pipiKS"]
+
+B0_Bd2piKKS = dtt_piKKS.B.addTupleTool("LoKi::Hybrid::TupleTool/B0_Bd2piKKS")
+B0_Bd2piKKS.Preambulo=preamble_BdKSPV
+B0_Bd2piKKS.Variables = dicts_Bd2hhKS["Bd2piKKS"]
+
+B0_Bd2KpiKS = dtt_KpiKS.B.addTupleTool("LoKi::Hybrid::TupleTool/B0_Bd2KpiKS")
+B0_Bd2KpiKS.Preambulo=preamble_BdKSPV
+B0_Bd2KpiKS.Variables = dicts_Bd2hhKS["Bd2KpiKS"]
+
+B0_Bd2pKKS = dtt_pKKS.B.addTupleTool("LoKi::Hybrid::TupleTool/B0_Bd2pKKS")
+B0_Bd2pKKS.Preambulo=preamble_BdKSPV
+B0_Bd2pKKS.Variables = dicts_Bd2hhKS["Bd2pKKS"]
+
+B0_Bd2KpKS = dtt_KpKS.B.addTupleTool("LoKi::Hybrid::TupleTool/B0_Bd2KpKS")
+B0_Bd2KpKS.Preambulo=preamble_BdKSPV
+B0_Bd2KpKS.Variables = dicts_Bd2hhKS["Bd2KpKS"]
+
+B0_Bd2pipKS = dtt_pipKS.B.addTupleTool("LoKi::Hybrid::TupleTool/B0_Bd2pipKS")
+B0_Bd2pipKS.Preambulo = preamble_BdKSPV
+B0_Bd2pipKS.Variables = dicts_Bd2hhKS["Bd2pipKS"]
+
+B0_Bd2ppiKS = dtt_ppiKS.B.addTupleTool("LoKi::Hybrid::TupleTool/B0_Bd2ppiKS")
+B0_Bd2ppiKS.Preambulo = preamble_BdKSPV
+B0_Bd2ppiKS.Variables = dicts_Bd2hhKS["Bd2ppiKS"]
+
+
+#Bd2hhKS
+B0_KKKS = dtt.B.addTupleTool("LoKi::Hybrid::TupleTool/B0_KKKS")
+B0_KKKS.Preambulo = preamble_KSPV
+B0_KKKS.Variables = dicts_hhKS["KKKS"]
+
+B0_pipiKS = dtt_pipiKS.B.addTupleTool("LoKi::Hybrid::TupleTool/B0_pipiKS")
+B0_pipiKS.Preambulo = preamble_KSPV
+B0_pipiKS.Variables = dicts_hhKS["pipiKS"]
+
+B0_piKKS = dtt_piKKS.B.addTupleTool("LoKi::Hybrid::TupleTool/B0_piKKS")
+B0_piKKS.Preambulo = preamble_KSPV
+B0_piKKS.Variables = dicts_hhKS["piKKS"]
+
+B0_KpiKS = dtt_KpiKS.B.addTupleTool("LoKi::Hybrid::TupleTool/B0_KpiKS")
+B0_KpiKS.Preambulo = preamble_KSPV
+B0_KpiKS.Variables = dicts_hhKS["KpiKS"]
+
+B0_pKKS = dtt_pKKS.B.addTupleTool("LoKi::Hybrid::TupleTool/B0_pKKS")
+B0_pKKS.Preambulo = preamble_KSPV
+B0_pKKS.Variables = dicts_hhKS["pKKS"]
+
+B0_KpKS = dtt_KpKS.B.addTupleTool("LoKi::Hybrid::TupleTool/B0_KpKS")
+B0_KpKS.Preambulo = preamble_KSPV
+B0_KpKS.Variables = dicts_hhKS["KpKS"]
+
+B0_pipKS = dtt_pipKS.B.addTupleTool("LoKi::Hybrid::TupleTool/B0_pipKS")
+B0_pipKS.Preambulo = preamble_BdKSPV
+B0_pipKS.Variables = dicts_hhKS["pipKS"]
+
+B0_ppiKS = dtt_ppiKS.B.addTupleTool("LoKi::Hybrid::TupleTool/B0_ppiKS")
+B0_ppiKS.Preambulo = preamble_BdKSPV
+B0_ppiKS.Variables = dicts_hhKS["ppiKS"]
+
+#Bs2KShh variables
+
+B0_Bs2KKKS = dtt.B.addTupleTool("LoKi::Hybrid::TupleTool/B0_Bs2KKKS")
+B0_Bs2KKKS.Preambulo = preamble_BsKSPV
+B0_Bs2KKKS.Variables = dicts_Bs2hhKS["Bs2KKKS"]
+
+B0_Bs2pipiKS = dtt_pipiKS.B.addTupleTool("LoKi::Hybrid::TupleTool/B0_Bs2pipiKS")
+B0_Bs2pipiKS.Preambulo=preamble_BsKSPV
+B0_Bs2pipiKS.Variables = dicts_Bs2hhKS["Bs2pipiKS"]
+
+B0_Bs2piKKS = dtt_piKKS.B.addTupleTool("LoKi::Hybrid::TupleTool/B0_Bs2piKKS")
+B0_Bs2piKKS.Preambulo=preamble_BsKSPV
+B0_Bs2piKKS.Variables = dicts_Bs2hhKS["Bs2piKKS"]
+
+B0_Bs2KpiKS = dtt_KpiKS.B.addTupleTool("LoKi::Hybrid::TupleTool/B0_Bs2KpiKS")
+B0_Bs2KpiKS.Preambulo=preamble_BsKSPV
+B0_Bs2KpiKS.Variables = dicts_Bs2hhKS["Bs2KpiKS"]
+
+B0_Bs2pKKS = dtt_pKKS.B.addTupleTool("LoKi::Hybrid::TupleTool/B0_Bs2pKKS")
+B0_Bs2pKKS.Preambulo=preamble_BsKSPV
+B0_Bs2pKKS.Variables = dicts_Bs2hhKS["Bs2pKKS"]
+
+B0_Bs2KpKS = dtt_KpKS.B.addTupleTool("LoKi::Hybrid::TupleTool/B0_Bs2KpKS")
+B0_Bs2KpKS.Preambulo=preamble_BsKSPV
+B0_Bs2KpKS.Variables = dicts_Bs2hhKS["Bs2KpKS"]
+
+B0_Bs2pipKS = dtt_pipKS.B.addTupleTool("LoKi::Hybrid::TupleTool/B0_Bs2pipKS")
+B0_Bs2pipKS.Preambulo = preamble_BsKSPV
+B0_Bs2pipKS.Variables = dicts_Bs2hhKS["Bs2pipKS"]
+
+B0_Bs2ppiKS = dtt_ppiKS.B.addTupleTool("LoKi::Hybrid::TupleTool/B0_Bs2ppiKS")
+B0_Bs2ppiKS.Preambulo = preamble_BsKSPV
+B0_Bs2ppiKS.Variables = dicts_Bs2hhKS["Bs2ppiKS"]
+
+
+#VTX and CONE ISOLATION from Stripping
+B0_iso = dtt_pipiKS.B.addTupleTool('LoKi::Hybrid::TupleTool/B0_iso')
+KS_coneiso = dtt_pipiKS.B.addTupleTool('LoKi::Hybrid::TupleTool/KS_coneiso')  #attach to KS to me
+
+infoloc_vtxiso = '/Event/{0}/Phys/{1}/VtxIsolationVar_B'.format(stream, line)      #'/Event/Bhadron/Phys/B2KShh_DD_Run2_OS_Line/VtxIsolationVar_B'
+
+B0_iso.Variables = {
+        "VTXISODCHI2ONETRACK"     : "RELINFO('%s','VTXISODCHI2ONETRACK',-13.)"%infoloc_vtxiso,
+        "VTXISODCHI2MASSONETRACK" : "RELINFO('%s','VTXISODCHI2MASSONETRACK',-13.)"%infoloc_vtxiso,
+        "VTXISODCHI2TWOTRACK"     : "RELINFO('%s','VTXISODCHI2TWOTRACK',-13.)"%infoloc_vtxiso,
+        "VTXISODCHI2MASSTWOTRACK" : "RELINFO('%s','VTXISODCHI2MASSTWOTRACK',-13.)"%infoloc_vtxiso,
+        "VTXISONUMVTX"            : "RELINFO('%s','VTXISONUMVTX',-13.)"%infoloc_vtxiso
+}
+
+#cone isolation and asymm from TES location
+#B0_coneiso = dtt_pipiKS.addTupleTool('LoKi::Hybrid::TupleTool/B0_coneiso')
+cone_values = ["10", "15", "17", "20"]
+
+for XX in cone_values:
+
+    infoloc_coneiso = '/Event/{0}/Phys/{1}/ConeVar{2}_B'.format(stream, line, XX)
+    infoloc_coneiso_KS = '/Event/{0}/Phys/{1}/ConeVar{2}_KS'.format(stream, line, XX)
+
+    B0_iso.Variables.update({
+       f"CONEPXASYM_{XX}"    : "RELINFO('%s', 'CONEPXASYM', -13.)"%infoloc_coneiso,
+       f"CONEPYASYM_{XX}"    : "RELINFO('%s', 'CONEPYASYM', -13.)"%infoloc_coneiso,
+       f"CONEPZASYM_{XX}"    : "RELINFO('%s', 'CONEPZASYM', -13.)"%infoloc_coneiso,
+       f"CONEPASYM_{XX}"     : "RELINFO('%s', 'CONEPASYM', -13.)"%infoloc_coneiso,
+       f"CONEPTASYM_{XX}"    : "RELINFO('%s', 'CONEPTASYM', -13.)"%infoloc_coneiso,
+       f"CONEDELTAETA_{XX}"  : "RELINFO('%s', 'CONEDELTAETA', -13.)"%infoloc_coneiso,
+       f"CONEDELTAPHI_{XX}"  : "RELINFO('%s', 'CONEDELTAPHI', -13.)"%infoloc_coneiso,
+
+    })
+
+    KS_coneiso.Variables.update({
+       f"KS_CONEPXASYM_{XX}"    : "RELINFO('%s', 'CONEPXASYM', -13.)"%infoloc_coneiso_KS,
+       f"KS_CONEPYASYM_{XX}"    : "RELINFO('%s', 'CONEPYASYM', -13.)"%infoloc_coneiso_KS,
+       f"KS_CONEPZASYM_{XX}"    : "RELINFO('%s', 'CONEPZASYM', -13.)"%infoloc_coneiso_KS,
+       f"KS_CONEPASYM_{XX}"     : "RELINFO('%s', 'CONEPASYM', -13.)"%infoloc_coneiso_KS,
+       f"KS_CONEPTASYM_{XX}"    : "RELINFO('%s', 'CONEPTASYM', -13.)"%infoloc_coneiso_KS,
+       f"KS_CONEDELTAETA_{XX}"  : "RELINFO('%s', 'CONEDELTAETA', -13.)"%infoloc_coneiso_KS,
+       f"KS_CONEDELTAPHI_{XX}"  : "RELINFO('%s', 'CONEDELTAPHI', -13.)"%infoloc_coneiso_KS,
+
+    })
+
+
+
+#GETTING THE TRIGGER LINES
+#add to Trigger_tool
+triggerList_base = [
+    #L0 TCKsh getL0Channels(0x11741801)
+    "L0MuonDecision",
+    "L0DiMuonDecision",
+    "L0HadronDecision",
+    "L0ElectronDecision",
+    "L0PhotonDecision"
+]
+
+
+trigger_L0_add = []
+trigger_Hlt1_add = []
+trigger_Hlt2_add = []
+
+#year is something that is passed from the Ganga job
+
+if year in ['2015', '2016', '2017', '2018']:
+    trigger_Hlt1_add = [ "Hlt1TrackMVADecision", "Hlt1TwoTrackMVADecision"]
+    trigger_Hlt2_add = ["Hlt2Topo2BodyDecision", "Hlt2Topo3BodyDecision", "Hlt2Topo4BodyDecision"]     #Hlt2 lines TCKsh getHlt2(0x21751801)
+    if year in ['2018', '2017']:
+        trigger_L0_add = ["L0MuonEWDecision"]
+    if year in ['2016', '2015']:
+        trigger_L0_add = ["L0MuonEWDecision",  "L0JetElDecision", "L0JetPhDecision"   ]
+
+if year in ['2012b', '2012a', '2011']:
+    trigger_Hlt1_add = ["Hlt1TrackAllL0Decision"]
+    
+    if year in ['2012b', '2012a']:
+        trigger_Hlt2_add = ["Hlt2Topo2BodyBBDTDecision", "Hlt2Topo3BodyBBDTDecision", "Hlt2Topo4BodyBBDTDecision"]
+    if year in ['2011']:
+        trigger_Hlt2_add = ["Hlt2Topo2BodyBBDTDecision", "Hlt2Topo3BodyBBDTDecision", "Hlt2Topo4BodyBBDTDecision", "Hlt2Topo2BodySimpleDecision", "Hlt2Topo3BodySimpleDecision", "Hlt2Topo4BodySimpleDecision"]
+
+
+triggerList = triggerList_base + trigger_L0_add + trigger_Hlt1_add + trigger_Hlt2_add
+print(triggerList)
+
+Trigger_tool.TriggerList = triggerList      # add these trigger information to trigger tuple tool
+#TISTOS_tool.TriggerList = triggerList       # add these TISTOS to the trigger info
+
+#cose che devono essere associate a una particella
+dtt.B.addTupleTool('TupleToolTISTOS')
+dtt.B.TupleToolTISTOS.VerboseL0 = True
+dtt.B.TupleToolTISTOS.VerboseHlt1 = True
+dtt.B.TupleToolTISTOS.VerboseHlt2 = True
+dtt.B.TupleToolTISTOS.FillL0 = True
+dtt.B.TupleToolTISTOS.FillHlt1 = True
+dtt.B.TupleToolTISTOS.FillHlt2 = True
+dtt.B.TupleToolTISTOS.TriggerList = triggerList
+
+#add Geometry tuple tool in verbose mode
+#I want MINIPCHI2 for charged particles
+dtt.B.addTupleTool('TupleToolGeometry')
+dtt.B.TupleToolGeometry.Verbose= True
+
+dtt.h1.addTupleTool('TupleToolGeometry')
+dtt.h1.TupleToolGeometry.Verbose = True
+dtt.h2.addTupleTool('TupleToolGeometry')
+dtt.h2.TupleToolGeometry.Verbose= True
+dtt.KSpip.addTupleTool('TupleToolGeometry')
+dtt.KSpip.TupleToolGeometry.Verbose = True
+dtt.KSpim.addTupleTool('TupleToolGeometry')
+dtt.KSpim.TupleToolGeometry.Verbose = True
+
+#pipiKS
+dtt_pipiKS.B.addTupleTool('TupleToolTISTOS')
+dtt_pipiKS.B.TupleToolTISTOS.VerboseL0 = True
+dtt_pipiKS.B.TupleToolTISTOS.VerboseHlt1 = True
+dtt_pipiKS.B.TupleToolTISTOS.VerboseHlt2 = True
+dtt_pipiKS.B.TupleToolTISTOS.FillL0 = True
+dtt_pipiKS.B.TupleToolTISTOS.FillHlt1 = True
+dtt_pipiKS.B.TupleToolTISTOS.FillHlt2 = True
+dtt_pipiKS.B.TupleToolTISTOS.TriggerList = triggerList
+
+dtt_pipiKS.B.addTupleTool('TupleToolGeometry')
+dtt_pipiKS.B.TupleToolGeometry.Verbose= True
+dtt_pipiKS.h1.addTupleTool('TupleToolGeometry')
+dtt_pipiKS.h1.TupleToolGeometry.Verbose = True
+dtt_pipiKS.h2.addTupleTool('TupleToolGeometry')
+dtt_pipiKS.h2.TupleToolGeometry.Verbose= True
+dtt_pipiKS.KSpip.addTupleTool('TupleToolGeometry')
+dtt_pipiKS.KSpip.TupleToolGeometry.Verbose = True
+dtt_pipiKS.KSpim.addTupleTool('TupleToolGeometry')
+dtt_pipiKS.KSpim.TupleToolGeometry.Verbose = True
+
+
+#piKKS
+dtt_piKKS.B.addTupleTool('TupleToolTISTOS')
+dtt_piKKS.B.TupleToolTISTOS.VerboseL0 = True
+dtt_piKKS.B.TupleToolTISTOS.VerboseHlt1 = True
+dtt_piKKS.B.TupleToolTISTOS.VerboseHlt2 = True
+dtt_piKKS.B.TupleToolTISTOS.FillL0 = True
+dtt_piKKS.B.TupleToolTISTOS.FillHlt1 = True
+dtt_piKKS.B.TupleToolTISTOS.FillHlt2 = True
+dtt_piKKS.B.TupleToolTISTOS.TriggerList = triggerList
+
+#add Geometry tuple tool in verbose mode
+dtt_piKKS.B.addTupleTool('TupleToolGeometry')
+dtt_piKKS.B.TupleToolGeometry.Verbose= True
+dtt_piKKS.h1.addTupleTool('TupleToolGeometry')
+dtt_piKKS.h1.TupleToolGeometry.Verbose = True
+dtt_piKKS.h2.addTupleTool('TupleToolGeometry')
+dtt_piKKS.h2.TupleToolGeometry.Verbose= True
+dtt_piKKS.KSpip.addTupleTool('TupleToolGeometry')
+dtt_piKKS.KSpip.TupleToolGeometry.Verbose = True
+dtt_piKKS.KSpim.addTupleTool('TupleToolGeometry')
+dtt_piKKS.KSpim.TupleToolGeometry.Verbose = True
+
+
+#KpiKS
+dtt_KpiKS.B.addTupleTool('TupleToolTISTOS')
+dtt_KpiKS.B.TupleToolTISTOS.VerboseL0 = True
+dtt_KpiKS.B.TupleToolTISTOS.VerboseHlt1 = True
+dtt_KpiKS.B.TupleToolTISTOS.VerboseHlt2 = True
+dtt_KpiKS.B.TupleToolTISTOS.FillL0 = True
+dtt_KpiKS.B.TupleToolTISTOS.FillHlt1 = True
+dtt_KpiKS.B.TupleToolTISTOS.FillHlt2 = True
+dtt_KpiKS.B.TupleToolTISTOS.TriggerList = triggerList
+
+#add Geometry tuple tool in verbose mode
+dtt_KpiKS.B.addTupleTool('TupleToolGeometry')
+dtt_KpiKS.B.TupleToolGeometry.Verbose= True
+dtt_KpiKS.h1.addTupleTool('TupleToolGeometry')
+dtt_KpiKS.h1.TupleToolGeometry.Verbose = True
+dtt_KpiKS.h2.addTupleTool('TupleToolGeometry')
+dtt_KpiKS.h2.TupleToolGeometry.Verbose= True
+dtt_KpiKS.KSpip.addTupleTool('TupleToolGeometry')
+dtt_KpiKS.KSpip.TupleToolGeometry.Verbose = True
+dtt_KpiKS.KSpim.addTupleTool('TupleToolGeometry')
+dtt_KpiKS.KSpim.TupleToolGeometry.Verbose = True
+
+
+
+#tupleTool for B tagging
+
+tt_tagging = dtt.addTupleTool("TupleToolTagging")
+tt_tagging.Verbose = True
+tt_tagging.AddMVAFeatureInfo = True # Writes out all MVA features for the final tag
+tt_tagging.AddTagPartsInfo = False  # If True: Writes out all features of all tagging
+                                    # particles used in the selection
+
+btagtool = tt_tagging.addTool(BTaggingTool, name = "MyBTaggingTool")     #BTaggingTool, same as for the other version
+     #adding for 2019 part
+tt_tagging.allConfigurables["ToolSvc.InclusiveTagger"].setProp("ClassifierVersion", "IFT_Bd_v140521")   #line inspired from Thomas
+applyFTTuning(btagtool, tuning_version="Summer2019Optimisation_v1_Run2")   #new tuning version
+tt_tagging.TaggingToolName = btagtool.getFullName()
+
+
+
+
+
+# Configure DaVinci
+
+# add our new selection and the tuple into the sequencer
+seq = GaudiSequencer('MyTupleSeq')
+seq.Members += [selSeq.sequence()]
+seq.Members += [selSeq_piKKS.sequence()]
+seq.Members += [selSeq_KpiKS.sequence()]
+#seq.Members += [selSeq_pipiKS.sequence()]  #commented before
+seq.Members += [selSeq_pipKS.sequence()]
+seq.Members += [selSeq_ppiKS.sequence()]
+seq.Members += [selSeq_pKKS.sequence()]
+seq.Members += [selSeq_KpKS.sequence()]
+
+seq.Members += [dtt]
+seq.Members += [dtt_piKKS]
+seq.Members += [dtt_KpiKS]
+seq.Members += [dtt_pipKS]
+seq.Members += [dtt_ppiKS]
+seq.Members += [dtt_pKKS]
+seq.Members += [dtt_KpKS]
+seq.Members += [dtt_pipiKS]
+#seq.Members += [dtt_standard]
+DaVinci().appendToMainSequence([seq])
+
+
+#DaVinci().InputType = 'DST'
+#DaVinci().TupleFile = 'BdKKKS_2018_Do_DD.root'
+#DaVinci().PrintFreq = 1000
+#DaVinci().DataType = '2018'
+#DaVinci().Simulation = True
+# Only ask for luminosity information when not using simulated data
+#DaVinci().Lumi = not DaVinci().Simulation
+#DaVinci().EvtMax = -1
+#DaVinci().CondDBtag = 'sim-20190430-vc-md100'
+#DaVinci().DDDBtag = 'dddb-20170721-3'
+
+
-- 
GitLab


From 97fcdf06aec10338191dec5c2b0184ae8d9adfc2 Mon Sep 17 00:00:00 2001
From: Edoardo Mariani <edoardo.mariani@cern.ch>
Date: Mon, 6 Jan 2025 12:28:42 +0100
Subject: [PATCH 05/18] Delete .gitkeep

---
 bd2kkks_data/.gitkeep | 0
 1 file changed, 0 insertions(+), 0 deletions(-)
 delete mode 100644 bd2kkks_data/.gitkeep

diff --git a/bd2kkks_data/.gitkeep b/bd2kkks_data/.gitkeep
deleted file mode 100644
index e69de29bb2..0000000000
-- 
GitLab


From 3f0c2b30ef104ae1bc006f2bdd5f5c5927e8890f Mon Sep 17 00:00:00 2001
From: Edoardo Mariani <edoardo.mariani@cern.ch>
Date: Mon, 6 Jan 2025 14:27:33 +0100
Subject: [PATCH 06/18] Update info.yaml

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

diff --git a/bd2kkks_data/info.yaml b/bd2kkks_data/info.yaml
index cea995efab..48a80d0812 100644
--- a/bd2kkks_data/info.yaml
+++ b/bd2kkks_data/info.yaml
@@ -42,10 +42,9 @@ defaults:
 #Run2
 #KSreco determines the stripping line
 {%- for KSreco in ['DD', 'LL'] %}
-
-{%- for year, energy, recostrip, format in MCdatasets %}
-  {%- for polarity in ['MagDown', 'MagUp'] %}
-    {%- for etNumber, et in evttypes %}
+  {%- for year, energy, recostrip, format in MCdatasets %}
+    {%- for polarity in ['MagDown', 'MagUp'] %}
+      {%- for etNumber, et in evttypes %}
 
 MC_20{{year}}_{{polarity}}_{{KSreco}}_{et}:
     input:
@@ -55,9 +54,10 @@ MC_20{{year}}_{{polarity}}_{{KSreco}}_{et}:
     checks:
       - B2KKKS_check    
 
+      {%- endfor %}
+    {%- endfor %}
   {%- endfor %}
 {%- endfor %}
-{%- endfor %}
 
 #put only compulsory fields for checks
 checks: 
-- 
GitLab


From 5e4cc96334e1a7b41b1e7fc95128b540b301dbb4 Mon Sep 17 00:00:00 2001
From: Edoardo Mariani <edoardo.mariani@cern.ch>
Date: Mon, 6 Jan 2025 14:46:48 +0100
Subject: [PATCH 07/18] Update info.yaml

---
 bd2kkks_data/info.yaml | 10 ----------
 1 file changed, 10 deletions(-)

diff --git a/bd2kkks_data/info.yaml b/bd2kkks_data/info.yaml
index 48a80d0812..532fa08394 100644
--- a/bd2kkks_data/info.yaml
+++ b/bd2kkks_data/info.yaml
@@ -8,15 +8,6 @@ defaults:
     output: B2hhKS_MC.root
 
 
-#{%- set MCdatasets = [
-#  (2011, 3500, '0x40760037', '14c', '', '21r1p2', 'B2KSHH.STRIP.DST'),
-#  (2012, 4000, '0x4097003d', '14c', '21r0p2', 'B2KSHH.STRIP.DST'),
-#  (2012, 4000, '0x409f0045', '14c', '21r0p2', 'B2KSHH.STRIP.DST'),
-#  (15, 6500, '0x411400a2',  '15a', '24r2', 'B2KSHH.STRIP.DST'),
-#  (16, 6500, '0x6139160F', '16', '28r2', 'B2KSHH.STRIP.DST'),
-# (17, 6500, '0x62661709',  '17', '29r2p1', 'B2KSHH.STRIP.DST'),
-#  (18, 6500, '0x617d18a4', '18', '34r0p1', 'B2KSHH.STRIP.DST'),
-#]%}
 
 {%- set MCdatasets = [
   (2011, 3500,  'Nu2-Pythia8/Sim09h/Trig0x40760037/Reco14c/Stripping21r1p2Filtered', 'B2KSHH.STRIP.DST'),
@@ -53,7 +44,6 @@ MC_20{{year}}_{{polarity}}_{{KSreco}}_{et}:
       - B2hhKS_MC_opt_{{KSreco}}.py
     checks:
       - B2KKKS_check    
-
       {%- endfor %}
     {%- endfor %}
   {%- endfor %}
-- 
GitLab


From 3959d59f49cfaa6c4ecb2046d5be45866cbd82fc Mon Sep 17 00:00:00 2001
From: Edoardo Mariani <edoardo.mariani@cern.ch>
Date: Mon, 6 Jan 2025 15:09:12 +0100
Subject: [PATCH 08/18] Update info.yaml

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

diff --git a/bd2kkks_data/info.yaml b/bd2kkks_data/info.yaml
index 532fa08394..3d8307e7e4 100644
--- a/bd2kkks_data/info.yaml
+++ b/bd2kkks_data/info.yaml
@@ -37,7 +37,7 @@ defaults:
     {%- for polarity in ['MagDown', 'MagUp'] %}
       {%- for etNumber, et in evttypes %}
 
-MC_20{{year}}_{{polarity}}_{{KSreco}}_{et}:
+MC_20{{year}}_{{polarity}}_{{KSreco}}_{{et}}:
     input:
       bk_query: /MC/{{year}}/Beam{{energy}}GeV-{{year}}-{{polarity}}-{{recostrip}}/{etNumber}/{{format}}
     options:
-- 
GitLab


From 92fb7b2bb01fab9b795d267c7337c10ccade3f5f Mon Sep 17 00:00:00 2001
From: Edoardo Mariani <edoardo.mariani@cern.ch>
Date: Mon, 6 Jan 2025 15:24:45 +0100
Subject: [PATCH 09/18] Update info.yaml

---
 bd2kkks_data/info.yaml | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/bd2kkks_data/info.yaml b/bd2kkks_data/info.yaml
index 3d8307e7e4..b613489fa2 100644
--- a/bd2kkks_data/info.yaml
+++ b/bd2kkks_data/info.yaml
@@ -10,13 +10,13 @@ defaults:
 
 
 {%- set MCdatasets = [
-  (2011, 3500,  'Nu2-Pythia8/Sim09h/Trig0x40760037/Reco14c/Stripping21r1p2Filtered', 'B2KSHH.STRIP.DST'),
-  (2012, 4000,  'Nu2.5-Pythia8/Sim09j/Trig0x4097003d/Reco14c/Stripping21r0p2Filtered', 'B2KSHH.STRIP.DST'),
-  (2012, 4000, 'Nu2.5-Pythia8/Sim09j/Trig0x409f0045/Reco14c/Stripping21r0p2Filtered', 'B2KSHH.STRIP.DST'),
-  (15, 6500,  'Nu1.6-25ns-Pythia8/Sim09h/Trig0x411400a2/Reco15a/Turbo02/Stripping24r2Filtered', 'B2KSHH.STRIP.DST'),
-  (16, 6500,  'Nu1.6-25ns-Pythia8/Sim09h/Trig0x6139160F/Reco16/Turbo03a/Stripping28r2Filtered', 'B2KSHH.STRIP.DST'),
-  (17, 6500,  'Nu1.6-25ns-Pythia8/Sim09h/Trig0x62661709/Reco17/Turbo04a-WithTurcal/Stripping29r2p1Filtered', 'B2KSHH.STRIP.DST'),
-  (18, 6500,  'Nu1.6-25ns-Pythia8/Sim09h/Trig0x617d18a4/Reco18/Turbo05-WithTurcal/Stripping34r0p1Filtered', 'B2KSHH.STRIP.DST'),
+  (11, '2011',  3500,  'Nu2-Pythia8/Sim09h/Trig0x40760037/Reco14c/Stripping21r1p2Filtered', 'B2KSHH.STRIP.DST'),
+  (12, '2012a',  4000,  'Nu2.5-Pythia8/Sim09j/Trig0x4097003d/Reco14c/Stripping21r0p2Filtered', 'B2KSHH.STRIP.DST'),
+  (12, '2012b', 4000, 'Nu2.5-Pythia8/Sim09j/Trig0x409f0045/Reco14c/Stripping21r0p2Filtered', 'B2KSHH.STRIP.DST'),
+  (15, '2015',  6500,  'Nu1.6-25ns-Pythia8/Sim09h/Trig0x411400a2/Reco15a/Turbo02/Stripping24r2Filtered', 'B2KSHH.STRIP.DST'),
+  (16, '2016', 6500,  'Nu1.6-25ns-Pythia8/Sim09h/Trig0x6139160F/Reco16/Turbo03a/Stripping28r2Filtered', 'B2KSHH.STRIP.DST'),
+  (17, '2017',  6500,  'Nu1.6-25ns-Pythia8/Sim09h/Trig0x62661709/Reco17/Turbo04a-WithTurcal/Stripping29r2p1Filtered', 'B2KSHH.STRIP.DST'),
+  (18, '2018', 6500,  'Nu1.6-25ns-Pythia8/Sim09h/Trig0x617d18a4/Reco18/Turbo05-WithTurcal/Stripping34r0p1Filtered', 'B2KSHH.STRIP.DST'),
 ]%}
 
 
@@ -33,11 +33,11 @@ defaults:
 #Run2
 #KSreco determines the stripping line
 {%- for KSreco in ['DD', 'LL'] %}
-  {%- for year, energy, recostrip, format in MCdatasets %}
+  {%- for year, yy, energy, recostrip, format in MCdatasets %}
     {%- for polarity in ['MagDown', 'MagUp'] %}
       {%- for etNumber, et in evttypes %}
 
-MC_20{{year}}_{{polarity}}_{{KSreco}}_{{et}}:
+MC_{{yy}}_{{polarity}}_{{KSreco}}_{{et}}:
     input:
       bk_query: /MC/{{year}}/Beam{{energy}}GeV-{{year}}-{{polarity}}-{{recostrip}}/{etNumber}/{{format}}
     options:
-- 
GitLab


From 3d40e469035c21b9cf5174a3f21264ad08204fe2 Mon Sep 17 00:00:00 2001
From: Edoardo Mariani <edoardo.mariani@cern.ch>
Date: Mon, 6 Jan 2025 15:56:44 +0100
Subject: [PATCH 10/18] Update info.yaml

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

diff --git a/bd2kkks_data/info.yaml b/bd2kkks_data/info.yaml
index b613489fa2..8748a4b6a3 100644
--- a/bd2kkks_data/info.yaml
+++ b/bd2kkks_data/info.yaml
@@ -39,7 +39,7 @@ defaults:
 
 MC_{{yy}}_{{polarity}}_{{KSreco}}_{{et}}:
     input:
-      bk_query: /MC/{{year}}/Beam{{energy}}GeV-{{year}}-{{polarity}}-{{recostrip}}/{etNumber}/{{format}}
+      bk_query: /MC/20{{year}}/Beam{{energy}}GeV-20{{year}}-{{polarity}}-{{recostrip}}/{etNumber}/{{format}}
     options:
       - B2hhKS_MC_opt_{{KSreco}}.py
     checks:
-- 
GitLab


From 099c233e607883ca5bb3f0b551fa4951e246280e Mon Sep 17 00:00:00 2001
From: Edoardo Mariani <edoardo.mariani@cern.ch>
Date: Mon, 6 Jan 2025 16:01:31 +0100
Subject: [PATCH 11/18] Update info.yaml

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

diff --git a/bd2kkks_data/info.yaml b/bd2kkks_data/info.yaml
index 8748a4b6a3..271a5ded5e 100644
--- a/bd2kkks_data/info.yaml
+++ b/bd2kkks_data/info.yaml
@@ -39,7 +39,7 @@ defaults:
 
 MC_{{yy}}_{{polarity}}_{{KSreco}}_{{et}}:
     input:
-      bk_query: /MC/20{{year}}/Beam{{energy}}GeV-20{{year}}-{{polarity}}-{{recostrip}}/{etNumber}/{{format}}
+      bk_query: /MC/20{{year}}/Beam{{energy}}GeV-20{{year}}-{{polarity}}-{{recostrip}}/{{etNumber}}/{{format}}
     options:
       - B2hhKS_MC_opt_{{KSreco}}.py
     checks:
-- 
GitLab


From 6cc57ffa5334568ed7f06f89d4a57dcf93c65310 Mon Sep 17 00:00:00 2001
From: Edoardo Mariani <edoardo.mariani@cern.ch>
Date: Thu, 16 Jan 2025 14:55:36 +0100
Subject: [PATCH 12/18] Update info.yaml

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

diff --git a/bd2kkks_data/info.yaml b/bd2kkks_data/info.yaml
index 271a5ded5e..952afbf31c 100644
--- a/bd2kkks_data/info.yaml
+++ b/bd2kkks_data/info.yaml
@@ -10,13 +10,13 @@ defaults:
 
 
 {%- set MCdatasets = [
-  (11, '2011',  3500,  'Nu2-Pythia8/Sim09h/Trig0x40760037/Reco14c/Stripping21r1p2Filtered', 'B2KSHH.STRIP.DST'),
-  (12, '2012a',  4000,  'Nu2.5-Pythia8/Sim09j/Trig0x4097003d/Reco14c/Stripping21r0p2Filtered', 'B2KSHH.STRIP.DST'),
-  (12, '2012b', 4000, 'Nu2.5-Pythia8/Sim09j/Trig0x409f0045/Reco14c/Stripping21r0p2Filtered', 'B2KSHH.STRIP.DST'),
-  (15, '2015',  6500,  'Nu1.6-25ns-Pythia8/Sim09h/Trig0x411400a2/Reco15a/Turbo02/Stripping24r2Filtered', 'B2KSHH.STRIP.DST'),
-  (16, '2016', 6500,  'Nu1.6-25ns-Pythia8/Sim09h/Trig0x6139160F/Reco16/Turbo03a/Stripping28r2Filtered', 'B2KSHH.STRIP.DST'),
+  #(11, '2011',  3500,  'Nu2-Pythia8/Sim09h/Trig0x40760037/Reco14c/Stripping21r1p2Filtered', 'B2KSHH.STRIP.DST'),
+  #(12, '2012a',  4000,  'Nu2.5-Pythia8/Sim09j/Trig0x4097003d/Reco14c/Stripping21r0p2Filtered', 'B2KSHH.STRIP.DST'),
+  #(12, '2012b', 4000, 'Nu2.5-Pythia8/Sim09j/Trig0x409f0045/Reco14c/Stripping21r0p2Filtered', 'B2KSHH.STRIP.DST'),
+  #(15, '2015',  6500,  'Nu1.6-25ns-Pythia8/Sim09h/Trig0x411400a2/Reco15a/Turbo02/Stripping24r2Filtered', 'B2KSHH.STRIP.DST'),
+  #(16, '2016', 6500,  'Nu1.6-25ns-Pythia8/Sim09h/Trig0x6139160F/Reco16/Turbo03a/Stripping28r2Filtered', 'B2KSHH.STRIP.DST'),
   (17, '2017',  6500,  'Nu1.6-25ns-Pythia8/Sim09h/Trig0x62661709/Reco17/Turbo04a-WithTurcal/Stripping29r2p1Filtered', 'B2KSHH.STRIP.DST'),
-  (18, '2018', 6500,  'Nu1.6-25ns-Pythia8/Sim09h/Trig0x617d18a4/Reco18/Turbo05-WithTurcal/Stripping34r0p1Filtered', 'B2KSHH.STRIP.DST'),
+  #(18, '2018', 6500,  'Nu1.6-25ns-Pythia8/Sim09h/Trig0x617d18a4/Reco18/Turbo05-WithTurcal/Stripping34r0p1Filtered', 'B2KSHH.STRIP.DST'),
 ]%}
 
 
-- 
GitLab


From 508f1af399537306b89f0f439a1d591219cf4223 Mon Sep 17 00:00:00 2001
From: Edoardo Mariani <edoardo.mariani@cern.ch>
Date: Fri, 17 Jan 2025 14:16:23 +0100
Subject: [PATCH 13/18] Update info.yaml

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

diff --git a/bd2kkks_data/info.yaml b/bd2kkks_data/info.yaml
index 952afbf31c..2a01f8c202 100644
--- a/bd2kkks_data/info.yaml
+++ b/bd2kkks_data/info.yaml
@@ -10,15 +10,15 @@ defaults:
 
 
 {%- set MCdatasets = [
-  #(11, '2011',  3500,  'Nu2-Pythia8/Sim09h/Trig0x40760037/Reco14c/Stripping21r1p2Filtered', 'B2KSHH.STRIP.DST'),
+  (17, '2017',  6500,  'Nu1.6-25ns-Pythia8/Sim09h/Trig0x62661709/Reco17/Turbo04a-WithTurcal/Stripping29r2p1Filtered', 'B2KSHH.STRIP.DST')
+]%}
+
+#(11, '2011',  3500,  'Nu2-Pythia8/Sim09h/Trig0x40760037/Reco14c/Stripping21r1p2Filtered', 'B2KSHH.STRIP.DST'),
   #(12, '2012a',  4000,  'Nu2.5-Pythia8/Sim09j/Trig0x4097003d/Reco14c/Stripping21r0p2Filtered', 'B2KSHH.STRIP.DST'),
   #(12, '2012b', 4000, 'Nu2.5-Pythia8/Sim09j/Trig0x409f0045/Reco14c/Stripping21r0p2Filtered', 'B2KSHH.STRIP.DST'),
   #(15, '2015',  6500,  'Nu1.6-25ns-Pythia8/Sim09h/Trig0x411400a2/Reco15a/Turbo02/Stripping24r2Filtered', 'B2KSHH.STRIP.DST'),
   #(16, '2016', 6500,  'Nu1.6-25ns-Pythia8/Sim09h/Trig0x6139160F/Reco16/Turbo03a/Stripping28r2Filtered', 'B2KSHH.STRIP.DST'),
-  (17, '2017',  6500,  'Nu1.6-25ns-Pythia8/Sim09h/Trig0x62661709/Reco17/Turbo04a-WithTurcal/Stripping29r2p1Filtered', 'B2KSHH.STRIP.DST'),
   #(18, '2018', 6500,  'Nu1.6-25ns-Pythia8/Sim09h/Trig0x617d18a4/Reco18/Turbo05-WithTurcal/Stripping34r0p1Filtered', 'B2KSHH.STRIP.DST'),
-]%}
-
 
 
 {%- set evttypes = [
-- 
GitLab


From 502b29692f572b4cfda153654585ab4997fcb4b1 Mon Sep 17 00:00:00 2001
From: Edoardo Mariani <edoardo.mariani@cern.ch>
Date: Mon, 20 Jan 2025 09:36:33 +0100
Subject: [PATCH 14/18] Update info.yaml

---
 bd2kkks_data/info.yaml | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/bd2kkks_data/info.yaml b/bd2kkks_data/info.yaml
index 2a01f8c202..571380c7b4 100644
--- a/bd2kkks_data/info.yaml
+++ b/bd2kkks_data/info.yaml
@@ -10,7 +10,13 @@ defaults:
 
 
 {%- set MCdatasets = [
-  (17, '2017',  6500,  'Nu1.6-25ns-Pythia8/Sim09h/Trig0x62661709/Reco17/Turbo04a-WithTurcal/Stripping29r2p1Filtered', 'B2KSHH.STRIP.DST')
+  (11, '2011',  3500,  'Nu2-Pythia8/Sim09h/Trig0x40760037/Reco14c/Stripping21r1p2Filtered', 'B2KSHH.STRIP.DST'),
+  (12, '2012a',  4000,  'Nu2.5-Pythia8/Sim09j/Trig0x4097003d/Reco14c/Stripping21r0p2Filtered', 'B2KSHH.STRIP.DST'),
+  (12, '2012b', 4000, 'Nu2.5-Pythia8/Sim09j/Trig0x409f0045/Reco14c/Stripping21r0p2Filtered', 'B2KSHH.STRIP.DST'),
+  (15, '2015',  6500,  'Nu1.6-25ns-Pythia8/Sim09h/Trig0x411400a2/Reco15a/Turbo02/Stripping24r2Filtered', 'B2KSHH.STRIP.DST'),
+  (16, '2016', 6500,  'Nu1.6-25ns-Pythia8/Sim09h/Trig0x6139160F/Reco16/Turbo03a/Stripping28r2Filtered', 'B2KSHH.STRIP.DST'),
+  (17, '2017',  6500,  'Nu1.6-25ns-Pythia8/Sim09h/Trig0x62661709/Reco17/Turbo04a-WithTurcal/Stripping29r2p1Filtered', 'B2KSHH.STRIP.DST'),
+  (18, '2018', 6500,  'Nu1.6-25ns-Pythia8/Sim09h/Trig0x617d18a4/Reco18/Turbo05-WithTurcal/Stripping34r0p1Filtered', 'B2KSHH.STRIP.DST'),
 ]%}
 
 #(11, '2011',  3500,  'Nu2-Pythia8/Sim09h/Trig0x40760037/Reco14c/Stripping21r1p2Filtered', 'B2KSHH.STRIP.DST'),
-- 
GitLab


From c174cfbfa9bbfe5befb75149b76ff2356b9004d7 Mon Sep 17 00:00:00 2001
From: Edoardo Mariani <edoardo.mariani@cern.ch>
Date: Mon, 20 Jan 2025 16:40:51 +0100
Subject: [PATCH 15/18] Update info.yaml

---
 bd2kkks_data/info.yaml | 6 ------
 1 file changed, 6 deletions(-)

diff --git a/bd2kkks_data/info.yaml b/bd2kkks_data/info.yaml
index 571380c7b4..42048c8908 100644
--- a/bd2kkks_data/info.yaml
+++ b/bd2kkks_data/info.yaml
@@ -10,13 +10,7 @@ defaults:
 
 
 {%- set MCdatasets = [
-  (11, '2011',  3500,  'Nu2-Pythia8/Sim09h/Trig0x40760037/Reco14c/Stripping21r1p2Filtered', 'B2KSHH.STRIP.DST'),
-  (12, '2012a',  4000,  'Nu2.5-Pythia8/Sim09j/Trig0x4097003d/Reco14c/Stripping21r0p2Filtered', 'B2KSHH.STRIP.DST'),
-  (12, '2012b', 4000, 'Nu2.5-Pythia8/Sim09j/Trig0x409f0045/Reco14c/Stripping21r0p2Filtered', 'B2KSHH.STRIP.DST'),
-  (15, '2015',  6500,  'Nu1.6-25ns-Pythia8/Sim09h/Trig0x411400a2/Reco15a/Turbo02/Stripping24r2Filtered', 'B2KSHH.STRIP.DST'),
-  (16, '2016', 6500,  'Nu1.6-25ns-Pythia8/Sim09h/Trig0x6139160F/Reco16/Turbo03a/Stripping28r2Filtered', 'B2KSHH.STRIP.DST'),
   (17, '2017',  6500,  'Nu1.6-25ns-Pythia8/Sim09h/Trig0x62661709/Reco17/Turbo04a-WithTurcal/Stripping29r2p1Filtered', 'B2KSHH.STRIP.DST'),
-  (18, '2018', 6500,  'Nu1.6-25ns-Pythia8/Sim09h/Trig0x617d18a4/Reco18/Turbo05-WithTurcal/Stripping34r0p1Filtered', 'B2KSHH.STRIP.DST'),
 ]%}
 
 #(11, '2011',  3500,  'Nu2-Pythia8/Sim09h/Trig0x40760037/Reco14c/Stripping21r1p2Filtered', 'B2KSHH.STRIP.DST'),
-- 
GitLab


From b0aa422a8ad5efef97cba9475ce01e1c59759012 Mon Sep 17 00:00:00 2001
From: Edoardo Mariani <edoardo.mariani@cern.ch>
Date: Mon, 20 Jan 2025 16:41:38 +0100
Subject: [PATCH 16/18] Update B2hhKS_MC_opt_DD.py

-- 
GitLab


From 661644717593610c63fdaf018ed07183db6e89c7 Mon Sep 17 00:00:00 2001
From: Edoardo Mariani <edoardo.mariani@cern.ch>
Date: Wed, 22 Jan 2025 15:52:27 +0100
Subject: [PATCH 17/18] Update info.yaml

---
 bd2kkks_data/info.yaml | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/bd2kkks_data/info.yaml b/bd2kkks_data/info.yaml
index 42048c8908..571380c7b4 100644
--- a/bd2kkks_data/info.yaml
+++ b/bd2kkks_data/info.yaml
@@ -10,7 +10,13 @@ defaults:
 
 
 {%- set MCdatasets = [
+  (11, '2011',  3500,  'Nu2-Pythia8/Sim09h/Trig0x40760037/Reco14c/Stripping21r1p2Filtered', 'B2KSHH.STRIP.DST'),
+  (12, '2012a',  4000,  'Nu2.5-Pythia8/Sim09j/Trig0x4097003d/Reco14c/Stripping21r0p2Filtered', 'B2KSHH.STRIP.DST'),
+  (12, '2012b', 4000, 'Nu2.5-Pythia8/Sim09j/Trig0x409f0045/Reco14c/Stripping21r0p2Filtered', 'B2KSHH.STRIP.DST'),
+  (15, '2015',  6500,  'Nu1.6-25ns-Pythia8/Sim09h/Trig0x411400a2/Reco15a/Turbo02/Stripping24r2Filtered', 'B2KSHH.STRIP.DST'),
+  (16, '2016', 6500,  'Nu1.6-25ns-Pythia8/Sim09h/Trig0x6139160F/Reco16/Turbo03a/Stripping28r2Filtered', 'B2KSHH.STRIP.DST'),
   (17, '2017',  6500,  'Nu1.6-25ns-Pythia8/Sim09h/Trig0x62661709/Reco17/Turbo04a-WithTurcal/Stripping29r2p1Filtered', 'B2KSHH.STRIP.DST'),
+  (18, '2018', 6500,  'Nu1.6-25ns-Pythia8/Sim09h/Trig0x617d18a4/Reco18/Turbo05-WithTurcal/Stripping34r0p1Filtered', 'B2KSHH.STRIP.DST'),
 ]%}
 
 #(11, '2011',  3500,  'Nu2-Pythia8/Sim09h/Trig0x40760037/Reco14c/Stripping21r1p2Filtered', 'B2KSHH.STRIP.DST'),
-- 
GitLab


From 9c11ce1f026ae806d51347d9772cc91a35ee730b Mon Sep 17 00:00:00 2001
From: Edoardo Mariani <edoardo.mariani@cern.ch>
Date: Thu, 23 Jan 2025 19:09:06 +0100
Subject: [PATCH 18/18] Update info.yaml

---
 bd2kkks_data/info.yaml | 4 ----
 1 file changed, 4 deletions(-)

diff --git a/bd2kkks_data/info.yaml b/bd2kkks_data/info.yaml
index 571380c7b4..6be6e84d4b 100644
--- a/bd2kkks_data/info.yaml
+++ b/bd2kkks_data/info.yaml
@@ -10,10 +10,6 @@ defaults:
 
 
 {%- set MCdatasets = [
-  (11, '2011',  3500,  'Nu2-Pythia8/Sim09h/Trig0x40760037/Reco14c/Stripping21r1p2Filtered', 'B2KSHH.STRIP.DST'),
-  (12, '2012a',  4000,  'Nu2.5-Pythia8/Sim09j/Trig0x4097003d/Reco14c/Stripping21r0p2Filtered', 'B2KSHH.STRIP.DST'),
-  (12, '2012b', 4000, 'Nu2.5-Pythia8/Sim09j/Trig0x409f0045/Reco14c/Stripping21r0p2Filtered', 'B2KSHH.STRIP.DST'),
-  (15, '2015',  6500,  'Nu1.6-25ns-Pythia8/Sim09h/Trig0x411400a2/Reco15a/Turbo02/Stripping24r2Filtered', 'B2KSHH.STRIP.DST'),
   (16, '2016', 6500,  'Nu1.6-25ns-Pythia8/Sim09h/Trig0x6139160F/Reco16/Turbo03a/Stripping28r2Filtered', 'B2KSHH.STRIP.DST'),
   (17, '2017',  6500,  'Nu1.6-25ns-Pythia8/Sim09h/Trig0x62661709/Reco17/Turbo04a-WithTurcal/Stripping29r2p1Filtered', 'B2KSHH.STRIP.DST'),
   (18, '2018', 6500,  'Nu1.6-25ns-Pythia8/Sim09h/Trig0x617d18a4/Reco18/Turbo05-WithTurcal/Stripping34r0p1Filtered', 'B2KSHH.STRIP.DST'),
-- 
GitLab