Please fill also the fields below. Note that root -b -q will tell you this info, and starting from 6.28/06 upwards, you can call .forum bug from the ROOT prompt to pre-populate a topic.
ROOT Version: 6.40.04 Platform: macosxarm64 Compiler: Apple clang version 21.0.0 (clang-2100.1.1.101) std202002
I am trying to use TF12 to create projections of a TF2, and it doesn’t seem to work as documented. I have made a very simple example which I have posted below. I have a simple 2D function with 2 parameters. I want to make one projection, change a parameter, and make another projection. The documentation says you have to use DrawCopy to accomplish this task. This doesn’t seem to work. Also the title of the graph says “x=2” even though it should say “y=2” but that is a minor annoyance. I don’t understand why I don’t see a second line in the canvas. Any help instructing me in the ways of TF12 will be appreciated!
To run the example: Load (.L) this code into root and then “plot_func()”.
double my_func(double *args, double *parms){
double x = args[0];
double y = args[1];
double a = parms[0];
double b = parms[1];
return a*x + b*y*y;
}
void plot_func(){
TF2 *my_tf2 = new TF2("my_tf2", my_func, 0., 2., 0., 4., 2);
my_tf2->SetParameter(0,1.0);
my_tf2->SetParameter(1,2.0);
TF12 *my_tf12_x = new TF12("my_tf12_x", my_tf2, 2., "x");
auto *can = new TCanvas();
my_tf12_x->SetLineColor(1);
my_tf12_x->DrawCopy("f");
my_tf2->SetParameter(0,0.5);
my_tf12_x->SetLineColor(3);
my_tf12_x->DrawCopy("same");
}
```
When you call my_tf12_x->DrawCopy("f") only TF12 object is cloned and add to the canvas.
You call it twice - as a result two separate instances of TF12 object add to the canvas.
But both these instances reference to the same TF2 object. Therefore when you change parameter of this object with my_tf2->SetParameter(0,0.5); - both TF12 are affected.
Because they have similar settings - you see no difference between them.
Maybe you want use TF12::SetXY() to change value before drawing second instance of TF12?
Thank you for your comments. The documentation for TF12 explicitly says of DrawCopy: “This function MUST be used instead of Draw when you want to draw the same function with different parameters settings in the same canvas.” That is what I am trying to do, and it doesn’t work.
I don’t want to use the SetXY() command because that changes the fixed value of “y” (in my case). I don’t want to change this, instead I want to change the value of one of the parameters and draw the function again.
Seems to be TF12::DrawCopy() documentation is not precise enough. It means parameters of TF12 itself but not the parameters of TF2 object.
You need to create new TF2 instance, configure it with other parameters and create separate TF12 object for it. If you drawing TF12 object once - you can directly use Draw method.
I continue to play… If I remove the last two lines, so that the last line is
my_tf2->SetParameter(0,0.5);
then this causes the pad to update and the function is redrawn with the new parameter. So I never get to see two lines because the first one has been redrawn already.
This occurs independently of whether I used Draw or DrawCopy when I do the first drawing.
I would like to loop over values of one of the parameters and draw a series of curves. The documentation led me to believe this was a way to do this.