Belle II Software development
removeParticlesNotInLists.py
1#!/usr/bin/env python3
2
3
10
11import os
12import basf2
13import modularAnalysis as ma
14import b2test_utils
15
16main = basf2.create_path()
17
18ma.inputMdst(b2test_utils.require_file('analysis/tests/mdst.root'), path=main)
19
20kaons = ('K-', 'kaonID > 0.05')
21pions = ('pi+', 'pionID > 0.05')
22photons = ('gamma', '')
23ma.fillParticleLists([kaons, pions, photons], path=main)
24
25ma.reconstructDecay('pi0 -> gamma gamma', '0.11 < M < 0.15', 0, path=main)
26ma.reconstructDecay('D0 -> K- pi+ pi0', '1.7 < M < 1.9', 0, path=main)
27
28output = basf2.register_module('RootOutput')
29output.param('outputFileName', 'removeparticlesnotinlists_full.root')
30main.add_module(output)
31
32ma.summaryOfLists(['D0'], path=main)
33
34ma.removeParticlesNotInLists(['D0'], path=main)
35
36ma.matchMCTruth('D0', path=main)
37ma.matchMCTruth('pi0', path=main)
38
39# ensures that things in D0 list are ok
40ntupler = basf2.register_module('VariablesToNtuple')
41ntupler.param('fileName', 'removeparticlesnotinlists_D0ntuple.root')
42ntupler.param('variables', ['M', 'daughter(0, M)', 'daughter(2, M)', 'mcPDG'])
43ntupler.param('particleList', 'D0')
44main.add_module(ntupler)
45
46# pi0 list should also have been fixed
47ntupler = basf2.register_module('VariablesToNtuple')
48ntupler.param('fileName', 'removeparticlesnotinlists_pi0ntuple.root')
49ntupler.param('variables', ['M', 'daughter(0, M)', 'mcPDG'])
50ntupler.param('particleList', 'pi0')
51main.add_module(ntupler)
52
53output = basf2.register_module('RootOutput')
54output.param('outputFileName', 'removeparticlesnotinlists_reduced.root')
55main.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