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.SetLogx (not not op.logx)
172  pad.SetLogy (not not op.logy)
173 
174  if isinstance (obj, TH1) and not isinstance (obj, TH2):
175  h = obj
176  if op.norm:
177  h = h.Clone()
178  intg = h.Integral()
179  if intg == 0:
180  intg = 1
181  h.Scale (1. / intg)
182  if max is not None:
183  h.SetMaximum (max)
184 
185  # Special handling for 1D histograms.
186  # If SAME was specified, rescale the vertical axis, if needed.
187  if rescale_p and max is None:
188  # Find the first hist already plotted.
189  hfirst = None
190  prims = pad.GetListOfPrimitives()
191  # Avoids RecursiveRemove crash...
192  prims.ResetBit(TObject.kMustCleanup)
193  for obj in prims:
194  if isinstance (obj, TH1):
195  hfirst = obj
196  break
197 
198  # If the new hist's maximum is larger than the first one,
199  # adjust the maximum of the first.
200  if hfirst and h.GetMaximum() > hfirst.GetMaximum():
201  hfirst.SetMaximum (h.GetMaximum() * 1.1)
202 
203  if hfirst and h.GetMinimum() < hfirst.GetMinimum():
204  hfirst.SetMinimum (h.GetMinimum())
205 
206  # Draw a copy of the histogram.
207  # Adjust the line style.
208  hh = h.DrawCopy (op.other)
209  if op.linetype >= 0:
210  hh.SetLineStyle (op.linetype)
211  else:
212  hh.SetLineStyle ((_samecount%4)+1)
213  if op.color >= 0:
214  hh.SetLineColor (op.color)
215  elif op.linecolors and _samecount >= 4:
216  hh.SetLineColor (_samecount//4 + 1)
217  if op.fill >= 0:
218  hh.SetFillColor (op.fill)
219  obj = hh
220  else:
221  # Not a 1-D histogram. Just draw it.
222  obj.Draw (op.other)
223 
224  return obj
225 
226 

◆ 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 274 of file draw_obj.py.

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

◆ 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 227 of file draw_obj.py.

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

◆ printeps()

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

Definition at line 304 of file draw_obj.py.

304 def printeps (s = "out.eps"):
305  """Print the current canvas as an eps file."""
306 
307  c1 = get_canvas()
308  c1.Print (s, "eps,Portrait")
309  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 290 of file draw_obj.py.

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

Variable Documentation

◆ _canvas

python.draw_obj._canvas = None
private

Definition at line 273 of file draw_obj.py.

◆ _lastpad

int python.draw_obj._lastpad = 0
private

Definition at line 64 of file draw_obj.py.

◆ _nextpad

int python.draw_obj._nextpad = 1
private

Definition at line 67 of file draw_obj.py.

◆ _npads

int python.draw_obj._npads = 1
private

Definition at line 70 of file draw_obj.py.

◆ _samecount

int python.draw_obj._samecount = 0
private

Definition at line 60 of file draw_obj.py.

python.draw_obj.printeps
def printeps(s="out.eps")
Definition: draw_obj.py:304
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:274
python.draw_obj.zone
def zone(nx, ny)
Definition: draw_obj.py:290
python.draw_obj.get_pad
def get_pad(advance_p=1, padnum=-1)
Definition: draw_obj.py:227