fit1.C

Go to the documentation of this file.
00001 void fit1() {
00002    //Simple fitting example (1-d histogram with an interpreted function)
00003    //To see the output of this macro, click begin_html <a href="gif/fit1.gif">here</a>. end_html
00004    //Author: Rene Brun
00005    
00006    TCanvas *c1 = new TCanvas("c1_fit1","The Fit Canvas",200,10,700,500);
00007    c1->SetGridx();
00008    c1->SetGridy();
00009    c1->GetFrame()->SetFillColor(21);
00010    c1->GetFrame()->SetBorderMode(-1);
00011    c1->GetFrame()->SetBorderSize(5);
00012 
00013    gBenchmark->Start("fit1");
00014    //
00015    // We connect the ROOT file generated in a previous tutorial
00016    // (see begin_html <a href="fillrandom.C.html">Filling histograms with random numbers from a function</a>) end_html
00017    //
00018    TString dir = gSystem->UnixPathName(gInterpreter->GetCurrentMacroName());
00019    dir.ReplaceAll("fit1.C","");
00020    dir.ReplaceAll("/./","/");
00021    TFile *fill = TFile::Open("fillrandom.root");
00022    if (!fill) {
00023       gROOT->ProcessLine(Form(".x %s../hist/fillrandom.C",dir.Data()));
00024       fill = TFile::Open("fillrandom.root");
00025       if (!fill) return;
00026    }
00027       
00028    //
00029    // The function "ls()" lists the directory contents of this file
00030    //
00031    fill->ls();
00032 
00033    //
00034    // Get object "sqroot" from the file. Undefined objects are searched
00035    // for using gROOT->FindObject("xxx"), e.g.:
00036    // TF1 *sqroot = (TF1*) gROOT.FindObject("sqroot")
00037    //
00038    sqroot->Print();
00039 
00040    //
00041    // Now fit histogram h1f with the function sqroot
00042    //
00043    h1f->SetFillColor(45);
00044    h1f->Fit("sqroot");
00045 
00046    // We now annotate the picture by creating a PaveText object
00047    // and displaying the list of commands in this macro
00048    //
00049    fitlabel = new TPaveText(0.6,0.3,0.9,0.80,"NDC");
00050    fitlabel->SetTextAlign(12);
00051    fitlabel->SetFillColor(42);
00052    fitlabel->ReadFile(Form("%sfit1_C.C",dir.Data()));
00053    fitlabel->Draw();
00054    c1->Update();
00055    gBenchmark->Show("fit1");
00056 }

Generated on Tue Jul 5 15:44:06 2011 for ROOT_528-00b_version by  doxygen 1.5.1