Gaussion of a histo

Hello,

I’m still learning root. Now I want to fit a gaus of the histo h1. I tried much and read in the documentation, but it dont works.

Here is my code:

[code]#include
#include
#include
#include
#include
#include
#include

vector c=0;

using namespace std;

void a()
{

std::ifstream ifs;

ifs.open (“1986.asc”, std::ifstream::in);

= ifs.get();

while (ifs.good()) {
c.push_back(ifs.get());
}

ifs.close();

TCanvas*c1 = new TCanvas(“c1”,“c1”,800,1000);

TH1F *h1 = new TH1F(“h1”,“data”,100,-5,70);
TH1F *h2 = new TH1F(“h2”,“gaus of data 1”,100,-5,70);
//TH1F *h3 = new TH1F(“h3”,“gaus of data 2”,100,-5,70);

for(int i=0;i<c.size();i++)
h1->Fill(c.at(i));
h2->Fit(“h1”);
//h3->Fit(“gaus”);

h2->SetLineColor(kGreen);
//h3->SetLineColor(kGreen);

h1->Draw();
h2->Draw(“same”);
//h3->Draw(“same”);

c1->Print(“data.pdf”);

}

[/code]

So I have a third histogram but the third one isnt important now.
Thankyou for your help

HI,
If you want fit histogram by gausian or any other function use TF1 class. You can see example at http://root.cern.ch/root/html/tutorials/fit/myfit.C.html