CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
RZLine.cc
Go to the documentation of this file.
1 #include "RZLine.h"
3 
4 using namespace std;
5 template <class T> inline T sqr( T t) {return t*t;}
6 
7 RZLine::RZLine(const std::vector<float> & aR,
8  const std::vector<float> & aZ,
9  const std::vector<float> & aErrZ) :
10  storage(3*aR.size()) {
11  nPoints = aR.size();
12  r = &storage.front();
13  z = r+nPoints;
14  errZ2 = z+nPoints;
15  for (int i=0; i<nPoints; i++) {
16  r[i] = aR[i];
17  z[i]=aZ[i];
18  errZ2[i] = aErrZ[i]*aErrZ[i];
19  }
20 }
21 
22 RZLine::RZLine( const GlobalPoint * points,
23  const GlobalError * errors,
24  const bool * isBarrel, unsigned int size):
25  storage(3*size) {
26  nPoints = size;
27  r = &storage.front();
28  z = r+nPoints;
29  errZ2 = z+nPoints;
30  for (int i=0; i!=nPoints; ++i) {
31  const GlobalPoint & p = points[i];
32  r[i] = p.perp();
33  z[i] = p.z();
34  }
35 
36  float simpleCot2 = ( z[nPoints-1]-z[0] )/ (r[nPoints-1] - r[0] );
37  simpleCot2 *= simpleCot2;
38  for (int i=0; i!=nPoints; ++i) {
39  errZ2[i] = (isBarrel[i]) ? errors[i].czz() :
40  errors[i].rerr(points[i]) * simpleCot2;
41  }
42 }
43 
44 void RZLine::fit(float & cotTheta, float & intercept,
45  float &covss, float &covii, float &covsi) const
46 {
47  linearFit( r, z, nPoints, errZ2, cotTheta, intercept, covss, covii, covsi);
48 }
49 
50 float RZLine::chi2(float cotTheta, float intercept) const
51 {
52  float chi2 = 0.f;
53  for (int i=0; i!=nPoints; ++i) chi2 += sqr( ((z[i]-intercept) - cotTheta*r[i]) ) / errZ2[i];
54  return chi2;
55 }
int i
Definition: DBlmapReader.cc:9
float * errZ2
Definition: RZLine.h:31
T perp() const
Definition: PV3DBase.h:72
bool isBarrel(GeomDetEnumerators::SubDetector m)
T z() const
Definition: PV3DBase.h:64
T rerr(const GlobalPoint &aPoint) const
std::vector< float > storage
Definition: RZLine.h:29
void linearFit(T const *__restrict__ x, T const *__restrict__ y, int ndat, T const *__restrict__ sigy2, T &slope, T &intercept, T &covss, T &covii, T &covsi)
Definition: LinearFit.h:26
Square< F >::type sqr(const F &f)
Definition: Square.h:13
void fit(float &cotTheta, float &intercept, float &covss, float &covii, float &covsi) const
Definition: RZLine.cc:44
float * r
Definition: RZLine.h:31
int nPoints
Definition: RZLine.h:30
RZLine(const DynArray< GlobalPoint > &points, const DynArray< GlobalError > &errors, const DynArray< bool > &isBarrel)
Definition: RZLine.h:13
float chi2(float cotTheta, float intercept) const
Definition: RZLine.cc:50
float * z
Definition: RZLine.h:31
long double T
tuple size
Write out results.