Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 // Classname: TFitParticleMCCart
0002 // Author: Jan E. Sundermann, Verena Klose (TU Dresden)
0003 
0004 //________________________________________________________________
0005 //
0006 // TFitParticleMCCart::
0007 // --------------------
0008 //
0009 // Particle with cartesian 4vector parametrization and constrained mass
0010 // [three free parameters (px, py, pz) with initial values
0011 //  (px, py, pz)]
0012 //
0013 // p = px*u1 + py*u2 + pz*u3
0014 // E = Sqrt( |p|^2 + m^2 )
0015 //
0016 
0017 #include <iostream>
0018 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0019 #include "PhysicsTools/KinFitter/interface/TFitParticleMCCart.h"
0020 #include "TMath.h"
0021 
0022 //----------------
0023 // Constructor --
0024 //----------------
0025 TFitParticleMCCart::TFitParticleMCCart() : TAbsFitParticle() { init(nullptr, 0., nullptr); }
0026 
0027 TFitParticleMCCart::TFitParticleMCCart(const TFitParticleMCCart& fitParticle)
0028     : TAbsFitParticle(fitParticle.GetName(), fitParticle.GetTitle()) {
0029   _nPar = fitParticle._nPar;
0030   _u1 = fitParticle._u1;
0031   _u2 = fitParticle._u2;
0032   _u3 = fitParticle._u3;
0033   _covMatrix.ResizeTo(fitParticle._covMatrix);
0034   _covMatrix = fitParticle._covMatrix;
0035   _iniparameters.ResizeTo(fitParticle._iniparameters);
0036   _iniparameters = fitParticle._iniparameters;
0037   _parameters.ResizeTo(fitParticle._parameters);
0038   _parameters = fitParticle._parameters;
0039   _pini = fitParticle._pini;
0040   _pcurr = fitParticle._pcurr;
0041 }
0042 
0043 TFitParticleMCCart::TFitParticleMCCart(TVector3* p, Double_t M, const TMatrixD* theCovMatrix) : TAbsFitParticle() {
0044   init(p, M, theCovMatrix);
0045 }
0046 
0047 TFitParticleMCCart::TFitParticleMCCart(
0048     const TString& name, const TString& title, TVector3* p, Double_t M, const TMatrixD* theCovMatrix)
0049     : TAbsFitParticle(name, title) {
0050   init(p, M, theCovMatrix);
0051 }
0052 
0053 TAbsFitParticle* TFitParticleMCCart::clone(const TString& newname) const {
0054   // Returns a copy of itself
0055 
0056   TAbsFitParticle* myclone = new TFitParticleMCCart(*this);
0057   if (newname.Length() > 0)
0058     myclone->SetName(newname);
0059   return myclone;
0060 }
0061 
0062 //--------------
0063 // Destructor --
0064 //--------------
0065 TFitParticleMCCart::~TFitParticleMCCart() {}
0066 
0067 //--------------
0068 // Operations --
0069 //--------------
0070 void TFitParticleMCCart::init(TVector3* p, Double_t M, const TMatrixD* theCovMatrix) {
0071   _nPar = 3;
0072   setIni4Vec(p, M);
0073   setCovMatrix(theCovMatrix);
0074 }
0075 
0076 TLorentzVector* TFitParticleMCCart::calc4Vec(const TMatrixD* params) {
0077   // Calculates a 4vector corresponding to the given
0078   // parameter values
0079 
0080   if (params == nullptr) {
0081     return nullptr;
0082   }
0083 
0084   if (params->GetNcols() != 1 || params->GetNrows() != _nPar) {
0085     edm::LogError("WrongMatrixSize") << GetName() << "::calc4Vec - Parameter matrix has wrong size.";
0086     return nullptr;
0087   }
0088 
0089   Double_t X = (*params)(0, 0);
0090   Double_t Y = (*params)(1, 0);
0091   Double_t Z = (*params)(2, 0);
0092   Double_t E = TMath::Sqrt(X * X + Y * Y + Z * Z + _pini.M2());
0093 
0094   TLorentzVector* vec = new TLorentzVector(X, Y, Z, E);
0095   return vec;
0096 }
0097 
0098 void TFitParticleMCCart::setIni4Vec(const TLorentzVector* pini) {
0099   // Set the initial 4vector. Will also set the
0100   // inital parameter values
0101 
0102   TVector3 vec(pini->Vect());
0103   setIni4Vec(&vec, pini->M());
0104 }
0105 
0106 void TFitParticleMCCart::setIni4Vec(const TVector3* p, Double_t M) {
0107   // Set the initial 4vector. Will also set the
0108   // inital parameter values
0109 
0110   if (p == nullptr) {
0111     _iniparameters.ResizeTo(_nPar, 1);
0112     _iniparameters(0, 0) = 0.;
0113     _iniparameters(1, 0) = 0.;
0114     _iniparameters(2, 0) = 0.;
0115     _parameters.ResizeTo(_nPar, 1);
0116     _parameters = _iniparameters;
0117 
0118     _pini.SetXYZM(0., 0., 0., M);
0119     _pcurr = _pini;
0120 
0121   } else {
0122     _iniparameters.ResizeTo(_nPar, 1);
0123     _iniparameters(0, 0) = p->x();
0124     _iniparameters(1, 0) = p->y();
0125     _iniparameters(2, 0) = p->z();
0126     _parameters.ResizeTo(_nPar, 1);
0127     _parameters = _iniparameters;
0128 
0129     _pini.SetXYZM(p->x(), p->y(), p->z(), M);
0130     _pcurr = _pini;
0131 
0132     _u1.SetXYZ(1., 0., 0.);
0133     _u2.SetXYZ(0., 1., 0.);
0134     _u3.SetXYZ(0., 0., 1.);
0135   }
0136 }
0137 
0138 TMatrixD* TFitParticleMCCart::getDerivative() {
0139   // returns derivative dP/dy with P=(p,E) and y=(px, py, pz)
0140   // the free parameters of the fit. The columns of the matrix contain
0141   // (dP/dpx, dP/dpy, ...).
0142 
0143   TMatrixD* DerivativeMatrix = new TMatrixD(4, 3);
0144   (*DerivativeMatrix) *= 0.;
0145 
0146   //1st column: dP/dx
0147   (*DerivativeMatrix)(0, 0) = 1.;
0148   (*DerivativeMatrix)(1, 0) = 0.;
0149   (*DerivativeMatrix)(2, 0) = 0.;
0150   (*DerivativeMatrix)(3, 0) = _parameters(0, 0) / _pcurr.E();
0151 
0152   //2nd column: dP/dy
0153   (*DerivativeMatrix)(0, 1) = 0.;
0154   (*DerivativeMatrix)(1, 1) = 1.;
0155   (*DerivativeMatrix)(2, 1) = 0.;
0156   (*DerivativeMatrix)(3, 1) = _parameters(1, 0) / _pcurr.E();
0157 
0158   //3rd column: dP/dz
0159   (*DerivativeMatrix)(0, 2) = 0.;
0160   (*DerivativeMatrix)(1, 2) = 0.;
0161   (*DerivativeMatrix)(2, 2) = 1.;
0162   (*DerivativeMatrix)(3, 2) = _parameters(2, 0) / _pcurr.E();
0163 
0164   return DerivativeMatrix;
0165 }
0166 
0167 TMatrixD* TFitParticleMCCart::transform(const TLorentzVector& vec) {
0168   // Returns the parameters corresponding to the given
0169   // 4vector
0170 
0171   TVector3 vec3(vec.Vect());
0172 
0173   // retrieve parameters
0174   TMatrixD* tparams = new TMatrixD(_nPar, 1);
0175   (*tparams)(0, 0) = vec3.x();
0176   (*tparams)(1, 0) = vec3.y();
0177   (*tparams)(2, 0) = vec3.z();
0178 
0179   return tparams;
0180 }