Fitting multiple hist/graph joined by a common parameter

Hello Folks,

I wan to fit two histogram or graphs, y1(x1), y2(x2). The fit functions share a parameter, T:

y1(x1; y1_0, y1_1, T); y2(x2; y2_0, y2_1, T);
(Note that in the general case the two data sets are not necessarily sampled at the same x values.)

I can fit them separately, but I get different best-fit values for T. (Of course-no reason why the two data sets should yield the exact same fit value.)

How do I do a joint fit, obtaining a global best fit for all parameters (y1_0, y1_1, y2_0, y2_1, T) across both data sets?

I know I’ve seen the solution before here or in the tutorial examples, but I can’t find it again.

Thanks,
Peter

see $ROOTSYS/tutorials/fit/TwoHistoFit2D.C

Rene

Thanks. I’ve been working from that example, but it won’t compile because of the minimizer function reference. Here is the pseudo-code:

[code]void
MyClass::Min_FCN(Int_t &nPar, Double_t *grad, Double_t &fval, Double_t *p, Int_t iflag)
{ // Joint fit minimization function
// Compute chi squared
}

void
MyClass::Fit()
{ // Perform joint fit
TVirtualFitter * minuit = TVirtualFitter::Fitter(0, nPar);
minuit->SetParameter(…);

minuit->SetFCN(&MyClass::Min_FCN);

arglist[0] = 0;
minuit->ExecuteCommand(“SET PRINT”,arglist,2);
arglist[0] = 5000; // number of function calls
arglist[1] = 0.01; // tolerance
fres = minuit->ExecuteCommand(“MIGRAD”,arglist,2);

}[/code]

With the SetFCN call shown, I get:

error: no matching function for call to 'TVirtualFitter::SetFCN(void (NGMMomentFit::*)(Int_t&, Double_t*, Double_t&, Double_t*, Int_t))' include/TVirtualFitter.h:99: note: candidates are: virtual void include/TVirtualFitter::SetFCN(void*) include/TVirtualFitter.h:100: note: virtual void TVirtualFitter::SetFCN(void (*)(Int_t&, Double_t*, Double_t&, Double_t*, Int_t))

If I change to

I get (with the same candidate list):

If I change to

I get (with the same candidate list):

Any ideas?

Thanks,
Peter

Hi !
I have the same problem !

How you resolved it ?

I also used (following this example)

minuit->SetFCN(MyClass::Min_Y2FY3F);

but gave me

error: no matching function for call to ‘TMinuit::SetFCN()’
/cern/root/include/TMinuit.h:269: note: candidates are: virtual void TMinuit::SetFCN(void*)
/cern/root/include/TMinuit.h:270: note: virtual void TMinuit::SetFCN(void ()(Int_t&, Double_t, Double_t&, Double_t*, Int_t))

Thanks a lot !!!

Hi !

Looking here:

root.cern.ch/phpBB2/viewtopic.ph … cn+fuction

and here:

root.cern.ch/phpBB2/viewtopic.ph … f94200e95c

I have found a partial explaination…

Any evolution up to now ?

Hello Paolo,

No, that’s where I gave up and went on to other things.

Your first link looks interesting. At first I couldn’t find any examples of FCNBase or TFcnAdapter, then I searched in the source code, and found math/minuit2/test/testMinimize.cxx, which begins (more or less)

[code]class MyFCN : public ROOT::Minuit2::FCNBase {

public:

MyFCN() ;

double operator() (const std::vector & x) const ;

double Up() const ;

};[/code]
and goes on with the example from there. I haven’t had a chance to try this in my code, however.

Let me know if you succeed,
Peter

I think this issue was discussed recently

root.cern.ch/phpBB2/viewtopic.ph … highlight=

Due the popular demand I wrote an example. It works under ROOT 5.12 and 5.22 (I did not convert it to the TVirtualFitter due lack of time ). See attachments.
To execute this example one has to apply ACliC

root.exe fit.C++

[code]root.exe [0]
Processing fit.C++…
Info in TUnixSystem::ACLiC: creating shared library /direct/star+data08/users/fine/QTROOT/expert/./fit_C.so
In file included from /direct/star+data08/users/fine/QTROOT/expert/./fileK3oINo.h:32,
from /direct/star+data08/users/fine/QTROOT/expert/./fileK3oINo.cxx:16:


** 1 **SET ERR 1


PARAMETER DEFINITIONS:
NO. NAME VALUE STEP SIZE LIMITS
1 a0 7.00000e-01 1.00000e-01 no limits
2 a1 1.50000e+00 1.00000e-01 no limits
3 a2 0.00000e+00 1.00000e-01 no limits


** 2 **MIGRAD 500 1


FIRST CALL TO USER FUNCTION AT NEW START POINT, WITH IFLAG=4.
START MIGRAD MINIMIZATION. STRATEGY 1. CONVERGENCE WHEN EDM .LT. 1.00e-03
FCN=1260.75 FROM MIGRAD STATUS=INITIATE 12 CALLS 13 TOTAL
EDM= unknown STRATEGY= 1 NO ERROR MATRIX
EXT PARAMETER CURRENT GUESS STEP FIRST
NO. NAME VALUE ERROR SIZE DERIVATIVE
1 a0 7.00000e-01 1.00000e-01 1.00000e-01 1.60400e+03
2 a1 1.50000e+00 1.00000e-01 1.00000e-01 2.94600e+03
3 a2 0.00000e+00 1.00000e-01 1.00000e-01 7.95875e+02
MIGRAD MINIMIZATION HAS CONVERGED.
MIGRAD WILL VERIFY CONVERGENCE AND ERROR MATRIX.
COVARIANCE MATRIX CALCULATED SUCCESSFULLY
FCN=36.3293 FROM MIGRAD STATUS=CONVERGED 54 CALLS 55 TOTAL
EDM=2.53371e-20 STRATEGY= 1 ERROR MATRIX ACCURATE
EXT PARAMETER STEP FIRST
NO. NAME VALUE ERROR SIZE DERIVATIVE
1 a0 -4.55139e-01 1.10395e-01 1.05475e-04 -1.68415e-10
2 a1 1.16792e+00 5.69235e-02 5.86482e-05 -1.21153e-09
3 a2 4.80354e-01 2.48330e-02 5.12514e-05 8.66492e-09
EXTERNAL ERROR MATRIX. NDIM= 25 NPAR= 3 ERR DEF=1
1.219e-02 -5.572e-03 -1.034e-03
-5.572e-03 3.240e-03 7.008e-05
-1.034e-03 7.008e-05 6.167e-04
PARAMETER CORRELATION COEFFICIENTS
NO. GLOBAL 1 2 3
1 0.94733 1.000 -0.887 -0.377
2 0.93847 -0.887 1.000 0.050
3 0.72209 -0.377 0.050 1.000
root.exe [1][/code]



fit.C (7.37 KB)