MnPrint.cxx

Go to the documentation of this file.
00001 // @(#)root/minuit2:$Id: MnPrint.cxx 35508 2010-09-21 08:23:57Z moneta $
00002 // Authors: M. Winkler, F. James, L. Moneta, A. Zsenei   2003-2005  
00003 
00004 /**********************************************************************
00005  *                                                                    *
00006  * Copyright (c) 2005 LCG ROOT Math team,  CERN/PH-SFT                *
00007  *                                                                    *
00008  **********************************************************************/
00009 
00010 #include "Minuit2/MnPrint.h"
00011 #include "Minuit2/LAVector.h"
00012 #include "Minuit2/LASymMatrix.h"
00013 #include "Minuit2/FunctionMinimum.h"
00014 #include "Minuit2/MnUserParameters.h"
00015 #include "Minuit2/MnUserCovariance.h"
00016 #include "Minuit2/MnGlobalCorrelationCoeff.h"
00017 #include "Minuit2/MnUserParameterState.h"
00018 #include "Minuit2/MinuitParameter.h"
00019 #include "Minuit2/MnMachinePrecision.h"
00020 #include "Minuit2/MinosError.h"
00021 #include "Minuit2/ContoursError.h"
00022 #include "Minuit2/MnPlot.h"
00023 
00024 #include <iomanip>
00025 
00026 #define PRECISION 13
00027 #define WIDTH     20
00028 
00029 namespace ROOT {
00030 
00031    namespace Minuit2 {
00032 
00033 
00034 std::ostream& operator<<(std::ostream& os, const LAVector& vec) {
00035    // print a vector
00036    os << "LAVector parameters:" << std::endl;
00037    int pr = os.precision(PRECISION);
00038    { 
00039       int nrow = vec.size();
00040       for (int i = 0; i < nrow; i++) {
00041          os.width(WIDTH); 
00042          os << vec(i) << std::endl;
00043       }
00044    }
00045    os.precision(pr);
00046    return os;
00047 }
00048 
00049 std::ostream& operator<<(std::ostream& os, const LASymMatrix& matrix) {
00050    // print a matrix
00051    os << "LASymMatrix parameters:" << std::endl;
00052    int pr = os.precision(8);
00053    { 
00054       //os << std::endl;
00055       int n = matrix.Nrow();
00056       for (int i = 0; i < n; i++) {
00057          for (int j = 0; j < n; j++) {
00058             os.width(15); os << matrix(i,j);
00059          }
00060          os << std::endl;
00061       }
00062    }
00063    os.precision(pr);
00064    return os;
00065 }
00066 
00067 std::ostream& operator<<(std::ostream& os, const MnUserParameters& par) {
00068    // print the MnUserParameter object
00069    os << std::endl;
00070    
00071    os << "# ext. |" << "|   Name    |" << "|   type  |" << "|     Value     |" << "|  Error +/- " << std::endl;
00072    
00073    os << std::endl;
00074    int pr = os.precision();
00075    
00076    bool atLoLim = false;
00077    bool atHiLim = false;
00078    for(std::vector<MinuitParameter>::const_iterator ipar = par.Parameters().begin(); ipar != par.Parameters().end(); ipar++) {
00079       os << std::setw(4) << (*ipar).Number() << std::setw(5) << "||"; 
00080       os << std::setw(10) << (*ipar).Name()   << std::setw(3) << "||";
00081       if((*ipar).IsConst()) {
00082          os << "  const  ||" << std::setprecision(PRECISION) << std::setw(WIDTH) << (*ipar).Value() << " ||" << std::endl;
00083       } else if((*ipar).IsFixed()) {
00084          os << "  fixed  ||" << std::setprecision(PRECISION) << std::setw(WIDTH) << (*ipar).Value() << " ||" << std::endl;
00085       } else if((*ipar).HasLimits()) {
00086          if((*ipar).Error() > 0.) {
00087             os << " limited ||" << std::setprecision(PRECISION) << std::setw(WIDTH) << (*ipar).Value();
00088             if(fabs((*ipar).Value() - (*ipar).LowerLimit()) < par.Precision().Eps2()) {
00089                os <<"*";
00090                atLoLim = true;
00091             }
00092             if(fabs((*ipar).Value() - (*ipar).UpperLimit()) < par.Precision().Eps2()) {
00093                os <<"**";
00094                atHiLim = true;
00095             }
00096             os << " ||" << std::setw(12) << (*ipar).Error() << std::endl;
00097          } else
00098             os << "  free   ||" << std::setprecision(PRECISION) << std::setw(WIDTH) << (*ipar).Value() << " ||" << std::setw(12) << "no" << std::endl;
00099       } else {
00100          if((*ipar).Error() > 0.)
00101             os << "  free   ||" << std::setprecision(PRECISION) << std::setw(WIDTH) << (*ipar).Value() << " ||" << std::setw(12) << (*ipar).Error() << std::endl;
00102          else
00103             os << "  free   ||" << std::setprecision(PRECISION) << std::setw(WIDTH) << (*ipar).Value() << " ||" << std::setw(12) << "no" << std::endl;
00104          
00105       }
00106    }
00107    os << std::endl;
00108    if(atLoLim) os << "* Parameter is at Lower limit" << std::endl;
00109    if(atHiLim) os << "** Parameter is at Upper limit" << std::endl;
00110    os << std::endl;
00111    os.precision(pr);
00112    
00113    return os;
00114 }
00115 
00116 std::ostream& operator<<(std::ostream& os, const MnUserCovariance& matrix) {
00117    // print the MnUserCovariance
00118    os << std::endl;
00119    
00120    os << "MnUserCovariance: " << std::endl;
00121    int pr = os.precision(6);
00122    { 
00123       os << std::endl;
00124       unsigned int n = matrix.Nrow();
00125       for (unsigned int i = 0; i < n; i++) {
00126          for (unsigned int j = 0; j < n; j++) {
00127             os.width(13); os << matrix(i,j);
00128          }
00129          os << std::endl;
00130       }
00131    }
00132 
00133    os << std::endl;
00134    os << "MnUserCovariance Parameter correlations: " << std::endl;
00135    
00136    { 
00137       os << std::endl;
00138       unsigned int n = matrix.Nrow();
00139       for (unsigned int i = 0; i < n; i++) {
00140          double di = matrix(i,i);
00141          for (unsigned int j = 0; j < n; j++) {
00142             double dj = matrix(j,j);    
00143             os.width(13); os << matrix(i,j)/sqrt(fabs(di*dj));
00144          }
00145          os << std::endl;
00146       }
00147    }
00148    
00149    os.precision(pr);
00150    return os;   
00151 }
00152 
00153 std::ostream& operator<<(std::ostream& os, const MnGlobalCorrelationCoeff& coeff) {
00154    // print the global correlation coefficient
00155    os << std::endl;
00156    
00157    os << "MnGlobalCorrelationCoeff: " << std::endl;
00158    int pr =  os.precision(6);
00159    { 
00160       os << std::endl;
00161       for (unsigned int i = 0; i < coeff.GlobalCC().size(); i++) {
00162          os.width(13); os << coeff.GlobalCC()[i];
00163          os << std::endl;
00164       }
00165    }
00166    
00167    os.precision(pr);
00168    return os;   
00169 }
00170 
00171 std::ostream& operator<<(std::ostream& os, const MnUserParameterState& state) {
00172    // print the MnUserParameterState
00173    os << std::endl;
00174    
00175    if(!state.IsValid()) {
00176       os << std::endl;
00177       os <<"WARNING: MnUserParameterState is not valid."<<std::endl;
00178       os << std::endl;
00179    }
00180    int pr = os.precision(PRECISION);
00181    
00182    os <<"# of function calls: "<<state.NFcn()<<std::endl;
00183    os <<"function Value: " << state.Fval()<<std::endl;
00184    os <<"expected distance to the Minimum (edm): " << state.Edm()<<std::endl;
00185    os <<"external parameters: "<<state.Parameters()<<std::endl;
00186    if(state.HasCovariance())
00187       os <<"covariance matrix: "<<state.Covariance()<<std::endl;
00188    if(state.HasGlobalCC()) 
00189       os <<"global correlation coefficients : "<<state.GlobalCC()<<std::endl;
00190    
00191    if(!state.IsValid())
00192       os <<"WARNING: MnUserParameterState is not valid."<<std::endl;
00193    
00194    os << std::endl;
00195    os.precision(pr);
00196 
00197    return os;
00198 } 
00199 
00200 std::ostream& operator<<(std::ostream& os, const FunctionMinimum& min) {
00201    // print the FunctionMinimum
00202    os << std::endl;
00203    if(!min.IsValid()) {
00204       os <<"WARNING: Minuit did not converge."<<std::endl;
00205       os << std::endl;
00206    } else {
00207       os <<"Minuit did successfully converge."<<std::endl;
00208    }
00209    int pr = os.precision(PRECISION);
00210    
00211    os <<"# of function calls: "<<min.NFcn()<<std::endl;
00212    os <<"minimum function Value: "  << min.Fval()<<std::endl;
00213    os <<"minimum edm: "  << min.Edm()<<std::endl;
00214    os <<"minimum internal state vector: "<<min.Parameters().Vec()<<std::endl;
00215    if(min.HasValidCovariance()) 
00216       os <<"minimum internal covariance matrix: "<<min.Error().Matrix()<<std::endl;
00217    
00218    os << min.UserParameters() << std::endl;
00219    //os << min.UserCovariance() << std::endl;
00220    //os << min.UserState().GlobalCC() << std::endl;
00221    
00222    if(!min.IsValid())
00223       os <<"WARNING: FunctionMinimum is invalid."<<std::endl;
00224    
00225    os << std::endl;
00226    os.precision(pr);
00227 
00228    return os;
00229 }
00230 
00231 std::ostream& operator<<(std::ostream& os, const MinimumState& min) {
00232    
00233    os << std::endl;
00234    int pr = os.precision(PRECISION);
00235    
00236    os <<"minimum function Value: "  << min.Fval()<<std::endl;
00237    os <<"minimum edm: " << min.Edm()<<std::endl;
00238    os <<"minimum internal state vector: "<<min.Vec()<<std::endl;
00239    os <<"minimum internal Gradient vector: "<<min.Gradient().Vec()<<std::endl;
00240    if(min.HasCovariance()) 
00241       os <<"minimum internal covariance matrix: "<<min.Error().Matrix()<<std::endl;
00242    
00243    os << std::endl;
00244    os.precision(pr);
00245 
00246    return os;
00247 }
00248 
00249 std::ostream& operator<<(std::ostream& os, const MnMachinePrecision& prec) {
00250    // print the Precision
00251    os << std::endl;
00252    
00253    int pr = os.precision(PRECISION);
00254    os <<"current machine precision is set to "<<prec.Eps()<<std::endl;
00255    
00256    os << std::endl;
00257    os.precision(pr);
00258    
00259    return os;
00260 }
00261 
00262 std::ostream& operator<<(std::ostream& os, const MinosError& me) {
00263    // print the Minos Error
00264    os << std::endl;
00265    
00266    os <<"Minos # of function calls: "<<me.NFcn()<<std::endl;
00267    
00268    if(!me.IsValid())
00269       os << "Minos Error is not valid." <<std::endl;
00270    if(!me.LowerValid())
00271       os << "lower Minos Error is not valid." <<std::endl;
00272    if(!me.UpperValid())
00273       os << "upper Minos Error is not valid." <<std::endl;
00274    if(me.AtLowerLimit())
00275       os << "Minos Error is Lower limit of Parameter "<<me.Parameter()<<"." <<std::endl;
00276    if(me.AtUpperLimit())
00277       os << "Minos Error is Upper limit of Parameter "<<me.Parameter()<<"." <<std::endl;
00278    if(me.AtLowerMaxFcn())
00279       os << "Minos number of function calls for Lower Error exhausted."<<std::endl;
00280    if(me.AtUpperMaxFcn())
00281       os << "Minos number of function calls for Upper Error exhausted."<<std::endl;
00282    if(me.LowerNewMin()) {
00283       os << "Minos found a new Minimum in negative direction."<<std::endl;
00284       os << me.LowerState() <<std::endl;
00285    }
00286    if(me.UpperNewMin()) {
00287       os << "Minos found a new Minimum in positive direction."<<std::endl;
00288       os << me.UpperState() <<std::endl;
00289    }
00290 
00291    int pr = os.precision();
00292    
00293    os << "# ext. |" << "|   Name    |" << "|   Value@min   |" << "|    negative   |" << "|   positive  " << std::endl;
00294    os << std::setw(4) << me.Parameter() << std::setw(5) << "||"; 
00295    os << std::setw(10) << me.LowerState().Name(me.Parameter()) << std::setw(3) << "||";
00296    os << std::setprecision(PRECISION) << std::setw(WIDTH) << me.Min() << " ||" << std::setprecision(PRECISION) << std::setw(WIDTH) << me.Lower() << " ||" << std::setw(WIDTH) << me.Upper() << std::endl;
00297    
00298    os << std::endl;
00299    os.precision(pr);
00300 
00301    return os;
00302 }
00303 
00304 std::ostream& operator<<(std::ostream& os, const ContoursError& ce) {
00305    // print the ContoursError
00306    os << std::endl;
00307    os <<"Contours # of function calls: "<<ce.NFcn()<<std::endl;
00308    os << "MinosError in x: "<<std::endl;
00309    os << ce.XMinosError() << std::endl;
00310    os << "MinosError in y: "<<std::endl;
00311    os << ce.YMinosError() << std::endl;
00312    MnPlot plot;
00313    plot(ce.XMin(), ce.YMin(), ce());
00314    for(std::vector<std::pair<double,double> >::const_iterator ipar = ce().begin(); ipar != ce().end(); ipar++) {
00315       os << ipar - ce().begin() <<"  "<< (*ipar).first <<"  "<< (*ipar).second <<std::endl;
00316    }
00317    os << std::endl;
00318    
00319    return os;
00320 }
00321 
00322    }  // namespace Minuit2
00323 
00324 }  // namespace ROOT

Generated on Tue Jul 5 14:37:10 2011 for ROOT_528-00b_version by  doxygen 1.5.1