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 //
7 // TFitParticleMCMomDev
8 // --------------------
9 //
10 // Particle with special parametrization of the momentum 4vector and
11 // constant mass (3 free parameters). The parametrization is chosen as
12 // follows:
13 //
14 // p = r*|p|*u_r + theta*u_theta + phi*u_phi
15 // E(fit) = Sqrt( |p|^2 + m^2 )
16 //
17 // with u_r = p/|p|
18 // u_phi = (u_z x u_r)/|u_z x u_r|
19 // u_theta = (u_r x u_phi)/|u_r x u_phi|
20 //
21 // The initial parameters values are chosen like (r, theta, phi) = (1., 0., 0.)
22 // corresponding to the measured momentum.
23 //
24 
25 #include <iostream>
28 #include "TMath.h"
29 
30 
31 //----------------
32 // Constructor --
33 //----------------
36 {
37  init( 0, 0., 0);
38 }
39 
41  :TAbsFitParticle( fitParticle.GetName(), fitParticle.GetTitle() )
42 {
43 
44  _nPar = fitParticle._nPar;
45  _u1 = fitParticle._u1;
46  _u2 = fitParticle._u2;
47  _u3 = fitParticle._u3;
48  _covMatrix.ResizeTo( fitParticle._covMatrix );
49  _covMatrix = fitParticle._covMatrix;
50  _iniparameters.ResizeTo( fitParticle._iniparameters );
51  _iniparameters = fitParticle._iniparameters;
52  _parameters.ResizeTo( fitParticle._parameters );
53  _parameters = fitParticle._parameters;
54  _pini = fitParticle._pini;
55  _pcurr = fitParticle._pcurr;
56 
57 }
58 
59 TFitParticleMCMomDev::TFitParticleMCMomDev(TVector3* p, Double_t M, const TMatrixD* theCovMatrix)
61 {
62  init(p, M, theCovMatrix);
63 }
64 
65 TFitParticleMCMomDev::TFitParticleMCMomDev(const TString &name, const TString &title,
66  TVector3* p, Double_t M, const TMatrixD* theCovMatrix)
67  :TAbsFitParticle(name, title)
68 {
69  init(p, M, theCovMatrix);
70 }
71 
72 TAbsFitParticle* TFitParticleMCMomDev::clone(const TString& newname ) const {
73  // Returns a copy of itself
74 
75  TAbsFitParticle* myclone = new TFitParticleMCMomDev( *this );
76  if ( newname.Length() > 0 ) myclone->SetName(newname);
77  return myclone;
78 
79 }
80 
81 //--------------
82 // Destructor --
83 //--------------
85 
86 }
87 
88 
89 //--------------
90 // Operations --
91 //--------------
92 void TFitParticleMCMomDev::init(TVector3* p, Double_t M, const TMatrixD* theCovMatrix) {
93 
94  _nPar = 3;
95  setIni4Vec(p, M);
96  _iniparameters.ResizeTo(_nPar,1);
97  _iniparameters(0,0)=1.;
98  _iniparameters(1,0)=0.;
99  _iniparameters(2,0)=0.;
100  _parameters.ResizeTo(_nPar, 1);
102  setCovMatrix(theCovMatrix);
103 
104 }
105 
106 TLorentzVector* TFitParticleMCMomDev::calc4Vec( const TMatrixD* params ) {
107  // Calculates a 4vector corresponding to the given
108  // parameter values
109 
110  if (params == 0) {
111  return 0;
112  }
113 
114  if ( params->GetNcols() != 1 || params->GetNrows() !=_nPar ) {
115  edm::LogError ("WrongMatrixSize")
116  << GetName() << "::calc4Vec - Parameter matrix has wrong size.";
117  return 0;
118  }
119 
120  Double_t X = _pini.P() * (*params)(0,0) *_u1.X()+
121  (*params)(1,0) * _u2.X()+
122  (*params)(2,0) * _u3.X() ;
123  Double_t Y = _pini.P() * (*params)(0,0) *_u1.Y()+
124  (*params)(1,0) * _u2.Y()+
125  (*params)(2,0) * _u3.Y() ;
126  Double_t Z = _pini.P() * (*params)(0,0) *_u1.Z()+
127  (*params)(1,0) * _u2.Z()+
128  (*params)(2,0) * _u3.Z() ;
129  Double_t E = TMath::Sqrt( X*X + Y*Y + Z*Z + _pini.M2() );
130 
131  TLorentzVector* vec = new TLorentzVector( X, Y, Z, E );
132  return vec;
133 
134 }
135 
136 void TFitParticleMCMomDev::setIni4Vec(const TLorentzVector* pini) {
137  // Set the initial 4vector. Will also set the
138  // inital parameter values
139 
140  TVector3 vec( pini->Vect() );
141  setIni4Vec( &vec, pini->M() );
142 
143 }
144 
145 void TFitParticleMCMomDev::setIni4Vec(const TVector3* p, Double_t M) {
146  // Set the initial 4vector. Will also set the
147  // inital parameter values
148 
149  if ( p == 0 ) {
150 
151  _pini.SetXYZM( 0., 0., 0., M);
152  _pcurr = _pini;
153 
154  } else {
155 
156  _pini.SetXYZM( p->x(), p->y(), p->z(), M);
157  _pcurr = _pini;
158 
159  _u1 = (*p);
160  _u1 *= 1./_u1.Mag();
161 
162  TVector3 uz(0., 0., 1.);
163  _u3 = uz.Cross(_u1);
164  _u3 *= 1./_u3.Mag();
165 
166  _u2 = _u3.Cross(_u1);
167  _u2 *= 1./_u2.Mag();
168 
169  }
170 
172 
173 }
174 
176  // returns derivative dP/dy with P=(p,E) and y=(r, theta, phi)
177  // the free parameters of the fit. The columns of the matrix contain
178  // (dP/dr, dP/dtheta, dP/dphi).
179 
180  TMatrixD* DerivativeMatrix = new TMatrixD(4,3);
181  (*DerivativeMatrix) *= 0.;
182  //1st column: dP/dr
183  (*DerivativeMatrix)(0,0)=_pini.P()*_u1.X();
184  (*DerivativeMatrix)(1,0)=_pini.P()*_u1.Y();
185  (*DerivativeMatrix)(2,0)=_pini.P()*_u1.Z();
186  (*DerivativeMatrix)(3,0)=_pini.P()*_pini.P()*_parameters(0,0)/_pcurr.E();
187 
188 // (*DerivativeMatrix)(3,0)=0.;
189 
190  //2nd column: dP/dtheta
191  (*DerivativeMatrix)(0,1)=_u2.X();
192  (*DerivativeMatrix)(1,1)=_u2.Y();
193  (*DerivativeMatrix)(2,1)=_u2.Z();
194  (*DerivativeMatrix)(3,1)=_parameters(1,0)/_pcurr.E();
195 
196  //(*DerivativeMatrix)(3,1)=0.;
197 
198  //3rd column: dP/dphi
199  (*DerivativeMatrix)(0,2)=_u3.X();
200  (*DerivativeMatrix)(1,2)=_u3.Y();
201  (*DerivativeMatrix)(2,2)=_u3.Z();
202  (*DerivativeMatrix)(3,2)=_parameters(2,0)/_pcurr.E();
203 
204  //(*DerivativeMatrix)(3,2)=0.;
205 
206  return DerivativeMatrix;
207 
208 }
209 
210 TMatrixD* TFitParticleMCMomDev::transform(const TLorentzVector& vec) {
211  // Returns the parameters corresponding to the given
212  // 4vector wrt. to the current base vectors u_r, u_theta, and u_phi
213 
214  // construct rotation matrix
215  TRotation rot;
216  rot.RotateAxes( _u1, _u2, _u3 );
217  rot.Invert();
218 
219  // rotate vector
220  TVector3 vec3( vec.Vect() );
221  vec3.Transform( rot );
222 
223  // retrieve parameters
224  TMatrixD* tparams = new TMatrixD( _nPar, 1 );
225  (*tparams)(0,0) = vec3(0)/_pini.P();
226  (*tparams)(1,0) = vec3(1);
227  (*tparams)(2,0) = vec3(2);
228 
229  return tparams;
230 
231 }
virtual TAbsFitParticle * clone(const TString &newname=TString("")) const
virtual TLorentzVector * calc4Vec(const TMatrixD *params)
#define X(str)
Definition: MuonsGrabber.cc:48
void init(TVector3 *p, Double_t M, const TMatrixD *theCovMatrix)
virtual TMatrixD * getDerivative()
TLorentzVector _pini
std::vector< vec2 > vec3
Definition: HCALResponse.h:17
TMatrixD _parameters
TLorentzVector _pcurr
virtual void setCovMatrix(const TMatrixD *theCovMatrix)
virtual TMatrixD * transform(const TLorentzVector &vec)
TMatrixD _iniparameters
virtual void setIni4Vec(const TLorentzVector *pini)