fillrandom.C

Go to the documentation of this file.
00001 void fillrandom() {
00002    //Fill a 1-D histogram from a parametric function
00003    // To see the output of this macro, click begin_html <a href="gif/fillrandom.gif">here</a>. end_html
00004    //Author: Rene Brun
00005    
00006    TCanvas *c1 = new TCanvas("c1","The FillRandom example",200,10,700,900);
00007    c1->SetFillColor(18);
00008 
00009    pad1 = new TPad("pad1","The pad with the function",0.05,0.50,0.95,0.95,21);
00010    pad2 = new TPad("pad2","The pad with the histogram",0.05,0.05,0.95,0.45,21);
00011    pad1->Draw();
00012    pad2->Draw();
00013    pad1->cd();
00014 
00015    gBenchmark->Start("fillrandom");
00016    //
00017    // A function (any dimension) or a formula may reference
00018    // an already defined formula
00019    //
00020    form1 = new TFormula("form1","abs(sin(x)/x)");
00021    sqroot = new TF1("sqroot","x*gaus(0) + [3]*form1",0,10);
00022    sqroot->SetParameters(10,4,1,20);
00023    pad1->SetGridx();
00024    pad1->SetGridy();
00025    pad1->GetFrame()->SetFillColor(42);
00026    pad1->GetFrame()->SetBorderMode(-1);
00027    pad1->GetFrame()->SetBorderSize(5);
00028    sqroot->SetLineColor(4);
00029    sqroot->SetLineWidth(6);
00030    sqroot->Draw();
00031    lfunction = new TPaveLabel(5,39,9.8,46,"The sqroot function");
00032    lfunction->SetFillColor(41);
00033    lfunction->Draw();
00034    c1->Update();
00035 
00036    //
00037    // Create a one dimensional histogram (one float per bin)
00038    // and fill it following the distribution in function sqroot.
00039    //
00040    pad2->cd();
00041    pad2->GetFrame()->SetFillColor(42);
00042    pad2->GetFrame()->SetBorderMode(-1);
00043    pad2->GetFrame()->SetBorderSize(5);
00044    h1f = new TH1F("h1f","Test random numbers",200,0,10);
00045    h1f->SetFillColor(45);
00046    h1f->FillRandom("sqroot",10000);
00047    h1f->Draw();
00048    c1->Update();
00049    //
00050    // Open a ROOT file and save the formula, function and histogram
00051    //
00052    TFile myfile("fillrandom.root","RECREATE");
00053    form1->Write();
00054    sqroot->Write();
00055    h1f->Write();
00056    gBenchmark->Show("fillrandom");
00057 }

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