Hello rooters, I am having a hard time understanding the use of the "goption" parameter used when fitting histogram by a function ; Int_t TH1::Fit(TF1 *f1 ,Option_t *option ,Option_t *goption, Axis_t xxmin, Axis_t xxmax) What I "naively" believed about this option is illustrated in the macro below where I tried several way of fitting 1D and 2D histograms and drawing the resulting function above the histogram : In the canvas with 1D histograms, I would have assumed that either pad 2 or pad 3 would Have looked like pad 4, but they both look like pad 1 In the canvas with 2D histograms the two pads look different, I would have expect them to look the same. I could no find in roottalk diggest or manual or HTML doc a detailed explanation of the effects of this option. Looking in the source makes me even more puzzled, because it seems That goption is applied to draw the histogram, not the fitting function QUOTE : if (!Foption.Nograph && GetDimension() < 3) Draw(goption); (yet in the macro exemple below, the option doesn't seems to affect the way the histograms are drawn neither) Wouldn't it make more sense if this drawing option was applied to the function instead of the histogram ? Or am I missing something ? This would be particularly helpfull for 2D histrograms, since in that case the "default" scattered points drawing of the 2D function doesn't suit, most of the time, the way the histrogram is drawn. I am using ROOT 4.00.08 with GDK on WIN2K (however, I verified that the described behaviours are the same on ROOT 3.10, or on linux box ) Thanks, eric **** MACRO ***** // RMK : I know the duplication of the functions is useless, but at some point I // got nervous about to what object the drawing option were applied ... // it is eventually not the point ... { // 1D thing ********** TCanvas canvas1D("canvasFit1D","canvasFit1D"); canvas1D.Divide(2,2); gStyle->SetOptFit(1); TH1D histo1D("fittedHisto1D","fittedHisto1D",11,-5,5); histo1D.FillRandom("gaus"); TF1 fitgaus1D_1("fitgaus1D_1","gaus"); TF1 fitgaus1D_2("fitgaus1D_2","gaus"); TF1 fitgaus1D_3("fitgaus1D_3","gaus"); fitgaus1D_1.SetNpx(22); // twice more than bins ... fitgaus1D_2.SetNpx(22); // twice more than bins ... fitgaus1D_3.SetNpx(22); // twice more than bins ... canvas1D.cd(1); histo1D.Draw(); canvas1D.cd(2); TH1D* histo1D_copy = histo1D.DrawCopy(); canvas1D.cd(3); TH1D* histo1D_copy2 = histo1D.DrawCopy(); canvas1D.cd(4); TH1D* histo1D_copy3 = histo1D.DrawCopy(); canvas1D.cd(1); histo1D.Fit(&fitgaus1D_1); canvas1D.cd(2); histo1D_copy->Fit(&fitgaus1D_2,"","Ptext"); // no text, no marker ... "L" Option canvas1D.cd(3); histo1D_copy2->Fit(&fitgaus1D_3,"","samePtext"); // no text, no marker .... "L" option canvas1D.cd(4); fitgaus1D_1.Draw("samePtext"); // P, text and no "L" option // 2D thing *************************** TCanvas canvas2D("canvasFit2D","canvasFit2D"); canvas2D.Divide(1,2); gStyle->SetOptFit(1); TH2D histo("fittedHisto","fittedHisto",11,-5,5,11,-5,5); histo.Fill(0,0,10); histo.Fill(1,0,1); histo.Fill(0,1,1); histo.Fill(-1,0,1); histo.Fill(0,-1,1); canvas2D.cd(1); histo.Draw("lego2"); canvas2D.cd(2); TH2D* histocopy = histo.DrawCopy("lego2"); TF2 fitgaus_1("fitgaus2D_1","xygaus"); fitgaus_1.SetParameters(10,0,0.1,0,0.1); TF2 fitgaus_2("fitgaus2D_2","xygaus"); fitgaus_2.SetParameters(10,0,0.1,0,0.1); canvas2D.cd(1); histo.Fit(&fitgaus_1,"0"); // fit without drawing fitgaus_1.Draw("surfsame"); // superimpose fit on histogram canvas2D.cd(2); histocopy->Fit(&fitgaus_2,"","surfsame"); // : try to superimpose during fit => scattered points plot }
This archive was generated by hypermail 2b29 : Sun Jan 02 2005 - 05:50:09 MET