6 from numpy
import isnan
7 from ROOT
import Double, TH1F
20 nPoints = graph.GetN()
22 for iPoint
in xrange(0,nPoints) :
23 dataPointX = Double(0)
24 dataPointY = Double(0)
26 errorX = graph.GetErrorX(iPoint)
27 errorY = graph.GetErrorY(iPoint)
29 graph.GetPoint(iPoint,dataPointX,dataPointY)
32 if isnan(dataPointY) :
39 if errorY < 0.00000001 :
47 print "DEBUG: List of bad points for plot", graph.GetName(),
":"
62 nPoints = graph.GetN()
64 for iPoint
in xrange(0,nPoints) :
65 dataPointX = Double(0)
66 dataPointY = Double(0)
68 errorX = graph.GetErrorX(iPoint)
69 errorY = graph.GetErrorY(iPoint)
71 graph.GetPoint(iPoint,dataPointX,dataPointY)
74 if isnan(dataPointY) :
81 if errorY < 0.00000001 :
86 print "DEBUG: List of bad points for plot", graph.GetName(),
":"
94 nPoints = graph.GetN()
96 for iPoint
in xrange(0,nPoints) :
97 dataPointX = Double(0)
98 dataPointY = Double(0)
100 errorX = graph.GetErrorX(iPoint)
101 errorY = graph.GetErrorY(iPoint)
103 graph.GetPoint(iPoint,dataPointX,dataPointY)
105 if iPoint
in listOfBadPoints :
107 graph.SetPoint(iPoint, dataPointX, -999)
108 graph.SetPointError(iPoint, errorX, 0)
113 nPoints = graph.GetN()
115 for iPoint
in xrange(0,nPoints) :
116 dataPointX = Double(0)
117 dataPointY = Double(0)
119 errorX = graph.GetErrorX(iPoint)
120 errorY = graph.GetErrorY(iPoint)
122 graph.GetPoint(iPoint,dataPointX,dataPointY)
124 graph.SetPoint(iPoint, dataPointX/1000, dataPointY)
125 graph.SetPointError(iPoint, errorX/1000, errorY)
130 nPoints = graph.GetN()
132 print graph.GetName()
134 for iPoint
in xrange(0,nPoints) :
135 dataPointX = Double(0)
136 dataPointY = Double(0)
138 errorX = graph.GetErrorX(iPoint)
139 errorY = graph.GetErrorY(iPoint)
141 graph.GetPoint(iPoint,dataPointX,dataPointY)
143 print dataPointX,
":", dataPointY
148 nPoints = graph.GetN()
150 for iPoint
in xrange(0,nPoints) :
151 errorY = graph.GetErrorY(iPoint)
152 graph.SetPointError(iPoint, 0, errorY)
157 nPoints = graph.GetN()
159 for iPoint
in xrange(0,nPoints) :
160 errorX = graph.GetErrorX(iPoint)
161 graph.SetPointError(iPoint, errorX, 0.00000001)
164 def scaleGraph(graphToScale, scalingInputGraph, oneMinus = False) :
167 nPointsGraphToScale= graphToScale.GetN()
168 nPointsScalingInputGraph = scalingInputGraph.GetN()
170 if nPointsGraphToScale!=nPointsScalingInputGraph :
171 print "ERROR in JESUncertainty_RatioUtils::scaleGraph: graphs don't have the same number of points"
175 scaledGraph = graphToScale.Clone()
176 scaledGraph.SetName(graphToScale.GetName()+
"_Scaled")
179 for iPoint
in xrange(0,nPointsGraphToScale) :
183 maxPointError = Double(0)
186 dataPointXgraphToScale = Double(0)
187 dataPointYgraphToScale = Double(0)
188 errorXgraphToScale= graphToScale.GetErrorX(iPoint)
189 errorYgraphToScale = graphToScale.GetErrorY(iPoint)
190 graphToScale.GetPoint(iPoint,dataPointXgraphToScale,dataPointYgraphToScale)
192 dataPointXscalingInputGraph = Double(0)
193 dataPointYscalingInputGraph = Double(0)
194 errorXscalingInputGraph = scalingInputGraph.GetErrorX(iPoint)
195 errorYscalingInputGraph = scalingInputGraph.GetErrorY(iPoint)
196 scalingInputGraph.GetPoint(iPoint,dataPointXscalingInputGraph,dataPointYscalingInputGraph)
198 if abs(dataPointXgraphToScale-dataPointXscalingInputGraph) > 0.0001:
199 print "ERROR in JESUncertainty_RatioUtils::scaleGraph: x coordinates of data points do not match"
203 if abs(dataPointYscalingInputGraph) < 0:
204 print "WARNING in JESUncertainty_RatioUtils::scaleGraph: negative scale factor for point: ", iPoint,
", X:", dataPointXgraphToScale
205 scaledGraph.SetPoint(iPoint, dataPointXgraphToScale, dataPointYscalingInputGraph*dataPointYgraphToScale)
206 scaledGraph.SetPointError(iPoint, errorXgraphToScale, abs(dataPointYscalingInputGraph)*dataPointYgraphToScale)
209 scaledGraph.SetPoint(iPoint, dataPointXgraphToScale, (1-dataPointYscalingInputGraph)*dataPointYgraphToScale)
210 scaledGraph.SetPointError(iPoint, errorXgraphToScale, abs(dataPointYscalingInputGraph)*dataPointYgraphToScale)
217 nPoints = graph.GetN()
223 for iPoint
in xrange(0,nPoints) :
224 dataPointX = Double(0)
225 dataPointY = Double(0)
227 errorX = graph.GetErrorX(iPoint)
228 errorY = graph.GetErrorY(iPoint)
230 graph.GetPoint(iPoint,dataPointX,dataPointY)
233 if dataPointY > 2.
or errorY > 0.1:
235 print "WARNING in JESUncertainty_RatioUtils::extendLastGoodBin: "
236 print "found bad point for graph:", graph.GetName(),
"at point: ", iPoint,
", X:", dataPointX,
"Y:", dataPointY
237 print "extending previous point:", lastGoodBin
238 newDataPointY=lastGoodBin
239 newErrorY = lastGoodError
240 graph.SetPoint(iPoint,dataPointX,newDataPointY)
241 graph.SetPointError(iPoint, errorX, newErrorY)
243 lastGoodBin = dataPointY
244 lastGoodError = errorY
251 nPoints = graph.GetN()
261 for iPoint
in xrange(0,nPoints) :
263 dataPointX = Double(0)
264 dataPointY = Double(0)
265 graph.GetPoint(iPoint,dataPointX,dataPointY)
266 dataErrorX = graph.GetErrorX(iPoint)
267 dataErrorY = graph.GetErrorY(iPoint)
269 x.append(dataPointX-dataErrorX)
271 ey.append(dataErrorY)
274 x.append(dataPointX+dataErrorX)
277 for iPoint
in xrange(0,nPoints) :
278 if isnan(y[iPoint]) :
280 if isnan(x[iPoint]) :
282 if y[iPoint]<0.00000001 :
286 myHist=
TH1F(
"Hist"+graph.GetName(),graph.GetTitle(),nPoints,x)
288 for iPoint
in xrange(0,nPoints) :
290 myHist.SetBinContent(iPoint+1,y[iPoint])
292 myHist.SetBinError(iPoint+1,0)
300 nPoints = graph.GetN()
310 for iPoint
in xrange(0,nPoints) :
312 dataPointX = Double(0)
313 dataPointY = Double(0)
314 graph.GetPoint(iPoint,dataPointX,dataPointY)
315 dataErrorX = graph.GetErrorX(iPoint)
316 dataErrorY = graph.GetErrorY(iPoint)
318 x.append(dataPointX-dataErrorX)
320 ey.append(dataErrorY)
323 x.append(dataPointX+dataErrorX)
326 for iPoint
in xrange(0,nPoints) :
327 if isnan(y[iPoint]) :
329 if isnan(x[iPoint]) :
331 if y[iPoint]<0.00000001 :
335 myHist=
TH1F(
"Hist"+graph.GetName(),graph.GetTitle(),nPoints,x)
337 for iPoint
in xrange(0,nPoints) :
339 myHist.SetBinContent(iPoint+1,y[iPoint])
340 myHist.SetBinError(iPoint+1,ey[iPoint])