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