00001 #include "TrackingTools/TrajectoryState/interface/BasicSingleTrajectoryState.h"
00002 #include "TrackingTools/AnalyticalJacobians/interface/JacobianLocalToCurvilinear.h"
00003 #include "TrackingTools/AnalyticalJacobians/interface/JacobianCurvilinearToLocal.h"
00004 #include "TrackingTools/AnalyticalJacobians/interface/JacobianLocalToCartesian.h"
00005 #include "TrackingTools/AnalyticalJacobians/interface/JacobianCartesianToLocal.h"
00006
00007 #include <cmath>
00008
00009 BasicSingleTrajectoryState::
00010 BasicSingleTrajectoryState( const FreeTrajectoryState& fts,
00011 const Surface& aSurface,
00012 const SurfaceSide side) :
00013 theFreeState( new FreeTrajectoryState(fts)),
00014 theGlobalParamsUp2Date(true),
00015 theCartesianErrorUp2Date(fts.hasCartesianError()),
00016 theCurvilinErrorUp2Date(fts.hasCurvilinearError()),
00017 theLocalParameters(),
00018 theLocalError(),
00019 theLocalParametersValid(false),
00020 theLocalErrorValid(false),
00021 theSurfaceP( &aSurface), theSurfaceSide(side), theWeight(1.),
00022 theField( &fts.parameters().magneticField())
00023 {}
00024
00025 BasicSingleTrajectoryState::
00026 BasicSingleTrajectoryState( const GlobalTrajectoryParameters& par,
00027 const Surface& aSurface,
00028 const SurfaceSide side) :
00029 theFreeState( new FreeTrajectoryState(par)),
00030 theGlobalParamsUp2Date(true),
00031 theCartesianErrorUp2Date(false),
00032 theCurvilinErrorUp2Date(false),
00033 theLocalParameters(),
00034 theLocalError(),
00035 theLocalParametersValid(false),
00036 theLocalErrorValid(false),
00037 theSurfaceP( &aSurface), theSurfaceSide(side), theWeight(1.),
00038 theField( &par.magneticField())
00039 {}
00040
00041 BasicSingleTrajectoryState::
00042 BasicSingleTrajectoryState( const GlobalTrajectoryParameters& par,
00043 const CartesianTrajectoryError& err,
00044 const Surface& aSurface,
00045 const SurfaceSide side) :
00046 theFreeState( new FreeTrajectoryState(par, err)),
00047 theGlobalParamsUp2Date(true),
00048 theCartesianErrorUp2Date(true),
00049 theCurvilinErrorUp2Date(false),
00050 theLocalParameters(),
00051 theLocalError(),
00052 theLocalParametersValid(false),
00053 theLocalErrorValid(false),
00054 theSurfaceP( &aSurface), theSurfaceSide(side), theWeight(1.),
00055 theField( &par.magneticField())
00056 {}
00057
00058 BasicSingleTrajectoryState::
00059 BasicSingleTrajectoryState( const GlobalTrajectoryParameters& par,
00060 const CurvilinearTrajectoryError& err,
00061 const Surface& aSurface,
00062 const SurfaceSide side,
00063 double weight) :
00064 theFreeState( new FreeTrajectoryState(par, err)),
00065 theGlobalParamsUp2Date(true),
00066 theCartesianErrorUp2Date(false),
00067 theCurvilinErrorUp2Date(true),
00068 theLocalParameters(),
00069 theLocalError(),
00070 theLocalParametersValid(false),
00071 theLocalErrorValid(false),
00072 theSurfaceP( &aSurface), theSurfaceSide(side), theWeight(weight),
00073 theField( &par.magneticField())
00074 {}
00075
00076 BasicSingleTrajectoryState::
00077 BasicSingleTrajectoryState( const GlobalTrajectoryParameters& par,
00078 const CurvilinearTrajectoryError& err,
00079 const Surface& aSurface,
00080 double weight) :
00081 theFreeState( new FreeTrajectoryState(par, err)),
00082 theGlobalParamsUp2Date(true),
00083 theCartesianErrorUp2Date(false),
00084 theCurvilinErrorUp2Date(true),
00085 theLocalParameters(),
00086 theLocalError(),
00087 theLocalParametersValid(false),
00088 theLocalErrorValid(false),
00089 theSurfaceP( &aSurface), theSurfaceSide(SurfaceSideDefinition::atCenterOfSurface),
00090 theWeight(weight),
00091 theField( &par.magneticField())
00092 {}
00093
00094 BasicSingleTrajectoryState::
00095 BasicSingleTrajectoryState( const LocalTrajectoryParameters& par,
00096 const Surface& aSurface,
00097 const MagneticField* field,
00098 const SurfaceSide side) :
00099 theFreeState(0),
00100 theGlobalParamsUp2Date(false),
00101 theCartesianErrorUp2Date(false),
00102 theCurvilinErrorUp2Date(false),
00103 theLocalParameters(par),
00104 theLocalError(),
00105 theLocalParametersValid(true),
00106 theLocalErrorValid(false),
00107 theSurfaceP( &aSurface), theSurfaceSide(side),
00108 theWeight(1.),
00109 theField(field)
00110 {}
00111
00112 BasicSingleTrajectoryState::
00113 BasicSingleTrajectoryState( const LocalTrajectoryParameters& par,
00114 const LocalTrajectoryError& err,
00115 const Surface& aSurface,
00116 const MagneticField* field,
00117 const SurfaceSide side,
00118 double weight) :
00119 theFreeState(0),
00120 theGlobalParamsUp2Date(false),
00121 theCartesianErrorUp2Date(false),
00122 theCurvilinErrorUp2Date(false),
00123 theLocalParameters(par),
00124 theLocalError(err),
00125 theLocalParametersValid(true),
00126 theLocalErrorValid(true),
00127 theSurfaceP( &aSurface),
00128 theSurfaceSide(side),
00129 theWeight(weight),
00130 theField(field)
00131 {}
00132
00133 BasicSingleTrajectoryState::
00134 BasicSingleTrajectoryState( const LocalTrajectoryParameters& par,
00135 const LocalTrajectoryError& err,
00136 const Surface& aSurface,
00137 const MagneticField* field,
00138 double weight) :
00139 theFreeState(0),
00140 theGlobalParamsUp2Date(false),
00141 theCartesianErrorUp2Date(false),
00142 theCurvilinErrorUp2Date(false),
00143 theLocalParameters(par),
00144 theLocalError(err),
00145 theLocalParametersValid(true),
00146 theLocalErrorValid(true),
00147 theSurfaceP( &aSurface), theSurfaceSide(SurfaceSideDefinition::atCenterOfSurface),
00148 theWeight(weight),
00149 theField(field)
00150 {}
00151
00152 BasicSingleTrajectoryState::
00153 BasicSingleTrajectoryState(const Surface& aSurface) :
00154 theFreeState(0),
00155 theGlobalParamsUp2Date(false),
00156 theCartesianErrorUp2Date(false),
00157 theCurvilinErrorUp2Date(false),
00158 theLocalParameters(),
00159 theLocalError(),
00160 theLocalParametersValid(false),
00161 theLocalErrorValid(false),
00162 theSurfaceP( &aSurface), theSurfaceSide(SurfaceSideDefinition::atCenterOfSurface), theWeight(0.),
00163 theField(0)
00164 {}
00165
00166
00167 BasicSingleTrajectoryState::~BasicSingleTrajectoryState(){}
00168
00169 void BasicSingleTrajectoryState::checkGlobalParameters() const {
00170 if(!theGlobalParamsUp2Date){
00171
00172 theGlobalParamsUp2Date = true;
00173 theCurvilinErrorUp2Date = false;
00174 theCartesianErrorUp2Date = false;
00175
00176 GlobalPoint x = surface().toGlobal(theLocalParameters.position());
00177 GlobalVector p = surface().toGlobal(theLocalParameters.momentum());
00178 theFreeState.replaceWith(new FreeTrajectoryState(x, p,
00179 theLocalParameters.charge(),
00180 theField));
00181 }
00182 }
00183
00184 void BasicSingleTrajectoryState::checkCurvilinError() const {
00185 if(!theCurvilinErrorUp2Date){
00186 if(!theLocalParametersValid) createLocalParameters();
00187
00188 if(!theLocalErrorValid) createLocalError();
00189
00190 theCurvilinErrorUp2Date = true;
00191
00192 JacobianLocalToCurvilinear loc2Curv(surface(), localParameters(), *theField);
00193 const AlgebraicMatrix55& jac = loc2Curv.jacobian();
00194
00195 const AlgebraicSymMatrix55 &cov = ROOT::Math::Similarity(jac, theLocalError.matrix());
00196
00197
00198 theFreeState->setCurvilinearError( cov );
00199 }
00200 }
00201
00202 void BasicSingleTrajectoryState::checkCartesianError() const {
00203 if(!theCartesianErrorUp2Date){
00204 if(!theLocalParametersValid) createLocalParameters();
00205 if(!theLocalErrorValid) createLocalError();
00206 theCartesianErrorUp2Date = true;
00207
00208 JacobianLocalToCartesian loc2Cart(surface(), localParameters());
00209 const AlgebraicMatrix65& jac = loc2Cart.jacobian();
00210
00211 const AlgebraicSymMatrix66 &cov = ROOT::Math::Similarity(jac, theLocalError.matrix());
00212
00213
00214 theFreeState->setCartesianError( cov );
00215 }
00216 }
00217
00218
00219 void BasicSingleTrajectoryState::createLocalParameters() const {
00220 LocalPoint x = surface().toLocal(theFreeState->position());
00221 LocalVector p = surface().toLocal(theFreeState->momentum());
00222
00223 bool isCharged = theFreeState->charge()!=0;
00224 theLocalParameters =
00225 LocalTrajectoryParameters(isCharged?theFreeState->signedInverseMomentum():1./p.mag(),
00226 p.x()/p.z(), p.y()/p.z(), x.x(), x.y(), p.z()>0. ? 1.:-1., isCharged);
00227 theLocalParametersValid = true;
00228 }
00229
00230 void BasicSingleTrajectoryState::createLocalError() const {
00231 if(theFreeState->hasCurvilinearError())
00232 createLocalErrorFromCurvilinearError();
00233 else if(theFreeState->hasCartesianError())
00234 createLocalErrorFromCartesianError();
00235 else
00236 theLocalErrorValid = false;
00237 }
00238
00239 void
00240 BasicSingleTrajectoryState::createLocalErrorFromCurvilinearError() const {
00241
00242 JacobianCurvilinearToLocal curv2Loc(surface(), localParameters(), *theField);
00243 const AlgebraicMatrix55& jac = curv2Loc.jacobian();
00244
00245 const AlgebraicSymMatrix55 &cov =
00246 ROOT::Math::Similarity(jac, theFreeState->curvilinearError().matrix());
00247
00248 theLocalError = LocalTrajectoryError(cov);
00249 theLocalErrorValid = true;
00250 }
00251
00252 void
00253 BasicSingleTrajectoryState::createLocalErrorFromCartesianError() const {
00254
00255 JacobianCartesianToLocal cart2Loc(surface(), localParameters());
00256 const AlgebraicMatrix56& jac = cart2Loc.jacobian();
00257
00258
00259 const AlgebraicSymMatrix55 &C =
00260 ROOT::Math::Similarity(jac, theFreeState->cartesianError().matrix());
00261 theLocalError = LocalTrajectoryError(C);
00262 theLocalErrorValid = true;
00263 }