# Function written to file loses parameters?

Hi

I encountered some strange behaviour on root v4-00-04 which might just be
a lack of understanding on my part.

I also tried this on an install of v4-02-00 and the behaviour was the same

I want to fit a surface to some data and store the 2-dimensional fit as my
parameterisation in a file. When I ran my code and retrieved my
parameterisations from the file all the fit parameters had been reset to 0.

I stripped my code down to the trivial macro below - it still does it - if you
retrieve the TF2 from the file its parameters are all zero.

Could someone please explain what I need to do so actually save the function
parameters and not just the function?

Thanks,

Mark

Here is my code and the output from a session is below that.

[code]TF2* GLOBAL_FCN = 0;

void Test2(TString centrality = “6”)
{
GLOBAL_FCN = new TF2(“f2dEfficiency”,"[0]+[1]*x^2+[2]*x^4+[3]*x^6+[4]*x^8+[5]*exp([6]*y)+[7]*y+[8]yy + [9]*exp(-((TMath::Abs(x)-[10])^2) /[11] - (( TMath::Abs(y)-[12] )^2) /[13]) + [14]*exp(-((TMath::Abs(x)-[15])^2) /[16] - (( TMath::Abs(y)-[17] )^2) /[18]) ",-1.,1.,0.,12.);

TH2D* hist1 = Get2D();

TFile fsave(TString(“Mark.Test.root”),“RECREATE”);
cout << "Parameters : “<<GLOBAL_FCN->GetParameter(0)<<” “<<GLOBAL_FCN->GetParameter(2)<<” "<<GLOBAL_FCN->GetParameter(4)<<endl;
GLOBAL_FCN->Write();
fsave.Close();

}

TH2D* Get2D()
{
for (Int_t i=0;i<9;i++) GLOBAL_FCN->SetParameter(i,1.0);
GLOBAL_FCN->SetParameter(9,0.1); // amplitude of deviation
GLOBAL_FCN->SetParameter(10,0.9); //eta centre of deviation
GLOBAL_FCN->SetParameter(11,0.2); //eta width of deviation
GLOBAL_FCN->SetParameter(12,0.3);
GLOBAL_FCN->SetParameter(13,0.05);

GLOBAL_FCN->SetParameter(14,0.1); // amplitude of deviation
GLOBAL_FCN->SetParameter(15,0.); //eta centre of deviation
GLOBAL_FCN->SetParameter(16,0.4); //eta width of deviation
GLOBAL_FCN->SetParameter(17,1.0);
GLOBAL_FCN->SetParameter(18,0.3);

return 0;

}
[/code]

[quote]root4star [0] TFile f(“Mark.Test.root”)
root4star [1] f.ls()
TFile** Mark.Test.root
TFile* Mark.Test.root
KEY: TF2 f2dEfficiency;1 [0]+[1]*x^2+[2]*x^4+[3]*x^6+[4]*x^8+[5]*exp([6]*y)+[7]*y+[8]yy+[9]*exp(-((TMath::Abs(x)-[10])^2)/[11]-((TMath::Abs(y)-[12])^2)/[13])+[14]exp(-((TMath::Abs(x)-[15])^2)/[16]-((TMath::Abs(y)-[17])^2)/[18])
root4star [2] TF2
func = f.Get(“f2dEfficiency”)
root4star [3] func->Print()
f2dEfficiency : [0]+[1]*x^2+[2]*x^4+[3]*x^6+[4]*x^8+[5]*exp([6]*y)+[7]*y+[8]yy+[9]*exp(-((TMath::Abs(x)-[10])^2)/[11]-((TMath::Abs(y)-[12])^2)/[13])+[14]*exp(-((TMath::Abs(x)-[15])^2)/[16]-((TMath::Abs(y)-[17])^2)/[18]) Ndim= 2, Npar= 19, Noper= 81
fExpr[0] = [0] action = 140 action param = 0
fExpr[1] = [1] action = 140 action param = 1
fExpr[2] = x action = 144 action param = 0
fExpr[3] = sq action = 21 action param = 0
fExpr[4] = * action = 3 action param = 0
fExpr[5] = + action = 1 action param = 0
fExpr[6] = [2] action = 140 action param = 2
fExpr[7] = x action = 144 action param = 0
fExpr[8] = 4 action = 141 action param = 0
fExpr[9] = ^ action = 20 action param = 0
fExpr[10] = * action = 3 action param = 0
fExpr[11] = + action = 1 action param = 0
fExpr[12] = [3] action = 140 action param = 3
fExpr[13] = x action = 144 action param = 0
fExpr[14] = 6 action = 141 action param = 1
fExpr[15] = ^ action = 20 action param = 0
fExpr[16] = * action = 3 action param = 0
fExpr[17] = + action = 1 action param = 0
fExpr[18] = [4] action = 140 action param = 4
fExpr[19] = x action = 144 action param = 0
fExpr[20] = 8 action = 141 action param = 2
fExpr[21] = ^ action = 20 action param = 0
fExpr[22] = * action = 3 action param = 0
fExpr[23] = + action = 1 action param = 0
fExpr[24] = [5] action = 140 action param = 5
fExpr[25] = [6] action = 140 action param = 6
fExpr[26] = y action = 144 action param = 1
fExpr[27] = * action = 3 action param = 0
fExpr[28] = exp action = 31 action param = 0
fExpr[29] = * action = 3 action param = 0
fExpr[30] = + action = 1 action param = 0
fExpr[31] = [7] action = 140 action param = 7
fExpr[32] = y action = 144 action param = 1
fExpr[33] = * action = 3 action param = 0
fExpr[34] = + action = 1 action param = 0
fExpr[35] = [8] action = 140 action param = 8
fExpr[36] = y action = 144 action param = 1
fExpr[37] = y action = 144 action param = 1
fExpr[38] = * action = 3 action param = 0
fExpr[39] = * action = 3 action param = 0
fExpr[40] = + action = 1 action param = 0
fExpr[41] = [9] action = 140 action param = 9
fExpr[42] = x action = 144 action param = 0
fExpr[43] = Double_t TMath::Abs(Double_t d) action = 145 action param = 1
fExpr[44] = [10] action = 140 action param = 10
fExpr[45] = - action = 2 action param = 0
fExpr[46] = sq action = 21 action param = 0
fExpr[47] = [11] action = 140 action param = 11
fExpr[48] = / action = 4 action param = 0
fExpr[49] = - action = 44 action param = 0
fExpr[50] = y action = 144 action param = 1
fExpr[51] = Double_t TMath::Abs(Double_t d) action = 145 action param = 1001
fExpr[52] = [12] action = 140 action param = 12
fExpr[53] = - action = 2 action param = 0
fExpr[54] = sq action = 21 action param = 0
fExpr[55] = [13] action = 140 action param = 13
fExpr[56] = / action = 4 action param = 0
fExpr[57] = - action = 2 action param = 0
fExpr[58] = exp action = 31 action param = 0
fExpr[59] = * action = 3 action param = 0
fExpr[60] = + action = 1 action param = 0
fExpr[61] = [14] action = 140 action param = 14
fExpr[62] = x action = 144 action param = 0
fExpr[63] = Double_t TMath::Abs(Double_t d) action = 145 action param = 2001
fExpr[64] = [15] action = 140 action param = 15
fExpr[65] = - action = 2 action param = 0
fExpr[66] = sq action = 21 action param = 0
fExpr[67] = [16] action = 140 action param = 16
fExpr[68] = / action = 4 action param = 0
fExpr[69] = - action = 44 action param = 0
fExpr[70] = y action = 144 action param = 1
fExpr[71] = Double_t TMath::Abs(Double_t d) action = 145 action param = 3001
fExpr[72] = [17] action = 140 action param = 17
fExpr[73] = - action = 2 action param = 0
fExpr[74] = sq action = 21 action param = 0
fExpr[75] = [18] action = 140 action param = 18
fExpr[76] = / action = 4 action param = 0

fExpr[77] = - action = 2 action param = 0
fExpr[78] = exp action = 31 action param = 0
fExpr[79] = * action = 3 action param = 0
fExpr[80] = + action = 1 action param = 0
Par 0 p0 = 0
Par 1 p1 = 0
Par 2 p2 = 0
Par 3 p3 = 0
Par 4 p4 = 0
Par 5 p5 = 0
Par 6 p6 = 0
Par 7 p7 = 0
Par 8 p8 = 0
Par 9 p9 = 0
Par 10 p10 = 0
Par 11 p11 = 0
Par 12 p12 = 0
Par 13 p13 = 0
Par 14 p14 = 0
Par 15 p15 = 0
Par 16 p16 = 0
Par 17 p17 = 0
Par 18 p18 = 0
root4star [4] .q

This is the end of ROOT – Goodbye
[/quote][/i]

I cannot reproduce this problem using the standard root executable.
Seems to be related to root4star.
I get as expected:

```Root [0] TFile f("Mark.Test.root") Root [1] .ls TFile** Mark.Test.root TFile* Mark.Test.root KEY: TF2 f2dEfficiency;1 [0]+[1]*x^2+[2]*x^4+[3]*x^6+[4]*x^8+[5]*exp([6]*y)+[7]*y+[8]*y*y+[9]*exp(-((TMath::Abs(x)-[10])^2)/[11]-((TMath::Abs(y)-[12])^2)/[13])+[14]*exp(-((TMath::Abs(x)-[15])^2)/[16]-((TMath::Abs(y)-[17])^2)/[18]) Root [2] f2dEfficiency.Print() f2dEfficiency : [0]+[1]*x^2+[2]*x^4+[3]*x^6+[4]*x^8+[5]*exp([6]*y)+[7]*y+[8]*y*y+[9]*exp(-((TMath::Abs(x)-[10])^2)/[11]-((TMath::Abs(y)-[12])^2)/[13])+[14]*exp(-((TMath::Abs(x)-[15])^2)/[16]-((TMath::Abs(y)-[17])^2)/[18]) Ndim= 2, Npar= 19, Noper= 81 fExpr[0] = [0] action = 140 action param = 0 fExpr[1] = [1] action = 140 action param = 1 fExpr[2] = x action = 144 action param = 0 fExpr[3] = sq action = 21 action param = 0 fExpr[4] = * action = 3 action param = 0 fExpr[5] = + action = 1 action param = 0 fExpr[6] = [2] action = 140 action param = 2 fExpr[7] = x action = 144 action param = 0 fExpr[8] = 4 action = 141 action param = 0 fExpr[9] = ^ action = 20 action param = 0 fExpr[10] = * action = 3 action param = 0 fExpr[11] = + action = 1 action param = 0 fExpr[12] = [3] action = 140 action param = 3 fExpr[13] = x action = 144 action param = 0 fExpr[14] = 6 action = 141 action param = 1 fExpr[15] = ^ action = 20 action param = 0 fExpr[16] = * action = 3 action param = 0 fExpr[17] = + action = 1 action param = 0 fExpr[18] = [4] action = 140 action param = 4 fExpr[19] = x action = 144 action param = 0 fExpr[20] = 8 action = 141 action param = 2 fExpr[21] = ^ action = 20 action param = 0 fExpr[22] = * action = 3 action param = 0 fExpr[23] = + action = 1 action param = 0 fExpr[24] = [5] action = 140 action param = 5 fExpr[25] = [6] action = 140 action param = 6 fExpr[26] = y action = 144 action param = 1 fExpr[27] = * action = 3 action param = 0 fExpr[28] = exp action = 31 action param = 0 fExpr[29] = * action = 3 action param = 0 fExpr[30] = + action = 1 action param = 0 fExpr[31] = [7] action = 140 action param = 7 fExpr[32] = y action = 144 action param = 1 fExpr[33] = * action = 3 action param = 0 fExpr[34] = + action = 1 action param = 0 fExpr[35] = [8] action = 140 action param = 8 fExpr[36] = y action = 144 action param = 1 fExpr[37] = y action = 144 action param = 1 fExpr[38] = * action = 3 action param = 0 fExpr[39] = * action = 3 action param = 0 fExpr[40] = + action = 1 action param = 0 fExpr[41] = [9] action = 140 action param = 9 fExpr[42] = x action = 144 action param = 0 fExpr[43] = Double_t TMath::Abs(Double_t d) action = 145 action param = 1 fExpr[44] = [10] action = 140 action param = 10 fExpr[45] = - action = 2 action param = 0 fExpr[46] = sq action = 21 action param = 0 fExpr[47] = [11] action = 140 action param = 11 fExpr[48] = / action = 4 action param = 0 fExpr[49] = - action = 44 action param = 0 fExpr[50] = y action = 144 action param = 1 fExpr[51] = Double_t TMath::Abs(Double_t d) action = 145 action param = 1001 fExpr[52] = [12] action = 140 action param = 12 fExpr[53] = - action = 2 action param = 0 fExpr[54] = sq action = 21 action param = 0 fExpr[55] = [13] action = 140 action param = 13 fExpr[56] = / action = 4 action param = 0 fExpr[57] = - action = 2 action param = 0 fExpr[58] = exp action = 31 action param = 0 fExpr[59] = * action = 3 action param = 0 fExpr[60] = + action = 1 action param = 0 fExpr[61] = [14] action = 140 action param = 14 fExpr[62] = x action = 144 action param = 0 fExpr[63] = Double_t TMath::Abs(Double_t d) action = 145 action param = 2001 fExpr[64] = [15] action = 140 action param = 15 fExpr[65] = - action = 2 action param = 0 fExpr[66] = sq action = 21 action param = 0 fExpr[67] = [16] action = 140 action param = 16 fExpr[68] = / action = 4 action param = 0 fExpr[69] = - action = 44 action param = 0 fExpr[70] = y action = 144 action param = 1 fExpr[71] = Double_t TMath::Abs(Double_t d) action = 145 action param = 3001 fExpr[72] = [17] action = 140 action param = 17 fExpr[73] = - action = 2 action param = 0 fExpr[74] = sq action = 21 action param = 0 fExpr[75] = [18] action = 140 action param = 18 fExpr[76] = / action = 4 action param = 0 fExpr[77] = - action = 2 action param = 0 fExpr[78] = exp action = 31 action param = 0 fExpr[79] = * action = 3 action param = 0 fExpr[80] = + action = 1 action param = 0 Optimized expresion fExpr[0] = [0] action = 146 action param = 0 fExpr[1] = [1] action = 146 action param = 1 fExpr[2] = x,sq action = 147 action param = 0 fExpr[3] = * action = 3 action param = 0 fExpr[4] = + action = 1 action param = 0 fExpr[5] = [2] action = 146 action param = 2 fExpr[6] = x action = 146 action param = 0 fExpr[7] = 4 action = 146 action param = 0 fExpr[8] = ^ action = 20 action param = 0 fExpr[9] = * action = 3 action param = 0 fExpr[10] = + action = 1 action param = 0 fExpr[11] = [3] action = 146 action param = 3 fExpr[12] = x action = 146 action param = 0 fExpr[13] = 6 action = 146 action param = 1 fExpr[14] = ^ action = 20 action param = 0 fExpr[15] = * action = 3 action param = 0 fExpr[16] = + action = 1 action param = 0 fExpr[17] = [4] action = 146 action param = 4 fExpr[18] = x action = 146 action param = 0 fExpr[19] = 8 action = 146 action param = 2 fExpr[20] = ^ action = 20 action param = 0 fExpr[21] = * action = 3 action param = 0 fExpr[22] = + action = 1 action param = 0 fExpr[23] = [5] action = 146 action param = 5 fExpr[24] = [6],y,* action = 148 action param = 0 fExpr[25] = exp action = 161 action param = 0 fExpr[26] = * action = 3 action param = 0 fExpr[27] = + action = 1 action param = 0 fExpr[28] = [7],y,* action = 148 action param = 0 fExpr[29] = + action = 1 action param = 0 fExpr[30] = [8],y,y,*,* action = 149 action param = 0 fExpr[31] = + action = 1 action param = 0 fExpr[32] = [9] action = 146 action param = 9 fExpr[33] = x,Double_t TMath::Abs(Double_t d) action = 147 action param = 0 fExpr[34] = [10] action = 146 action param = 10 fExpr[35] = - action = 2 action param = 0 fExpr[36] = sq action = 161 action param = 0 fExpr[37] = [11] action = 146 action param = 11 fExpr[38] = / action = 4 action param = 0 fExpr[39] = - action = 44 action param = 0 fExpr[40] = y,Double_t TMath::Abs(Double_t d) action = 147 action param = 0 fExpr[41] = [12] action = 146 action param = 12 fExpr[42] = - action = 2 action param = 0 fExpr[43] = sq action = 161 action param = 0 fExpr[44] = [13] action = 146 action param = 13 fExpr[45] = / action = 4 action param = 0 fExpr[46] = - action = 2 action param = 0 fExpr[47] = exp action = 161 action param = 0 fExpr[48] = * action = 3 action param = 0 fExpr[49] = + action = 1 action param = 0 fExpr[50] = [14] action = 146 action param = 14 fExpr[51] = x,Double_t TMath::Abs(Double_t d) action = 147 action param = 0 fExpr[52] = [15] action = 146 action param = 15 fExpr[53] = - action = 2 action param = 0 fExpr[54] = sq action = 161 action param = 0 fExpr[55] = [16] action = 146 action param = 16 fExpr[56] = / action = 4 action param = 0 fExpr[57] = - action = 44 action param = 0 fExpr[58] = y,Double_t TMath::Abs(Double_t d) action = 147 action param = 0 fExpr[59] = [17] action = 146 action param = 17 fExpr[60] = - action = 2 action param = 0 fExpr[61] = sq action = 161 action param = 0 fExpr[62] = [18] action = 146 action param = 18 fExpr[63] = / action = 4 action param = 0 fExpr[64] = - action = 2 action param = 0 fExpr[65] = exp action = 161 action param = 0 fExpr[66] = * action = 3 action param = 0 fExpr[67] = + action = 1 action param = 0 Par 0 p0 = 1 Par 1 p1 = 1 Par 2 p2 = 1 Par 3 p3 = 1 Par 4 p4 = 1 Par 5 p5 = 1 Par 6 p6 = 1 Par 7 p7 = 1 Par 8 p8 = 1 Par 9 p9 = 0.1 Par 10 p10 = 0.9 Par 11 p11 = 0.2 Par 12 p12 = 0.3 Par 13 p13 = 0.05 Par 14 p14 = 0.1 Par 15 p15 = 0 Par 16 p16 = 0.4 Par 17 p17 = 1 Par 18 p18 = 0.3 Root [3] .q [ ```

Rene

This problem was solved on July 1st. The fix is currently only available in the CVS head (ROOT v5.03/01). Note that the data on the file is correct. The only issue was with reading it back when the formula contains a function call.

Cheers,
Philippe.