Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:32:39

0001 // Classname: TFitParticleEtThetaPhi
0002 // Author: S.Paktinat(IPM, CMS)
0003 // 27 July 2005
0004 
0005 //________________________________________________________________
0006 //
0007 // TFitParticleEtThetaPhi::
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, Et/Tan(Theta)
0015 // E =  Et/Sin(Theta)
0016 //
0017 
0018 #include <iostream>
0019 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0020 #include "PhysicsTools/KinFitter/interface/TFitParticleEtThetaPhi.h"
0021 #include "TMath.h"
0022 #include <cmath>
0023 
0024 //----------------
0025 // Constructor --
0026 //----------------
0027 TFitParticleEtThetaPhi::TFitParticleEtThetaPhi() : TAbsFitParticle() { init(nullptr, nullptr); }
0028 
0029 TFitParticleEtThetaPhi::TFitParticleEtThetaPhi(const TFitParticleEtThetaPhi& 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 TFitParticleEtThetaPhi::TFitParticleEtThetaPhi(TLorentzVector* pini, const TMatrixD* theCovMatrix) : TAbsFitParticle() {
0046   init(pini, theCovMatrix);
0047 }
0048 
0049 TFitParticleEtThetaPhi::TFitParticleEtThetaPhi(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* TFitParticleEtThetaPhi::clone(const TString& newname) const {
0058   // Returns a copy of itself
0059 
0060   TAbsFitParticle* myclone = new TFitParticleEtThetaPhi(*this);
0061   if (newname.Length() > 0)
0062     myclone->SetName(newname);
0063   return myclone;
0064 }
0065 
0066 //--------------
0067 // Destructor --
0068 //--------------
0069 TFitParticleEtThetaPhi::~TFitParticleEtThetaPhi() {}
0070 
0071 //--------------
0072 // Operations --
0073 //--------------
0074 void TFitParticleEtThetaPhi::init(TLorentzVector* pini, const TMatrixD* theCovMatrix) {
0075   _nPar = 3;
0076   setIni4Vec(pini);
0077   setCovMatrix(theCovMatrix);
0078 }
0079 
0080 TLorentzVector* TFitParticleEtThetaPhi::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 theta = (*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::Tan(theta);
0100   Double_t E = et / TMath::Sin(theta);
0101 
0102   TLorentzVector* vec = new TLorentzVector(X, Y, Z, E);
0103   return vec;
0104 }
0105 
0106 void TFitParticleEtThetaPhi::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 theta = pini->Theta();
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) = theta;
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(TMath::Cos(phi) * TMath::Cos(theta),
0145                TMath::Sin(phi) * TMath::Cos(theta),
0146                -1. * TMath::Sin(theta));  // 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* TFitParticleEtThetaPhi::getDerivative() {
0152   // returns derivative dP/dy with P=(p,E) and y=(et, theta, phi)
0153   // the free parameters of the fit. The columns of the matrix contain
0154   // (dP/d(et), dP/d(theta), 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 theta = _parameters(1, 0);
0161   Double_t phi = _parameters(2, 0);
0162 
0163   Double_t CotanTheta = 1. / TMath::Tan(theta);
0164 
0165   //1st column: dP/d(et)
0166   (*DerivativeMatrix)(0, 0) = TMath::Cos(phi);
0167   (*DerivativeMatrix)(1, 0) = TMath::Sin(phi);
0168   (*DerivativeMatrix)(2, 0) = CotanTheta;
0169   (*DerivativeMatrix)(3, 0) = 1. / TMath::Sin(theta);
0170 
0171   //2nd column: dP/d(theta)
0172   (*DerivativeMatrix)(0, 1) = 0.;
0173   (*DerivativeMatrix)(1, 1) = 0.;
0174   (*DerivativeMatrix)(2, 1) = -1. * et * (1. + CotanTheta * CotanTheta);
0175   (*DerivativeMatrix)(3, 1) = -1. * et * CotanTheta / (TMath::Sin(theta));
0176 
0177   //3rd column: dP/d(phi)
0178   (*DerivativeMatrix)(0, 2) = -1. * et * TMath::Sin(phi);
0179   (*DerivativeMatrix)(1, 2) = et * TMath::Cos(phi);
0180   (*DerivativeMatrix)(2, 2) = 0.;
0181   (*DerivativeMatrix)(3, 2) = 0.;
0182 
0183   return DerivativeMatrix;
0184 }
0185 
0186 TMatrixD* TFitParticleEtThetaPhi::transform(const TLorentzVector& vec) {
0187   // Returns the parameters corresponding to the given
0188   // 4vector
0189 
0190   // retrieve parameters
0191   TMatrixD* tparams = new TMatrixD(_nPar, 1);
0192   (*tparams)(0, 0) = vec.E() * std::fabs(sin(vec.Theta()));
0193   (*tparams)(1, 0) = vec.Theta();
0194   (*tparams)(2, 0) = vec.Phi();
0195 
0196   return tparams;
0197 }