Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-10-28 07:59:55

0001 #!/usr/bin/env python
0002 
0003 import ROOT
0004 from array import array
0005 
0006 def plot_1_file (file):
0007     ROOT.gROOT.Reset()
0008     ROOT.gROOT.SetBatch(True)
0009 
0010     input_file_1=ROOT.TFile(file+'.root','READ')
0011     h11 = input_file_1.Get('histo/h1.1')
0012     h12 = input_file_1.Get('histo/h1.2')
0013     h13 = input_file_1.Get('histo/h1.3')
0014     h14 = input_file_1.Get('histo/h1.4')
0015     h21 = input_file_1.Get('histo/h2.1')
0016     h22 = input_file_1.Get('histo/h2.2')
0017     h23 = input_file_1.Get('histo/h2.3')
0018     h24 = input_file_1.Get('histo/h2.4')
0019 
0020     c1 = ROOT.TCanvas('c1', file+'.h1', 200, 10, 1200, 700)
0021     c1.Divide(4,2)
0022     histos1 = [h11, h12, h13, h14]
0023     pad = 1
0024     for h1 in histos1:
0025         if h1:
0026             c1.cd(pad)
0027             h1.Draw()
0028             pad = pad + 1
0029 
0030     histos2 = [h21, h22, h23, h24]
0031     pad = 5
0032     for h2 in histos2:
0033        if h2:
0034            c1.cd(pad)
0035            h2.Draw()
0036            pad = pad + 1
0037     c1.Print(file+'.png')
0038 
0039     input_file_1.Close()
0040 
0041 def plot_2_files (file):
0042    ROOT.gROOT.Reset()
0043    ROOT.gROOT.SetBatch(True)
0044 
0045    input_file_1=ROOT.TFile(file+"a.root",'READ')
0046    input_file_2=ROOT.TFile(file+"b.root",'READ')
0047 
0048    input_file_1.cd()
0049    h_1_1 = input_file_1.Get('histo/h1.1')
0050 
0051    c1 = ROOT.TCanvas('c1', file, 200, 10, 700, 500)
0052    c1.SetGridx()
0053    c1.SetGridy()
0054    c1.SetLogx()
0055    c1.SetLogy()
0056 
0057    #histogram for energy spectra
0058    n = 41
0059    bin = array( 'f' )
0060 
0061    for i in range( n ):
0062        bin.append(pow(10,(-2+0.1*i)))
0063 
0064    h_1 = ROOT.TH1F('unbiased','Source Spectrum',40,bin)
0065    h_2 = ROOT.TH1F('biased','Source Spectrum',40,bin)
0066 
0067    input_file_1.cd()
0068    #get the tuple t1
0069    t1 = input_file_1.Get('ntuple/101')
0070    for i in range(t1.GetEntries()):
0071        t1.GetEntry(i)
0072        h_1.Fill(t1.Ekin,t1.weight)
0073 
0074    input_file_2.cd()
0075    # get the tuple t1
0076    t2 =  input_file_2.Get('ntuple/101')
0077    for i in range(t2.GetEntries()):
0078        t2.GetEntry(i)
0079        h_2.Fill(t2.Ekin,t2.weight)
0080 
0081    h_2.Draw();
0082    h_1.Draw("same") ;
0083    c1.Update()
0084    c1.Print(file+".png")
0085 
0086    input_file_1.Close()
0087    input_file_2.Close()
0088