CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_1/src/PhysicsTools/KinFitter/src/TFitParticleMCCart.cc

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