1from __future__
import print_function
2from __future__
import division
5 import rlcompleter, readline
6 readline.parse_and_bind(
'tab: complete' )
7 readline.parse_and_bind(
'set show-all-if-ambiguous On' )
12from ROOT
import TFile,gROOT,TH3D,TH2D,TH1D,TCanvas,TProfile,gSystem
16 if fname[0:4] ==
"/eos":
17 eospath = gSystem.Getenv(
"EOSSHIP")+fname
18 f = TFile.Open(eospath)
21 for akey
in f.GetListOfKeys():
23 try: hname = int(name)
26 if not hname
in wanted:
continue
28 cln = obj.Class().GetName()
29 if not cln.find(
'TCanv')<0:
30 h[hname] = obj.Clone()
31 if cln.find(
'TH')<0
and cln.find(
'TP')<0
and cln.find(
'TE')<0:
continue
33 if hasattr(h[hname],
"Add"): rc = h[hname].Add(obj)
34 if not rc: print(
"Error when adding histogram ",hname)
36 h[hname] = obj.Clone()
37 if hasattr(h[hname],
"GetSumw2N"):
38 if h[hname].GetSumw2N()==0 : h[hname].Sumw2()
39 h[hname].SetDirectory(gROOT)
40 if (cln ==
'TH2D' or cln ==
'TH2F')
and withProj:
41 for p
in [
'_projx',
'_projy']:
42 if type(hname) == type(
's'): projname = hname+p
43 else: projname = str(hname)+p
44 if p.find(
'x')>-1: h[projname] = h[hname].ProjectionX()
45 else : h[projname] = h[hname].ProjectionY()
46 h[projname].SetName(name+p)
47 h[projname].SetDirectory(gROOT)
49def bookHist(h,key=None,title='',nbinsx=100,xmin=0,xmax=1,nbinsy=0,ymin=0,ymax=1,nbinsz=0,zmin=0,zmax=1):
54 if key
in h: h[key].Reset()
55 elif nbinsz >0: h[key] = TH3D(rkey,title,nbinsx,xmin,xmax,nbinsy,ymin,ymax,nbinsz,zmin,zmax)
56 elif nbinsy >0: h[key] = TH2D(rkey,title,nbinsx,xmin,xmax,nbinsy,ymin,ymax)
57 else: h[key] = TH1D(rkey,title,nbinsx,xmin,xmax)
58 h[key].SetDirectory(gROOT)
59def bookProf(h,key=None,title='',nbinsx=100,xmin=0,xmax=1,ymin=None,ymax=None,option=""):
64 if key
in h: h[key].Reset()
65 if ymin==
None or ymax==
None: h[key] = TProfile(key,title,nbinsx,xmin,xmax,option)
66 else: h[key] = TProfile(key,title,nbinsx,xmin,xmax,ymin,ymax,option)
67 h[key].SetDirectory(gROOT)
69 f = TFile(fname,
'RECREATE')
71 if not hasattr(h[akey],
'Class'):
continue
72 cln = h[akey].Class().GetName()
73 if not cln.find(
'TH')<0
or not cln.find(
'TP')<0
or not cln.find(
'TE')<0:
75 if plusCanvas
and not cln.find(
'TC')<0: h[akey].Write()
77def bookCanvas(h,key=None,title='',nx=900,ny=600,cx=1,cy=1):
82 h[key]=TCanvas(key,title,nx,ny)
85 l = sys.modules[
'__main__'].log
89 l = sys.modules[
'__main__'].log
90 if len(l) > 0:
"Summary of recorded incidents:"
95 for x
in [
'.gif',
'.eps',
'.jpg'] :
99 os.system(
'cp '+temp+
' '+Work)
103 if printout: print(
'entries',leaves.GetEntries())
104 for i
in range(0,leaves.GetEntries() ) :
106 name = leaf.GetName()
107 if printout: print(name)
109 pyl.__setattr__(name,leaf)
118 print(
"name ZipBytes[MB] TotBytes[MB] TotalSize[MB]")
119 counter[
'total']=[0,0,0]
120 for l
in sTree.GetListOfLeaves():
123 print(
"%30s :%8.3F %8.3F %8.3F "%(nm,b.GetZipBytes()/1.E6,b.GetTotBytes()/1.E6,b.GetTotalSize()/1.E6))
124 bnm = nm.split(
'.')[0]
125 if bnm
not in counter: counter[bnm]=[0,0,0]
126 counter[bnm][0]+=b.GetZipBytes()/1.E6
127 counter[bnm][1]+=b.GetTotBytes()/1.E6
128 counter[bnm][2]+=b.GetTotalSize()/1.E6
129 counter[
'total'][0]+=b.GetZipBytes()/1.E6
130 counter[
'total'][1]+=b.GetTotBytes()/1.E6
131 counter[
'total'][2]+=b.GetTotalSize()/1.E6
132 print(
"---> SUMMARY <---------------")
133 N = sTree.GetEntries()/1000.
135 print(
" name ZipBytes[kB]/ev TotBytes[kB]/ev TotalSize[kB]/ev")
137 print(
" name ZipBytes[MB] TotBytes[MB] TotalSize[MB]")
138 sorted_c = sorted(counter.items(), key=operator.itemgetter(1))
140 for i
in range(len(sorted_c)):
143 print(
"%30s :%8.3F %8.3F %8.3F"%(x,counter[x][0]/N,counter[x][1]/N,counter[x][2]/N))
145 print(
"%30s :%8.3F %8.3F %8.3F"%(x,counter[x][0],counter[x][1],counter[x][2]))
150 nEvents = sTree.GetEntries()
152 oldTargetClass =
False
153 if sTree.GetBranch(
"SmearedHits"):
154 sTree.SetBranchStatus(
"SmearedHits",0)
156 if sTree.GetBranch(
"TargetPoint"):
157 if sTree.GetLeaf(
"cbmroot.Target.TargetPoint.fEmTop"): oldTargetClass =
True
159 for x
in sTree.GetListOfLeaves():
160 if not x.GetName().find(
"TargetPoint")<0:
161 b = x.GetBranch().GetName()
162 sTree.SetBranchStatus(b,0)
165 sFile = fout.replace(
"_rec.root",
"_recs.root")
166 recf = TFile(sFile,
"recreate")
167 if not oldTargetClass: newTree = sTree.CloneTree(-1,
'fast')
169 newTree = sTree.CloneTree(0)
170 for n
in range(nEvents):
172 if oldTargetClass: sTree.TargetPoint.Clear()
174 sTree.FitTracks.Delete()
182 if nEvents == sTree.GetEntries(): print(
"looks ok, could be deleted",os.path.abspath(
'.'))
183 else: print(
"stripping failed, keep old file",os.path.abspath(
'.'))
186 if x[0:4] ==
"/eos": f=gSystem.Getenv(
"EOSSHIP")+x
190 print(
"input file",f,
" does not exist. Missing authentication?")
192 if test.FindObjectAny(
'cbmsim'):
197 amin,amax = 1E30, -130
199 for n
in range(1,histo.GetNbinsX()+1):
200 c = histo.GetBinContent(n)
207 return amin,amax,nmin,nmax
210 h[name]=h[key].Clone(name)
211 h[name].SetTitle(
'Integral > '+h[key].GetTitle())
212 for n
in range(1,h[key].GetNbinsX()+1):
213 if n==1: h[name].SetBinContent(1,h[key].GetSumOfWeights())
214 else: h[name].SetBinContent(n,h[name].GetBinContent(n-1)-h[key].GetBinContent(n-1))
writeHists(h, fname, plusCanvas=False)
printout(atc, name, Work)
readHists(h, fname, wanted=[], withProj=True)
bookProf(h, key=None, title='', nbinsx=100, xmin=0, xmax=1, ymin=None, ymax=None, option="")
makeIntegralDistrib(h, key)
findMaximumAndMinimum(histo)
bookHist(h, key=None, title='', nbinsx=100, xmin=0, xmax=1, nbinsy=0, ymin=0, ymax=1, nbinsz=0, zmin=0, zmax=1)
container_sizes(sTree, perEvent=False)
setAttributes(pyl, leaves, printout=False)
bookCanvas(h, key=None, title='', nx=900, ny=600, cx=1, cy=1)