ATLAS Offline Software
Public Member Functions | Private Member Functions | Private Attributes | List of all members
PlotUtils.PlotUtils Class Reference
Inheritance diagram for PlotUtils.PlotUtils:
Collaboration diagram for PlotUtils.PlotUtils:

Public Member Functions

def __init__ (self, size=18, status="Internal", lumi=1., sqrts="13", normalizedToUnity=False)
 
def DrawTLatex (self, x, y, text, size=18, font=43, align=11, ndc=True, color=-1)
 
def GetStatus (self)
 
def GetLumi (self)
 
def DrawAtlas (self, x, y, align=11)
 
def DrawLumiSqrtS (self, x, y, align=11, lumi=1.)
 
def DrawSqrtS (self, x, y, align=11)
 
def CreateLegend (self, x1, y1, x2, y2, textsize=22)
 
def GetLegend (self, x1=0, y1=1., x2=1., y2=1.)
 
def AddToLegend (self, Items, Style="FL")
 
def DrawLegend (self, NperCol=3)
 
def DrawSource (self, probe, x, y, align=11)
 
def Prepare1PadCanvas (self, cname, width=800, height=600, isQuad=False)
 
def GetCanvas (self)
 
def Prepare2PadCanvas (self, cname, width=800, height=600, isQuad=False, DoLogX=False)
 
def GetTopPad (self)
 
def GetBottomPad (self)
 
def AdaptLabelsTopPad (self, histos)
 
def AdaptLabelsBottomPad (self, histos, scale=1.)
 
def drawStyling (self, Template, ymin, ymax, TopPad=True, RemoveLabel=False)
 
def addValuesInText (self, histo, on_top=True, off_set_y=0.005)
 
def saveHisto (self, name, outputfiletypes)
 

Private Member Functions

def __AddItemToLegend (self, Item, Style)
 

Private Attributes

 __Status
 
 __Size
 
 __Lumi
 
 __SqrtS
 
 __VerticalCanvasSplit
 
 __Canvas
 
 __Pad1
 
 __Pad2
 
 __Styling
 
 __RatStyling
 
 __Legend
 
 __NLegEnt
 
 __normalizedToUnity
 
 __Objects
 

Detailed Description

Definition at line 97 of file PlotUtils.py.

Constructor & Destructor Documentation

◆ __init__()

def PlotUtils.PlotUtils.__init__ (   self,
  size = 18,
  status = "Internal",
  lumi = 1.,
  sqrts = "13",
  normalizedToUnity = False 
)

Definition at line 98 of file PlotUtils.py.

98  def __init__(self, size=18, status="Internal", lumi=1., sqrts="13", normalizedToUnity=False):
99  self.__Status = status
100  self.__Size = size
101  self.__Lumi = lumi # in fb^-1
102  self.__SqrtS = sqrts
103  self.__VerticalCanvasSplit = 0.4
104  self.__Canvas = None
105  self.__Pad1 = None
106  self.__Pad2 = None
107  self.__Styling = None
108  self.__RatStyling = None
109  self.__Legend = None
110  self.__NLegEnt = 0
111  self.__normalizedToUnity = normalizedToUnity
112  self.__Objects = []
113 

Member Function Documentation

◆ __AddItemToLegend()

def PlotUtils.PlotUtils.__AddItemToLegend (   self,
  Item,
  Style 
)
private

Definition at line 173 of file PlotUtils.py.

173  def __AddItemToLegend(self, Item, Style):
174  try:
175  self.__Legend.AddEntry(Item, Item.GetTitle(), Style)
176  except:
177  self.__Legend.AddEntry(Item.get(), Item.GetTitle(), Style)
178 
179  self.__NLegEnt += 1
180 

◆ AdaptLabelsBottomPad()

def PlotUtils.PlotUtils.AdaptLabelsBottomPad (   self,
  histos,
  scale = 1. 
)

Definition at line 238 of file PlotUtils.py.

238  def AdaptLabelsBottomPad(self, histos, scale=1.):
239  if self.__VerticalCanvasSplit == 0:
240  labelscalefact = 1.
241  else:
242  labelscalefact = 1. / (scale * self.__VerticalCanvasSplit)
243  for hist in histos:
244  hist.GetXaxis().SetTitleSize(labelscalefact * hist.GetXaxis().GetTitleSize())
245  hist.GetYaxis().SetTitleSize(labelscalefact * hist.GetYaxis().GetTitleSize())
246  hist.GetXaxis().SetLabelSize(labelscalefact * hist.GetXaxis().GetLabelSize())
247  hist.GetYaxis().SetLabelSize(labelscalefact * hist.GetYaxis().GetLabelSize())
248  hist.GetXaxis().SetTitleOffset(2.2 / labelscalefact * hist.GetXaxis().GetTitleOffset())
249  hist.GetYaxis().SetTitleOffset(1.05 / labelscalefact * hist.GetYaxis().GetTitleOffset())
250 

◆ AdaptLabelsTopPad()

def PlotUtils.PlotUtils.AdaptLabelsTopPad (   self,
  histos 
)

Definition at line 228 of file PlotUtils.py.

228  def AdaptLabelsTopPad(self, histos):
229  labelscalefact = 1. / (1. - self.__VerticalCanvasSplit)
230  for hist in histos:
231  hist.GetXaxis().SetTitleSize(labelscalefact * hist.GetXaxis().GetTitleSize())
232  hist.GetYaxis().SetTitleSize(labelscalefact * hist.GetYaxis().GetTitleSize())
233  hist.GetXaxis().SetLabelSize(labelscalefact * hist.GetXaxis().GetLabelSize())
234  hist.GetYaxis().SetLabelSize(labelscalefact * hist.GetYaxis().GetLabelSize())
235  hist.GetXaxis().SetTitleOffset(1. / labelscalefact * hist.GetXaxis().GetTitleOffset())
236  hist.GetYaxis().SetTitleOffset(1. / labelscalefact * hist.GetYaxis().GetTitleOffset())
237 

◆ AddToLegend()

def PlotUtils.PlotUtils.AddToLegend (   self,
  Items,
  Style = "FL" 
)

Definition at line 166 of file PlotUtils.py.

166  def AddToLegend(self, Items, Style="FL"):
167  if isinstance(Items, list):
168  for I in Items:
169  self.__AddItemToLegend(I, Style)
170  else:
171  self.__AddItemToLegend(Items, Style)
172 

◆ addValuesInText()

def PlotUtils.PlotUtils.addValuesInText (   self,
  histo,
  on_top = True,
  off_set_y = 0.005 
)

Definition at line 260 of file PlotUtils.py.

260  def addValuesInText(self, histo, on_top=True, off_set_y=0.005):
261  plot_range_x = (histo.GetXaxis().GetBinUpEdge(histo.GetNbinsX()) - histo.GetXaxis().GetBinLowEdge(1)) / (
262  (1 - self.GetCanvas().GetRightMargin()) - self.GetCanvas().GetLeftMargin())
263  plot_range_y = (histo.GetMaximum() - histo.GetMinimum())
264 
265  left_margin = self.GetCanvas().GetLeftMargin()
266  bottom_margin = 0
267  if on_top and self.__Pad1:
268  plot_range_y /= (1 - self.__Pad1.GetTopMargin() - self.__Pad1.GetBottomMargin())
269  bottom_margin = self.__Pad1.GetBottomMargin()
270 
271  elif on_top and self.GetCanvas():
272  plot_range_y /= (1 - self.GetCanvas().GetTopMargin() - self.GetCanvas().GetBottomMargin())
273  bottom_margin = self.GetCanvas().GetBottomMargin()
274  elif not on_top and self.__Pad2:
275  plot_range_y /= (1 - self.__Pad2.GetTopMargin() - self.__Pad2.GetBottomMargin())
276  bottom_margin = self.__Pad2.GetBottomMargin()
277 
278  for i in range(1, histo.GetNbinsX() + 1):
279  tex = self.DrawTLatex(
280  left_margin + ((histo.GetBinCenter(i) - histo.GetXaxis().GetBinLowEdge(1)) / plot_range_x),
281  bottom_margin + (histo.GetBinContent(i) + off_set_y - histo.GetMinimum()) / plot_range_y,
282  "%.3f" % (histo.GetBinContent(i)),
283  size=10,
284  align=21,
285  color=histo.GetLineColor(),
286  )

◆ CreateLegend()

def PlotUtils.PlotUtils.CreateLegend (   self,
  x1,
  y1,
  x2,
  y2,
  textsize = 22 
)

Definition at line 151 of file PlotUtils.py.

151  def CreateLegend(self, x1, y1, x2, y2, textsize=22):
152  if self.__Legend:
153  print "WARNING: There already exists a legend. Will delete the old one"
154  del self.__Legend
155  self.__Legend = ROOT.TLegend(x1, y1, x2, y2)
156  self.__Legend.SetFillStyle(0)
157  self.__Legend.SetBorderSize(0)
158  self.__Legend.SetTextFont(43)
159  self.__Legend.SetTextSize(textsize)
160  return self.__Legend
161 

◆ DrawAtlas()

def PlotUtils.PlotUtils.DrawAtlas (   self,
  x,
  y,
  align = 11 
)

Definition at line 130 of file PlotUtils.py.

130  def DrawAtlas(self, x, y, align=11):
131  # print "Size is %.2f"%self.__Size
132  self.DrawTLatex(x, y, "#font[72]{ATLAS} %s" % self.__Status, self.__Size, 43, align)
133 

◆ DrawLegend()

def PlotUtils.PlotUtils.DrawLegend (   self,
  NperCol = 3 
)

Definition at line 181 of file PlotUtils.py.

181  def DrawLegend(self, NperCol=3):
182  if not self.__Legend:
183  print "No legend has been defined yet"
184  return
185  N = self.__NLegEnt
186  Col = int((N - N % NperCol) / NperCol + (N % NperCol > 0))
187  if Col < 1: Col = 1
188  self.__Legend.SetNColumns(Col)
189  self.__Legend.Draw()
190 

◆ DrawLumiSqrtS()

def PlotUtils.PlotUtils.DrawLumiSqrtS (   self,
  x,
  y,
  align = 11,
  lumi = 1. 
)

Definition at line 134 of file PlotUtils.py.

134  def DrawLumiSqrtS(self, x, y, align=11, lumi=1.):
135  if self.__normalizedToUnity: self.DrawTLatex(x, y, "#sqrt{s} = %s TeV" % (self.__SqrtS), self.__Size, 43, align)
136  elif self.__Lumi >= 999999999: self.DrawTLatex(x, y, "#sqrt{s} = %s TeV, ?? pb^{-1}" % (self.__SqrtS), self.__Size, 43, align)
137  elif self.__Lumi < 1.e-6:
138  lumiToPrint = "%.0f" % (self.__Lumi * 1e6)
139  self.DrawTLatex(x, y, "#sqrt{s} = %s TeV, %s nb^{-1}" % (self.__SqrtS, lumiToPrint), self.__Size, 43, align)
140  elif self.__Lumi < 1.e-3:
141  lumiToPrint = "%.0f" % (self.__Lumi * 1e3)
142  self.DrawTLatex(x, y, "#sqrt{s} = %s TeV, %s pb^{-1}" % (self.__SqrtS, lumiToPrint), self.__Size, 43, align)
143  else:
144  lumiToPrint = "%.1f" % (self.__Lumi)
145  self.DrawTLatex(x, y, "#sqrt{s} = %s TeV, %s fb^{-1}" % (self.__SqrtS, lumiToPrint), self.__Size, 43, align)
146 

◆ DrawSource()

def PlotUtils.PlotUtils.DrawSource (   self,
  probe,
  x,
  y,
  align = 11 
)

Definition at line 191 of file PlotUtils.py.

191  def DrawSource(self, probe, x, y, align=11):
192  self.DrawTLatex(x, y, self.ProbeName(probe), self.__Size, 43, align)
193 

◆ DrawSqrtS()

def PlotUtils.PlotUtils.DrawSqrtS (   self,
  x,
  y,
  align = 11 
)

Definition at line 147 of file PlotUtils.py.

147  def DrawSqrtS(self, x, y, align=11):
148  self.DrawTLatex(x, y, "#sqrt{s} = %s TeV" % (self.__SqrtS), self.__Size, 43, align)
149 
150 

◆ drawStyling()

def PlotUtils.PlotUtils.drawStyling (   self,
  Template,
  ymin,
  ymax,
  TopPad = True,
  RemoveLabel = False 
)

Definition at line 251 of file PlotUtils.py.

251  def drawStyling(self, Template, ymin, ymax, TopPad=True, RemoveLabel=False):
252  self.__Styling = Template.Clone("Style" + Template.GetName())
253  self.__Styling.SetMinimum(ymin)
254  self.__Styling.SetMaximum(ymax)
255 
256  if RemoveLabel == True: self.__Styling.GetXaxis().SetLabelOffset(10.)
257  if TopPad: self.AdaptLabelsTopPad([self.__Styling])
258  self.__Styling.Draw("AXIS")
259 

◆ DrawTLatex()

def PlotUtils.PlotUtils.DrawTLatex (   self,
  x,
  y,
  text,
  size = 18,
  font = 43,
  align = 11,
  ndc = True,
  color = -1 
)

Definition at line 114 of file PlotUtils.py.

114  def DrawTLatex(self, x, y, text, size=18, font=43, align=11, ndc=True, color=-1):
115  tex = ROOT.TLatex()
116  tex.SetTextAlign(align)
117  tex.SetTextSize(size)
118  tex.SetTextFont(font)
119  if ndc: tex.SetNDC()
120  if color > -1: tex.SetTextColor(color)
121  self.__Objects.append(tex)
122  tex.DrawLatex(x, y, text)
123 

◆ GetBottomPad()

def PlotUtils.PlotUtils.GetBottomPad (   self)

Definition at line 226 of file PlotUtils.py.

226  def GetBottomPad(self):
227  return self.__Pad2

◆ GetCanvas()

def PlotUtils.PlotUtils.GetCanvas (   self)

Definition at line 204 of file PlotUtils.py.

204  def GetCanvas(self):
205  if not self.__Canvas: print "WARNING: No Canvas has been created yet. Please call CreateXPadCanvas() before"
206  return self.__Canvas
207 

◆ GetLegend()

def PlotUtils.PlotUtils.GetLegend (   self,
  x1 = 0,
  y1 = 1.,
  x2 = 1.,
  y2 = 1. 
)

Definition at line 162 of file PlotUtils.py.

162  def GetLegend(self, x1=0, y1=1., x2=1., y2=1.):
163  if not self.__Legend: return CreateLegend(x1, y1, x2, y2)
164  return self.__Legend
165 

◆ GetLumi()

def PlotUtils.PlotUtils.GetLumi (   self)

Definition at line 127 of file PlotUtils.py.

127  def GetLumi(self):
128  return self.__Lumi
129 

◆ GetStatus()

def PlotUtils.PlotUtils.GetStatus (   self)

Definition at line 124 of file PlotUtils.py.

124  def GetStatus(self):
125  return self.__Status
126 

◆ GetTopPad()

def PlotUtils.PlotUtils.GetTopPad (   self)

Definition at line 224 of file PlotUtils.py.

224  def GetTopPad(self):
225  return self.__Pad1

◆ Prepare1PadCanvas()

def PlotUtils.PlotUtils.Prepare1PadCanvas (   self,
  cname,
  width = 800,
  height = 600,
  isQuad = False 
)

Definition at line 194 of file PlotUtils.py.

194  def Prepare1PadCanvas(self, cname, width=800, height=600, isQuad=False):
195  if isQuad: height = width
196  if self.__Canvas:
197  if self.__Canvas.GetName() != cname: self.__Canvas = None
198  else:
199  print "INFO Already found a canvas named: " + cname
200  return self.__Canvas
201  self.__Canvas = ROOT.TCanvas(cname, cname, width, height)
202  self.__Canvas.cd()
203 

◆ Prepare2PadCanvas()

def PlotUtils.PlotUtils.Prepare2PadCanvas (   self,
  cname,
  width = 800,
  height = 600,
  isQuad = False,
  DoLogX = False 
)

Definition at line 208 of file PlotUtils.py.

208  def Prepare2PadCanvas(self, cname, width=800, height=600, isQuad=False, DoLogX=False):
209  self.Prepare1PadCanvas(cname, width, height, isQuad)
210 
211  self.__Pad1 = ROOT.TPad(cname+"Pad1", cname, 0.0, self.__VerticalCanvasSplit - 0.03, 1.0, 1.0)
212  self.__Pad2 = ROOT.TPad(cname+"Pad2", cname, 0.0, 0.0, 1.0, self.__VerticalCanvasSplit - 0.03)
213  if DoLogX:
214  self.__Pad1.SetLogx()
215  self.__Pad2.SetLogx()
216  self.__Pad1.SetBottomMargin(0.03) # set to 0 for space between top and bottom pad
217  self.__Pad1.SetTopMargin(0.09)
218  self.__Pad1.Draw()
219  self.__Pad2.SetTopMargin(0.01) # set to 0 for space between top and bottom pad
220  self.__Pad2.SetBottomMargin(0.35)
221  self.__Pad2.SetGridy()
222  self.__Pad2.Draw()
223 

◆ saveHisto()

def PlotUtils.PlotUtils.saveHisto (   self,
  name,
  outputfiletypes 
)

Definition at line 287 of file PlotUtils.py.

287  def saveHisto(self, name, outputfiletypes):
288  Path = RemoveSpecialChars(name)
289  if Path.find("/") != -1:
290  dir_name = Path[ : Path.rfind("/") ]
291  os.system("mkdir -p %s"%(dir_name))
292  if "png" in outputfiletypes:
293  # need a 'pdf' file for using 'convert' to create a 'png'
294  if not "pdf" in outputfiletypes:
295  outputfiletypes.append("pdf")
296  a, b = outputfiletypes.index('pdf'), outputfiletypes.index('png')
297  outputfiletypes[b], outputfiletypes[a] = outputfiletypes[a], outputfiletypes[b]
298  if self.GetBottomPad(): self.GetBottomPad().RedrawAxis()
299  if self.GetTopPad(): self.GetTopPad().RedrawAxis()
300 
301  for otype in outputfiletypes:
302  if otype != "png":
303  self.__Canvas.SaveAs("%s.%s" % (Path, otype))
304  else:
305  # due to problems in png creation, convert pdfs to pngs manually
306  os.system("convert -density 300 %s.pdf %s.png" % (Path, Path))

Member Data Documentation

◆ __Canvas

PlotUtils.PlotUtils.__Canvas
private

Definition at line 104 of file PlotUtils.py.

◆ __Legend

PlotUtils.PlotUtils.__Legend
private

Definition at line 109 of file PlotUtils.py.

◆ __Lumi

PlotUtils.PlotUtils.__Lumi
private

Definition at line 101 of file PlotUtils.py.

◆ __NLegEnt

PlotUtils.PlotUtils.__NLegEnt
private

Definition at line 110 of file PlotUtils.py.

◆ __normalizedToUnity

PlotUtils.PlotUtils.__normalizedToUnity
private

Definition at line 111 of file PlotUtils.py.

◆ __Objects

PlotUtils.PlotUtils.__Objects
private

Definition at line 112 of file PlotUtils.py.

◆ __Pad1

PlotUtils.PlotUtils.__Pad1
private

Definition at line 105 of file PlotUtils.py.

◆ __Pad2

PlotUtils.PlotUtils.__Pad2
private

Definition at line 106 of file PlotUtils.py.

◆ __RatStyling

PlotUtils.PlotUtils.__RatStyling
private

Definition at line 108 of file PlotUtils.py.

◆ __Size

PlotUtils.PlotUtils.__Size
private

Definition at line 100 of file PlotUtils.py.

◆ __SqrtS

PlotUtils.PlotUtils.__SqrtS
private

Definition at line 102 of file PlotUtils.py.

◆ __Status

PlotUtils.PlotUtils.__Status
private

Definition at line 99 of file PlotUtils.py.

◆ __Styling

PlotUtils.PlotUtils.__Styling
private

Definition at line 107 of file PlotUtils.py.

◆ __VerticalCanvasSplit

PlotUtils.PlotUtils.__VerticalCanvasSplit
private

Definition at line 103 of file PlotUtils.py.


The documentation for this class was generated from the following file:
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
plotIsoValidation.DrawTLatex
def DrawTLatex(x, y, text, size=18, font=43, align=11)
Definition: plotIsoValidation.py:7
dumpHVPathFromNtuple.append
bool append
Definition: dumpHVPathFromNtuple.py:91
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:195
PlotUtils.RemoveSpecialChars
def RemoveSpecialChars(In)
Definition: PlotUtils.py:7
plotIsoValidation.saveHisto
def saveHisto(plot_options, histo)
Definition: plotIsoValidation.py:17
python.processes.powheg.ZZ.ZZ.__init__
def __init__(self, base_directory, **kwargs)
Constructor: all process options are set here.
Definition: ZZ.py:18
calibdata.cd
cd
Definition: calibdata.py:51