ATLAS Offline Software
Public Member Functions | Public Attributes | List of all members
python.ROOTUtils.PlotLibrary Class Reference
Collaboration diagram for python.ROOTUtils.PlotLibrary:

Public Member Functions

def __init__ (self, name='MyPlots', otherMethods=[])
 
def protect (self, obj)
 
def plot (self, plotName='', *args)
 
def genPlot (self, what='ALL', code='plot', labels=[], *args)
 

Public Attributes

 name
 
 otherMethods
 
 rootObjects
 
 whatList
 
 singleCanvasSize
 
 allCanvasSize
 
 allCanvasDivs
 
 saveAsList
 
 gPadSaveAsList
 

Detailed Description

PlotLibrary is a base class that can be used to manage a set of
   plots. Each individual plot should be created as a method of a
   derived class.  Other methods of the derived class that do not
   generate plots should either have names starting with
   underscore, or should be declared when calling __init__ of the
   base class.

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

Constructor & Destructor Documentation

◆ __init__()

def python.ROOTUtils.PlotLibrary.__init__ (   self,
  name = 'MyPlots',
  otherMethods = [] 
)
Constructor. otherMethods specifies a list of methods of the derived
   class that are not creating plots and should not be called by plot().

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

82  def __init__(self, name = 'MyPlots', otherMethods=[]):
83  """Constructor. otherMethods specifies a list of methods of the derived
84  class that are not creating plots and should not be called by plot()."""
85  self.name = name
86  self.otherMethods = []
87  self.otherMethods.extend(otherMethods)
88  self.rootObjects = []
89 
90  # Variables used by genPlot
91  self.whatList = []
92  self.singleCanvasSize = 'default'
93  self.allCanvasSize = 'page'
94  self.allCanvasDivs = (3,4)
95  self.saveAsList = []
96  self.gPadSaveAsList = []
97 

Member Function Documentation

◆ genPlot()

def python.ROOTUtils.PlotLibrary.genPlot (   self,
  what = 'ALL',
  code = 'plot',
  labels = [],
args 
)
Make plots using a general code. genPlot makes either a single plot defined
   by argument what, or all plots (if what=''). The plots made in the latter
   case are specified by whatList. A canvas that is subdivided if necessary
   is created before the plotting code is called.

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

113  def genPlot(self,what='ALL',code='plot',labels=[],*args):
114  """Make plots using a general code. genPlot makes either a single plot defined
115  by argument what, or all plots (if what=''). The plots made in the latter
116  case are specified by whatList. A canvas that is subdivided if necessary
117  is created before the plotting code is called."""
118  if what=='' or what.upper()=='ALL':
119  c = self.protect( MyCanvas('%s-%s-%s' % (self.name,what,code),
120  self.allCanvasSize,self.allCanvasDivs[0],self.allCanvasDivs[1]) )
121  iCanvas = 0
122  for w in self.whatList:
123  iCanvas += 1
124  c.cd(iCanvas)
125  try:
126  self.__class__.__dict__[code](self,w,*args)
127  except Exception:
128  self.__class__.__bases__[0].__dict__[code](self,w,*args)
129  ROOT.gPad.Update()
130  # For some strange reason, this works only for .eps, but not e.g. for gif files...???
131  for o in self.gPadSaveAsList:
132  if o[0]=='.':
133  ROOT.gPad.SaveAs('%s-%s-%s%s' % (self.name,code,w,o))
134  else:
135  ROOT.gPad.SaveAs(o)
136 
137  # If we want to put some labels on an empty pad, add them now.
138  if labels!=[] and self.allCanvasDivs[0]*self.allCanvasDivs[1] > len(self.whatList):
139  iCanvas+=1
140  c.cd(iCanvas)
141  xtext=0.0
142  ytext=0.8
143  for label in labels:
144  drawText(xtext,ytext,0.06,label)
145  ytext=ytext-0.1
146  elif labels!=[]:
147  print ("ERROR: can't add labels unless we have an empty pad to use. Ignoring labels.")
148 
149  for o in self.saveAsList:
150  if o[0]=='.':
151  c.SaveAs('%s-%s-%s%s' % (self.name,code,what,o))
152  else:
153  c.SaveAs(o)
154 
155  else:
156  c = self.protect( MyCanvas(what,self.singleCanvasSize) )
157  try:
158  self.__class__.__dict__[code](self,what,*args)
159  except Exception:
160  self.__class__.__bases__[0].__dict__[code](self,what,*args)
161  ROOT.gPad.Update()
162  for o in self.saveAsList:
163  if o[0]=='.':
164  c.SaveAs('%s-%s-%s%s' % (self.name,code,what,o))
165  else:
166  c.SaveAs(o)
167 

◆ plot()

def python.ROOTUtils.PlotLibrary.plot (   self,
  plotName = '',
args 
)
Make one or all (if plotName=='') plots.

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

103  def plot(self, plotName='',*args):
104  """Make one or all (if plotName=='') plots."""
105  if plotName:
106  self.__class__.__dict__[plotName](self,*args)
107  else:
108  for i in self.__class__.__dict__:
109  if i[0]=='_': continue # skip private methods
110  if i in self.otherMethods: continue
111  self.__class__.__dict__[i](self,*args)
112 

◆ protect()

def python.ROOTUtils.PlotLibrary.protect (   self,
  obj 
)
Protect ROOT object from garbage collection.

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

98  def protect(self,obj):
99  """Protect ROOT object from garbage collection."""
100  self.rootObjects.append(obj)
101  return obj
102 

Member Data Documentation

◆ allCanvasDivs

python.ROOTUtils.PlotLibrary.allCanvasDivs

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

◆ allCanvasSize

python.ROOTUtils.PlotLibrary.allCanvasSize

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

◆ gPadSaveAsList

python.ROOTUtils.PlotLibrary.gPadSaveAsList

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

◆ name

python.ROOTUtils.PlotLibrary.name

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

◆ otherMethods

python.ROOTUtils.PlotLibrary.otherMethods

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

◆ rootObjects

python.ROOTUtils.PlotLibrary.rootObjects

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

◆ saveAsList

python.ROOTUtils.PlotLibrary.saveAsList

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

◆ singleCanvasSize

python.ROOTUtils.PlotLibrary.singleCanvasSize

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

◆ whatList

python.ROOTUtils.PlotLibrary.whatList

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


The documentation for this class was generated from the following file:
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
dumpHVPathFromNtuple.append
bool append
Definition: dumpHVPathFromNtuple.py:91
python.processes.powheg.ZZ.ZZ.__init__
def __init__(self, base_directory, **kwargs)
Constructor: all process options are set here.
Definition: ZZ.py:18
plot
bool plot
Definition: listroot.cxx:44