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