ATLAS Offline Software
Classes | Functions | Variables
python.draw_obj Namespace Reference

Classes

class  _options
 

Functions

def draw_obj (obj, options="", padnum=-1, pad=None, min=None, max=None)
 
def get_pad (advance_p=1, padnum=-1)
 
def get_canvas (cname="c1")
 
def zone (nx, ny)
 
def printeps (s="out.eps")
 

Variables

int _samecount = 0
 
int _lastpad = 0
 
int _nextpad = 1
 
int _npads = 1
 
 _canvas = None
 

Function Documentation

◆ draw_obj()

def python.draw_obj.draw_obj (   obj,
  options = "",
  padnum = -1,
  pad = None,
  min = None,
  max = None 
)
Draw the root object OBJ in the next available pad.

Inputs:
  obj -         The object to draw.
  options -     Drawing options.
            These are passed through to the root Draw
            method, except that we have special
            handling for the SAME option, and add a new MERGE option.
            See the header for details.
  padnum -      If this is a non-negative integer, then this specifies
            the pad in which to draw, overriding
            other specifications except for PAD.  Note: subpad numbers
            start with 1.
  pad -         Explicitly specify the pad to use for drawing.
            Overrides all other specifications.

Returns:
  The object that we drew (may not be the same as OBJ if we
  made a copy).

Definition at line 109 of file draw_obj.py.

109 def draw_obj (obj, options = "", padnum = -1, pad = None, min=None, max=None):
110  """Draw the root object OBJ in the next available pad.
111 
112 Inputs:
113  obj - The object to draw.
114  options - Drawing options.
115  These are passed through to the root Draw
116  method, except that we have special
117  handling for the SAME option, and add a new MERGE option.
118  See the header for details.
119  padnum - If this is a non-negative integer, then this specifies
120  the pad in which to draw, overriding
121  other specifications except for PAD. Note: subpad numbers
122  start with 1.
123  pad - Explicitly specify the pad to use for drawing.
124  Overrides all other specifications.
125 
126 Returns:
127  The object that we drew (may not be the same as OBJ if we
128  made a copy).
129 """
130  global _samecount
131 
132  if min is not None:
133  obj.SetMinimum (min)
134  if max is not None:
135  obj.SetMaximum (max)
136 
137  op = _options (options)
138 
139  # Should we advance to the next pad?
140  advance_p = 0
141 
142  # Should we do vertical axis rescaling?
143  rescale_p = 0
144 
145  # For SAME and MERGE, we have to pass SAME on to root.
146  if op.same or op.merge:
147  op.other += "SAME"
148 
149  if not op.same:
150  # No SAME option. Reset the count.
151  _samecount = 0
152 
153  # Advance to the next pad.
154  advance_p = 1
155  else:
156  # SAME was specified. Keep count of the number of such.
157  _samecount += 1
158  rescale_p = 1
159 
160  # Handle the MERGE option.
161  if op.merge:
162  rescale_p = 1
163  advance_p = 1
164 
165  if pad:
166  pad.cd()
167  else:
168  pad = get_pad (advance_p, padnum)
169 
170  if not op.merge and not op.same:
171  pad.SetLogy (not not op.logy)
172 
173  if isinstance (obj, TH1) and not isinstance (obj, TH2):
174  h = obj
175  if op.norm:
176  h = h.Clone()
177  intg = h.Integral()
178  if intg == 0:
179  intg = 1
180  h.Scale (1. / intg)
181  if max is not None:
182  h.SetMaximum (max)
183 
184  # Special handling for 1D histograms.
185  # If SAME was specified, rescale the vertical axis, if needed.
186  if rescale_p and max is None:
187  # Find the first hist already plotted.
188  hfirst = None
189  prims = pad.GetListOfPrimitives()
190  # Avoids RecursiveRemove crash...
191  prims.ResetBit(TObject.kMustCleanup)
192  for obj in prims:
193  if isinstance (obj, TH1):
194  hfirst = obj
195  break
196 
197  # If the new hist's maximum is larger than the first one,
198  # adjust the maximum of the first.
199  if hfirst and h.GetMaximum() > hfirst.GetMaximum():
200  hfirst.SetMaximum (h.GetMaximum() * 1.1)
201 
202  if hfirst and h.GetMinimum() < hfirst.GetMinimum():
203  hfirst.SetMinimum (h.GetMinimum())
204 
205  # Draw a copy of the histogram.
206  # Adjust the line style.
207  hh = h.DrawCopy (op.other)
208  if op.linetype >= 0:
209  hh.SetLineStyle (op.linetype)
210  else:
211  hh.SetLineStyle ((_samecount%4)+1)
212  if op.color >= 0:
213  hh.SetLineColor (op.color)
214  elif op.linecolors and _samecount >= 4:
215  hh.SetLineColor (_samecount//4 + 1)
216  if op.fill >= 0:
217  hh.SetFillColor (op.fill)
218  obj = hh
219  else:
220  # Not a 1-D histogram. Just draw it.
221  obj.Draw (op.other)
222 
223  return obj
224 
225 

◆ get_canvas()

def python.draw_obj.get_canvas (   cname = "c1")
Return the canvas named CNAME.
Create it if it doesn't exist.

Definition at line 273 of file draw_obj.py.

273 def get_canvas (cname = "c1"):
274  """Return the canvas named CNAME.
275 Create it if it doesn't exist.
276 """
277  global _canvas
278  _canvas = gROOT.FindObject (cname)
279  if not _canvas:
280  _canvas = TCanvas (cname, cname, 700, 600)
281  _canvas.SetLeftMargin (0.15)
282  _canvas.SetBottomMargin (0.15)
283  _canvas.SetLogy (0)
284  return _canvas
285 
286 
287 

◆ get_pad()

def python.draw_obj.get_pad (   advance_p = 1,
  padnum = -1 
)
Advance to the next pad, if requested.
Allow clicking on the pads (button 2) to change the next pad.

Definition at line 226 of file draw_obj.py.

226 def get_pad (advance_p = 1, padnum = -1):
227  """Advance to the next pad, if requested.
228 Allow clicking on the pads (button 2) to change the next pad.
229 """
230  global _lastpad, _nextpad, _npads
231 
232  c1 = get_canvas()
233  pad = TVirtualPad.Pad()
234 
235  if advance_p:
236  if (pad and
237  pad.GetCanvasID() == c1.GetCanvasID() and
238  pad.GetNumber() != _lastpad and pad.GetNumber() != 0):
239  _nextpad = pad.GetNumber()
240  if _nextpad > _npads:
241  _nextpad = 1
242 
243  # Set up to draw on nextpad.
244  # Bump it for the next go around.
245  if _npads > 1:
246  _lastpad = _nextpad
247  _nextpad += 1
248  if _nextpad > _npads:
249  _nextpad = 1
250  else:
251  _lastpad = 0
252 
253  # Select the pad.
254  c1.cd (_lastpad)
255 
256  # Handle padnum.
257  if padnum >= 0:
258  _lastpad = padnum
259  if _npads > 0:
260  _nextpad = _lastpad + 1
261  if _nextpad > _npads:
262  _nextpad = 0
263  else:
264  _nextpad = 0
265 
266  c1.cd (_lastpad)
267 
268  # Refetch the pad.
269  return TVirtualPad.Pad()
270 
271 

◆ printeps()

def python.draw_obj.printeps (   s = "out.eps")
Print the current canvas as an eps file.

Definition at line 302 of file draw_obj.py.

302 def printeps (s = "out.eps"):
303  """Print the current canvas as an eps file."""
304 
305  c1 = get_canvas()
306  c1.Print (s, "eps,Portrait")
307  return

◆ zone()

def python.draw_obj.zone (   nx,
  ny 
)
Divide the canvas into subpads.
NX and NY are the number of subpads in x and y, respectively.

Definition at line 288 of file draw_obj.py.

288 def zone (nx, ny):
289  """Divide the canvas into subpads.
290 NX and NY are the number of subpads in x and y, respectively.
291 """
292  global _npads, _nextpad, _lastpad
293  c1 = get_canvas()
294  c1.Clear()
295  c1.Divide (nx, ny)
296  _npads = nx*ny
297  _nextpad = 1
298  _lastpad = 0
299  return
300 
301 

Variable Documentation

◆ _canvas

python.draw_obj._canvas = None
private

Definition at line 272 of file draw_obj.py.

◆ _lastpad

int python.draw_obj._lastpad = 0
private

Definition at line 65 of file draw_obj.py.

◆ _nextpad

int python.draw_obj._nextpad = 1
private

Definition at line 68 of file draw_obj.py.

◆ _npads

int python.draw_obj._npads = 1
private

Definition at line 71 of file draw_obj.py.

◆ _samecount

int python.draw_obj._samecount = 0
private

Definition at line 61 of file draw_obj.py.

python.draw_obj.printeps
def printeps(s="out.eps")
Definition: draw_obj.py:302
python.draw_obj.draw_obj
def draw_obj(obj, options="", padnum=-1, pad=None, min=None, max=None)
Definition: draw_obj.py:109
python.draw_obj.get_canvas
def get_canvas(cname="c1")
Definition: draw_obj.py:273
python.draw_obj.zone
def zone(nx, ny)
Definition: draw_obj.py:288
python.draw_obj.get_pad
def get_pad(advance_p=1, padnum=-1)
Definition: draw_obj.py:226