CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
TFitParticleMCPInvSpher.cc
Go to the documentation of this file.
1 // Classname: TFitParticleMCPInvSpher
2 // Author: Jan E. Sundermann, Verena Klose (TU Dresden)
3 
4 //________________________________________________________________
5 //
6 // TFitParticleMCPInvSpher::
7 // --------------------
8 //
9 // Particle with 1/r, theta, and phi parametrization of the momentum 4vector and
10 // constant mass (3 free parameters). The parametrization is chosen as
11 // follows:
12 //
13 // p = (1/r, theta, phi)
14 // E(fit) = Sqrt( |p|^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 TFitParticleMCPInvSpher::TFitParticleMCPInvSpher(TVector3* p, Double_t M, const TMatrixD* theCovMatrix)
44  : TAbsFitParticle() {
45  init(p, M, theCovMatrix);
46 }
47 
49  const TString& name, const TString& title, TVector3* p, Double_t M, const TMatrixD* theCovMatrix)
50  : TAbsFitParticle(name, title) {
51  init(p, M, theCovMatrix);
52 }
53 
54 TAbsFitParticle* TFitParticleMCPInvSpher::clone(const TString& newname) const {
55  // Returns a copy of itself
56 
57  TAbsFitParticle* myclone = new TFitParticleMCPInvSpher(*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 TFitParticleMCPInvSpher::init(TVector3* p, Double_t M, const TMatrixD* theCovMatrix) {
72  _nPar = 3;
73  setIni4Vec(p, M);
74  setCovMatrix(theCovMatrix);
75 }
76 
77 TLorentzVector* TFitParticleMCPInvSpher::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 r = (*params)(0, 0);
91  Double_t theta = (*params)(1, 0);
92  Double_t phi = (*params)(2, 0);
93 
94  Double_t X = 1 / r * TMath::Cos(phi) * TMath::Sin(theta);
95  Double_t Y = 1 / r * TMath::Sin(phi) * TMath::Sin(theta);
96  Double_t Z = 1 / r * TMath::Cos(theta);
97  Double_t E = TMath::Sqrt(X * X + Y * Y + Z * Z + _pini.M2());
98 
99  TLorentzVector* vec = new TLorentzVector(X, Y, Z, E);
100  return vec;
101 }
102 
103 void TFitParticleMCPInvSpher::setIni4Vec(const TLorentzVector* pini) {
104  // Set the initial 4vector. Will also set the
105  // inital parameter values
106 
107  TVector3 vec(pini->Vect());
108  setIni4Vec(&vec, pini->M());
109 }
110 
111 void TFitParticleMCPInvSpher::setIni4Vec(const TVector3* p, Double_t M) {
112  // Set the initial 4vector. Will also set the
113  // inital parameter values
114 
115  if (p == nullptr) {
116  _u1.SetXYZ(0., 0., 0.);
117  _u3.SetXYZ(0., 0., 0.);
118  _u2.SetXYZ(0., 0., 0.);
119  _pini.SetXYZM(0., 0., 0., M);
120  _pcurr = _pini;
121 
122  _iniparameters.ResizeTo(_nPar, 1);
123  _iniparameters(0, 0) = 0.;
124  _parameters.ResizeTo(_nPar, 1);
126 
127  } else {
128  _pini.SetXYZM(p->x(), p->y(), p->z(), M);
129  _pcurr = _pini;
130 
131  Double_t r = 1 / _pini.P();
132  Double_t theta = _pini.Theta();
133  Double_t phi = _pini.Phi();
134 
135  _iniparameters.ResizeTo(_nPar, 1);
136  _iniparameters(0, 0) = r;
137  _iniparameters(1, 0) = theta;
138  _iniparameters(2, 0) = phi;
139  _parameters.ResizeTo(_nPar, 1);
141 
142  _u1.SetXYZ(TMath::Cos(phi) * TMath::Sin(theta), TMath::Sin(phi) * TMath::Sin(theta), TMath::Cos(theta));
143  _u2.SetXYZ(TMath::Cos(phi) * TMath::Cos(theta), TMath::Sin(phi) * TMath::Cos(theta), -1. * TMath::Sin(theta));
144  _u3.SetXYZ(-1. * TMath::Sin(phi), TMath::Cos(phi), 0.);
145  }
146 }
147 
149  // returns derivative dP/dy with P=(p,E) and y=(r, theta, phi)
150  // the free parameters of the fit. The columns of the matrix contain
151  // (dP/dr, dP/dtheta, ...).
152 
153  TMatrixD* DerivativeMatrix = new TMatrixD(4, 3);
154  (*DerivativeMatrix) *= 0.;
155 
156  Double_t r = _parameters(0, 0);
157  Double_t p = 1. / r;
158  Double_t theta = _parameters(1, 0);
159  Double_t phi = _parameters(2, 0);
160 
161  //1st column: dP/dr
162  (*DerivativeMatrix)(0, 0) = -1. * p * p * TMath::Cos(phi) * TMath::Sin(theta);
163  (*DerivativeMatrix)(1, 0) = -1. * p * p * TMath::Sin(phi) * TMath::Sin(theta);
164  (*DerivativeMatrix)(2, 0) = -1. * p * p * TMath::Cos(theta);
165  (*DerivativeMatrix)(3, 0) = -1. * p * p * p / _pcurr.E();
166 
167  //2nd column: dP/dtheta
168  (*DerivativeMatrix)(0, 1) = p * TMath::Cos(phi) * TMath::Cos(theta);
169  (*DerivativeMatrix)(1, 1) = p * TMath::Sin(phi) * TMath::Cos(theta);
170  (*DerivativeMatrix)(2, 1) = -1. * p * TMath::Sin(theta);
171  (*DerivativeMatrix)(3, 1) = 0.;
172 
173  //3rd column: dP/dphi
174  (*DerivativeMatrix)(0, 2) = -1. * p * TMath::Sin(phi) * TMath::Sin(theta);
175  (*DerivativeMatrix)(1, 2) = p * TMath::Cos(phi) * TMath::Sin(theta);
176  ;
177  (*DerivativeMatrix)(2, 2) = 0.;
178  (*DerivativeMatrix)(3, 2) = 0.;
179 
180  return DerivativeMatrix;
181 }
182 
183 TMatrixD* TFitParticleMCPInvSpher::transform(const TLorentzVector& vec) {
184  // Returns the parameters corresponding to the given
185  // 4vector
186 
187  // retrieve parameters
188  TMatrixD* tparams = new TMatrixD(_nPar, 1);
189  (*tparams)(0, 0) = 1. / vec.P();
190  (*tparams)(1, 0) = vec.Theta();
191  (*tparams)(2, 0) = vec.Phi();
192 
193  return tparams;
194 }
TMatrixD * transform(const TLorentzVector &vec) override
Geom::Theta< T > theta() const
#define X(str)
Definition: MuonsGrabber.cc:38
Log< level::Error, false > LogError
TLorentzVector _pini
void init(TVector3 *p, Double_t M, const TMatrixD *theCovMatrix)
TMatrixD _parameters
TLorentzVector _pcurr
TMatrixD * getDerivative() override
virtual void setCovMatrix(const TMatrixD *theCovMatrix)
TAbsFitParticle * clone(const TString &newname=TString("")) const override
TLorentzVector * calc4Vec(const TMatrixD *params) override
void setIni4Vec(const TLorentzVector *pini) override
TMatrixD _iniparameters