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