CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
TAbsFitConstraint.cc
Go to the documentation of this file.
1 // Classname: TAbsFitConstraint
2 // Author: Jan E. Sundermann, Verena Klose (TU Dresden)
3 
4 //________________________________________________________________
5 //
6 // TAbsFitConstraint::
7 // --------------------
8 //
9 // Abstract base class for fit constraints
10 //
11 
14 #include <iostream>
15 #include <iomanip>
16 #include "TClass.h"
17 
19  : TNamed("NoName", "NoTitle"),
20  _covMatrix(),
21  _covMatrixFit(),
22  _covMatrixDeltaAlpha(),
23  _iniparameters(),
24  _parameters()
25 
26 {
27  _nPar = 0;
28 }
29 
30 TAbsFitConstraint::TAbsFitConstraint(const TString& name, const TString& title)
31  : TNamed(name, title),
32  _covMatrix(),
33  _covMatrixFit(),
34  _covMatrixDeltaAlpha(),
35  _iniparameters(),
36  _parameters()
37 
38 {
39  _nPar = 0;
40 }
41 
43 
45  // Reset parameters to initial values
46 
48  setCovMatrixFit(nullptr);
49 }
50 
51 void TAbsFitConstraint::setCovMatrix(const TMatrixD* theCovMatrix) {
52  // Set measured alpha covariance matrix
53 
54  _covMatrix.ResizeTo(_nPar, _nPar);
55  if (theCovMatrix == nullptr) {
56  _covMatrix.Zero();
57  } else if (theCovMatrix->GetNcols() == _nPar && theCovMatrix->GetNrows() == _nPar) {
58  _covMatrix = (*theCovMatrix);
59  } else {
60  edm::LogError("WrongMatrixSize") << GetName() << "::setCovMatrix - Measured alpha covariance matrix needs to be a "
61  << _nPar << "x" << _nPar << " matrix.";
62  }
63 }
64 
65 void TAbsFitConstraint::setCovMatrixFit(const TMatrixD* theCovMatrixFit) {
66  // Set the fitted covariance matrix
67 
68  _covMatrixFit.ResizeTo(_nPar, _nPar);
69  if (theCovMatrixFit == nullptr) {
70  _covMatrixFit.Zero();
71  } else if (theCovMatrixFit->GetNcols() == _nPar && theCovMatrixFit->GetNrows() == _nPar) {
72  _covMatrixFit = (*theCovMatrixFit);
73  } else {
74  edm::LogError("WrongMatrixSize") << GetName() << "::setCovMatrixFit - Fitted covariance matrix needs to be a "
75  << _nPar << "x" << _nPar << " matrix.";
76  }
77 }
78 
80  // Calculates V(deltaAlpha) == V(alpha_meas) - V(alpha_fit)
81 
82  _covMatrixDeltaAlpha.ResizeTo(_nPar, _nPar);
84  if (_covMatrixFit.GetNrows() == _nPar && _covMatrixFit.GetNcols() == _nPar)
86  else
87  edm::LogError("WrongMatrixSize") << GetName() << "::calcCovMatrixDeltaAlpha - _covMatrixFit probably not set.";
88 }
89 
90 void TAbsFitConstraint::applyDeltaAlpha(TMatrixD* corrMatrix) {
91  // Apply corrections to the parameters wrt. to the
92  // initial parameters alpha* = alpha + delta(alpha)
93 
95  _parameters += (*corrMatrix);
96 }
97 
98 void TAbsFitConstraint::setParIni(const TMatrixD* parini) {
99  // Set initial parameter values (before the fit)
100 
101  if (parini == nullptr)
102  return;
103  else if (parini->GetNrows() == _iniparameters.GetNrows() && parini->GetNcols() == _iniparameters.GetNcols())
104  _iniparameters = (*parini);
105  else {
106  edm::LogError("WrongMatrixSize") << GetName() << "::setParIni - Matrices don't fit.";
107  return;
108  }
109 }
110 
112  // Returns covariance matrix delta(alpha)
113 
115  return &_covMatrixDeltaAlpha;
116 }
117 
119  // Collect information to be used for printout
120 
121  std::stringstream info;
122  info << std::scientific << std::setprecision(6);
123 
124  info << "__________________________" << std::endl << std::endl;
125  info << "OBJ: " << IsA()->GetName() << "\t" << GetName() << "\t" << GetTitle() << std::endl;
126 
127  info << "initial value: " << getInitValue() << std::endl;
128  info << "current value: " << getCurrentValue() << std::endl;
129 
130  return info.str();
131 }
132 
134  // Print constraint contents
135 
136  edm::LogVerbatim("KinFitter") << this->getInfoString();
137 }
virtual void applyDeltaAlpha(TMatrixD *corrMatrix)
Log< level::Info, true > LogVerbatim
static const TGPicture * info(bool iBackgroundIsBlack)
virtual void reset()
virtual Double_t getCurrentValue()=0
virtual Double_t getInitValue()=0
virtual void setCovMatrix(const TMatrixD *theCovMatrix)
TMatrixD _covMatrixDeltaAlpha
Log< level::Error, false > LogError
virtual TString getInfoString()
virtual void setCovMatrixFit(const TMatrixD *theCovMatrixFit)
~TAbsFitConstraint() override
virtual const TMatrixD * getCovMatrixDeltaAlpha()
virtual void print()
void setParIni(const TMatrixD *parini)