CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_8_patch3/src/PhysicsTools/KinFitter/src/TAbsFitConstraint.cc

Go to the documentation of this file.
00001 // Classname: TAbsFitConstraint
00002 // Author: Jan E. Sundermann, Verena Klose (TU Dresden)      
00003 
00004 
00005 //________________________________________________________________
00006 // 
00007 // TAbsFitConstraint::
00008 // --------------------
00009 //
00010 // Abstract base class for fit constraints
00011 //
00012 
00013 #include "PhysicsTools/KinFitter/interface/TAbsFitConstraint.h"
00014 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00015 #include <iostream>
00016 #include <iomanip>
00017 #include "TClass.h"
00018 
00019 
00020 TAbsFitConstraint::TAbsFitConstraint() 
00021   : TNamed("NoName","NoTitle")
00022   ,_covMatrix()
00023   ,_covMatrixFit()
00024   ,_covMatrixDeltaAlpha()
00025   ,_iniparameters()
00026   ,_parameters()
00027 
00028 {
00029   _nPar = 0;
00030 }
00031 
00032 TAbsFitConstraint::TAbsFitConstraint(const TString &name, const TString &title) 
00033   : TNamed(name, title)
00034   ,_covMatrix()
00035   ,_covMatrixFit()
00036   ,_covMatrixDeltaAlpha()
00037   ,_iniparameters()
00038   ,_parameters()
00039 
00040 {
00041   _nPar = 0;
00042 }
00043 
00044 TAbsFitConstraint::~TAbsFitConstraint() {
00045 
00046 }
00047 
00048 void TAbsFitConstraint::reset() {
00049   // Reset parameters to initial values
00050 
00051   _parameters = _iniparameters;  
00052   setCovMatrixFit( 0 );
00053 
00054 }
00055 
00056 void TAbsFitConstraint::setCovMatrix(const TMatrixD* theCovMatrix) {
00057   // Set measured alpha covariance matrix
00058 
00059   _covMatrix.ResizeTo(_nPar, _nPar);
00060   if(theCovMatrix==0) {
00061     _covMatrix.Zero();
00062   } else if (theCovMatrix->GetNcols() ==_nPar && theCovMatrix->GetNrows() ==_nPar) {
00063     _covMatrix = (*theCovMatrix);
00064   } else {
00065     edm::LogError ("WrongMatrixSize")
00066       << GetName() << "::setCovMatrix - Measured alpha covariance matrix needs to be a "
00067       << _nPar << "x" << _nPar << " matrix.";
00068   }
00069 
00070 }
00071 
00072 void TAbsFitConstraint::setCovMatrixFit(const TMatrixD* theCovMatrixFit) {
00073   // Set the fitted covariance matrix
00074 
00075   _covMatrixFit.ResizeTo(_nPar, _nPar);
00076   if(theCovMatrixFit==0) {
00077     _covMatrixFit.Zero();
00078   } else if (theCovMatrixFit->GetNcols() ==_nPar && theCovMatrixFit->GetNrows() ==_nPar) {
00079     _covMatrixFit = (*theCovMatrixFit);
00080   } else {
00081     edm::LogError ("WrongMatrixSize")
00082       << GetName() << "::setCovMatrixFit - Fitted covariance matrix needs to be a "
00083       << _nPar << "x" << _nPar << " matrix.";
00084   }
00085 
00086 }
00087 
00088 void TAbsFitConstraint::calcCovMatrixDeltaAlpha() {
00089   // Calculates V(deltaAlpha) ==  V(alpha_meas) - V(alpha_fit)
00090 
00091   _covMatrixDeltaAlpha.ResizeTo( _nPar, _nPar );
00092   _covMatrixDeltaAlpha = _covMatrix;
00093   if(_covMatrixFit.GetNrows() == _nPar && _covMatrixFit.GetNcols() == _nPar)
00094     _covMatrixDeltaAlpha -= _covMatrixFit;
00095   else
00096     edm::LogError ("WrongMatrixSize")
00097       << GetName() << "::calcCovMatrixDeltaAlpha - _covMatrixFit probably not set.";
00098 }
00099 
00100 
00101 void TAbsFitConstraint::applyDeltaAlpha(TMatrixD* corrMatrix) {
00102   // Apply corrections to the parameters wrt. to the
00103   // initial parameters alpha* = alpha + delta(alpha)
00104 
00105   _parameters = _iniparameters;
00106   _parameters += (*corrMatrix);
00107 
00108 }
00109 
00110 void TAbsFitConstraint::setParIni(const TMatrixD* parini) {
00111   // Set initial parameter values (before the fit)
00112 
00113   if (parini == 0) return;
00114   else if( parini->GetNrows() == _iniparameters.GetNrows() &&
00115            parini->GetNcols() == _iniparameters.GetNcols() )
00116     _iniparameters = (*parini) ;
00117   else {
00118     edm::LogError ("WrongMatrixSize")
00119       << GetName() << "::setParIni - Matrices don't fit.";
00120     return;
00121   }
00122 
00123 }
00124 
00125 const TMatrixD* TAbsFitConstraint::getCovMatrixDeltaAlpha() {
00126   // Returns covariance matrix delta(alpha)
00127 
00128   calcCovMatrixDeltaAlpha(); 
00129   return &_covMatrixDeltaAlpha; 
00130 
00131 }
00132 
00133 TString TAbsFitConstraint::getInfoString() {
00134   // Collect information to be used for printout
00135 
00136   std::stringstream info;
00137   info << std::scientific << std::setprecision(6);
00138 
00139   info << "__________________________" << std::endl
00140        << std::endl;
00141   info <<"OBJ: " << IsA()->GetName() << "\t" << GetName() << "\t" << GetTitle() << std::endl;
00142   
00143   info << "initial value: " << getInitValue() << std::endl;
00144   info << "current value: " << getCurrentValue() << std::endl;
00145 
00146   return info.str();
00147 
00148 }
00149 
00150 void TAbsFitConstraint::print() {
00151   // Print constraint contents
00152 
00153   edm::LogVerbatim("KinFitter") << this->getInfoString();
00154 
00155 }
00156