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

MassConstraint.C

Go to the documentation of this file.
00001 
00002 // Class MassConstraint
00003 //
00004 // Author: Jenny Boehme
00005 // Last update: $Date: 2005/01/12 10:11:45 $
00006 //          by: $Author: blist $
00007 // 
00008 // Description: M(p1,p2)=M_W constraint
00009 //               
00011 
00012 #include "jbltools/kinfit/MassConstraint.h"
00013 #include "jbltools/kinfit/ParticleFitObject.h"
00014 
00015 #include<iostream>
00016 #include<cmath>
00017 #include<cassert>
00018 
00019 using std::cerr;
00020 using std::cout;
00021 using std::endl;
00022 
00023 // constructor
00024 MassConstraint::MassConstraint (double mass_) : mass(mass_) {}
00025 
00026 // destructor
00027 MassConstraint::~MassConstraint () {}
00028 
00029 // calulate current value of constraint function
00030 double MassConstraint::getValue() const {
00031   double totE[2] = {0,0};
00032   double totpx[2] = {0,0}; 
00033   double totpy[2] = {0,0}; 
00034   double totpz[2] = {0,0}; 
00035   for (unsigned int i = 0; i < fitobjects.size(); i++) {
00036     int index = (flags[i] == 1) ? 0 : 1; // default is 1, but 2 may indicate fitobjects for a second W -> equal mass constraint!
00037     totE[index] += fitobjects[i]->getE(); 
00038     totpx[index] += fitobjects[i]->getPx(); 
00039     totpy[index] += fitobjects[i]->getPy(); 
00040     totpz[index] += fitobjects[i]->getPz(); 
00041   }
00042   double result = -mass;
00043   result += std::sqrt(std::abs(totE[0]*totE[0]-totpx[0]*totpx[0]-totpy[0]*totpy[0]-totpz[0]*totpz[0]));
00044   result -= std::sqrt(std::abs(totE[1]*totE[1]-totpx[1]*totpx[1]-totpy[1]*totpy[1]-totpz[1]*totpz[1]));
00045   return result;
00046 }
00047 
00048 // calculate vector/array of derivatives of this contraint 
00049 // w.r.t. to ALL parameters of all fitobjects
00050 // here: d M /d par(j) 
00051 //          = d M /d p(i) * d p(i) /d par(j)
00052 //          =  +-1/M * p(i) * d p(i) /d par(j)
00053 void MassConstraint::getDerivatives(int idim, double der[]) const {
00054   double totE[2] = {0,0};
00055   double totpx[2] = {0,0}; 
00056   double totpy[2] = {0,0}; 
00057   double totpz[2] = {0,0}; 
00058   for (unsigned int i = 0; i < fitobjects.size(); i++) {
00059     int index = (flags[i]==1) ? 0 : 1; // default is 1, but 2 may indicate fitobjects for a second W -> equal mass constraint!
00060     totE[index] += fitobjects[i]->getE(); 
00061     totpx[index] += fitobjects[i]->getPx(); 
00062     totpy[index] += fitobjects[i]->getPy(); 
00063     totpz[index] += fitobjects[i]->getPz(); 
00064   }
00065   for (unsigned int i = 0; i < fitobjects.size(); i++) {
00066     int index = (flags[i]==1) ? 0 : 1; // default is 1, but 2 may indicate fitobjects for a second W -> equal mass constraint!
00067     for (int ilocal = 0; ilocal < fitobjects[i]->getNPar(); ilocal++) {
00068       if (!fitobjects[i]->isParamFixed(ilocal)) {
00069         int iglobal = fitobjects[i]->getGlobalParNum (ilocal);
00070         assert (iglobal >= 0 && iglobal < idim);
00071         der[iglobal] = 0;
00072         der[iglobal] += totE[index] * fitobjects[i]->getDE (ilocal);
00073         der[iglobal] -= totpx[index] * fitobjects[i]->getDPx (ilocal);
00074         der[iglobal] -= totpy[index] * fitobjects[i]->getDPy (ilocal);
00075         der[iglobal] -= totpz[index] * fitobjects[i]->getDPz (ilocal);
00076         double m2 = totE[index]*totE[index] - totpx[index]*totpx[index]
00077                     - totpy[index]*totpy[index] - totpz[index]*totpz[index];
00078         if (m2 < 0) cerr << "MassConstraint::getDerivatives: m2<0!" << endl;
00079         if (m2 == 0) cerr << "MassConstraint::getDerivatives: m2==0!" << endl;
00080         else der[iglobal] /= std::sqrt (std::abs(m2));
00081         if (index == 1) der[iglobal] *= -1.;
00082       }
00083     }
00084   }
00085 }
00086   
00087 double MassConstraint::getMass (int flag) {
00088   double totE = 0;
00089   double totpx = 0; 
00090   double totpy = 0; 
00091   double totpz = 0; 
00092   for (unsigned int i = 0; i < fitobjects.size(); i++) {
00093     if (flags[i] == flag) {
00094       totE += fitobjects[i]->getE(); 
00095       totpx += fitobjects[i]->getPx(); 
00096       totpy += fitobjects[i]->getPy(); 
00097       totpz += fitobjects[i]->getPz(); 
00098     }
00099   }
00100   return std::sqrt(std::abs(totE*totE-totpx*totpx-totpy*totpy-totpz*totpz));
00101 }

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