4 from array
import array
5 from math
import fabs,exp,log,log10
16 return [key.GetName()
for key
in gDirectory.GetListOfKeys()]
17 TFile.GetKeyNames = GetKeyNames
20 return os.path.basename(self.GetName())
22 TFile.GetNameNoDir = GetNameNoDir
29 if name ==
"gray" or name ==
"grayscale":
30 stops = [0.00, 0.34, 0.61, 0.84, 1.00]
31 red = [1.00, 0.84, 0.61, 0.34, 0.00]
32 green = [1.00, 0.84, 0.61, 0.34, 0.00]
33 blue = [1.00, 0.84, 0.61, 0.34, 0.00]
34 elif name ==
"Sophie":
36 stops = [0.00, 0.50, 0.75, 1.00]
37 red = [1.00, 0.20, 0.00, 0.20]
38 green = [0.00, 0.20, 1.00, 1.00]
39 blue = [1.00, 1.00, 1.00, 0.20]
40 elif name ==
"SophieInverse":
42 stops = [0.00, 0.50, 0.75, 1.00]
43 red = [0.20, 0.00, 0.20, 1.00]
44 green = [1.00, 1.00, 0.20, 0.00]
45 blue = [0.20, 1.00, 1.00, 1.00]
46 elif name ==
"Steven":
48 stops = [0.00, 0.50, 1.00]
49 red = [0.70, 0.00, 0.20]
50 green = [0.00, 0.50, 1.00]
51 blue = [0.00, 0.70, 0.20]
52 elif name ==
"StevenInverse":
54 stops = [0.00, 0.50, 1.00]
55 red = [0.20, 0.00, 0.70]
56 green = [1.00, 0.50, 0.00]
57 blue = [0.20, 0.70, 0.00]
58 elif name ==
"StevenCentred":
60 stops = [0.00, 0.15, 0.50, 0.85, 1.00]
61 red = [0.00, 0.00, 0.20, 0.70, 1.00]
62 green = [0.00, 0.50, 1.00, 0.00, 0.00]
63 blue = [1.00, 0.70, 0.20, 0.00, 0.00]
66 stops = [0.00, 0.34, 0.61, 0.84, 1.00]
67 red = [0.00, 0.00, 0.87, 1.00, 0.51]
68 green = [0.00, 0.81, 1.00, 0.20, 0.00]
69 blue = [0.51, 1.00, 0.12, 0.00, 0.00]
77 TColor.CreateGradientColorTable(npoints, s, r, g, b, ncontours)
78 gStyle.SetNumberContours(ncontours)
83 gStyle.SetPaintTextFormat(
"0.3g")
90 if not doDrawText.tex:
91 doDrawText.tex = TLatex()
92 doDrawText.tex.SetNDC()
93 doDrawText.tex.SetTextFont(42)
94 doDrawText.tex.SetTextSize(0.040)
96 doDrawText.tex.DrawLatex(xPos,yPos,text)
104 for binX
in range(1,histo.GetNbinsX()+1):
105 for binY
in range(1,histo.GetNbinsY()+1):
106 value = histo.GetBinContent(binX,binY)
107 if value > lowBound
and value < highBound:
108 if value > max: max = value
109 if value < min: min = value
113 actuallyOneSided =
True
116 if not SetAxisRange.relativeAxis:
117 if max > 0
and min < 0:
118 balanceFrac = fabs(min/max)
if max != 0
else 100
119 if balanceFrac < 25
and balanceFrac > 0.25:
121 actuallyOneSided =
False
123 if max > 1
and min < 1:
124 balanceFrac = fabs((1-min)/(max-1))
if max != 1
else 100
125 if balanceFrac < 25
and balanceFrac > 0.25:
127 actuallyOneSided =
False
128 if not actuallyOneSided
and not SetAxisRange.forceOneSided:
129 print "Warning: Ignoring one-sided axis request due to magnitudes of min and max (|min/max| = |%f/%f| = %f)"%(min,max,balanceFrac)
130 print "This can be overridden using SetAxisRange.forceOneSided = True"
134 if not SetAxisRange.relativeAxis:
135 isPositiveSide =
True if max > 0
and max > fabs(min)
else False
137 isPositiveSide =
True if max > 1
and (max > 1/min
if min < 1
else max > min)
else False
141 if not SetAxisRange.relativeAxis:
143 print "Warning: Ignoring min of %f and setting min to 0"%(min)
146 print "Warning: Ignoring min of %f and setting min to 1"%(min)
150 set_palette(
"StevenInverse" if not SetAxisRange.invertAxisColour
else "Steven")
152 if not SetAxisRange.relativeAxis:
153 histo.GetZaxis().SetRangeUser(-1.e-4,
int(max*20+1)/20.)
155 histo.GetZaxis().SetRangeUser(1-1.e-4,
int(max*20+1)/20.)
157 elif not isPositiveSide:
158 if not SetAxisRange.relativeAxis:
160 print "Warning: Ignoring max of %f and setting max to 0"%(max)
163 print "Warning: Ignoring max of %f and setting max to 1"%(max)
167 set_palette(
"Steven" if not SetAxisRange.invertAxisColour
else "StevenInverse")
169 if not SetAxisRange.relativeAxis:
170 histo.GetZaxis().SetRangeUser(-
int(fabs(min)*20+1)/20.,1.e-4)
172 histo.GetZaxis().SetRangeUser(
int(min*20-1)/20.,1+1.e-4)
175 if not SetAxisRange.relativeAxis:
177 if fabs(max) > fabs(min):
178 extremeVal = fabs(max)
180 extremeVal = fabs(min)
184 histo.GetZaxis().SetRangeUser(-
int(extremeVal*20+1)/20.,
int(extremeVal*20+1)/20.)
193 histo.GetZaxis().SetRangeUser(min,
pow(10,-log10(min)))
196 histo.GetZaxis().SetRangeUser(
pow(10,-log10(max)),max)
197 SetAxisRange.forceOneSided =
False
198 SetAxisRange.relativeAxis =
False
199 SetAxisRange.invertAxisColour =
False
204 factorX = histo.GetNbinsX()/len(xValues)
205 factorY = histo.GetNbinsY()/len(yValues)
207 for index
in range(1,len(xValues)+1):
208 histo.GetXaxis().SetBinLabel(
int(factorX*(index-0.5)),labelString%(xValues[index-1]))
209 for index
in range(1,len(yValues)+1):
210 histo.GetYaxis().SetBinLabel(
int(factorY*(index-0.5)),labelString%(yValues[index-1]))
212 histo.GetXaxis().LabelsOption(
"h")
213 histo.GetYaxis().LabelsOption(
"h")
215 histo.GetXaxis().SetTickLength(0)
216 histo.GetYaxis().SetTickLength(0)
222 factorX = histo.GetNbinsX()/len(xValues)
223 factorY = histo.GetNbinsY()/len(yValues)
225 for index
in range(1,len(xValues)):
228 line.SetLineColor(kBlack)
230 line.DrawLine(
int(factorX*index),histo.GetYaxis().GetBinLowEdge(1),
int(factorX*index),histo.GetYaxis().GetBinLowEdge(histo.GetNbinsY()+1))
231 DrawGrid.lines.append(line)
232 for index
in range(1,len(yValues)):
235 line.SetLineColor(kBlack)
237 line.DrawLine(histo.GetXaxis().GetBinLowEdge(1),
int(factorY*index),histo.GetXaxis().GetBinLowEdge(histo.GetNbinsX()+1),
int(factorY*index))
238 DrawGrid.lines.append(line)
258 if not DetermineStatValues.tex:
259 DetermineStatValues.tex = TLatex()
260 DetermineStatValues.tex.SetTextSize(0.025)
261 DetermineStatValues.tex.SetTextFont(42)
262 DetermineStatValues.tex.SetTextColor(kBlack)
267 for indexX
in range(0,len(xValues)):
268 factorX =
int(histo.GetNbinsX()/len(xValues))
269 lowX = indexX*factorX+1
270 highX = (indexX+1)*factorX
271 for indexY
in range(0,len(yValues)):
272 factorY =
int(histo.GetNbinsY()/len(yValues))
273 lowY = indexY*factorY+1
274 highY = (indexY+1)*factorY
282 for binX
in range(lowX,highX):
283 for binY
in range(lowY,highY):
284 binValue = histo.GetBinContent(binX,binY)
285 if binValue > lowBound
and binValue < highBound:
288 if not DetermineStatValues.minInsteadOfMax
and fabs(binValue) > fabs(extremeVal):
289 extremeVal = binValue
290 elif DetermineStatValues.minInsteadOfMax
and fabs(binValue) < fabs(extremeVal):
291 extremeVal = binValue
292 if fabs(extremeVal) > fabs(overallMax) :
293 overallMax = extremeVal
296 if fabs(meanVal) > fabs(maxAvg) :
298 DetermineStatValues.tex.DrawLatex(
int(factorX*(indexX+0.4)),
int(factorY*(indexY+0.70)),
"%.f"%(extremeVal*100)
if percent
else "%.1f"%(extremeVal))
299 DetermineStatValues.tex.DrawLatex(
int(factorX*(indexX+0.4)),
int(factorY*(indexY+0.30)),
"%.f"%(meanVal*100)
if percent
else "%.1f"%(meanVal))
300 return overallMax,maxAvg
301 DetermineStatValues.tex =
None
302 DetermineStatValues.minInsteadOfMax =
False