Re: Fitting histograms

From: Chris J Schilling <cschill_at_slac.stanford.edu>
Date: Sun, 7 Aug 2005 09:34:54 -0700


When you fit, ROOT draws the histogram and replaces the TCanvas with the fitted histogram. The way I know to get around this is a little complicated, so you may get better replies.

When you fit, try this:

h->Fit("gaus", "0");
h->GetFunction("gaus")->ResetBit(512);
h->Draw("same");

On Aug 7, 2005, at 5:24 AM, monika_at_rcf.rhic.bnl.gov wrote:

>
> Hi everybody,
>
> I have a root file which has 8 histograms. The aim is to draw all of
> them
> in one histogram. Out of these 8 histograms, I want to fit 6 of them
> with
> "gaus". But when I use the following script, it just draws the last
> histogram and fits it with "gaus". What am I missing here.
>
> After reading all of them from the root file I am saying :
>
> c1->SetBorderMode(1);
> c1->SetFillColor(kWhite);
> gStyle->SetOptFit(0);
> gStyle->SetOptStat("");
> c1->SetLogy();
> h1->SetMaximum(500);
> h1->SetMinimum(0);
> h1->SetLineColor(2);
> h1->SetLineWidth(2);
> h1->GetXaxis()->SetRange(0,150);
> h1->Draw();
> h2->SetLineColor(4);
> h2->SetLineWidth(2);
> h2->Draw("same");
> h3->Fit("gaus");
> h3->SetMarkerColor(8);
> h3->SetMarkerStyle(22);
> h3->SetMarkerSize(0.6);
> h3->Draw("pSame");
> h4->SetMarkerColor(6);
> h4->SetMarkerStyle(29);
> h4->SetMarkerSize(0.6);
> h4->Fit("gaus");
> h4->Draw("pSame");
> h5->SetMarkerColor(50);
> h5->SetMarkerStyle(28);
> h5->SetMarkerSize(0.6);
> h5->Fit("gaus");
> h5->Draw("pSame");
> h6->SetMarkerColor(1);
> h6->SetMarkerStyle(30);
> h6->SetMarkerSize(0.6);
> h6->Fit("gaus");
> h6->Draw("pSame");
> h7->SetMarkerColor(3);
> h7->SetMarkerStyle(23);
> h7->SetMarkerSize(0.6);
> h7->Fit("gaus");
> h7->Draw("pSame");
> h8->SetMarkerColor(3);
> h8->SetMarkerStyle(23);
> h8->SetMarkerSize(0.6);
> h8->Fit("gaus");
> h8->Draw("pSame");
>
> Thanks very much for any help.
>
> Monika
>
>
>
>



Research Assistant
University of Texas @ Austin
SLAC
High Energy Physics
512-589-3606 (cell)
650-926-2449 (office) Received on Sun Aug 07 2005 - 18:35:04 MEST

This archive was generated by hypermail 2.2.0 : Tue Jan 02 2007 - 14:45:11 MET