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