Skip to content
Snippets Groups Projects

Removing PID cuts when tuping from DST files (MC) for QQbar2MuMu 2024 studies

Merged Mengzhen Wang requested to merge jpsi2MuMu_noPID_mc_test into master
Files
11
+ 156
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. #
###############################################################################
"""
Read and process a .xgen file with the new DaVinci configuration.
rst_title: Run on XGEN files
rst_description: This example reads and process a `.xgen` file.
rst_running: lbexec DaVinciExamples.tupling.option_davinci_tupling_from_xgen:main $DAVINCIEXAMPLESROOT/example_data/Gauss_12143001_xgen.yaml
rst_yaml: ../DaVinciExamples/example_data/Gauss_12143001_xgen.yaml
"""
import Functors as F
import FunTuple.functorcollections as FC
from FunTuple import FunctorCollection, FunTuple_MCParticles as FuntupleMC
from PyConf.reading import get_particles, get_pvs, get_rec_summary
from PyConf.Algorithms import PrintMCTree
from DaVinci import Options, make_config
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_mc_particles, get_mc_header
from PyConf.reading import get_odin # get_decreports,
from DecayTreeFitter import DecayTreeFitter
def mctree_template(fields):
# FunTuple: define fields (branches)
#fields = {
# "QQbar": "J/psi(1S) ==> mu+ mu-",
# "mup": "J/psi(1S) ==> ^mu+ mu-",
# "mum": "J/psi(1S) ==> mu+ ^mu-",
#}
# FunTuple: define input data
QQbar2mumu_line = get_mc_particles("/Event/HLT2/MC/Particles")
pvs = get_pvs()
#define event level variables
odin = get_odin()
rec_sum=get_rec_summary()
event_info = 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"),
#"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"),
})
MC_MOTHER_ID = lambda gen: F.VALUE_OR(0) @ F.MC_MOTHER(gen, F.PARTICLE_ID)
MC_MOTHER_KEY = lambda gen: F.VALUE_OR(-1) @ F.MC_MOTHER(gen, F.OBJECT_KEY)
# FunTuple: define variables for the J/psi
composite_variables = FunctorCollection(
{
"ETA": F.ETA,
"PHI": F.PHI,
"TAU": F.MC_LIFETIME,
"ORIGIN_VX": F.ORIGIN_VX,
"ORIGIN_VY": F.ORIGIN_VY,
"ORIGIN_VZ": F.ORIGIN_VZ,
"END_VX": F.END_VX,
"END_VY": F.END_VY,
"END_VZ": F.END_VZ,
"M": F.MASS,
"FOURMOMENTUM": F.FOURMOMENTUM,
"PT": F.PT,
"MC_MOTHER_ID": MC_MOTHER_ID(1),
"MC_MOTHER_KEY": MC_MOTHER_KEY(1),
"MC_GD_MOTHER_ID": MC_MOTHER_ID(2),
"MC_GD_MOTHER_KEY": MC_MOTHER_KEY(2),
"MC_GD_GD_MOTHER_ID": MC_MOTHER_ID(3),
"MC_GD_GD_MOTHER_KEY": MC_MOTHER_KEY(3),
}
)
# FunTuple: define variables for the muon
basic_variables = FunctorCollection(
{
"ETA": F.ETA,
"PHI": F.PHI,
"ORIGIN_VX": F.ORIGIN_VX,
"ORIGIN_VY": F.ORIGIN_VY,
"ORIGIN_VZ": F.ORIGIN_VZ,
"M": F.MASS,
"FOURMOMENTUM": F.FOURMOMENTUM,
"PT": F.PT,
"MC_MOTHER_ID": MC_MOTHER_ID(1),
"MC_MOTHER_KEY": MC_MOTHER_KEY(1),
"MC_GD_MOTHER_ID": MC_MOTHER_ID(2),
"MC_GD_MOTHER_KEY": MC_MOTHER_KEY(2),
"MC_GD_GD_MOTHER_ID": MC_MOTHER_ID(3),
"MC_GD_GD_MOTHER_KEY": MC_MOTHER_KEY(3),
"TAU": F.MC_LIFETIME,
"END_VX": F.END_VX,
"END_VY": F.END_VY,
"END_VZ": F.END_VZ,
}
)
# FunTuple: associate functor collections to field (branch) name
variables = {
"QQbar": composite_variables + FC.Kinematics(),
"mup": basic_variables + FC.Kinematics(),
"mum": basic_variables + FC.Kinematics(),
}
# FunTuple: define event-level variables using functor collections
mc_header = get_mc_header(extra_inputs=[QQbar2mumu_line])
evt_vars = event_info
#evt_vars = FC.MCPrimaries(mc_header=mc_header) + event_info
#printMC = PrintMCTree(
# MCParticles=QQbar2mumu_line, ParticleNames=["J/psi(1S)"], OutputLevel=4
#)
tuple_QQbar2mumu = FuntupleMC(
name="MCDecayTreeTuple",
tuple_name="MCDecayTree",
fields=fields,
variables=variables,
event_variables=evt_vars,
inputs=QQbar2mumu_line,
)
return tuple_QQbar2mumu
Loading