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