TSpectrum2 problem


I have a problem involving SearchHighRes method from TSpectrum2 class. First I tried to do ordinary Search

TSpectrum2* s= new TSpectrum2(20,1);
Int_t val=s->Search(histo,3.,"",0.2);

It worked fine, but when I tried to do

   biny=(ymax- ymin)/nbinsy;
   cout<<"positions acquired"<<endl;
   //initial values
   for(Int_t i=0;i<n;i++){
TSpectrum2Fit *pfit=new TSpectrum2Fit(n);
pfit->SetFitParameters(xmin, xmax-1,ymin, ymax-1, 1000, 0.1, pfit->kFitOptimChiCounts,pfit->kFitAlphaHalving,pfit->kFitPower2,pfit->kFitTaylorOrderFirst);
     pfit->SetPeakParameters(2, kFALSE,2 , kFALSE, 0, kTRUE, PosX, (Bool_t *) FixPosX, PosY, (Bool_t *) FixPosY, PosX, (Bool_t *) FixPosX, PosY, (Bool_t *) FixPosY, Amp, (Bool_t *) FixAmp, AmpXY, (Bool_t *) FixAmp, AmpXY, (Bool_t *) FixAmp); 
     cout<<"fit parameters set!"<<endl;

, I got segmentation fault, right at the point of fitting! Despite the fact that I already used a lot of tutorial program from reference guide, I simply copied it this time completely, now involving SearchHighRes method. Of course, it was taken care of proper binning and ranges for input histogram. Now the situation was even worse. The program gave me peak positions out of the proper range of histogram! Then I tried to assume these are the relative positions above the xmin and ymin of histogram, but calculated amplitudes were then zero. I’m not sure why this is happening, why program crashes in first case, and why it behaves strangely in second case. I will be very thankful for any help.
Here’s also the source with ordinary search attached.
peak_fitter2D.cpp (3.06 KB)

Here’s also the source with High resolution fitting.


tutor.C (2.98 KB)

I figured out that positions of peaks are retrieved for high resolution search as bin numbers and not as actual positions…but it still does not work :cry: ROOT on my laptop says there is C++ exception.

Could you post the shortest possible RUNNING script (including necessary data files) reproducing your problem?


Here is the root file with histogram and a script. When I do

.L tutor1.C tutor1()
it comes to exception. The same happens with

.x tutor1.C

I’m not sure if the script can be made any shorter. Everything inside it has to do with searching and fitting. As I said, I basically used tutorial program from reference guide on TSpectrum2Fit. My ROOT version is 5.20.00.
histo.root (19.5 KB)
tutor1.C (3.13 KB)

I do not understand your remark about PosX and PosY. These arrays are the x and y positions of the peaks, not the peak numbers.


I meant that right amplitudes were obtained by

as index numbers of the source matrix, and not as


as I thought before.
but to obtain the positions of peaks in range of the histogram (for x from 1000 to 5000) , PosX must be then modified

xbin=1+(int)(PosX[i]+0.5); PosX[i]=search->GetXaxis()->GetBinCenter(xbin);
That was the only way I got reasonable results printed on screen, and I think that way positions were returned in the code of Search() method.