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