# Positions of maximums with TSpectrum

**URL:** <https://root-forum.cern.ch/t/positions-of-maximums-with-tspectrum/21978>\
**Category:** ROOT\
**Created:** [October 3, 2016, 4:07pm UTC](https://root-forum.cern.ch/t/positions-of-maximums-with-tspectrum/21978 "2016-10-03T16:07:44Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![SergeyKo](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/s/6a8cbe/32.png) [@SergeyKo](https://root-forum.cern.ch/u/SergeyKo)\
**Post date:** [October 3, 2016, 4:07pm UTC](https://root-forum.cern.ch/t/positions-of-maximums-with-tspectrum/21978/1 "2016-10-03T16:07:44Z")

</div>

Dear rooters,  
I have a problem using TSpectrum.  
I’m trying to understand the standart macro: [https://root.cern.ch/root/html/tutorials/spectrum/peaks.C.html](https://root.cern.ch/root/html/tutorials/spectrum/peaks.C.html).  
Program works well but when I’m trying to print positions of maximums I’ll get wrong values.  
Here is how I try to get positions:

` Double_t xp = xpeaks[p];
      Int_t bin = h->GetXaxis()->FindBin(xp);
      Double_t yp = h->GetBinContent(bin);
      [b]cout<<"Xp= "<<xp<<" Yp="<<yp<<endl;[/b]`  
And here is the result for [color=#0040BF]peaks(4)[/color]:

`Found 4 candidate peaks to fit
Xp= 5.39567e+20 Yp=0
Xp= 2.23206e+21 Yp=0
Xp= 8.73532e-313 Yp=577
Xp= 3.60739e-313 Yp=577`  
The question is how to get these positions correctly?  
Thank you for help in advance!  
Sergey

---

<div class="post-metadata">

**Author:** ![Pepe\_Le\_Pew](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/pepe_le_pew/32/12365_2.png) [@Pepe\_Le\_Pew](https://root-forum.cern.ch/u/Pepe_Le_Pew)\
**Post date:** [October 3, 2016, 4:21pm UTC](https://root-forum.cern.ch/t/positions-of-maximums-with-tspectrum/21978/2 "2016-10-03T16:21:51Z")

</div>

Which ROOT version?  
Note: [ROOT 6 returns “Double\_t” peaks’ positions](https://root.cern.ch/root/html/tutorials/spectrum/peaks.C.html), while [ROOT 5 returns “Float\_t” peaks’ positions](https://root.cern.ch/root/html534/tutorials/spectrum/peaks.C.html).  
Try something like this: ` // ...
#if ROOT_VERSION_CODE >= ROOT_VERSION(6,00,00)
  Double_t *xpeaks; // ROOT 6
#else
  Float_t *xpeaks; // ROOT 5
#endif
  xpeaks = s->GetPositionX();
  for (p = 0; p < nfound; p++) {
    Double_t xp = xpeaks[p]; // ROOT 6 or 5
    // ...
  }
  // ...` See also: [Illegal pointer to class object back 0x0 165](https://root-forum.cern.ch/t/illegal-pointer-to-class-object-back-0x0-165/21084/9)

---

<div class="post-metadata">

**Author:** ![SergeyKo](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/s/6a8cbe/32.png) [@SergeyKo](https://root-forum.cern.ch/u/SergeyKo)\
**Post date:** [October 5, 2016, 4:15pm UTC](https://root-forum.cern.ch/t/positions-of-maximums-with-tspectrum/21978/3 "2016-10-05T16:15:08Z")

</div>

Dear Pepe Le Pew,  
thank you for answer, now it works!

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [October 10, 2016, 9:16am UTC](https://root-forum.cern.ch/t/positions-of-maximums-with-tspectrum/21978/4 "2016-10-10T09:16:29Z")

</div>

Note that the spectrum tutorials collection has been extended recently:  
[root.cern.ch/doc/master/group\_\_ … ctrum.html](https://root.cern.ch/doc/master/group __tutorial__ spectrum.html)
