Trouble getting x axis values using Tspectrum


This might be a simple question but I am not very familiar with root yet so I am having trouble figuring this out.
I have a plot with multiple peaks in it. I am using Tspectrum to find the peaks and I need the x axis values for which I am using GetPositionX() command. However, this command is giving me incorrect values to x. Maybe it is giving the channel no but I need the user-defined values i.e. I need to read the values from the plot. I am attaching a pdf of the data.
Background subtracted data.pdf (110.5 KB)

So for example, the x value of first peak should give me something like 29 but I am getting 197 which is clearly incorrect. Can anyone help with this? Here is the part of the code -

TSpectrum *mySpec = new TSpectrum();

Int_t npeaksFound = mySpec->Search(hTVsC_backsub, 20," ",0.1);

Double_t *xpeaks = mySpec->GetPositionX();

Double_t x[npeaksFound];

for(Int_t iter = 0; iter<npeaksFound; iter++ ) {

cout << xpeaks[iter] << endl;


cout << "No. of Peaks found is = " << npeaksFound << endl;

I really appreciate your help. Thank you for your time

_ ROOT Version:* 6.18/04
Platform:* C++
Compiler:* Visual Studio Code

std::cout << hTVsC_backsub->GetXaxis()->GetBinCenter(1 + Int_t(xpeaks[iter] + 0.5)) << std::endl;

Thank you for getting back so quick. I tried using the command you sent, it still is giving incorrect values. This is what it produces-

No. of Peaks found is = 14

I don’t know how to proceed. Thank you for your time! Appreciate it!

std::cout << hTVsC_backsub->GetBinCenter(1) + xpeaks[iter] * hTVsC_backsub->GetBinWidth(1) << std::endl;

Still gives similar values, changed by some decimal numbers.

What values do you get from the original (post the full list):

I get these numbers -
No. of Peaks found is = 14

These are not correct. The actual number should be something
152 and so on (Just by reading the graph visually after zooming in)

It looks like you have the correct values.
Note that the peaks are “ordered” according to their “heights”.

1 Like

I think it is giving me the correct values but they are not in order of the peaks in the plot. The values check out with reading the x axis by zooming in the plot. It’s just that the first value is not for the first peak. I have no idea how to fix that though. :stuck_out_tongue: Let me know if you have any suggestions on that!
Ha! :smiley: Thank you so much @Wile_E_Coyote. I really appreciate your time and help. Thank you again!

Haha! Yeah, I was typing the same thing! Thank you so much! You have been very helpful! Appreciate it!
Have a great day!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.