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