CMS 3D CMS Logo

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