MucRecQuadFit Class Reference

#include <MucRecQuadFit.h>

List of all members.

Public Member Functions

 MucRecQuadFit ()
 Constructor.
 ~MucRecQuadFit ()
 Destructor.
int QuadFit (float x[], float y[], float w[], int n, float *a, float *b, float *c, int *half, float *chisq, float *siga, float *sigb, float *sigc)


Detailed Description

Definition at line 15 of file MucRecQuadFit.h.


Constructor & Destructor Documentation

MucRecQuadFit::MucRecQuadFit (  ) 

Constructor.

Definition at line 21 of file MucRecQuadFit.cxx.

00022 {
00023     // Constructor.
00024 }

MucRecQuadFit::~MucRecQuadFit (  ) 

Destructor.

Definition at line 26 of file MucRecQuadFit.cxx.

00027 {
00028   // Destructor.
00029 }


Member Function Documentation

int MucRecQuadFit::QuadFit ( float  x[],
float  y[],
float  w[],
int  n,
float *  a,
float *  b,
float *  c,
int *  half,
float *  chisq,
float *  siga,
float *  sigb,
float *  sigc 
)

Definition at line 67 of file MucRecQuadFit.cxx.

References EvtCyclic3::ABC, EvtCyclic3::C, and genRecEmupikp::i.

Referenced by MucRec2DRoad::SimpleFit(), and MucRec2DRoad::SimpleFitNoCurrentGap().

00074                                                          : left 2 : right
00075                        float *chisq,
00076                        float *siga, 
00077                        float *sigb,
00078                        float *sigc)
00079   
00080 {
00081   double sumx, sumx2, sumx3, sumx4,sumy, sumyx, sumyx2, det;
00082   float chi;
00083   
00084   /* The variable "i" is declared 8 bytes long to avoid triggering an
00085      apparent alignment bug in optimized code produced by gcc-2.95.3.
00086      The bug doesn't seem to be present in gcc-3.2. */
00087   long i; 
00088 
00089   chi = 99999999.0;
00090   *a = 0; *b = 0; *c = 0;
00091   *half = 0;
00092 
00093   /* N must be >= 2 for this guy to work */
00094   if (n < 3) 
00095     {
00096       //cout << "utiQuadFit-W: Too few points for quad fit \n" << endl;
00097       return -1;
00098     }
00099 
00100   /* Initialization */
00101   sumx  = 0.0;
00102   sumx2 = 0.0;
00103   sumx3 = 0.0;
00104   sumx4 = 0.0;
00105   sumy  = 0.0;
00106   sumyx = 0.0;
00107   sumyx2 = 0.0;
00108 
00109 
00110   /* Find sum , sumx ,sumy, sumxx, sumxy */
00111   for (i = 0; i < n; i++)
00112     {
00113       sumx = sumx + w[i] * x[i];
00114       sumx2 = sumx2 + w[i] * x[i] * x[i];
00115       sumx3 = sumx3 + w[i] * x[i] * x[i] * x[i];
00116       sumx4 = sumx4 + w[i] * x[i] * x[i] * x[i] * x[i];
00117       sumy = sumy + w[i] * y[i];
00118       sumyx = sumyx + w[i] * y[i] * x[i];
00119       sumyx2 = sumyx2 + w[i] * y[i] * x[i] * x[i];      
00120       //cout<<"x : y "<<x[i]<<" "<<y[i]<<endl;
00121 
00122     }
00123 
00124 
00125 
00126   /* compute the best fitted parameters A,B,C */
00127 
00128     HepMatrix D(3,3,1);
00129     HepMatrix C(3,1), ABC(3,1);
00130     D(1,1) = sumx4; D(1,2) = D(2,1) = sumx3; D(1,3) = D(3,1) = D(2,2) = sumx2;
00131     D(3,2) = D(2,3) = sumx; D(3,3) = n;
00132     C(1,1) = sumyx2; C(2,1) = sumyx; C(3,1) = sumy;
00133 
00134     int ierr;
00135     ABC = (D.inverse(ierr))*C;
00136 
00137     *a = ABC(1,1);
00138     *b = ABC(2,1);
00139     *c = ABC(3,1);
00140     
00141     //judge which half parabola these points belone to
00142     float center = *b/(-2*(*a));
00143     float mean_x;
00144     for(i = 0; i < n; i++){
00145       mean_x += x[i]/n;
00146     }
00147 
00148     if(mean_x > center) *half = 2;//right half
00149     else *half = 1;//left half
00150     
00151     //cout<<"in MucRecQuadFit:: which half= "<<*half<<endl;
00152 
00153   /* calculate chi-square */
00154   chi = 0.0;
00155   for (i=0; i<n; i++) 
00156     {
00157       chi = chi+(w[i])*((y[i])-*a*(x[i])-*b)*
00158         ((y[i])-*a*(x[i])-*b);
00159     }
00160   
00161   //*siga = sum/det;
00162   //*sigb = sxx/det;
00163   
00164   *chisq = chi;
00165   return 1;
00166 }   


Generated on Tue Nov 29 23:20:30 2016 for BOSS_7.0.2 by  doxygen 1.4.7