Fitting a 2-D histogram This tutorial illustrates :
- how to create a 2-d function
- fill a 2-d histogram randomly from this function
- fit the histogram
- display the fitted function on top of the histogram
This example can be executed via the interpreter or ACLIC
root > .x fit2.C
root > .x fit2.C++
Processing /mnt/build/workspace/root-makedoc-v610/rootspi/rdoc/src/v6-10-00-patches/tutorials/fit/fit2.C...
FCN=1048.29 FROM MIGRAD STATUS=CONVERGED 384 CALLS 385 TOTAL
EDM=1.71322e-07 STRATEGY= 1 ERROR MATRIX UNCERTAINTY 1.7 per cent
EXT PARAMETER STEP FIRST
NO. NAME VALUE ERROR SIZE DERIVATIVE
1 p0 3.92557e+02 1.80794e+00 -8.93084e-04 1.08687e-04
2 p1 -2.99839e+00 1.13352e-02 -6.49022e-06 -1.81169e-02
3 p2 2.98485e+00 7.41044e-03 3.61029e-06 -5.86707e-02
4 p3 -3.00202e+00 1.11595e-02 -5.78995e-06 -1.75291e-02
5 p4 2.97271e+00 7.15832e-03 -3.28537e-06 -4.12671e-02
6 p5 6.01136e+02 9.83774e+00 3.21496e-03 -2.69039e-05
7 p6 6.14587e-03 1.13579e-02 5.13988e-06 2.41415e-02
8 p7 8.16263e-01 9.52518e-03 3.01650e-06 -8.27905e-03
9 p8 -7.76134e-04 1.27854e-02 5.13130e-06 -5.37314e-03
10 p9 9.11281e-01 1.09052e-02 -6.70501e-06 2.34956e-02
11 p10 1.46899e+02 4.66962e+00 -3.42265e-04 5.38650e-05
12 p11 3.98822e+00 1.79131e-02 1.99375e-05 9.00581e-03
13 p12 7.27558e-01 1.32237e-02 -2.78349e-06 5.94851e-03
14 p13 4.02638e+00 1.71292e-02 4.21852e-06 5.32470e-03
15 p14 7.03078e-01 1.29939e-02 1.10617e-06 -3.47421e-02
}
Double_t result = g2(x,p1) + g2(x,p2) + g2(x,p3);
}
void fit2() {
{100,-3,3,-3,3,160,0,0.8,0,0.9,40,4,0.7,4,0.7};
TF2 *f2 =
new TF2(
"f2",fun2,-10,10,-10,10, npar);
TH2F *h2 =
new TH2F(
"h2",
"from f2",40,-10,10,40,-10,10);
f2params[ 0] *= ratio;
f2params[ 5] *= ratio;
f2params[10] *= ratio;
}
- Author
- Rene Brun
Definition in file fit2.C.