BOSS 7.1.0
BESIII Offline Software System
Loading...
Searching...
No Matches
MdcLine.cxx
Go to the documentation of this file.
1// MdcLine.cc -- simple straight line fitter
2
4#include <stdlib.h>
5#include <math.h>
6// End Implementation Dependencies -------------------------------------
7#include <iostream>
8using namespace std;//yzhang debug
9
10int MdcLine::fit(int nUse) {
11
12 double s1, sx, sy, sxx, sxy; // The various sums.
13 double delinv, denom;
14 double weight = 0.013; // weight for hits, calculated from sigmas.
15 int ihit;
16 if (nUse > nPoint) nUse = nPoint;
17 s1 = sx = sy = sxx = sxy = 0.0;
18 chisq = 0.0;
19 for (ihit = 0; ihit < nUse; ihit++) {
20
21 if (sigma[ihit] < 0.0) continue;
22 weight = 1. / (sigma[ihit] * sigma[ihit]);//NEED sigma of MdcHits
23 s1 += weight;
24 sx += x[ihit] * weight;
25 sy += y[ihit] * weight;
26 sxx += x[ihit] * (x[ihit] * weight);
27 sxy += y[ihit] * (x[ihit] * weight);
28
29 //std::cout<<__FILE__<<" "<<__LINE__<< " "<<ihit<<" sigma "<<
30 //sigma[ihit] <<" weight "
31 //<< weight<<" x "
32 //<< x[ihit]<<" y "
33 //<< y[ihit]<< std::endl;
34 }
35
36 /* Calculate parameters. */
37 denom = s1 * sxx - sx * sx;
38 delinv = (denom == 0.0) ? 1.e20 : 1. / denom;
39 intercept = (sy * sxx - sx * sxy) * delinv;
40 slope = (s1 * sxy - sx * sy) * delinv;
41 errmat[0] = sxx * delinv;
42 errmat[1] = -sx * delinv;
43 errmat[2] = s1 * delinv;
44 //std::cout << " After Fit:" << std::endl;//yzhang debug
45 /* Calculate residuals. */
46 for (ihit = 0; ihit < nUse; ihit++) {
47 if (sigma[ihit] < 0.0) continue;
48 resid[ihit] = ( y[ihit] - intercept - slope * x[ihit] );
49 chisq += resid[ihit] * resid[ihit] / (sigma[ihit] * sigma[ihit]);
50 //std::cout << "resid "<<ihit<<" "<<resid[ihit]<<" sigma "<<sigma[ihit]<<" chisq add "<<resid[ihit] * resid[ihit] / (sigma[ihit] * sigma[ihit]) << std::endl;//yzhang debug
51 }
52
53 //std::cout<<__FILE__<<" "<<__LINE__
54 //<< " intercept "<<intercept<<" slope "<<slope
55 //<< " chisq "<<chisq<<std::endl;//yzhang debug
56 return 0;
57}
58
59
60
61
62
*********Class see also m_nmax DOUBLE PRECISION m_MasPhot DOUBLE PRECISION m_phsu DOUBLE PRECISION m_Xenph DOUBLE PRECISION m_r2 DOUBLE PRECISION m_WtMass INTEGER m_nmax INTEGER m_Nevgen INTEGER m_IsFSR INTEGER m_MarTot *COMMON c_KarFin $ !Output file $ !Event serial number $ !alpha QED at Thomson limit $ !minimum energy at CMS for remooval $ !infrared dimensionless $ !dummy photon IR regulator $ !crude photon multiplicity enhancement factor *EVENT $ !MC crude volume of PhhSpace *Sfactors $ !YFS formfactor IR part only $ !YFS formfactor non IR finite part $ !mass weight
Definition: KarFin.h:34
double * x
Definition: MdcLine.h:15
double intercept
Definition: MdcLine.h:21
double * y
Definition: MdcLine.h:16
double slope
Definition: MdcLine.h:20
int nPoint
Definition: MdcLine.h:19
double chisq
Definition: MdcLine.h:22
double * resid
Definition: MdcLine.h:18
double errmat[3]
Definition: MdcLine.h:23
int fit(int nUse)
Definition: MdcLine.cxx:10
double * sigma
Definition: MdcLine.h:17