00001
00002
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
00019 TF1 *f1 = new TF1("f1","[0] +[1]*x +gaus(2)",0,5);
00020 f1->SetParameters(6,-1,5,3,0.2);
00021
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
00027 reject = kTRUE;
00028 h->Fit(fl,"0");
00029 reject = kFALSE;
00030
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