Belle II Software  release-08-01-10
removeParticlesNotInLists.py
1 #!/usr/bin/env python3
2 
3 
10 
11 import os
12 import basf2
13 import modularAnalysis as ma
14 import b2test_utils
15 
16 main = basf2.create_path()
17 
18 ma.inputMdst(b2test_utils.require_file('analysis/tests/mdst.root'), path=main)
19 
20 kaons = ('K-', 'kaonID > 0.05')
21 pions = ('pi+', 'pionID > 0.05')
22 photons = ('gamma', '')
23 ma.fillParticleLists([kaons, pions, photons], path=main)
24 
25 ma.reconstructDecay('pi0 -> gamma gamma', '0.11 < M < 0.15', 0, path=main)
26 ma.reconstructDecay('D0 -> K- pi+ pi0', '1.7 < M < 1.9', 0, path=main)
27 
28 output = basf2.register_module('RootOutput')
29 output.param('outputFileName', 'removeparticlesnotinlists_full.root')
30 main.add_module(output)
31 
32 ma.summaryOfLists(['D0'], path=main)
33 
34 ma.removeParticlesNotInLists(['D0'], path=main)
35 
36 ma.matchMCTruth('D0', path=main)
37 ma.matchMCTruth('pi0', path=main)
38 
39 # ensures that things in D0 list are ok
40 ntupler = basf2.register_module('VariablesToNtuple')
41 ntupler.param('fileName', 'removeparticlesnotinlists_D0ntuple.root')
42 ntupler.param('variables', ['M', 'daughter(0, M)', 'daughter(2, M)', 'mcPDG'])
43 ntupler.param('particleList', 'D0')
44 main.add_module(ntupler)
45 
46 # pi0 list should also have been fixed
47 ntupler = basf2.register_module('VariablesToNtuple')
48 ntupler.param('fileName', 'removeparticlesnotinlists_pi0ntuple.root')
49 ntupler.param('variables', ['M', 'daughter(0, M)', 'mcPDG'])
50 ntupler.param('particleList', 'pi0')
51 main.add_module(ntupler)
52 
53 output = basf2.register_module('RootOutput')
54 output.param('outputFileName', 'removeparticlesnotinlists_reduced.root')
55 main.add_module(output)
56 
59 
60  statfull = os.stat('removeparticlesnotinlists_full.root').st_size
61  statreduced = os.stat('removeparticlesnotinlists_reduced.root').st_size
62  basf2.B2RESULT("original size (kB): " + str(statfull / 1024))
63  basf2.B2RESULT("reduced size (kB): " + str(statreduced / 1024))
64  if statfull <= statreduced:
65  basf2.B2FATAL("Reduced file is not smaller than original")
def require_file(filename, data_type="", py_case=None)
Definition: __init__.py:54
def clean_working_directory()
Definition: __init__.py:189
def safe_process(*args, **kwargs)
Definition: __init__.py:236