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