Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members

State.cpp

Go to the documentation of this file.
00001 // $Id: State.cpp,v 1.6 2005/05/25 10:08:20 hernando Exp $
00002 
00003 #include <math.h>
00004 #include <gsl/gsl_math.h>
00005 
00006 // local
00007 #include "Event/State.h"
00008 #include "Event/StateKeys.h"
00009 
00010 #include "CLHEP/Matrix/Matrix.h"
00011 
00012 //-----------------------------------------------------------------------------
00013 // Implementation file for class : State
00014 //
00015 // 2004-12-14 : Jose Hernando, Eduardo Rodrigues
00016 //-----------------------------------------------------------------------------
00017 
00018 //=============================================================================
00019 // Default constructor
00020 //=============================================================================
00021 State::State() {
00022   setLocation( StateKeys::LocationUnknown );
00023   m_z           = 0.;
00024   m_stateVector = HepVector(5,0);
00025   m_covariance  = HepSymMatrix(5,0);
00026 }
00027 
00028 //=============================================================================
00029 // Retrieve the charge-over-momentum Q/P of the state
00030 //=============================================================================
00031 double State::qOverP() const
00032 {
00033   return m_stateVector[4];
00034 };
00035 
00036 //=============================================================================
00037 // Retrieve the momentum of the state
00038 //=============================================================================
00039 double State::p() const
00040 {
00041   if ( m_stateVector[4] != 0. ) return fabs( 1./m_stateVector[4] );
00042   return HUGE_VAL;
00043 };
00044 
00045 //=============================================================================
00046 // Retrieve the transverse momentum of the state
00047 //=============================================================================
00048 double State::pt() const
00049 {
00050   if ( m_stateVector[4] != 0. ) {
00051     double txy2 =   m_stateVector[2]*m_stateVector[2]
00052                   + m_stateVector[3]*m_stateVector[3];
00053     return sqrt( txy2/(1.+txy2) ) / fabs( m_stateVector[4] );
00054   }
00055   return HUGE_VAL;
00056 };
00057 
00058 //=============================================================================
00059 // Retrieve the 6D covariance matrix (x,y,z,px,py,pz) of the state
00060 //=============================================================================
00061 HepSymMatrix State::posMomCovariance() const
00062 {
00063   // Transformation done in 2 steps:
00064   // 1) "convert" first from (x,y,tx,ty,Q/p) to (x,y,z,tx,ty,Q/p)
00065   const HepSymMatrix cov5D = covariance();
00066   HepSymMatrix cov6Dtmp    = HepSymMatrix(6,0);
00067 
00068   std::vector<int> index;
00069   index.push_back( 1 );
00070   index.push_back( 3 );
00071   index.push_back( 4 );
00072   index.push_back( 5 );
00073 
00074   for ( int jj=0 ; jj<5 ; jj++ ) {
00075     for ( int i=jj ; i<5 ; i++ ) {
00076       cov6Dtmp.fast(index[i]+1,index[jj]+1) = cov5D.fast(i+1,jj+1);
00077     }
00078   }
00079   cov6Dtmp.fast(3,1) = 0.;
00080   cov6Dtmp.fast(3,2) = 0.;
00081   cov6Dtmp.fast(3,3) = 0.;
00082   cov6Dtmp.fast(4,3) = 0.;
00083   cov6Dtmp.fast(5,3) = 0.;
00084   cov6Dtmp.fast(6,3) = 0.;
00085 
00086   // 2) transformation from (x,y,z,tx,ty,Q/p) to (x,y,z,px,py,pz)
00087   // jacobian J = I 0
00088   //              0 j
00089   //  -> covariance matrix C = C_A  C_B.T()
00090   //                           C_B  C_D
00091   //     becomes C' = C_A   (j.C_B).T()  after similarity transformation
00092   //                  j.C_B j.C_D.(j.T())
00093   double Tx     = tx();
00094   double Ty     = ty();
00095   double QOverP = qOverP();
00096   double Q   = ( QOverP != 0. ? (fabs(QOverP)/QOverP) : 0. );
00097   double Tx2 = Tx * Tx;
00098   double Ty2 = Ty * Ty;
00099   double Qp  = Q * p();
00100   double N   = 1. / sqrt( 1 + Tx2 + Ty2 );
00101   double N2  = N*N;
00102 
00103   HepSymMatrix cov6D = HepSymMatrix(6,0);
00104   HepSymMatrix C_A = cov6Dtmp.sub(1,3);
00105   HepSymMatrix C_D = cov6Dtmp.sub(4,6);
00106   HepMatrix    C_B = HepMatrix(3,3,0);
00107   HepMatrix    jmat   = HepMatrix(3,3,0);
00108 
00109   jmat[0][0] = ( 1 + Ty2 ) * N2;
00110   jmat[0][1] = - Tx * Ty * N2;
00111   jmat[0][2] = - Qp * Tx;
00112   jmat[1][0] = - Tx * Ty * N2;
00113   jmat[1][1] = ( 1 + Tx2 ) * N2;
00114   jmat[1][2] = - Qp * Ty;
00115   jmat[2][0] = - Tx * N2;
00116   jmat[2][1] = - Ty * N2;
00117   jmat[2][2] = - Qp;
00118 
00119   C_B(1,1) = cov6Dtmp.fast(4,1);
00120   C_B(2,1) = cov6Dtmp.fast(5,1);
00121   C_B(2,2) = cov6Dtmp.fast(5,2);
00122   C_B(3,1) = cov6Dtmp.fast(6,1);
00123   C_B(3,2) = cov6Dtmp.fast(6,2);
00124   C_B(3,3) = cov6Dtmp.fast(6,3);
00125 
00126   C_B = jmat * C_B;
00127 
00128   cov6D.sub(1,C_A);
00129   cov6D.sub(4,C_D.similarity(jmat));
00130   cov6D.fast(4,1) = C_B(1,1);
00131   cov6D.fast(5,1) = C_B(2,1);
00132   cov6D.fast(6,1) = C_B(3,1);
00133   cov6D.fast(4,2) = C_B(1,2);
00134   cov6D.fast(5,2) = C_B(2,2);
00135   cov6D.fast(6,2) = C_B(3,2);
00136   cov6D.fast(4,3) = C_B(1,3);
00137   cov6D.fast(5,3) = C_B(2,3);
00138   cov6D.fast(6,3) = C_B(3,3);
00139 
00140   return cov6D;
00141 };
00142 
00143 //=============================================================================
00144 // Retrieve the squared error on the charge-over-momentum Q/P of the state
00145 //=============================================================================
00146 double State::errQOverP2() const
00147 {
00148   return m_covariance.fast(5,5);
00149 };
00150 
00151 //=============================================================================
00152 // Retrieve the squared error on the momentum of the state
00153 //=============================================================================
00154 double State::errP2() const
00155 {
00156   if ( m_stateVector[4] != 0. )
00157     return errQOverP2() / gsl_pow_4( m_stateVector[4] );
00158   return 0.;
00159 };
00160 
00161 //=============================================================================
00162 // Retrieve the errors on the momentum vector of the state
00163 //=============================================================================
00164 HepSymMatrix State::errMomentum() const
00165 {
00166 //  if ( m_stateVector[4] != 0. ) {
00167     const HepSymMatrix temp = posMomCovariance(); // CLHEP 1.9, must be const
00168     return temp.sub(4,6);
00169 //  }
00170 //  else {
00171 //    return HepSymMatrix(3,0);
00172 //  }
00173 };
00174 
00175 //=============================================================================
00176 // Retrieve the squared error on the Q/Pperp of the state
00177 //=============================================================================
00178 double State::errQOverPperp2() const
00179 {
00180   double tx2        = tx() * tx();
00181   double ty2        = ty() * ty();
00182   double qOverP2    = qOverP() * qOverP();
00183   double transSlope = 1. + tx2;
00184   double norm       = 1 + tx2 + ty2;
00185 
00186   double QOverPperpError = ( (norm/transSlope) * m_covariance[4][4] )
00187 
00188     + ( qOverP2 * tx2 * ty2*ty2 * m_covariance[2][2]/
00189        (gsl_pow_3(transSlope)*norm))
00190 
00191     + ( qOverP2 * ty2 * m_covariance[3][3] / (norm*transSlope) )
00192 
00193     - ( 2. * qOverP() * tx() * ty2 * m_covariance[2][4]
00194         / ( transSlope*transSlope ) )
00195 
00196     + 2. * qOverP() * ty() * m_covariance[3][4] / transSlope
00197 
00198     - 2. * ( qOverP2 * tx() * ty() * ty2 * m_covariance[2][3]
00199          / ( norm* transSlope*transSlope ) );
00200 
00201   return QOverPperpError;
00202 };
00203 
00204 //=============================================================================
00205 // Clone the state
00206 //=============================================================================
00207 State* State::clone() const
00208 {
00209   State* state = new State(*this);
00210   state->setLocation( StateKeys::LocationUnknown );
00211   return state;
00212 };
00213 
00214 //=============================================================================
00215 // Update the state vector (presumably of type State::HasMomentum)
00216 //=============================================================================
00217 void State::setState( double x, double y, double z,
00218                         double tx, double ty,
00219                         double qOverP )
00220 {
00221   m_stateVector[0] = x;
00222   m_stateVector[1] = y;
00223   m_stateVector[2] = tx;
00224   m_stateVector[3] = ty;
00225   m_stateVector[4] = qOverP;
00226   m_z              = z;
00227 };
00228 
00229 //=============================================================================
00230 // Update the Q/P value of the state
00231 //=============================================================================
00232 void State::setQOverP( double value )
00233 {
00234   m_stateVector[4] = value;
00235 };
00236 
00237 //=============================================================================

Generated on Fri May 27 13:59:37 2005 for New Track Event Model by doxygen 1.4.1