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

PxConstraint.C

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

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