00001 00020 #include "jbltools/kinfit/PyConstraint.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 PyConstraint::PyConstraint () {} 00031 00032 // destructor 00033 PyConstraint::~PyConstraint () {} 00034 00035 // calulate current value of constraint function 00036 double PyConstraint::getValue() const { 00037 double totpy = 0; 00038 for (unsigned int i = 0; i < fitobjects.size(); i++) { 00039 totpy += fitobjects[i]->getPy(); 00040 } 00041 return totpy; 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(py) /d par(i,j) 00047 // = d sum(py) /d py(i) * d py(i) /d par(i, j) 00048 // = 1 * d py(i) /d par(i, j) 00049 void PyConstraint::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 int iglobal = fitobjects[i]->getGlobalParNum (ilocal); 00053 if (!fitobjects[i]->isParamFixed(ilocal)) { 00054 assert (iglobal >= 0 && iglobal < idim); 00055 der[iglobal] = fitobjects[i]->getDPy(ilocal); 00056 // cout << "Py: der[" << iglobal << "] = " << der[iglobal] 00057 // << " for jet " << i << " and ilocal = " << ilocal << endl; 00058 } 00059 } 00060 } 00061 } 00062 00063 void PyConstraint::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->getDPy(ilocal); 00076 M[idim*iglobal+kglobal] += d; 00077 M[idim*kglobal+iglobal] += d; 00078 } 00079 } 00080 } 00081 } 00082 00083 void PyConstraint::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, lambda, 0, 0); 00089 } 00090 } 00091 00092 00093 00094 00095