ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
fitslicesy.C
Go to the documentation of this file.
1 void fitslicesy() {
2 //
3 // Illustrates how to use the TH1::FitSlicesY function
4 // To see the output of this macro, click begin_html <a href="gif/fitslicesy.gif" >here</a> end_html
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 //Author: Rene Brun
11 
12 // Change some default parameters in the current style
13  gStyle->SetLabelSize(0.06,"x");
14  gStyle->SetLabelSize(0.06,"y");
16  gStyle->SetTitleW(0.6);
17  gStyle->SetTitleH(0.1);
18 
19 // Connect the input file and get the 2-d histogram in memory
20  TString dir = gSystem->UnixPathName(__FILE__);
21  dir.ReplaceAll("fitslicesy.C","../hsimple.C");
22  dir.ReplaceAll("/./","/");
23  if (!gInterpreter->IsLoaded(dir.Data())) gInterpreter->LoadMacro(dir.Data());
24  TFile *hsimple = (TFile*)gROOT->ProcessLineFast("hsimple(1)");
25  if (!hsimple) return;
26  TH2F *hpxpy = (TH2F*)hsimple->Get("hpxpy");
27 
28 // Create a canvas and divide it
29  TCanvas *c1 = new TCanvas("c1","c1",700,500);
30  c1->SetFillColor(42);
31  c1->Divide(2,1);
32  TPad *left = (TPad*)c1->cd(1);;
33  left->Divide(1,2);
34 
35 // Draw 2-d original histogram
36  left->cd(1);
37  gPad->SetTopMargin(0.12);
38  gPad->SetFillColor(33);
39  hpxpy->Draw();
40  hpxpy->GetXaxis()->SetLabelSize(0.06);
41  hpxpy->GetYaxis()->SetLabelSize(0.06);
42  hpxpy->SetMarkerColor(kYellow);
43 
44 // Fit slices projected along Y fron bins in X [7,32] with more than 20 bins in Y filled
45  hpxpy->FitSlicesY(0,7,32,20);
46 
47 // Show fitted "mean" for each slice
48  left->cd(2);
49  gPad->SetFillColor(33);
50  TH2F *hpxpy_0 = (TH2F*)hsimple->Get("hpxpy_0");
51  hpxpy_0->Draw();
52  TPad *right = (TPad*)c1->cd(2);
53  right->Divide(1,2);
54  right->cd(1);
55  gPad->SetTopMargin(0.12);
56  gPad->SetLeftMargin(0.15);
57  gPad->SetFillColor(33);
58  TH2F *hpxpy_1 = (TH2F*)hsimple->Get("hpxpy_1");
59  hpxpy_1->Draw();
60 
61 // Show fitted "sigma" for each slice
62  right->cd(2);
63  gPad->SetTopMargin(0.12);
64  gPad->SetLeftMargin(0.15);
65  gPad->SetFillColor(33);
66  TH2F *hpxpy_2 = (TH2F*)hsimple->Get("hpxpy_2");
67  hpxpy_2->SetMinimum(0.8);
68  hpxpy_2->Draw();
69 
70 //attributes
71  hpxpy_0->SetLineColor(5);
72  hpxpy_1->SetLineColor(5);
73  hpxpy_2->SetLineColor(5);
74  hpxpy_0->SetMarkerColor(2);
75  hpxpy_1->SetMarkerColor(2);
76  hpxpy_2->SetMarkerColor(2);
77  hpxpy_0->SetMarkerStyle(21);
78  hpxpy_1->SetMarkerStyle(21);
79  hpxpy_2->SetMarkerStyle(21);
80  hpxpy_0->SetMarkerSize(0.6);
81  hpxpy_1->SetMarkerSize(0.6);
82  hpxpy_2->SetMarkerSize(0.6);
83 }
TCanvas * c1
Definition: legend1.C:2
TString & ReplaceAll(const TString &s1, const TString &s2)
Definition: TString.h:635
void SetTitleW(Float_t w=0)
Definition: TStyle.h:409
R__EXTERN TStyle * gStyle
Definition: TStyle.h:423
void fitslicesy()
Definition: fitslicesy.C:1
TH2F * hpxpy
Definition: hcons.C:33
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format...
Definition: TFile.h:45
TVirtualPad * cd(Int_t subpadnumber=0)
Set current canvas & pad.
Definition: TCanvas.cxx:659
virtual TObject * Get(const char *namecycle)
Return pointer to object identified by namecycle.
virtual void SetMinimum(Double_t minimum=-1111)
Definition: TH1.h:395
#define gROOT
Definition: TROOT.h:344
Basic string class.
Definition: TString.h:137
#define gInterpreter
Definition: TInterpreter.h:502
Definition: Rtypes.h:61
virtual const char * UnixPathName(const char *unixpathname)
Convert from a Unix pathname to a local pathname.
Definition: TSystem.cxx:1020
const char * Data() const
Definition: TString.h:349
TVirtualPad * cd(Int_t subpadnumber=0)
Set Current pad.
Definition: TPad.cxx:514
void SetFrameFillColor(Color_t color=1)
Definition: TStyle.h:367
virtual void SetMarkerColor(Color_t mcolor=1)
Definition: TAttMarker.h:51
virtual void SetLineColor(Color_t lcolor)
Definition: TAttLine.h:54
R__EXTERN TSystem * gSystem
Definition: TSystem.h:545
virtual void Draw(Option_t *option="")
Draw this histogram with options.
Definition: TH1.cxx:2878
virtual void SetFillColor(Color_t fcolor)
Definition: TAttFill.h:50
2-D histogram with a float per channel (see TH1 documentation)}
Definition: TH2.h:256
The most important graphics class in the ROOT system.
Definition: TPad.h:46
virtual void SetMarkerStyle(Style_t mstyle=1)
Definition: TAttMarker.h:53
TAxis * GetYaxis()
Definition: TH1.h:320
void SetTitleH(Float_t h=0)
Definition: TStyle.h:410
virtual void SetLabelSize(Float_t size=0.04)
Set size of axis labels The size is expressed in per cent of the pad width.
Definition: TAttAxis.cxx:187
virtual void SetMarkerSize(Size_t msize=1)
Definition: TAttMarker.h:54
The Canvas class.
Definition: TCanvas.h:48
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:956
void dir(char *path=0)
Definition: rootalias.C:30
void SetLabelSize(Float_t size=0.04, Option_t *axis="X")
Set size of axis labels.
Definition: TStyle.cxx:1063
TFile * hsimple(Int_t get=0)
Definition: hsimple.C:13
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:1073
#define gPad
Definition: TVirtualPad.h:288
TAxis * GetXaxis()
Definition: TH1.h:319