BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
Reconstruction/MdcPatRec/MdcRecoUtil/include/MdcRecoUtil/DifNumber.h
Go to the documentation of this file.
1//--------------------------------------------------------------------------
2// File and Version Information:
3// $Id: DifNumber.h,v 1.3 2009/12/23 02:59:56 zhangy Exp $
4//
5// Description:
6// Class Header for |DifNumber|
7// class to represent a number with derivatives
8//
9// Environment:
10// Software developed for the BaBar Detector at the SLAC B-Factory.
11//
12// Author List:
13// A. Snyder
14//
15// Copyright Information:
16// Copyright (C) 1996 SLAC
17//
18// History:
19// Migration for BESIII MDC
20//
21//------------------------------------------------------------------------
22
23#ifndef DifNumber_HH
24#define DifNumber_HH
25
26#define MATRIX_BOUND_CHECK
27// #include "BaBar/BaBar.hh"
28#include "CLHEP/Matrix/Matrix.h"
29#include "CLHEP/Matrix/SymMatrix.h"
30#include "CLHEP/Matrix/Vector.h"
31#include "MdcRecoUtil/Code.h"
32#include <assert.h>
33#include <math.h>
34using CLHEP::HepMatrix;
35using CLHEP::HepSymMatrix;
36using CLHEP::HepVector;
37
38#include <iosfwd>
39class DifIndepPar;
40
41class DifNumber {
42
43private:
44 enum { _nmax = 100 };
45
46public:
47 // constructors and destructor
48 inline DifNumber(); // zero with derivatives=0
49 inline explicit // disallow implicit promotion to DifNumber
50 DifNumber // s w/o derivatives
51 ( double s, int npar = 0 ); // or s with derivatives=0
52 inline DifNumber // s with derivatives d
53 ( double s, const HepVector& d );
54 inline DifNumber( double s, int i, double di, int npar ); // s with i'th derivative set
55 inline DifNumber( double s, int i, int npar ); // s with ith derivative=1.0
56 inline DifNumber( double s,
57 const DifIndepPar* indeppar ); // s with derivatives 0 wrt |indeppar|
58 inline DifNumber( double s, int i,
59 const DifIndepPar* indepar ); // s with i'th derivative wrt |indpar|
60
61private:
62 inline DifNumber( double newval, const DifNumber& old,
63 double factor = 0.0 ); // new value, derivs*factor
64
65public:
66 inline DifNumber( const DifNumber& s ); // copy
67 virtual ~DifNumber() {}
68
69 // set
70 inline void setNumber( double i ) { _number = i; }
71 inline void setNPar( int i ) { _npar = i; }
72 inline void setDerivatives( const HepVector& d ) { copyDerivs( d ); }
73 inline void setDerivative( int i, double value ) { _derivatives[i - 1] = value; }
74 inline void zeroDerivatives() {
75 for ( int i = 1; i <= nPar(); i++ ) setDerivative( i, 0.0 );
76 }
77 inline void setIndepPar( const DifIndepPar* par ) { _indepPar = par; }
78 inline void extendPar( int nnew );
79
80 // access info
81 inline double number() const { return _number; }
82 inline double& gimeNumber() { return _number; }
83 HepVector derivatives() const;
84 inline double derivative( int i ) const { return _derivatives[i - 1]; }
85 inline int nMax() { return _nmax; }
86 inline int nPar() const { return _npar; }
87 inline const DifIndepPar* indepPar() const { return _indepPar; }
88 double error( const HepSymMatrix& e ) const; // error from specified error
89 double error() const; // error from default error
90 inline void tickle() const { return; } // tickle a number
91
92 // io
93 void print( /*std::ostream& o*/ ) const; // print out
94
95 // operators and such
96
97 // internals
98 inline DifNumber& operator+=( const DifNumber& a );
99 inline DifNumber& operator-=( const DifNumber& a );
100 inline DifNumber& operator*=( const DifNumber& a );
101 inline DifNumber& operator/=( const DifNumber& a );
102 inline DifNumber& operator=( const DifNumber& a );
103 inline DifNumber operator-() const { return DifNumber( *this ).flipsign(); } // unary minus
104
105 inline DifNumber& operator+=( const double& a );
106 inline DifNumber& operator-=( const double& a );
107 inline DifNumber& operator*=( const double& a );
108 inline DifNumber& operator/=( const double& a );
109 inline DifNumber& operator=( const double& a );
110
111 // manupulate this guy - reverse polish style algebra
112 inline DifNumber& inverse(); // invert
113 inline DifNumber& flipsign(); // flip the sign
114 inline DifNumber& absolute() /* take absolute value */ {
115 if ( _number < 0 ) flipsign();
116 return *this;
117 }
118 inline void cosAndSin( DifNumber& c, DifNumber& s ) const; // calc sine and cosine of this
119 inline DifNumber& squareRoot(); // take square root of this
120 inline DifNumber& mod( double lo, double hi ); // mod to specified range
121 inline DifNumber& arcTangent( const DifNumber& x ); // arctangent |*this/x| = atan2(*this,x)
122 inline DifNumber& power( double p ); // raise to a power
123 inline DifNumber& power( const DifNumber& p ); // raise to a power
124
125 inline double sign() const /* return sign of number */ { return _number >= 0 ? 1 : -1; }
126 double correlation( const DifNumber& b,
127 const HepSymMatrix& e ) const; // correlation for specified error
128 double correlation( const DifNumber& b ) const; // correlation from default matrix
129
130 // sum into functions
131 void sumMatrix( HepMatrix& m ) const;
132
133 // fetch functions
134 void fetchNumber( double& n ) const { n = number(); }
135 void fetchDerivatives( HepVector& v ) const;
136
137 // friends
138 inline friend DifNumber operator+( const DifNumber& a, const DifNumber& b ) {
139 return DifNumber( a ) += b;
140 }
141 inline friend DifNumber operator-( const DifNumber& a, const DifNumber& b ) {
142 return DifNumber( a ) -= b;
143 }
144 inline friend DifNumber operator*( const DifNumber& a, const DifNumber& b ) {
145 return DifNumber( a ) *= b;
146 }
147 inline friend DifNumber operator/( const DifNumber& a, const DifNumber& b ) {
148 return DifNumber( a ) /= b;
149 }
150
151 inline friend DifNumber operator+( const DifNumber& a, const double& b ) {
152 return DifNumber( a ) += b;
153 }
154 inline friend DifNumber operator-( const DifNumber& a, const double& b ) {
155 return DifNumber( a ) -= b;
156 }
157 inline friend DifNumber operator*( const DifNumber& a, const double& b ) {
158 return DifNumber( a ) *= b;
159 }
160 inline friend DifNumber operator/( const DifNumber& a, const double& b ) {
161 return DifNumber( a ) /= b;
162 }
163
164 inline friend DifNumber operator+( const double& a, const DifNumber& b ) {
165 return DifNumber( a ) += b;
166 }
167 inline friend DifNumber operator-( const double& a, const DifNumber& b ) {
168 return DifNumber( a ) -= b;
169 }
170 inline friend DifNumber operator*( const double& a, const DifNumber& b ) {
171 return DifNumber( a ) *= b;
172 }
173 inline friend DifNumber operator/( const double& a, const DifNumber& b ) {
174 return DifNumber( a ) /= b;
175 }
176
177 inline friend bool operator>( const DifNumber& a, const DifNumber& b ) {
178 return a.number() > b.number();
179 }
180 inline friend bool operator>( const DifNumber& a, const double& b ) {
181 return a.number() > b;
182 }
183 inline friend bool operator>( const double& a, const DifNumber& b ) {
184 return a > b.number();
185 }
186
187 inline friend bool operator<( const DifNumber& a, const DifNumber& b ) { return b > a; }
188 inline friend bool operator<( const DifNumber& a, const double& b ) { return b > a; }
189 inline friend bool operator<( const double& a, const DifNumber& b ) { return b > a; }
190
191 inline friend bool operator>=( const DifNumber& a, const DifNumber& b ) {
192 return a.number() >= b.number();
193 }
194 inline friend bool operator>=( const DifNumber& a, const double& b ) {
195 return a.number() >= b;
196 }
197 inline friend bool operator>=( const double& a, const DifNumber& b ) {
198 return a >= b.number();
199 }
200
201 inline friend bool operator<=( const DifNumber& a, const DifNumber& b ) { return b >= a; }
202 inline friend bool operator<=( const DifNumber& a, const double& b ) { return b >= a; }
203 inline friend bool operator<=( const double& a, const DifNumber& b ) { return b >= a; }
204
205 inline friend bool operator==( const DifNumber& a, const DifNumber& b );
206 inline friend bool operator==( const DifNumber& a, const double& b ) { return false; }
207 inline friend bool operator==( const double& a, const DifNumber& b ) { return false; }
208
209 inline friend bool operator!=( const DifNumber& a, const DifNumber& b ) {
210 return !( a == b );
211 }
212 inline friend bool operator!=( const DifNumber& a, const double& b ) { return true; }
213 inline friend bool operator!=( const double& a, const DifNumber& b ) { return true; }
214
215 inline friend DifNumber sin( const DifNumber& a ) {
216 return DifNumber( sin( a.number() ), a, cos( a.number() ) );
217 }
218 inline friend DifNumber cos( const DifNumber& a ) {
219 return DifNumber( cos( a.number() ), a, -sin( a.number() ) );
220 }
221 inline friend DifNumber tan( const DifNumber& a ) {
222 double t = tan( a.number() );
223 return DifNumber( t, a, 1.0 + t * t );
224 }
225 inline friend DifNumber sec( const DifNumber& a ) { return DifNumber( cos( a ) ).inverse(); }
226 inline friend DifNumber asin( const DifNumber& a );
227 inline friend DifNumber acos( const DifNumber& a );
228 inline friend DifNumber atan( const DifNumber& a );
229
230 inline friend DifNumber atan2( const DifNumber& y, const DifNumber& x ) {
231 return DifNumber( y ).arcTangent( x );
232 }
233 inline friend DifNumber atan2( const DifNumber& y, const double& x ) {
234 return DifNumber( y ).arcTangent( DifNumber( x ) );
235 }
236 inline friend DifNumber atan2( const double& y, const DifNumber& x ) {
237 return DifNumber( y ).arcTangent( x );
238 }
239
240 inline friend DifNumber exp( const DifNumber& a ) {
241 double e = exp( a.number() );
242 return DifNumber( e, a, e );
243 }
244 inline friend DifNumber cosh( const DifNumber& a ) {
245 return 0.5 * ( DifNumber( exp( a ) ) += exp( -a ) );
246 }
247 inline friend DifNumber sinh( const DifNumber& a ) {
248 return 0.5 * ( DifNumber( exp( a ) ) -= exp( -a ) );
249 }
250 inline friend DifNumber tanh( const DifNumber& a ) {
251 double t = tanh( a.number() );
252 return DifNumber( t, a, 1.0 - t * t );
253 }
254 // inline friend DifNumber sqrt(const DifNumber& a)
255 //{ DifNumber temp(a); return temp.squareRoot(); }
256 inline friend DifNumber sqrt( const DifNumber& a ) { return DifNumber( a ).squareRoot(); }
257 inline friend DifNumber log( const DifNumber& a ) {
258 return DifNumber( log( a.number() ), a, 1.0 / a.number() );
259 }
260 inline friend DifNumber fabs( const DifNumber& a ) {
261 return DifNumber( fabs( a.number() ), a, a.sign() );
262 }
263 inline friend DifNumber pow( const DifNumber& a, const DifNumber& b ) {
264 return DifNumber( a ).power( b );
265 }
266 inline friend DifNumber pow( const DifNumber& a, int i ) { return pow( a, (double)i ); }
267 inline friend DifNumber pow( const DifNumber& a, float i ) { return pow( a, (double)i ); }
268 inline friend DifNumber pow( const DifNumber& a, double i ) {
269 return i == 0 ? DifNumber( 1.0, a, 0.0 )
270 : DifNumber( pow( a.number(), i ), a, i * pow( a.number(), i - 1 ) );
271 }
272
273 // FIXME: this one should be inlined...
274 friend double correlation( const DifNumber& a, const DifNumber& b,
275 const HepSymMatrix& e ); // correlation for specified error
276
277 inline friend double correlation( const DifNumber& a,
278 const DifNumber& b ); // correlation from default matrix
279
280private:
281 // data
282 double _number; // value of number
283 int _npar; // number of parameters
284 const DifIndepPar* _indepPar; // pointer to independent parameters
285 double _derivatives[_nmax]; // derivatives
286
287 // functions
288 inline DifNumber& copyDerivs( const DifNumber& n ); // copy derivatives from n
289 inline DifNumber& scaleDerivs( const DifNumber& n,
290 double factor ); // copy byt scale by factor
291 inline DifNumber& copyDerivs( const HepVector& v ); // copy derivatives v
292 inline DifNumber& check( const DifNumber& a ); // check for consistent numbers
293 inline DifNumber& setLike( const DifNumber& a ); // set change to same type as |a|
294};
295
296// io
297// yzhang delete
298// inline std::ostream& operator<<(std::ostream& o,const DifNumber& n) { n.print(o); return o;
299// }
300//
301DifNumber solveQuad( const DifNumber& a, const DifNumber& b, const DifNumber& c, int pref,
302 Code& code );
303
304#include "MdcRecoUtil/DifNumber.icc"
305
306#endif
const Int_t n
XmlRpcServer s
**********Class see also m_nmax DOUBLE PRECISION m_amel DOUBLE PRECISION m_x2 DOUBLE PRECISION m_alfinv DOUBLE PRECISION m_Xenph INTEGER m_KeyWtm INTEGER m_idyfs DOUBLE PRECISION m_zini DOUBLE PRECISION m_q2 DOUBLE PRECISION m_Wt_KF DOUBLE PRECISION m_WtCut INTEGER m_KFfin *COMMON c_KarLud $ !Input CMS energy[GeV] $ !CMS energy after beam spread beam strahlung[GeV] $ !Beam energy spread[GeV] $ !z boost due to beam spread $ !electron beam mass *ff pair spectrum $ !minimum v
Definition KarLud.h:35
DifNumber solveQuad(const DifNumber &a, const DifNumber &b, const DifNumber &c, int pref, Code &code)
Definition DifNumber.cxx:91
friend bool operator==(const DifNumber &a, const DifNumber &b)
void fetchDerivatives(HepVector &v) const
friend DifNumber atan2(const DifNumber &y, const double &x)
friend DifNumber operator*(const DifNumber &a, const double &b)
friend DifNumber operator+(const DifNumber &a, const double &b)
friend bool operator>=(const DifNumber &a, const DifNumber &b)
DifNumber & power(double p)
HepVector derivatives() const
friend bool operator<(const DifNumber &a, const double &b)
double correlation(const DifNumber &b, const HepSymMatrix &e) const
void extendPar(int nnew)
friend bool operator>=(const double &a, const DifNumber &b)
friend bool operator==(const double &a, const DifNumber &b)
friend DifNumber asin(const DifNumber &a)
friend DifNumber operator-(const DifNumber &a, const double &b)
friend bool operator<(const DifNumber &a, const DifNumber &b)
friend DifNumber pow(const DifNumber &a, const DifNumber &b)
void print() const
DifNumber(double s, int i, int npar)
friend bool operator!=(const DifNumber &a, const double &b)
double error() const
DifNumber & operator=(const double &a)
friend bool operator>(const DifNumber &a, const double &b)
friend bool operator>(const DifNumber &a, const DifNumber &b)
DifNumber & flipsign()
DifNumber & operator=(const DifNumber &a)
friend DifNumber operator/(const DifNumber &a, const double &b)
friend DifNumber operator+(const double &a, const DifNumber &b)
friend DifNumber pow(const DifNumber &a, double i)
DifNumber & operator/=(const DifNumber &a)
friend bool operator>(const double &a, const DifNumber &b)
DifNumber(const DifNumber &s)
friend bool operator<(const double &a, const DifNumber &b)
double correlation(const DifNumber &b) const
friend DifNumber atan(const DifNumber &a)
friend DifNumber pow(const DifNumber &a, float i)
friend DifNumber operator*(const double &a, const DifNumber &b)
DifNumber & mod(double lo, double hi)
DifNumber(double s, const DifIndepPar *indeppar)
friend DifNumber pow(const DifNumber &a, int i)
friend DifNumber operator-(const double &a, const DifNumber &b)
friend DifNumber operator/(const DifNumber &a, const DifNumber &b)
DifNumber(double s, int i, double di, int npar)
DifNumber & operator/=(const double &a)
friend DifNumber atan2(const DifNumber &y, const DifNumber &x)
DifNumber(double s, int i, const DifIndepPar *indepar)
friend bool operator<=(const DifNumber &a, const double &b)
friend DifNumber acos(const DifNumber &a)
DifNumber & operator*=(const DifNumber &a)
friend bool operator>=(const DifNumber &a, const double &b)
DifNumber & operator+=(const double &a)
friend bool operator!=(const DifNumber &a, const DifNumber &b)
void cosAndSin(DifNumber &c, DifNumber &s) const
DifNumber & operator-=(const double &a)
DifNumber & operator-=(const DifNumber &a)
friend bool operator<=(const DifNumber &a, const DifNumber &b)
DifNumber & squareRoot()
DifNumber & operator*=(const double &a)
void sumMatrix(HepMatrix &m) const
DifNumber & operator+=(const DifNumber &a)
friend DifNumber operator+(const DifNumber &a, const DifNumber &b)
double error(const HepSymMatrix &e) const
friend DifNumber operator-(const DifNumber &a, const DifNumber &b)
friend DifNumber operator*(const DifNumber &a, const DifNumber &b)
DifNumber & inverse()
friend bool operator!=(const double &a, const DifNumber &b)
DifNumber & arcTangent(const DifNumber &x)
friend DifNumber operator/(const double &a, const DifNumber &b)
friend DifNumber atan2(const double &y, const DifNumber &x)
DifNumber & power(const DifNumber &p)
friend bool operator==(const DifNumber &a, const double &b)
friend bool operator<=(const double &a, const DifNumber &b)
int t()
Definition t.c:1