Writing a TF3 to file

Dear developers,

I have a question regardin writing a TF3 object to a root file.
I have a macro foo.C:

double hc = 0.197327;

double C3FitFunc3D(double x, double par)
double Ri12Q = x[0]par[3]/hc;
double Ri23Q = x[1]par[3]/hc;
double Ri31Q = x[2]par[3]/hc;
double Rp12Q = x[0]50/hc;
double Rp23Q = x[1]50/hc;
double Rp31Q = x[2]50/hc;
double fc = par[1];
double pc = par[2];
double a = par[4];
double Si12 = exp(-0.5
double Si23 = exp(-0.5
double Si31 = exp(-0.5
double Sp12 = exp(-0.5
double Sp23 = exp(-0.5
double Sp31 = exp(-0.5
return par[0]+fc

I do in root interactively:

root [0] .L foo.C root [1] TF3 * c3func = new TF3("c3func",C3FitFunc3D,0,0.15,0,0.15,0$ root [2] c3func->SetParameters(1.0,1.0,0.276299,6.34383,1.74912); root [3] cerr << c3func->Eval(0.01,0.01,0.01) << endl; 3.71442 root [4] cerr << c3func->Eval(0.1,0.1,0.1) << endl; 1.00172 root [5] f = new TFile("try3.root","RECREATE"); root [6] c3func->Write(); root [7] f.Write(); root [8] .ls TFile** try3.root TFile* try3.root KEY: TF3 c3func;1 C3FitFunc3D root [9] .q
After that:

root [0] new TFile("try3.root"); root [1] .ls TFile** try3.root TFile* try3.root KEY: TF3 c3func;1 C3FitFunc3D root [2] cerr << c3func->Eval(0.1,0.1,0.1) << endl; 1.92592 root [3] cerr << c3func->Eval(0.01,0.01,0.01) << endl; 4.27538

How can that be? How can a different function in the written file than it was before?
I also tried c3func->Save(0,0.15,0,0.15,0,0.15), but it did not help. But the saved function seems not to be ‘completely random’, but something like 2x the original one.
It would be great if you could tell me why this is happening, or (more importantly), how to fix this behavior.
I use ROOT 4.01/02 under Scientific Linux 3.0.1.

Mate Csanad

Saving a TF3 in case of an interpreted or compiled function is not implemented. Because we cannot save the code of the function,
we need to save the function values at cells i,j,k and make an interpolation when reading. This is implemented for TF1 and TF2, but
not for TF3.


Dear Rene,

Thanks a lot for your quick answer.
So there is basically no way for saving a TF3, right? Or is it possible somehow through some kind of TF1 sub-objects of the TF3 object?
The thing is, that I calculate a TF3, and this lasts really really long (this TF3 is not the one included before, that was just for giving an example what doesn’t work). So, if I would like to quit root but look at my calculated function two days later, I have to calculate the whole function again?
Can you recommend anything?

Thanks a lot,
Mate Csanad

Of course, I forgot to mention that we will implement this functionality.
The current CVS head contains already a first implementation.
We still have to implement a trilinear interpolation from the table
of tabulated function values when writing a TF3 to a file.


OK, support for TF3 persistency in case of interpreted functions is now
fully implemented in CVS head.