CMS 3D CMS Logo

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 }
TAbsFitConstraint::reset
virtual void reset()
Definition: TAbsFitConstraint.cc:44
MessageLogger.h
TAbsFitConstraint::setParIni
void setParIni(const TMatrixD *parini)
Definition: TAbsFitConstraint.cc:98
TAbsFitConstraint::_covMatrix
TMatrixD _covMatrix
Definition: TAbsFitConstraint.h:49
TAbsFitConstraint::setCovMatrix
virtual void setCovMatrix(const TMatrixD *theCovMatrix)
Definition: TAbsFitConstraint.cc:51
TAbsFitConstraint::getInitValue
virtual Double_t getInitValue()=0
info
static const TGPicture * info(bool iBackgroundIsBlack)
Definition: FWCollectionSummaryWidget.cc:152
TAbsFitConstraint::setCovMatrixFit
virtual void setCovMatrixFit(const TMatrixD *theCovMatrixFit)
Definition: TAbsFitConstraint.cc:65
TAbsFitConstraint::_nPar
Int_t _nPar
Definition: TAbsFitConstraint.h:47
TAbsFitConstraint::getCurrentValue
virtual Double_t getCurrentValue()=0
TAbsFitConstraint::_covMatrixDeltaAlpha
TMatrixD _covMatrixDeltaAlpha
Definition: TAbsFitConstraint.h:51
TAbsFitConstraint::getCovMatrixDeltaAlpha
virtual const TMatrixD * getCovMatrixDeltaAlpha()
Definition: TAbsFitConstraint.cc:111
TAbsFitConstraint::getInfoString
virtual TString getInfoString()
Definition: TAbsFitConstraint.cc:118
TAbsFitConstraint::~TAbsFitConstraint
~TAbsFitConstraint() override
Definition: TAbsFitConstraint.cc:42
TAbsFitConstraint::TAbsFitConstraint
TAbsFitConstraint()
Definition: TAbsFitConstraint.cc:18
TAbsFitConstraint::_iniparameters
TMatrixD _iniparameters
Definition: TAbsFitConstraint.h:52
TAbsFitConstraint::_covMatrixFit
TMatrixD _covMatrixFit
Definition: TAbsFitConstraint.h:50
edm::LogError
Definition: MessageLogger.h:183
TAbsFitConstraint::_parameters
TMatrixD _parameters
Definition: TAbsFitConstraint.h:53
edm::LogVerbatim
Definition: MessageLogger.h:297
TAbsFitConstraint::calcCovMatrixDeltaAlpha
void calcCovMatrixDeltaAlpha()
Definition: TAbsFitConstraint.cc:79
TAbsFitConstraint.h
overlapproblemtsosanalyzer_cfi.title
title
Definition: overlapproblemtsosanalyzer_cfi.py:7
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
TAbsFitConstraint::print
virtual void print()
Definition: TAbsFitConstraint.cc:133
TAbsFitConstraint::applyDeltaAlpha
virtual void applyDeltaAlpha(TMatrixD *corrMatrix)
Definition: TAbsFitConstraint.cc:90