ATLAS Offline Software
Loading...
Searching...
No Matches
ROOTUtils.PlotLibrary Class Reference
Inheritance diagram for ROOTUtils.PlotLibrary:
Collaboration diagram for ROOTUtils.PlotLibrary:

Public Member Functions

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

Public Attributes

 name = name
list otherMethods = []
list rootObjects = []
list whatList = []
str singleCanvasSize = 'default'
str allCanvasSize = 'page'
tuple allCanvasDivs = (3,4)
list saveAsList = []
list 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 77 of file roofit/ROOTUtils.py.

Constructor & Destructor Documentation

◆ __init__()

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

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

Member Function Documentation

◆ genPlot()

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

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

◆ plot()

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

Reimplemented in beamspotnt.Plots, and beamspotnt.Plots.

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

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

◆ protect()

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

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

101 def protect(self,obj):
102 """Protect ROOT object from garbage collection."""
103 self.rootObjects.append(obj)
104 return obj
105

Member Data Documentation

◆ allCanvasDivs

tuple ROOTUtils.PlotLibrary.allCanvasDivs = (3,4)

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

◆ allCanvasSize

str ROOTUtils.PlotLibrary.allCanvasSize = 'page'

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

◆ gPadSaveAsList

list ROOTUtils.PlotLibrary.gPadSaveAsList = []

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

◆ name

ROOTUtils.PlotLibrary.name = name

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

◆ otherMethods

list ROOTUtils.PlotLibrary.otherMethods = []

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

◆ rootObjects

list ROOTUtils.PlotLibrary.rootObjects = []

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

◆ saveAsList

list ROOTUtils.PlotLibrary.saveAsList = []

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

◆ singleCanvasSize

str ROOTUtils.PlotLibrary.singleCanvasSize = 'default'

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

◆ whatList

list ROOTUtils.PlotLibrary.whatList = []

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


The documentation for this class was generated from the following file: