Main Page | Class Hierarchy | Compound List | File List | Compound Members | File Members

PzConstraint.C

Go to the documentation of this file.
00001 
00020 #include "jbltools/kinfit/PzConstraint.h"
00021 #include "jbltools/kinfit/ParticleFitObject.h"
00022 
00023 #include<iostream>
00024 #include<cassert>
00025 
00026 using std::cout;
00027 using std::endl;
00028 
00029 // constructor
00030 PzConstraint::PzConstraint () {}
00031 
00032 // destructor
00033 PzConstraint::~PzConstraint () {}
00034 
00035 // calulate current value of constraint function
00036 double PzConstraint::getValue() const {
00037   double totpz = 0;
00038   for (unsigned int i = 0; i < fitobjects.size(); i++) {
00039     totpz += fitobjects[i]->getPz(); 
00040   }
00041   return totpz;
00042 }
00043 
00044 // calculate vector/array of derivatives of this contraint 
00045 // w.r.t. to ALL parameters of all fitobjects
00046 // here: d sum(px) /d par(i,j) 
00047 //                      = d sum(px) /d px(i) * d px(i) /d par(i, j)
00048 //                                      =  1 * d px(i) /d par(i, j)
00049 void PzConstraint::getDerivatives(int idim, double der[]) const {
00050   for (unsigned int i = 0; i < fitobjects.size(); i++) {
00051     for (int ilocal = 0; ilocal < fitobjects[i]->getNPar(); ilocal++) {
00052       if (!fitobjects[i]->isParamFixed(ilocal)) {
00053         int iglobal = fitobjects[i]->getGlobalParNum (ilocal);
00054         assert (iglobal >= 0 && iglobal < idim);
00055         der[iglobal] = fitobjects[i]->getDPz(ilocal);
00056 //       cout << "Pz: der[" << iglobal << "] = " << der[iglobal] 
00057 //            << " for jet " << i << " and ilocal = " << ilocal << endl;
00058       }
00059     }
00060   }
00061 }
00062   
00063 void PzConstraint::add1stDerivativesToMatrix(int idim, double *M) const {
00064   assert (M);
00065   int kglobal = getGlobalNum();
00066   assert (kglobal >= 0 && kglobal < idim);
00067   
00068   for (ConstFitObjectIterator i = fitobjects.begin(); i != fitobjects.end(); ++i) {
00069     const ParticleFitObject *fo = *i;
00070     assert (fo);
00071     for (int ilocal = 0; ilocal < fo->getNPar(); ++ilocal) {
00072       if (!fo->isParamFixed(ilocal)) {
00073         int iglobal = fo->getGlobalParNum (ilocal);
00074         assert (iglobal >= 0 && iglobal < idim);
00075         double d = fo->getDPz(ilocal);
00076         M[idim*iglobal+kglobal] += d;
00077         M[idim*kglobal+iglobal] += d;
00078       }
00079     }
00080   }
00081 }
00082   
00083 void PzConstraint::add2ndDerivativesToMatrix(int idim, double *M, double lambda) const {
00084   assert (M);
00085   for (ConstFitObjectIterator i = fitobjects.begin(); i != fitobjects.end(); ++i) {
00086     const ParticleFitObject *fo = *i;
00087     assert (fo);
00088     fo->addTo2ndDerivatives(M, idim, 0, 0, lambda, 0);
00089   }
00090 }
00091 

Generated on Fri Sep 14 17:38:21 2007 for Kinfit by doxygen 1.3.2