Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
add_histos_bX.py
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file add_histos_bX.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 import sys
7 
8 gROOT.SetBatch(True)
9 
10 dirName = '/sphenix/user/shulga/Work/TpcPadPlane_phi_coresoftware/coresoftware/calibrations/tpc/fillSpaceChargeMaps/Files/'
11 #bXs = [1508071, 3016509, 4524020, 6032112, 7540028, 9048092, 10556072, 12064371, 13572143, 15080178, 16588072, 18096105]
12 #bXs = [18096105]
13 h_names = []#'_h_hits','_h_R','_h_DC_E']
14 for i in range(30):
15  h_names.append('_h_SC_ibf_{}'.format(i))
16  h_names.append('_h_SC_prim_{}'.format(i))
17 
18 
19 #sys.argv[0]
20 ib = sys.argv[1]
21 bX = sys.argv[2]
22 
23 
24 print(bX)
25 name = 'mdc2_ADCBins_UseFieldMaps_hist_G4Hits_sHijing_0-12fm_bX{}*'.format(bX)
26 outputName = './Files/Summary_hist_mdc2_UseFieldMaps_AA_event_{}_bX{}_new.root'.format(ib,bX)
27 
28 filePattern = dirName+name
29 files = sorted(glob.glob(filePattern))
30 #print(files)
31 #n=0
32 histos = []
33 for n,file in enumerate(files):
34  #h=0
35  f = TFile.Open(file)
36  print(file)
37  for h,h_name in enumerate(h_names):
38  newName=h_name+'_{}'.format(n)
39  if n==0:
40  newName=h_name
41  #print(h_name)
42  hist = f.Get(h_name).Clone(newName)
43  if n==0:
44  histos.append(hist)
45  if n>0:
46  histos[h].Add(hist)
47  hist.SetDirectory(0)
48  #h+=1
49  #n+=1
50 
51 outfile = TFile(outputName, "RECREATE")
52 for hist in histos:
53  hist.Sumw2(False)
54  hist.Write()
55 outfile.Write()
56 outfile.Close()
57 
58 
59 # Remove all the used files
60 for file in files :
61  if os.path.exists(file):
62  os.remove(file)
63  else:
64  print("Can not delete the file as it doesn't exist:{}",file)
65