ATLAS Offline Software
Loading...
Searching...
No Matches
fitman.Plots Class Reference
Inheritance diagram for fitman.Plots:
Collaboration diagram for fitman.Plots:

Public Member Functions

 __init__ (self, name=options.name, whatList=[])
 prepareMainPad (self)
 drawRatioPad (self, frame, hmin, hmax)
 labels (self)
 legend (self, frame)
 hist (self, what)
 x (self)
 y (self)
 z (self)
 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

Definition at line 156 of file fitman.py.

Constructor & Destructor Documentation

◆ __init__()

fitman.Plots.__init__ ( self,
name = options.name,
whatList = [] )

Definition at line 158 of file fitman.py.

158 def __init__(self, name = options.name, whatList = []):
160 self.whatList = whatList
161 self.allCanvasSize = 'landscape'
162 self.allCanvasDivs = (2,2)
163 self.singleCanvasSize = options.canvas
164
__init__(self, name='MyPlots', otherMethods=[])

Member Function Documentation

◆ drawRatioPad()

fitman.Plots.drawRatioPad ( self,
frame,
hmin,
hmax )

Definition at line 173 of file fitman.py.

173 def drawRatioPad(self,frame,hmin,hmax):
174 ROOT.gROOT.ProcessLine(".L ratioPlot.C+")
175 axisTitle = frame.GetXaxis().GetTitle()
176 frame.GetXaxis().SetTitle('')
177 frame.GetXaxis().SetLabelSize(0.)
178 frame.GetYaxis().SetTitleOffset(1.0)
179 canvas = ROOT.gPad.GetCanvas()
180 canvas.cd()
181 ratioPad = self.protect( ROOT.TPad("ratioPad","ratioPad",0.,0.,1.,0.3) )
182 ratioPad.SetTopMargin(0.)
183 ratioPad.SetBottomMargin(0.3)
184 ratioPad.Draw()
185 ratioPad.cd()
186 dataHist = frame.getObject(0)
187 fitCurve = frame.getObject(1)
188 #global pull
189 #pull = dataHist.makeResidHist(fitCurve,True,True)
190 global ratio
191 ratio = ROOT.ratioPlot(dataHist,fitCurve)
192 ratio.Draw('AP')
193 # NOTE: SetRangeUser chooses bin edges, so ratio plot would not be perfectly aligned
194 ratio.GetXaxis().SetLimits(hmin,hmax)
195 scale = 2.5
196 size = scale*options.lsize
197 ratio.GetXaxis().SetLabelSize(size)
198 ratio.GetXaxis().SetTitle(axisTitle)
199 ratio.GetXaxis().SetTitleSize(size)
200 ratio.GetXaxis().SetTitleOffset(1.)
201 ratio.GetYaxis().SetRangeUser(0.3,1.7)
202 ratio.GetYaxis().SetLabelSize(size)
203 ratio.GetYaxis().SetTitle('Data / fit')
204 #ratio.GetYaxis().SetTitleSize(scale*ratio.GetYaxis().GetTitleSize())
205 ratio.GetYaxis().SetTitleSize(size)
206 ratio.GetYaxis().SetTitleOffset(1.0/scale)
207 ratio.GetYaxis().SetNdivisions(504)
208 ratio.SetMarkerSize(0.7)
209 line = self.protect( ROOT.TLine(hmin,1,hmax,1) )
210 line.Draw()
211
212

◆ genPlot()

ROOTUtils.PlotLibrary.genPlot ( self,
what = 'ALL',
code = 'plot',
labels = [],
* args )
inherited
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

◆ hist()

fitman.Plots.hist ( self,
what )

Definition at line 233 of file fitman.py.

233 def hist(self,what):
234 if not what:
235 return
236 if options.hmin is not None or options.hmax is not None or options.hnbins is not None:
237 options.hmin = options.hmin if options.hmin is not None else 0.
238 options.hmax = options.hmax if options.hmax is not None else 1.
239 options.hnbins = options.hnbins if options.hnbins is not None else 40
240 h = ROOTUtils.protect( ROOT.TH1F('tmp','%s;%s' % (what,what),
241 options.hnbins,options.hmin,options.hmax))
242 vtxData.Draw('%s >> tmp' % what)
243 else:
244 vtxData.Draw(what)
245 if options.logy:
246 ROOT.gPad.SetLogy(options.logy)
247

◆ labels()

fitman.Plots.labels ( self)

Definition at line 213 of file fitman.py.

213 def labels(self):
214 # ATLAS labels and other text
215 if options.prelim:
216 ROOTUtils.atlasLabel(options.atlasx,options.atlasy,True,offset=options.atlasdx,energy=8,size=options.lsize)
217 if options.approval:
218 ROOTUtils.atlasLabel(options.atlasx,options.atlasy,False,offset=options.atlasdx,isForApproval=True,energy=8,size=options.lsize)
219 if options.published:
220 ROOTUtils.atlasLabel(options.atlasx,options.atlasy,False,offset=options.atlasdx,energy=8,size=options.lsize)
221 if options.comment:
222 self.protect( ROOTUtils.drawText(options.commentx,options.commenty,0.06,options.comment,font=42) )
223
atlasLabel(x, y, isPreliminary=False, color=1, offset=0.115, isForApproval=False, energy=8, customstring="", size=0.05)
drawText(x=0.74, y=0.87, dy=0.06, text='', font=62, color=1, align=11, linesep=';')

◆ legend()

fitman.Plots.legend ( self,
frame )

Definition at line 224 of file fitman.py.

224 def legend(self,frame):
225 legendList = []
226 legendList.append([frame.getObject(0),'Data','P'])
227 legendList.append([frame.getObject(1),'Fit projection','L'])
228 if options.showbs:
229 legendList.append([frame.getObject(2),'Beam spot','L'])
230 legendMinY = max(options.legendy-options.lsize*1.4*len(legendList),0.2)
231 self.protect( ROOTUtils.drawLegend(options.legendx,legendMinY,0.92,options.legendy,legendList,textSize=options.lsize) )
232
#define max(a, b)
Definition cfImp.cxx:41
drawLegend(x1, y1, x2, y2, legendList=[], fillColor=0, lineColor=0, textSize=None, protectLegend=True)

◆ plot()

ROOTUtils.PlotLibrary.plot ( self,
plotName = '',
* args )
inherited
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

◆ prepareMainPad()

fitman.Plots.prepareMainPad ( self)

Definition at line 165 of file fitman.py.

165 def prepareMainPad(self):
166 mainPad = self.protect( ROOT.TPad("mainPad","mainPad",0.,0.3,1.,1.) )
167 mainPad.SetBottomMargin(0.03) # with space between the two pads
168 #mainPad.SetBottomMargin(0.00) # w/o space between the two pads
169 mainPad.Draw()
170 mainPad.cd()
171 return mainPad
172

◆ protect()

ROOTUtils.PlotLibrary.protect ( self,
obj )
inherited
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

◆ x()

fitman.Plots.x ( self)

Definition at line 248 of file fitman.py.

248 def x(self):
249 if options.showratio:
250 self.prepareMainPad()
251 dx = options.hrange/2 if options.hrange else max(options.minrange/2.,8.*sx.getVal())
252 hmin = options.hmin if options.hmin is not None else mx.getVal()-dx
253 hmax = options.hmax if options.hmax is not None else mx.getVal()+dx
254 global xframe
255 xframe = self.protect( x.frame(hmin,hmax) )
256 if options.hnbins is not None:
257 binning = ROOT.RooBinning(hmin, hmax)
258 binning.addUniform(options.hnbins, hmin, hmax)
259 data.plotOn(xframe,RooFit.Binning(binning))
260 xbinWidth = (hmax-hmin)/float(options.hnbins)
261 else:
262 data.plotOn(xframe)
263 xbinWidth = xframe.GetXaxis().GetBinWidth(1)
264 #xframe.GetYaxis().SetTitle("Number of primary vertices per %3.1f #mum" % round(1000.*xbinWidth,1))
265 xframe.GetYaxis().SetTitle("Events / %1.0f #mum" % round(1000.*xbinWidth,1))
266 xframe.GetYaxis().SetLabelSize(options.lsize)
267 xframe.GetYaxis().SetTitleSize(options.lsize)
268 if options.stats:
269 data.statOn(xframe)
270 cov = RooArgSet(vxx,vyy,vxy)
271 fitmodel.plotOn(xframe,RooFit.ProjWData(cov,data),
272 RooFit.NumCPU(options.nCpu))
273 if options.showbs:
274 k.setVal(0.0)
275 fitmodel.plotOn(xframe,RooFit.ProjWData(cov,data),
276 RooFit.NumCPU(options.nCpu),
277 RooFit.LineStyle(RooFit.kDashed))
278 xframe.Draw()
279 if options.logy:
280 ROOT.gPad.SetLogy(options.logy)
281 self.labels()
282 self.legend(xframe)
283 if options.showratio:
284 self.drawRatioPad(xframe,hmin,hmax)
285

◆ y()

fitman.Plots.y ( self)

Definition at line 286 of file fitman.py.

286 def y(self):
287 if options.showratio:
288 self.prepareMainPad()
289 dy = options.hrange/2 if options.hrange else max(options.minrange/2.,8.*sy.getVal())
290 hmin = options.hmin if options.hmin is not None else my.getVal()-dy
291 hmax = options.hmax if options.hmax is not None else my.getVal()+dy
292 global yframe
293 yframe = self.protect( y.frame(hmin,hmax) )
294 if options.hnbins is not None:
295 binning = ROOT.RooBinning(hmin, hmax)
296 binning.addUniform(options.hnbins, hmin, hmax)
297 data.plotOn(yframe,RooFit.Binning(binning))
298 ybinWidth = (hmax-hmin)/float(options.hnbins)
299 else:
300 data.plotOn(yframe)
301 ybinWidth = yframe.GetXaxis().GetBinWidth(1)
302 #yframe.GetYaxis().SetTitle("Number of primary vertices per %3.1f #mum" % round(1000.*ybinWidth,1))
303 yframe.GetYaxis().SetTitle("Events / %1.0f #mum" % round(1000.*ybinWidth,1))
304 yframe.GetYaxis().SetLabelSize(options.lsize)
305 yframe.GetYaxis().SetTitleSize(options.lsize)
306 if options.stats:
307 data.statOn(yframe)
308 cov = RooArgSet(vxx,vyy,vxy)
309 fitmodel.plotOn(yframe,RooFit.ProjWData(cov,data),
310 RooFit.NumCPU(options.nCpu))
311 if options.showbs:
312 k.setVal(0.0)
313 fitmodel.plotOn(yframe,RooFit.ProjWData(cov,data),
314 RooFit.NumCPU(options.nCpu),
315 RooFit.LineStyle(RooFit.kDashed))
316 yframe.Draw()
317 if options.logy:
318 ROOT.gPad.SetLogy(options.logy)
319 self.labels()
320 self.legend(yframe)
321 if options.showratio:
322 self.drawRatioPad(yframe,hmin,hmax)
323

◆ z()

fitman.Plots.z ( self)

Definition at line 324 of file fitman.py.

324 def z(self):
325 if options.showratio:
326 self.prepareMainPad()
327 dz = options.hrange/2 if options.hrange else max(options.minrange/2.,8.*sz.getVal())
328 hmin = options.hmin if options.hmin is not None else mz.getVal()-dz
329 hmax = options.hmax if options.hmax is not None else mz.getVal()+dz
330 global zframe
331 zframe = self.protect( z.frame(hmin,hmax) )
332 if options.hnbins is not None:
333 binning = ROOT.RooBinning(hmin, hmax)
334 binning.addUniform(options.hnbins, hmin, hmax)
335 data.plotOn(zframe,RooFit.Binning(binning))
336 zbinWidth = (hmax-hmin)/float(options.hnbins)
337 else:
338 data.plotOn(zframe)
339 zbinWidth = zframe.GetXaxis().GetBinWidth(1)
340 #zframe.GetYaxis().SetTitle("Number of primary vertices per %3.1f mm" % round(zbinWidth,1))
341 zframe.GetYaxis().SetLabelSize(options.lsize)
342 zframe.GetYaxis().SetTitleSize(options.lsize)
343 zframe.GetYaxis().SetTitle("Events / %1.0f mm" % round(zbinWidth,1))
344 if options.stats:
345 data.statOn(zframe)
346 cov = RooArgSet(vxx,vyy,vxy)
347 fitmodel.plotOn(zframe,RooFit.ProjWData(cov,data),
348 RooFit.NumCPU(options.nCpu)) # could also use e.g. RooFit.Range(-100.,100.)
349 if options.showbs:
350 k.setVal(0.0)
351 fitmodel.plotOn(zframe,RooFit.ProjWData(cov,data),
352 RooFit.NumCPU(options.nCpu),
353 RooFit.LineStyle(RooFit.kDashed))
354 zframe.Draw()
355 if options.logy:
356 ROOT.gPad.SetLogy(options.logy)
357 self.labels()
358 self.legend(zframe)
359 if options.showratio:
360 self.drawRatioPad(zframe,hmin,hmax)
361
362
363#
364# If extract command is given, must process it here, before setting up
365# RooFit
366#

Member Data Documentation

◆ allCanvasDivs

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

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

◆ allCanvasSize

str ROOTUtils.PlotLibrary.allCanvasSize = 'page'
inherited

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

◆ gPadSaveAsList

list ROOTUtils.PlotLibrary.gPadSaveAsList = []
inherited

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

◆ name

ROOTUtils.PlotLibrary.name = name
inherited

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

◆ otherMethods

list ROOTUtils.PlotLibrary.otherMethods = []
inherited

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

◆ rootObjects

list ROOTUtils.PlotLibrary.rootObjects = []
inherited

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

◆ saveAsList

list ROOTUtils.PlotLibrary.saveAsList = []
inherited

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

◆ singleCanvasSize

str ROOTUtils.PlotLibrary.singleCanvasSize = 'default'
inherited

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

◆ whatList

list ROOTUtils.PlotLibrary.whatList = []
inherited

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


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