CMS 3D CMS Logo

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

Generated on Tue Jun 9 17:41:16 2009 for CMSSW by  doxygen 1.5.4