Belle II Software development
checkMemoryUsage.py
1#!/usr/bin/env python3
2
3
10
11
23
24import argparse
25import basf2 as b2
26import modularAnalysis as ma
27import stdV0s
28import flavorTagger as ft
29import vertex as vx
30import variables.collections as vc
31import variables.utils as vu
32
33b2.set_random_seed("aSeed")
34
35# create path
36main = b2.Path()
37
38parser = argparse.ArgumentParser(
39 description="Script to chech memory usage as part of light release validaiton"
40)
41
42parser.add_argument(
43 "--release", type=str, help="The light release that is being tested."
44)
45args = parser.parse_args()
46
47# load input ROOT file
48ma.inputMdst(filename="", path=main)
49
50# create muon particle list
51ma.fillParticleList(decayString="mu+:all", cut="", path=main)
52
53# reconstruct J/psi -> mu+ mu- decay
54# keep only candidates with dM<0.11
55ma.reconstructDecay(
56 decayString="J/psi:mumu -> mu+:all mu-:all", cut="dM<0.11", path=main
57)
58
59# load KS from standard particle list
60stdV0s.stdKshorts(fitter="TreeFit", path=main)
61
62# reconstruct B0 -> J/psi KS decay
63ma.reconstructDecay(
64 decayString="B0:sig -> J/psi:mumu K_S0:merged",
65 cut="Mbc > 5.2 and abs(deltaE)<0.15",
66 path=main,
67)
68
69# match reconstructed with MC particles
70ma.matchMCTruth(list_name="B0:sig", path=main)
71
72# build the rest of the event associated to the B0
73ma.buildRestOfEvent(target_list_name="B0:sig", path=main)
74
75# set analysis global tag
76b2.conditions.prepend_globaltag(ma.getAnalysisGlobaltag())
77
78# Flavor Tagging
79ft.flavorTagger(
80 particleLists=["B0:sig"], weightFiles="B2nunubarBGx1", path=main, useGNN=True
81)
82
83# rank by highest r- factor
84ma.rankByHighest(
85 particleList="B0:sig",
86 variable="abs(qrOutput(FBDT))",
87 numBest=0,
88 outputVariable="Dilution_rank",
89 path=main,
90)
91
92# fit B vertex on the signal side
93vx.treeFit(
94 list_name="B0:sig",
95 conf_level=-1,
96 massConstraint=["K_S0"],
97 ipConstraint=True,
98 updateAllDaughters=True,
99 path=main,
100)
101
102# fit B vertex on the tag side
103vx.TagV(list_name="B0:sig", MCassociation="breco", path=main)
104
105# select variables that will be stored to ntuple
106fs_vars = vc.pid + vc.track + vc.track_hits + vc.mc_truth
107jpsiandk0s_vars = vc.mc_truth
108vertex_vars = vc.vertex + vc.mc_vertex + vc.kinematics + vc.mc_kinematics
109bvars = (
110 vc.reco_stats
111 + vc.deltae_mbc
112 + vc.mc_truth
113 + vc.roe_multiplicities
114 + vc.tag_vertex
115 + vc.mc_tag_vertex
116 + vertex_vars
117)
118
119# Attention: the collection of flavor tagging variables is defined in the flavorTagger
120bvars += ft.flavor_tagging
121
122# Create aliases to save information for different particles
123bvars = (
124 bvars
125 + vu.create_aliases_for_selected(
126 list_of_variables=fs_vars,
127 decay_string="B0 -> [J/psi -> ^mu+ ^mu-] [K_S0 -> ^pi+ ^pi-]",
128 )
129 + vu.create_aliases_for_selected(
130 list_of_variables=jpsiandk0s_vars,
131 decay_string="B0 -> [^J/psi -> mu+ mu-] [^K_S0 -> pi+ pi-]",
132 )
133 + vu.create_aliases_for_selected(
134 list_of_variables=vertex_vars,
135 decay_string="B0 -> [^J/psi -> ^mu+ ^mu-] [^K_S0 -> ^pi+ ^pi-]",
136 )
137)
138
139# saving variables to ntuple
140output_file = f"output/{args.release}.root"
141ma.variablesToNtuple(
142 decayString="B0:sig",
143 variables=bvars,
144 filename=output_file,
145 treename="tree",
146 path=main,
147)
148
149# summary of created Lists
150ma.summaryOfLists(particleLists=["K_S0:merged", "J/psi:mumu", "B0:sig"], path=main)
151
152# profile execution time and memory usage
153main.add_module(
154 "Profile",
155 outputFileName=f"output/MemoryUsage_{args.release}.root",
156 rssOutputFileName=f"output/RSSMemoryUsage_{args.release}.root",
157)
158
159# process the events
160b2.process(main)
161
162# print out the summary
163print(b2.statistics)
stdKshorts(prioritiseV0=True, fitter="TreeFit", path=None, updateAllDaughters=False, writeOut=False, addSuffix=False)
Definition stdV0s.py:25