CMS 3D CMS Logo

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

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