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