ATLAS Offline Software
Classes | Functions | Variables
python.ROOTUtils Namespace Reference

Classes

class  MyCanvas
 
class  PlotLibrary
 
class  StyleFactory
 

Functions

def protect (obj)
 
def drawAxisFrame (xmin, xmax, ymin, ymax, title='', xTitleOffset=None, yTitleOffset=None, doPlot=True, protectFrame=True)
 
def drawHorizontalBand (xmin, xmax, y, ywidth, color=33, protectBand=True, centralLine=False)
 
def drawText (x=0.74, y=0.87, dy=0.06, text='', font=62, color=1, align=11, linesep=';')
 
def drawLegend (x1, y1, x2, y2, legendList=[], fillColor=0, lineColor=0, textSize=None, protectLegend=True)
 
def moveStats (h, dx, dy, xw=0, yw=0, label='')
 
def atlasLabel (x, y, isPreliminary=False, color=1, offset=0.115, isForApproval=False, energy=8, customstring="", size=0.05)
 
def atlasStyle (protectStyle=True)
 
def setStyle (style=None)
 

Variables

string __author__ = 'Juerg Beringer'
 
string __version__ = '$Id: ROOTUtils.py 759047 2016-07-01 00:45:13Z beringer $'
 
list protectedObjectList = []
 
dictionary myCanvasSizes
 

Function Documentation

◆ atlasLabel()

def python.ROOTUtils.atlasLabel (   x,
  y,
  isPreliminary = False,
  color = 1,
  offset = 0.115,
  isForApproval = False,
  energy = 8,
  customstring = "",
  size = 0.05 
)

Definition at line 300 of file python/ROOTUtils.py.

300 def atlasLabel(x,y,isPreliminary=False,color=1,offset=0.115,isForApproval=False,energy=8,customstring="",size=0.05):
301  if x is None or y is None:
302  print ("Must set (x,y) position using --atlasx and --atlasy to add labels. No ATLAS labels created.")
303  return
304  offset = offset/0.05*size
305  l = ROOT.TLatex()
306  l.SetNDC()
307  l.SetTextFont(72)
308  l.SetTextSize(size)
309  l.SetTextColor(color)
310  l.DrawLatex(x,y,"ATLAS")
311 
312  p = ROOT.TLatex()
313  p.SetNDC()
314  p.SetTextFont(42)
315  p.SetTextSize(size)
316  p.SetTextColor(color)
317 
318  if customstring != "":
319  p.DrawLatex(x+offset,y,customstring)
320  else:
321  if (isPreliminary):
322  p.DrawLatex(x+offset,y,"Preliminary")
323  if (isForApproval):
324  #p.DrawLatex(x+offset,y,"Internal for approval")
325  p.DrawLatex(x+offset,y,"Internal")
326 
327  if energy:
328  if float(energy)<15:
329  p.DrawLatex(x, y-(0.07/0.05*size), "#sqrt{s} = %s TeV" % energy)
330  else:
331  p.DrawLatex(x, y-(0.07/0.05*size), "#sqrt{s} = %s GeV" % energy)
332 
333 
334 

◆ atlasStyle()

def python.ROOTUtils.atlasStyle (   protectStyle = True)

Definition at line 335 of file python/ROOTUtils.py.

335 def atlasStyle(protectStyle=True):
336  s = ROOT.TStyle('ATLAS','ATLAS Style V2.02')
337 
338  # use plain black on white colors
339  icol=0 # WHITE
340  s.SetFrameBorderMode(icol)
341  s.SetFrameFillColor(icol)
342  s.SetCanvasBorderMode(icol)
343  s.SetCanvasColor(icol)
344  s.SetPadBorderMode(icol)
345  s.SetPadColor(icol)
346  s.SetStatColor(icol)
347  #s.SetFillColor(icol) # don't use: white fill color floa *all* objects
348 
349  # set the paper & margin sizes
350  s.SetPaperSize(20,26)
351  s.SetPadTopMargin(0.05)
352  s.SetPadRightMargin(0.05)
353  s.SetPadBottomMargin(0.16)
354  s.SetPadLeftMargin(0.16)
355 
356  # set title offsets (for axis label)
357  s.SetTitleXOffset(1.4)
358  s.SetTitleYOffset(1.4)
359 
360  # use large fonts
361  #Int_t font=72 # Helvetica italics
362  font = 42 # Helvetica
363  tsize = 0.05
364  s.SetTextFont(font)
365 
366  s.SetTextSize(tsize)
367  s.SetLabelFont(font,"x")
368  s.SetTitleFont(font,"x")
369  s.SetLabelFont(font,"y")
370  s.SetTitleFont(font,"y")
371  s.SetLabelFont(font,"z")
372  s.SetTitleFont(font,"z")
373 
374  s.SetLabelSize(tsize,"x")
375  s.SetTitleSize(tsize,"x")
376  s.SetLabelSize(tsize,"y")
377  s.SetTitleSize(tsize,"y")
378  s.SetLabelSize(tsize,"z")
379  s.SetTitleSize(tsize,"z")
380 
381  # use bold lines and markers
382  s.SetMarkerStyle(20)
383  s.SetMarkerSize(1.2)
384  s.SetHistLineWidth(2)
385  s.SetLineStyleString(2,"[12 12]") # postscript dashes
386 
387  # get rid of X error bars and y error bar caps
388  #s.SetErrorX(0.001)
389 
390  # get rid of error bar caps
391  s.SetEndErrorSize(0.)
392 
393  # do not display any of the standard histogram decorations
394  s.SetOptTitle(0)
395  #s.SetOptStat(1111)
396  s.SetOptStat(0)
397  #s.SetOptFit(1111)
398  s.SetOptFit(0)
399 
400  # put tick marks on top and RHS of plots
401  s.SetPadTickX(1)
402  s.SetPadTickY(1)
403 
404  if protectStyle:
405  protect(s)
406 
407  return s
408 
409 

◆ drawAxisFrame()

def python.ROOTUtils.drawAxisFrame (   xmin,
  xmax,
  ymin,
  ymax,
  title = '',
  xTitleOffset = None,
  yTitleOffset = None,
  doPlot = True,
  protectFrame = True 
)

Definition at line 210 of file python/ROOTUtils.py.

210 def drawAxisFrame(xmin,xmax,ymin,ymax,title='',xTitleOffset=None,yTitleOffset=None,doPlot=True,protectFrame=True):
211  frame = ROOT.TH2F('axisFrame',title,100,xmin,xmax,100,ymin,ymax)
212  frame.SetStats(False)
213  if xTitleOffset is not None:
214  frame.GetXaxis().SetTitleOffset(xTitleOffset)
215  if yTitleOffset is not None:
216  frame.GetYaxis().SetTitleOffset(yTitleOffset)
217  if doPlot:
218  frame.Draw()
219  if protectFrame:
220  protect(frame)
221  return frame
222 
223 

◆ drawHorizontalBand()

def python.ROOTUtils.drawHorizontalBand (   xmin,
  xmax,
  y,
  ywidth,
  color = 33,
  protectBand = True,
  centralLine = False 
)
Draw a horizontal band of width +-ywidth. Nice colors are 19 and 33.

Definition at line 224 of file python/ROOTUtils.py.

224 def drawHorizontalBand(xmin,xmax,y,ywidth,color=33,protectBand=True,centralLine=False):
225  """Draw a horizontal band of width +-ywidth. Nice colors are 19 and 33."""
226  b = ROOT.TH1F('band','band',1,xmin,xmax)
227  b.SetBinContent(1,y)
228  b.SetBinError(1,ywidth)
229  b.SetFillColor(color)
230  b.SetMarkerColor(color)
231  b.SetMarkerSize(0.01)
232  b.Draw('SAMEe2')
233  if centralLine:
234  b.Draw('SAMEL')
235  if protectBand:
236  protect(b)
237  return b
238 
239 

◆ drawLegend()

def python.ROOTUtils.drawLegend (   x1,
  y1,
  x2,
  y2,
  legendList = [],
  fillColor = 0,
  lineColor = 0,
  textSize = None,
  protectLegend = True 
)
Draw a legend with one or more entries. legendList is a list of lists,
   where each inner list defines the object, text and option of a legend entry.
   NOTE: Must store returned TLegend, otherwise legend will disappear!

Definition at line 256 of file python/ROOTUtils.py.

256 def drawLegend(x1,y1,x2,y2,legendList=[],fillColor=0,lineColor=0,textSize=None,protectLegend=True):
257  """Draw a legend with one or more entries. legendList is a list of lists,
258  where each inner list defines the object, text and option of a legend entry.
259  NOTE: Must store returned TLegend, otherwise legend will disappear!"""
260  nlines = len(legendList)
261  if not nlines:
262  print ("ERROR: drawLegend called w/o any legend entries")
263  #maxchar = 0
264  #for e in legendList:
265  # maxchar = max(len(e[1]),maxchar)
266  #l = ROOT.TLegend(x,y-nlines*s,x+(2+maxchar)*s/3.7,y)
267  l = ROOT.TLegend(x1,y1,x2,y2)
268  l.SetFillColor(fillColor)
269  l.SetLineColor(lineColor)
270  l.SetShadowColor(lineColor)
271  if textSize:
272  l.SetTextSize(textSize)
273  for e in legendList:
274  l.AddEntry(e[0],e[1],e[2])
275  l.Draw()
276  if protectLegend:
277  protect(l)
278  return l
279 
280 

◆ drawText()

def python.ROOTUtils.drawText (   x = 0.74,
  y = 0.87,
  dy = 0.06,
  text = '',
  font = 62,
  color = 1,
  align = 11,
  linesep = ';' 
)
Draw a variable number of lines of text.

Definition at line 240 of file python/ROOTUtils.py.

240 def drawText(x=0.74,y=0.87,dy=0.06,text='',font=62,color=1,align=11,linesep=';'):
241  """Draw a variable number of lines of text."""
242  t = ROOT.TLatex()
243  t.SetNDC()
244  t.SetTextFont(font)
245  t.SetTextColor(color)
246  t.SetTextAlign(align)
247  t.SetTextSize(dy/1.2)
248  for line in text.split(linesep):
249  t.DrawLatex(x,y,line)
250  y = y-dy
251  # Seems TLatex text doesn't need to be protected - why not?
252  return t
253 
254 
255 #def drawLegend(x=0.18,y=0.9,s=0.07,legendList=[],fillColor=0,lineColor=0):

◆ moveStats()

def python.ROOTUtils.moveStats (   h,
  dx,
  dy,
  xw = 0,
  yw = 0,
  label = '' 
)

Definition at line 281 of file python/ROOTUtils.py.

281 def moveStats(h,dx,dy,xw=0,yw=0,label=''):
282  if not h:
283  return
284  ROOT.gPad.Update()
285  st = h.GetListOfFunctions().FindObject('stats')
286  if not st:
287  print ('ERROR: No stats found - cannot move it')
288  return
289  st.SetTextColor(h.GetLineColor())
290  st.SetX1NDC(st.GetX1NDC()+dx)
291  st.SetY1NDC(st.GetY1NDC()+dy)
292  st.SetX2NDC(st.GetX2NDC()+xw if xw!=0 else st.GetX2NDC()+dx)
293  st.SetY2NDC(st.GetY2NDC()+yw if yw!=0 else st.GetY2NDC()+dy)
294  if not label:
295  h.SetName(label)
296  ROOT.gPad.Modified()
297  ROOT.gPad.Update
298 
299 

◆ protect()

def python.ROOTUtils.protect (   obj)
Utility function to prevent ROOT objects from being garbage-collected,
   (thus disappearing from plots) when they go out of scope.

Definition at line 14 of file python/ROOTUtils.py.

14 def protect(obj):
15  """Utility function to prevent ROOT objects from being garbage-collected,
16  (thus disappearing from plots) when they go out of scope."""
17  protectedObjectList.append(obj)
18  return obj
19 
20 
21 # Define a set of useful canvas sizes for different purposes

◆ setStyle()

def python.ROOTUtils.setStyle (   style = None)

Definition at line 410 of file python/ROOTUtils.py.

410 def setStyle(style = None):
411  if not style:
412  style = atlasStyle()
413  print ('\nApplying style %s (%s) ...\n' % (style.GetName(),style.GetTitle()))
414  ROOT.gROOT.SetStyle(style.GetName())
415  ROOT.gROOT.ForceStyle()

Variable Documentation

◆ __author__

string python.ROOTUtils.__author__ = 'Juerg Beringer'
private

Definition at line 6 of file python/ROOTUtils.py.

◆ __version__

string python.ROOTUtils.__version__ = '$Id: ROOTUtils.py 759047 2016-07-01 00:45:13Z beringer $'
private

Definition at line 7 of file python/ROOTUtils.py.

◆ myCanvasSizes

dictionary python.ROOTUtils.myCanvasSizes
Initial value:
1 = { 'default': (700, 500),
2  'default2d': (545, 500),
3  'slide1': (900,560),
4  'slide2': (450,560),
5  'slide2text': (400,500),
6  'fig1': (700, 500),
7  'fig2': (1400, 500),
8  'page': (750,1000),
9  'landscape': (1600,1000),
10  'wide': (1000,500),
11  'extrawide': (1500,500),
12  'square': (700,700)
13  }

Definition at line 22 of file python/ROOTUtils.py.

◆ protectedObjectList

list python.ROOTUtils.protectedObjectList = []

Definition at line 12 of file python/ROOTUtils.py.

python.ROOTUtils.setStyle
def setStyle(style=None)
Definition: python/ROOTUtils.py:410
python.ROOTUtils.drawText
def drawText(x=0.74, y=0.87, dy=0.06, text='', font=62, color=1, align=11, linesep=';')
Definition: python/ROOTUtils.py:240
python.ROOTUtils.protect
def protect(obj)
Definition: python/ROOTUtils.py:14
python.ROOTUtils.drawLegend
def drawLegend(x1, y1, x2, y2, legendList=[], fillColor=0, lineColor=0, textSize=None, protectLegend=True)
Definition: python/ROOTUtils.py:256
python.ROOTUtils.atlasStyle
def atlasStyle(protectStyle=True)
Definition: python/ROOTUtils.py:335
python.ROOTUtils.atlasLabel
def atlasLabel(x, y, isPreliminary=False, color=1, offset=0.115, isForApproval=False, energy=8, customstring="", size=0.05)
Definition: python/ROOTUtils.py:300
python.ROOTUtils.drawAxisFrame
def drawAxisFrame(xmin, xmax, ymin, ymax, title='', xTitleOffset=None, yTitleOffset=None, doPlot=True, protectFrame=True)
Definition: python/ROOTUtils.py:210
readCCLHist.float
float
Definition: readCCLHist.py:83
python.ROOTUtils.moveStats
def moveStats(h, dx, dy, xw=0, yw=0, label='')
Definition: python/ROOTUtils.py:281
python.ROOTUtils.drawHorizontalBand
def drawHorizontalBand(xmin, xmax, y, ywidth, color=33, protectBand=True, centralLine=False)
Definition: python/ROOTUtils.py:224