test/TestTFndFitter.C

00001 
00002 //                                             //
00003 // This macro is an example for using the      //
00004 //  most important facilities provided by the  //
00005 //  FIN_AN namespace:                          //
00006 //    (see $FROOTSYS/ANALYSIS/FIN_AN.h)        //
00007 //                                             //
00008 // Peak fitting is supported by TFndFitter     //
00009 //    (see $FROOTSYS/ANALYSIS/TFndFitter.h)    //
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   // --- peaks simulation
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   // --- peaks evaluation
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   //  TH1F *start_his = new TH1F("starthis","starthis",3000,0,1);
00047   //   for(Int_t i=0;i<20000;i++)  start_his->Fill(gRandom->Gaus(.5,.02) );
00048   
00049   
00050   // --- evaluate background
00051   TH1F *fBckHis = 0;
00052   if(eval_background) fBckHis = EvalBackground(start_his,n_max_expected_peaks,n_iter_background);
00053 
00054   // --- check peaks before subtracting background
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   // --- subtract background (if required)
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   // --- check peaks after subtracting background
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   //  fndfit->FitSinglePeak_GausYield(2,expected_sigma,sigma_maxerr);
00083   fndfit->PrintFittedPeaks_GausYield();
00084   Printf("...peaks fit completed... :)");
00085 
00086   // --- now find a specific peak and get information:
00087   TF1 *foundpeak = fndfit->LocateFittedPeak_GausYield(0.4,0.6);
00088 
00089   Printf("Peak found: %s",foundpeak->GetName());
00090 }

Generated on Tue Oct 16 15:40:48 2007 by  doxygen 1.5.2