CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_3/src/PhysicsTools/KinFitter/src/TFitParticleMCSpher.cc

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