Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
fitExclude.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_fit
3/// \notebook -js
4/// Illustrates how to fit excluding points in a given range.
5///
6/// \macro_image
7/// \macro_output
8/// \macro_code
9///
10/// \author Rene Brun
11
12#include <TH1.h>
13#include <TF1.h>
14#include <TROOT.h>
15
16bool reject;
17double fline(double *x, double *par)
18{
19 if (reject && x[0] > 2.5 && x[0] < 3.5) {
21 return 0;
22 }
23 return par[0] + par[1]*x[0];
24}
25
26void fitExclude() {
27 //Create a source function
28 TF1 *f1 = new TF1("f1","[0] +[1]*x +gaus(2)",0,5);
29 f1->SetParameters(6,-1,5,3,0.2);
30 // create and fill histogram according to the source function
31 TH1F *h = new TH1F("h","background + signal",100,0,5);
32 h->FillRandom("f1",2000);
33 TF1 *fl = new TF1("fl",fline,0,5,2);
34 fl->SetParameters(2,-1);
35 //fit only the linear background excluding the signal area
36 reject = true;
37 h->Fit(fl,"0");
38 reject = false;
39 //store 2 separate functions for visualization
40 TF1 *fleft = new TF1("fleft",fline,0,2.5,2);
41 fleft->SetParameters(fl->GetParameters());
42 h->GetListOfFunctions()->Add(fleft);
43 gROOT->GetListOfFunctions()->Remove(fleft);
44 TF1 *fright = new TF1("fright",fline,3.5,5,2);
45 fright->SetParameters(fl->GetParameters());
46 h->GetListOfFunctions()->Add(fright);
47 gROOT->GetListOfFunctions()->Remove(fright);
48 h->Draw();
49}
50
#define h(i)
Definition RSha256.hxx:106
#define gROOT
Definition TROOT.h:407
1-Dim function class
Definition TF1.h:233
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:3683
virtual Double_t * GetParameters() const
Definition TF1.h:548
virtual void SetParameters(const Double_t *params)
Definition TF1.h:672
1-D histogram with a float per channel (see TH1 documentation)
Definition TH1.h:622
Double_t x[n]
Definition legend1.C:17
TF1 * f1
Definition legend1.C:11