// @(#)root/minuit2:$Id$ // Authors: M. Winkler, F. James, L. Moneta, A. Zsenei 2003-2005 /********************************************************************** * * * Copyright (c) 2005 LCG ROOT Math team, CERN/PH-SFT * * * **********************************************************************/ #include "Minuit2/MnPrint.h" #include "Minuit2/LAVector.h" #include "Minuit2/LASymMatrix.h" #include "Minuit2/FunctionMinimum.h" #include "Minuit2/MnUserParameters.h" #include "Minuit2/MnUserCovariance.h" #include "Minuit2/MnGlobalCorrelationCoeff.h" #include "Minuit2/MnUserParameterState.h" #include "Minuit2/MinuitParameter.h" #include "Minuit2/MnMachinePrecision.h" #include "Minuit2/MinosError.h" #include "Minuit2/ContoursError.h" #include "Minuit2/MnPlot.h" #include #define PRECISION 13 #define WIDTH 20 namespace ROOT { namespace Minuit2 { #ifdef DEBUG int gPrintLevel = 3; #else int gPrintLevel = 0; #endif int MnPrint::SetLevel(int level) { int prevLevel = gPrintLevel; gPrintLevel = level; return prevLevel; } int MnPrint::Level( ) { return gPrintLevel; } void MnPrint::PrintState(std::ostream & os, const MinimumState & state, const char * msg, int iter) { // helper function to print function value, edm and ncalls from state in one single line MnPrint::PrintState(os, state.Fval(), state.Edm(), state.NFcn(), msg, iter); } void MnPrint::PrintState(std::ostream & os, double fval, double edm, int ncalls, const char * msg, int iter) { // helper function to print function value, edm and ncalls and message in one single line os << msg; if (iter>=0) os << std::setw(3) << iter; int pr = os.precision(PRECISION); const int width = PRECISION+3; os << " - FCN = " << std::setw(width) << fval; os.precision(pr); os << " Edm = " << std::setw(12) << edm << " NCalls = " << std::setw(6) << ncalls; os << std::endl; } std::ostream& operator<<(std::ostream& os, const LAVector& vec) { // print a vector os << "LAVector parameters:" << std::endl; int pr = os.precision(PRECISION); { int nrow = vec.size(); for (int i = 0; i < nrow; i++) { os.width(WIDTH); os << vec(i) << std::endl; } } os.precision(pr); return os; } std::ostream& operator<<(std::ostream& os, const LASymMatrix& matrix) { // print a matrix os << "LASymMatrix parameters:" << std::endl; int pr = os.precision(8); { //os << std::endl; int n = matrix.Nrow(); for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { os.width(15); os << matrix(i,j); } os << std::endl; } } os.precision(pr); return os; } std::ostream& operator<<(std::ostream& os, const MnUserParameters& par) { // print the MnUserParameter object os << std::endl; os << "# ext. |" << "| Name |" << "| type |" << "| Value |" << "| Error +/- " << std::endl; os << std::endl; int pr = os.precision(); bool atLoLim = false; bool atHiLim = false; for(std::vector::const_iterator ipar = par.Parameters().begin(); ipar != par.Parameters().end(); ipar++) { os << std::setw(4) << (*ipar).Number() << std::setw(5) << "||"; os << std::setw(10) << (*ipar).Name() << std::setw(3) << "||"; if((*ipar).IsConst()) { os << " const ||" << std::setprecision(PRECISION) << std::setw(WIDTH) << (*ipar).Value() << " ||" << std::endl; } else if((*ipar).IsFixed()) { os << " fixed ||" << std::setprecision(PRECISION) << std::setw(WIDTH) << (*ipar).Value() << " ||" << std::endl; } else if((*ipar).HasLimits()) { if((*ipar).Error() > 0.) { os << " limited ||" << std::setprecision(PRECISION) << std::setw(WIDTH) << (*ipar).Value(); if(fabs((*ipar).Value() - (*ipar).LowerLimit()) < par.Precision().Eps2()) { os <<"*"; atLoLim = true; } if(fabs((*ipar).Value() - (*ipar).UpperLimit()) < par.Precision().Eps2()) { os <<"**"; atHiLim = true; } os << " ||" << std::setw(12) << (*ipar).Error() << std::endl; } else os << " free ||" << std::setprecision(PRECISION) << std::setw(WIDTH) << (*ipar).Value() << " ||" << std::setw(12) << "no" << std::endl; } else { if((*ipar).Error() > 0.) os << " free ||" << std::setprecision(PRECISION) << std::setw(WIDTH) << (*ipar).Value() << " ||" << std::setw(12) << (*ipar).Error() << std::endl; else os << " free ||" << std::setprecision(PRECISION) << std::setw(WIDTH) << (*ipar).Value() << " ||" << std::setw(12) << "no" << std::endl; } } os << std::endl; if(atLoLim) os << "* Parameter is at Lower limit" << std::endl; if(atHiLim) os << "** Parameter is at Upper limit" << std::endl; os << std::endl; os.precision(pr); return os; } std::ostream& operator<<(std::ostream& os, const MnUserCovariance& matrix) { // print the MnUserCovariance os << std::endl; os << "MnUserCovariance: " << std::endl; int pr = os.precision(6); { os << std::endl; unsigned int n = matrix.Nrow(); for (unsigned int i = 0; i < n; i++) { for (unsigned int j = 0; j < n; j++) { os.width(13); os << matrix(i,j); } os << std::endl; } } os << std::endl; os << "MnUserCovariance Parameter correlations: " << std::endl; { os << std::endl; unsigned int n = matrix.Nrow(); for (unsigned int i = 0; i < n; i++) { double di = matrix(i,i); for (unsigned int j = 0; j < n; j++) { double dj = matrix(j,j); os.width(13); os << matrix(i,j)/sqrt(fabs(di*dj)); } os << std::endl; } } os.precision(pr); return os; } std::ostream& operator<<(std::ostream& os, const MnGlobalCorrelationCoeff& coeff) { // print the global correlation coefficient os << std::endl; os << "MnGlobalCorrelationCoeff: " << std::endl; int pr = os.precision(6); { os << std::endl; for (unsigned int i = 0; i < coeff.GlobalCC().size(); i++) { os.width(13); os << coeff.GlobalCC()[i]; os << std::endl; } } os.precision(pr); return os; } std::ostream& operator<<(std::ostream& os, const MnUserParameterState& state) { // print the MnUserParameterState os << std::endl; if(!state.IsValid()) { os << std::endl; os <<"WARNING: MnUserParameterState is not valid."< >::const_iterator ipar = ce().begin(); ipar != ce().end(); ipar++) { os << ipar - ce().begin() <<" "<< (*ipar).first <<" "<< (*ipar).second <