Why function is not taking parameters that are set by me inside the program

I want to fit the peaks in the histogram by gaus function but when i write a C program function is not taking the parameters that are set by me. why is this happening? how to resolve it?

Code is

#include "Riostream.h"
#include "TFile.h"
#include "TH1.h"
#include "TNtuple.h"
void hist() 
{
ifstream in;
in.open(Form("rough.dat"));
Float_t x,y;
Int_t nlines= 0;
TFile*f= new TFile("basic.root","RECREATE");
TH1F *h1 = new TH1F("h1","x distribution",472,128.5,600.5);


TNtuple*ntuple= new TNtuple("ntuple","data from asciifile","x:y");
while (1) 
{
in >> x>> y;
if (!in.good()) break;
if (nlines< 5) 
printf("x=%8f, y=%8f",x,y);
h1->Fill(x,y);

ntuple->Fill(x,y);
nlines++;
}
TF1 *func= new TF1 ("func", "[0]*exp(-0.5*((x-[1])/[2])^2)",350,450);
func->SetParameters(5850,413,1.8);
h1->Fit("func");

printf("found %dpoints\n",nlines);
in.close();
f->Write();
}

_ROOT Version:6.16
Platform:Ubuntu
Compiler: Not Provided


Maybe you want: h1->Fit(func, "", "", 350., 450.);

I have tried the same way also but it still taking the parameters by its own.

Hi
you do not provide input data, so one cant test your program.

Btw: I assume by “my parameters” you mean
“starting values of parameters to be fitted”
How do you know func is not taking your parameters

What happens if you do

h1->Draw();
func->Draw("same");

instead of

h1->Fit("func");

Otto

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.