Re: Drawing Histograms in Canvas

From: Rene Brun (Rene.Brun@cern.ch)
Date: Tue Mar 30 1999 - 00:26:09 MEST


Hi Anton,
As already reported multiple times, the Draw function adds a reference
to the object. In most Root classes, the Draw function is not even
implemented, TObject::Draw is adequate. TObject::Draw is one statement
   AppenPad(option);

However, for some high level classes, such as histograms, the Draw
function is redefined. For example TH1::Draw by default clears
the current pad. This is simply a question of convention.
We estimated that most of the time, when drawing an histogram
you want to clear the pad. If you do not want to clear the pad,
use hist->Draw("same").
Clearing the pad would not make sense for low level primitives,
such as lines or text. In this case, you are likely going to draw
many low level primitives.
You should check when using a class, if its Draw function has been
redefined or not.
In your particular example, in the loop, new histograms
are imported from shared memory. Each histogram is drawn
into a separate pad. For exaple hpx->Draw will clear the pad
and add hpx to the list of objects to be painted later (TCanvas::Update)

Rene Brun


On Mon, 29 Mar 1999, Anton Fokin wrote:

> Hi rooters,
> 
> Having in mind that one should not call Draw() in a loop; for an object in
> a canvas (because TPad adds poiter to an object every time one calls
> Draw()), I find this example a little bit strange (taken from Consumer
> example) :
> 
>    Int_t oldentries = 0;
>    while (1) {
>       hpx    = (TH1F *) mfile->Get("hpx", hpx);
>       hpxpy  = (TH2F *) mfile->Get("hpxpy", hpxpy);
>       hprof  = (TProfile *) mfile->Get("hprof", hprof);
>       if (hpx->GetEntries() == oldentries) break;
>       oldentries = hpx->GetEntries();
>       if (!gROOT->IsBatch()) {
>          pad1->cd();
>          hpx->Draw();
>          pad2->cd();
>          hprof->Draw();
>          pad3->cd();
>          hpxpy->Draw("cont");
>          c1->Modified();
>          c1->Update();
>       } else {
>          printf("Entries, hpx=%d, Mean=%g,
> RMS=%g\n",hpx->GetEntries(),hpx->GetMean(),hpx->GetRMS());
>       }
>       gSystem->Sleep(100);   // sleep for 0.1 seconds
>    }
> 
> 
> Of course every time we call TMapFile.Get(); we get a new object, but then
> what about multiple Draw(); calls for the same TPad(); ? Is it ok, or can
> we avoid it somehow?
> 
> Best regards,
> 
> Dr. Anton Fokin
> 
> Division of Cosmic and Subatomic Physics
> Lund University
> Sweden
> 



This archive was generated by hypermail 2b29 : Tue Jan 04 2000 - 00:43:31 MET