fitslicesy.C

Go to the documentation of this file.
00001 void fitslicesy() {
00002 //
00003 // Illustrates how to use the TH1::FitSlicesY function
00004 // To see the output of this macro, click begin_html <a href="gif/fitslicesy.gif" >here</a> end_html
00005 //    It uses the TH2F histogram generated in macro hsimple.C
00006 //    It invokes FitSlicesY and draw the fitted "mean" and "sigma"
00007 //    in 2 sepate pads.
00008 //    This macro shows also how to annotate a picture, change
00009 //    some pad parameters.
00010 //Author: Rene Brun
00011    
00012 // Change some default parameters in the current style
00013    gStyle->SetLabelSize(0.06,"x");
00014    gStyle->SetLabelSize(0.06,"y");
00015    gStyle->SetFrameFillColor(38);
00016    gStyle->SetTitleW(0.6);
00017    gStyle->SetTitleH(0.1);
00018 
00019 // Connect the input file and get the 2-d histogram in memory
00020    TString dir = gSystem->UnixPathName(gInterpreter->GetCurrentMacroName());
00021    dir.ReplaceAll("fitslicesy.C","../hsimple.C");
00022    dir.ReplaceAll("/./","/");
00023    if (!gInterpreter->IsLoaded(dir.Data())) gInterpreter->LoadMacro(dir.Data());
00024    TFile *hsimple = (TFile*)gROOT->ProcessLineFast("hsimple(1)");
00025    if (!hsimple) return;
00026    TH2F *hpxpy = (TH2F*)hsimple->Get("hpxpy");
00027 
00028 // Create a canvas and divide it
00029    TCanvas *c1 = new TCanvas("c1","c1",700,500);
00030    c1->SetFillColor(42);
00031    c1->Divide(2,1);
00032    c1->cd(1);
00033    TPad *left = (TPad*)gPad;
00034    left->Divide(1,2);
00035 
00036 // Draw 2-d original histogram
00037    left->cd(1);
00038    gPad->SetTopMargin(0.12);
00039    gPad->SetFillColor(33);
00040    hpxpy->Draw();
00041    hpxpy->GetXaxis()->SetLabelSize(0.06);
00042    hpxpy->GetYaxis()->SetLabelSize(0.06);
00043    hpxpy->SetMarkerColor(kYellow);
00044 
00045 // Fit slices projected along Y fron bins in X [7,32] with more than 20 bins  in Y filled
00046    hpxpy->FitSlicesY(0,7,32,20);
00047 
00048 // Show fitted "mean" for each slice
00049    left->cd(2);
00050    gPad->SetFillColor(33);
00051    hpxpy_0->Draw();
00052    c1->cd(2);
00053    TPad *right = (TPad*)gPad;
00054    right->Divide(1,2);
00055    right->cd(1);
00056    gPad->SetTopMargin(0.12);
00057    gPad->SetLeftMargin(0.15);
00058    gPad->SetFillColor(33);
00059    hpxpy_1->Draw();
00060 
00061 // Show fitted "sigma" for each slice
00062    right->cd(2);
00063    gPad->SetTopMargin(0.12);
00064    gPad->SetLeftMargin(0.15);
00065    gPad->SetFillColor(33);
00066    hpxpy_2->SetMinimum(0.8);
00067    hpxpy_2->Draw();
00068 
00069 //attributes
00070    hpxpy_0->SetLineColor(kYellow);
00071    hpxpy_1->SetLineColor(kYellow);
00072    hpxpy_2->SetLineColor(kYellow);
00073    hpxpy_0->SetMarkerColor(kRed);
00074    hpxpy_1->SetMarkerColor(kRed);
00075    hpxpy_2->SetMarkerColor(kRed);
00076    hpxpy_0->SetMarkerStyle(21);
00077    hpxpy_1->SetMarkerStyle(21);
00078    hpxpy_2->SetMarkerStyle(21);
00079    hpxpy_0->SetMarkerSize(0.6);
00080    hpxpy_1->SetMarkerSize(0.6);
00081    hpxpy_2->SetMarkerSize(0.6);
00082 }

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