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.
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.
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]