1 |
loizides |
1.1 |
//--------------------------------------------------------------------------------------------------
|
2 |
loizides |
1.3 |
// $Id: Helix.h,v 1.2 2009/03/20 13:33:19 loizides Exp $
|
3 |
loizides |
1.1 |
//
|
4 |
|
|
// Class Helix
|
5 |
|
|
//
|
6 |
loizides |
1.3 |
// Implementation of a general helix class with a set of tools for working with objects like
|
7 |
loizides |
1.1 |
// tracks and finding intersections (vertices).
|
8 |
|
|
//
|
9 |
loizides |
1.2 |
// Author: C.Paus (stolen and adjusted from CDF implementation of Kurt Rinnert,
|
10 |
|
|
// therefore not all our coding conventions fulfilled)
|
11 |
loizides |
1.1 |
//--------------------------------------------------------------------------------------------------
|
12 |
|
|
|
13 |
|
|
#ifndef MITCOMMON_MATHTOOLS_HELIX_H
|
14 |
|
|
#define MITCOMMON_MATHTOOLS_HELIX_H
|
15 |
|
|
|
16 |
|
|
#include <TVector.h>
|
17 |
|
|
#include <TVector3.h>
|
18 |
|
|
#include "MitCommon/MathTools/interface/Angle.h"
|
19 |
|
|
|
20 |
|
|
namespace mithep {
|
21 |
|
|
class Helix {
|
22 |
|
|
|
23 |
|
|
public:
|
24 |
|
|
|
25 |
|
|
// Constructor
|
26 |
|
|
inline Helix();
|
27 |
|
|
|
28 |
|
|
// Construct a helix in various ways
|
29 |
|
|
Helix(const TVector3 &mom, const TVector3 &pos, double q, double Field);
|
30 |
|
|
inline Helix(const Helix &right);
|
31 |
|
|
inline Helix(double cotTheta, double curvature, double z0, double d0, Angle phi0);
|
32 |
|
|
static Helix create(const TVector & v);
|
33 |
|
|
|
34 |
|
|
// Destructor
|
35 |
|
|
virtual ~Helix();
|
36 |
|
|
|
37 |
|
|
// Operators
|
38 |
|
|
inline const Helix & operator=(const Helix &right);
|
39 |
|
|
bool operator == (const Helix & right) const;
|
40 |
|
|
bool operator != (const Helix & right) const;
|
41 |
|
|
|
42 |
|
|
inline void SetParameters(const TVector &p);
|
43 |
|
|
inline const TVector &Parameters() const;
|
44 |
|
|
inline void SetCotTheta(double cotTheta);
|
45 |
|
|
inline void SetCurvature(double curvature);
|
46 |
|
|
inline void SetZ0(double z0);
|
47 |
|
|
inline void SetD0(double d0);
|
48 |
|
|
inline void SetPhi0(Angle phi0);
|
49 |
|
|
|
50 |
|
|
virtual TVector3 Position(double s = 0.0) const;
|
51 |
|
|
virtual TVector3 Direction(double s = 0.0) const;
|
52 |
|
|
// the second derivative of the helix vs (three-dimensional) path length
|
53 |
|
|
virtual TVector3 SecondDerivative(double s = 0.0) const;
|
54 |
|
|
// Get pathlength at fixed rho=sqrt(x^2 + y^2)
|
55 |
|
|
virtual double PathLengthAtRhoEquals(double rho) const;
|
56 |
|
|
|
57 |
|
|
// Get certain parameters as a function of two-dimensional R.
|
58 |
|
|
Angle PhiAtR(double r) const;
|
59 |
|
|
double ZAtR(double r) const;
|
60 |
|
|
double L2DAtR(double r) const;
|
61 |
|
|
double CosAlphaAtR(double r) const;
|
62 |
|
|
double InverseRadius() const;
|
63 |
|
|
double Radius() const;
|
64 |
|
|
SignedAngle TurningAngle(double s) const; // turning angle as function of path length
|
65 |
|
|
double Curvature() const;
|
66 |
|
|
double Helicity() const; // helicity, positive = counterclockwise
|
67 |
|
|
double CotTheta() const;
|
68 |
|
|
Angle Phi0() const;
|
69 |
|
|
double D0() const;
|
70 |
|
|
double Z0() const;
|
71 |
|
|
double SignLz() const;
|
72 |
|
|
double SinPhi0() const;
|
73 |
|
|
double CosPhi0() const;
|
74 |
|
|
double SinTheta() const;
|
75 |
|
|
double CosTheta() const;
|
76 |
|
|
static unsigned int ParameterSpaceSize() { return 5; }
|
77 |
|
|
|
78 |
|
|
//============================================================================================
|
79 |
|
|
// KCDF: analytical computation of helix/plane intersection.
|
80 |
|
|
//
|
81 |
|
|
// What we really compute is the intersection of a line and a circle (projected helix)
|
82 |
|
|
// in the x-y plane.
|
83 |
|
|
//
|
84 |
|
|
// >>>>>>>>>> W A R N I N G W A R N I N G W A R N I N G <<<<<<<<<<
|
85 |
|
|
// > <
|
86 |
|
|
// > We assume the plane to be parallel or perpendicular <
|
87 |
|
|
// > to the z axis (i.e. the B-field), <
|
88 |
|
|
// > since otherwise there is no analytical solution. (One would end up <
|
89 |
|
|
// > with an equation of type cos(alpha) == alpha.) <
|
90 |
|
|
// > Although we know this assumption doesn´t hold exactly, we think it <
|
91 |
|
|
// > is a reasonable first approximation. <
|
92 |
|
|
// > In cases when our assumption has to be dropped, one can use the <
|
93 |
|
|
// > intersection point computed here as a *good* starting point of a <
|
94 |
|
|
// > numerical method, or one uses another analytical method to compute <
|
95 |
|
|
// > the intersection of the tangent line at the point and the plane. <
|
96 |
|
|
// > We plan to use one of these approaches in the near future, but <
|
97 |
|
|
// > this is NOT YET IMPLEMENTED! <
|
98 |
|
|
// > For the time being, we invoke the old numerical <
|
99 |
|
|
// > Trajectory::newIntersectionWith in such circumstances. <
|
100 |
|
|
// > <
|
101 |
|
|
// >>>>>>>>>> W A R N I N G W A R N I N G W A R N I N G <<<<<<<<<<
|
102 |
|
|
//
|
103 |
|
|
// Kurt Rinnert, 08/31/1998
|
104 |
|
|
//============================================================================================
|
105 |
|
|
//Location* newIntersectionWith(const HepPlane3D& plane) const;
|
106 |
|
|
|
107 |
|
|
private:
|
108 |
|
|
// This is the Helix
|
109 |
|
|
double fCotTheta;
|
110 |
|
|
double fCurvature;
|
111 |
|
|
double fZ0;
|
112 |
|
|
double fD0;
|
113 |
|
|
Angle fPhi0;
|
114 |
|
|
|
115 |
|
|
// This is the cache
|
116 |
|
|
mutable TVector *fVParameters;
|
117 |
|
|
mutable bool fIsStale;
|
118 |
|
|
mutable double fSinPhi0;
|
119 |
|
|
mutable double fCosPhi0;
|
120 |
|
|
mutable double fSinTheta;
|
121 |
|
|
mutable double fCosTheta;
|
122 |
|
|
mutable double fS;
|
123 |
|
|
mutable double fAa;
|
124 |
|
|
mutable double fSs;
|
125 |
|
|
mutable double fCc;
|
126 |
|
|
mutable bool fCenterIsValid; //needed by newIntersectionWith KR
|
127 |
|
|
mutable double fMx;
|
128 |
|
|
mutable double fMy;
|
129 |
|
|
|
130 |
|
|
// Needed whenever fSinPhi0, fCosPh0, fSinTheta, or fCosTheta is used.
|
131 |
|
|
inline void fRefreshCache() const;
|
132 |
|
|
|
133 |
|
|
// Needed whenever fSs or fCc are used.
|
134 |
|
|
inline void fCacheSinesAndCosines(double s) const;
|
135 |
loizides |
1.3 |
|
136 |
|
|
ClassDef(Helix, 0) // General helix class
|
137 |
loizides |
1.1 |
};
|
138 |
|
|
}
|
139 |
|
|
|
140 |
loizides |
1.2 |
//--------------------------------------------------------------------------------------------------
|
141 |
loizides |
1.1 |
inline
|
142 |
loizides |
1.2 |
void mithep::Helix::fRefreshCache() const
|
143 |
|
|
{
|
144 |
|
|
// Update fSinTheta,fCosTheta,fSinPhi0, and fCosPhi0
|
145 |
|
|
|
146 |
loizides |
1.1 |
if (fIsStale) {
|
147 |
|
|
fIsStale=false;
|
148 |
|
|
double theta;
|
149 |
|
|
if ( fCotTheta==0.0 ) {
|
150 |
|
|
theta = M_PI/2.0;
|
151 |
|
|
}
|
152 |
|
|
else {
|
153 |
|
|
theta=atan(1.0/fCotTheta);
|
154 |
|
|
if (theta<0.0) theta+=M_PI;
|
155 |
|
|
}
|
156 |
|
|
if (theta==0.0) {
|
157 |
|
|
fSinTheta=0.0;
|
158 |
|
|
fCosTheta=1.0;
|
159 |
|
|
}
|
160 |
|
|
else {
|
161 |
|
|
fCosTheta=cos(theta);
|
162 |
|
|
fSinTheta=sqrt(1-fCosTheta*fCosTheta);
|
163 |
|
|
}
|
164 |
|
|
if (fPhi0==0.0) {
|
165 |
|
|
fSinPhi0=0.0;
|
166 |
|
|
fCosPhi0=1.0;
|
167 |
|
|
}
|
168 |
|
|
else {
|
169 |
|
|
fCosPhi0 = cos(fPhi0);
|
170 |
|
|
fSinPhi0 = sqrt(1.0-fCosPhi0*fCosPhi0);
|
171 |
|
|
if (fPhi0>M_PI) fSinPhi0 = -fSinPhi0;
|
172 |
|
|
}
|
173 |
|
|
}
|
174 |
|
|
}
|
175 |
|
|
|
176 |
loizides |
1.2 |
//--------------------------------------------------------------------------------------------------
|
177 |
loizides |
1.1 |
inline
|
178 |
loizides |
1.2 |
void mithep::Helix::fCacheSinesAndCosines(double s) const
|
179 |
|
|
{
|
180 |
|
|
// Update fS, fAa, fSs, and fCc if the arclength has changed.
|
181 |
|
|
|
182 |
loizides |
1.1 |
fRefreshCache();
|
183 |
|
|
if (fS!=s){
|
184 |
|
|
fS=s;
|
185 |
|
|
fAa=2.0*fS*fCurvature*fSinTheta;
|
186 |
|
|
if (fAa==0.0) {
|
187 |
|
|
fSs=0.0;
|
188 |
|
|
fCc=1.0;
|
189 |
|
|
}
|
190 |
|
|
else {
|
191 |
|
|
fSs=sin(fAa);
|
192 |
|
|
fCc=cos(fAa);
|
193 |
|
|
}
|
194 |
|
|
}
|
195 |
|
|
}
|
196 |
|
|
|
197 |
|
|
|
198 |
loizides |
1.2 |
//--------------------------------------------------------------------------------------------------
|
199 |
loizides |
1.1 |
inline
|
200 |
|
|
mithep::Helix::Helix() :
|
201 |
|
|
fCotTheta(0.0),
|
202 |
|
|
fCurvature(0.0),
|
203 |
|
|
fZ0(0.0),
|
204 |
|
|
fD0(0.0),
|
205 |
|
|
fPhi0(0.0),
|
206 |
|
|
fVParameters(0),
|
207 |
|
|
fIsStale(1),
|
208 |
|
|
fSinPhi0(2),
|
209 |
|
|
fCosPhi0(2),
|
210 |
|
|
fSinTheta(2),
|
211 |
|
|
fCosTheta(2),
|
212 |
|
|
fS(-999.999),
|
213 |
|
|
fAa(2),
|
214 |
|
|
fSs(2),
|
215 |
|
|
fCc(2),
|
216 |
|
|
fCenterIsValid(false),
|
217 |
|
|
fMx(0.0),
|
218 |
|
|
fMy(0.0)
|
219 |
|
|
{
|
220 |
|
|
}
|
221 |
|
|
|
222 |
loizides |
1.2 |
//--------------------------------------------------------------------------------------------------
|
223 |
loizides |
1.1 |
inline
|
224 |
|
|
mithep::Helix::Helix(const Helix &right) :
|
225 |
|
|
fCotTheta(right.fCotTheta),
|
226 |
|
|
fCurvature(right.fCurvature),
|
227 |
|
|
fZ0(right.fZ0),
|
228 |
|
|
fD0(right.fD0),
|
229 |
|
|
fPhi0(right.fPhi0),
|
230 |
|
|
fVParameters(0),
|
231 |
|
|
fIsStale(right.fIsStale),
|
232 |
|
|
fSinPhi0(right.fSinPhi0),
|
233 |
|
|
fCosPhi0(right.fCosPhi0),
|
234 |
|
|
fSinTheta(right.fSinTheta),
|
235 |
|
|
fCosTheta(right.fCosTheta),
|
236 |
|
|
fS(right.fS),
|
237 |
|
|
fAa(right.fAa),
|
238 |
|
|
fSs(right.fSs),
|
239 |
|
|
fCc(right.fCc),
|
240 |
|
|
fCenterIsValid(right.fCenterIsValid),
|
241 |
|
|
fMx(right.fMx),
|
242 |
|
|
fMy(right.fMy)
|
243 |
|
|
{
|
244 |
|
|
if (right.fVParameters)
|
245 |
|
|
fVParameters=new TVector(*(right.fVParameters));
|
246 |
|
|
}
|
247 |
|
|
|
248 |
loizides |
1.2 |
//--------------------------------------------------------------------------------------------------
|
249 |
loizides |
1.1 |
inline
|
250 |
|
|
mithep::Helix::Helix(double cotTheta,double curvature,double z0,double d0, Angle phi0) :
|
251 |
|
|
fCotTheta(cotTheta),
|
252 |
|
|
fCurvature(curvature),
|
253 |
|
|
fZ0(z0),
|
254 |
|
|
fD0(d0),
|
255 |
|
|
fPhi0(phi0),
|
256 |
|
|
fVParameters(0),
|
257 |
|
|
fIsStale(1),
|
258 |
|
|
fSinPhi0(2),
|
259 |
|
|
fCosPhi0(2),
|
260 |
|
|
fSinTheta(2),
|
261 |
|
|
fCosTheta(2),
|
262 |
|
|
fS(-999.999),
|
263 |
|
|
fAa(2),
|
264 |
|
|
fSs(2),
|
265 |
|
|
fCc(2),
|
266 |
|
|
fCenterIsValid(false),
|
267 |
|
|
fMx(0.0),
|
268 |
|
|
fMy(0.0)
|
269 |
|
|
{
|
270 |
|
|
}
|
271 |
|
|
|
272 |
loizides |
1.2 |
//--------------------------------------------------------------------------------------------------
|
273 |
loizides |
1.1 |
inline
|
274 |
|
|
const mithep::Helix & mithep::Helix::operator=(const mithep::Helix &right)
|
275 |
|
|
{
|
276 |
loizides |
1.2 |
// Assign helix and cache
|
277 |
|
|
|
278 |
loizides |
1.1 |
if (this != &right) {
|
279 |
|
|
fCotTheta=right.fCotTheta;
|
280 |
|
|
fCurvature=right.fCurvature;
|
281 |
|
|
fZ0=right.fZ0;
|
282 |
|
|
fD0=right.fD0;
|
283 |
|
|
fPhi0=right.fPhi0;
|
284 |
|
|
fIsStale= right.fIsStale;
|
285 |
|
|
fSinTheta=right.fSinTheta;
|
286 |
|
|
fCosTheta=right.fCosTheta;
|
287 |
|
|
fSinPhi0=right.fSinPhi0;
|
288 |
|
|
fCosPhi0=right.fCosPhi0;
|
289 |
|
|
fS=right.fS;
|
290 |
|
|
fAa=right.fAa;
|
291 |
|
|
fSs=right.fSs;
|
292 |
|
|
fCc=right.fCc;
|
293 |
|
|
if (fVParameters)
|
294 |
|
|
delete fVParameters;
|
295 |
|
|
fVParameters=0;
|
296 |
|
|
if (right.fVParameters)
|
297 |
|
|
fVParameters = new TVector(*(right.fVParameters));
|
298 |
|
|
fCenterIsValid = right.fCenterIsValid;
|
299 |
|
|
fMx = right.fMx;
|
300 |
|
|
fMy = right.fMy;
|
301 |
|
|
}
|
302 |
|
|
return *this;
|
303 |
|
|
}
|
304 |
|
|
|
305 |
loizides |
1.2 |
//--------------------------------------------------------------------------------------------------
|
306 |
loizides |
1.1 |
inline
|
307 |
|
|
void mithep::Helix::SetCotTheta(double cotTheta)
|
308 |
|
|
{
|
309 |
|
|
fCotTheta=cotTheta;
|
310 |
|
|
fIsStale=true;
|
311 |
|
|
}
|
312 |
|
|
|
313 |
loizides |
1.2 |
//--------------------------------------------------------------------------------------------------
|
314 |
loizides |
1.1 |
inline
|
315 |
|
|
void mithep::Helix::SetZ0(double z0)
|
316 |
|
|
{
|
317 |
|
|
fZ0 = z0;
|
318 |
|
|
fIsStale=true;
|
319 |
|
|
}
|
320 |
|
|
|
321 |
loizides |
1.2 |
//--------------------------------------------------------------------------------------------------
|
322 |
loizides |
1.1 |
inline
|
323 |
|
|
void mithep::Helix::SetCurvature(double curvature)
|
324 |
|
|
{
|
325 |
|
|
fCurvature=curvature;
|
326 |
|
|
fIsStale=true;
|
327 |
|
|
}
|
328 |
|
|
|
329 |
loizides |
1.2 |
//--------------------------------------------------------------------------------------------------
|
330 |
loizides |
1.1 |
inline
|
331 |
|
|
void mithep::Helix::SetD0(double d0)
|
332 |
|
|
{
|
333 |
|
|
fD0=d0;
|
334 |
|
|
fIsStale=true;
|
335 |
|
|
}
|
336 |
|
|
|
337 |
loizides |
1.2 |
//--------------------------------------------------------------------------------------------------
|
338 |
loizides |
1.1 |
inline
|
339 |
|
|
void mithep::Helix::SetPhi0(Angle phi0)
|
340 |
|
|
{
|
341 |
|
|
fPhi0=phi0;
|
342 |
|
|
fIsStale=true;
|
343 |
|
|
}
|
344 |
|
|
|
345 |
loizides |
1.2 |
//--------------------------------------------------------------------------------------------------
|
346 |
loizides |
1.1 |
inline
|
347 |
|
|
void mithep::Helix::SetParameters(const TVector &p)
|
348 |
|
|
{
|
349 |
|
|
// Check we're getting a sensible vector
|
350 |
|
|
if (p.GetNrows() < 5) {
|
351 |
|
|
return;
|
352 |
|
|
}
|
353 |
|
|
SetCotTheta(p[0]);
|
354 |
|
|
SetCurvature(p[1]);
|
355 |
|
|
SetZ0(p[2]);
|
356 |
|
|
SetD0(p[3]);
|
357 |
|
|
SetPhi0(p[4]);
|
358 |
|
|
fIsStale = true;
|
359 |
|
|
}
|
360 |
|
|
|
361 |
loizides |
1.2 |
//--------------------------------------------------------------------------------------------------
|
362 |
loizides |
1.1 |
inline
|
363 |
|
|
const TVector & mithep::Helix::Parameters() const
|
364 |
|
|
{
|
365 |
|
|
if (!fVParameters)
|
366 |
|
|
fVParameters = new TVector(5);
|
367 |
|
|
(*fVParameters)(1)=CotTheta();
|
368 |
|
|
(*fVParameters)(2)=Curvature();
|
369 |
|
|
(*fVParameters)(3)=Z0();
|
370 |
|
|
(*fVParameters)(4)=D0();
|
371 |
|
|
(*fVParameters)(5)=Phi0();
|
372 |
|
|
return *fVParameters;;
|
373 |
|
|
}
|
374 |
|
|
|
375 |
loizides |
1.2 |
//--------------------------------------------------------------------------------------------------
|
376 |
loizides |
1.1 |
inline
|
377 |
loizides |
1.2 |
mithep::Helix mithep::Helix::create(const TVector & v)
|
378 |
|
|
{
|
379 |
loizides |
1.1 |
return mithep::Helix(v(1),v(2),v(3),v(4),v(5));
|
380 |
|
|
}
|
381 |
|
|
#endif
|