CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_4_5_patch3/src/PhysicsTools/KinFitter/src/TAbsFitParticle.cc

Go to the documentation of this file.
00001 // Classname: TAbsFitParticle
00002 // Author: Jan E. Sundermann, Verena Klose (TU Dresden)      
00003 
00004 
00005 //________________________________________________________________
00006 // 
00007 // TAbsFitParticle::
00008 // --------------------
00009 //
00010 // Abstract base class for particles to be used with kinematic fitter
00011 //
00012 
00013 #include "PhysicsTools/KinFitter/interface/TAbsFitParticle.h"
00014 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00015 #include <iostream>
00016 #include <iomanip>
00017 #include "TClass.h"
00018 
00019 
00020 TAbsFitParticle::TAbsFitParticle():
00021   TNamed("NoName","NoTitle")
00022   ,_nPar(0)     
00023   ,_u1()   
00024   ,_u2()
00025   ,_u3()
00026   ,_covMatrix()
00027   ,_covMatrixFit()
00028   ,_covMatrixDeltaY()
00029   ,_pull()
00030   ,_iniparameters(1,1)
00031   ,_parameters(1,1)
00032   ,_pini()
00033   ,_pcurr()
00034 {
00035  
00036 }
00037 
00038 TAbsFitParticle::TAbsFitParticle(const TString &name, const TString &title ):
00039   TNamed(name,title)
00040   ,_nPar(0)     
00041   ,_u1()   
00042   ,_u2()
00043   ,_u3()
00044   ,_covMatrix()
00045   ,_covMatrixFit()
00046   ,_covMatrixDeltaY()
00047   ,_pull()
00048   ,_iniparameters(1,1)
00049   ,_parameters(1,1)
00050   ,_pini()
00051   ,_pcurr()
00052 {
00053  
00054 }
00055 
00056 
00057 TAbsFitParticle::~TAbsFitParticle() {
00058 
00059 }
00060 
00061 TString
00062 TAbsFitParticle::getInfoString() {
00063   // Collect information to be used for printout
00064 
00065   std::stringstream info;
00066   info << std::scientific << std::setprecision(6);
00067 
00068   info << "__________________________" << std::endl
00069        << std::endl;
00070 
00071   info << "OBJ: " << IsA()->GetName() << "\t" << GetName() << "\t" << GetTitle() << std::endl;
00072 
00073   info << std::setw(22) << "initial parameters:"  << std::setw(5) << " " << std::setw(20) << "current parameters:" << std::endl;
00074   for (int i = 0; i< _nPar ;i++){
00075     info << "par[" << i << "] = "
00076          << std::setw(18) << (*getParIni())(i,0) 
00077          << std::setw(20) << (*getParCurr())(i,0) << std::endl;
00078   }
00079 
00080   info << std::setw(22) << "initial 4vector:" << std::setw(5) << " " << std::setw(20) << "current 4vector:" << std::endl;
00081   for (int i = 0; i< 4 ;i++){
00082     info << "p[" << i << "] = "
00083          << std::setw(20) << (*getIni4Vec())[i] 
00084          << std::setw(20) << (*getCurr4Vec())[i] << std::endl;
00085    }
00086   info << "mass = " 
00087        << std::setw(20) << (*getIni4Vec()).M() 
00088        << std::setw(20) << (*getCurr4Vec()).M() << std::endl;
00089 
00090    info << "u1  = " << _u1.X() << ", " << _u1.Y() << ", " << _u1.Z() << std::endl;
00091    info << "u2  = " << _u2.X() << ", " << _u2.Y() << ", " << _u2.Z() << std::endl;
00092    info << "u3  = " << _u3.X() << ", " << _u3.Y() << ", " << _u3.Z() << std::endl;
00093 
00094    return info.str();
00095 
00096 }
00097 
00098 void 
00099 TAbsFitParticle::print() {
00100   // Print particle contents
00101 
00102   edm::LogVerbatim("KinFitter") << this->getInfoString();
00103 
00104 }
00105 
00106 void TAbsFitParticle::reset() {
00107   // Reset particle to initial values
00108 
00109   _parameters = _iniparameters;  
00110   _pcurr = _pini;
00111   setCovMatrixFit( 0 );
00112   _pull.ResizeTo(_nPar, 1);
00113   _pull.Zero();
00114 
00115 }
00116 
00117 void TAbsFitParticle::setCovMatrix(const TMatrixD* theCovMatrix) {
00118   // Set the measured covariance matrix
00119 
00120   _covMatrix.ResizeTo(_nPar, _nPar);
00121   if(theCovMatrix==0) {
00122     _covMatrix.Zero();
00123   } else if (theCovMatrix->GetNcols() ==_nPar && theCovMatrix->GetNrows() ==_nPar) {
00124     _covMatrix = (*theCovMatrix);
00125   } else {
00126     edm::LogError ("WrongMatrixSize")
00127       << GetName() << "::setCovMatrix - Covariance matrix needs to be a "
00128       << _nPar << "x" << _nPar << " matrix.";
00129   }
00130 
00131 }
00132 
00133 
00134 void TAbsFitParticle::setCovMatrixFit(const TMatrixD* theCovMatrixFit) {
00135   // Set the fitted covariance matrix
00136 
00137   _covMatrixFit.ResizeTo(_nPar, _nPar);
00138   if(theCovMatrixFit==0) {
00139     _covMatrixFit.Zero();
00140   } else if (theCovMatrixFit->GetNcols() ==_nPar && theCovMatrixFit->GetNrows() ==_nPar) {
00141     _covMatrixFit = (*theCovMatrixFit);
00142   } else {
00143     edm::LogError ("WrongMatrixSize")
00144       << GetName() << "::setCovMatrixFit - Fitted covariance matrix needs to be a "
00145       << _nPar << "x" << _nPar << " matrix.";
00146   }
00147 
00148 }
00149 
00150 void TAbsFitParticle::calcCovMatrixDeltaY() {
00151   // Calculates V(deltaY) ==  V(y_meas) - V(y_fit)
00152 
00153   _covMatrixDeltaY.ResizeTo( _nPar, _nPar );
00154   _covMatrixDeltaY = _covMatrix;
00155   if(_covMatrixFit.GetNrows() == _nPar && _covMatrixFit.GetNcols() == _nPar)
00156     _covMatrixDeltaY -= _covMatrixFit;
00157   else 
00158     edm::LogError ("WrongMatrixSize")
00159       << GetName() << "::calcCovMatrixDeltaY - _covMatrixFit probably not set.";
00160 }
00161 
00162 const TMatrixD* TAbsFitParticle::getPull() {
00163   // Calculates the pull (y_fit - y_meas) / sigma
00164   // with sigma = Sqrt( sigma[y_meas]^2 - V[y_fit]^2 )
00165   // for all parameters
00166 
00167   _pull.ResizeTo( _nPar, 1 );
00168   _pull = _parameters;
00169   _pull -= _iniparameters;
00170   calcCovMatrixDeltaY(); 
00171   for (int i = 0; i<_nPar; i++) {
00172     Double_t sigmaDeltaY = _covMatrixDeltaY(i, i);
00173     if (sigmaDeltaY < 0) {
00174       edm::LogWarning ("NegativeDiagonalElem") << "V[deltaY] has a negative diagonal element.";
00175       _pull.Zero();
00176       return &_pull;
00177     } else {
00178       _pull(i,0) /= TMath::Sqrt( sigmaDeltaY );
00179     }
00180   }
00181 
00182   return &_pull;
00183 
00184 }
00185 
00186 void TAbsFitParticle::applycorr(TMatrixD* corrMatrix) {
00187   // Apply corrections to the parameters wrt. to the
00188   // initial parameters y* = y + delta(y)
00189   // This method will also calculate the fitted 
00190   // 4vector of the particle
00191 
00192   // update _parameters-Matrix
00193   _parameters = _iniparameters;
00194   _parameters += (*corrMatrix);
00195 
00196   // calculates new 4vec
00197   TLorentzVector* vec = calc4Vec( &_parameters );
00198   _pcurr = (*vec);
00199   delete vec;
00200 
00201 }
00202 
00203 void TAbsFitParticle::setParIni(const TMatrixD* parini) {
00204   if (parini == 0) return;
00205   else if( parini->GetNrows() == _iniparameters.GetNrows()
00206            && parini->GetNcols() == _iniparameters.GetNcols() )
00207     _iniparameters = (*parini) ;
00208   else {
00209     edm::LogError ("WrongMatrixSize")
00210       << GetName() << "::setParIni - Matrices don't fit.";
00211     return;
00212       }
00213 }
00214 
00215 const TMatrixD* TAbsFitParticle::getCovMatrixDeltaY() {
00216   //
00217   calcCovMatrixDeltaY(); 
00218   return &_covMatrixDeltaY; 
00219 }