Belle II Software  release-05-01-25
B2A405-Rave-MassVertexFit.py
1 #!/usr/bin/env python3
2 
3 
26 
27 import basf2 as b2
28 from modularAnalysis import inputMdst
29 from modularAnalysis import reconstructDecay
30 from modularAnalysis import matchMCTruth
31 from vertex import raveFit
32 from modularAnalysis import variablesToExtraInfo
33 from stdCharged import stdPi, stdK
34 from modularAnalysis import variablesToNtuple
35 from variables import variables as vm
36 import variables.collections as vc
37 import variables.utils as vu
38 
39 
40 # create path
41 my_path = b2.create_path()
42 
43 # load input ROOT file
44 inputMdst(environmentType='default',
45  filename=b2.find_file('B02pi0D0_D2kpi_B2Dstarpi_Dstar2Dpi_D2kpi.root', 'examples', False),
46  path=my_path)
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 reconstructDecay('D0:kpi_mass -> K-:loose pi+:loose', '1.8 < M < 1.9', path=my_path)
61 
62 # perform D0 vertex fit
63 # First, saving mass before fit
64 variablesToExtraInfo("D0:kpi", variables={'M': 'M_before_vertex_fit'}, path=my_path)
65 # Second, creating alias for the extra info variable
66 vm.addAlias("M_BeforeFit", "extraInfo(M_before_vertex_fit)")
67 # Now, do the fit keeping candidates only passing C.L. value of the fit > 0.0 (no cut)
68 raveFit('D0:kpi', 0.0, path=my_path)
69 
70 # perform mass constrained D0 vertex fit
71 # keep candidates only passing C.L. value of the fit > 0.0 (no cut)
72 variablesToExtraInfo("D0:kpi_mass", variables={'M': 'M_before_vertex_fit'}, path=my_path)
73 # no need to create alias again
74 raveFit('D0:kpi_mass', 0.0, fit_type='massvertex', path=my_path)
75 
76 # reconstruct two D*+ -> D0 pi+ decay
77 # keep only candidates with Q = M(D0pi) - M(D0) - M(pi) < 20 MeV
78 # and D* CMS momentum > 2.5 GeV
79 reconstructDecay('D*+:1 -> D0:kpi pi+:all',
80  '0.0 <= Q < 0.02 and 2.5 < useCMSFrame(p) < 5.5', path=my_path)
81 reconstructDecay('D*+:2 -> D0:kpi_mass pi+:all',
82  '0.0 <= Q < 0.02 and 2.5 < useCMSFrame(p) < 5.5', path=my_path)
83 
84 # perform MC matching (MC truth association)
85 matchMCTruth('D*+:1', path=my_path)
86 matchMCTruth('D*+:2', path=my_path)
87 
88 # perform D*+ kinematic vertex fit using the D0 and the pi+
89 # keep candidates only passing C.L. value of the fit > 0.0 (no cut)
90 raveFit('D*+:1', 0.0, path=my_path)
91 
92 # perform D*+ kinematic beam spot constrained vertex fit using the D0 and the pi+
93 # keep candidates only passing C.L. value of the fit > 0.0 (no cut)
94 raveFit('D*+:2', 0.0, constraint='ipprofile', path=my_path)
95 
96 
97 # Select variables that we want to store to ntuple
98 dstar_vars = vc.inv_mass + vc.mc_truth + \
99  vc.mc_flight_info + vc.flight_info
100 
101 fs_hadron_vars = vu.create_aliases_for_selected(
102  vc.pid + vc.track + vc.mc_truth,
103  'D*+ -> [D0 -> ^K- ^pi+] ^pi+')
104 
105 d0_vars = vu.create_aliases_for_selected(
106  vc.inv_mass + vc.mc_truth + ["M_BeforeFit"],
107  'D*+ -> ^D0 pi+', 'D0')
108 
109 
110 # Saving variables to ntuple
111 output_file = 'B2A405-Rave-MassVertexFit.root'
112 variablesToNtuple('D*+:1', dstar_vars + d0_vars + fs_hadron_vars,
113  filename=output_file, treename='dsttree1', path=my_path)
114 variablesToNtuple('D*+:2', dstar_vars + d0_vars + fs_hadron_vars,
115  filename=output_file, treename='dsttree2', path=my_path)
116 
117 
118 # Process the events
119 b2.process(my_path)
120 
121 # print out the summary
122 print(b2.statistics)
variablesToNtuple
Definition: variablesToNtuple.py:1
variablesToExtraInfo
Definition: variablesToExtraInfo.py:1
variables.utils
Definition: utils.py:1
variables.collections
Definition: collections.py:1