fitExclude.C

Go to the documentation of this file.
00001 // Illustrate how to fit excluding points in a given range
00002 // Author: Rene Brun
00003 #include "TH1.h"
00004 #include "TF1.h"
00005 #include "TList.h"
00006 
00007 Bool_t reject;
00008 Double_t fline(Double_t *x, Double_t *par)
00009 {
00010     if (reject && x[0] > 2.5 && x[0] < 3.5) {
00011       TF1::RejectPoint();
00012       return 0;
00013    }
00014    return par[0] + par[1]*x[0];
00015 }
00016 
00017 void fitExclude() {
00018    //Create a source function
00019    TF1 *f1 = new TF1("f1","[0] +[1]*x +gaus(2)",0,5);
00020    f1->SetParameters(6,-1,5,3,0.2);
00021    // create and fill histogram according to the source function
00022    TH1F *h = new TH1F("h","background + signal",100,0,5);
00023    h->FillRandom("f1",2000);
00024    TF1 *fl = new TF1("fl",fline,0,5,2);
00025    fl->SetParameters(2,-1);      
00026    //fit only the linear background excluding the signal area
00027    reject = kTRUE;
00028    h->Fit(fl,"0");
00029    reject = kFALSE;
00030    //store 2 separate functions for visualization
00031    TF1 *fleft = new TF1("fleft",fline,0,2.5,2);
00032    fleft->SetParameters(fl->GetParameters());
00033    h->GetListOfFunctions()->Add(fleft);
00034    gROOT->GetListOfFunctions()->Remove(fleft);
00035    TF1 *fright = new TF1("fright",fline,3.5,5,2);
00036    fright->SetParameters(fl->GetParameters());
00037    h->GetListOfFunctions()->Add(fright);
00038    gROOT->GetListOfFunctions()->Remove(fright);
00039    h->Draw();
00040 }
00041    

Generated on Tue Jul 5 15:44:06 2011 for ROOT_528-00b_version by  doxygen 1.5.1