CMS 3D CMS Logo

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