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