Error: cannot initialize a variable of type 'TH2D *' with an rvalue of type 'TH1 *'


Please read tips for efficient and successful posting and posting code

ROOT Version: 6.18
Platform: Not Provided
Compiler: Not Provided


Good day

I am using ROOT 6.18 and I am trying to gate on a cube and these how I proceeded on the terminal.

ggdt_cube->GetZaxis()->SetRangeUser(386,406)

TH2D* matrix = ggdt_cube->Project3D(“xy”)

At this point I get this error

error: cannot initialize a variable of type ‘TH2D *’ with an rvalue of type ‘TH1 *’

Please help

Hi,

instead of

TH2D* matrix = ggdt_cube->Project3D("xy");

try

TH2D* matrix = static_cast<TH2D*>(ggdt_cube->Project3D("xy"));
1 Like

Thank you so much it worked like a charm