Dear Rooters,
I’m trying to search the peak positions in a spectrum with TSpectrum::Search() and would like to sort the array obtained from TSpectrum::GetPositionX() with TMath::Sort, but when I look at the index obtained with Sort, they make no sense. I’ve found an example here of sorting an array that works fine for me :
float a[8]={2, 1, 5, 4,7,15, 12, 9};
long long size = 8;
long long ind[8];
TMath::Sort(size,a,ind,kFALSE);
for (int k = 0; k < size; ++k)
std::cout <<a[k]<< " INDEX "<< ind[k] << std::endl;
but my code doesn’t at all.
Here is the code:
[code]{
TH1F*h; //I get the histo from a root file
int npeaks = 8;
float sigma = 3;
float threshold = 0.01;
TSpectrum *s = new TSpectrum(npeaks);
Int_t nfound = s->Search(h, sigma, “”,threshold);
const Float_t *mean = s->GetPositionX();
long long sizes = nfound;
long long inds[nfound];
for(int k=0; k<nfound; k++) inds[k] = 0;
TMath::Sort(sizes,mean,inds,kFALSE);
for(int j=0; j<nfound; j++)
cout<<mean[j]<<" index "<<inds[j]<<endl;
}
[/code]
and here is the output:
385 index 2
947 index 0
177 index 5
3631 index 1
2043 index 4
695 index 6
2511 index 7
2883 index 3
I naively (??) expect the index to increase from the smallest to the biggest value of the mean[i] array.
Where am I wrong? Can anyone help please?
Thank you, cheers
Paola