Belle II Software  release-05-01-25
B2A403-KFit-VertexFit.py
1 #!/usr/bin/env python3
2 
3 
28 
29 import basf2 as b2
30 from modularAnalysis import inputMdst
31 from modularAnalysis import reconstructDecay
32 from modularAnalysis import matchMCTruth
33 from vertex import kFit
34 from stdCharged import stdPi, stdK
35 from modularAnalysis import variablesToNtuple
36 import variables.collections as vc
37 import variables.utils as vu
38 
39 # create path
40 my_path = b2.create_path()
41 
42 # load input ROOT file
43 inputMdst(environmentType='default',
44  filename=b2.find_file('B02pi0D0_D2kpi_B2Dstarpi_Dstar2Dpi_D2kpi.root', 'examples', False),
45  path=my_path)
46 
47 
48 # use standard final state particle lists
49 #
50 # creates "pi+:all" ParticleList (and c.c.)
51 stdPi('all', path=my_path)
52 # creates "pi+:loose" ParticleList (and c.c.)
53 stdPi('loose', path=my_path)
54 # creates "K+:loose" ParticleList (and c.c.)
55 stdK('loose', path=my_path)
56 
57 # reconstruct D0 -> K- pi+ decay
58 # keep only candidates with 1.8 < M(Kpi) < 1.9 GeV
59 reconstructDecay('D0:kpi -> K-:loose pi+:loose', '1.8 < M < 1.9', path=my_path)
60 
61 # Perform D0 vertex fit.
62 # Reject the candidates with failed fit.
63 kFit('D0:kpi', 0.0, path=my_path)
64 
65 # reconstruct D*+ -> D0 pi+ decay
66 # keep only candidates with Q = M(D0pi) - M(D0) - M(pi) < 20 MeV
67 # and D* CMS momentum > 2.5 GeV
68 reconstructDecay('D*+ -> D0:kpi pi+:all', '0.0 <= Q < 0.02 and 2.5 < useCMSFrame(p) < 5.5', path=my_path)
69 
70 # perform MC matching (MC truth association)
71 matchMCTruth('D*+', path=my_path)
72 
73 # perform D*+ vertex fit
74 # keep candidates only passing C.L. value of the fit > 0.0 (no cut)
75 kFit('D*+', 0.0, path=my_path)
76 
77 # Select variables that we want to store to ntuple
78 
79 dstar_vars = vc.inv_mass + vc.mc_truth
80 
81 fs_hadron_vars = vu.create_aliases_for_selected(
82  vc.pid + vc.track + vc.mc_truth,
83  'D*+ -> [D0 -> ^K- ^pi+] ^pi+')
84 
85 d0_vars = vu.create_aliases_for_selected(
86  vc.inv_mass + vc.mc_truth,
87  'D*+ -> ^D0 pi+', 'D0')
88 
89 
90 # Saving variables to ntuple
91 output_file = 'B2A403-KFit-VertexFit.root'
92 variablesToNtuple('D*+', dstar_vars + d0_vars + fs_hadron_vars,
93  filename=output_file, treename='dsttree', path=my_path)
94 
95 # Process the events
96 b2.process(my_path)
97 
98 # print out the summary
99 print(b2.statistics)
variablesToNtuple
Definition: variablesToNtuple.py:1
variables.utils
Definition: utils.py:1
variables.collections
Definition: collections.py:1