CMS 3D CMS Logo

TFitParticleEtThetaPhi.cc
Go to the documentation of this file.
1 // Classname: TFitParticleEtThetaPhi
2 // Author: S.Paktinat(IPM, CMS)
3 // 27 July 2005
4 
5 //________________________________________________________________
6 //
7 // TFitParticleEtThetaPhi::
8 // --------------------
9 //
10 // Particle with a special parametrization useful in hadron
11 // colliders (3 free parameters (Et, Eta, Phi). The parametrization is
12 // chosen as follows:
13 //
14 // p = (EtCosPhi, EtSinPhi, Et/Tan(Theta)
15 // E = Et/Sin(Theta)
16 //
17 
18 #include <iostream>
21 #include "TMath.h"
22 #include <cmath>
23 
24 //----------------
25 // Constructor --
26 //----------------
28 
30  : TAbsFitParticle(fitParticle.GetName(), fitParticle.GetTitle()) {
31  _nPar = fitParticle._nPar;
32  _u1 = fitParticle._u1;
33  _u2 = fitParticle._u2;
34  _u3 = fitParticle._u3;
35  _covMatrix.ResizeTo(fitParticle._covMatrix);
36  _covMatrix = fitParticle._covMatrix;
37  _iniparameters.ResizeTo(fitParticle._iniparameters);
38  _iniparameters = fitParticle._iniparameters;
39  _parameters.ResizeTo(fitParticle._parameters);
40  _parameters = fitParticle._parameters;
41  _pini = fitParticle._pini;
42  _pcurr = fitParticle._pcurr;
43 }
44 
45 TFitParticleEtThetaPhi::TFitParticleEtThetaPhi(TLorentzVector* pini, const TMatrixD* theCovMatrix) : TAbsFitParticle() {
46  init(pini, theCovMatrix);
47 }
48 
50  const TString& title,
51  TLorentzVector* pini,
52  const TMatrixD* theCovMatrix)
54  init(pini, theCovMatrix);
55 }
56 
57 TAbsFitParticle* TFitParticleEtThetaPhi::clone(const TString& newname) const {
58  // Returns a copy of itself
59 
60  TAbsFitParticle* myclone = new TFitParticleEtThetaPhi(*this);
61  if (newname.Length() > 0)
62  myclone->SetName(newname);
63  return myclone;
64 }
65 
66 //--------------
67 // Destructor --
68 //--------------
70 
71 //--------------
72 // Operations --
73 //--------------
74 void TFitParticleEtThetaPhi::init(TLorentzVector* pini, const TMatrixD* theCovMatrix) {
75  _nPar = 3;
76  setIni4Vec(pini);
77  setCovMatrix(theCovMatrix);
78 }
79 
80 TLorentzVector* TFitParticleEtThetaPhi::calc4Vec(const TMatrixD* params) {
81  // Calculates a 4vector corresponding to the given
82  // parameter values
83 
84  if (params == nullptr) {
85  return nullptr;
86  }
87 
88  if (params->GetNcols() != 1 || params->GetNrows() != _nPar) {
89  edm::LogError("WrongMatrixSize") << GetName() << "::calc4Vec - Parameter matrix has wrong size.";
90  return nullptr;
91  }
92 
93  Double_t et = (*params)(0, 0);
94  Double_t theta = (*params)(1, 0);
95  Double_t phi = (*params)(2, 0);
96 
97  Double_t X = et * TMath::Cos(phi);
98  Double_t Y = et * TMath::Sin(phi);
99  Double_t Z = et / TMath::Tan(theta);
100  Double_t E = et / TMath::Sin(theta);
101 
102  TLorentzVector* vec = new TLorentzVector(X, Y, Z, E);
103  return vec;
104 }
105 
106 void TFitParticleEtThetaPhi::setIni4Vec(const TLorentzVector* pini) {
107  // Set the initial 4vector. Will also set the
108  // inital parameter values
109 
110  if (pini == nullptr) {
111  _u1.SetXYZ(0., 0., 0.);
112  _u3.SetXYZ(0., 0., 0.);
113  _u2.SetXYZ(0., 0., 0.);
114  _pini.SetXYZT(0., 0., 0., 0.);
115  _pcurr = _pini;
116 
117  _iniparameters.ResizeTo(_nPar, 1);
118  _iniparameters(0, 0) = 0.;
119  _iniparameters(1, 0) = 0.;
120  _iniparameters(2, 0) = 0.;
121 
122  _parameters.ResizeTo(_nPar, 1);
123  _parameters(0, 0) = 0.;
124  _parameters(1, 0) = 0.;
125  _parameters(2, 0) = 0.;
126 
127  } else {
128  Double_t et = pini->E() * std::fabs(sin(pini->Theta()));
129  Double_t theta = pini->Theta();
130  Double_t phi = pini->Phi();
131 
132  _pini = (*pini);
133  _pcurr = _pini;
134 
135  _iniparameters.ResizeTo(_nPar, 1);
136  _iniparameters(0, 0) = et;
137  _iniparameters(1, 0) = theta;
138  _iniparameters(2, 0) = phi;
139 
140  _parameters.ResizeTo(_nPar, 1);
142 
143  _u1.SetXYZ(TMath::Cos(phi), TMath::Sin(phi), 0.); // the base vector of Et
144  _u2.SetXYZ(TMath::Cos(phi) * TMath::Cos(theta),
145  TMath::Sin(phi) * TMath::Cos(theta),
146  -1. * TMath::Sin(theta)); // the base vector of Eta ( same as the base vector for Theta)
147  _u3.SetXYZ(-1. * TMath::Sin(phi), TMath::Cos(phi), 0.); // the base vector of Phi
148  }
149 }
150 
152  // returns derivative dP/dy with P=(p,E) and y=(et, theta, phi)
153  // the free parameters of the fit. The columns of the matrix contain
154  // (dP/d(et), dP/d(theta), dP/d(phi)).
155 
156  TMatrixD* DerivativeMatrix = new TMatrixD(4, 3);
157  (*DerivativeMatrix) *= 0.;
158 
159  Double_t et = _parameters(0, 0);
160  Double_t theta = _parameters(1, 0);
161  Double_t phi = _parameters(2, 0);
162 
163  Double_t CotanTheta = 1. / TMath::Tan(theta);
164 
165  //1st column: dP/d(et)
166  (*DerivativeMatrix)(0, 0) = TMath::Cos(phi);
167  (*DerivativeMatrix)(1, 0) = TMath::Sin(phi);
168  (*DerivativeMatrix)(2, 0) = CotanTheta;
169  (*DerivativeMatrix)(3, 0) = 1. / TMath::Sin(theta);
170 
171  //2nd column: dP/d(theta)
172  (*DerivativeMatrix)(0, 1) = 0.;
173  (*DerivativeMatrix)(1, 1) = 0.;
174  (*DerivativeMatrix)(2, 1) = -1. * et * (1. + CotanTheta * CotanTheta);
175  (*DerivativeMatrix)(3, 1) = -1. * et * CotanTheta / (TMath::Sin(theta));
176 
177  //3rd column: dP/d(phi)
178  (*DerivativeMatrix)(0, 2) = -1. * et * TMath::Sin(phi);
179  (*DerivativeMatrix)(1, 2) = et * TMath::Cos(phi);
180  (*DerivativeMatrix)(2, 2) = 0.;
181  (*DerivativeMatrix)(3, 2) = 0.;
182 
183  return DerivativeMatrix;
184 }
185 
186 TMatrixD* TFitParticleEtThetaPhi::transform(const TLorentzVector& vec) {
187  // Returns the parameters corresponding to the given
188  // 4vector
189 
190  // retrieve parameters
191  TMatrixD* tparams = new TMatrixD(_nPar, 1);
192  (*tparams)(0, 0) = vec.E() * std::fabs(sin(vec.Theta()));
193  (*tparams)(1, 0) = vec.Theta();
194  (*tparams)(2, 0) = vec.Phi();
195 
196  return tparams;
197 }
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
#define X(str)
Definition: MuonsGrabber.cc:38
Log< level::Error, false > LogError
TLorentzVector _pini
TMatrixD * transform(const TLorentzVector &vec) override
TMatrixD _parameters
TLorentzVector _pcurr
TLorentzVector * calc4Vec(const TMatrixD *params) override
TAbsFitParticle * clone(const TString &newname="") const override
virtual void setCovMatrix(const TMatrixD *theCovMatrix)
void setIni4Vec(const TLorentzVector *pini) override
TMatrixD _iniparameters
TMatrixD * getDerivative() override
void init(TLorentzVector *pini, const TMatrixD *theCovMatrix)