CMS 3D CMS Logo

CMSSW_4_4_3_patch1/src/Alignment/ReferenceTrajectories/src/TwoBodyDecayTrajectoryState.cc

Go to the documentation of this file.
00001 
00002 #include "Alignment/ReferenceTrajectories/interface/TwoBodyDecayTrajectoryState.h"
00003 #include "TrackingTools/TrajectoryState/interface/FreeTrajectoryState.h" 
00004 
00005 #include "Alignment/TwoBodyDecay/interface/TwoBodyDecayModel.h"
00006 #include "Alignment/TwoBodyDecay/interface/TwoBodyDecayDerivatives.h"
00007 
00008 #include "TrackingTools/TrajectoryParametrization/interface/GlobalTrajectoryParameters.h"
00009 
00010 #include "TrackingTools/AnalyticalJacobians/interface/AnalyticalCurvilinearJacobian.h"
00011 #include "TrackingTools/AnalyticalJacobians/interface/JacobianCurvilinearToLocal.h"
00012 #include "TrackingTools/AnalyticalJacobians/interface/JacobianCartesianToCurvilinear.h"
00013 
00014 #include "TrackingTools/GeomPropagators/interface/AnalyticalPropagator.h"
00015 
00016 #include "DataFormats/CLHEP/interface/Migration.h"
00017 
00018 using namespace std;
00019 
00020 
00021 TwoBodyDecayTrajectoryState::TwoBodyDecayTrajectoryState( const TsosContainer & tsos,
00022                                                           const TwoBodyDecay & tbd,
00023                                                           double particleMass,
00024                                                           const MagneticField* magField,
00025                                                           bool propagateErrors )
00026   : theValidityFlag( false ),
00027     theParticleMass( particleMass ),
00028     theParameters( tbd.decayParameters() ),
00029     theDerivatives( AlgebraicMatrix( nLocalParam, nDecayParam ), AlgebraicMatrix( nLocalParam, nDecayParam ) ),
00030     theOriginalTsos( tsos ),
00031     thePrimaryMass( tbd.primaryMass() ),
00032     thePrimaryWidth( tbd.primaryWidth() )
00033 {
00034   construct( magField, propagateErrors );
00035 }
00036 
00037 
00038 TwoBodyDecayTrajectoryState::TwoBodyDecayTrajectoryState( const TsosContainer & tsos,
00039                                                           const TwoBodyDecayParameters & param,
00040                                                           double particleMass,
00041                                                           const MagneticField* magField,
00042                                                           bool propagateErrors )
00043   : theValidityFlag( false ),
00044     theParticleMass( particleMass ),
00045     theParameters( param ),
00046     theDerivatives( AlgebraicMatrix( 5, 9 ), AlgebraicMatrix( 5, 9 ) ),
00047     theOriginalTsos( tsos ),
00048     thePrimaryMass( 0. ),
00049     thePrimaryWidth( -1. ) // dummy values
00050 {
00051   construct( magField, propagateErrors );
00052 }
00053 
00054 
00055 void TwoBodyDecayTrajectoryState::rescaleError( double scale )
00056 {
00057   theOriginalTsos.first.rescaleError( scale );
00058   theOriginalTsos.second.rescaleError( scale );
00059   theRefittedTsos.first.rescaleError( scale );
00060   theRefittedTsos.second.rescaleError( scale );
00061 }
00062 
00063 
00064 void TwoBodyDecayTrajectoryState::construct( const MagneticField* magField,
00065                                              bool propagateErrors )
00066 {
00067   // construct global trajectory parameters at the starting point
00068   TwoBodyDecayModel tbdDecayModel( theParameters[TwoBodyDecayParameters::mass], theParticleMass );
00069   pair< AlgebraicVector, AlgebraicVector > secondaryMomenta = tbdDecayModel.cartesianSecondaryMomenta( theParameters );
00070 
00071   GlobalPoint vtx( theParameters[TwoBodyDecayParameters::x],
00072                    theParameters[TwoBodyDecayParameters::y],
00073                    theParameters[TwoBodyDecayParameters::z] );
00074 
00075   GlobalVector p1( secondaryMomenta.first[0],
00076                    secondaryMomenta.first[1],
00077                    secondaryMomenta.first[2] );
00078 
00079   GlobalVector p2( secondaryMomenta.second[0],
00080                    secondaryMomenta.second[1],
00081                    secondaryMomenta.second[2] );
00082 
00083   GlobalTrajectoryParameters gtp1( vtx, p1, theOriginalTsos.first.charge(), magField );
00084   FreeTrajectoryState fts1( gtp1 );
00085 
00086   GlobalTrajectoryParameters gtp2( vtx, p2, theOriginalTsos.second.charge(), magField );
00087   FreeTrajectoryState fts2( gtp2 );
00088 
00089   // contruct derivatives at the starting point
00090   TwoBodyDecayDerivatives tbdDerivatives( theParameters[TwoBodyDecayParameters::mass], theParticleMass );
00091   pair< AlgebraicMatrix, AlgebraicMatrix > derivatives = tbdDerivatives.derivatives( theParameters );
00092 
00093   AlgebraicMatrix deriv1( 6, 9, 0 );
00094   deriv1.sub( 1, 1, AlgebraicMatrix( 3, 3, 1 ) );
00095   deriv1.sub( 4, 4, derivatives.first );
00096 
00097   AlgebraicMatrix deriv2( 6, 9, 0 );
00098   deriv2.sub( 1, 1, AlgebraicMatrix( 3, 3, 1 ) );
00099   deriv2.sub( 4, 4, derivatives.second );
00100 
00101   // compute errors of initial states
00102   if ( propagateErrors ) {
00103     setError( fts1, deriv1 );
00104     setError( fts2, deriv2 );
00105   }
00106 
00107 
00108   // propgate states and derivatives from the starting points to the end points
00109   bool valid1 = propagateSingleState( fts1, gtp1, deriv1, theOriginalTsos.first.surface(),
00110                                       magField, theRefittedTsos.first, theDerivatives.first );
00111 
00112   bool valid2 = propagateSingleState( fts2, gtp2, deriv2, theOriginalTsos.second.surface(),
00113                                       magField, theRefittedTsos.second, theDerivatives.second );
00114 
00115   theValidityFlag = valid1 && valid2;
00116 
00117   return;
00118 }
00119 
00120 
00121 bool TwoBodyDecayTrajectoryState::propagateSingleState( const FreeTrajectoryState & fts,
00122                                                         const GlobalTrajectoryParameters & gtp,
00123                                                         const AlgebraicMatrix & startDeriv,
00124                                                         const Surface & surface,
00125                                                         const MagneticField* magField,
00126                                                         TrajectoryStateOnSurface & tsos,
00127                                                         AlgebraicMatrix & endDeriv ) const
00128 {
00129   AnalyticalPropagator propagator( magField );
00130 
00131   // propagate state
00132   pair< TrajectoryStateOnSurface, double > tsosWithPath = propagator.propagateWithPath( fts, surface );
00133 
00134   // check if propagation was successful
00135   if ( !tsosWithPath.first.isValid() ) return false;
00136 
00137   // jacobian for transformation from cartesian to curvilinear frame at the starting point
00138   JacobianCartesianToCurvilinear cartToCurv( gtp );
00139   const AlgebraicMatrix56& matCartToCurv = cartToCurv.jacobian();
00140 
00141   // jacobian in curvilinear frame for propagation from the starting point to the end point
00142   AnalyticalCurvilinearJacobian curvJac( gtp, tsosWithPath.first.globalPosition(),
00143                                          tsosWithPath.first.globalMomentum(),
00144                                          tsosWithPath.second );
00145   const AlgebraicMatrix55& matCurvJac = curvJac.jacobian();
00146 
00147   // jacobian for transformation from curvilinear to local frame at the end point
00148   JacobianCurvilinearToLocal curvToLoc( surface, tsosWithPath.first.localParameters(), *magField );
00149   const AlgebraicMatrix55& matCurvToLoc = curvToLoc.jacobian();
00150 
00151   AlgebraicMatrix56 tmpDeriv = matCurvToLoc*matCurvJac*matCartToCurv;
00152   AlgebraicMatrix hepMatDeriv( asHepMatrix( tmpDeriv ) );
00153   //AlgebraicMatrix hepMatDeriv = asHepMatrix< 5, 6 >( tmpDeriv );
00154 
00155   // replace original state with new state
00156   tsos = tsosWithPath.first;
00157 
00158   // propagate derivative matrix
00159   endDeriv = hepMatDeriv*startDeriv;
00160 
00161   return true;
00162 }
00163 
00164 
00165 void TwoBodyDecayTrajectoryState::setError( FreeTrajectoryState& fts,
00166                                             AlgebraicMatrix& derivative ) const
00167 {
00168   AlgebraicSymMatrix ftsCartesianError( theParameters.covariance().similarity( derivative ) );
00169   fts.setCartesianError( asSMatrix<6>( ftsCartesianError ) );
00170 }