Can't call TH1::TH1

Hi,

I have a code below to create a canvas and draw a histogram with a set X and Y axis on that canvas. It doesn’t draw the histogram part just the canvas.

[code]void ComparingMediums()
{
//Create the canvas
TCanvas* my_canvas = new TCanvas(“my_canvas”, “FIXED AXIS”, 200, 10, 600, 400);

TH1 *hist = new TH1("hist", "New Plot", 350, 0., 320., 20, 0., -10.);
hist->Draw(); //Draw histogram

}[/code]

I get an error that says: Can’t call TH1::TH1(“hist”, “New Plot”, 350, 0., 320., 20, 0., -10.) in current scope.

Please help [-o<

Hi Leo,

two things:

  1. TH1 is the mother class of all histograms and its constructor is protected. For 2D histograms you should use a TH2F or similar
  2. Even if it wasn’t protected, you could not use it as you specified too many parameters in the constructor.

What exactly are you trying to achieve?

Cheers,
Danilo

Hi Danilo,

Thanks for replying .

What I’m trying to do now is to show a canvas and have the x axis and y axis with certain parameters and number of bins. I don’t understand why my code below won’t work. I’m still new to ROOT, and maybe I’m doing something obviously wrong.

Leo.

Hi Danilo,

It took me a while to understand what you meant, I’ve got it working but my y axis and x axis ranges are not showing.

For example, x axis from 0 to 350 and y axis from 0 to -10.

Thanks,
Leo

Nevermind, got it to work. I messed up the ranged co-ordinates after I change TH1 TO TH2F.

Thanks,
Leo