# Create a histrogram and fit it with a gaussian?

Hi, i’m trying to create a histogram in which i have 7 bins and counts with a specific error (not sqrt(N)) how can i do? I have tried to read some tutorials but i was not able to create a program.

Thanks

``````{
const int n = 7;
double x[(n + 1)] = {-4., -3., -2., -1., 1., 2., 3., 4.};
TH1F *h = new TH1F("h", "my histo title;some X axis;some Y axis", n, x);
#if 0 /* 0 or 1 */
h->Sumw2(kTRUE);
h->FillRandom("gaus");
#else /* 0 or 1 */
h->SetBinContent(1, 10.); h->SetBinError(1, 3.);
h->SetBinContent(2, 100.); h->SetBinError(2, 10.);
h->SetBinContent(3, 700.); h->SetBinError(3, 25.);
h->SetBinContent(4, 3400.); h->SetBinError(4, 60.);
h->SetBinContent(5, 700.); h->SetBinError(5, 25.);
h->SetBinContent(6, 100.); h->SetBinError(6, 10.);
h->SetBinContent(7, 10.); h->SetBinError(7, 3.);
#endif /* 0 or 1 */
h->Print("all");
h->Fit("gaus", "IWL"); // "IWL" ... or ... "IL"
}
``````

Maybe you’d better try to use one of:
TGraphErrors
TGraphAsymmErrors
TGraphBentErrors
and:
TGraph::Fit

Thanks, last questions:

if i want to see the histogram, how can i do?
If i want to fit the histogram with a general function, how can i do?

Thanks

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