# 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:

[code]
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
pow(abs(Ri12Q),a));
double Si23 = exp(-0.5
pow(abs(Ri23Q),a));
double Si31 = exp(-0.5
pow(abs(Ri31Q),a));
double Sp12 = exp(-0.5
pow(abs(Rp12Q),a));
double Sp23 = exp(-0.5
pow(abs(Rp23Q),a));
double Sp31 = exp(-0.5
pow(abs(Rp31Q),a));
return par[0]+fc
fc
(1-pc)((1-pc)Si12Si12+2pcSi12Sp12+
(1-pc)Si23Si23+2pcSi23Sp23+
(1-pc)Si31Si31+2
pcSi31Sp31)+
2fcfcfc(1-pc)(1-pc)((1-pc)Si12Si23Si31+
pc
(Si12Si23Sp31+Si12Sp23Si31+Sp12Si23Si31));
}[/code]

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.

Thanks,

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.

Rene

Dear Rene,

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,