CMS 3D CMS Logo

TFitParticleMomDev.cc
Go to the documentation of this file.
1 // Classname: TFitParticleMomDev
2 // Author: Jan E. Sundermann, Verena Klose (TU Dresden)
3 
4 //________________________________________________________________
5 //
6 // TFitParticleMomDev
7 // --------------------
8 //
9 // Particle with special parametrization of the momentum 4vector and
10 // free mass (4 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) = Sqrt( |p|^2 + d^2*m^2 )
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, d) = (1., 0., 0., 1.)
21 // corresponding to the measured momentum and mass.
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 TFitParticleMomDev::TFitParticleMomDev(TLorentzVector* pini, const TMatrixD* theCovMatrix) : TAbsFitParticle() {
51  init(pini, theCovMatrix);
52 }
53 
55  const TString& title,
56  TLorentzVector* pini,
57  const TMatrixD* theCovMatrix)
59  init(pini, theCovMatrix);
60 }
61 
62 TAbsFitParticle* TFitParticleMomDev::clone(const TString& newname) const {
63  // Returns a copy of itself
64 
65  TAbsFitParticle* myclone = new TFitParticleMomDev(*this);
66  if (newname.Length() > 0)
67  myclone->SetName(newname);
68  return myclone;
69 }
70 
71 //--------------
72 // Destructor --
73 //--------------
75 
76 //--------------
77 // Operations --
78 //--------------
79 void TFitParticleMomDev::init(TLorentzVector* pini, const TMatrixD* theCovMatrix) {
80  _nPar = 4;
81  _iniparameters.ResizeTo(_nPar, 1);
82  _iniparameters(0, 0) = 1.;
83  _iniparameters(1, 0) = 0.;
84  _iniparameters(2, 0) = 0.;
85  _iniparameters(3, 0) = 1.;
86  _parameters.ResizeTo(_nPar, 1);
88  setIni4Vec(pini);
89  setCovMatrix(theCovMatrix);
90 }
91 
92 void TFitParticleMomDev::setIni4Vec(const TLorentzVector* pini) {
93  // Set the initial 4vector. Will also set the
94  // inital parameter values
95 
96  if (pini == nullptr) {
97  _u1.SetXYZ(0., 0., 0.);
98  _u3.SetXYZ(0., 0., 0.);
99  _u2.SetXYZ(0., 0., 0.);
100  _pini.SetXYZT(0., 0., 0., 0.);
101  _pcurr = _pini;
102 
103  } else {
104  _pini = (*pini);
105  _pcurr = _pini;
106 
107  _u1 = pini->Vect();
108  _u1 *= 1. / _u1.Mag();
109 
110  TVector3 uz(0., 0., 1.);
111  _u3 = uz.Cross(_u1);
112  _u3 *= 1. / _u3.Mag();
113 
114  _u2 = _u3.Cross(_u1);
115  _u2 *= 1. / _u2.Mag();
116  }
117 
118  // reset parameters
120 }
121 
122 TLorentzVector* TFitParticleMomDev::calc4Vec(const TMatrixD* params) {
123  // Calculates a 4vector corresponding to the given
124  // parameter values
125 
126  if (params == nullptr) {
127  return nullptr;
128  }
129 
130  if (params->GetNcols() != 1 || params->GetNrows() != _nPar) {
131  edm::LogError("WrongMatrixSize") << GetName() << "::calc4Vec - Parameter matrix has wrong size.";
132  return nullptr;
133  }
134 
135  Double_t X = _pini.P() * (*params)(0, 0) * _u1.X() + (*params)(1, 0) * _u2.X() + (*params)(2, 0) * _u3.X();
136  Double_t Y = _pini.P() * (*params)(0, 0) * _u1.Y() + (*params)(1, 0) * _u2.Y() + (*params)(2, 0) * _u3.Y();
137  Double_t Z = _pini.P() * (*params)(0, 0) * _u1.Z() + (*params)(1, 0) * _u2.Z() + (*params)(2, 0) * _u3.Z();
138  Double_t E = TMath::Sqrt(X * X + Y * Y + Z * Z + (*params)(3, 0) * (*params)(3, 0) * _pini.M2());
139 
140  TLorentzVector* vec = new TLorentzVector(X, Y, Z, E);
141  return vec;
142 }
143 
145  // returns derivative dP/dy with P=(p,E) and y=(r, theta, phi, d)
146  // the free parameters of the fit. The columns of the matrix contain
147  // (dP/dr, dP/dtheta, dP/dphi, dP/dd).
148 
149  TMatrixD* DerivativeMatrix = new TMatrixD(4, 4);
150  (*DerivativeMatrix) *= 0.;
151 
152  //1st column: dP/dr
153  (*DerivativeMatrix)(0, 0) = _pini.P() * _u1.X();
154  (*DerivativeMatrix)(1, 0) = _pini.P() * _u1.Y();
155  (*DerivativeMatrix)(2, 0) = _pini.P() * _u1.Z();
156  (*DerivativeMatrix)(3, 0) = 0.;
157 
158  //2nd column: dP/dtheta
159  (*DerivativeMatrix)(0, 1) = _u2.X();
160  (*DerivativeMatrix)(1, 1) = _u2.Y();
161  (*DerivativeMatrix)(2, 1) = _u2.Z();
162  (*DerivativeMatrix)(3, 1) = 0.;
163 
164  //3rd column: dP/dphi
165  (*DerivativeMatrix)(0, 2) = _u3.X();
166  (*DerivativeMatrix)(1, 2) = _u3.Y();
167  (*DerivativeMatrix)(2, 2) = _u3.Z();
168  (*DerivativeMatrix)(3, 2) = 0.;
169 
170  //4th column: dP/dm
171  (*DerivativeMatrix)(0, 3) = 0.;
172  (*DerivativeMatrix)(1, 3) = 0.;
173  (*DerivativeMatrix)(2, 3) = 0.;
174  (*DerivativeMatrix)(3, 3) = _pini.M() * _pini.M() * _parameters(3, 0) / _pcurr.E();
175 
176  return DerivativeMatrix;
177 }
178 
179 TMatrixD* TFitParticleMomDev::transform(const TLorentzVector& vec) {
180  // Returns the parameters corresponding to the given
181  // 4vector wrt. to the current base vectors u_r, u_theta, and u_phi
182 
183  // construct rotation matrix
184  TRotation rot;
185  rot.RotateAxes(_u1, _u2, _u3);
186  rot.Invert();
187 
188  // rotate vector
189  TVector3 vec3(vec.Vect());
190  vec3.Transform(rot);
191 
192  // retrieve parameters
193  TMatrixD* tparams = new TMatrixD(_nPar, 1);
194  (*tparams)(0, 0) = vec3(0) / _pini.P();
195  (*tparams)(1, 0) = vec3(1);
196  (*tparams)(2, 0) = vec3(2);
197  (*tparams)(3, 0) = vec.M() / _pini.M();
198 
199  return tparams;
200 }
TAbsFitParticle::_iniparameters
TMatrixD _iniparameters
Definition: TAbsFitParticle.h:58
TFitParticleMomDev::init
void init(TLorentzVector *pini, const TMatrixD *theCovMatrix)
Definition: TFitParticleMomDev.cc:79
runGCPTkAlMap.title
string title
Definition: runGCPTkAlMap.py:94
TFitParticleMomDev::calc4Vec
TLorentzVector * calc4Vec(const TMatrixD *params) override
Definition: TFitParticleMomDev.cc:122
MessageLogger.h
vec3
std::vector< vec2 > vec3
Definition: HCALResponse.h:17
X
#define X(str)
Definition: MuonsGrabber.cc:38
CalibrationSummaryClient_cfi.params
params
Definition: CalibrationSummaryClient_cfi.py:14
TAbsFitParticle::_parameters
TMatrixD _parameters
Definition: TAbsFitParticle.h:59
TAbsFitParticle::_pcurr
TLorentzVector _pcurr
Definition: TAbsFitParticle.h:61
TFitParticleMomDev::setIni4Vec
void setIni4Vec(const TLorentzVector *pini) override
Definition: TFitParticleMomDev.cc:92
TAbsFitParticle::_pini
TLorentzVector _pini
Definition: TAbsFitParticle.h:60
TAbsFitParticle::_covMatrix
TMatrixD _covMatrix
Definition: TAbsFitParticle.h:54
TFitParticleMomDev
Definition: TFitParticleMomDev.h:10
TAbsFitParticle::_u2
TVector3 _u2
Definition: TAbsFitParticle.h:51
TAbsFitParticle::_nPar
Int_t _nPar
Definition: TAbsFitParticle.h:49
TFitParticleMomDev::TFitParticleMomDev
TFitParticleMomDev()
Definition: TFitParticleMomDev.cc:32
TFitParticleMomDev::getDerivative
TMatrixD * getDerivative() override
Definition: TFitParticleMomDev.cc:144
TAbsFitParticle
Definition: TAbsFitParticle.h:9
TAbsFitParticle::setCovMatrix
virtual void setCovMatrix(const TMatrixD *theCovMatrix)
Definition: TAbsFitParticle.cc:98
TAbsFitParticle::_u3
TVector3 _u3
Definition: TAbsFitParticle.h:52
edm::LogError
Log< level::Error, false > LogError
Definition: MessageLogger.h:123
TFitParticleMomDev::~TFitParticleMomDev
~TFitParticleMomDev() override
Definition: TFitParticleMomDev.cc:74
TFitParticleMomDev.h
TAbsFitParticle::_u1
TVector3 _u1
Definition: TAbsFitParticle.h:50
makeMuonMisalignmentScenario.rot
rot
Definition: makeMuonMisalignmentScenario.py:322
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
BeamSpotPI::Y
Definition: BeamSpotPayloadInspectorHelper.h:31
BeamSpotPI::Z
Definition: BeamSpotPayloadInspectorHelper.h:32
TFitParticleMomDev::transform
TMatrixD * transform(const TLorentzVector &vec) override
Definition: TFitParticleMomDev.cc:179
TFitParticleMomDev::clone
TAbsFitParticle * clone(const TString &newname=TString("")) const override
Definition: TFitParticleMomDev.cc:62