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