ATLAS Offline Software
Classes | Functions | Variables
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 ROOTUtils.atlasLabel (   x,
  y,
  isPreliminary = False,
  color = 1,
  offset = 0.115,
  isForApproval = False,
  energy = 8,
  customstring = "",
  size = 0.05 
)

Definition at line 303 of file roofit/ROOTUtils.py.

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

◆ atlasStyle()

def ROOTUtils.atlasStyle (   protectStyle = True)

Definition at line 338 of file roofit/ROOTUtils.py.

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

◆ drawAxisFrame()

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

Definition at line 213 of file roofit/ROOTUtils.py.

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

◆ drawHorizontalBand()

def 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 227 of file roofit/ROOTUtils.py.

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

◆ drawLegend()

def 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 259 of file roofit/ROOTUtils.py.

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

◆ drawText()

def 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 243 of file roofit/ROOTUtils.py.

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

◆ moveStats()

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

Definition at line 284 of file roofit/ROOTUtils.py.

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

◆ protect()

def 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 17 of file roofit/ROOTUtils.py.

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

◆ setStyle()

def ROOTUtils.setStyle (   style = None)

Definition at line 413 of file roofit/ROOTUtils.py.

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

Variable Documentation

◆ __author__

string ROOTUtils.__author__ = 'Juerg Beringer'
private

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

◆ __version__

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

Definition at line 8 of file roofit/ROOTUtils.py.

◆ myCanvasSizes

dictionary 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 25 of file roofit/ROOTUtils.py.

◆ protectedObjectList

list ROOTUtils.protectedObjectList = []

Definition at line 15 of file roofit/ROOTUtils.py.

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