CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_10_patch1/src/PhysicsTools/KinFitter/src/TFitParticleCart.cc

Go to the documentation of this file.
00001 // Classname: TFitParticleCart
00002 // Author: Jan E. Sundermann, Verena Klose (TU Dresden)      
00003 
00004 
00005 //________________________________________________________________
00006 // 
00007 // TFitParticleCart::
00008 // --------------------
00009 //
00010 // Particle with cartesian 4vector parametrization and free mass
00011 // [four free parameters (px, py, pz, d) with initial values
00012 //  (px, py, pz, 1)]
00013 //
00014 // p = px*u1 + py*u2 + pz*u3
00015 // E = Sqrt( |p|^2 + d^2*m^2 )
00016 //
00017 
00018 #include <iostream>
00019 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00020 #include "PhysicsTools/KinFitter/interface/TFitParticleCart.h"
00021 #include "TMath.h"
00022 
00023 
00024 //----------------
00025 // Constructor --
00026 //----------------
00027 TFitParticleCart::TFitParticleCart()
00028   :TAbsFitParticle()  
00029 {
00030   init(0, 0);
00031 }
00032 
00033 TFitParticleCart::TFitParticleCart( const TFitParticleCart& fitParticle )
00034   :TAbsFitParticle( fitParticle.GetName(), fitParticle.GetTitle() )
00035 {
00036 
00037   _nPar = fitParticle._nPar;
00038   _u1 = fitParticle._u1;
00039   _u2 = fitParticle._u2;
00040   _u3 = fitParticle._u3;
00041   _covMatrix.ResizeTo(  fitParticle._covMatrix );
00042   _covMatrix = fitParticle._covMatrix;
00043   _iniparameters.ResizeTo( fitParticle._iniparameters );
00044   _iniparameters = fitParticle._iniparameters;
00045   _parameters.ResizeTo( fitParticle._parameters );
00046   _parameters = fitParticle._parameters;
00047   _pini = fitParticle._pini;
00048   _pcurr = fitParticle._pcurr;
00049 
00050 }
00051 
00052 TFitParticleCart::TFitParticleCart(TLorentzVector* pini, const TMatrixD* theCovMatrix)
00053   :TAbsFitParticle()  
00054 {
00055   init(pini, theCovMatrix);
00056 }
00057 
00058 TFitParticleCart::TFitParticleCart(const TString &name, const TString &title, 
00059                                    TLorentzVector* pini, const TMatrixD* theCovMatrix)
00060   :TAbsFitParticle(name, title)  
00061 {
00062   init(pini, theCovMatrix);
00063 }
00064 
00065 TAbsFitParticle* TFitParticleCart::clone( TString newname ) const {
00066   // Returns a copy of itself
00067 
00068   TAbsFitParticle* myclone = new TFitParticleCart( *this );
00069   if ( newname.Length() > 0 ) myclone->SetName(newname);
00070   return myclone;
00071 
00072 }
00073 
00074 //--------------
00075 // Destructor --
00076 //--------------
00077 TFitParticleCart::~TFitParticleCart() {
00078 
00079 }
00080 
00081 //--------------
00082 // Operations --
00083 //--------------
00084 void TFitParticleCart::init(TLorentzVector* pini, const TMatrixD* theCovMatrix ) {
00085 
00086   _nPar = 4;
00087   setIni4Vec(pini);
00088   setCovMatrix(theCovMatrix);
00089 
00090 }
00091 
00092 TLorentzVector* TFitParticleCart::calc4Vec( const TMatrixD* params ) {
00093   // Calculates a 4vector corresponding to the given
00094   // parameter values
00095 
00096   if (params == 0) {
00097     return 0;
00098   }
00099 
00100   if ( params->GetNcols() != 1 || params->GetNrows() !=_nPar ) {
00101     edm::LogError ("WrongMatrixSize")
00102       << GetName() << "::calc4Vec - Parameter matrix has wrong size.";
00103     return 0;
00104   }
00105   
00106   Double_t X = (*params)(0,0);
00107   Double_t Y = (*params)(1,0);
00108   Double_t Z = (*params)(2,0);
00109   Double_t E =  TMath::Sqrt( X*X + Y*Y + Z*Z + (*params)(3,0)*(*params)(3,0)*_pini.M2() );
00110 
00111   TLorentzVector* vec = new TLorentzVector( X, Y, Z, E );
00112   return vec;
00113 
00114 }
00115 
00116 void TFitParticleCart::setIni4Vec(const TLorentzVector* pini) {
00117   // Set the initial 4vector. Will also set the 
00118   // inital parameter values
00119 
00120   if (pini == 0) {
00121 
00122     _u1.SetXYZ(0., 0., 0.);
00123     _u3.SetXYZ(0., 0., 0.);
00124     _u2.SetXYZ(0., 0., 0.);
00125     _pini.SetXYZT(0., 0., 0., 0.);
00126     _pcurr = _pini;
00127 
00128     _iniparameters.ResizeTo(_nPar,1);
00129     _iniparameters(0,0)=0;
00130     _iniparameters(1,0)=0;
00131     _iniparameters(2,0)=0;
00132     _iniparameters(3,0)=0.;
00133 
00134     _parameters.ResizeTo(_nPar,1);
00135     _parameters(0,0)=0.;
00136     _parameters(1,0)=0.;
00137     _parameters(2,0)=0.;   
00138     _parameters(3,0)=0.;   
00139     
00140   } else {
00141     
00142     _pini = (*pini);
00143     _pcurr = _pini;
00144 
00145     _u1.SetXYZ( 1., 0., 0. );
00146     _u2.SetXYZ( 0., 1., 0. );
00147     _u3.SetXYZ( 0., 0., 1. );
00148   
00149     _iniparameters.ResizeTo(_nPar,1);
00150     _iniparameters(0,0)=_pini.X();
00151     _iniparameters(1,0)=_pini.Y();
00152     _iniparameters(2,0)=_pini.Z();
00153     _iniparameters(3,0)=1.;
00154     _parameters.ResizeTo(_nPar,1);
00155     _parameters = _iniparameters;
00156 
00157   }
00158 
00159 }
00160 
00161 TMatrixD* TFitParticleCart::getDerivative() {
00162   // returns derivative dP/dy with P=(p,E) and y=(px, py, pz, d) 
00163   // the free parameters of the fit. The columns of the matrix contain 
00164   // (dP/dpx, dP/dpy, ...).
00165 
00166   TMatrixD* DerivativeMatrix = new TMatrixD(4,4);
00167   (*DerivativeMatrix) *= 0.;
00168 
00169   //1st column: dP/dx
00170   (*DerivativeMatrix)(0,0)=1.;
00171   (*DerivativeMatrix)(1,0)=0.;
00172   (*DerivativeMatrix)(2,0)=0.;
00173   (*DerivativeMatrix)(3,0)=0.;
00174 
00175   //2nd column: dP/dy
00176   (*DerivativeMatrix)(0,1)=0;
00177   (*DerivativeMatrix)(1,1)=1;
00178   (*DerivativeMatrix)(2,1)=0;
00179   (*DerivativeMatrix)(3,1)=0.;
00180 
00181    //3rd column: dP/dz
00182   (*DerivativeMatrix)(0,2)=0.;
00183   (*DerivativeMatrix)(1,2)=0.;
00184   (*DerivativeMatrix)(2,2)=1.;
00185   (*DerivativeMatrix)(3,2)=0.;
00186 
00187    //4th column: dP/dm
00188   (*DerivativeMatrix)(0,3)=0.;
00189   (*DerivativeMatrix)(1,3)=0.;
00190   (*DerivativeMatrix)(2,3)=0.;
00191   (*DerivativeMatrix)(3,3)=_pini.M()*_pini.M()*_parameters(3,0)/_pcurr.E();
00192 
00193   return DerivativeMatrix;  
00194 }
00195 
00196 TMatrixD* TFitParticleCart::transform(const TLorentzVector& vec) {
00197   // Returns the parameters corresponding to the given 
00198   // 4vector
00199 
00200   TMatrixD* tparams = new TMatrixD( _nPar, 1 );
00201   (*tparams)(0,0) = vec.X();
00202   (*tparams)(1,0) = vec.Y();
00203   (*tparams)(2,0) = vec.Z();
00204   (*tparams)(3,0) = vec.M()/_pini.M();
00205 
00206   return tparams;
00207 
00208 }