Problem in fitting a gaussian

Hello, I have an already written code that I have to use in order to analyze on some data for a Haynes-Shockley experiment. The code works but it gives me a different result from what I want: I need to fit the second pseudo-gaussian peak and find its mean value, but when running the code the last part of my data is fitted. I tried changing the way the maximum value of y is found, but encountered some issues.
I uploaded both the code and the data file (it’s in .txt format but it should be converted back to .CSV) and added an image where you can see the peak I’m trying to fit.
Thanks in advance :smiling_face_with_tear:

Haynes.C (5.8 KB)
TEK00000.txt (42.0 KB)

Hi @liz,

I believe this is not a ROOT issue but the problem with your data. The noisy data at the end of the measurement impact your fitting. I would suggest excluding those measurements and then re-running your code.

When I exclude the noise, I get something like that with your code: