Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:23:36

0001 // Classname: TFitParticleEtEtaPhi
0002 // Author: S.Paktinat(IPM, CMS)
0003 // 27 July 2005
0004 
0005 //________________________________________________________________
0006 //
0007 // TFitParticleEtEtaPhi::
0008 // --------------------
0009 //
0010 // Particle with a special parametrization useful in hadron
0011 // colliders (3 free parameters (Et, Eta, Phi). The parametrization is
0012 // chosen as follows:
0013 //
0014 // p = (EtCosPhi, EtSinPhi, EtSinhEta)
0015 // E =  EtCoshEta
0016 //
0017 
0018 #include <iostream>
0019 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0020 #include "PhysicsTools/KinFitter/interface/TFitParticleEtEtaPhi.h"
0021 #include "TMath.h"
0022 #include <cmath>
0023 
0024 //----------------
0025 // Constructor --
0026 //----------------
0027 TFitParticleEtEtaPhi::TFitParticleEtEtaPhi() : TAbsFitParticle() { init(nullptr, nullptr); }
0028 
0029 TFitParticleEtEtaPhi::TFitParticleEtEtaPhi(const TFitParticleEtEtaPhi& fitParticle)
0030     : TAbsFitParticle(fitParticle.GetName(), fitParticle.GetTitle()) {
0031   _nPar = fitParticle._nPar;
0032   _u1 = fitParticle._u1;
0033   _u2 = fitParticle._u2;
0034   _u3 = fitParticle._u3;
0035   _covMatrix.ResizeTo(fitParticle._covMatrix);
0036   _covMatrix = fitParticle._covMatrix;
0037   _iniparameters.ResizeTo(fitParticle._iniparameters);
0038   _iniparameters = fitParticle._iniparameters;
0039   _parameters.ResizeTo(fitParticle._parameters);
0040   _parameters = fitParticle._parameters;
0041   _pini = fitParticle._pini;
0042   _pcurr = fitParticle._pcurr;
0043 }
0044 
0045 TFitParticleEtEtaPhi::TFitParticleEtEtaPhi(TLorentzVector* pini, const TMatrixD* theCovMatrix) : TAbsFitParticle() {
0046   init(pini, theCovMatrix);
0047 }
0048 
0049 TFitParticleEtEtaPhi::TFitParticleEtEtaPhi(const TString& name,
0050                                            const TString& title,
0051                                            TLorentzVector* pini,
0052                                            const TMatrixD* theCovMatrix)
0053     : TAbsFitParticle(name, title) {
0054   init(pini, theCovMatrix);
0055 }
0056 
0057 TAbsFitParticle* TFitParticleEtEtaPhi::clone(const TString& newname) const {
0058   // Returns a copy of itself
0059 
0060   TAbsFitParticle* myclone = new TFitParticleEtEtaPhi(*this);
0061   if (newname.Length() > 0)
0062     myclone->SetName(newname);
0063   return myclone;
0064 }
0065 
0066 //--------------
0067 // Destructor --
0068 //--------------
0069 TFitParticleEtEtaPhi::~TFitParticleEtEtaPhi() {}
0070 
0071 //--------------
0072 // Operations --
0073 //--------------
0074 void TFitParticleEtEtaPhi::init(TLorentzVector* pini, const TMatrixD* theCovMatrix) {
0075   _nPar = 3;
0076   setIni4Vec(pini);
0077   setCovMatrix(theCovMatrix);
0078 }
0079 
0080 TLorentzVector* TFitParticleEtEtaPhi::calc4Vec(const TMatrixD* params) {
0081   // Calculates a 4vector corresponding to the given
0082   // parameter values
0083 
0084   if (params == nullptr) {
0085     return nullptr;
0086   }
0087 
0088   if (params->GetNcols() != 1 || params->GetNrows() != _nPar) {
0089     edm::LogError("WrongMatrixSize") << GetName() << "::calc4Vec - Parameter matrix has wrong size.";
0090     return nullptr;
0091   }
0092 
0093   Double_t et = (*params)(0, 0);
0094   Double_t eta = (*params)(1, 0);
0095   Double_t phi = (*params)(2, 0);
0096 
0097   Double_t X = et * TMath::Cos(phi);
0098   Double_t Y = et * TMath::Sin(phi);
0099   Double_t Z = et * TMath::SinH(eta);
0100   Double_t E = et * TMath::CosH(eta);
0101 
0102   TLorentzVector* vec = new TLorentzVector(X, Y, Z, E);
0103   return vec;
0104 }
0105 
0106 void TFitParticleEtEtaPhi::setIni4Vec(const TLorentzVector* pini) {
0107   // Set the initial 4vector. Will also set the
0108   // inital parameter values
0109 
0110   if (pini == nullptr) {
0111     _u1.SetXYZ(0., 0., 0.);
0112     _u3.SetXYZ(0., 0., 0.);
0113     _u2.SetXYZ(0., 0., 0.);
0114     _pini.SetXYZT(0., 0., 0., 0.);
0115     _pcurr = _pini;
0116 
0117     _iniparameters.ResizeTo(_nPar, 1);
0118     _iniparameters(0, 0) = 0.;
0119     _iniparameters(1, 0) = 0.;
0120     _iniparameters(2, 0) = 0.;
0121 
0122     _parameters.ResizeTo(_nPar, 1);
0123     _parameters(0, 0) = 0.;
0124     _parameters(1, 0) = 0.;
0125     _parameters(2, 0) = 0.;
0126 
0127   } else {
0128     Double_t et = pini->E() * std::fabs(sin(pini->Theta()));
0129     Double_t eta = pini->Eta();
0130     Double_t phi = pini->Phi();
0131 
0132     _pini = (*pini);
0133     _pcurr = _pini;
0134 
0135     _iniparameters.ResizeTo(_nPar, 1);
0136     _iniparameters(0, 0) = et;
0137     _iniparameters(1, 0) = eta;
0138     _iniparameters(2, 0) = phi;
0139 
0140     _parameters.ResizeTo(_nPar, 1);
0141     _parameters = _iniparameters;
0142 
0143     _u1.SetXYZ(TMath::Cos(phi), TMath::Sin(phi), 0.);  // the base vector of Et
0144     _u2.SetXYZ(-1. * TMath::Cos(phi) * TMath::TanH(eta),
0145                -1. * TMath::Sin(phi) * TMath::TanH(eta),
0146                1. / TMath::CosH(eta));  // the base vector of Eta ( same as the base vector for Theta)
0147     _u3.SetXYZ(-1. * TMath::Sin(phi), TMath::Cos(phi), 0.);  // the base vector of Phi
0148   }
0149 }
0150 
0151 TMatrixD* TFitParticleEtEtaPhi::getDerivative() {
0152   // returns derivative dP/dy with P=(p,E) and y=(et, eta, phi)
0153   // the free parameters of the fit. The columns of the matrix contain
0154   // (dP/d(et), dP/d(eta), dP/d(phi)).
0155 
0156   TMatrixD* DerivativeMatrix = new TMatrixD(4, 3);
0157   (*DerivativeMatrix) *= 0.;
0158 
0159   Double_t et = _parameters(0, 0);
0160   Double_t eta = _parameters(1, 0);
0161   Double_t phi = _parameters(2, 0);
0162 
0163   //1st column: dP/d(et)
0164   (*DerivativeMatrix)(0, 0) = TMath::Cos(phi);
0165   (*DerivativeMatrix)(1, 0) = TMath::Sin(phi);
0166   (*DerivativeMatrix)(2, 0) = TMath::SinH(eta);
0167   (*DerivativeMatrix)(3, 0) = TMath::CosH(eta);
0168 
0169   //2nd column: dP/d(eta)
0170   (*DerivativeMatrix)(0, 1) = 0.;
0171   (*DerivativeMatrix)(1, 1) = 0.;
0172   (*DerivativeMatrix)(2, 1) = et * TMath::CosH(eta);
0173   (*DerivativeMatrix)(3, 1) = et * TMath::SinH(eta);
0174 
0175   //3rd column: dP/d(phi)
0176   (*DerivativeMatrix)(0, 2) = -1. * et * TMath::Sin(phi);
0177   (*DerivativeMatrix)(1, 2) = et * TMath::Cos(phi);
0178   (*DerivativeMatrix)(2, 2) = 0.;
0179   (*DerivativeMatrix)(3, 2) = 0.;
0180 
0181   return DerivativeMatrix;
0182 }
0183 
0184 TMatrixD* TFitParticleEtEtaPhi::transform(const TLorentzVector& vec) {
0185   // Returns the parameters corresponding to the given
0186   // 4vector
0187 
0188   // retrieve parameters
0189   TMatrixD* tparams = new TMatrixD(_nPar, 1);
0190   (*tparams)(0, 0) = vec.E() * std::fabs(sin(vec.Theta()));
0191   (*tparams)(1, 0) = vec.Eta();
0192   (*tparams)(2, 0) = vec.Phi();
0193 
0194   return tparams;
0195 }