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