test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PixelFitterByHelixProjections.cc
Go to the documentation of this file.
3 
5 
9 
13 //#include "DataFormats/SiPixelDetId/interface/PixelSubdetector.h"
15 
16 
19 
22 
25 
26 
28 
29 #include "RZLine.h"
30 #include "CircleFromThreePoints.h"
34 
36 
37 using namespace std;
38 
39 namespace {
40 
41  int charge(DynArray<GlobalPoint> const & points) {
42  // the cross product will tell me...
43  float dir = (points[1].x()-points[0].x())*(points[2].y()-points[1].y())
44  - (points[1].y()-points[0].y())*(points[2].x()-points[1].x());
45 
46  /*
47  GlobalVector v21 = points[1]-points[0];
48  GlobalVector v32 = points[2]-points[1];
49  float dphi = v32.phi() - v21.phi();
50  while (dphi > Geom::fpi()) dphi -= Geom::ftwoPi();
51  while (dphi < -Geom::fpi()) dphi += Geom::ftwoPi();
52  return (dphi > 0) ? -1 : 1;
53  */
54  return (dir>0) ? -1 : 1;
55  }
56 
57  float cotTheta(const GlobalPoint& inner, const GlobalPoint& outer) {
58  float dr = outer.perp()-inner.perp();
59  float dz = outer.z()-inner.z();
60  return (std::abs(dr) > 1.e-3f) ? dz/dr : 0;
61  }
62 
63  inline float phi(float xC, float yC, int charge) {
64  return (charge>0) ? std::atan2(xC,-yC) : std::atan2(-xC,yC);
65  }
66 
67  float zip(float d0, float phi_p, float curv,
68  const GlobalPoint& pinner, const GlobalPoint& pouter) {
69  //
70  //phi = asin(r*rho/2) with asin(x) ~= x+x**3/(2*3) = x(1+x*x/6);
71  //
72 
73  float phi0 = phi_p - Geom::fhalfPi();
74  GlobalPoint pca(d0*std::cos(phi0), d0*std::sin(phi0),0.);
75 
76 
77  constexpr float o24 = 1.f/24.f;
78  float rho2 = curv*curv;
79  float r1s = (pinner-pca).perp2();
80  double phi1 = std::sqrt(r1s)*(curv*0.5f)*(1.f+r1s*(rho2*o24));
81  float r2s = (pouter-pca).perp2();
82  double phi2 = std::sqrt(r2s)*(curv*0.5f)*(1.f+r2s*(rho2*o24));
83  double z1 = pinner.z();
84  double z2 = pouter.z();
85 
86  if (fabs(curv)>1.e-5)
87  return z1 - phi1/(phi1-phi2)*(z1-z2);
88  else {
89  double dr = std::max(std::sqrt(r2s)-std::sqrt(r1s),1.e-5f);
90  return z1-std::sqrt(r1s)*(z2-z1)/dr;
91  }
92  }
93 }
94 
96  const edm::ParameterSet& cfg)
97  : theConfig(cfg), theField(nullptr) {}
98 
100  const edm::EventSetup& es,
101  const std::vector<const TrackingRecHit * > & hits,
102  const TrackingRegion & region) const
103 {
104  int nhits = hits.size();
105  if (nhits <2) return 0;
106 
107  {
109  es.get<IdealMagneticFieldRecord>().get(fieldESH);
110  theField = fieldESH.product();
111  }
112 
113  declareDynArray(GlobalPoint,nhits, points);
115  declareDynArray(bool,nhits, isBarrel);
116 
117 
118  for ( int i=0; i!=nhits; ++i) {
119  auto const & recHit = hits[i];
120  points[i] = GlobalPoint( recHit->globalPosition().basicVector()-region.origin().basicVector());
121  errors[i] = recHit->globalPositionError();
122  isBarrel[i] = recHit->detUnit()->type().isBarrel();
123  }
124 
125  CircleFromThreePoints circle = (nhits==2) ?
126  CircleFromThreePoints( GlobalPoint(0.,0.,0.), points[0], points[1]) :
127  CircleFromThreePoints(points[0],points[1],points[2]);
128 
129  float valPhi, valTip, valPt;
130 
131  int iCharge = charge(points);
132  float curvature = circle.curvature();
133 
134  if ((curvature > 1.e-4)&&
136  float invPt = PixelRecoUtilities::inversePt( circle.curvature(), es);
137  valPt = (invPt > 1.e-4f) ? 1.f/invPt : 1.e4f;
138  CircleFromThreePoints::Vector2D center = circle.center();
139  valTip = iCharge * (center.mag()-1.f/curvature);
140  valPhi = phi(center.x(), center.y(), iCharge);
141  }
142  else {
143  valPt = 1.e4f;
144  GlobalVector direction(points[1]-points[0]);
145  valPhi = direction.barePhi();
146  valTip = -points[0].x()*sin(valPhi) + points[0].y()*cos(valPhi);
147  }
148 
149  float valCotTheta = cotTheta(points[0],points[1]);
150  float valEta = std::asinh(valCotTheta);
151  float valZip = zip(valTip, valPhi, curvature, points[0],points[1]);
152 
153  PixelTrackErrorParam param(valEta, valPt);
154  float errValPt = param.errPt();
155  float errValCot = param.errCot();
156  float errValTip = param.errTip();
157  float errValPhi = param.errPhi();
158  float errValZip = param.errZip();
159 
160 
161  float chi2 = 0;
162  if (nhits > 2) {
163  RZLine rzLine(points,errors,isBarrel);
164  float cottheta, intercept, covss, covii, covsi;
165  rzLine.fit(cottheta, intercept, covss, covii, covsi);
166  chi2 = rzLine.chi2(cottheta, intercept); //FIXME: check which intercept to use!
167  }
168 
169  PixelTrackBuilder builder;
170  Measurement1D pt(valPt, errValPt);
171  Measurement1D phi(valPhi, errValPhi);
172  Measurement1D cotTheta(valCotTheta, errValCot);
173  Measurement1D tip(valTip, errValTip);
174  Measurement1D zip(valZip, errValZip);
175 
176  return builder.build(pt, phi, cotTheta, tip, zip, chi2, iCharge, hits, theField, region.origin() );
177 }
178 
179 
180 
181 
int i
Definition: DBlmapReader.cc:9
tuple cfg
Definition: looper.py:293
T perp() const
Definition: PV3DBase.h:72
GlobalPoint const & origin() const
PixelFitterByHelixProjections(const edm::ParameterSet &cfg)
bool isBarrel(GeomDetEnumerators::SubDetector m)
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())
virtual reco::Track * run(const edm::EventSetup &es, const std::vector< const TrackingRecHit * > &hits, const TrackingRegion &region) const
#define nullptr
#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)
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:9
constexpr float fhalfPi()
Definition: Pi.h:37
const T & get() const
Definition: EventSetup.h:56
T const * product() const
Definition: ESHandle.h:86
T perp2() const
Squared magnitude of transverse component.
Geom::Phi< T > phi() const
void fit(float &cotTheta, float &intercept, float &covss, float &covii, float &covsi) const
Definition: RZLine.cc:44
#define declareDynArray(T, n, x)
Definition: DynArray.h:58
float chi2(float cotTheta, float intercept) const
Definition: RZLine.cc:50
dbl *** dir
Definition: mlp_gen.cc:35
float fieldInInvGev(const edm::EventSetup &iSetup)
const BasicVectorType & basicVector() const
Definition: PV3DBase.h:56
T x() const
Cartesian x coordinate.