ATLAS Offline Software
Functions | Variables
FormattingUtils Namespace Reference

Functions

def formatPlotNoStat (plot)
 
def formatJetPlot (plot, i)
 
def rescaleJetPlot (plot)
 
def fixPlots (middleGraph)
 
def fixPlots_withErrors (middleGraph)
 
def removeLargeErrorPoints (nomGraph, graphs)
 
def removeLargeErrorPoints_noFirstBin (nomGraph, graphs)
 
def removeLargeErrorPoints_noCheck (nomGraph, graphs)
 
def TGraphToTH1 (graph)
 
def TGraphToTH1_error (graph)
 
def removeLargeErrorPointsSingle (graph)
 

Variables

 argv
 

Function Documentation

◆ fixPlots()

def FormattingUtils.fixPlots (   middleGraph)

Definition at line 66 of file FormattingUtils.py.

66 def fixPlots (middleGraph) :
67 
68  thisBandsGraph = TGraphAsymmErrors()
69  thisBandsGraph.SetName(middleGraph.GetName())
70  thisBandsGraph.SetMarkerStyle(middleGraph.GetMarkerStyle());
71  thisBandsGraph.SetMarkerSize(middleGraph.GetMarkerSize());
72  thisBandsGraph.SetMarkerColor(middleGraph.GetMarkerColor());
73  thisBandsGraph.SetLineColor(middleGraph.GetLineColor());
74 
75  for iPoint in xrange(0, middleGraph.GetN()) :
76  # Retrieve middle graph for (x,y) coordinates
77  dataPointX = Double(0)
78  dataPointY = Double(0)
79  dataErrorX = Double(0)
80 
81  middleGraph.GetPoint(iPoint,dataPointX,dataPointY)
82  dataErrorX = middleGraph.GetErrorX(iPoint)
83  dataPointY = fabs(dataPointY-1)
84 
85  if(dataPointY != 0 and iPoint < middleGraph.GetN()):
86  thisBandsGraph.SetPoint(iPoint, dataPointX, dataPointY)
87  thisBandsGraph.SetPointError(iPoint, dataErrorX, dataErrorX, 0, 0)
88 
89  return thisBandsGraph
90 

◆ fixPlots_withErrors()

def FormattingUtils.fixPlots_withErrors (   middleGraph)

Definition at line 91 of file FormattingUtils.py.

91 def fixPlots_withErrors (middleGraph) :
92 
93  thisBandsGraph = TGraphAsymmErrors()
94  thisBandsGraph.SetName(middleGraph.GetName())
95  thisBandsGraph.SetMarkerStyle(middleGraph.GetMarkerStyle());
96  thisBandsGraph.SetMarkerSize(middleGraph.GetMarkerSize());
97  thisBandsGraph.SetMarkerColor(middleGraph.GetMarkerColor());
98  thisBandsGraph.SetLineColor(middleGraph.GetLineColor());
99 
100  for iPoint in xrange(0, middleGraph.GetN()) :
101  # Retrieve middle graph for (x,y) coordinates
102  dataPointX = Double(0)
103  dataPointY = Double(0)
104  dataErrorX = Double(0)
105 
106  middleGraph.GetPoint(iPoint,dataPointX,dataPointY)
107  dataErrorX = middleGraph.GetErrorX(iPoint)
108  dataErrorY = middleGraph.GetErrorY(iPoint)
109 
110  dataPointY = fabs(dataPointY-1)
111 
112  if(iPoint < middleGraph.GetN()):
113  #if(dataPointY != 0 and iPoint < middleGraph.GetN()):
114 
115  print "fixPlots:" , dataPointX
116 
117  thisBandsGraph.SetPoint(iPoint, dataPointX, dataPointY)
118  thisBandsGraph.SetPointError(iPoint, dataErrorX, dataErrorX, dataErrorY, dataErrorY)
119 
120  #if (dataPointY == 0) :
121 
122  #thisBandsGraph.SetPoint(iPoint, dataPointX, dataPointY)
123  #thisBandsGraph.SetPointError(iPoint, dataErrorX, dataErrorX, dataErrorY, dataErrorY)
124 
125  return thisBandsGraph
126 

◆ formatJetPlot()

def FormattingUtils.formatJetPlot (   plot,
  i 
)

Definition at line 23 of file FormattingUtils.py.

23 def formatJetPlot (plot, i) :
24 # colorlist = [214,100,617,417,221,869,603,635,807,413,616,215]
25  #colorlist = [413,603,633,807,100,869,2,616,215,214,617,417]
26  #markerlist = [20,24,22,26,23,21,27,25,29,28,5]
27  colorlist = [214,100,221,417,869,617,603,635,807,413,616,215]
28  markerlist = [20,25,22,26,21,20,24,27,29,28,20,30]
29 
30 
31  plot.SetMarkerStyle(markerlist[i])
32  plot.SetMarkerColor(colorlist[i])
33  plot.SetMarkerSize(1)
34  plot.SetLineColor(colorlist[i])
35 

◆ formatPlotNoStat()

def FormattingUtils.formatPlotNoStat (   plot)

Definition at line 14 of file FormattingUtils.py.

14 def formatPlotNoStat (plot) :
15  #plot.SetTitleFont(42)
16  plot.GetXaxis().SetLabelFont(42)
17  plot.GetXaxis().SetTitleFont(42)
18  plot.GetYaxis().SetLabelFont(42)
19  plot.GetYaxis().SetTitleFont(42)
20  #plot.ResetStats()
21  #plot.SetStats(False)
22 

◆ removeLargeErrorPoints()

def FormattingUtils.removeLargeErrorPoints (   nomGraph,
  graphs 
)

Definition at line 127 of file FormattingUtils.py.

127 def removeLargeErrorPoints(nomGraph, graphs) :
128 
129  newGraphsIntermediate = []
130  newGraphsFinal = []
131  badPoints = []
132 
133  for i, graph in enumerate(graphs+[nomGraph]):
134  #print graph.GetName()
135 
136  for iPoint in xrange(0, graph.GetN()) :
137 
138  dataPointX = Double(0)
139  dataPointY = Double(0)
140 
141  graph.GetPoint(iPoint,dataPointX,dataPointY)
142  dataErrorX = graph.GetErrorX(iPoint)
143  dataErrorY = graph.GetErrorY(iPoint)
144  print "graph no:", i
145  print graph.GetName()
146 
147  print "removeLargeErrorPoints:" , dataPointX, dataPointY, dataErrorX, dataErrorY
148 
149  if dataErrorY > 0.011 or dataErrorY < 0.00000001 :
150  if not (iPoint in badPoints) : badPoints.append(iPoint)
151 
152  #print badPoints
153 
154  for i, graph in enumerate(graphs):
155 
156  newGraph = graph.Clone()
157  newGraphsFinal.append(newGraph)
158 
159  for iPoint in xrange(0, graph.GetN()) :
160 
161  dataPointX = Double(0)
162  dataPointY = Double(0)
163 
164  dataErrorX = graph.GetErrorX(iPoint)
165  dataErrorY = graph.GetErrorY(iPoint)
166 
167  graph.GetPoint(iPoint,dataPointX,dataPointY)
168 
169  if not (iPoint in badPoints) :
170  newGraph.SetPoint(iPoint, dataPointX, dataPointY)
171  newGraph.SetPointError(iPoint, dataErrorX, dataErrorY)
172 
173  else :
174  newGraph.SetPoint(iPoint, dataPointX, 1)
175  newGraph.SetPointError(iPoint, dataErrorX, 0)
176 
177 
178  nomGraphFinal = nomGraph.Clone()
179 
180  for iPoint in xrange(0, nomGraph.GetN()) :
181 
182  dataPointX = Double(0)
183  dataPointY = Double(0)
184  nomGraph.GetPoint(iPoint,dataPointX,dataPointY)
185  dataErrorX = nomGraph.GetErrorX(iPoint)
186  dataErrorY = nomGraph.GetErrorY(iPoint)
187 
188  if not (iPoint in badPoints) :
189  nomGraphFinal.SetPoint(iPoint, dataPointX, dataPointY)
190  nomGraphFinal.SetPointError(iPoint, dataErrorX, dataErrorY)
191 
192  else :
193  nomGraphFinal.SetPoint(iPoint, dataPointX, 1)
194  nomGraphFinal.SetPointError(iPoint, dataErrorX, 0)
195 
196  c = TCanvas()
197 
198  #nomGraphFinal.Draw("AP")
199  #for graph in newGraphsFinal :
200  #newgraph.FixPlot(graph)
201  #newgraph.Draw("Psame")
202 
203  return nomGraphFinal, newGraphsFinal
204 
205  #dataPointY = fabs(dataPointY-1)
206 
207  #if(dataPointY != 0 and iPoint < graph.GetN()):
208  #thisBandsGraph.SetPoint(iPoint, dataPointX, dataPointY)
209  #thisBandsGraph.SetPointError(iPoint, dataErrorX, dataErrorX, 0, 0)
210 
211  #return thisBandsGraph
212 

◆ removeLargeErrorPoints_noCheck()

def FormattingUtils.removeLargeErrorPoints_noCheck (   nomGraph,
  graphs 
)

Definition at line 297 of file FormattingUtils.py.

297 def removeLargeErrorPoints_noCheck(nomGraph, graphs) :
298 
299  newGraphsIntermediate = []
300  newGraphsFinal = []
301  badPoints = []
302 
303  for i, graph in enumerate(graphs+[nomGraph]):
304  #print graph.GetName()
305 
306  for iPoint in xrange(0, graph.GetN()) :
307 
308  dataPointX = Double(0)
309  dataPointY = Double(0)
310 
311  graph.GetPoint(iPoint,dataPointX,dataPointY)
312  dataErrorX = graph.GetErrorX(iPoint)
313  dataErrorY = graph.GetErrorY(iPoint)
314 
315  if dataErrorY > 5 or dataErrorY < 0.00000001 :
316  if not (iPoint in badPoints) : badPoints.append(iPoint)
317 
318  #print badPoints
319 
320  for i, graph in enumerate(graphs):
321 
322  newGraph = graph.Clone()
323  newGraphsFinal.append(newGraph)
324 
325  for iPoint in xrange(0, graph.GetN()) :
326 
327  dataPointX = Double(0)
328  dataPointY = Double(0)
329 
330  dataErrorX = graph.GetErrorX(iPoint)
331  dataErrorY = graph.GetErrorY(iPoint)
332 
333  graph.GetPoint(iPoint,dataPointX,dataPointY)
334 
335  if not (iPoint in badPoints) :
336  newGraph.SetPoint(iPoint, dataPointX, dataPointY)
337  newGraph.SetPointError(iPoint, dataErrorX, dataErrorY)
338 
339  else :
340  newGraph.SetPoint(iPoint, dataPointX, 1)
341  newGraph.SetPointError(iPoint, dataErrorX, 0)
342 
343 
344  nomGraphFinal = nomGraph.Clone()
345 
346  for iPoint in xrange(0, nomGraph.GetN()) :
347 
348  dataPointX = Double(0)
349  dataPointY = Double(0)
350  nomGraph.GetPoint(iPoint,dataPointX,dataPointY)
351  dataErrorX = nomGraph.GetErrorX(iPoint)
352  dataErrorY = nomGraph.GetErrorY(iPoint)
353 
354  if not (iPoint in badPoints) :
355  nomGraphFinal.SetPoint(iPoint, dataPointX, dataPointY)
356  nomGraphFinal.SetPointError(iPoint, dataErrorX, dataErrorY)
357 
358  else :
359  nomGraphFinal.SetPoint(iPoint, dataPointX, 1)
360  nomGraphFinal.SetPointError(iPoint, dataErrorX, 0)
361 
362  #c = TCanvas()
363 
364  #nomGraphFinal.Draw("AP")
365  #for graph in newGraphsFinal :
366  #newgraph.FixPlot(graph)
367  #newgraph.Draw("Psame")
368 
369  return nomGraphFinal, newGraphsFinal
370 
371 #this fcn works with TGraphs with symmetric x errors

◆ removeLargeErrorPoints_noFirstBin()

def FormattingUtils.removeLargeErrorPoints_noFirstBin (   nomGraph,
  graphs 
)

Definition at line 213 of file FormattingUtils.py.

213 def removeLargeErrorPoints_noFirstBin(nomGraph, graphs) :
214 
215  newGraphsIntermediate = []
216  newGraphsFinal = []
217  badPoints = []
218 
219  for i, graph in enumerate(graphs+[nomGraph]):
220  #print graph.GetName()
221 
222  for iPoint in xrange(0, graph.GetN()) :
223 
224  #no check if it's the first point (it sucks anyways)
225  if iPoint == 0 : continue
226  dataPointX = Double(0)
227  dataPointY = Double(0)
228 
229  graph.GetPoint(iPoint,dataPointX,dataPointY)
230  dataErrorX = graph.GetErrorX(iPoint)
231  dataErrorY = graph.GetErrorY(iPoint)
232  print graph.GetName()
233 
234  if dataErrorY > 0.011 or dataErrorY < 0.00000001 :
235  if not (iPoint in badPoints) : badPoints.append(iPoint)
236 
237  #print badPoints
238 
239  for i, graph in enumerate(graphs):
240 
241  newGraph = graph.Clone()
242  newGraphsFinal.append(newGraph)
243 
244  for iPoint in xrange(0, graph.GetN()) :
245 
246  dataPointX = Double(0)
247  dataPointY = Double(0)
248 
249  dataErrorX = graph.GetErrorX(iPoint)
250  dataErrorY = graph.GetErrorY(iPoint)
251 
252  graph.GetPoint(iPoint,dataPointX,dataPointY)
253 
254  if not (iPoint in badPoints) :
255  newGraph.SetPoint(iPoint, dataPointX, dataPointY)
256  newGraph.SetPointError(iPoint, dataErrorX, dataErrorY)
257 
258  else :
259  newGraph.SetPoint(iPoint, dataPointX, 1)
260  newGraph.SetPointError(iPoint, dataErrorX, 0)
261 
262 
263  nomGraphFinal = nomGraph.Clone()
264 
265  for iPoint in xrange(0, nomGraph.GetN()) :
266 
267  dataPointX = Double(0)
268  dataPointY = Double(0)
269  nomGraph.GetPoint(iPoint,dataPointX,dataPointY)
270  dataErrorX = nomGraph.GetErrorX(iPoint)
271  dataErrorY = nomGraph.GetErrorY(iPoint)
272 
273  if not (iPoint in badPoints) :
274  nomGraphFinal.SetPoint(iPoint, dataPointX, dataPointY)
275  nomGraphFinal.SetPointError(iPoint, dataErrorX, dataErrorY)
276 
277  else :
278  nomGraphFinal.SetPoint(iPoint, dataPointX, 1)
279  nomGraphFinal.SetPointError(iPoint, dataErrorX, 0)
280 
281 
282  #nomGraphFinal.Draw("AP")
283  #for graph in newGraphsFinal :
284  #newgraph.FixPlot(graph)
285  #newgraph.Draw("Psame")
286 
287  return nomGraphFinal, newGraphsFinal
288 
289  #dataPointY = fabs(dataPointY-1)
290 
291  #if(dataPointY != 0 and iPoint < graph.GetN()):
292  #thisBandsGraph.SetPoint(iPoint, dataPointX, dataPointY)
293  #thisBandsGraph.SetPointError(iPoint, dataErrorX, dataErrorX, 0, 0)
294 
295  #return thisBandsGraph
296 

◆ removeLargeErrorPointsSingle()

def FormattingUtils.removeLargeErrorPointsSingle (   graph)

Definition at line 469 of file FormattingUtils.py.

469 def removeLargeErrorPointsSingle(graph) :
470 
471  badPoints = []
472 
473  for iPoint in xrange(0, graph.GetN()) :
474 
475  dataPointX = Double(0)
476  dataPointY = Double(0)
477 
478  graph.GetPoint(iPoint,dataPointX,dataPointY)
479  dataErrorX = graph.GetErrorX(iPoint)
480  dataErrorY = graph.GetErrorY(iPoint)
481 
482  if dataErrorY > 0.011 or dataErrorY < 0.00000001 or iPoint>graph.GetN()-3 :
483  if not (iPoint in badPoints) : badPoints.append(iPoint)
484 
485  newGraph = graph.Clone()
486 
487  for iPoint in xrange(0, graph.GetN()) :
488 
489  dataPointX = Double(0)
490  dataPointY = Double(0)
491 
492  dataErrorX = graph.GetErrorX(iPoint)
493  dataErrorY = graph.GetErrorY(iPoint)
494 
495  graph.GetPoint(iPoint,dataPointX,dataPointY)
496 
497  if not (iPoint in badPoints) :
498  newGraph.SetPoint(iPoint, dataPointX, dataPointY)
499  newGraph.SetPointError(iPoint, dataErrorX, dataErrorY)
500 
501  else :
502  newGraph.SetPoint(iPoint, dataPointX, 0.00000001)
503  newGraph.SetPointError(iPoint, dataErrorX, 0)
504 
505  return newGraph

◆ rescaleJetPlot()

def FormattingUtils.rescaleJetPlot (   plot)

Definition at line 36 of file FormattingUtils.py.

36 def rescaleJetPlot (plot) :
37 
38  #loop on all data points
39  nPoints = plot.GetN()
40 # print "old:",plot.GetName(), nPoints
41  #create another TGraph
42  newPlot = TGraphErrors()
43 
44  for i in xrange(0,nPoints) :
45 
46  dataPointX = Double(0)
47  dataPointY = Double(0)
48  error = Double(0)
49  plot.GetPoint(i,dataPointX,dataPointY)
50  #if numpy.isnan(dataPointY) : dataPointY = 0.000001
51  if dataPointY < 0.000001 : dataPointY = 0.000001
52  errorX = plot.GetErrorX(i)
53  errorY = plot.GetErrorY(i)
54  newPlot.SetPoint(i, dataPointX/1000., dataPointY)
55  newPlot.SetPointError(i, errorX/1000., errorY)
56 
57 # print "new:", newPlot.GetName(), newPlot.GetN()
58 
59  return newPlot
60 
61 
63 
64 
65 

◆ TGraphToTH1()

def FormattingUtils.TGraphToTH1 (   graph)

Definition at line 372 of file FormattingUtils.py.

372 def TGraphToTH1 (graph) :
373 
374  #loop on all data points
375  nPoints = graph.GetN()
376  #print "nPoints", nPoints
377 
378  x=array('f')
379  y=array('f')
380  ey=array('f')
381 
382  dataPointX = None
383  dataErrorX = None
384 
385  for iPoint in xrange(0,nPoints) :
386  #get info on data point
387  dataPointX = Double(0)
388  dataPointY = Double(0)
389  graph.GetPoint(iPoint,dataPointX,dataPointY)
390  dataErrorX = graph.GetErrorX(iPoint)
391  dataErrorY = graph.GetErrorY(iPoint)
392 
393  x.append(dataPointX-dataErrorX)
394  y.append(dataPointY)
395  ey.append(dataErrorY)
396 
397  #this needs to be done at the END for the upper limit
398  x.append(dataPointX+dataErrorX)
399 
400 # print x, y, ey
401 
402  #safety checks...regardless of malmsteen
403  for iPoint in xrange(0,nPoints) :
404  #if numpy.isnan(y[iPoint]) :
405  #y[iPoint]=0
406  #if numpy.isnan(x[iPoint]) :
407  #x[iPoint]=0
408 
409  if y[iPoint]<0.00000001 :
410  y[iPoint]=0
411  ey[iPoint]=0
412 
413  myHist=TH1F("Hist"+graph.GetName(),graph.GetTitle(),nPoints,x)
414 
415  for iPoint in xrange(0,nPoints) :
416 
417  myHist.SetBinContent(iPoint+1,y[iPoint])#the +1 is needed because TH1 have overflows
418 # myHist.SetBinError(iPoint+1,ey[iPoint])#the +1 is needed because TH1 have overflows
419  myHist.SetBinError(iPoint+1,0)#avoid poissonian errors, pick up errors from graph anyways
420 
421  print x, y, ey
422 
423  return myHist
424 
425 
426 #this fcn works with TGraphs with symmetric x errors
427 #it assumes that the data points of the TGraph are all around zero
428 #it translates a TGraphErrors into a TH1 where the bin content = error

◆ TGraphToTH1_error()

def FormattingUtils.TGraphToTH1_error (   graph)

Definition at line 429 of file FormattingUtils.py.

429 def TGraphToTH1_error (graph) :
430 
431  #loop on all data points
432  nPoints = graph.GetN()
433 
434  x=array('f')
435  y=array('f')
436  ey=array('f')
437 
438  for iPoint in xrange(0,nPoints) :
439  #get info on data point
440  dataPointX = Double(0)
441  dataPointY = Double(0)
442  graph.GetPoint(iPoint,dataPointX,dataPointY)
443  dataErrorX = graph.GetErrorX(iPoint)
444  dataErrorY = graph.GetErrorYhigh(iPoint)
445 
446  x.append(dataPointX-dataErrorX)
447  y.append(dataPointY)
448  ey.append(dataErrorY)
449 
450  x.append(dataPointX+dataErrorX)
451 
452  #print x, y, ey
453 
454  if y[0]!=0 :
455  print "This TGraph is not centered at zero!"
456  return 0
457 
458  myHist=TH1F("Hist","Hist",nPoints,x)
459 
460  for iPoint in xrange(0,nPoints) :
461  if x[iPoint]<=x[iPoint+1] : "HELP!"
462 
463  #print ey[iPoint]
464  myHist.SetBinContent(iPoint+1,ey[iPoint])#the +1 is needed because TH1 have overflows
465  myHist.SetBinError(iPoint+1,0)#set the error to zero otherwise a meaningless poisson error will be stuck there
466 
467  return myHist
468 

Variable Documentation

◆ argv

FormattingUtils.argv

Definition at line 7 of file FormattingUtils.py.

xrange
void xrange(TH1 *h, bool symmetric)
Definition: computils.cxx:515
FormattingUtils.TGraphToTH1_error
def TGraphToTH1_error(graph)
Definition: FormattingUtils.py:429
FormattingUtils.removeLargeErrorPointsSingle
def removeLargeErrorPointsSingle(graph)
Definition: FormattingUtils.py:469
FormattingUtils.fixPlots
def fixPlots(middleGraph)
Definition: FormattingUtils.py:66
FormattingUtils.formatJetPlot
def formatJetPlot(plot, i)
Definition: FormattingUtils.py:23
FormattingUtils.rescaleJetPlot
def rescaleJetPlot(plot)
Definition: FormattingUtils.py:36
FormattingUtils.removeLargeErrorPoints
def removeLargeErrorPoints(nomGraph, graphs)
Definition: FormattingUtils.py:127
FormattingUtils.fixPlots_withErrors
def fixPlots_withErrors(middleGraph)
Definition: FormattingUtils.py:91
array
FormattingUtils.removeLargeErrorPoints_noFirstBin
def removeLargeErrorPoints_noFirstBin(nomGraph, graphs)
Definition: FormattingUtils.py:213
FormattingUtils.TGraphToTH1
def TGraphToTH1(graph)
Definition: FormattingUtils.py:372
FormattingUtils.formatPlotNoStat
def formatPlotNoStat(plot)
Definition: FormattingUtils.py:14
FormattingUtils.removeLargeErrorPoints_noCheck
def removeLargeErrorPoints_noCheck(nomGraph, graphs)
Definition: FormattingUtils.py:297
TH1F
Definition: rootspy.cxx:320
if
if(febId1==febId2)
Definition: LArRodBlockPhysicsV0.cxx:569