From 572930a810cff3801e1a98576389ff32001e9e09 Mon Sep 17 00:00:00 2001
From: "yichen.sun" <yichen.sun@cern.ch>
Date: Thu, 7 Nov 2024 14:11:01 +0100
Subject: [PATCH 1/3] DrellYan_161718

---
 DrellYan_Track/DV_Data_TRK_DIMUON.py | 204 +++++++++++++++++++++++
 DrellYan_Track/DV_MC_TRK_LM.py       | 238 +++++++++++++++++++++++++++
 DrellYan_Track/info.yaml             |  46 ++++++
 3 files changed, 488 insertions(+)
 create mode 100644 DrellYan_Track/DV_Data_TRK_DIMUON.py
 create mode 100644 DrellYan_Track/DV_MC_TRK_LM.py
 create mode 100644 DrellYan_Track/info.yaml

diff --git a/DrellYan_Track/DV_Data_TRK_DIMUON.py b/DrellYan_Track/DV_Data_TRK_DIMUON.py
new file mode 100644
index 0000000000..baaf44756b
--- /dev/null
+++ b/DrellYan_Track/DV_Data_TRK_DIMUON.py
@@ -0,0 +1,204 @@
+from os import environ
+from GaudiKernel.SystemOfUnits import *
+from Gaudi.Configuration import *
+from Configurables import GaudiSequencer, CombineParticles
+from Configurables import DecayTreeTuple, EventTuple, TupleToolTrigger, TupleToolTISTOS
+from Configurables import BackgroundCategory, TupleToolDecay, TupleToolVtxIsoln,TupleToolPid,EventCountHisto,TupleToolRecoStats,TupleToolDecayTreeFitter
+from Configurables import LoKi__Hybrid__TupleTool, TupleToolVeto
+from PhysConf.Selections import TupleSelection, CombineSelection
+from DecayTreeTuple.Configuration import *
+from PhysSelPython.Wrappers import AutomaticData,SelectionSequence
+from Configurables import GaudiSequencer
+
+## ------------------------------------------------------------------------- ##
+## ------------------------------------------------------------------------- ##
+## trigger lines
+mtl = [
+   # L0 lines
+   'L0MuonDecision',
+   'L0DiMuonDecision',
+   'L0MuonEWDecision',
+
+   # Hlt1 lines
+   "Hlt1DiMuonHighMassDecision",
+   "Hlt1DiMuonLowMassDecision",
+   "Hlt1DiMuonNoIPDecision",
+   "Hlt1SingleMuonNoIPDecision",
+   "Hlt1SingleMuonHighPTDecision",
+   "Hlt1TrackMuonDecision",
+  
+   # Hlt2 lines
+   "Hlt2SingleMuonDecision",
+   "Hlt2SingleMuonHighPTDecision",
+   "Hlt2SingleMuonVHighPTDecision",
+   "Hlt2DiMuonZDecision",
+   "Hlt2EWSingleMuonHighPtDecision",
+   "Hlt2EWSingleMuonLowPtDecision",
+   "Hlt2EWSingleMuonVHighPtDecision",
+   "Hlt2EWDiMuonDY1Decision",
+   "Hlt2EWDiMuonDY2Decision",
+   "Hlt2EWDiMuonDY3Decision",
+   "Hlt2EWDiMuonDY4Decision",
+   "Hlt2EWDiMuonDYSSDecision"
+   "Hlt2EWDiMuonZDecision"
+ ]
+
+tl= [
+   "TupleToolBremInfo", 
+   "TupleToolAngles", 
+   "TupleToolTrigger",
+   "TupleToolKinematic",
+   "TupleToolPid"      ,
+   "TupleToolTrackInfo" ,
+   "TupleToolPrimaries" ,
+   #"TupleToolPropertime",
+   "TupleToolEventInfo" ,
+   "TupleToolRecoStats" ,
+   "TupleToolGeometry" , 
+   "TupleToolTrackIsolation",
+   "TupleToolTrackPosition", 
+   "TupleToolConeIsolation",
+   "TupleToolVtxIsoln",
+   "TupleToolVeto",
+ ]
+z_decay = "Z0-> ^mu+ ^mu-"
+upsilon_decay = "Upsilon(1S) -> ^mu+ ^mu-"
+z_branches = {
+    "mup"     : "Z0 -> ^mu+  mu-",
+    "mum"     : "Z0 ->  mu+ ^mu-",
+    "ZBoson"  : "Z0 ->  mu+  mu-",
+}
+upsilon_branches = {
+    "mup"     : "Upsilon(1S) -> ^mu+  mu-",
+    "mum"     : "Upsilon(1S) ->  mu+ ^mu-",
+    "ZBoson"  : "Upsilon(1S) ->  mu+  mu-",
+}
+
+## ------------------------------------------------------------------------- ##
+## ------------------------------------------------------------------------- ##
+"""
+    Lines of interest:
+
+    TrackEffMuonTT_JpsiLine1       : Jpsi-> mu mu, long: minus, muonTT: plus
+    TrackEffMuonTT_JpsiLine2       : Jpsi-> mu mu, long: plus, muonTT: minus
+
+    TrackEffMuonTT_UpsilonLine1    : Upsilon-> mu mu, long: minus, muonTT: plus
+    TrackEffMuonTT_UpsilonLine2    : Upsilon-> mu mu, long: plus, muonTT: minus
+
+    TrackEffMuonTT_ZLine1          : Z-> mu mu, long: minus, muonTT: plus
+    TrackEffMuonTT_ZLine2          : Z-> mu mu, long: plus, muonTT: minus
+
+"""
+## W: reco from StdAllLooseMuons
+ZLine1_location="/Event/Dimuon/Phys/TrackEffMuonTT_ZLine1/Particles" 
+ZLine2_location="/Event/Dimuon/Phys/TrackEffMuonTT_ZLine2/Particles"
+UpsilonLine1_location="/Event/Dimuon/Phys/TrackEffMuonTT_UpsilonLine1/Particles"
+UpsilonLine2_location="/Event/Dimuon/Phys/TrackEffMuonTT_UpsilonLine2/Particles"
+ZLine1_input = AutomaticData(ZLine1_location)
+ZLine2_input = AutomaticData(ZLine2_location)
+UpsilonLine1_input = AutomaticData(UpsilonLine1_location)
+UpsilonLine2_input = AutomaticData(UpsilonLine2_location)
+## ------------------------------------------------------------------------- ##
+## DY:
+tuple_ZLine1 = TupleSelection(
+        "ZLine1",
+        [ZLine1_input],
+        Decay = z_decay,
+        Branches = z_branches )
+tuple_ZLine2 = TupleSelection(
+        "ZLine2",
+        [ZLine2_input],
+        Decay = z_decay,
+        Branches = z_branches )
+tuple_UpsilonLine1 = TupleSelection(
+        "UpsilonLine1",
+        [UpsilonLine1_input],
+        Decay = upsilon_decay,
+        Branches = upsilon_branches )
+tuple_UpsilonLine2 = TupleSelection(
+        "UpsilonLine2",
+        [UpsilonLine2_input],
+        Decay = upsilon_decay,
+        Branches = upsilon_branches )
+
+## define a list of tuples
+ztuples = [ tuple_ZLine1, tuple_ZLine2, tuple_UpsilonLine1, tuple_UpsilonLine2 ]
+
+## ------------------------------------------------------------------------- ##
+## ------------------------------------------------------------------------- ##
+## add algorithms
+for tpm in ztuples:
+    tpm.ToolList += tl
+
+    tool = tpm.addTupleTool(TupleToolTISTOS)
+    tool.Verbose=True
+    tool.VerboseL0=True
+    tool.VerboseHlt1=True
+    tool.VerboseHlt2= True
+    tool.FillL0  = True
+    tool.FillHlt1  = True
+    tool.FillHlt2  = True
+    tool.OutputLevel = INFO
+    tool.TriggerList = mtl
+
+    # solve TISTOS problems[2]  2017/9/14 10:00
+    from Configurables import TriggerTisTos
+    #tool = tpm.addTupleTool(TupleToolTISTOS)
+    tool.addTool(TriggerTisTos())
+
+    ## disable CALO hit matching
+    tool.TriggerTisTos.TOSFracEcal = 0.
+    tool.TriggerTisTos.TOSFracHcal = 0.
+    tool.TriggerTisTos.PropertiesPrint = True
+    ## disable muon hit matching  (change TOSFracMu)
+    tool.TriggerTisTos.TOSFracMuon = 0.
+    tool.TriggerTisTos.PropertiesPrint = True
+
+    from Configurables import LoKi__Hybrid__TupleTool
+    LoKi_All =  LoKi__Hybrid__TupleTool( 'LoKi_All')
+    LoKi_All.Preambulo = ["from LoKiTracks.decorators import *"]
+    LoKi_All.Variables =  {
+        "LoKi_ITClusters": "TRFUN(TrIDC('isIT'))",
+        "LoKi_OTClusters": "TRFUN(TrIDC('isOT'))",
+        "LoKi_TTClusters": "TRFUN(TrIDC('isTT'))",
+        "LoKi_VeloClusters":"TRFUN(TrIDC('isVelo'))",
+        "LoKi_TRCHI2DOF":"TRCHI2DOF",
+        "LoKi_MIPCHI2DV" : "MIPCHI2DV(PRIMARY)",
+        "LoKi_MIPDV" : "MIPDV(PRIMARY)",
+        "LoKi_PIDmu" : "PIDmu",
+        "LoKi_Q"     : "Q",
+        "LoKi_ISMUON" : "switch(ISMUON,1,0)",
+        "LoKi_INMUON": "PPINFO(LHCb.ProtoParticle.InAccMuon,-1)",
+        "LoKi_HcalE" : "PPINFO(LHCb.ProtoParticle.CaloHcalE,-1)",
+        "LoKi_EcalE" : "PPINFO(LHCb.ProtoParticle.CaloEcalE,-1)",
+        "LoKi_PERR2":"PERR2"
+    }
+
+    tpm.mup.addTupleTool(LoKi_All)
+    tpm.mum.addTupleTool(LoKi_All)
+
+## ------------------------------------------------------------------------- ##
+## ------------------------------------------------------------------------- ##
+seq_ZLine1     = SelectionSequence('SEQ_ZLine1',     tuple_ZLine1)
+seq_ZLine2     = SelectionSequence('SEQ_ZLine2',     tuple_ZLine2)
+seq_UpsilonLine1     = SelectionSequence('SEQ_UpsilonLine1',     tuple_UpsilonLine1)
+seq_UpsilonLine2     = SelectionSequence('SEQ_UpsilonLine2',     tuple_UpsilonLine2)
+## ------------------------------------------------------------------------- ##
+## ------------------------------------------------------------------------- ##
+## DaVinci
+from Configurables import DaVinci
+DaVinci().EvtMax    = -1          # Number of events
+DaVinci().PrintFreq = 5000
+DaVinci().SkipEvents = 0                 # Events to skip
+#DaVinci().InputType = 'DST'
+#DaVinci().DataType  = "2018"
+#DaVinci().Lumi = True
+#DaVinci().Simulation   =  False
+
+from Configurables import CondDB
+CondDB( LatestGlobalTagByDataType = "2018" )
+
+#DaVinci().TupleFile = "Tuple.root"          # Ntuple
+DaVinci().UserAlgorithms = [ seq_ZLine1.sequence(), seq_ZLine2.sequence(), seq_UpsilonLine1.sequence(), seq_UpsilonLine2.sequence()] 
+
+
diff --git a/DrellYan_Track/DV_MC_TRK_LM.py b/DrellYan_Track/DV_MC_TRK_LM.py
new file mode 100644
index 0000000000..6fed4f9830
--- /dev/null
+++ b/DrellYan_Track/DV_MC_TRK_LM.py
@@ -0,0 +1,238 @@
+from os import environ
+from GaudiKernel.SystemOfUnits import *
+from Gaudi.Configuration import *
+from Configurables import GaudiSequencer, CombineParticles
+from Configurables import DecayTreeTuple, EventTuple, TupleToolTrigger, TupleToolTISTOS
+from Configurables import BackgroundCategory, TupleToolDecay, TupleToolVtxIsoln,TupleToolPid,EventCountHisto,TupleToolRecoStats,TupleToolDecayTreeFitter
+from Configurables import LoKi__Hybrid__TupleTool, TupleToolVeto
+from PhysConf.Selections import TupleSelection, CombineSelection
+from DecayTreeTuple.Configuration import *
+from PhysSelPython.Wrappers import AutomaticData,SelectionSequence
+from Configurables import GaudiSequencer
+
+## ------------------------------------------------------------------------- ##
+## ------------------------------------------------------------------------- ##
+## trigger lines
+mtl = [
+   # L0 lines
+   'L0MuonDecision',
+   'L0DiMuonDecision',
+   'L0MuonEWDecision',
+
+   # Hlt1 lines
+   "Hlt1DiMuonHighMassDecision",
+   "Hlt1DiMuonLowMassDecision",
+   "Hlt1DiMuonNoIPDecision",
+   "Hlt1SingleMuonNoIPDecision",
+   "Hlt1SingleMuonHighPTDecision",
+   "Hlt1TrackMuonDecision",
+  
+   # Hlt2 lines
+   "Hlt2SingleMuonDecision",
+   "Hlt2SingleMuonHighPTDecision",
+   "Hlt2SingleMuonVHighPTDecision",
+   "Hlt2DiMuonZDecision",
+   "Hlt2EWSingleMuonHighPtDecision",
+   "Hlt2EWSingleMuonLowPtDecision",
+   "Hlt2EWSingleMuonVHighPtDecision",
+   "Hlt2EWDiMuonDY1Decision",
+   "Hlt2EWDiMuonDY2Decision",
+   "Hlt2EWDiMuonDY3Decision",
+   "Hlt2EWDiMuonDY4Decision",
+   "Hlt2EWDiMuonDYSSDecision"
+   "Hlt2EWDiMuonZDecision"
+ ]
+
+tl= [
+   "TupleToolBremInfo", 
+   "TupleToolAngles", 
+   "TupleToolTrigger",
+   "TupleToolKinematic",
+   "TupleToolPid"      ,
+   "TupleToolTrackInfo" ,
+   "TupleToolPrimaries" ,
+   #"TupleToolPropertime",
+   "TupleToolEventInfo" ,
+   "TupleToolRecoStats" ,
+   "TupleToolGeometry" , 
+   "TupleToolTrackIsolation",
+   "TupleToolTrackPosition", 
+   "TupleToolConeIsolation",
+   "TupleToolVtxIsoln",
+   "TupleToolVeto",
+ ]
+z_decay = "Z0-> ^mu+ ^mu-"
+upsilon_decay = "Upsilon(1S) -> ^mu+ ^mu-"
+z_branches = {
+    "mup"     : "Z0 -> ^mu+  mu-",
+    "mum"     : "Z0 ->  mu+ ^mu-",
+    "ZBoson"  : "Z0 ->  mu+  mu-",
+}
+upsilon_branches = {
+    "mup"     : "Upsilon(1S) -> ^mu+  mu-",
+    "mum"     : "Upsilon(1S) ->  mu+ ^mu-",
+    "ZBoson"  : "Upsilon(1S) ->  mu+  mu-",
+}
+
+## ------------------------------------------------------------------------- ##
+## ------------------------------------------------------------------------- ##
+"""
+    Lines of interest:
+
+    TrackEffMuonTT_JpsiLine1       : Jpsi-> mu mu, long: minus, muonTT: plus
+    TrackEffMuonTT_JpsiLine2       : Jpsi-> mu mu, long: plus, muonTT: minus
+
+    TrackEffMuonTT_UpsilonLine1    : Upsilon-> mu mu, long: minus, muonTT: plus
+    TrackEffMuonTT_UpsilonLine2    : Upsilon-> mu mu, long: plus, muonTT: minus
+
+    TrackEffMuonTT_ZLine1          : Z-> mu mu, long: minus, muonTT: plus
+    TrackEffMuonTT_ZLine2          : Z-> mu mu, long: plus, muonTT: minus
+
+"""
+## W: reco from StdAllLooseMuons
+ZLine1_location="/Event/AllStreams/Phys/TrackEffMuonTT_ZLine1/Particles" 
+ZLine2_location="/Event/AllStreams/Phys/TrackEffMuonTT_ZLine2/Particles"
+UpsilonLine1_location="/Event/AllStreams/Phys/TrackEffMuonTT_UpsilonLine1/Particles"
+UpsilonLine2_location="/Event/AllStreams/Phys/TrackEffMuonTT_UpsilonLine2/Particles"
+ZLine1_input = AutomaticData(ZLine1_location)
+ZLine2_input = AutomaticData(ZLine2_location)
+UpsilonLine1_input = AutomaticData(UpsilonLine1_location)
+UpsilonLine2_input = AutomaticData(UpsilonLine2_location)
+## ------------------------------------------------------------------------- ##
+## DY:
+tuple_ZLine1 = TupleSelection(
+        "ZLine1",
+        [ZLine1_input],
+        Decay = z_decay,
+        Branches = z_branches )
+tuple_ZLine2 = TupleSelection(
+        "ZLine2",
+        [ZLine2_input],
+        Decay = z_decay,
+        Branches = z_branches )
+tuple_UpsilonLine1 = TupleSelection(
+        "UpsilonLine1",
+        [UpsilonLine1_input],
+        Decay = upsilon_decay,
+        Branches = upsilon_branches )
+tuple_UpsilonLine2 = TupleSelection(
+        "UpsilonLine2",
+        [UpsilonLine2_input],
+        Decay = upsilon_decay,
+        Branches = upsilon_branches )
+
+## define a list of tuples
+ztuples = [ tuple_ZLine1, tuple_ZLine2, tuple_UpsilonLine1, tuple_UpsilonLine2 ]
+
+## ------------------------------------------------------------------------- ##
+## ------------------------------------------------------------------------- ##
+## add algorithms
+for tpm in ztuples:
+    tpm.ToolList += tl
+
+    tool = tpm.addTupleTool(TupleToolTISTOS)
+    tool.Verbose=True
+    tool.VerboseL0=True
+    tool.VerboseHlt1=True
+    tool.VerboseHlt2= True
+    tool.FillL0  = True
+    tool.FillHlt1  = True
+    tool.FillHlt2  = True
+    tool.OutputLevel = INFO
+    tool.TriggerList = mtl
+
+    # solve TISTOS problems[2]  2017/9/14 10:00
+    from Configurables import TriggerTisTos
+    #tool = tpm.addTupleTool(TupleToolTISTOS)
+    tool.addTool(TriggerTisTos())
+
+    ## disable CALO hit matching
+    tool.TriggerTisTos.TOSFracEcal = 0.
+    tool.TriggerTisTos.TOSFracHcal = 0.
+    tool.TriggerTisTos.PropertiesPrint = True
+    ## disable muon hit matching  (change TOSFracMu)
+    tool.TriggerTisTos.TOSFracMuon = 0.
+    tool.TriggerTisTos.PropertiesPrint = True
+
+    from Configurables import LoKi__Hybrid__TupleTool
+    LoKi_All =  LoKi__Hybrid__TupleTool( 'LoKi_All')
+    LoKi_All.Preambulo = ["from LoKiTracks.decorators import *"]
+    LoKi_All.Variables =  {
+        "LoKi_ITClusters": "TRFUN(TrIDC('isIT'))",
+        "LoKi_OTClusters": "TRFUN(TrIDC('isOT'))",
+        "LoKi_TTClusters": "TRFUN(TrIDC('isTT'))",
+        "LoKi_VeloClusters":"TRFUN(TrIDC('isVelo'))",
+        "LoKi_TRCHI2DOF":"TRCHI2DOF",
+        "LoKi_MIPCHI2DV" : "MIPCHI2DV(PRIMARY)",
+        "LoKi_MIPDV" : "MIPDV(PRIMARY)",
+        "LoKi_PIDmu" : "PIDmu",
+        "LoKi_Q"     : "Q",
+        "LoKi_ISMUON" : "switch(ISMUON,1,0)",
+        "LoKi_INMUON": "PPINFO(LHCb.ProtoParticle.InAccMuon,-1)",
+        "LoKi_HcalE" : "PPINFO(LHCb.ProtoParticle.CaloHcalE,-1)",
+        "LoKi_EcalE" : "PPINFO(LHCb.ProtoParticle.CaloEcalE,-1)",
+        "LoKi_PERR2":"PERR2"
+    }
+
+    tpm.mup.addTupleTool(LoKi_All)
+    tpm.mum.addTupleTool(LoKi_All)
+
+## ------------------------------------------------------------------------- ##
+## ------------------------------------------------------------------------- ##
+seq_ZLine1     = SelectionSequence('SEQ_ZLine1',     tuple_ZLine1)
+seq_ZLine2     = SelectionSequence('SEQ_ZLine2',     tuple_ZLine2)
+seq_UpsilonLine1     = SelectionSequence('SEQ_UpsilonLine1',     tuple_UpsilonLine1)
+seq_UpsilonLine2     = SelectionSequence('SEQ_UpsilonLine2',     tuple_UpsilonLine2)
+## ------------------------------------------------------------------------- ##
+## ------------------------------------------------------------------------- ##
+#fill the truth information
+mct = MCDecayTreeTuple('mct')
+mct.Decay = "Z0-> ^mu+ ^mu-"
+mct.Branches = {
+    "mup"     : "Z0 -> ^mu+  mu-",
+    "mum"     : "Z0 ->  mu+ ^mu-",
+    "ZBoson"  : "Z0 ->  mu+  mu-",
+   }
+
+
+mctl=[ 'MCTupleToolAngles',
+       'MCTupleToolHierarchy',
+       'MCTupleToolKinematic',
+       'MCTupleToolPrimaries',
+       'MCTupleToolReconstructed',
+       'MCTupleToolInteractions' ]
+mct.ToolList=mctl
+## ------------------------------------------------------------------------- ##
+## ------------------------------------------------------------------------- ##
+## DaVinci
+from Configurables import DaVinci
+DaVinci().EvtMax    = -1          # Number of events
+DaVinci().PrintFreq = 5000
+DaVinci().SkipEvents = 0                 # Events to skip
+#DaVinci().InputType = 'DST'
+#DaVinci().DataType  = "2018"
+#DaVinci().Lumi = False
+#DaVinci().Simulation   =  True
+
+#DaVinci().DDDBtag="dddb-20170721-3"
+#DaVinci().CondDBtag="sim-20190430-vc-md100"
+#DaVinci().TupleFile = "Tuple.root"          # Ntuple
+DaVinci().UserAlgorithms = [ seq_ZLine1.sequence(), seq_ZLine2.sequence(), seq_UpsilonLine1.sequence(), seq_UpsilonLine2.sequence(),mct] 
+
+
+#from GaudiConf import IOHelper
+######################### Test ##################################################
+'''
+# Use the local input data
+if DaVinci().Simulation == True:
+  DaVinci().EvtMax = 1000
+  IOHelper().inputFiles([
+    '/afs/cern.ch/user/s/sunyi/eos/18/MC_DY_5GeV_dst/00120488_00000004_7.AllStreams.dst'
+    ], clear=True)
+   #  '/afs/cern.ch/user/d/duliu/eos/Duanqing_work/xia_bookkeeping/test_DaVinci/00098349_00000001_1.b2dh.strip.dst'
+   #  ], clear=True)
+else:
+  IOHelper().inputFiles([
+     '/afs/cern.ch/user/d/duliu/eos/Duanqing_work/xia_bookkeeping/test_DaVinci/2018_Data.bhadroncompleteevent.dst'
+     ], clear=True)
+'''
diff --git a/DrellYan_Track/info.yaml b/DrellYan_Track/info.yaml
new file mode 100644
index 0000000000..a41f88f440
--- /dev/null
+++ b/DrellYan_Track/info.yaml
@@ -0,0 +1,46 @@
+defaults:
+    application: DaVinci/v46r10
+    wg: QEE
+    automatically_configure: yes    
+    inform:
+        - sunyi@cern.ch
+
+
+
+{%- set year_data = [
+    ('16',  'Reco16',  '28r2'),
+    ('17',  'Reco17',  '29r2'),
+    ('18',  'Reco18',  '34'),
+]%}
+
+{%- for year, reco, strip_version in year_data %}
+    {%- for polarity in ['MagDown', 'MagUp'] %}
+
+Data_Dimuon_{{year}}_{{polarity}}_tuple:
+    input:
+        bk_query: /LHCb/Collision{{year}}/Beam6500GeV-VeloClosed-{{polarity}}/Real Data/{{reco}}/Stripping{{strip_version}}/90000000/DIMUON.DST
+    options:
+        - DV_Data_TRK_DIMUON.py 
+    output: TRK_Data.root
+    
+  {%- endfor %}
+{%- endfor %}
+
+{%- set DY_MC = [
+    ('DY_5',       '42112012'),
+    ('DY_10',      '42112011'),
+    ('DY_20',      '42112014'),
+    ('DY_2040',    '42112015'),
+]%}
+{%- for MCtype, Decay_mode in DY_MC %}
+    {%- for polarity in ['MagDown', 'MagUp'] %}
+
+MC_{{MCtype}}_{{polarity}}_tuple:
+    input:
+        bk_query: /MC/2018/Beam6500GeV-2018-{{polarity}}-Nu1.6-25ns-Pythia8/Sim09j/Trig0x617d18a4/Reco18/Turbo05-WithTurcal/Stripping34NoPrescalingFlagged/{{Decay_mode}}/ALLSTREAMS.DST
+    output: TRK_MC.root
+    options:
+        - DV_MC_TRK_LM.py
+   {%- endfor %}
+{%- endfor %}
+
-- 
GitLab


From 435a384279ba9edd6445291d6c12cff6cbe120be Mon Sep 17 00:00:00 2001
From: "yichen.sun" <yichen.sun@cern.ch>
Date: Thu, 7 Nov 2024 14:33:27 +0100
Subject: [PATCH 2/3] DrellYan_161718

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

diff --git a/DrellYan_Track/info.yaml b/DrellYan_Track/info.yaml
index a41f88f440..6544dbc90d 100644
--- a/DrellYan_Track/info.yaml
+++ b/DrellYan_Track/info.yaml
@@ -29,7 +29,6 @@ Data_Dimuon_{{year}}_{{polarity}}_tuple:
 {%- set DY_MC = [
     ('DY_5',       '42112012'),
     ('DY_10',      '42112011'),
-    ('DY_20',      '42112014'),
     ('DY_2040',    '42112015'),
 ]%}
 {%- for MCtype, Decay_mode in DY_MC %}
-- 
GitLab


From 1c6bd202f0dfff51a3aac6cfb4bb26753bd7bb43 Mon Sep 17 00:00:00 2001
From: "yichen.sun" <yichen.sun@cern.ch>
Date: Fri, 22 Nov 2024 09:15:33 +0100
Subject: [PATCH 3/3] mct trk eff

---
 DrellYan_Track/DV_Data_TRK_DIMUON.py          | 204 ------------------
 .../DV_MC_TRK_LM.py                           |  32 +--
 DrellYan_Track_v1/DV_MC_TRK_LM_mct.py         | 108 ++++++++++
 .../info.yaml                                 |  22 +-
 4 files changed, 125 insertions(+), 241 deletions(-)
 delete mode 100644 DrellYan_Track/DV_Data_TRK_DIMUON.py
 rename {DrellYan_Track => DrellYan_Track_v1}/DV_MC_TRK_LM.py (91%)
 create mode 100644 DrellYan_Track_v1/DV_MC_TRK_LM_mct.py
 rename {DrellYan_Track => DrellYan_Track_v1}/info.yaml (53%)

diff --git a/DrellYan_Track/DV_Data_TRK_DIMUON.py b/DrellYan_Track/DV_Data_TRK_DIMUON.py
deleted file mode 100644
index baaf44756b..0000000000
--- a/DrellYan_Track/DV_Data_TRK_DIMUON.py
+++ /dev/null
@@ -1,204 +0,0 @@
-from os import environ
-from GaudiKernel.SystemOfUnits import *
-from Gaudi.Configuration import *
-from Configurables import GaudiSequencer, CombineParticles
-from Configurables import DecayTreeTuple, EventTuple, TupleToolTrigger, TupleToolTISTOS
-from Configurables import BackgroundCategory, TupleToolDecay, TupleToolVtxIsoln,TupleToolPid,EventCountHisto,TupleToolRecoStats,TupleToolDecayTreeFitter
-from Configurables import LoKi__Hybrid__TupleTool, TupleToolVeto
-from PhysConf.Selections import TupleSelection, CombineSelection
-from DecayTreeTuple.Configuration import *
-from PhysSelPython.Wrappers import AutomaticData,SelectionSequence
-from Configurables import GaudiSequencer
-
-## ------------------------------------------------------------------------- ##
-## ------------------------------------------------------------------------- ##
-## trigger lines
-mtl = [
-   # L0 lines
-   'L0MuonDecision',
-   'L0DiMuonDecision',
-   'L0MuonEWDecision',
-
-   # Hlt1 lines
-   "Hlt1DiMuonHighMassDecision",
-   "Hlt1DiMuonLowMassDecision",
-   "Hlt1DiMuonNoIPDecision",
-   "Hlt1SingleMuonNoIPDecision",
-   "Hlt1SingleMuonHighPTDecision",
-   "Hlt1TrackMuonDecision",
-  
-   # Hlt2 lines
-   "Hlt2SingleMuonDecision",
-   "Hlt2SingleMuonHighPTDecision",
-   "Hlt2SingleMuonVHighPTDecision",
-   "Hlt2DiMuonZDecision",
-   "Hlt2EWSingleMuonHighPtDecision",
-   "Hlt2EWSingleMuonLowPtDecision",
-   "Hlt2EWSingleMuonVHighPtDecision",
-   "Hlt2EWDiMuonDY1Decision",
-   "Hlt2EWDiMuonDY2Decision",
-   "Hlt2EWDiMuonDY3Decision",
-   "Hlt2EWDiMuonDY4Decision",
-   "Hlt2EWDiMuonDYSSDecision"
-   "Hlt2EWDiMuonZDecision"
- ]
-
-tl= [
-   "TupleToolBremInfo", 
-   "TupleToolAngles", 
-   "TupleToolTrigger",
-   "TupleToolKinematic",
-   "TupleToolPid"      ,
-   "TupleToolTrackInfo" ,
-   "TupleToolPrimaries" ,
-   #"TupleToolPropertime",
-   "TupleToolEventInfo" ,
-   "TupleToolRecoStats" ,
-   "TupleToolGeometry" , 
-   "TupleToolTrackIsolation",
-   "TupleToolTrackPosition", 
-   "TupleToolConeIsolation",
-   "TupleToolVtxIsoln",
-   "TupleToolVeto",
- ]
-z_decay = "Z0-> ^mu+ ^mu-"
-upsilon_decay = "Upsilon(1S) -> ^mu+ ^mu-"
-z_branches = {
-    "mup"     : "Z0 -> ^mu+  mu-",
-    "mum"     : "Z0 ->  mu+ ^mu-",
-    "ZBoson"  : "Z0 ->  mu+  mu-",
-}
-upsilon_branches = {
-    "mup"     : "Upsilon(1S) -> ^mu+  mu-",
-    "mum"     : "Upsilon(1S) ->  mu+ ^mu-",
-    "ZBoson"  : "Upsilon(1S) ->  mu+  mu-",
-}
-
-## ------------------------------------------------------------------------- ##
-## ------------------------------------------------------------------------- ##
-"""
-    Lines of interest:
-
-    TrackEffMuonTT_JpsiLine1       : Jpsi-> mu mu, long: minus, muonTT: plus
-    TrackEffMuonTT_JpsiLine2       : Jpsi-> mu mu, long: plus, muonTT: minus
-
-    TrackEffMuonTT_UpsilonLine1    : Upsilon-> mu mu, long: minus, muonTT: plus
-    TrackEffMuonTT_UpsilonLine2    : Upsilon-> mu mu, long: plus, muonTT: minus
-
-    TrackEffMuonTT_ZLine1          : Z-> mu mu, long: minus, muonTT: plus
-    TrackEffMuonTT_ZLine2          : Z-> mu mu, long: plus, muonTT: minus
-
-"""
-## W: reco from StdAllLooseMuons
-ZLine1_location="/Event/Dimuon/Phys/TrackEffMuonTT_ZLine1/Particles" 
-ZLine2_location="/Event/Dimuon/Phys/TrackEffMuonTT_ZLine2/Particles"
-UpsilonLine1_location="/Event/Dimuon/Phys/TrackEffMuonTT_UpsilonLine1/Particles"
-UpsilonLine2_location="/Event/Dimuon/Phys/TrackEffMuonTT_UpsilonLine2/Particles"
-ZLine1_input = AutomaticData(ZLine1_location)
-ZLine2_input = AutomaticData(ZLine2_location)
-UpsilonLine1_input = AutomaticData(UpsilonLine1_location)
-UpsilonLine2_input = AutomaticData(UpsilonLine2_location)
-## ------------------------------------------------------------------------- ##
-## DY:
-tuple_ZLine1 = TupleSelection(
-        "ZLine1",
-        [ZLine1_input],
-        Decay = z_decay,
-        Branches = z_branches )
-tuple_ZLine2 = TupleSelection(
-        "ZLine2",
-        [ZLine2_input],
-        Decay = z_decay,
-        Branches = z_branches )
-tuple_UpsilonLine1 = TupleSelection(
-        "UpsilonLine1",
-        [UpsilonLine1_input],
-        Decay = upsilon_decay,
-        Branches = upsilon_branches )
-tuple_UpsilonLine2 = TupleSelection(
-        "UpsilonLine2",
-        [UpsilonLine2_input],
-        Decay = upsilon_decay,
-        Branches = upsilon_branches )
-
-## define a list of tuples
-ztuples = [ tuple_ZLine1, tuple_ZLine2, tuple_UpsilonLine1, tuple_UpsilonLine2 ]
-
-## ------------------------------------------------------------------------- ##
-## ------------------------------------------------------------------------- ##
-## add algorithms
-for tpm in ztuples:
-    tpm.ToolList += tl
-
-    tool = tpm.addTupleTool(TupleToolTISTOS)
-    tool.Verbose=True
-    tool.VerboseL0=True
-    tool.VerboseHlt1=True
-    tool.VerboseHlt2= True
-    tool.FillL0  = True
-    tool.FillHlt1  = True
-    tool.FillHlt2  = True
-    tool.OutputLevel = INFO
-    tool.TriggerList = mtl
-
-    # solve TISTOS problems[2]  2017/9/14 10:00
-    from Configurables import TriggerTisTos
-    #tool = tpm.addTupleTool(TupleToolTISTOS)
-    tool.addTool(TriggerTisTos())
-
-    ## disable CALO hit matching
-    tool.TriggerTisTos.TOSFracEcal = 0.
-    tool.TriggerTisTos.TOSFracHcal = 0.
-    tool.TriggerTisTos.PropertiesPrint = True
-    ## disable muon hit matching  (change TOSFracMu)
-    tool.TriggerTisTos.TOSFracMuon = 0.
-    tool.TriggerTisTos.PropertiesPrint = True
-
-    from Configurables import LoKi__Hybrid__TupleTool
-    LoKi_All =  LoKi__Hybrid__TupleTool( 'LoKi_All')
-    LoKi_All.Preambulo = ["from LoKiTracks.decorators import *"]
-    LoKi_All.Variables =  {
-        "LoKi_ITClusters": "TRFUN(TrIDC('isIT'))",
-        "LoKi_OTClusters": "TRFUN(TrIDC('isOT'))",
-        "LoKi_TTClusters": "TRFUN(TrIDC('isTT'))",
-        "LoKi_VeloClusters":"TRFUN(TrIDC('isVelo'))",
-        "LoKi_TRCHI2DOF":"TRCHI2DOF",
-        "LoKi_MIPCHI2DV" : "MIPCHI2DV(PRIMARY)",
-        "LoKi_MIPDV" : "MIPDV(PRIMARY)",
-        "LoKi_PIDmu" : "PIDmu",
-        "LoKi_Q"     : "Q",
-        "LoKi_ISMUON" : "switch(ISMUON,1,0)",
-        "LoKi_INMUON": "PPINFO(LHCb.ProtoParticle.InAccMuon,-1)",
-        "LoKi_HcalE" : "PPINFO(LHCb.ProtoParticle.CaloHcalE,-1)",
-        "LoKi_EcalE" : "PPINFO(LHCb.ProtoParticle.CaloEcalE,-1)",
-        "LoKi_PERR2":"PERR2"
-    }
-
-    tpm.mup.addTupleTool(LoKi_All)
-    tpm.mum.addTupleTool(LoKi_All)
-
-## ------------------------------------------------------------------------- ##
-## ------------------------------------------------------------------------- ##
-seq_ZLine1     = SelectionSequence('SEQ_ZLine1',     tuple_ZLine1)
-seq_ZLine2     = SelectionSequence('SEQ_ZLine2',     tuple_ZLine2)
-seq_UpsilonLine1     = SelectionSequence('SEQ_UpsilonLine1',     tuple_UpsilonLine1)
-seq_UpsilonLine2     = SelectionSequence('SEQ_UpsilonLine2',     tuple_UpsilonLine2)
-## ------------------------------------------------------------------------- ##
-## ------------------------------------------------------------------------- ##
-## DaVinci
-from Configurables import DaVinci
-DaVinci().EvtMax    = -1          # Number of events
-DaVinci().PrintFreq = 5000
-DaVinci().SkipEvents = 0                 # Events to skip
-#DaVinci().InputType = 'DST'
-#DaVinci().DataType  = "2018"
-#DaVinci().Lumi = True
-#DaVinci().Simulation   =  False
-
-from Configurables import CondDB
-CondDB( LatestGlobalTagByDataType = "2018" )
-
-#DaVinci().TupleFile = "Tuple.root"          # Ntuple
-DaVinci().UserAlgorithms = [ seq_ZLine1.sequence(), seq_ZLine2.sequence(), seq_UpsilonLine1.sequence(), seq_UpsilonLine2.sequence()] 
-
-
diff --git a/DrellYan_Track/DV_MC_TRK_LM.py b/DrellYan_Track_v1/DV_MC_TRK_LM.py
similarity index 91%
rename from DrellYan_Track/DV_MC_TRK_LM.py
rename to DrellYan_Track_v1/DV_MC_TRK_LM.py
index 6fed4f9830..4a48b48780 100644
--- a/DrellYan_Track/DV_MC_TRK_LM.py
+++ b/DrellYan_Track_v1/DV_MC_TRK_LM.py
@@ -158,20 +158,9 @@ for tpm in ztuples:
     LoKi_All =  LoKi__Hybrid__TupleTool( 'LoKi_All')
     LoKi_All.Preambulo = ["from LoKiTracks.decorators import *"]
     LoKi_All.Variables =  {
-        "LoKi_ITClusters": "TRFUN(TrIDC('isIT'))",
-        "LoKi_OTClusters": "TRFUN(TrIDC('isOT'))",
-        "LoKi_TTClusters": "TRFUN(TrIDC('isTT'))",
-        "LoKi_VeloClusters":"TRFUN(TrIDC('isVelo'))",
-        "LoKi_TRCHI2DOF":"TRCHI2DOF",
-        "LoKi_MIPCHI2DV" : "MIPCHI2DV(PRIMARY)",
-        "LoKi_MIPDV" : "MIPDV(PRIMARY)",
-        "LoKi_PIDmu" : "PIDmu",
-        "LoKi_Q"     : "Q",
-        "LoKi_ISMUON" : "switch(ISMUON,1,0)",
-        "LoKi_INMUON": "PPINFO(LHCb.ProtoParticle.InAccMuon,-1)",
-        "LoKi_HcalE" : "PPINFO(LHCb.ProtoParticle.CaloHcalE,-1)",
-        "LoKi_EcalE" : "PPINFO(LHCb.ProtoParticle.CaloEcalE,-1)",
-        "LoKi_PERR2":"PERR2"
+        'ETA' : 'ETA',
+        'PHI' : 'PHI',
+
     }
 
     tpm.mup.addTupleTool(LoKi_All)
@@ -195,13 +184,25 @@ mct.Branches = {
    }
 
 
-mctl=[ 'MCTupleToolAngles',
+mctl=[ 'LoKi::Hybrid::MCTupleTool/MCLoKiTool',
+        'MCTupleToolAngles',
        'MCTupleToolHierarchy',
        'MCTupleToolKinematic',
        'MCTupleToolPrimaries',
        'MCTupleToolReconstructed',
        'MCTupleToolInteractions' ]
 mct.ToolList=mctl
+from Configurables import LoKi__Hybrid__MCTupleTool
+MCLoKiTool = LoKi__Hybrid__MCTupleTool( 'MCLoKiTool' )
+mct.addTool( MCLoKiTool, name = 'MCLoKiTool')
+mct.MCLoKiTool.Variables = {
+  'TRUEID'  : 'MCID',
+  'TRUEETA' : 'MCETA',
+  'TRUEPHI' : 'MCPHI',
+  'TRUEP'   : 'MCP'
+}
+
+
 ## ------------------------------------------------------------------------- ##
 ## ------------------------------------------------------------------------- ##
 ## DaVinci
@@ -213,7 +214,6 @@ DaVinci().SkipEvents = 0                 # Events to skip
 #DaVinci().DataType  = "2018"
 #DaVinci().Lumi = False
 #DaVinci().Simulation   =  True
-
 #DaVinci().DDDBtag="dddb-20170721-3"
 #DaVinci().CondDBtag="sim-20190430-vc-md100"
 #DaVinci().TupleFile = "Tuple.root"          # Ntuple
diff --git a/DrellYan_Track_v1/DV_MC_TRK_LM_mct.py b/DrellYan_Track_v1/DV_MC_TRK_LM_mct.py
new file mode 100644
index 0000000000..160e9ef2fa
--- /dev/null
+++ b/DrellYan_Track_v1/DV_MC_TRK_LM_mct.py
@@ -0,0 +1,108 @@
+from os import environ
+from GaudiKernel.SystemOfUnits import *
+from Gaudi.Configuration import *
+from Configurables import GaudiSequencer, CombineParticles
+from Configurables import DecayTreeTuple, EventTuple, TupleToolTrigger, TupleToolTISTOS
+from Configurables import BackgroundCategory, TupleToolDecay, TupleToolVtxIsoln,TupleToolPid,EventCountHisto,TupleToolRecoStats,TupleToolDecayTreeFitter
+from Configurables import LoKi__Hybrid__TupleTool, TupleToolVeto
+from PhysConf.Selections import TupleSelection, CombineSelection
+from DecayTreeTuple.Configuration import *
+from PhysSelPython.Wrappers import AutomaticData,SelectionSequence
+from Configurables import GaudiSequencer
+
+## ------------------------------------------------------------------------- ##
+## ------------------------------------------------------------------------- ##
+## trigger lines
+mtl = [
+   # L0 lines
+   'L0MuonDecision',
+   'L0DiMuonDecision',
+   'L0MuonEWDecision',
+
+   # Hlt1 lines
+   "Hlt1DiMuonHighMassDecision",
+   "Hlt1DiMuonLowMassDecision",
+   "Hlt1DiMuonNoIPDecision",
+   "Hlt1SingleMuonNoIPDecision",
+   "Hlt1SingleMuonHighPTDecision",
+   "Hlt1TrackMuonDecision",
+  
+   # Hlt2 lines
+   "Hlt2SingleMuonDecision",
+   "Hlt2SingleMuonHighPTDecision",
+   "Hlt2SingleMuonVHighPTDecision",
+   "Hlt2DiMuonZDecision",
+   "Hlt2EWSingleMuonHighPtDecision",
+   "Hlt2EWSingleMuonLowPtDecision",
+   "Hlt2EWSingleMuonVHighPtDecision",
+   "Hlt2EWDiMuonDY1Decision",
+   "Hlt2EWDiMuonDY2Decision",
+   "Hlt2EWDiMuonDY3Decision",
+   "Hlt2EWDiMuonDY4Decision",
+   "Hlt2EWDiMuonDYSSDecision"
+   "Hlt2EWDiMuonZDecision"
+ ]
+
+## ------------------------------------------------------------------------- ##
+## ------------------------------------------------------------------------- ##
+#fill the truth information
+mct = MCDecayTreeTuple('mct')
+mct.Decay = "Z0-> ^mu+ ^mu-"
+mct.Branches = {
+    "mup"     : "Z0 -> ^mu+  mu-",
+    "mum"     : "Z0 ->  mu+ ^mu-",
+    "ZBoson"  : "Z0 ->  mu+  mu-",
+   }
+
+
+mctl=[ 'LoKi::Hybrid::MCTupleTool/MCLoKiTool',
+        'MCTupleToolAngles',
+       'MCTupleToolHierarchy',
+       'MCTupleToolKinematic',
+       'MCTupleToolPrimaries',
+       'MCTupleToolReconstructed',
+       'MCTupleToolInteractions' ]
+mct.ToolList=mctl
+from Configurables import LoKi__Hybrid__MCTupleTool
+MCLoKiTool = LoKi__Hybrid__MCTupleTool( 'MCLoKiTool' )
+mct.addTool( MCLoKiTool, name = 'MCLoKiTool')
+mct.MCLoKiTool.Variables = {
+  'TRUEID'  : 'MCID',
+  'TRUEETA' : 'MCETA',
+  'TRUEPHI' : 'MCPHI',
+  'TRUEP'   : 'MCP'
+}
+
+## ------------------------------------------------------------------------- ##
+## ------------------------------------------------------------------------- ##
+## DaVinci
+from Configurables import DaVinci
+DaVinci().EvtMax    = -1          # Number of events
+DaVinci().PrintFreq = 5000
+DaVinci().SkipEvents = 0                 # Events to skip
+#DaVinci().InputType = 'DST'
+#DaVinci().DataType  = "2018"
+#DaVinci().Lumi = False
+#DaVinci().Simulation   =  True
+#DaVinci().DDDBtag="dddb-20170721-3"
+#DaVinci().CondDBtag="sim-20190430-vc-md100"
+#DaVinci().TupleFile = "Tuple.root"          # Ntuple
+DaVinci().UserAlgorithms = [mct] 
+
+
+#from GaudiConf import IOHelper
+######################### Test ##################################################
+'''
+# Use the local input data
+if DaVinci().Simulation == True:
+  DaVinci().EvtMax = 1000
+  IOHelper().inputFiles([
+    '/afs/cern.ch/user/s/sunyi/eos/18/MC_DY_5GeV_dst/00120488_00000004_7.AllStreams.dst'
+    ], clear=True)
+   #  '/afs/cern.ch/user/d/duliu/eos/Duanqing_work/xia_bookkeeping/test_DaVinci/00098349_00000001_1.b2dh.strip.dst'
+   #  ], clear=True)
+else:
+  IOHelper().inputFiles([
+     '/afs/cern.ch/user/d/duliu/eos/Duanqing_work/xia_bookkeeping/test_DaVinci/2018_Data.bhadroncompleteevent.dst'
+     ], clear=True)
+'''
diff --git a/DrellYan_Track/info.yaml b/DrellYan_Track_v1/info.yaml
similarity index 53%
rename from DrellYan_Track/info.yaml
rename to DrellYan_Track_v1/info.yaml
index 6544dbc90d..55c9861b94 100644
--- a/DrellYan_Track/info.yaml
+++ b/DrellYan_Track_v1/info.yaml
@@ -6,26 +6,6 @@ defaults:
         - sunyi@cern.ch
 
 
-
-{%- set year_data = [
-    ('16',  'Reco16',  '28r2'),
-    ('17',  'Reco17',  '29r2'),
-    ('18',  'Reco18',  '34'),
-]%}
-
-{%- for year, reco, strip_version in year_data %}
-    {%- for polarity in ['MagDown', 'MagUp'] %}
-
-Data_Dimuon_{{year}}_{{polarity}}_tuple:
-    input:
-        bk_query: /LHCb/Collision{{year}}/Beam6500GeV-VeloClosed-{{polarity}}/Real Data/{{reco}}/Stripping{{strip_version}}/90000000/DIMUON.DST
-    options:
-        - DV_Data_TRK_DIMUON.py 
-    output: TRK_Data.root
-    
-  {%- endfor %}
-{%- endfor %}
-
 {%- set DY_MC = [
     ('DY_5',       '42112012'),
     ('DY_10',      '42112011'),
@@ -39,7 +19,7 @@ MC_{{MCtype}}_{{polarity}}_tuple:
         bk_query: /MC/2018/Beam6500GeV-2018-{{polarity}}-Nu1.6-25ns-Pythia8/Sim09j/Trig0x617d18a4/Reco18/Turbo05-WithTurcal/Stripping34NoPrescalingFlagged/{{Decay_mode}}/ALLSTREAMS.DST
     output: TRK_MC.root
     options:
-        - DV_MC_TRK_LM.py
+        - DV_MC_TRK_LM_mct.py
    {%- endfor %}
 {%- endfor %}
 
-- 
GitLab