CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_1/src/PhysicsTools/KinFitter/src/TFitParticleEtEtaPhi.cc

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