CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
TFitParticleESpher.cc
Go to the documentation of this file.
1 // Classname: TFitParticleESpher
2 // Author: Jan E. Sundermann, Verena Klose (TU Dresden)
3 
4 //________________________________________________________________
5 //
6 // TFitParticleESpher::
7 // --------------------
8 //
9 // Particle with spherical parametrization of the momentum 4vector and
10 // free energy (4 free parameters). The parametrization is chosen as
11 // follows:
12 //
13 // p = (r, theta, phi)
14 // E(fit) = d * E_meas
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 TFitParticleESpher::TFitParticleESpher(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* TFitParticleESpher::clone(const TString& newname) const {
56  // Returns a copy of itself
57 
58  TAbsFitParticle* myclone = new TFitParticleESpher(*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 TFitParticleESpher::init(TLorentzVector* pini, const TMatrixD* theCovMatrix) {
73  _nPar = 4;
74  setIni4Vec(pini);
75  setCovMatrix(theCovMatrix);
76 }
77 
78 TLorentzVector* TFitParticleESpher::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 r = (*params)(0, 0);
92  Double_t theta = (*params)(1, 0);
93  Double_t phi = (*params)(2, 0);
94  Double_t d = (*params)(3, 0);
95 
96  Double_t X = r * TMath::Cos(phi) * TMath::Sin(theta);
97  Double_t Y = r * TMath::Sin(phi) * TMath::Sin(theta);
98  Double_t Z = r * TMath::Cos(theta);
99  Double_t E = d * _pini.E();
100 
101  TLorentzVector* vec = new TLorentzVector(X, Y, Z, E);
102  return vec;
103 }
104 
105 void TFitParticleESpher::setIni4Vec(const TLorentzVector* pini) {
106  // Set the initial 4vector. Will also set the
107  // inital parameter values
108 
109  if (pini == nullptr) {
110  _u1.SetXYZ(0., 0., 0.);
111  _u3.SetXYZ(0., 0., 0.);
112  _u2.SetXYZ(0., 0., 0.);
113  _pini.SetXYZT(0., 0., 0., 0.);
114  _pcurr = _pini;
115 
116  _iniparameters.ResizeTo(_nPar, 1);
117  _iniparameters(0, 0) = 0.;
118  _iniparameters(1, 0) = 0.;
119  _iniparameters(2, 0) = 0.;
120  _iniparameters(3, 0) = 1.;
121 
122  _parameters.ResizeTo(_nPar, 1);
123  _parameters(0, 0) = 0.;
124  _parameters(1, 0) = 0.;
125  _parameters(2, 0) = 0.;
126  _parameters(3, 0) = 1.;
127 
128  } else {
129  Double_t r = pini->P();
130  Double_t theta = pini->Theta();
131  Double_t phi = pini->Phi();
132 
133  _pini = (*pini);
134  _pcurr = _pini;
135 
136  _iniparameters.ResizeTo(_nPar, 1);
137  _iniparameters(0, 0) = r;
138  _iniparameters(1, 0) = theta;
139  _iniparameters(2, 0) = phi;
140  _iniparameters(3, 0) = 1.;
141 
142  _parameters.ResizeTo(_nPar, 1);
144 
145  _u1.SetXYZ(TMath::Cos(phi) * TMath::Sin(theta), TMath::Sin(phi) * TMath::Sin(theta), TMath::Cos(theta));
146  _u2.SetXYZ(TMath::Cos(phi) * TMath::Cos(theta), TMath::Sin(phi) * TMath::Cos(theta), -1. * TMath::Sin(theta));
147  _u3.SetXYZ(-1. * TMath::Sin(phi), TMath::Cos(phi), 0.);
148  }
149 }
150 
152  // returns derivative dP/dy with P=(p,E) and y=(r, theta, phi, d)
153  // the free parameters of the fit. The columns of the matrix contain
154  // (dP/dr, dP/dtheta, ...).
155 
156  TMatrixD* DerivativeMatrix = new TMatrixD(4, 4);
157  (*DerivativeMatrix) *= 0.;
158 
159  Double_t r = _parameters(0, 0);
160  Double_t theta = _parameters(1, 0);
161  Double_t phi = _parameters(2, 0);
162  //Double_t d = _parameters(3,0);
163 
164  //1st column: dP/dr
165  (*DerivativeMatrix)(0, 0) = TMath::Cos(phi) * TMath::Sin(theta);
166  (*DerivativeMatrix)(1, 0) = TMath::Sin(phi) * TMath::Sin(theta);
167  (*DerivativeMatrix)(2, 0) = TMath::Cos(theta);
168  (*DerivativeMatrix)(3, 0) = 0.;
169 
170  //2nd column: dP/dtheta
171  (*DerivativeMatrix)(0, 1) = r * TMath::Cos(phi) * TMath::Cos(theta);
172  (*DerivativeMatrix)(1, 1) = r * TMath::Sin(phi) * TMath::Cos(theta);
173  (*DerivativeMatrix)(2, 1) = -1. * r * TMath::Sin(theta);
174  (*DerivativeMatrix)(3, 1) = 0.;
175 
176  //3rd column: dP/dphi
177  (*DerivativeMatrix)(0, 2) = -1. * r * TMath::Sin(phi) * TMath::Sin(theta);
178  (*DerivativeMatrix)(1, 2) = r * TMath::Cos(phi) * TMath::Sin(theta);
179  ;
180  (*DerivativeMatrix)(2, 2) = 0.;
181  (*DerivativeMatrix)(3, 2) = 0.;
182 
183  //4th column: dP/dm
184  (*DerivativeMatrix)(0, 3) = 0.;
185  (*DerivativeMatrix)(1, 3) = 0.;
186  (*DerivativeMatrix)(2, 3) = 0.;
187  (*DerivativeMatrix)(3, 3) = _pini.E();
188 
189  return DerivativeMatrix;
190 }
191 
192 TMatrixD* TFitParticleESpher::transform(const TLorentzVector& vec) {
193  // Returns the parameters corresponding to the given
194  // 4vector
195 
196  // retrieve parameters
197  TMatrixD* tparams = new TMatrixD(_nPar, 1);
198  (*tparams)(0, 0) = vec.P();
199  (*tparams)(1, 0) = vec.Theta();
200  (*tparams)(2, 0) = vec.Phi();
201  (*tparams)(3, 0) = vec.E() / _pini.E();
202 
203  return tparams;
204 }
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
~TFitParticleESpher() override
tuple d
Definition: ztail.py:151
TMatrixD _parameters
TLorentzVector _pcurr
void init(TLorentzVector *pini, const TMatrixD *theCovMatrix)
virtual void setCovMatrix(const TMatrixD *theCovMatrix)
TMatrixD * getDerivative() override
void setIni4Vec(const TLorentzVector *pini) override
TAbsFitParticle * clone(const TString &newname=TString("")) const override
TMatrixD _iniparameters
TLorentzVector * calc4Vec(const TMatrixD *params) override