ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitCommon/MathTools/interface/Helix.h
Revision: 1.1
Committed: Wed Sep 17 04:01:50 2008 UTC (16 years, 7 months ago) by loizides
Content type: text/plain
Branch: MAIN
CVS Tags: Mit_008pre2, Mit_008pre1, Mit_006b, Mit_006a, Mit_006, Mit_005, Mit_004
Log Message:
Moved MitVertex contents to MitCommon. MitVertex therefore is obsolute and should not be touched anymore.

File Contents

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