CMS 3D CMS Logo

TAbsFitParticle.cc
Go to the documentation of this file.
1 // Classname: TAbsFitParticle
2 // Author: Jan E. Sundermann, Verena Klose (TU Dresden)
3 
4 //________________________________________________________________
5 //
6 // TAbsFitParticle::
7 // --------------------
8 //
9 // Abstract base class for particles to be used with kinematic fitter
10 //
11 
14 #include <iostream>
15 #include <iomanip>
16 #include "TClass.h"
17 
19  : TNamed("NoName", "NoTitle"),
20  _nPar(0),
21  _u1(),
22  _u2(),
23  _u3(),
24  _covMatrix(),
25  _covMatrixFit(),
26  _covMatrixDeltaY(),
27  _pull(),
28  _iniparameters(1, 1),
29  _parameters(1, 1),
30  _pini(),
31  _pcurr() {}
32 
33 TAbsFitParticle::TAbsFitParticle(const TString& name, const TString& title)
34  : TNamed(name, title),
35  _nPar(0),
36  _u1(),
37  _u2(),
38  _u3(),
39  _covMatrix(),
40  _covMatrixFit(),
41  _covMatrixDeltaY(),
42  _pull(),
43  _iniparameters(1, 1),
44  _parameters(1, 1),
45  _pini(),
46  _pcurr() {}
47 
49 
51  // Collect information to be used for printout
52 
53  std::stringstream info;
54  info << std::scientific << std::setprecision(6);
55 
56  info << "__________________________" << std::endl << std::endl;
57 
58  info << "OBJ: " << IsA()->GetName() << "\t" << GetName() << "\t" << GetTitle() << std::endl;
59 
60  info << std::setw(22) << "initial parameters:" << std::setw(5) << " " << std::setw(20)
61  << "current parameters:" << std::endl;
62  for (int i = 0; i < _nPar; i++) {
63  info << "par[" << i << "] = " << std::setw(18) << (*getParIni())(i, 0) << std::setw(20) << (*getParCurr())(i, 0)
64  << std::endl;
65  }
66 
67  info << std::setw(22) << "initial 4vector:" << std::setw(5) << " " << std::setw(20)
68  << "current 4vector:" << std::endl;
69  for (int i = 0; i < 4; i++) {
70  info << "p[" << i << "] = " << std::setw(20) << (*getIni4Vec())[i] << std::setw(20) << (*getCurr4Vec())[i]
71  << std::endl;
72  }
73  info << "mass = " << std::setw(20) << (*getIni4Vec()).M() << std::setw(20) << (*getCurr4Vec()).M() << std::endl;
74 
75  info << "u1 = " << _u1.X() << ", " << _u1.Y() << ", " << _u1.Z() << std::endl;
76  info << "u2 = " << _u2.X() << ", " << _u2.Y() << ", " << _u2.Z() << std::endl;
77  info << "u3 = " << _u3.X() << ", " << _u3.Y() << ", " << _u3.Z() << std::endl;
78 
79  return info.str();
80 }
81 
83  // Print particle contents
84 
85  edm::LogVerbatim("KinFitter") << this->getInfoString();
86 }
87 
89  // Reset particle to initial values
90 
92  _pcurr = _pini;
93  setCovMatrixFit(nullptr);
94  _pull.ResizeTo(_nPar, 1);
95  _pull.Zero();
96 }
97 
98 void TAbsFitParticle::setCovMatrix(const TMatrixD* theCovMatrix) {
99  // Set the measured covariance matrix
100 
101  _covMatrix.ResizeTo(_nPar, _nPar);
102  if (theCovMatrix == nullptr) {
103  _covMatrix.Zero();
104  } else if (theCovMatrix->GetNcols() == _nPar && theCovMatrix->GetNrows() == _nPar) {
105  _covMatrix = (*theCovMatrix);
106  } else {
107  edm::LogError("WrongMatrixSize") << GetName() << "::setCovMatrix - Covariance matrix needs to be a " << _nPar << "x"
108  << _nPar << " matrix.";
109  }
110 }
111 
112 void TAbsFitParticle::setCovMatrixFit(const TMatrixD* theCovMatrixFit) {
113  // Set the fitted covariance matrix
114 
115  _covMatrixFit.ResizeTo(_nPar, _nPar);
116  if (theCovMatrixFit == nullptr) {
117  _covMatrixFit.Zero();
118  } else if (theCovMatrixFit->GetNcols() == _nPar && theCovMatrixFit->GetNrows() == _nPar) {
119  _covMatrixFit = (*theCovMatrixFit);
120  } else {
121  edm::LogError("WrongMatrixSize") << GetName() << "::setCovMatrixFit - Fitted covariance matrix needs to be a "
122  << _nPar << "x" << _nPar << " matrix.";
123  }
124 }
125 
127  // Calculates V(deltaY) == V(y_meas) - V(y_fit)
128 
129  _covMatrixDeltaY.ResizeTo(_nPar, _nPar);
131  if (_covMatrixFit.GetNrows() == _nPar && _covMatrixFit.GetNcols() == _nPar)
133  else
134  edm::LogError("WrongMatrixSize") << GetName() << "::calcCovMatrixDeltaY - _covMatrixFit probably not set.";
135 }
136 
137 const TMatrixD* TAbsFitParticle::getPull() {
138  // Calculates the pull (y_fit - y_meas) / sigma
139  // with sigma = Sqrt( sigma[y_meas]^2 - V[y_fit]^2 )
140  // for all parameters
141 
142  _pull.ResizeTo(_nPar, 1);
143  _pull = _parameters;
146  for (int i = 0; i < _nPar; i++) {
147  Double_t sigmaDeltaY = _covMatrixDeltaY(i, i);
148  if (sigmaDeltaY < 0) {
149  edm::LogWarning("NegativeDiagonalElem") << "V[deltaY] has a negative diagonal element.";
150  _pull.Zero();
151  return &_pull;
152  } else {
153  _pull(i, 0) /= TMath::Sqrt(sigmaDeltaY);
154  }
155  }
156 
157  return &_pull;
158 }
159 
160 void TAbsFitParticle::applycorr(TMatrixD* corrMatrix) {
161  // Apply corrections to the parameters wrt. to the
162  // initial parameters y* = y + delta(y)
163  // This method will also calculate the fitted
164  // 4vector of the particle
165 
166  // update _parameters-Matrix
168  _parameters += (*corrMatrix);
169 
170  // calculates new 4vec
171  TLorentzVector* vec = calc4Vec(&_parameters);
172  _pcurr = (*vec);
173  delete vec;
174 }
175 
176 void TAbsFitParticle::setParIni(const TMatrixD* parini) {
177  if (parini == nullptr)
178  return;
179  else if (parini->GetNrows() == _iniparameters.GetNrows() && parini->GetNcols() == _iniparameters.GetNcols())
180  _iniparameters = (*parini);
181  else {
182  edm::LogError("WrongMatrixSize") << GetName() << "::setParIni - Matrices don't fit.";
183  return;
184  }
185 }
186 
188  //
190  return &_covMatrixDeltaY;
191 }
TAbsFitParticle::_iniparameters
TMatrixD _iniparameters
Definition: TAbsFitParticle.h:58
runGCPTkAlMap.title
string title
Definition: runGCPTkAlMap.py:94
mps_fire.i
i
Definition: mps_fire.py:428
MessageLogger.h
TAbsFitParticle::setCovMatrixFit
virtual void setCovMatrixFit(const TMatrixD *theCovMatrixFit)
Definition: TAbsFitParticle.cc:112
TAbsFitParticle::calc4Vec
virtual TLorentzVector * calc4Vec(const TMatrixD *params)=0
TAbsFitParticle::calcCovMatrixDeltaY
void calcCovMatrixDeltaY()
Definition: TAbsFitParticle.cc:126
TAbsFitParticle::_parameters
TMatrixD _parameters
Definition: TAbsFitParticle.h:59
TAbsFitParticle::_covMatrixFit
TMatrixD _covMatrixFit
Definition: TAbsFitParticle.h:55
info
static const TGPicture * info(bool iBackgroundIsBlack)
Definition: FWCollectionSummaryWidget.cc:153
TAbsFitParticle::_pcurr
TLorentzVector _pcurr
Definition: TAbsFitParticle.h:61
vertexPlots._pull
_pull
Definition: vertexPlots.py:94
edm::LogWarning
Log< level::Warning, false > LogWarning
Definition: MessageLogger.h:122
TAbsFitParticle::_pini
TLorentzVector _pini
Definition: TAbsFitParticle.h:60
TAbsFitParticle::_covMatrix
TMatrixD _covMatrix
Definition: TAbsFitParticle.h:54
TAbsFitParticle::_u2
TVector3 _u2
Definition: TAbsFitParticle.h:51
TAbsFitParticle::_nPar
Int_t _nPar
Definition: TAbsFitParticle.h:49
TAbsFitParticle::getPull
virtual const TMatrixD * getPull()
Definition: TAbsFitParticle.cc:137
TAbsFitParticle::setParIni
void setParIni(const TMatrixD *parini)
Definition: TAbsFitParticle.cc:176
TAbsFitParticle::getCurr4Vec
const TLorentzVector * getCurr4Vec()
Definition: TAbsFitParticle.h:31
TAbsFitParticle::getParIni
const TMatrixD * getParIni()
Definition: TAbsFitParticle.h:35
TAbsFitParticle::setCovMatrix
virtual void setCovMatrix(const TMatrixD *theCovMatrix)
Definition: TAbsFitParticle.cc:98
TAbsFitParticle::reset
virtual void reset()
Definition: TAbsFitParticle.cc:88
TAbsFitParticle::TAbsFitParticle
TAbsFitParticle()
Definition: TAbsFitParticle.cc:18
TAbsFitParticle::applycorr
virtual void applycorr(TMatrixD *corrMatrix)
Definition: TAbsFitParticle.cc:160
TAbsFitParticle::_u3
TVector3 _u3
Definition: TAbsFitParticle.h:52
TAbsFitParticle::print
virtual void print()
Definition: TAbsFitParticle.cc:82
edm::LogError
Log< level::Error, false > LogError
Definition: MessageLogger.h:123
TAbsFitParticle::getCovMatrixDeltaY
virtual const TMatrixD * getCovMatrixDeltaY()
Definition: TAbsFitParticle.cc:187
TAbsFitParticle::getInfoString
TString getInfoString()
Definition: TAbsFitParticle.cc:50
TAbsFitParticle::getParCurr
const TMatrixD * getParCurr()
Definition: TAbsFitParticle.h:37
edm::LogVerbatim
Log< level::Info, true > LogVerbatim
Definition: MessageLogger.h:128
TAbsFitParticle::_pull
TMatrixD _pull
Definition: TAbsFitParticle.h:57
TAbsFitParticle::_u1
TVector3 _u1
Definition: TAbsFitParticle.h:50
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
TAbsFitParticle.h
TAbsFitParticle::~TAbsFitParticle
~TAbsFitParticle() override
Definition: TAbsFitParticle.cc:48
TAbsFitParticle::_covMatrixDeltaY
TMatrixD _covMatrixDeltaY
Definition: TAbsFitParticle.h:56
TAbsFitParticle::getIni4Vec
const TLorentzVector * getIni4Vec()
Definition: TAbsFitParticle.h:32