Logo ROOT  
Reference Guide
fitslicesy.C File Reference

Detailed Description

View in nbviewer Open in SWAN Illustrates how to use the TH1::FitSlicesY function It uses the TH2F histogram generated in macro hsimple.C It invokes FitSlicesY and draw the fitted "mean" and "sigma" in 2 sepate pads. This macro shows also how to annotate a picture, change some pad parameters.

void fitslicesy() {
// Change some default parameters in the current style
gStyle->SetLabelSize(0.06,"x");
gStyle->SetLabelSize(0.06,"y");
// Connect the input file and get the 2-d histogram in memory
TString dir = gROOT->GetTutorialDir();
dir.Append("/hsimple.C");
dir.ReplaceAll("/./","/");
if (!gInterpreter->IsLoaded(dir.Data())) gInterpreter->LoadMacro(dir.Data());
TFile *hsimpleFile = (TFile*)gROOT->ProcessLineFast("hsimple(1)");
if (!hsimpleFile) return;
TH2F *hpxpy = (TH2F*)hsimpleFile->Get("hpxpy");
// Create a canvas and divide it
TCanvas *c1 = new TCanvas("c1","c1",700,500);
c1->SetFillColor(42);
c1->Divide(2,1);
TPad *leftPad = (TPad*)c1->cd(1);;
leftPad->Divide(1,2);
// Draw 2-d original histogram
leftPad->cd(1);
gPad->SetTopMargin(0.12);
gPad->SetFillColor(33);
hpxpy->Draw();
hpxpy->GetXaxis()->SetLabelSize(0.06);
hpxpy->GetYaxis()->SetLabelSize(0.06);
hpxpy->SetMarkerColor(kYellow);
// Fit slices projected along Y fron bins in X [7,32] with more than 20 bins in Y filled
hpxpy->FitSlicesY(0,7,32,20);
// Show fitted "mean" for each slice
leftPad->cd(2);
gPad->SetFillColor(33);
TH2F *hpxpy_0 = (TH2F*)hsimpleFile->Get("hpxpy_0");
hpxpy_0->Draw();
TPad *rightPad = (TPad*)c1->cd(2);
rightPad->Divide(1,2);
rightPad->cd(1);
gPad->SetTopMargin(0.12);
gPad->SetLeftMargin(0.15);
gPad->SetFillColor(33);
TH2F *hpxpy_1 = (TH2F*)hsimpleFile->Get("hpxpy_1");
hpxpy_1->Draw();
// Show fitted "sigma" for each slice
rightPad->cd(2);
gPad->SetTopMargin(0.12);
gPad->SetLeftMargin(0.15);
gPad->SetFillColor(33);
TH2F *hpxpy_2 = (TH2F*)hsimpleFile->Get("hpxpy_2");
hpxpy_2->SetMinimum(0.8);
hpxpy_2->Draw();
//attributes
hpxpy_0->SetLineColor(5);
hpxpy_1->SetLineColor(5);
hpxpy_2->SetLineColor(5);
hpxpy_0->SetMarkerColor(2);
hpxpy_1->SetMarkerColor(2);
hpxpy_2->SetMarkerColor(2);
hpxpy_0->SetMarkerStyle(21);
hpxpy_1->SetMarkerStyle(21);
hpxpy_2->SetMarkerStyle(21);
hpxpy_0->SetMarkerSize(0.6);
hpxpy_1->SetMarkerSize(0.6);
hpxpy_2->SetMarkerSize(0.6);
}
Author
Rene Brun

Definition in file fitslicesy.C.

TStyle::SetLabelSize
void SetLabelSize(Float_t size=0.04, Option_t *axis="X")
Set size of axis labels.
Definition: TStyle.cxx:1395
TPad
Definition: TPad.h:26
TH1::SetMinimum
virtual void SetMinimum(Double_t minimum=-1111)
Definition: TH1.h:396
TH2F
2-D histogram with a float per channel (see TH1 documentation)}
Definition: TH2.h:251
TString::Data
const char * Data() const
Definition: TString.h:369
gInterpreter
#define gInterpreter
Definition: TInterpreter.h:558
TPad::Divide
virtual void Divide(Int_t nx=1, Int_t ny=1, Float_t xmargin=0.01, Float_t ymargin=0.01, Int_t color=0)
Automatic pad generation by division.
Definition: TPad.cxx:1166
TString
Definition: TString.h:136
TString::ReplaceAll
TString & ReplaceAll(const TString &s1, const TString &s2)
Definition: TString.h:692
TH2::FitSlicesY
virtual void FitSlicesY(TF1 *f1=0, Int_t firstxbin=0, Int_t lastxbin=-1, Int_t cut=0, Option_t *option="QNR", TObjArray *arr=0)
Project slices along Y in case of a 2-D histogram, then fit each slice with function f1 and make a hi...
Definition: TH2.cxx:962
TAttAxis::SetLabelSize
virtual void SetLabelSize(Float_t size=0.04)
Set size of axis labels.
Definition: TAttAxis.cxx:203
TDirectoryFile::Get
TObject * Get(const char *namecycle) override
Return pointer to object identified by namecycle.
Definition: TDirectoryFile.cxx:909
gStyle
R__EXTERN TStyle * gStyle
Definition: TStyle.h:412
TH1::GetYaxis
TAxis * GetYaxis()
Definition: TH1.h:318
TString::Append
TString & Append(const char *cs)
Definition: TString.h:564
TFile
Definition: TFile.h:54
TStyle::SetTitleW
void SetTitleW(Float_t w=0)
Definition: TStyle.h:398
TCanvas
Definition: TCanvas.h:23
TPad::cd
TVirtualPad * cd(Int_t subpadnumber=0)
Set Current pad.
Definition: TPad.cxx:594
TStyle::SetTitleH
void SetTitleH(Float_t h=0)
Definition: TStyle.h:399
gPad
#define gPad
Definition: TVirtualPad.h:287
TStyle::SetFrameFillColor
void SetFrameFillColor(Color_t color=1)
Definition: TStyle.h:355
TH1::GetXaxis
TAxis * GetXaxis()
Get the behaviour adopted by the object about the statoverflows. See EStatOverflows for more informat...
Definition: TH1.h:317
kYellow
@ kYellow
Definition: Rtypes.h:66
gROOT
#define gROOT
Definition: TROOT.h:406
TH1::Draw
virtual void Draw(Option_t *option="")
Draw this histogram with options.
Definition: TH1.cxx:2997
c1
return c1
Definition: legend1.C:41