Re: Draw

Rene Brun (Rene.Brun@cern.ch)
Fri, 11 Sep 1998 15:38:26 +0200


Patrice (Pat) wrote:
>
> Imagine drawing a histogram on canvas c1:
>
> hist->Draw();
>
> After, you create a new pad:
>
> TPad *newpad = new TPad("newpad","newpad",0.298851,0.391949,0.945402,0.976695);
> newpad->Draw();
>
> then, you modify the maximum:
> hist->SetMaximun(10);
>
> and you draw it in newpad:
> newpad->cd();
> hist->Draw(); // all looks right but:
>
> when you print it:
> c1.Print("plot.ps");
>
> you have a surprise. It is the same picture on c1 and on newpad
> (the maximum value being 10).
>
> It is possible to avoid that without creating a new histogram ?

Patrice,
When you object->Draw(), Root adds simply a reference to object
in the list of objects to be drawn in the pad. This means that
if you draw the same object into many pads, then modify the object,
the object will be modified in all pads.
You should use functions such as TH1::DrawCopy.
hist->DrawCopy() will create a copy of hist and the pad will have
a reference to the copied object, not the original object hist.
In your case, you should
hist->DrawCopy(); in the first pad
hist->setMaximum(...);
newpad->cd();
hist->Draw();

Many Root classes have the DrawCopy function. For classes with no
DrawCopy, you must create a copy of the object yourself.

Rene Brun