CMS 3D CMS Logo

TFitParticleEScaledMomDev.cc
Go to the documentation of this file.
1 // Classname: TFitParticleEScaledMomDev
2 // Author: Jan E. Sundermann, Verena Klose (TU Dresden)
3 
4 //________________________________________________________________
5 //
6 // TFitParticleEScaledMomDev::
7 // --------------------
8 //
9 // Particle with special parametrization of the momentum 4vector and
10 // constant E/p (3 free parameters). The parametrization is chosen as
11 // follows:
12 //
13 // p = r*|p|*u_r + theta*u_theta + phi*u_phi
14 // E(fit) = E(ini)/P(ini)*p(fit)
15 //
16 // with u_r = p/|p|
17 // u_phi = (u_z x u_r)/|u_z x u_r|
18 // u_theta = (u_r x u_phi)/|u_r x u_phi|
19 //
20 // The initial parameters values are chosen like (r, theta, phi) = (1., 0., 0.)
21 // corresponding to the measured momentum.
22 //
23 
24 #include <iostream>
27 #include "TMath.h"
28 
29 //----------------
30 // Constructor --
31 //----------------
33 
35  : TAbsFitParticle(fitParticle.GetName(), fitParticle.GetTitle()) {
36  _nPar = fitParticle._nPar;
37  _u1 = fitParticle._u1;
38  _u2 = fitParticle._u2;
39  _u3 = fitParticle._u3;
40  _covMatrix.ResizeTo(fitParticle._covMatrix);
41  _covMatrix = fitParticle._covMatrix;
42  _iniparameters.ResizeTo(fitParticle._iniparameters);
43  _iniparameters = fitParticle._iniparameters;
44  _parameters.ResizeTo(fitParticle._parameters);
45  _parameters = fitParticle._parameters;
46  _pini = fitParticle._pini;
47  _pcurr = fitParticle._pcurr;
48 }
49 
50 TFitParticleEScaledMomDev::TFitParticleEScaledMomDev(TLorentzVector* pini, const TMatrixD* theCovMatrix)
51  : TAbsFitParticle() {
52  init(pini, theCovMatrix);
53 }
54 
56  const TString& title,
57  TLorentzVector* pini,
58  const TMatrixD* theCovMatrix)
60  init(pini, theCovMatrix);
61 }
62 
63 TAbsFitParticle* TFitParticleEScaledMomDev::clone(const TString& newname) const {
64  // Returns a copy of itself
65 
66  TAbsFitParticle* myclone = new TFitParticleEScaledMomDev(*this);
67  if (newname.Length() > 0)
68  myclone->SetName(newname);
69  return myclone;
70 }
71 
72 //--------------
73 // Destructor --
74 //--------------
76 
77 //--------------
78 // Operations --
79 //--------------
80 void TFitParticleEScaledMomDev::init(TLorentzVector* pini, const TMatrixD* theCovMatrix) {
81  _nPar = 3;
82  setIni4Vec(pini);
83  _iniparameters.ResizeTo(_nPar, 1);
84  _iniparameters(0, 0) = 1.;
85  _iniparameters(1, 0) = 0.;
86  _iniparameters(2, 0) = 0.;
87  _parameters.ResizeTo(_nPar, 1);
89  setCovMatrix(theCovMatrix);
90 }
91 
92 TLorentzVector* TFitParticleEScaledMomDev::calc4Vec(const TMatrixD* params) {
93  // Calculates a 4vector corresponding to the given
94  // parameter values
95 
96  if (params == nullptr) {
97  return nullptr;
98  }
99 
100  if (params->GetNcols() != 1 || params->GetNrows() != _nPar) {
101  edm::LogError("WrongMatrixSize") << GetName() << "::calc4Vec - Parameter matrix has wrong size.";
102  return nullptr;
103  }
104 
105  Double_t X = _pini.P() * (*params)(0, 0) * _u1.X() + (*params)(1, 0) * _u2.X() + (*params)(2, 0) * _u3.X();
106  Double_t Y = _pini.P() * (*params)(0, 0) * _u1.Y() + (*params)(1, 0) * _u2.Y() + (*params)(2, 0) * _u3.Y();
107  Double_t Z = _pini.P() * (*params)(0, 0) * _u1.Z() + (*params)(1, 0) * _u2.Z() + (*params)(2, 0) * _u3.Z();
108  Double_t pcurr = TMath::Sqrt(X * X + Y * Y + Z * Z);
109  Double_t E = _pini.E() * pcurr / _pini.P();
110 
111  TLorentzVector* vec = new TLorentzVector(X, Y, Z, E);
112  return vec;
113 }
114 
115 void TFitParticleEScaledMomDev::setIni4Vec(const TLorentzVector* pini) {
116  // Set the initial 4vector. Will also set the
117  // inital parameter values
118 
119  if (pini == nullptr) {
120  _u1.SetXYZ(0., 0., 0.);
121  _u3.SetXYZ(0., 0., 0.);
122  _u2.SetXYZ(0., 0., 0.);
123  _pini.SetXYZT(0., 0., 0., 0.);
124 
125  } else {
126  _pini = (*pini);
127  _pcurr = _pini;
128 
129  _u1 = pini->Vect();
130  _u1 *= 1. / _u1.Mag();
131 
132  TVector3 uz(0., 0., 1.);
133  _u3 = uz.Cross(_u1);
134  _u3 *= 1. / _u3.Mag();
135 
136  _u2 = _u3.Cross(_u1);
137  _u2 *= 1. / _u2.Mag();
138  }
139 
141 }
142 
144  // returns derivative dP/dy with P=(p,E) and y=(r, theta, phi)
145  // the free parameters of the fit. The columns of the matrix contain
146  // (dP/dr, dP/dtheta, dP/dphi).
147 
148  TMatrixD* DerivativeMatrix = new TMatrixD(4, 3);
149  (*DerivativeMatrix) *= 0.;
150 
151  //1st column: dP/dr
152  (*DerivativeMatrix)(0, 0) = _pini.P() * _u1.X();
153  (*DerivativeMatrix)(1, 0) = _pini.P() * _u1.Y();
154  (*DerivativeMatrix)(2, 0) = _pini.P() * _u1.Z();
155  (*DerivativeMatrix)(3, 0) = _pini.P() * _pini.E() * _parameters(0, 0) / _pcurr.P();
156  //2nd column: dP/dtheta
157  (*DerivativeMatrix)(0, 1) = _u2.X();
158  (*DerivativeMatrix)(1, 1) = _u2.Y();
159  (*DerivativeMatrix)(2, 1) = _u2.Z();
160  (*DerivativeMatrix)(3, 1) = _pini.E() / _pini.P() / _pcurr.P() * _parameters(1, 0);
161  //3rd column: dP/dphi
162  (*DerivativeMatrix)(0, 2) = _u3.X();
163  (*DerivativeMatrix)(1, 2) = _u3.Y();
164  (*DerivativeMatrix)(2, 2) = _u3.Z();
165  ;
166  (*DerivativeMatrix)(3, 2) = _pini.E() / _pini.P() / _pcurr.P() * _parameters(2, 0);
167 
168  return DerivativeMatrix;
169 }
170 
171 TMatrixD* TFitParticleEScaledMomDev::transform(const TLorentzVector& vec) {
172  // Returns the parameters corresponding to the given
173  // 4vector wrt. to the current base vectors u_r, u_theta, and u_phi
174 
175  // construct rotation matrix
176  TRotation rot;
177  rot.RotateAxes(_u1, _u2, _u3);
178  rot.Invert();
179 
180  // rotate vector
181  TVector3 vec3(vec.Vect());
182  vec3.Transform(rot);
183 
184  // retrieve parameters
185  TMatrixD* tparams = new TMatrixD(_nPar, 1);
186  (*tparams)(0, 0) = vec3(0) / _pini.P();
187  (*tparams)(1, 0) = vec3(1);
188  (*tparams)(2, 0) = vec3(2);
189 
190  return tparams;
191 }
#define X(str)
Definition: MuonsGrabber.cc:38
TMatrixD * transform(const TLorentzVector &vec) override
Log< level::Error, false > LogError
void setIni4Vec(const TLorentzVector *pini) override
TLorentzVector _pini
void init(TLorentzVector *pini, const TMatrixD *theCovMatrix)
std::vector< vec2 > vec3
Definition: HCALResponse.h:17
TAbsFitParticle * clone(const TString &newname="") const override
TMatrixD _parameters
TLorentzVector _pcurr
TLorentzVector * calc4Vec(const TMatrixD *params) override
virtual void setCovMatrix(const TMatrixD *theCovMatrix)
TMatrixD _iniparameters