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

Generated on Thu Apr 7 22:43:27 2005 for New Track Event Model by doxygen 1.4.1