CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC4_patch1/src/PhysicsTools/KinFitter/src/TFitParticleSpher.cc

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