/home/bes3soft/bes3soft/Boss/7.0.2/dist/7.0.2/Reconstruction/MdcPatRec/MdcTrkRecon/MdcTrkRecon-00-03-45/src/MdcLine.cxx

Go to the documentation of this file.
00001 // MdcLine.cc -- simple straight line fitter
00002 
00003 #include "MdcTrkRecon/MdcLine.h"
00004 #include <stdlib.h>
00005 #include <math.h>
00006 // End Implementation Dependencies -------------------------------------
00007 #include <iostream>
00008 using namespace std;//yzhang debug
00009 
00010 int MdcLine::fit(int nUse) {
00011 
00012   double s1, sx, sy, sxx, sxy;  // The various sums. 
00013   double delinv, denom;
00014   double weight = 0.013;     // weight for hits, calculated from sigmas. 
00015   int ihit;
00016   if (nUse > nPoint) nUse = nPoint;
00017   s1 = sx = sy = sxx = sxy = 0.0;
00018   chisq = 0.0;
00019   for (ihit = 0; ihit < nUse; ihit++) {
00020     
00021     if (sigma[ihit] < 0.0) continue;
00022     weight = 1. / (sigma[ihit] * sigma[ihit]);//NEED sigma of MdcHits
00023     s1 += weight;    
00024     sx += x[ihit] * weight;
00025     sy += y[ihit] * weight;
00026     sxx += x[ihit] * (x[ihit] * weight);
00027     sxy += y[ihit] * (x[ihit] * weight);
00028 
00029     //std::cout<<__FILE__<<" "<<__LINE__<< " "<<ihit<<" sigma "<<
00030       //sigma[ihit] <<" weight "
00031       //<< weight<<" x "
00032       //<< x[ihit]<<" y "
00033       //<< y[ihit]<< std::endl;
00034   }
00035   
00036   /* Calculate parameters. */
00037   denom = s1 * sxx - sx * sx;
00038   delinv = (denom == 0.0) ? 1.e20 : 1. / denom;
00039   intercept = (sy * sxx - sx * sxy) * delinv;
00040   slope = (s1 * sxy - sx * sy) * delinv;
00041   errmat[0] = sxx * delinv;
00042   errmat[1] = -sx * delinv;
00043   errmat[2] = s1 * delinv;
00044   //std::cout << " After Fit:" << std::endl;//yzhang debug
00045   /* Calculate residuals. */
00046   for (ihit = 0; ihit < nUse; ihit++) {
00047     if (sigma[ihit] < 0.0) continue;
00048     resid[ihit] = ( y[ihit] - intercept - slope * x[ihit] );
00049     chisq += resid[ihit] * resid[ihit] / (sigma[ihit] * sigma[ihit]);
00050     //std::cout << "resid "<<ihit<<" "<<resid[ihit]<<" sigma "<<sigma[ihit]<<" chisq add "<<resid[ihit] * resid[ihit] / (sigma[ihit] * sigma[ihit]) << std::endl;//yzhang debug 
00051   }
00052 
00053   //std::cout<<__FILE__<<" "<<__LINE__
00054   //<< " intercept "<<intercept<<" slope "<<slope 
00055           //<< " chisq "<<chisq<<std::endl;//yzhang debug 
00056   return 0;
00057 }
00058 
00059 
00060 
00061 
00062 

Generated on Tue Nov 29 23:13:33 2016 for BOSS_7.0.2 by  doxygen 1.4.7