CMS 3D CMS Logo

PixelTrackBuilder.cc
Go to the documentation of this file.
2 
6 
11 
16 
17 #include <sstream>
18 using namespace std;
19 using namespace reco;
20 
21 template <class T>
22 T inline sqr(T t) {
23  return t * t;
24 }
25 
26 namespace {
28  const Measurement1D& phi,
29  const Measurement1D& cotTheta,
30  const Measurement1D& tip,
31  const Measurement1D& zip,
32  float chi2,
33  int charge) {
34  ostringstream str;
35  str << "\t pt: " << pt.value() << "+/-" << pt.error() << "\t phi: " << phi.value() << "+/-" << phi.error()
36  << "\t cot: " << cotTheta.value() << "+/-" << cotTheta.error() << "\t tip: " << tip.value() << "+/-"
37  << tip.error() << "\t zip: " << zip.value() << "+/-" << zip.error() << "\t chi2: " << chi2
38  << "\t charge: " << charge;
39  return str.str();
40  }
41 
42  __attribute__((unused)) std::string print(const reco::Track& track, const GlobalPoint& origin) {
43  math::XYZPoint bs(origin.x(), origin.y(), origin.z());
44 
45  Measurement1D phi(track.phi(), track.phiError());
46 
47  float theta = track.theta();
48  float cosTheta = cos(theta);
49  float sinTheta = sin(theta);
50  float errLambda2 = sqr(track.lambdaError());
51  Measurement1D cotTheta(cosTheta / sinTheta, sqrt(errLambda2) / sqr(sinTheta));
52 
53  float pt_v = track.pt();
54  float errInvP2 = sqr(track.qoverpError());
55  float covIPtTheta = track.covariance(TrackBase::i_qoverp, TrackBase::i_lambda);
56  float errInvPt2 =
57  (errInvP2 + sqr(cosTheta / pt_v) * errLambda2 + 2 * (cosTheta / pt_v) * covIPtTheta) / sqr(sinTheta);
58  Measurement1D pt(pt_v, sqr(pt_v) * sqrt(errInvPt2));
59 
60  Measurement1D tip(track.dxy(bs), track.d0Error());
61 
62  Measurement1D zip(track.dz(bs), track.dzError());
63 
64  return print(pt, phi, cotTheta, tip, zip, track.chi2(), track.charge());
65  }
66 
68  // TrajectoryStateOnSurface state(bstate);
69  float pt_v = state.globalMomentum().perp();
70  float phi_v = state.globalMomentum().phi();
71  float theta_v = state.globalMomentum().theta();
72 
73  CurvilinearTrajectoryError curv = state.curvilinearError();
74  float errPhi2 = curv.matrix()(3, 3);
75  float errLambda2 = curv.matrix()(2, 2);
76  float errInvP2 = curv.matrix()(1, 1);
77  float covIPtTheta = curv.matrix()(1, 2);
78  float cosTheta = cos(theta_v);
79  float sinTheta = sin(theta_v);
80  float errInvPt2 =
81  (errInvP2 + sqr(cosTheta / pt_v) * errLambda2 + 2 * (cosTheta / pt_v) * covIPtTheta) / sqr(sinTheta);
82  float errCotTheta = sqrt(errLambda2) / sqr(sinTheta);
83  Measurement1D pt(pt_v, sqr(pt_v) * sqrt(errInvPt2));
84  Measurement1D phi(phi_v, sqrt(errPhi2));
85  Measurement1D cotTheta(cosTheta / sinTheta, errCotTheta);
86 
87  float zip_v = state.globalPosition().z();
88  float zip_e = sqrt(state.localError().matrix()(4, 4));
89  Measurement1D zip(zip_v, zip_e);
90 
91  float tip_v = state.localPosition().x();
92  int tip_sign = (state.localMomentum().y() * cotTheta.value() > 0) ? -1 : 1;
93  float tip_e = sqrt(state.localError().matrix()(3, 3));
94  Measurement1D tip(tip_sign * tip_v, tip_e);
95 
96  return print(pt, phi, cotTheta, tip, zip, 0., state.charge());
97  }
98 
99 #ifdef DEBUG_STATE
100  inline void checkState(const BasicTrajectoryStateOnSurface& bstate,
101  const MagneticField* mf,
102  const GlobalPoint& origin) {
104 
105  LogTrace("") << " *** PixelTrackBuilder::checkState: ";
106  LogTrace("") << "INPUT, ROTATION" << '\n' << state.surface().rotation();
107  LogTrace("") << "INPUT, TSOS:" << '\n' << state;
108 
110  TrajectoryStateOnSurface test = tipe.extrapolate(state, origin);
111  LogTrace("") << "CHECK-1 ROTATION" << '\n' << test.surface().rotation();
112  LogTrace("") << "CHECK-1 TSOS" << '\n' << test;
113 
114  TSCPBuilderNoMaterial tscpBuilder;
115  TrajectoryStateClosestToPoint tscp = tscpBuilder(*(state.freeState()), origin);
116  const FreeTrajectoryState& fs = tscp.theState();
117  LogTrace("") << "CHECK-2 FTS: " << fs;
118  }
119 #endif
120 
121 } // namespace
122 
124  const Measurement1D& phi,
125  const Measurement1D& cotTheta,
126  const Measurement1D& tip,
127  const Measurement1D& zip,
128  float chi2,
129  int charge,
130  const std::vector<const TrackingRecHit*>& hits,
131  const MagneticField* mf,
132  const GlobalPoint& origin) const {
133  LogDebug("PixelTrackBuilder::build") << "";
134  LogTrace("") << "Reconstructed triplet kinematics: " << print(pt, phi, cotTheta, tip, zip, chi2, charge);
135 
136  double sinTheta = 1 / std::sqrt(1 + sqr(cotTheta.value()));
137  double cosTheta = cotTheta.value() * sinTheta;
138  int tipSign = tip.value() > 0 ? 1 : -1;
139 
141  double invPtErr = 1. / sqr(pt.value()) * pt.error();
142  m(0, 0) = sqr(sinTheta) * (sqr(invPtErr) + sqr(cotTheta.error() / pt.value() * cosTheta * sinTheta));
143  m(0, 2) = sqr(cotTheta.error()) * cosTheta * sqr(sinTheta) / pt.value();
144  m(1, 1) = sqr(phi.error());
145  m(2, 2) = sqr(cotTheta.error());
146  m(3, 3) = sqr(tip.error());
147  m(4, 4) = sqr(zip.error());
149 
150  LocalTrajectoryParameters lpar(LocalPoint(tipSign * tip.value(), -tipSign * zip.value(), 0),
151  LocalVector(0., -tipSign * pt.value() * cotTheta.value(), pt.value()),
152  charge);
153 
154  float sp = std::sin(phi.value());
155  float cp = std::cos(phi.value());
156  Surface::RotationType rot(sp * tipSign, -cp * tipSign, 0, 0, 0, -tipSign, cp, sp, 0);
157 
158  // BTSOS hold Surface in a shared pointer and will be autodeleted when BTSOS goes out of scope...
159  // to avoid memory churn we allocate it locally and just avoid it be deleted by refcount...
160  Plane impPointPlane(origin, rot);
161  // (twice just to be sure!)
162  impPointPlane.addReference();
163  impPointPlane.addReference();
164  // use Base (to avoid a useless new)
165  BasicTrajectoryStateOnSurface impactPointState(lpar, error, impPointPlane, mf);
166 
167 #ifdef DEBUG_STATE
168  checkState(impactPointState, mf);
169 #endif
170  LogTrace("") << "constructed TSOS:\n" << print(impactPointState);
171 
172  int ndof = 2 * hits.size() - 5;
173  GlobalPoint vv = impactPointState.globalPosition();
174  math::XYZPoint pos(vv.x(), vv.y(), vv.z());
175  GlobalVector pp = impactPointState.globalMomentum();
176  math::XYZVector mom(pp.x(), pp.y(), pp.z());
177 
178  reco::Track* track =
179  new reco::Track(chi2, ndof, pos, mom, impactPointState.charge(), impactPointState.curvilinearError());
180 
181  return track;
182 }
Local3DVector LocalVector
Definition: LocalVector.h:12
Point3DBase< Scalar, LocalTag > LocalPoint
Definition: Definitions.h:30
GlobalVector globalMomentum() const
T z() const
Definition: PV3DBase.h:61
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
Definition: Plane.h:16
#define LogTrace(id)
TrackCharge charge() const
reco::Track * build(const Measurement1D &pt, const Measurement1D &phi, const Measurement1D &cotTheta, const Measurement1D &tip, const Measurement1D &zip, float chi2, int charge, const std::vector< const TrackingRecHit *> &hits, const MagneticField *mf, const GlobalPoint &reference=GlobalPoint(0, 0, 0)) const
T x() const
Definition: PV3DBase.h:59
T y() const
Definition: PV3DBase.h:60
OutputIterator zip(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp)
T sqrt(T t)
Definition: SSEVec.h:19
float __attribute__((vector_size(8))) cms_float32x2_t
Definition: ExtVec.h:12
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
T sqr(T t)
XYZVectorD XYZVector
spatial vector with cartesian internal representation
Definition: Vector3D.h:31
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12
GlobalPoint globalPosition() const
const AlgebraicSymMatrix55 & matrix() const
ROOT::Math::SMatrix< double, 5, 5, ROOT::Math::MatRepSym< double, 5 > > AlgebraicSymMatrix55
const FreeTrajectoryState & theState() const
double value() const
Definition: Measurement1D.h:25
fixed size matrix
double error() const
Definition: Measurement1D.h:27
#define str(s)
long double T
Geom::Theta< T > theta() const
const CurvilinearTrajectoryError & curvilinearError() const
#define LogDebug(id)