00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00012
00013 #include "Riostream.h"
00014 #include "TSystem.h"
00015 #include "TStyle.h"
00016 #include "TCanvas.h"
00017 #include "TH1F.h"
00018 #include "TRandom.h"
00019 #include "TThread.h"
00020
00021 #include "TFndFitter.h"
00022
00023 #include "HistogramCreators.C"
00024
00025
00026 void TestTFndFitter(){
00027 gStyle->SetOptStat(1001111);
00028
00029
00030 Int_t n_simul_peaks=7;
00031 Double_t simul_sigma=0.01;
00032 Double_t sig_noise_ratio=2.;
00033
00034 Bool_t eval_background = kTRUE;
00035 Int_t n_iter_background = 50;
00036 Double_t resolution_factor = 1.5;
00037
00038
00039 Int_t n_max_expected_peaks = 10;
00040 Double_t expected_sigma = 0.015;
00041 Double_t sigma_maxerr=0.005;
00042 Double_t peaks_threshold = 0.3;
00043
00044 TH1F *start_his = BuildExampleHistogram(n_simul_peaks,simul_sigma,sig_noise_ratio,kTRUE);
00045
00046
00047
00048
00049
00050
00051 TH1F *fBckHis = 0;
00052 if(eval_background) fBckHis = EvalBackground(start_his,n_max_expected_peaks,n_iter_background);
00053
00054
00055 TSpectrum *spec = FindPeaks(start_his,n_max_expected_peaks,expected_sigma,peaks_threshold,resolution_factor,"");
00056 UpdateDisplay(start_his,fBckHis);
00057 PrintFoundPeaks(spec);
00058
00059
00060
00061 TH1F *clean_his = (TH1F*)(start_his->Clone("CloneHis") );
00062 clean_his->SetTitle("Clean histogram (simple clone)");
00063 if(fBckHis){
00064 Printf("Now evaluating clean histogram (subtracting background)...");
00065 clean_his->SetName("CleanHis");
00066 clean_his->SetTitle("Clean histogram");
00067 clean_his->Add(fBckHis,-1);
00068 Printf("...clean histogram evaluated");
00069 }
00070
00071
00072
00073 spec = FindPeaks(clean_his,n_max_expected_peaks,expected_sigma,peaks_threshold,resolution_factor,"");
00074 UpdateDisplay(start_his,fBckHis,clean_his);
00075
00076 TFndFitter *fndfit = new TFndFitter();
00077 fndfit->SetCurrentHistogram(clean_his);
00078 fndfit->SetCurrentSpectrum(spec);
00079 fndfit->SetResolutionFactor(resolution_factor);
00080
00081 fndfit->FitAllPeaks_GausYield(expected_sigma,sigma_maxerr);
00082
00083 fndfit->PrintFittedPeaks_GausYield();
00084 Printf("...peaks fit completed... :)");
00085
00086
00087 TF1 *foundpeak = fndfit->LocateFittedPeak_GausYield(0.4,0.6);
00088
00089 Printf("Peak found: %s",foundpeak->GetName());
00090 }