CMS 3D CMS Logo

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