test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
TrackFitter.cc
Go to the documentation of this file.
3 
8 
12 
17 
22 
25 
28 
30 
34 
35 using namespace std;
37 
38 
39 namespace {
40 int getCharge
41  (const DynArray<GlobalPoint> & points)
42 {
43  GlobalVector v21 = points[1]-points[0];
44  GlobalVector v32 = points[2]-points[1];
45  float dphi = v32.phi() - v21.phi();
46  while (dphi > M_PI) dphi -= 2*M_PI;
47  while (dphi < -M_PI) dphi += 2*M_PI;
48  return (dphi > 0) ? -1 : 1;
49 }
50 
51 
52 
53 }
54 
55 
56 /*****************************************************************************/
59  theConfig(cfg), theTracker(0), theField(0), theTTRecHitBuilder(0)
60 {
61 }
62 
63 /*****************************************************************************/
65  (const edm::EventSetup& es,
66  const std::vector<const TrackingRecHit *> & hits,
67  const TrackingRegion & region) const
68 {
69  int nhits = hits.size();
70  if(nhits <2) return 0;
71 
72  declareDynArray(GlobalPoint,nhits, points);
74  declareDynArray(bool,nhits, isBarrel);
75 
76  if (!theField || !theTracker || !theTTRecHitBuilder)
77  {
79  es.get<TrackerDigiGeometryRecord>().get(trackerESH);
80  theTracker = trackerESH.product();
81 
83  es.get<IdealMagneticFieldRecord>().get(fieldESH);
84  theField = fieldESH.product();
85 
87  std::string builderName = theConfig.getParameter<std::string>("TTRHBuilder");
88  es.get<TransientRecHitRecord>().get(builderName,ttrhbESH);
89  theTTRecHitBuilder = ttrhbESH.product();
90  }
91 
92  unsigned int i=0;
93  for (auto const & ih : hits)
94  {
95  auto recHit = theTTRecHitBuilder->build(ih);
96 
97  points[i] = recHit->globalPosition();
98  errors[i] = recHit->globalPositionError();
99  isBarrel[++i] = recHit->detUnit()->type().isBarrel();
100  }
101 
102  CircleFromThreePoints circle = (nhits==2) ?
103  CircleFromThreePoints(GlobalPoint(0.,0.,0.), points[0], points[1]) :
104  CircleFromThreePoints(points[0],points[1],points[2]);
105 
106  int charge = getCharge(points);
107  float curvature = circle.curvature();
108 
109  // pt
110  float invPt = PixelRecoUtilities::inversePt(curvature, es);
111  float valPt = (invPt > 1.e-4) ? 1./invPt : 1.e4;
112  float errPt = 0.055*valPt + 0.017*valPt*valPt;
113 
114  CircleFromThreePoints::Vector2D center = circle.center();
115 
116  // tip
117  float valTip = charge * (center.mag()-1/curvature);
118  // zip
119  float valZip = getZip(valTip, curvature, points[0],points[1]);
120  // phi
121  float valPhi = getPhi(center.x(), center.y(), charge);
122  // cot(theta), update zip
123  float valCotTheta =
124  getCotThetaAndUpdateZip(points[0],points[1], 1/curvature,
125  valPhi,valTip,valZip);
126 
127  // errors
128  float errTip, errZip;
129  getErrTipAndErrZip(valPt, points.back().eta(), errTip,errZip);
130  float errPhi = 0.002;
131  float errCotTheta = 0.002;
132 
133  float chi2 = 0;
134  if(nhits > 2)
135  {
136  RZLine rzLine(points,errors,isBarrel);
137  chi2 = rzLine.chi2();
138  }
139 
140  // build pixel track
141  PixelTrackBuilder builder;
142 
143  Measurement1D pt (valPt, errPt);
144  Measurement1D phi (valPhi, errPhi);
145  Measurement1D cotTheta(valCotTheta, errCotTheta);
146  Measurement1D tip (valTip, errTip);
147  Measurement1D zip (valZip, errZip);
148 
149  return builder.build(pt, phi, cotTheta, tip, zip, chi2,
150  charge, hits, theField);
151 }
152 
153 
154 /*****************************************************************************/
157  float radius, float phi, float d0, float& zip) const
158 {
159  float chi = phi - M_PI_2;
160  GlobalPoint IP(d0*cos(chi), d0*sin(chi),zip);
161 
162  float phi1 = 2*asin(0.5*(inner - IP).perp()/radius);
163  float phi2 = 2*asin(0.5*(outer - IP).perp()/radius);
164 
165  float dr = radius*(phi2 - phi1);
166  float dz = outer.z()-inner.z();
167 
168  // Recalculate ZIP
169  zip = (inner.z()*phi2 - outer.z()*phi1)/(phi2 - phi1);
170 
171  return (fabs(dr) > 1.e-3) ? dz/dr : 0;
172 }
173 
174 /*****************************************************************************/
176  (float xC, float yC, int charge) const
177 {
178  float phiC;
179 
180  if (charge>0) phiC = atan2(xC,-yC);
181  else phiC = atan2(-xC,yC);
182 
183  return phiC;
184 }
185 
186 /*****************************************************************************/
188  (float d0, float curv,
189  const GlobalPoint& inner, const GlobalPoint& outer) const
190 {
191  // phi = asin(r*rho/2) with asin(x) ~= x+x**3/(2*3)
192  float rho3 = curv*curv*curv;
193 
194  float r1 = inner.perp();
195  double phi1 = r1*curv/2 + inner.perp2()*r1*rho3/48.;
196 
197  float r2 = outer.perp();
198  double phi2 = r2*curv/2 + outer.perp2()*r2*rho3/48.;
199 
200  double z1 = inner.z();
201  double z2 = outer.z();
202 
203  return z1 - phi1/(phi1-phi2)*(z1-z2);
204 }
205 
206 /*****************************************************************************/
208  (float pt, float eta, float & errTip, float & errZip) const
209 {
210  float coshEta = cosh(eta);
211 
212  { // transverse
213  float c_ms = 0.0115; //0.0115;
214  float s_le = 0.0095; //0.0123;
215  float s_ms2 = c_ms*c_ms / (pt*pt) * coshEta;
216 
217  errTip = sqrt(s_le*s_le + s_ms2 );
218  }
219 
220  { // z
221  float c_ms = 0.0070;
222  float s_le = 0.0135;
223 
224  errZip = sqrt( (s_le*s_le + c_ms*c_ms/(pt*pt)) * coshEta*coshEta*coshEta);
225  }
226 }
227 
int i
Definition: DBlmapReader.cc:9
tuple cfg
Definition: looper.py:293
T perp() const
Definition: PV3DBase.h:72
bool isBarrel(GeomDetEnumerators::SubDetector m)
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
Geom::Phi< T > phi() const
Definition: PV3DBase.h:69
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
#define M_PI_2
void getErrTipAndErrZip(float pt, float eta, float &errZip, float &errTip) const
Definition: TrackFitter.cc:208
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
T perp2() const
Definition: PV3DBase.h:71
T inversePt(T curvature, const edm::EventSetup &iSetup)
float getZip(float d0, float curv, const GlobalPoint &inner, const GlobalPoint &outer) const
Definition: TrackFitter.cc:188
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
tuple IP
Definition: listHistos.py:76
float getCotThetaAndUpdateZip(const GlobalPoint &inner, const GlobalPoint &outer, float radius, float phi, float d0, float &zip) const
Definition: TrackFitter.cc:156
int getCharge(int phi1, int phi2, int phi3, int phi4, int mode)
T y() const
Cartesian y coordinate.
#define M_PI
Definition: RZLine.h:12
const T & get() const
Definition: EventSetup.h:56
T const * product() const
Definition: ESHandle.h:86
Geom::Phi< T > phi() const
T perp() const
Magnitude of transverse component.
TrackFitter(const edm::ParameterSet &cfg)
Definition: TrackFitter.cc:58
#define declareDynArray(T, n, x)
Definition: DynArray.h:59
float getPhi(float xC, float yC, int charge) const
Definition: TrackFitter.cc:176
float chi2() const
Definition: RZLine.h:97
T x() const
Cartesian x coordinate.
virtual reco::Track * run(const edm::EventSetup &es, const std::vector< const TrackingRecHit * > &hits, const TrackingRegion &region) const
Definition: TrackFitter.cc:65