9 #include "CLHEP/Matrix/Matrix.h"
10 #include "CLHEP/Matrix/SymMatrix.h"
11 #include "CLHEP/Vector/TwoVector.h"
13 #include "streamlog/streamlog.h"
16 namespace LCIOTrackPropagators{
24 const double d0 = ts.
getD0() ;
25 const double phi0 = ts.
getPhi() ;
27 const double z0 = ts.
getZ0() ;
33 const double radius = 1.0/omega ;
35 const double sinPhi0 = sin(phi0) ;
36 const double cosPhi0 = cos(phi0) ;
38 const double deltaX = xref - ref[0] ;
39 const double deltaY = yref - ref[1] ;
41 double phi0Prime = atan2( sinPhi0 - (deltaX/(radius-d0)) , cosPhi0 + (deltaY/(radius-d0)) ) ;
43 while ( phi0Prime < 0 ) phi0Prime += 2.0*
M_PI ;
44 while ( phi0Prime >= 2.0*
M_PI ) phi0Prime -= 2.0*
M_PI ;
46 const double d0Prime = d0 + deltaX*sinPhi0 - deltaY*cosPhi0 + ( ( deltaX*cosPhi0 + deltaY*sinPhi0 ) * tan( (phi0Prime-phi0) / 2.0) ) ;
50 const double sinDeltaPhi = ( -omega / ( 1.0 - ( omega * d0Prime ) ) ) * ( deltaX * cosPhi0 + deltaY * sinPhi0 ) ;
52 const double cosDeltaPhi = 1.0 + ( omega*omega / ( 2.0 * ( 1.0 - omega * d0Prime ) ) ) * ( d0Prime*d0Prime - ( deltaX + d0 * sinPhi0 )*( deltaX + d0 * sinPhi0 ) - ( deltaY - d0 * cosPhi0 )*( deltaY - d0 * cosPhi0 ) ) ;
54 const double s = atan2(-sinDeltaPhi,cosDeltaPhi) / omega ;
56 const double z0Prime = ref[2] - zref + z0 + tanL * s ;
60 CLHEP::HepSymMatrix cov0(5) ;
64 for(
int irow=0; irow<5; ++irow ){
65 for(
int jcol=0; jcol<irow+1; ++jcol){
73 CLHEP::HepMatrix propagatorMatrix(5, 5, 0) ;
78 propagatorMatrix(1,1) = cosDeltaPhi ;
79 propagatorMatrix(1,2) = -( radius - d0 ) * sinDeltaPhi ;
80 propagatorMatrix(1,3) = radius*radius * ( cosDeltaPhi -1 ) ;
83 propagatorMatrix(2,1) = sinDeltaPhi / ( radius - d0Prime ) ;
84 propagatorMatrix(2,2) = ( ( radius - d0 ) * cosDeltaPhi ) / ( radius - d0Prime ) ;
85 propagatorMatrix(2,3) = radius*radius * sinDeltaPhi / ( radius - d0Prime ) ;
88 propagatorMatrix(3,3) = 1.0 ;
91 propagatorMatrix(4,1) = radius * tanL * sinDeltaPhi / ( d0Prime + radius ) ;
92 propagatorMatrix(4,2) = radius * tanL * ( 1.0 - ( ( d0 + radius ) * cosDeltaPhi / ( d0Prime + radius ) ) ) ;
93 propagatorMatrix(4,3) = radius*radius * tanL * ( (phi0Prime - phi0) - radius * sinDeltaPhi / ( d0Prime + radius ) ) ;
94 propagatorMatrix(4,4) = 1.0 ;
95 propagatorMatrix(4,5) = s ;
98 propagatorMatrix(5,5) = 1.0 ;
101 CLHEP::HepSymMatrix covPrime = cov0.similarity(propagatorMatrix);
107 for(
int irow=0; irow<5; ++irow ){
108 for(
int jcol=0; jcol<irow+1; ++jcol){
110 cov[icov] = covPrime[irow][jcol] ;
116 while ( phi0Prime < -
M_PI ) phi0Prime += 2.0*
M_PI ;
117 while ( phi0Prime >=
M_PI ) phi0Prime -= 2.0*
M_PI ;
119 ts.
setD0( d0Prime ) ;
122 ts.
setZ0( z0Prime ) ;
126 float refPointPrime[3] ;
127 refPointPrime[0] = xref ;
128 refPointPrime[1] = yref ;
129 refPointPrime[2] = zref ;
156 const double d0 = ts.
getD0() ;
157 const double z0 = ts.
getZ0() ;
158 const double phi0 = ts.
getPhi() ;
160 const double omega = ts.
getOmega() ;
162 const double rho = 1.0 / omega ;
163 const double x_pca = x_ref - d0 * sin(phi0) ;
164 const double y_pca = y_ref + d0 * cos(phi0) ;
165 const double z_pca = z_ref + z0 ;
167 const double sin_phi0 = sin(phi0);
168 const double cos_phi0 = cos(phi0);
170 const double x_c = x_ref + ( rho - d0) * sin_phi0 ;
171 const double y_c = y_ref - ( rho - d0) * cos_phi0 ;
173 const double r1 = fabs(rho) ;
178 const double dx = x_c - x0;
179 const double dy = y_c - y0;
182 const double d = hypot(dx,dy);
190 if (d < fabs(r0 - r1))
207 const double a = ((r0*r0) - (r1*r1) + (d*d)) / (2.0 * d) ;
210 const double x2 = x0 + (dx * a/d);
211 const double y2 = y0 + (dy * a/d);
216 const double h = sqrt((r0*r0) - (a*a));
221 const double rx = -dy * (h/d);
222 const double ry = dx * (h/d);
225 const double x_ins1 = x2 + rx;
226 const double y_ins1 = y2 + ry;
228 const double x_ins2 = x2 - rx;
229 const double y_ins2 = y2 - ry;
238 const double delta_x1 = x_ins1 - x_pca ;
239 const double delta_y1 = y_ins1 - y_pca ;
241 const double sin_delta_phi1 = - omega*delta_x1*cos_phi0 - omega*delta_y1*sin_phi0 ;
242 const double cos_delta_phi1 = 1.0 - omega*delta_x1*sin_phi0 + omega*delta_y1*cos_phi0 ;
244 s_1 = atan2(-sin_delta_phi1,cos_delta_phi1) / omega ;
247 const double delta_x2 = x_ins2 - x_pca ;
248 const double delta_y2 = y_ins2 - y_pca ;
250 const double sin_delta_phi2 = - omega*delta_x2*cos_phi0 - omega*delta_y2*sin_phi0 ;
251 const double cos_delta_phi2 = 1.0 - omega*delta_x2*sin_phi0 + omega*delta_y2*cos_phi0 ;
253 s_2 = atan2(-sin_delta_phi2,cos_delta_phi2) / omega ;
255 double x=0, y=0, z=0 ;
257 if( direction == 0 ) {
258 if( fabs(s_1) < fabs(s_2) ) {
262 z = z_pca + s_1 * tanl ;
268 z = z_pca + s_2 * tanl ;
274 if ( s_1 < 0.0 ) s_1 += 2.0*
M_PI * r1 ;
275 if ( s_2 < 0.0 ) s_2 += 2.0*
M_PI * r1 ;
277 if( direction == 1 ){
281 z = z_pca + s_1 * tanl ;
286 z = z_pca + s_2 * tanl ;
289 else if(direction == -1) {
293 z = z_pca + s_1 * tanl ;
298 z = z_pca + s_2 * tanl ;
315 const double d0 = ts.
getD0() ;
316 const double z0 = ts.
getZ0() ;
317 const double phi0 = ts.
getPhi() ;
319 const double omega = ts.
getOmega() ;
321 const double x_pca = x_ref - d0 * sin(phi0) ;
322 const double y_pca = y_ref + d0 * cos(phi0) ;
323 const double z_pca = z_ref + z0 ;
326 const double s = ( z - z_pca ) / tanl;
328 const double delta_phi_half = (omega*s)/2.0 ;
330 const double x = x_pca + s * ( sin(delta_phi_half) / delta_phi_half ) * cos( phi0 - delta_phi_half ) ;
331 const double y = y_pca + s * ( sin(delta_phi_half) / delta_phi_half ) * sin( phi0 - delta_phi_half ) ;
346 if( !( direction == 0 || direction == 1 || direction == -1) )
return -1 ;
354 const double d0 = ts.
getD0() ;
355 const double z0 = ts.
getZ0() ;
356 const double phi0 = ts.
getPhi() ;
358 const double omega = ts.
getOmega() ;
360 const double rho = 1.0 / omega ;
361 const double x_pca = x_ref - d0 * sin(phi0) ;
362 const double y_pca = y_ref + d0 * cos(phi0) ;
363 const double z_pca = z_ref + z0 ;
365 const double sin_phi0 = sin(phi0);
366 const double cos_phi0 = cos(phi0);
368 const double x_c = x_ref + ( rho - d0) * sin_phi0 ;
369 const double y_c = y_ref - ( rho - d0) * cos_phi0 ;
371 const double dx = x2 - x1 ;
372 const double dy = y2 - y1 ;
374 const double a = dx * dx + dy * dy ;
376 const double b = 2.0 * ( dx * (x1 - x_c) + dy * (y1 - y_c) ) ;
378 double c = x_c * x_c + y_c * y_c;
379 c += x1 * x1 + y1 * y1 ;
381 c -= 2.0 * ( x_c * x1 + y_c * y1 );
384 const double bb4ac = b * b - 4.0 * a * c;
390 if (bb4ac + epsilon < 0.0 ) {
393 else if(bb4ac - epsilon < 0.0) {
397 u1 = (-b + sqrt(bb4ac)) / (2.0 * a);
398 u2 = (-b - sqrt(bb4ac)) / (2.0 * a);
401 const double x_ins1 = x1 + u1 * (dx) ;
402 const double y_ins1 = y1 + u1 * (dy) ;
404 const double x_ins2 = x1 + u2 * (dx) ;
405 const double y_ins2 = y1 + u2 * (dy) ;
416 const double delta_x1 = x_ins1 - x_pca ;
417 const double delta_y1 = y_ins1 - y_pca ;
419 const double sin_delta_phi1 = - omega*delta_x1*cos_phi0 - omega*delta_y1*sin_phi0 ;
420 const double cos_delta_phi1 = 1.0 - omega*delta_x1*sin_phi0 + omega*delta_y1*cos_phi0 ;
422 s_1 = atan2(-sin_delta_phi1,cos_delta_phi1) / omega ;
424 const double delta_x2 = x_ins2 - x_pca ;
425 const double delta_y2 = y_ins2 - y_pca ;
427 const double sin_delta_phi2 = - omega*delta_x2*cos_phi0 - omega*delta_y2*sin_phi0 ;
428 const double cos_delta_phi2 = 1.0 - omega*delta_x2*sin_phi0 + omega*delta_y2*cos_phi0 ;
430 s_2 = atan2(-sin_delta_phi2,cos_delta_phi2) / omega ;
432 double x(0.0), y(0.0), z(0.0) ;
434 if( direction == 0 ) {
435 if( fabs(s_1) < fabs(s_2) ) {
439 z = z_pca + s_1 * tanl ;
445 z = z_pca + s_2 * tanl ;
451 if ( s_1 < 0.0 ) s_1 += 2.0*
M_PI * fabs(rho) ;
452 if ( s_2 < 0.0 ) s_2 += 2.0*
M_PI * fabs(rho) ;
454 if( direction == 1 ){
459 z = z_pca + s_1 * tanl ;
465 z = z_pca + s_2 * tanl ;
468 else if( direction == -1 ) {
473 z = z_pca + s_1 * tanl ;
479 z = z_pca + s_2 * tanl ;
virtual float getZ0() const
virtual void setD0(float d0)
virtual float getOmega() const
virtual void setTanLambda(float tanLambda)
virtual void setReferencePoint(const float *rPnt)
virtual void setCovMatrix(const float *cov)
int PropagateLCIOToPlaneParralelToZ(IMPL::TrackStateImpl &ts, float x1, float y1, float x2, float y2, int direction=0, double epsilon=1.0e-8)
Propagate trackstate to a new reference point taken as its crossing point with a plane parallel to th...
virtual float getTanLambda() const
virtual float getD0() const
virtual void setZ0(float z0)
virtual const float * getReferencePoint() const
int PropagateLCIOToCylinder(IMPL::TrackStateImpl &ts, float r, float x0, float y0, int direction=0, double epsilon=1.0e-8)
Propagate trackstate to a new reference point taken as its crossing point with a cylinder of infinite...
virtual void setPhi(float phi)
virtual const EVENT::FloatVec & getCovMatrix() const
int PropagateLCIOToNewRef(IMPL::TrackStateImpl &ts, double xref, double yref, double zref)
Propagate trackstate to a new reference point.
int PropagateLCIOToZPlane(IMPL::TrackStateImpl &ts, float z)
Propagate trackstate to a new reference point taken as its crossing point with an infinite plane loca...
virtual void setOmega(float omega)
virtual float getPhi() const