Belle II Software development
039_various_additions.py
1#!/usr/bin/env python3
2
3import sys
4import basf2 as b2
5import modularAnalysis as ma
6import stdV0s
7from variables import variables as vm # shorthand for VariableManager
8import variables.collections as vc
9import variables.utils as vu
10
11# get input file number from the command line
12filenumber = sys.argv[1]
13
14# create path
15main = b2.Path()
16
17# load input data from mdst/udst file
18ma.inputMdstList(
19 filelist=[b2.find_file(f"starterkit/2021/1111540100_eph3_BGx0_{filenumber}.root", "examples")],
20 path=main,
21)
22
23# fill final state particle lists
24ma.fillParticleList(
25 "e+:uncorrected",
26 "electronID > 0.1 and dr < 0.5 and abs(dz) < 2 and thetaInCDCAcceptance",
27 path=main,
28)
29stdV0s.stdKshorts(path=main)
30
31# apply Bremsstrahlung correction to electrons [S10|S20]
32vm.addAlias(
33 "goodFWDGamma", "passesCut(clusterReg == 1 and clusterE > 0.075)"
34) # [E10]
35vm.addAlias(
36 "goodBRLGamma", "passesCut(clusterReg == 2 and clusterE > 0.05)"
37)
38vm.addAlias(
39 "goodBWDGamma", "passesCut(clusterReg == 3 and clusterE > 0.1)"
40)
41vm.addAlias(
42 "goodGamma", "passesCut(goodFWDGamma or goodBRLGamma or goodBWDGamma)"
43) # [E20]
44ma.fillParticleList("gamma:brems", "goodGamma", path=main)
45ma.correctBrems("e+:corrected", "e+:uncorrected", "gamma:brems", path=main) # [S30]
46vm.addAlias("isBremsCorrected", "extraInfo(bremsCorrected)") # [E30]
47
48# combine final state particles to form composite particles [S40]
49ma.reconstructDecay(
50 "J/psi:ee -> e+:corrected e-:corrected ?addbrems",
51 cut="abs(dM) < 0.11",
52 path=main,
53) # [E40]
54
55# combine J/psi and KS candidates to form B0 candidates
56ma.reconstructDecay(
57 "B0 -> J/psi:ee K_S0:merged",
58 cut="Mbc > 5.2 and abs(deltaE) < 0.15",
59 path=main,
60)
61
62# match reconstructed with MC particles
63ma.matchMCTruth("B0", path=main)
64
65# build the rest of the event
66ma.buildRestOfEvent("B0", fillWithMostLikely=True, path=main)
67track_based_cuts = "thetaInCDCAcceptance and pt > 0.075 and dr < 5 and abs(dz) < 10"
68ecl_based_cuts = "thetaInCDCAcceptance and E > 0.05"
69roe_mask = ("my_mask", track_based_cuts, ecl_based_cuts)
70ma.appendROEMasks("B0", [roe_mask], path=main)
71
72# perform best candidate selection [S60]
73b2.set_random_seed("Belle II StarterKit")
74ma.rankByHighest("B0", variable="random", numBest=1, path=main) # [E60]
75
76# Create list of variables to save into the output file
77b_vars = []
78
79standard_vars = vc.kinematics + vc.mc_kinematics + vc.mc_truth
80b_vars += vc.deltae_mbc
81b_vars += standard_vars
82
83# ROE variables
84roe_kinematics = ["roeE()", "roeM()", "roeP()", "roeMbc()", "roeDeltae()"]
85roe_multiplicities = [
86 "nROE_Charged()",
87 "nROE_Photons()",
88 "nROE_NeutralHadrons()",
89]
90b_vars += roe_kinematics + roe_multiplicities
91# Let's also add a version of the ROE variables that includes the mask:
92for roe_variable in roe_kinematics + roe_multiplicities:
93 # e.g. instead of 'roeE()' (no mask) we want 'roeE(my_mask)'
94 roe_variable_with_mask = roe_variable.replace("()", "(my_mask)")
95 b_vars.append(roe_variable_with_mask)
96
97# Variables for final states (electrons, positrons, pions)
98fs_vars = vc.pid + vc.track + vc.track_hits + standard_vars
99b_vars += vu.create_aliases_for_selected(
100 fs_vars + ["isBremsCorrected"],
101 "B0 -> [J/psi -> ^e+ ^e-] K_S0",
102 prefix=["ep", "em"],
103)
104b_vars += vu.create_aliases_for_selected(
105 fs_vars, "B0 -> J/psi [K_S0 -> ^pi+ ^pi-]", prefix=["pip", "pim"]
106)
107# Variables for J/Psi, KS
108jpsi_ks_vars = vc.inv_mass + standard_vars
109b_vars += vu.create_aliases_for_selected(jpsi_ks_vars, "B0 -> ^J/psi ^K_S0")
110# Add the J/Psi mass calculated with uncorrected electrons:
111vm.addAlias( # [S50]
112 "Jpsi_M_uncorrected", "daughter(0, daughterCombination(M,0:0,1:0))"
113) # [E50]
114b_vars += ["Jpsi_M_uncorrected"]
115# Also add kinematic variables boosted to the center of mass frame (CMS)
116# for all particles
117cmskinematics = vu.create_aliases(
118 vc.kinematics, "useCMSFrame({variable})", "CMS"
119)
120b_vars += vu.create_aliases_for_selected(
121 cmskinematics, "^B0 -> [^J/psi -> ^e+ ^e-] [^K_S0 -> ^pi+ ^pi-]"
122)
123
124vm.addAlias(
125 "withBremsCorrection",
126 "passesCut(passesCut(ep_isBremsCorrected == 1) or passesCut(em_isBremsCorrected == 1))",
127)
128b_vars += ["withBremsCorrection"]
129
130# Save variables to an output file (ntuple)
131ma.variablesToNtuple(
132 "B0",
133 variables=b_vars,
134 filename="Bd2JpsiKS.root",
135 treename="tree",
136 path=main,
137)
138
139# Start the event loop (actually start processing things)
140b2.process(main)
141
142# print out the summary
143print(b2.statistics)
def stdKshorts(prioritiseV0=True, fitter='TreeFit', path=None, updateAllDaughters=False, writeOut=False)
Definition: stdV0s.py:17