6 from ROOT
import TGraphErrors,TGraph, TGraphAsymmErrors, Double, TCanvas, gPad
8 from math
import fabs, sqrt
15 DataPointsForAverage=[]
19 nPointsNum = plotNum.GetN()
20 nPointsDen = plotDen.GetN()
22 if nPointsNum!=nPointsDen :
23 print "Plots don't have the same number of points!"
26 plotRatio = TGraphErrors()
28 plotRatio.SetName(plotNum.GetName())
40 for pointNum
in xrange(0,nPointsNum) :
41 pointNum =
int(pointNum)
43 for pointDen
in xrange(0,nPointsDen) :
44 pointDen =
int(pointDen)
45 plotNum.GetPoint(pointNum, x1, y1)
46 plotDen.GetPoint(pointDen, x2, y2)
47 dx1 = plotNum.GetErrorX(pointNum)
48 dx2 = plotNum.GetErrorX(pointDen)
50 if fabs(x1-x2)>=emean
and fabs(x1-x2)>dx :
54 matchcount=matchcount+1
55 dx1 = plotNum.GetErrorX(pointNum)
56 if y1 != 0 : dy1 = plotNum.GetErrorY(pointNum)/y1
57 if y2 != 0 : dy2 = plotNum.GetErrorY(pointDen)/y2
60 plotRatio.SetPoint(iv, x1, y1/y2)
61 if doAverage : DataPointsForAverage.append(y1/y2)
64 plotRatio.SetPoint(iv, x1, y2)
65 if doAverage : DataPointsForAverage.append(y2)
69 if y1 != 0
and y2 != 0 : e=sqrt(dy1*dy1+dy2*dy2)*(y1/y2)
70 plotRatio.SetPointError(iv, dx1, e)
71 if doAverage : ErrorsForAverage.append(e)
76 print "too many x points matched!"
82 maxDelta =
getMaxDelta(DataPointsForAverage, ErrorsForAverage)
85 return plotRatio, averageDelta-1, maxDelta
89 if len(DataPoints) != len(ErrorsOnDataPoints) :
90 "Data points and errors do not match"
96 for datapoint,error
in zip(DataPoints, ErrorsOnDataPoints) :
98 if error<0.00000001
or error>0.03 :
99 skippedDataPoints = skippedDataPoints+1
105 average = average/(len(DataPoints)-skippedDataPoints)
109 if len(DataPoints) != len(ErrorsOnDataPoints) :
110 "Data points and errors do not match"
115 for datapoint,error
in zip(DataPoints, ErrorsOnDataPoints) :
117 if error<0.00000001 :
123 if fabs(datapoint-1) > fabs(maxDelta) : maxDelta = datapoint-1
132 nPoints = graph.GetN()
134 newGraph=TGraphAsymmErrors(nPoints)
140 for iPoint
in xrange(0,nPoints) :
142 dataPointX = Double(0)
143 dataPointY = Double(0)
144 graph.GetPoint(iPoint,dataPointX,dataPointY)
145 dataErrorX = graph.GetErrorX(iPoint)
146 dataErrorY = graph.GetErrorY(iPoint)
149 newDataPointX = dataPointX * dataPointY
151 newErrorXLeft = fabs(newDataPointX - (dataPointX-dataErrorX))
152 newErrorXRight = fabs(newDataPointX - (dataPointX+dataErrorX))
155 newGraph.SetPoint(iPoint, newDataPointX, dataPointY)
156 newGraph.SetPointEXhigh(iPoint, newErrorXRight)
157 newGraph.SetPointEXlow(iPoint, newErrorXLeft)
158 newGraph.SetPointEYhigh(iPoint, dataErrorY)
159 newGraph.SetPointEYlow(iPoint, dataErrorY)
161 print dataPointY, newDataPointX
163 binRangeLow = dataPointX-dataErrorX
164 binRangeHigh = dataPointX+dataErrorX
165 if newDataPointX<binRangeLow
or newDataPointX>binRangeHigh :
166 print "Warning! Data point should not be here!"
167 print "Old data point: ", dataPointX
168 print "New NI data point:" , newDataPointX
169 print "XLow: ", binRangeLow
170 print "XHigh: ", binRangeHigh
171 newGraph.SetPoint(iPoint, dataPointX, 0.0000000000001)
172 newGraph.SetPointEXhigh(iPoint, dataErrorX)
173 newGraph.SetPointEXlow(iPoint, dataErrorX)
174 newGraph.SetPointEYhigh(iPoint, dataErrorY)
175 newGraph.SetPointEYlow(iPoint, dataErrorY)