CMS 3D CMS Logo

TFitParticleMCMomDev.cc
Go to the documentation of this file.
1 // Classname: TFitParticleMCMomDev
2 // Author: Jan E. Sundermann, Verena Klose (TU Dresden)
3 
4 //________________________________________________________________
5 //
6 // TFitParticleMCMomDev
7 // --------------------
8 //
9 // Particle with special parametrization of the momentum 4vector and
10 // constant mass (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) = Sqrt( |p|^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) = (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 TFitParticleMCMomDev::TFitParticleMCMomDev(TVector3* p, Double_t M, const TMatrixD* theCovMatrix) : TAbsFitParticle() {
51  init(p, M, theCovMatrix);
52 }
53 
55  const TString& name, const TString& title, TVector3* p, Double_t M, const TMatrixD* theCovMatrix)
57  init(p, M, theCovMatrix);
58 }
59 
60 TAbsFitParticle* TFitParticleMCMomDev::clone(const TString& newname) const {
61  // Returns a copy of itself
62 
63  TAbsFitParticle* myclone = new TFitParticleMCMomDev(*this);
64  if (newname.Length() > 0)
65  myclone->SetName(newname);
66  return myclone;
67 }
68 
69 //--------------
70 // Destructor --
71 //--------------
73 
74 //--------------
75 // Operations --
76 //--------------
77 void TFitParticleMCMomDev::init(TVector3* p, Double_t M, const TMatrixD* theCovMatrix) {
78  _nPar = 3;
79  setIni4Vec(p, M);
80  _iniparameters.ResizeTo(_nPar, 1);
81  _iniparameters(0, 0) = 1.;
82  _iniparameters(1, 0) = 0.;
83  _iniparameters(2, 0) = 0.;
84  _parameters.ResizeTo(_nPar, 1);
86  setCovMatrix(theCovMatrix);
87 }
88 
89 TLorentzVector* TFitParticleMCMomDev::calc4Vec(const TMatrixD* params) {
90  // Calculates a 4vector corresponding to the given
91  // parameter values
92 
93  if (params == nullptr) {
94  return nullptr;
95  }
96 
97  if (params->GetNcols() != 1 || params->GetNrows() != _nPar) {
98  edm::LogError("WrongMatrixSize") << GetName() << "::calc4Vec - Parameter matrix has wrong size.";
99  return nullptr;
100  }
101 
102  Double_t X = _pini.P() * (*params)(0, 0) * _u1.X() + (*params)(1, 0) * _u2.X() + (*params)(2, 0) * _u3.X();
103  Double_t Y = _pini.P() * (*params)(0, 0) * _u1.Y() + (*params)(1, 0) * _u2.Y() + (*params)(2, 0) * _u3.Y();
104  Double_t Z = _pini.P() * (*params)(0, 0) * _u1.Z() + (*params)(1, 0) * _u2.Z() + (*params)(2, 0) * _u3.Z();
105  Double_t E = TMath::Sqrt(X * X + Y * Y + Z * Z + _pini.M2());
106 
107  TLorentzVector* vec = new TLorentzVector(X, Y, Z, E);
108  return vec;
109 }
110 
111 void TFitParticleMCMomDev::setIni4Vec(const TLorentzVector* pini) {
112  // Set the initial 4vector. Will also set the
113  // inital parameter values
114 
115  TVector3 vec(pini->Vect());
116  setIni4Vec(&vec, pini->M());
117 }
118 
119 void TFitParticleMCMomDev::setIni4Vec(const TVector3* p, Double_t M) {
120  // Set the initial 4vector. Will also set the
121  // inital parameter values
122 
123  if (p == nullptr) {
124  _pini.SetXYZM(0., 0., 0., M);
125  _pcurr = _pini;
126 
127  } else {
128  _pini.SetXYZM(p->x(), p->y(), p->z(), M);
129  _pcurr = _pini;
130 
131  _u1 = (*p);
132  _u1 *= 1. / _u1.Mag();
133 
134  TVector3 uz(0., 0., 1.);
135  _u3 = uz.Cross(_u1);
136  _u3 *= 1. / _u3.Mag();
137 
138  _u2 = _u3.Cross(_u1);
139  _u2 *= 1. / _u2.Mag();
140  }
141 
143 }
144 
146  // returns derivative dP/dy with P=(p,E) and y=(r, theta, phi)
147  // the free parameters of the fit. The columns of the matrix contain
148  // (dP/dr, dP/dtheta, dP/dphi).
149 
150  TMatrixD* DerivativeMatrix = new TMatrixD(4, 3);
151  (*DerivativeMatrix) *= 0.;
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) = _pini.P() * _pini.P() * _parameters(0, 0) / _pcurr.E();
157 
158  // (*DerivativeMatrix)(3,0)=0.;
159 
160  //2nd column: dP/dtheta
161  (*DerivativeMatrix)(0, 1) = _u2.X();
162  (*DerivativeMatrix)(1, 1) = _u2.Y();
163  (*DerivativeMatrix)(2, 1) = _u2.Z();
164  (*DerivativeMatrix)(3, 1) = _parameters(1, 0) / _pcurr.E();
165 
166  //(*DerivativeMatrix)(3,1)=0.;
167 
168  //3rd column: dP/dphi
169  (*DerivativeMatrix)(0, 2) = _u3.X();
170  (*DerivativeMatrix)(1, 2) = _u3.Y();
171  (*DerivativeMatrix)(2, 2) = _u3.Z();
172  (*DerivativeMatrix)(3, 2) = _parameters(2, 0) / _pcurr.E();
173 
174  //(*DerivativeMatrix)(3,2)=0.;
175 
176  return DerivativeMatrix;
177 }
178 
179 TMatrixD* TFitParticleMCMomDev::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 
198  return tparams;
199 }
TAbsFitParticle::_iniparameters
TMatrixD _iniparameters
Definition: TAbsFitParticle.h:58
runGCPTkAlMap.title
string title
Definition: runGCPTkAlMap.py:94
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
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
TAbsFitParticle::_parameters
TMatrixD _parameters
Definition: TAbsFitParticle.h:59
TFitParticleMCMomDev::calc4Vec
TLorentzVector * calc4Vec(const TMatrixD *params) override
Definition: TFitParticleMCMomDev.cc:89
TAbsFitParticle::_pcurr
TLorentzVector _pcurr
Definition: TAbsFitParticle.h:61
TFitParticleMCMomDev
Definition: TFitParticleMCMomDev.h:10
TAbsFitParticle::_pini
TLorentzVector _pini
Definition: TAbsFitParticle.h:60
TAbsFitParticle::_covMatrix
TMatrixD _covMatrix
Definition: TAbsFitParticle.h:54
TFitParticleMCMomDev::~TFitParticleMCMomDev
~TFitParticleMCMomDev() override
Definition: TFitParticleMCMomDev.cc:72
TFitParticleMCMomDev::clone
TAbsFitParticle * clone(const TString &newname=TString("")) const override
Definition: TFitParticleMCMomDev.cc:60
TFitParticleMCMomDev::transform
TMatrixD * transform(const TLorentzVector &vec) override
Definition: TFitParticleMCMomDev.cc:179
TAbsFitParticle::_u2
TVector3 _u2
Definition: TAbsFitParticle.h:51
TAbsFitParticle::_nPar
Int_t _nPar
Definition: TAbsFitParticle.h:49
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
TFitParticleMCMomDev::init
void init(TVector3 *p, Double_t M, const TMatrixD *theCovMatrix)
Definition: TFitParticleMCMomDev.cc:77
TFitParticleMCMomDev::TFitParticleMCMomDev
TFitParticleMCMomDev()
Definition: TFitParticleMCMomDev.cc:32
edm::LogError
Log< level::Error, false > LogError
Definition: MessageLogger.h:123
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
TFitParticleMCMomDev::setIni4Vec
void setIni4Vec(const TLorentzVector *pini) override
Definition: TFitParticleMCMomDev.cc:111
BeamSpotPI::Z
Definition: BeamSpotPayloadInspectorHelper.h:32
TFitParticleMCMomDev::getDerivative
TMatrixD * getDerivative() override
Definition: TFitParticleMCMomDev.cc:145
TFitParticleMCMomDev.h