BOSS 7.0.6
BESIII Offline Software System
Loading...
Searching...
No Matches
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
27#define MATRIX_BOUND_CHECK
28//#include "BaBar/BaBar.hh"
29#include <math.h>
30#include <assert.h>
31#include "CLHEP/Matrix/Vector.h"
32#include "CLHEP/Matrix/SymMatrix.h"
33#include "CLHEP/Matrix/Matrix.h"
34#include "MdcRecoUtil/Code.h"
35using CLHEP::HepVector;
36using CLHEP::HepMatrix;
37using CLHEP::HepSymMatrix;
38
39#include <iosfwd>
40class DifIndepPar;
41
42class DifNumber {
43
44private:
45 enum{_nmax=100};
46
47public:
48
49 //constructors and destructor
50 inline
51 DifNumber(); // zero with derivatives=0
52 inline
53 explicit // disallow implicit promotion to DifNumber
54 DifNumber // s w/o derivatives
55 (double s,int npar=0); // or s with derivatives=0
56 inline
57 DifNumber // s with derivatives d
58 (double s,const HepVector& d);
59 inline
60 DifNumber(double s,int i,double di,int npar); // s with i'th derivative set
61 inline
62 DifNumber(double s,int i,int npar); // s with ith derivative=1.0
63 inline
64 DifNumber(double s,const DifIndepPar* indeppar); // s with derivatives 0 wrt |indeppar|
65 inline
66 DifNumber(double s,int i,const DifIndepPar* indepar); // s with i'th derivative wrt |indpar|
67
68private:
69 inline
70 DifNumber(double newval,const DifNumber& old,double factor=0.0);// new value, derivs*factor
71
72public:
73 inline
74 DifNumber(const DifNumber& s); // copy
75 virtual ~DifNumber() {}
76
77 //set
78 inline void setNumber(double i) { _number=i;}
79 inline void setNPar(int i) { _npar=i;}
80 inline void setDerivatives(const HepVector& d) { copyDerivs(d); }
81 inline void setDerivative(int i,double value) { _derivatives[i-1]=value;}
82 inline void zeroDerivatives() { for(int i=1; i<=nPar(); i++) setDerivative(i,0.0); }
83 inline void setIndepPar(const DifIndepPar* par) { _indepPar=par;}
84 inline void extendPar(int nnew);
85
86 //access info
87 inline double number()const {return _number;}
88 inline double& gimeNumber() {return _number;}
89 HepVector derivatives()const;
90 inline double derivative(int i)const {return _derivatives[i-1];}
91 inline int nMax() {return _nmax;}
92 inline int nPar()const {return _npar;}
93 inline const DifIndepPar* indepPar()const {return _indepPar;}
94 double error(const HepSymMatrix& e)const; // error from specified error
95 double error()const; // error from default error
96 inline void tickle()const {return;} // tickle a number
97
98 //io
99 void print(/*std::ostream& o*/)const; // print out
100
101 //operators and such
102
103 //internals
104 inline DifNumber& operator+=(const DifNumber& a);
105 inline DifNumber& operator-=(const DifNumber& a);
106 inline DifNumber& operator*=(const DifNumber& a);
107 inline DifNumber& operator/=(const DifNumber& a);
108 inline DifNumber& operator=(const DifNumber& a);
109 inline DifNumber operator-()const
110 { return DifNumber(*this).flipsign(); } // unary minus
111
112 inline DifNumber& operator+=(const double& a);
113 inline DifNumber& operator-=(const double& a);
114 inline DifNumber& operator*=(const double& a);
115 inline DifNumber& operator/=(const double& a);
116 inline DifNumber& operator=(const double& a);
117
118
119 //manupulate this guy - reverse polish style algebra
120 inline DifNumber& inverse(); // invert
121 inline DifNumber& flipsign(); // flip the sign
122 inline DifNumber& absolute() /* take absolute value */ { if (_number<0) flipsign(); return *this; }
123 inline void cosAndSin(DifNumber& c,DifNumber& s)const; // calc sine and cosine of this
124 inline DifNumber& squareRoot(); // take square root of this
125 inline DifNumber& mod(double lo,double hi); // mod to specified range
126 inline DifNumber& arcTangent(const DifNumber& x); // arctangent |*this/x| = atan2(*this,x)
127 inline DifNumber& power(double p); // raise to a power
128 inline DifNumber& power(const DifNumber& p); // raise to a power
129
130 inline double sign()const /* return sign of number */ { return _number>=0 ? 1 : -1; }
131 double correlation(const DifNumber& b,const HepSymMatrix& e) const; // correlation for specified error
132 double correlation(const DifNumber& b) const; // correlation from default matrix
133
134 //sum into functions
135 void sumMatrix(HepMatrix& m)const;
136
137 //fetch functions
138 void fetchNumber(double& n)const {n=number();}
139 void fetchDerivatives(HepVector& v)const;
140
141 //friends
142 inline friend DifNumber operator+(const DifNumber& a,const DifNumber& b) { return DifNumber(a)+=b; }
143 inline friend DifNumber operator-(const DifNumber& a,const DifNumber& b) { return DifNumber(a)-=b; }
144 inline friend DifNumber operator*(const DifNumber& a,const DifNumber& b) { return DifNumber(a)*=b; }
145 inline friend DifNumber operator/(const DifNumber& a,const DifNumber& b) { return DifNumber(a)/=b; }
146
147 inline friend DifNumber operator+(const DifNumber& a,const double& b) { return DifNumber(a)+=b; }
148 inline friend DifNumber operator-(const DifNumber& a,const double& b) { return DifNumber(a)-=b; }
149 inline friend DifNumber operator*(const DifNumber& a,const double& b) { return DifNumber(a)*=b; }
150 inline friend DifNumber operator/(const DifNumber& a,const double& b) { return DifNumber(a)/=b; }
151
152 inline friend DifNumber operator+(const double& a,const DifNumber& b) { return DifNumber(a)+=b; }
153 inline friend DifNumber operator-(const double& a,const DifNumber& b) { return DifNumber(a)-=b; }
154 inline friend DifNumber operator*(const double& a,const DifNumber& b) { return DifNumber(a)*=b; }
155 inline friend DifNumber operator/(const double& a,const DifNumber& b) { return DifNumber(a)/=b; }
156
157
158 inline friend bool operator>(const DifNumber& a,const DifNumber& b) { return a.number()>b.number(); }
159 inline friend bool operator>(const DifNumber& a,const double& b) { return a.number()>b; }
160 inline friend bool operator>(const double& a,const DifNumber& b) { return a>b.number(); }
161
162 inline friend bool operator<(const DifNumber& a,const DifNumber& b) { return b>a; }
163 inline friend bool operator<(const DifNumber& a,const double& b) { return b>a; }
164 inline friend bool operator<(const double& a,const DifNumber& b) { return b>a; }
165
166
167 inline friend bool operator>=(const DifNumber& a,const DifNumber& b) { return a.number()>=b.number(); }
168 inline friend bool operator>=(const DifNumber& a,const double& b) { return a.number()>=b; }
169 inline friend bool operator>=(const double& a,const DifNumber& b) { return a>=b.number(); }
170
171 inline friend bool operator<=(const DifNumber& a,const DifNumber& b) { return b>=a; }
172 inline friend bool operator<=(const DifNumber& a,const double& b) { return b>=a; }
173 inline friend bool operator<=(const double& a,const DifNumber& b) { return b>=a; }
174
175 inline friend bool operator==(const DifNumber& a,const DifNumber& b);
176 inline friend bool operator==(const DifNumber& a,const double & b) {return false;}
177 inline friend bool operator==(const double& a,const DifNumber& b) {return false;}
178
179 inline friend bool operator!=(const DifNumber& a,const DifNumber& b) { return !(a==b); }
180 inline friend bool operator!=(const DifNumber& a,const double& b) { return true; }
181 inline friend bool operator!=(const double& a,const DifNumber& b) { return true; }
182
183 inline friend DifNumber sin(const DifNumber& a)
184 { return DifNumber(sin(a.number()),a,cos(a.number())); }
185 inline friend DifNumber cos(const DifNumber& a)
186 { return DifNumber(cos(a.number()),a,-sin(a.number())); }
187 inline friend DifNumber tan(const DifNumber &a)
188 { double t=tan(a.number()); return DifNumber(t,a,1.0+t*t); }
189 inline friend DifNumber sec(const DifNumber &a)
190 { return DifNumber(cos(a)).inverse(); }
191 inline friend DifNumber asin(const DifNumber &a);
192 inline friend DifNumber acos(const DifNumber &a);
193 inline friend DifNumber atan(const DifNumber &a);
194
195 inline friend DifNumber atan2(const DifNumber& y,const DifNumber& x) { return DifNumber(y).arcTangent(x); }
196 inline friend DifNumber atan2(const DifNumber& y,const double& x) { return DifNumber(y).arcTangent(DifNumber(x)); }
197 inline friend DifNumber atan2(const double& y,const DifNumber& x) { return DifNumber(y).arcTangent(x); }
198
199 inline friend DifNumber exp(const DifNumber& a)
200 { double e=exp(a.number()); return DifNumber(e,a,e); }
201 inline friend DifNumber cosh(const DifNumber& a)
202 { return 0.5*(DifNumber(exp(a))+=exp(-a)); }
203 inline friend DifNumber sinh(const DifNumber& a)
204 { return 0.5*(DifNumber(exp(a))-=exp(-a)); }
205 inline friend DifNumber tanh(const DifNumber& a)
206 { double t=tanh(a.number()); return DifNumber(t,a,1.0-t*t); }
207 // inline friend DifNumber sqrt(const DifNumber& a)
208 //{ DifNumber temp(a); return temp.squareRoot(); }
209 inline friend DifNumber sqrt(const DifNumber& a)
210 { return DifNumber(a).squareRoot(); }
211 inline friend DifNumber log(const DifNumber& a)
212 { return DifNumber(log(a.number()),a,1.0/a.number()); }
213 inline friend DifNumber fabs(const DifNumber& a)
214 { return DifNumber(fabs(a.number()),a,a.sign()); }
215 inline friend DifNumber pow(const DifNumber& a,const DifNumber& b) { return DifNumber(a).power(b); }
216 inline friend DifNumber pow(const DifNumber& a,int i) { return pow(a,(double)i);}
217 inline friend DifNumber pow(const DifNumber& a,float i) { return pow(a,(double)i);}
218 inline friend DifNumber pow(const DifNumber& a,double i) {
219 return i==0?DifNumber(1.0,a,0.0)
220 :DifNumber(pow(a.number(),i),a,i*pow(a.number(),i-1)); }
221
222
223 // FIXME: this one should be inlined...
224 friend double correlation(const DifNumber& a,const DifNumber& b,const HepSymMatrix& e); // correlation for specified error
225
226 inline friend double correlation(const DifNumber& a,const DifNumber& b); // correlation from default matrix
227
228
229private:
230
231 //data
232 double _number; // value of number
233 int _npar; // number of parameters
234 const DifIndepPar* _indepPar; // pointer to independent parameters
235 double _derivatives[_nmax]; // derivatives
236
237 //functions
238 inline DifNumber& copyDerivs(const DifNumber& n); // copy derivatives from n
239 inline DifNumber& scaleDerivs(const DifNumber& n,double factor); // copy byt scale by factor
240 inline DifNumber& copyDerivs(const HepVector& v); // copy derivatives v
241 inline DifNumber& check(const DifNumber& a); // check for consistent numbers
242 inline DifNumber& setLike(const DifNumber& a); // set change to same type as |a|
243};
244
245
246//io
247//yzhang delete
248//inline std::ostream& operator<<(std::ostream& o,const DifNumber& n) { n.print(o); return o; }
249//
250DifNumber solveQuad(const DifNumber& a, const DifNumber& b, const DifNumber& c, int pref, Code& code);
251
252#include "MdcRecoUtil/DifNumber.icc"
253
254#endif
DifNumber solveQuad(const DifNumber &a, const DifNumber &b, const DifNumber &c, int pref, Code &code)
Definition: DifNumber.cxx:91
XmlRpcServer s
Definition: HelloServer.cpp:11
**********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
TTree * t
Definition: binning.cxx:23
Definition: Code.h:31
friend bool operator==(const DifNumber &a, const DifNumber &b)
void fetchDerivatives(HepVector &v) const
Definition: DifNumber.cxx:41
friend DifNumber atan2(const DifNumber &y, const double &x)
Definition: DifNumber.h:196
friend DifNumber operator*(const DifNumber &a, const double &b)
Definition: DifNumber.h:149
friend DifNumber operator+(const DifNumber &a, const double &b)
Definition: DifNumber.h:147
friend bool operator>=(const DifNumber &a, const DifNumber &b)
Definition: DifNumber.h:167
DifNumber & power(double p)
void setIndepPar(const DifIndepPar *par)
Definition: DifNumber.h:83
double number() const
Definition: DifNumber.h:87
HepVector derivatives() const
Definition: DifNumber.cxx:46
void setNumber(double i)
Definition: DifNumber.h:78
virtual ~DifNumber()
Definition: DifNumber.h:75
friend bool operator<(const DifNumber &a, const double &b)
Definition: DifNumber.h:163
void extendPar(int nnew)
double & gimeNumber()
Definition: DifNumber.h:88
friend bool operator>=(const double &a, const DifNumber &b)
Definition: DifNumber.h:169
friend bool operator==(const double &a, const DifNumber &b)
Definition: DifNumber.h:177
friend DifNumber asin(const DifNumber &a)
friend DifNumber operator-(const DifNumber &a, const double &b)
Definition: DifNumber.h:148
friend bool operator<(const DifNumber &a, const DifNumber &b)
Definition: DifNumber.h:162
friend DifNumber pow(const DifNumber &a, const DifNumber &b)
Definition: DifNumber.h:215
void print() const
Definition: DifNumber.cxx:81
DifNumber(double s, int i, int npar)
friend bool operator!=(const DifNumber &a, const double &b)
Definition: DifNumber.h:180
friend DifNumber sqrt(const DifNumber &a)
Definition: DifNumber.h:209
double error() const
Definition: DifNumber.cxx:36
int nMax()
Definition: DifNumber.h:91
DifNumber & operator=(const double &a)
friend bool operator>(const DifNumber &a, const double &b)
Definition: DifNumber.h:159
friend bool operator>(const DifNumber &a, const DifNumber &b)
Definition: DifNumber.h:158
friend DifNumber fabs(const DifNumber &a)
Definition: DifNumber.h:213
DifNumber & flipsign()
DifNumber & operator=(const DifNumber &a)
friend DifNumber operator/(const DifNumber &a, const double &b)
Definition: DifNumber.h:150
friend DifNumber operator+(const double &a, const DifNumber &b)
Definition: DifNumber.h:152
DifNumber operator-() const
Definition: DifNumber.h:109
friend DifNumber pow(const DifNumber &a, double i)
Definition: DifNumber.h:218
friend DifNumber sinh(const DifNumber &a)
Definition: DifNumber.h:203
DifNumber & operator/=(const DifNumber &a)
friend DifNumber tanh(const DifNumber &a)
Definition: DifNumber.h:205
friend bool operator>(const double &a, const DifNumber &b)
Definition: DifNumber.h:160
DifNumber(const DifNumber &s)
friend bool operator<(const double &a, const DifNumber &b)
Definition: DifNumber.h:164
friend DifNumber atan(const DifNumber &a)
friend DifNumber pow(const DifNumber &a, float i)
Definition: DifNumber.h:217
friend DifNumber operator*(const double &a, const DifNumber &b)
Definition: DifNumber.h:154
friend DifNumber tan(const DifNumber &a)
Definition: DifNumber.h:187
DifNumber & mod(double lo, double hi)
friend DifNumber exp(const DifNumber &a)
Definition: DifNumber.h:199
DifNumber(double s, const DifIndepPar *indeppar)
friend DifNumber pow(const DifNumber &a, int i)
Definition: DifNumber.h:216
friend DifNumber operator-(const double &a, const DifNumber &b)
Definition: DifNumber.h:153
double derivative(int i) const
Definition: DifNumber.h:90
friend DifNumber sin(const DifNumber &a)
Definition: DifNumber.h:183
friend DifNumber operator/(const DifNumber &a, const DifNumber &b)
Definition: DifNumber.h:145
friend DifNumber log(const DifNumber &a)
Definition: DifNumber.h:211
DifNumber(double s, int i, double di, int npar)
void fetchNumber(double &n) const
Definition: DifNumber.h:138
DifNumber & operator/=(const double &a)
void zeroDerivatives()
Definition: DifNumber.h:82
const DifIndepPar * indepPar() const
Definition: DifNumber.h:93
friend DifNumber atan2(const DifNumber &y, const DifNumber &x)
Definition: DifNumber.h:195
DifNumber(double s, int i, const DifIndepPar *indepar)
friend bool operator<=(const DifNumber &a, const double &b)
Definition: DifNumber.h:172
friend DifNumber acos(const DifNumber &a)
DifNumber & operator*=(const DifNumber &a)
friend bool operator>=(const DifNumber &a, const double &b)
Definition: DifNumber.h:168
DifNumber & operator+=(const double &a)
friend bool operator!=(const DifNumber &a, const DifNumber &b)
Definition: DifNumber.h:179
void setNPar(int i)
Definition: DifNumber.h:79
void cosAndSin(DifNumber &c, DifNumber &s) const
int nPar() const
Definition: DifNumber.h:92
friend DifNumber sec(const DifNumber &a)
Definition: DifNumber.h:189
DifNumber & operator-=(const double &a)
DifNumber & operator-=(const DifNumber &a)
friend bool operator<=(const DifNumber &a, const DifNumber &b)
Definition: DifNumber.h:171
DifNumber & squareRoot()
friend DifNumber cosh(const DifNumber &a)
Definition: DifNumber.h:201
DifNumber & operator*=(const double &a)
void sumMatrix(HepMatrix &m) const
void setDerivative(int i, double value)
Definition: DifNumber.h:81
DifNumber & operator+=(const DifNumber &a)
friend double correlation(const DifNumber &a, const DifNumber &b, const HepSymMatrix &e)
Definition: DifNumber.cxx:78
double sign() const
Definition: DifNumber.h:130
friend DifNumber operator+(const DifNumber &a, const DifNumber &b)
Definition: DifNumber.h:142
friend DifNumber operator-(const DifNumber &a, const DifNumber &b)
Definition: DifNumber.h:143
friend DifNumber cos(const DifNumber &a)
Definition: DifNumber.h:185
DifNumber & absolute()
Definition: DifNumber.h:122
void setDerivatives(const HepVector &d)
Definition: DifNumber.h:80
friend DifNumber operator*(const DifNumber &a, const DifNumber &b)
Definition: DifNumber.h:144
DifNumber & inverse()
friend bool operator!=(const double &a, const DifNumber &b)
Definition: DifNumber.h:181
DifNumber & arcTangent(const DifNumber &x)
friend DifNumber operator/(const double &a, const DifNumber &b)
Definition: DifNumber.h:155
friend DifNumber atan2(const double &y, const DifNumber &x)
Definition: DifNumber.h:197
DifNumber & power(const DifNumber &p)
void tickle() const
Definition: DifNumber.h:96
friend bool operator==(const DifNumber &a, const double &b)
Definition: DifNumber.h:176
friend bool operator<=(const double &a, const DifNumber &b)
Definition: DifNumber.h:173
double y[1000]
double x[1000]
const double b
Definition: slope.cxx:9