7 sys.argv = [sys.argv[0],
'-b']
9 from ROOT
import TGraphAsymmErrors, Double, TGraphErrors, TCanvas
10 import atlasStyleMacro
11 from math
import fabs, sqrt
13 def makeBand (middleGraph, lowerGraph, upperGraph, noorder) :
15 bandsGraph = TGraphAsymmErrors()
16 bandsGraph.SetName(middleGraph.GetName())
17 bandsGraph.SetMarkerStyle(middleGraph.GetMarkerStyle());
18 bandsGraph.SetMarkerColor(middleGraph.GetMarkerColor());
19 bandsGraph.SetLineColor(middleGraph.GetLineColor());
31 if lowerGraph.GetN() != upperGraph.GetN()
or lowerGraph.GetN() != middleGraph.GetN() :
32 print "Plots don't have the same number of points!"
33 print "Lower: ", lowerGraph.GetN()
34 print "Upper: ", upperGraph.GetN()
35 print "Middle: ", middleGraph.GetN()
39 for iPoint
in xrange(1,lowerGraph.GetN()) :
40 middleGraph.GetPoint(iPoint, x1, y[0])
41 lowerGraph.GetPoint(iPoint, x1, y[1])
42 upperGraph.GetPoint(iPoint, x1, y[2])
44 if (iPoint == lowerGraph.GetN()-1) : x2 = x1
45 else : upperGraph.GetPoint(iPoint+1, x2, buf)
47 if (iPoint == 0) : x3 = x1
48 else : upperGraph.GetPoint(iPoint-1, x3, buf)
82 bandsGraph.SetPoint(iPoint, x1, yce)
84 ex0 = Double(lowerGraph.GetErrorX(iPoint))
92 if binwl==0. : binwl= binwh;
93 if binwh==0. : binwh= binwl;
107 bandsGraph.SetPointError(iPoint, binwl, binwh, dxl, dxh)
116 if graph1.GetN() != graph2.GetN() :
118 print "Plots don't have the same number of points!"
119 print "Error: ", graph1.GetN()
120 print "Middle: ", graph2.GetN()
123 largestGraph = graph1.Clone()
125 for iPoint
in xrange(0, graph1.GetN()) :
128 graph1PointX = Double(0)
129 graph1PointY = Double(0)
130 graph1ErrorX = graph1.GetErrorX(iPoint)
131 graph1ErrorY = graph1.GetErrorY(iPoint)
133 graph1.GetPoint(iPoint,graph1PointX,graph1PointY)
135 graph2PointX = Double(0)
136 graph2PointY = Double(0)
137 graph2ErrorX = graph2.GetErrorX(iPoint)
138 graph2ErrorY = graph2.GetErrorY(iPoint)
140 graph2.GetPoint(iPoint,graph2PointX,graph2PointY)
143 if graph1PointX - graph2PointX > 0.0001 :
144 print "Points are not ordered!"
145 print "graph1: ", graph1PointX
146 print "graph2: ", graph2PointX
149 largestPoint = Double(0)
152 if fabs(fabs(1-graph1PointY) - fabs(1-graph2PointY)) > 1000 :
153 print "found bad data point: ", graph1PointX, graph2PointY
154 if fabs(1-graph1PointY) > 100 :
155 largestPoint = graph2PointY
156 largestPointErrorX = graph2ErrorX
157 largestPointErrorY = graph2ErrorY
158 if fabs(1-graph2PointY) > 100 :
159 largestPoint = graph1PointX
160 largestPointErrorX = graph1ErrorX
161 largestPointErrorY = graph1ErrorY
164 elif fabs(1-graph1PointY) > fabs(1-graph2PointY) :
165 largestPoint = graph1PointY
166 largestPointErrorX = graph1ErrorX
167 largestPointErrorY = graph1ErrorY
170 largestPoint = graph2PointY
171 largestPointErrorX = graph2ErrorX
172 largestPointErrorY = graph2ErrorY
174 print "newpoint:", largestPoint, largestPointErrorY
177 largestGraph.SetPoint(iPoint, graph1PointX, largestPoint)
178 largestGraph.SetPointError(iPoint, largestPointErrorX, largestPointErrorY)
185 varGraph = graph.Clone()
187 for iPoint
in xrange(0, graph.GetN()) :
190 graphPointX = Double(0)
191 graphPointY = Double(0)
192 graphErrorX = graph.GetErrorX(iPoint)
193 graphErrorY = graph.GetErrorY(iPoint)
195 graph.GetPoint(iPoint,graphPointX,graphPointY)
199 newPoint = fabs(1-graphPointY)
200 newPointErrorX = graphErrorX
201 newPointErrorY = graphErrorY
204 varGraph.SetPoint(iPoint, graphPointX, newPoint)
205 varGraph.SetPointError(iPoint, newPointErrorX, newPointErrorY)
216 for iPoint
in xrange(0, middleGraph.GetN()) :
219 dataPointX = Double(0)
220 dataPointY = Double(0)
221 middleGraph.GetPoint(iPoint,dataPointX,dataPointY)
230 for errorGraph
in errorGraphs:
233 bandsGraph += [TGraphAsymmErrors()]
235 thisBandsGraph = bandsGraph[index]
236 thisBandsGraph.SetName(middleGraph.GetName())
237 thisBandsGraph.SetMarkerStyle(middleGraph.GetMarkerStyle());
238 thisBandsGraph.SetMarkerSize(middleGraph.GetMarkerSize());
239 thisBandsGraph.SetMarkerColor(middleGraph.GetMarkerColor());
240 thisBandsGraph.SetLineColor(middleGraph.GetLineColor());
245 if errorGraph.GetN() != middleGraph.GetN() :
246 print "Plots don't have the same number of points!"
247 print "Error: ", errorGraph.GetN()
248 print "Middle: ", middleGraph.GetN()
252 errorPointX = Double(0)
253 errorPointY = Double(0)
254 errorGraph.GetPoint(iPoint,errorPointX,errorPointY)
257 if dataPointX - errorPointX > 0.0001 :
258 print "Points are not ordered!"
259 print "dataPointX: ", dataPointX
260 print "errorX: ", errorPointX
263 errorX = middleGraph.GetErrorX(iPoint)
264 errorY += [fabs(1-errorPointY)]
267 sumErrorY = Double(0)
273 sumErrorY = sqrt(sumErrorY)
276 if( iPoint < middleGraph.GetN()):
277 thisBandsGraph.SetPoint(iPoint, dataPointX, 0)
278 thisBandsGraph.SetPointError(iPoint, errorX, errorX, sumErrorY, sumErrorY)
279 thisBandsGraph.SetPointEYlow(iPoint, 0)
281 return bandsGraph[-1:]
289 for iPoint
in xrange(0, middleGraph.GetN()) :
292 dataPointX = Double(0)
293 dataPointY = Double(0)
294 middleGraph.GetPoint(iPoint,dataPointX,dataPointY)
304 for iGraph, varGraph
in enumerate(varGraphs):
309 bandsGraph += [TGraphAsymmErrors()]
311 thisBandsGraph = bandsGraph[index]
312 thisBandsGraph.SetName(middleGraph.GetName())
313 thisBandsGraph.SetMarkerStyle(middleGraph.GetMarkerStyle());
314 thisBandsGraph.SetMarkerSize(middleGraph.GetMarkerSize());
315 thisBandsGraph.SetMarkerColor(middleGraph.GetMarkerColor());
316 thisBandsGraph.SetLineColor(middleGraph.GetLineColor());
321 if varGraph.GetN() != middleGraph.GetN() :
322 print "Plots don't have the same number of points!"
323 print "Error: ", varGraph.GetN()
324 print "Middle: ", middleGraph.GetN()
328 varPointX = Double(0)
329 varPointY = Double(0)
330 varGraph.GetPoint(iPoint,varPointX,varPointY)
331 varErrorY = varGraph.GetErrorY(iPoint)
335 if dataPointX - varPointX > 0.0001 :
336 print "Points are not ordered!"
337 print "dataPointX: ", dataPointX
338 print "varX: ", varPointX
341 varX = middleGraph.GetErrorX(iPoint)
342 varY += [fabs(1-varPointY)]
343 errorY += [varErrorY]
348 propagationY = Double(0)
353 sumVarY = sqrt(sumVarY)
358 for var, error
in zip(varY, errorY) :
359 if sumVarY > 0.0000001 : propagationY += var*var / sumVarY * error
364 propagationY = sqrt(propagationY)
370 if( iPoint < middleGraph.GetN()):
371 thisBandsGraph.SetPoint(iPoint, dataPointX, 0)
372 thisBandsGraph.SetPointError(iPoint, varX, varX, sumVarY, sumVarY)
373 thisBandsGraph.SetPointEYlow(iPoint, 0)
376 if (iGraph == len(varGraphs)-1) :
377 propagationVarY += [propagationY]
386 return (bandsGraph[-1:], propagationVarY)