BOSS 8.0.0
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
22#include "MdcRecoUtil/DifNumber.h"
23#include "MdcRecoUtil/DifIndepPar.h"
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
31double DifNumber::error( const HepSymMatrix& e ) const {
32 return sqrt( correlation( *this, e ) );
33}
34
35double DifNumber::error() const {
36 if ( indepPar() == 0 ) { return 0.0; }
37 return error( indepPar()->covariance() );
38}
39
40void DifNumber::fetchDerivatives( HepVector& v ) const {
41 assert( v.num_row() == nPar() );
42 for ( int i = 1; i <= nPar(); i++ ) { v( i ) = derivative( i ); }
43}
44
45HepVector DifNumber::derivatives() const {
46 HepVector temp( nPar() );
47 fetchDerivatives( temp );
48 return temp;
49}
50
51double DifNumber::correlation( const DifNumber& b, const HepSymMatrix& e ) const {
52 assert( e.num_col() == nPar() );
53 assert( e.num_row() == b.nPar() );
54 double error = 0.;
55 for ( int i = 1; i <= nPar(); i++ )
56 {
57 for ( int j = 1; j <= b.nPar(); j++ )
58 { error += derivative( i ) * e( i, j ) * b.derivative( j ); }
59 }
60 return error;
61}
62
63double DifNumber::correlation( const DifNumber& b ) const {
64 if ( indepPar() == 0 ) return 0.0;
65 if ( b.indepPar() != indepPar() ) return 0.0;
66 return correlation( b, indepPar()->covariance() );
67}
68
69double correlation( const DifNumber& a, const DifNumber& b ) // correlation from default matrix
70{
71 return ( a.indepPar() == 0 || b.indepPar() == 0 || a.indepPar() != b.indepPar() )
72 ? 0
73 : a.correlation( b, a.indepPar()->covariance() );
74}
75
76// FIXME: This function should be inlined, but that would require checking out additional
77// packages...
78double correlation( const DifNumber& a, const DifNumber& b,
79 const HepSymMatrix& e ) // correlation for specified error
80{
81 return a.correlation( b, e );
82}
83
84void DifNumber::print( /*ostream& o*/ ) const {
85 cout << "number:" << number() << endl;
86 cout << "npar:" << nPar() << endl;
87 for ( int i = 1; i <= nPar(); i++ )
88 { cout << "derivative(" << i << "):" << derivative( i ) << endl; }
89}
90
91extern DifNumber solveQuad( 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 )
99 { // solution not real
100 code.setFail( 1341 );
101 return DifNumber( 0.0 );
102 }
103 if ( a.number() == 0.0 )
104 {
105 if ( b.number() == 0.0 )
106 {
107 code.setFail( 1342 );
108 return DifNumber( 0.0 );
109 }
110 code.setSuccess( 40 );
111 return -c / b + a * c / pow( b, 3 );
112 }
113 code.setSuccess( 40 );
114 descr = sqrt( descr );
115 DifNumber s = -b;
116
117 if ( pref == +1 )
118 { // positive solution
119 s += descr;
120 }
121 else if ( pref == -1 )
122 { // negative solution
123 s -= descr;
124 }
125 else if ( pref == 0 )
126 { // smallest solution
127 if ( s > 0.0 ) { s -= descr; }
128 else { s += descr; }
129 }
130 else
131 { // illegal prefrence
132 code.setFail( 1343 );
133 return DifNumber( 0.0 );
134 }
135 s /= 2.0 * a;
136 return s;
137}
const DifNumber zero(0.0)
const DifNumber one(1.0)
double correlation(const DifNumber &a, const DifNumber &b)
Definition DifNumber.cxx:69
DifNumber solveQuad(const DifNumber &a, const DifNumber &b, const DifNumber &c, int pref, Code &code)
Definition DifNumber.cxx:91
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
void fetchDerivatives(HepVector &v) const
Definition DifNumber.cxx:40
HepVector derivatives() const
Definition DifNumber.cxx:45
double correlation(const DifNumber &b, const HepSymMatrix &e) const
Definition DifNumber.cxx:51
void print() const
Definition DifNumber.cxx:84
double error() const
Definition DifNumber.cxx:35
double error(const HepSymMatrix &e) const
Definition DifNumber.cxx:31