CGEM BOSS 6.6.5.g
BESIII Offline Software System
Loading...
Searching...
No Matches
DifNumber.cxx
Go to the documentation of this file.
1//--------------------------------------------------------------------------
2// File and Version Information:
3// $Id: DifNumber.cxx,v 1.3 2010/03/25 09:55:57 zhangy Exp $
4//
5// Description:
6// Class Implementation for |DifNumber|
7// What do i do ?
8// Environment:
9// Software developed for the BaBar Detector at the SLAC B-Factory.
10//
11// Author List:
12// A. Snyder
13//
14// Copyright Information:
15// Copyright (C) 1996 SLAC
16//
17// History:
18// Migration for BESIII MDC
19//
20//------------------------------------------------------------------------
21
24using std::endl;
25//CHANGE using std::ostream;
26using std::cout;
27
28extern const DifNumber zero(0.0);
29extern const DifNumber one(1.0);
30
31
32double DifNumber::error(const HepSymMatrix& e)const {
33 return sqrt(correlation(*this,e));
34}
35
36double DifNumber::error()const{
37 if(indepPar()==0) {return 0.0;}
38 return error(indepPar()->covariance());
39}
40
41void DifNumber::fetchDerivatives(HepVector& v)const {
42 assert(v.num_row()==nPar());
43 for(int i=1; i<=nPar(); i++) {v(i)=derivative(i);}
44}
45
46HepVector DifNumber::derivatives()const{
47 HepVector temp(nPar());
48 fetchDerivatives(temp);
49 return temp;
50}
51
52double
53DifNumber::correlation(const DifNumber& b,const HepSymMatrix &e) const {
54 assert(e.num_col()==nPar());
55 assert(e.num_row()==b.nPar());
56 double error = 0.;
57 for(int i=1; i<=nPar(); i++) {
58 for(int j=1; j<=b.nPar(); j++) {
59 error+=derivative(i)*e(i,j)*b.derivative(j);
60 }
61 }
62 return error;
63}
64
65double
67 if(indepPar()==0) return 0.0;
68 if(b.indepPar()!=indepPar()) return 0.0;
69 return correlation(b,indepPar()->covariance());
70}
71
72double correlation(const DifNumber& a,const DifNumber& b) // correlation from default matrix
73{
74 return (a.indepPar()==0||b.indepPar()==0||a.indepPar()!=b.indepPar())?0:a.correlation(b,a.indepPar()->covariance());
75}
76
77// FIXME: This function should be inlined, but that would require checking out additional packages...
78double correlation(const DifNumber& a,const DifNumber& b,const HepSymMatrix& e) // correlation for specified error
79{ return a.correlation(b,e); }
80
81void DifNumber::print(/*ostream& o*/)const {
82 cout << "number:" << number() << endl;
83 cout << "npar:" << nPar() << endl;
84 for(int i=1; i<=nPar(); i++) {
85 cout << "derivative(" << i << "):" << derivative(i) << endl;
86 }
87}
88
89
91(const DifNumber& a, // quadratic term
92 const DifNumber& b, // linear term
93 const DifNumber& c, // const term
94 int pref, // solution preference
95 Code& code) // error code
96{
97 DifNumber descr=b*b-4.0*a*c;
98 if(descr<0.0) { // solution not real
99 code.setFail(1341);
100 return DifNumber(0.0);
101 }
102 if(a.number()==0.0){
103 if(b.number()==0.0) {
104 code.setFail(1342);
105 return DifNumber(0.0);
106 }
107 code.setSuccess(40);
108 return -c/b+a*c/pow(b,3);
109 }
110 code.setSuccess(40);
111 descr=sqrt(descr);
112 DifNumber s=-b;
113
114 if(pref==+1) { // positive solution
115 s+=descr;
116 }else if(pref==-1){ // negative solution
117 s-=descr;
118 }else if(pref==0) { // smallest solution
119 if(s>0.0) {s-=descr;}else {s+=descr;}
120 }else { // illegal prefrence
121 code.setFail(1343);
122 return DifNumber(0.0);
123 }
124 s/=2.0*a;
125 return s;
126}
127
const DifNumber zero(0.0)
const DifNumber one(1.0)
double correlation(const DifNumber &a, const DifNumber &b)
Definition: DifNumber.cxx:72
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
Definition: Code.h:31
void setFail(int i)
Definition: Code.h:55
void setSuccess(int i)
Definition: Code.h:57
HepSymMatrix & covariance()
Definition: DifIndepPar.h:53
void fetchDerivatives(HepVector &v) const
Definition: DifNumber.cxx:41
double number() const
Definition: DifNumber.h:87
HepVector derivatives() const
Definition: DifNumber.cxx:46
double correlation(const DifNumber &b, const HepSymMatrix &e) const
Definition: DifNumber.cxx:53
void print() const
Definition: DifNumber.cxx:81
friend DifNumber sqrt(const DifNumber &a)
Definition: DifNumber.h:209
double error() const
Definition: DifNumber.cxx:36
double derivative(int i) const
Definition: DifNumber.h:90
const DifIndepPar * indepPar() const
Definition: DifNumber.h:93
int nPar() const
Definition: DifNumber.h:92
friend double correlation(const DifNumber &a, const DifNumber &b, const HepSymMatrix &e)
Definition: DifNumber.cxx:78