CMS 3D CMS Logo

KFBasedPixelFitter.cc
Go to the documentation of this file.
2 
6 
7 
9 
12 
14 
18 
21 
24 
27 #include "CircleFromThreePoints.h"
28 
32 
33 /*
34 #include "RecoVertex/KalmanVertexFit/interface/SingleTrackVertexConstraint.h"
35 #include "TrackingTools/TransientTrack/interface/TransientTrackFromFTSFactory.h"
36 
37 #include "TrackingTools/TransientTrack/interface/TransientTrackFromFTSFactory.h"
38 #include "Alignment/ReferenceTrajectories/interface/BeamSpotTransientTrackingRecHit.h"
39 #include "Alignment/ReferenceTrajectories/interface/BeamSpotGeomDet.h"
40 #include <TrackingTools/PatternTools/interface/TSCPBuilderNoMaterial.h>
41 #include <TrackingTools/PatternTools/interface/TSCBLBuilderNoMaterial.h>
42 #include "TrackingTools/TrajectoryState/interface/TrajectoryStateClosestToPoint.h"
43 #include "TrackingTools/TrajectoryState/interface/TrajectoryStateClosestToBeamLine.h"
44 */
45 
46 
47 #include <sstream>
48 template <class T> inline T sqr( T t) {return t*t;}
49 
51  : TValidTrackingRecHit(*geom)
52 {
53  localPosition_ = LocalPoint(0.,0.,0.);
54  localError_ = LocalError( sqr(beamSpot.BeamWidthX()), 0.0, sqr(beamSpot.sigmaZ())); //neglect XY differences and BS slope
55 }
56 
58 {
60  result[0] = localPosition().x();
61  return result;
62 }
64 {
67  m[0][0] = le.xx();
68  return m;
69 }
71 {
72  AlgebraicMatrix matrix( 1, 5, 0);
73  matrix[0][3] = 1;
74  return matrix;
75 }
76 
77 
79  const TransientTrackingRecHitBuilder *ttrhBuilder,
80  const TrackerGeometry *tracker, const MagneticField *field,
81  const reco::BeamSpot *beamSpot):
82  theES(es), thePropagator(propagator), theOPropagator(opropagator), theTTRHBuilder(ttrhBuilder),
83  theTracker(tracker), theField(field), theBeamSpot(beamSpot)
84 {}
85 
86 std::unique_ptr<reco::Track> KFBasedPixelFitter::run(const std::vector<const TrackingRecHit *>& hits, const TrackingRegion& region) const {
87  std::unique_ptr<reco::Track> ret;
88 
89  int nhits = hits.size();
90  if (nhits <2) return ret;
91 
92 
93  float ptMin = region.ptMin();
94 
95  const GlobalPoint vertexPos = region.origin();
96  GlobalError vertexErr( sqr(region.originRBound()), 0, sqr(region.originRBound()), 0, 0, sqr(region.originZBound()));
97 
98  std::vector<GlobalPoint> points(nhits);
99  points[0] = theTracker->idToDet(hits[0]->geographicalId())->toGlobal(hits[0]->localPosition());
100  points[1] = theTracker->idToDet(hits[1]->geographicalId())->toGlobal(hits[1]->localPosition());
101  points[2] = theTracker->idToDet(hits[2]->geographicalId())->toGlobal(hits[2]->localPosition());
102 
103  //
104  //initial Kinematics
105  //
106  GlobalVector initMom;
107  int charge;
108  float theta;
109  CircleFromThreePoints circle(points[0], points[1], points[2]);
110  if (circle.curvature() > 1.e-4) {
111  float invPt = PixelRecoUtilities::inversePt( circle.curvature(), *theES);
112  float valPt = 1.f/invPt;
113  float chargeTmp = (points[1].x()-points[0].x())*(points[2].y()-points[1].y())
114  - (points[1].y()-points[0].y())*(points[2].x()-points[1].x());
115  charge = (chargeTmp>0) ? -1 : 1;
116  float valPhi = (charge>0) ? std::atan2(circle.center().x(),-circle.center().y()) : std::atan2(-circle.center().x(),circle.center().y());
117  theta = GlobalVector(points[1]-points[0]).theta();
118  initMom = GlobalVector(valPt*cos(valPhi), valPt*sin(valPhi), valPt/tan(theta));
119  }
120  else {
121  initMom = GlobalVector(points[1]-points[0]);
122  initMom *= 10000./initMom.perp();
123  charge = 1;
124  theta = initMom.theta();
125  }
126  GlobalTrajectoryParameters initialKine(vertexPos, initMom, TrackCharge(charge), theField);
127 
128  //
129  // initial error
130  //
131  AlgebraicSymMatrix55 C = ROOT::Math::SMatrixIdentity();
132  float sin2th = sqr(sin(theta));
133  float minC00 = 1.0;
134  C[0][0] = std::max(sin2th/sqr(ptMin), minC00);
135  float zErr = vertexErr.czz();
136  float transverseErr = vertexErr.cxx(); // assume equal cxx cyy
137  C[3][3] = transverseErr;
138  C[4][4] = zErr*sin2th + transverseErr*(1-sin2th);
139  CurvilinearTrajectoryError initialError(C);
140 
141  FreeTrajectoryState fts(initialKine, initialError);
142 
143  // get updator
145 
146  // Now update initial state track using information from hits.
147  TrajectoryStateOnSurface outerState;
148  DetId outerDetId = 0;
149  const TrackingRecHit* hit = 0;
150  for ( unsigned int iHit = 0; iHit < hits.size(); iHit++) {
151  hit = hits[iHit];
152  if (iHit==0) outerState = thePropagator->propagate(fts,theTracker->idToDet(hit->geographicalId())->surface());
153  outerDetId = hit->geographicalId();
154  TrajectoryStateOnSurface state = thePropagator->propagate(outerState, theTracker->idToDet(outerDetId)->surface());
155  if (!state.isValid()) return ret;
156 // TransientTrackingRecHit::RecHitPointer recHit = (theTTRHBuilder->build(hit))->clone(state);
158  outerState = updator.update(state, *recHit);
159  if (!outerState.isValid()) return ret;
160  }
161 
162 
163 
164  TrajectoryStateOnSurface innerState = outerState;
165  DetId innerDetId = 0;
166  innerState.rescaleError(100000.);
167  for ( int iHit = 2; iHit >= 0; --iHit) {
168  hit = hits[iHit];
169  innerDetId = hit->geographicalId();
170  TrajectoryStateOnSurface state = theOPropagator->propagate(innerState, theTracker->idToDet(innerDetId)->surface());
171  if (!state.isValid()) return ret;
172 // TransientTrackingRecHit::RecHitPointer recHit = (theTTRHBuilder->build(hit))->clone(state);
174  innerState = updator.update(state, *recHit);
175  if (!innerState.isValid()) return ret;
176  }
177 
178 
179  // extrapolate to vertex
180  TrajectoryStateOnSurface impactPointState = TransverseImpactPointExtrapolator(theField).extrapolate( innerState, vertexPos);
181  if (!impactPointState.isValid()) return ret;
182 
183  //
184  // optionally update impact point state with Bs constraint
185  // using this potion makes sense if vertexPos (from TrackingRegion is centerewd at BeamSpot).
186  //
187  if (theBeamSpot) {
188  MyBeamSpotGeomDet bsgd(Plane::build(impactPointState.surface().position(), impactPointState.surface().rotation()));
189  MyBeamSpotHit bsrh(*theBeamSpot, &bsgd);
190  impactPointState = updator.update(impactPointState, bsrh); //update
191  impactPointState = TransverseImpactPointExtrapolator(theField).extrapolate( impactPointState, vertexPos); //reextrapolate
192  if (!impactPointState.isValid()) return ret;
193  }
194 
195  int ndof = 2*hits.size()-5;
196  GlobalPoint vv = impactPointState.globalPosition();
197  math::XYZPoint pos( vv.x(), vv.y(), vv.z() );
198  GlobalVector pp = impactPointState.globalMomentum();
199  math::XYZVector mom( pp.x(), pp.y(), pp.z() );
200 
201  float chi2 = 0.;
202  ret = std::make_unique<reco::Track>( chi2, ndof, pos, mom,
203  impactPointState.charge(), impactPointState.curvilinearError());
204 
205 /*
206  vv = outerState.globalPosition();
207  pp = outerState.globalMomentum();
208  math::XYZPoint outerPosition( vv.x(), vv.y(), vv.z());
209  math::XYZVector outerMomentum( pp.x(), pp.y(), pp.z());
210  vv = innerState.globalPosition();
211  pp = innerState.globalMomentum();
212  math::XYZPoint innerPosition( vv.x(), vv.y(), vv.z());
213  math::XYZVector innerMomentum( pp.x(), pp.y(), pp.z());
214 
215  reco::TrackExtra extra( outerPosition, outerMomentum, true,
216  innerPosition, innerMomentum, true,
217  outerState.curvilinearError(), outerDetId,
218  innerState.curvilinearError(), innerDetId,
219  anyDirection);
220 */
221 
222 // std::cout <<"TRACK CREATED" << std::endl;
223  return ret;
224 }
float originRBound() const
bounds the particle vertex in the transverse plane
const Propagator * theOPropagator
float xx() const
Definition: LocalError.h:24
const Propagator * thePropagator
Point3DBase< Scalar, LocalTag > LocalPoint
Definition: Definitions.h:32
KFBasedPixelFitter(const edm::EventSetup *es, const Propagator *propagator, const Propagator *opropagator, const TransientTrackingRecHitBuilder *ttrhBuilder, const TrackerGeometry *tracker, const MagneticField *field, const reco::BeamSpot *beamSpot)
std::unique_ptr< reco::Track > run(const std::vector< const TrackingRecHit * > &hits, const TrackingRegion &region) const override
T perp() const
Definition: PV3DBase.h:72
GlobalPoint const & origin() const
const TrackerGeometry * theTracker
GlobalPoint toGlobal(const Local2DPoint &lp) const
Conversion to the global R.F. from the R.F. of the GeomDet.
Definition: GeomDet.h:54
const CurvilinearTrajectoryError & curvilinearError() const
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
Geom::Theta< T > theta() const
T y() const
Definition: PV3DBase.h:63
virtual LocalPoint localPosition() const
GlobalPoint globalPosition() const
ROOT::Math::SMatrix< double, 5, 5, ROOT::Math::MatRepSym< double, 5 > > AlgebraicSymMatrix55
virtual LocalError localPositionError() const
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:42
const MagneticField * theField
Geom::Theta< T > theta() const
Definition: PV3DBase.h:75
T inversePt(T curvature, const edm::EventSetup &iSetup)
int TrackCharge
Definition: TrackCharge.h:4
const SurfaceType & surface() const
T sqr(T t)
TrajectoryStateOnSurface update(const TrajectoryStateOnSurface &, const TrackingRecHit &) const
Definition: KFUpdator.cc:75
CLHEP::HepMatrix AlgebraicMatrix
virtual AlgebraicMatrix projectionMatrix() const
static PlanePointer build(Args &&...args)
Definition: Plane.h:33
T z() const
Definition: PV3DBase.h:64
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
MyBeamSpotHit(const reco::BeamSpot &beamSpot, const GeomDet *geom)
Tan< T >::type tan(const T &t)
Definition: Tan.h:22
double BeamWidthX() const
beam width X
Definition: BeamSpot.h:86
T y() const
Cartesian y coordinate.
float originZBound() const
bounds the particle vertex in the longitudinal plane
std::shared_ptr< TrackingRecHit const > RecHitPointer
virtual RecHitPointer build(const TrackingRecHit *p) const =0
build a tracking rechit from an existing rechit
const reco::BeamSpot * theBeamSpot
const edm::EventSetup * theES
const TransientTrackingRecHitBuilder * theTTRHBuilder
Definition: DetId.h:18
CLHEP::HepVector AlgebraicVector
XYZVectorD XYZVector
spatial vector with cartesian internal representation
Definition: Vector3D.h:30
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12
double sigmaZ() const
sigma z
Definition: BeamSpot.h:80
float ptMin() const
minimal pt of interest
TrajectoryStateOnSurface propagate(STA const &state, SUR const &surface) const
Definition: Propagator.h:53
virtual AlgebraicVector parameters() const
TrajectoryStateOnSurface extrapolate(const FreeTrajectoryState &fts, const GlobalPoint &vtx) const
extrapolation with default (=geometrical) propagator
GlobalVector globalMomentum() const
CLHEP::HepSymMatrix AlgebraicSymMatrix
const RotationType & rotation() const
DetId geographicalId() const
long double T
T x() const
Definition: PV3DBase.h:62
const PositionType & position() const
virtual AlgebraicSymMatrix parametersError() const
T x() const
Cartesian x coordinate.
Global3DVector GlobalVector
Definition: GlobalVector.h:10
const TrackerGeomDet * idToDet(DetId) const