Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:23:35

0001 // Classname: TAbsFitConstraint
0002 // Author: Jan E. Sundermann, Verena Klose (TU Dresden)
0003 
0004 //________________________________________________________________
0005 //
0006 // TAbsFitConstraint::
0007 // --------------------
0008 //
0009 // Abstract base class for fit constraints
0010 //
0011 
0012 #include "PhysicsTools/KinFitter/interface/TAbsFitConstraint.h"
0013 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0014 #include <iostream>
0015 #include <iomanip>
0016 #include "TClass.h"
0017 
0018 TAbsFitConstraint::TAbsFitConstraint()
0019     : TNamed("NoName", "NoTitle"),
0020       _covMatrix(),
0021       _covMatrixFit(),
0022       _covMatrixDeltaAlpha(),
0023       _iniparameters(),
0024       _parameters()
0025 
0026 {
0027   _nPar = 0;
0028 }
0029 
0030 TAbsFitConstraint::TAbsFitConstraint(const TString& name, const TString& title)
0031     : TNamed(name, title),
0032       _covMatrix(),
0033       _covMatrixFit(),
0034       _covMatrixDeltaAlpha(),
0035       _iniparameters(),
0036       _parameters()
0037 
0038 {
0039   _nPar = 0;
0040 }
0041 
0042 TAbsFitConstraint::~TAbsFitConstraint() {}
0043 
0044 void TAbsFitConstraint::reset() {
0045   // Reset parameters to initial values
0046 
0047   _parameters = _iniparameters;
0048   setCovMatrixFit(nullptr);
0049 }
0050 
0051 void TAbsFitConstraint::setCovMatrix(const TMatrixD* theCovMatrix) {
0052   // Set measured alpha covariance matrix
0053 
0054   _covMatrix.ResizeTo(_nPar, _nPar);
0055   if (theCovMatrix == nullptr) {
0056     _covMatrix.Zero();
0057   } else if (theCovMatrix->GetNcols() == _nPar && theCovMatrix->GetNrows() == _nPar) {
0058     _covMatrix = (*theCovMatrix);
0059   } else {
0060     edm::LogError("WrongMatrixSize") << GetName() << "::setCovMatrix - Measured alpha covariance matrix needs to be a "
0061                                      << _nPar << "x" << _nPar << " matrix.";
0062   }
0063 }
0064 
0065 void TAbsFitConstraint::setCovMatrixFit(const TMatrixD* theCovMatrixFit) {
0066   // Set the fitted covariance matrix
0067 
0068   _covMatrixFit.ResizeTo(_nPar, _nPar);
0069   if (theCovMatrixFit == nullptr) {
0070     _covMatrixFit.Zero();
0071   } else if (theCovMatrixFit->GetNcols() == _nPar && theCovMatrixFit->GetNrows() == _nPar) {
0072     _covMatrixFit = (*theCovMatrixFit);
0073   } else {
0074     edm::LogError("WrongMatrixSize") << GetName() << "::setCovMatrixFit - Fitted covariance matrix needs to be a "
0075                                      << _nPar << "x" << _nPar << " matrix.";
0076   }
0077 }
0078 
0079 void TAbsFitConstraint::calcCovMatrixDeltaAlpha() {
0080   // Calculates V(deltaAlpha) ==  V(alpha_meas) - V(alpha_fit)
0081 
0082   _covMatrixDeltaAlpha.ResizeTo(_nPar, _nPar);
0083   _covMatrixDeltaAlpha = _covMatrix;
0084   if (_covMatrixFit.GetNrows() == _nPar && _covMatrixFit.GetNcols() == _nPar)
0085     _covMatrixDeltaAlpha -= _covMatrixFit;
0086   else
0087     edm::LogError("WrongMatrixSize") << GetName() << "::calcCovMatrixDeltaAlpha - _covMatrixFit probably not set.";
0088 }
0089 
0090 void TAbsFitConstraint::applyDeltaAlpha(TMatrixD* corrMatrix) {
0091   // Apply corrections to the parameters wrt. to the
0092   // initial parameters alpha* = alpha + delta(alpha)
0093 
0094   _parameters = _iniparameters;
0095   _parameters += (*corrMatrix);
0096 }
0097 
0098 void TAbsFitConstraint::setParIni(const TMatrixD* parini) {
0099   // Set initial parameter values (before the fit)
0100 
0101   if (parini == nullptr)
0102     return;
0103   else if (parini->GetNrows() == _iniparameters.GetNrows() && parini->GetNcols() == _iniparameters.GetNcols())
0104     _iniparameters = (*parini);
0105   else {
0106     edm::LogError("WrongMatrixSize") << GetName() << "::setParIni - Matrices don't fit.";
0107     return;
0108   }
0109 }
0110 
0111 const TMatrixD* TAbsFitConstraint::getCovMatrixDeltaAlpha() {
0112   // Returns covariance matrix delta(alpha)
0113 
0114   calcCovMatrixDeltaAlpha();
0115   return &_covMatrixDeltaAlpha;
0116 }
0117 
0118 TString TAbsFitConstraint::getInfoString() {
0119   // Collect information to be used for printout
0120 
0121   std::stringstream info;
0122   info << std::scientific << std::setprecision(6);
0123 
0124   info << "__________________________" << std::endl << std::endl;
0125   info << "OBJ: " << IsA()->GetName() << "\t" << GetName() << "\t" << GetTitle() << std::endl;
0126 
0127   info << "initial value: " << getInitValue() << std::endl;
0128   info << "current value: " << getCurrentValue() << std::endl;
0129 
0130   return info.str();
0131 }
0132 
0133 void TAbsFitConstraint::print() {
0134   // Print constraint contents
0135 
0136   edm::LogVerbatim("KinFitter") << this->getInfoString();
0137 }