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

Comparing UserCode/RootMacros/overlayHists.py (file contents):
Revision 1.6 by klukas, Fri Nov 20 20:16:30 2009 UTC vs.
Revision 1.8 by klukas, Tue Nov 24 22:18:26 2009 UTC

# Line 19 | Line 19 | naming: histograms whose names contain c
19    'Logx': x-axis will be on log scale
20    'Logy': y-axis will be on log scale"""
21  
22 < ## Define colors
22 > ## Define colors and styles
23   rgbvals = [[82, 124, 219],
24 <           [145, 83, 207],
24 >           [212,58,143],
25             [231, 139, 77],
26 +           [145, 83, 207],
27             [114, 173, 117],
28             [67, 77, 83]]
29 + marker_styles = [3, 4, 5, 25, 26, 27, 28, 30]
30  
31   ## Import python libraries
32   import sys
# Line 33 | Line 35 | import os
35   import re
36  
37   ## Import ROOT in batch mode
38 < if '-h' not in sys.argv:
38 > if '-h' not in sys.argv and len(sys.argv) > 1:
39      sys.argv.append('-b')
40      import ROOT
41 <    if os.path.exists('rootlogon.C'): ROOT.gROOT.Macro('rootlogon.C')
41 >    if os.path.exists('rootlogon.C'):
42 >        ROOT.gROOT.Macro('rootlogon.C')
43 >    else:
44 >        os.system('echo -e "{\n}\n" >> rootlogon.C')
45 >        ROOT.gROOT.Macro('rootlogon.C')
46 >        os.remove('rootlogon.C')
47      sys.argv.remove('-b')
48      ROOT.gErrorIgnoreLevel = ROOT.kWarning
49      colors = [ROOT.TColor.GetColor(rgb[0], rgb[1], rgb[2]) for rgb in rgbvals]
# Line 46 | Line 53 | if '-h' not in sys.argv:
53   parser = optparse.OptionParser(usage=usage)
54   parser.add_option('-n', '--normalize', action="store_true", default=False,
55                    help="area normalize all histograms")
56 + parser.add_option('-m', '--markers', action="store_true", default=False,
57 +                  help="add markers to histograms")
58   parser.add_option('-e', '--ext', default="pdf",
59                    help="choose an output extension; default is pdf")
60   parser.add_option('-o', '--output', default="overlaidHists", metavar="NAME",
61                    help="name of output directory; default is 'overlaidHists'")
62 < parser.add_option('-m', '--match', default="", metavar="REGEX",
62 > parser.add_option('--match', default="", metavar="REGEX",
63                    help="only make plots for paths containing the specified "
64                    "regular expression (use '.*' for wildcard)")
65 + parser.add_option('--timing', action="store_true", default=False,
66 +                  help="output timing information")
67   options, arguments = parser.parse_args()
68   plot_dir = "%s/%s" % (os.path.abspath('.'), options.output)
69   regex = re.compile(options.match)
# Line 77 | Line 88 | def main():
88          parser.print_help()
89          sys.exit(0)
90      process_directory("", files)
91 <    print
91 >    print ""
92      if options.ext == "pdf":
93 <        print "Writing merged pdf..."
83 <        os.system("gs -q -dBATCH -dNOPAUSE -sDEVICE=pdfwrite "
84 <                  "-dAutoRotatePages=/All "
85 <                  "-sOutputFile=%s.pdf " % options.output +
86 <                  "[0-9][0-9][0-9].pdf")
87 <        os.system("rm [0-9]*.pdf")
93 >        merge_pdf()
94  
95  
96  
# Line 125 | Line 131 | def process_directory(path, files):
131                  hist.SetTitle(file.name)
132                  color = colors[i % len(colors)]
133                  hist.SetLineColor(color)
134 <                ## hist.SetMarkerColor(color)
135 <                ## hist.SetMarkerStyle(i + 1)
134 >                if options.markers:
135 >                    hist.SetMarkerColor(color)
136 >                    hist.SetMarkerStyle(marker_styles[i])
137 >                else:
138 >                    hist.SetMarkerSize(0)
139                  if "Norm" in name or options.normalize:
140                      integral = hist.Integral()
141                      hist.Scale(1. / integral)
# Line 139 | Line 148 | def process_directory(path, files):
148                  stack.SetMaximum(1.)
149                  stack.SetMinimum(0.)
150              legend.Draw()
151 <            if options.ext == "pdf":
143 <                c1.SaveAs("%.3i.pdf" % counter)
144 <            c1.SaveAs("%s/%s/%s.%s" % (plot_dir, path, name, options.ext))
145 <            print "\r%i plots written to %s" % (counter, options.output),
146 <            sys.stdout.flush()
151 >            save_plot(stack, plot_dir, path, name, counter)
152              
153  
154  
155 + def save_plot(stack, plot_dir, path, name, counter):
156 +    if options.ext == "pdf":
157 +        c1.SaveAs("%.3i.pdf" % counter)
158 +    c1.SaveAs("%s/%s/%s.%s" % (plot_dir, path, name, options.ext))
159 +    report_progress(counter, 1)
160 +
161 +
162 +
163 + def report_progress(counter, divisor):
164 +    if counter % divisor == 0:
165 +        print "\r%i plots written to %s" % (counter, options.output),
166 +        sys.stdout.flush()
167 +
168 +
169 +
170 + def merge_pdf():
171 +    print "Writing merged pdf..."
172 +    os.system("gs -q -dBATCH -dNOPAUSE -sDEVICE=pdfwrite "
173 +              "-dAutoRotatePages=/All "
174 +              "-sOutputFile=%s.pdf " % options.output +
175 +              "[0-9][0-9][0-9].pdf")
176 +    os.system("rm [0-9]*.pdf")
177 +
178 +
179 +
180   def counter_generator():
181      k = 0
182      while True:
# Line 157 | Line 187 | next_counter = counter_generator().next
187  
188  
189   if __name__ == "__main__":
190 <    sys.exit(main())
190 >    if options.timing:
191 >        import cProfile
192 >        cProfile.run('main()', 'fooprof')
193 >        import pstats
194 >        p = pstats.Stats('fooprof')
195 >        p.sort_stats('cumulative').print_stats(15)
196 >    else:
197 >        sys.exit(main())
198  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines