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