CMS 3D CMS Logo

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

Generated on Tue Jun 9 17:41:16 2009 for CMSSW by  doxygen 1.5.4