ProjectionY function: problems with pointers

Hi,

Is the following normal ?

root [129] TH1 *e2d = (TH2D*)c1->FindObject("electrons")
root [130] e2d->Draw("lego")   // does the job
root [131] TH1 *e1d = e2d->ProjectionY("",1,1)  // doesn't work
 Error: Can't call TH1::ProjectionY("",1,1) in current scope FILE:(tmpfile) LINE:1
Possible candidates are...
[cut]
Error: Symbol e2d is not defined in current scope  FILE:(tmpfile) LINE:1
root [132] TH1 *e1d = ((TH2D*)e2d)->ProjectionY("electrons",1,1)   // now it works
root [135] e1d->Draw()
root [136] e2d->ClassName()
(const char* 0xa698964)"TH2D"
root [137] e2d->Class_Name()
(const char* 0xb75fc3a3)"TH1"

Till now, I found this extra need for parentheses (command 132) only for this kind of function; but as can be seen the ClassName() function recognize the
pointed object correctly.

I’m using 4-04-02f

Regards, Germano

You should not do:

TH1 *e2d = (TH2D*)c1->FindObject("electrons") but

TH2 *e2d = (TH2D*)c1->FindObject("electrons")

ProjectionY is only in TH2

Rene

You are right,
I’ve seen it is not a virtual function not it is defined for classes other than TH2.
This is why I must cast the pointer before using it… :blush:

Sorry and tnx