Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

TrState.cpp

Go to the documentation of this file.
00001 // $Id: $
00002 // Include files 
00003 
00004 // local
00005 #include "Event/TrState.h"
00006 
00007 //-----------------------------------------------------------------------------
00008 // Implementation file for class : TrState
00009 //
00010 // 2004-10-04 : Eduardo Rodrigues
00011 //-----------------------------------------------------------------------------
00012 
00013 //=============================================================================
00014 // Default constructor. State defined to be of type TrState::HasMomentum
00015 //=============================================================================
00016 TrState::TrState() {
00017   setType( TrState::HasMomentum );
00018   m_z          = 0.;
00019   m_state      = HepVector(5,0);
00020   m_covariance = HepSymMatrix(5,0);
00021 }
00022 
00023 /*
00024 //=============================================================================
00025 // Constructor with specification of the state type
00026 //=============================================================================
00027 TrState::TrState( unsigned type ):
00028   KeyedObject<int>()
00029 {
00030   setType( type );
00031   m_z          = 0.;
00032   m_state      = HepVector(5,0);
00033   m_covariance = HepSymMatrix(5,0);
00034 }
00035 
00036 //=============================================================================
00037 // Copy constructor
00038 //=============================================================================
00039 TrState::TrState( const TrState &state ):
00040   KeyedObject<int>()
00041 {
00042   m_flags      = state.flags();
00043   m_z          = state.z();
00044   m_state      = state.state();
00045   m_covariance = state.covariance();
00046 }
00047 */
00048 
00049 //=============================================================================
00050 // Retrieve the charge-over-momentum Q/P of the state
00051 //=============================================================================
00052 double TrState::qOverP() const
00053 {
00054   return m_state[4];
00055 };
00056 
00057 //=============================================================================
00058 // Retrieve the momentum of the state
00059 //=============================================================================
00060 double TrState::p() const
00061 {
00062   if ( m_state[4] != 0. ) return fabs( 1./m_state[4] );
00063   return 0.;
00064 };
00065 
00066 //=============================================================================
00067 // Retrieve the transverse momentum of the state
00068 //=============================================================================
00069 double TrState::pt() const
00070 {
00071   if ( m_state[4] != 0. ) {
00072     double txy2 = m_state[2]*m_state[2] + m_state[3]*m_state[3];
00073     return sqrt( txy2/(1.+txy2) ) / fabs( m_state[4] );
00074   }
00075   return 0.;
00076 };
00077 
00078 
00079 //=============================================================================
00080 // Retrieve the 6D covariance matrix (x,y,z,px,py,pz) of the state
00081 //=============================================================================
00082 HepSymMatrix TrState::posMomCovariance() const
00083 {
00084   HepSymMatrix cov = covariance();
00085   // to be written ...
00086 
00087   return cov;  
00088 };
00089 
00090 //=============================================================================
00091 // Retrieve the squared error on the charge-over-momentum Q/P of the state
00092 //=============================================================================
00093 double TrState::errQOverP2() const
00094 {
00095   return m_covariance.fast(5,5);
00096 };
00097 
00098 //=============================================================================
00099 // Retrieve the squared error on the momentum of the state
00100 //=============================================================================
00101 double TrState::errP2() const
00102 {
00103   if ( m_state[4] != 0. ) return errQOverP2() / pow( m_state[4], 4. );
00104   return 0.;
00105 };
00106 
00107 //=============================================================================
00108 // Retrieve the errors on the momentum vector of the state
00109 //=============================================================================
00110 HepSymMatrix TrState::errMomentum() const
00111 {
00112   if ( isFlagSet(TypeHasMomentumBits,TypeHasMomentumMask) ) {
00113     return posMomCovariance().sub(4,6);
00114   }
00115   else {
00116     //print out an error message ...
00117     return HepSymMatrix(3,0);
00118   }
00119 };
00120 
00121 //=============================================================================
00122 // Retrieve the squared error on the Q/Pperp of the state
00123 //=============================================================================
00124 double TrState::errQOverPperp2() const
00125 {
00126   double tx2        = tx() * tx();
00127   double ty2        = ty() * ty();
00128   double qOverP2    = qOverP() * qOverP();
00129   double transSlope = 1. + tx2;
00130   double norm       = 1 + tx2 + ty2;
00131 
00132   double QOverPperpError = ( (norm/transSlope) * m_covariance[4][4] )
00133 
00134     + ( qOverP2 * tx2 * ty2*ty2 * m_covariance[2][2]/
00135        (pow(transSlope,3.)*norm))
00136 
00137     + ( qOverP2 * ty2 * m_covariance[3][3] / (norm*transSlope) )
00138 
00139     - ( 2. * qOverP() * tx() * ty2 * m_covariance[2][4]
00140         / ( transSlope*transSlope ) )
00141 
00142     + 2. * qOverP() * ty() * m_covariance[3][4] / transSlope
00143 
00144     - 2. * ( qOverP2 * tx() * ty() * ty2 * m_covariance[2][3]
00145          / ( norm* transSlope*transSlope ) );
00146 
00147   return QOverPperpError;
00148 };
00149 
00150 //=============================================================================
00151 // Clone the state
00152 //=============================================================================
00153 TrState* TrState::clone() const
00154 {
00155   return new TrState(*this);
00156 };
00157 
00158 //=============================================================================
00159 // Clear the state before re-using it
00160 //=============================================================================
00161 void TrState::reset()
00162 {
00163   m_z          = 0.;
00164   m_state      = HepVector(5,0);
00165   m_covariance = HepSymMatrix(5,0);
00166 };
00167 
00168 //=============================================================================
00169 // Check State type
00170 //=============================================================================
00171 bool TrState::type( unsigned value ) const
00172 {
00173   if      ( value == TrState::HasMomentum)
00174     return isFlagSet( TypeHasMomentumBits, TypeHasMomentumMask );
00175   else if ( value == TrState::StraightLine)
00176     return isFlagSet( TypeStraightLineBits, TypeStraightLineMask );
00177 
00178   return false;
00179 };
00180 
00181 //=============================================================================
00182 // Retrieve the location of the state
00183 //=============================================================================
00184 bool TrState::location( unsigned value ) const
00185 {
00186   if      ( value == TrState::MostUpstream )
00187     return isFlagSet( LocationMostUpstreamMask, LocationMostUpstreamBits);
00188   else if ( value == TrState::FirstMeasurement )
00189     return isFlagSet( LocationFirstMeasurementMask, LocationFirstMeasurementBits);
00190   else if ( value == TrState::AtTT )
00191     return isFlagSet( LocationAtTTMask, LocationAtTTBits);
00192   else if ( value == TrState::AtT )
00193     return isFlagSet( LocationAtTMask, LocationAtTBits);
00194   else if ( value == TrState::BegRich1 )
00195     return isFlagSet( LocationBegRich1Mask, LocationBegRich1Bits);
00196   else if ( value == TrState::EndRich1 )
00197     return isFlagSet( LocationEndRich1Mask, LocationEndRich1Bits);
00198   else if ( value == TrState::BegRich2 )
00199     return isFlagSet( LocationBegRich2Mask, LocationBegRich2Bits);
00200   else if ( value == TrState::EndRich2 )
00201     return isFlagSet( LocationEndRich2Mask, LocationEndRich2Bits);
00202   else if ( value == TrState::Calo )
00203     return isFlagSet( LocationCaloMask, LocationCaloBits);
00204   else if ( value == TrState::Muon )
00205     return isFlagSet( LocationMuonMask, LocationMuonBits);
00206 
00207   return false;  
00208 };
00209 
00210 //=============================================================================
00211 // 
00212 //=============================================================================
00213 bool TrState::isFlagSet( unsigned bits, unsigned mask )
00214 {
00215   return (bool)((m_flags & mask) >> bits);
00216 };
00217 
00218 //=============================================================================
00219 // Update the state vector (presumably of type TrState::HasMomentum)
00220 //=============================================================================
00221 void TrState::setState( double x, double y, double z,
00222                         double tx, double ty,
00223                         double qOverP )
00224 {
00225   m_state[0] = x;
00226   m_state[1] = y;
00227   m_state[2] = tx;
00228   m_state[3] = ty;
00229   m_z        = z;
00230   if ( isFlagSet(TypeStraightLineBits,TypeStraightLineMask) ) {
00231     std::cerr
00232       << "ERROR   You're trying to set the Q/P value for a state of type TrState::StraightLine!"
00233       << "ERROR   This value will be discarded." << std::endl;
00234   }
00235   else {
00236      m_state[4] = qOverP;
00237   }
00238 };
00239 
00240 //=============================================================================
00241 // Update the Q/P value of the state
00242 //=============================================================================
00243 void TrState::setQOverP( double value )
00244 {
00245   m_state[4] = value;
00246 };
00247 
00248 //=============================================================================
00249 // Update State type
00250 //=============================================================================
00251 void TrState::setType( unsigned value )
00252 {
00253   if      ( value == TrState::HasMomentum )
00254     setFlag( true, TypeHasMomentumBits, TypeHasMomentumMask );
00255   else if ( value == TrState::StraightLine)
00256     setFlag( true, TypeStraightLineBits, TypeStraightLineMask );
00257 };
00258 
00259 //=============================================================================
00260 // Update the location of the state
00261 //=============================================================================
00262 void TrState::setLocation( unsigned value )
00263 {
00264   switch ( value )
00265   {
00266     case TrState::MostUpstream :
00267       setFlag( true, LocationMostUpstreamBits, LocationMostUpstreamMask );
00268       break;
00269     case TrState::FirstMeasurement :
00270       setFlag( true,  LocationFirstMeasurementBits, LocationFirstMeasurementMask );
00271       break;
00272     case TrState::AtTT :
00273       setFlag( true, LocationAtTTBits, LocationAtTTMask );
00274       break;
00275     case TrState::AtT :
00276       setFlag( true, LocationAtTBits, LocationAtTMask );
00277       break;
00278     case TrState::BegRich1 :
00279       setFlag( true, LocationBegRich1Bits, LocationBegRich1Mask );
00280       break;
00281     case TrState::EndRich1 :
00282       setFlag( true, LocationEndRich1Bits, LocationEndRich1Mask );
00283       break;
00284     case TrState::BegRich2 :
00285       setFlag( true, LocationBegRich2Bits, LocationBegRich2Mask );
00286       break;
00287     case TrState::EndRich2 :
00288       setFlag( true, LocationEndRich2Bits, LocationEndRich2Mask );
00289       break;
00290     case TrState::Calo :
00291       setFlag( true, LocationCaloBits, LocationCaloMask );
00292       break;
00293     case TrState::Muon :
00294       setFlag( true, LocationMuonBits, LocationMuonMask );
00295       break;
00296     default:
00297       ;
00298   }
00299 };
00300 
00301 //=============================================================================
00302 // 
00303 //=============================================================================
00304 void TrState::setFlag( bool value, unsigned bits, unsigned mask )
00305 {
00306   unsigned val  = (unsigned) value;
00307   m_flags &= ~mask;
00308   m_flags |= ((((unsigned)val) << bits) & mask);
00309 };
00310 
00311 //=============================================================================

Generated on Tue Dec 7 10:30:18 2004 for New Track Event Model by doxygen 1.2.14 written by Dimitri van Heesch, © 1997-2002