TObject::Clone and TF1


I clone a TF1 with TObject::Clone and then I change the value of the parameters of the new TF1 using SetParameters. If I inspect the parameter value with GetParameter I get the new values but when I Draw the TF1 I always get the graph of the original TF1 with the original set of parameters. Does it make sense? I am using 5.22.00. An example of the macro is here:

MomentumDistribution md(MomentumDistribution::Ratio);

double p[]={20,50,100,200,500,1000};
TF1 ff(“ff”,&md,-15,20,5,“MomentumDistribution”);

TObjArray farr(6);
for(int i=0;i<6;i++) {
char name[30];
TIter it(&farr);
TF1* func=0;
int i=0;
while(func = (TF1*)it.Next()) {
cout << "Fill parameter " << p[i] << endl;




Ciao Andrea,

the method TF1::Clone() uses the I/O system to copy the function. In the case of a C or C++ function, the only way to copy is sampling the function in a pre-defined number of points, and the information about the code implementing the function is lost. It will work only for interpreted function,
defined with a formula expression.
You should use the copy constructor of TF1, which will work, but be aware that it will perform only a shallow copy, i,.e it will not copy the object implementing the function, but perform only a simple pointer copy.

Best Regards