00001
00002
00003 #include <math.h>
00004
00005
00006 #include "Event/State.h"
00007 #include "Event/StateKeys.h"
00008
00009 #include "CLHEP/Matrix/Matrix.h"
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 State::State() {
00021 setType( StateKeys::HasMomentum );
00022 setLocation( StateKeys::LocationUnknown );
00023 m_z = 0.;
00024 m_state = HepVector(5,0);
00025 m_covariance = HepSymMatrix(5,0);
00026 }
00027
00028
00029
00030
00031 double State::qOverP() const
00032 {
00033 return m_state[4];
00034 };
00035
00036
00037
00038
00039 double State::p() const
00040 {
00041 if ( m_state[4] != 0. ) return fabs( 1./m_state[4] );
00042 return HUGE_VAL;
00043 };
00044
00045
00046
00047
00048 double State::pt() const
00049 {
00050 if ( m_state[4] != 0. ) {
00051 double txy2 = m_state[2]*m_state[2] + m_state[3]*m_state[3];
00052 return sqrt( txy2/(1.+txy2) ) / fabs( m_state[4] );
00053 }
00054 return HUGE_VAL;
00055 };
00056
00057
00058
00059
00060 HepSymMatrix State::posMomCovariance() const
00061 {
00062
00063
00064 const HepSymMatrix cov5D = covariance();
00065 HepSymMatrix cov6Dtmp = HepSymMatrix(6,0);
00066
00067 std::vector<int> index;
00068 index.push_back( 1 );
00069 index.push_back( 3 );
00070 index.push_back( 4 );
00071 index.push_back( 5 );
00072
00073 for ( int jj=0 ; jj<5 ; jj++ ) {
00074 for ( int i=jj ; i<5 ; i++ ) {
00075 cov6Dtmp.fast(index[i]+1,index[jj]+1) = cov5D.fast(i+1,jj+1);
00076 }
00077 }
00078 cov6Dtmp.fast(3,1) = 0.;
00079 cov6Dtmp.fast(3,2) = 0.;
00080 cov6Dtmp.fast(3,3) = 0.;
00081 cov6Dtmp.fast(4,3) = 0.;
00082 cov6Dtmp.fast(5,3) = 0.;
00083 cov6Dtmp.fast(6,3) = 0.;
00084
00085
00086
00087
00088
00089
00090
00091
00092 double Tx = tx();
00093 double Ty = ty();
00094 double QOverP = qOverP();
00095 double Q = ( QOverP != 0. ? (fabs(QOverP)/QOverP) : 0. );
00096 double Tx2 = Tx * Tx;
00097 double Ty2 = Ty * Ty;
00098 double Qp = Q * p();
00099 double N = 1. / sqrt( 1 + Tx2 + Ty2 );
00100 double N2 = N*N;
00101
00102 HepSymMatrix cov6D = HepSymMatrix(6,0);
00103 HepSymMatrix C_A = cov6Dtmp.sub(1,3);
00104 HepSymMatrix C_D = cov6Dtmp.sub(4,6);
00105 HepMatrix C_B = HepMatrix(3,3,0);
00106 HepMatrix jmat = HepMatrix(3,3,0);
00107
00108 jmat[0][0] = ( 1 + Ty2 ) * N2;
00109 jmat[0][1] = - Tx * Ty * N2;
00110 jmat[0][2] = - Qp * Tx;
00111 jmat[1][0] = - Tx * Ty * N2;
00112 jmat[1][1] = ( 1 + Tx2 ) * N2;
00113 jmat[1][2] = - Qp * Ty;
00114 jmat[2][0] = - Tx * N2;
00115 jmat[2][1] = - Ty * N2;
00116 jmat[2][2] = - Qp;
00117
00118 C_B(1,1) = cov6Dtmp.fast(4,1);
00119 C_B(2,1) = cov6Dtmp.fast(5,1);
00120 C_B(2,2) = cov6Dtmp.fast(5,2);
00121 C_B(3,1) = cov6Dtmp.fast(6,1);
00122 C_B(3,2) = cov6Dtmp.fast(6,2);
00123 C_B(3,3) = cov6Dtmp.fast(6,3);
00124
00125 C_B = jmat * C_B;
00126
00127 cov6D.sub(1,C_A);
00128 cov6D.sub(4,C_D.similarity(jmat));
00129 cov6D.fast(4,1) = C_B(1,1);
00130 cov6D.fast(5,1) = C_B(2,1);
00131 cov6D.fast(6,1) = C_B(3,1);
00132 cov6D.fast(4,2) = C_B(1,2);
00133 cov6D.fast(5,2) = C_B(2,2);
00134 cov6D.fast(6,2) = C_B(3,2);
00135 cov6D.fast(4,3) = C_B(1,3);
00136 cov6D.fast(5,3) = C_B(2,3);
00137 cov6D.fast(6,3) = C_B(3,3);
00138
00139 return cov6D;
00140 };
00141
00142
00143
00144
00145 double State::errQOverP2() const
00146 {
00147 return m_covariance.fast(5,5);
00148 };
00149
00150
00151
00152
00153 double State::errP2() const
00154 {
00155 if ( m_state[4] != 0. ) return errQOverP2() / pow( m_state[4], 4. );
00156 return 0.;
00157 };
00158
00159
00160
00161
00162 HepSymMatrix State::errMomentum() const
00163 {
00164 if ( checkType( StateKeys::HasMomentum ) ) {
00165 const HepSymMatrix temp = posMomCovariance();
00166 return temp.sub(4,6);
00167 }
00168 else {
00169 return HepSymMatrix(3,0);
00170 }
00171 };
00172
00173
00174
00175
00176 double State::errQOverPperp2() const
00177 {
00178 double tx2 = tx() * tx();
00179 double ty2 = ty() * ty();
00180 double qOverP2 = qOverP() * qOverP();
00181 double transSlope = 1. + tx2;
00182 double norm = 1 + tx2 + ty2;
00183
00184 double QOverPperpError = ( (norm/transSlope) * m_covariance[4][4] )
00185
00186 + ( qOverP2 * tx2 * ty2*ty2 * m_covariance[2][2]/
00187 (pow(transSlope,3.)*norm))
00188
00189 + ( qOverP2 * ty2 * m_covariance[3][3] / (norm*transSlope) )
00190
00191 - ( 2. * qOverP() * tx() * ty2 * m_covariance[2][4]
00192 / ( transSlope*transSlope ) )
00193
00194 + 2. * qOverP() * ty() * m_covariance[3][4] / transSlope
00195
00196 - 2. * ( qOverP2 * tx() * ty() * ty2 * m_covariance[2][3]
00197 / ( norm* transSlope*transSlope ) );
00198
00199 return QOverPperpError;
00200 };
00201
00202
00203
00204
00205 State* State::clone() const
00206 {
00207 return new State(*this);
00208 };
00209
00210
00211
00212
00213 void State::reset()
00214 {
00215 m_z = 0.;
00216 m_state = HepVector(5,0);
00217 m_covariance = HepSymMatrix(5,0);
00218 };
00219
00220
00221
00222
00223 void State::setState( double x, double y, double z,
00224 double tx, double ty,
00225 double qOverP )
00226 {
00227 m_state[0] = x;
00228 m_state[1] = y;
00229 m_state[2] = tx;
00230 m_state[3] = ty;
00231 m_z = z;
00232 if ( checkType( StateKeys::StraightLine ) ) {
00233 std::cerr
00234 << "ERROR You're trying to set the Q/P value for a state of type State::StraightLine!"
00235 << "ERROR This value will be discarded." << std::endl;
00236 }
00237 else {
00238 m_state[4] = qOverP;
00239 }
00240 };
00241
00242
00243
00244
00245 void State::setQOverP( double value )
00246 {
00247 m_state[4] = value;
00248 };
00249
00250