ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
fitExclude.C
Go to the documentation of this file.
1 // Illustrate how to fit excluding points in a given range
2 // Author: Rene Brun
3 #include "TH1.h"
4 #include "TF1.h"
5 #include "TList.h"
6 
9 {
10  if (reject && x[0] > 2.5 && x[0] < 3.5) {
12  return 0;
13  }
14  return par[0] + par[1]*x[0];
15 }
16 
17 void fitExclude() {
18  //Create a source function
19  TF1 *f1 = new TF1("f1","[0] +[1]*x +gaus(2)",0,5);
20  f1->SetParameters(6,-1,5,3,0.2);
21  // create and fill histogram according to the source function
22  TH1F *h = new TH1F("h","background + signal",100,0,5);
23  h->FillRandom("f1",2000);
24  TF1 *fl = new TF1("fl",fline,0,5,2);
25  fl->SetParameters(2,-1);
26  //fit only the linear background excluding the signal area
27  reject = kTRUE;
28  h->Fit(fl,"0");
29  reject = kFALSE;
30  //store 2 separate functions for visualization
31  TF1 *fleft = new TF1("fleft",fline,0,2.5,2);
32  fleft->SetParameters(fl->GetParameters());
33  h->GetListOfFunctions()->Add(fleft);
34  gROOT->GetListOfFunctions()->Remove(fleft);
35  TF1 *fright = new TF1("fright",fline,3.5,5,2);
36  fright->SetParameters(fl->GetParameters());
37  h->GetListOfFunctions()->Add(fright);
38  gROOT->GetListOfFunctions()->Remove(fright);
39  h->Draw();
40 }
41 
double par[1]
Definition: unuranDistr.cxx:38
TList * GetListOfFunctions() const
Definition: TH1.h:244
virtual void SetParameters(const Double_t *params)
Definition: TF1.h:432
TH1 * h
Definition: legend2.C:5
#define gROOT
Definition: TROOT.h:344
1-D histogram with a float per channel (see TH1 documentation)}
Definition: TH1.h:570
bool Bool_t
Definition: RtypesCore.h:59
const Bool_t kFALSE
Definition: Rtypes.h:92
Double_t x[n]
Definition: legend1.C:17
void fitExclude()
Definition: fitExclude.C:17
virtual void FillRandom(const char *fname, Int_t ntimes=5000)
Fill histogram following distribution in function fname.
Definition: TH1.cxx:3330
virtual void Draw(Option_t *option="")
Draw this histogram with options.
Definition: TH1.cxx:2878
static void RejectPoint(Bool_t reject=kTRUE)
Static function to set the global flag to reject points the fgRejectPoint global flag is tested by al...
Definition: TF1.cxx:3367
double Double_t
Definition: RtypesCore.h:55
Double_t fline(Double_t *x, Double_t *par)
Definition: fitExclude.C:8
virtual Double_t * GetParameters() const
Definition: TF1.h:358
virtual void Add(TObject *obj)
Definition: TList.h:81
1-Dim function class
Definition: TF1.h:149
TF1 * f1
Definition: legend1.C:11
const Bool_t kTRUE
Definition: Rtypes.h:91
Bool_t reject
Definition: fitExclude.C:7
virtual TFitResultPtr Fit(const char *formula, Option_t *option="", Option_t *goption="", Double_t xmin=0, Double_t xmax=0)
Fit histogram with function fname.
Definition: TH1.cxx:3607