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