ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/GPetrucc/scripts/plotAll.py
Revision: 1.1
Committed: Tue Apr 28 18:02:22 2009 UTC (16 years ago) by gpetrucc
Content type: text/x-python
Branch: MAIN
CVS Tags: V00-00-05, V00-00-04
Log Message:
A bunch of useful scripts

File Contents

# Content
1 #!/usr/bin/env python
2 import ROOT; ROOT.gROOT.SetBatch()
3 import sys, os, re, shutil
4 from os.path import basename
5 from getopt import getopt
6
7 optlist, args = getopt(sys.argv[1:],'m:as:y:S:T')
8 opts = dict(optlist)
9 match = None
10 if opts.has_key("-m"):
11 match = re.compile(opts["-m"])
12 print "Filtering only items with [",opts["-m"],"]"
13 append = opts.has_key("-a")
14
15 yaxis = None
16 if opts.has_key('-y'): yaxis = [float(y) for y in opts['-y'].split(':')]
17
18 stacks = {}
19 for v in [ v for k,v in optlist if k == "-s"]:
20 (name,allsubplots) = v.split("=")
21 stacks[name] = allsubplots.split(",")
22 cols = [1,2,4,6,8]
23 markers = [8 , 21, 29, 24, 25, 27, 28]
24 markersizes = [1.5,1.5,2.5,1.5,1.5,1.5,1.5]
25
26 styles=[]
27 for v in [ v for k,v in optlist if k == "-S"]:
28 (meth,arg) = v.split("=")
29 styles.append(('Set'+meth,float(arg)))
30 print "Will try to Set%s(%f)" % (meth,float(arg))
31 def setStyle(x):
32 for (k,v) in styles:
33 if hasattr(x,k):
34 try:
35 (getattr(x,k))(float(v));
36 continue
37 except:
38 #print "Failed to call %s(float(%f)) " % (k,v)
39 pass
40 try:
41 (getattr(x,k))(int(v))
42 continue
43 except:
44 #print "Failed to call %s(int(%f)) " % (k,v)
45 pass
46 else:
47 print "Failed to resolve %s on a %s" % (k,x)
48
49 if opts.has_key("-T"):
50 ROOT.gROOT.ProcessLine(".L ~/cpp/tdrstyle.cc")
51 ROOT.gROOT.ProcessLine("setTDRStyle()")
52
53 c1 = ROOT.TCanvas("c1","c1")
54 ROOT.gStyle.SetPalette(1)
55 for f in args:
56 file = ROOT.TFile.Open(f)
57 fbase = basename(f).replace(".root","")
58 try:
59 os.mkdir(fbase)
60 shutil.copy("/afs/cern.ch/user/g/gpetrucc/php/index.php", fbase+"/index.php");
61 except:
62 pass
63 if append == False:
64 from glob import glob
65 for old in glob("%s/*.png" % (fbase,)): os.remove(old)
66 keys = file.GetListOfKeys()
67 theseitems = {}
68 for k in keys:
69 o = k.ReadObj(); t = o.ClassName()
70 theseitems[k.GetName()] = o
71 if match != None and match.search(k.GetName()) == None: continue
72 print "Got",k.GetName(),"of type",t
73 if t.find("TH2") != -1:
74 o.Draw("COLZ")
75 elif t.find("TH1") != -1:
76 if styles != []: setStyle(o)
77 o.Draw()
78 if yaxis != None:
79 o.GetYaxis().SetRangeUser(yaxis[0], yaxis[1])
80 elif t == "TCanvas":
81 o.Print("%s/%s.png" % (fbase,k.GetName()))
82 c1.cd()
83 continue
84 else:
85 continue
86 #o.Draw()
87 print "Wrote %s/%s.png" % (fbase,k.GetName())
88 c1.Print("%s/%s.png" % (fbase,k.GetName()))
89 for name,subs in stacks.items():
90 legend = ROOT.TLegend(.70,.98-0.04*len(subs),.98,.99)
91 legend.SetTextFont(42); legend.SetTextSize(0.04); legend.SetFillColor(0);
92 o = theseitems[subs[0]]; i = -1
93 if styles != []: setStyle(o)
94 o.SetLineColor(cols[i+1]); o.SetMarkerColor(cols[i+1]);
95 o.SetMarkerStyle(markers[i+1]); o.SetMarkerSize(markersizes[i+1]);
96 o.SetStats(False); o.Draw(); legend.AddEntry(o,subs[0])
97 if yaxis != None: o.GetYaxis().SetRangeUser(yaxis[0], yaxis[1])
98 for (i,s) in enumerate(subs[1:]):
99 o = theseitems[s]
100 if styles != []: setStyle(o)
101 o.SetLineColor(cols[i+1]); o.SetMarkerColor(cols[i+1]);
102 o.SetMarkerStyle(markers[i+1]); o.SetMarkerSize(markersizes[i+1]);
103 o.SetStats(False); o.Draw("SAME"); legend.AddEntry(o,s)
104 legend.Draw();
105 c1.Print("%s/%s.png" % (fbase,name))