Simultaneous fit


I have a question about simultaneous fit.
I have 2 data sets, a(x, y) and b(x, y).
and user defined function “func” with 3 parameters par(0), par(1), and par(2).
Then, fit of 2 data sets, and get best values of par(0), par(1), and par(2) and chi2/ndf.
This means that I get 2 fitting lines (for a and b data).
The par(0,1,2) are for both a and b data sets and chi2/ndf is for both a and b data sets.
Would you tell me how to do simultaneous multi graph fitting?


a_data = new TGraphErrors(10);
b_data = new TGraphErrors(15);

Double_t func(Double_t *x, Double_t *par);

void main()

TF1 *intfunc_a = new TF1(“intfunc_a”, func, 0.0, 1.0, 3);

TF1 *intfunc_b = new TF1(“intfunc_b”, func, 0.0, 1.0, 3);


  |  *
  |  ------ *         a_data
  |    ---------  *
  |       -----------  *
  |  ----------------------       *
  |    +
  |  ---      +
  |  --------       +        b_data
  |     -------------      +
  |   -----------------------     +

------------------------ x

The above example is the independent fitting that means the fitting for a_data and fitting for b_data are separated.
And the parameters of a_data and the parameters of b_data are totally different, and chi2/ndf’s are different, too.
But, I want to get common parameters, means

par(0) for a_data = par(0) for b_data
par(1) for a_data = par(1) for b_data
par(2) for a_data = par(2) for b_data

and I want to know total chi2/ndf for (a_data + b_data).
So, this fitting is for minimizing total chi2.
The normalization constants (magnitude constant such as x 10, or x 100) are different for a_data and b_data.

I want to know how to do that.
Thank you!

see example in $ROOTSYS/tutorials/fit/fitMultiGraph.C



Thank you for your reply, however, the fitMultiGraph.C example is only ONE fitting line for
3 data sets. I want to get TWO fitting lines for 2 data sets using same parameters except
normalization constants (magnitude constants). How should I do for that?

Thank you,

How can you pretend to get two different lines with exactly the same function coefficients?



For example,

y = a * f(x); (for a_data set)
y = b * f(x); (for b_data set)
f(x) = f( x, par(0), par(1), par(2),… );

a and b are normalization constants (magnitude constants),
so, we can draw two lines and the f(x) is same function and same parameters.
(actually, the constant a and b are also parameters for the fitting)
That’s why I say “different normalization constants” in previous message.

Would you tell me how to do for that?
Thank you!

Dear friends,

Please let me continue this old thread.
Also I’m very interesting in Nobu-san’s questions.

I prepared instant samples as below, I would like to know how to extract normalization factor ‘a_0’ and ‘parameters’ using same function throughout simultaneous fit when we add two independent experimental data sets, for example.

In short, the point is to get ‘a_0’ which satisfies only one 2nd order polynomial shape for both data distributions simultaneously.

Carefully guessing, this kind analysis would be very popular, but I can’t solve it. Please let me share your wisdom.



  // dummy data point
  double x1[5], y1[5], ye1[5];
  for (int i=0; i<5; i++){
    x1[i] = 2+i;
    y1[i] = log(2+i) / 1000.;
    ye1[i] = y1[i] / 3.;

  double x2[5], y2[5], ye2[5];
  for (int i=0; i<5; i++){
    x2[i] = 5+i;
    y2[i] = sqrt(2+i);
    ye2[i] = y2[i] / 3.;

  TCanvas *c = new TCanvas("c", "", 0, 0, 900, 300);
  TH2F *h1 = new TH2F("h1","", 2, 0.0, 10.0, 2, 0, 0.010);
  h1->SetXTitle("x  ");
  h1->SetYTitle("a_{0} f  ");
  TGraphErrors *gr1 = new TGraphErrors(5, x1, y1, 0, ye1);
  TH2F *h2 = new TH2F("h2","", 2, 0.0, 10.0, 2, 0, 10);
  h2->SetXTitle("x  ");
  h2->SetYTitle("f  ");
  TGraphErrors *gr2 = new TGraphErrors(5, x2, y2, 0, ye2);

  // combined simultaneous fit?
  // decide a_0, par[0], par[1], and par[2] 
  // throughout simultaneous fit;
  TH2F *h3 = new TH2F("h3","", 2, 0.0, 10.0, 2, 0, 10);
  h3->SetXTitle("x  ");
  h3->SetYTitle("f  ");
  TMultiGraph *mg = new TMultiGraph("mg","");

  TF1 *ff = new TF1("ff", "[3] * ( [0] + [1]*x + [2]*x*x )");
  ff->SetParName(3,"a_{0}"); // norm

  //mg.Fit("ff", "E", "", 0.0, 9.5);