10 #include "FairRunAna.h"
13 #include "Math/IFunction.h"
14 #include "Minuit2/Minuit2Minimizer.h"
42 double Calculate(
double x,
double y,
double c[])
const {
return c[0]; }
72 return c[0] + c[1] *
x + c[2] *
y;
103 return c[0] + c[1] *
x + c[2] *
y + c[3] *
x *
x + c[4] *
x *
y
142 return c[0] + c[1] *
x + c[2] *
y + c[3] * x2 + c[4] *
x *
y + c[5] * y2
143 + c[6] * x3 + c[7] * x2y + c[8] * xy2 + c[9] * y3;
187 double x2y2 = x2 * y2;
190 return c[0] + c[1] *
x + c[2] *
y + c[3] * x2 + c[4] * xy + c[5] * y2
191 + c[6] * x3 + c[7] * x2y + c[8] * xy2 + c[9] * y3 + c[10] * x4
192 + c[11] * x3y + c[12] * x2y2 + c[13] * xy3 + c[14] * y4;
236 double x2y2 = x2 * y2;
242 double x2y3 = x2 * y3;
243 double x3y2 = x3 * y2;
246 return c[0] + c[1] *
x + c[2] *
y + c[3] * x2 + c[4] * xy + c[5] * y2
247 + c[6] * x3 + c[7] * x2y + c[8] * xy2 + c[9] * y3 + c[10] * x4
248 + c[11] * x3y + c[12] * x2y2 + c[13] * xy3 + c[14] * y4 + c[15] * x5
249 + c[16] * x4y + c[17] * x3y2 + c[18] * x2y3 + c[19] * xy4
294 double x2y2 = x2 * y2;
300 double x2y3 = x2 * y3;
301 double x3y2 = x3 * y2;
307 double x2y4 = x2 * y4;
308 double x3y3 = x3 * y3;
309 double x4y2 = x4 * y2;
312 return c[0] + c[1] *
x + c[2] *
y + c[3] * x2 + c[4] * xy + c[5] * y2
313 + c[6] * x3 + c[7] * x2y + c[8] * xy2 + c[9] * y3 + c[10] * x4
314 + c[11] * x3y + c[12] * x2y2 + c[13] * xy3 + c[14] * y4 + c[15] * x5
315 + c[16] * x4y + c[17] * x3y2 + c[18] * x2y3 + c[19] * xy4
316 + c[20] * y5 + c[21] * x6 + c[22] * x5y + c[23] * x4y2 + c[24] * x3y3
317 + c[25] * x2y4 + c[26] * xy5 + c[27] * y6;
361 double x2y2 = x2 * y2;
367 double x2y3 = x2 * y3;
368 double x3y2 = x3 * y2;
374 double x2y4 = x2 * y4;
375 double x3y3 = x3 * y3;
376 double x4y2 = x4 * y2;
382 double x2y5 = x2 * y5;
383 double x3y4 = x3 * y4;
384 double x4y3 = x4 * y3;
385 double x5y2 = x5 * y2;
388 return c[0] + c[1] *
x + c[2] *
y + c[3] * x2 + c[4] * xy + c[5] * y2
389 + c[6] * x3 + c[7] * x2y + c[8] * xy2 + c[9] * y3 + c[10] * x4
390 + c[11] * x3y + c[12] * x2y2 + c[13] * xy3 + c[14] * y4 + c[15] * x5
391 + c[16] * x4y + c[17] * x3y2 + c[18] * x2y3 + c[19] * xy4
392 + c[20] * y5 + c[21] * x6 + c[22] * x5y + c[23] * x4y2 + c[24] * x3y3
393 + c[25] * x2y4 + c[26] * xy5 + c[27] * y6 + c[28] * x7 + c[29] * x6y
394 + c[30] * x5y2 + c[31] * x4y3 + c[32] * x3y4 + c[33] * x2y5
395 + c[34] * xy6 + c[35] * y7;
439 double x2y2 = x2 * y2;
445 double x2y3 = x2 * y3;
446 double x3y2 = x3 * y2;
452 double x2y4 = x2 * y4;
453 double x3y3 = x3 * y3;
454 double x4y2 = x4 * y2;
460 double x2y5 = x2 * y5;
461 double x3y4 = x3 * y4;
462 double x4y3 = x4 * y3;
463 double x5y2 = x5 * y2;
469 double x2y6 = x2 * y6;
470 double x3y5 = x3 * y5;
471 double x4y4 = x4 * y4;
472 double x5y3 = x5 * y3;
473 double x6y2 = x6 * y2;
476 return c[0] + c[1] *
x + c[2] *
y + c[3] * x2 + c[4] * xy + c[5] * y2
477 + c[6] * x3 + c[7] * x2y + c[8] * xy2 + c[9] * y3 + c[10] * x4
478 + c[11] * x3y + c[12] * x2y2 + c[13] * xy3 + c[14] * y4 + c[15] * x5
479 + c[16] * x4y + c[17] * x3y2 + c[18] * x2y3 + c[19] * xy4
480 + c[20] * y5 + c[21] * x6 + c[22] * x5y + c[23] * x4y2 + c[24] * x3y3
481 + c[25] * x2y4 + c[26] * xy5 + c[27] * y6 + c[28] * x7 + c[29] * x6y
482 + c[30] * x5y2 + c[31] * x4y3 + c[32] * x3y4 + c[33] * x2y5
483 + c[34] * xy6 + c[35] * y7 + c[36] * x8 + c[37] * x7y + c[38] * x6y2
484 + c[39] * x5y3 + c[40] * x4y4 + c[41] * x3y5 + c[42] * x2y6
485 + c[43] * xy7 + c[44] * y8;
529 double x2y2 = x2 * y2;
535 double x2y3 = x2 * y3;
536 double x3y2 = x3 * y2;
542 double x2y4 = x2 * y4;
543 double x3y3 = x3 * y3;
544 double x4y2 = x4 * y2;
550 double x2y5 = x2 * y5;
551 double x3y4 = x3 * y4;
552 double x4y3 = x4 * y3;
553 double x5y2 = x5 * y2;
559 double x2y6 = x2 * y6;
560 double x3y5 = x3 * y5;
561 double x4y4 = x4 * y4;
562 double x5y3 = x5 * y3;
563 double x6y2 = x6 * y2;
569 double x2y7 = x2 * y7;
570 double x3y6 = x3 * y6;
571 double x4y5 = x4 * y5;
572 double x5y4 = x5 * y4;
573 double x6y3 = x6 * y3;
574 double x7y2 = x7 * y2;
577 return c[0] + c[1] *
x + c[2] *
y + c[3] * x2 + c[4] * xy + c[5] * y2
578 + c[6] * x3 + c[7] * x2y + c[8] * xy2 + c[9] * y3 + c[10] * x4
579 + c[11] * x3y + c[12] * x2y2 + c[13] * xy3 + c[14] * y4 + c[15] * x5
580 + c[16] * x4y + c[17] * x3y2 + c[18] * x2y3 + c[19] * xy4
581 + c[20] * y5 + c[21] * x6 + c[22] * x5y + c[23] * x4y2 + c[24] * x3y3
582 + c[25] * x2y4 + c[26] * xy5 + c[27] * y6 + c[28] * x7 + c[29] * x6y
583 + c[30] * x5y2 + c[31] * x4y3 + c[32] * x3y4 + c[33] * x2y5
584 + c[34] * xy6 + c[35] * y7 + c[36] * x8 + c[37] * x7y + c[38] * x6y2
585 + c[39] * x5y3 + c[40] * x4y4 + c[41] * x3y5 + c[42] * x2y6
586 + c[43] * xy7 + c[44] * y8 + c[45] * x9 + c[46] * x8y + c[47] * x7y2
587 + c[48] * x6y3 + c[49] * x5y4 + c[50] * x4y5 + c[51] * x3y6
588 + c[52] * x2y7 + c[53] * xy8 + c[54] * y9;
631 double x2y2 = x2 * y2;
637 double x2y3 = x2 * y3;
638 double x3y2 = x3 * y2;
644 double x2y4 = x2 * y4;
645 double x3y3 = x3 * y3;
646 double x4y2 = x4 * y2;
652 double x2y5 = x2 * y5;
653 double x3y4 = x3 * y4;
654 double x4y3 = x4 * y3;
655 double x5y2 = x5 * y2;
661 double x2y6 = x2 * y6;
662 double x3y5 = x3 * y5;
663 double x4y4 = x4 * y4;
664 double x5y3 = x5 * y3;
665 double x6y2 = x6 * y2;
671 double x2y7 = x2 * y7;
672 double x3y6 = x3 * y6;
673 double x4y5 = x4 * y5;
674 double x5y4 = x5 * y4;
675 double x6y3 = x6 * y3;
676 double x7y2 = x7 * y2;
682 double x2y8 = x2 * y8;
683 double x3y7 = x3 * y7;
684 double x4y6 = x4 * y6;
685 double x5y5 = x5 * y5;
686 double x6y4 = x6 * y4;
687 double x7y3 = x7 * y3;
688 double x8y2 = x8 * y2;
691 return c[0] + c[1] *
x + c[2] *
y + c[3] * x2 + c[4] * xy + c[5] * y2
692 + c[6] * x3 + c[7] * x2y + c[8] * xy2 + c[9] * y3 + c[10] * x4
693 + c[11] * x3y + c[12] * x2y2 + c[13] * xy3 + c[14] * y4 + c[15] * x5
694 + c[16] * x4y + c[17] * x3y2 + c[18] * x2y3 + c[19] * xy4
695 + c[20] * y5 + c[21] * x6 + c[22] * x5y + c[23] * x4y2 + c[24] * x3y3
696 + c[25] * x2y4 + c[26] * xy5 + c[27] * y6 + c[28] * x7 + c[29] * x6y
697 + c[30] * x5y2 + c[31] * x4y3 + c[32] * x3y4 + c[33] * x2y5
698 + c[34] * xy6 + c[35] * y7 + c[36] * x8 + c[37] * x7y + c[38] * x6y2
699 + c[39] * x5y3 + c[40] * x4y4 + c[41] * x3y5 + c[42] * x2y6
700 + c[43] * xy7 + c[44] * y8 + c[45] * x9 + c[46] * x8y + c[47] * x7y2
701 + c[48] * x6y3 + c[49] * x5y4 + c[50] * x4y5 + c[51] * x3y6
702 + c[52] * x2y7 + c[53] * xy8 + c[54] * y9 + c[55] * x10 + c[56] * x9y
703 + c[57] * x8y2 + c[58] * x7y3 + c[59] * x6y4 + c[60] * x5y5
704 + c[61] * x4y6 + c[62] * x3y7 + c[63] * x2y8 + c[64] * xy9
721 class FCNPolynom :
public ROOT::Math::IBaseFunctionMultiDim {
727 const std::vector<double>&
y,
728 const std::vector<double>& z,
740 virtual double Up()
const {
return 1.; }
750 double* p =
const_cast<double*
>(
x);
752 for (
unsigned int i = 0;
i <
fX.size();
i++) {
768 ROOT::Math::IBaseFunctionMultiDim*
Clone()
const {
779 std::vector<double>
fX;
780 std::vector<double>
fY;
781 std::vector<double>
fZ;
791 , fUseEllipseAcc(true)
792 , fPolynomDegree(polynomDegree) {
793 fField = FairRunAna::Instance()->GetField();
795 switch (polynomDegree) {
815 std::vector<double> aparBx, aparBy, aparBz;
816 FitSlice(Z, aparBx, aparBy, aparBz);
818 std::vector<T> aparBxT, aparByT, aparBzT;
819 aparBxT.assign(aparBx.begin(), aparBx.end());
820 aparByT.assign(aparBy.begin(), aparBy.end());
821 aparBzT.assign(aparBz.begin(), aparBz.end());
830 FitSlice<fscal>(Z, slice);
835 FitSlice<fvec>(Z, slice);
839 std::vector<double>& parBx,
840 std::vector<double>& parBy,
841 std::vector<double>& parBz) {
842 double tanXangle = std::tan(
fXangle * 3.14159265 / 180.);
843 double tanYangle = std::tan(
fYangle * 3.14159265 / 180.);
845 double Xmax = Z * tanXangle;
846 double Ymax = Z * tanYangle;
848 std::cout <<
"Fit slice. Xmax=" << Xmax <<
" Ymax=" << Ymax <<
" Z=" << Z
853 std::vector<double>
x;
854 std::vector<double>
y;
855 std::vector<double> Bx;
856 std::vector<double> By;
857 std::vector<double> Bz;
859 double X = -Xmax + j * HX;
861 double Y = -Ymax + k * HY;
865 double el = (X * X) / (Xmax * Xmax) + (Y * Y) / (Ymax * Ymax);
866 if (el > 1.) {
continue; }
870 double pos[3] = {X, Y, Z};
887 const std::vector<double>&
y,
888 const std::vector<double>& z,
889 std::vector<double>& par) {
893 ROOT::Minuit2::Minuit2Minimizer theMinuit;
895 theMinuit.SetPrintLevel(-1);
896 theMinuit.SetFunction(*theFCN);
899 for (
int i = 0;
i < nofParams;
i++) {
900 std::string ss =
"c" + Cbm::ToString<int>(
i);
901 theMinuit.SetVariable(
i, ss.c_str(), 0., 0.1);
902 theMinuit.SetVariableLimits(
i, 1., -1.);
905 theMinuit.Minimize();
907 const double* fitResults = theMinuit.X();
910 for (
int i = 0;
i < nofParams;
i++) {
911 par.push_back(fitResults[
i]);
918 std::vector<double>& parBx,
919 std::vector<double>& parBy,
920 std::vector<double>& parBz) {
922 const int N = (M + 1) * (M + 2) / 2;
924 double tanXangle = std::tan(
fXangle * 3.14159265 / 180);
925 double tanYangle = std::tan(
fYangle * 3.14159265 / 180);
927 double Xmax = Z * tanXangle;
928 double Ymax = Z * tanYangle;
933 if (dx > Xmax / N / 2) { dx = Xmax / N / 4.; }
934 if (dy > Ymax / N / 2) { dy = Ymax / N / 4.; }
945 TVectorD b0(N), b1(N), b2(N);
949 for (
int i = 0;
i < N;
i++) {
950 for (
int j = 0; j < N; j++) {
953 b0(
i) = b1(
i) = b2(
i) = 0.;
955 for (
double x = -Xmax;
x <= Xmax;
x += dx) {
956 for (
double y = -Ymax;
y <= Ymax;
y += dy) {
959 if (r > 1.) {
continue; }
960 Double_t w = 1. / (r * r + 1);
961 Double_t p[3] = {
x,
y, Z};
962 Double_t B[3] = {0., 0., 0.};
963 FairRunAna::Instance()->GetField()->GetFieldValue(p, B);
966 for (
int i = 1;
i <= M;
i++) {
967 int k = (
i - 1) * (
i) / 2;
968 int l =
i * (
i + 1) / 2;
969 for (
int j = 0; j <
i; j++) {
970 m(l + j) =
x *
m(k + j);
972 m(l +
i) =
y *
m(k +
i - 1);
976 for (
int i = 0;
i < N;
i++) {
977 for (
int j = 0; j < N; j++) {
978 A(
i, j) += w *
m(
i) *
m(j);
980 b0(
i) += w * B[0] *
m(
i);
981 b1(
i) += w * B[1] *
m(
i);
982 b2(
i) += w * B[2] *
m(
i);
988 TVectorD c0 = A * b0, c1 = A * b1, c2 = A * b2;
994 for (
int i = 0;
i < N;
i++) {
995 parBx.push_back(c0(
i));
996 parBy.push_back(c1(
i));
997 parBz.push_back(c2(
i));