BOSS 7.0.1
BESIII Offline Software System
Loading...
Searching...
No Matches
Reconstruction/TrackUtil/TrackUtil-00-00-08/TrackUtil/zav.h
Go to the documentation of this file.
1#ifndef _ZAV_H
2#define _ZAV_H
3//#include "mscl.h"
4#include <iostream>
5
6#include "CLHEP/Matrix/Matrix.h"
7#include "CLHEP/Matrix/SymMatrix.h"
8using namespace CLHEP;
9//#include "zhit.h"
10
11class zav {
12public:
13 zav();
14 zav(int) {} // dummy for one of the chain constructor
15 void set(const zav*);
16 double chisq() const { return _chisq; }
17 void add(double , double, double);
18 //void add(const zhit&);
19 double calculate();
20 double a() const { return _a; }
21 double b() const { return _b; }
22 double z(double s) const { return _a * s + _b; }
23 double d(double s, double z) const { return z - _a * s - _b; }
24 int nc() const { return _nc; }
25 void clear(void);
26 inline friend std::ostream&operator<<(std::ostream&, const zav&);
27 //HepSymMatrix cov() const;
28 //friend class chain;
29private:
30 double _a;
31 double _b;
32 double _w;
33 double _sav;
34 double _ssav;
35 double _zav;
36 double _szav;
37 double _zzav;
38 double _chisq;
39 double _sig_inv;
40 double _c11;
41 double _c21;
42 double _c22;
43 int _nc;
44};
45
46inline zav::zav() {
47 _a = _b = _w = _sav = _ssav = _zav = _szav = _zzav = 0;
48 _chisq = -1;
49 _c22 = _c21 = _c11 = _sig_inv = 0;
50 _nc = 0;
51}
52
53inline void zav::clear(void){
54 _w = _sav = _ssav = _zav = _szav = _zzav = 0;
55 _chisq = -1;
56 _c22 = _c21 = _c11 = _sig_inv = 0;
57 _nc = 0;
58}
59
60inline void zav::set(const zav *c) {
61 if(c) {
62 _w = c->_w;
63 _sav = c->_sav;
64 _ssav = c->_ssav;
65 _zav = c->_zav;
66 _szav = c->_szav;
67 _zzav = c->_zzav;
68 _sig_inv = c->_sig_inv;
69 _c11 = c->_c11;
70 _c21 = c->_c21;
71 _c22 = c->_c22;
72 _nc = c->_nc;
73 } else {
74 _w = _sav = _ssav = _zav = _szav = _zzav =
75 _sig_inv = _c11 = _c21 = _c22 = 0;
76 _nc = 0;
77 }
78 _a = _b = 0;
79 _chisq = -1;
80}
81
82inline void zav::add( double s, double z, double w) {
83 _w += w;
84 double sw = s * w;
85 _sav += sw;
86 _ssav += sw * s;
87 double zw = z * w;
88 _zav += zw;
89 _szav += zw * s;
90 _zzav += zw * z;
91 _chisq = -1;
92 _nc++;
93}
94/*
95inline void zav::add(const zhit & h) {
96 double errsq = h._z.error();
97 if (errsq==0) return;
98 errsq *= errsq;
99 double w = 1/errsq;
100 _w += w;
101 double s = (double)h._s;
102 double sw = s * w;
103 _sav += sw;
104 _ssav += sw * s;
105 double z = (double)h._z;
106 double zw = z * w;
107 _zav += zw;
108 _szav += zw * s;
109 _zzav += zw * z;
110 _chisq = -1;
111 _nc++;
112}
113*/
114inline double zav::calculate() {
115 double sig = _ssav * _w - _sav * _sav;
116 if (sig!=0) {
117 _sig_inv = 1/sig;
118 _a = ( _szav * _w - _sav * _zav ) * _sig_inv;
119 _b = ( _ssav * _zav - _sav * _szav ) * _sig_inv;
120 _chisq = _zzav - 2 * _a * _szav - 2 * _b * _zav + _a * _a * _ssav
121 + _b * _b * _w + 2 * _a * _b * _sav;
122 _c11 = _w * _sig_inv;
123 _c21 = - _sav * _sig_inv;
124 _c22 = _ssav * _sig_inv;
125 } else {
126 _sig_inv = 0;
127 _c11 = _c21 = _c22 = 0;
128 _chisq = -1;
129 }
130 if(_nc==2) {
131 _chisq = 0;
132 }
133 return _chisq;
134}
135
136inline std::ostream&operator<<(std::ostream&o,const zav&z) {
137 o << " zav::w=" << z._w << " sav=" << z._sav << " zav=" << z._zav
138 << " nc=" << z._nc << " chisq=" << z._chisq << " a=" << z._a
139 << " b=" << z._b << " c11=" << z._c11 << " c21=" << z._c21
140 << " c22=" << z._c22 << " sig_inv=" << z._sig_inv << std::endl;
141 return o;
142}
143
144/*inline HepSymMatrix zav::cov() const
145{
146#ifndef __GNUG__
147 HepSymMatrix vret(2);
148#endif
149// vret(1,1) = _ssav;
150// vret(2,1) = _sav;
151// vret(2,2) = _w;
152// int iret = invert(vret);
153// if (iret) cerr << "zav::cov(): cannot invert the matrix" << endl;
154 vret(1,1) = _ssav;
155 vret(2,1) = _sav;
156 vret(2,2) = _w;
157 return vret;
158}*/
159#endif /* ZAV */
160
XmlRpcServer s
Definition: HelloServer.cpp:11
std::ostream & operator<<(std::ostream &o, const zav &z)
friend std::ostream & operator<<(std::ostream &, const zav &)
void clear(void)
double calculate()
void add(double, double, double)
double d(double s, double z) const
void set(const zav *)