Belle II Software  release-06-02-00
vxdCdcMergerValidationCreatePlots.py
1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
3 
4 
11 
12 """
13 <header>
14  <contact>software-tracking@belle2.org</contact>
15  <input>VxdCdcValidationHarvested.root</input>
16  <description>This module creates efficiency plots for the V0 validation.</description>
17 </header>
18 """
19 
20 
21 import ROOT
22 
23 
25  """Create efficiency plots for the V0 validation"""
26 
27  def __init__(self, input_file='../VxdCdcValidationHarvested.root', output_file='VxdCdcMergerValidation.root'):
28  """Constructor"""
29 
30  self.input_fileinput_file = input_file
31 
32  self.output_fileoutput_file = output_file
33 
34 
35  self.hist_merged_hitshist_merged_hits = ROOT.TH1F("merged_hits", "Merged Hits", 70, 0, 140)
36 
37  self.hist_good_over_pthist_good_over_pt = ROOT.TProfile("good_over_pt", "Good Merge over Pt", 50, 0, 4)
38 
39  self.hist_good_over_thetahist_good_over_theta = ROOT.TProfile("good_over_theta", "Good Merge over Theta", 50, 0, 4)
40 
41  def collect_histograms(self):
42  """Fill the histograms in each event"""
43  input_root_file = ROOT.TFile.Open(self.input_fileinput_file, "READ")
44 
45  for event in input_root_file.VxdCdcMergerHarvester_tree:
46  self.hist_merged_hitshist_merged_hits.Fill(event.PR_NHITS)
47  self.hist_good_over_pthist_good_over_pt.Fill(event.MC_PT, event.GOOD_MERGE)
48  self.hist_good_over_thetahist_good_over_theta.Fill(event.MC_THETA, event.GOOD_MERGE)
49 
50  input_root_file.Close()
51  return self
52 
53  @staticmethod
54  def histogram_plot(hist, title, x_variable, x_unit=None, description='', check='', contact='', meta_options=''):
55  """Label and annotate the histograms"""
56  hist.SetName("".join(title.split()))
57  xlabel = '{} / ({})'.format(x_variable, x_unit) if x_unit is not None else '{}'.format(x_variable)
58  ylabel = 'Entries / ({} {})'.format((hist.GetXaxis().GetXmax() -
59  hist.GetXaxis().GetXmin()) /
60  hist.GetNbinsX(), x_unit) if x_unit is not None \
61  else 'Entries / ({})'.format((hist.GetXaxis().GetXmax() - hist.GetXaxis().GetXmin()) / hist.GetNbinsX())
62  hist.SetTitle("{};{};{}".format(title, xlabel, ylabel))
63  hist.GetListOfFunctions().Add(ROOT.TNamed('Description', description))
64  hist.GetListOfFunctions().Add(ROOT.TNamed('Check', check))
65  hist.GetListOfFunctions().Add(ROOT.TNamed('Contact', contact))
66  hist.GetListOfFunctions().Add(ROOT.TNamed('MetaOptions', meta_options))
67  return hist
68 
69  def plot(self):
70  """Draw all of the histograms to the output ROOT file"""
71  output_root_file = ROOT.TFile.Open(self.output_fileoutput_file, "RECREATE")
72 
73  VxdCdcMergerValidationPlots.histogram_plot(self.hist_merged_hitshist_merged_hits, "Number of hits of merged tracks", "Number of Hits", None,
74  description='Number of hits of merged tracks',
75  check='',
76  contact='',
77  meta_options='').Write()
78 
79  VxdCdcMergerValidationPlots.histogram_plot(self.hist_good_over_pthist_good_over_pt, "Good Merge over Pt", "MC Track Pt (GeV)", None,
80  description='Good Merge over Pt',
81  check='',
82  contact='',
83  meta_options='').Write()
84 
85  VxdCdcMergerValidationPlots.histogram_plot(self.hist_good_over_thetahist_good_over_theta, "Good Merge over Theta", "MC Track Theta (1)", None,
86  description='Good Merge over Theta',
87  check='',
88  contact='',
89  meta_options='').Write()
90 
91  output_root_file.Write()
92  output_root_file.Close()
93  return self
94 
95 
96 if __name__ == '__main__':
def histogram_plot(hist, title, x_variable, x_unit=None, description='', check='', contact='', meta_options='')
def __init__(self, input_file='../VxdCdcValidationHarvested.root', output_file='VxdCdcMergerValidation.root')
hist_good_over_pt
Profile histogram of good merged hits by transverse momentum.
hist_good_over_theta
Profile histogram of good merged hits by polar angle.
Definition: plot.py:1