# Problems with saving TF1

Take this simple macro:

[code]double survprobL(double *x, double *par) {

``````double p21 = (pow(1+sqrt(1-par[1]),2.0)/4)*par[0]*
pow(sin(1.27*par[2]*par[5]/x[0]),2.0);

double p31 =  (1+sqrt(1-par[0])/2)*par[1]*
pow(sin(1.27*par[4]*par[5]/x[0]),2.0);

double p32 = (1-sqrt(1-par[0])/2)*par[1]*
pow(sin(1.27*par[3]*par[5]/x[0]),2.0);
``````

return 1 - p21 -p31 -p32;
}

int main() {

double p[6];
p[0] = 0.857; // sin^2 theta_12
p[1] = 0.098; // sin^2 theta_13
p[2] = 7.50E-5; // Delta^2 m_21
p[3] = 2.32E-3; // Delta^2 m_32
p[4] = p[2] + p[3]; // Delta^2 m_31
p[5] = 52000 ; // Lenght in m

//define function and set options
TF1 *FsurvprobL = new TF1(“FsurvprobL”,survprobL,0.,10,6);
FsurvprobL -> SetNpx(1000);

// set parameters, as setup in above
FsurvprobL -> SetParameter(0,p[0]);
FsurvprobL -> SetParameter(1,p[1]);
FsurvprobL -> SetParameter(2,p[2]);
FsurvprobL -> SetParameter(3,p[3]);
FsurvprobL -> SetParameter(4,p[4]);
FsurvprobL -> SetParameter(5,p[5]);

``````FsurvprobL->Draw();
TFile * file = new TFile("juno.root","RECREATE");
FsurvprobL->Write();

return 0;
``````

}
[/code]

ROOT performs correctly the drawing, but if I try to look at the saved plot:

Warning in TCanvas::ResizePad: Canvas_1 height changed from 0 to 10

Any suggestions?

Thanks

Ok, then why this code instead works?

[code]double func(double *x, double *par) {

``````return x[0]*par[0] + par[1];
``````

}

int main() {

``````double p[2];
p[0] = 0.857;
p[1] = 0.098;

TF1 * Pee = new TF1( "Pee" , func , 0 , 10 , 2);
Pee->SetNpx(1000);

Pee->SetParameter(0 , p[0]);
Pee->SetParameter(1 , p[1]);

TDirectory* currentDir = gDirectory;
TFile* junoFile = new TFile( "juno.root" , "RECREATE" );
Pee->Write();
delete junoFile;
``````

return 0;

}[/code]

Hi,

Saving or Cloning a function will work, but what you will save is just a snapshot of the function evaluated at the Npx points, You cannot change anymore the parameters.
I would you suggest to re-create the function when you read back from the file.

Best Regards

Lorenzo