ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/GPetrucc/scripts/plotAll.py
(Generate patch)

Comparing UserCode/GPetrucc/scripts/plotAll.py (file contents):
Revision 1.2 by gpetrucc, Wed May 13 15:35:56 2009 UTC vs.
Revision 1.4 by gpetrucc, Tue Jun 30 10:01:45 2009 UTC

# Line 4 | Line 4 | 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')
7 > optlist, args = getopt(sys.argv[1:],'m:as:d:y:S:Trzx')
8   opts = dict(optlist)
9   match = None
10   if opts.has_key("-m"):
# Line 15 | Line 15 | append = opts.has_key("-a")
15   yaxis = None
16   if opts.has_key('-y'): yaxis = [float(y) for y in opts['-y'].split(':')]
17  
18 < stacks = {}
18 > reversePrefix = opts.has_key("-r")
19 >
20 > stacks = {}; diffs = {}
21   for v in [ v for k,v in optlist if k == "-s"]:
22      (name,allsubplots) = v.split("=")
23      stacks[name] = allsubplots.split(",")
24 < cols = [1,2,4,6,8]
25 < markers     = [8  , 21, 29, 24, 25, 27, 28]
26 < markersizes = [1.5,1.5,2.5,1.5,1.5,1.5,1.5]
24 > for v in [ v for k,v in optlist if k == "-d"]:
25 >    (name,allsubplots) = v.split("=")
26 >    diffs[name] = allsubplots.split(",")
27 > cols = [1,4,2,209,6,8]
28 > print "color: ",cols
29 > markers     = [8  , 29, 21, 24, 25, 27, 28]
30 > markersizes = [2.1,2.5,1.1,1.5,1.5,1.5,1.5]
31 > legendYup = .30# .98
32  
33   styles=[]
34   for v in [ v for k,v in optlist if k == "-S"]:
# Line 49 | Line 56 | def setStyle(x):
56   if opts.has_key("-T"):
57      ROOT.gROOT.ProcessLine(".L ~/cpp/tdrstyle.cc")
58      ROOT.gROOT.ProcessLine("setTDRStyle()")
59 + if opts.has_key("-x"):
60 +    ROOT.gStyle.SetErrorX(0.5)
61 +    
62  
63   c1 = ROOT.TCanvas("c1","c1")
64   ROOT.gStyle.SetPalette(1)
65 < for f in args:
66 <    file = ROOT.TFile.Open(f)
67 <    fbase = basename(f).replace(".root","")
68 <    try:
69 <        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)
65 >
66 > if opts.has_key("-z"):
67 >    ROOT.gStyle.SetHistMinimumZero();
68 >
69 > def goPlot(file,fbase,prefix=""):
70      keys = file.GetListOfKeys()
71      theseitems = {}
72      for k in keys:
# Line 70 | Line 74 | for f in args:
74          theseitems[k.GetName()] = o
75          if match != None and match.search(k.GetName()) == None: continue
76          print "Got",k.GetName(),"of type",t
77 +        plotname = reversePrefix and k.GetName()+prefix or prefix+k.GetName();
78          if t.find("TH2") != -1:
79              c1.cd()
80              o.Draw("COLZ")
# Line 80 | Line 85 | for f in args:
85              if yaxis != None:
86                  o.GetYaxis().SetRangeUser(yaxis[0], yaxis[1])
87          elif t == "TCanvas":
88 <            o.Print("%s/%s.png" % (fbase,k.GetName()))
88 >            o.Print("%s/%s.png" % (fbase,plotname))
89              c1.cd()
90              continue
91 +        elif t == "TDirectoryFile":
92 +            
93 +            goPlot(o,fbase, reversePrefix and ("_"+k.GetName()+prefix) or (prefix+k.GetName()+"_"))
94 +            continue
95          else:
96              continue
97              #o.Draw()
98 <        print "Wrote %s/%s.png" % (fbase,k.GetName())
99 <        c1.Print("%s/%s.png" % (fbase,k.GetName()))
98 >        print "Wrote %s/%s.png" % (fbase,plotname)
99 >        c1.Print("%s/%s.png" % (fbase,plotname))
100      for name,subs in stacks.items():
101 <        legend = ROOT.TLegend(.65,.98-0.04*len(subs),.98,.99)
101 >        legend = ROOT.TLegend(.60,legendYup-0.04*len(subs),.96,legendYup+.01)
102          legend.SetTextFont(42); legend.SetTextSize(0.04); legend.SetFillColor(0);
103          o = theseitems[subs[0]]; i = -1
104          if styles != []: setStyle(o)
# Line 97 | Line 106 | for f in args:
106          o.SetMarkerStyle(markers[i+1]); o.SetMarkerSize(markersizes[i+1]);
107          o.SetStats(False); o.Draw(); legend.AddEntry(o,subs[0])
108          if yaxis != None: o.GetYaxis().SetRangeUser(yaxis[0], yaxis[1])
109 <        for (i,s) in enumerate(subs[1:]):
109 >        for (i,s) in [p for p in enumerate(subs[1:])]: #+ [(-1,subs[0])]:
110              o = theseitems[s]
111              if styles != []: setStyle(o)
112              o.SetLineColor(cols[i+1]); o.SetMarkerColor(cols[i+1]);
113              o.SetMarkerStyle(markers[i+1]); o.SetMarkerSize(markersizes[i+1]);
114 <            o.SetStats(False); o.Draw("SAME"); legend.AddEntry(o,s)
114 >            o.SetStats(False); o.Draw("SAME");
115 >            if i != -1: legend.AddEntry(o,s)
116 >        legend.Draw();
117 >        c1.Print("%s/%s.png" % (fbase,reversePrefix and name+prefix or prefix+name))
118 >    for name,subs in diffs.items():
119 >        c1.cd();
120 >        toplot = []
121 >        legend = ROOT.TLegend(.60,legendYup-0.04*len(subs),.96,legendYup+.01)
122 >        legend.SetTextFont(42); legend.SetTextSize(0.04); legend.SetFillColor(0);
123 >        o0 = theseitems[subs[0]].Clone();
124 >        for b in range(0, o0.GetNbinsX()+2): o0.SetBinError(b, 0.0)
125 >        o = theseitems[subs[0]].Clone(name);
126 >        o.Add(o0, -1); i = -1
127 >        if styles != []: setStyle(o)
128 >        o.SetLineColor(cols[i+1]); o.SetMarkerColor(cols[i+1]);
129 >        o.SetMarkerStyle(markers[i+1]); o.SetMarkerSize(markersizes[i+1]);
130 >        o.SetStats(False); toplot.append(o); legend.AddEntry(o,subs[0])
131 >        for (i,s) in [p for p in enumerate(subs[1:])]: #+ [(-1,subs[0])]:
132 >            o = theseitems[s].Clone(); o.Add(o0, -1)
133 >            if styles != []: setStyle(o)
134 >            o.SetLineColor(cols[i+1]); o.SetMarkerColor(cols[i+1]);
135 >            o.SetMarkerStyle(markers[i+1]); o.SetMarkerSize(markersizes[i+1]);
136 >            o.SetStats(False);
137 >            if i != -1: toplot.append(o);
138 >            if i != -1: legend.AddEntry(o,s)
139 >        toplot[1].Draw();
140 >        if yaxis != None: toplot[1].GetYaxis().SetRangeUser(yaxis[0], yaxis[1])
141 >        for X in toplot: X.Draw("SAME")
142          legend.Draw();
143 <        c1.Print("%s/%s.png" % (fbase,name))
143 >        c1.Print("%s/%s.png" % (fbase,reversePrefix and name+prefix or prefix+name))
144 >
145 >
146 > for f in args:
147 >    file = ROOT.TFile.Open(f)
148 >    fbase = basename(f).replace(".root","")
149 >    try:
150 >        os.mkdir(fbase)
151 >        shutil.copy("/afs/cern.ch/user/g/gpetrucc/php/index.php", fbase+"/index.php");
152 >    except:
153 >        pass
154 >    if append == False:
155 >        from glob import glob
156 >        for old in glob("%s/*.png" % (fbase,)): os.remove(old)
157 >    goPlot(file,fbase)
158 >

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines