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 import glob
6 
7 gROOT.SetBatch(True)
8 
9 dirName = '/sphenix/user/shulga/Work/IBF/DistortionMap/Files/'
10 bXs = [1508071, 3016509, 4524020, 6032112, 7540028, 9048092, 10556072, 12064371, 13572143, 15080178, 16588072, 18096105]
11 #bXs = [18096105]
12 h_names = ['_h_hits','_h_R','_h_DC_E']
13 for i in range(30):
14  h_names.append('_h_SC_ibf_{}'.format(i))
15  h_names.append('_h_SC_prim_{}'.format(i))
16 
17 
18 for ib,bX in enumerate(bXs):
19  print(bX)
20  name = 'mdc2_ADCBins_UseFieldMaps_hist_G4Hits_sHijing_0-12fm_bX{}*'.format(bX)
21  outputName = '/sphenix/user/shulga/Work/IBF/DistortionMap/Files/Summary_hist_mdc2_UseFieldMaps_AA_event_{}_bX{}.root'.format(ib,bX)
22 
23  filePattern = dirName+name
24  files = sorted(glob.glob(filePattern))
25  #print(files)
26  #n=0
27  histos = []
28  for n,file in enumerate(files):
29  #h=0
30  f = TFile.Open(file)
31  for h,h_name in enumerate(h_names):
32  newName=h_name+'_{}'.format(n)
33  if n==0:
34  newName=h_name
35  hist = f.Get(h_name).Clone(h_name)
36  if n==0:
37  histos.append(hist)
38  if n>0:
39  histos[h].Add(hist)
40  hist.SetDirectory(0)
41  #h+=1
42  #n+=1
43 
44  outfile = TFile(outputName, "RECREATE")
45  for hist in histos:
46  hist.Sumw2(False)
47  hist.Write()
48  outfile.Write()
49  outfile.Close()
50 #print(files)
51 #
52 #