File indexing completed on 2024-04-06 12:31:41
0001 #include "TrackingTools/TrajectoryState/interface/TrajectoryStateTransform.h"
0002 #include "DataFormats/TrackReco/interface/Track.h"
0003 #include "TrackingTools/TrajectoryState/interface/TrajectoryStateOnSurface.h"
0004 #include "TrackingTools/TrajectoryState/interface/FreeTrajectoryState.h"
0005 #include "DataFormats/GeometrySurface/interface/Surface.h"
0006 #include "TrackingTools/TrajectoryParametrization/interface/GlobalTrajectoryParameters.h"
0007 #include "Geometry/CommonDetUnit/interface/TrackingGeometry.h"
0008 #include "Geometry/CommonDetUnit/interface/GeomDet.h"
0009
0010 namespace trajectoryStateTransform {
0011
0012 using namespace SurfaceSideDefinition;
0013
0014 PTrajectoryStateOnDet persistentState(const TrajectoryStateOnSurface& ts, unsigned int detid) {
0015 int surfaceSide = static_cast<int>(ts.surfaceSide());
0016 auto pt = ts.globalMomentum().perp();
0017
0018 if (ts.hasError()) {
0019 AlgebraicSymMatrix55 const& m = ts.localError().matrix();
0020
0021 int dim = 5;
0022 float localErrors[15];
0023
0024 int k = 0;
0025 for (int i = 0; i < dim; i++) {
0026 for (int j = 0; j <= i; j++) {
0027 localErrors[k++] = m(i, j);
0028 }
0029 }
0030 return PTrajectoryStateOnDet(ts.localParameters(), pt, localErrors, detid, surfaceSide);
0031 }
0032 return PTrajectoryStateOnDet(ts.localParameters(), pt, detid, surfaceSide);
0033 }
0034
0035 TrajectoryStateOnSurface transientState(const PTrajectoryStateOnDet& ts,
0036 const Surface* surface,
0037 const MagneticField* field) {
0038 AlgebraicSymMatrix55 m;
0039 bool errInv = true;
0040 if (ts.hasError()) {
0041 errInv = false;
0042 int dim = 5;
0043 int k = 0;
0044 for (int i = 0; i < dim; i++) {
0045 for (int j = 0; j <= i; j++) {
0046 m(i, j) = ts.error(k++);
0047 }
0048 }
0049 }
0050
0051 return TrajectoryStateOnSurface(ts.parameters(),
0052 errInv ? LocalTrajectoryError(InvalidError()) : LocalTrajectoryError(m),
0053 *surface,
0054 field,
0055 static_cast<SurfaceSide>(ts.surfaceSide()));
0056 }
0057
0058 FreeTrajectoryState initialFreeState(const reco::Track& tk, const MagneticField* field, bool withErr) {
0059 Basic3DVector<float> pos(tk.vertex());
0060 GlobalPoint gpos(pos);
0061 Basic3DVector<float> mom(tk.momentum());
0062 GlobalVector gmom(mom);
0063 GlobalTrajectoryParameters par(gpos, gmom, tk.charge(), field);
0064 if (!withErr)
0065 return FreeTrajectoryState(par);
0066 CurvilinearTrajectoryError err(tk.covariance());
0067 return FreeTrajectoryState(par, err);
0068 }
0069
0070 FreeTrajectoryState initialFreeStateL1TTrack(const TTTrack<Ref_Phase2TrackerDigi_>& tk,
0071 const MagneticField* field,
0072 bool withErr) {
0073 Basic3DVector<float> pos(tk.POCA());
0074 GlobalPoint gpos(pos);
0075 GlobalVector gmom = tk.momentum();
0076 int charge = tk.rInv() > 0.f ? 1 : -1;
0077
0078 GlobalTrajectoryParameters par(gpos, gmom, charge, field);
0079 if (!withErr)
0080 return FreeTrajectoryState(par);
0081 AlgebraicSymMatrix55 mat = AlgebraicMatrixID();
0082 mat *= 1e-8;
0083 return FreeTrajectoryState(par, mat);
0084 }
0085
0086 FreeTrajectoryState innerFreeState(const reco::Track& tk, const MagneticField* field, bool withErr) {
0087 Basic3DVector<float> pos(tk.innerPosition());
0088 GlobalPoint gpos(pos);
0089 Basic3DVector<float> mom(tk.innerMomentum());
0090 GlobalVector gmom(mom);
0091 GlobalTrajectoryParameters par(gpos, gmom, tk.charge(), field);
0092 if (!withErr)
0093 return FreeTrajectoryState(par);
0094 CurvilinearTrajectoryError err(tk.extra()->innerStateCovariance());
0095 return FreeTrajectoryState(par, err);
0096 }
0097
0098 FreeTrajectoryState outerFreeState(const reco::Track& tk, const MagneticField* field, bool withErr) {
0099 Basic3DVector<float> pos(tk.outerPosition());
0100 GlobalPoint gpos(pos);
0101 Basic3DVector<float> mom(tk.outerMomentum());
0102 GlobalVector gmom(mom);
0103 GlobalTrajectoryParameters par(gpos, gmom, tk.charge(), field);
0104 if (!withErr)
0105 return FreeTrajectoryState(par);
0106 CurvilinearTrajectoryError err(tk.extra()->outerStateCovariance());
0107 return FreeTrajectoryState(par, err);
0108 }
0109
0110 TrajectoryStateOnSurface innerStateOnSurface(const reco::Track& tk,
0111 const TrackingGeometry& geom,
0112 const MagneticField* field,
0113 bool withErr) {
0114 const Surface& surface = geom.idToDet(DetId(tk.extra()->innerDetId()))->surface();
0115 return TrajectoryStateOnSurface(innerFreeState(tk, field, withErr), surface);
0116 }
0117
0118 TrajectoryStateOnSurface outerStateOnSurface(const reco::Track& tk,
0119 const TrackingGeometry& geom,
0120 const MagneticField* field,
0121 bool withErr) {
0122 const Surface& surface = geom.idToDet(DetId(tk.extra()->outerDetId()))->surface();
0123 return TrajectoryStateOnSurface(outerFreeState(tk, field, withErr), surface);
0124 }
0125
0126 }