6 from numpy
import isnan
7 from ROOT
import Double, TGraphErrors
17 nPointsNum = numeratorGraph.GetN()
18 nPointsDen = denominatorGraph.GetN()
20 if nPointsNum!=nPointsDen :
21 print "ERROR in JESUncertainty_RatioUtils:: graphs don't have the same number of points"
25 graphRatio = TGraphErrors()
26 graphRatio.SetName(numeratorGraph.GetName())
29 for iPoint
in xrange(0,nPointsNum) :
32 dataPointXNum = Double(0)
33 dataPointYNum = Double(0)
34 errorXNum = numeratorGraph.GetErrorX(iPoint)
35 errorYNum = numeratorGraph.GetErrorY(iPoint)
36 numeratorGraph.GetPoint(iPoint,dataPointXNum,dataPointYNum)
38 dataPointXDen = Double(0)
39 dataPointYDen = Double(0)
40 errorXDen = denominatorGraph.GetErrorX(iPoint)
41 errorYDen = denominatorGraph.GetErrorY(iPoint)
42 denominatorGraph.GetPoint(iPoint,dataPointXDen,dataPointYDen)
44 if abs(dataPointXNum-dataPointXDen) > 0.0001:
45 print "ERROR in JESUncertainty_RatioUtils::divideGraphs: x coordinates of data points do not match"
49 dataPointXRatio = dataPointXNum
50 dataPointYRatio =
None
51 if dataPointYDen != 0 :
52 dataPointYRatio = dataPointYNum/dataPointYDen
56 print "WARNING in JESUncertainty_RatioUtils::divideGraphs: division by zero for x point: ", dataPointXNum
57 print "numerator graph:", numeratorGraph.GetName()
58 print "denominator graph:", denominatorGraph.GetName()
60 errorXRatio = errorXNum
64 if errorYNum != 0
and errorYDen != 0 :
67 errorYRatioNoCorr = sqrt(
68 pow(errorYNum,2)/
pow(dataPointYDen,2)+
69 pow(errorYDen,2)*
pow(dataPointYNum,2)/
pow(dataPointYDen,4)
80 errorYRatio = errorYRatioNoCorr
84 elif dataPointYNum == 0
or dataPointYDen == 0 :
87 graphRatio.SetPoint(iPoint, dataPointXRatio, dataPointYRatio)
88 graphRatio.SetPointError(iPoint, errorXRatio, errorYRatio)
100 nPoints = graph.GetN()
103 deltaVarGraph = TGraphErrors()
104 deltaVarGraph.SetName(graph.GetName())
107 for iPoint
in xrange(0,nPoints) :
110 dataPointX = Double(0)
111 dataPointY = Double(0)
112 errorX = graph.GetErrorX(iPoint)
113 errorY = graph.GetErrorY(iPoint)
114 graph.GetPoint(iPoint,dataPointX,dataPointY)
117 dataPointXDeltaVar = dataPointX
118 dataPointYDeltaVar = abs(1-dataPointY)
119 errorXDeltaVar = errorX
121 deltaVarGraph.SetPoint(iPoint, dataPointXDeltaVar, dataPointYDeltaVar)
124 errorYDeltaVar = errorY
132 deltaVarGraph.SetPointError(iPoint, errorXDeltaVar, errorYDeltaVar)
144 nPointsGraph1= graph1.GetN()
145 nPointsGraph2 = graph2.GetN()
147 if nPointsGraph1!=nPointsGraph2 :
148 print "ERROR in JESUncertainty_RatioUtils::getMaxVariationGraph: graphs don't have the same number of points"
152 maxVarGraph = graph1.Clone()
153 maxVarGraph.SetName(graph1.GetName()+
"_Max")
156 for iPoint
in xrange(0,nPointsGraph1) :
160 maxPointError = Double(0)
163 dataPointXGraph1 = Double(0)
164 dataPointYGraph1 = Double(0)
165 errorXGraph1= graph1.GetErrorX(iPoint)
166 errorYGraph1 = graph1.GetErrorY(iPoint)
167 graph1.GetPoint(iPoint,dataPointXGraph1,dataPointYGraph1)
169 dataPointXGraph2 = Double(0)
170 dataPointYGraph2 = Double(0)
171 errorXGraph2 = graph2.GetErrorX(iPoint)
172 errorYGraph2 = graph2.GetErrorY(iPoint)
173 graph2.GetPoint(iPoint,dataPointXGraph2,dataPointYGraph2)
175 if abs(dataPointXGraph1-dataPointXGraph2) > 0.0001:
176 print "ERROR in JESUncertainty_RatioUtils::getMaxVariationGraph: x coordinates of data points do not match"
180 if dataPointYGraph1 > dataPointYGraph2 :
181 maxPoint = dataPointYGraph1
182 maxPointError = errorYGraph1
185 maxPoint = dataPointYGraph2
186 maxPointError = errorYGraph2
188 maxVarGraph.SetPoint(iPoint, dataPointXGraph1, maxPoint)
189 maxVarGraph.SetPointError(iPoint, errorXGraph1, maxPointError)
218 for graphToSum
in listOfGraphs :
220 nPointsDummyGraph = dummyGraph.GetN()
221 nPointsGraphToSum = graphToSum.GetN()
223 if nPointsDummyGraph!=nPointsGraphToSum :
224 print "ERROR in JESUncertainty_RatioUtils::getQuadratureGraph: graphs don't have the same number of points"
228 for iPoint
in xrange(0,nPointsDummyGraph) :
231 dataPointXDummyGraph = Double(0)
232 dataPointYDummyGraph = Double(0)
233 dummyGraph.GetPoint(iPoint,dataPointXDummyGraph,dataPointYDummyGraph)
235 dataPointXGraphToSum = Double(0)
236 dataPointYGraphToSum = Double(0)
237 errorXGraphToSum = graphToSum.GetErrorX(iPoint)
238 errorYGraphToSum = graphToSum.GetErrorY(iPoint)
239 graphToSum.GetPoint(iPoint,dataPointXGraphToSum,dataPointYGraphToSum)
241 if abs(dataPointXDummyGraph-dataPointXGraphToSum) > 0.0001:
242 print "ERROR in JESUncertainty_RatioUtils::getQuadratureGraph: x coordinates of data points do not match"
252 quadratureGraph = dummyGraph.Clone()
253 quadratureGraph.SetName(listOfGraphs[0].GetName()+
"_Quadrature")
255 for iPoint
in xrange(0,nPointsDummyGraph) :
261 for graphToSum
in listOfGraphs :
263 dataPointXGraphToSum = Double(0)
264 dataPointYGraphToSum = Double(0)
265 errorXGraphToSum = graphToSum.GetErrorX(iPoint)
266 errorYGraphToSum = graphToSum.GetErrorY(iPoint)
267 graphToSum.GetPoint(iPoint,dataPointXGraphToSum,dataPointYGraphToSum)
270 if dataPointYGraphToSum < -998 :
274 squaredSum +=
pow(dataPointYGraphToSum,2)
280 error +=
pow(dataPointYGraphToSum*errorYGraphToSum,2)
284 sqrtSquaredSum = sqrt(squaredSum)
285 sqrtError = sqrt(error/squaredSum)
292 sqrtSquaredSum = -999
293 sqrtError = 0.000000001
296 AllSquaredSums.append(sqrtSquaredSum)
297 AllErrors.append(sqrtError)
300 quadratureGraph.SetPoint(iPoint, dataPointXGraphToSum, sqrtSquaredSum)
301 quadratureGraph.SetPointError(iPoint, errorXGraphToSum, sqrtError)
303 return quadratureGraph
312 for graphToSum
in listOfGraphs :
314 nPointsDummyGraph = dummyGraph.GetN()
315 nPointsGraphToSum = graphToSum.GetN()
317 if nPointsDummyGraph!=nPointsGraphToSum :
318 print "ERROR in JESUncertainty_RatioUtils::getQuadratureGraph: graphs don't have the same number of points"
322 for iPoint
in xrange(0,nPointsDummyGraph) :
325 dataPointXDummyGraph = Double(0)
326 dataPointYDummyGraph = Double(0)
327 dummyGraph.GetPoint(iPoint,dataPointXDummyGraph,dataPointYDummyGraph)
329 dataPointXGraphToSum = Double(0)
330 dataPointYGraphToSum = Double(0)
331 errorXGraphToSum = graphToSum.GetErrorX(iPoint)
332 errorYGraphToSum = graphToSum.GetErrorY(iPoint)
333 graphToSum.GetPoint(iPoint,dataPointXGraphToSum,dataPointYGraphToSum)
335 if abs(dataPointXDummyGraph-dataPointXGraphToSum) > 0.0001:
336 print "ERROR in JESUncertainty_RatioUtils::getQuadratureGraph: x coordinates of data points do not match"
350 linearGraph = dummyGraph.Clone()
351 linearGraph.SetName(listOfGraphs[0].GetName()+
"_Quadrature")
353 for iPoint
in xrange(0,nPointsDummyGraph) :
360 for graphToSum
in listOfGraphs :
362 dataPointXGraphToSum = Double(0)
363 dataPointYGraphToSum = Double(0)
364 errorXGraphToSum = graphToSum.GetErrorX(iPoint)
365 errorYGraphToSum = graphToSum.GetErrorY(iPoint)
366 graphToSum.GetPoint(iPoint,dataPointXGraphToSum,dataPointYGraphToSum)
369 if dataPointYGraphToSum < -998 :
373 theSum += dataPointYGraphToSum
377 uncorrError +=
pow(errorYGraphToSum,2)
378 ListOfErrors.append(errorYGraphToSum)
382 while len(ListOfErrors) != 0 :
383 for iError, theError
in enumerate(ListOfErrors) :
384 theError = ListOfErrors.pop(iError)
385 for jError, theOtherError
in enumerate(ListOfErrors) :
386 corrError =+ theError * theOtherError
389 sqrtError = sqrt(uncorrError + 2 * corrError)
394 sqrtError = 0.000000001
397 AllSquaredSums.append(sqrtSum)
398 AllErrors.append(sqrtError)
403 linearGraph.SetPoint(iPoint, dataPointXGraphToSum, sqrtSum)
404 linearGraph.SetPointError(iPoint, errorXGraphToSum, sqrtError)