CMS 3D CMS Logo

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
TFitParticleECart.cc
Go to the documentation of this file.
1 // Classname: TFitParticleECart
2 // Author: Jan E. Sundermann, Verena Klose (TU Dresden)
3 
4 //________________________________________________________________
5 //
6 // TFitParticleECart::
7 // --------------------
8 //
9 // Particle with cartesian 4vector parametrization and free mass
10 // [four free parameters (px, py, pz, d) with initial values
11 // (px, py, pz, 1)]
12 //
13 // p = px*u1 + py*u2 + pz*u3
14 // E = d
15 //
16 
17 #include <iostream>
20 
21 //----------------
22 // Constructor --
23 //----------------
25 
27  : TAbsFitParticle(fitParticle.GetName(), fitParticle.GetTitle()) {
28  _nPar = fitParticle._nPar;
29  _u1 = fitParticle._u1;
30  _u2 = fitParticle._u2;
31  _u3 = fitParticle._u3;
32  _covMatrix.ResizeTo(fitParticle._covMatrix);
33  _covMatrix = fitParticle._covMatrix;
34  _iniparameters.ResizeTo(fitParticle._iniparameters);
35  _iniparameters = fitParticle._iniparameters;
36  _parameters.ResizeTo(fitParticle._parameters);
37  _parameters = fitParticle._parameters;
38  _pini = fitParticle._pini;
39  _pcurr = fitParticle._pcurr;
40 }
41 
42 TFitParticleECart::TFitParticleECart(TLorentzVector* pini, const TMatrixD* theCovMatrix) : TAbsFitParticle() {
43  init(pini, theCovMatrix);
44 }
45 
47  const TString& title,
48  TLorentzVector* pini,
49  const TMatrixD* theCovMatrix)
50  : TAbsFitParticle(name, title) {
51  init(pini, theCovMatrix);
52 }
53 
54 TAbsFitParticle* TFitParticleECart::clone(const TString& newname) const {
55  // Returns a copy of itself
56 
57  TAbsFitParticle* myclone = new TFitParticleECart(*this);
58  if (newname.Length() > 0)
59  myclone->SetName(newname);
60  return myclone;
61 }
62 
63 //--------------
64 // Destructor --
65 //--------------
67 
68 //--------------
69 // Operations --
70 //--------------
71 void TFitParticleECart::init(TLorentzVector* pini, const TMatrixD* theCovMatrix) {
72  _nPar = 4;
73  setIni4Vec(pini);
74  setCovMatrix(theCovMatrix);
75 }
76 
77 TLorentzVector* TFitParticleECart::calc4Vec(const TMatrixD* params) {
78  // Calculates a 4vector corresponding to the given
79  // parameter values
80 
81  if (params == nullptr) {
82  return nullptr;
83  }
84 
85  if (params->GetNcols() != 1 || params->GetNrows() != _nPar) {
86  edm::LogError("WrongMatrixSize") << GetName() << "::calc4Vec - Parameter matrix has wrong size.";
87  return nullptr;
88  }
89 
90  Double_t X = (*params)(0, 0);
91  Double_t Y = (*params)(1, 0);
92  Double_t Z = (*params)(2, 0);
93  Double_t E = (*params)(3, 0);
94 
95  TLorentzVector* vec = new TLorentzVector(X, Y, Z, E);
96  return vec;
97 }
98 
99 void TFitParticleECart::setIni4Vec(const TLorentzVector* pini) {
100  // Set the initial 4vector. Will also set the
101  // inital parameter values
102 
103  if (pini == nullptr) {
104  _u1.SetXYZ(0., 0., 0.);
105  _u3.SetXYZ(0., 0., 0.);
106  _u2.SetXYZ(0., 0., 0.);
107  _pini.SetXYZT(0., 0., 0., 0.);
108  _pcurr = _pini;
109 
110  _iniparameters.ResizeTo(_nPar, 1);
111  _iniparameters(0, 0) = 0;
112  _iniparameters(1, 0) = 0;
113  _iniparameters(2, 0) = 0;
114  _iniparameters(3, 0) = 0.;
115 
116  _parameters.ResizeTo(_nPar, 1);
118 
119  } else {
120  _pini = (*pini);
121  _pcurr = _pini;
122 
123  _u1.SetXYZ(1., 0., 0.);
124  _u2.SetXYZ(0., 1., 0.);
125  _u3.SetXYZ(0., 0., 1.);
126 
127  _iniparameters.ResizeTo(_nPar, 1);
128  _iniparameters(0, 0) = _pini.X();
129  _iniparameters(1, 0) = _pini.Y();
130  _iniparameters(2, 0) = _pini.Z();
131  _iniparameters(3, 0) = _pini.E();
132  _parameters.ResizeTo(_nPar, 1);
134  }
135 }
136 
138  // returns derivative dP/dy with P=(p,E) and y=(px, py, pz, d)
139  // the free parameters of the fit. The columns of the matrix contain
140  // (dP/dpx, dP/dpy, ...).
141 
142  TMatrixD* DerivativeMatrix = new TMatrixD(4, 4);
143  (*DerivativeMatrix) *= 0.;
144 
145  //1st column: dP/dx
146  (*DerivativeMatrix)(0, 0) = 1.;
147  (*DerivativeMatrix)(1, 0) = 0.;
148  (*DerivativeMatrix)(2, 0) = 0.;
149  (*DerivativeMatrix)(3, 0) = 0.;
150 
151  //2nd column: dP/dy
152  (*DerivativeMatrix)(0, 1) = 0;
153  (*DerivativeMatrix)(1, 1) = 1;
154  (*DerivativeMatrix)(2, 1) = 0;
155  (*DerivativeMatrix)(3, 1) = 0.;
156 
157  //3rd column: dP/dz
158  (*DerivativeMatrix)(0, 2) = 0.;
159  (*DerivativeMatrix)(1, 2) = 0.;
160  (*DerivativeMatrix)(2, 2) = 1.;
161  (*DerivativeMatrix)(3, 2) = 0.;
162 
163  //4th column: dP/dm
164  (*DerivativeMatrix)(0, 3) = 0.;
165  (*DerivativeMatrix)(1, 3) = 0.;
166  (*DerivativeMatrix)(2, 3) = 0.;
167  (*DerivativeMatrix)(3, 3) = 1.;
168 
169  return DerivativeMatrix;
170 }
171 
172 TMatrixD* TFitParticleECart::transform(const TLorentzVector& vec) {
173  // Returns the parameters corresponding to the given
174  // 4vector
175 
176  TMatrixD* tparams = new TMatrixD(_nPar, 1);
177  (*tparams)(0, 0) = vec.X();
178  (*tparams)(1, 0) = vec.Y();
179  (*tparams)(2, 0) = vec.Z();
180  (*tparams)(3, 0) = vec.E();
181 
182  return tparams;
183 }
TMatrixD * getDerivative() override
#define X(str)
Definition: MuonsGrabber.cc:38
Log< level::Error, false > LogError
TLorentzVector _pini
TLorentzVector * calc4Vec(const TMatrixD *params) override
TMatrixD _parameters
TLorentzVector _pcurr
void setIni4Vec(const TLorentzVector *pini) override
virtual void setCovMatrix(const TMatrixD *theCovMatrix)
TMatrixD * transform(const TLorentzVector &vec) override
TMatrixD _iniparameters
TAbsFitParticle * clone(const TString &newname=TString("")) const override
void init(TLorentzVector *pini, const TMatrixD *theCovMatrix)
~TFitParticleECart() override