[ROOT] When to use a pointer for TBox?

From: Remigius K. Mommsen (remigius.mommsen@cern.ch)
Date: Fri Aug 30 2002 - 23:07:54 MEST


Hi,

I stumbled over a mistake which I don't really understand.
I'd like to plot a 2D histogram and then draw a
box into it with TBox. First I started with a macro like:

{
ntuple->Draw("deltaE:mB");

TBox box(4,-4,5,0);
box.Draw();
}

When I execute this macro on the root command line it works as expected.
Well, then lets make a class out of it:

class myBox {

public:
   myBox() {}

   void draw() {
     ntuple->Draw("deltaE:mB");

     TBox _box(4,-4,5,0);
     _box.Draw();
   }
};

Using this class on the command line with
root [1] .L myBox.C
root [2] myBox *box = new myBox();
root [3] box->draw();

does draw the histogram but no box is drawn.

Finally I relized that I have to define the _box as pointer inside the
class myBox to make it work:

     TBox *_box = new TBox(4,-4,5,0);
     _box->Draw();

I don't understand why it worked in the first place (as macro), but
does not work when I use it inside a class. Could somebody
enlighten me?

Thanks a lot and best regards

Remi


*********************************************************************
Remigius K. Mommsen                 e-mail: mommsen@slac.stanford.edu
University of California, Irvine       URL:      home.cern.ch/mommsen
c/o SLAC                             voice:        ++1 (650) 926-3595
2575 Sand Hill Road #35             mobile:        ++1 (650) 387-1402
Menlo Park, CA 94025, US               fax:        ++1 (650) 926-8522
*********************************************************************



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