Re: [ROOT] Lost of the memory of SetDrawOption()?

From: Rene Brun (Rene.Brun@cern.ch)
Date: Wed Oct 23 2002 - 18:36:01 MEST


Hi Daniel,



On Wed, 23 Oct 2002, Daniel Cussol wrote:

> Hello Rooters,
>  I am facing the following problem: when I want to set a default Draw
> Option by using the SetDrawOption method, it seems that this a no effect
> when the object is plotted.
> 
> root [37] TH2F *h2=new TH2F("hh","Test",20,0,10,20,0,10)
> root [38] h2->SetDrawOption("box")
> root [39] h2->Fill(1,2,1)
> root [40] h2->Fill(2,2,3)
> root [41] h2->Fill(8,6,15)
> root [42] h2->Draw()
> 

SetDrawOption (See TObject::setDrawOption doc) applies only to an already 
drawn object. This function is typicalled called from the object context
menu to set a different option.
In your case, the h2->Draw() call will erase the current canvas and draw
the object h2 with the default options. If you do:
  h2->Draw();
  h2->SetDrawOption("box");
  gPad->Update(); //the change will become effective

>
> The h2 histogram is plotted with the
scatter plot ("HIST") option.
> If I now add objects to the list of function of this object, the draw
> options are also "lost" when plotting the histogram. Here is another
> example.
> 
> root [24] TArrow *ar=new TArrow(5.,0.,5.,5.)
> root [25] ar->SetArrowSize(0.05)                    
> root [26] ar->SetFillColor(kRed)
> root [26] ar->SetDrawOption("|>")
> root [27] h2->GetListOfFunctions()->Add(ar)
> root [28] h2->Draw()
> 
> The arrow is plotted as a straight line without any arrow, as if the ""
> Draw option was set. When looking at the DrawOption of the objects (using
> GetDrawOption() ), it seems that the SetDrawOption(Option_t *) has no
> effect!

You should do instead:

 TArrow *ar=new TArrow(5.,0.,5.,5.)
 ar->SetArrowSize(0.05) 
 ar->SetFillColor(kRed) 
 h2->GetListOfFunctions()->Add(ar,"|>");
 h2->Draw()

This form has the advantage that you can draw the same object
with different options in different pads of the same canvas.
The form of Add with a second argument was introduced only in 3.03/09.
I strongly suggest you move to this version.

Salutations

Rene Brun

> 
> Is it a standard behaviour? Could it be possible to store the wanted draw
> option and use it while drawing the object, as it was the case for "old"
> root versions?
> 
> I use root v3.02/04 alphacxx6 on Alpha UNIX DS20.
> 
> Daniel CUSSOL
> 
> LPC Caen
> Boulevard du Marechal Juin
> 14050 CAEN CEDEX
> 
> e-mail : cussol@in2p3.fr
> Tel    : +33-(0)2-31-45-29-73
> FAX    : +33-(0)2-31-45-25-49
> 



This archive was generated by hypermail 2b29 : Sat Jan 04 2003 - 23:51:15 MET