CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
KFBasedPixelFitter.cc
Go to the documentation of this file.
2 
8 
9 
12 
18 
21 
25 
28 
31 
34 #include "CircleFromThreePoints.h"
35 
39 
40 /*
41 #include "RecoVertex/KalmanVertexFit/interface/SingleTrackVertexConstraint.h"
42 #include "TrackingTools/TransientTrack/interface/TransientTrackFromFTSFactory.h"
43 
44 #include "TrackingTools/TransientTrack/interface/TransientTrackFromFTSFactory.h"
45 #include "Alignment/ReferenceTrajectories/interface/BeamSpotTransientTrackingRecHit.h"
46 #include "Alignment/ReferenceTrajectories/interface/BeamSpotGeomDet.h"
47 #include <TrackingTools/PatternTools/interface/TSCPBuilderNoMaterial.h>
48 #include <TrackingTools/PatternTools/interface/TSCBLBuilderNoMaterial.h>
49 #include "TrackingTools/TrajectoryState/interface/TrajectoryStateClosestToPoint.h"
50 #include "TrackingTools/TrajectoryState/interface/TrajectoryStateClosestToBeamLine.h"
51 */
52 
53 
54 #include <sstream>
55 template <class T> inline T sqr( T t) {return t*t;}
56 
57 KFBasedPixelFitter::MyBeamSpotHit::MyBeamSpotHit (const reco::BeamSpot &beamSpot, const GeomDet * geom)
58  : TValidTrackingRecHit(geom, 0)
59 {
60  localPosition_ = LocalPoint(0.,0.,0.);
61  localError_ = LocalError( sqr(beamSpot.BeamWidthX()), 0.0, sqr(beamSpot.sigmaZ())); //neglect XY differences and BS slope
62 }
63 
65 {
67  result[0] = localPosition().x();
68  return result;
69 }
70 AlgebraicSymMatrix KFBasedPixelFitter::MyBeamSpotHit::parametersError() const
71 {
72  LocalError le = localPositionError();
74  m[0][0] = le.xx();
75  return m;
76 }
77 AlgebraicMatrix KFBasedPixelFitter::MyBeamSpotHit::projectionMatrix() const
78 {
79  AlgebraicMatrix matrix( 1, 5, 0);
80  matrix[0][3] = 1;
81  return matrix;
82 }
83 
84 
86  :
87  thePropagatorLabel(cfg.getParameter<std::string>("propagator")),
88  thePropagatorOppositeLabel(cfg.getParameter<std::string>("propagatorOpposite")),
89  theUseBeamSpot(cfg.getParameter<bool>("useBeamSpotConstraint")),
90  theTTRHBuilderName(cfg.getParameter<std::string>("TTRHBuilder"))
91 {
92  if (theUseBeamSpot) theBeamSpot = cfg.getParameter<edm::InputTag>("beamSpotConstraint");
93 }
94 
96  const edm::Event& ev,
97  const edm::EventSetup& es,
98  const std::vector<const TrackingRecHit * > & hits,
99  const TrackingRegion & region) const
100 {
101  int nhits = hits.size();
102  if (nhits <2) return 0;
103 
105  es.get<TrackerDigiGeometryRecord>().get(tracker);
106 
108  es.get<IdealMagneticFieldRecord>().get(field);
109 
111  es.get<TransientRecHitRecord>().get( theTTRHBuilderName, ttrhb);
112 
113  float ptMin = region.ptMin();
114 
115  const GlobalPoint vertexPos = region.origin();
116  GlobalError vertexErr( sqr(region.originRBound()), 0, sqr(region.originRBound()), 0, 0, sqr(region.originZBound()));
117 
118  std::vector<GlobalPoint> points(nhits);
119  points[0] = tracker->idToDet(hits[0]->geographicalId())->toGlobal(hits[0]->localPosition());
120  points[1] = tracker->idToDet(hits[1]->geographicalId())->toGlobal(hits[1]->localPosition());
121  points[2] = tracker->idToDet(hits[2]->geographicalId())->toGlobal(hits[2]->localPosition());
122 
123  //
124  //initial Kinematics
125  //
126  GlobalVector initMom;
127  int charge;
128  float theta;
129  CircleFromThreePoints circle(points[0], points[1], points[2]);
130  if (circle.curvature() > 1.e-4) {
131  float invPt = PixelRecoUtilities::inversePt( circle.curvature(), es);
132  float valPt = 1.f/invPt;
133  float chargeTmp = (points[1].x()-points[0].x())*(points[2].y()-points[1].y())
134  - (points[1].y()-points[0].y())*(points[2].x()-points[1].x());
135  int charge = (chargeTmp>0) ? -1 : 1;
136  float valPhi = (charge>0) ? std::atan2(circle.center().x(),-circle.center().y()) : std::atan2(-circle.center().x(),circle.center().y());
137  theta = GlobalVector(points[1]-points[0]).theta();
138  initMom = GlobalVector(valPt*cos(valPhi), valPt*sin(valPhi), valPt/tan(theta));
139  }
140  else {
141  initMom = GlobalVector(points[1]-points[0]);
142  initMom *= 10000./initMom.perp();
143  charge = 1;
144  theta = initMom.theta();
145  }
146  GlobalTrajectoryParameters initialKine(vertexPos, initMom, TrackCharge(charge), &*field);
147 
148  //
149  // initial error
150  //
151  AlgebraicSymMatrix55 C = ROOT::Math::SMatrixIdentity();
152  float sin2th = sqr(sin(theta));
153  float minC00 = 1.0;
154  C[0][0] = std::max(sin2th/sqr(ptMin), minC00);
155  float zErr = vertexErr.czz();
156  float transverseErr = vertexErr.cxx(); // assume equal cxx cyy
157  C[3][3] = transverseErr;
158  C[4][4] = zErr*sin2th + transverseErr*(1-sin2th);
159  CurvilinearTrajectoryError initialError(C);
160 
161  FreeTrajectoryState fts(initialKine, initialError);
162 
163  // get propagator
165  es.get<TrackingComponentsRecord>().get(thePropagatorLabel, propagator);
166 
167  // get updator
168  KFUpdator updator;
169 
170  // Now update initial state track using information from hits.
171  TrajectoryStateOnSurface outerState;
172  DetId outerDetId = 0;
173  const TrackingRecHit* hit = 0;
174  for ( unsigned int iHit = 0; iHit < hits.size(); iHit++) {
175  hit = hits[iHit];
176  if (iHit==0) outerState = propagator->propagate(fts,tracker->idToDet(hit->geographicalId())->surface());
177  outerDetId = hit->geographicalId();
178  TrajectoryStateOnSurface state = propagator->propagate(outerState, tracker->idToDet(outerDetId)->surface());
179  if (!state.isValid()) return 0;
180 // TransientTrackingRecHit::RecHitPointer recHit = (ttrhb->build(hit))->clone(state);
181  TransientTrackingRecHit::RecHitPointer recHit = ttrhb->build(hit);
182  outerState = updator.update(state, *recHit);
183  if (!outerState.isValid()) return 0;
184  }
185 
186 
187 
188  // get propagator
189  edm::ESHandle<Propagator> opropagator;
191  TrajectoryStateOnSurface innerState = outerState;
192  DetId innerDetId = 0;
193  innerState.rescaleError(100000.);
194  for ( int iHit = 2; iHit >= 0; --iHit) {
195  hit = hits[iHit];
196  innerDetId = hit->geographicalId();
197  TrajectoryStateOnSurface state = opropagator->propagate(innerState, tracker->idToDet(innerDetId)->surface());
198  if (!state.isValid()) return 0;
199 // TransientTrackingRecHit::RecHitPointer recHit = (ttrhb->build(hit))->clone(state);
200  TransientTrackingRecHit::RecHitPointer recHit = ttrhb->build(hit);
201  innerState = updator.update(state, *recHit);
202  if (!innerState.isValid()) return 0;
203  }
204 
205 
206  // extrapolate to vertex
207  TrajectoryStateOnSurface impactPointState = TransverseImpactPointExtrapolator(&*field).extrapolate( innerState, vertexPos);
208  if (!impactPointState.isValid()) return 0;
209 
210  //
211  // optionally update impact point state with Bs constraint
212  // using this potion makes sense if vertexPos (from TrackingRegion is centerewd at BeamSpot).
213  //
214  if (theUseBeamSpot) {
216  ev.getByLabel( "offlineBeamSpot", beamSpot);
217  MyBeamSpotGeomDet bsgd(Plane::build(impactPointState.surface().position(), impactPointState.surface().rotation()));
218  MyBeamSpotHit bsrh(*beamSpot, &bsgd);
219  impactPointState = updator.update(impactPointState, bsrh); //update
220  impactPointState = TransverseImpactPointExtrapolator(&*field).extrapolate( impactPointState, vertexPos); //reextrapolate
221  if (!impactPointState.isValid()) return 0;
222  }
223 
224  int ndof = 2*hits.size()-5;
225  GlobalPoint vv = impactPointState.globalPosition();
226  math::XYZPoint pos( vv.x(), vv.y(), vv.z() );
227  GlobalVector pp = impactPointState.globalMomentum();
228  math::XYZVector mom( pp.x(), pp.y(), pp.z() );
229 
230  float chi2 = 0.;
231  reco::Track * track = new reco::Track( chi2, ndof, pos, mom,
232  impactPointState.charge(), impactPointState.curvilinearError());
233 
234 /*
235  vv = outerState.globalPosition();
236  pp = outerState.globalMomentum();
237  math::XYZPoint outerPosition( vv.x(), vv.y(), vv.z());
238  math::XYZVector outerMomentum( pp.x(), pp.y(), pp.z());
239  vv = innerState.globalPosition();
240  pp = innerState.globalMomentum();
241  math::XYZPoint innerPosition( vv.x(), vv.y(), vv.z());
242  math::XYZVector innerMomentum( pp.x(), pp.y(), pp.z());
243 
244  reco::TrackExtra extra( outerPosition, outerMomentum, true,
245  innerPosition, innerMomentum, true,
246  outerState.curvilinearError(), outerDetId,
247  innerState.curvilinearError(), innerDetId,
248  anyDirection);
249 */
250 
251 // std::cout <<"TRACK CREATED" << std::endl;
252  return track;
253 }
float originRBound() const
bounds the particle vertex in the transverse plane
T getParameter(std::string const &) const
float xx() const
Definition: LocalError.h:24
dictionary parameters
Definition: Parameters.py:2
std::string thePropagatorLabel
T perp() const
Definition: PV3DBase.h:72
GlobalPoint const & origin() const
tuple pp
Definition: createTree.py:15
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
GlobalPoint globalPosition() const
ROOT::Math::SMatrix< double, 5, 5, ROOT::Math::MatRepSym< double, 5 > > AlgebraicSymMatrix55
double charge(const std::vector< uint8_t > &Ampls)
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
CLHEP::HepMatrix AlgebraicMatrix
const T & max(const T &a, const T &b)
static PlanePointer build(Args &&...args)
Definition: Plane.h:36
T z() const
Definition: PV3DBase.h:64
tuple result
Definition: query.py:137
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
Tan< T >::type tan(const T &t)
Definition: Tan.h:22
double BeamWidthX() const
beam width X
Definition: BeamSpot.h:87
T y() const
Cartesian y coordinate.
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:361
float originZBound() const
bounds the particle vertex in the longitudinal plane
Definition: DetId.h:20
CLHEP::HepVector AlgebraicVector
XYZVectorD XYZVector
spatial vector with cartesian internal representation
Definition: Vector3D.h:31
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:13
const T & get() const
Definition: EventSetup.h:55
double sigmaZ() const
sigma z
Definition: BeamSpot.h:81
float ptMin() const
minimal pt of interest
char state
Definition: procUtils.cc:75
TrajectoryStateOnSurface extrapolate(const FreeTrajectoryState &fts, const GlobalPoint &vtx) const
extrapolation with default (=geometrical) propagator
GlobalVector globalMomentum() const
Square< F >::type sqr(const F &f)
Definition: Square.h:13
CLHEP::HepSymMatrix AlgebraicSymMatrix
Local3DPoint LocalPoint
Definition: LocalPoint.h:11
const RotationType & rotation() const
virtual reco::Track * run(const edm::Event &ev, const edm::EventSetup &es, const std::vector< const TrackingRecHit * > &hits, const TrackingRegion &region) const
DetId geographicalId() const
Definition: DDAxes.h:10
long double T
T x() const
Definition: PV3DBase.h:62
std::string thePropagatorOppositeLabel
const PositionType & position() const
std::string theTTRHBuilderName
T x() const
Cartesian x coordinate.
Global3DVector GlobalVector
Definition: GlobalVector.h:10