CMS 3D CMS Logo

CMSSW_4_4_3_patch1/src/PhysicsTools/KinFitter/src/TFitParticleEtThetaPhi.cc

Go to the documentation of this file.
00001 // Classname: TFitParticleEtThetaPhi
00002 // Author: S.Paktinat(IPM, CMS)     
00003 // 27 July 2005
00004 
00005 //________________________________________________________________
00006 // 
00007 // TFitParticleEtThetaPhi::
00008 // --------------------
00009 //
00010 // Particle with a special parametrization useful in hadron 
00011 // colliders (3 free parameters (Et, Eta, Phi). The parametrization is 
00012 // chosen as follows:
00013 //
00014 // p = (EtCosPhi, EtSinPhi, Et/Tan(Theta)
00015 // E =  Et/Sin(Theta)
00016 //
00017 
00018 #include <iostream>
00019 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00020 #include "PhysicsTools/KinFitter/interface/TFitParticleEtThetaPhi.h"
00021 #include "TMath.h"
00022 #include <cmath>
00023 
00024 //----------------
00025 // Constructor --
00026 //----------------
00027 TFitParticleEtThetaPhi::TFitParticleEtThetaPhi()
00028   :TAbsFitParticle()  
00029 {
00030   init(0, 0);
00031 }
00032 
00033 TFitParticleEtThetaPhi::TFitParticleEtThetaPhi( const TFitParticleEtThetaPhi& 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 TFitParticleEtThetaPhi::TFitParticleEtThetaPhi(TLorentzVector* pini, const TMatrixD* theCovMatrix)
00053   :TAbsFitParticle()  
00054 {
00055   init(pini, theCovMatrix);
00056 }
00057 
00058 TFitParticleEtThetaPhi::TFitParticleEtThetaPhi(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* TFitParticleEtThetaPhi::clone( TString newname ) const {
00066   // Returns a copy of itself
00067   
00068   TAbsFitParticle* myclone = new TFitParticleEtThetaPhi( *this );
00069   if ( newname.Length() > 0 ) myclone->SetName(newname);
00070   return myclone;
00071 
00072 }
00073 
00074 //--------------
00075 // Destructor --
00076 //--------------
00077 TFitParticleEtThetaPhi::~TFitParticleEtThetaPhi() {
00078 
00079 }
00080 
00081 //--------------
00082 // Operations --
00083 //--------------
00084 void TFitParticleEtThetaPhi::init(TLorentzVector* pini, const TMatrixD* theCovMatrix ) {
00085 
00086   _nPar = 3;
00087   setIni4Vec(pini);
00088   setCovMatrix(theCovMatrix);
00089 
00090 }
00091 
00092 TLorentzVector* TFitParticleEtThetaPhi::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 et = (*params)(0,0);
00107   Double_t theta = (*params)(1,0);
00108   Double_t phi = (*params)(2,0);
00109 
00110   Double_t X = et*TMath::Cos(phi);
00111   Double_t Y = et*TMath::Sin(phi);
00112   Double_t Z = et/TMath::Tan(theta);
00113   Double_t E = et/TMath::Sin(theta);
00114                 
00115   TLorentzVector* vec = new TLorentzVector( X, Y, Z, E );
00116   return vec;
00117 
00118 }
00119 
00120 void TFitParticleEtThetaPhi::setIni4Vec(const TLorentzVector* pini) {
00121   // Set the initial 4vector. Will also set the 
00122   // inital parameter values 
00123 
00124   if (pini == 0) {
00125 
00126     _u1.SetXYZ(0., 0., 0.);
00127     _u3.SetXYZ(0., 0., 0.);
00128     _u2.SetXYZ(0., 0., 0.);
00129     _pini.SetXYZT(0., 0., 0., 0.);
00130     _pcurr = _pini;
00131 
00132     _iniparameters.ResizeTo(_nPar,1);
00133     _iniparameters(0,0) = 0.;
00134     _iniparameters(1,0) = 0.;
00135     _iniparameters(2,0) = 0.;
00136     
00137     _parameters.ResizeTo(_nPar,1);
00138     _parameters(0,0) = 0.;
00139     _parameters(1,0) = 0.;
00140     _parameters(2,0) = 0.;   
00141     
00142   } else {
00143     
00144     Double_t et = pini->E()*std::fabs(sin(pini->Theta()));
00145     Double_t theta = pini->Theta();
00146     Double_t phi = pini->Phi();
00147     
00148     _pini = (*pini);
00149     _pcurr = _pini;
00150     
00151     _iniparameters.ResizeTo(_nPar,1);
00152     _iniparameters(0,0) = et;
00153     _iniparameters(1,0) = theta;
00154     _iniparameters(2,0) = phi;
00155     
00156     _parameters.ResizeTo(_nPar,1);
00157     _parameters = _iniparameters;
00158 
00159     _u1.SetXYZ( TMath::Cos(phi), TMath::Sin(phi), 0.); // the base vector of Et
00160     _u2.SetXYZ( TMath::Cos(phi)*TMath::Cos(theta), TMath::Sin(phi)*TMath::Cos(theta), -1.*TMath::Sin(theta) );// the base vector of Eta ( same as the base vector for Theta)
00161     _u3.SetXYZ( -1.*TMath::Sin(phi), TMath::Cos(phi), 0. );// the base vector of Phi
00162 
00163   }
00164 
00165 }
00166 
00167 TMatrixD* TFitParticleEtThetaPhi::getDerivative() {
00168   // returns derivative dP/dy with P=(p,E) and y=(et, theta, phi) 
00169   // the free parameters of the fit. The columns of the matrix contain 
00170   // (dP/d(et), dP/d(theta), dP/d(phi)).
00171 
00172   TMatrixD* DerivativeMatrix = new TMatrixD(4,3);
00173   (*DerivativeMatrix) *= 0.;
00174 
00175   Double_t et = _parameters(0,0);
00176   Double_t theta = _parameters(1,0);
00177   Double_t phi = _parameters(2,0);
00178 
00179   Double_t CotanTheta = 1./TMath::Tan(theta);
00180 
00181   //1st column: dP/d(et)
00182   (*DerivativeMatrix)(0,0) = TMath::Cos(phi);
00183   (*DerivativeMatrix)(1,0) = TMath::Sin(phi);
00184   (*DerivativeMatrix)(2,0) = CotanTheta;
00185   (*DerivativeMatrix)(3,0) = 1./TMath::Sin(theta);
00186 
00187   //2nd column: dP/d(theta)
00188   (*DerivativeMatrix)(0,1) = 0.;
00189   (*DerivativeMatrix)(1,1) = 0.;
00190   (*DerivativeMatrix)(2,1) = -1.*et*(1.+CotanTheta*CotanTheta);
00191   (*DerivativeMatrix)(3,1) = -1.*et*CotanTheta/(TMath::Sin(theta));
00192 
00193    //3rd column: dP/d(phi)
00194   (*DerivativeMatrix)(0,2) = -1.*et*TMath::Sin(phi);
00195   (*DerivativeMatrix)(1,2) = et*TMath::Cos(phi);
00196   (*DerivativeMatrix)(2,2) = 0.;
00197   (*DerivativeMatrix)(3,2) = 0.;
00198 
00199   return DerivativeMatrix;
00200 
00201 }
00202 
00203 TMatrixD* TFitParticleEtThetaPhi::transform(const TLorentzVector& vec) {
00204   // Returns the parameters corresponding to the given 
00205   // 4vector
00206 
00207   // retrieve parameters
00208   TMatrixD* tparams = new TMatrixD( _nPar, 1 );
00209   (*tparams)(0,0) = vec.E()*std::fabs(sin(vec.Theta()));
00210   (*tparams)(1,0) = vec.Theta();
00211   (*tparams)(2,0) = vec.Phi();
00212 
00213   return tparams;
00214 
00215 }