Geant4  9.6.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
plotfiles.py
Go to the documentation of this file.
1 #!/usr/bin/python
2 
3 from ROOT import *
4 from array import array
5 
6 def plot_1_file (file):
7  gROOT.Reset()
8  input_file_1=TFile(file+'.root','READ')
9  h1 = input_file_1.Get("Source Energy Spectrum")
10  h2 = input_file_1.Get("Source X-Y distribution")
11  h3 = input_file_1.Get("Source X-Z distribution")
12  h4 = input_file_1.Get("Source Y-Z distribution")
13  h5 = input_file_1.Get("Source phi-std::cos(theta) distribution")
14  h6 = input_file_1.Get("Source phi-theta distribution")
15 
16  c1 = TCanvas('c1', file, 200, 10, 700, 900)
17  c1.Divide(2,3)
18 
19  c1.cd(1)
20  h1.Draw()
21  c1.cd(2)
22  h2.Draw()
23  c1.cd(3)
24  h3.Draw()
25  c1.cd(4)
26  h4.Draw()
27  c1.cd(5)
28  h5.Draw()
29  c1.cd(6)
30  h6.Draw()
31  c1.Update()
32  c1.Print("./"+file+".png")
33 
34  input_file_1.Close()
35 
36 # h_gam.SetLineColor(2)
37 
38 def plot_2_files (file):
39  gROOT.Reset()
40 
41  input_file_1=TFile(file+'a.root','READ')
42  input_file_2=TFile(file+'b.root','READ')
43 
44 #input_file_1.cd()
45 #h_1_1 = input_file_1.Get("h16")
46 
47  c1 = TCanvas('c1', file, 200, 10, 700, 500)
48  c1.SetGridx()
49  c1.SetGridy()
50  c1.SetLogx()
51  c1.SetLogy()
52 
53 # histogram for energy spectra
54  n = 41
55  bin = array( 'f' )
56 
57  for i in range( n ):
58  bin.append(pow(10,(-2+0.1*i)))
59 #
60  h_1 = TH1F('unbiased','Source Spectrum',40,bin)
61  h_2 = TH1F('biased','Source Spectrum',40,bin)
62 
63 #
64  input_file_1.cd()
65 # get the tuple t1
66  t1 = gROOT.FindObject('MyTuple')
67  for i in range(t1.GetEntries()):
68  t1.GetEntry(i)
69  h_1.Fill(t1.Energy,t1.Weight)
70 
71  input_file_2.cd()
72 # get the tuple t1
73  t2 = gROOT.FindObject("MyTuple")
74  for i in range(t2.GetEntries()):
75  t2.GetEntry(i)
76  h_2.Fill(t2.Energy,t2.Weight)
77 
78  h_2.SetLineStyle(kDashed);
79  h_2.SetLineColor(kBlue);
80  h_2.Draw();
81  h_1.Draw("same") ;
82  c1.Update()
83  c1.Print("./"+file+".png")
84 
85  input_file_1.Close()
86  input_file_2.Close()
87