Combined (simultaneous) fit of two histogram with separate functions and some common parameters
See http://root.cern.ch/phpBB3//viewtopic.php?f=3&t=11740#p50908 for a modified version working with Fumili or GSLMultiFit
N.B. this macro must be compiled with ACliC
Processing /mnt/build/workspace/root-makedoc-v614/rootspi/rdoc/src/v6-14-00-patches/tutorials/fit/combinedFit.C...
****************************************
Minimizer is Minuit2 / Migrad
Chi2 = 131.104
NDf = 115
Edm = 2.11602e-08
NCalls = 225
Par_0 = 5.5396 +/- 0.0354094
Par_1 = 4.66089 +/- 0.050106
Par_2 = -0.0514037 +/- 0.00108539 (limited)
Par_3 = 77.2733 +/- 3.93105 (limited)
Par_4 = 30 (fixed)
Par_5 = 4.864 +/- 0.243005
int iparB[2] = { 0,
2
};
int iparSB[5] = { 1,
2,
3,
4,
5
};
struct GlobalChi2 {
fChi2_1(&f1), fChi2_2(&f2) {}
for (int i = 0; i < 2; ++i) p1[i] = par[iparB[i] ];
for (int i = 0; i < 5; ++i) p2[i] = par[iparSB[i] ];
return (*fChi2_1)(
p1) + (*fChi2_2)(
p2);
}
};
void combinedFit() {
TH1D * hB =
new TH1D(
"hB",
"histo B",100,0,100);
TH1D * hSB =
new TH1D(
"hSB",
"histo S+B",100, 0,100);
TF1 * fB =
new TF1(
"fB",
"expo",0,100);
TF1 * fS =
new TF1(
"fS",
"gaus",0,100);
TF1 * fSB =
new TF1(
"fSB",
"expo + gaus(2)",0,100);
GlobalChi2 globalChi2(chi2_B, chi2_SB);
const int Npar = 6;
double par0[Npar] = { 5,5,-0.1,100, 30,10};
fitter.
FitFCN(6,globalChi2,0,dataB.Size()+dataSB.Size(),
true);
TCanvas * c1 =
new TCanvas(
"Simfit",
"Simultaneous fit of two histograms",
10,10,700,700);
}
- Author
- Lorenzo Moneta
Definition in file combinedFit.C.