Re: TSpectrum: question

From: Boris Skorodumov <bskorodo_at_nd.edu>
Date: Thu, 27 Jan 2005 21:19:14 -0500


Thank you, Rene,

I made cvs update, now no problems with TSpectrum.

But one think left to be understood(for myself). When I made actual fit, the position of fitted peaks quite different from real peaks. As a starting points for the fit I took simply values found by TSpectrum(in the case of gaus, this is just Max, center and sigma). I attached to this letter code itself + test.root file. ALso, i see three additional peaks that basicly "grow up from nothing".

And last think that I noticed with converting cancas to eps format. If you will try to save it from menu, just "Save" c1.eps, the picture in the first pad was automaticly redrawn with the fitted function (please, see c1.eps in attachment). As a result, i have two pads with the same pictures, but i was expected to have first pad with just experimental graph, and the second pad with fit.
My root version is 4.03/01.

Thank you again,
Boris.


| Boris Skorodumov, Graduate Student |
| Physics Department                 |
| University of Notre Dame           |
| Indiana 46556, USA                 |
| WWW:   http://www.nd.edu/~bskorodo |
--------------------------------------




Rene BRUN wrote:

> Hi Boris,
>
> The current version of TSpectrum::Search looks for peaks in the full
> histogram range. In your case teh first bin of your histogram is
> around 650000 while the other visible peaks are around 100.
> With your version of ROOT simply call h1->SetBinContent(1,0)
> and Search will find the 6 peaks.
>
> In the CVS version, I have added support for a bin range such that you
> do not need the SetBinContent(1,0).
>
> Rene Brun
>
> Boris Skorodumov wrote:
>
>> Dear rooters,
>>
>> I was trying to change example program peaks.C to force it working
>> with real spectrum (for example, detector calbration, Gaus fitter
>> should work with it). I was trying to use the next procedure to find
>> peaks:
>> .....
>> TSpectrum *s = new TSpectrum(npeaks);
>> Int_t nfound = s->Search(h2,1,"");
>> printf("Found %d candidate peaks to fit\n",nfound);
>> .....
>> but i always getting 0. to tell you the truth, i do not know what the
>> problem, maybe with resolutions of the peaks, maybe with sigma
>> settings, maybe something more.
>>
>> I attached source file and test.root with test histogram.
>> Thank you for the help,
>> Boris.
>>
>>
>> ------------------------------------------------------------------------
>>
>> #include "TCanvas.h"
>> #include "TH1.h"
>> #include "TF1.h"
>> #include "TRandom.h"
>> #include "TSpectrum.h"
>> #include "TVirtualFitter.h"
>> Int_t npeaks = 30;
>>
>> Double_t fpeaks(Double_t *x, Double_t *par) {
>> // Double_t result = par[0] + par[1]*x[0];
>> Double_t result =0.0;
>> for (Int_t p=0;p<npeaks;p++) {
>> Double_t norm = par[3*p];
>> Double_t mean = par[3*p+1];
>> Double_t sigma = par[3*p+2];
>> result += norm*TMath::Gaus(x[0],mean,sigma);
>> }
>> return result;
>> }
>>
>>
>> void d1_fit(Int_t np=10) {
>>
>> npeaks = np;
>> Double_t par[3000];
>> TFile *hfile = gROOT->FindObject("test.root"); if (hfile)
>> hfile->Close();
>> hfile = new TFile("test.root","READ","Test Calibration");
>> TCanvas *c1 = new TCanvas("c1","c1",10,10,700,700);
>> c1->Divide(1,2);
>> c1->cd(1);
>> h1->GetXaxis()->SetRange(50,500);
>> h1->Draw(); // TH1F *h = new TH1F("h","test",1000,0,2000);
>> TH1F *h2 = (TH1F*)h1->Clone("h2");
>>
>> // cout << npeaks; TSpectrum *s = new TSpectrum(npeaks);
>> // s->SetResolution(0.1);
>> Int_t nfound = s->Search(h2,1,"");
>> printf("Found %d candidate peaks to fit\n",nfound);
>> npeaks = nfound;
>> c1->Update();
>> c1->cd(2);
>> printf("Now fitting: Be patient\n");
>> TF1 *fit = new TF1("fit",fpeaks,0,2000,3*npeaks);
>> TVirtualFitter::Fitter(h2,10+3*npeaks); fit->SetParameters(par);
>> fit->SetNpx(2000);
>> h2->Fit("fit"); }
>> // t->Draw()
>> // TH1F *h1 = new TH1F("h1","h1 title",2000,0,2000);("epsd >> h1");
>> // h1->GetXaxis()->SetRange(50,500) ; h1->Draw();
>
>

Received on Fri Jan 28 2005 - 03:19:25 MET

This archive was generated by hypermail 2.2.0 : Tue Jan 02 2007 - 14:45:04 MET