CMS 3D CMS Logo

PixelFitterByHelixProjections.cc
Go to the documentation of this file.
3 
5 
9 
13 //#include "DataFormats/SiPixelDetId/interface/PixelSubdetector.h"
15 
16 
19 
22 
24 
26 
28 #include "CircleFromThreePoints.h"
32 
34 
35 using namespace std;
36 
37 namespace {
38 
39  int charge(DynArray<GlobalPoint> const & points) {
40  // the cross product will tell me...
41  float dir = (points[1].x()-points[0].x())*(points[2].y()-points[1].y())
42  - (points[1].y()-points[0].y())*(points[2].x()-points[1].x());
43 
44  /*
45  GlobalVector v21 = points[1]-points[0];
46  GlobalVector v32 = points[2]-points[1];
47  float dphi = v32.phi() - v21.phi();
48  while (dphi > Geom::fpi()) dphi -= Geom::ftwoPi();
49  while (dphi < -Geom::fpi()) dphi += Geom::ftwoPi();
50  return (dphi > 0) ? -1 : 1;
51  */
52  return (dir>0) ? -1 : 1;
53  }
54 
55  float cotTheta(const GlobalPoint& inner, const GlobalPoint& outer) {
56  float dr = outer.perp()-inner.perp();
57  float dz = outer.z()-inner.z();
58  return (std::abs(dr) > 1.e-3f) ? dz/dr : 0;
59  }
60 
61  inline float phi(float xC, float yC, int charge) {
62  return (charge>0) ? std::atan2(xC,-yC) : std::atan2(-xC,yC);
63  }
64 
65  float zip(float d0, float phi_p, float curv,
66  const GlobalPoint& pinner, const GlobalPoint& pouter) {
67  //
68  //phi = asin(r*rho/2) with asin(x) ~= x+x**3/(2*3) = x(1+x*x/6);
69  //
70 
71  float phi0 = phi_p - Geom::fhalfPi();
72  GlobalPoint pca(d0*std::cos(phi0), d0*std::sin(phi0),0.);
73 
74 
75  constexpr float o24 = 1.f/24.f;
76  float rho2 = curv*curv;
77  float r1s = (pinner-pca).perp2();
78  double phi1 = std::sqrt(r1s)*(curv*0.5f)*(1.f+r1s*(rho2*o24));
79  float r2s = (pouter-pca).perp2();
80  double phi2 = std::sqrt(r2s)*(curv*0.5f)*(1.f+r2s*(rho2*o24));
81  double z1 = pinner.z();
82  double z2 = pouter.z();
83 
84  if (fabs(curv)>1.e-5)
85  return z1 - phi1/(phi1-phi2)*(z1-z2);
86  else {
87  double dr = std::max(std::sqrt(r2s)-std::sqrt(r1s),1.e-5f);
88  return z1-std::sqrt(r1s)*(z2-z1)/dr;
89  }
90  }
91 }
92 
94  theES(es), theField(field) {}
95 
96 std::unique_ptr<reco::Track> PixelFitterByHelixProjections::run(
97  const std::vector<const TrackingRecHit * > & hits,
98  const TrackingRegion & region) const
99 {
100  std::unique_ptr<reco::Track> ret;
101 
102  int nhits = hits.size();
103  if (nhits <2) return ret;
104 
105  declareDynArray(GlobalPoint,nhits, points);
107  declareDynArray(bool,nhits, isBarrel);
108 
109  for ( int i=0; i!=nhits; ++i) {
110  auto const & recHit = hits[i];
111  points[i] = GlobalPoint( recHit->globalPosition().basicVector()-region.origin().basicVector());
112  errors[i] = recHit->globalPositionError();
113  isBarrel[i] = recHit->detUnit()->type().isBarrel();
114  }
115 
116  CircleFromThreePoints circle = (nhits==2) ?
117  CircleFromThreePoints( GlobalPoint(0.,0.,0.), points[0], points[1]) :
118  CircleFromThreePoints(points[0],points[1],points[2]);
119 
120  float valPhi, valTip, valPt;
121 
122  int iCharge = charge(points);
123  float curvature = circle.curvature();
124 
125  if ((curvature > 1.e-4)&&
127  float invPt = PixelRecoUtilities::inversePt( circle.curvature(), *theES);
128  valPt = (invPt > 1.e-4f) ? 1.f/invPt : 1.e4f;
129  CircleFromThreePoints::Vector2D center = circle.center();
130  valTip = iCharge * (center.mag()-1.f/curvature);
131  valPhi = phi(center.x(), center.y(), iCharge);
132  }
133  else {
134  valPt = 1.e4f;
135  GlobalVector direction(points[1]-points[0]);
136  valPhi = direction.barePhi();
137  valTip = -points[0].x()*sin(valPhi) + points[0].y()*cos(valPhi);
138  }
139 
140  float valCotTheta = cotTheta(points[0],points[1]);
141  float valEta = std::asinh(valCotTheta);
142  float valZip = zip(valTip, valPhi, curvature, points[0],points[1]);
143 
144  PixelTrackErrorParam param(valEta, valPt);
145  float errValPt = param.errPt();
146  float errValCot = param.errCot();
147  float errValTip = param.errTip();
148  float errValPhi = param.errPhi();
149  float errValZip = param.errZip();
150 
151 
152  float chi2 = 0;
153  if (nhits > 2) {
154  RZLine rzLine(points,errors,isBarrel);
155  chi2 = rzLine.chi2();
156  }
157 
158  PixelTrackBuilder builder;
159  Measurement1D pt(valPt, errValPt);
160  Measurement1D phi(valPhi, errValPhi);
161  Measurement1D cotTheta(valCotTheta, errValCot);
162  Measurement1D tip(valTip, errValTip);
163  Measurement1D zip(valZip, errValZip);
164 
165  ret.reset(builder.build(pt, phi, cotTheta, tip, zip, chi2, iCharge, hits, theField, region.origin() ));
166  return ret;
167 }
168 
169 
170 
171 
T perp() const
Definition: PV3DBase.h:72
GlobalPoint const & origin() const
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
#define constexpr
T barePhi() const
Definition: PV3DBase.h:68
T inversePt(T curvature, const edm::EventSetup &iSetup)
T x() const
Cartesian x coordinate.
#define likely(x)
T curvature(T InversePt, const edm::EventSetup &iSetup)
PixelFitterByHelixProjections(const edm::EventSetup *es, const MagneticField *field)
OutputIterator zip(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp)
T sqrt(T t)
Definition: SSEVec.h:18
T z() const
Definition: PV3DBase.h:64
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
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
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
double f[11][100]
T y() const
Cartesian y coordinate.
Definition: RZLine.h:12
constexpr float fhalfPi()
Definition: Pi.h:37
T perp2() const
Squared magnitude of transverse component.
Definition: errors.py:1
#define declareDynArray(T, n, x)
Definition: DynArray.h:59
dbl *** dir
Definition: mlp_gen.cc:35
float fieldInInvGev(const edm::EventSetup &iSetup)
const BasicVectorType & basicVector() const
Definition: PV3DBase.h:56
float chi2() const
Definition: RZLine.h:97
virtual std::unique_ptr< reco::Track > run(const std::vector< const TrackingRecHit * > &hits, const TrackingRegion &region) const override
T x() const
Cartesian x coordinate.