Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-06 08:16:41

0001 #!/usr/bin/env python3
0002 from ROOT import TCanvas, TFile, TH1F,TH2F,TH3F, TF1, TGraph, gROOT
0003 import os
0004 import re
0005 
0006 gROOT.SetBatch(True)
0007 
0008 dirName = './Files/'
0009 bXs = [1508071, 3016509, 4524020, 6032112, 7540028, 9048092, 10556072, 12064371, 13572143, 15080178, 16588072, 18096105]
0010 h_names = ['_h_DC_E',
0011             '_h_DC_SC',
0012             '_h_DC_SC_XY',
0013             '_h_R',
0014             '_h_SC_ibf',
0015             '_h_hits']
0016 
0017 for bX in bXs:
0018     print(bX)
0019     name = 'hist_G4Hits_sHijing_0-12fm_bX{}'.format(bX)
0020     outputName = './Files/Summary_ADC_NoW_hist_AA_event_0_bX{}.root'.format(bX)
0021     files = [f for f in os.listdir(dirName) if re.match(name, f)]
0022     n=0
0023     histos = []
0024     for file in files:
0025         h=0
0026         f = TFile.Open(dirName+file)
0027         for h_name in h_names:
0028             newName=h_name+'_{}'.format(n)
0029             if n==0:
0030                 newName=h_name
0031             hist = f.Get(h_name).Clone()
0032             hist.SetDirectory(0)
0033             if n==0:
0034                 histos.append(hist)
0035             if n>0:
0036                 histos[h].Add(hist) 
0037             h+=1
0038         n+=1
0039 
0040     outfile = TFile(outputName, "RECREATE")
0041     for hist in histos:
0042         hist.Sumw2(False)
0043         hist.Write()
0044     outfile.Write()
0045     outfile.Close()
0046 #print(files)
0047 #
0048 #