Skip to content
Snippets Groups Projects

fanjie/run3_Lb2LcDKpi

Closed Fanjie Meng requested to merge fanjie/run3_Lb2LcDKpi into master
1 unresolved thread
4 files
+ 812
0
Compare changes
  • Side-by-side
  • Inline
Files
4
+ 366
0
from DaVinci import make_config, Options
from DaVinci.algorithms import create_lines_filter
from PyConf.reading import get_rec_summary, get_pvs
from PyConf.reading import get_particles
import FunTuple.functorcollections as FC
import Functors as F
from FunTuple import FunctorCollection
from FunTuple import FunTuple_Event
from FunTuple import FunTuple_Particles
from Hlt2Conf.standard_particles import make_long_kaons, make_long_protons, make_long_pions
#from PyConf.reading import (get_particles, get_charged_protoparticles, get_pvs, get_rec_summary, _get_unpacked)
from Functors.math import in_range
from Hlt2Conf.algorithms_thor import ParticleCombiner, ParticleFilter
from RecoConf.event_filters import require_pvs
from Hlt2Conf.standard_particles import get_long_track_selector, standard_protoparticle_filter
from PyConf.Algorithms import FunctionalParticleMaker
from PyConf.reading import get_charged_protoparticles as _make_charged_protoparticles
from PyConf.reading import get_odin
from GaudiKernel.SystemOfUnits import MeV, picosecond, mm
from itertools import combinations
from .descriptor_writer import decay_branches
_basic = "basic"
_composite = "composite"
_toplevel = "toplevel"
def all_variables(pvs, mctruth, ptype, candidates=None, ftAlg=None):
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
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)})
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": 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})
# 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})
all_vars.update({"TRACK_MOM_": F.TRACK_MOMVEC})
all_vars.update({"TRACK_POS_CLOSESTTOBEAM_": F.TRACK_POSVEC_CLOSESTTOBEAM})
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 comp:
all_vars.update({"MAXPT": F.MAX(F.PT)})
all_vars.update({"MAXDOCA": F.MAXSDOCA})
all_vars.update({"MAXDOCACHI2": F.MAXSDOCACHI2})
#all_vars.update({"MINDOCA": F.MINSDOCA})
#all_vars.update({"MINDOCACHI2": F.MINSDOCACHI2})
# 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})
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({"SDOCA12": F.SDOCA(1, 2)})
all_vars.update({"SDOCA12_CHI2": 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 top:
all_vars.update({"SDOCA13": F.SDOCA(1, 3)})
all_vars.update({"SDOCA13_CHI2": F.SDOCACHI2(1, 3)})
all_vars.update({"SDOCA23": F.SDOCA(2, 3)})
all_vars.update({"SDOCA23_CHI2": F.SDOCACHI2(2, 3)})
all_vars.update({"SUBCOMB13_MM": F.SUBCOMB(Functor=F.MASS, Indices=(1, 3))})
all_vars.update({"SUBCOMB23_MM": F.SUBCOMB(Functor=F.MASS, Indices=(2, 3))})
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, rec_sum, hlt1_lines, sprucing_lines):
"""
event variables
"""
## Some empty summaries removed
evt_vars = 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),
})
evt_vars += FC.EventInfo()
evt_vars += FC.SelectionInfo( selection_type="Hlt1", trigger_lines=hlt1_lines)
evt_vars += FC.SelectionInfo( selection_type="Hlt2", trigger_lines=sprucing_lines)
# 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 candidate_variables(pvs, mother, daughters):
variables_B = {mother: all_variables(pvs, None, _toplevel)}
for daughter in daughters:
if ("psi" in daughter) or ("Lambda" in daughter) or ("lambda" in daughter):
variables_B.update( {daughter: all_variables(pvs, None, _composite)} )
else:
variables_B.update( {daughter: all_variables(pvs, None, _basic)} )
return variables_B
def main(options: Options):
sprucing_line = 'SpruceBandQ_JpsiToMuMuDetached'
Jpsi2mumu_data = get_particles(f"/Event/Spruce/{sprucing_line}/Particles")
rec_sum = get_rec_summary()
v2_pvs = get_pvs()
pions = make_long_pions()
kaons = make_long_kaons()
protons = make_long_protons()
# create particle containers
pid_pions = ParticleFilter( pions, Cut=F.FILTER( F.require_all( F.PID_K < 5 ) ) )
pid_kaons = ParticleFilter( kaons, Cut=F.FILTER( F.require_all( F.PID_K > 0 ) ) )
pid_protons = ParticleFilter( protons, Cut=F.FILTER( F.require_all( F.PID_P > 0, (F.PID_P-F.PID_K)>0 ) ) )
mother = "Lb"
daughters = ["Jpsi", "mup", "mum", "Pp", "Km"]
decay = "[Lambda_b0 -> J/psi(1S) p+ K-]cc"
Lb2JpsipK = ParticleCombiner(
Inputs = [Jpsi2mumu_data, pid_protons, pid_kaons],
DecayDescriptor = decay,
name="JpsiToMuMu_Detached_line_validation",
CombinationCut=F.require_all(in_range(5400, F.MASS, 6600)),
CompositeCut=F.require_all(in_range(5400, F.MASS, 6600), F.CHI2DOF < 20, F.BPVLTIME(v2_pvs) > 0.2 * picosecond, F.BPVVDRHO(v2_pvs) > 0. * mm, F.BPVVDZ(v2_pvs) > 0. * mm, F.BPVDIRA(v2_pvs) > 0.),
)
#FunTuple: define branches.
hlt1_trigger_lines = [ 'Hlt1TrackMVADecision',
'Hlt1TwoTrackMVADecision',
'Hlt1D2KKDecision',
'Hlt1D2KPiDecision',
'Hlt1D2PiPiDecision',
'Hlt1DiMuonHighMassDecision',
'Hlt1DiMuonLowMassDecision',
'Hlt1DiMuonSoftDecision',
'Hlt1KsToPiPiDecision',
'Hlt1LowPtMuonDecision',
'Hlt1LowPtDiMuonDecision',
'Hlt1SingleHighPtMuonDecision',
'Hlt1TrackMuonMVADecision']
#variables_B = { "Lb": all_variables(v2_pvs, None, _toplevel),
# "Jpsi": all_variables(v2_pvs, None, _composite),
# "mup": all_variables(v2_pvs, None, _basic),
# "mum": all_variables(v2_pvs, None, _basic),
# "Pp": all_variables(v2_pvs, None, _basic),
# "Km": all_variables(v2_pvs, None, _basic),
#}
odin = get_odin()
decreports = None
line_prefilter = create_lines_filter(name=f"PreFilter_{sprucing_line}", lines=[sprucing_line])
evt_vars = event_variables(v2_pvs, odin, decreports, rec_sum, hlt1_trigger_lines, [sprucing_line])
candidate_vars = candidate_variables(v2_pvs, mother, daughters)
Lb2JpsipK_branches = decay_branches(mother, daughters, decay)
print(Lb2JpsipK_branches)
# define tupling algorithms
Lb2JpsipK_tuple = FunTuple_Particles(name="Lb2JpsipKTuple",
inputs=Lb2JpsipK,
tuple_name="DecayTree",
fields=Lb2JpsipK_branches,
variables=candidate_vars,
store_multiple_cand_info = True,
event_variables = evt_vars)
algs = { "Lb2JpsipK_tuple":[ Lb2JpsipK_tuple, line_prefilter ],}
return make_config( options, algs )
Loading