Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
add_histos.py
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file add_histos.py
1 #!/usr/bin/env python3
2 from ROOT import TCanvas, TFile, TH1F,TH2F,TH3F, TF1, TGraph, gROOT
3 import os
4 import re
5 
6 gROOT.SetBatch(True)
7 
8 dirName = './Files/'
9 bXs = [1508071, 3016509, 4524020, 6032112, 7540028, 9048092, 10556072, 12064371, 13572143, 15080178, 16588072, 18096105]
10 h_names = ['_h_DC_E',
11  '_h_DC_SC',
12  '_h_DC_SC_XY',
13  '_h_R',
14  '_h_SC_ibf',
15  '_h_hits']
16 
17 for bX in bXs:
18  print(bX)
19  name = 'hist_G4Hits_sHijing_0-12fm_bX{}'.format(bX)
20  outputName = './Files/Summary_ADC_NoW_hist_AA_event_0_bX{}.root'.format(bX)
21  files = [f for f in os.listdir(dirName) if re.match(name, f)]
22  n=0
23  histos = []
24  for file in files:
25  h=0
26  f = TFile.Open(dirName+file)
27  for h_name in h_names:
28  newName=h_name+'_{}'.format(n)
29  if n==0:
30  newName=h_name
31  hist = f.Get(h_name).Clone()
32  hist.SetDirectory(0)
33  if n==0:
34  histos.append(hist)
35  if n>0:
36  histos[h].Add(hist)
37  h+=1
38  n+=1
39 
40  outfile = TFile(outputName, "RECREATE")
41  for hist in histos:
42  hist.Sumw2(False)
43  hist.Write()
44  outfile.Write()
45  outfile.Close()
46 #print(files)
47 #
48 #