815{
816 int i, j, nf, nvar;
817 int itelim = 0;
818
819 int nstillgood;
820
821 double sum;
822
823 double step[150];
824
825 double trackpars[2*mlocal];
826
827 int ntotal_start, ntotal;
828
829 cout << "..... Making global fit ....." << endl;
830
832
833 std::vector<double> track_slopes;
834
835 track_slopes.resize(2*ntotal_start);
836
837 for (i=0; i<2*ntotal_start; i++) track_slopes[i] = 0.;
838
839 if (itert <= 1) itelim=10;
840
841 while (itert < itelim)
842 {
843 if (
debug_mode) cout <<
"ITERATION --> " << itert << endl;
844
846 cout << "...using " << ntotal << " tracks..." << endl;
847
848
849
850 for (i=0; i<nagb; i++) {diag[i] = cgmat[i][i];}
851
852
853
854 nf = 0;
855
856 for (i=0; i<nagb; i++)
857 {
858 if (psigm[i] <= 0.0)
859 {
860 nf++;
861
862 for (j=0; j<nagb; j++)
863 {
864 cgmat[i][j] = 0.0;
865 cgmat[j][i] = 0.0;
866 }
867 }
868 else if (psigm[i] > 0.0)
869 {
870 cgmat[i][i] += 1.0/(psigm[i]*psigm[i]);
871 }
872 }
873
874 nvar = nagb;
875 if (
debug_mode) cout <<
"Number of constraint equations : " << ncs << endl;
876
877 if (ncs > 0)
878 {
879 for (i=0; i<ncs; i++)
880 {
881 sum = arhs[i];
882 for (j=0; j<nagb; j++)
883 {
884 cgmat[nvar][j] = float(ntotal)*adercs[i][j];
885 cgmat[j][nvar] = float(ntotal)*adercs[i][j];
886 sum -= adercs[i][j]*(pparm[j]+dparm[j]);
887 }
888
889 cgmat[nvar][nvar] = 0.0;
890 bgvec[nvar] = float(ntotal)*sum;
891 nvar++;
892 }
893 }
894
895
896
897
898 double final_cor = 0.0;
899
900 if (itert > 1)
901 {
902 for (j=0; j<nagb; j++)
903 {
904 for (i=0; i<nagb; i++)
905 {
906 if (psigm[i] > 0.0)
907 {
908 final_cor += step[j]*cgmat[j][i]*step[i];
909 if (i == j) final_cor -= step[i]*step[i]/(psigm[i]*psigm[i]);
910 }
911 }
912 }
913 }
914
915 cout << " Final coeff is " << final_cor << endl;
916 cout << " Final NDOFs = " << nagb << endl;
917
918
919
920 nrank = Millepede::SpmInv(cgmat, bgvec, nvar, scdiag, scflag);
921
922 for (i=0; i<nagb; i++)
923 {
924 dparm[i] += bgvec[i];
925 if (
verbose_mode) cout <<
"dparm[" << i <<
"] = " << dparm[i] << endl;
926 if (
verbose_mode) cout <<
"cgmat[" << i <<
"][" << i <<
"] = " << cgmat[i][i] << endl;
927 if (
verbose_mode) cout <<
"err = " << sqrt(fabs(cgmat[i][i])) << endl;
928
929 step[i] = bgvec[i];
930
931 if (itert == 1)
error[i] = cgmat[i][i];
932 }
933
934 cout << "" << endl;
935 cout << "The rank defect of the symmetric " << nvar << " by " << nvar
936 << " matrix is " << nvar-nf-nrank << " (bad if non 0)" << endl;
937
938 if (itert == 0) break;
939 itert++;
940
941 cout << "" << endl;
942 cout << "Total : " << loctot << " local fits, "
943 << locrej << " rejected." << endl;
944
945
946
947 loctot = 0;
948 locrej = 0;
949
950 if (cfactr != cfactref && sqrt(cfactr) > 1.2*cfactref)
951 {
952 cfactr = sqrt(cfactr);
953 }
954 else
955 {
956 cfactr = cfactref;
957
958 }
959
960 if (itert == itelim) break;
961
962 cout << "Iteration " << itert << " with cut factor " << cfactr << endl;
963
964
965
966 for (i=0; i<nvar; i++)
967 {
968 bgvec[i] = 0.0;
969 for (j=0; j<nvar; j++)
970 {
971 cgmat[i][j] = 0.0;
972 }
973 }
974
975
976
977
978
979
980
981 nstillgood = 0;
982
983 for (i=0; i<ntotal_start; i++)
984 {
985 int rank_i = 0;
986 int rank_f = 0;
987
988 (i>0) ? rank_i =
abs(storeplace[i-1]) : rank_i = 0;
989 rank_f = storeplace[i];
990
991 if (
verbose_mode) cout <<
"Track " << i <<
" : " << endl;
992 if (
verbose_mode) cout <<
"Starts at " << rank_i << endl;
994
995 if (rank_f >= 0)
996 {
997
998 if (itert > 3)
999 {
1000 indst.clear();
1001 arest.clear();
1002
1003 for (j=rank_i; j<rank_f; j++)
1004 {
1005 indst.push_back(storeind[j]);
1006
1007 if (storenl[j] == 0) arest.push_back(storeare[j]);
1008 if (storenl[j] == 1) arest.push_back(track_slopes[2*i]*storeare[j]);
1009 if (storenl[j] == 2) arest.push_back(track_slopes[2*i+1]*storeare[j]);
1010 }
1011
1012 for (j=0; j<2*nalc; j++) {trackpars[j] = 0.;}
1013
1015
1016 track_slopes[2*i] = trackpars[2];
1017 track_slopes[2*i+1] = trackpars[6];
1018 }
1019
1020 indst.clear();
1021 arest.clear();
1022
1023 for (j=rank_i; j<rank_f; j++)
1024 {
1025 indst.push_back(storeind[j]);
1026
1027 if (storenl[j] == 0) arest.push_back(storeare[j]);
1028 if (storenl[j] == 1) arest.push_back(track_slopes[2*i]*storeare[j]);
1029 if (storenl[j] == 2) arest.push_back(track_slopes[2*i+1]*storeare[j]);
1030 }
1031
1032 for (j=0; j<2*nalc; j++) {trackpars[j] = 0.;}
1033
1035
1036 (sc)
1037 ? nstillgood++
1038 : storeplace[i] = -rank_f;
1039 }
1040 }
1041
1043
1044 }
1045
1046 Millepede::PrtGlo();
1047
1048 for (j=0; j<nagb; j++)
1049 {
1050 par[j] = dparm[j];
1051 dparm[j] = 0.;
1052 pull[j] = par[j]/sqrt(psigm[j]*psigm[j]-cgmat[j][j]);
1053 error[j] = sqrt(fabs(cgmat[j][j]));
1054 }
1055
1056 cout << std::setw(10) << " " << endl;
1057 cout << std::setw(10) << " * o o o " << endl;
1058 cout << std::setw(10) << " o o o " << endl;
1059 cout << std::setw(10) << " o ooooo o o o oo ooo oo ooo oo " << endl;
1060 cout << std::setw(10) << " o o o o o o o o o o o o o o o o " << endl;
1061 cout << std::setw(10) << " o o o o o o oooo o o oooo o o oooo " << endl;
1062 cout << std::setw(10) << " o o o o o o o ooo o o o o " << endl;
1063 cout << std::setw(10) << " o o o o o o oo o oo ooo oo ++ ends." << endl;
1064 cout << std::setw(10) << " o " << endl;
1065
1066 return true;
1067}
double abs(const EvtComplex &c)
bool FitLoc(int n, double track_params[], int single_fit)