ROOT Version: 6.30/06 Platform: ubuntu Compiler: Not Provided

I save my data in an textfile and it it loos like this (2 21 0 4 13 1 15 31 2) i.e x1,y1,z1,x2,y2,z2,x3,y3,z3. I plotted this to a 3D histogram but I have trouble with fitting a linear regression through the data set. I attach my macro. FitMuonTrajectory.C (1.6 KB)

It is hard to understand what exactly the problem is. Can you reduce the example to a few lines, make explicit what you expect and expose what you get?

You need to use TF2 instead of TF1 because your fit function is two-dimensional, as you write in the formula and in the comment. That is a mistake for sure.