Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
fitslicesy.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_fit
3/// \notebook -js
4/// Illustrates how to use the TH1::FitSlicesY function
5/// It uses the TH2F histogram generated in macro hsimple.C
6/// It invokes FitSlicesY and draw the fitted "mean" and "sigma"
7/// in 2 sepate pads.
8/// This macro shows also how to annotate a picture, change
9/// some pad parameters.
10///
11/// \macro_image
12/// \macro_output
13/// \macro_code
14///
15/// \author Rene Brun
16
17void fitslicesy() {
18// Change some default parameters in the current style
19 gStyle->SetLabelSize(0.06,"x");
20 gStyle->SetLabelSize(0.06,"y");
22 gStyle->SetTitleW(0.6);
23 gStyle->SetTitleH(0.1);
24
25// Connect the input file and get the 2-d histogram in memory
26 TString dir = gROOT->GetTutorialDir();
27 dir.Append("/hsimple.C");
28 dir.ReplaceAll("/./","/");
29 if (!gInterpreter->IsLoaded(dir.Data())) gInterpreter->LoadMacro(dir.Data());
30 TFile *hsimpleFile = (TFile*)gROOT->ProcessLineFast("hsimple(1)");
31 if (!hsimpleFile) return;
32 TH2F *hpxpy = (TH2F*)hsimpleFile->Get("hpxpy");
33
34// Create a canvas and divide it
35 TCanvas *c1 = new TCanvas("c1","c1",700,500);
36 c1->SetFillColor(42);
37 c1->Divide(2,1);
38 TPad *leftPad = (TPad*)c1->cd(1);;
39 leftPad->Divide(1,2);
40
41// Draw 2-d original histogram
42 leftPad->cd(1);
43 gPad->SetTopMargin(0.12);
44 gPad->SetFillColor(33);
45 hpxpy->Draw();
46 hpxpy->GetXaxis()->SetLabelSize(0.06);
47 hpxpy->GetYaxis()->SetLabelSize(0.06);
48 hpxpy->SetMarkerColor(kYellow);
49
50// Fit slices projected along Y fron bins in X [7,32] with more than 20 bins in Y filled
51 hpxpy->FitSlicesY(0,7,32,20);
52
53// Show fitted "mean" for each slice
54 leftPad->cd(2);
55 gPad->SetFillColor(33);
56 TH2F *hpxpy_0 = (TH2F*)hsimpleFile->Get("hpxpy_0");
57 hpxpy_0->Draw();
58 TPad *rightPad = (TPad*)c1->cd(2);
59 rightPad->Divide(1,2);
60 rightPad->cd(1);
61 gPad->SetTopMargin(0.12);
62 gPad->SetLeftMargin(0.15);
63 gPad->SetFillColor(33);
64 TH2F *hpxpy_1 = (TH2F*)hsimpleFile->Get("hpxpy_1");
65 hpxpy_1->Draw();
66
67// Show fitted "sigma" for each slice
68 rightPad->cd(2);
69 gPad->SetTopMargin(0.12);
70 gPad->SetLeftMargin(0.15);
71 gPad->SetFillColor(33);
72 TH2F *hpxpy_2 = (TH2F*)hsimpleFile->Get("hpxpy_2");
73 hpxpy_2->SetMinimum(0.8);
74 hpxpy_2->Draw();
75
76//attributes
77 hpxpy_0->SetLineColor(5);
78 hpxpy_1->SetLineColor(5);
79 hpxpy_2->SetLineColor(5);
80 hpxpy_0->SetMarkerColor(2);
81 hpxpy_1->SetMarkerColor(2);
82 hpxpy_2->SetMarkerColor(2);
83 hpxpy_0->SetMarkerStyle(21);
84 hpxpy_1->SetMarkerStyle(21);
85 hpxpy_2->SetMarkerStyle(21);
86 hpxpy_0->SetMarkerSize(0.6);
87 hpxpy_1->SetMarkerSize(0.6);
88 hpxpy_2->SetMarkerSize(0.6);
89}
@ kYellow
Definition Rtypes.h:66
#define gInterpreter
#define gROOT
Definition TROOT.h:404
R__EXTERN TStyle * gStyle
Definition TStyle.h:413
#define gPad
virtual void SetLabelSize(Float_t size=0.04)
Set size of axis labels.
Definition TAttAxis.cxx:205
virtual void SetFillColor(Color_t fcolor)
Set the fill area color.
Definition TAttFill.h:37
virtual void SetLineColor(Color_t lcolor)
Set the line color.
Definition TAttLine.h:40
virtual void SetMarkerColor(Color_t mcolor=1)
Set the marker color.
Definition TAttMarker.h:38
virtual void SetMarkerStyle(Style_t mstyle=1)
Set the marker style.
Definition TAttMarker.h:40
virtual void SetMarkerSize(Size_t msize=1)
Set the marker size.
Definition TAttMarker.h:41
virtual void SetTopMargin(Float_t topmargin)
Set Pad top margin in fraction of the pad height.
Definition TAttPad.cxx:129
The Canvas class.
Definition TCanvas.h:23
TObject * Get(const char *namecycle) override
Return pointer to object identified by namecycle.
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format.
Definition TFile.h:54
TAxis * GetXaxis()
Get the behaviour adopted by the object about the statoverflows. See EStatOverflows for more informat...
Definition TH1.h:320
TAxis * GetYaxis()
Definition TH1.h:321
virtual void SetMinimum(Double_t minimum=-1111)
Definition TH1.h:399
virtual void Draw(Option_t *option="")
Draw this histogram with options.
Definition TH1.cxx:3074
2-D histogram with a float per channel (see TH1 documentation)}
Definition TH2.h:251
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:1044
The most important graphics class in the ROOT system.
Definition TPad.h:26
void Divide(Int_t nx=1, Int_t ny=1, Float_t xmargin=0.01, Float_t ymargin=0.01, Int_t color=0) override
Automatic pad generation by division.
Definition TPad.cxx:1178
TVirtualPad * cd(Int_t subpadnumber=0) override
Set Current pad.
Definition TPad.cxx:604
Basic string class.
Definition TString.h:136
const char * Data() const
Definition TString.h:369
TString & ReplaceAll(const TString &s1, const TString &s2)
Definition TString.h:692
TString & Append(const char *cs)
Definition TString.h:564
void SetFrameFillColor(Color_t color=1)
Definition TStyle.h:355
void SetTitleW(Float_t w=0)
Definition TStyle.h:398
void SetTitleH(Float_t h=0)
Definition TStyle.h:399
void SetLabelSize(Float_t size=0.04, Option_t *axis="X")
Set size of axis labels.
Definition TStyle.cxx:1392
return c1
Definition legend1.C:41