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