CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC2/src/PhysicsTools/KinFitter/src/TFitParticleECart.cc

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