CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_1/src/PhysicsTools/KinFitter/src/TFitParticleMCPInvSpher.cc

Go to the documentation of this file.
00001 // Classname: TFitParticleMCPInvSpher
00002 // Author: Jan E. Sundermann, Verena Klose (TU Dresden)      
00003 
00004 
00005 //________________________________________________________________
00006 // 
00007 // TFitParticleMCPInvSpher::
00008 // --------------------
00009 //
00010 // Particle with 1/r, theta, and phi parametrization of the momentum 4vector and
00011 // constant mass (3 free parameters). The parametrization is chosen as
00012 // follows:
00013 //
00014 // p = (1/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/TFitParticleMCPInvSpher.h"
00021 #include "TMath.h"
00022 
00023 
00024 //----------------
00025 // Constructor --
00026 //----------------
00027 TFitParticleMCPInvSpher::TFitParticleMCPInvSpher()
00028   :TAbsFitParticle()
00029 { 
00030   init( 0, 0., 0);
00031 }
00032 
00033 TFitParticleMCPInvSpher::TFitParticleMCPInvSpher( const TFitParticleMCPInvSpher& 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 TFitParticleMCPInvSpher::TFitParticleMCPInvSpher(TVector3* p, Double_t M, const TMatrixD* theCovMatrix)
00053   :TAbsFitParticle()
00054 { 
00055   init(p, M, theCovMatrix);
00056 }
00057 
00058 TFitParticleMCPInvSpher::TFitParticleMCPInvSpher(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* TFitParticleMCPInvSpher::clone( TString newname ) const {
00066   // Returns a copy of itself
00067   
00068   TAbsFitParticle* myclone = new TFitParticleMCPInvSpher( *this );
00069   if ( newname.Length() > 0 ) myclone->SetName(newname);
00070   return myclone;
00071 
00072 }
00073 
00074 //--------------
00075 // Destructor --
00076 //--------------
00077 TFitParticleMCPInvSpher::~TFitParticleMCPInvSpher() {
00078 
00079 }
00080 
00081 
00082 //--------------
00083 // Operations --
00084 //--------------
00085 void TFitParticleMCPInvSpher::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* TFitParticleMCPInvSpher::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 = 1/r*TMath::Cos(phi)*TMath::Sin(theta);
00112   Double_t Y = 1/r*TMath::Sin(phi)*TMath::Sin(theta);
00113   Double_t Z = 1/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 TFitParticleMCPInvSpher::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 TFitParticleMCPInvSpher::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 = 1/_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* TFitParticleMCPInvSpher::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 p = 1./r;
00181   Double_t theta = _parameters(1,0);
00182   Double_t phi = _parameters(2,0);
00183 
00184   //1st column: dP/dr
00185   (*DerivativeMatrix)(0,0) = -1.*p*p*TMath::Cos(phi)*TMath::Sin(theta);
00186   (*DerivativeMatrix)(1,0) = -1.*p*p*TMath::Sin(phi)*TMath::Sin(theta);
00187   (*DerivativeMatrix)(2,0) = -1.*p*p*TMath::Cos(theta);
00188   (*DerivativeMatrix)(3,0) = -1.*p*p*p/_pcurr.E();
00189 
00190   //2nd column: dP/dtheta
00191   (*DerivativeMatrix)(0,1) = p*TMath::Cos(phi)*TMath::Cos(theta);
00192   (*DerivativeMatrix)(1,1) = p*TMath::Sin(phi)*TMath::Cos(theta);
00193   (*DerivativeMatrix)(2,1) = -1.*p*TMath::Sin(theta);
00194   (*DerivativeMatrix)(3,1) = 0.;
00195 
00196    //3rd column: dP/dphi
00197   (*DerivativeMatrix)(0,2) = -1.*p*TMath::Sin(phi)*TMath::Sin(theta);
00198   (*DerivativeMatrix)(1,2) = p*TMath::Cos(phi)*TMath::Sin(theta);;
00199   (*DerivativeMatrix)(2,2) = 0.;
00200   (*DerivativeMatrix)(3,2) = 0.;
00201 
00202   return DerivativeMatrix;  
00203 
00204 }
00205 
00206 TMatrixD* TFitParticleMCPInvSpher::transform(const TLorentzVector& vec) {
00207   // Returns the parameters corresponding to the given 
00208   // 4vector
00209 
00210   // retrieve parameters
00211   TMatrixD* tparams = new TMatrixD( _nPar, 1 );
00212   (*tparams)(0,0) = 1./vec.P();
00213   (*tparams)(1,0) = vec.Theta();
00214   (*tparams)(2,0) = vec.Phi();
00215 
00216   return tparams;
00217 
00218 }