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

JetFitObject.C

Go to the documentation of this file.
00001 
00015 #include"jbltools/kinfit/JetFitObject.h"
00016 #include <cmath>
00017 #include <cassert>
00018 
00019 using std::sqrt;
00020 using std::sin;
00021 using std::cos;
00022 
00023 // constructor
00024 JetFitObject::JetFitObject(double E, double theta, double phi,  
00025                            double DE, double Dtheta, double Dphi, 
00026                            double m) {
00027   initCov();                         
00028   setParam (0, E, true);
00029   setParam (1, theta, true);
00030   setParam (2, phi, true);
00031   setMParam (0, E);
00032   setMParam (1, theta);
00033   setMParam (2, phi);
00034   setError (0, DE);
00035   setError (1, Dtheta);
00036   setError (2, Dphi);
00037   setMass (m);
00038   invalidateCache();
00039 }
00040 
00041 // destructor
00042 JetFitObject::~JetFitObject() {}
00043 
00044 const char *JetFitObject::getParamName (int ilocal) const {
00045   switch (ilocal) {
00046     case 0: return "E";
00047     case 1: return "theta";
00048     case 2: return "phi";
00049   }
00050   return "undefined";
00051 }
00052 
00053 // these depend on actual parametrisation!
00054 double JetFitObject::getPx() const {
00055   if (!cachevalid) updateCache();
00056   return px;
00057 }
00058 double JetFitObject::getPy() const {
00059   if (!cachevalid) updateCache();
00060   return py;
00061 }
00062 double JetFitObject::getPz() const {
00063   if (!cachevalid) updateCache();
00064   return pz;
00065 }
00066 double JetFitObject::getE() const {return par[0];}
00067 
00068 double JetFitObject::getP() const {
00069   if (!cachevalid) updateCache();
00070   return p;
00071 }
00072 double JetFitObject::getP2() const {
00073   if (!cachevalid) updateCache();
00074   return p2;
00075 }
00076 double JetFitObject::getPt() const {
00077   if (!cachevalid) updateCache();
00078   return pt;
00079 }
00080 double JetFitObject::getPt2() const {
00081   if (!cachevalid) updateCache();
00082   return pt*pt;
00083 }
00084 
00085 double JetFitObject::getDPx(int ilocal) const {
00086   assert (ilocal >= 0 && ilocal < NPAR);
00087   if (!cachevalid) updateCache();
00088   switch (ilocal) {
00089     case 0: return dpxdE;
00090     case 1: return dpxdtheta;
00091     case 2: return -py;
00092   }
00093   return 0; 
00094 }
00095 
00096 double JetFitObject::getDPy(int ilocal) const {
00097   assert (ilocal >= 0 && ilocal < NPAR);
00098   if (!cachevalid) updateCache();
00099   switch (ilocal) {
00100     case 0: return dpydE;
00101     case 1: return dpydtheta;
00102     case 2: return px;
00103   }
00104   return 0; 
00105 }
00106 
00107 double JetFitObject::getDPz(int ilocal) const {
00108   assert (ilocal >= 0 && ilocal < NPAR);
00109   if (!cachevalid) updateCache();
00110   switch (ilocal) {
00111     case 0: return dpzdE;
00112     case 1: return -pt;
00113     case 2: return 0;
00114   }
00115   return 0; 
00116 }
00117 
00118 double JetFitObject::getDE(int ilocal) const {
00119   assert (ilocal >= 0 && ilocal < NPAR);
00120   if (!cachevalid) updateCache();
00121   switch (ilocal) {
00122     case 0: return 1;
00123     case 1: return 0;
00124     case 2: return 0;
00125   }
00126   return 0; 
00127 }
00128     
00129 void   JetFitObject::addToDerivatives (double der[],
00130                                        int idim,
00131                                        double pxfact, 
00132                                        double pyfact, 
00133                                        double pzfact, 
00134                                        double efact) const {
00135   int i_E     = globalParNum[0];
00136   int i_theta = globalParNum[1];
00137   int i_phi   = globalParNum[2];
00138   assert (i_E     >= 0 && i_E     < idim);
00139   assert (i_theta >= 0 && i_theta < idim);
00140   assert (i_phi   >= 0 && i_phi   < idim);
00141   
00142   if (!cachevalid) updateCache();
00143   // for numerical accuracy, add up derivatives first,
00144   // then add them to global vector
00145   double der_E = 0;
00146   double der_theta = 0;
00147   double der_phi = 0;
00148   
00149   if (pxfact != 0) {
00150     der_E     += pxfact*dpxdE;
00151     der_theta += pxfact*dpydtheta;
00152     der_phi   -= pxfact*py;
00153   }
00154   if (pyfact != 0) {
00155     der_E     += pyfact*dpydE;
00156     der_theta += pyfact*dpydtheta;
00157     der_phi   += pyfact*px;
00158   }
00159   if (pzfact != 0) {
00160     der_E     += pzfact*dpdE*ctheta;
00161     der_theta -= pzfact*pt;
00162   }
00163   der_E     += efact;
00164   
00165   der[i_E]     += der_E;
00166   der[i_theta] += der_theta;
00167   der[i_phi]   += der_phi;
00168 }
00169     
00170 void   JetFitObject::addTo2ndDerivatives (double der2[],
00171                                           int idim,
00172                                           double pxfact, 
00173                                           double pyfact, 
00174                                           double pzfact, 
00175                                           double efact) const {
00176   int i_E  = globalParNum[0];
00177   int i_th = globalParNum[1];
00178   int i_ph= globalParNum[2];
00179   assert (i_E  >= 0 && i_E  < idim);
00180   assert (i_th >= 0 && i_th < idim);
00181   assert (i_ph >= 0 && i_ph < idim);
00182   
00183   if (!cachevalid) updateCache();
00184   // for numerical accuracy, add up derivatives first,
00185   // then add them to global vector
00186   double der_EE   = 0;
00187   double der_Eth  = 0;
00188   double der_Eph  = 0;
00189   double der_thth = 0;
00190   double der_thph = 0;
00191   double der_phph = 0;
00192   
00193   double d2pdE2 = (mass != 0) ? -mass*mass/(p*p*p) : 0;
00194   double d2ptdE2 = d2pdE2*stheta;
00195   
00196   if (pxfact != 0) {
00197     der_EE   += pxfact*d2ptdE2*cphi;
00198     der_Eth  += pxfact*dpzdE*cphi;
00199     der_Eph  -= pxfact*dpydE;
00200     der_thth -= pxfact*px;
00201     der_thph -= pxfact*dpydtheta;
00202     der_phph -= pxfact*px;
00203   }
00204   if (pyfact != 0) {
00205     der_EE   += pyfact*d2ptdE2*sphi;
00206     der_Eth  += pyfact*dpzdE*sphi;
00207     der_Eph  += pyfact*dpxdE;
00208     der_thth -= pyfact*py;
00209     der_thph += pyfact*dpxdtheta;
00210     der_phph -= pyfact*py;
00211   }
00212   if (pzfact != 0) {
00213     der_EE   += pzfact*d2pdE2*ctheta;
00214     der_Eth  -= pzfact*dptdE;
00215     der_thth -= pzfact*pz;
00216   }
00217   
00218   der2[idim*i_E+i_E]   += der_EE;
00219   der2[idim*i_E+i_th]  += der_Eth;
00220   der2[idim*i_E+i_ph]  += der_Eph;
00221   der2[idim*i_th+i_E]  += der_Eth;
00222   der2[idim*i_th+i_th] += der_thth;
00223   der2[idim*i_th+i_ph] += der_thph;
00224   der2[idim*i_ph+i_E]  += der_Eph;
00225   der2[idim*i_ph+i_th] += der_thph;
00226   der2[idim*i_ph+i_ph] += der_phph;
00227 }
00228 
00229 
00230           
00231 void JetFitObject::addToGlobalDerMatrix (int idim, double c, double *M) const {
00232   // add second derivatives to global matrix
00233   if (c == 0) return;
00234   assert (0);
00235   
00236   
00237 }
00238 
00239 void JetFitObject::initCov() {
00240   for (int i = 0; i < NPAR; ++i) {
00241     for (int j = 0; j < NPAR; ++j) {
00242       cov[i][j] = static_cast<double>(i == j);
00243     }
00244   }    
00245 }
00246 
00247 void JetFitObject::invalidateCache() const {
00248   cachevalid = false;
00249 }
00250 
00251 void JetFitObject::updateCache() const {
00252   double e     = par[0];
00253   double theta = par[1];
00254   double phi   = par[2];
00255 
00256   ctheta = cos(theta);
00257   stheta = sin(theta);
00258   cphi   = cos(phi);
00259   sphi   = sin(phi);
00260 
00261   p2 = std::abs(e*e-mass*mass);
00262   p = std::sqrt(p2);
00263   pt = p*stheta;
00264 
00265   px = pt*cphi;
00266   py = pt*sphi;
00267   pz = p*ctheta;
00268   dpdE = e/p;
00269   dptdE = dpdE*stheta;
00270   dpxdE = dptdE*cphi;
00271   dpydE = dptdE*sphi;
00272   dpzdE = dpdE*ctheta;
00273   dpxdtheta = pz*cphi;
00274   dpydtheta = pz*sphi;
00275 //   d2pdE2 
00276 //   d2ptsE2
00277 
00278   cachevalid = true;
00279 }

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