6 <contact>software-tracking@belle2.org</contact>
7 <input>V0ValidationHarvested.root</input>
8 <description>This module creates efficiency plots for the V0 validation.</description>
19 """Reads the output created by the V0Harvester and creates plots from it."""
21 def __init__(self, input_file='../V0ValidationHarvested.root', output_file='V0Validation.root'):
22 """Reads the output created by the V0Harvester defines histograms which will be filled later.
24 :param input_file: Output of V0ValidationHarvester.
25 :param output_file: Plots displayed in the V0Validation.
33 self.
hist_r = ROOT.TH1F(
"",
"True R", 20, 0, 20)
35 self.
hist_theta = ROOT.TH1F(
"",
"True Theta", 26, 20, 150)
37 self.
hist_phi = ROOT.TH1F(
"",
"True Phi", 36, -180, 180)
39 self.
hist_p = ROOT.TH1F(
"",
"True P", 25, 0.0, 1.0)
77 """Fills the defined histograms with the V0Harvester data.
81 input_root_file = ROOT.TFile.Open(self.
input_file,
"READ")
83 for event
in input_root_file.V0Harvester_tree:
84 self.
hist_r.Fill(event.R_MC)
85 self.
hist_theta.Fill(numpy.rad2deg(event.THETA_MC))
86 self.
hist_phi.Fill(numpy.rad2deg(event.PHI_MC))
87 self.
hist_p.Fill(event.P_MC)
108 assert event.R_MC <= 1.0
113 input_root_file.Close()
117 def efficiency_plot(found, all, title, x_variable, x_unit, description='', check='', contact='', meta_options=''):
118 """Create an efficiency plot.
120 :param found: Histogram with all found entries (i.e. reconstructed).
121 :param all: Histogram with all entries (i.e. MCTruth).
122 :param title: Title of the histogram.
123 :param x_variable: x variable.
124 :param x_unit: x unit.
125 :param description: Description text shown on the validation page.
126 :param check: Check text shown on the validation page.
127 :param contact: Contact text shown on the validation page.
128 :param meta_options: Meta options for the validation page.
129 :return: ROOT.TEfficiency
131 efficiency = ROOT.TEfficiency(found, all)
132 efficiency.SetName(
"".join(title.split()))
133 ylabel =
'Efficiency / ({} {})'.format((found.GetXaxis().GetXmax() -
134 found.GetXaxis().GetXmin()) / found.GetNbinsX(), x_unit)
135 efficiency.SetTitle(
"{};{} / ({});{}".format(title, x_variable, x_unit, ylabel))
136 efficiency.GetListOfFunctions().Add(ROOT.TNamed(
'Description', description))
137 efficiency.GetListOfFunctions().Add(ROOT.TNamed(
'Check', check))
138 efficiency.GetListOfFunctions().Add(ROOT.TNamed(
'Contact', contact))
139 efficiency.GetListOfFunctions().Add(ROOT.TNamed(
'MetaOptions', meta_options))
143 def histogram_plot(hist, title, x_variable, x_unit=None, description='', check='', contact='', meta_options=''):
144 """Create (annotate) an histogram plot.
147 :param title: Title of the histogram.
148 :param x_variable: x variable.
149 :param x_unit: x unit.
150 :param description: Description text shown on the validation page.
151 :param check: Check text shown on the validation page.
152 :param contact: Contact text shown on the validation page.
153 :param meta_options: Meta options for the validation page.
154 :return: modified hist
156 hist.SetName(
"".join(title.split()))
157 xlabel =
'{} / ({})'.format(x_variable, x_unit)
if x_unit
is not None else '{}'.format(x_variable)
158 ylabel =
'Entries / ({} {})'.format((hist.GetXaxis().GetXmax() -
159 hist.GetXaxis().GetXmin()) /
160 hist.GetNbinsX(), x_unit)
if x_unit
is not None \
161 else 'Entries / ({})'.format((hist.GetXaxis().GetXmax() - hist.GetXaxis().GetXmin()) / hist.GetNbinsX())
162 hist.SetTitle(
"{};{};{}".format(title, xlabel, ylabel))
163 hist.GetListOfFunctions().Add(ROOT.TNamed(
'Description', description))
164 hist.GetListOfFunctions().Add(ROOT.TNamed(
'Check', check))
165 hist.GetListOfFunctions().Add(ROOT.TNamed(
'Contact', contact))
166 hist.GetListOfFunctions().Add(ROOT.TNamed(
'MetaOptions', meta_options))
171 description='', check='', contact='', meta_options=''):
172 """Create a 2d hisogram plot.
175 :param title: Title of the histogram.
176 :param x_variable: x variable
177 :param y_variable: y variable
178 :param x_unit: x unit
179 :param y_unit: y unit
180 :param description: Description text shown on the validation page.
181 :param check: Check text shown on the validation page.
182 :param contact: Contact text shown on the validation page.
183 :param meta_options: Meta options for the validation page.
184 :return: ROOT.TEfficiency
187 hist.SetName(
"".join(title.split()))
188 xlabel =
'{} / ({})'.format(x_variable, x_unit)
if x_unit
is not None else '{}'.format(x_variable)
189 ylabel =
'{} / ({})'.format(y_variable, y_unit)
if y_unit
is not None else '{}'.format(y_variable)
190 hist.SetTitle(
"{};{};{}".format(title, xlabel, ylabel))
191 hist.GetListOfFunctions().Add(ROOT.TNamed(
'Description', description))
192 hist.GetListOfFunctions().Add(ROOT.TNamed(
'Check', check))
193 hist.GetListOfFunctions().Add(ROOT.TNamed(
'Contact', contact))
194 hist.GetListOfFunctions().Add(ROOT.TNamed(
'MetaOptions', meta_options))
198 """Create plots with the data filled with 'collect_histograms'.
202 output_root_file = ROOT.TFile.Open(self.
output_file,
"RECREATE")
204 V0ValidationPlots.efficiency_plot(self.
hist_r_found, self.
hist_r,
'Efficiency vs R',
'r',
'cm',
205 description=
'Reconstruction Efficiency vs. r (perpendicular)',
207 contact=
'software-tracking@belle2.org',
208 meta_options=
'').Write()
211 description=
'Reconstruction Efficiency vs. theta',
213 contact=
'software-tracking@belle2.org',
214 meta_options=
'').Write()
217 description=
'Reconstruction Efficiency vs phi',
219 contact=
'software-tracking@belle2.org',
220 meta_options=
'').Write()
222 V0ValidationPlots.efficiency_plot(self.
hist_p_found, self.
hist_p,
'Efficiency vs P',
'P',
'GeV',
223 description=
'Reconstruction Efficiency vs momentum',
225 contact=
'software-tracking@belle2.org',
226 meta_options=
'').Write()
228 V0ValidationPlots.histogram_plot(self.
hist_invariant_mass,
"KShort Invariant Mass",
"m",
"GeV",
229 description=
'Reconstructed invariant mass of KShorts with standard reconstruction',
230 check=
'Invariant mass peak around KShort nominal mass 497.61 MeV.',
231 contact=
'software-tracking@belle2.org',
232 meta_options=
'').Write()
235 description=
'Invariant mass residuum of KShorts with standard reconstruction',
237 contact=
'software-tracking@belle2.org',
238 meta_options=
'').Write()
240 V0ValidationPlots.histogram_plot(self.
hist_chi2,
"Chi2 of Vertex Fits.",
"Chi2",
None,
241 description=
'Chi2 distributions of the vertex fits.',
242 check=
'Check if distribution looks like a Chi2 distribution with 1 dof',
243 contact=
'software-tracking@belle2.org',
244 meta_options=
'').Write()
246 V0ValidationPlots.histogram_plot(self.
hist_chi2_inside,
"Chi2 of Vertex Fits Inside Beampipe.",
"Chi2",
None,
247 description=
'Chi2 distributions of the vertex fits inside the beampipe.',
248 check=
'Check if distribution looks like a Chi2 distribution with 1 dof',
249 contact=
'software-tracking@belle2.org',
250 meta_options=
'expert').Write()
252 V0ValidationPlots.histogram_plot(self.
hist_chi2_outside,
"Chi2 of Vertex Fits Outside Beampipe.",
"Chi2",
None,
253 description=
'Chi2 distributions of the vertex fits outside the beampipe.',
254 check=
'Check if distribution looks like a Chi2 distribution with 1 dof',
255 contact=
'software-tracking@belle2.org',
256 meta_options=
'expert').Write()
259 "Reconstructed Mass",
"GeV",
"MC Mass",
"GeV",
260 description=
"Reconstructed mass vs invariant Mass.",
262 contact=
"software-tracking@belle2.org",
263 meta_options=
'expert').Write()
265 V0ValidationPlots.histogram_plot(self.
hist_r_residuum,
"KShort R Residuum",
"Rec - MC",
"cm",
266 description=
'R residuum of KShorts with standard reconstruction',
268 contact=
'software-tracking@belle2.org',
269 meta_options=
'').Write()
270 V0ValidationPlots.histogram_plot(self.
hist_theta_residuum,
"KShort Theta Residuum",
"Rec - MC",
"rad",
271 description=
'Theta residuum of KShorts with standard reconstruction',
273 contact=
'software-tracking@belle2.org',
274 meta_options=
'').Write()
275 V0ValidationPlots.histogram_plot(self.
hist_phi_residuum,
"KShort Phi Residuum",
"Rec - MC",
"rad",
276 description=
'Phi residuum of KShorts with standard reconstruction',
278 contact=
'software-tracking@belle2.org',
279 meta_options=
'').Write()
280 V0ValidationPlots.histogram_plot(self.
hist_p_residuum,
"KShort Momentum Residuum",
"Rec - MC",
"GeV",
281 description=
'Momentum residuum of KShorts with standard reconstruction',
283 contact=
'software-tracking@belle2.org',
284 meta_options=
'').Write()
286 output_root_file.Write()
287 output_root_file.Close()
291 if __name__ ==
'__main__':