Root doesn't draw

I wrote this macro, root draw the function but when i do the fit doesn’t draw it.Someone can help me?
cosmics.c (1015 Bytes)

Hi,

the histogram is owned by the currently opened file; once you close the file the histogram vanishes, too (see the users guide on ownership). Call h1->SetDirectory(0) to cut the histogram’s connection to the file.

Cheers, Axel.

[quote=“Axel”]Hi,

the histogram is owned by the currently opened file; once you close the file the histogram vanishes, too (see the users guide on ownership). Call h1->SetDirectory(0) to cut the histogram’s connection to the file.

Cheers, Axel.[/quote]

You can also call

and all histograms created after this call will act as if you called

(I’m putting this here for me as much as anybody since I can never seem to find this when I want it. :smiley: )

Cheers,
Charles

ok it works!!But i try on another macro but it doesn’t work, i post this macro.
angolo.C (1.16 KB)

Hi,

a TGraph is not a histogram. And there is no TFile involved. Why do you call SetDirectory() in this macro?

Cheers, Axel.

Because it draw the function, but when i do the fit it doesn’t draw.

Hi,
The function is not drawn because it is evaluated in the wrong range. Your function makes sense for values of x > PI/2. You must set the correct function range and the using option “R” when fitting to avoid that the function is evaluated outside its range.
Do:

TF1 *f1 = new TF1("angolo",coseno,0,TMath::Pi()/2,2);

and later on

gr->Fit("angolo","R");

Best Regards

Lorenzo

With the parameters returned by the fit the function cannot be computed in the graph range (you get a NaN)
You can restrict the function range from {0,2] to [0,1.55] and you will see the function.

Rene

it works!Thanks