From aa98efd6a03833dbe4c88dc53f95b088fda2a04e Mon Sep 17 00:00:00 2001 From: Chenxu Yu <yuc@lxplus955.cern.ch> Date: Tue, 25 Jun 2024 10:00:06 +0200 Subject: [PATCH 01/15] BandQ_MCBuds_NoMuonLines --- BandQ_MCBuds_NoMuonLines/AddHlt2/newHlt2.py | 83 +++ BandQ_MCBuds_NoMuonLines/AddHlt2/newlines.py | 366 +++++++++++++ ...allen_mc_hlt1_pp_matching_no_ut_1000KHz.py | 8 + BandQ_MCBuds_NoMuonLines/dv_mc.py | 64 +++ BandQ_MCBuds_NoMuonLines/info.yaml | 102 ++++ BandQ_MCBuds_NoMuonLines/make_dtf.py | 265 +++++++++ BandQ_MCBuds_NoMuonLines/moore_mc_turbo.py | 74 +++ BandQ_MCBuds_NoMuonLines/tupling_maker.py | 351 ++++++++++++ BandQ_MCBuds_NoMuonLines/tupling_maker_new.py | 513 ++++++++++++++++++ 9 files changed, 1826 insertions(+) create mode 100644 BandQ_MCBuds_NoMuonLines/AddHlt2/newHlt2.py create mode 100644 BandQ_MCBuds_NoMuonLines/AddHlt2/newlines.py create mode 100644 BandQ_MCBuds_NoMuonLines/allen_mc_hlt1_pp_matching_no_ut_1000KHz.py create mode 100644 BandQ_MCBuds_NoMuonLines/dv_mc.py create mode 100644 BandQ_MCBuds_NoMuonLines/info.yaml create mode 100644 BandQ_MCBuds_NoMuonLines/make_dtf.py create mode 100644 BandQ_MCBuds_NoMuonLines/moore_mc_turbo.py create mode 100644 BandQ_MCBuds_NoMuonLines/tupling_maker.py create mode 100644 BandQ_MCBuds_NoMuonLines/tupling_maker_new.py diff --git a/BandQ_MCBuds_NoMuonLines/AddHlt2/newHlt2.py b/BandQ_MCBuds_NoMuonLines/AddHlt2/newHlt2.py new file mode 100644 index 0000000000..d05c92d825 --- /dev/null +++ b/BandQ_MCBuds_NoMuonLines/AddHlt2/newHlt2.py @@ -0,0 +1,83 @@ +from PyConf import configurable + +from Moore.config import Hlt2Line, register_line_builder + +#get bandq builders +from Hlt2Conf.lines.bandq.builders.prefilters import make_prefilters +from Hlt2Conf.lines.bandq.builders import b_to_jpsiX_lines, \ + doublecharm, \ + b_for_spectroscopy +from Hlt2Conf.lines.bandq.builders import dps_lines +from Hlt2Conf.lines.bandq.builders import dimuon_lines +from Hlt2Conf.lines.bandq.builders import ccbargamma_conv_lines, ccbarmumu_lines +from Hlt2Conf.lines.bandq.builders import qqbar_to_hadrons +from Hlt2Conf.lines.bandq.builders import ppmumu_lines +from Hlt2Conf.lines.bandq.builders import bbaryon_to_lcdsX_lines +from Hlt2Conf.lines.bandq.builders import jpsi_to_lmdlmd_lines +from .AddHlt2 import b_to_jpsiX_NoMuonID +from Hlt2Conf.lines.bandq.builders import b_to_LcX_TT_lines +from Hlt2Conf.lines.charmonium_to_dimuon_detached import make_detached_jpsi +from Hlt2Conf.lines.bandq.builders.b_to_jpsiX_TT_lines import make_Lb2JpsiLambdaTT, make_Bd2JpsiKsTT +from Hlt2Conf.lines.bandq.builders.jpsi_to_lmdlmd_lines import make_lambdall, make_lambdadd, make_lambdatt +from Hlt2Conf.lines.b_to_open_charm.builders.d_builder import make_dsplus_to_kpkmpip #import this to force Lb2LcDs T-track line do the Ds sector long-track reconstruction and selection first. + +PROCESS = 'hlt2' +turbo_lines = {} +full_lines = {} + + +@register_line_builder(turbo_lines) +@configurable +def Bp2JpsiKp_NoMuonIDbak_line(name='Hlt2BandQ_Bp2JpsiKp_NoMuonID', + prescale=1, + persistreco=False): + """B+->Jpsi K+ without Muon-based PID cuts.""" + line_alg = b_to_jpsiX_NoMuonID.make_Bp2JpsiKp_NoMuonID() + return Hlt2Line( + name=name, + algs=make_prefilters() + [line_alg], + prescale=prescale, + persistreco=persistreco) + + +@register_line_builder(turbo_lines) +@configurable +def Bz2JpsiKpPim_NoMuonIDbak_line(name='Hlt2BandQ_Bz2JpsiKpPim_NoMuonID', + prescale=1, + persistreco=False): + """B0->Jpsi K+ pi- without Muon-based PID cuts. Cover the full KPi mass spectrum""" + line_alg = b_to_jpsiX_NoMuonID.make_Bz2JpsiKpPim_NoMuonID() + return Hlt2Line( + name=name, + algs=make_prefilters() + [line_alg], + prescale=prescale, + persistreco=persistreco) + + +#This is a back-up choice if the rate of Bz2JpsiKpPim_NoMuonID_line is found to be not acceptable during rate tuning in Feb. +#@register_line_builder(turbo_lines) +#@configurable +#def Bz2JpsiKst_NoMuonID_line(name='Hlt2BandQ_Bz2JpsiKst_NoMuonID', +# prescale=1, +# persistreco=False): +# """B0->Jpsi K*0 without Muon-based PID cuts. Focus on the K*(892) region""" +# line_alg = b_to_jpsiX_NoMuonID.make_Bz2JpsiKst_NoMuonID() +# return Hlt2Line( +# name=name, +# algs=make_prefilters() + [line_alg], +# prescale=prescale, +# persistreco=persistreco) + + +@register_line_builder(turbo_lines) +@configurable +def Bs2JpsiKpKm_NoMuonIDbak_line(name='Hlt2BandQ_Bs2JpsiKpKm_NoMuonID', + prescale=1, + persistreco=False): + """Bs0->Jpsi K+ K- without Muon-based PID cuts. Cover the full KPi mass spectrum""" + line_alg = b_to_jpsiX_NoMuonID.make_Bs2JpsiKpKm_NoMuonID() + return Hlt2Line( + name=name, + algs=make_prefilters() + [line_alg], + prescale=prescale, + persistreco=persistreco) diff --git a/BandQ_MCBuds_NoMuonLines/AddHlt2/newlines.py b/BandQ_MCBuds_NoMuonLines/AddHlt2/newlines.py new file mode 100644 index 0000000000..3376dcc1dc --- /dev/null +++ b/BandQ_MCBuds_NoMuonLines/AddHlt2/newlines.py @@ -0,0 +1,366 @@ +############################################################################### +# (c) Copyright 2022 CERN for the benefit of the LHCb Collaboration # +# # +# This software is distributed under the terms of the GNU General Public # +# Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". # +# # +# In applying this licence, CERN does not waive the privileges and immunities # +# granted to it by virtue of its status as an Intergovernmental Organization # +# or submit itself to any jurisdiction. # +############################################################################### +""" +A standalone builder for exclusive B+->Jpsi K+, B0->Jpsi K+ pi-, Bs->Jpsi K+ K- decays. +Do not cut on MUON-station-based MuonID info. +Use the line to perform data-driven check of MuonID performance. +Tight kinematic cuts to make rate under control. +""" +from GaudiKernel.SystemOfUnits import GeV, MeV, picosecond + +from RecoConf.reconstruction_objects import make_pvs + +from Hlt2Conf.algorithms_thor import ParticleFilter, ParticleCombiner +from Functors import require_all +from PyConf import configurable + +from Hlt2Conf.standard_particles import make_long_muons + +import Functors as F +from Functors.math import in_range + +from Hlt2Conf.lines.bandq.builders.charged_hadrons import make_detached_kaons, make_detached_pions + +#for ghost probNN: didn't perform online, as unknowing the quality of further data taking +@configurable +def make_NoMuonID_muons( + make_particles=make_long_muons, + name="bandq_NoMuonID_muons_{hash}", + # pt_min=300. * MeV, #?OK + pt_min=600. * MeV, + p_min=4 * GeV, + p_max=200. * GeV, + eta_min=2., + eta_max=5., + mipchi2dvprimary_min=9, + CHI2DOF_max=14.,#?OK + #pid=None): + pid=require_all(F.RICH_DLL_MU > -10, + F.CHI2DOF< CHI2DOF_max, + F.RICH_DLL_MU - F.RICH_DLL_K > -5.)): + + pvs = make_pvs() + + code = require_all(F.PT > pt_min, in_range(p_min, F.P, p_max), + in_range(eta_min, F.ETA, eta_max), + F.MINIPCHI2(pvs) > mipchi2dvprimary_min) + + if (pid is not None): + code &= pid + + return ParticleFilter(make_particles(), name=name, Cut=F.FILTER(code)) + + +@configurable +def make_detached_kaons_forB2JpsiX_NoMuonID( + make_particles=make_detached_kaons, + name="bandq_detached_kaons_forB2JpsiX_NoMuonID_{hash}", + # pt_min=300. * MeV, ?OK + pt_min=300. * MeV, + p_min=4 * GeV, + p_max=200. * GeV, + eta_min=2., + eta_max=5., + mipchi2dvprimary_min=9, + pid=(F.PID_K > 5.)): + pvs = make_pvs() + + code = require_all(F.PT > pt_min, in_range(p_min, F.P, p_max), + in_range(eta_min, F.ETA, eta_max), + F.MINIPCHI2(pvs) > mipchi2dvprimary_min) + + if (pid is not None): + code &= pid + + return ParticleFilter(make_particles(), name=name, Cut=F.FILTER(code)) + + +@configurable +def make_detached_kaons_forBp2JpsiKp_NoMuonID( + make_particles=make_detached_kaons, + name="bandq_detached_kaons_forB2JpsiX_NoMuonID_{hash}", + # pt_min=300. * MeV, ?OK + pt_min=500. * MeV, + p_min=4 * GeV, + p_max=200. * GeV, + eta_min=2., + eta_max=5., + mipchi2dvprimary_min=9, + pid=(F.PID_K > 5.)): + pvs = make_pvs() + + code = require_all(F.PT > pt_min, in_range(p_min, F.P, p_max), + in_range(eta_min, F.ETA, eta_max), + F.MINIPCHI2(pvs) > mipchi2dvprimary_min) + + if (pid is not None): + code &= pid + + return ParticleFilter(make_particles(), name=name, Cut=F.FILTER(code)) + + +@configurable +def make_detached_pions_forB2JpsiX_NoMuonID( + make_particles=make_detached_pions, + name="bandq_detached_pions_forB2JpsiX_NoMuonID_{hash}", + pt_min=200. * MeV, + p_min=3 * GeV, + p_max=200. * GeV, + eta_min=2., + eta_max=5., + mipchi2dvprimary_min=9, + pid=(F.PID_K < -5.)): + pvs = make_pvs() + + code = require_all(F.PT > pt_min, in_range(p_min, F.P, p_max), + in_range(eta_min, F.ETA, eta_max), + F.MINIPCHI2(pvs) > mipchi2dvprimary_min) + + if (pid is not None): + code &= pid + + return ParticleFilter(make_particles(), name=name, Cut=F.FILTER(code)) + + +@configurable +def make_detachedKPi_forB2JpsiX_NoMuonID( + kaons=make_detached_kaons_forB2JpsiX_NoMuonID, + pions=make_detached_pions_forB2JpsiX_NoMuonID, + name="bandq_detachedKPi_forB2JpsiX_NoMuonID_{hash}", + descriptor='[K*(892)0 -> K+ pi-]cc', + am_max=2500 * MeV, + # maxdocachi2=20., ?OK + maxdocachi2=20., + m_max=2450. * MeV, + bpvdls_min=3): + + pvs = make_pvs() + + combination_code = F.require_all(F.MASS < am_max, + F.MAXSDOCACHI2CUT(maxdocachi2)) + + vertex_code = F.require_all(in_range(m_min, F.MASS> m_max, F.BPVDLS(pvs) > bpvdls_min) + + return ParticleCombiner( + name=name, + Inputs=[kaons(), pions()], + DecayDescriptor=descriptor, + CombinationCut=combination_code, + CompositeCut=vertex_code) + + +@configurable +def make_detachedKst_forB2JpsiX_NoMuonID( + KPi_comb=make_detachedKPi_forB2JpsiX_NoMuonID, + name="bandq_detachedKst_forB2JpsiX_NoMuonID_{hash}", + #?OK + # m_min=800. * MeV, + # m_max=1000. * MeV): + m_min=750. * MeV, + m_max=1050. * MeV, + PT_min=400 * MeV, + CHI2DOF_max=12.): + + code = F.require_all(in_range(m_min, F.MASS, m_max), F.PT>PT_min, F.CHI2DOF<CHI2DOF_max) + + return ParticleFilter(KPi_comb(), name=name, Cut=F.FILTER(code)) + + +@configurable +def make_detachedKK_forB2JpsiX_NoMuonID( + kaons=make_detached_kaons_forB2JpsiX_NoMuonID, + name="bandq_detachedKK_forB2JpsiX_NoMuonID_{hash}", + descriptor='phi(1020) -> K+ K-', + am_max=2500 * MeV, + maxdocachi2=20., + m_max=2450. * MeV, + bpvdls_min=3): + + pvs = make_pvs() + + combination_code = F.require_all(F.MASS < am_max, + F.MAXSDOCACHI2CUT(maxdocachi2)) + + vertex_code = F.require_all(F.MASS < m_max, F.BPVDLS(pvs) > bpvdls_min) + + return ParticleCombiner( + name=name, + Inputs=[kaons(), kaons()], + DecayDescriptor=descriptor, + CombinationCut=combination_code, + CompositeCut=vertex_code) + + +@configurable +def make_detachedPhi_forB2JpsiX_NoMuonID( + KK_comb=make_detachedKK_forB2JpsiX_NoMuonID, + name="bandq_detachedPhi_forB2JpsiX_NoMuonID_{hash}", + # m_max=1300. * MeV): ?OK + CHI2DOF_max=12., + m_max=1100. * MeV, + PT_min=400. * MeV): + + code = F.require_all(F.MASS < m_max, F.PT > PT_min, F.CHI2DOF < CHI2DOF_max) + + return ParticleFilter(KK_comb(), name=name, Cut=F.FILTER(code)) + + +@configurable +def make_Jpsi_NoMuonID(muons=make_NoMuonID_muons, + name="bandq_Jpsi_NoMuonID_{hash}", + descriptor='J/psi(1S) -> mu+ mu-', + # am_min=2996. * MeV, + # am_max=3196. * MeV,?OK + am_min=2946. * MeV, + am_max=3246. * MeV, + apt_min=600 * MeV, + maxdocachi2=20., + # pt_min=1000 * MeV, ?OK + pt_min=1200 * MeV, + bpvdls_min=3, + CHI2DOF_max=16): + + pvs = make_pvs() + + combination_code = F.require_all( + in_range(am_min, F.MASS, am_max), F.MAXSDOCACHI2CUT(maxdocachi2), + (F.PT > apt_min), F.CHI2DOF<CHI2DOF_max) + + vertex_code = F.require_all( #remove mass cuts, add B-Jpsi mass cuts instead ?OK + (F.PT > pt_min), + F.BPVDLS(pvs) > bpvdls_min) + + return ParticleCombiner( + name=name, + Inputs=[muons(), muons()], + DecayDescriptor=descriptor, + CombinationCut=combination_code, + CompositeCut=vertex_code) + + +@configurable +def make_Bp2JpsiKp_NoMuonID(Jpsi=make_Jpsi_NoMuonID, + kaons=make_detached_kaons_forBp2JpsiKp_NoMuonID, + name="bandq_Bp2JpsiKp_NoMuonID_{hash}", + descriptor='[B+ -> J/psi(1S) K+]cc', + # am_min=5190. * MeV, + # am_max=5370. * MeV, ?OK + am_min=4950. * MeV, + am_max=5550. * MeV, + apt_min=1200 * MeV, + # m_min=5200. * MeV, + # m_max=5360. * MeV, + m_min=5000. * MeV, + m_max=5500. * MeV, + pt_min=1400 * MeV, + delta_m_min=2050*MeV,#?OK(also following 3 lines) + delta_m_max=2310*MeV, + bpv_dira_min=0.99985, # more severe + vtx_chi2pdof_max=12, + bpvltime_min=0.2 * picosecond): + + pvs = make_pvs() + + combination_code = F.require_all( + in_range(am_min, F.MASS, am_max), (F.PT > apt_min)) + + vertex_code = F.require_all( + in_range(m_min, F.MASS, m_max), F.CHI2DOF < vtx_chi2pdof_max, + (F.PT > pt_min), in_range(delta_m_min, F.MASS-F.CHILD(1,F.MASS), delta_m_max), + F.BPVLTIME(pvs) > bpvltime_min) + + return ParticleCombiner( + name=name, + Inputs=[Jpsi(), kaons()], + DecayDescriptor=descriptor, + CombinationCut=combination_code, + F.BPVDIRA(pvs) > bpv_dira_min, + CompositeCut=vertex_code) + + + +@configurable +def make_Bz2JpsiKst_NoMuonID(Jpsi=make_Jpsi_NoMuonID, + KPi_comb=make_detachedKst_forB2JpsiX_NoMuonID, + name="bandq_Bz2JpsiKst_NoMuonID_{hash}", + descriptor='[B0 -> K*(892)0 J/psi(1S)]cc', + am_min=4950. * MeV, + am_max=5550. * MeV, + apt_min=1200 * MeV, + m_min=5000. * MeV, + m_max=5500. * MeV, + pt_min=1400 * MeV, + delta_m_min=2050*MeV,#?OK (also following 3 lines) + delta_m_max=2310*MeV, + bpv_dira_min=0.9997, + vtx_chi2pdof_max=16, + bpvltime_min=0.2 * picosecond): + + pvs = make_pvs() + + combination_code = F.require_all( + in_range(am_min, F.MASS, am_max), (F.PT > apt_min)) + + vertex_code = F.require_all( + in_range(m_min, F.MASS, m_max), F.CHI2DOF < vtx_chi2pdof_max, + (F.PT > pt_min), in_range(delta_m_min, F.MASS-F.CHILD(1,F.MASS), delta_m_max), + F.BPVDIRA(pvs) > bpv_dira_min, + F.BPVLTIME(pvs) > bpvltime_min) + + return ParticleCombiner( + name=name, + Inputs=[KPi_comb(), Jpsi()], + DecayDescriptor=descriptor, + CombinationCut=combination_code, + CompositeCut=vertex_code) + + + + + +@configurable +def make_Bs2JpsiPhi_NoMuonID(Jpsi=make_Jpsi_NoMuonID, + KK_comb=make_detachedPhi_forB2JpsiX_NoMuonID, + name="bandq_Bs2JpsiPhi_NoMuonID_{hash}", + descriptor='B_s0 -> phi(1020) J/psi(1S)', + # am_min=5280. * MeV, + # am_max=5460. * MeV,?OK + am_min=5100. * MeV, + am_max=5640. * MeV, + apt_min=1200 * MeV, + # m_min=5290. * MeV, + # m_max=5450. * MeV, + m_min=5120. * MeV, + m_max=5620. * MeV, + pt_min=1400 * MeV, + vtx_chi2pdof_max=16, + delta_m_min=2150*MeV,#?OK + delta_m_max=2400*MeV, + bpv_dira_min=0.9997, + bpvltime_min=0.2 * picosecond): + + pvs = make_pvs() + + combination_code = F.require_all( + in_range(am_min, F.MASS, am_max), (F.PT > apt_min)) + + vertex_code = F.require_all( + in_range(m_min, F.MASS, m_max), F.CHI2DOF < vtx_chi2pdof_max, + (F.PT > pt_min), in_range(delta_m_min, F.MASS-F.CHILD(1,F.MASS), delta_m_max), + F.BPVDIRA(pvs) > bpv_dira_min, + F.BPVLTIME(pvs) > bpvltime_min) + + return ParticleCombiner( + name=name, + Inputs=[KK_comb(), Jpsi()], + DecayDescriptor=descriptor, + CombinationCut=combination_code, + CompositeCut=vertex_code) diff --git a/BandQ_MCBuds_NoMuonLines/allen_mc_hlt1_pp_matching_no_ut_1000KHz.py b/BandQ_MCBuds_NoMuonLines/allen_mc_hlt1_pp_matching_no_ut_1000KHz.py new file mode 100644 index 0000000000..2244cc4819 --- /dev/null +++ b/BandQ_MCBuds_NoMuonLines/allen_mc_hlt1_pp_matching_no_ut_1000KHz.py @@ -0,0 +1,8 @@ +from Moore import options, Options +from Moore.config import run_allen +from RecoConf.hlt1_allen import allen_gaudi_config as allen_sequence + +def main(options: Options, sequence : str = "hlt1_pp_matching_no_ut_1000KHz"): + with allen_sequence.bind(sequence=sequence): + return run_allen(options) + diff --git a/BandQ_MCBuds_NoMuonLines/dv_mc.py b/BandQ_MCBuds_NoMuonLines/dv_mc.py new file mode 100644 index 0000000000..5422517d71 --- /dev/null +++ b/BandQ_MCBuds_NoMuonLines/dv_mc.py @@ -0,0 +1,64 @@ +from .tupling_maker_new import mc_template, line_prefilter +from DaVinci import Options, make_config +# import yaml + +def Bz2JpsiKpPim_NoMuonID(options: Options): + decay_descriptor = { + "Bz": '[B0 -> (J/psi(1S) -> mu+ mu-) (K*(892)0 -> K+ pi-)]CC', + "Jpsi": '[B0 -> ^(J/psi(1S) -> mu+ mu-) (K*(892)0 -> K+ pi-)]CC', + "Kstar": '[B0 -> (J/psi(1S) -> mu+ mu-) ^(K*(892)0 -> K+ pi-)]CC', + "Kp": '[B0 -> (J/psi(1S) -> mu+ mu-) (K*(892)0 -> ^K+ pi-)]CC', + "pim": '[B0 -> (J/psi(1S) -> mu+ mu-) (K*(892)0 -> K+ ^pi-)]CC', + "mum": '[B0 -> (J/psi(1S) -> mu+ ^mu-) (K*(892)0 -> K+ pi-)]CC', + "mup": '[B0 -> (J/psi(1S) -> ^mu+ mu-) (K*(892)0 -> K+ pi-)]CC', + } + line_name = "Hlt2BandQ_Bz2JpsiKpPim_NoMuonID" + tuple_dir_name = "Bz2JpsiKpPim" + # with open("dv_Spruc.yaml", "r") as f: + # ANA_inpp = yaml.safe_load(f) + # decay_descriptor = ANA_inpp["decay_descriptor"] + # line_name = ANA_inpp["line_name"] + my_tuple = mc_template(decay_descriptor, line_name, True, [], ["Bz", "Jpsi", "Kstar"], ["Kp", "pim", "mup", "mum"],tuple_dir_name) + my_filter = line_prefilter(line_name) + return make_config(options, [my_filter, my_tuple]) + +def Bs2JpsiKpKm_NoMuonID(options: Options): + decay_descriptor = { + "Bs": '[B_s0 -> (J/psi(1S) -> mu+ mu-) (phi(1020) -> K+ K-)]CC', + "Jpsi": '[B_s0 -> ^(J/psi(1S) -> mu+ mu-) (phi(1020) -> K+ K-)]CC', + "phi": '[B_s0 -> (J/psi(1S) -> mu+ mu-) ^(phi(1020) -> K+ K-)]CC', + "Kp": '[B_s0 -> (J/psi(1S) -> mu+ mu-) (phi(1020) -> ^K+ K-)]CC', + "Km": '[B_s0 -> (J/psi(1S) -> mu+ mu-) (phi(1020) -> K+ ^K-)]CC', + "mum": '[B_s0 -> (J/psi(1S) -> mu+ ^mu-) (phi(1020) -> K+ K-)]CC', + "mup": '[B_s0 -> (J/psi(1S) -> ^mu+ mu-) (phi(1020) -> K+ K-)]CC', + } + line_name = "Hlt2BandQ_Bs2JpsiKpKm_NoMuonID" + tuple_dir_name = "Bs2JpsiKpKm" + # with open("dv_Spruc.yaml", "r") as f: + # ANA_inpp = yaml.safe_load(f) + # decay_descriptor = ANA_inpp["decay_descriptor"] + # line_name = ANA_inpp["line_name"] + # my_tuple = template(decay_descriptor, line_name, True, [], ["Bs", "Jpsi", "phi"], ["Kp", "Km", "mup","mum"]) + my_tuple = mc_template(decay_descriptor, line_name, True, [], ["Bs", "Jpsi", "phi"], ["Kp", "Km", "mup","mum"], tuple_dir_name) + my_filter = line_prefilter(line_name) + return make_config(options, [my_filter, my_tuple]) + +def Bp2JpsiKp_NoMuonID(options: Options): + decay_descriptor = { + "Bp": '[B+ -> (J/psi(1S) -> mu+ mu-) K+]CC', + "Jpsi": '[B+ -> ^(J/psi(1S) -> mu+ mu-) K+]CC', + "Kp": '[B+ -> (J/psi(1S) -> mu+ mu-) ^K+]CC', + "mum": '[B+ -> (J/psi(1S) -> mu+ ^mu-) K+]CC', + "mup": '[B+ -> (J/psi(1S) -> ^mu+ mu-) K+]CC', + } + line_name = "Hlt2BandQ_Bp2JpsiKp_NoMuonID" + tuple_dir_name = "Bp2JpsiKpKm" + # with open("dv_Spruc.yaml", "r") as f: + # ANA_inpp = yaml.safe_load(f) + # decay_descriptor = ANA_inpp["decay_descriptor"] + # line_name = ANA_inpp["line_name"] + my_tuple = mc_template(decay_descriptor, line_name, True, [], ["Bp", "Jpsi"], ["Kp", "mup","mum"], tuple_dir_name) + # my_tuple = template(decay_descriptor, line_name, True, [], ["Bp", "Jpsi"], ["Kp", "mup","mum"]) + my_filter = line_prefilter(line_name) + return make_config(options, [my_filter, my_tuple]) + diff --git a/BandQ_MCBuds_NoMuonLines/info.yaml b/BandQ_MCBuds_NoMuonLines/info.yaml new file mode 100644 index 0000000000..7720fe204e --- /dev/null +++ b/BandQ_MCBuds_NoMuonLines/info.yaml @@ -0,0 +1,102 @@ +defaults: + application: DaVinci/v64r6 + wg: BandQ + inform: + - sanqiang.qu@cern.ch + - mengzhen.wang@cern.ch + - jianqiao.wang@cern.ch + +# mc configuration +{%- set entrypoints = [ + ("Jpsi_NoMuonBp", "Bp2JpsiKp_NoMuonID", "12143001", "turbo", "TurboPass"), + ("Jpsi_NoMuonBs", "Bs2JpsiKpKm_NoMuonID", "13144011", "turbo", "TurboPass"), + ("Jpsi_NoMuonBz", "Bz2JpsiKpPim_NoMuonID", "11144001", "turbo", "TurboPass"), +]%} + +{%- set MC_conditions = [ + ("MagDown", "MagDown", "7.6", "7_6", "dddb-20240427", "sim10-2024.Q1.2-v1.1-md100", "24Q12", "2024", "2024.Q1.2", "Sim10d"), + ("MagDown", "MagDown", "4.3", "4_3", "dddb-20240427", "sim10-2024.Q1.2-v1.1-md100", "24Q12", "2024", "2024.Q1.2", "Sim10d"), + ("MagUp", "MagUp", "7.6", "7_6", "dddb-20240427", "sim10-2024.Q1.2-v1.1-mu100", "24Q12", "2024", "2024.Q1.2", "Sim10d"), + ("MagUp", "MagUp", "4.3", "4_3", "dddb-20240427", "sim10-2024.Q1.2-v1.1-mu100", "24Q12", "2024", "2024.Q1.2", "Sim10d"), +]%} + +{%- set hlt_conditions = [ + ("hlt1_pp_matching_no_ut_1000KHz", "hlt1v1"), +]%} + + +{%- set dv_platform_detdesc = "x86_64_v2-el9-gcc13+detdesc-opt" %} + + +{%- for module, channel, eventtype, fullturbo, dv_input_process in entrypoints %} + {%- for polarity_mc, polarity_mc_jobtitle, nu, n_u, dddb, conddb, mcversion_jobtitle, BKK_label1, BKK_label2, simversion in MC_conditions %} + {% for hlt1_condition, hlt1_condition_jobtitle in hlt_conditions %} + +MC_{{module}}_Nu{{n_u}}_{{polarity_mc_jobtitle}}_VPClose_{{mcversion_jobtitle}}_{{hlt1_condition_jobtitle}}_HLT1: + application: "Moore/v55r7@x86_64_v2-el9-gcc13+detdesc-opt" + input: + bk_query: "/MC/{{BKK_label1}}/Beam6800GeV-{{BKK_label2}}-{{ polarity_mc }}-Nu{{ nu }}-25ns-Pythia8/{{simversion}}/{{ eventtype }}/DIGI" + dq_flags: + - OK + keep_running: true + n_test_lfns: 1 + output: QQbar2mumu_MC24_HLT1.DST + options: + entrypoint: BandQ_MCBuds_NoMuonLines.allen_mc_{{hlt1_condition}}:main + extra_options: + input_raw_format: 0.5 + conddb_tag: {{ conddb }} + dddb_tag: {{ dddb }} + input_type: "ROOT" + output_type: "ROOT" + simulation: True + data_type: "Upgrade" + scheduler_legacy_mode: False + compression: + algorithm: ZSTD + level: 1 + max_buffer_size: 1048576 + +MC_{{module}}_Nu{{n_u}}_{{polarity_mc_jobtitle}}_VPClose_{{mcversion_jobtitle}}_{{hlt1_condition_jobtitle}}_HLT2: + application: "Moore/v55r7@x86_64_v2-el9-gcc13+detdesc-opt" + input: + job_name: MC_{{module}}_Nu{{n_u}}_{{polarity_mc_jobtitle}}_VPClose_{{mcversion_jobtitle}}_{{hlt1_condition_jobtitle}}_HLT1 + output: QQbar2mumu_MC24_HLT2_{{fullturbo}}.DST + options: + entrypoint: BandQ_MCBuds_NoMuonLines.moore_mc_{{fullturbo}}:main + extra_options: + conddb_tag: {{ conddb }} + dddb_tag: {{ dddb }} + input_type: "ROOT" + input_raw_format: 0.5 + output_type: "ROOT" + simulation: True + data_type: "Upgrade" + scheduler_legacy_mode: False + compression: + algorithm: ZSTD + level: 1 + max_buffer_size: 1048576 + + +MC_{{module}}_Nu{{n_u}}_{{polarity_mc_jobtitle}}_VPClose_{{mcversion_jobtitle}}_{{hlt1_condition_jobtitle}}_ROOT: + application: "DaVinci/v64r6@{{ dv_platform_detdesc }}" + input: + job_name: MC_{{module}}_Nu{{n_u}}_{{polarity_mc_jobtitle}}_VPClose_{{mcversion_jobtitle}}_{{hlt1_condition_jobtitle}}_HLT2 + output: QQbar2mumu_MC24_tuple.ROOT + options: + entrypoint: BandQ_MCBuds_NoMuonLines.dv_mc:{{channel}} + extra_options: + input_raw_format: 0.5 + dddb_tag: {{ dddb }} + conddb_tag: {{ conddb }} + input_type: ROOT + simulation: True + data_type: "Upgrade" + input_process: "{{dv_input_process}}" + input_stream: "bandq" + + + {%- endfor %} + {%- endfor %} +{%- endfor %} diff --git a/BandQ_MCBuds_NoMuonLines/make_dtf.py b/BandQ_MCBuds_NoMuonLines/make_dtf.py new file mode 100644 index 0000000000..efae1d910f --- /dev/null +++ b/BandQ_MCBuds_NoMuonLines/make_dtf.py @@ -0,0 +1,265 @@ +import Functors as F +from Functors.math import log + +from FunTuple import FunctorCollection +from FunTuple.functorcollections import ( + MCHierarchy, + MCPromptDecay, + Kinematics, + SelectionInfo, + HltTisTos, + MCVertexInfo, + MCKinematics, + ParticleID, #wrong variables PID_PI = 0, PROBNN_D = nan + EventInfo, + LHCInfo, + ParticleIsolation, + MCPrimaries, + MCReconstructed, + MCReconstructible, +) + +from DaVinciMCTools import MCTruthAndBkgCat, MCReconstructed, MCReconstructible +from PyConf.Algorithms import ParticleToSubcombinationsAlg +from DecayTreeFitter import DecayTreeFitter + +from DaVinci.algorithms import create_lines_filter +from PyConf.reading import get_particles +from FunTuple import FunTuple_Particles as Funtuple + + + +def make_basic_dtf_variables(pvs, data, DTF=None, pv_constraint=False, mass_constraint=False, particle_name=""): + variables = ( + FunctorCollection( + { + "TRCHI2DOF": F.CHI2DOF @ F.TRACK, + "ETA": F.ETA, + "PHI": F.PHI, + "TRGHOSTPROB": F.GHOSTPROB, + "BPVIPCHI2": F.BPVIPCHI2(pvs), + "BPVIP": F.BPVIP(pvs), + "BPVX": F.BPVX(pvs), + "BPVY": F.BPVY(pvs), + "BPVZ": F.BPVZ(pvs), + "TX" : F.TX, + "TY" : F.TY, + # "MINIPCHI2" : F.MINIPCHI2(pvs), + # "MINIP" : F.MINIP(pvs), + "KEY" : F.VALUE_OR(-1) @ F.OBJECT_KEY @ F.TRACK, + "CTB" : F.POSITION @ F.CLOSESTTOBEAM @ F.TRACK, + "TRACKPT": F.TRACK_PT, + "TRACKHISTORY": F.VALUE_OR(-1) @ F.TRACKHISTORY @ F.TRACK, + "QOVERP": F.QOVERP @ F.TRACK, + "NDOF": F.VALUE_OR(-1) @ F.NDOF @ F.TRACK, + } + ) + + Kinematics() + ) + + if(mass_constraint): + if(pv_constraint): # MASS + PV + dtf_variables_mass_pv = FunctorCollection({ + 'DTF_PV_M'+ particle_name + '_' + k: DTF(v) + for k, v in variables.get_thor_functors().items() + }) + return dtf_variables_mass_pv + else: # MASS + dtf_variables_mass = FunctorCollection( + {'DTF_M'+ particle_name + '_' + k: DTF(v) + for k, v in variables.get_thor_functors().items()}) + return dtf_variables_mass + + elif(pv_constraint): # PV + dtf_variables_pv = FunctorCollection({ + 'DTF_PV_' + k: DTF(v) + for k, v in variables.get_thor_functors().items() + }) + return dtf_variables_pv + + else: # NO MASS/PV + dtf_variables = FunctorCollection( + {'DTF_' + k: DTF(v) + for k, v in variables.get_thor_functors().items()}) + return dtf_variables + + +def make_composite_dtf_variables(pvs, data, DTF=None, pv_constraint=False, mass_constraint=False, particle_name=""): + variables = ( + FunctorCollection( + { + # "MAXPT": F.MAX(F.PT), + # "MINPT": F.MIN(F.PT), + # "SUMPT": F.SUM(F.PT), + # "MAXP": F.MAX(F.P), + # "MINP": F.MIN(F.P), + "BPVDIRA": F.BPVDIRA(pvs), + "VCHI2DOF": F.CHI2DOF, #CHI2VXNDOF + "BPVFDCHI2": F.BPVFDCHI2(pvs), + "BPVFD": F.BPVFD(pvs), + "BPVVDRHO": F.BPVVDRHO(pvs), + "BPVVDZ": F.BPVVDZ(pvs), + "BPVIPCHI2": F.BPVIPCHI2(pvs), + "BPVIP": F.BPVIP(pvs), + # "LOGBPVIPCHI2": log(F.BPVIPCHI2(pvs)), + "BPVLTIME": F.BPVLTIME(pvs), + # "MAXBPVIPCHI2": F.MAX(F.BPVIPCHI2(pvs)), #MAX_ + # "MINBPVIPCHI2": F.MIN(F.BPVIPCHI2(pvs)), + # "MAXBPVIP": F.MAX(F.BPVIP(pvs)), + # "MINBPVIP": F.MIN(F.BPVIP(pvs)), + "ETA": F.ETA, + "PHI": F.PHI, + "END_VX": F.END_VX, #END_ + "END_VY": F.END_VY, + "END_VZ": F.END_VZ, + "BPVX": F.BPVX(pvs), + "BPVY": F.BPVY(pvs), + "BPVZ": F.BPVZ(pvs), + "ALLPVFD" : F.ALLPV_FD(pvs), + "ALLPVIP" : F.ALLPV_IP(pvs), + + } + ) + + Kinematics() + ) + + addstring = "DTF" + if(pv_constraint): + addstring += '_PV' + if(mass_constraint): + addstring += '_M' + addstring += particle_name + + DTF_chi2ndof = FunctorCollection( + { + addstring+"_DTFCHI2": DTF.CHI2, + addstring+"_DTFNDOF": DTF.NDOF, + addstring+"_CTAU": DTF.CTAU, + addstring+"_CTAUERR": DTF.CTAUERR, + addstring+"_MERR": DTF.MASSERR, + } + ) + + if(mass_constraint): + if(pv_constraint): # MASS + PV + dtf_variables_mass_pv = FunctorCollection({ + 'DTF_PV_M'+ particle_name + '_' + k: DTF(v) + for k, v in variables.get_thor_functors().items() + }) + return dtf_variables_mass_pv+DTF_chi2ndof + else: # MASS + dtf_variables_mass = FunctorCollection( + {'DTF_M'+ particle_name + '_' + k: DTF(v) + for k, v in variables.get_thor_functors().items()}) + return dtf_variables_mass+DTF_chi2ndof + + elif(pv_constraint): # PV + dtf_variables_pv = FunctorCollection({ + 'DTF_PV_' + k: DTF(v) + for k, v in variables.get_thor_functors().items() + }) + return dtf_variables_pv+DTF_chi2ndof + + else: # NO MASS/PV + dtf_variables = FunctorCollection( + {'DTF_' + k: DTF(v) + for k, v in variables.get_thor_functors().items()}) + return dtf_variables+DTF_chi2ndof + + + +def make_dtf_variables(pvs, input_data, ptype): + + if ptype not in ["basic", "composite"]: + Exception(f"Need \'basic\' or \'composite\'. Got {ptype}") + + from DecayTreeFitter import DecayTreeFitter + + DTF = DecayTreeFitter( + name=f'DTF_{{hash}}', + input_particles=input_data) + + DTFvtx = DecayTreeFitter( + name=f'DTFvtx_{{hash}}', + input_particles=input_data, + input_pvs=pvs) + + DTFmassJpsi = DecayTreeFitter( + name=f'DTFmassJpsi_{{hash}}', + input_particles=input_data, + mass_constraints=["J/psi(1S)"]) + + DTFvtxmassJpsi = DecayTreeFitter( + name=f'DTFvtxmassJpsi_{{hash}}', + input_particles=input_data, + input_pvs=pvs, + mass_constraints=["J/psi(1S)"]) + + # DTFmassBcJpsi = DecayTreeFitter( + # name=f'DTFmassBcJpsi_{{hash}}', + # input_particles=input_data, + # mass_constraints=["B_c+","J/psi(1S)"]) + + # DTFvtxmassBcJpsi = DecayTreeFitter( + # name=f'DTFvtxmassBcJpsi_{{hash}}', + # input_particles=input_data, + # input_pvs=pvs, + # mass_constraints=["B_c+","J/psi(1S)"]) + + + if ptype == "basic": + dtf_vars = make_basic_dtf_variables(pvs, input_data, + DTF=DTF, + pv_constraint=False, + mass_constraint=False) + dtf_vars += make_basic_dtf_variables(pvs, input_data, + DTF=DTFvtx, + pv_constraint=True, + mass_constraint=False) + dtf_vars += make_basic_dtf_variables(pvs, input_data, + DTF=DTFmassJpsi, + pv_constraint=False, + mass_constraint=True, particle_name="Jpsi") + dtf_vars += make_basic_dtf_variables(pvs, input_data, + DTF=DTFvtxmassJpsi, + pv_constraint=True, + mass_constraint=True, particle_name="Jpsi") + # dtf_vars += make_basic_dtf_variables(pvs, input_data, + # DTF=DTFmassBcJpsi, + # pv_constraint=False, + # mass_constraint=True, particle_name="BcJpsi") + # dtf_vars += make_basic_dtf_variables(pvs, input_data, + # DTF=DTFvtxmassBcJpsi, + # pv_constraint=True, + # mass_constraint=True, particle_name="BcJpsi") + + return dtf_vars + + if ptype == "composite": + dtf_vars = make_composite_dtf_variables(pvs, input_data, + DTF=DTF, + pv_constraint=False, + mass_constraint=False) + dtf_vars += make_composite_dtf_variables(pvs, input_data, + DTF=DTFvtx, + pv_constraint=True, + mass_constraint=False) + dtf_vars += make_composite_dtf_variables(pvs, input_data, + DTF=DTFmassJpsi, + pv_constraint=False, + mass_constraint=True, particle_name="Jpsi") + dtf_vars += make_composite_dtf_variables(pvs, input_data, + DTF=DTFvtxmassJpsi, + pv_constraint=True, + mass_constraint=True, particle_name="Jpsi") + # dtf_vars += make_composite_dtf_variables(pvs, input_data, + # DTF=DTFmassBcJpsi, + # pv_constraint=False, + # mass_constraint=True, particle_name="BcJpsi") + # dtf_vars += make_composite_dtf_variables(pvs, input_data, + # DTF=DTFvtxmassBcJpsi, + # pv_constraint=True, + # mass_constraint=True, particle_name="BcJpsi") + + return dtf_vars + diff --git a/BandQ_MCBuds_NoMuonLines/moore_mc_turbo.py b/BandQ_MCBuds_NoMuonLines/moore_mc_turbo.py new file mode 100644 index 0000000000..f6b756e31c --- /dev/null +++ b/BandQ_MCBuds_NoMuonLines/moore_mc_turbo.py @@ -0,0 +1,74 @@ +from Moore import Options, run_moore +from RecoConf.global_tools import stateProvider_with_simplified_geom, trackMasterExtrapolator_with_simplified_geom +from RecoConf.reconstruction_objects import reconstruction +from RecoConf.hlt2_global_reco import reconstruction as hlt2_reconstruction, make_light_reco_pr_kf_without_UT +from RecoConf.hlt2_tracking import ( + make_TrackBestTrackCreator_tracks, + make_PrKalmanFilter_noUT_tracks, + make_PrKalmanFilter_Velo_tracks, + make_PrKalmanFilter_Seed_tracks, +) +from RecoConf.decoders import default_VeloCluster_source +from RecoConf.protoparticles import make_charged_protoparticles +from RecoConf.event_filters import require_gec +from Hlt2Conf.settings.defaults import get_default_hlt1_filter_code_for_hlt2 +from Moore.streams import Stream, Streams +from Hlt2Conf.lines.semileptonic import all_lines as full_lines # all full-stream lines +import sys + +from RecoConf.decoders import default_VeloCluster_source +from Moore.streams import Stream, Streams, DETECTORS +from Hlt2Conf.lines.charmonium_to_dimuon import JpsiToMuMu_line, Psi2SToMuMu_line +from Hlt2Conf.lines.rd.qqbar_to_ll import upsilon_to_mumu_line +from Hlt2Conf.lines.qee.dimuon_no_ip import dimuonnoip_massrange3_line, dimuonnoip_massrange4_line, dimuonnoip_massrange5_line +from Hlt2Conf.lines.bandq.hlt2_bandq import UpsilonToMuMuEMTF_line +from Hlt2Conf.lines.bandq import hlt2_turbo_lines as turbo_lines + +def make_streams(): + lines = [ + builder() for line_dict in [turbo_lines] + for builder in line_dict.values() + ] + streams = [ + # Stream( + # "full", + # lines=[builder() for builder in full_lines.values()], + # routing_bit=98, + # detectors=[] + # # detectors=DETECTORS - import from Moore.streams + # ), # Turbo or Full case - no detector raw banks, for TurCal add them as above. + # Add turbo lines as well if you like: + Stream( + "turbo", + lines = lines, + #lines=[dimuonnoip_massrange3_line(), dimuonnoip_massrange4_line(), dimuonnoip_massrange5_line(), JpsiToMuMu_line(), Psi2SToMuMu_line(), UpsilonToMuMuEMTF_line(), upsilon_to_mumu_line()], + routing_bit=99, + detectors=DETECTORS + ) + ] + return Streams(streams=streams) + +def main(options: Options): + public_tools = [ + trackMasterExtrapolator_with_simplified_geom(), + stateProvider_with_simplified_geom(), + ] + with reconstruction.bind(from_file=False), hlt2_reconstruction.bind(make_reconstruction=make_light_reco_pr_kf_without_UT),\ + require_gec.bind(skipUT=True),\ + default_VeloCluster_source.bind(bank_type="VPRetinaCluster"),\ + make_charged_protoparticles.bind(fill_probnn_defaults=True),\ + make_TrackBestTrackCreator_tracks.bind(max_ghost_prob=0.7, max_chi2ndof=sys.float_info.max),\ + make_PrKalmanFilter_Velo_tracks.bind(max_chi2ndof=5.),\ + make_PrKalmanFilter_noUT_tracks.bind(max_chi2ndof=4.),\ + make_PrKalmanFilter_Seed_tracks.bind(max_chi2ndof=6.),\ + get_default_hlt1_filter_code_for_hlt2.bind(code=r"Hlt1(?!PassthroughLargeEvent).*Decision"): + config = run_moore(options, make_streams, public_tools) +# with reconstruction.bind(from_file=False), hlt2_reconstruction.bind(make_reconstruction=make_light_reco_pr_kf_without_UT),\ +# require_gec.bind(skipUT=True),\ +# default_VeloCluster_source.bind(bank_type="VPRetinaCluster"),\ +# make_TrackBestTrackCreator_tracks.bind(max_ghost_prob=0.7, max_chi2ndof=sys.float_info.max),\ +# make_PrKalmanFilter_Velo_tracks.bind(max_chi2ndof=5.),\ +# make_PrKalmanFilter_noUT_tracks.bind(max_chi2ndof=4.),\ +# make_PrKalmanFilter_Seed_tracks.bind(max_chi2ndof=6.): +# config = run_moore(options, make_streams, public_tools) + return config diff --git a/BandQ_MCBuds_NoMuonLines/tupling_maker.py b/BandQ_MCBuds_NoMuonLines/tupling_maker.py new file mode 100644 index 0000000000..7086ca14e2 --- /dev/null +++ b/BandQ_MCBuds_NoMuonLines/tupling_maker.py @@ -0,0 +1,351 @@ +############################################################################### +# (c) Copyright 2021-2022 CERN for the benefit of the LHCb Collaboration # +# # +# This software is distributed under the terms of the GNU General Public # +# Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". # +# # +# In applying this licence, CERN does not waive the privileges and immunities # +# granted to it by virtue of its status as an Intergovernmental Organization # +# or submit itself to any jurisdiction. # +############################################################################### +""" +Read an HLT2 file and create an ntuple with the new DaVinci configuration. +""" +import Functors as F +import FunTuple.functorcollections as FC +from FunTuple import FunctorCollection +from FunTuple import FunTuple_Particles as Funtuple +from PyConf.reading import get_particles, get_pvs, get_rec_summary +from DaVinci.algorithms import create_lines_filter +from DaVinciMCTools import MCTruthAndBkgCat +from FunTuple.functorcollections import MCHierarchy, MCPrimaries, MCPromptDecay, Kinematics, SelectionInfo, HltTisTos, MCVertexInfo, MCKinematics, ParticleID, EventInfo +from PyConf.reading import get_odin # get_decreports, +from DecayTreeFitter import DecayTreeFitter +from Hlt2Conf.algorithms_thor import ParticleFilter +from GaudiKernel.SystemOfUnits import MeV +from .make_dtf import * + +_basic = "basic" +_composite = "composite" +_toplevel = "toplevel" + +def all_variables(pvs, mctruth, ptype, candidates=None, ftAlg=None): + """ + function that returns dictionary of functors that work. + + functors are listed in order of https://lhcbdoc.web.cern.ch/lhcbdoc/moore/master/selection/thor_functors_reference.html#module-Functo + """ + if ptype not in [_basic, _composite]: + Exception(f"I want {_basic} or {_composite}. Got {ptype}") + all_vars = FunctorCollection({}) + + comp = _composite == ptype or _toplevel == ptype # is composite + basic = _basic == ptype # is not composite + top = _toplevel == ptype # the B + + # First import everything that comes in functorcollections + all_vars += FC.Kinematics() + if basic: + all_vars += FC.ParticleID(extra_info=True) + + if comp: + all_vars.update({"ALV": F.ALV(Child1=1, Child2=2)}) + + if comp: # all these require a vertex + all_vars.update({"BPVCORRM": F.BPVCORRM(pvs)}) + all_vars.update({"BPVCORRMERR": F.BPVCORRMERR(pvs)}) + all_vars.update({"BPVDIRA": F.BPVDIRA(pvs)}) + all_vars.update({"BPVDLS": F.BPVDLS(pvs)}) + all_vars.update({"BPVETA": F.BPVETA(pvs)}) + all_vars.update({"BPVFD": F.BPVFD(pvs)}) + all_vars.update({"BPVFDCHI2": F.BPVFDCHI2(pvs)}) + all_vars.update({"BPVFDIR": F.BPVFDIR(pvs)}) + all_vars.update({"BPVFDVEC": F.BPVFDVEC(pvs)}) + + all_vars.update({"BPVIP": F.BPVIP(pvs)}) + all_vars.update({"BPVIPCHI2": F.BPVIPCHI2(pvs)}) + all_vars.update({"BPVX": F.BPVX(pvs)}) + all_vars.update({"BPVY": F.BPVY(pvs)}) + all_vars.update({"BPVZ": F.BPVZ(pvs)}) + + if comp: # all these require a vertex + all_vars.update({"ALLPV_FD": F.ALLPV_FD(pvs)}) + all_vars.update({"ALLPV_IP": F.ALLPV_IP(pvs)}) + all_vars.update({"BPVLTIME": F.BPVLTIME(pvs)}) + all_vars.update({"BPVVDRHO": F.BPVVDRHO(pvs)}) + all_vars.update({"BPVVDX": F.BPVVDX(pvs)}) + all_vars.update({"BPVVDY": F.BPVVDY(pvs)}) + all_vars.update({"BPVVDZ": F.BPVVDZ(pvs)}) + + all_vars.update({"CHARGE": F.CHARGE}) + all_vars.update({"CHI2": F.CHI2}) + all_vars.update({"CHI2DOF": F.CHI2DOF}) + + if top: # apply this only to B + all_vars.update({"CHILD1_PT": F.CHILD(1, F.PT)}) # example of CHILD + all_vars.update({"Ds_END_VZ": F.CHILD(1, F.END_VZ)}) + all_vars.update({"Delta_END_VZ_DsB0": F.CHILD(1, F.END_VZ) - F.END_VZ}) + + if comp: + all_vars.update({"DOCA": F.SDOCA(Child1=1, Child2=2)}) + all_vars.update({"DOCACHI2": F.SDOCACHI2(Child1=1, Child2=2)}) + all_vars.update({"END_VRHO": F.END_VRHO}) + all_vars.update({"END_VX": F.END_VX}) + all_vars.update({"END_VY": F.END_VY}) + all_vars.update({"END_VZ": F.END_VZ}) + all_vars.update({"NEWW_DIFF_MASS":F.MASS-F.CHILD(1,F.MASS)}) + + all_vars.update({"ETA": F.ETA}) + all_vars.update({"FOURMOMENTUM": F.FOURMOMENTUM}) + all_vars.update({"ISBASIC": F.ISBASICPARTICLE}) + + if basic: + all_vars.update({"GHOSTPROB": F.GHOSTPROB}) + all_vars.update({"ISMUON": F.ISMUON}) + all_vars.update({"INMUON": F.INMUON}) + all_vars.update({"INECAL": F.INECAL}) + all_vars.update({"INHCAL": F.INHCAL}) + all_vars.update({"HASBREM": F.HASBREM}) + all_vars.update({"BREMENERGY": F.BREMENERGY}) + all_vars.update({"BREMBENDCORR": F.BREMBENDCORR}) + all_vars.update({"BREMPIDE": F.BREMPIDE}) + all_vars.update({"ECALPIDE": F.ECALPIDE}) + all_vars.update({"ECALPIDMU": F.ECALPIDMU}) + all_vars.update({"HCALPIDE": F.HCALPIDE}) + all_vars.update({"HCALPIDMU": F.HCALPIDMU}) + all_vars.update({"ELECTRONSHOWEREOP": F.ELECTRONSHOWEREOP}) + all_vars.update({"CLUSTERMATCH": F.CLUSTERMATCH_CHI2}) + all_vars.update({"ELECTRONMATCH": F.ELECTRONMATCH_CHI2}) + all_vars.update({"BREMHYPOMATCH": F.BREMHYPOMATCH_CHI2}) + all_vars.update({"ELECTRONENERGY": F.ELECTRONENERGY}) + all_vars.update({"BREMHYPOENERGY": F.BREMHYPOENERGY}) + all_vars.update({"BREMHYPODELTAX": F.BREMHYPODELTAX}) + all_vars.update({"ELECTRONID": F.ELECTRONID}) + all_vars.update({"HCALEOP": F.HCALEOP}) + # Note: the observables for the two functors below are (TRACK_MOM_X, TRACK_MOM_Y, TRACK_MOM_Z}) + # and (TRACK_POS_CLOSEST_TO_BEAM_X, TRACK_POS_CLOSEST_TO_BEAM_Y, TRACK_POS_CLOSEST_TO_BEAM_Z), + # which is why the trailing underscore in the name is added i.e. "TRACK_MOM_" and "TRACK_POS_CLOSEST_TO_BEAM_" + all_vars.update({"TRACK_MOM_": F.TRACK_MOMVEC}) + all_vars.update({"TRACK_POS_CLOSESTTOBEAM_": F.TRACK_POSVEC_CLOSESTTOBEAM}) + + all_vars.update({"IS_ABS_ID_pi": F.IS_ABS_ID("pi+")}) + all_vars.update({"IS_ID_pi": F.IS_ID("pi-")}) + all_vars.update({"PDG_MASS_pi": F.PDG_MASS("pi+")}) + all_vars.update({"SIGNED_DELTA_MASS_pi": F.SIGNED_DELTA_MASS("pi+")}) + all_vars.update({"ABS_DELTA_MASS_pi": F.ABS_DELTA_MASS("pi+")}) + all_vars.update({"IS_NOT_H": F.IS_NOT_H}) + all_vars.update({"IS_PHOTON": F.IS_PHOTON}) + + # update ?OK + all_vars.update({"RICH_DLL_MU": F.RICH_DLL_MU}) + all_vars.update({"RICH_DLL_E": F.RICH_DLL_E}) + all_vars.update({"RICH_DLL_P": F.RICH_DLL_P}) + all_vars.update({"RICH_DLL_K": F.RICH_DLL_K}) + all_vars.update({"RICH_DLL_Pi": F.RICH_DLL_PI}) + + all_vars.update({"MASS": F.MASS}) + + if comp: + all_vars.update({"MAXPT": F.MAX(F.PT)}) + all_vars.update({"MAXDOCA": F.MAXSDOCA}) + all_vars.update({"MAXDOCACHI2": F.MAXSDOCACHI2}) + # the above in cut versions. + + if comp: + all_vars.update({"MINPT": F.MIN(F.PT)}) + all_vars.update({"MINIP": F.MINIP(pvs)}) + all_vars.update({"MINIPCHI2": F.MINIPCHI2(pvs)}) + + if basic: + all_vars.update({"TRACKPT": F.TRACK_PT}) + all_vars.update({"TRACKHISTORY": F.VALUE_OR(-1) @ F.TRACKHISTORY @ F.TRACK}) + all_vars.update({"QOVERP": F.QOVERP @ F.TRACK}) + all_vars.update({"NDOF": F.VALUE_OR(-1) @ F.NDOF @ F.TRACK}) + all_vars.update({"NFTHITS": F.VALUE_OR(-1) @ F.NFTHITS @ F.TRACK}) + all_vars.update({"NHITS": F.VALUE_OR(-1) @ F.NHITS @ F.TRACK}) + all_vars.update({"NUTHITS": F.VALUE_OR(-1) @ F.NUTHITS @ F.TRACK}) + all_vars.update({"NVPHITS": F.VALUE_OR(-1) @ F.NVPHITS @ F.TRACK}) + all_vars.update({"TRACKHASVELO": F.VALUE_OR(-1) @ F.TRACKHASVELO @ F.TRACK}) + all_vars.update({"TRACKHASUT": F.VALUE_OR(-1) @ F.TRACKHASUT @ F.TRACK}) + + all_vars.update({"OBJECT_KEY": F.OBJECT_KEY}) + + all_vars.update({"PHI": F.PHI}) + + all_vars.update({"ABS_PX": F.ABS @ F.PX}) + + all_vars.update({"REFERENCEPOINT_X": F.REFERENCEPOINT_X}) + all_vars.update({"REFERENCEPOINT_Y": F.REFERENCEPOINT_Y}) + all_vars.update({"REFERENCEPOINT_Z": F.REFERENCEPOINT_Z}) + + if comp: + all_vars.update({"SDOCA": F.SDOCA(1, 2)}) + all_vars.update({"SDOCACHI2": F.SDOCACHI2(1, 2)}) + if basic: + all_vars.update({"SHOWER_SHAPE": F.CALO_NEUTRAL_SHOWER_SHAPE}) + + if comp: + all_vars.update({"SUBCOMB12_MM": F.SUBCOMB(Functor=F.MASS, Indices=(1, 2))}) + all_vars.update({"SUMPT": F.SUM(F.PT)}) + + if basic: + all_vars.update({"TX": F.TX}) + all_vars.update({"TY": F.TY}) + + print(f"### For {ptype} returning variables {all_vars.functor_dict.keys()}") + return all_vars + + +def event_variables(PVs, ODIN, decreports, lines): + """ + event variables + """ + + evt_vars = FunctorCollection({}) + evt_vars += FC.EventInfo() + + evt_vars += FC.SelectionInfo(selection_type="Hlt2", trigger_lines=lines) + + if decreports: + evt_vars.update( + { + "DECISIONS": F.DECISIONS( + Lines=[bd2dsk_line + "Decision"], DecReports=decreports + ) + } + ) + evt_vars.update( + { + "DECREPORTS_FILTER": F.DECREPORTS_FILTER( + Lines=[bd2dsk_line + "Decision"], DecReports=decreports + ) + } + ) + + if ODIN: + evt_vars.update({"EVENTTYPE": F.EVENTTYPE(ODIN)}) + + evt_vars.update({"PV_SIZE": F.SIZE(PVs)}) + + if decreports: + evt_vars.update({"TCK": F.TCK(decreports)}) + + print(f"### For event returning variables {evt_vars.functor_dict.keys()}") + return evt_vars + + +def template(decay_descriptor, line_name, isturbo, Hlt2_decisions, composite_particles, daughter_particles, cutAdd=(F.MASS>1.*MeV)): + + evtpath_prefix = "/Event/Spruce/" + if isturbo: + evtpath_prefix = "/Event/HLT2/" + + PsiXXX_data_raw = get_particles(evtpath_prefix + f"{line_name}/Particles") + PsiXXX_data = ParticleFilter(PsiXXX_data_raw, Cut=F.FILTER(cutAdd) ) + + + pvs = get_pvs() + + Hlt1_decisions = [ # already contain Hlt1TrackMVADecision ?OK + 'Hlt1TrackMVADecision', 'Hlt1TwoTrackMVADecision', #'Hlt1D2KKDecision', + #'Hlt1D2KPiDecision', 'Hlt1D2PiPiDecision', + 'Hlt1DiMuonHighMassDecision', #'Hlt1DiMuonLowMassDecision', + #'Hlt1DiMuonSoftDecision', + #'Hlt1KsToPiPiDecision', 'Hlt1LowPtMuonDecision', + 'Hlt1LowPtDiMuonDecision', 'Hlt1SingleHighPtMuonDecision', + 'Hlt1TrackMuonMVADecision', "Hlt1DiMuonNoIP_SSDecision", + #"Hlt1DiMuonDrellYan_VLowMassDecision", + #"Hlt1DiMuonDrellYan_VLowMass_SSDecision", + #"Hlt1DiMuonDrellYanDecision", + #"Hlt1DiMuonDrellYan_SSDecision", + #"Hlt1DetJpsiToMuMuPosTagLineDecision", + #"Hlt1DetJpsiToMuMuNegTagLineDecision", + #"Hlt1TrackElectronMVADecision", + #"Hlt1SingleHighPtElectronDecision", + #"Hlt1DiElectronDisplacedDecision", + #"Hlt1SingleHighEtDecision", + #"Hlt1DiPhotonHighMassDecision", + #"Hlt1Pi02GammaGammaDecision", + #"Hlt1DiElectronHighMass_SSDecision", + #"Hlt1DiElectronHighMassDecision", + "Hlt1DiMuonNoIPDecision", + ] + + composite_variables = FunctorCollection({ + "END_VX_ERR":F.SQRT @ F.CALL(0,0) @ F.POS_COV_MATRIX @ F.ENDVERTEX, + "END_VY_ERR":F.SQRT @ F.CALL(1,1) @ F.POS_COV_MATRIX @ F.ENDVERTEX, + "END_VZ_ERR":F.SQRT @ F.CALL(2,2) @ F.POS_COV_MATRIX @ F.ENDVERTEX, + "BPVX_ERR": F.SQRT @ F.CALL(0,0) @ F.POS_COV_MATRIX @ F.BPV(pvs), + "BPVY_ERR": F.SQRT @ F.CALL(1,1) @ F.POS_COV_MATRIX @ F.BPV(pvs), + "BPVZ_ERR": F.SQRT @ F.CALL(2,2) @ F.POS_COV_MATRIX @ F.BPV(pvs), + "PERR": F.SQRT @ F.PERR2, + "PXERR": F.SQRT @ F.CALL(0,0) @ F.THREE_MOM_COV_MATRIX, + "PYERR": F.SQRT @ F.CALL(1,1) @ F.THREE_MOM_COV_MATRIX, + "PZERR": F.SQRT @ F.CALL(2,2) @ F.THREE_MOM_COV_MATRIX, + }) + + composite_variables += HltTisTos( selection_type="Hlt1", trigger_lines=Hlt1_decisions, data=PsiXXX_data) + if not isturbo: + composite_variables += HltTisTos( selection_type="Hlt2", trigger_lines=Hlt2_decisions, data=PsiXXX_data) + + daughter_variables = FunctorCollection({ + "PERR": F.SQRT @ F.PERR2, + "PZERR": F.SQRT @ F.CALL(2,2) @ F.THREE_MOM_COV_MATRIX, + }) + + #define event level variables + odin = get_odin() + decreports = None + rec_sum=get_rec_summary() + event_info = event_variables(pvs, odin, decreports, [line_name]) + FunctorCollection({ + "nPVs": F.VALUE_OR(-1) @F.RECSUMMARY_INFO(rec_sum,"nPVs"), + "nTTracks": F.VALUE_OR(-1) @F.RECSUMMARY_INFO(rec_sum,"nTTracks"), + "nLongTracks": F.VALUE_OR(-1) @F.RECSUMMARY_INFO(rec_sum,"nLongTracks"), + "nDownstreamTracks": F.VALUE_OR(-1) @F.RECSUMMARY_INFO(rec_sum,"nDownstreamTracks"), + "nUpstreamTracks": F.VALUE_OR(-1) @F.RECSUMMARY_INFO(rec_sum,"nUpstreamTracks"), + "nVeloTracks": F.VALUE_OR(-1) @F.RECSUMMARY_INFO(rec_sum,"nVeloTracks"), + "nBackTracks": F.VALUE_OR(-1) @F.RECSUMMARY_INFO(rec_sum,"nBackTracks"), + "nRich1Hits": F.VALUE_OR(-1) @F.RECSUMMARY_INFO(rec_sum,"nRich1Hits"), + "nRich2Hits": F.VALUE_OR(-1) @F.RECSUMMARY_INFO(rec_sum,"nRich2Hits"), + "nVPClusters": F.VALUE_OR(-1) @F.RECSUMMARY_INFO(rec_sum,"nVPClusters"), + "nFTClusters": F.VALUE_OR(-1) @F.RECSUMMARY_INFO(rec_sum,"nFTClusters"), + "eCalTot": F.VALUE_OR(-1) @F.RECSUMMARY_INFO(rec_sum,"eCalTot"), + "hCalTot": F.VALUE_OR(-1) @F.RECSUMMARY_INFO(rec_sum,"hCalTot"), + "nEcalClusters": F.VALUE_OR(-1) @F.RECSUMMARY_INFO(rec_sum,"nEcalClusters"), + "ALLPVX": F.ALLPVX(pvs), + "ALLPVY": F.ALLPVY(pvs), + "ALLPVZ": F.ALLPVZ(pvs), + + }) + + event_info += FC.SelectionInfo( + selection_type="Hlt1", trigger_lines=Hlt1_decisions + ) + + variables = {} + + for composite_particle in composite_particles: + variables[composite_particle] = composite_variables + all_variables(pvs, None, _composite) + make_dtf_variables(pvs, PsiXXX_data, _composite) + for daughter_particle in daughter_particles: + variables[daughter_particle] = daughter_variables + all_variables(pvs, None, _basic) + make_dtf_variables(pvs, PsiXXX_data, _basic) +# variables = { +# "QQbar": composite_variables + all_variables(pvs, None, _composite), +# "mup": daughter_variables + all_variables(pvs, None, _basic), +# "mum": daughter_variables + all_variables(pvs, None, _basic), +# } + + #define FunTuple instance + my_tuple = Funtuple( + name=line_name, + tuple_name="DecayTree", + fields=decay_descriptor, + variables=variables, + event_variables=event_info, + store_multiple_cand_info = True, + inputs=PsiXXX_data) + + return my_tuple + + +def line_prefilter(line_name): + return create_lines_filter(name=f"PreFilter_{line_name}", lines=[line_name]) diff --git a/BandQ_MCBuds_NoMuonLines/tupling_maker_new.py b/BandQ_MCBuds_NoMuonLines/tupling_maker_new.py new file mode 100644 index 0000000000..89b05dd523 --- /dev/null +++ b/BandQ_MCBuds_NoMuonLines/tupling_maker_new.py @@ -0,0 +1,513 @@ +############################################################################### +# (c) Copyright 2021-2022 CERN for the benefit of the LHCb Collaboration # +# # +# This software is distributed under the terms of the GNU General Public # +# Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". # +# # +# In applying this licence, CERN does not waive the privileges and immunities # +# granted to it by virtue of its status as an Intergovernmental Organization # +# or submit itself to any jurisdiction. # +############################################################################### +""" +Read an HLT2 file and create an ntuple with the new DaVinci configuration. +""" +import Functors as F +import FunTuple.functorcollections as FC +from FunTuple import FunctorCollection +from FunTuple import FunTuple_Particles as Funtuple +from PyConf.reading import get_particles, get_pvs, get_rec_summary +from DaVinci.algorithms import create_lines_filter +from DaVinciMCTools import MCTruthAndBkgCat +from FunTuple.functorcollections import MCHierarchy, MCPrimaries, MCPromptDecay, Kinematics, SelectionInfo, HltTisTos, MCVertexInfo, MCKinematics, ParticleID, EventInfo +from PyConf.reading import get_odin # get_decreports, +from DecayTreeFitter import DecayTreeFitter +from .make_dtf import * + +_basic = "basic" +_composite = "composite" +_toplevel = "toplevel" + +#def all_variables(pvs, dtf, mctruth, ptype, candidates=None, ftAlg=None): +def all_variables(pvs, mctruth, ptype, candidates=None, ftAlg=None): + """ + function that returns dictionary of functors that work. + + functors are listed in order of https://lhcbdoc.web.cern.ch/lhcbdoc/moore/master/selection/thor_functors_reference.html#module-Functo + """ + if ptype not in [_basic, _composite]: + Exception(f"I want {_basic} or {_composite}. Got {ptype}") + all_vars = FunctorCollection({}) + + comp = _composite == ptype or _toplevel == ptype # is composite + basic = _basic == ptype # is not composite + top = _toplevel == ptype # the B + + # First import everything that comes in functorcollections + all_vars += FC.Kinematics() + if basic: + all_vars += FC.ParticleID(extra_info=True) + all_vars += FC.MCKinematics(mctruth_alg=mctruth) + all_vars += FC.MCHierarchy(mctruth_alg=mctruth) + #all_vars += FC.MCPrimaryVertexInfo(mctruth_alg=mctruth) + #Hlt1_decisions = ["Hlt1TrackMVADecision", "Hlt1TwoTrackMVADecision"] + #if candidates: + #all_vars += FC.HltTisTos( + #selection_type="Hlt", trigger_lines=Hlt1_decisions, data=candidates + #) + #if comp: + # all_vars += FC.MCVertexInfo(mctruth_alg=mctruth) + #if top: + # all_vars += FC.MCPromptDecay(mctruth_alg=mctruth) + + # + # FTAlg not yet implemented + # For Track isolation see weightedrelations_trackvariables + # + # Now all other functors + + # ALL : Not useful for tupling + + if comp: + all_vars.update({"ALV": F.ALV(Child1=1, Child2=2)}) + + all_vars.update({"BKGCAT": mctruth.BkgCat}) + + if comp: # all these require a vertex + all_vars.update({"BPVCORRM": F.BPVCORRM(pvs)}) + all_vars.update({"BPVCORRMERR": F.BPVCORRMERR(pvs)}) + all_vars.update({"BPVDIRA": F.BPVDIRA(pvs)}) + all_vars.update({"BPVDLS": F.BPVDLS(pvs)}) + all_vars.update({"BPVETA": F.BPVETA(pvs)}) + all_vars.update({"BPVFD": F.BPVFD(pvs)}) + all_vars.update({"BPVFDCHI2": F.BPVFDCHI2(pvs)}) + all_vars.update({"BPVFDIR": F.BPVFDIR(pvs)}) + all_vars.update({"BPVFDVEC": F.BPVFDVEC(pvs)}) + + all_vars.update({"BPVIP": F.BPVIP(pvs)}) + all_vars.update({"BPVIPCHI2": F.BPVIPCHI2(pvs)}) + all_vars.update({"BPVX": F.BPVX(pvs)}) + all_vars.update({"BPVY": F.BPVY(pvs)}) + all_vars.update({"BPVZ": F.BPVZ(pvs)}) + # When storing variable length array one can + # give a custom branch name for the index. + # This can be achieved by enclosing custom index + # name within square brackets (see code below). + # The branch name ("nPV") will correspond to the + # index of the PV. If no index branch name given i.e. + # all_vars.update({ 'ALLPVX'] the default "indx" is used. + #all_vars.update({"ALLPVX[nPVs]": F.ALLPVX(pvs)}) + #all_vars.update({"ALLPVY[nPVs]": F.ALLPVY(pvs)}) + #all_vars.update({"ALLPVZ[nPVs]": F.ALLPVZ(pvs)}) + all_vars.update({"ALLPVX": F.ALLPVX(pvs)}) + all_vars.update({"ALLPVY": F.ALLPVY(pvs)}) + all_vars.update({"ALLPVZ": F.ALLPVZ(pvs)}) + + if comp: # all these require a vertex + #all_vars.update({"ALLPV_FD[nPVs]": F.ALLPV_FD(pvs)}) + #all_vars.update({"ALLPV_IP[nPVs]": F.ALLPV_IP(pvs)}) + all_vars.update({"ALLPV_FD": F.ALLPV_FD(pvs)}) + all_vars.update({"ALLPV_IP": F.ALLPV_IP(pvs)}) + all_vars.update({"BPVLTIME": F.BPVLTIME(pvs)}) + all_vars.update({"BPVVDRHO": F.BPVVDRHO(pvs)}) + all_vars.update({"BPVVDX": F.BPVVDX(pvs)}) + all_vars.update({"BPVVDY": F.BPVVDY(pvs)}) + all_vars.update({"BPVVDZ": F.BPVVDZ(pvs)}) + + all_vars.update({"CHARGE": F.CHARGE}) + all_vars.update({"CHI2": F.CHI2}) + all_vars.update({"CHI2DOF": F.CHI2DOF}) + if top: # apply this only to B + all_vars.update({"CHILD1_PT": F.CHILD(1, F.PT)}) # example of CHILD + all_vars.update({"Ds_END_VZ": F.CHILD(1, F.END_VZ)}) + all_vars.update({"Delta_END_VZ_DsB0": F.CHILD(1, F.END_VZ) - F.END_VZ}) + + # if basic: all_vars.update({ 'CLOSESTTOBEAM' : F.CLOSESTTOBEAM # 'Track__ClosestToBeamState' object has no attribute 'to_json' + # COMB + # if basic: all_vars.update({ 'COV' : F.COV # 'Track__Covariance' object has no attribute 'to_json' + + if comp: + all_vars.update({"DOCA": F.SDOCA(Child1=1, Child2=2)}) + all_vars.update({"DOCACHI2": F.SDOCACHI2(Child1=1, Child2=2)}) + all_vars.update({"END_VRHO": F.END_VRHO}) + all_vars.update({"END_VX": F.END_VX}) + all_vars.update({"END_VY": F.END_VY}) + all_vars.update({"END_VZ": F.END_VZ}) + + # duplicated from FC all_vars.update({"ENERGY" : F.ENERGY}) + all_vars.update({"ETA": F.ETA}) + all_vars.update({"FOURMOMENTUM": F.FOURMOMENTUM}) + all_vars.update({"ISBASIC": F.ISBASICPARTICLE}) + + if basic: + all_vars.update({"GHOSTPROB": F.GHOSTPROB}) + all_vars.update({"ISMUON": F.ISMUON}) + all_vars.update({"INMUON": F.INMUON}) + all_vars.update({"INECAL": F.INECAL}) + all_vars.update({"INHCAL": F.INHCAL}) + all_vars.update({"HASBREM": F.HASBREM}) + all_vars.update({"BREMENERGY": F.BREMENERGY}) + all_vars.update({"BREMBENDCORR": F.BREMBENDCORR}) + all_vars.update({"BREMPIDE": F.BREMPIDE}) + all_vars.update({"ECALPIDE": F.ECALPIDE}) + all_vars.update({"ECALPIDMU": F.ECALPIDMU}) + all_vars.update({"HCALPIDE": F.HCALPIDE}) + all_vars.update({"HCALPIDMU": F.HCALPIDMU}) + all_vars.update({"ELECTRONSHOWEREOP": F.ELECTRONSHOWEREOP}) + all_vars.update({"CLUSTERMATCH": F.CLUSTERMATCH_CHI2}) + all_vars.update({"ELECTRONMATCH": F.ELECTRONMATCH_CHI2}) + all_vars.update({"BREMHYPOMATCH": F.BREMHYPOMATCH_CHI2}) + all_vars.update({"ELECTRONENERGY": F.ELECTRONENERGY}) + all_vars.update({"BREMHYPOENERGY": F.BREMHYPOENERGY}) + all_vars.update({"BREMHYPODELTAX": F.BREMHYPODELTAX}) + all_vars.update({"ELECTRONID": F.ELECTRONID}) + all_vars.update({"HCALEOP": F.HCALEOP}) + # Note: the observables for the two functors below are (TRACK_MOM_X, TRACK_MOM_Y, TRACK_MOM_Z}) + # and (TRACK_POS_CLOSEST_TO_BEAM_X, TRACK_POS_CLOSEST_TO_BEAM_Y, TRACK_POS_CLOSEST_TO_BEAM_Z), + # which is why the trailing underscore in the name is added i.e. "TRACK_MOM_" and "TRACK_POS_CLOSEST_TO_BEAM_" + all_vars.update({"TRACK_MOM_": F.TRACK_MOMVEC}) + all_vars.update({"TRACK_POS_CLOSESTTOBEAM_": F.TRACK_POSVEC_CLOSESTTOBEAM}) + + all_vars.update({"IS_ABS_ID_pi": F.IS_ABS_ID("pi+")}) + all_vars.update({"IS_ID_pi": F.IS_ID("pi-")}) + all_vars.update({"PDG_MASS_pi": F.PDG_MASS("pi+")}) + all_vars.update({"SIGNED_DELTA_MASS_pi": F.SIGNED_DELTA_MASS("pi+")}) + all_vars.update({"ABS_DELTA_MASS_pi": F.ABS_DELTA_MASS("pi+")}) + all_vars.update({"IS_NOT_H": F.IS_NOT_H}) + all_vars.update({"IS_PHOTON": F.IS_PHOTON}) + + #if dtf: + # all_vars.update({"DTF_PT": dtf(F.PT)}) + # all_vars.update({"DTF_BPVIPCHI2": dtf(F.BPVIPCHI2(pvs))}) + + #if top and dtf: + # all_vars.update({"DTF_NITER": dtf.NITER}) + # all_vars.update({"DTF_CHI2": dtf.CHI2}) + # all_vars.update({"DTF_NDOF": dtf.NDOF}) + # all_vars.update({"DTF_CHI2DOF": dtf.CHI2DOF}) + + #if comp and dtf: + # all_vars.update({"DTF_MASS": dtf.MASS}) + # all_vars.update({"DTF_MASSERR": dtf.MASSERR}) + # all_vars.update({"DTF_P": dtf.P}) + # all_vars.update({"DTF_PERR": dtf.PERR}) + # all_vars.update({"DTF_TAU": dtf.TAU}) + # all_vars.update({"DTF_TAUERR": dtf.TAUERR}) + # all_vars.update({"DTF_FD": dtf.FD}) + # all_vars.update({"DTF_FDERR": dtf.FDERR}) + + all_vars.update({"MASS": F.MASS}) + #if top: # B + # all_vars.update({"MASSWITHHYPOTHESES": F.MASSWITHHYPOTHESES((939.0, 939.0))}) + #elif comp: # Ds + # all_vars.update( + # {"MASSWITHHYPOTHESES": F.MASSWITHHYPOTHESES((493.7, 493.7, 139.6))} + # ) + if comp: + all_vars.update({"MAXPT": F.MAX(F.PT)}) + all_vars.update({"MAXDOCA": F.MAXSDOCA}) + all_vars.update({"MAXDOCACHI2": F.MAXSDOCACHI2}) + # the above in cut versions. + + # duplicated from FC all_vars.update({ 'MC_MOTHER_ID' : F.VALUE_OR(0) @ mctruth( + # duplicated from FC F.MC_MOTHER(1, F.PARTICLE_ID))}) + + if comp: + all_vars.update({"MINPT": F.MIN(F.PT)}) + all_vars.update({"MINIP": F.MINIP(pvs)}) + all_vars.update({"MINIPCHI2": F.MINIPCHI2(pvs)}) + + if basic: + all_vars.update({"TRACKPT": F.TRACK_PT}) + all_vars.update({"TRACKHISTORY": F.VALUE_OR(-1) @ F.TRACKHISTORY @ F.TRACK}) + all_vars.update({"QOVERP": F.QOVERP @ F.TRACK}) + all_vars.update({"NDOF": F.VALUE_OR(-1) @ F.NDOF @ F.TRACK}) + all_vars.update({"NFTHITS": F.VALUE_OR(-1) @ F.NFTHITS @ F.TRACK}) + all_vars.update({"NHITS": F.VALUE_OR(-1) @ F.NHITS @ F.TRACK}) + all_vars.update({"NUTHITS": F.VALUE_OR(-1) @ F.NUTHITS @ F.TRACK}) + all_vars.update({"NVPHITS": F.VALUE_OR(-1) @ F.NVPHITS @ F.TRACK}) + all_vars.update({"TRACKHASVELO": F.VALUE_OR(-1) @ F.TRACKHASVELO @ F.TRACK}) + all_vars.update({"TRACKHASUT": F.VALUE_OR(-1) @ F.TRACKHASUT @ F.TRACK}) + + all_vars.update({"OBJECT_KEY": F.OBJECT_KEY}) + + # duplicated from FC all_vars.update({ 'ORIGIN_VX' : mctruth(F.ORIGIN_VX) }) + # duplicated from FC all_vars.update({ 'ORIGIN_VY' : mctruth(F.ORIGIN_VY) }) + # duplicated from FC all_vars.update({ 'ORIGIN_VZ' : mctruth(F.ORIGIN_VZ) }) + + # duplicated from FC all_vars.update({"P" : F.P}) + # duplicated from FC all_vars.update({"PARTICLE_ID" : F.PARTICLE_ID}) + all_vars.update({"PHI": F.PHI}) + + # duplicated from FC if basic: + # duplicated from FC all_vars.update({"PID_E" : F.PID_E}) + # duplicated from FC all_vars.update({"PID_K" : F.PID_K}) + # duplicated from FC all_vars.update({"PID_MU" : F.PID_MU}) + # duplicated from FC all_vars.update({"PID_P" : F.PID_P}) + # duplicated from FC all_vars.update({"PID_PI" : F.PID_PI}) + # duplicated from FC #all_vars.update({"PROBNN_D" : F.PROBNN_D}) + # duplicated from FC all_vars.update({"PROBNN_E" : F.PROBNN_E}) + # duplicated from FC all_vars.update({"PROBNN_GHOST" : F.PROBNN_GHOST}) + # duplicated from FC all_vars.update({"PROBNN_K" : F.PROBNN_K}) + # duplicated from FC all_vars.update({"PROBNN_MU" : F.PROBNN_MU}) + # duplicated from FC all_vars.update({"PROBNN_P" : F.PROBNN_P}) + # duplicated from FC all_vars.update({"PROBNN_PI" : F.PROBNN_PI}) + + # duplicated from FC all_vars.update({ 'PT' : F.PT }) + # duplicated from FC all_vars.update({ 'PX' : F.PX }) + # duplicated from FC all_vars.update({ 'PY' : F.PY }) + # duplicated from FC all_vars.update({ 'PZ' : F.PZ }) + all_vars.update({"ABS_PX": F.ABS @ F.PX}) + + all_vars.update({"REFERENCEPOINT_X": F.REFERENCEPOINT_X}) + all_vars.update({"REFERENCEPOINT_Y": F.REFERENCEPOINT_Y}) + all_vars.update({"REFERENCEPOINT_Z": F.REFERENCEPOINT_Z}) + + if comp: + all_vars.update({"SDOCA": F.SDOCA(1, 2)}) + all_vars.update({"SDOCACHI2": F.SDOCACHI2(1, 2)}) + if basic: + all_vars.update({"SHOWER_SHAPE": F.CALO_NEUTRAL_SHOWER_SHAPE}) + + if comp: + all_vars.update({"SUBCOMB12_MM": F.SUBCOMB(Functor=F.MASS, Indices=(1, 2))}) + all_vars.update({"SUMPT": F.SUM(F.PT)}) + + if basic: + all_vars.update({"TX": F.TX}) + all_vars.update({"TY": F.TY}) + + print(f"### For {ptype} returning variables {all_vars.functor_dict.keys()}") + return all_vars + + +def event_variables(PVs, ODIN, decreports, lines, hlt1lines): + """ + event variables + """ + + evt_vars = FunctorCollection({}) + evt_vars += FC.EventInfo() + + evt_vars += FC.SelectionInfo(selection_type="Hlt2", trigger_lines=lines) + evt_vars += FC.SelectionInfo(selection_type="Hlt1", trigger_lines=hlt1lines) + # duplicated from FC if ODIN: + # duplicated from FC evt_vars.update({ 'BUNCHCROSSING_ID' : F.BUNCHCROSSING_ID(ODIN) }) + # duplicated from FC evt_vars.update({ 'BUNCHCROSSING_TYPE' : F.BUNCHCROSSING_TYPE(ODIN) }) + + if decreports: + evt_vars.update( + { + "DECISIONS": F.DECISIONS( + Lines=[bd2dsk_line + "Decision"], DecReports=decreports + ) + } + ) + evt_vars.update( + { + "DECREPORTS_FILTER": F.DECREPORTS_FILTER( + Lines=[bd2dsk_line + "Decision"], DecReports=decreports + ) + } + ) + + if ODIN: + evt_vars.update({"EVENTTYPE": F.EVENTTYPE(ODIN)}) + + # duplicated from FC evt_vars.update({ 'GPSTIME' : F.GPSTIME(ODIN) }) + # duplicated from FC evt_vars.update({ 'ODINTCK' : F.ODINTCK(ODIN) }) + + evt_vars.update({"PV_SIZE": F.SIZE(PVs)}) + # duplicated from FC evt_vars.update({ 'GPSTIME' : F.GPSTIME(ODIN) }) + # duplicated from FC evt_vars.update({ 'ODINTCK' : F.ODINTCK(ODIN) }) + + if decreports: + evt_vars.update({"TCK": F.TCK(decreports)}) + + print(f"### For event returning variables {evt_vars.functor_dict.keys()}") + return evt_vars + + +def mc_template(decay_descriptor, line_name, isturbo, Hlt2_decisions, composite_particles, daughter_particles, tuple_dir_name): + evtpath_prefix = "/Event/Spruce/" + if isturbo: + evtpath_prefix = "/Event/HLT2/" + + QQbar2mumu_data = get_particles(evtpath_prefix+f"{line_name}/Particles") + + pvs = get_pvs() + + Hlt1_decisions = [ +# Global line + "Hlt1GlobalDecision", "Hlt1PhysDecision", +# Physics lines + "Hlt1TrackMVADecision", "Hlt1TwoTrackMVADecision", "Hlt1D2KKDecision", "Hlt1D2KPiDecision", "Hlt1D2PiPiDecision", "Hlt1Dst2D0PiDecision", "Hlt1KsToPiPiDecision", "Hlt1KsToPiPiDoubleMuonMisIDDecision", "Hlt1TwoTrackKsDecision", "Hlt1TwoKsDecision", "Hlt1LambdaLLDetachedTrackDecision", "Hlt1XiOmegaLLLDecision", "Hlt1SingleHighPtMuonDecision", "Hlt1SingleHighPtMuonNoMuIDDecision", "Hlt1DiMuonHighMassDecision", "Hlt1DiMuonDisplacedDecision", "Hlt1DiMuonSoftDecision", "Hlt1TrackMuonMVADecision", "Hlt1DiMuonNoIP_SSDecision", "Hlt1DiMuonDrellYan_VLowMassDecision", "Hlt1DiMuonDrellYan_VLowMass_SSDecision", "Hlt1DiMuonDrellYanDecision", "Hlt1DiMuonDrellYan_SSDecision", "Hlt1DetJpsiToMuMuPosTagLineDecision", "Hlt1DetJpsiToMuMuNegTagLineDecision", "Hlt1TrackElectronMVADecision", "Hlt1SingleHighPtElectronDecision", "Hlt1DiElectronDisplacedDecision", "Hlt1SingleHighEtDecision", "Hlt1DiPhotonHighMassDecision", "Hlt1Pi02GammaGammaDecision", "Hlt1DiElectronHighMass_SSDecision", "Hlt1DiElectronHighMassDecision", "Hlt1DiMuonNoIPDecision" +## alignment lines +# "Hlt1RICH1AlignmentDecision", "Hlt1RICH2AlignmentDecision", "Hlt1D2KPiAlignmentDecision", "Hlt1Dst2D0PiAlignmentDecision", "Hlt1MaterialVertexSeedsDownstreamzDecision", "Hlt1MaterialVertexSeeds_DWFSDecision", "Hlt1DiMuonHighMassAlignmentDecision", "Hlt1DiMuonJpsiMassAlignmentDecision", "Hlt1OneMuonTrackLineDecision", "Hlt1BeamGasDecision", +## smog2 lines +# "Hlt1SMOG2D2KpiDecision", "Hlt1VeloMicroBiasDecision", "Hlt1SMOG2etacToppDecision", "Hlt1SMOG2KsTopipiDecision", "Hlt1SMOG2etacToppDecision", "Hlt1SMOG2KsTopipiDecision", "Hlt1SMOG22BodyGenericDecision", "Hlt1SMOG22BodyGenericLowPtDecision", "Hlt1SMOG2SingleTrackVeryHighPtDecision", "Hlt1SMOG2SingleTrackHighPtDecision", "Hlt1SMOG2DiMuonHighMassDecision", "Hlt1SMOG2SingleMuonDecision", "Hlt1SMOG2L0ToppiDecision", +## bgi lines +# "Hlt1BGIPseudoPVsNoBeamDecision", "Hlt1BGIPseudoPVsBeamOneDecision", "Hlt1BGIPseudoPVsBeamTwoDecision", "Hlt1BGIPseudoPVsUpBeamBeamDecision", "Hlt1BGIPseudoPVsDownBeamBeamDecision", "Hlt1BGIPseudoPVsIRBeamBeamDecision", "Hlt1BGIPVsCylNoBeamDecision", "Hlt1BGIPVsCylBeamOneDecision", "Hlt1BGIPVsCylBeamTwoDecision", "Hlt1BGIPVsCylUpBeamBeamDecision", "Hlt1BGIPVsCylDownBeamBeamDecision", "Hlt1BGIPVsCylIRBeamBeamDecision", "Hlt1BGIVeloClustersMicroBiasDecision", "Hlt1BGICaloDigitsDecision", "Hlt1BGIPlumeActivityDecision", +## setup hlt1 nodes lines +# "Hlt1ODINCalibDecision", "Hlt1TAEPassthroughDecision", "Hlt1ErrorBankDecision", "Hlt1VeloMicroBiasVeloClosingDecision", "Hlt1GECPassthroughDecision", "Hlt1SMOG2BENoBiasDecision", "Hlt1SMOG2PassThroughLowMult5Decision", "Hlt1SMOG2BELowMultElectronsDecision", "Hlt1SMOG2MinimumBiasDecision", "Hlt1PassthroughPVinSMOG2Decision" + ] + + + composite_variables = FunctorCollection({ + #"ID": F.PARTICLE_ID, + #"KEY": F.OBJECT_KEY, + #"PT": F.PT, + #"PX": F.PX, + #"PY": F.PY, + #"PZ": F.PZ, + #"ENERGY": F.ENERGY, + #"P": F.P, + #"M": F.MASS, + #"ETA": F.ETA, + #"PHI": F.PHI, + #"ENDVERTEX_CHI2NDOF": F.CHI2DOF, + #"FOURMOMENTUM": F.FOURMOMENTUM, + #"BPVDIRA": F.BPVDIRA(pvs), + #"BPVX": F.BPVX(pvs), + #"BPVY": F.BPVY(pvs), + #"BPVZ": F.BPVZ(pvs), + #"END_VX": F.END_VX, + #"END_VY": F.END_VY, + #"END_VZ": F.END_VZ, + "END_VZ_ERR":F.SQRT @ F.CALL(2,2) @ F.POS_COV_MATRIX @ F.ENDVERTEX, + "END_VY_ERR":F.SQRT @ F.CALL(1,1) @ F.POS_COV_MATRIX @ F.ENDVERTEX, + "END_VX_ERR":F.SQRT @ F.CALL(0,0) @ F.POS_COV_MATRIX @ F.ENDVERTEX, + "BPVZ_ERR": F.SQRT @ F.CALL(2,2) @ F.POS_COV_MATRIX @ F.BPV(pvs), + "BPVY_ERR": F.SQRT @ F.CALL(1,1) @ F.POS_COV_MATRIX @ F.BPV(pvs), + "BPVX_ERR": F.SQRT @ F.CALL(0,0) @ F.POS_COV_MATRIX @ F.BPV(pvs), + #"TAU": F.BPVLTIME(pvs), + #"BPVFDCHI2": F.BPVFDCHI2(pvs), + #"BPVIPCHI2": F.BPVIPCHI2(pvs) + }) + + #composite_variables += Kinematics() + #composite_variables += ParticleID(extra_info=True) + composite_variables += HltTisTos( selection_type="Hlt1", trigger_lines=Hlt1_decisions, data=QQbar2mumu_data) + if not isturbo: + composite_variables += HltTisTos( selection_type="Hlt2", trigger_lines=Hlt2_decisions, data=QQbar2mumu_data) + + daughter_variables = FunctorCollection({ + #"ID": F.PARTICLE_ID, + #"PT": F.PT, + #"PX": F.PX, + #"PY": F.PY, + #"PZ": F.PZ, + #"M": F.MASS, + #"ENERGY": F.ENERGY, + #"P": F.P, + #"ETA": F.ETA, + #"PHI": F.PHI, + #"Track_CHI2NDOF": F.CHI2DOF, + #"ProbNNmu": F.PROBNN_MU, + #"PIDmu": F.PID_MU, + #"IsMuon": F.ISMUON, + #"GhostProb": F.GHOSTPROB, + #"FOURMOMENTUM": F.FOURMOMENTUM, + "PERR": F.SQRT @ F.PERR2, + "PZERR": F.SQRT @ F.CALL(2,2) @ F.THREE_MOM_COV_MATRIX, + }) + + #daughter_variables += Kinematics() + #daughter_variables += ParticleID(extra_info=True) + +# line_prefilter = create_lines_filter(name=f"HLT_PASS{line_name}", lines=[line_name]) + + #define event level variables + odin = get_odin() + decreports = None + rec_sum=get_rec_summary() + event_info = event_variables(pvs, odin, decreports, [line_name], Hlt1_decisions) + FunctorCollection({ + "nPVs": F.VALUE_OR(-1) @F.RECSUMMARY_INFO(rec_sum,"nPVs"), + "nTracks": F.VALUE_OR(-1) @F.RECSUMMARY_INFO(rec_sum,"nTracks"), + "nLongTracks": F.VALUE_OR(-1) @F.RECSUMMARY_INFO(rec_sum,"nLongTracks"), + "nDownstreamTracks": F.VALUE_OR(-1) @F.RECSUMMARY_INFO(rec_sum,"nDownstreamTracks"), + "nUpstreamTracks": F.VALUE_OR(-1) @F.RECSUMMARY_INFO(rec_sum,"nUpstreamTracks"), + "nVeloTracks": F.VALUE_OR(-1) @F.RECSUMMARY_INFO(rec_sum,"nVeloTracks"), + "nBackTracks": F.VALUE_OR(-1) @F.RECSUMMARY_INFO(rec_sum,"nBackTracks"), + "nGhosts": F.VALUE_OR(-1) @F.RECSUMMARY_INFO(rec_sum,"nGhosts"), + "nRich1Hits": F.VALUE_OR(-1) @F.RECSUMMARY_INFO(rec_sum,"nRich1Hits"), + "nRich2Hits": F.VALUE_OR(-1) @F.RECSUMMARY_INFO(rec_sum,"nRich2Hits"), + "nVeloClusters": F.VALUE_OR(-1) @F.RECSUMMARY_INFO(rec_sum,"nVeloClusters"), + "nVPClusters": F.VALUE_OR(-1) @F.RECSUMMARY_INFO(rec_sum,"nVPClusters"), + "nITClusters": F.VALUE_OR(-1) @F.RECSUMMARY_INFO(rec_sum,"nITClusters"), + "nTTClusters": F.VALUE_OR(-1) @F.RECSUMMARY_INFO(rec_sum,"nTTClusters"), + "nUTClusters": F.VALUE_OR(-1) @F.RECSUMMARY_INFO(rec_sum,"nUTClusters"), + "nOTClusters": F.VALUE_OR(-1) @F.RECSUMMARY_INFO(rec_sum,"nOTClusters"), + "nFTClusters": F.VALUE_OR(-1) @F.RECSUMMARY_INFO(rec_sum,"nFTClusters"), + "nSPDhits": F.VALUE_OR(-1) @F.RECSUMMARY_INFO(rec_sum,"nSPDhits"), + "eCalTot": F.VALUE_OR(-1) @F.RECSUMMARY_INFO(rec_sum,"eCalTot"), + "hCalTot": F.VALUE_OR(-1) @F.RECSUMMARY_INFO(rec_sum,"hCalTot"), + "nEcalClusters": F.VALUE_OR(-1) @F.RECSUMMARY_INFO(rec_sum,"nEcalClusters"), + "nMuonCoordsS0": F.VALUE_OR(-1) @F.RECSUMMARY_INFO(rec_sum,"nMuonCoordsS0"), + "nMuonCoordsS1": F.VALUE_OR(-1) @F.RECSUMMARY_INFO(rec_sum,"nMuonCoordsS1"), + "nMuonCoordsS2": F.VALUE_OR(-1) @F.RECSUMMARY_INFO(rec_sum,"nMuonCoordsS2"), + "nMuonCoordsS3": F.VALUE_OR(-1) @F.RECSUMMARY_INFO(rec_sum,"nMuonCoordsS3"), + "nMuonCoordsS4": F.VALUE_OR(-1) @F.RECSUMMARY_INFO(rec_sum,"nMuonCoordsS4"), + "nMuonTracks": F.VALUE_OR(-1) @F.RECSUMMARY_INFO(rec_sum,"nMuonTracks"), + "ALLPVX": F.ALLPVX(pvs), + "ALLPVY": F.ALLPVY(pvs), + "ALLPVZ": F.ALLPVZ(pvs), + }) + + # get trueid bkgcat info + MC_TRUTH = MCTruthAndBkgCat(QQbar2mumu_data, name='MCTruthAndBkgCat_'+line_name) + MCMOTHER_ID = lambda n: F.VALUE_OR(0) @ MC_TRUTH(F.MC_MOTHER(n, F.PARTICLE_ID)) + MCMOTHER_KEY = lambda n: F.VALUE_OR(-1) @ MC_TRUTH(F.MC_MOTHER(n, F.OBJECT_KEY)) + + trueid_bkgcat_info = FunctorCollection({ + #"TRUEID": F.VALUE_OR(0) @ MC_TRUTH(F.PARTICLE_ID), + "TRUEKEY": F.VALUE_OR(-1) @ MC_TRUTH(F.OBJECT_KEY), + #"TRUEPT": MC_TRUTH(F.PT), + #"TRUEPX": MC_TRUTH(F.PX), + #"TRUEPY": MC_TRUTH(F.PY), + #"TRUEPZ": MC_TRUTH(F.PZ), + #"TRUEENERGY": MC_TRUTH(F.ENERGY), + #"TRUEP": MC_TRUTH(F.P), + "TRUEM": MC_TRUTH(F.MASS), + "TRUEETA": MC_TRUTH(F.ETA), + "TRUEPHI": MC_TRUTH(F.PHI), + "TRUEFOURMOMENTUM": MC_TRUTH(F.FOURMOMENTUM), + #"MC_MOTHER_ID": MCMOTHER_ID(1), + #"MC_MOTHER_KEY": MCMOTHER_KEY(1), + #"MC_GD_MOTHER_ID": MCMOTHER_ID(2), + #"MC_GD_MOTHER_KEY": MCMOTHER_KEY(2), + #"MC_GD_GD_MOTHER_ID": MCMOTHER_ID(3), + #"MC_GD_GD_MOTHER_KEY": MCMOTHER_KEY(3), + "TRUEORIGIN_VX": MC_TRUTH(F.ORIGIN_VX), + "TRUEORIGIN_VY": MC_TRUTH(F.ORIGIN_VY), + "TRUEORIGIN_VZ": MC_TRUTH(F.ORIGIN_VZ), + #"TRUEEND_VX": MC_TRUTH(F.END_VX), + #"TRUEEND_VY": MC_TRUTH(F.END_VY), + #"TRUEEND_VZ": MC_TRUTH(F.END_VZ), + "BKGCAT": MC_TRUTH.BkgCat, + }) + + variables = { + "QQbar": composite_variables + all_variables(pvs, MC_TRUTH, _composite) + trueid_bkgcat_info , + "mup": daughter_variables + all_variables(pvs, MC_TRUTH, _basic) + trueid_bkgcat_info, + "mum": daughter_variables + all_variables(pvs, MC_TRUTH, _basic) + trueid_bkgcat_info, + } + variables = {} + for composite_particle in composite_particles: + variables[composite_particle] = composite_variables + all_variables(pvs, MC_TRUTH, _composite)+ trueid_bkgcat_info + make_dtf_variables(pvs, QQbar2mumu_data, _composite) + for daughter_particle in daughter_particles: + variables[daughter_particle] = daughter_variables + all_variables(pvs, MC_TRUTH, _basic)+ trueid_bkgcat_info+ make_dtf_variables(pvs, QQbar2mumu_data, _basic) + #define FunTuple instance + my_tuple = Funtuple( + name=tuple_dir_name, + tuple_name="DecayTree", + fields=decay_descriptor, + variables=variables, + event_variables=event_info, + store_multiple_cand_info = True, + inputs=QQbar2mumu_data) + + return my_tuple + +def line_prefilter(line_name): + return create_lines_filter(name=f"HLT_PASS{line_name}", lines=[line_name]) + -- GitLab From 2218b808279b785861ea134f6532396ea54eb4ca Mon Sep 17 00:00:00 2001 From: Chenxu Yu <yuc@lxplus955.cern.ch> Date: Tue, 25 Jun 2024 10:08:09 +0200 Subject: [PATCH 02/15] =?UTF-8?q?=E4=BF=9D=E5=AD=98=E6=9C=AC=E5=9C=B0?= =?UTF-8?q?=E6=9B=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Beauty_XS_Bs2DsPi/README.md | 3 - Beauty_XS_Bs2DsPi/dv_simple.py | 252 --------------------------------- Beauty_XS_Bs2DsPi/hlt1.py | 31 ---- Beauty_XS_Bs2DsPi/hlt2.py | 68 --------- Beauty_XS_Bs2DsPi/info.yaml | 79 ----------- 5 files changed, 433 deletions(-) delete mode 100644 Beauty_XS_Bs2DsPi/README.md delete mode 100644 Beauty_XS_Bs2DsPi/dv_simple.py delete mode 100644 Beauty_XS_Bs2DsPi/hlt1.py delete mode 100644 Beauty_XS_Bs2DsPi/hlt2.py delete mode 100644 Beauty_XS_Bs2DsPi/info.yaml diff --git a/Beauty_XS_Bs2DsPi/README.md b/Beauty_XS_Bs2DsPi/README.md deleted file mode 100644 index 769ed08b69..0000000000 --- a/Beauty_XS_Bs2DsPi/README.md +++ /dev/null @@ -1,3 +0,0 @@ -Production of Bs -> Ds pi to run on 2024 collision data to include both up and down polarities - -This is for use in early measurements of Beauty XS diff --git a/Beauty_XS_Bs2DsPi/dv_simple.py b/Beauty_XS_Bs2DsPi/dv_simple.py deleted file mode 100644 index b4254db880..0000000000 --- a/Beauty_XS_Bs2DsPi/dv_simple.py +++ /dev/null @@ -1,252 +0,0 @@ -# Based on: -# https://gitlab.cern.ch/lhcb/DaVinci/-/blob/v63r2/DaVinciExamples/python/DaVinciExamples/tupling/option_davinci_tupling_from_hlt2.py - -import Functors as F -import FunTuple.functorcollections as FC -from FunTuple import FunctorCollection, FunTuple_Particles as Funtuple -from PyConf.reading import get_particles, get_pvs, get_rec_summary, get_odin -#from PyConf.Algorithms import AdvancedCloneKiller, Run2SSPionTagger -from GaudiKernel.SystemOfUnits import GeV -from Hlt2Conf.algorithms_thor import ParticleFilter -#from DaVinci.common_particles import make_long_pions -from DaVinci.algorithms import create_lines_filter -from DaVinci import Options, make_config -from DaVinciMCTools import MCTruthAndBkgCat -from DecayTreeFitter import DecayTreeFitter -from Hlt2Conf.flavourTagging import run2_all_taggers -# specific for the B2OC SigmaNet -import Functors.math as fmath -import os - - -def alg_config(options: Options): - - line = "Hlt2B2OC_BdToDsmPi_DsmToKpKmPim" - line_data = get_particles(f"/Event/HLT2/{line}/Particles") - my_filter = create_lines_filter("Hlt2Line_Filter", - lines=[f"{line}"]) - Hlt1_decisions = [ - "Hlt1TrackMVADecision", - "Hlt1TwoTrackMVADecision", - ] - Hlt2_decisions = ['Hlt2B2OC_BdToDsmPi_DsmToKpKmPimDecision', - 'Hlt2Topo2BodyDecision', - 'Hlt2Topo3BodyDecision'] - - fields = { - "lab0": "[[B0]CC -> (D_s- -> K+ K- pi-) pi+]CC", - "lab1": "[[B0]CC -> (D_s- -> K+ K- pi-) ^pi+]CC", - "lab2": "[[B0]CC -> ^(D_s- -> K+ K- pi-) pi+]CC", - "lab3": "[[B0]CC -> (D_s- -> ^K+ K- pi-) pi+]CC", - "lab4": "[[B0]CC -> (D_s- -> K+ ^K- pi-) pi+]CC", - "lab5": "[[B0]CC -> (D_s- -> K+ K- ^pi-) pi+]CC", - } - - pvs = get_pvs() - - DTF_MassFitConsD = DecayTreeFitter(name="DTF_MassFitConsD", - input_particles=line_data, - mass_constraints=["D_s-"]) - DTF_LifetimeFit = DecayTreeFitter(name="DTF_LifetimeFit", - input_particles=line_data, - input_pvs=pvs) - - all_tagging = run2_all_taggers(line_data) - - # define helper functors - get_child = F.CHILD(1, F.FORWARDARG0) # change here the index of the child - get_SV = F.ENDVERTEX @ F.FORWARDARG0 - get_SV_pos = F.TOLINALG @ F.POSITION @ get_SV # only if composite (i.e. has vertex) - get_child_endvtx_pos = F.ENDVERTEX_POS @ get_child - get_fdvec_child = get_child_endvtx_pos - get_SV_pos - - # define observables - IP_wrt_SV = F.IP.bind(get_SV_pos , get_child) - IPCHI2_wrt_SV = F.IPCHI2.bind(get_SV , get_child) # only if child is composite (i.e. has vertex) - FD_wrt_SV = F.MAGNITUDE @ get_fdvec_child - FDCHI2_wrt_SV = F.VTX_FDCHI2.bind(get_SV, get_child) - - B_variables = FunctorCollection( - { - "ID": F.PARTICLE_ID, - "PT": F.PT, - "ETA": F.ETA, - "P": F.P, - "SUMPT": F.SUM(F.PT), - "MASS": F.MASS, - "BPVDIRA": F.BPVDIRA(pvs), - "CHI2DOF": F.CHI2DOF, - "BPVIPCHI2": F.BPVIPCHI2(pvs), - "BPVIP": F.BPVIP(pvs), - "BPVFDCHI2": F.BPVFDCHI2(pvs), - "BPVLTIME": F.BPVLTIME(pvs), - "BPVFD": F.BPVFD(pvs), - "CHILD1_IPwrtSV": IP_wrt_SV, - "CHILD1_IPCHI2wrtSV": IPCHI2_wrt_SV, - "CHILD1_FDwrtSV": FD_wrt_SV, - "CHILD1_FDCHI2wrtSV": FDCHI2_wrt_SV, - "DTF_MassFitConsD_MASS": DTF_MassFitConsD(F.MASS), - "DTF_MassFitConsD_CHI2DOF": DTF_MassFitConsD(F.CHI2DOF), # track or vertex chi2/ndf - "DTF_MassFitConsD_P": DTF_MassFitConsD(F.P), - "DTF_LifetimeFit_MASS": DTF_LifetimeFit(F.MASS), - "DTF_LifetimeFit_CHI2DOF": DTF_LifetimeFit(F.CHI2DOF), # track or vertex chi2/ndf - "DTF_LifetimeFit_CTAU": DTF_LifetimeFit.CTAU, - "DTF_LifetimeFit_CTAUERR": DTF_LifetimeFit.CTAUERR, - "PX": F.PX, - "PY": F.PY, - "PZ": F.PZ, - "BPVX": F.BPVX(pvs), - "BPVY": F.BPVY(pvs), - "BPVZ": F.BPVZ(pvs), - "END_VX": F.END_VX, - "END_VY": F.END_VY, - "END_VZ": F.END_VZ, - "END_VCHI2DOF": F.CHI2DOF @ F.ENDVERTEX, - "BPVCHI2DOF": F.CHI2DOF @ F.BPV(pvs), - # B2OC generic B hadron NN Hlt2 algorithm, - # not planning to use it directly for B2OC EM - "MVA": F.MVA( - MVAType="SigmaNet", - Config={ - "File": - "paramfile://data/Hlt2B2OC_B_SigmaNet_Run3-v2.json", - "Name": - "B2OC_SigmaNet_Generic", - "Lambda": - "2.0", - "NLayers": - "3", - "InputSize": - "6", - "Monotone_Constraints": - "[1,-1,-1,-1,-1,-1]", - "Variables": - "log_B_PT,B_ETA,log_B_DIRA,log_B_ENDVERTEX_CHI2,log_B_IPCHI2_OWNPV,log_B_IP_OWNPV", - }, - Inputs={ - "log_B_PT": fmath.log(F.PT), - "B_ETA": F.ETA, - "log_B_DIRA": fmath.log(1. +1.e-6 - F.BPVDIRA(pvs)), - "log_B_ENDVERTEX_CHI2": fmath.log(F.CHI2DOF), - "log_B_IPCHI2_OWNPV": fmath.log(F.BPVIPCHI2(pvs)), - "log_B_IP_OWNPV": fmath.log(F.BPVIP(pvs)), - }), - } - ) - B_variables+=FC.HltTisTos(selection_type="Hlt1", trigger_lines=Hlt1_decisions, data=line_data) - B_variables+=FC.FlavourTaggingResults(all_tagging) - - C_variables = FunctorCollection( - { - "ID": F.PARTICLE_ID, - "PT": F.PT, - "ETA": F.ETA, - "P": F.P, - "SUMPT": F.SUM(F.PT), - "MASS": F.MASS, - "DOCA12": F.DOCA(1, 2), - "DOCA13": F.DOCA(1, 3), - "DOCA23": F.DOCA(2, 3), - "BPVDIRA": F.BPVDIRA(pvs), - "CHI2DOF": F.CHI2DOF, - "BPVIP": F.BPVIP(pvs), - "BPVIPCHI2": F.BPVIPCHI2(pvs), - "BPVFD": F.BPVFD(pvs), - "BPVFDCHI2": F.BPVFDCHI2(pvs), - "MINIPCHI2": F.MINIPCHI2(pvs), - "PX": F.PX, - "PY": F.PY, - "PZ": F.PZ, - "BPVX": F.BPVX(pvs), - "BPVY": F.BPVY(pvs), - "BPVZ": F.BPVZ(pvs), - "END_VX": F.END_VX, - "END_VY": F.END_VY, - "END_VZ": F.END_VZ, - "END_VCHI2DOF": F.CHI2DOF @ F.ENDVERTEX, - } - ) - - fs_variables = FunctorCollection( - { - "ID": F.PARTICLE_ID, - "PT": F.PT, - "ETA": F.ETA, - "PHI": F.PHI, - "P": F.P, - "MASS": F.MASS, - "CHI2DOF": F.CHI2DOF, - "MINIPCHI2": F.MINIPCHI2(pvs), - "BPVIPCHI2": F.BPVIPCHI2(pvs), - "PX": F.PX, - "PY": F.PY, - "PZ": F.PZ, - "hasRICH": F.PPHASRICH() @ F.PROTOPARTICLE(), - "PIDK": F.PID_K, - "PIDp": F.PID_P, - "PIDe": F.PID_E, - "PIDmu": F.PID_MU, - "isMuon": F.ISMUON, - "TRACK_GhostProb": F.GHOSTPROB, - "ProbNNp": F.PROBNN_P, - "NHITS": F.VALUE_OR(-1) @ F.NHITS @ F.TRACK, - "NVPHITS": F.VALUE_OR(-1) @ F.NVPHITS @ F.TRACK, # VeloPixel hits - "NUTHITS": F.VALUE_OR(-1) @ F.NUTHITS @ F.TRACK, # UpstreamTracker hits - "NFTHITS": F.VALUE_OR(-1) @ F.NFTHITS @ F.TRACK, # ForwardTracker hits - "TRACKHASVELO": F.VALUE_OR(-1) @ F.TRACKHASVELO @ F.TRACK, - } - ) - - variables = { - "lab0": B_variables, - "lab1": fs_variables, - "lab2": C_variables, - "lab3": fs_variables, - "lab4": fs_variables, - "lab5": fs_variables, - } - - if options.simulation: - mctruth = MCTruthAndBkgCat(line_data, name="MCTruthAndBkgCat") - trueid_bkgcat_info = { - "TRUEID": F.VALUE_OR(0) @ mctruth(F.PARTICLE_ID), - "TRUEKEY": F.VALUE_OR(-1) @ mctruth(F.OBJECT_KEY), - "TRUEPT": mctruth(F.PT), - "TRUEPX": mctruth(F.PX), - "TRUEPY": mctruth(F.PY), - "TRUEPZ": mctruth(F.PZ), - "TRUEENERGY": mctruth(F.ENERGY), - "TRUEP": mctruth(F.P), - "TRUEFOURMOMENTUM": mctruth(F.FOURMOMENTUM), - "TRUETAU": mctruth(F.MC_LIFETIME), - "BKGCAT": mctruth.BkgCat, - } - for field in variables.keys(): - variables[field] += FunctorCollection(trueid_bkgcat_info) - - - odin = get_odin() - rec_summary = get_rec_summary() - # define event level variables - evt_variables = FunctorCollection({ - "RUNNUMBER": F.RUNNUMBER(odin), - "EVENTNUMBER": F.EVENTNUMBER(odin), - "nPVs": F.VALUE_OR(-1) @ F.RECSUMMARY_INFO(rec_summary, "nPVs"), - "nLongTracks": F.VALUE_OR(-1) @ F.RECSUMMARY_INFO(rec_summary, "nLongTracks"), - }) - evt_variables+=FC.SelectionInfo(selection_type="Hlt1", trigger_lines=Hlt1_decisions) - evt_variables+=FC.SelectionInfo(selection_type="Hlt2", trigger_lines=Hlt2_decisions) - - # define FunTuple instance - my_tuple = Funtuple( - name="Tuple", - tuple_name="DecayTree", - fields=fields, - variables=variables, - event_variables=evt_variables, - inputs=line_data, - store_multiple_cand_info=True, - ) - - return make_config(options, [my_filter, my_tuple]) - diff --git a/Beauty_XS_Bs2DsPi/hlt1.py b/Beauty_XS_Bs2DsPi/hlt1.py deleted file mode 100644 index d40c23bc29..0000000000 --- a/Beauty_XS_Bs2DsPi/hlt1.py +++ /dev/null @@ -1,31 +0,0 @@ -############################################################################### -# (c) Copyright 2023 CERN for the benefit of the LHCb Collaboration # -# # -# This software is distributed under the terms of the GNU General Public # -# Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". # -# # -# In applying this licence, CERN does not waive the privileges and immunities # -# granted to it by virtue of its status as an Intergovernmental Organization # -# or submit itself to any jurisdiction. # -############################################################################### -""" -Configures running HLT1 via Moore. -""" - -from Moore import Options -from Moore.config import allen_control_flow -from RecoConf.hlt1_allen import allen_gaudi_config, get_allen_line_names -from PyConf.application import configure_input, configure - -def alg_config(options: Options): - """ - Configures algorithm running of HLT1 via Moore to be passed to Analysis Productions. - """ - - config = configure_input(options) - with allen_gaudi_config.bind(sequence="hlt1_pp_matching_no_ut_1000KHz"): - line_names = get_allen_line_names() - allen_node = allen_control_flow(options) - config.update(configure(options, allen_node)) - - return config diff --git a/Beauty_XS_Bs2DsPi/hlt2.py b/Beauty_XS_Bs2DsPi/hlt2.py deleted file mode 100644 index 86070c155c..0000000000 --- a/Beauty_XS_Bs2DsPi/hlt2.py +++ /dev/null @@ -1,68 +0,0 @@ -############################################################################### -# (c) Copyright 2023 CERN for the benefit of the LHCb Collaboration # -# # -# This software is distributed under the terms of the GNU General Public # -# Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". # -# # -# In applying this licence, CERN does not waive the privileges and immunities # -# granted to it by virtue of its status as an Intergovernmental Organization # -# or submit itself to any jurisdiction. # -############################################################################### -""" -Configures running HLT2 via Moore. -""" - -from Moore import options, Options, run_moore -from Hlt2Conf.lines.b_to_open_charm import all_lines -# -from RecoConf.global_tools import stateProvider_with_simplified_geom, trackMasterExtrapolator_with_simplified_geom -from RecoConf.reconstruction_objects import reconstruction -from RecoConf.hlt2_global_reco import reconstruction as hlt2_reconstruction, make_light_reco_pr_kf_without_UT -from RecoConf.hlt2_tracking import ( - make_TrackBestTrackCreator_tracks, - make_PrKalmanFilter_noUT_tracks, - make_PrKalmanFilter_Velo_tracks, - make_PrKalmanFilter_Seed_tracks, -) -from RecoConf.decoders import default_VeloCluster_source -from RecoConf.event_filters import require_gec -from Hlt2Conf.settings.defaults import get_default_hlt1_filter_code_for_hlt2 -import sys - -all_lines = {} -from Hlt2Conf.lines.b_to_open_charm.hlt2_b2oc import make_hlt2_lines -default_lines = [ - 'BdToDsmPi_DsmToKpKmPim', -] -extra_config = { - 'flavour_tagging': [ - 'BdToDsmPi_DsmToKpKmPim', - ] -} -make_hlt2_lines( - line_dict=all_lines, - all_lines=default_lines, - extra_config=extra_config) - -def make_lines(): - lines = [builder() for builder in all_lines.values()] - return lines - -def alg_config(options: Options): - - public_tools = [ - trackMasterExtrapolator_with_simplified_geom(), - stateProvider_with_simplified_geom() - ] - - # require_gec.bind(skipUT=True),\ # B2OC lines do not have require_gec() - with reconstruction.bind(from_file=False),\ - hlt2_reconstruction.bind(make_reconstruction=make_light_reco_pr_kf_without_UT),\ - default_VeloCluster_source.bind(bank_type="VPRetinaCluster"),\ - make_TrackBestTrackCreator_tracks.bind(max_ghost_prob=0.7, max_chi2ndof=sys.float_info.max),\ - make_PrKalmanFilter_Velo_tracks.bind(max_chi2ndof=5.),\ - make_PrKalmanFilter_noUT_tracks.bind(max_chi2ndof=4.),\ - make_PrKalmanFilter_Seed_tracks.bind(max_chi2ndof=6.): - config = run_moore(options, make_lines, public_tools) - - return config diff --git a/Beauty_XS_Bs2DsPi/info.yaml b/Beauty_XS_Bs2DsPi/info.yaml deleted file mode 100644 index b903958273..0000000000 --- a/Beauty_XS_Bs2DsPi/info.yaml +++ /dev/null @@ -1,79 +0,0 @@ - -defaults: - wg: B2OC - automatically_configure: no - inform: - - alessandro.bertolin@pd.infn.it - -{%- set mc_datasets = [ -('13264021', 'Down', 'sim10-2024.Q1.2-v1.0-md100', 'dddb-20240427'), -('13264021', 'Up', 'sim10-2024.Q1.2-v1.0-mu100', 'dddb-20240427'), -]%} - -{%- for evttype, polarity, conddb, dddb in mc_datasets %} - -MC_Bs2DsPi_{{ polarity }}_Nu4d3_hlt1: - application: Moore/v55r9@x86_64_v2-el9-gcc13+detdesc-opt - input: - bk_query: "/MC/Dev/Beam6800GeV-2024.Q1.2-Mag{{ polarity }}-VeloDrift-Nu4.3-25ns-Pythia8/Sim10d/{{ evttype }}/DIGI" - dq_flags: - - OK - n_test_lfns: 1 - options: - entrypoint: Beauty_XS_Bs2DsPi.hlt1:alg_config - extra_options: - input_raw_format: 0.5 - conddb_tag: {{ conddb }} - dddb_tag: {{ dddb }} - input_type: "ROOT" - output_type: "ROOT" - simulation: True - data_type: "Upgrade" - scheduler_legacy_mode: False - compression: - algorithm: ZSTD - level: 1 - max_buffer_size: 1048576 - output: hlt1.dst - -MC_Bs2DsPi_{{ polarity }}_Nu4d3_hlt2: - application: Moore/v55r9@x86_64_v2-el9-gcc13+detdesc-opt - input: - job_name: MC_Bs2DsPi_{{ polarity }}_Nu4d3_hlt1 - options: - entrypoint: Beauty_XS_Bs2DsPi.hlt2:alg_config - extra_options: - input_raw_format: 0.5 - persistreco_version: 0.0 - conddb_tag: {{ conddb }} - dddb_tag: {{ dddb }} - input_type: "ROOT" - output_type: "ROOT" - simulation: True - data_type: "Upgrade" - output_manifest_file: hlt2_{{ evttype }}_{{ polarity }}.tck.json - scheduler_legacy_mode: False - compression: - algorithm: ZSTD - level: 1 - max_buffer_size: 1048576 - output: hlt2.dst - -MC_Bs2DsPi_{{ polarity }}_Nu4d3_DV: - application: DaVinci/v64r6@x86_64_v2-el9-gcc13+detdesc-opt - input: - job_name: MC_Bs2DsPi_{{ polarity }}_Nu4d3_hlt2 - output: dv_{{ polarity }}.root - options: - entrypoint: Beauty_XS_Bs2DsPi.dv_simple:alg_config - extra_options: - input_raw_format: 0.5 - input_type: "ROOT" - simulation: True - data_type: "Upgrade" - conddb_tag: {{ conddb }} - dddb_tag: {{ dddb }} - input_process: "Hlt2" - -{%- endfor %} - -- GitLab From 36af0f76ffc2f93848def7775c74fbabc23f1d0f Mon Sep 17 00:00:00 2001 From: Seophine Stanislaus <seophine.stanislaus@cern.ch> Date: Mon, 24 Jun 2024 14:00:56 +0200 Subject: [PATCH 03/15] PID 2024 mag up --- run3_pidcalib_tupling/Functions.py | 450 ++++++++++++++ run3_pidcalib_tupling/alg.py | 239 ++++++++ run3_pidcalib_tupling/info.yaml | 115 ++++ .../tupling_PID_turboonly.py | 561 ++++++++++++++++++ run3_pidcalib_tupling/tupling_PID_turboraw.py | 271 +++++++++ 5 files changed, 1636 insertions(+) create mode 100644 run3_pidcalib_tupling/Functions.py create mode 100644 run3_pidcalib_tupling/alg.py create mode 100644 run3_pidcalib_tupling/info.yaml create mode 100644 run3_pidcalib_tupling/tupling_PID_turboonly.py create mode 100644 run3_pidcalib_tupling/tupling_PID_turboraw.py diff --git a/run3_pidcalib_tupling/Functions.py b/run3_pidcalib_tupling/Functions.py new file mode 100644 index 0000000000..d11432b7f8 --- /dev/null +++ b/run3_pidcalib_tupling/Functions.py @@ -0,0 +1,450 @@ +import Functors as F +from FunTuple import FunctorCollection +from FunTuple.functorcollections import ( + Kinematics, + ParticleID, + ChargedCaloInfo, + DecayTreeFitterResults, +) +from DecayTreeFitter import DecayTreeFitter + + +def get_hlt2_vars(hlt2_dec_report, hlt2_lines): + + hlt_two_vars = FunctorCollection( + { + "Hlt2_TCK": F.TCK(hlt2_dec_report), + "Hlt2_DECISIONS": F.DECREPORTS_FILTER( + DecReports=hlt2_dec_report, Lines=hlt2_lines + ), + } + ) + return hlt_two_vars + + +def get_rec_summary_vars(rec_summary, odin): + + rec_summary_vars = FunctorCollection( + { + "EVENTTYPE": F.EVENTTYPE(odin), + "nPVs": F.VALUE_OR(-1) @ F.RECSUMMARY_INFO(rec_summary, "nPVs"), + "nLongTracks": F.VALUE_OR(-1) + @ F.RECSUMMARY_INFO(rec_summary, "nLongTracks"), + "nDownstreamTracks": F.VALUE_OR(-1) + @ F.RECSUMMARY_INFO(rec_summary, "nDownstreamTracks"), + "nUpstreamTracks": F.VALUE_OR(-1) + @ F.RECSUMMARY_INFO(rec_summary, "nUpstreamTracks"), + "nVeloTracks": F.VALUE_OR(-1) + @ F.RECSUMMARY_INFO(rec_summary, "nVeloTracks"), + "nTTracks": F.VALUE_OR(-1) @ F.RECSUMMARY_INFO(rec_summary, "nTTracks"), + "nBackTracks": F.VALUE_OR(-1) + @ F.RECSUMMARY_INFO(rec_summary, "nBackTracks"), + "nTracks": F.VALUE_OR(-1) @ F.RECSUMMARY_INFO(rec_summary, "nTracks"), + "nGhosts": F.VALUE_OR(-1) @ F.RECSUMMARY_INFO(rec_summary, "nGhosts"), + "nRich1Hits": F.VALUE_OR(-1) @ F.RECSUMMARY_INFO(rec_summary, "nRich1Hits"), + "nRich2Hits": F.VALUE_OR(-1) @ F.RECSUMMARY_INFO(rec_summary, "nRich2Hits"), + "nVeloClusters": F.VALUE_OR(-1) + @ F.RECSUMMARY_INFO(rec_summary, "nVeloClusters"), + "nFTClusters": F.VALUE_OR(-1) + @ F.RECSUMMARY_INFO(rec_summary, "nFTClusters"), + "nITClusters": F.VALUE_OR(-1) + @ F.RECSUMMARY_INFO(rec_summary, "nITClusters"), + "nTTClusters": F.VALUE_OR(-1) + @ F.RECSUMMARY_INFO(rec_summary, "nTTClusters"), + "nUTClusters": F.VALUE_OR(-1) + @ F.RECSUMMARY_INFO(rec_summary, "nUTClusters"), + "nOTClusters": F.VALUE_OR(-1) + @ F.RECSUMMARY_INFO(rec_summary, "nOTClusters"), + "nVPClusters": F.VALUE_OR(-1) + @ F.RECSUMMARY_INFO(rec_summary, "nVPClusters"), + "eCalTot": F.VALUE_OR(-1) @ F.RECSUMMARY_INFO(rec_summary, "eCalTot"), + "hCalTot": F.VALUE_OR(-1) @ F.RECSUMMARY_INFO(rec_summary, "hCalTot"), + "nEcalClusters": F.VALUE_OR(-1) + @ F.RECSUMMARY_INFO(rec_summary, "nEcalClusters"), + "nMuonCoordsS0": F.VALUE_OR(-1) + @ F.RECSUMMARY_INFO(rec_summary, "nMuonCoordsS0"), + "nMuonCoordsS1": F.VALUE_OR(-1) + @ F.RECSUMMARY_INFO(rec_summary, "nMuonCoordsS1"), + "nMuonCoordsS2": F.VALUE_OR(-1) + @ F.RECSUMMARY_INFO(rec_summary, "nMuonCoordsS2"), + "nMuonCoordsS3": F.VALUE_OR(-1) + @ F.RECSUMMARY_INFO(rec_summary, "nMuonCoordsS3"), + "nMuonCoordsS4": F.VALUE_OR(-1) + @ F.RECSUMMARY_INFO(rec_summary, "nMuonCoordsS4"), + "nMuonTracks": F.VALUE_OR(-1) + @ F.RECSUMMARY_INFO(rec_summary, "nMuonTracks"), + } + ) + + return rec_summary_vars + + +def get_common_vars(pvs): + + common_vars = FunctorCollection( + { + "ALLPVX": F.ALLPVX(pvs), + "ALLPVY": F.ALLPVY(pvs), + "ALLPVZ": F.ALLPVZ(pvs), + "BPVIP": F.BPVIP(pvs), + "BPVIPCHI2": F.BPVIPCHI2(pvs), + "BPVX": F.BPVX(pvs), + "BPVY": F.BPVY(pvs), + "BPVZ": F.BPVZ(pvs), + "CHARGE": F.CHARGE, + "CHI2": F.CHI2, + "CHI2DOF": F.CHI2DOF, + "ETA": F.ETA, + "FOURMOMENTUM": F.FOURMOMENTUM, + "PARTICLE_ID": F.PARTICLE_ID, + "MINIP": F.MINIP(pvs), + "MINIPCHI2": F.MINIPCHI2(pvs), + "PHI": F.PHI, + "POSITION_STATEAT_BegRich1_X" : F.POSITION_X @ F.STATE_AT("BegRich1") @ F.TRACK , + "POSITION_STATEAT_BegRich1_Y" : F.POSITION_Y @ F.STATE_AT("BegRich1") @ F.TRACK , + "POSITION_STATEAT_BegRich1_Z" : F.POSITION_Z @ F.STATE_AT("BegRich1") @ F.TRACK , + "POSITION_STATEAT_EndRich1_X" : F.POSITION_X @ F.STATE_AT("EndRich1") @ F.TRACK , + "POSITION_STATEAT_EndRich1_Y" : F.POSITION_Y @ F.STATE_AT("EndRich1") @ F.TRACK , + "POSITION_STATEAT_EndRich1_Z" : F.POSITION_Z @ F.STATE_AT("EndRich1") @ F.TRACK , + "POSITION_STATEAT_BegRich2_X" : F.POSITION_X @ F.STATE_AT("BegRich2") @ F.TRACK , + "POSITION_STATEAT_BegRich2_Y" : F.POSITION_Y @ F.STATE_AT("BegRich2") @ F.TRACK , + "POSITION_STATEAT_BegRich2_Z" : F.POSITION_Z @ F.STATE_AT("BegRich2") @ F.TRACK , + "POSITION_STATEAT_EndRich2_X" : F.POSITION_X @ F.STATE_AT("EndRich2") @ F.TRACK , + "POSITION_STATEAT_EndRich2_Y" : F.POSITION_Y @ F.STATE_AT("EndRich2") @ F.TRACK , + "POSITION_STATEAT_EndRich2_Z" : F.POSITION_Z @ F.STATE_AT("EndRich2") @ F.TRACK , + + } + ) + common_vars += Kinematics() + + return common_vars + + +def get_composite_vars(pvs): + + composite_vars = FunctorCollection( + { + "ALLPV_FD": F.ALLPV_FD(pvs), + "ALLPV_IP": F.ALLPV_IP(pvs), + "BPVCORRM": F.BPVCORRM(pvs), + "BPVCORRMERR": F.BPVCORRMERR(pvs), + "BPVDIRA": F.BPVDIRA(pvs), + "BPVDLS": F.BPVDLS(pvs), + "BPVETA": F.BPVETA(pvs), + "BPVFD": F.BPVFD(pvs), + "BPVFDCHI2": F.BPVFDCHI2(pvs), + "BPVFDIR": F.BPVFDIR(pvs), + "BPVLTIME": F.BPVLTIME(pvs), + "BPVVDRHO": F.BPVVDRHO(pvs), + "BPVVDX": F.BPVVDX(pvs), + "BPVVDY": F.BPVVDY(pvs), + "BPVVDZ": F.BPVVDZ(pvs), + "DOCACHI2_12": F.DOCACHI2(Child1=1, Child2=2), + "DOCA_12": F.DOCA(Child1=1, Child2=2), + "MAXDOCA": F.MAXDOCA, + "MAXDOCACHI2": F.MAXDOCACHI2, + "SDOCACHI2_12": F.SDOCACHI2(Child1=1, Child2=2), + "SDOCA_12": F.SDOCA(Child1=1, Child2=2), + "END_VX": F.END_VX, + "END_VY": F.END_VY, + "END_VZ": F.END_VZ, + } + ) + + return composite_vars + + +def get_rich_pid_vars(): + + RICH_PID_vars = FunctorCollection( + { + "PPHASRICH": F.PPHASRICH @ F.PROTOPARTICLE, + "RICH1_GAS_USED": F.RICH1_GAS_USED, + "RICH2_GAS_USED": F.RICH2_GAS_USED, + "RICH_DLL_BT": F.RICH_DLL_BT, + "RICH_DLL_D": F.RICH_DLL_D, + "RICH_DLL_E": F.RICH_DLL_E, + "RICH_DLL_K": F.RICH_DLL_K, + "RICH_DLL_MU": F.RICH_DLL_MU, + "RICH_DLL_P": F.RICH_DLL_P, + "RICH_DLL_PI": F.RICH_DLL_PI, + "RICH_SCALED_DLL_E": F.RICH_SCALED_DLL_E, + "RICH_SCALED_DLL_MU": F.RICH_SCALED_DLL_MU, + "RICH_THRESHOLD_DE": F.RICH_THRESHOLD_DE, + "RICH_THRESHOLD_EL": F.RICH_THRESHOLD_EL, + "RICH_THRESHOLD_KA": F.RICH_THRESHOLD_KA, + "RICH_THRESHOLD_MU": F.RICH_THRESHOLD_MU, + "RICH_THRESHOLD_PI": F.RICH_THRESHOLD_PI, + "RICH_THRESHOLD_PR": F.RICH_THRESHOLD_PR, + } + ) + + return RICH_PID_vars + + +def get_muon_pid_vars(): + + muon_PID_vars = FunctorCollection( + { + "PPHASMUONINFO": F.PPHASMUONINFO @ F.PROTOPARTICLE, + "INMUON": F.INMUON, + "ISMUON": F.ISMUON, + "ISMUONTIGHT": F.ISMUONTIGHT, + "MUONCATBOOST": F.MUONCATBOOST, + "MUONCHI2CORR": F.MUONCHI2CORR, + "MUONLLBG": F.MUONLLBG, + "MUONLLMU": F.MUONLLMU, + } + ) + + return muon_PID_vars + + +def get_general_pid_vars(): + """ + Get the PID_X and PROBNN_X functors + """ + return ParticleID(extra_info=True) + + +def get_track_vars(): + + track_vars = FunctorCollection( + { + "GHOSTPROB": F.GHOSTPROB, + "NFTHITS": F.VALUE_OR(-1) @ F.NFTHITS @ F.TRACK, + "NHITS": F.VALUE_OR(-1) @ F.NHITS @ F.TRACK, + "NUTHITS": F.VALUE_OR(-1) @ F.NUTHITS @ F.TRACK, + "NVPHITS": F.VALUE_OR(-1) @ F.NVPHITS @ F.TRACK, + "OBJECT_KEY": F.VALUE_OR(-1) @ F.OBJECT_KEY @ F.TRACK, + "QOVERP": F.QOVERP @ F.TRACK, + "TRACKTYPE": F.VALUE_OR(-1) @ F.TRACKTYPE @ F.TRACK, + "TCHI2DOF": F.CHI2DOF @ F.TRACK, + "TRACKHAST": F.VALUE_OR(-1) @ F.TRACKHAST @ F.TRACK, + "TRACKHASUT": F.VALUE_OR(-1) @ F.TRACKHASUT @ F.TRACK, + "TRACKHASVELO": F.VALUE_OR(-1) @ F.TRACKHASVELO @ F.TRACK, + "TRACKHISTORY": F.VALUE_OR(-1) @ F.TRACKHISTORY @ F.TRACK, + "TRACKISCLONE": F.VALUE_OR(-1) @ F.TRACKISCLONE @ F.TRACK, + "TRACKISDOWNSTREAM": F.VALUE_OR(-1) @ F.TRACKISDOWNSTREAM @ F.TRACK, + "TRACKISINVALID": F.VALUE_OR(-1) @ F.TRACKISINVALID @ F.TRACK, + "TRACKISLONG": F.VALUE_OR(-1) @ F.TRACKISLONG @ F.TRACK, + "TRACKISSELECTED": F.VALUE_OR(-1) @ F.TRACKISSELECTED @ F.TRACK, + "TRACKISTTRACK": F.VALUE_OR(-1) @ F.TRACKISTTRACK @ F.TRACK, + "TRACKISUPSTREAM": F.VALUE_OR(-1) @ F.TRACKISUPSTREAM @ F.TRACK, + "TRACKISVELO": F.VALUE_OR(-1) @ F.TRACKISVELO @ F.TRACK, + "TRACKISVELOBACKWARD": F.VALUE_OR(-1) @ F.TRACKISVELOBACKWARD @ F.TRACK, + "TRACK_P": F.VALUE_OR(-1) @ F.P @ F.TRACK, + "TRACK_PT": F.VALUE_OR(-1) @ F.PT @ F.TRACK, + "TRACK_PX": F.VALUE_OR(-1) @ F.PX @ F.TRACK, + "TRACK_PY": F.VALUE_OR(-1) @ F.PY @ F.TRACK, + "TRACK_PX": F.VALUE_OR(-1) @ F.PZ @ F.TRACK, + # "TRACK_PT_WITH_BREM": F.VALUE_OR(-1) @ F.PT_WITH_BREM @ F.TRACK, + # "TRACK_P_WITH_BREM": F.VALUE_OR(-1) @ F.P_WITH_BREM @ F.TRACK, + } + ) + + return track_vars + + +def get_charged_calo_vars(): + """ + Full list at https://gitlab.cern.ch/lhcb/DaVinci/-/blob/2024-patches/Phys/FunTuple/python/FunTuple/functorcollections.py + extra_info includes electron / brem variables + """ + return ChargedCaloInfo(extra_info=True) + + +def get_three_body_vars(): + + three_body_vars = FunctorCollection( + { + "DOCACHI2_13": F.DOCACHI2(Child1=1, Child2=3), + "DOCACHI2_23": F.DOCACHI2(Child1=2, Child2=3), + "DOCA_13": F.DOCA(Child1=1, Child2=3), + "DOCA_23": F.DOCA(Child1=2, Child2=3), + "SDOCACHI2_13": F.SDOCACHI2(Child1=1, Child2=3), + "SDOCACHI2_23": F.SDOCACHI2(Child1=2, Child2=3), + "SDOCA_13": F.SDOCA(Child1=1, Child2=3), + "SDOCA_23": F.SDOCA(Child1=2, Child2=3), + } + ) + + return three_body_vars + + +def get_four_body_vars(): + + four_body_vars = FunctorCollection( + { + "DOCACHI2_14": F.DOCACHI2(Child1=1, Child2=4), + "DOCACHI2_24": F.DOCACHI2(Child1=2, Child2=4), + "DOCACHI2_34": F.DOCACHI2(Child1=3, Child2=4), + "DOCA_14": F.DOCA(Child1=1, Child2=4), + "DOCA_24": F.DOCA(Child1=2, Child2=4), + "DOCA_34": F.DOCA(Child1=3, Child2=4), + "SDOCACHI2_14": F.SDOCACHI2(Child1=1, Child2=4), + "SDOCACHI2_24": F.SDOCACHI2(Child1=2, Child2=4), + "SDOCACHI2_34": F.SDOCACHI2(Child1=3, Child2=4), + "SDOCA_14": F.SDOCA(Child1=1, Child2=4), + "SDOCA_24": F.SDOCA(Child1=2, Child2=4), + "SDOCA_34": F.SDOCA(Child1=3, Child2=4), + } + ) + + return four_body_vars + + +def get_d_to_kpipipi_misid_vars(): + + d0tokpipipi_misid_vars = FunctorCollection( + { + "WM_PIMPIMPIPKP": F.MASSWITHHYPOTHESES(("pi-", "pi-", "pi+", "K+")), + "WM_PIMPIMKPPIP": F.MASSWITHHYPOTHESES(("pi-", "pi-", "K+", "pi+")), + } + ) + + return d0tokpipipi_misid_vars + + +def get_d_to_kpi_misid_vars(): + + d0tokpi_misid_vars = FunctorCollection( + { + "WM_PIK": F.MASSWITHHYPOTHESES(("pi-", "K+")), + "WM_PIPI": F.MASSWITHHYPOTHESES(("pi-", "pi+")), + "WM_KK": F.MASSWITHHYPOTHESES(("K-", "K+")), + } + ) + + return d0tokpi_misid_vars + + +def get_ks_to_pipi_misid_vars(): + + kstopipi_misid_vars = FunctorCollection( + { + "WM_PPI": F.MASSWITHHYPOTHESES(("p+", "pi-")), + "WM_PIP": F.MASSWITHHYPOTHESES(("pi+", "p~-")), + } + ) + return kstopipi_misid_vars + + +def get_l0_to_ppi_misid_vars(): + + l0toppi_misid_vars = FunctorCollection( + {"WM_PIPI": F.MASSWITHHYPOTHESES(("pi+", "pi-"))} + ) + + return l0toppi_misid_vars + + +def get_lc_to_pkpi_misid_vars(): + + lctopkpi_misid_vars = FunctorCollection( + { + "WM_PIKPI": F.MASSWITHHYPOTHESES(("pi+", "K-", "pi-")), + "WM_KKPI": F.MASSWITHHYPOTHESES(("K+", "K-", "pi-")), + } + ) + + return lctopkpi_misid_vars + + + +def get_dtf_variables(options, data, mass, pv): + func_coll = FunctorCollection( + { + "ETA": F.ETA, + "FOURMOMENTUM": F.FOURMOMENTUM, + } + ) + func_coll += Kinematics() + + if mass == "J/psi(1S)": + DTF = DecayTreeFitter( + name="JpsiMFit_{hash}", + input_particles=data, + mass_constraints=[mass], + output_level=3, + ) + dtf_variables = FunctorCollection( + {"JpsiMFit_" + k: DTF(v) for k, v in func_coll.get_thor_functors().items()} + ) + DTF = DecayTreeFitter( + name="PVandJpsiMFit_{hash}", + input_particles=data, + input_pvs=pv, + mass_constraints=[mass], + output_level=3, + ) + dtf_variables += FunctorCollection( + {"PVandJpsiMFit_" + k: DTF(v) for k, v in func_coll.get_thor_functors().items()} + ) + + elif mass == "B+": + DTF = DecayTreeFitter( + name="BMFit_{hash}", + input_particles=data, + mass_constraints=[mass], + output_level=3, + ) + dtf_variables = FunctorCollection( + {"BMFit_" + k: DTF(v) for k, v in func_coll.get_thor_functors().items()} + ) + DTF = DecayTreeFitter( + name="PVandBMFit_{hash}", + input_particles=data, + input_pvs=pv, + mass_constraints=[mass], + output_level=3, + ) + dtf_variables += FunctorCollection( + {"PVandBMFit_" + k: DTF(v) for k, v in func_coll.get_thor_functors().items()} + ) + + elif mass == "D*(2010)+": + DTF = DecayTreeFitter( + name="DstMFit_{hash}", + input_particles=data, + mass_constraints=[mass], + output_level=3, + ) + dtf_variables = FunctorCollection( + {"DstMFit_" + k: DTF(v) for k, v in func_coll.get_thor_functors().items()} + ) + DTF = DecayTreeFitter( + name="PVandDstMFit_{hash}", + input_particles=data, + input_pvs=pv, + mass_constraints=[mass], + output_level=3, + ) + dtf_variables += FunctorCollection( + {"PVandDstMFit_" + k: DTF(v) for k, v in func_coll.get_thor_functors().items()} + ) + + elif mass == "D0": + DTF = DecayTreeFitter( + name="D0MFit_{hash}", + input_particles=data, + mass_constraints=[mass], + output_level=3, + ) + dtf_variables = FunctorCollection( + {"D0MFit_" + k: DTF(v) for k, v in func_coll.get_thor_functors().items()} + ) + DTF = DecayTreeFitter( + name="PVandD0MFit_{hash}", + input_particles=data, + input_pvs=pv, + mass_constraints=[mass], + output_level=3, + ) + dtf_variables += FunctorCollection( + {"PVandD0MFit_" + k: DTF(v) for k, v in func_coll.get_thor_functors().items()} + ) + + return dtf_variables + + diff --git a/run3_pidcalib_tupling/alg.py b/run3_pidcalib_tupling/alg.py new file mode 100644 index 0000000000..2170162ca8 --- /dev/null +++ b/run3_pidcalib_tupling/alg.py @@ -0,0 +1,239 @@ +############################################################################### +# (c) Copyright 2023 CERN for the benefit of the LHCb Collaboration # +# # +# This software is distributed under the terms of the GNU General Public # +# Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". # +# # +# In applying this licence, CERN does not waive the privileges and immunities # +# granted to it by virtue of its status as an Intergovernmental Organization # +# or submit itself to any jurisdiction. # +############################################################################### +""" +Read HLT2 files and create PID calibration ntuples. + +This script follows the Run 2 convention of creating a single file with +multiple trees. +""" + +from .Functions import get_dtf_variables, get_hlt2_vars, get_rec_summary_vars +import Functors as F + +from DaVinci import Options, make_config +from DaVinci.algorithms import create_lines_filter + +# from DaVinciMCTools import MCTruthAndBkgCat + +from FunTuple import FunctorCollection +from FunTuple import FunTuple_Particles as Funtuple +from FunTuple.functorcollections import ( + HltTisTos, + Kinematics, + MCHierarchy, + MCKinematics, + EventInfo, + LHCInfo, + SelectionInfo, + ParticleIsolation, + SMOGInfo, +) +from IsolationTools import VertexAndConeIsolation # type: ignore[import] +from PyConf.reading import get_decreports, get_particles, get_rec_summary, get_odin, get_pvs + +# Uncomment for 2023 data +# from DDDB.CheckDD4Hep import UseDD4Hep +# from Configurables import LHCb__Det__LbDD4hep__DD4hepSvc as DD4hepSvc +# dd4hepSvc = DD4hepSvc() +# dd4hepSvc.DetectorList = ['/world', 'VP', 'FT', 'Magnet', 'Rich1', 'Rich2', 'Ecal', 'Hcal', 'Muon'] #removes the UT + + +def create_tuple_alg(line, data, options): + + # For 2023 data use "/Event/HLT2/HLT2PID_{line}/Particles" + input_data = get_particles(f"/Event/Spruce/SpruceTurCalPID_{line}/Particles") + + # get ODIN and DecReports location + odin = get_odin() + hlt2_dec = get_decreports("Hlt2") + hlt1_dec = get_decreports("Hlt1") + + pvs = get_pvs() + + # Add DTF variables + if "BToJpsiK_JpsiToE" in line: + data["variables"]["B"] += get_dtf_variables( + options, input_data, mass="J/psi(1S)", pv=pvs + ) + data["variables"]["Jpsi"] += get_dtf_variables( + options, input_data, mass="B+", pv=pvs + ) + elif "BToJpsiK_JpsiToMu" in line: + data["variables"]["B"] += get_dtf_variables( + options, input_data, mass="J/psi(1S)", pv=pvs + ) + data["variables"]["Jpsi"] += get_dtf_variables( + options, input_data, mass="B+", pv=pvs + ) + elif "JpsiToMu" in line: + data["variables"]["Jpsi"] += get_dtf_variables( + options, input_data, mass="J/psi(1S)", pv=pvs + ) + elif "DstToD0Pi" in line: + data["variables"]["Dst"] += get_dtf_variables( + options, input_data, mass="D0", pv=pvs + ) + data["variables"]["D"] += get_dtf_variables( + options, input_data, mass="D*(2010)+", pv=pvs + ) + + my_filter = create_lines_filter( + name=f"HDRFilter_{line}", + lines=[f"Hlt2PID_{line}"], + ) + + # get configured "MCTruthAndBkgCatAlg" algorithm for HLT2 output + # mctruth = configured_MCTruthAndBkgCatAlg(inputs=input_data) + + # kin = Kinematics() + # mckin = MCKinematics(mctruth) + # mchierarchy = MCHierarchy(mctruth) + + # MCTRUTH = lambda func: F.MAP_INPUT(func, mctruth.MCAssocTable) + # extra_info = { + # # Important note: specify an invalid value for integer functors if there exists no truth info. + # # The invalid value for floating point functors is set to nan. + # "TRUEEID": F.VALUE_OR(0) @ MCTRUTH(F.PARTICLE_ID), + # "TRUEEPHI": MCTRUTH(F.PHI), + # } + # extra_info = FC(extra_info) + + # The algorithm mctruth also outputs a map b/w particle and bkg category which can be obtained using the functor + # For more info on background category see: https://twiki.cern.ch/twiki/bin/view/LHCb/TupleToolMCBackgroundInfo + # bkg_cat = FunctorCollection({"BKGCAT": F.BKGCAT(Relations=mctruth.BkgCatTable)}) + + evt_vars = EventInfo() + evt_vars += LHCInfo(extra_info=True) + + hlt2_lines = [f"Hlt2PID_{line}Decision"] + evt_vars += get_hlt2_vars(hlt2_dec, hlt2_lines) + + rec_summary = get_rec_summary() + evt_vars += get_rec_summary_vars(rec_summary, odin) + + evt_vars += EventInfo() + evt_vars += LHCInfo(extra_info=True) + + evt_vars += SMOGInfo() + + hlt1_decisions = [ + # "Hlt1BeamGasDecision", + # "Hlt1BeamOneDecision", + # "Hlt1BeamTwoDecision", + # "Hlt1BothBeamsDecision", + "Hlt1Bs2GammaGammaDecision", + "Hlt1D2KKDecision", + "Hlt1D2KPiAlignmentDecision", + "Hlt1D2KPiDecision", + "Hlt1D2PiPiDecision", + "Hlt1DiMuonHighMassAlignmentDecision", + "Hlt1DiMuonLowMassDecision", + "Hlt1DiMuonNoIPDecision", + "Hlt1DiMuonNoIP_ssDecision", + "Hlt1DiMuonSoftDecision", + "Hlt1DisplacedDiMuonAlignmentDecision", + #"Hlt1DisplacedDielectronDecision", # remove duplicate + "Hlt1DisplacedLeptonsDecision", + # "Hlt1HeavyIonDecision", + "Hlt1KsToPiPiDecision", + # "Hlt1L02PPiDecision", + # "Hlt1LowMassNoipDielectronDecision", + "Hlt1LowMassNoipDielectron_SS_massSlice1_displacedDecision", + "Hlt1LowMassNoipDielectron_SS_massSlice1_promptDecision", + "Hlt1LowMassNoipDielectron_SS_massSlice2_displacedDecision", + "Hlt1LowMassNoipDielectron_SS_massSlice2_promptDecision", + "Hlt1LowMassNoipDielectron_SS_massSlice3_displacedDecision", + "Hlt1LowMassNoipDielectron_SS_massSlice3_promptDecision", + "Hlt1LowMassNoipDielectron_SS_massSlice4_displacedDecision", + "Hlt1LowMassNoipDielectron_SS_massSlice4_promptDecision", + "Hlt1LowMassNoipDielectron_massSlice1_displacedDecision", + "Hlt1LowMassNoipDielectron_massSlice1_promptDecision", + "Hlt1LowMassNoipDielectron_massSlice2_displacedDecision", + "Hlt1LowMassNoipDielectron_massSlice2_promptDecision", + "Hlt1LowMassNoipDielectron_massSlice3_displacedDecision", + "Hlt1LowMassNoipDielectron_massSlice3_promptDecision", + "Hlt1LowMassNoipDielectron_massSlice4_displacedDecision", + "Hlt1LowMassNoipDielectron_massSlice4_promptDecision", + "Hlt1LowPtDiMuonDecision", + "Hlt1LowPtMuonDecision", + # "Hlt1NoBeamDecision", + # "Hlt1ODINLumiDecision", + # "Hlt1ODINNoBiasDecision", + # "Hlt1ODINVeloOpenDecision", + "Hlt1OneMuonTrackLineDecision", + # "Hlt1PassthroughDecision", + "Hlt1RICH1AlignmentDecision", + "Hlt1RICH2AlignmentDecision", + # "Hlt1SingleCaloClusterDecision", + "Hlt1DisplacedDiMuonDecision", + "Hlt1SingleHighPtMuonNoMuIDDecision", + "Hlt1TrackElectronMVADecision", + "Hlt1Pi02GammaGammaDecision", + "Hlt1TwoKsDecision", + "Hlt1TwoTrackKsDecision", + "Hlt1TwoTrackMVACharmXSecDecision", + "Hlt1SingleHighEtDecision", #RB 14 + "Hlt1DisplacedDielectronDecision", #RB 14 + "Hlt1SingleHighPtElectronDecision", #RB 14 + "Hlt1TrackMuonMVADecision", #RB 14 + "Hlt1DiMuonHighMassDecision", #RB 14 + "Hlt1SingleHighPtMuonDecision", #RB 14 + "Hlt1TrackMVADecision", #RB 14 + "Hlt1TwoTrackMVADecision", #RB 14 + "Hlt1Dst2D0PiDecision", #RB 17 + "Hlt1DetJpsiToMuMuPosTagLineDecision", #RB 17 + "Hlt1DetJpsiToMuMuNegTagLineDecision" #RB 17 + ] + # SMOG lines + hlt1lines_muon = [ "Hlt1SMOG2SingleMuonDecision", "Hlt1SMOG2DiMuonHighMassDecision",] + hlt1lines_BE = [ "Hlt1SMOG2BENoBiasDecision", "Hlt1SMOG2PassThroughLowMult5Decision", "Hlt1SMOG2BELowMultElectronsDecision" ] + hlt1lines_MB = [ "Hlt1SMOG2MinimumBiasDecision", "Hlt1PassthroughPVinSMOG2Decision" ] + hlt1lines_track = [ "Hlt1SMOG2SingleTrackHighPtDecision", "Hlt1SMOG2SingleTrackVeryHighPtDecision", "Hlt1SMOG22BodyGenericDecision", "Hlt1SMOG22BodyGenericPromptDecision"] + hlt1lines_hadron = [ "Hlt1SMOG2etacToppDecision", "Hlt1SMOG2D2KpiDecision", ] + hlt1lines_longlived = [ "Hlt1SMOG2L0ToppiDecision", "Hlt1SMOG2KsTopipiDecision", ] + + hlt1_decisions += hlt1lines_muon + hlt1_decisions += hlt1lines_BE + hlt1_decisions += hlt1lines_MB + hlt1_decisions += hlt1lines_track + hlt1_decisions += hlt1lines_hadron + hlt1_decisions += hlt1lines_longlived + + + # Add event-level Hlt1 decisions + evt_vars += SelectionInfo(selection_type="Hlt1", trigger_lines=hlt1_decisions) + + # Add track-level Hlt1 TIS/TOS decisions + data["variables"]["ALL"] += HltTisTos( + selection_type="Hlt1", trigger_lines=hlt1_decisions, data=input_data + ) + + iso_alg = VertexAndConeIsolation( + name="iso_0.4", + reference_particles=input_data, + related_particles=input_data, + cut=(F.DR2() < 0.4), + ) + + data["variables"]["ALL"] += ParticleIsolation( + isolation_alg=iso_alg, array_indx_name="indx" + ) + + my_tuple = Funtuple( + name=line, + tuple_name="DecayTree", + fields=data["fields"], + variables=data["variables"], + event_variables=evt_vars, + inputs=input_data, + ) + + return {f"{line}_Algs": [my_filter, my_tuple]} diff --git a/run3_pidcalib_tupling/info.yaml b/run3_pidcalib_tupling/info.yaml new file mode 100644 index 0000000000..9a8733e365 --- /dev/null +++ b/run3_pidcalib_tupling/info.yaml @@ -0,0 +1,115 @@ +defaults: + application: "DaVinci/v64r5" + wg: PID + turbo: yes + automatically_configure: no + inform: + - seophine.stanislaus@cern.ch + - innes.mackay@cern.ch + +checks: + histogram_D0ToKPi_M: + type: range + expression: D_M + tree_pattern: DstToD0Pi_D0ToKPi/DecayTree + limits: + min: 1800 + max: 1920 + + histogram_D0ToKPi_DeltaM: + type: range + expression: Dst_M - D_M + tree_pattern: DstToD0Pi_D0ToKPi/DecayTree + limits: + min: 139 + max: 155 + + histogram_D0ToKPiPiPi_DeltaM: + type: range + expression: Dst_M - D_M + tree_pattern: DstToD0Pi_D0ToKPiPiPi/DecayTree + limits: + min: 139 + max: 155 + + histogram_Ks_M: + type: range + expression: Ks_M + tree_pattern: KsToPiPi_.*/DecayTree + limits: + min: 470 + max: 525 + + histogram_L0_M: + type: range + expression: L0_M + tree_pattern: L0ToPPi_LL/DecayTree + limits: + min: 1100 + max: 1130 + + turbo_only_at_least_10_entries: + type: num_entries + tree_pattern: (KsToPiPi_LL|LcToPKPi)/DecayTree + count: 10 + + turbo_raw_at_least_10_entries: + type: num_entries + tree_pattern: (DstToD0Pi_D0ToKPi|L0ToPPi_LL)/DecayTree + count: 10 + + +Collision24_magup_veloclosed_excludeut_turboonly: + options: + entrypoint: run3_pidcalib_tupling.tupling_PID_turboonly:main + extra_options: + input_raw_format: 0.5 + input_type: "ROOT" + conditions_version: "master" + geometry_version: "run3/2024.Q1.2-v00.00" + lumi: true + simulation: false + data_type: "Upgrade" + input_process: "Spruce" + input_stream: "turcal_mdst" + output: PID_TURBOONLY_TUPLE.ROOT + checks: + - histogram_D0ToKPiPiPi_DeltaM + - histogram_Ks_M + - turbo_only_at_least_10_entries + input: + bk_query: "/LHCb/Collision24/Beam6800GeV-VeloClosed-MagUp-Excl-UT/Real Data/Sprucing24c1/95100000/TURCAL_MDST.DST" + dq_flags: + - OK + - UNCHECKED + keep_running: true + n_test_lfns: 1 + +Collision24_magup_veloclosed_excludeut_turboraw: + options: + entrypoint: run3_pidcalib_tupling.tupling_PID_turboraw:main + extra_options: + input_raw_format: 0.5 + input_type: "ROOT" + conditions_version: "master" + geometry_version: "run3/2024.Q1.2-v00.00" + lumi: true + simulation: false + data_type: "Upgrade" + input_process: "Spruce" + input_stream: "turcal_rawbanks" + output: PID_TURBORAW_TUPLE.ROOT + checks: + - histogram_D0ToKPi_M + - histogram_D0ToKPi_DeltaM + - histogram_L0_M + - turbo_raw_at_least_10_entries + input: + bk_query: "/LHCb/Collision24/Beam6800GeV-VeloClosed-MagUp-Excl-UT/Real Data/Sprucing24c1/95100000/TURCAL_RAWBANKS.DST" + dq_flags: + - OK + - UNCHECKED + keep_running: true + n_test_lfns: 1 + + diff --git a/run3_pidcalib_tupling/tupling_PID_turboonly.py b/run3_pidcalib_tupling/tupling_PID_turboonly.py new file mode 100644 index 0000000000..f03daf6995 --- /dev/null +++ b/run3_pidcalib_tupling/tupling_PID_turboonly.py @@ -0,0 +1,561 @@ +############################################################################### +# (c) Copyright 2023 CERN for the benefit of the LHCb Collaboration # +# # +# This software is distributed under the terms of the GNU General Public # +# Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". # +# # +# In applying this licence, CERN does not waive the privileges and immunities # +# granted to it by virtue of its status as an Intergovernmental Organization # +# or submit itself to any jurisdiction. # +############################################################################### +""" +Read HLT2 files and create PID calibration ntuples. +This script follows the Run 2 convention of creating a single file with +multiple trees. +""" +from .alg import create_tuple_alg +from .Functions import * +from DaVinci import Options, make_config +from PyConf.reading import get_pvs + + +# NOTE: Uncomment if using 2023 data! Double check it works first. +# dd4hepSvc = DD4hepSvc() +# dd4hepSvc.DetectorList = ['/world', 'VP', 'FT', 'Magnet', 'Rich1', 'Rich2', 'Ecal', 'Hcal', 'Muon'] #removes the UT + + +def main(options: Options): + + pvs = get_pvs() + + common_vars = get_common_vars(pvs) + composite_vars = get_composite_vars(pvs) + + track_vars = get_track_vars() + rich_pid_vars = get_rich_pid_vars() + muon_pid_vars = get_muon_pid_vars() + general_pid_vars = get_general_pid_vars() + charged_calo_vars = get_charged_calo_vars() + stable_vars = ( + track_vars + + rich_pid_vars + + muon_pid_vars + + general_pid_vars + + charged_calo_vars + ) + + three_body_vars = get_three_body_vars() + four_body_vars = get_four_body_vars() + + d0tokpipipi_misid_vars = get_d_to_kpipipi_misid_vars() + kstopipi_misid_vars = get_ks_to_pipi_misid_vars() + l0toppi_misid_vars = get_l0_to_ppi_misid_vars() + lctopkpi_misid_vars = get_lc_to_pkpi_misid_vars() + + lines = {} + + lines["DstToD0Pi_D0ToKPiPiPi"] = { + "fields": { + "Dst": "[D*(2010)+ -> (D0 -> K- pi+ pi+ pi-) pi+]CC", + "D": "[D*(2010)+ -> ^(D0 -> K- pi+ pi+ pi-) pi+]CC", + "pis": "[D*(2010)+ -> (D0 -> K- pi+ pi+ pi-) ^pi+]CC", + "K": "[D*(2010)+ -> (D0 -> ^K- pi+ pi+ pi-) pi+]CC", + "pi1": "[D*(2010)+ -> (D0 -> K- ^pi+ pi+ pi-) pi+]CC", + "pi2": "[D*(2010)+ -> (D0 -> K- pi+ ^pi+ pi-) pi+]CC", + "pi3": "[D*(2010)+ -> (D0 -> K- pi+ pi+ ^pi-) pi+]CC", + }, + "variables": { + "ALL": common_vars, + "Dst": composite_vars, + "D": composite_vars + + d0tokpipipi_misid_vars + + three_body_vars + + four_body_vars, + "pis": stable_vars, + "K": stable_vars, + "pi1": stable_vars, + "pi2": stable_vars, + "pi3": stable_vars, + }, + } + + lines["KsToPiPi_LL"] = { + "fields": { + "Ks": "KS0 -> pi+ pi-", + "pip": "KS0 -> ^pi+ pi-", + "pim": "KS0 -> pi+ ^pi-", + }, + "variables": { + "ALL": common_vars, + "Ks": composite_vars + kstopipi_misid_vars, + "pip": stable_vars, + "pim": stable_vars, + }, + } + + lines["KsToPiPi_DD"] = { + "fields": { + "Ks": "KS0 -> pi+ pi-", + "pip": "KS0 -> ^pi+ pi-", + "pim": "KS0 -> pi+ ^pi-", + }, + "variables": { + "ALL": common_vars, + "Ks": composite_vars + kstopipi_misid_vars, + "pip": stable_vars, + "pim": stable_vars, + }, + } + + lines["L0ToPPi_DD_LowPT"] = { + "fields": { + "L0": "[Lambda0 -> p+ pi-]CC", + "p": "[Lambda0 -> ^p+ pi-]CC", + "pi": "[Lambda0 -> p+ ^pi-]CC", + }, + "variables": { + "ALL": common_vars, + "L0": composite_vars + l0toppi_misid_vars, + "p": stable_vars, + "pi": stable_vars, + }, + } + + lines["L0ToPPi_DD_MidPT"] = { + "fields": { + "L0": "[Lambda0 -> p+ pi-]CC", + "p": "[Lambda0 -> ^p+ pi-]CC", + "pi": "[Lambda0 -> p+ ^pi-]CC", + }, + "variables": { + "ALL": common_vars, + "L0": composite_vars + l0toppi_misid_vars, + "p": stable_vars, + "pi": stable_vars, + }, + } + + lines["L0ToPPi_DD_HighPT"] = { + "fields": { + "L0": "[Lambda0 -> p+ pi-]CC", + "p": "[Lambda0 -> ^p+ pi-]CC", + "pi": "[Lambda0 -> p+ ^pi-]CC", + }, + "variables": { + "ALL": common_vars, + "L0": composite_vars + l0toppi_misid_vars, + "p": stable_vars, + "pi": stable_vars, + }, + } + + lines["L0ToPPi_DD_VeryHighPT"] = { + "fields": { + "L0": "[Lambda0 -> p+ pi-]CC", + "p": "[Lambda0 -> ^p+ pi-]CC", + "pi": "[Lambda0 -> p+ ^pi-]CC", + }, + "variables": { + "ALL": common_vars, + "L0": composite_vars + l0toppi_misid_vars, + "p": stable_vars, + "pi": stable_vars, + }, + } + + lines["LbToLcPi_LcToPKPi"] = { + "fields": { + "Lb": "[Lambda_b0 -> (Lambda_c+ -> p+ K- pi+) pi-]CC", + "Lc": "[Lambda_b0 -> ^(Lambda_c+ -> p+ K- pi+) pi-]CC", + "Lbpi": "[Lambda_b0 -> (Lambda_c+ -> p+ K- pi+) ^pi-]CC", + "p": "[Lambda_b0 -> (Lambda_c+ -> ^p+ K- pi+) pi-]CC", + "K": "[Lambda_b0 -> (Lambda_c+ -> p+ ^K- pi+) pi-]CC", + "pi": "[Lambda_b0 -> (Lambda_c+ -> p+ K- ^pi+) pi-]CC", + }, + "variables": { + "ALL": common_vars, + "Lb": composite_vars, + "Lc": composite_vars + lctopkpi_misid_vars + three_body_vars, + "p": stable_vars, + "K": stable_vars, + "pi": stable_vars, + "Lbpi": stable_vars, + }, + } + + lines["LbToLcMuNu_LcToPKPi"] = { + "fields": { + "Lb": "[Lambda_b0 -> (Lambda_c+ -> p+ K- pi+) mu-]CC", + "Lc": "[Lambda_b0 -> ^(Lambda_c+ -> p+ K- pi+) mu-]CC", + "mu": "[Lambda_b0 -> (Lambda_c+ -> p+ K- pi+) ^mu-]CC", + "p": "[Lambda_b0 -> (Lambda_c+ -> ^p+ K- pi+) mu-]CC", + "K": "[Lambda_b0 -> (Lambda_c+ -> p+ ^K- pi+) mu-]CC", + "pi": "[Lambda_b0 -> (Lambda_c+ -> p+ K- ^pi+) mu-]CC", + }, + "variables": { + "ALL": common_vars, + "Lb": composite_vars, + "Lc": composite_vars + lctopkpi_misid_vars + three_body_vars, + "p": stable_vars, + "K": stable_vars, + "pi": stable_vars, + "mu": stable_vars, + }, + } + + lines["LcToPKPi"] = { + "fields": { + "Lc": "[Lambda_c+ -> p+ K- pi+]CC", + "p": "[Lambda_c+ -> ^p+ K- pi+]CC", + "K": "[Lambda_c+ -> p+ ^K- pi+]CC", + "pi": "[Lambda_c+ -> p+ K- ^pi+]CC", + }, + "variables": { + "ALL": common_vars, + "Lc": composite_vars + lctopkpi_misid_vars + three_body_vars, + "p": stable_vars, + "K": stable_vars, + "pi": stable_vars, + }, + } + + lines["PhiToKK_Unbiased_Detached"] = { + "fields": { + "phi": "phi(1020) -> K+ K-", + "Kp": "phi(1020) -> ^K+ K-", + "Km": "phi(1020) -> K+ ^K-", + }, + "variables": { + "ALL": common_vars, + "phi": composite_vars, + "Kp": stable_vars, + "Km": stable_vars, + }, + } + + lines["PhiToKmKpTagged_Detached"] = { + "fields": { + "phi": "phi(1020) -> K+ K-", + "Ktag": "phi(1020) -> ^K+ K-", + "Kprobe": "phi(1020) -> K+ ^K-", + }, + "variables": { + "ALL": common_vars, + "phi": composite_vars, + "Ktag": stable_vars, + "Kprobe": stable_vars, + }, + } + + lines["PhiToKpKmTagged_Detached"] = { + "fields": { + "phi": "phi(1020) -> K+ K-", + "Kprobe": "phi(1020) -> ^K+ K-", + "Ktag": "phi(1020) -> K+ ^K-", + }, + "variables": { + "ALL": common_vars, + "phi": composite_vars, + "Kprobe": stable_vars, + "Ktag": stable_vars, + }, + } + + lines["DsToPhiPi_PhiToMuMupTagged_Detached"] = { + "fields": { + "Ds": "[D_s+ -> (phi(1020) -> mu+ mu-) pi+]CC", + "phi": "[D_s+ -> ^(phi(1020) -> mu+ mu-) pi+]CC", + "pi": "[D_s+ -> (phi(1020) -> mu+ mu-) ^pi+]CC", + "mutag": "[D_s+ -> (phi(1020) -> ^mu+ mu-) pi+]CC", + "muprobe": "[D_s+ -> (phi(1020) -> mu+ ^mu-) pi+]CC", + }, + "variables": { + "ALL": common_vars, + "Ds": composite_vars, + "phi": composite_vars, + "pi": stable_vars, + "mutag": stable_vars, + "muprobe": stable_vars, + }, + } + + lines["DsToPhiPi_PhiToMuMumTagged_Detached"] = { + "fields": { + "Ds": "[D_s+ -> (phi(1020) -> mu- mu+) pi+]CC", + "phi": "[D_s+ -> ^(phi(1020) -> mu- mu+) pi+]CC", + "pi": "[D_s+ -> (phi(1020) -> mu- mu+) ^pi+]CC", + "mutag": "[D_s+ -> (phi(1020) -> ^mu- mu+) pi+]CC", + "muprobe": "[D_s+ -> (phi(1020) -> mu- ^mu+) pi+]CC", + }, + "variables": { + "ALL": common_vars, + "Ds": composite_vars, + "phi": composite_vars, + "pi": stable_vars, + "mutag": stable_vars, + "muprobe": stable_vars, + }, + } + + lines["BToJpsiK_JpsiToPpPmTagged_Detached"] = { + "fields": { + "B": "[B+]CC -> (J/psi(1S) -> p+ p~-) [K+]CC", + "Jpsi": "[B+]CC -> ^(J/psi(1S) -> p+ p~-) [K+]CC", + "K": "[B+]CC -> (J/psi(1S) -> p+ p~-) ^[K+]CC", + "pprobe": "[B+]CC -> (J/psi(1S) -> ^p+ p~-) [K+]CC", + "ptag": "[B+]CC -> (J/psi(1S) -> p+ ^p~-) [K+]CC", + }, + "variables": { + "ALL": common_vars, + "B": composite_vars, + "Jpsi": composite_vars, + "K": stable_vars, + "pprobe": stable_vars, + "ptag": stable_vars, + }, + } + + lines["BToJpsiK_JpsiToPmPpTagged_Detached"] = { + "fields": { + "B": "[B+]CC -> (J/psi(1S) -> p+ p~-) [K+]CC", + "Jpsi": "[B+]CC -> ^(J/psi(1S) -> p+ p~-) [K+]CC", + "K": "[B+]CC -> (J/psi(1S) -> p+ p~-) ^[K+]CC", + "ptag": "[B+]CC -> (J/psi(1S) -> ^p+ p~-) [K+]CC", + "pprobe": "[B+]CC -> (J/psi(1S) -> p+ ^p~-) [K+]CC", + }, + "variables": { + "ALL": common_vars, + "B": composite_vars, + "Jpsi": composite_vars, + "K": stable_vars, + "ptag": stable_vars, + "pprobe": stable_vars, + }, + } + + lines["OmegaToL0K_L0ToPPi_LLL"] = { + "fields": { + "Omega": "[Omega- -> (Lambda0 -> p+ pi-) K-]CC", + "Lambda0": "[Omega- -> ^(Lambda0 -> p+ pi-) K-]CC", + "K": "[Omega- -> (Lambda0 -> p+ pi-) ^K-]CC", + "p": "[Omega- -> (Lambda0 -> ^p+ pi-) K-]CC", + "pi": "[Omega- -> (Lambda0 -> p+ ^pi-) K-]CC", + }, + "variables": { + "ALL": common_vars, + "Omega": composite_vars, + "K": stable_vars, + "p": stable_vars, + "pi": stable_vars, + }, + } + + lines["OmegaToL0K_L0ToPPi_DDD"] = { + "fields": { + "Omega": "[Omega- -> (Lambda0 -> p+ pi-) K-]CC", + "Lambda0": "[Omega- -> ^(Lambda0 -> p+ pi-) K-]CC", + "K": "[Omega- -> (Lambda0 -> p+ pi-) ^K-]CC", + "p": "[Omega- -> (Lambda0 -> ^p+ pi-) K-]CC", + "pi": "[Omega- -> (Lambda0 -> p+ ^pi-) K-]CC", + }, + "variables": { + "ALL": common_vars, + "Omega": composite_vars, + "K": stable_vars, + "p": stable_vars, + "pi": stable_vars, + }, + } + + lines["SMOG2Dst2KPi"] = { + "fields": { + "Dstp": "[D*(2010)+ -> (D0 -> K- pi+ ) pi+]CC", + "D0": "[D*(2010)+ -> ^(D0 -> K- pi+ ) pi+]CC", + "Km": "[D*(2010)+ -> (D0 -> ^K- pi+ ) pi+]CC", + "pip": "[D*(2010)+ -> (D0 -> K- ^pi+ ) pi+]CC", + "pipsoft": "[D*(2010)+ -> (D0 -> K- pi+ ) ^pi+]CC", + }, + "variables": { + "ALL": common_vars, + "Dstp": composite_vars, + "D0": composite_vars, + "Km": stable_vars, + "pip": stable_vars, + "pipsoft": stable_vars, + }, + } + + lines["SMOG2KS2PiPiDD"] = { + "fields": { + "Ks0": "KS0 -> pi+ pi-", + "pip": "KS0 -> ^pi+ pi-", + "pim": "KS0 -> pi+ ^pi-", + }, + "variables": { + "ALL": common_vars, + "Ks0": composite_vars, + "pip": stable_vars, + "pim": stable_vars, + }, + } + + lines["SMOG2KS2PiPiLLHighPT"] = { + "fields": { + "Ks0": "KS0 -> pi+ pi-", + "pip": "KS0 -> ^pi+ pi-", + "pim": "KS0 -> pi+ ^pi-", + }, + "variables": { + "ALL": common_vars, + "Ks0": composite_vars, + "pip": stable_vars, + "pim": stable_vars, + }, + } + + lines["SMOG2KS2PiPiLLLowPT"] = { + "fields": { + "Ks0": "KS0 -> pi+ pi-", + "pip": "KS0 -> ^pi+ pi-", + "pim": "KS0 -> pi+ ^pi-", + }, + "variables": { + "ALL": common_vars, + "Ks0": composite_vars, + "pip": stable_vars, + "pim": stable_vars, + }, + } + + lines["SMOG2Lambda02PPiDD"] = { + "fields": { + "Lambda": "[Lambda0 -> p+ pi-]CC", + "pbar": "[Lambda0 -> ^p+ pi-]CC", + "pim": "[Lambda0 -> p+ ^pi-]CC", + }, + "variables": { + "ALL": common_vars, + "Lambda": composite_vars, + "pbar": stable_vars, + "pim": stable_vars, + }, + } + + lines["SMOG2Lambda02PPiLLLowPT"] = { + "fields": { + "Lambda": "[Lambda0 -> p+ pi-]CC", + "pbar": "[Lambda0 -> ^p+ pi-]CC", + "pim": "[Lambda0 -> p+ ^pi-]CC", + }, + "variables": { + "ALL": common_vars, + "Lambda": composite_vars, + "pbar": stable_vars, + "pim": stable_vars, + }, + } + + lines["SMOG2Lambda02PPiLLHighPT"] = { + "fields": { + "Lambda": "[Lambda0 -> p+ pi-]CC", + "pbar": "[Lambda0 -> ^p+ pi-]CC", + "pim": "[Lambda0 -> p+ ^pi-]CC", + }, + "variables": { + "ALL": common_vars, + "Lambda": composite_vars, + "pbar": stable_vars, + "pim": stable_vars, + }, + } + + lines["SMOG2PIDJpsi2MuMumTagged"] = { + "fields": { + "Jpsi": "J/psi(1S) -> mu- mu+", + "mum": "J/psi(1S) -> ^mu- mu+", + "mup": "J/psi(1S) -> mu- ^mu+", + }, + "variables": { + "ALL": common_vars, + "Jpsi": composite_vars, + "mum": stable_vars, + "mup": stable_vars, + }, + } + + lines["SMOG2PIDJpsi2MuMupTagged"] = { + "fields": { + "Jpsi": "J/psi(1S) -> mu- mu+", + "mum": "J/psi(1S) -> ^mu- mu+", + "mup": "J/psi(1S) -> mu- ^mu+", + }, + "variables": { + "ALL": common_vars, + "Jpsi": composite_vars, + "mum": stable_vars, + "mup": stable_vars, + }, + } + + lines["SMOG2Phi2kkHighPT_Kmprobe"] = { + "fields": { + "Phi": "phi(1020) -> K+ K-", + "Kp": "phi(1020) -> ^K+ K-", + "Km": "phi(1020) -> ^K+ K-", + }, + "variables": { + "ALL": common_vars, + "Phi": composite_vars, + "Kp": stable_vars, + "Km": stable_vars, + }, + } + + lines["SMOG2Phi2kkHighPT_Kpprobe"] = { + "fields": { + "Phi": "phi(1020) -> K+ K-", + "Kp": "phi(1020) -> ^K+ K-", + "Km": "phi(1020) -> ^K+ K-", + }, + "variables": { + "ALL": common_vars, + "Phi": composite_vars, + "Kp": stable_vars, + "Km": stable_vars, + }, + } + + lines["SMOG2Phi2kk_Kmprobe"] = { + "fields": { + "Phi": "phi(1020) -> K+ K-", + "Kp": "phi(1020) -> ^K+ K-", + "Km": "phi(1020) -> ^K+ K-", + }, + "variables": { + "ALL": common_vars, + "Phi": composite_vars, + "Kp": stable_vars, + "Km": stable_vars, + }, + } + + lines["SMOG2Phi2kk_Kpprobe"] = { + "fields": { + "Phi": "phi(1020) -> K+ K-", + "Kp": "phi(1020) -> ^K+ K-", + "Km": "phi(1020) -> ^K+ K-", + }, + "variables": { + "ALL": common_vars, + "Phi": composite_vars, + "Kp": stable_vars, + "Km": stable_vars, + }, + } + + algs = {} + for line, data in lines.items(): + algs.update(create_tuple_alg(line, data, options)) + + return make_config(options, algs) + diff --git a/run3_pidcalib_tupling/tupling_PID_turboraw.py b/run3_pidcalib_tupling/tupling_PID_turboraw.py new file mode 100644 index 0000000000..eb96f88b0e --- /dev/null +++ b/run3_pidcalib_tupling/tupling_PID_turboraw.py @@ -0,0 +1,271 @@ +############################################################################### +# (c) Copyright 2023 CERN for the benefit of the LHCb Collaboration # +# # +# This software is distributed under the terms of the GNU General Public # +# Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". # +# # +# In applying this licence, CERN does not waive the privileges and immunities # +# granted to it by virtue of its status as an Intergovernmental Organization # +# or submit itself to any jurisdiction. # +############################################################################### +""" +Read HLT2 files and create PID calibration ntuples. + +This script follows the Run 2 convention of creating a single file with +multiple trees. +""" + +from .alg import create_tuple_alg +from .Functions import * +from DaVinci import Options, make_config +from PyConf.reading import get_pvs + + +# NOTE: Uncomment if using 2023 data! Double check it works first. +# dd4hepSvc = DD4hepSvc() +# dd4hepSvc.DetectorList = ['/world', 'VP', 'FT', 'Magnet', 'Rich1', 'Rich2', 'Ecal', 'Hcal', 'Muon'] #removes the UT + + +def main(options: Options): + + pvs = get_pvs() + + common_vars = get_common_vars(pvs) + composite_vars = get_composite_vars(pvs) + + track_vars = get_track_vars() + rich_pid_vars = get_rich_pid_vars() + muon_pid_vars = get_muon_pid_vars() + general_pid_vars = get_general_pid_vars() + charged_calo_vars = get_charged_calo_vars() + stable_vars = ( + track_vars + + rich_pid_vars + + muon_pid_vars + + general_pid_vars + + charged_calo_vars + ) + + three_body_vars = get_three_body_vars() + four_body_vars = get_four_body_vars() + + d0tokpi_misid_vars = get_d_to_kpi_misid_vars() + l0toppi_misid_vars = get_l0_to_ppi_misid_vars() + + lines = {} + lines["DstToD0Pi_D0ToKPi"] = { + "fields": { + "Dst": "[D*(2010)+ -> (D0 -> K- pi+) pi+]CC", + "D": "[D*(2010)+ -> ^(D0 -> K- pi+) pi+]CC", + "pis": "[D*(2010)+ -> (D0 -> K- pi+) ^pi+]CC", + "K": "[D*(2010)+ -> (D0 -> ^K- pi+) pi+]CC", + "pi": "[D*(2010)+ -> (D0 -> K- ^pi+) pi+]CC", + }, + "variables": { + "ALL": common_vars, + "Dst": composite_vars, + "D": composite_vars + d0tokpi_misid_vars, + "pis": stable_vars, + "K": stable_vars, + "pi": stable_vars, + }, + } + + lines["L0ToPPi_LL_LowPT"] = { + "fields": { + "L0": "[Lambda0 -> p+ pi-]CC", + "p": "[Lambda0 -> ^p+ pi-]CC", + "pi": "[Lambda0 -> p+ ^pi-]CC", + }, + "variables": { + "ALL": common_vars, + "L0": composite_vars + l0toppi_misid_vars, + "p": stable_vars, + "pi": stable_vars, + }, + } + + lines["L0ToPPi_LL_MidPT"] = { + "fields": { + "L0": "[Lambda0 -> p+ pi-]CC", + "p": "[Lambda0 -> ^p+ pi-]CC", + "pi": "[Lambda0 -> p+ ^pi-]CC", + }, + "variables": { + "ALL": common_vars, + "L0": composite_vars + l0toppi_misid_vars, + "p": stable_vars, + "pi": stable_vars, + }, + } + + lines["L0ToPPi_LL_HighPT"] = { + "fields": { + "L0": "[Lambda0 -> p+ pi-]CC", + "p": "[Lambda0 -> ^p+ pi-]CC", + "pi": "[Lambda0 -> p+ ^pi-]CC", + }, + "variables": { + "ALL": common_vars, + "L0": composite_vars + l0toppi_misid_vars, + "p": stable_vars, + "pi": stable_vars, + }, + } + + lines["L0ToPPi_LL_VeryHighPT"] = { + "fields": { + "L0": "[Lambda0 -> p+ pi-]CC", + "p": "[Lambda0 -> ^p+ pi-]CC", + "pi": "[Lambda0 -> p+ ^pi-]CC", + }, + "variables": { + "ALL": common_vars, + "L0": composite_vars + l0toppi_misid_vars, + "p": stable_vars, + "pi": stable_vars, + }, + } + + lines["BToJpsiK_JpsiToEmbremEpbremTagged"] = { + "fields": { + "B": "[B+]CC -> (J/psi(1S) -> e+ e-) [K+]CC", + "Jpsi": "[B+]CC -> ^(J/psi(1S) -> e+ e-) [K+]CC", + "K": "[B+]CC -> (J/psi(1S) -> e+ e-) ^[K+]CC", + "etag": "[B+]CC -> (J/psi(1S) -> ^e+ e-) [K+]CC", + "eprobe": "[B+]CC -> (J/psi(1S) -> e+ ^e-) [K+]CC", + }, + "variables": { + "ALL": common_vars, + "B": composite_vars, + "Jpsi": composite_vars, + "K": stable_vars, + "etag": stable_vars, + "eprobe": stable_vars, + }, + } + + lines["BToJpsiK_JpsiToEpbremEmbremTagged"] = { + "fields": { + "B": "[B+]CC -> (J/psi(1S) -> e+ e-) [K+]CC", + "Jpsi": "[B+]CC -> ^(J/psi(1S) -> e+ e-) [K+]CC", + "K": "[B+]CC -> (J/psi(1S) -> e+ e-) ^[K+]CC", + "etag": "[B+]CC -> (J/psi(1S) -> e+ ^e-) [K+]CC", + "eprobe": "[B+]CC -> (J/psi(1S) -> ^e+ e-) [K+]CC", + }, + "variables": { + "ALL": common_vars, + "B": composite_vars, + "Jpsi": composite_vars, + "K": stable_vars, + "etag": stable_vars, + "eprobe": stable_vars, + }, + } + + lines["BToJpsiK_JpsiToEmbremEpbremTagged_noPIDe"] = { + "fields": { + "B": "[B+]CC -> (J/psi(1S) -> e+ e-) [K+]CC", + "Jpsi": "[B+]CC -> ^(J/psi(1S) -> e+ e-) [K+]CC", + "K": "[B+]CC -> (J/psi(1S) -> e+ e-) ^[K+]CC", + "etag": "[B+]CC -> (J/psi(1S) -> ^e+ e-) [K+]CC", + "eprobe": "[B+]CC -> (J/psi(1S) -> e+ ^e-) [K+]CC", + }, + "variables": { + "ALL": common_vars, + "B": composite_vars, + "Jpsi": composite_vars, + "K": stable_vars, + "etag": stable_vars, + "eprobe": stable_vars, + }, + } + + lines["BToJpsiK_JpsiToEpbremEmbremTagged_noPIDe"] = { + "fields": { + "B": "[B+]CC -> (J/psi(1S) -> e+ e-) [K+]CC", + "Jpsi": "[B+]CC -> ^(J/psi(1S) -> e+ e-) [K+]CC", + "K": "[B+]CC -> (J/psi(1S) -> e+ e-) ^[K+]CC", + "etag": "[B+]CC -> (J/psi(1S) -> e+ ^e-) [K+]CC", + "eprobe": "[B+]CC -> (J/psi(1S) -> ^e+ e-) [K+]CC", + }, + "variables": { + "ALL": common_vars, + "B": composite_vars, + "Jpsi": composite_vars, + "K": stable_vars, + "etag": stable_vars, + "eprobe": stable_vars, + }, + } + + lines["JpsiToMuMupTagged_Detached"] = { + "fields": { + "Jpsi": "J/psi(1S) -> mu+ mu-", + "mutag": "J/psi(1S) -> ^mu+ mu-", + "muprobe": "J/psi(1S) -> mu+ ^mu-", + }, + "variables": { + "ALL": common_vars, + "Jpsi": composite_vars, + "mutag": stable_vars, + "muprobe": stable_vars, + }, + } + + lines["JpsiToMuMumTagged_Detached"] = { + "fields": { + "Jpsi": "J/psi(1S) -> mu+ mu-", + "mutag": "J/psi(1S) -> mu+ ^mu-", + "muprobe": "J/psi(1S) -> ^mu+ mu-", + }, + "variables": { + "ALL": common_vars, + "Jpsi": composite_vars, + "mutag": stable_vars, + "muprobe": stable_vars, + }, + } + + lines["BToJpsiK_JpsiToMuMupTagged_Detached"] = { + "fields": { + "B": "[B+]CC -> (J/psi(1S) -> mu+ mu-) [K+]CC", + "Jpsi": "[B+]CC -> ^(J/psi(1S) -> mu+ mu-) [K+]CC", + "K": "[B+]CC -> (J/psi(1S) -> mu+ mu-) ^[K+]CC", + "mutag": "[B+]CC -> (J/psi(1S) -> ^mu+ mu-) [K+]CC", + "muprobe": "[B+]CC -> (J/psi(1S) -> mu+ ^mu-) [K+]CC", + }, + "variables": { + "ALL": common_vars, + "B": composite_vars, + "Jpsi": composite_vars, + "K": stable_vars, + "mutag": stable_vars, + "muprobe": stable_vars, + }, + } + + lines["BToJpsiK_JpsiToMuMumTagged_Detached"] = { + "fields": { + "B": "[B+]CC -> (J/psi(1S) -> mu+ mu-) [K+]CC", + "Jpsi": "[B+]CC -> ^(J/psi(1S) -> mu+ mu-) [K+]CC", + "K": "[B+]CC -> (J/psi(1S) -> mu+ mu-) ^[K+]CC", + "mutag": "[B+]CC -> (J/psi(1S) -> mu+ ^mu-) [K+]CC", + "muprobe": "[B+]CC -> (J/psi(1S) -> ^mu+ mu-) [K+]CC", + }, + "variables": { + "ALL": common_vars, + "B": composite_vars, + "Jpsi": composite_vars, + "K": stable_vars, + "mutag": stable_vars, + "muprobe": stable_vars, + }, + } + + + algs = {} + for line, data in lines.items(): + algs.update(create_tuple_alg(line, data, options)) + + return make_config(options, algs) -- GitLab From 95773b163c72ecf87eecda8415673c1ed36876ea Mon Sep 17 00:00:00 2001 From: LHCb Data Processing and Analysis <lhcb.dpa@cern.ch> Date: Mon, 24 Jun 2024 14:01:09 +0200 Subject: [PATCH 04/15] Revert "PID 2024 mag up" This reverts merge request !1317 --- run3_pidcalib_tupling/Functions.py | 450 -------------- run3_pidcalib_tupling/alg.py | 239 -------- run3_pidcalib_tupling/info.yaml | 115 ---- .../tupling_PID_turboonly.py | 561 ------------------ run3_pidcalib_tupling/tupling_PID_turboraw.py | 271 --------- 5 files changed, 1636 deletions(-) delete mode 100644 run3_pidcalib_tupling/Functions.py delete mode 100644 run3_pidcalib_tupling/alg.py delete mode 100644 run3_pidcalib_tupling/info.yaml delete mode 100644 run3_pidcalib_tupling/tupling_PID_turboonly.py delete mode 100644 run3_pidcalib_tupling/tupling_PID_turboraw.py diff --git a/run3_pidcalib_tupling/Functions.py b/run3_pidcalib_tupling/Functions.py deleted file mode 100644 index d11432b7f8..0000000000 --- a/run3_pidcalib_tupling/Functions.py +++ /dev/null @@ -1,450 +0,0 @@ -import Functors as F -from FunTuple import FunctorCollection -from FunTuple.functorcollections import ( - Kinematics, - ParticleID, - ChargedCaloInfo, - DecayTreeFitterResults, -) -from DecayTreeFitter import DecayTreeFitter - - -def get_hlt2_vars(hlt2_dec_report, hlt2_lines): - - hlt_two_vars = FunctorCollection( - { - "Hlt2_TCK": F.TCK(hlt2_dec_report), - "Hlt2_DECISIONS": F.DECREPORTS_FILTER( - DecReports=hlt2_dec_report, Lines=hlt2_lines - ), - } - ) - return hlt_two_vars - - -def get_rec_summary_vars(rec_summary, odin): - - rec_summary_vars = FunctorCollection( - { - "EVENTTYPE": F.EVENTTYPE(odin), - "nPVs": F.VALUE_OR(-1) @ F.RECSUMMARY_INFO(rec_summary, "nPVs"), - "nLongTracks": F.VALUE_OR(-1) - @ F.RECSUMMARY_INFO(rec_summary, "nLongTracks"), - "nDownstreamTracks": F.VALUE_OR(-1) - @ F.RECSUMMARY_INFO(rec_summary, "nDownstreamTracks"), - "nUpstreamTracks": F.VALUE_OR(-1) - @ F.RECSUMMARY_INFO(rec_summary, "nUpstreamTracks"), - "nVeloTracks": F.VALUE_OR(-1) - @ F.RECSUMMARY_INFO(rec_summary, "nVeloTracks"), - "nTTracks": F.VALUE_OR(-1) @ F.RECSUMMARY_INFO(rec_summary, "nTTracks"), - "nBackTracks": F.VALUE_OR(-1) - @ F.RECSUMMARY_INFO(rec_summary, "nBackTracks"), - "nTracks": F.VALUE_OR(-1) @ F.RECSUMMARY_INFO(rec_summary, "nTracks"), - "nGhosts": F.VALUE_OR(-1) @ F.RECSUMMARY_INFO(rec_summary, "nGhosts"), - "nRich1Hits": F.VALUE_OR(-1) @ F.RECSUMMARY_INFO(rec_summary, "nRich1Hits"), - "nRich2Hits": F.VALUE_OR(-1) @ F.RECSUMMARY_INFO(rec_summary, "nRich2Hits"), - "nVeloClusters": F.VALUE_OR(-1) - @ F.RECSUMMARY_INFO(rec_summary, "nVeloClusters"), - "nFTClusters": F.VALUE_OR(-1) - @ F.RECSUMMARY_INFO(rec_summary, "nFTClusters"), - "nITClusters": F.VALUE_OR(-1) - @ F.RECSUMMARY_INFO(rec_summary, "nITClusters"), - "nTTClusters": F.VALUE_OR(-1) - @ F.RECSUMMARY_INFO(rec_summary, "nTTClusters"), - "nUTClusters": F.VALUE_OR(-1) - @ F.RECSUMMARY_INFO(rec_summary, "nUTClusters"), - "nOTClusters": F.VALUE_OR(-1) - @ F.RECSUMMARY_INFO(rec_summary, "nOTClusters"), - "nVPClusters": F.VALUE_OR(-1) - @ F.RECSUMMARY_INFO(rec_summary, "nVPClusters"), - "eCalTot": F.VALUE_OR(-1) @ F.RECSUMMARY_INFO(rec_summary, "eCalTot"), - "hCalTot": F.VALUE_OR(-1) @ F.RECSUMMARY_INFO(rec_summary, "hCalTot"), - "nEcalClusters": F.VALUE_OR(-1) - @ F.RECSUMMARY_INFO(rec_summary, "nEcalClusters"), - "nMuonCoordsS0": F.VALUE_OR(-1) - @ F.RECSUMMARY_INFO(rec_summary, "nMuonCoordsS0"), - "nMuonCoordsS1": F.VALUE_OR(-1) - @ F.RECSUMMARY_INFO(rec_summary, "nMuonCoordsS1"), - "nMuonCoordsS2": F.VALUE_OR(-1) - @ F.RECSUMMARY_INFO(rec_summary, "nMuonCoordsS2"), - "nMuonCoordsS3": F.VALUE_OR(-1) - @ F.RECSUMMARY_INFO(rec_summary, "nMuonCoordsS3"), - "nMuonCoordsS4": F.VALUE_OR(-1) - @ F.RECSUMMARY_INFO(rec_summary, "nMuonCoordsS4"), - "nMuonTracks": F.VALUE_OR(-1) - @ F.RECSUMMARY_INFO(rec_summary, "nMuonTracks"), - } - ) - - return rec_summary_vars - - -def get_common_vars(pvs): - - common_vars = FunctorCollection( - { - "ALLPVX": F.ALLPVX(pvs), - "ALLPVY": F.ALLPVY(pvs), - "ALLPVZ": F.ALLPVZ(pvs), - "BPVIP": F.BPVIP(pvs), - "BPVIPCHI2": F.BPVIPCHI2(pvs), - "BPVX": F.BPVX(pvs), - "BPVY": F.BPVY(pvs), - "BPVZ": F.BPVZ(pvs), - "CHARGE": F.CHARGE, - "CHI2": F.CHI2, - "CHI2DOF": F.CHI2DOF, - "ETA": F.ETA, - "FOURMOMENTUM": F.FOURMOMENTUM, - "PARTICLE_ID": F.PARTICLE_ID, - "MINIP": F.MINIP(pvs), - "MINIPCHI2": F.MINIPCHI2(pvs), - "PHI": F.PHI, - "POSITION_STATEAT_BegRich1_X" : F.POSITION_X @ F.STATE_AT("BegRich1") @ F.TRACK , - "POSITION_STATEAT_BegRich1_Y" : F.POSITION_Y @ F.STATE_AT("BegRich1") @ F.TRACK , - "POSITION_STATEAT_BegRich1_Z" : F.POSITION_Z @ F.STATE_AT("BegRich1") @ F.TRACK , - "POSITION_STATEAT_EndRich1_X" : F.POSITION_X @ F.STATE_AT("EndRich1") @ F.TRACK , - "POSITION_STATEAT_EndRich1_Y" : F.POSITION_Y @ F.STATE_AT("EndRich1") @ F.TRACK , - "POSITION_STATEAT_EndRich1_Z" : F.POSITION_Z @ F.STATE_AT("EndRich1") @ F.TRACK , - "POSITION_STATEAT_BegRich2_X" : F.POSITION_X @ F.STATE_AT("BegRich2") @ F.TRACK , - "POSITION_STATEAT_BegRich2_Y" : F.POSITION_Y @ F.STATE_AT("BegRich2") @ F.TRACK , - "POSITION_STATEAT_BegRich2_Z" : F.POSITION_Z @ F.STATE_AT("BegRich2") @ F.TRACK , - "POSITION_STATEAT_EndRich2_X" : F.POSITION_X @ F.STATE_AT("EndRich2") @ F.TRACK , - "POSITION_STATEAT_EndRich2_Y" : F.POSITION_Y @ F.STATE_AT("EndRich2") @ F.TRACK , - "POSITION_STATEAT_EndRich2_Z" : F.POSITION_Z @ F.STATE_AT("EndRich2") @ F.TRACK , - - } - ) - common_vars += Kinematics() - - return common_vars - - -def get_composite_vars(pvs): - - composite_vars = FunctorCollection( - { - "ALLPV_FD": F.ALLPV_FD(pvs), - "ALLPV_IP": F.ALLPV_IP(pvs), - "BPVCORRM": F.BPVCORRM(pvs), - "BPVCORRMERR": F.BPVCORRMERR(pvs), - "BPVDIRA": F.BPVDIRA(pvs), - "BPVDLS": F.BPVDLS(pvs), - "BPVETA": F.BPVETA(pvs), - "BPVFD": F.BPVFD(pvs), - "BPVFDCHI2": F.BPVFDCHI2(pvs), - "BPVFDIR": F.BPVFDIR(pvs), - "BPVLTIME": F.BPVLTIME(pvs), - "BPVVDRHO": F.BPVVDRHO(pvs), - "BPVVDX": F.BPVVDX(pvs), - "BPVVDY": F.BPVVDY(pvs), - "BPVVDZ": F.BPVVDZ(pvs), - "DOCACHI2_12": F.DOCACHI2(Child1=1, Child2=2), - "DOCA_12": F.DOCA(Child1=1, Child2=2), - "MAXDOCA": F.MAXDOCA, - "MAXDOCACHI2": F.MAXDOCACHI2, - "SDOCACHI2_12": F.SDOCACHI2(Child1=1, Child2=2), - "SDOCA_12": F.SDOCA(Child1=1, Child2=2), - "END_VX": F.END_VX, - "END_VY": F.END_VY, - "END_VZ": F.END_VZ, - } - ) - - return composite_vars - - -def get_rich_pid_vars(): - - RICH_PID_vars = FunctorCollection( - { - "PPHASRICH": F.PPHASRICH @ F.PROTOPARTICLE, - "RICH1_GAS_USED": F.RICH1_GAS_USED, - "RICH2_GAS_USED": F.RICH2_GAS_USED, - "RICH_DLL_BT": F.RICH_DLL_BT, - "RICH_DLL_D": F.RICH_DLL_D, - "RICH_DLL_E": F.RICH_DLL_E, - "RICH_DLL_K": F.RICH_DLL_K, - "RICH_DLL_MU": F.RICH_DLL_MU, - "RICH_DLL_P": F.RICH_DLL_P, - "RICH_DLL_PI": F.RICH_DLL_PI, - "RICH_SCALED_DLL_E": F.RICH_SCALED_DLL_E, - "RICH_SCALED_DLL_MU": F.RICH_SCALED_DLL_MU, - "RICH_THRESHOLD_DE": F.RICH_THRESHOLD_DE, - "RICH_THRESHOLD_EL": F.RICH_THRESHOLD_EL, - "RICH_THRESHOLD_KA": F.RICH_THRESHOLD_KA, - "RICH_THRESHOLD_MU": F.RICH_THRESHOLD_MU, - "RICH_THRESHOLD_PI": F.RICH_THRESHOLD_PI, - "RICH_THRESHOLD_PR": F.RICH_THRESHOLD_PR, - } - ) - - return RICH_PID_vars - - -def get_muon_pid_vars(): - - muon_PID_vars = FunctorCollection( - { - "PPHASMUONINFO": F.PPHASMUONINFO @ F.PROTOPARTICLE, - "INMUON": F.INMUON, - "ISMUON": F.ISMUON, - "ISMUONTIGHT": F.ISMUONTIGHT, - "MUONCATBOOST": F.MUONCATBOOST, - "MUONCHI2CORR": F.MUONCHI2CORR, - "MUONLLBG": F.MUONLLBG, - "MUONLLMU": F.MUONLLMU, - } - ) - - return muon_PID_vars - - -def get_general_pid_vars(): - """ - Get the PID_X and PROBNN_X functors - """ - return ParticleID(extra_info=True) - - -def get_track_vars(): - - track_vars = FunctorCollection( - { - "GHOSTPROB": F.GHOSTPROB, - "NFTHITS": F.VALUE_OR(-1) @ F.NFTHITS @ F.TRACK, - "NHITS": F.VALUE_OR(-1) @ F.NHITS @ F.TRACK, - "NUTHITS": F.VALUE_OR(-1) @ F.NUTHITS @ F.TRACK, - "NVPHITS": F.VALUE_OR(-1) @ F.NVPHITS @ F.TRACK, - "OBJECT_KEY": F.VALUE_OR(-1) @ F.OBJECT_KEY @ F.TRACK, - "QOVERP": F.QOVERP @ F.TRACK, - "TRACKTYPE": F.VALUE_OR(-1) @ F.TRACKTYPE @ F.TRACK, - "TCHI2DOF": F.CHI2DOF @ F.TRACK, - "TRACKHAST": F.VALUE_OR(-1) @ F.TRACKHAST @ F.TRACK, - "TRACKHASUT": F.VALUE_OR(-1) @ F.TRACKHASUT @ F.TRACK, - "TRACKHASVELO": F.VALUE_OR(-1) @ F.TRACKHASVELO @ F.TRACK, - "TRACKHISTORY": F.VALUE_OR(-1) @ F.TRACKHISTORY @ F.TRACK, - "TRACKISCLONE": F.VALUE_OR(-1) @ F.TRACKISCLONE @ F.TRACK, - "TRACKISDOWNSTREAM": F.VALUE_OR(-1) @ F.TRACKISDOWNSTREAM @ F.TRACK, - "TRACKISINVALID": F.VALUE_OR(-1) @ F.TRACKISINVALID @ F.TRACK, - "TRACKISLONG": F.VALUE_OR(-1) @ F.TRACKISLONG @ F.TRACK, - "TRACKISSELECTED": F.VALUE_OR(-1) @ F.TRACKISSELECTED @ F.TRACK, - "TRACKISTTRACK": F.VALUE_OR(-1) @ F.TRACKISTTRACK @ F.TRACK, - "TRACKISUPSTREAM": F.VALUE_OR(-1) @ F.TRACKISUPSTREAM @ F.TRACK, - "TRACKISVELO": F.VALUE_OR(-1) @ F.TRACKISVELO @ F.TRACK, - "TRACKISVELOBACKWARD": F.VALUE_OR(-1) @ F.TRACKISVELOBACKWARD @ F.TRACK, - "TRACK_P": F.VALUE_OR(-1) @ F.P @ F.TRACK, - "TRACK_PT": F.VALUE_OR(-1) @ F.PT @ F.TRACK, - "TRACK_PX": F.VALUE_OR(-1) @ F.PX @ F.TRACK, - "TRACK_PY": F.VALUE_OR(-1) @ F.PY @ F.TRACK, - "TRACK_PX": F.VALUE_OR(-1) @ F.PZ @ F.TRACK, - # "TRACK_PT_WITH_BREM": F.VALUE_OR(-1) @ F.PT_WITH_BREM @ F.TRACK, - # "TRACK_P_WITH_BREM": F.VALUE_OR(-1) @ F.P_WITH_BREM @ F.TRACK, - } - ) - - return track_vars - - -def get_charged_calo_vars(): - """ - Full list at https://gitlab.cern.ch/lhcb/DaVinci/-/blob/2024-patches/Phys/FunTuple/python/FunTuple/functorcollections.py - extra_info includes electron / brem variables - """ - return ChargedCaloInfo(extra_info=True) - - -def get_three_body_vars(): - - three_body_vars = FunctorCollection( - { - "DOCACHI2_13": F.DOCACHI2(Child1=1, Child2=3), - "DOCACHI2_23": F.DOCACHI2(Child1=2, Child2=3), - "DOCA_13": F.DOCA(Child1=1, Child2=3), - "DOCA_23": F.DOCA(Child1=2, Child2=3), - "SDOCACHI2_13": F.SDOCACHI2(Child1=1, Child2=3), - "SDOCACHI2_23": F.SDOCACHI2(Child1=2, Child2=3), - "SDOCA_13": F.SDOCA(Child1=1, Child2=3), - "SDOCA_23": F.SDOCA(Child1=2, Child2=3), - } - ) - - return three_body_vars - - -def get_four_body_vars(): - - four_body_vars = FunctorCollection( - { - "DOCACHI2_14": F.DOCACHI2(Child1=1, Child2=4), - "DOCACHI2_24": F.DOCACHI2(Child1=2, Child2=4), - "DOCACHI2_34": F.DOCACHI2(Child1=3, Child2=4), - "DOCA_14": F.DOCA(Child1=1, Child2=4), - "DOCA_24": F.DOCA(Child1=2, Child2=4), - "DOCA_34": F.DOCA(Child1=3, Child2=4), - "SDOCACHI2_14": F.SDOCACHI2(Child1=1, Child2=4), - "SDOCACHI2_24": F.SDOCACHI2(Child1=2, Child2=4), - "SDOCACHI2_34": F.SDOCACHI2(Child1=3, Child2=4), - "SDOCA_14": F.SDOCA(Child1=1, Child2=4), - "SDOCA_24": F.SDOCA(Child1=2, Child2=4), - "SDOCA_34": F.SDOCA(Child1=3, Child2=4), - } - ) - - return four_body_vars - - -def get_d_to_kpipipi_misid_vars(): - - d0tokpipipi_misid_vars = FunctorCollection( - { - "WM_PIMPIMPIPKP": F.MASSWITHHYPOTHESES(("pi-", "pi-", "pi+", "K+")), - "WM_PIMPIMKPPIP": F.MASSWITHHYPOTHESES(("pi-", "pi-", "K+", "pi+")), - } - ) - - return d0tokpipipi_misid_vars - - -def get_d_to_kpi_misid_vars(): - - d0tokpi_misid_vars = FunctorCollection( - { - "WM_PIK": F.MASSWITHHYPOTHESES(("pi-", "K+")), - "WM_PIPI": F.MASSWITHHYPOTHESES(("pi-", "pi+")), - "WM_KK": F.MASSWITHHYPOTHESES(("K-", "K+")), - } - ) - - return d0tokpi_misid_vars - - -def get_ks_to_pipi_misid_vars(): - - kstopipi_misid_vars = FunctorCollection( - { - "WM_PPI": F.MASSWITHHYPOTHESES(("p+", "pi-")), - "WM_PIP": F.MASSWITHHYPOTHESES(("pi+", "p~-")), - } - ) - return kstopipi_misid_vars - - -def get_l0_to_ppi_misid_vars(): - - l0toppi_misid_vars = FunctorCollection( - {"WM_PIPI": F.MASSWITHHYPOTHESES(("pi+", "pi-"))} - ) - - return l0toppi_misid_vars - - -def get_lc_to_pkpi_misid_vars(): - - lctopkpi_misid_vars = FunctorCollection( - { - "WM_PIKPI": F.MASSWITHHYPOTHESES(("pi+", "K-", "pi-")), - "WM_KKPI": F.MASSWITHHYPOTHESES(("K+", "K-", "pi-")), - } - ) - - return lctopkpi_misid_vars - - - -def get_dtf_variables(options, data, mass, pv): - func_coll = FunctorCollection( - { - "ETA": F.ETA, - "FOURMOMENTUM": F.FOURMOMENTUM, - } - ) - func_coll += Kinematics() - - if mass == "J/psi(1S)": - DTF = DecayTreeFitter( - name="JpsiMFit_{hash}", - input_particles=data, - mass_constraints=[mass], - output_level=3, - ) - dtf_variables = FunctorCollection( - {"JpsiMFit_" + k: DTF(v) for k, v in func_coll.get_thor_functors().items()} - ) - DTF = DecayTreeFitter( - name="PVandJpsiMFit_{hash}", - input_particles=data, - input_pvs=pv, - mass_constraints=[mass], - output_level=3, - ) - dtf_variables += FunctorCollection( - {"PVandJpsiMFit_" + k: DTF(v) for k, v in func_coll.get_thor_functors().items()} - ) - - elif mass == "B+": - DTF = DecayTreeFitter( - name="BMFit_{hash}", - input_particles=data, - mass_constraints=[mass], - output_level=3, - ) - dtf_variables = FunctorCollection( - {"BMFit_" + k: DTF(v) for k, v in func_coll.get_thor_functors().items()} - ) - DTF = DecayTreeFitter( - name="PVandBMFit_{hash}", - input_particles=data, - input_pvs=pv, - mass_constraints=[mass], - output_level=3, - ) - dtf_variables += FunctorCollection( - {"PVandBMFit_" + k: DTF(v) for k, v in func_coll.get_thor_functors().items()} - ) - - elif mass == "D*(2010)+": - DTF = DecayTreeFitter( - name="DstMFit_{hash}", - input_particles=data, - mass_constraints=[mass], - output_level=3, - ) - dtf_variables = FunctorCollection( - {"DstMFit_" + k: DTF(v) for k, v in func_coll.get_thor_functors().items()} - ) - DTF = DecayTreeFitter( - name="PVandDstMFit_{hash}", - input_particles=data, - input_pvs=pv, - mass_constraints=[mass], - output_level=3, - ) - dtf_variables += FunctorCollection( - {"PVandDstMFit_" + k: DTF(v) for k, v in func_coll.get_thor_functors().items()} - ) - - elif mass == "D0": - DTF = DecayTreeFitter( - name="D0MFit_{hash}", - input_particles=data, - mass_constraints=[mass], - output_level=3, - ) - dtf_variables = FunctorCollection( - {"D0MFit_" + k: DTF(v) for k, v in func_coll.get_thor_functors().items()} - ) - DTF = DecayTreeFitter( - name="PVandD0MFit_{hash}", - input_particles=data, - input_pvs=pv, - mass_constraints=[mass], - output_level=3, - ) - dtf_variables += FunctorCollection( - {"PVandD0MFit_" + k: DTF(v) for k, v in func_coll.get_thor_functors().items()} - ) - - return dtf_variables - - diff --git a/run3_pidcalib_tupling/alg.py b/run3_pidcalib_tupling/alg.py deleted file mode 100644 index 2170162ca8..0000000000 --- a/run3_pidcalib_tupling/alg.py +++ /dev/null @@ -1,239 +0,0 @@ -############################################################################### -# (c) Copyright 2023 CERN for the benefit of the LHCb Collaboration # -# # -# This software is distributed under the terms of the GNU General Public # -# Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". # -# # -# In applying this licence, CERN does not waive the privileges and immunities # -# granted to it by virtue of its status as an Intergovernmental Organization # -# or submit itself to any jurisdiction. # -############################################################################### -""" -Read HLT2 files and create PID calibration ntuples. - -This script follows the Run 2 convention of creating a single file with -multiple trees. -""" - -from .Functions import get_dtf_variables, get_hlt2_vars, get_rec_summary_vars -import Functors as F - -from DaVinci import Options, make_config -from DaVinci.algorithms import create_lines_filter - -# from DaVinciMCTools import MCTruthAndBkgCat - -from FunTuple import FunctorCollection -from FunTuple import FunTuple_Particles as Funtuple -from FunTuple.functorcollections import ( - HltTisTos, - Kinematics, - MCHierarchy, - MCKinematics, - EventInfo, - LHCInfo, - SelectionInfo, - ParticleIsolation, - SMOGInfo, -) -from IsolationTools import VertexAndConeIsolation # type: ignore[import] -from PyConf.reading import get_decreports, get_particles, get_rec_summary, get_odin, get_pvs - -# Uncomment for 2023 data -# from DDDB.CheckDD4Hep import UseDD4Hep -# from Configurables import LHCb__Det__LbDD4hep__DD4hepSvc as DD4hepSvc -# dd4hepSvc = DD4hepSvc() -# dd4hepSvc.DetectorList = ['/world', 'VP', 'FT', 'Magnet', 'Rich1', 'Rich2', 'Ecal', 'Hcal', 'Muon'] #removes the UT - - -def create_tuple_alg(line, data, options): - - # For 2023 data use "/Event/HLT2/HLT2PID_{line}/Particles" - input_data = get_particles(f"/Event/Spruce/SpruceTurCalPID_{line}/Particles") - - # get ODIN and DecReports location - odin = get_odin() - hlt2_dec = get_decreports("Hlt2") - hlt1_dec = get_decreports("Hlt1") - - pvs = get_pvs() - - # Add DTF variables - if "BToJpsiK_JpsiToE" in line: - data["variables"]["B"] += get_dtf_variables( - options, input_data, mass="J/psi(1S)", pv=pvs - ) - data["variables"]["Jpsi"] += get_dtf_variables( - options, input_data, mass="B+", pv=pvs - ) - elif "BToJpsiK_JpsiToMu" in line: - data["variables"]["B"] += get_dtf_variables( - options, input_data, mass="J/psi(1S)", pv=pvs - ) - data["variables"]["Jpsi"] += get_dtf_variables( - options, input_data, mass="B+", pv=pvs - ) - elif "JpsiToMu" in line: - data["variables"]["Jpsi"] += get_dtf_variables( - options, input_data, mass="J/psi(1S)", pv=pvs - ) - elif "DstToD0Pi" in line: - data["variables"]["Dst"] += get_dtf_variables( - options, input_data, mass="D0", pv=pvs - ) - data["variables"]["D"] += get_dtf_variables( - options, input_data, mass="D*(2010)+", pv=pvs - ) - - my_filter = create_lines_filter( - name=f"HDRFilter_{line}", - lines=[f"Hlt2PID_{line}"], - ) - - # get configured "MCTruthAndBkgCatAlg" algorithm for HLT2 output - # mctruth = configured_MCTruthAndBkgCatAlg(inputs=input_data) - - # kin = Kinematics() - # mckin = MCKinematics(mctruth) - # mchierarchy = MCHierarchy(mctruth) - - # MCTRUTH = lambda func: F.MAP_INPUT(func, mctruth.MCAssocTable) - # extra_info = { - # # Important note: specify an invalid value for integer functors if there exists no truth info. - # # The invalid value for floating point functors is set to nan. - # "TRUEEID": F.VALUE_OR(0) @ MCTRUTH(F.PARTICLE_ID), - # "TRUEEPHI": MCTRUTH(F.PHI), - # } - # extra_info = FC(extra_info) - - # The algorithm mctruth also outputs a map b/w particle and bkg category which can be obtained using the functor - # For more info on background category see: https://twiki.cern.ch/twiki/bin/view/LHCb/TupleToolMCBackgroundInfo - # bkg_cat = FunctorCollection({"BKGCAT": F.BKGCAT(Relations=mctruth.BkgCatTable)}) - - evt_vars = EventInfo() - evt_vars += LHCInfo(extra_info=True) - - hlt2_lines = [f"Hlt2PID_{line}Decision"] - evt_vars += get_hlt2_vars(hlt2_dec, hlt2_lines) - - rec_summary = get_rec_summary() - evt_vars += get_rec_summary_vars(rec_summary, odin) - - evt_vars += EventInfo() - evt_vars += LHCInfo(extra_info=True) - - evt_vars += SMOGInfo() - - hlt1_decisions = [ - # "Hlt1BeamGasDecision", - # "Hlt1BeamOneDecision", - # "Hlt1BeamTwoDecision", - # "Hlt1BothBeamsDecision", - "Hlt1Bs2GammaGammaDecision", - "Hlt1D2KKDecision", - "Hlt1D2KPiAlignmentDecision", - "Hlt1D2KPiDecision", - "Hlt1D2PiPiDecision", - "Hlt1DiMuonHighMassAlignmentDecision", - "Hlt1DiMuonLowMassDecision", - "Hlt1DiMuonNoIPDecision", - "Hlt1DiMuonNoIP_ssDecision", - "Hlt1DiMuonSoftDecision", - "Hlt1DisplacedDiMuonAlignmentDecision", - #"Hlt1DisplacedDielectronDecision", # remove duplicate - "Hlt1DisplacedLeptonsDecision", - # "Hlt1HeavyIonDecision", - "Hlt1KsToPiPiDecision", - # "Hlt1L02PPiDecision", - # "Hlt1LowMassNoipDielectronDecision", - "Hlt1LowMassNoipDielectron_SS_massSlice1_displacedDecision", - "Hlt1LowMassNoipDielectron_SS_massSlice1_promptDecision", - "Hlt1LowMassNoipDielectron_SS_massSlice2_displacedDecision", - "Hlt1LowMassNoipDielectron_SS_massSlice2_promptDecision", - "Hlt1LowMassNoipDielectron_SS_massSlice3_displacedDecision", - "Hlt1LowMassNoipDielectron_SS_massSlice3_promptDecision", - "Hlt1LowMassNoipDielectron_SS_massSlice4_displacedDecision", - "Hlt1LowMassNoipDielectron_SS_massSlice4_promptDecision", - "Hlt1LowMassNoipDielectron_massSlice1_displacedDecision", - "Hlt1LowMassNoipDielectron_massSlice1_promptDecision", - "Hlt1LowMassNoipDielectron_massSlice2_displacedDecision", - "Hlt1LowMassNoipDielectron_massSlice2_promptDecision", - "Hlt1LowMassNoipDielectron_massSlice3_displacedDecision", - "Hlt1LowMassNoipDielectron_massSlice3_promptDecision", - "Hlt1LowMassNoipDielectron_massSlice4_displacedDecision", - "Hlt1LowMassNoipDielectron_massSlice4_promptDecision", - "Hlt1LowPtDiMuonDecision", - "Hlt1LowPtMuonDecision", - # "Hlt1NoBeamDecision", - # "Hlt1ODINLumiDecision", - # "Hlt1ODINNoBiasDecision", - # "Hlt1ODINVeloOpenDecision", - "Hlt1OneMuonTrackLineDecision", - # "Hlt1PassthroughDecision", - "Hlt1RICH1AlignmentDecision", - "Hlt1RICH2AlignmentDecision", - # "Hlt1SingleCaloClusterDecision", - "Hlt1DisplacedDiMuonDecision", - "Hlt1SingleHighPtMuonNoMuIDDecision", - "Hlt1TrackElectronMVADecision", - "Hlt1Pi02GammaGammaDecision", - "Hlt1TwoKsDecision", - "Hlt1TwoTrackKsDecision", - "Hlt1TwoTrackMVACharmXSecDecision", - "Hlt1SingleHighEtDecision", #RB 14 - "Hlt1DisplacedDielectronDecision", #RB 14 - "Hlt1SingleHighPtElectronDecision", #RB 14 - "Hlt1TrackMuonMVADecision", #RB 14 - "Hlt1DiMuonHighMassDecision", #RB 14 - "Hlt1SingleHighPtMuonDecision", #RB 14 - "Hlt1TrackMVADecision", #RB 14 - "Hlt1TwoTrackMVADecision", #RB 14 - "Hlt1Dst2D0PiDecision", #RB 17 - "Hlt1DetJpsiToMuMuPosTagLineDecision", #RB 17 - "Hlt1DetJpsiToMuMuNegTagLineDecision" #RB 17 - ] - # SMOG lines - hlt1lines_muon = [ "Hlt1SMOG2SingleMuonDecision", "Hlt1SMOG2DiMuonHighMassDecision",] - hlt1lines_BE = [ "Hlt1SMOG2BENoBiasDecision", "Hlt1SMOG2PassThroughLowMult5Decision", "Hlt1SMOG2BELowMultElectronsDecision" ] - hlt1lines_MB = [ "Hlt1SMOG2MinimumBiasDecision", "Hlt1PassthroughPVinSMOG2Decision" ] - hlt1lines_track = [ "Hlt1SMOG2SingleTrackHighPtDecision", "Hlt1SMOG2SingleTrackVeryHighPtDecision", "Hlt1SMOG22BodyGenericDecision", "Hlt1SMOG22BodyGenericPromptDecision"] - hlt1lines_hadron = [ "Hlt1SMOG2etacToppDecision", "Hlt1SMOG2D2KpiDecision", ] - hlt1lines_longlived = [ "Hlt1SMOG2L0ToppiDecision", "Hlt1SMOG2KsTopipiDecision", ] - - hlt1_decisions += hlt1lines_muon - hlt1_decisions += hlt1lines_BE - hlt1_decisions += hlt1lines_MB - hlt1_decisions += hlt1lines_track - hlt1_decisions += hlt1lines_hadron - hlt1_decisions += hlt1lines_longlived - - - # Add event-level Hlt1 decisions - evt_vars += SelectionInfo(selection_type="Hlt1", trigger_lines=hlt1_decisions) - - # Add track-level Hlt1 TIS/TOS decisions - data["variables"]["ALL"] += HltTisTos( - selection_type="Hlt1", trigger_lines=hlt1_decisions, data=input_data - ) - - iso_alg = VertexAndConeIsolation( - name="iso_0.4", - reference_particles=input_data, - related_particles=input_data, - cut=(F.DR2() < 0.4), - ) - - data["variables"]["ALL"] += ParticleIsolation( - isolation_alg=iso_alg, array_indx_name="indx" - ) - - my_tuple = Funtuple( - name=line, - tuple_name="DecayTree", - fields=data["fields"], - variables=data["variables"], - event_variables=evt_vars, - inputs=input_data, - ) - - return {f"{line}_Algs": [my_filter, my_tuple]} diff --git a/run3_pidcalib_tupling/info.yaml b/run3_pidcalib_tupling/info.yaml deleted file mode 100644 index 9a8733e365..0000000000 --- a/run3_pidcalib_tupling/info.yaml +++ /dev/null @@ -1,115 +0,0 @@ -defaults: - application: "DaVinci/v64r5" - wg: PID - turbo: yes - automatically_configure: no - inform: - - seophine.stanislaus@cern.ch - - innes.mackay@cern.ch - -checks: - histogram_D0ToKPi_M: - type: range - expression: D_M - tree_pattern: DstToD0Pi_D0ToKPi/DecayTree - limits: - min: 1800 - max: 1920 - - histogram_D0ToKPi_DeltaM: - type: range - expression: Dst_M - D_M - tree_pattern: DstToD0Pi_D0ToKPi/DecayTree - limits: - min: 139 - max: 155 - - histogram_D0ToKPiPiPi_DeltaM: - type: range - expression: Dst_M - D_M - tree_pattern: DstToD0Pi_D0ToKPiPiPi/DecayTree - limits: - min: 139 - max: 155 - - histogram_Ks_M: - type: range - expression: Ks_M - tree_pattern: KsToPiPi_.*/DecayTree - limits: - min: 470 - max: 525 - - histogram_L0_M: - type: range - expression: L0_M - tree_pattern: L0ToPPi_LL/DecayTree - limits: - min: 1100 - max: 1130 - - turbo_only_at_least_10_entries: - type: num_entries - tree_pattern: (KsToPiPi_LL|LcToPKPi)/DecayTree - count: 10 - - turbo_raw_at_least_10_entries: - type: num_entries - tree_pattern: (DstToD0Pi_D0ToKPi|L0ToPPi_LL)/DecayTree - count: 10 - - -Collision24_magup_veloclosed_excludeut_turboonly: - options: - entrypoint: run3_pidcalib_tupling.tupling_PID_turboonly:main - extra_options: - input_raw_format: 0.5 - input_type: "ROOT" - conditions_version: "master" - geometry_version: "run3/2024.Q1.2-v00.00" - lumi: true - simulation: false - data_type: "Upgrade" - input_process: "Spruce" - input_stream: "turcal_mdst" - output: PID_TURBOONLY_TUPLE.ROOT - checks: - - histogram_D0ToKPiPiPi_DeltaM - - histogram_Ks_M - - turbo_only_at_least_10_entries - input: - bk_query: "/LHCb/Collision24/Beam6800GeV-VeloClosed-MagUp-Excl-UT/Real Data/Sprucing24c1/95100000/TURCAL_MDST.DST" - dq_flags: - - OK - - UNCHECKED - keep_running: true - n_test_lfns: 1 - -Collision24_magup_veloclosed_excludeut_turboraw: - options: - entrypoint: run3_pidcalib_tupling.tupling_PID_turboraw:main - extra_options: - input_raw_format: 0.5 - input_type: "ROOT" - conditions_version: "master" - geometry_version: "run3/2024.Q1.2-v00.00" - lumi: true - simulation: false - data_type: "Upgrade" - input_process: "Spruce" - input_stream: "turcal_rawbanks" - output: PID_TURBORAW_TUPLE.ROOT - checks: - - histogram_D0ToKPi_M - - histogram_D0ToKPi_DeltaM - - histogram_L0_M - - turbo_raw_at_least_10_entries - input: - bk_query: "/LHCb/Collision24/Beam6800GeV-VeloClosed-MagUp-Excl-UT/Real Data/Sprucing24c1/95100000/TURCAL_RAWBANKS.DST" - dq_flags: - - OK - - UNCHECKED - keep_running: true - n_test_lfns: 1 - - diff --git a/run3_pidcalib_tupling/tupling_PID_turboonly.py b/run3_pidcalib_tupling/tupling_PID_turboonly.py deleted file mode 100644 index f03daf6995..0000000000 --- a/run3_pidcalib_tupling/tupling_PID_turboonly.py +++ /dev/null @@ -1,561 +0,0 @@ -############################################################################### -# (c) Copyright 2023 CERN for the benefit of the LHCb Collaboration # -# # -# This software is distributed under the terms of the GNU General Public # -# Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". # -# # -# In applying this licence, CERN does not waive the privileges and immunities # -# granted to it by virtue of its status as an Intergovernmental Organization # -# or submit itself to any jurisdiction. # -############################################################################### -""" -Read HLT2 files and create PID calibration ntuples. -This script follows the Run 2 convention of creating a single file with -multiple trees. -""" -from .alg import create_tuple_alg -from .Functions import * -from DaVinci import Options, make_config -from PyConf.reading import get_pvs - - -# NOTE: Uncomment if using 2023 data! Double check it works first. -# dd4hepSvc = DD4hepSvc() -# dd4hepSvc.DetectorList = ['/world', 'VP', 'FT', 'Magnet', 'Rich1', 'Rich2', 'Ecal', 'Hcal', 'Muon'] #removes the UT - - -def main(options: Options): - - pvs = get_pvs() - - common_vars = get_common_vars(pvs) - composite_vars = get_composite_vars(pvs) - - track_vars = get_track_vars() - rich_pid_vars = get_rich_pid_vars() - muon_pid_vars = get_muon_pid_vars() - general_pid_vars = get_general_pid_vars() - charged_calo_vars = get_charged_calo_vars() - stable_vars = ( - track_vars - + rich_pid_vars - + muon_pid_vars - + general_pid_vars - + charged_calo_vars - ) - - three_body_vars = get_three_body_vars() - four_body_vars = get_four_body_vars() - - d0tokpipipi_misid_vars = get_d_to_kpipipi_misid_vars() - kstopipi_misid_vars = get_ks_to_pipi_misid_vars() - l0toppi_misid_vars = get_l0_to_ppi_misid_vars() - lctopkpi_misid_vars = get_lc_to_pkpi_misid_vars() - - lines = {} - - lines["DstToD0Pi_D0ToKPiPiPi"] = { - "fields": { - "Dst": "[D*(2010)+ -> (D0 -> K- pi+ pi+ pi-) pi+]CC", - "D": "[D*(2010)+ -> ^(D0 -> K- pi+ pi+ pi-) pi+]CC", - "pis": "[D*(2010)+ -> (D0 -> K- pi+ pi+ pi-) ^pi+]CC", - "K": "[D*(2010)+ -> (D0 -> ^K- pi+ pi+ pi-) pi+]CC", - "pi1": "[D*(2010)+ -> (D0 -> K- ^pi+ pi+ pi-) pi+]CC", - "pi2": "[D*(2010)+ -> (D0 -> K- pi+ ^pi+ pi-) pi+]CC", - "pi3": "[D*(2010)+ -> (D0 -> K- pi+ pi+ ^pi-) pi+]CC", - }, - "variables": { - "ALL": common_vars, - "Dst": composite_vars, - "D": composite_vars - + d0tokpipipi_misid_vars - + three_body_vars - + four_body_vars, - "pis": stable_vars, - "K": stable_vars, - "pi1": stable_vars, - "pi2": stable_vars, - "pi3": stable_vars, - }, - } - - lines["KsToPiPi_LL"] = { - "fields": { - "Ks": "KS0 -> pi+ pi-", - "pip": "KS0 -> ^pi+ pi-", - "pim": "KS0 -> pi+ ^pi-", - }, - "variables": { - "ALL": common_vars, - "Ks": composite_vars + kstopipi_misid_vars, - "pip": stable_vars, - "pim": stable_vars, - }, - } - - lines["KsToPiPi_DD"] = { - "fields": { - "Ks": "KS0 -> pi+ pi-", - "pip": "KS0 -> ^pi+ pi-", - "pim": "KS0 -> pi+ ^pi-", - }, - "variables": { - "ALL": common_vars, - "Ks": composite_vars + kstopipi_misid_vars, - "pip": stable_vars, - "pim": stable_vars, - }, - } - - lines["L0ToPPi_DD_LowPT"] = { - "fields": { - "L0": "[Lambda0 -> p+ pi-]CC", - "p": "[Lambda0 -> ^p+ pi-]CC", - "pi": "[Lambda0 -> p+ ^pi-]CC", - }, - "variables": { - "ALL": common_vars, - "L0": composite_vars + l0toppi_misid_vars, - "p": stable_vars, - "pi": stable_vars, - }, - } - - lines["L0ToPPi_DD_MidPT"] = { - "fields": { - "L0": "[Lambda0 -> p+ pi-]CC", - "p": "[Lambda0 -> ^p+ pi-]CC", - "pi": "[Lambda0 -> p+ ^pi-]CC", - }, - "variables": { - "ALL": common_vars, - "L0": composite_vars + l0toppi_misid_vars, - "p": stable_vars, - "pi": stable_vars, - }, - } - - lines["L0ToPPi_DD_HighPT"] = { - "fields": { - "L0": "[Lambda0 -> p+ pi-]CC", - "p": "[Lambda0 -> ^p+ pi-]CC", - "pi": "[Lambda0 -> p+ ^pi-]CC", - }, - "variables": { - "ALL": common_vars, - "L0": composite_vars + l0toppi_misid_vars, - "p": stable_vars, - "pi": stable_vars, - }, - } - - lines["L0ToPPi_DD_VeryHighPT"] = { - "fields": { - "L0": "[Lambda0 -> p+ pi-]CC", - "p": "[Lambda0 -> ^p+ pi-]CC", - "pi": "[Lambda0 -> p+ ^pi-]CC", - }, - "variables": { - "ALL": common_vars, - "L0": composite_vars + l0toppi_misid_vars, - "p": stable_vars, - "pi": stable_vars, - }, - } - - lines["LbToLcPi_LcToPKPi"] = { - "fields": { - "Lb": "[Lambda_b0 -> (Lambda_c+ -> p+ K- pi+) pi-]CC", - "Lc": "[Lambda_b0 -> ^(Lambda_c+ -> p+ K- pi+) pi-]CC", - "Lbpi": "[Lambda_b0 -> (Lambda_c+ -> p+ K- pi+) ^pi-]CC", - "p": "[Lambda_b0 -> (Lambda_c+ -> ^p+ K- pi+) pi-]CC", - "K": "[Lambda_b0 -> (Lambda_c+ -> p+ ^K- pi+) pi-]CC", - "pi": "[Lambda_b0 -> (Lambda_c+ -> p+ K- ^pi+) pi-]CC", - }, - "variables": { - "ALL": common_vars, - "Lb": composite_vars, - "Lc": composite_vars + lctopkpi_misid_vars + three_body_vars, - "p": stable_vars, - "K": stable_vars, - "pi": stable_vars, - "Lbpi": stable_vars, - }, - } - - lines["LbToLcMuNu_LcToPKPi"] = { - "fields": { - "Lb": "[Lambda_b0 -> (Lambda_c+ -> p+ K- pi+) mu-]CC", - "Lc": "[Lambda_b0 -> ^(Lambda_c+ -> p+ K- pi+) mu-]CC", - "mu": "[Lambda_b0 -> (Lambda_c+ -> p+ K- pi+) ^mu-]CC", - "p": "[Lambda_b0 -> (Lambda_c+ -> ^p+ K- pi+) mu-]CC", - "K": "[Lambda_b0 -> (Lambda_c+ -> p+ ^K- pi+) mu-]CC", - "pi": "[Lambda_b0 -> (Lambda_c+ -> p+ K- ^pi+) mu-]CC", - }, - "variables": { - "ALL": common_vars, - "Lb": composite_vars, - "Lc": composite_vars + lctopkpi_misid_vars + three_body_vars, - "p": stable_vars, - "K": stable_vars, - "pi": stable_vars, - "mu": stable_vars, - }, - } - - lines["LcToPKPi"] = { - "fields": { - "Lc": "[Lambda_c+ -> p+ K- pi+]CC", - "p": "[Lambda_c+ -> ^p+ K- pi+]CC", - "K": "[Lambda_c+ -> p+ ^K- pi+]CC", - "pi": "[Lambda_c+ -> p+ K- ^pi+]CC", - }, - "variables": { - "ALL": common_vars, - "Lc": composite_vars + lctopkpi_misid_vars + three_body_vars, - "p": stable_vars, - "K": stable_vars, - "pi": stable_vars, - }, - } - - lines["PhiToKK_Unbiased_Detached"] = { - "fields": { - "phi": "phi(1020) -> K+ K-", - "Kp": "phi(1020) -> ^K+ K-", - "Km": "phi(1020) -> K+ ^K-", - }, - "variables": { - "ALL": common_vars, - "phi": composite_vars, - "Kp": stable_vars, - "Km": stable_vars, - }, - } - - lines["PhiToKmKpTagged_Detached"] = { - "fields": { - "phi": "phi(1020) -> K+ K-", - "Ktag": "phi(1020) -> ^K+ K-", - "Kprobe": "phi(1020) -> K+ ^K-", - }, - "variables": { - "ALL": common_vars, - "phi": composite_vars, - "Ktag": stable_vars, - "Kprobe": stable_vars, - }, - } - - lines["PhiToKpKmTagged_Detached"] = { - "fields": { - "phi": "phi(1020) -> K+ K-", - "Kprobe": "phi(1020) -> ^K+ K-", - "Ktag": "phi(1020) -> K+ ^K-", - }, - "variables": { - "ALL": common_vars, - "phi": composite_vars, - "Kprobe": stable_vars, - "Ktag": stable_vars, - }, - } - - lines["DsToPhiPi_PhiToMuMupTagged_Detached"] = { - "fields": { - "Ds": "[D_s+ -> (phi(1020) -> mu+ mu-) pi+]CC", - "phi": "[D_s+ -> ^(phi(1020) -> mu+ mu-) pi+]CC", - "pi": "[D_s+ -> (phi(1020) -> mu+ mu-) ^pi+]CC", - "mutag": "[D_s+ -> (phi(1020) -> ^mu+ mu-) pi+]CC", - "muprobe": "[D_s+ -> (phi(1020) -> mu+ ^mu-) pi+]CC", - }, - "variables": { - "ALL": common_vars, - "Ds": composite_vars, - "phi": composite_vars, - "pi": stable_vars, - "mutag": stable_vars, - "muprobe": stable_vars, - }, - } - - lines["DsToPhiPi_PhiToMuMumTagged_Detached"] = { - "fields": { - "Ds": "[D_s+ -> (phi(1020) -> mu- mu+) pi+]CC", - "phi": "[D_s+ -> ^(phi(1020) -> mu- mu+) pi+]CC", - "pi": "[D_s+ -> (phi(1020) -> mu- mu+) ^pi+]CC", - "mutag": "[D_s+ -> (phi(1020) -> ^mu- mu+) pi+]CC", - "muprobe": "[D_s+ -> (phi(1020) -> mu- ^mu+) pi+]CC", - }, - "variables": { - "ALL": common_vars, - "Ds": composite_vars, - "phi": composite_vars, - "pi": stable_vars, - "mutag": stable_vars, - "muprobe": stable_vars, - }, - } - - lines["BToJpsiK_JpsiToPpPmTagged_Detached"] = { - "fields": { - "B": "[B+]CC -> (J/psi(1S) -> p+ p~-) [K+]CC", - "Jpsi": "[B+]CC -> ^(J/psi(1S) -> p+ p~-) [K+]CC", - "K": "[B+]CC -> (J/psi(1S) -> p+ p~-) ^[K+]CC", - "pprobe": "[B+]CC -> (J/psi(1S) -> ^p+ p~-) [K+]CC", - "ptag": "[B+]CC -> (J/psi(1S) -> p+ ^p~-) [K+]CC", - }, - "variables": { - "ALL": common_vars, - "B": composite_vars, - "Jpsi": composite_vars, - "K": stable_vars, - "pprobe": stable_vars, - "ptag": stable_vars, - }, - } - - lines["BToJpsiK_JpsiToPmPpTagged_Detached"] = { - "fields": { - "B": "[B+]CC -> (J/psi(1S) -> p+ p~-) [K+]CC", - "Jpsi": "[B+]CC -> ^(J/psi(1S) -> p+ p~-) [K+]CC", - "K": "[B+]CC -> (J/psi(1S) -> p+ p~-) ^[K+]CC", - "ptag": "[B+]CC -> (J/psi(1S) -> ^p+ p~-) [K+]CC", - "pprobe": "[B+]CC -> (J/psi(1S) -> p+ ^p~-) [K+]CC", - }, - "variables": { - "ALL": common_vars, - "B": composite_vars, - "Jpsi": composite_vars, - "K": stable_vars, - "ptag": stable_vars, - "pprobe": stable_vars, - }, - } - - lines["OmegaToL0K_L0ToPPi_LLL"] = { - "fields": { - "Omega": "[Omega- -> (Lambda0 -> p+ pi-) K-]CC", - "Lambda0": "[Omega- -> ^(Lambda0 -> p+ pi-) K-]CC", - "K": "[Omega- -> (Lambda0 -> p+ pi-) ^K-]CC", - "p": "[Omega- -> (Lambda0 -> ^p+ pi-) K-]CC", - "pi": "[Omega- -> (Lambda0 -> p+ ^pi-) K-]CC", - }, - "variables": { - "ALL": common_vars, - "Omega": composite_vars, - "K": stable_vars, - "p": stable_vars, - "pi": stable_vars, - }, - } - - lines["OmegaToL0K_L0ToPPi_DDD"] = { - "fields": { - "Omega": "[Omega- -> (Lambda0 -> p+ pi-) K-]CC", - "Lambda0": "[Omega- -> ^(Lambda0 -> p+ pi-) K-]CC", - "K": "[Omega- -> (Lambda0 -> p+ pi-) ^K-]CC", - "p": "[Omega- -> (Lambda0 -> ^p+ pi-) K-]CC", - "pi": "[Omega- -> (Lambda0 -> p+ ^pi-) K-]CC", - }, - "variables": { - "ALL": common_vars, - "Omega": composite_vars, - "K": stable_vars, - "p": stable_vars, - "pi": stable_vars, - }, - } - - lines["SMOG2Dst2KPi"] = { - "fields": { - "Dstp": "[D*(2010)+ -> (D0 -> K- pi+ ) pi+]CC", - "D0": "[D*(2010)+ -> ^(D0 -> K- pi+ ) pi+]CC", - "Km": "[D*(2010)+ -> (D0 -> ^K- pi+ ) pi+]CC", - "pip": "[D*(2010)+ -> (D0 -> K- ^pi+ ) pi+]CC", - "pipsoft": "[D*(2010)+ -> (D0 -> K- pi+ ) ^pi+]CC", - }, - "variables": { - "ALL": common_vars, - "Dstp": composite_vars, - "D0": composite_vars, - "Km": stable_vars, - "pip": stable_vars, - "pipsoft": stable_vars, - }, - } - - lines["SMOG2KS2PiPiDD"] = { - "fields": { - "Ks0": "KS0 -> pi+ pi-", - "pip": "KS0 -> ^pi+ pi-", - "pim": "KS0 -> pi+ ^pi-", - }, - "variables": { - "ALL": common_vars, - "Ks0": composite_vars, - "pip": stable_vars, - "pim": stable_vars, - }, - } - - lines["SMOG2KS2PiPiLLHighPT"] = { - "fields": { - "Ks0": "KS0 -> pi+ pi-", - "pip": "KS0 -> ^pi+ pi-", - "pim": "KS0 -> pi+ ^pi-", - }, - "variables": { - "ALL": common_vars, - "Ks0": composite_vars, - "pip": stable_vars, - "pim": stable_vars, - }, - } - - lines["SMOG2KS2PiPiLLLowPT"] = { - "fields": { - "Ks0": "KS0 -> pi+ pi-", - "pip": "KS0 -> ^pi+ pi-", - "pim": "KS0 -> pi+ ^pi-", - }, - "variables": { - "ALL": common_vars, - "Ks0": composite_vars, - "pip": stable_vars, - "pim": stable_vars, - }, - } - - lines["SMOG2Lambda02PPiDD"] = { - "fields": { - "Lambda": "[Lambda0 -> p+ pi-]CC", - "pbar": "[Lambda0 -> ^p+ pi-]CC", - "pim": "[Lambda0 -> p+ ^pi-]CC", - }, - "variables": { - "ALL": common_vars, - "Lambda": composite_vars, - "pbar": stable_vars, - "pim": stable_vars, - }, - } - - lines["SMOG2Lambda02PPiLLLowPT"] = { - "fields": { - "Lambda": "[Lambda0 -> p+ pi-]CC", - "pbar": "[Lambda0 -> ^p+ pi-]CC", - "pim": "[Lambda0 -> p+ ^pi-]CC", - }, - "variables": { - "ALL": common_vars, - "Lambda": composite_vars, - "pbar": stable_vars, - "pim": stable_vars, - }, - } - - lines["SMOG2Lambda02PPiLLHighPT"] = { - "fields": { - "Lambda": "[Lambda0 -> p+ pi-]CC", - "pbar": "[Lambda0 -> ^p+ pi-]CC", - "pim": "[Lambda0 -> p+ ^pi-]CC", - }, - "variables": { - "ALL": common_vars, - "Lambda": composite_vars, - "pbar": stable_vars, - "pim": stable_vars, - }, - } - - lines["SMOG2PIDJpsi2MuMumTagged"] = { - "fields": { - "Jpsi": "J/psi(1S) -> mu- mu+", - "mum": "J/psi(1S) -> ^mu- mu+", - "mup": "J/psi(1S) -> mu- ^mu+", - }, - "variables": { - "ALL": common_vars, - "Jpsi": composite_vars, - "mum": stable_vars, - "mup": stable_vars, - }, - } - - lines["SMOG2PIDJpsi2MuMupTagged"] = { - "fields": { - "Jpsi": "J/psi(1S) -> mu- mu+", - "mum": "J/psi(1S) -> ^mu- mu+", - "mup": "J/psi(1S) -> mu- ^mu+", - }, - "variables": { - "ALL": common_vars, - "Jpsi": composite_vars, - "mum": stable_vars, - "mup": stable_vars, - }, - } - - lines["SMOG2Phi2kkHighPT_Kmprobe"] = { - "fields": { - "Phi": "phi(1020) -> K+ K-", - "Kp": "phi(1020) -> ^K+ K-", - "Km": "phi(1020) -> ^K+ K-", - }, - "variables": { - "ALL": common_vars, - "Phi": composite_vars, - "Kp": stable_vars, - "Km": stable_vars, - }, - } - - lines["SMOG2Phi2kkHighPT_Kpprobe"] = { - "fields": { - "Phi": "phi(1020) -> K+ K-", - "Kp": "phi(1020) -> ^K+ K-", - "Km": "phi(1020) -> ^K+ K-", - }, - "variables": { - "ALL": common_vars, - "Phi": composite_vars, - "Kp": stable_vars, - "Km": stable_vars, - }, - } - - lines["SMOG2Phi2kk_Kmprobe"] = { - "fields": { - "Phi": "phi(1020) -> K+ K-", - "Kp": "phi(1020) -> ^K+ K-", - "Km": "phi(1020) -> ^K+ K-", - }, - "variables": { - "ALL": common_vars, - "Phi": composite_vars, - "Kp": stable_vars, - "Km": stable_vars, - }, - } - - lines["SMOG2Phi2kk_Kpprobe"] = { - "fields": { - "Phi": "phi(1020) -> K+ K-", - "Kp": "phi(1020) -> ^K+ K-", - "Km": "phi(1020) -> ^K+ K-", - }, - "variables": { - "ALL": common_vars, - "Phi": composite_vars, - "Kp": stable_vars, - "Km": stable_vars, - }, - } - - algs = {} - for line, data in lines.items(): - algs.update(create_tuple_alg(line, data, options)) - - return make_config(options, algs) - diff --git a/run3_pidcalib_tupling/tupling_PID_turboraw.py b/run3_pidcalib_tupling/tupling_PID_turboraw.py deleted file mode 100644 index eb96f88b0e..0000000000 --- a/run3_pidcalib_tupling/tupling_PID_turboraw.py +++ /dev/null @@ -1,271 +0,0 @@ -############################################################################### -# (c) Copyright 2023 CERN for the benefit of the LHCb Collaboration # -# # -# This software is distributed under the terms of the GNU General Public # -# Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". # -# # -# In applying this licence, CERN does not waive the privileges and immunities # -# granted to it by virtue of its status as an Intergovernmental Organization # -# or submit itself to any jurisdiction. # -############################################################################### -""" -Read HLT2 files and create PID calibration ntuples. - -This script follows the Run 2 convention of creating a single file with -multiple trees. -""" - -from .alg import create_tuple_alg -from .Functions import * -from DaVinci import Options, make_config -from PyConf.reading import get_pvs - - -# NOTE: Uncomment if using 2023 data! Double check it works first. -# dd4hepSvc = DD4hepSvc() -# dd4hepSvc.DetectorList = ['/world', 'VP', 'FT', 'Magnet', 'Rich1', 'Rich2', 'Ecal', 'Hcal', 'Muon'] #removes the UT - - -def main(options: Options): - - pvs = get_pvs() - - common_vars = get_common_vars(pvs) - composite_vars = get_composite_vars(pvs) - - track_vars = get_track_vars() - rich_pid_vars = get_rich_pid_vars() - muon_pid_vars = get_muon_pid_vars() - general_pid_vars = get_general_pid_vars() - charged_calo_vars = get_charged_calo_vars() - stable_vars = ( - track_vars - + rich_pid_vars - + muon_pid_vars - + general_pid_vars - + charged_calo_vars - ) - - three_body_vars = get_three_body_vars() - four_body_vars = get_four_body_vars() - - d0tokpi_misid_vars = get_d_to_kpi_misid_vars() - l0toppi_misid_vars = get_l0_to_ppi_misid_vars() - - lines = {} - lines["DstToD0Pi_D0ToKPi"] = { - "fields": { - "Dst": "[D*(2010)+ -> (D0 -> K- pi+) pi+]CC", - "D": "[D*(2010)+ -> ^(D0 -> K- pi+) pi+]CC", - "pis": "[D*(2010)+ -> (D0 -> K- pi+) ^pi+]CC", - "K": "[D*(2010)+ -> (D0 -> ^K- pi+) pi+]CC", - "pi": "[D*(2010)+ -> (D0 -> K- ^pi+) pi+]CC", - }, - "variables": { - "ALL": common_vars, - "Dst": composite_vars, - "D": composite_vars + d0tokpi_misid_vars, - "pis": stable_vars, - "K": stable_vars, - "pi": stable_vars, - }, - } - - lines["L0ToPPi_LL_LowPT"] = { - "fields": { - "L0": "[Lambda0 -> p+ pi-]CC", - "p": "[Lambda0 -> ^p+ pi-]CC", - "pi": "[Lambda0 -> p+ ^pi-]CC", - }, - "variables": { - "ALL": common_vars, - "L0": composite_vars + l0toppi_misid_vars, - "p": stable_vars, - "pi": stable_vars, - }, - } - - lines["L0ToPPi_LL_MidPT"] = { - "fields": { - "L0": "[Lambda0 -> p+ pi-]CC", - "p": "[Lambda0 -> ^p+ pi-]CC", - "pi": "[Lambda0 -> p+ ^pi-]CC", - }, - "variables": { - "ALL": common_vars, - "L0": composite_vars + l0toppi_misid_vars, - "p": stable_vars, - "pi": stable_vars, - }, - } - - lines["L0ToPPi_LL_HighPT"] = { - "fields": { - "L0": "[Lambda0 -> p+ pi-]CC", - "p": "[Lambda0 -> ^p+ pi-]CC", - "pi": "[Lambda0 -> p+ ^pi-]CC", - }, - "variables": { - "ALL": common_vars, - "L0": composite_vars + l0toppi_misid_vars, - "p": stable_vars, - "pi": stable_vars, - }, - } - - lines["L0ToPPi_LL_VeryHighPT"] = { - "fields": { - "L0": "[Lambda0 -> p+ pi-]CC", - "p": "[Lambda0 -> ^p+ pi-]CC", - "pi": "[Lambda0 -> p+ ^pi-]CC", - }, - "variables": { - "ALL": common_vars, - "L0": composite_vars + l0toppi_misid_vars, - "p": stable_vars, - "pi": stable_vars, - }, - } - - lines["BToJpsiK_JpsiToEmbremEpbremTagged"] = { - "fields": { - "B": "[B+]CC -> (J/psi(1S) -> e+ e-) [K+]CC", - "Jpsi": "[B+]CC -> ^(J/psi(1S) -> e+ e-) [K+]CC", - "K": "[B+]CC -> (J/psi(1S) -> e+ e-) ^[K+]CC", - "etag": "[B+]CC -> (J/psi(1S) -> ^e+ e-) [K+]CC", - "eprobe": "[B+]CC -> (J/psi(1S) -> e+ ^e-) [K+]CC", - }, - "variables": { - "ALL": common_vars, - "B": composite_vars, - "Jpsi": composite_vars, - "K": stable_vars, - "etag": stable_vars, - "eprobe": stable_vars, - }, - } - - lines["BToJpsiK_JpsiToEpbremEmbremTagged"] = { - "fields": { - "B": "[B+]CC -> (J/psi(1S) -> e+ e-) [K+]CC", - "Jpsi": "[B+]CC -> ^(J/psi(1S) -> e+ e-) [K+]CC", - "K": "[B+]CC -> (J/psi(1S) -> e+ e-) ^[K+]CC", - "etag": "[B+]CC -> (J/psi(1S) -> e+ ^e-) [K+]CC", - "eprobe": "[B+]CC -> (J/psi(1S) -> ^e+ e-) [K+]CC", - }, - "variables": { - "ALL": common_vars, - "B": composite_vars, - "Jpsi": composite_vars, - "K": stable_vars, - "etag": stable_vars, - "eprobe": stable_vars, - }, - } - - lines["BToJpsiK_JpsiToEmbremEpbremTagged_noPIDe"] = { - "fields": { - "B": "[B+]CC -> (J/psi(1S) -> e+ e-) [K+]CC", - "Jpsi": "[B+]CC -> ^(J/psi(1S) -> e+ e-) [K+]CC", - "K": "[B+]CC -> (J/psi(1S) -> e+ e-) ^[K+]CC", - "etag": "[B+]CC -> (J/psi(1S) -> ^e+ e-) [K+]CC", - "eprobe": "[B+]CC -> (J/psi(1S) -> e+ ^e-) [K+]CC", - }, - "variables": { - "ALL": common_vars, - "B": composite_vars, - "Jpsi": composite_vars, - "K": stable_vars, - "etag": stable_vars, - "eprobe": stable_vars, - }, - } - - lines["BToJpsiK_JpsiToEpbremEmbremTagged_noPIDe"] = { - "fields": { - "B": "[B+]CC -> (J/psi(1S) -> e+ e-) [K+]CC", - "Jpsi": "[B+]CC -> ^(J/psi(1S) -> e+ e-) [K+]CC", - "K": "[B+]CC -> (J/psi(1S) -> e+ e-) ^[K+]CC", - "etag": "[B+]CC -> (J/psi(1S) -> e+ ^e-) [K+]CC", - "eprobe": "[B+]CC -> (J/psi(1S) -> ^e+ e-) [K+]CC", - }, - "variables": { - "ALL": common_vars, - "B": composite_vars, - "Jpsi": composite_vars, - "K": stable_vars, - "etag": stable_vars, - "eprobe": stable_vars, - }, - } - - lines["JpsiToMuMupTagged_Detached"] = { - "fields": { - "Jpsi": "J/psi(1S) -> mu+ mu-", - "mutag": "J/psi(1S) -> ^mu+ mu-", - "muprobe": "J/psi(1S) -> mu+ ^mu-", - }, - "variables": { - "ALL": common_vars, - "Jpsi": composite_vars, - "mutag": stable_vars, - "muprobe": stable_vars, - }, - } - - lines["JpsiToMuMumTagged_Detached"] = { - "fields": { - "Jpsi": "J/psi(1S) -> mu+ mu-", - "mutag": "J/psi(1S) -> mu+ ^mu-", - "muprobe": "J/psi(1S) -> ^mu+ mu-", - }, - "variables": { - "ALL": common_vars, - "Jpsi": composite_vars, - "mutag": stable_vars, - "muprobe": stable_vars, - }, - } - - lines["BToJpsiK_JpsiToMuMupTagged_Detached"] = { - "fields": { - "B": "[B+]CC -> (J/psi(1S) -> mu+ mu-) [K+]CC", - "Jpsi": "[B+]CC -> ^(J/psi(1S) -> mu+ mu-) [K+]CC", - "K": "[B+]CC -> (J/psi(1S) -> mu+ mu-) ^[K+]CC", - "mutag": "[B+]CC -> (J/psi(1S) -> ^mu+ mu-) [K+]CC", - "muprobe": "[B+]CC -> (J/psi(1S) -> mu+ ^mu-) [K+]CC", - }, - "variables": { - "ALL": common_vars, - "B": composite_vars, - "Jpsi": composite_vars, - "K": stable_vars, - "mutag": stable_vars, - "muprobe": stable_vars, - }, - } - - lines["BToJpsiK_JpsiToMuMumTagged_Detached"] = { - "fields": { - "B": "[B+]CC -> (J/psi(1S) -> mu+ mu-) [K+]CC", - "Jpsi": "[B+]CC -> ^(J/psi(1S) -> mu+ mu-) [K+]CC", - "K": "[B+]CC -> (J/psi(1S) -> mu+ mu-) ^[K+]CC", - "mutag": "[B+]CC -> (J/psi(1S) -> mu+ ^mu-) [K+]CC", - "muprobe": "[B+]CC -> (J/psi(1S) -> ^mu+ mu-) [K+]CC", - }, - "variables": { - "ALL": common_vars, - "B": composite_vars, - "Jpsi": composite_vars, - "K": stable_vars, - "mutag": stable_vars, - "muprobe": stable_vars, - }, - } - - - algs = {} - for line, data in lines.items(): - algs.update(create_tuple_alg(line, data, options)) - - return make_config(options, algs) -- GitLab From 7f4fe6209936cc18d2fcf94caa840fb450f3b406 Mon Sep 17 00:00:00 2001 From: Aidan Richard Wiederhold <aidan.richard.wiederhold@cern.ch> Date: Mon, 24 Jun 2024 15:50:26 +0200 Subject: [PATCH 05/15] Add the remainder of Run 2 data --- Bd2DPi_TDCPV_run2/README.md | 8 ++ Bd2DPi_TDCPV_run2/info.yaml | 42 +++++++ Bd2DPi_TDCPV_run2/prompt_D.py | 224 ++++++++++++++++++++++++++++++++++ 3 files changed, 274 insertions(+) create mode 100644 Bd2DPi_TDCPV_run2/README.md create mode 100644 Bd2DPi_TDCPV_run2/info.yaml create mode 100644 Bd2DPi_TDCPV_run2/prompt_D.py diff --git a/Bd2DPi_TDCPV_run2/README.md b/Bd2DPi_TDCPV_run2/README.md new file mode 100644 index 0000000000..963d94cdc0 --- /dev/null +++ b/Bd2DPi_TDCPV_run2/README.md @@ -0,0 +1,8 @@ + +## Tuples for the measurement of time dependent CP violation in B->DPi decays with D->KPiPi + +This third production gathers 2015-2018 data to act as a prompt D- sample to be used for time resolution studies. + +The second production collected the 2018 prompt D- data, this is superseded by the third production due to a bug fix in the momentum scaling input location. +The first production obtained run 2 data and 2018 signal MC for Bd -> D- pi+ decays. +The script was based on that of the DsK analysis, updated to include the inclusive flavour tagger outputs and track isolation variables. diff --git a/Bd2DPi_TDCPV_run2/info.yaml b/Bd2DPi_TDCPV_run2/info.yaml new file mode 100644 index 0000000000..6e76177c12 --- /dev/null +++ b/Bd2DPi_TDCPV_run2/info.yaml @@ -0,0 +1,42 @@ +defaults: + application: DaVinci/v45r8 + wg: B2OC + automatically_configure: yes + turbo: no + inform: + - aidan.richard.wiederhold@cern.ch + output: Bd2DPi.ROOT + options: + - prompt_D.py + +2018_MagDown_Prompt_Data: + input: + bk_query: "/LHCb/Collision18/Beam6500GeV-VeloClosed-MagDown/Real Data/Reco18/Stripping34/90000000/BHADRON.MDST" + +2018_MagUp_Prompt_Data: + input: + bk_query: "/LHCb/Collision18/Beam6500GeV-VeloClosed-MagUp/Real Data/Reco18/Stripping34/90000000/BHADRON.MDST" + +2017_MagDown_Prompt_Data: + input: + bk_query: "/LHCb/Collision17/Beam6500GeV-VeloClosed-MagDown/Real Data/Reco17/Stripping29r2/90000000/BHADRON.MDST" + +2017_MagUp_Prompt_Data: + input: + bk_query: "/LHCb/Collision17/Beam6500GeV-VeloClosed-MagUp/Real Data/Reco17/Stripping29r2/90000000/BHADRON.MDST" + +2016_MagDown_Prompt_Data: + input: + bk_query: "/LHCb/Collision16/Beam6500GeV-VeloClosed-MagDown/Real Data/Reco16/Stripping28r2/90000000/BHADRON.MDST" + +2016_MagUp_Prompt_Data: + input: + bk_query: "/LHCb/Collision16/Beam6500GeV-VeloClosed-MagUp/Real Data/Reco16/Stripping28r2/90000000/BHADRON.MDST" + +2015_MagDown_Prompt_Data: + input: + bk_query: "/LHCb/Collision15/Beam6500GeV-VeloClosed-MagDown/Real Data/Reco15a/Stripping24r2/90000000/BHADRON.MDST" + +2015_MagUp_Prompt_Data: + input: + bk_query: "/LHCb/Collision15/Beam6500GeV-VeloClosed-MagUp/Real Data/Reco15a/Stripping24r2/90000000/BHADRON.MDST" diff --git a/Bd2DPi_TDCPV_run2/prompt_D.py b/Bd2DPi_TDCPV_run2/prompt_D.py new file mode 100644 index 0000000000..a91ee32041 --- /dev/null +++ b/Bd2DPi_TDCPV_run2/prompt_D.py @@ -0,0 +1,224 @@ +import sys +import optparse +from os import environ +from Gaudi.Configuration import * +from Configurables import DecayTreeTuple, BTaggingTool, SubstitutePID +from Configurables import CombineParticles, FilterDesktop, TupleToolDecayTreeFitter, TupleToolDecay +from Configurables import BackgroundCategory, TupleToolKinematic, TupleToolGeometry, TupleToolRecoStats +from Configurables import TupleToolTrackIsolation, TupleToolPropertime, TupleToolTISTOS +from Configurables import TupleToolTagging, BTagging +from Configurables import LoKi__PVReFitter +from PhysConf.Filters import LoKi_Filters +from FlavourTagging.Tunings import TuneTool +from FlavourTagging.Tunings import applyTuning +from DecayTreeTuple.Configuration import * +from Configurables import TrackScaleState, TrackSmearState +from Configurables import CondDB +from Configurables import DaVinci + +################################################### +# +# Tools +# +################################################### +def configureConventionalTaggingTools(BTuple, BsBd, inputs): + Btag = BTagging("BTagging") + Btag.Inputs = inputs + Btag.OutputLevel = 6 + toolname = BsBd+"TaggingTool" + BTuple.TaggingToolName ="BTaggingTool/"+toolname + BTuple.ExtraName = toolname + #TuneTool(BTuple,"Stripping21",toolname) # change S21 --> S28!!! + + ############ Summer2017Optimisation ####################### + BTuple.Verbose = True + BTuple.AddMVAFeatureInfo = True + BTuple.AddTagPartsInfo = False + from Configurables import BTaggingTool + btagtool = BTuple.addTool(BTaggingTool,name=toolname) + from FlavourTagging.Tunings import applyTuning as applyFTTuning + applyFTTuning(btagtool, tuning_version="Summer2017Optimisation_v4_Run2") + BTuple.TaggingToolName = btagtool.getFullName() + ############################################################ + +def configureInclusiveTaggingTool(BTuple_IFT, BsBd): + ############ Inclusive Flavour Tagging ##################### + + btagtool_ift = BTuple_IFT.addTool(BTaggingTool, name = "IftBTaggingTool") + btagtool_ift.TaggingParticleLocation = "Phys/TaggingIFTTracks" + BTuple_IFT.allConfigurables["ToolSvc.InclusiveTagger"].setProp("ClassifierVersion", f"IFT_{BsBd}_v140521") + BTuple_IFT.ExtraName = "IFT" + applyTuning(btagtool_ift, tuning_version="Summer2019Optimisation_v1_Run2") + BTuple_IFT.TaggingToolName = btagtool_ift.getFullName() + + ############################################################ + +def genFilterDesktop(name, inputs, code): + retVal = FilterDesktop(name) + retVal.Inputs = inputs + retVal.Code = code + return retVal + +def genDecayTreeTuple(name, inputs, decay, triggers): + retVal = DecayTreeTuple(name) + retVal.Inputs = inputs + retVal.Decay = decay + retVal.addTool(TupleToolDecay, name = 'lab0') + retVal.addTool(TupleToolDecay, name = 'lab2') + #"[[B0]CC -> (D- -> K+ pi- pi-) pi+ ]CC" + retVal.Branches = { 'lab0': decay.replace('^', ''), + 'lab2': decay.replace('^', '').replace('(D-', '^(D-')} + + # refit PVs + retVal.ReFitPVs = True + + # fill with generic info + retVal.ToolList = ([ + "TupleToolKinematic", + "TupleToolPid", + "TupleToolGeometry", + "TupleToolPrimaries", + "TupleToolTrackInfo", + "TupleToolEventInfo", + "TupleToolRecoStats", + "TupleToolAngles", + "TupleToolTrackIsolation"]) + if DaVinci().Simulation: + retVal.addTool(TupleToolMCTruth) + retVal.ToolList += (["TupleToolMCTruth", "TupleToolMCBackgroundInfo"]) + retVal.TupleToolMCTruth.ToolList += ["MCTupleToolHierarchy"] + + retVal.addTool( TupleToolKinematic,name = "TupleToolKinematic" ) + retVal.TupleToolKinematic.Verbose = False + + retVal.addTool( TupleToolGeometry, name = "TupleToolGeometry" ) + retVal.TupleToolGeometry.Verbose = False + + retVal.addTool( TupleToolRecoStats, name="TupleToolRecoStats") + retVal.TupleToolRecoStats.Verbose = True + + retVal.addTool( TupleToolTrackIsolation, name = "TupleToolTrackIsolation" ) + retVal.TupleToolTrackIsolation.Verbose = True + retVal.TupleToolTrackIsolation.MaxConeAngle = 1.75 + retVal.TupleToolTrackIsolation.MinConeAngle = 0.75 + retVal.TupleToolTrackIsolation.StepSize = 0.25 + + + retVal.UseLabXSyntax = True + retVal.RevertToPositiveID = False + + # fill charm info + retVal.lab2.ToolList = ["TupleToolPropertime","TupleToolGeometry/VerboseGeomForD"] + # retVal.lab2.ToolList = [TupleToolGeometry/VerboseGeomForD"] + retVal.lab2.addTool(TupleToolPropertime, name = "TupleToolPropertime") + retVal.lab2.addTool(TupleToolGeometry, name = "VerboseGeomForD") + retVal.lab2.VerboseGeomForD.Verbose = True + + # fill beauty info + retVal.lab0.addTool(TupleToolPropertime, name = "TupleToolPropertime") + retVal.lab0.ToolList = [ "TupleToolTISTOS/TisTosB", + "TupleToolDecayTreeFitter/MassFitConsD", + "TupleToolDecayTreeFitter/LifetimeFit", + "TupleToolDecayTreeFitter/LifetimeFitConsD", + "TupleToolPropertime"] + + # TIS-TOS on B-cand + retVal.lab0.addTool(TupleToolTISTOS, name = "TisTosB") + retVal.lab0.TisTosB.Verbose = True + retVal.lab0.TisTosB.TriggerList = triggers + + # do mass constraints + bssubs = {'Beauty -> Meson ^D+' : 'D_s+', 'Beauty -> Meson ^D-' : 'D_s-'} + retVal.lab0.addTool(TupleToolDecayTreeFitter, name = "MassFitConsD") + retVal.lab0.MassFitConsD.Verbose = True + retVal.lab0.MassFitConsD.constrainToOriginVertex = False + if not ('Bs' in name): + retVal.lab0.MassFitConsD.daughtersToConstrain = [ "D-" ] + else: + retVal.lab0.MassFitConsD.daughtersToConstrain = [ "D_s-" ] + retVal.lab0.MassFitConsD.Substitutions = bssubs + + # do lifetime fit + retVal.lab0.addTool(TupleToolDecayTreeFitter, name = "LifetimeFit") # w/o D-mass cons + retVal.lab0.LifetimeFit.Verbose = True + retVal.lab0.LifetimeFit.constrainToOriginVertex = True + + retVal.lab0.addTool(TupleToolDecayTreeFitter, name = "LifetimeFitConsD") # w/ D-mass cons + retVal.lab0.LifetimeFitConsD.Verbose = True + retVal.lab0.LifetimeFitConsD.constrainToOriginVertex = True + if not ('Bs' in name): + retVal.lab0.LifetimeFitConsD.daughtersToConstrain = [ "D-" ] + else: + retVal.lab0.LifetimeFitConsD.daughtersToConstrain = [ "D_s-" ] + retVal.lab0.LifetimeFitConsD.Substitutions = bssubs + + # fill Flavour Tagging info + #tag = retVal.lab0.addTupleTool( TupleToolTagging, name = "BsAll" if ("Bs" in name) else "BdAll" ) + #tag_IFT = retVal.lab0.addTupleTool("TupleToolTagging/ift") + #configureInclusiveTaggingTool(tag_IFT, "Bs" if ("Bs" in name) else "Bd") + #configureConventionalTaggingTools(tag, "Bs" if ("Bs" in name) else "Bd", inputs) + return retVal + + +################################################### +# +# Configuration +# +################################################### +# Stripping lines +#if simulation == True: stream = "/Event/b0s2dssth.Strip" # for filtered MC!!! +#if DaVinci().Simulation: stream = "/Event/B2DH.Strip" +if DaVinci().Simulation: + location_prefix_0 = "/Event" + location_prefix_1 = "/AllStreams" +else: + DaVinci().RootInTES = "/Event/Bhadron" + location_prefix_0 = "" + location_prefix_1 = "" +inputs = [f"{location_prefix_0}{location_prefix_1}/Phys/B02DKLTUBD2HHHBeauty2CharmLine/Particles"] + +# Trigger lines +triggers = [ "L0HadronDecision", + "Hlt1TrackMVADecision", + "Hlt1TwoTrackMVADecision", + "Hlt2Topo2BodyDecision", + "Hlt2Topo3BodyDecision", + "Hlt2Topo4BodyDecision", + "Hlt2PhiIncPhiDecision" ] + +# Event filter +B2DXSel = genFilterDesktop("B2DXSel", inputs, "(INTREE((ABSID=='D+')&(M<1945)))") + +from Configurables import CheckPV +checkpv = CheckPV() + +MyFilterSeq = GaudiSequencer("MyFilterSeq") +MyFilterSeq.Members = [B2DXSel] +MyFilterSeq.IgnoreFilterPassed = True + +check_refitted_pv = FilterDesktop('CheckReFitPV', + Code='BPVVALID()', + Inputs=[f"{location_prefix_0}/Phys/B2DXSel/Particles"], + ReFitPVs=True) + +# DecayTreeTuple +Bd2DPiOfflineTree = genDecayTreeTuple( + "Bd2DPiOfflineTree", + [f"{location_prefix_0}/Phys/CheckReFitPV/Particles"], + "[[B0]CC -> ^(pi+ || K+) ^(D- -> ^K+ ^pi- ^pi-)]CC", + triggers) + +UserSequence = GaudiSequencer("UserSequence") +UserSequence.Members += [ + checkpv, + check_refitted_pv, + Bd2DPiOfflineTree + ] +if not DaVinci().Simulation: + scaler = TrackScaleState('MomentumScaler') + scaler.RootInTES = DaVinci().RootInTES + DaVinci().UserAlgorithms += [scaler] +DaVinci().UserAlgorithms += [ + MyFilterSeq, + UserSequence + ] -- GitLab From e4fd3911852b9a5711608fdab20fe16c22184442 Mon Sep 17 00:00:00 2001 From: LHCb Data Processing and Analysis <lhcb.dpa@cern.ch> Date: Mon, 24 Jun 2024 15:50:45 +0200 Subject: [PATCH 06/15] Revert "Add the remainder of Run 2 data" This reverts merge request !1425 --- Bd2DPi_TDCPV_run2/README.md | 8 -- Bd2DPi_TDCPV_run2/info.yaml | 42 ------ Bd2DPi_TDCPV_run2/prompt_D.py | 224 ----------------------------- Beauty_XS_Bs2DsPi/README.md | 3 + Beauty_XS_Bs2DsPi/dv_simple.py | 252 +++++++++++++++++++++++++++++++++ Beauty_XS_Bs2DsPi/hlt1.py | 31 ++++ Beauty_XS_Bs2DsPi/hlt2.py | 68 +++++++++ Beauty_XS_Bs2DsPi/info.yaml | 79 +++++++++++ 8 files changed, 433 insertions(+), 274 deletions(-) delete mode 100644 Bd2DPi_TDCPV_run2/README.md delete mode 100644 Bd2DPi_TDCPV_run2/info.yaml delete mode 100644 Bd2DPi_TDCPV_run2/prompt_D.py create mode 100644 Beauty_XS_Bs2DsPi/README.md create mode 100644 Beauty_XS_Bs2DsPi/dv_simple.py create mode 100644 Beauty_XS_Bs2DsPi/hlt1.py create mode 100644 Beauty_XS_Bs2DsPi/hlt2.py create mode 100644 Beauty_XS_Bs2DsPi/info.yaml diff --git a/Bd2DPi_TDCPV_run2/README.md b/Bd2DPi_TDCPV_run2/README.md deleted file mode 100644 index 963d94cdc0..0000000000 --- a/Bd2DPi_TDCPV_run2/README.md +++ /dev/null @@ -1,8 +0,0 @@ - -## Tuples for the measurement of time dependent CP violation in B->DPi decays with D->KPiPi - -This third production gathers 2015-2018 data to act as a prompt D- sample to be used for time resolution studies. - -The second production collected the 2018 prompt D- data, this is superseded by the third production due to a bug fix in the momentum scaling input location. -The first production obtained run 2 data and 2018 signal MC for Bd -> D- pi+ decays. -The script was based on that of the DsK analysis, updated to include the inclusive flavour tagger outputs and track isolation variables. diff --git a/Bd2DPi_TDCPV_run2/info.yaml b/Bd2DPi_TDCPV_run2/info.yaml deleted file mode 100644 index 6e76177c12..0000000000 --- a/Bd2DPi_TDCPV_run2/info.yaml +++ /dev/null @@ -1,42 +0,0 @@ -defaults: - application: DaVinci/v45r8 - wg: B2OC - automatically_configure: yes - turbo: no - inform: - - aidan.richard.wiederhold@cern.ch - output: Bd2DPi.ROOT - options: - - prompt_D.py - -2018_MagDown_Prompt_Data: - input: - bk_query: "/LHCb/Collision18/Beam6500GeV-VeloClosed-MagDown/Real Data/Reco18/Stripping34/90000000/BHADRON.MDST" - -2018_MagUp_Prompt_Data: - input: - bk_query: "/LHCb/Collision18/Beam6500GeV-VeloClosed-MagUp/Real Data/Reco18/Stripping34/90000000/BHADRON.MDST" - -2017_MagDown_Prompt_Data: - input: - bk_query: "/LHCb/Collision17/Beam6500GeV-VeloClosed-MagDown/Real Data/Reco17/Stripping29r2/90000000/BHADRON.MDST" - -2017_MagUp_Prompt_Data: - input: - bk_query: "/LHCb/Collision17/Beam6500GeV-VeloClosed-MagUp/Real Data/Reco17/Stripping29r2/90000000/BHADRON.MDST" - -2016_MagDown_Prompt_Data: - input: - bk_query: "/LHCb/Collision16/Beam6500GeV-VeloClosed-MagDown/Real Data/Reco16/Stripping28r2/90000000/BHADRON.MDST" - -2016_MagUp_Prompt_Data: - input: - bk_query: "/LHCb/Collision16/Beam6500GeV-VeloClosed-MagUp/Real Data/Reco16/Stripping28r2/90000000/BHADRON.MDST" - -2015_MagDown_Prompt_Data: - input: - bk_query: "/LHCb/Collision15/Beam6500GeV-VeloClosed-MagDown/Real Data/Reco15a/Stripping24r2/90000000/BHADRON.MDST" - -2015_MagUp_Prompt_Data: - input: - bk_query: "/LHCb/Collision15/Beam6500GeV-VeloClosed-MagUp/Real Data/Reco15a/Stripping24r2/90000000/BHADRON.MDST" diff --git a/Bd2DPi_TDCPV_run2/prompt_D.py b/Bd2DPi_TDCPV_run2/prompt_D.py deleted file mode 100644 index a91ee32041..0000000000 --- a/Bd2DPi_TDCPV_run2/prompt_D.py +++ /dev/null @@ -1,224 +0,0 @@ -import sys -import optparse -from os import environ -from Gaudi.Configuration import * -from Configurables import DecayTreeTuple, BTaggingTool, SubstitutePID -from Configurables import CombineParticles, FilterDesktop, TupleToolDecayTreeFitter, TupleToolDecay -from Configurables import BackgroundCategory, TupleToolKinematic, TupleToolGeometry, TupleToolRecoStats -from Configurables import TupleToolTrackIsolation, TupleToolPropertime, TupleToolTISTOS -from Configurables import TupleToolTagging, BTagging -from Configurables import LoKi__PVReFitter -from PhysConf.Filters import LoKi_Filters -from FlavourTagging.Tunings import TuneTool -from FlavourTagging.Tunings import applyTuning -from DecayTreeTuple.Configuration import * -from Configurables import TrackScaleState, TrackSmearState -from Configurables import CondDB -from Configurables import DaVinci - -################################################### -# -# Tools -# -################################################### -def configureConventionalTaggingTools(BTuple, BsBd, inputs): - Btag = BTagging("BTagging") - Btag.Inputs = inputs - Btag.OutputLevel = 6 - toolname = BsBd+"TaggingTool" - BTuple.TaggingToolName ="BTaggingTool/"+toolname - BTuple.ExtraName = toolname - #TuneTool(BTuple,"Stripping21",toolname) # change S21 --> S28!!! - - ############ Summer2017Optimisation ####################### - BTuple.Verbose = True - BTuple.AddMVAFeatureInfo = True - BTuple.AddTagPartsInfo = False - from Configurables import BTaggingTool - btagtool = BTuple.addTool(BTaggingTool,name=toolname) - from FlavourTagging.Tunings import applyTuning as applyFTTuning - applyFTTuning(btagtool, tuning_version="Summer2017Optimisation_v4_Run2") - BTuple.TaggingToolName = btagtool.getFullName() - ############################################################ - -def configureInclusiveTaggingTool(BTuple_IFT, BsBd): - ############ Inclusive Flavour Tagging ##################### - - btagtool_ift = BTuple_IFT.addTool(BTaggingTool, name = "IftBTaggingTool") - btagtool_ift.TaggingParticleLocation = "Phys/TaggingIFTTracks" - BTuple_IFT.allConfigurables["ToolSvc.InclusiveTagger"].setProp("ClassifierVersion", f"IFT_{BsBd}_v140521") - BTuple_IFT.ExtraName = "IFT" - applyTuning(btagtool_ift, tuning_version="Summer2019Optimisation_v1_Run2") - BTuple_IFT.TaggingToolName = btagtool_ift.getFullName() - - ############################################################ - -def genFilterDesktop(name, inputs, code): - retVal = FilterDesktop(name) - retVal.Inputs = inputs - retVal.Code = code - return retVal - -def genDecayTreeTuple(name, inputs, decay, triggers): - retVal = DecayTreeTuple(name) - retVal.Inputs = inputs - retVal.Decay = decay - retVal.addTool(TupleToolDecay, name = 'lab0') - retVal.addTool(TupleToolDecay, name = 'lab2') - #"[[B0]CC -> (D- -> K+ pi- pi-) pi+ ]CC" - retVal.Branches = { 'lab0': decay.replace('^', ''), - 'lab2': decay.replace('^', '').replace('(D-', '^(D-')} - - # refit PVs - retVal.ReFitPVs = True - - # fill with generic info - retVal.ToolList = ([ - "TupleToolKinematic", - "TupleToolPid", - "TupleToolGeometry", - "TupleToolPrimaries", - "TupleToolTrackInfo", - "TupleToolEventInfo", - "TupleToolRecoStats", - "TupleToolAngles", - "TupleToolTrackIsolation"]) - if DaVinci().Simulation: - retVal.addTool(TupleToolMCTruth) - retVal.ToolList += (["TupleToolMCTruth", "TupleToolMCBackgroundInfo"]) - retVal.TupleToolMCTruth.ToolList += ["MCTupleToolHierarchy"] - - retVal.addTool( TupleToolKinematic,name = "TupleToolKinematic" ) - retVal.TupleToolKinematic.Verbose = False - - retVal.addTool( TupleToolGeometry, name = "TupleToolGeometry" ) - retVal.TupleToolGeometry.Verbose = False - - retVal.addTool( TupleToolRecoStats, name="TupleToolRecoStats") - retVal.TupleToolRecoStats.Verbose = True - - retVal.addTool( TupleToolTrackIsolation, name = "TupleToolTrackIsolation" ) - retVal.TupleToolTrackIsolation.Verbose = True - retVal.TupleToolTrackIsolation.MaxConeAngle = 1.75 - retVal.TupleToolTrackIsolation.MinConeAngle = 0.75 - retVal.TupleToolTrackIsolation.StepSize = 0.25 - - - retVal.UseLabXSyntax = True - retVal.RevertToPositiveID = False - - # fill charm info - retVal.lab2.ToolList = ["TupleToolPropertime","TupleToolGeometry/VerboseGeomForD"] - # retVal.lab2.ToolList = [TupleToolGeometry/VerboseGeomForD"] - retVal.lab2.addTool(TupleToolPropertime, name = "TupleToolPropertime") - retVal.lab2.addTool(TupleToolGeometry, name = "VerboseGeomForD") - retVal.lab2.VerboseGeomForD.Verbose = True - - # fill beauty info - retVal.lab0.addTool(TupleToolPropertime, name = "TupleToolPropertime") - retVal.lab0.ToolList = [ "TupleToolTISTOS/TisTosB", - "TupleToolDecayTreeFitter/MassFitConsD", - "TupleToolDecayTreeFitter/LifetimeFit", - "TupleToolDecayTreeFitter/LifetimeFitConsD", - "TupleToolPropertime"] - - # TIS-TOS on B-cand - retVal.lab0.addTool(TupleToolTISTOS, name = "TisTosB") - retVal.lab0.TisTosB.Verbose = True - retVal.lab0.TisTosB.TriggerList = triggers - - # do mass constraints - bssubs = {'Beauty -> Meson ^D+' : 'D_s+', 'Beauty -> Meson ^D-' : 'D_s-'} - retVal.lab0.addTool(TupleToolDecayTreeFitter, name = "MassFitConsD") - retVal.lab0.MassFitConsD.Verbose = True - retVal.lab0.MassFitConsD.constrainToOriginVertex = False - if not ('Bs' in name): - retVal.lab0.MassFitConsD.daughtersToConstrain = [ "D-" ] - else: - retVal.lab0.MassFitConsD.daughtersToConstrain = [ "D_s-" ] - retVal.lab0.MassFitConsD.Substitutions = bssubs - - # do lifetime fit - retVal.lab0.addTool(TupleToolDecayTreeFitter, name = "LifetimeFit") # w/o D-mass cons - retVal.lab0.LifetimeFit.Verbose = True - retVal.lab0.LifetimeFit.constrainToOriginVertex = True - - retVal.lab0.addTool(TupleToolDecayTreeFitter, name = "LifetimeFitConsD") # w/ D-mass cons - retVal.lab0.LifetimeFitConsD.Verbose = True - retVal.lab0.LifetimeFitConsD.constrainToOriginVertex = True - if not ('Bs' in name): - retVal.lab0.LifetimeFitConsD.daughtersToConstrain = [ "D-" ] - else: - retVal.lab0.LifetimeFitConsD.daughtersToConstrain = [ "D_s-" ] - retVal.lab0.LifetimeFitConsD.Substitutions = bssubs - - # fill Flavour Tagging info - #tag = retVal.lab0.addTupleTool( TupleToolTagging, name = "BsAll" if ("Bs" in name) else "BdAll" ) - #tag_IFT = retVal.lab0.addTupleTool("TupleToolTagging/ift") - #configureInclusiveTaggingTool(tag_IFT, "Bs" if ("Bs" in name) else "Bd") - #configureConventionalTaggingTools(tag, "Bs" if ("Bs" in name) else "Bd", inputs) - return retVal - - -################################################### -# -# Configuration -# -################################################### -# Stripping lines -#if simulation == True: stream = "/Event/b0s2dssth.Strip" # for filtered MC!!! -#if DaVinci().Simulation: stream = "/Event/B2DH.Strip" -if DaVinci().Simulation: - location_prefix_0 = "/Event" - location_prefix_1 = "/AllStreams" -else: - DaVinci().RootInTES = "/Event/Bhadron" - location_prefix_0 = "" - location_prefix_1 = "" -inputs = [f"{location_prefix_0}{location_prefix_1}/Phys/B02DKLTUBD2HHHBeauty2CharmLine/Particles"] - -# Trigger lines -triggers = [ "L0HadronDecision", - "Hlt1TrackMVADecision", - "Hlt1TwoTrackMVADecision", - "Hlt2Topo2BodyDecision", - "Hlt2Topo3BodyDecision", - "Hlt2Topo4BodyDecision", - "Hlt2PhiIncPhiDecision" ] - -# Event filter -B2DXSel = genFilterDesktop("B2DXSel", inputs, "(INTREE((ABSID=='D+')&(M<1945)))") - -from Configurables import CheckPV -checkpv = CheckPV() - -MyFilterSeq = GaudiSequencer("MyFilterSeq") -MyFilterSeq.Members = [B2DXSel] -MyFilterSeq.IgnoreFilterPassed = True - -check_refitted_pv = FilterDesktop('CheckReFitPV', - Code='BPVVALID()', - Inputs=[f"{location_prefix_0}/Phys/B2DXSel/Particles"], - ReFitPVs=True) - -# DecayTreeTuple -Bd2DPiOfflineTree = genDecayTreeTuple( - "Bd2DPiOfflineTree", - [f"{location_prefix_0}/Phys/CheckReFitPV/Particles"], - "[[B0]CC -> ^(pi+ || K+) ^(D- -> ^K+ ^pi- ^pi-)]CC", - triggers) - -UserSequence = GaudiSequencer("UserSequence") -UserSequence.Members += [ - checkpv, - check_refitted_pv, - Bd2DPiOfflineTree - ] -if not DaVinci().Simulation: - scaler = TrackScaleState('MomentumScaler') - scaler.RootInTES = DaVinci().RootInTES - DaVinci().UserAlgorithms += [scaler] -DaVinci().UserAlgorithms += [ - MyFilterSeq, - UserSequence - ] diff --git a/Beauty_XS_Bs2DsPi/README.md b/Beauty_XS_Bs2DsPi/README.md new file mode 100644 index 0000000000..769ed08b69 --- /dev/null +++ b/Beauty_XS_Bs2DsPi/README.md @@ -0,0 +1,3 @@ +Production of Bs -> Ds pi to run on 2024 collision data to include both up and down polarities + +This is for use in early measurements of Beauty XS diff --git a/Beauty_XS_Bs2DsPi/dv_simple.py b/Beauty_XS_Bs2DsPi/dv_simple.py new file mode 100644 index 0000000000..b4254db880 --- /dev/null +++ b/Beauty_XS_Bs2DsPi/dv_simple.py @@ -0,0 +1,252 @@ +# Based on: +# https://gitlab.cern.ch/lhcb/DaVinci/-/blob/v63r2/DaVinciExamples/python/DaVinciExamples/tupling/option_davinci_tupling_from_hlt2.py + +import Functors as F +import FunTuple.functorcollections as FC +from FunTuple import FunctorCollection, FunTuple_Particles as Funtuple +from PyConf.reading import get_particles, get_pvs, get_rec_summary, get_odin +#from PyConf.Algorithms import AdvancedCloneKiller, Run2SSPionTagger +from GaudiKernel.SystemOfUnits import GeV +from Hlt2Conf.algorithms_thor import ParticleFilter +#from DaVinci.common_particles import make_long_pions +from DaVinci.algorithms import create_lines_filter +from DaVinci import Options, make_config +from DaVinciMCTools import MCTruthAndBkgCat +from DecayTreeFitter import DecayTreeFitter +from Hlt2Conf.flavourTagging import run2_all_taggers +# specific for the B2OC SigmaNet +import Functors.math as fmath +import os + + +def alg_config(options: Options): + + line = "Hlt2B2OC_BdToDsmPi_DsmToKpKmPim" + line_data = get_particles(f"/Event/HLT2/{line}/Particles") + my_filter = create_lines_filter("Hlt2Line_Filter", + lines=[f"{line}"]) + Hlt1_decisions = [ + "Hlt1TrackMVADecision", + "Hlt1TwoTrackMVADecision", + ] + Hlt2_decisions = ['Hlt2B2OC_BdToDsmPi_DsmToKpKmPimDecision', + 'Hlt2Topo2BodyDecision', + 'Hlt2Topo3BodyDecision'] + + fields = { + "lab0": "[[B0]CC -> (D_s- -> K+ K- pi-) pi+]CC", + "lab1": "[[B0]CC -> (D_s- -> K+ K- pi-) ^pi+]CC", + "lab2": "[[B0]CC -> ^(D_s- -> K+ K- pi-) pi+]CC", + "lab3": "[[B0]CC -> (D_s- -> ^K+ K- pi-) pi+]CC", + "lab4": "[[B0]CC -> (D_s- -> K+ ^K- pi-) pi+]CC", + "lab5": "[[B0]CC -> (D_s- -> K+ K- ^pi-) pi+]CC", + } + + pvs = get_pvs() + + DTF_MassFitConsD = DecayTreeFitter(name="DTF_MassFitConsD", + input_particles=line_data, + mass_constraints=["D_s-"]) + DTF_LifetimeFit = DecayTreeFitter(name="DTF_LifetimeFit", + input_particles=line_data, + input_pvs=pvs) + + all_tagging = run2_all_taggers(line_data) + + # define helper functors + get_child = F.CHILD(1, F.FORWARDARG0) # change here the index of the child + get_SV = F.ENDVERTEX @ F.FORWARDARG0 + get_SV_pos = F.TOLINALG @ F.POSITION @ get_SV # only if composite (i.e. has vertex) + get_child_endvtx_pos = F.ENDVERTEX_POS @ get_child + get_fdvec_child = get_child_endvtx_pos - get_SV_pos + + # define observables + IP_wrt_SV = F.IP.bind(get_SV_pos , get_child) + IPCHI2_wrt_SV = F.IPCHI2.bind(get_SV , get_child) # only if child is composite (i.e. has vertex) + FD_wrt_SV = F.MAGNITUDE @ get_fdvec_child + FDCHI2_wrt_SV = F.VTX_FDCHI2.bind(get_SV, get_child) + + B_variables = FunctorCollection( + { + "ID": F.PARTICLE_ID, + "PT": F.PT, + "ETA": F.ETA, + "P": F.P, + "SUMPT": F.SUM(F.PT), + "MASS": F.MASS, + "BPVDIRA": F.BPVDIRA(pvs), + "CHI2DOF": F.CHI2DOF, + "BPVIPCHI2": F.BPVIPCHI2(pvs), + "BPVIP": F.BPVIP(pvs), + "BPVFDCHI2": F.BPVFDCHI2(pvs), + "BPVLTIME": F.BPVLTIME(pvs), + "BPVFD": F.BPVFD(pvs), + "CHILD1_IPwrtSV": IP_wrt_SV, + "CHILD1_IPCHI2wrtSV": IPCHI2_wrt_SV, + "CHILD1_FDwrtSV": FD_wrt_SV, + "CHILD1_FDCHI2wrtSV": FDCHI2_wrt_SV, + "DTF_MassFitConsD_MASS": DTF_MassFitConsD(F.MASS), + "DTF_MassFitConsD_CHI2DOF": DTF_MassFitConsD(F.CHI2DOF), # track or vertex chi2/ndf + "DTF_MassFitConsD_P": DTF_MassFitConsD(F.P), + "DTF_LifetimeFit_MASS": DTF_LifetimeFit(F.MASS), + "DTF_LifetimeFit_CHI2DOF": DTF_LifetimeFit(F.CHI2DOF), # track or vertex chi2/ndf + "DTF_LifetimeFit_CTAU": DTF_LifetimeFit.CTAU, + "DTF_LifetimeFit_CTAUERR": DTF_LifetimeFit.CTAUERR, + "PX": F.PX, + "PY": F.PY, + "PZ": F.PZ, + "BPVX": F.BPVX(pvs), + "BPVY": F.BPVY(pvs), + "BPVZ": F.BPVZ(pvs), + "END_VX": F.END_VX, + "END_VY": F.END_VY, + "END_VZ": F.END_VZ, + "END_VCHI2DOF": F.CHI2DOF @ F.ENDVERTEX, + "BPVCHI2DOF": F.CHI2DOF @ F.BPV(pvs), + # B2OC generic B hadron NN Hlt2 algorithm, + # not planning to use it directly for B2OC EM + "MVA": F.MVA( + MVAType="SigmaNet", + Config={ + "File": + "paramfile://data/Hlt2B2OC_B_SigmaNet_Run3-v2.json", + "Name": + "B2OC_SigmaNet_Generic", + "Lambda": + "2.0", + "NLayers": + "3", + "InputSize": + "6", + "Monotone_Constraints": + "[1,-1,-1,-1,-1,-1]", + "Variables": + "log_B_PT,B_ETA,log_B_DIRA,log_B_ENDVERTEX_CHI2,log_B_IPCHI2_OWNPV,log_B_IP_OWNPV", + }, + Inputs={ + "log_B_PT": fmath.log(F.PT), + "B_ETA": F.ETA, + "log_B_DIRA": fmath.log(1. +1.e-6 - F.BPVDIRA(pvs)), + "log_B_ENDVERTEX_CHI2": fmath.log(F.CHI2DOF), + "log_B_IPCHI2_OWNPV": fmath.log(F.BPVIPCHI2(pvs)), + "log_B_IP_OWNPV": fmath.log(F.BPVIP(pvs)), + }), + } + ) + B_variables+=FC.HltTisTos(selection_type="Hlt1", trigger_lines=Hlt1_decisions, data=line_data) + B_variables+=FC.FlavourTaggingResults(all_tagging) + + C_variables = FunctorCollection( + { + "ID": F.PARTICLE_ID, + "PT": F.PT, + "ETA": F.ETA, + "P": F.P, + "SUMPT": F.SUM(F.PT), + "MASS": F.MASS, + "DOCA12": F.DOCA(1, 2), + "DOCA13": F.DOCA(1, 3), + "DOCA23": F.DOCA(2, 3), + "BPVDIRA": F.BPVDIRA(pvs), + "CHI2DOF": F.CHI2DOF, + "BPVIP": F.BPVIP(pvs), + "BPVIPCHI2": F.BPVIPCHI2(pvs), + "BPVFD": F.BPVFD(pvs), + "BPVFDCHI2": F.BPVFDCHI2(pvs), + "MINIPCHI2": F.MINIPCHI2(pvs), + "PX": F.PX, + "PY": F.PY, + "PZ": F.PZ, + "BPVX": F.BPVX(pvs), + "BPVY": F.BPVY(pvs), + "BPVZ": F.BPVZ(pvs), + "END_VX": F.END_VX, + "END_VY": F.END_VY, + "END_VZ": F.END_VZ, + "END_VCHI2DOF": F.CHI2DOF @ F.ENDVERTEX, + } + ) + + fs_variables = FunctorCollection( + { + "ID": F.PARTICLE_ID, + "PT": F.PT, + "ETA": F.ETA, + "PHI": F.PHI, + "P": F.P, + "MASS": F.MASS, + "CHI2DOF": F.CHI2DOF, + "MINIPCHI2": F.MINIPCHI2(pvs), + "BPVIPCHI2": F.BPVIPCHI2(pvs), + "PX": F.PX, + "PY": F.PY, + "PZ": F.PZ, + "hasRICH": F.PPHASRICH() @ F.PROTOPARTICLE(), + "PIDK": F.PID_K, + "PIDp": F.PID_P, + "PIDe": F.PID_E, + "PIDmu": F.PID_MU, + "isMuon": F.ISMUON, + "TRACK_GhostProb": F.GHOSTPROB, + "ProbNNp": F.PROBNN_P, + "NHITS": F.VALUE_OR(-1) @ F.NHITS @ F.TRACK, + "NVPHITS": F.VALUE_OR(-1) @ F.NVPHITS @ F.TRACK, # VeloPixel hits + "NUTHITS": F.VALUE_OR(-1) @ F.NUTHITS @ F.TRACK, # UpstreamTracker hits + "NFTHITS": F.VALUE_OR(-1) @ F.NFTHITS @ F.TRACK, # ForwardTracker hits + "TRACKHASVELO": F.VALUE_OR(-1) @ F.TRACKHASVELO @ F.TRACK, + } + ) + + variables = { + "lab0": B_variables, + "lab1": fs_variables, + "lab2": C_variables, + "lab3": fs_variables, + "lab4": fs_variables, + "lab5": fs_variables, + } + + if options.simulation: + mctruth = MCTruthAndBkgCat(line_data, name="MCTruthAndBkgCat") + trueid_bkgcat_info = { + "TRUEID": F.VALUE_OR(0) @ mctruth(F.PARTICLE_ID), + "TRUEKEY": F.VALUE_OR(-1) @ mctruth(F.OBJECT_KEY), + "TRUEPT": mctruth(F.PT), + "TRUEPX": mctruth(F.PX), + "TRUEPY": mctruth(F.PY), + "TRUEPZ": mctruth(F.PZ), + "TRUEENERGY": mctruth(F.ENERGY), + "TRUEP": mctruth(F.P), + "TRUEFOURMOMENTUM": mctruth(F.FOURMOMENTUM), + "TRUETAU": mctruth(F.MC_LIFETIME), + "BKGCAT": mctruth.BkgCat, + } + for field in variables.keys(): + variables[field] += FunctorCollection(trueid_bkgcat_info) + + + odin = get_odin() + rec_summary = get_rec_summary() + # define event level variables + evt_variables = FunctorCollection({ + "RUNNUMBER": F.RUNNUMBER(odin), + "EVENTNUMBER": F.EVENTNUMBER(odin), + "nPVs": F.VALUE_OR(-1) @ F.RECSUMMARY_INFO(rec_summary, "nPVs"), + "nLongTracks": F.VALUE_OR(-1) @ F.RECSUMMARY_INFO(rec_summary, "nLongTracks"), + }) + evt_variables+=FC.SelectionInfo(selection_type="Hlt1", trigger_lines=Hlt1_decisions) + evt_variables+=FC.SelectionInfo(selection_type="Hlt2", trigger_lines=Hlt2_decisions) + + # define FunTuple instance + my_tuple = Funtuple( + name="Tuple", + tuple_name="DecayTree", + fields=fields, + variables=variables, + event_variables=evt_variables, + inputs=line_data, + store_multiple_cand_info=True, + ) + + return make_config(options, [my_filter, my_tuple]) + diff --git a/Beauty_XS_Bs2DsPi/hlt1.py b/Beauty_XS_Bs2DsPi/hlt1.py new file mode 100644 index 0000000000..d40c23bc29 --- /dev/null +++ b/Beauty_XS_Bs2DsPi/hlt1.py @@ -0,0 +1,31 @@ +############################################################################### +# (c) Copyright 2023 CERN for the benefit of the LHCb Collaboration # +# # +# This software is distributed under the terms of the GNU General Public # +# Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". # +# # +# In applying this licence, CERN does not waive the privileges and immunities # +# granted to it by virtue of its status as an Intergovernmental Organization # +# or submit itself to any jurisdiction. # +############################################################################### +""" +Configures running HLT1 via Moore. +""" + +from Moore import Options +from Moore.config import allen_control_flow +from RecoConf.hlt1_allen import allen_gaudi_config, get_allen_line_names +from PyConf.application import configure_input, configure + +def alg_config(options: Options): + """ + Configures algorithm running of HLT1 via Moore to be passed to Analysis Productions. + """ + + config = configure_input(options) + with allen_gaudi_config.bind(sequence="hlt1_pp_matching_no_ut_1000KHz"): + line_names = get_allen_line_names() + allen_node = allen_control_flow(options) + config.update(configure(options, allen_node)) + + return config diff --git a/Beauty_XS_Bs2DsPi/hlt2.py b/Beauty_XS_Bs2DsPi/hlt2.py new file mode 100644 index 0000000000..86070c155c --- /dev/null +++ b/Beauty_XS_Bs2DsPi/hlt2.py @@ -0,0 +1,68 @@ +############################################################################### +# (c) Copyright 2023 CERN for the benefit of the LHCb Collaboration # +# # +# This software is distributed under the terms of the GNU General Public # +# Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". # +# # +# In applying this licence, CERN does not waive the privileges and immunities # +# granted to it by virtue of its status as an Intergovernmental Organization # +# or submit itself to any jurisdiction. # +############################################################################### +""" +Configures running HLT2 via Moore. +""" + +from Moore import options, Options, run_moore +from Hlt2Conf.lines.b_to_open_charm import all_lines +# +from RecoConf.global_tools import stateProvider_with_simplified_geom, trackMasterExtrapolator_with_simplified_geom +from RecoConf.reconstruction_objects import reconstruction +from RecoConf.hlt2_global_reco import reconstruction as hlt2_reconstruction, make_light_reco_pr_kf_without_UT +from RecoConf.hlt2_tracking import ( + make_TrackBestTrackCreator_tracks, + make_PrKalmanFilter_noUT_tracks, + make_PrKalmanFilter_Velo_tracks, + make_PrKalmanFilter_Seed_tracks, +) +from RecoConf.decoders import default_VeloCluster_source +from RecoConf.event_filters import require_gec +from Hlt2Conf.settings.defaults import get_default_hlt1_filter_code_for_hlt2 +import sys + +all_lines = {} +from Hlt2Conf.lines.b_to_open_charm.hlt2_b2oc import make_hlt2_lines +default_lines = [ + 'BdToDsmPi_DsmToKpKmPim', +] +extra_config = { + 'flavour_tagging': [ + 'BdToDsmPi_DsmToKpKmPim', + ] +} +make_hlt2_lines( + line_dict=all_lines, + all_lines=default_lines, + extra_config=extra_config) + +def make_lines(): + lines = [builder() for builder in all_lines.values()] + return lines + +def alg_config(options: Options): + + public_tools = [ + trackMasterExtrapolator_with_simplified_geom(), + stateProvider_with_simplified_geom() + ] + + # require_gec.bind(skipUT=True),\ # B2OC lines do not have require_gec() + with reconstruction.bind(from_file=False),\ + hlt2_reconstruction.bind(make_reconstruction=make_light_reco_pr_kf_without_UT),\ + default_VeloCluster_source.bind(bank_type="VPRetinaCluster"),\ + make_TrackBestTrackCreator_tracks.bind(max_ghost_prob=0.7, max_chi2ndof=sys.float_info.max),\ + make_PrKalmanFilter_Velo_tracks.bind(max_chi2ndof=5.),\ + make_PrKalmanFilter_noUT_tracks.bind(max_chi2ndof=4.),\ + make_PrKalmanFilter_Seed_tracks.bind(max_chi2ndof=6.): + config = run_moore(options, make_lines, public_tools) + + return config diff --git a/Beauty_XS_Bs2DsPi/info.yaml b/Beauty_XS_Bs2DsPi/info.yaml new file mode 100644 index 0000000000..b903958273 --- /dev/null +++ b/Beauty_XS_Bs2DsPi/info.yaml @@ -0,0 +1,79 @@ + +defaults: + wg: B2OC + automatically_configure: no + inform: + - alessandro.bertolin@pd.infn.it + +{%- set mc_datasets = [ +('13264021', 'Down', 'sim10-2024.Q1.2-v1.0-md100', 'dddb-20240427'), +('13264021', 'Up', 'sim10-2024.Q1.2-v1.0-mu100', 'dddb-20240427'), +]%} + +{%- for evttype, polarity, conddb, dddb in mc_datasets %} + +MC_Bs2DsPi_{{ polarity }}_Nu4d3_hlt1: + application: Moore/v55r9@x86_64_v2-el9-gcc13+detdesc-opt + input: + bk_query: "/MC/Dev/Beam6800GeV-2024.Q1.2-Mag{{ polarity }}-VeloDrift-Nu4.3-25ns-Pythia8/Sim10d/{{ evttype }}/DIGI" + dq_flags: + - OK + n_test_lfns: 1 + options: + entrypoint: Beauty_XS_Bs2DsPi.hlt1:alg_config + extra_options: + input_raw_format: 0.5 + conddb_tag: {{ conddb }} + dddb_tag: {{ dddb }} + input_type: "ROOT" + output_type: "ROOT" + simulation: True + data_type: "Upgrade" + scheduler_legacy_mode: False + compression: + algorithm: ZSTD + level: 1 + max_buffer_size: 1048576 + output: hlt1.dst + +MC_Bs2DsPi_{{ polarity }}_Nu4d3_hlt2: + application: Moore/v55r9@x86_64_v2-el9-gcc13+detdesc-opt + input: + job_name: MC_Bs2DsPi_{{ polarity }}_Nu4d3_hlt1 + options: + entrypoint: Beauty_XS_Bs2DsPi.hlt2:alg_config + extra_options: + input_raw_format: 0.5 + persistreco_version: 0.0 + conddb_tag: {{ conddb }} + dddb_tag: {{ dddb }} + input_type: "ROOT" + output_type: "ROOT" + simulation: True + data_type: "Upgrade" + output_manifest_file: hlt2_{{ evttype }}_{{ polarity }}.tck.json + scheduler_legacy_mode: False + compression: + algorithm: ZSTD + level: 1 + max_buffer_size: 1048576 + output: hlt2.dst + +MC_Bs2DsPi_{{ polarity }}_Nu4d3_DV: + application: DaVinci/v64r6@x86_64_v2-el9-gcc13+detdesc-opt + input: + job_name: MC_Bs2DsPi_{{ polarity }}_Nu4d3_hlt2 + output: dv_{{ polarity }}.root + options: + entrypoint: Beauty_XS_Bs2DsPi.dv_simple:alg_config + extra_options: + input_raw_format: 0.5 + input_type: "ROOT" + simulation: True + data_type: "Upgrade" + conddb_tag: {{ conddb }} + dddb_tag: {{ dddb }} + input_process: "Hlt2" + +{%- endfor %} + -- GitLab From f86a1b4e43d63004899cf1c6d2b84901f700fdb3 Mon Sep 17 00:00:00 2001 From: Qucheng Qian <qucheng.qian@cern.ch> Date: Mon, 24 Jun 2024 16:12:37 +0200 Subject: [PATCH 07/15] Qqian/di jpsi --- run3_diJpsi/dv_data.py | 18 ++ run3_diJpsi/info.yaml | 40 +++++ run3_diJpsi/make_dtf.py | 266 +++++++++++++++++++++++++++ run3_diJpsi/tupling_maker.py | 340 +++++++++++++++++++++++++++++++++++ 4 files changed, 664 insertions(+) create mode 100644 run3_diJpsi/dv_data.py create mode 100644 run3_diJpsi/info.yaml create mode 100644 run3_diJpsi/make_dtf.py create mode 100644 run3_diJpsi/tupling_maker.py diff --git a/run3_diJpsi/dv_data.py b/run3_diJpsi/dv_data.py new file mode 100644 index 0000000000..6415ddaa91 --- /dev/null +++ b/run3_diJpsi/dv_data.py @@ -0,0 +1,18 @@ +from .tupling_maker import template, line_prefilter +from DaVinci import Options, make_config + +def DoubleDiMuon_Jpsi_Jpsi(options: Options): + decay_descriptor = { + "X" : "chi_b2(1P) -> (J/psi(1S) -> mu+ mu-) (J/psi(1S) -> mu+ mu-)", + "Jpsi1" : "chi_b2(1P) -> ^(J/psi(1S) -> mu+ mu-) (J/psi(1S) -> mu+ mu-)", + "Jpsi2" : "chi_b2(1P) -> (J/psi(1S) -> mu+ mu-) ^(J/psi(1S) -> mu+ mu-)", + "mup1" : "chi_b2(1P) -> (J/psi(1S) -> ^mu+ mu-) (J/psi(1S) -> mu+ mu-)", + "mum1" : "chi_b2(1P) -> (J/psi(1S) -> mu+ ^mu-) (J/psi(1S) -> mu+ mu-)", + "mup2" : "chi_b2(1P) -> (J/psi(1S) -> mu+ mu-) (J/psi(1S) -> ^mu+ mu-)", + "mum2" : "chi_b2(1P) -> (J/psi(1S) -> mu+ mu-) (J/psi(1S) -> mu+ ^mu-)", + } + line_name = 'Hlt2BandQ_DoubleDiMuon_Jpsi_Jpsi_DPS' + my_tuple = template(decay_descriptor, line_name, True, [], ["X", "Jpsi1","Jpsi2"], ["mup1", "mum1", "mup2","mum2"]) + my_filter = line_prefilter(line_name) + return make_config(options, [my_filter, my_tuple]) + diff --git a/run3_diJpsi/info.yaml b/run3_diJpsi/info.yaml new file mode 100644 index 0000000000..55f70955d1 --- /dev/null +++ b/run3_diJpsi/info.yaml @@ -0,0 +1,40 @@ +defaults: + application: DaVinci/v64r6 + wg: BandQ + inform: + -qucheng.qian@cern.ch + +# data configuration +{%- set datasets = [ + ('Collision24', 'Sprucing24c1/94000000', 'BANDQ', 'DoubleDiMuon_Jpsi_Jpsi', 'MagDown', 'VeloClosed', 'TurboPass', 'bandq'), + ('Collision24', 'Sprucing24c1/94000000', 'BANDQ', 'DoubleDiMuon_Jpsi_Jpsi', 'MagUp', 'VeloClosed', 'TurboPass', 'bandq'), +]%} + + +{%- set dv_platform_detdesc = "x86_64_v2-el9-gcc13+detdesc-opt" %} + +{%- for data, Type, wg, decay, polarity, Velo, process, stream in datasets %} + +data_{{decay}}_{{wg}}_{{process}}_{{data}}_{{Velo}}_{{polarity}}: + application: "DaVinci/v64r6" + input: + bk_query: "/LHCb/{{data}}/Beam6800GeV-{{Velo}}-{{polarity}}-Excl-UT/Real Data/{{Type}}/{{wg}}.DST" + dq_flags: + - OK + - UNCHECKED + keep_running: True + n_test_lfns: 1 + options: + entrypoint: run3_diJpsi.dv_data:{{decay}} + extra_options: + input_type: ROOT + input_process: "{{process}}" + input_stream: "{{stream}}" + input_raw_format: 0.5 + simulation: False + data_type: "Upgrade" + geometry_version: run3/2024.Q1.2-v00.00 + conditions_version: master + output: Data_{{process}}_{{stream}}_{{decay}}.ROOT +{%- endfor %} + diff --git a/run3_diJpsi/make_dtf.py b/run3_diJpsi/make_dtf.py new file mode 100644 index 0000000000..feb219bfa5 --- /dev/null +++ b/run3_diJpsi/make_dtf.py @@ -0,0 +1,266 @@ +import Functors as F +from Functors.math import log + +from FunTuple import FunctorCollection +from FunTuple.functorcollections import ( + MCHierarchy, + MCPromptDecay, + Kinematics, + SelectionInfo, + HltTisTos, + MCVertexInfo, + MCKinematics, + ParticleID, #wrong variables PID_PI = 0, PROBNN_D = nan + EventInfo, + LHCInfo, + ParticleIsolation, + MCPrimaries, + MCReconstructed, + MCReconstructible, +) + +from DaVinciMCTools import MCTruthAndBkgCat, MCReconstructed, MCReconstructible +from PyConf.Algorithms import ParticleToSubcombinationsAlg +from DecayTreeFitter import DecayTreeFitter + +from DaVinci.algorithms import create_lines_filter +from PyConf.reading import get_particles +from FunTuple import FunTuple_Particles as Funtuple + + + +def make_basic_dtf_variables(pvs, data, DTF=None, pv_constraint=False, mass_constraint=False, particle_name=""): + variables = ( + FunctorCollection( + { + "TRCHI2DOF": F.CHI2DOF @ F.TRACK, + "ETA": F.ETA, + "PHI": F.PHI, + "TRGHOSTPROB": F.GHOSTPROB, + "BPVIPCHI2": F.BPVIPCHI2(pvs), + "BPVIP": F.BPVIP(pvs), + "BPVX": F.BPVX(pvs), + "BPVY": F.BPVY(pvs), + "BPVZ": F.BPVZ(pvs), + "TX" : F.TX, + "TY" : F.TY, + # "MINIPCHI2" : F.MINIPCHI2(pvs), + # "MINIP" : F.MINIP(pvs), + "KEY" : F.VALUE_OR(-1) @ F.OBJECT_KEY @ F.TRACK, + "CTB" : F.POSITION @ F.CLOSESTTOBEAM @ F.TRACK, + "TRACKPT": F.TRACK_PT, + "TRACKHISTORY": F.VALUE_OR(-1) @ F.TRACKHISTORY @ F.TRACK, + "QOVERP": F.QOVERP @ F.TRACK, + "NDOF": F.VALUE_OR(-1) @ F.NDOF @ F.TRACK, + } + ) + + Kinematics() + ) + + if(mass_constraint): + if(pv_constraint): # MASS + PV + dtf_variables_mass_pv = FunctorCollection({ + 'DTF_PV_M'+ particle_name + '_' + k: DTF(v) + for k, v in variables.get_thor_functors().items() + }) + return dtf_variables_mass_pv + else: # MASS + dtf_variables_mass = FunctorCollection( + {'DTF_M'+ particle_name + '_' + k: DTF(v) + for k, v in variables.get_thor_functors().items()}) + return dtf_variables_mass + + elif(pv_constraint): # PV + dtf_variables_pv = FunctorCollection({ + 'DTF_PV_' + k: DTF(v) + for k, v in variables.get_thor_functors().items() + }) + return dtf_variables_pv + + else: # NO MASS/PV + dtf_variables = FunctorCollection( + {'DTF_' + k: DTF(v) + for k, v in variables.get_thor_functors().items()}) + return dtf_variables + + +def make_composite_dtf_variables(pvs, data, DTF=None, pv_constraint=False, mass_constraint=False, particle_name=""): + variables = ( + FunctorCollection( + { + # "MAXPT": F.MAX(F.PT), + # "MINPT": F.MIN(F.PT), + # "SUMPT": F.SUM(F.PT), + # "MAXP": F.MAX(F.P), + # "MINP": F.MIN(F.P), + "BPVDIRA": F.BPVDIRA(pvs), + "VCHI2DOF": F.CHI2DOF, #CHI2VXNDOF + "BPVFDCHI2": F.BPVFDCHI2(pvs), + "BPVFD": F.BPVFD(pvs), + "BPVVDRHO": F.BPVVDRHO(pvs), + "BPVVDZ": F.BPVVDZ(pvs), + "BPVIPCHI2": F.BPVIPCHI2(pvs), + "BPVIP": F.BPVIP(pvs), + # "LOGBPVIPCHI2": log(F.BPVIPCHI2(pvs)), + "BPVLTIME": F.BPVLTIME(pvs), + # "MAXBPVIPCHI2": F.MAX(F.BPVIPCHI2(pvs)), #MAX_ + # "MINBPVIPCHI2": F.MIN(F.BPVIPCHI2(pvs)), + # "MAXBPVIP": F.MAX(F.BPVIP(pvs)), + # "MINBPVIP": F.MIN(F.BPVIP(pvs)), + "ETA": F.ETA, + "PHI": F.PHI, + "END_VX": F.END_VX, #END_ + "END_VY": F.END_VY, + "END_VZ": F.END_VZ, + "BPVX": F.BPVX(pvs), + "BPVY": F.BPVY(pvs), + "BPVZ": F.BPVZ(pvs), + "ALLPVFD" : F.ALLPV_FD(pvs), + "ALLPVIP" : F.ALLPV_IP(pvs), + + } + ) + + Kinematics() + ) + + addstring = "DTF" + if(pv_constraint): + addstring += '_PV' + if(mass_constraint): + addstring += '_M' + addstring += particle_name + + DTF_chi2ndof = FunctorCollection( + { + addstring+"_DTFCHI2": DTF.CHI2, + addstring+"_DTFNDOF": DTF.NDOF, + addstring+"_CTAU": DTF.CTAU, + addstring+"_CTAUERR": DTF.CTAUERR, + addstring+"_MERR": DTF.MASSERR, + } + ) + + if(mass_constraint): + if(pv_constraint): # MASS + PV + dtf_variables_mass_pv = FunctorCollection({ + 'DTF_PV_M'+ particle_name + '_' + k: DTF(v) + for k, v in variables.get_thor_functors().items() + }) + return dtf_variables_mass_pv+DTF_chi2ndof + else: # MASS + dtf_variables_mass = FunctorCollection( + {'DTF_M'+ particle_name + '_' + k: DTF(v) + for k, v in variables.get_thor_functors().items()}) + return dtf_variables_mass+DTF_chi2ndof + + elif(pv_constraint): # PV + dtf_variables_pv = FunctorCollection({ + 'DTF_PV_' + k: DTF(v) + for k, v in variables.get_thor_functors().items() + }) + return dtf_variables_pv+DTF_chi2ndof + + else: # NO MASS/PV + dtf_variables = FunctorCollection( + {'DTF_' + k: DTF(v) + for k, v in variables.get_thor_functors().items()}) + return dtf_variables+DTF_chi2ndof + + + +def make_dtf_variables(pvs, input_data, ptype): + + if ptype not in ["basic", "composite"]: + Exception(f"Need \'basic\' or \'composite\'. Got {ptype}") + + from DecayTreeFitter import DecayTreeFitter + + DTF = DecayTreeFitter( + name=f'DTF_{{hash}}', + input_particles=input_data) + + DTFvtx = DecayTreeFitter( + name=f'DTFvtx_{{hash}}', + input_particles=input_data, + input_pvs=pvs) + + DTFmassJpsi = DecayTreeFitter( + name=f'DTFmassJpsi_{{hash}}', + input_particles=input_data, + mass_constraints=["J/psi(1S)"]) + + DTFvtxmassJpsi = DecayTreeFitter( + name=f'DTFvtxmassJpsi_{{hash}}', + input_particles=input_data, + input_pvs=pvs, + mass_constraints=["J/psi(1S)"]) + + # DTFmassBcJpsi = DecayTreeFitter( + # name=f'DTFmassBcJpsi_{{hash}}', + # input_particles=input_data, + # mass_constraints=["B_c+","J/psi(1S)"]) + + # DTFvtxmassBcJpsi = DecayTreeFitter( + # name=f'DTFvtxmassBcJpsi_{{hash}}', + # input_particles=input_data, + # input_pvs=pvs, + # mass_constraints=["B_c+","J/psi(1S)"]) + + + if ptype == "basic": + dtf_vars = make_basic_dtf_variables(pvs, input_data, + DTF=DTF, + pv_constraint=False, + mass_constraint=False) + dtf_vars += make_basic_dtf_variables(pvs, input_data, + DTF=DTFvtx, + pv_constraint=True, + mass_constraint=False) + dtf_vars += make_basic_dtf_variables(pvs, input_data, + DTF=DTFmassJpsi, + pv_constraint=False, + mass_constraint=True, particle_name="Jpsi") + dtf_vars += make_basic_dtf_variables(pvs, input_data, + DTF=DTFvtxmassJpsi, + pv_constraint=True, + mass_constraint=True, particle_name="Jpsi") + # dtf_vars += make_basic_dtf_variables(pvs, input_data, + # DTF=DTFmassBcJpsi, + # pv_constraint=False, + # mass_constraint=True, particle_name="BcJpsi") + # dtf_vars += make_basic_dtf_variables(pvs, input_data, + # DTF=DTFvtxmassBcJpsi, + # pv_constraint=True, + # mass_constraint=True, particle_name="BcJpsi") + + return dtf_vars + + if ptype == "composite": + dtf_vars = make_composite_dtf_variables(pvs, input_data, + DTF=DTF, + pv_constraint=False, + mass_constraint=False) + dtf_vars += make_composite_dtf_variables(pvs, input_data, + DTF=DTFvtx, + pv_constraint=True, + mass_constraint=False) + dtf_vars += make_composite_dtf_variables(pvs, input_data, + DTF=DTFmassJpsi, + pv_constraint=False, + mass_constraint=True, particle_name="Jpsi") + dtf_vars += make_composite_dtf_variables(pvs, input_data, + DTF=DTFvtxmassJpsi, + pv_constraint=True, + mass_constraint=True, particle_name="Jpsi") + # dtf_vars += make_composite_dtf_variables(pvs, input_data, + # DTF=DTFmassBcJpsi, + # pv_constraint=False, + # mass_constraint=True, particle_name="BcJpsi") + # dtf_vars += make_composite_dtf_variables(pvs, input_data, + # DTF=DTFvtxmassBcJpsi, + # pv_constraint=True, + # mass_constraint=True, particle_name="BcJpsi") + + return dtf_vars + + diff --git a/run3_diJpsi/tupling_maker.py b/run3_diJpsi/tupling_maker.py new file mode 100644 index 0000000000..c9a6d7a5f8 --- /dev/null +++ b/run3_diJpsi/tupling_maker.py @@ -0,0 +1,340 @@ +############################################################################### +# (c) Copyright 2021-2022 CERN for the benefit of the LHCb Collaboration # +# # +# This software is distributed under the terms of the GNU General Public # +# Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". # +# # +# In applying this licence, CERN does not waive the privileges and immunities # +# granted to it by virtue of its status as an Intergovernmental Organization # +# or submit itself to any jurisdiction. # +############################################################################### +""" +Read an HLT2 file and create an ntuple with the new DaVinci configuration. +""" +import Functors as F +import FunTuple.functorcollections as FC +from FunTuple import FunctorCollection +from FunTuple import FunTuple_Particles as Funtuple +from PyConf.reading import get_particles, get_pvs, get_rec_summary +from DaVinci.algorithms import create_lines_filter +from DaVinciMCTools import MCTruthAndBkgCat +from FunTuple.functorcollections import MCHierarchy, MCPrimaries, MCPromptDecay, Kinematics, SelectionInfo, HltTisTos, MCVertexInfo, MCKinematics, ParticleID, EventInfo +from PyConf.reading import get_odin # get_decreports, +from DecayTreeFitter import DecayTreeFitter + +from .make_dtf import * + +_basic = "basic" +_composite = "composite" +_toplevel = "toplevel" + +def all_variables(pvs, mctruth, ptype, candidates=None, ftAlg=None): + """ + function that returns dictionary of functors that work. + + functors are listed in order of https://lhcbdoc.web.cern.ch/lhcbdoc/moore/master/selection/thor_functors_reference.html#module-Functo + """ + if ptype not in [_basic, _composite]: + Exception(f"I want {_basic} or {_composite}. Got {ptype}") + all_vars = FunctorCollection({}) + + comp = _composite == ptype or _toplevel == ptype # is composite + basic = _basic == ptype # is not composite + top = _toplevel == ptype # the B + + # First import everything that comes in functorcollections + all_vars += FC.Kinematics() + if basic: + all_vars += FC.ParticleID(extra_info=True) + + if comp: + all_vars.update({"ALV": F.ALV(Child1=1, Child2=2)}) + + if comp: # all these require a vertex + all_vars.update({"BPVCORRM": F.BPVCORRM(pvs)}) + all_vars.update({"BPVCORRMERR": F.BPVCORRMERR(pvs)}) + all_vars.update({"BPVDIRA": F.BPVDIRA(pvs)}) + all_vars.update({"BPVDLS": F.BPVDLS(pvs)}) + all_vars.update({"BPVETA": F.BPVETA(pvs)}) + all_vars.update({"BPVFD": F.BPVFD(pvs)}) + all_vars.update({"BPVFDCHI2": F.BPVFDCHI2(pvs)}) + all_vars.update({"BPVFDIR": F.BPVFDIR(pvs)}) + all_vars.update({"BPVFDVEC": F.BPVFDVEC(pvs)}) + + all_vars.update({"BPVIP": F.BPVIP(pvs)}) + all_vars.update({"BPVIPCHI2": F.BPVIPCHI2(pvs)}) + all_vars.update({"BPVX": F.BPVX(pvs)}) + all_vars.update({"BPVY": F.BPVY(pvs)}) + all_vars.update({"BPVZ": F.BPVZ(pvs)}) + + if comp: # all these require a vertex + all_vars.update({"ALLPV_FD": F.ALLPV_FD(pvs)}) + all_vars.update({"ALLPV_IP": F.ALLPV_IP(pvs)}) + all_vars.update({"BPVLTIME": F.BPVLTIME(pvs)}) + all_vars.update({"BPVVDRHO": F.BPVVDRHO(pvs)}) + all_vars.update({"BPVVDX": F.BPVVDX(pvs)}) + all_vars.update({"BPVVDY": F.BPVVDY(pvs)}) + all_vars.update({"BPVVDZ": F.BPVVDZ(pvs)}) + + all_vars.update({"CHARGE": F.CHARGE}) + all_vars.update({"CHI2": F.CHI2}) + all_vars.update({"CHI2DOF": F.CHI2DOF}) + + if top: # apply this only to B + all_vars.update({"CHILD1_PT": F.CHILD(1, F.PT)}) # example of CHILD + all_vars.update({"Ds_END_VZ": F.CHILD(1, F.END_VZ)}) + all_vars.update({"Delta_END_VZ_DsB0": F.CHILD(1, F.END_VZ) - F.END_VZ}) + + if comp: + all_vars.update({"DOCA": F.SDOCA(Child1=1, Child2=2)}) + all_vars.update({"DOCACHI2": F.SDOCACHI2(Child1=1, Child2=2)}) + all_vars.update({"END_VRHO": F.END_VRHO}) + all_vars.update({"END_VX": F.END_VX}) + all_vars.update({"END_VY": F.END_VY}) + all_vars.update({"END_VZ": F.END_VZ}) + + all_vars.update({"ETA": F.ETA}) + all_vars.update({"FOURMOMENTUM": F.FOURMOMENTUM}) + all_vars.update({"ISBASIC": F.ISBASICPARTICLE}) + + if basic: + all_vars.update({"GHOSTPROB": F.GHOSTPROB}) + all_vars.update({"ISMUON": F.ISMUON}) + all_vars.update({"INMUON": F.INMUON}) + all_vars.update({"INECAL": F.INECAL}) + all_vars.update({"INHCAL": F.INHCAL}) + all_vars.update({"HASBREM": F.HASBREM}) + all_vars.update({"BREMENERGY": F.BREMENERGY}) + all_vars.update({"BREMBENDCORR": F.BREMBENDCORR}) + all_vars.update({"BREMPIDE": F.BREMPIDE}) + all_vars.update({"ECALPIDE": F.ECALPIDE}) + all_vars.update({"ECALPIDMU": F.ECALPIDMU}) + all_vars.update({"HCALPIDE": F.HCALPIDE}) + all_vars.update({"HCALPIDMU": F.HCALPIDMU}) + all_vars.update({"ELECTRONSHOWEREOP": F.ELECTRONSHOWEREOP}) + all_vars.update({"CLUSTERMATCH": F.CLUSTERMATCH_CHI2}) + all_vars.update({"ELECTRONMATCH": F.ELECTRONMATCH_CHI2}) + all_vars.update({"BREMHYPOMATCH": F.BREMHYPOMATCH_CHI2}) + all_vars.update({"ELECTRONENERGY": F.ELECTRONENERGY}) + all_vars.update({"BREMHYPOENERGY": F.BREMHYPOENERGY}) + all_vars.update({"BREMHYPODELTAX": F.BREMHYPODELTAX}) + all_vars.update({"ELECTRONID": F.ELECTRONID}) + all_vars.update({"HCALEOP": F.HCALEOP}) + # Note: the observables for the two functors below are (TRACK_MOM_X, TRACK_MOM_Y, TRACK_MOM_Z}) + # and (TRACK_POS_CLOSEST_TO_BEAM_X, TRACK_POS_CLOSEST_TO_BEAM_Y, TRACK_POS_CLOSEST_TO_BEAM_Z), + # which is why the trailing underscore in the name is added i.e. "TRACK_MOM_" and "TRACK_POS_CLOSEST_TO_BEAM_" + all_vars.update({"TRACK_MOM_": F.TRACK_MOMVEC}) + all_vars.update({"TRACK_POS_CLOSESTTOBEAM_": F.TRACK_POSVEC_CLOSESTTOBEAM}) + + all_vars.update({"IS_ABS_ID_pi": F.IS_ABS_ID("pi+")}) + all_vars.update({"IS_ID_pi": F.IS_ID("pi-")}) + all_vars.update({"PDG_MASS_pi": F.PDG_MASS("pi+")}) + all_vars.update({"SIGNED_DELTA_MASS_pi": F.SIGNED_DELTA_MASS("pi+")}) + all_vars.update({"ABS_DELTA_MASS_pi": F.ABS_DELTA_MASS("pi+")}) + all_vars.update({"IS_NOT_H": F.IS_NOT_H}) + all_vars.update({"IS_PHOTON": F.IS_PHOTON}) + + all_vars.update({"MASS": F.MASS}) + + if comp: + all_vars.update({"MAXPT": F.MAX(F.PT)}) + all_vars.update({"MAXDOCA": F.MAXSDOCA}) + all_vars.update({"MAXDOCACHI2": F.MAXSDOCACHI2}) + # the above in cut versions. + + if comp: + all_vars.update({"MINPT": F.MIN(F.PT)}) + all_vars.update({"MINIP": F.MINIP(pvs)}) + all_vars.update({"MINIPCHI2": F.MINIPCHI2(pvs)}) + + if basic: + all_vars.update({"TRACKPT": F.TRACK_PT}) + all_vars.update({"TRACKHISTORY": F.VALUE_OR(-1) @ F.TRACKHISTORY @ F.TRACK}) + all_vars.update({"QOVERP": F.QOVERP @ F.TRACK}) + all_vars.update({"NDOF": F.VALUE_OR(-1) @ F.NDOF @ F.TRACK}) + all_vars.update({"NFTHITS": F.VALUE_OR(-1) @ F.NFTHITS @ F.TRACK}) + all_vars.update({"NHITS": F.VALUE_OR(-1) @ F.NHITS @ F.TRACK}) + all_vars.update({"NUTHITS": F.VALUE_OR(-1) @ F.NUTHITS @ F.TRACK}) + all_vars.update({"NVPHITS": F.VALUE_OR(-1) @ F.NVPHITS @ F.TRACK}) + all_vars.update({"TRACKHASVELO": F.VALUE_OR(-1) @ F.TRACKHASVELO @ F.TRACK}) + all_vars.update({"TRACKHASUT": F.VALUE_OR(-1) @ F.TRACKHASUT @ F.TRACK}) + + all_vars.update({"OBJECT_KEY": F.OBJECT_KEY}) + + all_vars.update({"PHI": F.PHI}) + + all_vars.update({"ABS_PX": F.ABS @ F.PX}) + + all_vars.update({"REFERENCEPOINT_X": F.REFERENCEPOINT_X}) + all_vars.update({"REFERENCEPOINT_Y": F.REFERENCEPOINT_Y}) + all_vars.update({"REFERENCEPOINT_Z": F.REFERENCEPOINT_Z}) + + if comp: + all_vars.update({"SDOCA": F.SDOCA(1, 2)}) + all_vars.update({"SDOCACHI2": F.SDOCACHI2(1, 2)}) + if basic: + all_vars.update({"SHOWER_SHAPE": F.CALO_NEUTRAL_SHOWER_SHAPE}) + + if comp: + all_vars.update({"SUBCOMB12_MM": F.SUBCOMB(Functor=F.MASS, Indices=(1, 2))}) + all_vars.update({"SUMPT": F.SUM(F.PT)}) + + if basic: + all_vars.update({"TX": F.TX}) + all_vars.update({"TY": F.TY}) + + print(f"### For {ptype} returning variables {all_vars.functor_dict.keys()}") + return all_vars + + +def event_variables(PVs, ODIN, decreports, lines): + """ + event variables + """ + + evt_vars = FunctorCollection({}) + evt_vars += FC.EventInfo() + + evt_vars += FC.SelectionInfo(selection_type="Hlt2", trigger_lines=lines) + + if decreports: + evt_vars.update( + { + "DECISIONS": F.DECISIONS( + Lines=[bd2dsk_line + "Decision"], DecReports=decreports + ) + } + ) + evt_vars.update( + { + "DECREPORTS_FILTER": F.DECREPORTS_FILTER( + Lines=[bd2dsk_line + "Decision"], DecReports=decreports + ) + } + ) + + if ODIN: + evt_vars.update({"EVENTTYPE": F.EVENTTYPE(ODIN)}) + + evt_vars.update({"PV_SIZE": F.SIZE(PVs)}) + + if decreports: + evt_vars.update({"TCK": F.TCK(decreports)}) + + print(f"### For event returning variables {evt_vars.functor_dict.keys()}") + return evt_vars + + +def template(decay_descriptor, line_name, isturbo, Hlt2_decisions, composite_particles, daughter_particles): + + evtpath_prefix = "/Event/Spruce/" + if isturbo: + evtpath_prefix = "/Event/HLT2/" + + input_data = get_particles(evtpath_prefix + f"{line_name}/Particles") + + pvs = get_pvs() + + Hlt1_decisions = [ + 'Hlt1TrackMVADecision', 'Hlt1TwoTrackMVADecision', #'Hlt1D2KKDecision', + #'Hlt1D2KPiDecision', 'Hlt1D2PiPiDecision', + 'Hlt1DiMuonHighMassDecision', #'Hlt1DiMuonLowMassDecision', + #'Hlt1DiMuonSoftDecision', + #'Hlt1KsToPiPiDecision', 'Hlt1LowPtMuonDecision', + 'Hlt1LowPtDiMuonDecision', 'Hlt1SingleHighPtMuonDecision', + 'Hlt1TrackMuonMVADecision', "Hlt1DiMuonNoIP_SSDecision", + #"Hlt1DiMuonDrellYan_VLowMassDecision", + #"Hlt1DiMuonDrellYan_VLowMass_SSDecision", + #"Hlt1DiMuonDrellYanDecision", + #"Hlt1DiMuonDrellYan_SSDecision", + #"Hlt1DetJpsiToMuMuPosTagLineDecision", + #"Hlt1DetJpsiToMuMuNegTagLineDecision", + #"Hlt1TrackElectronMVADecision", + #"Hlt1SingleHighPtElectronDecision", + #"Hlt1DiElectronDisplacedDecision", + #"Hlt1SingleHighEtDecision", + #"Hlt1DiPhotonHighMassDecision", + #"Hlt1Pi02GammaGammaDecision", + #"Hlt1DiElectronHighMass_SSDecision", + #"Hlt1DiElectronHighMassDecision", + "Hlt1DiMuonNoIPDecision", + ] + + composite_variables = FunctorCollection({ + "END_VX_ERR":F.SQRT @ F.CALL(0,0) @ F.POS_COV_MATRIX @ F.ENDVERTEX, + "END_VY_ERR":F.SQRT @ F.CALL(1,1) @ F.POS_COV_MATRIX @ F.ENDVERTEX, + "END_VZ_ERR":F.SQRT @ F.CALL(2,2) @ F.POS_COV_MATRIX @ F.ENDVERTEX, + "BPVX_ERR": F.SQRT @ F.CALL(0,0) @ F.POS_COV_MATRIX @ F.BPV(pvs), + "BPVY_ERR": F.SQRT @ F.CALL(1,1) @ F.POS_COV_MATRIX @ F.BPV(pvs), + "BPVZ_ERR": F.SQRT @ F.CALL(2,2) @ F.POS_COV_MATRIX @ F.BPV(pvs), + "PERR": F.SQRT @ F.PERR2, + "PXERR": F.SQRT @ F.CALL(0,0) @ F.THREE_MOM_COV_MATRIX, + "PYERR": F.SQRT @ F.CALL(1,1) @ F.THREE_MOM_COV_MATRIX, + "PZERR": F.SQRT @ F.CALL(2,2) @ F.THREE_MOM_COV_MATRIX, + }) + + composite_variables += HltTisTos( selection_type="Hlt1", trigger_lines=Hlt1_decisions, data=input_data) + if not isturbo: + composite_variables += HltTisTos( selection_type="Hlt2", trigger_lines=Hlt2_decisions, data=input_data) + + daughter_variables = FunctorCollection({ + "PERR": F.SQRT @ F.PERR2, + "PZERR": F.SQRT @ F.CALL(2,2) @ F.THREE_MOM_COV_MATRIX, + }) + + #define event level variables + odin = get_odin() + decreports = None + rec_sum=get_rec_summary() + event_info = event_variables(pvs, odin, decreports, [line_name]) + FunctorCollection({ + "nPVs": F.VALUE_OR(-1) @F.RECSUMMARY_INFO(rec_sum,"nPVs"), + "nTTracks": F.VALUE_OR(-1) @F.RECSUMMARY_INFO(rec_sum,"nTTracks"), + "nLongTracks": F.VALUE_OR(-1) @F.RECSUMMARY_INFO(rec_sum,"nLongTracks"), + "nDownstreamTracks": F.VALUE_OR(-1) @F.RECSUMMARY_INFO(rec_sum,"nDownstreamTracks"), + "nUpstreamTracks": F.VALUE_OR(-1) @F.RECSUMMARY_INFO(rec_sum,"nUpstreamTracks"), + "nVeloTracks": F.VALUE_OR(-1) @F.RECSUMMARY_INFO(rec_sum,"nVeloTracks"), + "nBackTracks": F.VALUE_OR(-1) @F.RECSUMMARY_INFO(rec_sum,"nBackTracks"), + "nRich1Hits": F.VALUE_OR(-1) @F.RECSUMMARY_INFO(rec_sum,"nRich1Hits"), + "nRich2Hits": F.VALUE_OR(-1) @F.RECSUMMARY_INFO(rec_sum,"nRich2Hits"), + "nVPClusters": F.VALUE_OR(-1) @F.RECSUMMARY_INFO(rec_sum,"nVPClusters"), + "nFTClusters": F.VALUE_OR(-1) @F.RECSUMMARY_INFO(rec_sum,"nFTClusters"), + "eCalTot": F.VALUE_OR(-1) @F.RECSUMMARY_INFO(rec_sum,"eCalTot"), + "hCalTot": F.VALUE_OR(-1) @F.RECSUMMARY_INFO(rec_sum,"hCalTot"), + "nEcalClusters": F.VALUE_OR(-1) @F.RECSUMMARY_INFO(rec_sum,"nEcalClusters"), + "ALLPVX": F.ALLPVX(pvs), + "ALLPVY": F.ALLPVY(pvs), + "ALLPVZ": F.ALLPVZ(pvs), + }) + + event_info += FC.SelectionInfo( + selection_type="Hlt1", trigger_lines=Hlt1_decisions + ) + + variables = {} + + for composite_particle in composite_particles: + variables[composite_particle] = composite_variables + all_variables(pvs, None, _composite)+make_dtf_variables(pvs, input_data, _composite) + for daughter_particle in daughter_particles: + variables[daughter_particle] = daughter_variables + all_variables(pvs, None, _basic)+make_dtf_variables(pvs, input_data, _basic) + +# variables = { +# "QQbar": composite_variables + all_variables(pvs, None, _composite), +# "mup": daughter_variables + all_variables(pvs, None, _basic), +# "mum": daughter_variables + all_variables(pvs, None, _basic), +# } + + #define FunTuple instance + my_tuple = Funtuple( + name=line_name, + tuple_name="DecayTree", + fields=decay_descriptor, + variables=variables, + event_variables=event_info, + store_multiple_cand_info = True, + inputs=input_data) + + return my_tuple + +def line_prefilter(line_name): + return create_lines_filter(name=f"PreFilter_{line_name}", lines=[line_name]) + -- GitLab From d43ca3a631c059384a18bedeac2dff204ea6e5f7 Mon Sep 17 00:00:00 2001 From: LHCb Data Processing and Analysis <lhcb.dpa@cern.ch> Date: Mon, 24 Jun 2024 16:12:54 +0200 Subject: [PATCH 08/15] Revert "Qqian/di jpsi" This reverts merge request !1431 --- run3_diJpsi/dv_data.py | 18 -- run3_diJpsi/info.yaml | 40 ----- run3_diJpsi/make_dtf.py | 266 --------------------------- run3_diJpsi/tupling_maker.py | 340 ----------------------------------- 4 files changed, 664 deletions(-) delete mode 100644 run3_diJpsi/dv_data.py delete mode 100644 run3_diJpsi/info.yaml delete mode 100644 run3_diJpsi/make_dtf.py delete mode 100644 run3_diJpsi/tupling_maker.py diff --git a/run3_diJpsi/dv_data.py b/run3_diJpsi/dv_data.py deleted file mode 100644 index 6415ddaa91..0000000000 --- a/run3_diJpsi/dv_data.py +++ /dev/null @@ -1,18 +0,0 @@ -from .tupling_maker import template, line_prefilter -from DaVinci import Options, make_config - -def DoubleDiMuon_Jpsi_Jpsi(options: Options): - decay_descriptor = { - "X" : "chi_b2(1P) -> (J/psi(1S) -> mu+ mu-) (J/psi(1S) -> mu+ mu-)", - "Jpsi1" : "chi_b2(1P) -> ^(J/psi(1S) -> mu+ mu-) (J/psi(1S) -> mu+ mu-)", - "Jpsi2" : "chi_b2(1P) -> (J/psi(1S) -> mu+ mu-) ^(J/psi(1S) -> mu+ mu-)", - "mup1" : "chi_b2(1P) -> (J/psi(1S) -> ^mu+ mu-) (J/psi(1S) -> mu+ mu-)", - "mum1" : "chi_b2(1P) -> (J/psi(1S) -> mu+ ^mu-) (J/psi(1S) -> mu+ mu-)", - "mup2" : "chi_b2(1P) -> (J/psi(1S) -> mu+ mu-) (J/psi(1S) -> ^mu+ mu-)", - "mum2" : "chi_b2(1P) -> (J/psi(1S) -> mu+ mu-) (J/psi(1S) -> mu+ ^mu-)", - } - line_name = 'Hlt2BandQ_DoubleDiMuon_Jpsi_Jpsi_DPS' - my_tuple = template(decay_descriptor, line_name, True, [], ["X", "Jpsi1","Jpsi2"], ["mup1", "mum1", "mup2","mum2"]) - my_filter = line_prefilter(line_name) - return make_config(options, [my_filter, my_tuple]) - diff --git a/run3_diJpsi/info.yaml b/run3_diJpsi/info.yaml deleted file mode 100644 index 55f70955d1..0000000000 --- a/run3_diJpsi/info.yaml +++ /dev/null @@ -1,40 +0,0 @@ -defaults: - application: DaVinci/v64r6 - wg: BandQ - inform: - -qucheng.qian@cern.ch - -# data configuration -{%- set datasets = [ - ('Collision24', 'Sprucing24c1/94000000', 'BANDQ', 'DoubleDiMuon_Jpsi_Jpsi', 'MagDown', 'VeloClosed', 'TurboPass', 'bandq'), - ('Collision24', 'Sprucing24c1/94000000', 'BANDQ', 'DoubleDiMuon_Jpsi_Jpsi', 'MagUp', 'VeloClosed', 'TurboPass', 'bandq'), -]%} - - -{%- set dv_platform_detdesc = "x86_64_v2-el9-gcc13+detdesc-opt" %} - -{%- for data, Type, wg, decay, polarity, Velo, process, stream in datasets %} - -data_{{decay}}_{{wg}}_{{process}}_{{data}}_{{Velo}}_{{polarity}}: - application: "DaVinci/v64r6" - input: - bk_query: "/LHCb/{{data}}/Beam6800GeV-{{Velo}}-{{polarity}}-Excl-UT/Real Data/{{Type}}/{{wg}}.DST" - dq_flags: - - OK - - UNCHECKED - keep_running: True - n_test_lfns: 1 - options: - entrypoint: run3_diJpsi.dv_data:{{decay}} - extra_options: - input_type: ROOT - input_process: "{{process}}" - input_stream: "{{stream}}" - input_raw_format: 0.5 - simulation: False - data_type: "Upgrade" - geometry_version: run3/2024.Q1.2-v00.00 - conditions_version: master - output: Data_{{process}}_{{stream}}_{{decay}}.ROOT -{%- endfor %} - diff --git a/run3_diJpsi/make_dtf.py b/run3_diJpsi/make_dtf.py deleted file mode 100644 index feb219bfa5..0000000000 --- a/run3_diJpsi/make_dtf.py +++ /dev/null @@ -1,266 +0,0 @@ -import Functors as F -from Functors.math import log - -from FunTuple import FunctorCollection -from FunTuple.functorcollections import ( - MCHierarchy, - MCPromptDecay, - Kinematics, - SelectionInfo, - HltTisTos, - MCVertexInfo, - MCKinematics, - ParticleID, #wrong variables PID_PI = 0, PROBNN_D = nan - EventInfo, - LHCInfo, - ParticleIsolation, - MCPrimaries, - MCReconstructed, - MCReconstructible, -) - -from DaVinciMCTools import MCTruthAndBkgCat, MCReconstructed, MCReconstructible -from PyConf.Algorithms import ParticleToSubcombinationsAlg -from DecayTreeFitter import DecayTreeFitter - -from DaVinci.algorithms import create_lines_filter -from PyConf.reading import get_particles -from FunTuple import FunTuple_Particles as Funtuple - - - -def make_basic_dtf_variables(pvs, data, DTF=None, pv_constraint=False, mass_constraint=False, particle_name=""): - variables = ( - FunctorCollection( - { - "TRCHI2DOF": F.CHI2DOF @ F.TRACK, - "ETA": F.ETA, - "PHI": F.PHI, - "TRGHOSTPROB": F.GHOSTPROB, - "BPVIPCHI2": F.BPVIPCHI2(pvs), - "BPVIP": F.BPVIP(pvs), - "BPVX": F.BPVX(pvs), - "BPVY": F.BPVY(pvs), - "BPVZ": F.BPVZ(pvs), - "TX" : F.TX, - "TY" : F.TY, - # "MINIPCHI2" : F.MINIPCHI2(pvs), - # "MINIP" : F.MINIP(pvs), - "KEY" : F.VALUE_OR(-1) @ F.OBJECT_KEY @ F.TRACK, - "CTB" : F.POSITION @ F.CLOSESTTOBEAM @ F.TRACK, - "TRACKPT": F.TRACK_PT, - "TRACKHISTORY": F.VALUE_OR(-1) @ F.TRACKHISTORY @ F.TRACK, - "QOVERP": F.QOVERP @ F.TRACK, - "NDOF": F.VALUE_OR(-1) @ F.NDOF @ F.TRACK, - } - ) - + Kinematics() - ) - - if(mass_constraint): - if(pv_constraint): # MASS + PV - dtf_variables_mass_pv = FunctorCollection({ - 'DTF_PV_M'+ particle_name + '_' + k: DTF(v) - for k, v in variables.get_thor_functors().items() - }) - return dtf_variables_mass_pv - else: # MASS - dtf_variables_mass = FunctorCollection( - {'DTF_M'+ particle_name + '_' + k: DTF(v) - for k, v in variables.get_thor_functors().items()}) - return dtf_variables_mass - - elif(pv_constraint): # PV - dtf_variables_pv = FunctorCollection({ - 'DTF_PV_' + k: DTF(v) - for k, v in variables.get_thor_functors().items() - }) - return dtf_variables_pv - - else: # NO MASS/PV - dtf_variables = FunctorCollection( - {'DTF_' + k: DTF(v) - for k, v in variables.get_thor_functors().items()}) - return dtf_variables - - -def make_composite_dtf_variables(pvs, data, DTF=None, pv_constraint=False, mass_constraint=False, particle_name=""): - variables = ( - FunctorCollection( - { - # "MAXPT": F.MAX(F.PT), - # "MINPT": F.MIN(F.PT), - # "SUMPT": F.SUM(F.PT), - # "MAXP": F.MAX(F.P), - # "MINP": F.MIN(F.P), - "BPVDIRA": F.BPVDIRA(pvs), - "VCHI2DOF": F.CHI2DOF, #CHI2VXNDOF - "BPVFDCHI2": F.BPVFDCHI2(pvs), - "BPVFD": F.BPVFD(pvs), - "BPVVDRHO": F.BPVVDRHO(pvs), - "BPVVDZ": F.BPVVDZ(pvs), - "BPVIPCHI2": F.BPVIPCHI2(pvs), - "BPVIP": F.BPVIP(pvs), - # "LOGBPVIPCHI2": log(F.BPVIPCHI2(pvs)), - "BPVLTIME": F.BPVLTIME(pvs), - # "MAXBPVIPCHI2": F.MAX(F.BPVIPCHI2(pvs)), #MAX_ - # "MINBPVIPCHI2": F.MIN(F.BPVIPCHI2(pvs)), - # "MAXBPVIP": F.MAX(F.BPVIP(pvs)), - # "MINBPVIP": F.MIN(F.BPVIP(pvs)), - "ETA": F.ETA, - "PHI": F.PHI, - "END_VX": F.END_VX, #END_ - "END_VY": F.END_VY, - "END_VZ": F.END_VZ, - "BPVX": F.BPVX(pvs), - "BPVY": F.BPVY(pvs), - "BPVZ": F.BPVZ(pvs), - "ALLPVFD" : F.ALLPV_FD(pvs), - "ALLPVIP" : F.ALLPV_IP(pvs), - - } - ) - + Kinematics() - ) - - addstring = "DTF" - if(pv_constraint): - addstring += '_PV' - if(mass_constraint): - addstring += '_M' - addstring += particle_name - - DTF_chi2ndof = FunctorCollection( - { - addstring+"_DTFCHI2": DTF.CHI2, - addstring+"_DTFNDOF": DTF.NDOF, - addstring+"_CTAU": DTF.CTAU, - addstring+"_CTAUERR": DTF.CTAUERR, - addstring+"_MERR": DTF.MASSERR, - } - ) - - if(mass_constraint): - if(pv_constraint): # MASS + PV - dtf_variables_mass_pv = FunctorCollection({ - 'DTF_PV_M'+ particle_name + '_' + k: DTF(v) - for k, v in variables.get_thor_functors().items() - }) - return dtf_variables_mass_pv+DTF_chi2ndof - else: # MASS - dtf_variables_mass = FunctorCollection( - {'DTF_M'+ particle_name + '_' + k: DTF(v) - for k, v in variables.get_thor_functors().items()}) - return dtf_variables_mass+DTF_chi2ndof - - elif(pv_constraint): # PV - dtf_variables_pv = FunctorCollection({ - 'DTF_PV_' + k: DTF(v) - for k, v in variables.get_thor_functors().items() - }) - return dtf_variables_pv+DTF_chi2ndof - - else: # NO MASS/PV - dtf_variables = FunctorCollection( - {'DTF_' + k: DTF(v) - for k, v in variables.get_thor_functors().items()}) - return dtf_variables+DTF_chi2ndof - - - -def make_dtf_variables(pvs, input_data, ptype): - - if ptype not in ["basic", "composite"]: - Exception(f"Need \'basic\' or \'composite\'. Got {ptype}") - - from DecayTreeFitter import DecayTreeFitter - - DTF = DecayTreeFitter( - name=f'DTF_{{hash}}', - input_particles=input_data) - - DTFvtx = DecayTreeFitter( - name=f'DTFvtx_{{hash}}', - input_particles=input_data, - input_pvs=pvs) - - DTFmassJpsi = DecayTreeFitter( - name=f'DTFmassJpsi_{{hash}}', - input_particles=input_data, - mass_constraints=["J/psi(1S)"]) - - DTFvtxmassJpsi = DecayTreeFitter( - name=f'DTFvtxmassJpsi_{{hash}}', - input_particles=input_data, - input_pvs=pvs, - mass_constraints=["J/psi(1S)"]) - - # DTFmassBcJpsi = DecayTreeFitter( - # name=f'DTFmassBcJpsi_{{hash}}', - # input_particles=input_data, - # mass_constraints=["B_c+","J/psi(1S)"]) - - # DTFvtxmassBcJpsi = DecayTreeFitter( - # name=f'DTFvtxmassBcJpsi_{{hash}}', - # input_particles=input_data, - # input_pvs=pvs, - # mass_constraints=["B_c+","J/psi(1S)"]) - - - if ptype == "basic": - dtf_vars = make_basic_dtf_variables(pvs, input_data, - DTF=DTF, - pv_constraint=False, - mass_constraint=False) - dtf_vars += make_basic_dtf_variables(pvs, input_data, - DTF=DTFvtx, - pv_constraint=True, - mass_constraint=False) - dtf_vars += make_basic_dtf_variables(pvs, input_data, - DTF=DTFmassJpsi, - pv_constraint=False, - mass_constraint=True, particle_name="Jpsi") - dtf_vars += make_basic_dtf_variables(pvs, input_data, - DTF=DTFvtxmassJpsi, - pv_constraint=True, - mass_constraint=True, particle_name="Jpsi") - # dtf_vars += make_basic_dtf_variables(pvs, input_data, - # DTF=DTFmassBcJpsi, - # pv_constraint=False, - # mass_constraint=True, particle_name="BcJpsi") - # dtf_vars += make_basic_dtf_variables(pvs, input_data, - # DTF=DTFvtxmassBcJpsi, - # pv_constraint=True, - # mass_constraint=True, particle_name="BcJpsi") - - return dtf_vars - - if ptype == "composite": - dtf_vars = make_composite_dtf_variables(pvs, input_data, - DTF=DTF, - pv_constraint=False, - mass_constraint=False) - dtf_vars += make_composite_dtf_variables(pvs, input_data, - DTF=DTFvtx, - pv_constraint=True, - mass_constraint=False) - dtf_vars += make_composite_dtf_variables(pvs, input_data, - DTF=DTFmassJpsi, - pv_constraint=False, - mass_constraint=True, particle_name="Jpsi") - dtf_vars += make_composite_dtf_variables(pvs, input_data, - DTF=DTFvtxmassJpsi, - pv_constraint=True, - mass_constraint=True, particle_name="Jpsi") - # dtf_vars += make_composite_dtf_variables(pvs, input_data, - # DTF=DTFmassBcJpsi, - # pv_constraint=False, - # mass_constraint=True, particle_name="BcJpsi") - # dtf_vars += make_composite_dtf_variables(pvs, input_data, - # DTF=DTFvtxmassBcJpsi, - # pv_constraint=True, - # mass_constraint=True, particle_name="BcJpsi") - - return dtf_vars - - diff --git a/run3_diJpsi/tupling_maker.py b/run3_diJpsi/tupling_maker.py deleted file mode 100644 index c9a6d7a5f8..0000000000 --- a/run3_diJpsi/tupling_maker.py +++ /dev/null @@ -1,340 +0,0 @@ -############################################################################### -# (c) Copyright 2021-2022 CERN for the benefit of the LHCb Collaboration # -# # -# This software is distributed under the terms of the GNU General Public # -# Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". # -# # -# In applying this licence, CERN does not waive the privileges and immunities # -# granted to it by virtue of its status as an Intergovernmental Organization # -# or submit itself to any jurisdiction. # -############################################################################### -""" -Read an HLT2 file and create an ntuple with the new DaVinci configuration. -""" -import Functors as F -import FunTuple.functorcollections as FC -from FunTuple import FunctorCollection -from FunTuple import FunTuple_Particles as Funtuple -from PyConf.reading import get_particles, get_pvs, get_rec_summary -from DaVinci.algorithms import create_lines_filter -from DaVinciMCTools import MCTruthAndBkgCat -from FunTuple.functorcollections import MCHierarchy, MCPrimaries, MCPromptDecay, Kinematics, SelectionInfo, HltTisTos, MCVertexInfo, MCKinematics, ParticleID, EventInfo -from PyConf.reading import get_odin # get_decreports, -from DecayTreeFitter import DecayTreeFitter - -from .make_dtf import * - -_basic = "basic" -_composite = "composite" -_toplevel = "toplevel" - -def all_variables(pvs, mctruth, ptype, candidates=None, ftAlg=None): - """ - function that returns dictionary of functors that work. - - functors are listed in order of https://lhcbdoc.web.cern.ch/lhcbdoc/moore/master/selection/thor_functors_reference.html#module-Functo - """ - if ptype not in [_basic, _composite]: - Exception(f"I want {_basic} or {_composite}. Got {ptype}") - all_vars = FunctorCollection({}) - - comp = _composite == ptype or _toplevel == ptype # is composite - basic = _basic == ptype # is not composite - top = _toplevel == ptype # the B - - # First import everything that comes in functorcollections - all_vars += FC.Kinematics() - if basic: - all_vars += FC.ParticleID(extra_info=True) - - if comp: - all_vars.update({"ALV": F.ALV(Child1=1, Child2=2)}) - - if comp: # all these require a vertex - all_vars.update({"BPVCORRM": F.BPVCORRM(pvs)}) - all_vars.update({"BPVCORRMERR": F.BPVCORRMERR(pvs)}) - all_vars.update({"BPVDIRA": F.BPVDIRA(pvs)}) - all_vars.update({"BPVDLS": F.BPVDLS(pvs)}) - all_vars.update({"BPVETA": F.BPVETA(pvs)}) - all_vars.update({"BPVFD": F.BPVFD(pvs)}) - all_vars.update({"BPVFDCHI2": F.BPVFDCHI2(pvs)}) - all_vars.update({"BPVFDIR": F.BPVFDIR(pvs)}) - all_vars.update({"BPVFDVEC": F.BPVFDVEC(pvs)}) - - all_vars.update({"BPVIP": F.BPVIP(pvs)}) - all_vars.update({"BPVIPCHI2": F.BPVIPCHI2(pvs)}) - all_vars.update({"BPVX": F.BPVX(pvs)}) - all_vars.update({"BPVY": F.BPVY(pvs)}) - all_vars.update({"BPVZ": F.BPVZ(pvs)}) - - if comp: # all these require a vertex - all_vars.update({"ALLPV_FD": F.ALLPV_FD(pvs)}) - all_vars.update({"ALLPV_IP": F.ALLPV_IP(pvs)}) - all_vars.update({"BPVLTIME": F.BPVLTIME(pvs)}) - all_vars.update({"BPVVDRHO": F.BPVVDRHO(pvs)}) - all_vars.update({"BPVVDX": F.BPVVDX(pvs)}) - all_vars.update({"BPVVDY": F.BPVVDY(pvs)}) - all_vars.update({"BPVVDZ": F.BPVVDZ(pvs)}) - - all_vars.update({"CHARGE": F.CHARGE}) - all_vars.update({"CHI2": F.CHI2}) - all_vars.update({"CHI2DOF": F.CHI2DOF}) - - if top: # apply this only to B - all_vars.update({"CHILD1_PT": F.CHILD(1, F.PT)}) # example of CHILD - all_vars.update({"Ds_END_VZ": F.CHILD(1, F.END_VZ)}) - all_vars.update({"Delta_END_VZ_DsB0": F.CHILD(1, F.END_VZ) - F.END_VZ}) - - if comp: - all_vars.update({"DOCA": F.SDOCA(Child1=1, Child2=2)}) - all_vars.update({"DOCACHI2": F.SDOCACHI2(Child1=1, Child2=2)}) - all_vars.update({"END_VRHO": F.END_VRHO}) - all_vars.update({"END_VX": F.END_VX}) - all_vars.update({"END_VY": F.END_VY}) - all_vars.update({"END_VZ": F.END_VZ}) - - all_vars.update({"ETA": F.ETA}) - all_vars.update({"FOURMOMENTUM": F.FOURMOMENTUM}) - all_vars.update({"ISBASIC": F.ISBASICPARTICLE}) - - if basic: - all_vars.update({"GHOSTPROB": F.GHOSTPROB}) - all_vars.update({"ISMUON": F.ISMUON}) - all_vars.update({"INMUON": F.INMUON}) - all_vars.update({"INECAL": F.INECAL}) - all_vars.update({"INHCAL": F.INHCAL}) - all_vars.update({"HASBREM": F.HASBREM}) - all_vars.update({"BREMENERGY": F.BREMENERGY}) - all_vars.update({"BREMBENDCORR": F.BREMBENDCORR}) - all_vars.update({"BREMPIDE": F.BREMPIDE}) - all_vars.update({"ECALPIDE": F.ECALPIDE}) - all_vars.update({"ECALPIDMU": F.ECALPIDMU}) - all_vars.update({"HCALPIDE": F.HCALPIDE}) - all_vars.update({"HCALPIDMU": F.HCALPIDMU}) - all_vars.update({"ELECTRONSHOWEREOP": F.ELECTRONSHOWEREOP}) - all_vars.update({"CLUSTERMATCH": F.CLUSTERMATCH_CHI2}) - all_vars.update({"ELECTRONMATCH": F.ELECTRONMATCH_CHI2}) - all_vars.update({"BREMHYPOMATCH": F.BREMHYPOMATCH_CHI2}) - all_vars.update({"ELECTRONENERGY": F.ELECTRONENERGY}) - all_vars.update({"BREMHYPOENERGY": F.BREMHYPOENERGY}) - all_vars.update({"BREMHYPODELTAX": F.BREMHYPODELTAX}) - all_vars.update({"ELECTRONID": F.ELECTRONID}) - all_vars.update({"HCALEOP": F.HCALEOP}) - # Note: the observables for the two functors below are (TRACK_MOM_X, TRACK_MOM_Y, TRACK_MOM_Z}) - # and (TRACK_POS_CLOSEST_TO_BEAM_X, TRACK_POS_CLOSEST_TO_BEAM_Y, TRACK_POS_CLOSEST_TO_BEAM_Z), - # which is why the trailing underscore in the name is added i.e. "TRACK_MOM_" and "TRACK_POS_CLOSEST_TO_BEAM_" - all_vars.update({"TRACK_MOM_": F.TRACK_MOMVEC}) - all_vars.update({"TRACK_POS_CLOSESTTOBEAM_": F.TRACK_POSVEC_CLOSESTTOBEAM}) - - all_vars.update({"IS_ABS_ID_pi": F.IS_ABS_ID("pi+")}) - all_vars.update({"IS_ID_pi": F.IS_ID("pi-")}) - all_vars.update({"PDG_MASS_pi": F.PDG_MASS("pi+")}) - all_vars.update({"SIGNED_DELTA_MASS_pi": F.SIGNED_DELTA_MASS("pi+")}) - all_vars.update({"ABS_DELTA_MASS_pi": F.ABS_DELTA_MASS("pi+")}) - all_vars.update({"IS_NOT_H": F.IS_NOT_H}) - all_vars.update({"IS_PHOTON": F.IS_PHOTON}) - - all_vars.update({"MASS": F.MASS}) - - if comp: - all_vars.update({"MAXPT": F.MAX(F.PT)}) - all_vars.update({"MAXDOCA": F.MAXSDOCA}) - all_vars.update({"MAXDOCACHI2": F.MAXSDOCACHI2}) - # the above in cut versions. - - if comp: - all_vars.update({"MINPT": F.MIN(F.PT)}) - all_vars.update({"MINIP": F.MINIP(pvs)}) - all_vars.update({"MINIPCHI2": F.MINIPCHI2(pvs)}) - - if basic: - all_vars.update({"TRACKPT": F.TRACK_PT}) - all_vars.update({"TRACKHISTORY": F.VALUE_OR(-1) @ F.TRACKHISTORY @ F.TRACK}) - all_vars.update({"QOVERP": F.QOVERP @ F.TRACK}) - all_vars.update({"NDOF": F.VALUE_OR(-1) @ F.NDOF @ F.TRACK}) - all_vars.update({"NFTHITS": F.VALUE_OR(-1) @ F.NFTHITS @ F.TRACK}) - all_vars.update({"NHITS": F.VALUE_OR(-1) @ F.NHITS @ F.TRACK}) - all_vars.update({"NUTHITS": F.VALUE_OR(-1) @ F.NUTHITS @ F.TRACK}) - all_vars.update({"NVPHITS": F.VALUE_OR(-1) @ F.NVPHITS @ F.TRACK}) - all_vars.update({"TRACKHASVELO": F.VALUE_OR(-1) @ F.TRACKHASVELO @ F.TRACK}) - all_vars.update({"TRACKHASUT": F.VALUE_OR(-1) @ F.TRACKHASUT @ F.TRACK}) - - all_vars.update({"OBJECT_KEY": F.OBJECT_KEY}) - - all_vars.update({"PHI": F.PHI}) - - all_vars.update({"ABS_PX": F.ABS @ F.PX}) - - all_vars.update({"REFERENCEPOINT_X": F.REFERENCEPOINT_X}) - all_vars.update({"REFERENCEPOINT_Y": F.REFERENCEPOINT_Y}) - all_vars.update({"REFERENCEPOINT_Z": F.REFERENCEPOINT_Z}) - - if comp: - all_vars.update({"SDOCA": F.SDOCA(1, 2)}) - all_vars.update({"SDOCACHI2": F.SDOCACHI2(1, 2)}) - if basic: - all_vars.update({"SHOWER_SHAPE": F.CALO_NEUTRAL_SHOWER_SHAPE}) - - if comp: - all_vars.update({"SUBCOMB12_MM": F.SUBCOMB(Functor=F.MASS, Indices=(1, 2))}) - all_vars.update({"SUMPT": F.SUM(F.PT)}) - - if basic: - all_vars.update({"TX": F.TX}) - all_vars.update({"TY": F.TY}) - - print(f"### For {ptype} returning variables {all_vars.functor_dict.keys()}") - return all_vars - - -def event_variables(PVs, ODIN, decreports, lines): - """ - event variables - """ - - evt_vars = FunctorCollection({}) - evt_vars += FC.EventInfo() - - evt_vars += FC.SelectionInfo(selection_type="Hlt2", trigger_lines=lines) - - if decreports: - evt_vars.update( - { - "DECISIONS": F.DECISIONS( - Lines=[bd2dsk_line + "Decision"], DecReports=decreports - ) - } - ) - evt_vars.update( - { - "DECREPORTS_FILTER": F.DECREPORTS_FILTER( - Lines=[bd2dsk_line + "Decision"], DecReports=decreports - ) - } - ) - - if ODIN: - evt_vars.update({"EVENTTYPE": F.EVENTTYPE(ODIN)}) - - evt_vars.update({"PV_SIZE": F.SIZE(PVs)}) - - if decreports: - evt_vars.update({"TCK": F.TCK(decreports)}) - - print(f"### For event returning variables {evt_vars.functor_dict.keys()}") - return evt_vars - - -def template(decay_descriptor, line_name, isturbo, Hlt2_decisions, composite_particles, daughter_particles): - - evtpath_prefix = "/Event/Spruce/" - if isturbo: - evtpath_prefix = "/Event/HLT2/" - - input_data = get_particles(evtpath_prefix + f"{line_name}/Particles") - - pvs = get_pvs() - - Hlt1_decisions = [ - 'Hlt1TrackMVADecision', 'Hlt1TwoTrackMVADecision', #'Hlt1D2KKDecision', - #'Hlt1D2KPiDecision', 'Hlt1D2PiPiDecision', - 'Hlt1DiMuonHighMassDecision', #'Hlt1DiMuonLowMassDecision', - #'Hlt1DiMuonSoftDecision', - #'Hlt1KsToPiPiDecision', 'Hlt1LowPtMuonDecision', - 'Hlt1LowPtDiMuonDecision', 'Hlt1SingleHighPtMuonDecision', - 'Hlt1TrackMuonMVADecision', "Hlt1DiMuonNoIP_SSDecision", - #"Hlt1DiMuonDrellYan_VLowMassDecision", - #"Hlt1DiMuonDrellYan_VLowMass_SSDecision", - #"Hlt1DiMuonDrellYanDecision", - #"Hlt1DiMuonDrellYan_SSDecision", - #"Hlt1DetJpsiToMuMuPosTagLineDecision", - #"Hlt1DetJpsiToMuMuNegTagLineDecision", - #"Hlt1TrackElectronMVADecision", - #"Hlt1SingleHighPtElectronDecision", - #"Hlt1DiElectronDisplacedDecision", - #"Hlt1SingleHighEtDecision", - #"Hlt1DiPhotonHighMassDecision", - #"Hlt1Pi02GammaGammaDecision", - #"Hlt1DiElectronHighMass_SSDecision", - #"Hlt1DiElectronHighMassDecision", - "Hlt1DiMuonNoIPDecision", - ] - - composite_variables = FunctorCollection({ - "END_VX_ERR":F.SQRT @ F.CALL(0,0) @ F.POS_COV_MATRIX @ F.ENDVERTEX, - "END_VY_ERR":F.SQRT @ F.CALL(1,1) @ F.POS_COV_MATRIX @ F.ENDVERTEX, - "END_VZ_ERR":F.SQRT @ F.CALL(2,2) @ F.POS_COV_MATRIX @ F.ENDVERTEX, - "BPVX_ERR": F.SQRT @ F.CALL(0,0) @ F.POS_COV_MATRIX @ F.BPV(pvs), - "BPVY_ERR": F.SQRT @ F.CALL(1,1) @ F.POS_COV_MATRIX @ F.BPV(pvs), - "BPVZ_ERR": F.SQRT @ F.CALL(2,2) @ F.POS_COV_MATRIX @ F.BPV(pvs), - "PERR": F.SQRT @ F.PERR2, - "PXERR": F.SQRT @ F.CALL(0,0) @ F.THREE_MOM_COV_MATRIX, - "PYERR": F.SQRT @ F.CALL(1,1) @ F.THREE_MOM_COV_MATRIX, - "PZERR": F.SQRT @ F.CALL(2,2) @ F.THREE_MOM_COV_MATRIX, - }) - - composite_variables += HltTisTos( selection_type="Hlt1", trigger_lines=Hlt1_decisions, data=input_data) - if not isturbo: - composite_variables += HltTisTos( selection_type="Hlt2", trigger_lines=Hlt2_decisions, data=input_data) - - daughter_variables = FunctorCollection({ - "PERR": F.SQRT @ F.PERR2, - "PZERR": F.SQRT @ F.CALL(2,2) @ F.THREE_MOM_COV_MATRIX, - }) - - #define event level variables - odin = get_odin() - decreports = None - rec_sum=get_rec_summary() - event_info = event_variables(pvs, odin, decreports, [line_name]) + FunctorCollection({ - "nPVs": F.VALUE_OR(-1) @F.RECSUMMARY_INFO(rec_sum,"nPVs"), - "nTTracks": F.VALUE_OR(-1) @F.RECSUMMARY_INFO(rec_sum,"nTTracks"), - "nLongTracks": F.VALUE_OR(-1) @F.RECSUMMARY_INFO(rec_sum,"nLongTracks"), - "nDownstreamTracks": F.VALUE_OR(-1) @F.RECSUMMARY_INFO(rec_sum,"nDownstreamTracks"), - "nUpstreamTracks": F.VALUE_OR(-1) @F.RECSUMMARY_INFO(rec_sum,"nUpstreamTracks"), - "nVeloTracks": F.VALUE_OR(-1) @F.RECSUMMARY_INFO(rec_sum,"nVeloTracks"), - "nBackTracks": F.VALUE_OR(-1) @F.RECSUMMARY_INFO(rec_sum,"nBackTracks"), - "nRich1Hits": F.VALUE_OR(-1) @F.RECSUMMARY_INFO(rec_sum,"nRich1Hits"), - "nRich2Hits": F.VALUE_OR(-1) @F.RECSUMMARY_INFO(rec_sum,"nRich2Hits"), - "nVPClusters": F.VALUE_OR(-1) @F.RECSUMMARY_INFO(rec_sum,"nVPClusters"), - "nFTClusters": F.VALUE_OR(-1) @F.RECSUMMARY_INFO(rec_sum,"nFTClusters"), - "eCalTot": F.VALUE_OR(-1) @F.RECSUMMARY_INFO(rec_sum,"eCalTot"), - "hCalTot": F.VALUE_OR(-1) @F.RECSUMMARY_INFO(rec_sum,"hCalTot"), - "nEcalClusters": F.VALUE_OR(-1) @F.RECSUMMARY_INFO(rec_sum,"nEcalClusters"), - "ALLPVX": F.ALLPVX(pvs), - "ALLPVY": F.ALLPVY(pvs), - "ALLPVZ": F.ALLPVZ(pvs), - }) - - event_info += FC.SelectionInfo( - selection_type="Hlt1", trigger_lines=Hlt1_decisions - ) - - variables = {} - - for composite_particle in composite_particles: - variables[composite_particle] = composite_variables + all_variables(pvs, None, _composite)+make_dtf_variables(pvs, input_data, _composite) - for daughter_particle in daughter_particles: - variables[daughter_particle] = daughter_variables + all_variables(pvs, None, _basic)+make_dtf_variables(pvs, input_data, _basic) - -# variables = { -# "QQbar": composite_variables + all_variables(pvs, None, _composite), -# "mup": daughter_variables + all_variables(pvs, None, _basic), -# "mum": daughter_variables + all_variables(pvs, None, _basic), -# } - - #define FunTuple instance - my_tuple = Funtuple( - name=line_name, - tuple_name="DecayTree", - fields=decay_descriptor, - variables=variables, - event_variables=event_info, - store_multiple_cand_info = True, - inputs=input_data) - - return my_tuple - -def line_prefilter(line_name): - return create_lines_filter(name=f"PreFilter_{line_name}", lines=[line_name]) - -- GitLab From 102882399ac25b63b854ebadce71435ac0f7bfd3 Mon Sep 17 00:00:00 2001 From: Chenxu Yu <yuc@lxplus955.cern.ch> Date: Tue, 25 Jun 2024 10:08:09 +0200 Subject: [PATCH 09/15] =?UTF-8?q?=E4=BF=9D=E5=AD=98=E6=9C=AC=E5=9C=B0?= =?UTF-8?q?=E6=9B=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Beauty_XS_Bs2DsPi/README.md | 3 - Beauty_XS_Bs2DsPi/dv_simple.py | 252 --------------------------------- Beauty_XS_Bs2DsPi/hlt1.py | 31 ---- Beauty_XS_Bs2DsPi/hlt2.py | 68 --------- Beauty_XS_Bs2DsPi/info.yaml | 79 ----------- 5 files changed, 433 deletions(-) delete mode 100644 Beauty_XS_Bs2DsPi/README.md delete mode 100644 Beauty_XS_Bs2DsPi/dv_simple.py delete mode 100644 Beauty_XS_Bs2DsPi/hlt1.py delete mode 100644 Beauty_XS_Bs2DsPi/hlt2.py delete mode 100644 Beauty_XS_Bs2DsPi/info.yaml diff --git a/Beauty_XS_Bs2DsPi/README.md b/Beauty_XS_Bs2DsPi/README.md deleted file mode 100644 index 769ed08b69..0000000000 --- a/Beauty_XS_Bs2DsPi/README.md +++ /dev/null @@ -1,3 +0,0 @@ -Production of Bs -> Ds pi to run on 2024 collision data to include both up and down polarities - -This is for use in early measurements of Beauty XS diff --git a/Beauty_XS_Bs2DsPi/dv_simple.py b/Beauty_XS_Bs2DsPi/dv_simple.py deleted file mode 100644 index b4254db880..0000000000 --- a/Beauty_XS_Bs2DsPi/dv_simple.py +++ /dev/null @@ -1,252 +0,0 @@ -# Based on: -# https://gitlab.cern.ch/lhcb/DaVinci/-/blob/v63r2/DaVinciExamples/python/DaVinciExamples/tupling/option_davinci_tupling_from_hlt2.py - -import Functors as F -import FunTuple.functorcollections as FC -from FunTuple import FunctorCollection, FunTuple_Particles as Funtuple -from PyConf.reading import get_particles, get_pvs, get_rec_summary, get_odin -#from PyConf.Algorithms import AdvancedCloneKiller, Run2SSPionTagger -from GaudiKernel.SystemOfUnits import GeV -from Hlt2Conf.algorithms_thor import ParticleFilter -#from DaVinci.common_particles import make_long_pions -from DaVinci.algorithms import create_lines_filter -from DaVinci import Options, make_config -from DaVinciMCTools import MCTruthAndBkgCat -from DecayTreeFitter import DecayTreeFitter -from Hlt2Conf.flavourTagging import run2_all_taggers -# specific for the B2OC SigmaNet -import Functors.math as fmath -import os - - -def alg_config(options: Options): - - line = "Hlt2B2OC_BdToDsmPi_DsmToKpKmPim" - line_data = get_particles(f"/Event/HLT2/{line}/Particles") - my_filter = create_lines_filter("Hlt2Line_Filter", - lines=[f"{line}"]) - Hlt1_decisions = [ - "Hlt1TrackMVADecision", - "Hlt1TwoTrackMVADecision", - ] - Hlt2_decisions = ['Hlt2B2OC_BdToDsmPi_DsmToKpKmPimDecision', - 'Hlt2Topo2BodyDecision', - 'Hlt2Topo3BodyDecision'] - - fields = { - "lab0": "[[B0]CC -> (D_s- -> K+ K- pi-) pi+]CC", - "lab1": "[[B0]CC -> (D_s- -> K+ K- pi-) ^pi+]CC", - "lab2": "[[B0]CC -> ^(D_s- -> K+ K- pi-) pi+]CC", - "lab3": "[[B0]CC -> (D_s- -> ^K+ K- pi-) pi+]CC", - "lab4": "[[B0]CC -> (D_s- -> K+ ^K- pi-) pi+]CC", - "lab5": "[[B0]CC -> (D_s- -> K+ K- ^pi-) pi+]CC", - } - - pvs = get_pvs() - - DTF_MassFitConsD = DecayTreeFitter(name="DTF_MassFitConsD", - input_particles=line_data, - mass_constraints=["D_s-"]) - DTF_LifetimeFit = DecayTreeFitter(name="DTF_LifetimeFit", - input_particles=line_data, - input_pvs=pvs) - - all_tagging = run2_all_taggers(line_data) - - # define helper functors - get_child = F.CHILD(1, F.FORWARDARG0) # change here the index of the child - get_SV = F.ENDVERTEX @ F.FORWARDARG0 - get_SV_pos = F.TOLINALG @ F.POSITION @ get_SV # only if composite (i.e. has vertex) - get_child_endvtx_pos = F.ENDVERTEX_POS @ get_child - get_fdvec_child = get_child_endvtx_pos - get_SV_pos - - # define observables - IP_wrt_SV = F.IP.bind(get_SV_pos , get_child) - IPCHI2_wrt_SV = F.IPCHI2.bind(get_SV , get_child) # only if child is composite (i.e. has vertex) - FD_wrt_SV = F.MAGNITUDE @ get_fdvec_child - FDCHI2_wrt_SV = F.VTX_FDCHI2.bind(get_SV, get_child) - - B_variables = FunctorCollection( - { - "ID": F.PARTICLE_ID, - "PT": F.PT, - "ETA": F.ETA, - "P": F.P, - "SUMPT": F.SUM(F.PT), - "MASS": F.MASS, - "BPVDIRA": F.BPVDIRA(pvs), - "CHI2DOF": F.CHI2DOF, - "BPVIPCHI2": F.BPVIPCHI2(pvs), - "BPVIP": F.BPVIP(pvs), - "BPVFDCHI2": F.BPVFDCHI2(pvs), - "BPVLTIME": F.BPVLTIME(pvs), - "BPVFD": F.BPVFD(pvs), - "CHILD1_IPwrtSV": IP_wrt_SV, - "CHILD1_IPCHI2wrtSV": IPCHI2_wrt_SV, - "CHILD1_FDwrtSV": FD_wrt_SV, - "CHILD1_FDCHI2wrtSV": FDCHI2_wrt_SV, - "DTF_MassFitConsD_MASS": DTF_MassFitConsD(F.MASS), - "DTF_MassFitConsD_CHI2DOF": DTF_MassFitConsD(F.CHI2DOF), # track or vertex chi2/ndf - "DTF_MassFitConsD_P": DTF_MassFitConsD(F.P), - "DTF_LifetimeFit_MASS": DTF_LifetimeFit(F.MASS), - "DTF_LifetimeFit_CHI2DOF": DTF_LifetimeFit(F.CHI2DOF), # track or vertex chi2/ndf - "DTF_LifetimeFit_CTAU": DTF_LifetimeFit.CTAU, - "DTF_LifetimeFit_CTAUERR": DTF_LifetimeFit.CTAUERR, - "PX": F.PX, - "PY": F.PY, - "PZ": F.PZ, - "BPVX": F.BPVX(pvs), - "BPVY": F.BPVY(pvs), - "BPVZ": F.BPVZ(pvs), - "END_VX": F.END_VX, - "END_VY": F.END_VY, - "END_VZ": F.END_VZ, - "END_VCHI2DOF": F.CHI2DOF @ F.ENDVERTEX, - "BPVCHI2DOF": F.CHI2DOF @ F.BPV(pvs), - # B2OC generic B hadron NN Hlt2 algorithm, - # not planning to use it directly for B2OC EM - "MVA": F.MVA( - MVAType="SigmaNet", - Config={ - "File": - "paramfile://data/Hlt2B2OC_B_SigmaNet_Run3-v2.json", - "Name": - "B2OC_SigmaNet_Generic", - "Lambda": - "2.0", - "NLayers": - "3", - "InputSize": - "6", - "Monotone_Constraints": - "[1,-1,-1,-1,-1,-1]", - "Variables": - "log_B_PT,B_ETA,log_B_DIRA,log_B_ENDVERTEX_CHI2,log_B_IPCHI2_OWNPV,log_B_IP_OWNPV", - }, - Inputs={ - "log_B_PT": fmath.log(F.PT), - "B_ETA": F.ETA, - "log_B_DIRA": fmath.log(1. +1.e-6 - F.BPVDIRA(pvs)), - "log_B_ENDVERTEX_CHI2": fmath.log(F.CHI2DOF), - "log_B_IPCHI2_OWNPV": fmath.log(F.BPVIPCHI2(pvs)), - "log_B_IP_OWNPV": fmath.log(F.BPVIP(pvs)), - }), - } - ) - B_variables+=FC.HltTisTos(selection_type="Hlt1", trigger_lines=Hlt1_decisions, data=line_data) - B_variables+=FC.FlavourTaggingResults(all_tagging) - - C_variables = FunctorCollection( - { - "ID": F.PARTICLE_ID, - "PT": F.PT, - "ETA": F.ETA, - "P": F.P, - "SUMPT": F.SUM(F.PT), - "MASS": F.MASS, - "DOCA12": F.DOCA(1, 2), - "DOCA13": F.DOCA(1, 3), - "DOCA23": F.DOCA(2, 3), - "BPVDIRA": F.BPVDIRA(pvs), - "CHI2DOF": F.CHI2DOF, - "BPVIP": F.BPVIP(pvs), - "BPVIPCHI2": F.BPVIPCHI2(pvs), - "BPVFD": F.BPVFD(pvs), - "BPVFDCHI2": F.BPVFDCHI2(pvs), - "MINIPCHI2": F.MINIPCHI2(pvs), - "PX": F.PX, - "PY": F.PY, - "PZ": F.PZ, - "BPVX": F.BPVX(pvs), - "BPVY": F.BPVY(pvs), - "BPVZ": F.BPVZ(pvs), - "END_VX": F.END_VX, - "END_VY": F.END_VY, - "END_VZ": F.END_VZ, - "END_VCHI2DOF": F.CHI2DOF @ F.ENDVERTEX, - } - ) - - fs_variables = FunctorCollection( - { - "ID": F.PARTICLE_ID, - "PT": F.PT, - "ETA": F.ETA, - "PHI": F.PHI, - "P": F.P, - "MASS": F.MASS, - "CHI2DOF": F.CHI2DOF, - "MINIPCHI2": F.MINIPCHI2(pvs), - "BPVIPCHI2": F.BPVIPCHI2(pvs), - "PX": F.PX, - "PY": F.PY, - "PZ": F.PZ, - "hasRICH": F.PPHASRICH() @ F.PROTOPARTICLE(), - "PIDK": F.PID_K, - "PIDp": F.PID_P, - "PIDe": F.PID_E, - "PIDmu": F.PID_MU, - "isMuon": F.ISMUON, - "TRACK_GhostProb": F.GHOSTPROB, - "ProbNNp": F.PROBNN_P, - "NHITS": F.VALUE_OR(-1) @ F.NHITS @ F.TRACK, - "NVPHITS": F.VALUE_OR(-1) @ F.NVPHITS @ F.TRACK, # VeloPixel hits - "NUTHITS": F.VALUE_OR(-1) @ F.NUTHITS @ F.TRACK, # UpstreamTracker hits - "NFTHITS": F.VALUE_OR(-1) @ F.NFTHITS @ F.TRACK, # ForwardTracker hits - "TRACKHASVELO": F.VALUE_OR(-1) @ F.TRACKHASVELO @ F.TRACK, - } - ) - - variables = { - "lab0": B_variables, - "lab1": fs_variables, - "lab2": C_variables, - "lab3": fs_variables, - "lab4": fs_variables, - "lab5": fs_variables, - } - - if options.simulation: - mctruth = MCTruthAndBkgCat(line_data, name="MCTruthAndBkgCat") - trueid_bkgcat_info = { - "TRUEID": F.VALUE_OR(0) @ mctruth(F.PARTICLE_ID), - "TRUEKEY": F.VALUE_OR(-1) @ mctruth(F.OBJECT_KEY), - "TRUEPT": mctruth(F.PT), - "TRUEPX": mctruth(F.PX), - "TRUEPY": mctruth(F.PY), - "TRUEPZ": mctruth(F.PZ), - "TRUEENERGY": mctruth(F.ENERGY), - "TRUEP": mctruth(F.P), - "TRUEFOURMOMENTUM": mctruth(F.FOURMOMENTUM), - "TRUETAU": mctruth(F.MC_LIFETIME), - "BKGCAT": mctruth.BkgCat, - } - for field in variables.keys(): - variables[field] += FunctorCollection(trueid_bkgcat_info) - - - odin = get_odin() - rec_summary = get_rec_summary() - # define event level variables - evt_variables = FunctorCollection({ - "RUNNUMBER": F.RUNNUMBER(odin), - "EVENTNUMBER": F.EVENTNUMBER(odin), - "nPVs": F.VALUE_OR(-1) @ F.RECSUMMARY_INFO(rec_summary, "nPVs"), - "nLongTracks": F.VALUE_OR(-1) @ F.RECSUMMARY_INFO(rec_summary, "nLongTracks"), - }) - evt_variables+=FC.SelectionInfo(selection_type="Hlt1", trigger_lines=Hlt1_decisions) - evt_variables+=FC.SelectionInfo(selection_type="Hlt2", trigger_lines=Hlt2_decisions) - - # define FunTuple instance - my_tuple = Funtuple( - name="Tuple", - tuple_name="DecayTree", - fields=fields, - variables=variables, - event_variables=evt_variables, - inputs=line_data, - store_multiple_cand_info=True, - ) - - return make_config(options, [my_filter, my_tuple]) - diff --git a/Beauty_XS_Bs2DsPi/hlt1.py b/Beauty_XS_Bs2DsPi/hlt1.py deleted file mode 100644 index d40c23bc29..0000000000 --- a/Beauty_XS_Bs2DsPi/hlt1.py +++ /dev/null @@ -1,31 +0,0 @@ -############################################################################### -# (c) Copyright 2023 CERN for the benefit of the LHCb Collaboration # -# # -# This software is distributed under the terms of the GNU General Public # -# Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". # -# # -# In applying this licence, CERN does not waive the privileges and immunities # -# granted to it by virtue of its status as an Intergovernmental Organization # -# or submit itself to any jurisdiction. # -############################################################################### -""" -Configures running HLT1 via Moore. -""" - -from Moore import Options -from Moore.config import allen_control_flow -from RecoConf.hlt1_allen import allen_gaudi_config, get_allen_line_names -from PyConf.application import configure_input, configure - -def alg_config(options: Options): - """ - Configures algorithm running of HLT1 via Moore to be passed to Analysis Productions. - """ - - config = configure_input(options) - with allen_gaudi_config.bind(sequence="hlt1_pp_matching_no_ut_1000KHz"): - line_names = get_allen_line_names() - allen_node = allen_control_flow(options) - config.update(configure(options, allen_node)) - - return config diff --git a/Beauty_XS_Bs2DsPi/hlt2.py b/Beauty_XS_Bs2DsPi/hlt2.py deleted file mode 100644 index 86070c155c..0000000000 --- a/Beauty_XS_Bs2DsPi/hlt2.py +++ /dev/null @@ -1,68 +0,0 @@ -############################################################################### -# (c) Copyright 2023 CERN for the benefit of the LHCb Collaboration # -# # -# This software is distributed under the terms of the GNU General Public # -# Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". # -# # -# In applying this licence, CERN does not waive the privileges and immunities # -# granted to it by virtue of its status as an Intergovernmental Organization # -# or submit itself to any jurisdiction. # -############################################################################### -""" -Configures running HLT2 via Moore. -""" - -from Moore import options, Options, run_moore -from Hlt2Conf.lines.b_to_open_charm import all_lines -# -from RecoConf.global_tools import stateProvider_with_simplified_geom, trackMasterExtrapolator_with_simplified_geom -from RecoConf.reconstruction_objects import reconstruction -from RecoConf.hlt2_global_reco import reconstruction as hlt2_reconstruction, make_light_reco_pr_kf_without_UT -from RecoConf.hlt2_tracking import ( - make_TrackBestTrackCreator_tracks, - make_PrKalmanFilter_noUT_tracks, - make_PrKalmanFilter_Velo_tracks, - make_PrKalmanFilter_Seed_tracks, -) -from RecoConf.decoders import default_VeloCluster_source -from RecoConf.event_filters import require_gec -from Hlt2Conf.settings.defaults import get_default_hlt1_filter_code_for_hlt2 -import sys - -all_lines = {} -from Hlt2Conf.lines.b_to_open_charm.hlt2_b2oc import make_hlt2_lines -default_lines = [ - 'BdToDsmPi_DsmToKpKmPim', -] -extra_config = { - 'flavour_tagging': [ - 'BdToDsmPi_DsmToKpKmPim', - ] -} -make_hlt2_lines( - line_dict=all_lines, - all_lines=default_lines, - extra_config=extra_config) - -def make_lines(): - lines = [builder() for builder in all_lines.values()] - return lines - -def alg_config(options: Options): - - public_tools = [ - trackMasterExtrapolator_with_simplified_geom(), - stateProvider_with_simplified_geom() - ] - - # require_gec.bind(skipUT=True),\ # B2OC lines do not have require_gec() - with reconstruction.bind(from_file=False),\ - hlt2_reconstruction.bind(make_reconstruction=make_light_reco_pr_kf_without_UT),\ - default_VeloCluster_source.bind(bank_type="VPRetinaCluster"),\ - make_TrackBestTrackCreator_tracks.bind(max_ghost_prob=0.7, max_chi2ndof=sys.float_info.max),\ - make_PrKalmanFilter_Velo_tracks.bind(max_chi2ndof=5.),\ - make_PrKalmanFilter_noUT_tracks.bind(max_chi2ndof=4.),\ - make_PrKalmanFilter_Seed_tracks.bind(max_chi2ndof=6.): - config = run_moore(options, make_lines, public_tools) - - return config diff --git a/Beauty_XS_Bs2DsPi/info.yaml b/Beauty_XS_Bs2DsPi/info.yaml deleted file mode 100644 index b903958273..0000000000 --- a/Beauty_XS_Bs2DsPi/info.yaml +++ /dev/null @@ -1,79 +0,0 @@ - -defaults: - wg: B2OC - automatically_configure: no - inform: - - alessandro.bertolin@pd.infn.it - -{%- set mc_datasets = [ -('13264021', 'Down', 'sim10-2024.Q1.2-v1.0-md100', 'dddb-20240427'), -('13264021', 'Up', 'sim10-2024.Q1.2-v1.0-mu100', 'dddb-20240427'), -]%} - -{%- for evttype, polarity, conddb, dddb in mc_datasets %} - -MC_Bs2DsPi_{{ polarity }}_Nu4d3_hlt1: - application: Moore/v55r9@x86_64_v2-el9-gcc13+detdesc-opt - input: - bk_query: "/MC/Dev/Beam6800GeV-2024.Q1.2-Mag{{ polarity }}-VeloDrift-Nu4.3-25ns-Pythia8/Sim10d/{{ evttype }}/DIGI" - dq_flags: - - OK - n_test_lfns: 1 - options: - entrypoint: Beauty_XS_Bs2DsPi.hlt1:alg_config - extra_options: - input_raw_format: 0.5 - conddb_tag: {{ conddb }} - dddb_tag: {{ dddb }} - input_type: "ROOT" - output_type: "ROOT" - simulation: True - data_type: "Upgrade" - scheduler_legacy_mode: False - compression: - algorithm: ZSTD - level: 1 - max_buffer_size: 1048576 - output: hlt1.dst - -MC_Bs2DsPi_{{ polarity }}_Nu4d3_hlt2: - application: Moore/v55r9@x86_64_v2-el9-gcc13+detdesc-opt - input: - job_name: MC_Bs2DsPi_{{ polarity }}_Nu4d3_hlt1 - options: - entrypoint: Beauty_XS_Bs2DsPi.hlt2:alg_config - extra_options: - input_raw_format: 0.5 - persistreco_version: 0.0 - conddb_tag: {{ conddb }} - dddb_tag: {{ dddb }} - input_type: "ROOT" - output_type: "ROOT" - simulation: True - data_type: "Upgrade" - output_manifest_file: hlt2_{{ evttype }}_{{ polarity }}.tck.json - scheduler_legacy_mode: False - compression: - algorithm: ZSTD - level: 1 - max_buffer_size: 1048576 - output: hlt2.dst - -MC_Bs2DsPi_{{ polarity }}_Nu4d3_DV: - application: DaVinci/v64r6@x86_64_v2-el9-gcc13+detdesc-opt - input: - job_name: MC_Bs2DsPi_{{ polarity }}_Nu4d3_hlt2 - output: dv_{{ polarity }}.root - options: - entrypoint: Beauty_XS_Bs2DsPi.dv_simple:alg_config - extra_options: - input_raw_format: 0.5 - input_type: "ROOT" - simulation: True - data_type: "Upgrade" - conddb_tag: {{ conddb }} - dddb_tag: {{ dddb }} - input_process: "Hlt2" - -{%- endfor %} - -- GitLab From e37d79dcdb42fb381e56a1b6146f34d7077bcd3e Mon Sep 17 00:00:00 2001 From: Chenxu Yu <chenxu.yu@cern.ch> Date: Tue, 25 Jun 2024 13:38:26 +0200 Subject: [PATCH 10/15] Update file info.yaml --- BandQ_MCBuds_NoMuonLines/info.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BandQ_MCBuds_NoMuonLines/info.yaml b/BandQ_MCBuds_NoMuonLines/info.yaml index 7720fe204e..8f6baea2be 100644 --- a/BandQ_MCBuds_NoMuonLines/info.yaml +++ b/BandQ_MCBuds_NoMuonLines/info.yaml @@ -93,7 +93,7 @@ MC_{{module}}_Nu{{n_u}}_{{polarity_mc_jobtitle}}_VPClose_{{mcversion_jobtitle}}_ input_type: ROOT simulation: True data_type: "Upgrade" - input_process: "{{dv_input_process}}" + input_process: "Hlt2" input_stream: "bandq" -- GitLab From 867bd72a13b4ecd13cf02e0786aacbd0bf059ed0 Mon Sep 17 00:00:00 2001 From: yuc <yuc@cern.ch> Date: Sat, 26 Oct 2024 17:01:24 +0800 Subject: [PATCH 11/15] initialize --- .../dv_data.py | 120 ++++ .../info.yaml | 41 ++ .../make_dtf.py | 35 +- .../tupling_maker.py | 6 + BandQ_MCBuds_NoMuonLines/AddHlt2/newHlt2.py | 83 --- BandQ_MCBuds_NoMuonLines/AddHlt2/newlines.py | 366 ------------- ...allen_mc_hlt1_pp_matching_no_ut_1000KHz.py | 8 - BandQ_MCBuds_NoMuonLines/dv_mc.py | 64 --- BandQ_MCBuds_NoMuonLines/info.yaml | 102 ---- BandQ_MCBuds_NoMuonLines/moore_mc_turbo.py | 74 --- BandQ_MCBuds_NoMuonLines/tupling_maker_new.py | 513 ------------------ 11 files changed, 186 insertions(+), 1226 deletions(-) create mode 100644 BandQ_Bp2JpsiKp_MuonID_NoMuonID_Lines/dv_data.py create mode 100644 BandQ_Bp2JpsiKp_MuonID_NoMuonID_Lines/info.yaml rename {BandQ_MCBuds_NoMuonLines => BandQ_Bp2JpsiKp_MuonID_NoMuonID_Lines}/make_dtf.py (89%) rename {BandQ_MCBuds_NoMuonLines => BandQ_Bp2JpsiKp_MuonID_NoMuonID_Lines}/tupling_maker.py (99%) delete mode 100644 BandQ_MCBuds_NoMuonLines/AddHlt2/newHlt2.py delete mode 100644 BandQ_MCBuds_NoMuonLines/AddHlt2/newlines.py delete mode 100644 BandQ_MCBuds_NoMuonLines/allen_mc_hlt1_pp_matching_no_ut_1000KHz.py delete mode 100644 BandQ_MCBuds_NoMuonLines/dv_mc.py delete mode 100644 BandQ_MCBuds_NoMuonLines/info.yaml delete mode 100644 BandQ_MCBuds_NoMuonLines/moore_mc_turbo.py delete mode 100644 BandQ_MCBuds_NoMuonLines/tupling_maker_new.py diff --git a/BandQ_Bp2JpsiKp_MuonID_NoMuonID_Lines/dv_data.py b/BandQ_Bp2JpsiKp_MuonID_NoMuonID_Lines/dv_data.py new file mode 100644 index 0000000000..b1080e22ca --- /dev/null +++ b/BandQ_Bp2JpsiKp_MuonID_NoMuonID_Lines/dv_data.py @@ -0,0 +1,120 @@ +from .tupling_maker import template, line_prefilter +from DaVinci import Options, make_config +import Functors as F +from Functors.math import in_range +from GaudiKernel.SystemOfUnits import MeV +# import yaml + +def Bz2JpsiKst_mTag_NoMuonID( ): + decay_descriptor = { + "Bz": '[B0 -> (J/psi(1S) -> mu+ mu-) (K*(892)0 -> K+ pi-)]CC', + "Jpsi": '[B0 -> ^(J/psi(1S) -> mu+ mu-) (K*(892)0 -> K+ pi-)]CC', + "Kstar": '[B0 -> (J/psi(1S) -> mu+ mu-) ^(K*(892)0 -> K+ pi-)]CC', + "Kp": '[B0 -> (J/psi(1S) -> mu+ mu-) (K*(892)0 -> ^K+ pi-)]CC', + "pim": '[B0 -> (J/psi(1S) -> mu+ mu-) (K*(892)0 -> K+ ^pi-)]CC', + "mum": '[B0 -> (J/psi(1S) -> mu+ ^mu-) (K*(892)0 -> K+ pi-)]CC', + "mup": '[B0 -> (J/psi(1S) -> ^mu+ mu-) (K*(892)0 -> K+ pi-)]CC', + } + line_name = "Hlt2BandQ_Bz2JpsiKst_mTag_NoMuonID" + decay_name = "Bs2JpsiKst_mTag" + dict = {} + my_tuple = template(decay_descriptor, line_name, True, [], ["Bz", "Jpsi", "Kstar"], ["Kp", "pim", "mup", "mum"]) + my_filter = line_prefilter(line_name) + dict[decay_name] = [my_filter, my_tuple] + return dict + +def Bz2JpsiKst_pTag_NoMuonID( ): + decay_descriptor = { + "Bz": '[B0 -> (J/psi(1S) -> mu+ mu-) (K*(892)0 -> K+ pi-)]CC', + "Jpsi": '[B0 -> ^(J/psi(1S) -> mu+ mu-) (K*(892)0 -> K+ pi-)]CC', + "Kstar": '[B0 -> (J/psi(1S) -> mu+ mu-) ^(K*(892)0 -> K+ pi-)]CC', + "Kp": '[B0 -> (J/psi(1S) -> mu+ mu-) (K*(892)0 -> ^K+ pi-)]CC', + "pim": '[B0 -> (J/psi(1S) -> mu+ mu-) (K*(892)0 -> K+ ^pi-)]CC', + "mum": '[B0 -> (J/psi(1S) -> mu+ ^mu-) (K*(892)0 -> K+ pi-)]CC', + "mup": '[B0 -> (J/psi(1S) -> ^mu+ mu-) (K*(892)0 -> K+ pi-)]CC', + } + line_name = "Hlt2BandQ_Bz2JpsiKst_pTag_NoMuonID" + decay_name = "Bz2JpsiKst_pTag" + dict = {} + my_tuple = template(decay_descriptor, line_name, True, [], ["Bz", "Jpsi", "Kstar"], ["Kp", "pim", "mup", "mum"]) + my_filter = line_prefilter(line_name) + dict[decay_name] = [my_filter, my_tuple] + return dict + +def Bs2JpsiPhi_mTag_NoMuonID( ): + decay_descriptor = { + "Bs": '[B_s0 -> (J/psi(1S) -> mu+ mu-) (phi(1020) -> K+ K-)]CC', + "Jpsi": '[B_s0 -> ^(J/psi(1S) -> mu+ mu-) (phi(1020) -> K+ K-)]CC', + "phi": '[B_s0 -> (J/psi(1S) -> mu+ mu-) ^(phi(1020) -> K+ K-)]CC', + "Kp": '[B_s0 -> (J/psi(1S) -> mu+ mu-) (phi(1020) -> ^K+ K-)]CC', + "Km": '[B_s0 -> (J/psi(1S) -> mu+ mu-) (phi(1020) -> K+ ^K-)]CC', + "mum": '[B_s0 -> (J/psi(1S) -> mu+ ^mu-) (phi(1020) -> K+ K-)]CC', + "mup": '[B_s0 -> (J/psi(1S) -> ^mu+ mu-) (phi(1020) -> K+ K-)]CC', + } + line_name = "Hlt2BandQ_Bs2JpsiPhi_mTag_NoMuonID" + decay_name = "Bs2JpsiPhi_mTag" + dict = {} + my_tuple = template(decay_descriptor, line_name, True, [], ["Bs", "Jpsi", "phi"], ["Kp", "Km", "mup","mum"]) + my_filter = line_prefilter(line_name) + dict[decay_name] = [my_filter, my_tuple] + return dict + +def Bs2JpsiPhi_pTag_NoMuonID( ): + decay_descriptor = { + "Bs": '[B_s0 -> (J/psi(1S) -> mu+ mu-) (phi(1020) -> K+ K-)]CC', + "Jpsi": '[B_s0 -> ^(J/psi(1S) -> mu+ mu-) (phi(1020) -> K+ K-)]CC', + "phi": '[B_s0 -> (J/psi(1S) -> mu+ mu-) ^(phi(1020) -> K+ K-)]CC', + "Kp": '[B_s0 -> (J/psi(1S) -> mu+ mu-) (phi(1020) -> ^K+ K-)]CC', + "Km": '[B_s0 -> (J/psi(1S) -> mu+ mu-) (phi(1020) -> K+ ^K-)]CC', + "mum": '[B_s0 -> (J/psi(1S) -> mu+ ^mu-) (phi(1020) -> K+ K-)]CC', + "mup": '[B_s0 -> (J/psi(1S) -> ^mu+ mu-) (phi(1020) -> K+ K-)]CC', + } + line_name = "Hlt2BandQ_Bs2JpsiPhi_pTag_NoMuonID" + decay_name = "Bs2JpsiPhi_pTag" + dict = {} + my_tuple = template(decay_descriptor, line_name, True, [], ["Bs", "Jpsi", "phi"], ["Kp", "Km", "mup","mum"]) + my_filter = line_prefilter(line_name) + dict[decay_name] = [my_filter, my_tuple] + return dict + +def Bp2JpsiKp_mTag_NoMuonID( ): + decay_descriptor = { + "Bp": '[B+ -> (J/psi(1S) -> mu+ mu-) K+]CC', + "Jpsi": '[B+ -> ^(J/psi(1S) -> mu+ mu-) K+]CC', + "Kp": '[B+ -> (J/psi(1S) -> mu+ mu-) ^K+]CC', + "mum": '[B+ -> (J/psi(1S) -> mu+ ^mu-) K+]CC', + "mup": '[B+ -> (J/psi(1S) -> ^mu+ mu-) K+]CC', + } + line_name = "Hlt2BandQ_Bp2JpsiKp_mTag_NoMuonID" + decay_name = "Bp2JpsiKp_mTag" + dict = {} + my_tuple = template(decay_descriptor, line_name, True, [], ["Bp", "Jpsi"], ["Kp", "mup","mum"]) + my_filter = line_prefilter(line_name) + dict[decay_name] = [my_filter, my_tuple] + return dict + +def Bp2JpsiKp_pTag_NoMuonID( ): + decay_descriptor = { + "Bp": '[B+ -> (J/psi(1S) -> mu+ mu-) K+]CC', + "Jpsi": '[B+ -> ^(J/psi(1S) -> mu+ mu-) K+]CC', + "Kp": '[B+ -> (J/psi(1S) -> mu+ mu-) ^K+]CC', + "mum": '[B+ -> (J/psi(1S) -> mu+ ^mu-) K+]CC', + "mup": '[B+ -> (J/psi(1S) -> ^mu+ mu-) K+]CC', + } + line_name = "Hlt2BandQ_Bp2JpsiKp_pTag_NoMuonID" + decay_name = "Bp2JpsiKp_pTag" + dict = {} + my_tuple = template(decay_descriptor, line_name, True, [], ["Bp", "Jpsi"], ["Kp", "mup","mum"]) + my_filter = line_prefilter(line_name) + dict[decay_name] = [my_filter, my_tuple] + return dict + +def Entry_Point(options: Options): + algs_dict = Bp2JpsiKp_pTag_NoMuonID() + algs_dict.update(Bp2JpsiKp_mTag_NoMuonID()) + algs_dict.update(Bz2JpsiKst_pTag_NoMuonID()) + algs_dict.update(Bz2JpsiKst_mTag_NoMuonID()) + algs_dict.update(Bs2JpsiPhi_pTag_NoMuonID()) + algs_dict.update(Bs2JpsiPhi_mTag_NoMuonID()) + return make_config(options, algs_dict) + \ No newline at end of file diff --git a/BandQ_Bp2JpsiKp_MuonID_NoMuonID_Lines/info.yaml b/BandQ_Bp2JpsiKp_MuonID_NoMuonID_Lines/info.yaml new file mode 100644 index 0000000000..200789a1c9 --- /dev/null +++ b/BandQ_Bp2JpsiKp_MuonID_NoMuonID_Lines/info.yaml @@ -0,0 +1,41 @@ +{%- set dv_platform_detdesc = "x86_64_v2-el9-clang16-opt" %} +defaults: + application: "DaVinci/v64r9" + wg: BandQ + inform: + - yuc@cern.ch + +# data configuration +{%- set datasets = [ + ('Collision24', 'Sprucing24c4/94000000', 'BANDQ', 'B2JpsiX_pmTag_NoMuonID', 'MagDown', 'VeloClosed', 'TurboPass', 'bandq'), + ('Collision24', 'Sprucing24c4/94000000', 'BANDQ', 'B2JpsiX_pmTag_NoMuonID', 'MagUp', 'VeloClosed', 'TurboPass', 'bandq'), +]%} + + + +{%- for data, Type, wg, decay, polarity, Velo, process, stream in datasets %} + +data_{{decay}}_{{wg}}_c4_{{Velo}}_WithUT_{{polarity}}: + application: "DaVinci/v64r9@{{dv_platform_detdesc}}" + input: + bk_query: "/LHCb/{{data}}/Beam6800GeV-{{Velo}}-{{polarity}}/Real Data/{{Type}}/{{wg}}.DST" + dq_flags: + - OK + - UNCHECKED + keep_running: True + n_test_lfns: 1 + options: + entrypoint: BandQ_Bp2JpsiKp_MuonID_NoMuonID_Lines.dv_data:Entry_Point + extra_options: + input_type: ROOT + input_process: "{{process}}" + input_stream: "{{stream}}" + input_raw_format: 0.5 + simulation: False + data_type: "Upgrade" + geometry_version: run3/2024.Q1.2-v00.00 + conditions_version: master + output: Data_{{stream}}_{{decay}}.ROOT +{%- endfor %} + + diff --git a/BandQ_MCBuds_NoMuonLines/make_dtf.py b/BandQ_Bp2JpsiKp_MuonID_NoMuonID_Lines/make_dtf.py similarity index 89% rename from BandQ_MCBuds_NoMuonLines/make_dtf.py rename to BandQ_Bp2JpsiKp_MuonID_NoMuonID_Lines/make_dtf.py index efae1d910f..b179e05028 100644 --- a/BandQ_MCBuds_NoMuonLines/make_dtf.py +++ b/BandQ_Bp2JpsiKp_MuonID_NoMuonID_Lines/make_dtf.py @@ -209,17 +209,18 @@ def make_dtf_variables(pvs, input_data, ptype): if ptype == "basic": dtf_vars = make_basic_dtf_variables(pvs, input_data, - DTF=DTF, - pv_constraint=False, - mass_constraint=False) - dtf_vars += make_basic_dtf_variables(pvs, input_data, DTF=DTFvtx, pv_constraint=True, mass_constraint=False) - dtf_vars += make_basic_dtf_variables(pvs, input_data, - DTF=DTFmassJpsi, - pv_constraint=False, - mass_constraint=True, particle_name="Jpsi") + # dtf_vars += make_basic_dtf_variables(pvs, input_data, + # DTF=DTF, + # pv_constraint=False, + # mass_constraint=False) + + # dtf_vars += make_basic_dtf_variables(pvs, input_data, + # DTF=DTFmassJpsi, + # pv_constraint=False, + # mass_constraint=True, particle_name="Jpsi") dtf_vars += make_basic_dtf_variables(pvs, input_data, DTF=DTFvtxmassJpsi, pv_constraint=True, @@ -237,17 +238,19 @@ def make_dtf_variables(pvs, input_data, ptype): if ptype == "composite": dtf_vars = make_composite_dtf_variables(pvs, input_data, - DTF=DTF, - pv_constraint=False, - mass_constraint=False) - dtf_vars += make_composite_dtf_variables(pvs, input_data, DTF=DTFvtx, pv_constraint=True, mass_constraint=False) - dtf_vars += make_composite_dtf_variables(pvs, input_data, - DTF=DTFmassJpsi, - pv_constraint=False, - mass_constraint=True, particle_name="Jpsi") + + # dtf_vars += make_composite_dtf_variables(pvs, input_data, + # DTF=DTF, + # pv_constraint=False, + # mass_constraint=False) + + # dtf_vars += make_composite_dtf_variables(pvs, input_data, + # DTF=DTFmassJpsi, + # pv_constraint=False, + # mass_constraint=True, particle_name="Jpsi") dtf_vars += make_composite_dtf_variables(pvs, input_data, DTF=DTFvtxmassJpsi, pv_constraint=True, diff --git a/BandQ_MCBuds_NoMuonLines/tupling_maker.py b/BandQ_Bp2JpsiKp_MuonID_NoMuonID_Lines/tupling_maker.py similarity index 99% rename from BandQ_MCBuds_NoMuonLines/tupling_maker.py rename to BandQ_Bp2JpsiKp_MuonID_NoMuonID_Lines/tupling_maker.py index 7086ca14e2..1fdf0ab42b 100644 --- a/BandQ_MCBuds_NoMuonLines/tupling_maker.py +++ b/BandQ_Bp2JpsiKp_MuonID_NoMuonID_Lines/tupling_maker.py @@ -244,6 +244,12 @@ def template(decay_descriptor, line_name, isturbo, Hlt2_decisions, composite_par PsiXXX_data = ParticleFilter(PsiXXX_data_raw, Cut=F.FILTER(cutAdd) ) + + + + + + pvs = get_pvs() Hlt1_decisions = [ # already contain Hlt1TrackMVADecision ?OK diff --git a/BandQ_MCBuds_NoMuonLines/AddHlt2/newHlt2.py b/BandQ_MCBuds_NoMuonLines/AddHlt2/newHlt2.py deleted file mode 100644 index d05c92d825..0000000000 --- a/BandQ_MCBuds_NoMuonLines/AddHlt2/newHlt2.py +++ /dev/null @@ -1,83 +0,0 @@ -from PyConf import configurable - -from Moore.config import Hlt2Line, register_line_builder - -#get bandq builders -from Hlt2Conf.lines.bandq.builders.prefilters import make_prefilters -from Hlt2Conf.lines.bandq.builders import b_to_jpsiX_lines, \ - doublecharm, \ - b_for_spectroscopy -from Hlt2Conf.lines.bandq.builders import dps_lines -from Hlt2Conf.lines.bandq.builders import dimuon_lines -from Hlt2Conf.lines.bandq.builders import ccbargamma_conv_lines, ccbarmumu_lines -from Hlt2Conf.lines.bandq.builders import qqbar_to_hadrons -from Hlt2Conf.lines.bandq.builders import ppmumu_lines -from Hlt2Conf.lines.bandq.builders import bbaryon_to_lcdsX_lines -from Hlt2Conf.lines.bandq.builders import jpsi_to_lmdlmd_lines -from .AddHlt2 import b_to_jpsiX_NoMuonID -from Hlt2Conf.lines.bandq.builders import b_to_LcX_TT_lines -from Hlt2Conf.lines.charmonium_to_dimuon_detached import make_detached_jpsi -from Hlt2Conf.lines.bandq.builders.b_to_jpsiX_TT_lines import make_Lb2JpsiLambdaTT, make_Bd2JpsiKsTT -from Hlt2Conf.lines.bandq.builders.jpsi_to_lmdlmd_lines import make_lambdall, make_lambdadd, make_lambdatt -from Hlt2Conf.lines.b_to_open_charm.builders.d_builder import make_dsplus_to_kpkmpip #import this to force Lb2LcDs T-track line do the Ds sector long-track reconstruction and selection first. - -PROCESS = 'hlt2' -turbo_lines = {} -full_lines = {} - - -@register_line_builder(turbo_lines) -@configurable -def Bp2JpsiKp_NoMuonIDbak_line(name='Hlt2BandQ_Bp2JpsiKp_NoMuonID', - prescale=1, - persistreco=False): - """B+->Jpsi K+ without Muon-based PID cuts.""" - line_alg = b_to_jpsiX_NoMuonID.make_Bp2JpsiKp_NoMuonID() - return Hlt2Line( - name=name, - algs=make_prefilters() + [line_alg], - prescale=prescale, - persistreco=persistreco) - - -@register_line_builder(turbo_lines) -@configurable -def Bz2JpsiKpPim_NoMuonIDbak_line(name='Hlt2BandQ_Bz2JpsiKpPim_NoMuonID', - prescale=1, - persistreco=False): - """B0->Jpsi K+ pi- without Muon-based PID cuts. Cover the full KPi mass spectrum""" - line_alg = b_to_jpsiX_NoMuonID.make_Bz2JpsiKpPim_NoMuonID() - return Hlt2Line( - name=name, - algs=make_prefilters() + [line_alg], - prescale=prescale, - persistreco=persistreco) - - -#This is a back-up choice if the rate of Bz2JpsiKpPim_NoMuonID_line is found to be not acceptable during rate tuning in Feb. -#@register_line_builder(turbo_lines) -#@configurable -#def Bz2JpsiKst_NoMuonID_line(name='Hlt2BandQ_Bz2JpsiKst_NoMuonID', -# prescale=1, -# persistreco=False): -# """B0->Jpsi K*0 without Muon-based PID cuts. Focus on the K*(892) region""" -# line_alg = b_to_jpsiX_NoMuonID.make_Bz2JpsiKst_NoMuonID() -# return Hlt2Line( -# name=name, -# algs=make_prefilters() + [line_alg], -# prescale=prescale, -# persistreco=persistreco) - - -@register_line_builder(turbo_lines) -@configurable -def Bs2JpsiKpKm_NoMuonIDbak_line(name='Hlt2BandQ_Bs2JpsiKpKm_NoMuonID', - prescale=1, - persistreco=False): - """Bs0->Jpsi K+ K- without Muon-based PID cuts. Cover the full KPi mass spectrum""" - line_alg = b_to_jpsiX_NoMuonID.make_Bs2JpsiKpKm_NoMuonID() - return Hlt2Line( - name=name, - algs=make_prefilters() + [line_alg], - prescale=prescale, - persistreco=persistreco) diff --git a/BandQ_MCBuds_NoMuonLines/AddHlt2/newlines.py b/BandQ_MCBuds_NoMuonLines/AddHlt2/newlines.py deleted file mode 100644 index 3376dcc1dc..0000000000 --- a/BandQ_MCBuds_NoMuonLines/AddHlt2/newlines.py +++ /dev/null @@ -1,366 +0,0 @@ -############################################################################### -# (c) Copyright 2022 CERN for the benefit of the LHCb Collaboration # -# # -# This software is distributed under the terms of the GNU General Public # -# Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". # -# # -# In applying this licence, CERN does not waive the privileges and immunities # -# granted to it by virtue of its status as an Intergovernmental Organization # -# or submit itself to any jurisdiction. # -############################################################################### -""" -A standalone builder for exclusive B+->Jpsi K+, B0->Jpsi K+ pi-, Bs->Jpsi K+ K- decays. -Do not cut on MUON-station-based MuonID info. -Use the line to perform data-driven check of MuonID performance. -Tight kinematic cuts to make rate under control. -""" -from GaudiKernel.SystemOfUnits import GeV, MeV, picosecond - -from RecoConf.reconstruction_objects import make_pvs - -from Hlt2Conf.algorithms_thor import ParticleFilter, ParticleCombiner -from Functors import require_all -from PyConf import configurable - -from Hlt2Conf.standard_particles import make_long_muons - -import Functors as F -from Functors.math import in_range - -from Hlt2Conf.lines.bandq.builders.charged_hadrons import make_detached_kaons, make_detached_pions - -#for ghost probNN: didn't perform online, as unknowing the quality of further data taking -@configurable -def make_NoMuonID_muons( - make_particles=make_long_muons, - name="bandq_NoMuonID_muons_{hash}", - # pt_min=300. * MeV, #?OK - pt_min=600. * MeV, - p_min=4 * GeV, - p_max=200. * GeV, - eta_min=2., - eta_max=5., - mipchi2dvprimary_min=9, - CHI2DOF_max=14.,#?OK - #pid=None): - pid=require_all(F.RICH_DLL_MU > -10, - F.CHI2DOF< CHI2DOF_max, - F.RICH_DLL_MU - F.RICH_DLL_K > -5.)): - - pvs = make_pvs() - - code = require_all(F.PT > pt_min, in_range(p_min, F.P, p_max), - in_range(eta_min, F.ETA, eta_max), - F.MINIPCHI2(pvs) > mipchi2dvprimary_min) - - if (pid is not None): - code &= pid - - return ParticleFilter(make_particles(), name=name, Cut=F.FILTER(code)) - - -@configurable -def make_detached_kaons_forB2JpsiX_NoMuonID( - make_particles=make_detached_kaons, - name="bandq_detached_kaons_forB2JpsiX_NoMuonID_{hash}", - # pt_min=300. * MeV, ?OK - pt_min=300. * MeV, - p_min=4 * GeV, - p_max=200. * GeV, - eta_min=2., - eta_max=5., - mipchi2dvprimary_min=9, - pid=(F.PID_K > 5.)): - pvs = make_pvs() - - code = require_all(F.PT > pt_min, in_range(p_min, F.P, p_max), - in_range(eta_min, F.ETA, eta_max), - F.MINIPCHI2(pvs) > mipchi2dvprimary_min) - - if (pid is not None): - code &= pid - - return ParticleFilter(make_particles(), name=name, Cut=F.FILTER(code)) - - -@configurable -def make_detached_kaons_forBp2JpsiKp_NoMuonID( - make_particles=make_detached_kaons, - name="bandq_detached_kaons_forB2JpsiX_NoMuonID_{hash}", - # pt_min=300. * MeV, ?OK - pt_min=500. * MeV, - p_min=4 * GeV, - p_max=200. * GeV, - eta_min=2., - eta_max=5., - mipchi2dvprimary_min=9, - pid=(F.PID_K > 5.)): - pvs = make_pvs() - - code = require_all(F.PT > pt_min, in_range(p_min, F.P, p_max), - in_range(eta_min, F.ETA, eta_max), - F.MINIPCHI2(pvs) > mipchi2dvprimary_min) - - if (pid is not None): - code &= pid - - return ParticleFilter(make_particles(), name=name, Cut=F.FILTER(code)) - - -@configurable -def make_detached_pions_forB2JpsiX_NoMuonID( - make_particles=make_detached_pions, - name="bandq_detached_pions_forB2JpsiX_NoMuonID_{hash}", - pt_min=200. * MeV, - p_min=3 * GeV, - p_max=200. * GeV, - eta_min=2., - eta_max=5., - mipchi2dvprimary_min=9, - pid=(F.PID_K < -5.)): - pvs = make_pvs() - - code = require_all(F.PT > pt_min, in_range(p_min, F.P, p_max), - in_range(eta_min, F.ETA, eta_max), - F.MINIPCHI2(pvs) > mipchi2dvprimary_min) - - if (pid is not None): - code &= pid - - return ParticleFilter(make_particles(), name=name, Cut=F.FILTER(code)) - - -@configurable -def make_detachedKPi_forB2JpsiX_NoMuonID( - kaons=make_detached_kaons_forB2JpsiX_NoMuonID, - pions=make_detached_pions_forB2JpsiX_NoMuonID, - name="bandq_detachedKPi_forB2JpsiX_NoMuonID_{hash}", - descriptor='[K*(892)0 -> K+ pi-]cc', - am_max=2500 * MeV, - # maxdocachi2=20., ?OK - maxdocachi2=20., - m_max=2450. * MeV, - bpvdls_min=3): - - pvs = make_pvs() - - combination_code = F.require_all(F.MASS < am_max, - F.MAXSDOCACHI2CUT(maxdocachi2)) - - vertex_code = F.require_all(in_range(m_min, F.MASS> m_max, F.BPVDLS(pvs) > bpvdls_min) - - return ParticleCombiner( - name=name, - Inputs=[kaons(), pions()], - DecayDescriptor=descriptor, - CombinationCut=combination_code, - CompositeCut=vertex_code) - - -@configurable -def make_detachedKst_forB2JpsiX_NoMuonID( - KPi_comb=make_detachedKPi_forB2JpsiX_NoMuonID, - name="bandq_detachedKst_forB2JpsiX_NoMuonID_{hash}", - #?OK - # m_min=800. * MeV, - # m_max=1000. * MeV): - m_min=750. * MeV, - m_max=1050. * MeV, - PT_min=400 * MeV, - CHI2DOF_max=12.): - - code = F.require_all(in_range(m_min, F.MASS, m_max), F.PT>PT_min, F.CHI2DOF<CHI2DOF_max) - - return ParticleFilter(KPi_comb(), name=name, Cut=F.FILTER(code)) - - -@configurable -def make_detachedKK_forB2JpsiX_NoMuonID( - kaons=make_detached_kaons_forB2JpsiX_NoMuonID, - name="bandq_detachedKK_forB2JpsiX_NoMuonID_{hash}", - descriptor='phi(1020) -> K+ K-', - am_max=2500 * MeV, - maxdocachi2=20., - m_max=2450. * MeV, - bpvdls_min=3): - - pvs = make_pvs() - - combination_code = F.require_all(F.MASS < am_max, - F.MAXSDOCACHI2CUT(maxdocachi2)) - - vertex_code = F.require_all(F.MASS < m_max, F.BPVDLS(pvs) > bpvdls_min) - - return ParticleCombiner( - name=name, - Inputs=[kaons(), kaons()], - DecayDescriptor=descriptor, - CombinationCut=combination_code, - CompositeCut=vertex_code) - - -@configurable -def make_detachedPhi_forB2JpsiX_NoMuonID( - KK_comb=make_detachedKK_forB2JpsiX_NoMuonID, - name="bandq_detachedPhi_forB2JpsiX_NoMuonID_{hash}", - # m_max=1300. * MeV): ?OK - CHI2DOF_max=12., - m_max=1100. * MeV, - PT_min=400. * MeV): - - code = F.require_all(F.MASS < m_max, F.PT > PT_min, F.CHI2DOF < CHI2DOF_max) - - return ParticleFilter(KK_comb(), name=name, Cut=F.FILTER(code)) - - -@configurable -def make_Jpsi_NoMuonID(muons=make_NoMuonID_muons, - name="bandq_Jpsi_NoMuonID_{hash}", - descriptor='J/psi(1S) -> mu+ mu-', - # am_min=2996. * MeV, - # am_max=3196. * MeV,?OK - am_min=2946. * MeV, - am_max=3246. * MeV, - apt_min=600 * MeV, - maxdocachi2=20., - # pt_min=1000 * MeV, ?OK - pt_min=1200 * MeV, - bpvdls_min=3, - CHI2DOF_max=16): - - pvs = make_pvs() - - combination_code = F.require_all( - in_range(am_min, F.MASS, am_max), F.MAXSDOCACHI2CUT(maxdocachi2), - (F.PT > apt_min), F.CHI2DOF<CHI2DOF_max) - - vertex_code = F.require_all( #remove mass cuts, add B-Jpsi mass cuts instead ?OK - (F.PT > pt_min), - F.BPVDLS(pvs) > bpvdls_min) - - return ParticleCombiner( - name=name, - Inputs=[muons(), muons()], - DecayDescriptor=descriptor, - CombinationCut=combination_code, - CompositeCut=vertex_code) - - -@configurable -def make_Bp2JpsiKp_NoMuonID(Jpsi=make_Jpsi_NoMuonID, - kaons=make_detached_kaons_forBp2JpsiKp_NoMuonID, - name="bandq_Bp2JpsiKp_NoMuonID_{hash}", - descriptor='[B+ -> J/psi(1S) K+]cc', - # am_min=5190. * MeV, - # am_max=5370. * MeV, ?OK - am_min=4950. * MeV, - am_max=5550. * MeV, - apt_min=1200 * MeV, - # m_min=5200. * MeV, - # m_max=5360. * MeV, - m_min=5000. * MeV, - m_max=5500. * MeV, - pt_min=1400 * MeV, - delta_m_min=2050*MeV,#?OK(also following 3 lines) - delta_m_max=2310*MeV, - bpv_dira_min=0.99985, # more severe - vtx_chi2pdof_max=12, - bpvltime_min=0.2 * picosecond): - - pvs = make_pvs() - - combination_code = F.require_all( - in_range(am_min, F.MASS, am_max), (F.PT > apt_min)) - - vertex_code = F.require_all( - in_range(m_min, F.MASS, m_max), F.CHI2DOF < vtx_chi2pdof_max, - (F.PT > pt_min), in_range(delta_m_min, F.MASS-F.CHILD(1,F.MASS), delta_m_max), - F.BPVLTIME(pvs) > bpvltime_min) - - return ParticleCombiner( - name=name, - Inputs=[Jpsi(), kaons()], - DecayDescriptor=descriptor, - CombinationCut=combination_code, - F.BPVDIRA(pvs) > bpv_dira_min, - CompositeCut=vertex_code) - - - -@configurable -def make_Bz2JpsiKst_NoMuonID(Jpsi=make_Jpsi_NoMuonID, - KPi_comb=make_detachedKst_forB2JpsiX_NoMuonID, - name="bandq_Bz2JpsiKst_NoMuonID_{hash}", - descriptor='[B0 -> K*(892)0 J/psi(1S)]cc', - am_min=4950. * MeV, - am_max=5550. * MeV, - apt_min=1200 * MeV, - m_min=5000. * MeV, - m_max=5500. * MeV, - pt_min=1400 * MeV, - delta_m_min=2050*MeV,#?OK (also following 3 lines) - delta_m_max=2310*MeV, - bpv_dira_min=0.9997, - vtx_chi2pdof_max=16, - bpvltime_min=0.2 * picosecond): - - pvs = make_pvs() - - combination_code = F.require_all( - in_range(am_min, F.MASS, am_max), (F.PT > apt_min)) - - vertex_code = F.require_all( - in_range(m_min, F.MASS, m_max), F.CHI2DOF < vtx_chi2pdof_max, - (F.PT > pt_min), in_range(delta_m_min, F.MASS-F.CHILD(1,F.MASS), delta_m_max), - F.BPVDIRA(pvs) > bpv_dira_min, - F.BPVLTIME(pvs) > bpvltime_min) - - return ParticleCombiner( - name=name, - Inputs=[KPi_comb(), Jpsi()], - DecayDescriptor=descriptor, - CombinationCut=combination_code, - CompositeCut=vertex_code) - - - - - -@configurable -def make_Bs2JpsiPhi_NoMuonID(Jpsi=make_Jpsi_NoMuonID, - KK_comb=make_detachedPhi_forB2JpsiX_NoMuonID, - name="bandq_Bs2JpsiPhi_NoMuonID_{hash}", - descriptor='B_s0 -> phi(1020) J/psi(1S)', - # am_min=5280. * MeV, - # am_max=5460. * MeV,?OK - am_min=5100. * MeV, - am_max=5640. * MeV, - apt_min=1200 * MeV, - # m_min=5290. * MeV, - # m_max=5450. * MeV, - m_min=5120. * MeV, - m_max=5620. * MeV, - pt_min=1400 * MeV, - vtx_chi2pdof_max=16, - delta_m_min=2150*MeV,#?OK - delta_m_max=2400*MeV, - bpv_dira_min=0.9997, - bpvltime_min=0.2 * picosecond): - - pvs = make_pvs() - - combination_code = F.require_all( - in_range(am_min, F.MASS, am_max), (F.PT > apt_min)) - - vertex_code = F.require_all( - in_range(m_min, F.MASS, m_max), F.CHI2DOF < vtx_chi2pdof_max, - (F.PT > pt_min), in_range(delta_m_min, F.MASS-F.CHILD(1,F.MASS), delta_m_max), - F.BPVDIRA(pvs) > bpv_dira_min, - F.BPVLTIME(pvs) > bpvltime_min) - - return ParticleCombiner( - name=name, - Inputs=[KK_comb(), Jpsi()], - DecayDescriptor=descriptor, - CombinationCut=combination_code, - CompositeCut=vertex_code) diff --git a/BandQ_MCBuds_NoMuonLines/allen_mc_hlt1_pp_matching_no_ut_1000KHz.py b/BandQ_MCBuds_NoMuonLines/allen_mc_hlt1_pp_matching_no_ut_1000KHz.py deleted file mode 100644 index 2244cc4819..0000000000 --- a/BandQ_MCBuds_NoMuonLines/allen_mc_hlt1_pp_matching_no_ut_1000KHz.py +++ /dev/null @@ -1,8 +0,0 @@ -from Moore import options, Options -from Moore.config import run_allen -from RecoConf.hlt1_allen import allen_gaudi_config as allen_sequence - -def main(options: Options, sequence : str = "hlt1_pp_matching_no_ut_1000KHz"): - with allen_sequence.bind(sequence=sequence): - return run_allen(options) - diff --git a/BandQ_MCBuds_NoMuonLines/dv_mc.py b/BandQ_MCBuds_NoMuonLines/dv_mc.py deleted file mode 100644 index 5422517d71..0000000000 --- a/BandQ_MCBuds_NoMuonLines/dv_mc.py +++ /dev/null @@ -1,64 +0,0 @@ -from .tupling_maker_new import mc_template, line_prefilter -from DaVinci import Options, make_config -# import yaml - -def Bz2JpsiKpPim_NoMuonID(options: Options): - decay_descriptor = { - "Bz": '[B0 -> (J/psi(1S) -> mu+ mu-) (K*(892)0 -> K+ pi-)]CC', - "Jpsi": '[B0 -> ^(J/psi(1S) -> mu+ mu-) (K*(892)0 -> K+ pi-)]CC', - "Kstar": '[B0 -> (J/psi(1S) -> mu+ mu-) ^(K*(892)0 -> K+ pi-)]CC', - "Kp": '[B0 -> (J/psi(1S) -> mu+ mu-) (K*(892)0 -> ^K+ pi-)]CC', - "pim": '[B0 -> (J/psi(1S) -> mu+ mu-) (K*(892)0 -> K+ ^pi-)]CC', - "mum": '[B0 -> (J/psi(1S) -> mu+ ^mu-) (K*(892)0 -> K+ pi-)]CC', - "mup": '[B0 -> (J/psi(1S) -> ^mu+ mu-) (K*(892)0 -> K+ pi-)]CC', - } - line_name = "Hlt2BandQ_Bz2JpsiKpPim_NoMuonID" - tuple_dir_name = "Bz2JpsiKpPim" - # with open("dv_Spruc.yaml", "r") as f: - # ANA_inpp = yaml.safe_load(f) - # decay_descriptor = ANA_inpp["decay_descriptor"] - # line_name = ANA_inpp["line_name"] - my_tuple = mc_template(decay_descriptor, line_name, True, [], ["Bz", "Jpsi", "Kstar"], ["Kp", "pim", "mup", "mum"],tuple_dir_name) - my_filter = line_prefilter(line_name) - return make_config(options, [my_filter, my_tuple]) - -def Bs2JpsiKpKm_NoMuonID(options: Options): - decay_descriptor = { - "Bs": '[B_s0 -> (J/psi(1S) -> mu+ mu-) (phi(1020) -> K+ K-)]CC', - "Jpsi": '[B_s0 -> ^(J/psi(1S) -> mu+ mu-) (phi(1020) -> K+ K-)]CC', - "phi": '[B_s0 -> (J/psi(1S) -> mu+ mu-) ^(phi(1020) -> K+ K-)]CC', - "Kp": '[B_s0 -> (J/psi(1S) -> mu+ mu-) (phi(1020) -> ^K+ K-)]CC', - "Km": '[B_s0 -> (J/psi(1S) -> mu+ mu-) (phi(1020) -> K+ ^K-)]CC', - "mum": '[B_s0 -> (J/psi(1S) -> mu+ ^mu-) (phi(1020) -> K+ K-)]CC', - "mup": '[B_s0 -> (J/psi(1S) -> ^mu+ mu-) (phi(1020) -> K+ K-)]CC', - } - line_name = "Hlt2BandQ_Bs2JpsiKpKm_NoMuonID" - tuple_dir_name = "Bs2JpsiKpKm" - # with open("dv_Spruc.yaml", "r") as f: - # ANA_inpp = yaml.safe_load(f) - # decay_descriptor = ANA_inpp["decay_descriptor"] - # line_name = ANA_inpp["line_name"] - # my_tuple = template(decay_descriptor, line_name, True, [], ["Bs", "Jpsi", "phi"], ["Kp", "Km", "mup","mum"]) - my_tuple = mc_template(decay_descriptor, line_name, True, [], ["Bs", "Jpsi", "phi"], ["Kp", "Km", "mup","mum"], tuple_dir_name) - my_filter = line_prefilter(line_name) - return make_config(options, [my_filter, my_tuple]) - -def Bp2JpsiKp_NoMuonID(options: Options): - decay_descriptor = { - "Bp": '[B+ -> (J/psi(1S) -> mu+ mu-) K+]CC', - "Jpsi": '[B+ -> ^(J/psi(1S) -> mu+ mu-) K+]CC', - "Kp": '[B+ -> (J/psi(1S) -> mu+ mu-) ^K+]CC', - "mum": '[B+ -> (J/psi(1S) -> mu+ ^mu-) K+]CC', - "mup": '[B+ -> (J/psi(1S) -> ^mu+ mu-) K+]CC', - } - line_name = "Hlt2BandQ_Bp2JpsiKp_NoMuonID" - tuple_dir_name = "Bp2JpsiKpKm" - # with open("dv_Spruc.yaml", "r") as f: - # ANA_inpp = yaml.safe_load(f) - # decay_descriptor = ANA_inpp["decay_descriptor"] - # line_name = ANA_inpp["line_name"] - my_tuple = mc_template(decay_descriptor, line_name, True, [], ["Bp", "Jpsi"], ["Kp", "mup","mum"], tuple_dir_name) - # my_tuple = template(decay_descriptor, line_name, True, [], ["Bp", "Jpsi"], ["Kp", "mup","mum"]) - my_filter = line_prefilter(line_name) - return make_config(options, [my_filter, my_tuple]) - diff --git a/BandQ_MCBuds_NoMuonLines/info.yaml b/BandQ_MCBuds_NoMuonLines/info.yaml deleted file mode 100644 index 8f6baea2be..0000000000 --- a/BandQ_MCBuds_NoMuonLines/info.yaml +++ /dev/null @@ -1,102 +0,0 @@ -defaults: - application: DaVinci/v64r6 - wg: BandQ - inform: - - sanqiang.qu@cern.ch - - mengzhen.wang@cern.ch - - jianqiao.wang@cern.ch - -# mc configuration -{%- set entrypoints = [ - ("Jpsi_NoMuonBp", "Bp2JpsiKp_NoMuonID", "12143001", "turbo", "TurboPass"), - ("Jpsi_NoMuonBs", "Bs2JpsiKpKm_NoMuonID", "13144011", "turbo", "TurboPass"), - ("Jpsi_NoMuonBz", "Bz2JpsiKpPim_NoMuonID", "11144001", "turbo", "TurboPass"), -]%} - -{%- set MC_conditions = [ - ("MagDown", "MagDown", "7.6", "7_6", "dddb-20240427", "sim10-2024.Q1.2-v1.1-md100", "24Q12", "2024", "2024.Q1.2", "Sim10d"), - ("MagDown", "MagDown", "4.3", "4_3", "dddb-20240427", "sim10-2024.Q1.2-v1.1-md100", "24Q12", "2024", "2024.Q1.2", "Sim10d"), - ("MagUp", "MagUp", "7.6", "7_6", "dddb-20240427", "sim10-2024.Q1.2-v1.1-mu100", "24Q12", "2024", "2024.Q1.2", "Sim10d"), - ("MagUp", "MagUp", "4.3", "4_3", "dddb-20240427", "sim10-2024.Q1.2-v1.1-mu100", "24Q12", "2024", "2024.Q1.2", "Sim10d"), -]%} - -{%- set hlt_conditions = [ - ("hlt1_pp_matching_no_ut_1000KHz", "hlt1v1"), -]%} - - -{%- set dv_platform_detdesc = "x86_64_v2-el9-gcc13+detdesc-opt" %} - - -{%- for module, channel, eventtype, fullturbo, dv_input_process in entrypoints %} - {%- for polarity_mc, polarity_mc_jobtitle, nu, n_u, dddb, conddb, mcversion_jobtitle, BKK_label1, BKK_label2, simversion in MC_conditions %} - {% for hlt1_condition, hlt1_condition_jobtitle in hlt_conditions %} - -MC_{{module}}_Nu{{n_u}}_{{polarity_mc_jobtitle}}_VPClose_{{mcversion_jobtitle}}_{{hlt1_condition_jobtitle}}_HLT1: - application: "Moore/v55r7@x86_64_v2-el9-gcc13+detdesc-opt" - input: - bk_query: "/MC/{{BKK_label1}}/Beam6800GeV-{{BKK_label2}}-{{ polarity_mc }}-Nu{{ nu }}-25ns-Pythia8/{{simversion}}/{{ eventtype }}/DIGI" - dq_flags: - - OK - keep_running: true - n_test_lfns: 1 - output: QQbar2mumu_MC24_HLT1.DST - options: - entrypoint: BandQ_MCBuds_NoMuonLines.allen_mc_{{hlt1_condition}}:main - extra_options: - input_raw_format: 0.5 - conddb_tag: {{ conddb }} - dddb_tag: {{ dddb }} - input_type: "ROOT" - output_type: "ROOT" - simulation: True - data_type: "Upgrade" - scheduler_legacy_mode: False - compression: - algorithm: ZSTD - level: 1 - max_buffer_size: 1048576 - -MC_{{module}}_Nu{{n_u}}_{{polarity_mc_jobtitle}}_VPClose_{{mcversion_jobtitle}}_{{hlt1_condition_jobtitle}}_HLT2: - application: "Moore/v55r7@x86_64_v2-el9-gcc13+detdesc-opt" - input: - job_name: MC_{{module}}_Nu{{n_u}}_{{polarity_mc_jobtitle}}_VPClose_{{mcversion_jobtitle}}_{{hlt1_condition_jobtitle}}_HLT1 - output: QQbar2mumu_MC24_HLT2_{{fullturbo}}.DST - options: - entrypoint: BandQ_MCBuds_NoMuonLines.moore_mc_{{fullturbo}}:main - extra_options: - conddb_tag: {{ conddb }} - dddb_tag: {{ dddb }} - input_type: "ROOT" - input_raw_format: 0.5 - output_type: "ROOT" - simulation: True - data_type: "Upgrade" - scheduler_legacy_mode: False - compression: - algorithm: ZSTD - level: 1 - max_buffer_size: 1048576 - - -MC_{{module}}_Nu{{n_u}}_{{polarity_mc_jobtitle}}_VPClose_{{mcversion_jobtitle}}_{{hlt1_condition_jobtitle}}_ROOT: - application: "DaVinci/v64r6@{{ dv_platform_detdesc }}" - input: - job_name: MC_{{module}}_Nu{{n_u}}_{{polarity_mc_jobtitle}}_VPClose_{{mcversion_jobtitle}}_{{hlt1_condition_jobtitle}}_HLT2 - output: QQbar2mumu_MC24_tuple.ROOT - options: - entrypoint: BandQ_MCBuds_NoMuonLines.dv_mc:{{channel}} - extra_options: - input_raw_format: 0.5 - dddb_tag: {{ dddb }} - conddb_tag: {{ conddb }} - input_type: ROOT - simulation: True - data_type: "Upgrade" - input_process: "Hlt2" - input_stream: "bandq" - - - {%- endfor %} - {%- endfor %} -{%- endfor %} diff --git a/BandQ_MCBuds_NoMuonLines/moore_mc_turbo.py b/BandQ_MCBuds_NoMuonLines/moore_mc_turbo.py deleted file mode 100644 index f6b756e31c..0000000000 --- a/BandQ_MCBuds_NoMuonLines/moore_mc_turbo.py +++ /dev/null @@ -1,74 +0,0 @@ -from Moore import Options, run_moore -from RecoConf.global_tools import stateProvider_with_simplified_geom, trackMasterExtrapolator_with_simplified_geom -from RecoConf.reconstruction_objects import reconstruction -from RecoConf.hlt2_global_reco import reconstruction as hlt2_reconstruction, make_light_reco_pr_kf_without_UT -from RecoConf.hlt2_tracking import ( - make_TrackBestTrackCreator_tracks, - make_PrKalmanFilter_noUT_tracks, - make_PrKalmanFilter_Velo_tracks, - make_PrKalmanFilter_Seed_tracks, -) -from RecoConf.decoders import default_VeloCluster_source -from RecoConf.protoparticles import make_charged_protoparticles -from RecoConf.event_filters import require_gec -from Hlt2Conf.settings.defaults import get_default_hlt1_filter_code_for_hlt2 -from Moore.streams import Stream, Streams -from Hlt2Conf.lines.semileptonic import all_lines as full_lines # all full-stream lines -import sys - -from RecoConf.decoders import default_VeloCluster_source -from Moore.streams import Stream, Streams, DETECTORS -from Hlt2Conf.lines.charmonium_to_dimuon import JpsiToMuMu_line, Psi2SToMuMu_line -from Hlt2Conf.lines.rd.qqbar_to_ll import upsilon_to_mumu_line -from Hlt2Conf.lines.qee.dimuon_no_ip import dimuonnoip_massrange3_line, dimuonnoip_massrange4_line, dimuonnoip_massrange5_line -from Hlt2Conf.lines.bandq.hlt2_bandq import UpsilonToMuMuEMTF_line -from Hlt2Conf.lines.bandq import hlt2_turbo_lines as turbo_lines - -def make_streams(): - lines = [ - builder() for line_dict in [turbo_lines] - for builder in line_dict.values() - ] - streams = [ - # Stream( - # "full", - # lines=[builder() for builder in full_lines.values()], - # routing_bit=98, - # detectors=[] - # # detectors=DETECTORS - import from Moore.streams - # ), # Turbo or Full case - no detector raw banks, for TurCal add them as above. - # Add turbo lines as well if you like: - Stream( - "turbo", - lines = lines, - #lines=[dimuonnoip_massrange3_line(), dimuonnoip_massrange4_line(), dimuonnoip_massrange5_line(), JpsiToMuMu_line(), Psi2SToMuMu_line(), UpsilonToMuMuEMTF_line(), upsilon_to_mumu_line()], - routing_bit=99, - detectors=DETECTORS - ) - ] - return Streams(streams=streams) - -def main(options: Options): - public_tools = [ - trackMasterExtrapolator_with_simplified_geom(), - stateProvider_with_simplified_geom(), - ] - with reconstruction.bind(from_file=False), hlt2_reconstruction.bind(make_reconstruction=make_light_reco_pr_kf_without_UT),\ - require_gec.bind(skipUT=True),\ - default_VeloCluster_source.bind(bank_type="VPRetinaCluster"),\ - make_charged_protoparticles.bind(fill_probnn_defaults=True),\ - make_TrackBestTrackCreator_tracks.bind(max_ghost_prob=0.7, max_chi2ndof=sys.float_info.max),\ - make_PrKalmanFilter_Velo_tracks.bind(max_chi2ndof=5.),\ - make_PrKalmanFilter_noUT_tracks.bind(max_chi2ndof=4.),\ - make_PrKalmanFilter_Seed_tracks.bind(max_chi2ndof=6.),\ - get_default_hlt1_filter_code_for_hlt2.bind(code=r"Hlt1(?!PassthroughLargeEvent).*Decision"): - config = run_moore(options, make_streams, public_tools) -# with reconstruction.bind(from_file=False), hlt2_reconstruction.bind(make_reconstruction=make_light_reco_pr_kf_without_UT),\ -# require_gec.bind(skipUT=True),\ -# default_VeloCluster_source.bind(bank_type="VPRetinaCluster"),\ -# make_TrackBestTrackCreator_tracks.bind(max_ghost_prob=0.7, max_chi2ndof=sys.float_info.max),\ -# make_PrKalmanFilter_Velo_tracks.bind(max_chi2ndof=5.),\ -# make_PrKalmanFilter_noUT_tracks.bind(max_chi2ndof=4.),\ -# make_PrKalmanFilter_Seed_tracks.bind(max_chi2ndof=6.): -# config = run_moore(options, make_streams, public_tools) - return config diff --git a/BandQ_MCBuds_NoMuonLines/tupling_maker_new.py b/BandQ_MCBuds_NoMuonLines/tupling_maker_new.py deleted file mode 100644 index 89b05dd523..0000000000 --- a/BandQ_MCBuds_NoMuonLines/tupling_maker_new.py +++ /dev/null @@ -1,513 +0,0 @@ -############################################################################### -# (c) Copyright 2021-2022 CERN for the benefit of the LHCb Collaboration # -# # -# This software is distributed under the terms of the GNU General Public # -# Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". # -# # -# In applying this licence, CERN does not waive the privileges and immunities # -# granted to it by virtue of its status as an Intergovernmental Organization # -# or submit itself to any jurisdiction. # -############################################################################### -""" -Read an HLT2 file and create an ntuple with the new DaVinci configuration. -""" -import Functors as F -import FunTuple.functorcollections as FC -from FunTuple import FunctorCollection -from FunTuple import FunTuple_Particles as Funtuple -from PyConf.reading import get_particles, get_pvs, get_rec_summary -from DaVinci.algorithms import create_lines_filter -from DaVinciMCTools import MCTruthAndBkgCat -from FunTuple.functorcollections import MCHierarchy, MCPrimaries, MCPromptDecay, Kinematics, SelectionInfo, HltTisTos, MCVertexInfo, MCKinematics, ParticleID, EventInfo -from PyConf.reading import get_odin # get_decreports, -from DecayTreeFitter import DecayTreeFitter -from .make_dtf import * - -_basic = "basic" -_composite = "composite" -_toplevel = "toplevel" - -#def all_variables(pvs, dtf, mctruth, ptype, candidates=None, ftAlg=None): -def all_variables(pvs, mctruth, ptype, candidates=None, ftAlg=None): - """ - function that returns dictionary of functors that work. - - functors are listed in order of https://lhcbdoc.web.cern.ch/lhcbdoc/moore/master/selection/thor_functors_reference.html#module-Functo - """ - if ptype not in [_basic, _composite]: - Exception(f"I want {_basic} or {_composite}. Got {ptype}") - all_vars = FunctorCollection({}) - - comp = _composite == ptype or _toplevel == ptype # is composite - basic = _basic == ptype # is not composite - top = _toplevel == ptype # the B - - # First import everything that comes in functorcollections - all_vars += FC.Kinematics() - if basic: - all_vars += FC.ParticleID(extra_info=True) - all_vars += FC.MCKinematics(mctruth_alg=mctruth) - all_vars += FC.MCHierarchy(mctruth_alg=mctruth) - #all_vars += FC.MCPrimaryVertexInfo(mctruth_alg=mctruth) - #Hlt1_decisions = ["Hlt1TrackMVADecision", "Hlt1TwoTrackMVADecision"] - #if candidates: - #all_vars += FC.HltTisTos( - #selection_type="Hlt", trigger_lines=Hlt1_decisions, data=candidates - #) - #if comp: - # all_vars += FC.MCVertexInfo(mctruth_alg=mctruth) - #if top: - # all_vars += FC.MCPromptDecay(mctruth_alg=mctruth) - - # - # FTAlg not yet implemented - # For Track isolation see weightedrelations_trackvariables - # - # Now all other functors - - # ALL : Not useful for tupling - - if comp: - all_vars.update({"ALV": F.ALV(Child1=1, Child2=2)}) - - all_vars.update({"BKGCAT": mctruth.BkgCat}) - - if comp: # all these require a vertex - all_vars.update({"BPVCORRM": F.BPVCORRM(pvs)}) - all_vars.update({"BPVCORRMERR": F.BPVCORRMERR(pvs)}) - all_vars.update({"BPVDIRA": F.BPVDIRA(pvs)}) - all_vars.update({"BPVDLS": F.BPVDLS(pvs)}) - all_vars.update({"BPVETA": F.BPVETA(pvs)}) - all_vars.update({"BPVFD": F.BPVFD(pvs)}) - all_vars.update({"BPVFDCHI2": F.BPVFDCHI2(pvs)}) - all_vars.update({"BPVFDIR": F.BPVFDIR(pvs)}) - all_vars.update({"BPVFDVEC": F.BPVFDVEC(pvs)}) - - all_vars.update({"BPVIP": F.BPVIP(pvs)}) - all_vars.update({"BPVIPCHI2": F.BPVIPCHI2(pvs)}) - all_vars.update({"BPVX": F.BPVX(pvs)}) - all_vars.update({"BPVY": F.BPVY(pvs)}) - all_vars.update({"BPVZ": F.BPVZ(pvs)}) - # When storing variable length array one can - # give a custom branch name for the index. - # This can be achieved by enclosing custom index - # name within square brackets (see code below). - # The branch name ("nPV") will correspond to the - # index of the PV. If no index branch name given i.e. - # all_vars.update({ 'ALLPVX'] the default "indx" is used. - #all_vars.update({"ALLPVX[nPVs]": F.ALLPVX(pvs)}) - #all_vars.update({"ALLPVY[nPVs]": F.ALLPVY(pvs)}) - #all_vars.update({"ALLPVZ[nPVs]": F.ALLPVZ(pvs)}) - all_vars.update({"ALLPVX": F.ALLPVX(pvs)}) - all_vars.update({"ALLPVY": F.ALLPVY(pvs)}) - all_vars.update({"ALLPVZ": F.ALLPVZ(pvs)}) - - if comp: # all these require a vertex - #all_vars.update({"ALLPV_FD[nPVs]": F.ALLPV_FD(pvs)}) - #all_vars.update({"ALLPV_IP[nPVs]": F.ALLPV_IP(pvs)}) - all_vars.update({"ALLPV_FD": F.ALLPV_FD(pvs)}) - all_vars.update({"ALLPV_IP": F.ALLPV_IP(pvs)}) - all_vars.update({"BPVLTIME": F.BPVLTIME(pvs)}) - all_vars.update({"BPVVDRHO": F.BPVVDRHO(pvs)}) - all_vars.update({"BPVVDX": F.BPVVDX(pvs)}) - all_vars.update({"BPVVDY": F.BPVVDY(pvs)}) - all_vars.update({"BPVVDZ": F.BPVVDZ(pvs)}) - - all_vars.update({"CHARGE": F.CHARGE}) - all_vars.update({"CHI2": F.CHI2}) - all_vars.update({"CHI2DOF": F.CHI2DOF}) - if top: # apply this only to B - all_vars.update({"CHILD1_PT": F.CHILD(1, F.PT)}) # example of CHILD - all_vars.update({"Ds_END_VZ": F.CHILD(1, F.END_VZ)}) - all_vars.update({"Delta_END_VZ_DsB0": F.CHILD(1, F.END_VZ) - F.END_VZ}) - - # if basic: all_vars.update({ 'CLOSESTTOBEAM' : F.CLOSESTTOBEAM # 'Track__ClosestToBeamState' object has no attribute 'to_json' - # COMB - # if basic: all_vars.update({ 'COV' : F.COV # 'Track__Covariance' object has no attribute 'to_json' - - if comp: - all_vars.update({"DOCA": F.SDOCA(Child1=1, Child2=2)}) - all_vars.update({"DOCACHI2": F.SDOCACHI2(Child1=1, Child2=2)}) - all_vars.update({"END_VRHO": F.END_VRHO}) - all_vars.update({"END_VX": F.END_VX}) - all_vars.update({"END_VY": F.END_VY}) - all_vars.update({"END_VZ": F.END_VZ}) - - # duplicated from FC all_vars.update({"ENERGY" : F.ENERGY}) - all_vars.update({"ETA": F.ETA}) - all_vars.update({"FOURMOMENTUM": F.FOURMOMENTUM}) - all_vars.update({"ISBASIC": F.ISBASICPARTICLE}) - - if basic: - all_vars.update({"GHOSTPROB": F.GHOSTPROB}) - all_vars.update({"ISMUON": F.ISMUON}) - all_vars.update({"INMUON": F.INMUON}) - all_vars.update({"INECAL": F.INECAL}) - all_vars.update({"INHCAL": F.INHCAL}) - all_vars.update({"HASBREM": F.HASBREM}) - all_vars.update({"BREMENERGY": F.BREMENERGY}) - all_vars.update({"BREMBENDCORR": F.BREMBENDCORR}) - all_vars.update({"BREMPIDE": F.BREMPIDE}) - all_vars.update({"ECALPIDE": F.ECALPIDE}) - all_vars.update({"ECALPIDMU": F.ECALPIDMU}) - all_vars.update({"HCALPIDE": F.HCALPIDE}) - all_vars.update({"HCALPIDMU": F.HCALPIDMU}) - all_vars.update({"ELECTRONSHOWEREOP": F.ELECTRONSHOWEREOP}) - all_vars.update({"CLUSTERMATCH": F.CLUSTERMATCH_CHI2}) - all_vars.update({"ELECTRONMATCH": F.ELECTRONMATCH_CHI2}) - all_vars.update({"BREMHYPOMATCH": F.BREMHYPOMATCH_CHI2}) - all_vars.update({"ELECTRONENERGY": F.ELECTRONENERGY}) - all_vars.update({"BREMHYPOENERGY": F.BREMHYPOENERGY}) - all_vars.update({"BREMHYPODELTAX": F.BREMHYPODELTAX}) - all_vars.update({"ELECTRONID": F.ELECTRONID}) - all_vars.update({"HCALEOP": F.HCALEOP}) - # Note: the observables for the two functors below are (TRACK_MOM_X, TRACK_MOM_Y, TRACK_MOM_Z}) - # and (TRACK_POS_CLOSEST_TO_BEAM_X, TRACK_POS_CLOSEST_TO_BEAM_Y, TRACK_POS_CLOSEST_TO_BEAM_Z), - # which is why the trailing underscore in the name is added i.e. "TRACK_MOM_" and "TRACK_POS_CLOSEST_TO_BEAM_" - all_vars.update({"TRACK_MOM_": F.TRACK_MOMVEC}) - all_vars.update({"TRACK_POS_CLOSESTTOBEAM_": F.TRACK_POSVEC_CLOSESTTOBEAM}) - - all_vars.update({"IS_ABS_ID_pi": F.IS_ABS_ID("pi+")}) - all_vars.update({"IS_ID_pi": F.IS_ID("pi-")}) - all_vars.update({"PDG_MASS_pi": F.PDG_MASS("pi+")}) - all_vars.update({"SIGNED_DELTA_MASS_pi": F.SIGNED_DELTA_MASS("pi+")}) - all_vars.update({"ABS_DELTA_MASS_pi": F.ABS_DELTA_MASS("pi+")}) - all_vars.update({"IS_NOT_H": F.IS_NOT_H}) - all_vars.update({"IS_PHOTON": F.IS_PHOTON}) - - #if dtf: - # all_vars.update({"DTF_PT": dtf(F.PT)}) - # all_vars.update({"DTF_BPVIPCHI2": dtf(F.BPVIPCHI2(pvs))}) - - #if top and dtf: - # all_vars.update({"DTF_NITER": dtf.NITER}) - # all_vars.update({"DTF_CHI2": dtf.CHI2}) - # all_vars.update({"DTF_NDOF": dtf.NDOF}) - # all_vars.update({"DTF_CHI2DOF": dtf.CHI2DOF}) - - #if comp and dtf: - # all_vars.update({"DTF_MASS": dtf.MASS}) - # all_vars.update({"DTF_MASSERR": dtf.MASSERR}) - # all_vars.update({"DTF_P": dtf.P}) - # all_vars.update({"DTF_PERR": dtf.PERR}) - # all_vars.update({"DTF_TAU": dtf.TAU}) - # all_vars.update({"DTF_TAUERR": dtf.TAUERR}) - # all_vars.update({"DTF_FD": dtf.FD}) - # all_vars.update({"DTF_FDERR": dtf.FDERR}) - - all_vars.update({"MASS": F.MASS}) - #if top: # B - # all_vars.update({"MASSWITHHYPOTHESES": F.MASSWITHHYPOTHESES((939.0, 939.0))}) - #elif comp: # Ds - # all_vars.update( - # {"MASSWITHHYPOTHESES": F.MASSWITHHYPOTHESES((493.7, 493.7, 139.6))} - # ) - if comp: - all_vars.update({"MAXPT": F.MAX(F.PT)}) - all_vars.update({"MAXDOCA": F.MAXSDOCA}) - all_vars.update({"MAXDOCACHI2": F.MAXSDOCACHI2}) - # the above in cut versions. - - # duplicated from FC all_vars.update({ 'MC_MOTHER_ID' : F.VALUE_OR(0) @ mctruth( - # duplicated from FC F.MC_MOTHER(1, F.PARTICLE_ID))}) - - if comp: - all_vars.update({"MINPT": F.MIN(F.PT)}) - all_vars.update({"MINIP": F.MINIP(pvs)}) - all_vars.update({"MINIPCHI2": F.MINIPCHI2(pvs)}) - - if basic: - all_vars.update({"TRACKPT": F.TRACK_PT}) - all_vars.update({"TRACKHISTORY": F.VALUE_OR(-1) @ F.TRACKHISTORY @ F.TRACK}) - all_vars.update({"QOVERP": F.QOVERP @ F.TRACK}) - all_vars.update({"NDOF": F.VALUE_OR(-1) @ F.NDOF @ F.TRACK}) - all_vars.update({"NFTHITS": F.VALUE_OR(-1) @ F.NFTHITS @ F.TRACK}) - all_vars.update({"NHITS": F.VALUE_OR(-1) @ F.NHITS @ F.TRACK}) - all_vars.update({"NUTHITS": F.VALUE_OR(-1) @ F.NUTHITS @ F.TRACK}) - all_vars.update({"NVPHITS": F.VALUE_OR(-1) @ F.NVPHITS @ F.TRACK}) - all_vars.update({"TRACKHASVELO": F.VALUE_OR(-1) @ F.TRACKHASVELO @ F.TRACK}) - all_vars.update({"TRACKHASUT": F.VALUE_OR(-1) @ F.TRACKHASUT @ F.TRACK}) - - all_vars.update({"OBJECT_KEY": F.OBJECT_KEY}) - - # duplicated from FC all_vars.update({ 'ORIGIN_VX' : mctruth(F.ORIGIN_VX) }) - # duplicated from FC all_vars.update({ 'ORIGIN_VY' : mctruth(F.ORIGIN_VY) }) - # duplicated from FC all_vars.update({ 'ORIGIN_VZ' : mctruth(F.ORIGIN_VZ) }) - - # duplicated from FC all_vars.update({"P" : F.P}) - # duplicated from FC all_vars.update({"PARTICLE_ID" : F.PARTICLE_ID}) - all_vars.update({"PHI": F.PHI}) - - # duplicated from FC if basic: - # duplicated from FC all_vars.update({"PID_E" : F.PID_E}) - # duplicated from FC all_vars.update({"PID_K" : F.PID_K}) - # duplicated from FC all_vars.update({"PID_MU" : F.PID_MU}) - # duplicated from FC all_vars.update({"PID_P" : F.PID_P}) - # duplicated from FC all_vars.update({"PID_PI" : F.PID_PI}) - # duplicated from FC #all_vars.update({"PROBNN_D" : F.PROBNN_D}) - # duplicated from FC all_vars.update({"PROBNN_E" : F.PROBNN_E}) - # duplicated from FC all_vars.update({"PROBNN_GHOST" : F.PROBNN_GHOST}) - # duplicated from FC all_vars.update({"PROBNN_K" : F.PROBNN_K}) - # duplicated from FC all_vars.update({"PROBNN_MU" : F.PROBNN_MU}) - # duplicated from FC all_vars.update({"PROBNN_P" : F.PROBNN_P}) - # duplicated from FC all_vars.update({"PROBNN_PI" : F.PROBNN_PI}) - - # duplicated from FC all_vars.update({ 'PT' : F.PT }) - # duplicated from FC all_vars.update({ 'PX' : F.PX }) - # duplicated from FC all_vars.update({ 'PY' : F.PY }) - # duplicated from FC all_vars.update({ 'PZ' : F.PZ }) - all_vars.update({"ABS_PX": F.ABS @ F.PX}) - - all_vars.update({"REFERENCEPOINT_X": F.REFERENCEPOINT_X}) - all_vars.update({"REFERENCEPOINT_Y": F.REFERENCEPOINT_Y}) - all_vars.update({"REFERENCEPOINT_Z": F.REFERENCEPOINT_Z}) - - if comp: - all_vars.update({"SDOCA": F.SDOCA(1, 2)}) - all_vars.update({"SDOCACHI2": F.SDOCACHI2(1, 2)}) - if basic: - all_vars.update({"SHOWER_SHAPE": F.CALO_NEUTRAL_SHOWER_SHAPE}) - - if comp: - all_vars.update({"SUBCOMB12_MM": F.SUBCOMB(Functor=F.MASS, Indices=(1, 2))}) - all_vars.update({"SUMPT": F.SUM(F.PT)}) - - if basic: - all_vars.update({"TX": F.TX}) - all_vars.update({"TY": F.TY}) - - print(f"### For {ptype} returning variables {all_vars.functor_dict.keys()}") - return all_vars - - -def event_variables(PVs, ODIN, decreports, lines, hlt1lines): - """ - event variables - """ - - evt_vars = FunctorCollection({}) - evt_vars += FC.EventInfo() - - evt_vars += FC.SelectionInfo(selection_type="Hlt2", trigger_lines=lines) - evt_vars += FC.SelectionInfo(selection_type="Hlt1", trigger_lines=hlt1lines) - # duplicated from FC if ODIN: - # duplicated from FC evt_vars.update({ 'BUNCHCROSSING_ID' : F.BUNCHCROSSING_ID(ODIN) }) - # duplicated from FC evt_vars.update({ 'BUNCHCROSSING_TYPE' : F.BUNCHCROSSING_TYPE(ODIN) }) - - if decreports: - evt_vars.update( - { - "DECISIONS": F.DECISIONS( - Lines=[bd2dsk_line + "Decision"], DecReports=decreports - ) - } - ) - evt_vars.update( - { - "DECREPORTS_FILTER": F.DECREPORTS_FILTER( - Lines=[bd2dsk_line + "Decision"], DecReports=decreports - ) - } - ) - - if ODIN: - evt_vars.update({"EVENTTYPE": F.EVENTTYPE(ODIN)}) - - # duplicated from FC evt_vars.update({ 'GPSTIME' : F.GPSTIME(ODIN) }) - # duplicated from FC evt_vars.update({ 'ODINTCK' : F.ODINTCK(ODIN) }) - - evt_vars.update({"PV_SIZE": F.SIZE(PVs)}) - # duplicated from FC evt_vars.update({ 'GPSTIME' : F.GPSTIME(ODIN) }) - # duplicated from FC evt_vars.update({ 'ODINTCK' : F.ODINTCK(ODIN) }) - - if decreports: - evt_vars.update({"TCK": F.TCK(decreports)}) - - print(f"### For event returning variables {evt_vars.functor_dict.keys()}") - return evt_vars - - -def mc_template(decay_descriptor, line_name, isturbo, Hlt2_decisions, composite_particles, daughter_particles, tuple_dir_name): - evtpath_prefix = "/Event/Spruce/" - if isturbo: - evtpath_prefix = "/Event/HLT2/" - - QQbar2mumu_data = get_particles(evtpath_prefix+f"{line_name}/Particles") - - pvs = get_pvs() - - Hlt1_decisions = [ -# Global line - "Hlt1GlobalDecision", "Hlt1PhysDecision", -# Physics lines - "Hlt1TrackMVADecision", "Hlt1TwoTrackMVADecision", "Hlt1D2KKDecision", "Hlt1D2KPiDecision", "Hlt1D2PiPiDecision", "Hlt1Dst2D0PiDecision", "Hlt1KsToPiPiDecision", "Hlt1KsToPiPiDoubleMuonMisIDDecision", "Hlt1TwoTrackKsDecision", "Hlt1TwoKsDecision", "Hlt1LambdaLLDetachedTrackDecision", "Hlt1XiOmegaLLLDecision", "Hlt1SingleHighPtMuonDecision", "Hlt1SingleHighPtMuonNoMuIDDecision", "Hlt1DiMuonHighMassDecision", "Hlt1DiMuonDisplacedDecision", "Hlt1DiMuonSoftDecision", "Hlt1TrackMuonMVADecision", "Hlt1DiMuonNoIP_SSDecision", "Hlt1DiMuonDrellYan_VLowMassDecision", "Hlt1DiMuonDrellYan_VLowMass_SSDecision", "Hlt1DiMuonDrellYanDecision", "Hlt1DiMuonDrellYan_SSDecision", "Hlt1DetJpsiToMuMuPosTagLineDecision", "Hlt1DetJpsiToMuMuNegTagLineDecision", "Hlt1TrackElectronMVADecision", "Hlt1SingleHighPtElectronDecision", "Hlt1DiElectronDisplacedDecision", "Hlt1SingleHighEtDecision", "Hlt1DiPhotonHighMassDecision", "Hlt1Pi02GammaGammaDecision", "Hlt1DiElectronHighMass_SSDecision", "Hlt1DiElectronHighMassDecision", "Hlt1DiMuonNoIPDecision" -## alignment lines -# "Hlt1RICH1AlignmentDecision", "Hlt1RICH2AlignmentDecision", "Hlt1D2KPiAlignmentDecision", "Hlt1Dst2D0PiAlignmentDecision", "Hlt1MaterialVertexSeedsDownstreamzDecision", "Hlt1MaterialVertexSeeds_DWFSDecision", "Hlt1DiMuonHighMassAlignmentDecision", "Hlt1DiMuonJpsiMassAlignmentDecision", "Hlt1OneMuonTrackLineDecision", "Hlt1BeamGasDecision", -## smog2 lines -# "Hlt1SMOG2D2KpiDecision", "Hlt1VeloMicroBiasDecision", "Hlt1SMOG2etacToppDecision", "Hlt1SMOG2KsTopipiDecision", "Hlt1SMOG2etacToppDecision", "Hlt1SMOG2KsTopipiDecision", "Hlt1SMOG22BodyGenericDecision", "Hlt1SMOG22BodyGenericLowPtDecision", "Hlt1SMOG2SingleTrackVeryHighPtDecision", "Hlt1SMOG2SingleTrackHighPtDecision", "Hlt1SMOG2DiMuonHighMassDecision", "Hlt1SMOG2SingleMuonDecision", "Hlt1SMOG2L0ToppiDecision", -## bgi lines -# "Hlt1BGIPseudoPVsNoBeamDecision", "Hlt1BGIPseudoPVsBeamOneDecision", "Hlt1BGIPseudoPVsBeamTwoDecision", "Hlt1BGIPseudoPVsUpBeamBeamDecision", "Hlt1BGIPseudoPVsDownBeamBeamDecision", "Hlt1BGIPseudoPVsIRBeamBeamDecision", "Hlt1BGIPVsCylNoBeamDecision", "Hlt1BGIPVsCylBeamOneDecision", "Hlt1BGIPVsCylBeamTwoDecision", "Hlt1BGIPVsCylUpBeamBeamDecision", "Hlt1BGIPVsCylDownBeamBeamDecision", "Hlt1BGIPVsCylIRBeamBeamDecision", "Hlt1BGIVeloClustersMicroBiasDecision", "Hlt1BGICaloDigitsDecision", "Hlt1BGIPlumeActivityDecision", -## setup hlt1 nodes lines -# "Hlt1ODINCalibDecision", "Hlt1TAEPassthroughDecision", "Hlt1ErrorBankDecision", "Hlt1VeloMicroBiasVeloClosingDecision", "Hlt1GECPassthroughDecision", "Hlt1SMOG2BENoBiasDecision", "Hlt1SMOG2PassThroughLowMult5Decision", "Hlt1SMOG2BELowMultElectronsDecision", "Hlt1SMOG2MinimumBiasDecision", "Hlt1PassthroughPVinSMOG2Decision" - ] - - - composite_variables = FunctorCollection({ - #"ID": F.PARTICLE_ID, - #"KEY": F.OBJECT_KEY, - #"PT": F.PT, - #"PX": F.PX, - #"PY": F.PY, - #"PZ": F.PZ, - #"ENERGY": F.ENERGY, - #"P": F.P, - #"M": F.MASS, - #"ETA": F.ETA, - #"PHI": F.PHI, - #"ENDVERTEX_CHI2NDOF": F.CHI2DOF, - #"FOURMOMENTUM": F.FOURMOMENTUM, - #"BPVDIRA": F.BPVDIRA(pvs), - #"BPVX": F.BPVX(pvs), - #"BPVY": F.BPVY(pvs), - #"BPVZ": F.BPVZ(pvs), - #"END_VX": F.END_VX, - #"END_VY": F.END_VY, - #"END_VZ": F.END_VZ, - "END_VZ_ERR":F.SQRT @ F.CALL(2,2) @ F.POS_COV_MATRIX @ F.ENDVERTEX, - "END_VY_ERR":F.SQRT @ F.CALL(1,1) @ F.POS_COV_MATRIX @ F.ENDVERTEX, - "END_VX_ERR":F.SQRT @ F.CALL(0,0) @ F.POS_COV_MATRIX @ F.ENDVERTEX, - "BPVZ_ERR": F.SQRT @ F.CALL(2,2) @ F.POS_COV_MATRIX @ F.BPV(pvs), - "BPVY_ERR": F.SQRT @ F.CALL(1,1) @ F.POS_COV_MATRIX @ F.BPV(pvs), - "BPVX_ERR": F.SQRT @ F.CALL(0,0) @ F.POS_COV_MATRIX @ F.BPV(pvs), - #"TAU": F.BPVLTIME(pvs), - #"BPVFDCHI2": F.BPVFDCHI2(pvs), - #"BPVIPCHI2": F.BPVIPCHI2(pvs) - }) - - #composite_variables += Kinematics() - #composite_variables += ParticleID(extra_info=True) - composite_variables += HltTisTos( selection_type="Hlt1", trigger_lines=Hlt1_decisions, data=QQbar2mumu_data) - if not isturbo: - composite_variables += HltTisTos( selection_type="Hlt2", trigger_lines=Hlt2_decisions, data=QQbar2mumu_data) - - daughter_variables = FunctorCollection({ - #"ID": F.PARTICLE_ID, - #"PT": F.PT, - #"PX": F.PX, - #"PY": F.PY, - #"PZ": F.PZ, - #"M": F.MASS, - #"ENERGY": F.ENERGY, - #"P": F.P, - #"ETA": F.ETA, - #"PHI": F.PHI, - #"Track_CHI2NDOF": F.CHI2DOF, - #"ProbNNmu": F.PROBNN_MU, - #"PIDmu": F.PID_MU, - #"IsMuon": F.ISMUON, - #"GhostProb": F.GHOSTPROB, - #"FOURMOMENTUM": F.FOURMOMENTUM, - "PERR": F.SQRT @ F.PERR2, - "PZERR": F.SQRT @ F.CALL(2,2) @ F.THREE_MOM_COV_MATRIX, - }) - - #daughter_variables += Kinematics() - #daughter_variables += ParticleID(extra_info=True) - -# line_prefilter = create_lines_filter(name=f"HLT_PASS{line_name}", lines=[line_name]) - - #define event level variables - odin = get_odin() - decreports = None - rec_sum=get_rec_summary() - event_info = event_variables(pvs, odin, decreports, [line_name], Hlt1_decisions) + FunctorCollection({ - "nPVs": F.VALUE_OR(-1) @F.RECSUMMARY_INFO(rec_sum,"nPVs"), - "nTracks": F.VALUE_OR(-1) @F.RECSUMMARY_INFO(rec_sum,"nTracks"), - "nLongTracks": F.VALUE_OR(-1) @F.RECSUMMARY_INFO(rec_sum,"nLongTracks"), - "nDownstreamTracks": F.VALUE_OR(-1) @F.RECSUMMARY_INFO(rec_sum,"nDownstreamTracks"), - "nUpstreamTracks": F.VALUE_OR(-1) @F.RECSUMMARY_INFO(rec_sum,"nUpstreamTracks"), - "nVeloTracks": F.VALUE_OR(-1) @F.RECSUMMARY_INFO(rec_sum,"nVeloTracks"), - "nBackTracks": F.VALUE_OR(-1) @F.RECSUMMARY_INFO(rec_sum,"nBackTracks"), - "nGhosts": F.VALUE_OR(-1) @F.RECSUMMARY_INFO(rec_sum,"nGhosts"), - "nRich1Hits": F.VALUE_OR(-1) @F.RECSUMMARY_INFO(rec_sum,"nRich1Hits"), - "nRich2Hits": F.VALUE_OR(-1) @F.RECSUMMARY_INFO(rec_sum,"nRich2Hits"), - "nVeloClusters": F.VALUE_OR(-1) @F.RECSUMMARY_INFO(rec_sum,"nVeloClusters"), - "nVPClusters": F.VALUE_OR(-1) @F.RECSUMMARY_INFO(rec_sum,"nVPClusters"), - "nITClusters": F.VALUE_OR(-1) @F.RECSUMMARY_INFO(rec_sum,"nITClusters"), - "nTTClusters": F.VALUE_OR(-1) @F.RECSUMMARY_INFO(rec_sum,"nTTClusters"), - "nUTClusters": F.VALUE_OR(-1) @F.RECSUMMARY_INFO(rec_sum,"nUTClusters"), - "nOTClusters": F.VALUE_OR(-1) @F.RECSUMMARY_INFO(rec_sum,"nOTClusters"), - "nFTClusters": F.VALUE_OR(-1) @F.RECSUMMARY_INFO(rec_sum,"nFTClusters"), - "nSPDhits": F.VALUE_OR(-1) @F.RECSUMMARY_INFO(rec_sum,"nSPDhits"), - "eCalTot": F.VALUE_OR(-1) @F.RECSUMMARY_INFO(rec_sum,"eCalTot"), - "hCalTot": F.VALUE_OR(-1) @F.RECSUMMARY_INFO(rec_sum,"hCalTot"), - "nEcalClusters": F.VALUE_OR(-1) @F.RECSUMMARY_INFO(rec_sum,"nEcalClusters"), - "nMuonCoordsS0": F.VALUE_OR(-1) @F.RECSUMMARY_INFO(rec_sum,"nMuonCoordsS0"), - "nMuonCoordsS1": F.VALUE_OR(-1) @F.RECSUMMARY_INFO(rec_sum,"nMuonCoordsS1"), - "nMuonCoordsS2": F.VALUE_OR(-1) @F.RECSUMMARY_INFO(rec_sum,"nMuonCoordsS2"), - "nMuonCoordsS3": F.VALUE_OR(-1) @F.RECSUMMARY_INFO(rec_sum,"nMuonCoordsS3"), - "nMuonCoordsS4": F.VALUE_OR(-1) @F.RECSUMMARY_INFO(rec_sum,"nMuonCoordsS4"), - "nMuonTracks": F.VALUE_OR(-1) @F.RECSUMMARY_INFO(rec_sum,"nMuonTracks"), - "ALLPVX": F.ALLPVX(pvs), - "ALLPVY": F.ALLPVY(pvs), - "ALLPVZ": F.ALLPVZ(pvs), - }) - - # get trueid bkgcat info - MC_TRUTH = MCTruthAndBkgCat(QQbar2mumu_data, name='MCTruthAndBkgCat_'+line_name) - MCMOTHER_ID = lambda n: F.VALUE_OR(0) @ MC_TRUTH(F.MC_MOTHER(n, F.PARTICLE_ID)) - MCMOTHER_KEY = lambda n: F.VALUE_OR(-1) @ MC_TRUTH(F.MC_MOTHER(n, F.OBJECT_KEY)) - - trueid_bkgcat_info = FunctorCollection({ - #"TRUEID": F.VALUE_OR(0) @ MC_TRUTH(F.PARTICLE_ID), - "TRUEKEY": F.VALUE_OR(-1) @ MC_TRUTH(F.OBJECT_KEY), - #"TRUEPT": MC_TRUTH(F.PT), - #"TRUEPX": MC_TRUTH(F.PX), - #"TRUEPY": MC_TRUTH(F.PY), - #"TRUEPZ": MC_TRUTH(F.PZ), - #"TRUEENERGY": MC_TRUTH(F.ENERGY), - #"TRUEP": MC_TRUTH(F.P), - "TRUEM": MC_TRUTH(F.MASS), - "TRUEETA": MC_TRUTH(F.ETA), - "TRUEPHI": MC_TRUTH(F.PHI), - "TRUEFOURMOMENTUM": MC_TRUTH(F.FOURMOMENTUM), - #"MC_MOTHER_ID": MCMOTHER_ID(1), - #"MC_MOTHER_KEY": MCMOTHER_KEY(1), - #"MC_GD_MOTHER_ID": MCMOTHER_ID(2), - #"MC_GD_MOTHER_KEY": MCMOTHER_KEY(2), - #"MC_GD_GD_MOTHER_ID": MCMOTHER_ID(3), - #"MC_GD_GD_MOTHER_KEY": MCMOTHER_KEY(3), - "TRUEORIGIN_VX": MC_TRUTH(F.ORIGIN_VX), - "TRUEORIGIN_VY": MC_TRUTH(F.ORIGIN_VY), - "TRUEORIGIN_VZ": MC_TRUTH(F.ORIGIN_VZ), - #"TRUEEND_VX": MC_TRUTH(F.END_VX), - #"TRUEEND_VY": MC_TRUTH(F.END_VY), - #"TRUEEND_VZ": MC_TRUTH(F.END_VZ), - "BKGCAT": MC_TRUTH.BkgCat, - }) - - variables = { - "QQbar": composite_variables + all_variables(pvs, MC_TRUTH, _composite) + trueid_bkgcat_info , - "mup": daughter_variables + all_variables(pvs, MC_TRUTH, _basic) + trueid_bkgcat_info, - "mum": daughter_variables + all_variables(pvs, MC_TRUTH, _basic) + trueid_bkgcat_info, - } - variables = {} - for composite_particle in composite_particles: - variables[composite_particle] = composite_variables + all_variables(pvs, MC_TRUTH, _composite)+ trueid_bkgcat_info + make_dtf_variables(pvs, QQbar2mumu_data, _composite) - for daughter_particle in daughter_particles: - variables[daughter_particle] = daughter_variables + all_variables(pvs, MC_TRUTH, _basic)+ trueid_bkgcat_info+ make_dtf_variables(pvs, QQbar2mumu_data, _basic) - #define FunTuple instance - my_tuple = Funtuple( - name=tuple_dir_name, - tuple_name="DecayTree", - fields=decay_descriptor, - variables=variables, - event_variables=event_info, - store_multiple_cand_info = True, - inputs=QQbar2mumu_data) - - return my_tuple - -def line_prefilter(line_name): - return create_lines_filter(name=f"HLT_PASS{line_name}", lines=[line_name]) - -- GitLab From d6c1183a66946e55582faf5106df9cd56b866b64 Mon Sep 17 00:00:00 2001 From: yuc <yuc@cern.ch> Date: Sat, 26 Oct 2024 17:05:58 +0800 Subject: [PATCH 12/15] change-DaVCinci-version --- BandQ_Bp2JpsiKp_MuonID_NoMuonID_Lines/info.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/BandQ_Bp2JpsiKp_MuonID_NoMuonID_Lines/info.yaml b/BandQ_Bp2JpsiKp_MuonID_NoMuonID_Lines/info.yaml index 200789a1c9..ecc1cdd07c 100644 --- a/BandQ_Bp2JpsiKp_MuonID_NoMuonID_Lines/info.yaml +++ b/BandQ_Bp2JpsiKp_MuonID_NoMuonID_Lines/info.yaml @@ -1,6 +1,6 @@ {%- set dv_platform_detdesc = "x86_64_v2-el9-clang16-opt" %} defaults: - application: "DaVinci/v64r9" + application: "DaVinci/v64r10" wg: BandQ inform: - yuc@cern.ch @@ -16,7 +16,7 @@ defaults: {%- for data, Type, wg, decay, polarity, Velo, process, stream in datasets %} data_{{decay}}_{{wg}}_c4_{{Velo}}_WithUT_{{polarity}}: - application: "DaVinci/v64r9@{{dv_platform_detdesc}}" + application: "DaVinci/v64r10@{{dv_platform_detdesc}}" input: bk_query: "/LHCb/{{data}}/Beam6800GeV-{{Velo}}-{{polarity}}/Real Data/{{Type}}/{{wg}}.DST" dq_flags: -- GitLab From 3530a69f1d879424492e1bf7cf56ea2cd4b5a9c9 Mon Sep 17 00:00:00 2001 From: yuc <yuc@cern.ch> Date: Thu, 21 Nov 2024 01:13:40 +0800 Subject: [PATCH 13/15] Add_Muon_Information --- BandQ_Bp2JpsiKp_MuonID_NoMuonID_Lines/info.yaml | 4 +++- BandQ_Bp2JpsiKp_MuonID_NoMuonID_Lines/tupling_maker.py | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/BandQ_Bp2JpsiKp_MuonID_NoMuonID_Lines/info.yaml b/BandQ_Bp2JpsiKp_MuonID_NoMuonID_Lines/info.yaml index ecc1cdd07c..e5d539131d 100644 --- a/BandQ_Bp2JpsiKp_MuonID_NoMuonID_Lines/info.yaml +++ b/BandQ_Bp2JpsiKp_MuonID_NoMuonID_Lines/info.yaml @@ -8,14 +8,16 @@ defaults: # data configuration {%- set datasets = [ ('Collision24', 'Sprucing24c4/94000000', 'BANDQ', 'B2JpsiX_pmTag_NoMuonID', 'MagDown', 'VeloClosed', 'TurboPass', 'bandq'), + ('Collision24', 'Sprucing24c3/94000000', 'BANDQ', 'B2JpsiX_pmTag_NoMuonID', 'MagDown', 'VeloClosed', 'TurboPass', 'bandq'), ('Collision24', 'Sprucing24c4/94000000', 'BANDQ', 'B2JpsiX_pmTag_NoMuonID', 'MagUp', 'VeloClosed', 'TurboPass', 'bandq'), + ('Collision24', 'Sprucing24c3/94000000', 'BANDQ', 'B2JpsiX_pmTag_NoMuonID', 'MagUp', 'VeloClosed', 'TurboPass', 'bandq'), ]%} {%- for data, Type, wg, decay, polarity, Velo, process, stream in datasets %} -data_{{decay}}_{{wg}}_c4_{{Velo}}_WithUT_{{polarity}}: +data_{{decay}}_{{wg}}_cc{{Type[11]}}_{{Velo}}_WithUT_{{polarity}}: application: "DaVinci/v64r10@{{dv_platform_detdesc}}" input: bk_query: "/LHCb/{{data}}/Beam6800GeV-{{Velo}}-{{polarity}}/Real Data/{{Type}}/{{wg}}.DST" diff --git a/BandQ_Bp2JpsiKp_MuonID_NoMuonID_Lines/tupling_maker.py b/BandQ_Bp2JpsiKp_MuonID_NoMuonID_Lines/tupling_maker.py index 1fdf0ab42b..7b918c858d 100644 --- a/BandQ_Bp2JpsiKp_MuonID_NoMuonID_Lines/tupling_maker.py +++ b/BandQ_Bp2JpsiKp_MuonID_NoMuonID_Lines/tupling_maker.py @@ -167,6 +167,8 @@ def all_variables(pvs, mctruth, ptype, candidates=None, ftAlg=None): all_vars.update({"NVPHITS": F.VALUE_OR(-1) @ F.NVPHITS @ F.TRACK}) all_vars.update({"TRACKHASVELO": F.VALUE_OR(-1) @ F.TRACKHASVELO @ F.TRACK}) all_vars.update({"TRACKHASUT": F.VALUE_OR(-1) @ F.TRACKHASUT @ F.TRACK}) + all_vars.update({"STATEAT_MUON_position_X": F.POSITION_X @ F.EXTRAPOLATE_TRACK( 15100.) @ F.TRACK}) + all_vars.update({"STATEAT_MUON_position_Y": F.POSITION_Y @ F.EXTRAPOLATE_TRACK( 15100.) @ F.TRACK}) all_vars.update({"OBJECT_KEY": F.OBJECT_KEY}) -- GitLab From d196ef842eb500f6e111f46f57c6559d08b55f46 Mon Sep 17 00:00:00 2001 From: yuc <yuc@cern.ch> Date: Sun, 1 Dec 2024 16:18:28 +0800 Subject: [PATCH 14/15] update --- BandQ_Bp2JpsiKp_MuonID_NoMuonID_Lines/info.yaml | 2 +- .../tupling_maker.py | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/BandQ_Bp2JpsiKp_MuonID_NoMuonID_Lines/info.yaml b/BandQ_Bp2JpsiKp_MuonID_NoMuonID_Lines/info.yaml index e5d539131d..6cb70c45c4 100644 --- a/BandQ_Bp2JpsiKp_MuonID_NoMuonID_Lines/info.yaml +++ b/BandQ_Bp2JpsiKp_MuonID_NoMuonID_Lines/info.yaml @@ -17,7 +17,7 @@ defaults: {%- for data, Type, wg, decay, polarity, Velo, process, stream in datasets %} -data_{{decay}}_{{wg}}_cc{{Type[11]}}_{{Velo}}_WithUT_{{polarity}}: +data_{{decay}}_{{wg}}_c{{Type[11]}}_v2_{{Velo}}_WithUT_{{polarity}}: application: "DaVinci/v64r10@{{dv_platform_detdesc}}" input: bk_query: "/LHCb/{{data}}/Beam6800GeV-{{Velo}}-{{polarity}}/Real Data/{{Type}}/{{wg}}.DST" diff --git a/BandQ_Bp2JpsiKp_MuonID_NoMuonID_Lines/tupling_maker.py b/BandQ_Bp2JpsiKp_MuonID_NoMuonID_Lines/tupling_maker.py index 7b918c858d..9f516921b4 100644 --- a/BandQ_Bp2JpsiKp_MuonID_NoMuonID_Lines/tupling_maker.py +++ b/BandQ_Bp2JpsiKp_MuonID_NoMuonID_Lines/tupling_maker.py @@ -167,8 +167,16 @@ def all_variables(pvs, mctruth, ptype, candidates=None, ftAlg=None): all_vars.update({"NVPHITS": F.VALUE_OR(-1) @ F.NVPHITS @ F.TRACK}) all_vars.update({"TRACKHASVELO": F.VALUE_OR(-1) @ F.TRACKHASVELO @ F.TRACK}) all_vars.update({"TRACKHASUT": F.VALUE_OR(-1) @ F.TRACKHASUT @ F.TRACK}) - all_vars.update({"STATEAT_MUON_position_X": F.POSITION_X @ F.EXTRAPOLATE_TRACK( 15100.) @ F.TRACK}) - all_vars.update({"STATEAT_MUON_position_Y": F.POSITION_Y @ F.EXTRAPOLATE_TRACK( 15100.) @ F.TRACK}) + all_vars.update({"STATEAT_MUON_M1_position_X": F.POSITION_X @ F.EXTRAPOLATE_TRACK( 12100.) @ F.TRACK}) + all_vars.update({"STATEAT_MUON_M1_position_Y": F.POSITION_Y @ F.EXTRAPOLATE_TRACK( 12100.) @ F.TRACK}) + all_vars.update({"STATEAT_MUON_M2_position_X": F.POSITION_X @ F.EXTRAPOLATE_TRACK( 15100.) @ F.TRACK}) + all_vars.update({"STATEAT_MUON_M2_position_Y": F.POSITION_Y @ F.EXTRAPOLATE_TRACK( 15100.) @ F.TRACK}) + all_vars.update({"STATEAT_MUON_M3_position_X": F.POSITION_X @ F.EXTRAPOLATE_TRACK( 16300.) @ F.TRACK}) + all_vars.update({"STATEAT_MUON_M3_position_Y": F.POSITION_Y @ F.EXTRAPOLATE_TRACK( 16300.) @ F.TRACK}) + all_vars.update({"STATEAT_MUON_M4_position_X": F.POSITION_X @ F.EXTRAPOLATE_TRACK( 17500.) @ F.TRACK}) + all_vars.update({"STATEAT_MUON_M4_position_Y": F.POSITION_Y @ F.EXTRAPOLATE_TRACK( 17500.) @ F.TRACK}) + all_vars.update({"STATEAT_MUON_M5_position_X": F.POSITION_X @ F.EXTRAPOLATE_TRACK( 18700.) @ F.TRACK}) + all_vars.update({"STATEAT_MUON_M5_position_Y": F.POSITION_Y @ F.EXTRAPOLATE_TRACK( 18700.) @ F.TRACK}) all_vars.update({"OBJECT_KEY": F.OBJECT_KEY}) -- GitLab From da9f9bd1416876f443a8c87bbc18c19eaaab3c4a Mon Sep 17 00:00:00 2001 From: yuc <yuc@cern.ch> Date: Sun, 1 Dec 2024 19:43:56 +0800 Subject: [PATCH 15/15] update --- BandQ_Bp2JpsiKp_MuonID_NoMuonID_Lines/info.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BandQ_Bp2JpsiKp_MuonID_NoMuonID_Lines/info.yaml b/BandQ_Bp2JpsiKp_MuonID_NoMuonID_Lines/info.yaml index 6cb70c45c4..8900ecf298 100644 --- a/BandQ_Bp2JpsiKp_MuonID_NoMuonID_Lines/info.yaml +++ b/BandQ_Bp2JpsiKp_MuonID_NoMuonID_Lines/info.yaml @@ -37,7 +37,7 @@ data_{{decay}}_{{wg}}_c{{Type[11]}}_v2_{{Velo}}_WithUT_{{polarity}}: data_type: "Upgrade" geometry_version: run3/2024.Q1.2-v00.00 conditions_version: master - output: Data_{{stream}}_{{decay}}.ROOT + output: Data_v2_{{stream}}_{{decay}}.ROOT {%- endfor %} -- GitLab