Belle II Software light-2406-ragdoll
memcheck.py
1#!/usr/bin/env python3
2
3
10
11"""This script is used in the nightly build to check for memory issues with valgrind.
12It is run as a test to make sure the memcheck does not fail because of issues in the script."""
13
14from b2test_utils import skip_test_if_light
15skip_test_if_light() # light builds don't contain simulation, reconstruction etc; skip before trying to import # noqa
16
17from basf2 import set_random_seed, set_log_level, LogLevel, create_path, Module, find_file, process, statistics, conditions
18from simulation import add_simulation
19from reconstruction import add_reconstruction
20from mdst import add_mdst_output
21from ROOT import Belle2
22from modularAnalysis import reconstructDecay, rankByHighest, buildRestOfEvent, buildContinuumSuppression, matchMCTruth, \
23 variablesToNtuple, getAnalysisGlobaltag
24from stdCharged import stdPi, stdMu
25from vertex import treeFit, TagV
26from flavorTagger import flavorTagger
27from rawdata import add_packers, add_unpackers
28import glob
29import sys
30import os
31
32# set the random seed to get reproducible results
33set_random_seed(1)
34
35# suppress messages and warnings during processing:
36set_log_level(LogLevel.ERROR)
37
38# add the analysis globaltag (necessary for flavor tagging)
39conditions.prepend_globaltag(getAnalysisGlobaltag())
40
41# create path
42main = create_path()
43
44# specify number of events to be generated
45main.add_module('EventInfoSetter')
46
47
48class StopModule(Module):
49 """Module to stop the event processing in case the argument InitOnly is given"""
50
51 def event(self):
52 """Set the event meta data to end of data"""
53
54 eventMetaData = Belle2.PyStoreObj('EventMetaData')
55 eventMetaData.setEndOfData()
56
57
58if len(sys.argv) > 1 and sys.argv[1] == 'InitOnly':
59 main.add_module(StopModule())
60
61# print event numbers
62evtmetainfo = main.add_module('EventInfoPrinter')
63evtmetainfo.set_log_level(LogLevel.INFO)
64
65# generate BBbar events, with Bsig -> J/psi K0S
66main.add_module('EvtGenInput', userDECFile=find_file('decfiles/dec/1111440100.dec'))
67
68# detector simulation
69bg = None
70if 'BELLE2_BACKGROUND_DIR' in os.environ:
71 bg = glob.glob(os.environ['BELLE2_BACKGROUND_DIR'] + '/*.root')
72add_simulation(main, bkgfiles=bg)
73
74# reconstruction
75add_reconstruction(main)
76
77# mdst output
78add_mdst_output(main, True)
79
80# dst output
81main.add_module('RootOutput', outputFileName='dst.root')
82
83
84# use standard final state particle lists
85stdPi('loose', path=main)
86stdMu('loose', path=main)
87
88# reconstruct Ks -> pi+ pi- decay and keep only candidates with 0.4 < M(pipi) < 0.6 GeV
89reconstructDecay('K_S0:pipi -> pi+:loose pi-:loose', cut='0.4 < M < 0.6', path=main)
90
91# reconstruct J/psi -> mu+ mu- decay and keep only candidates with 3.0 < M(mumu) < 3.2 GeV
92reconstructDecay('J/psi:mumu -> mu+:loose mu-:loose', cut='3.0 < M < 3.2', path=main)
93
94# reconstruct B0 -> J/psi Ks decay and keep only candidates with 5.2 < M(J/PsiKs) < 5.4 GeV
95reconstructDecay('B0:jpsiks -> J/psi:mumu K_S0:pipi', cut='5.2 < M < 5.4', path=main)
96
97# perform B0 kinematic vertex fit and keep candidates only passing C.L. value of the fit > 0.0 (no cut)
98treeFit('B0:jpsiks', 0.0, path=main)
99
100# order candidates by chi2 probability
101rankByHighest('B0:jpsiks', 'chiProb', path=main)
102
103# build the rest of the event associated to the B0
104buildRestOfEvent('B0:jpsiks', path=main)
105
106# calculate continuum suppression variables
107buildContinuumSuppression('B0:jpsiks', 'all', path=main)
108
109# perform MC matching (MC truth association).
110matchMCTruth('B0:jpsiks', path=main)
111
112# do flavor tagging
113flavorTagger('B0:jpsiks', path=main)
114
115# calculate the Tag Vertex and Delta t (in ps), breco: type of MC association.
116TagV('B0:jpsiks', 'breco', path=main)
117
118# select variables that we want to store to ntuple
119fs_vars = ['kaonID', 'muonID', 'dr', 'dz', 'pValue', 'isSignal', 'mcErrors', 'genMotherID']
120b_vars = ['nTracks', 'Mbc', 'deltaE', 'p', 'E', 'useCMSFrame(p)', 'useCMSFrame(E)',
121 'isSignal', 'mcErrors', 'nROE_KLMClusters', 'qrOutput(FBDT)', 'TagVLBoost', 'TagVz', 'TagVzErr', 'mcDeltaT'] + \
122 [f'daughter(0,daughter(0,{var}))' for var in fs_vars]
123
124# save variables to ntuple
125variablesToNtuple('B0:jpsiks', variables=b_vars, filename='ntuple.root', treename='B0tree', path=main)
126
127# do raw data packing and unpacking
128add_packers(main)
129add_unpackers(main)
130for module in main.modules():
131 if module.type() == 'SVDUnpacker':
132 module.param('silentlyAppend', True)
133
134# gather profiling information
135main.add_module('Profile', outputFileName='vmem_profile.png', rssOutputFileName='rss_profile.png').set_log_level(LogLevel.INFO)
136
137# execute all
138process(main)
139
140# Print call statistics
141print(statistics)
a (simplified) python wrapper for StoreObjPtr.
Definition: PyStoreObj.h:67
def event(self)
Definition: memcheck.py:51