Using parameter values from ascii file

Hi I want to use m fitting parameter value from ascii file …how do i do it ?

Suppose have

TF1 func("func","[0]*(1 - [1]*x*x - [2]*x*x*x", 1.0, 10.);

I want the parameter ([0], [1], [2]) to be read from an ascii file (test.dat) which has three number (one single line as below)

0.3 0.4 0.13

how to read and assign the parameter values of “func” from test.dat ?


  TF1 func("func", "[0]*(1. - [1]*x*x - [2]*x*x*x)", 1., 10.);
  std::ifstream ifs("test.dat", std::ifstream::in);
  ifs >> (func.GetParameters())[0]
      >> (func.GetParameters())[1]
      >> (func.GetParameters())[2];

BTW. When you post “output” or “source code” here, do remember to enclose them into two lines which contain just three characters ``` (see how your post has been edited above).

Hi Wile,
Thanks, yes i can read it from ascii file but the parameters are not fixed to the values shown
in ascii file…because when i use “func” to fit a histogram, i see [0], [1] and [2] are completely different than the values in ascii file. How can i fix those parameters to the values shown in ascii file…

For example i want [0] to be fixed to 0.3, and [1] to be fixed to 0.4, and [2] to be fixed to 0.13.


Fixed it…don’t worry. Thanks.


This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.