BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
TrkCircleTraj.cxx
Go to the documentation of this file.
1//--------------------------------------------------------------------------
2// File and Version Information:
3// $Id: TrkCircleTraj.cxx,v 1.4 2006/03/31 07:29:23 zhangy Exp $
4//
5// Description:
6//
7// Environment:
8// Software developed for the BaBar Detector at the SLAC B-Factory.
9//
10// Author(s): Steve Schaffner
11//------------------------------------------------------------------------
12#include "TrkFitter/TrkCircleTraj.h"
13#include "MdcGeom/BesAngle.h"
14#include "MdcGeom/Constants.h"
15#include "MdcRecoUtil/DifNumber.h"
16#include "MdcRecoUtil/DifPoint.h"
17#include "MdcRecoUtil/DifVector.h"
18#include "TrkBase/TrkExchangePar.h"
19#include "TrkBase/TrkVisitor.h"
20#include <assert.h>
21#include <math.h>
22//
23// Fix for some machines
24//
25#ifndef M_2PI
26# define M_2PI 2 * M_PI
27#endif
28using CLHEP::Hep3Vector;
29using CLHEP::HepSymMatrix;
30
31//-----------------------------------------------------------------
32TrkCircleTraj::TrkCircleTraj( const HepVector& pvec, const HepSymMatrix& pcov, double lowlim,
33 double hilim, const HepPoint3D& refpoint )
34 : TrkSimpTraj( pvec, pcov, lowlim, hilim, refpoint )
35//-----------------------------------------------------------------
36{
37 // Make sure the dimensions of the input matrix and vector are correct
38 if ( pvec.num_row() != nCirPrm() || pcov.num_row() != nCirPrm() )
39 {
40 std::cout << "ErrMsg(fatal)"
41 << "CircleTraj: incorrect constructor vector/matrix dimension" << std::endl;
42 }
43
44 if ( omega() == 0.0 ) parameters()->parameter()[omegaIndex()] = 1.e-9;
45}
46
47//-----------------------------------------------------------------
48TrkCircleTraj::TrkCircleTraj( const TrkExchangePar& inpar, double lowlim, double hilim,
49 const HepPoint3D& refpoint )
50 : TrkSimpTraj( inpar.params(), inpar.covariance(), lowlim, hilim, refpoint ) {
51 //-----------------------------------------------------------------
52
53 if ( omega() == 0.0 ) parameters()->parameter()[omegaIndex()] = 1.e-9;
54}
55
57 : TrkSimpTraj( h.parameters()->parameter(), h.parameters()->covariance(), h.lowRange(),
58 h.hiRange(), h.referencePoint() ) {}
59
60TrkCircleTraj* TrkCircleTraj::clone() const { return new TrkCircleTraj( *this ); }
61
63 if ( &h != this )
64 {
66 _dtparams = *( h.parameters() );
68 }
69 return *this;
70}
71
73
74double TrkCircleTraj::x( const double& f ) const {
75 double sphi0 = sin( phi0() );
76 return ( sin( angle( f ) ) - sphi0 ) / omega() - d0() * sphi0 + referencePoint().x();
77}
78
79double TrkCircleTraj::y( const double& f ) const {
80 double cphi0 = cos( phi0() );
81 return -( cos( angle( f ) ) - cphi0 ) / omega() + d0() * cphi0 + referencePoint().y();
82}
83
85 double sphi0 = sin( phi0() );
86 double cphi0 = cos( phi0() );
87 double ang = angle( f );
88 double xt = ( sin( ang ) - sphi0 ) / omega() - d0() * sphi0 + referencePoint().x();
89 double yt = -( cos( ang ) - cphi0 ) / omega() + d0() * cphi0 + referencePoint().y();
90 return HepPoint3D( xt, yt, referencePoint().z() );
91}
92
93Hep3Vector TrkCircleTraj::direction( double f ) const {
94 // Angle formed by tangent vector after
95 // being rotated 'arclength' around orbit.
96 double alpha = angle( f );
97 // Construct 3-D tangent vector of unit magnitude.
98 return Hep3Vector( cos( alpha ), sin( alpha ), 0.0 );
99}
100
101Hep3Vector TrkCircleTraj::delDirect( double fltLen ) const {
102 double delX = -omega() * sin( angle( fltLen ) );
103 double delY = omega() * cos( angle( fltLen ) );
104 return Hep3Vector( delX, delY, 0.0 );
105}
106
107double TrkCircleTraj::distTo1stError( double, double tol, int ) const {
108 double arg = 2. * tol / fabs( omega() );
109 assert( arg >= 0. );
110 return sqrt( arg );
111}
112
113double TrkCircleTraj::distTo2ndError( double, double tol, int ) const {
114 // return pow(6.*tol / sqr(omega()), 0.33333333);//yzhang changed sqr
115 return pow( 6. * tol / ( omega() * omega() ), 0.33333333 );
116}
117
118void TrkCircleTraj::getInfo( double flt, HepPoint3D& pos, Hep3Vector& dir,
119 Hep3Vector& delDir ) const {
120 double sphi0 = sin( phi0() );
121 double cphi0 = cos( phi0() );
122 double ang = angle( flt );
123 double cang = cos( ang );
124 double sang = sin( ang );
125 double xt = ( sang - sphi0 ) / omega() - d0() * sphi0 + referencePoint().x();
126 double yt = -( cang - cphi0 ) / omega() + d0() * cphi0 + referencePoint().y();
127
128 pos.setX( xt );
129 pos.setY( yt );
130 pos.setZ( referencePoint().z() );
131
132 dir.setX( cang );
133 dir.setY( sang );
134 dir.setZ( 0.0 );
135
136 delDir.setX( -omega() * sang );
137 delDir.setY( omega() * cang );
138 delDir.setZ( 0. );
139}
140
141void TrkCircleTraj::getInfo( double fltLen, HepPoint3D& pos, Hep3Vector& dir ) const {
142 double sphi0 = sin( phi0() );
143 double cphi0 = cos( phi0() );
144 double ang = angle( fltLen );
145 double cang = cos( ang );
146 double sang = sin( ang );
147 double xt = ( sang - sphi0 ) / omega() - d0() * sphi0 + referencePoint().x();
148 double yt = -( cang - cphi0 ) / omega() + d0() * cphi0 + referencePoint().y();
149
150 pos.setX( xt );
151 pos.setY( yt );
152 pos.setZ( referencePoint().z() );
153
154 dir.setX( cang );
155 dir.setY( sang );
156 dir.setZ( 0.0 );
157}
158
159void TrkCircleTraj::getDFInfo2( double fltLen, DifPoint& pos, DifVector& dir ) const {
160 // Provides difNum version of information for calculation of derivatives.
161
162 // Create difNumber versions of parameters
163 DifNumber phi0Df( phi0(), phi0Index() + 1, nCirPrm() );
164 DifNumber d0Df( d0(), d0Index() + 1, nCirPrm() );
165 DifNumber omegaDf( omega(), omegaIndex() + 1, nCirPrm() );
166 phi0Df.setIndepPar( parameters() );
167 d0Df.setIndepPar( parameters() );
168 omegaDf.setIndepPar( parameters() );
169
170 DifNumber sinPhi0, cosPhi0;
171 phi0Df.cosAndSin( cosPhi0, sinPhi0 );
172
173 DifNumber alphaDf = omegaDf;
174 alphaDf *= fltLen;
175 alphaDf += phi0Df;
176
177 // This is not the prettiest line imaginable for this operation:
178 alphaDf.mod( -Constants::pi, Constants::pi );
179 DifNumber sinAlpha, cosAlpha;
180 alphaDf.cosAndSin( cosAlpha, sinAlpha );
181
182 // DifNumber x = (sinAlpha - sinPhi0) / omegaDf - d0Df * sinPhi0 + px;
183 // DifNumber y = -(cosAlpha - cosPhi0) / omegaDf + d0Df * cosPhi0 + py;
184
185 DifNumber x = sinAlpha;
186 x -= sinPhi0;
187 x /= omegaDf;
188 x -= ( d0Df * sinPhi0 );
189
190 DifNumber y = -cosAlpha;
191 y += cosPhi0;
192 y /= omegaDf;
193 y += ( d0Df * cosPhi0 );
194
195 static DifNumber zNull( 0. );
196
197 pos.x = x;
198 pos.y = y;
199 pos.z = zNull;
200
201 bool lref = ( referencePoint().x() != 0. || referencePoint().y() != 0. ||
202 referencePoint().z() != 0. );
203 if ( lref )
204 {
205 DifNumber px( referencePoint().x() );
206 DifNumber py( referencePoint().y() );
207 DifNumber pz( referencePoint().z() );
208 pos.x += px;
209 pos.y += py;
210 pos.z += pz;
211 }
212
213 dir.x = cosAlpha;
214 dir.y = sinAlpha;
215 dir.z = 0.;
216}
217
218void TrkCircleTraj::getDFInfo( double flt, DifPoint& pos, DifVector& dir,
219 DifVector& delDir ) const {
220 // Provides difNum version of information for calculation of derivatives.
221
222 // Create difNumber versions of parameters
223 DifNumber phi0Df( phi0(), phi0Index() + 1, nCirPrm() );
224 DifNumber d0Df( d0(), d0Index() + 1, nCirPrm() );
225 DifNumber omegaDf( omega(), omegaIndex() + 1, nCirPrm() );
226 phi0Df.setIndepPar( parameters() );
227 d0Df.setIndepPar( parameters() );
228 omegaDf.setIndepPar( parameters() );
229
230 DifNumber sinPhi0, cosPhi0;
231 phi0Df.cosAndSin( cosPhi0, sinPhi0 );
232
233 DifNumber alphaDf = omegaDf;
234 alphaDf *= flt;
235 alphaDf += phi0Df;
236
237 // This is not the prettiest line imaginable for this operation:
238 alphaDf.mod( -Constants::pi, Constants::pi );
239 DifNumber sinAlpha, cosAlpha;
240 alphaDf.cosAndSin( cosAlpha, sinAlpha );
241
242 // DifNumber x = (sinAlpha - sinPhi0) / omegaDf - d0Df * sinPhi0 + px;
243 // DifNumber y = -(cosAlpha - cosPhi0) / omegaDf + d0Df * cosPhi0 + py;
244
245 DifNumber x = sinAlpha;
246 x -= sinPhi0;
247 x /= omegaDf;
248 x -= ( d0Df * sinPhi0 );
249
250 DifNumber y = -cosAlpha;
251 y += cosPhi0;
252 y /= omegaDf;
253 y += ( d0Df * cosPhi0 );
254
255 static DifNumber zNull( 0. );
256
257 pos.x = x;
258 pos.y = y;
259 pos.z = zNull;
260
261 bool lref = ( referencePoint().x() != 0. || referencePoint().y() != 0. ||
262 referencePoint().z() != 0. );
263 if ( lref )
264 {
265 DifNumber px( referencePoint().x() );
266 DifNumber py( referencePoint().y() );
267 DifNumber pz( referencePoint().z() );
268 pos.x += px;
269 pos.y += py;
270 pos.z += pz;
271 }
272
273 dir.x = cosAlpha;
274 dir.y = sinAlpha;
275 dir.z = 0.;
276
277 delDir.x = -omegaDf;
278 delDir.x *= sinAlpha;
279
280 delDir.y = omegaDf;
281 delDir.y *= cosAlpha;
282
283 delDir.z = 0.;
284}
285HepMatrix TrkCircleTraj::derivDeflect( double fltlen, deflectDirection idirect ) const {
286 // This function computes the column matrix of derivatives for the change
287 // in parameters for a change in the direction of a track at a point along
288 // its flight, holding the momentum and position constant. The effects for
289 // changes in 2 perpendicular directions (theta1 = dip and
290 // theta2 = phi*cos(dip)) can sometimes be added, as scattering in these
291 // are uncorrelated.
292
293 HepMatrix ddflct( nCirPrm(), 1, 0 ); // initialize with zeros
294
295 // Compute some common things
296
297 double omeg = omega();
298 double arcl = arc( fltlen );
299 double dx = cos( arcl );
300 double dy = sin( arcl );
301 double darc = omeg * d0();
302
303 // Go through the parameters
304
305 switch ( idirect )
306 {
307 case theta1: break;
308 case theta2:
309 ddflct[d0Index()][0] = -dy / ( omeg );
310 ddflct[phi0Index()][0] = dx / ( 1 + darc );
311 }
312
313 return ddflct;
314}
315
316HepMatrix TrkCircleTraj::derivDisplace( double fltlen, deflectDirection idirect ) const {
317 // This function computes the column matrix of derivatives for the change
318 // in parameters for a change in the position of a track at a point along
319 // its flight, holding the momentum and direction constant. The effects for
320 // changes in 2 perpendicular directions (theta1 = dip and
321 // theta2 = phi*cos(dip)) can sometimes be added, as scattering in these
322 // are uncorrelated.
323
324 HepMatrix ddflct( nCirPrm(), 1, 0 ); // initialize with zeros
325
326 // Compute some common things
327
328 double omeg = omega();
329 double arcl = arc( fltlen );
330 double dx = cos( arcl );
331 double dy = sin( arcl );
332 double darc = omeg * d0();
333
334 // Go through the parameters
335
336 switch ( idirect )
337 {
338 case theta1: break;
339 case theta2: ddflct[d0Index()][0] = dx; ddflct[phi0Index()][0] = dy * omeg / ( 1 + darc );
340 }
341
342 return ddflct;
343}
344
345HepMatrix TrkCircleTraj::derivPFract( double fltlen ) const {
346 //
347 // This function computes the column matrix of derrivatives for the change
348 // in parameters from a (fractional) change in the track momentum,
349 // holding the direction and position constant. The momentum change can
350 // come from energy loss or bfield inhomogeneities.
351 //
352 // For a helix, dp/P = -domega/omega,
353 // dParam/d(domega/omega) = omega*dParam/ddomega
354
355 HepMatrix dmomfrac( nCirPrm(), 1 );
356
357 // Compute some common things
358
359 double omeg = omega();
360 double arcl = arc( fltlen );
361 double dx = cos( arcl );
362 double dy = sin( arcl );
363 double darc = omeg * d0();
364
365 // Go through the parameters
366 // omega
367 dmomfrac[omegaIndex()][0] = -omeg;
368 // d0
369 dmomfrac[d0Index()][0] = -( 1 - dx ) / omeg;
370 // phi0
371 dmomfrac[phi0Index()][0] = dy / ( 1 + darc );
372
373 return dmomfrac;
374}
375
376double TrkCircleTraj::curvature( double ) const {
377 // Compute the curvature as the magnitude of the 2nd derrivative
378 // of the position function with respect to the 3-d flight distance
379
380 return fabs( omega() );
381}
382
383double TrkCircleTraj::phi0() const {
384 return BesAngle( parameters()->parameter()[phi0Index()] ).rad();
385}
386
387void TrkCircleTraj::paramFunc( const HepPoint3D& oldpoint, const HepPoint3D& newpoint,
388 const HepVector& oldvec, const HepSymMatrix& oldcov,
389 HepVector& newvec, HepSymMatrix& newcov, double fltlen ) {
390 // copy the input parameter vector, in case the input and output are the same
391 HepVector parvec( oldvec );
392 // start with the input: omega doesn't change
393 newvec = parvec;
394 //
395 double delx = newpoint.x() - oldpoint.x();
396 double dely = newpoint.y() - oldpoint.y();
397 //
398 double rad = 1. / parvec[omegaIndex()];
399 double rad2 = rad * rad;
400 double delta = rad + parvec[d0Index()];
401 double cos0 = cos( parvec[phi0Index()] );
402 double sin0 = sin( parvec[phi0Index()] );
403 double perp = delx * sin0 - dely * cos0;
404 double para = delx * cos0 + dely * sin0;
405 double oldphi = parvec[phi0Index()] + fltlen * parvec[omegaIndex()];
406 // delta
407 double newdelta2 = delta * delta + delx * delx + dely * dely + 2.0 * delta * perp;
408 // assume delta, newdelta have the same sign
409 double newdelta = delta > 0 ? sqrt( newdelta2 ) : -sqrt( newdelta2 );
410 double invdelta = 1.0 / newdelta;
411 double invdelta2 = 1.0 / newdelta2;
412 // d0
413 newvec[d0Index()] = newdelta - rad;
414 // phi0; check that we don't get the wrong wrapping
415 double newphi = atan2( sin0 + delx / delta, cos0 - dely / delta );
416 while ( fabs( newphi - oldphi ) > M_PI )
417 if ( newphi > oldphi ) newphi -= M_2PI;
418 else newphi += M_2PI;
419 newvec[phi0Index()] = newphi;
420 // double delphi = newphi-parvec[phi0Index()];
421 // now covariance: first, compute the rotation matrix
422 HepMatrix covrot( nCirPrm(), nCirPrm(), 0 ); // start with 0: lots of terms are 0
423 //
424 // omega is diagonal
425 covrot[omegaIndex()][omegaIndex()] = 1.0;
426 // d0
427 covrot[d0Index()][omegaIndex()] = rad2 * ( 1.0 - invdelta * ( delta + perp ) );
428 covrot[d0Index()][d0Index()] = invdelta * ( delta + perp );
429 covrot[d0Index()][phi0Index()] = delta * para * invdelta;
430 // phi0
431 covrot[phi0Index()][omegaIndex()] = rad2 * para * invdelta2;
432 covrot[phi0Index()][d0Index()] = -para * invdelta2;
433 covrot[phi0Index()][phi0Index()] = delta * ( delta + perp ) * invdelta2;
434 //
435 // Apply the rotation
436 newcov = oldcov.similarity( covrot );
437 // done
438}
439
440void TrkCircleTraj::invertParams( TrkParams* params, std::vector<bool>& flags ) const {
441 // Inverts parameters and returns true if the parameter inversion
442 // requires a change in sign of elements in the covariance matrix
443
444 for ( unsigned iparam = 0; iparam < NCIRPAR; iparam++ )
445 {
446 switch ( iparam )
447 {
448 case d0Ind: // changes sign
449 case omegaInd: // changes sign
450 params->parameter()[iparam] *= -1.0;
451 flags[iparam] = true;
452 break;
453 case phi0Ind: // changes by pi, but covariance matrix shouldn't change
454 params->parameter()[iparam] = BesAngle( params->parameter()[iparam] + Constants::pi );
455 flags[iparam] = false;
456 }
457 }
458}
459// yzhang
460/*int
461TrkCircleTraj::nPar() const
462{
463 return NCIRPAR;
464}*/
465// zhangy
467 // Visitor access--just use the TrkVisitor class member function
468 vis->trkVisitCircleTraj( this );
469}
470
471double TrkCircleTraj::angle( const double& f ) const { return BesAngle( phi0() + arc( f ) ); }
HepGeom::Point3D< double > HepPoint3D
TFile f("ana_bhabha660a_dqa_mcPat_zy_old.root")
Double_t x[10]
double arg(const EvtComplex &c)
double alpha
#define M_2PI
Definition HelixTraj.cxx:25
#define M_PI
Definition TConstant.h:4
DifNumber & mod(double lo, double hi)
void cosAndSin(DifNumber &c, DifNumber &s) const
Trajectory & operator=(const Trajectory &)
virtual Hep3Vector direction(double fltLen) const
HepMatrix derivDeflect(double fltlen, deflectDirection) const
virtual void getDFInfo2(double fltLen, DifPoint &pos, DifVector &dir) const
virtual double distTo2ndError(double flt, double tol, int pathDir) const
virtual double distTo1stError(double flt, double tol, int pathDir) const
TrkCircleTraj * clone() const
virtual double curvature(double fltLen) const
TrkCircleTraj(const HepVector &, const HepSymMatrix &, double lowlim=-99999., double hilim=99999., const HepPoint3D &refpoint=_theOrigin)
HepMatrix derivDisplace(double fltlen, deflectDirection) const
virtual void visitAccept(TrkVisitor *vis) const
double phi0() const
void invertParams(TrkParams *params, std::vector< bool > &flags) const
virtual HepPoint3D position(double fltLen) const
virtual void getDFInfo(double fltLen, DifPoint &, DifVector &dir, DifVector &delDir) const
virtual Hep3Vector delDirect(double) const
HepMatrix derivPFract(double fltlen) const
virtual void getInfo(double fltLen, HepPoint3D &pos, Hep3Vector &dir) const
TrkCircleTraj & operator=(const TrkCircleTraj &)
TrkSimpTraj(const HepVector &params, const HepSymMatrix &cov, const double startRange=-99999., const double endRange=99999., const HepPoint3D &refpoint=_theOrigin)
virtual void trkVisitCircleTraj(const TrkCircleTraj *)=0