CMS 3D CMS Logo

CMSSW_4_4_3_patch1/src/PhysicsTools/KinFitter/src/TFitConstraintEp.cc

Go to the documentation of this file.
00001 // Classname: TFitConstraintEp
00002 // Author: Jan E. Sundermann, Verena Klose (TU Dresden)      
00003 
00004 
00005 //________________________________________________________________
00006 // 
00007 // TFitConstraintEp::
00008 // --------------------
00009 //
00010 // Fit constraint: energy and momentum conservation
00011 //
00012 
00013 #include "PhysicsTools/KinFitter/interface/TFitConstraintEp.h"
00014 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00015 #include <iostream>
00016 #include <iomanip>
00017 #include "TClass.h"
00018 
00019 //----------------
00020 // Constructor --
00021 //----------------
00022 
00023 
00024 
00025 TFitConstraintEp::TFitConstraintEp()
00026   :TAbsFitConstraint()
00027   ,_particles(0)
00028   ,_constraint(0.)
00029   ,_component(TFitConstraintEp::pX)
00030 {}
00031 
00032 TFitConstraintEp::TFitConstraintEp(std::vector<TAbsFitParticle*>* particles, 
00033                                    TFitConstraintEp::component thecomponent, 
00034                                    Double_t constraint)
00035   :TAbsFitConstraint()
00036   ,_particles(0)
00037   ,_constraint(constraint)
00038   ,_component(thecomponent)
00039 {
00040   // particles: vector containing pointer to TAbsFitParticle objects. 
00041   //            Energy or momentum conservation will be calculated for
00042   //            those particles.
00043   // thecomponent: conserved 4vector component ( pX, pY, pZ, E ). For
00044   //            full 4vector conservation four objects of type TFitConstraintEp
00045   //            are needed (four constraints)
00046   // constraint:value of energy or momentum constraint ( e.g. sum[ pX_i ] = constraint )
00047 
00048   if (particles) {
00049     _particles = (*particles);
00050   }
00051 }
00052 
00053 TFitConstraintEp::TFitConstraintEp(const TString &name, const TString &title,
00054                                    std::vector<TAbsFitParticle*>* particles, 
00055                                    TFitConstraintEp::component thecomponent, 
00056                                    Double_t constraint)
00057   :TAbsFitConstraint(name, title)
00058   ,_particles(0)
00059   ,_constraint(constraint)
00060   ,_component(thecomponent)
00061 {
00062   // particles: vector containing pointer to TAbsFitParticle objects. 
00063   //            Energy or momentum conservation will be calculated for
00064   //            those particles.
00065   // thecomponent: conserved 4vector component ( pX, pY, pZ, E ). For
00066   //            full 4vector conservation four objects of type TFitConstraintEp
00067   //            are needed (four constraints)
00068   // constraint:value of energy or momentum constraint ( e.g. sum[ pX_i ] = constraint )
00069 
00070   if (particles) {
00071     _particles = (*particles);
00072   }
00073 }
00074 
00075 //--------------
00076 // Destructor --
00077 //--------------
00078 TFitConstraintEp::~TFitConstraintEp() {
00079 
00080 }
00081 
00082 void TFitConstraintEp::addParticle( TAbsFitParticle* particle ) {
00083   // Add one particles to list of constrained particles
00084 
00085   _particles.push_back( particle );
00086 
00087 }
00088 
00089 void TFitConstraintEp::addParticles( TAbsFitParticle* p1, TAbsFitParticle* p2, TAbsFitParticle* p3, TAbsFitParticle* p4,
00090                                      TAbsFitParticle* p5, TAbsFitParticle* p6, TAbsFitParticle* p7, TAbsFitParticle* p8,
00091                                      TAbsFitParticle* p9, TAbsFitParticle* p10) {
00092   // Add many particles to list of constrained particles
00093 
00094   if (p1) addParticle( p1 );
00095   if (p2) addParticle( p2 );
00096   if (p3) addParticle( p3 );
00097   if (p4) addParticle( p4 );
00098   if (p5) addParticle( p5 );
00099   if (p6) addParticle( p6 );
00100   if (p7) addParticle( p7 );
00101   if (p8) addParticle( p8 );
00102   if (p9) addParticle( p9 );
00103   if (p10) addParticle( p10 );
00104 
00105 }
00106 
00107 //--------------
00108 // Operations --
00109 //--------------
00110 TMatrixD* TFitConstraintEp::getDerivative( TAbsFitParticle* particle ) {
00111   // returns derivative df/dP with P=(p,E) and f the constraint (f=0).
00112   // The matrix contains one row (df/dp, df/dE).
00113 
00114   TMatrixD* DerivativeMatrix = new TMatrixD(1,4);
00115   (*DerivativeMatrix) *= 0.;
00116   (*DerivativeMatrix)(0,(int) _component) = 1.;
00117   return DerivativeMatrix;
00118 }
00119 
00120 
00121 Double_t TFitConstraintEp::getInitValue() {
00122   // Get initial value of constraint (before the fit)
00123 
00124   Double_t InitValue(0) ; 
00125   UInt_t Npart = _particles.size();
00126   for (unsigned int i=0;i<Npart;i++) {
00127     const TLorentzVector* FourVec = _particles[i]->getIni4Vec();
00128     InitValue += (*FourVec)[(int) _component];
00129   }
00130   InitValue -= _constraint;
00131   return InitValue;
00132 }
00133 
00134 Double_t TFitConstraintEp::getCurrentValue() {
00135   // Get value of constraint after the fit
00136 
00137   Double_t CurrentValue(0);
00138   UInt_t Npart = _particles.size();
00139   for (unsigned int i=0;i<Npart;i++) {
00140     const TLorentzVector* FourVec = _particles[i]->getCurr4Vec();
00141     CurrentValue += (*FourVec)[(int) _component];
00142   }
00143   CurrentValue -= _constraint;
00144   return CurrentValue;
00145 }
00146 
00147 TString TFitConstraintEp::getInfoString() {
00148   // Collect information to be used for printout
00149 
00150   std::stringstream info;
00151   info << std::scientific << std::setprecision(6);
00152 
00153   info << "__________________________" << std::endl
00154        << std::endl;
00155   info << "OBJ: " << IsA()->GetName() << "\t" << GetName() << "\t" << GetTitle() << std::endl;
00156 
00157   info << "initial value: " << getInitValue() << std::endl;
00158   info << "current value: " << getCurrentValue() << std::endl;
00159   info << "component: " << _component << std::endl;
00160   info << "constraint: " << _constraint << std::endl;
00161 
00162   return info.str();
00163 
00164 }
00165 
00166 void TFitConstraintEp::print() {
00167   // Print constraint contents
00168 
00169   edm::LogVerbatim("KinFitter") << this->getInfoString();
00170 
00171 }