TGraph Fit Display

I am fitting a custom function to four TGraphErrors. All fits are ‘complete’ - they return accurate parameters - but are not displayed on the pad. In fact, they are displayed as single flat lines at the top of the pad (completely outside the graph). I can change the colour of this fitted line, even. I can select this line by moving my mouse over where the lfitted function ‘should’ be.

On a separate canvas I can draw these fit functions and they appear properly. Trying to ‘redraw’ these functions overtop of the graph data only results in another line at the top of the pad.

Of the four, a single graph displays its fit. When I input the ‘working’ X-axis data into the other pads, they fit properly as well. I have no problem displaying any other component of my graphs. The data of the other graphs are only marginally different from the working data - altered by a small correction.

The code collecting the corrected data is somewhat long but I will provide it if my description hasn’t provided enough information to solve the problem.

Thank you very much for your time and assistance, it’s greatly appreciated.
-Stef Simmons

Please send the shortest possible RUNNING script reproducing your problem and indicate which version of ROOT.


I’ve attached the file, as well as the ROOT file I am working with for it to run. I must admit that I’m already suspicious of this code, as I can only get it working the way I would like with a fresh ROOT session every time.

My version of root is 4.04/02.

Please let me know if you have any further questions. Thank you again for your help.

-Stef Simmons
TimeResEnergy.cxx (127 Bytes)
run00568.root (1.05 MB)
FitGraph.C (6.07 KB)

I cannot execute your script till the end.
Your statement;
TF1* t1func = new TF1(“t1func”,TimeResEnergy,0,2,3);
references the function TimeResEnergy


My apologies. I’ve attached the file to my previous post.

I have no problem running your script. I obtain the picture in attachement


My script produced two separate canvases - both ADC1 and ADC2. ADC1 was the one working canvas and I provided that for comparison, however ADC2 illustrated the problem I was having.

If ADC2 displys just as beautifully as your attached ADC1, I apologize for wasting your time. If so, I have one question for you: Where should I look internally to locate this problem?

Otherwise, best of luck with ADC2.

Thanks again,

In your function TimeResEnergy (x[0]-par[1]) can be <= 0
You should protect this case to avoid a negative sqrt.
You should also restrict the fit range for timeGraph2 to eg [1e-3,1e-2]


Those are good suggestions, but they do not fix my problem.

Just so I’m clear: Did ADC2 display properly for you?


Yes, it displays properly once you protect your function against division by 0.