Belle II Software  release-06-01-15
B2A400-TreeFit.py
1 #!/usr/bin/env python3
2 
3 
10 
11 
34 
35 import basf2 as b2
36 import modularAnalysis as ma
37 import vertex as vx
38 from stdPi0s import stdPi0s
39 
40 # create path
41 my_path = b2.create_path()
42 
43 # load input ROOT file
44 ma.inputMdst(environmentType='default',
45  filename=b2.find_file('B02D0pi0_D02pi0pi0.root', 'examples', False),
46  path=my_path)
47 
48 
49 # use standard final state particle lists
50 #
51 # creates "pi0:eff40_May2020Fit" ParticleList
52 # see Standard Particles section at https://software.belle2.org/
53 stdPi0s(listtype='eff40_May2020Fit', path=my_path)
54 
55 # reconstruct D0 -> pi0 pi0 decay
56 # keep only candidates with 1.7 < M(pi0pi0) < 2.0 GeV
57 ma.reconstructDecay(decayString='D0:pi0pi0 -> pi0:eff40_May2020Fit pi0:eff40_May2020Fit',
58  cut='1.7 < M < 2.0',
59  path=my_path)
60 
61 # reconstruct B0 -> D0 pi0 decay
62 # keep only candidates with Mbc > 5.24 GeV
63 # and -1 < Delta E < 1 GeV
64 ma.reconstructDecay(decayString='B0:all -> D0:pi0pi0 pi0:eff40_May2020Fit',
65  cut='5.24 < Mbc < 5.29 and abs(deltaE) < 1.0',
66  path=my_path)
67 
68 # perform MC matching (MC truth association)
69 ma.matchMCTruth(list_name='B0:all', path=my_path)
70 
71 vx.treeFit(list_name='B0:all',
72  conf_level=0, # 0:keep only fit survivors, -1: keep all candidates; optimise this cut for your need
73  ipConstraint=True,
74  # pins the B0 PRODUCTION vertex to the IP (increases SIG and BKG rejection) use for better vertex resolution
75  updateAllDaughters=True, # update momenta of ALL particles
76  massConstraint=['pi0'], # mass constrain ALL pi0
77  path=my_path)
78 
79 # whatever you are interested in
80 #
81 # see analysis/VariableManager/ for implementation of the vars
82 variables = [
83  'isSignal', # MC truth
84  'chiProb', # pValue of the fit use this in your analysis to reject background
85  "p", # momentum (of the B0)
86  "mcP", # generated momentum
87  "pErr", # momentum uncertainty taking the full px, py, pz covariance into account
88 ]
89 
90 # safe the output
91 output_name = "B2A400-TreeFit.root"
92 my_path.add_module('VariablesToNtuple',
93  treeName='B0',
94  particleList='B0:all',
95  variables=variables,
96  fileName=output_name)
97 
98 # Process the events
99 b2.process(my_path)
100 
101 # print out the summary
102 print(b2.statistics)