Problems with TSpectrum

Hello everybody,
I’m having some troubles using the TSpectrum class for the search of peaks in a TH1D, within a macro ROOT.
I have two TH1D and I use the macro written by Rene Brun peaks.C with some changes about the values over the background which I’m interested in.
Anyway since I have two TH1D I put the macro inside a for(i=0;i<2;i++) loop so that I can perform the search on the two histogram, but I noticed that the search goes backward (meaning from the last bin to the first) the second time the loop is executed.

I have declared the two histograms with

TH1D *hist1/2 =new TH1D ("hist1/2","name1/2" , 384, 0, 384);

thus they have 384 bins, isn’t it?
Then I copy their content in a third histogram hist_gen, declared as the former two, with


Is anyone able two help me? I want the search going always forward (from the first bin to the last).

And by the way how can I properly delete a histogram in general???

Thanks for your help,

Could you post a file containing your histograms and a script showing how you call TSpectrum ?


Goodmorning mr. Brun,
Thanks for your quick answer.

I call the TSPectrum with

TH1D *h2 = (TH1D*)hist_gen2->Clone("h2");
TSpectrum *s = new TSpectrum(2*npeaks);
 int nfound=s->search(hist_gen,sigmapeak,"new,goof", heightsecondary) 

I looked into the TSpectrum class and I noticed that the search method should return the x_coordinate of peaks
like this:
first peak position = highest peak coordinate;
second peak= second highest peak coordinate;

nth peak= lowest peak coordinate;
is that true??
If it isn’t, how can I tell root to do such thing??

My problem is that when I use the Tspectrum::search on the hist_gen filled with hist1/2 contents it seems that this pecularity of returning peaks positions as described before is lost!

PS since I got more deep in knowing and describing my problem I didn’t post the file with the two histograms, tell me if you need it anyway in order to helping me with my problem.

I’m sorry I did a mistake in writing obviously is

TH1D *h2 = (TH1D*)hist_gen->Clone("h2");

Thanks again,

Dear Mr. Brun,
I’ve tried to create a root file with those two histograms and the macro worked just fine. This made me thinking that probably there is something wrong with the filling of this histograms.
I have a TTree from which I read entries and copy them in std::vector (I don’t know how big is each entry at the beginning). Then I Fill the histograms with the elements of these std::vectors.
I went into a more detailed study of these problem and I noticed that there’s a very peculiar warning during the execution:

Warning: reverse iterator returned;

And I thought it 's due to the std::vector I use to fill the two histograms. could it be possible? If it is so how can I solve this problem?

Thanks again,

[quote]I have a TTree from which I read entries and copy them in std::vector (I don’t know how big is each entry at the beginning).[/quote]Why not fill the histogram directly?

Warning: reverse iterator returned;It does not look like this message is returned by ROOT. Do you have a complete running example showing this problem?