Inf/NaN propagated error

In the flollowing macro I am fiiting my histogram with user defined function
but I am getting error as follows.
Warning in TH1F::Fit: Abnormal termination of minimization.
FCN=nan FROM MIGRAD STATUS=CALL LIMIT 5004 CALLS 5005 TOTAL
EDM=nan STRATEGY= 1 NO ERROR MATRIX
EXT PARAMETER CURRENT GUESS STEP FIRST
NO. NAME VALUE ERROR SIZE DERIVATIVE
1 p0 nan 9.90000e-03 nan nan

Warning in TCanvas::ResizePad: Inf/NaN propagated to the pad. Check drawn objects.
Warning in TCanvas::ResizePad: c1 height changed from 0 to 10

root [1] Warning in TCanvas::ResizePad: Inf/NaN propagated to the pad. Check drawn objects.
Warning in TCanvas::ResizePad: c1 height changed from 0 to 10

Thanks and regards
sunil

/////////////////////////////////////////////////////

void test(){
TCanvas *c1 = new TCanvas(“c1”, “”, 800, 600, 800, 600);
TF1 *fitfun = new TF1(“fitfun”,FitFunction, 0.1, 0.99, 1);
TH1F *h1 = new TH1F(“h1”, “”, 100, 0,0.99);
fitfun->SetParameters(0,0.001);
Double_t f =0; Double_t P=0;
for(Int_t ii =0; ii<100;ii++){
f = f+.01;
P= 0.5/Double_t(sqrt(f));
h1->Fill(f,P);
}
Double_t total1 = h1->Integral();
cout<< total1<< endl;
h1->Scale(1./(float)total1);
h1->Draw();
h1->Fit(fitfun);
}

Double_t FitFunction(Double_t *x, Double_t par) {
double x1= par[0]+1/Float_t(2
sqrt(x));
return x1;
}

I do not see how you can fit your histogram with a function like yours.
I have modified your code and function such that you get a reasonable fit. See below the lines marked with “//<====”

Rene

void test(){ 
TCanvas *c1 = new TCanvas("c1", "", 800, 600, 800, 600); 
TF1 *fitfun = new TF1("fitfun",FitFunction, 0.01, 0.99, 2);  //<====
TH1F *h1 = new TH1F("h1", "", 100, 0,0.99); 
fitfun->SetParameters(0.001,2.);  //<====
Double_t f =0; Double_t P=0; 
for(Int_t ii =0; ii<100;ii++){ 
f = f+.01; 
P= 0.5/Double_t(sqrt(f)); 
h1->Fill(f,P); 
} 
Double_t total1 = h1->Integral(); 
cout<< total1<< endl; 
h1->Scale(1./(float)total1); 
h1->Draw(); 
h1->Fit(fitfun,"r"); //<====
} 

Double_t FitFunction(Double_t *x, Double_t *par) { 
double x1= par[0]+1./Float_t(par[1]*sqrt(x[0]));  //<====
return x1; 
} 

Hi,

I get the following error when I have n initiatlized with values>10. for n=20,30 or greater it gives the following:

Inf/NaN propagated to the pad. Check drawn objects.
Warning in <TCanvas::ResizePad>: c1 height changed from 0 to 10

Warning in <TCanvas::ResizePad>: Inf/NaN propagated to the pad. Check drawn objects.
Warning in <TCanvas::ResizePad>: c1 height changed from 0 to 10

My code(here am trying to plot a function in TGraph):

void p1()
{
Float_t alpha = 1090.;
Float_t p = 0.330;
const Int_t n = 10.;
Float_t V[n],r[n];
Float_t R;
for (Int_t i=0; i<n;i++)
{
r[i] = i*10/n;
R = r[i];
if (i == 0)
{V[i] = 1.;}
else {
V[i] = -14.4/R + alpha*exp(-R/p);
******after this I have a TGraph and draw which works well for n= 10*****
}
}

Hi,

Did you check that the values of V[I] are not indeed to large/small?

Philippe.

I am getting this error when I am trying to generate histogram like attached histogram. Macro That I am using is also attached. Kindly suggest me what possible changes that I can make?

root [0] 
Processing signaltobackratio.C...
sigma BR ====  4.34e-05
sigma BR ====  1e-05
sigma BR ====  4e-06
sigma BR ====  9.3e-07
sigma BR ====  35.7154
sigma BR ====  24.7804
sigma BR ====  9.64849
sigma BR ====  1.20161
Info in <TCanvas::MakeDefCanvas>:  created default TCanvas with name c1
============================
Max significance with bins 0-0 is: 0
S and B : 0, 0
S/B : -nan
S/sqrt(B) : -nan
Total signal eff.: 0
============================
Max significance with bins 0-0 is: 0
S and B are: 0, 0
S/B : -nan
S/sqrt(B) : -nan
Total signal eff.: 0
============================
Max significance with bins 0-0 is: 0
S and B are: 0, 0
S/B : -nan
S/sqrt(B) : -nan
Total signal eff.: 0
============================
Max significance with bins 0-0 is: 0
S and B are: 0, 0
S/B : -nan
S/sqrt(B) : -nan
Total signal eff.: 0
Warning in <TCanvas::ResizePad>: Inf/NaN propagated to the pad. Check drawn objects.
Warning in <TCanvas::ResizePad>: c1 height changed from 0 to 10

root [1] Warning in <TCanvas::ResizePad>: Inf/NaN propagated to the pad. Check drawn objects.
Warning in <TCanvas::ResizePad>: c1 height changed from 0 to 10

Warning in <TCanvas::ResizePad>: Inf/NaN propagated to the pad. Check drawn objects.
Warning in <TCanvas::ResizePad>: c1 height changed from 0 to 10

signaltobackratio.C (7.7 KB)

You need to understand why all your loops end with maxsig = S = B = 0.

BTW. Histogram bin numbers should go from 1 to nbins (bin 0 is the underflow bin):

  for(int i = 1; i <= nbins; i++) {
    for(int j = i + 1; j <= nbins; j++) {