109def draw_obj (obj, options = "", padnum = -1, pad = None, min=None, max=None):
110 """Draw the root object OBJ in the next available pad.
111
112Inputs:
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
126Returns:
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
140 advance_p = 0
141
142
143 rescale_p = 0
144
145
146 if op.same or op.merge:
147 op.other += "SAME"
148
149 if not op.same:
150
151 _samecount = 0
152
153
154 advance_p = 1
155 else:
156
157 _samecount += 1
158 rescale_p = 1
159
160
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
186
187 if rescale_p and max is None:
188
189 hfirst = None
190 prims = pad.GetListOfPrimitives()
191
192 prims.ResetBit(TObject.kMustCleanup)
193 for obj in prims:
194 if isinstance (obj, TH1):
195 hfirst = obj
196 break
197
198
199
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
207
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
222 obj.Draw (op.other)
223
224 return obj
225
226