plot_impactzipper.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 from math import log10
4 import ROOT
5 
6 def bilogify(hist, lmin = None):
7  """
8  Modify histogram so that it is rescaled in a "bilog" manner.
9  Negative values are -log10(-z). An offset in log10 is returned
10  and represents the 0.
11  """
12  nx,ny = hist.GetNbinsX(), hist.GetNbinsY()
13  zmax = max(abs(hist.GetMinimum()), abs(hist.GetMaximum()))
14 
15  if lmin is None:
16  zmin = sum([abs(hist.GetBinContent(99,iy)) for iy in range(ny)]) / ny
17  lmin = int(log10(zmin))
18 
19  lmax = 1+int(log10(zmax))
20 
21  for ix in range(hist.GetNbinsX()):
22  for iy in range(hist.GetNbinsY()):
23  val = hist.GetBinContent(ix, iy)
24  if val == 0.0:
25  hist.SetBinContent(ix, iy, 0.0)
26  continue
27 
28  sign = 1.0
29  if val > 0: # opposite sign to match Xin
30  sign = -1.0
31  lval = log10(abs(val))
32  if lval < lmin:
33  lval = 0.0
34  else:
35  lval -= lmin
36  lval *= sign
37  hist.SetBinContent(ix, iy, lval)
38  continue
39  continue
40 
41  lhmax = lmax - lmin
42 
43  hist.SetMaximum(lhmax)
44  hist.SetMinimum(-lhmax)
45  return lmin
46 
47 
48 from array import array
49 stops = array('d',[ 0.00, 0.45, 0.50, 0.55, 1.00 ])
50 reds = array('d',[ 0.00, 0.00, 1.00, 1.00, 0.51 ])
51 greens =array('d',[ 0.00, 0.81, 1.00, 0.20, 0.00 ])
52 blues =array('d',[ 0.51, 1.00, 1.00, 0.00, 0.00 ])
53 
54 #ROOT.gStyle.SetPalette(ROOT.kVisibleSpectrum)
55 #ROOT.TColor.CreateGradientColorTable(len(stops), stops, reds, greens, blues, 100)
56 ROOT.gStyle.SetNumberContours(100)
57 
58 def set_palette(which = "custom"):
59  if not which or which == "custom":
60  ROOT.TColor.CreateGradientColorTable(len(stops), stops, reds, greens, blues, 100)
61  return
62  ROOT.gStyle.SetPalette(which)
63 
64 fp = ROOT.TFile.Open("build/gen/test_impactzipper-uvw.root")
65 hists = {u:fp.Get("h%d"%n) for n,u in enumerate("uvw")}
66 limits = [1,1,2]
67 lmins = [-3, -3, -3]
68 
69 pdffile="plot_impactzipper.pdf"
70 
71 c = ROOT.TCanvas()
72 c.SetRightMargin(0.15)
73 c.Print(pdffile+"[","pdf")
74 c.SetGridx()
75 c.SetGridy()
76 
77 for (p,h),lim,lmin in zip(sorted(hists.items()), limits, lmins):
78  print p
79 
80  set_palette()
81  h.Draw("colz")
82  h.SetTitle(h.GetTitle() + " point source")
83  h.GetXaxis().SetRangeUser(3900, 4000)
84  h.GetYaxis().SetRangeUser(989, 1012)
85  h.GetZaxis().SetRangeUser(-lim, lim)
86  c.Print(pdffile,"pdf")
87 
88  set_palette(ROOT.kRainBow)
89  lminout = bilogify(h, lmin)
90  title = h.GetTitle()
91  title += " [sign(z)(log10(abs(z)) %d)]" % lminout
92  h.SetTitle(title)
93  h.SetZTitle("")
94  h.Draw("colz")
95  c.Print(pdffile,"pdf")
96 
97 
98 c.Print(pdffile+"]","pdf")
auto enumerate(Iterables &&...iterables)
Range-for loop helper tracking the number of iteration.
Definition: enumerate.h:69
T abs(T value)
static int max(int a, int b)
auto array(Array const &a)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:228
auto zip(Iterables &&...iterables)
Range-for loop helper iterating across many collections at the same time.
Definition: zip.h:295