BOSS 7.0.5
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 <assert.h>
13#include <math.h>
14#include "MdcGeom/Constants.h"
15#include "MdcGeom/BesAngle.h"
16#include "TrkFitter/TrkCircleTraj.h"
17#include "TrkBase/TrkVisitor.h"
18#include "MdcRecoUtil/DifNumber.h"
19#include "MdcRecoUtil/DifPoint.h"
20#include "MdcRecoUtil/DifVector.h"
21#include "TrkBase/TrkExchangePar.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,
33 double lowlim, 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() ||
39 pcov.num_row() != nCirPrm() ){
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
48//-----------------------------------------------------------------
50 double lowlim, double hilim, const HepPoint3D& refpoint) :
51 TrkSimpTraj(inpar.params(), inpar.covariance(), lowlim,hilim,refpoint) {
52//-----------------------------------------------------------------
53
54 if (omega() == 0.0) parameters()->parameter()[omegaIndex()] = 1.e-9;
55}
56
58 : TrkSimpTraj(h.parameters()->parameter(), h.parameters()->covariance(),
59 h.lowRange(),h.hiRange(),h.referencePoint())
60{
61
62}
63
66{
67 return new TrkCircleTraj(*this);
68}
69
72{
73 if( &h != this ){
75 _dtparams = *(h.parameters());
77 }
78 return *this;
79}
80
82{
83}
84
85double
86TrkCircleTraj::x( const double& f ) const
87{
88 double sphi0 = sin(phi0());
89 return ( sin(angle(f))-sphi0)/omega() - d0()*sphi0 + referencePoint().x();
90}
91
92double
93TrkCircleTraj::y( const double& f ) const
94{
95 double cphi0 = cos(phi0());
96 return -(cos(angle(f))-cphi0)/omega() + d0()*cphi0 + referencePoint().y();
97}
98
101{
102 double sphi0 = sin(phi0());
103 double cphi0 = cos(phi0());
104 double ang = angle(f);
105 double xt = ( sin(ang)-sphi0)/omega() - d0()*sphi0 + referencePoint().x();
106 double yt = -(cos(ang)-cphi0)/omega() + d0()*cphi0 + referencePoint().y();
107 return HepPoint3D(xt, yt, referencePoint().z());
108}
109
110Hep3Vector
112{
113 // Angle formed by tangent vector after
114 // being rotated 'arclength' around orbit.
115 double alpha = angle( f );
116 // Construct 3-D tangent vector of unit magnitude.
117 return Hep3Vector ( cos(alpha),
118 sin(alpha),
119 0.0);
120}
121
122Hep3Vector
123TrkCircleTraj::delDirect( double fltLen ) const
124{
125 double delX = -omega() * sin(angle(fltLen));
126 double delY = omega() * cos(angle(fltLen));
127 return Hep3Vector(delX, delY, 0.0);
128}
129
130double
131TrkCircleTraj::distTo1stError(double , double tol, int) const
132{
133 double arg = 2. * tol / fabs(omega());
134 assert (arg >= 0.);
135 return sqrt(arg);
136}
137
138double
139TrkCircleTraj::distTo2ndError(double , double tol, int) const
140{
141 //return pow(6.*tol / sqr(omega()), 0.33333333);//yzhang changed sqr
142 return pow(6.*tol / (omega()*omega()), 0.33333333);
143}
144
145void
146TrkCircleTraj::getInfo(double flt, HepPoint3D& pos, Hep3Vector& dir,
147 Hep3Vector& delDir) const
148{
149 double sphi0 = sin(phi0());
150 double cphi0 = cos(phi0());
151 double ang = angle(flt);
152 double cang = cos(ang);
153 double sang = sin(ang);
154 double xt = (sang-sphi0)/omega() - d0()*sphi0 + referencePoint().x();
155 double yt = -(cang-cphi0)/omega() + d0()*cphi0 + referencePoint().y();
156
157 pos.setX(xt);
158 pos.setY(yt);
159 pos.setZ(referencePoint().z());
160
161 dir.setX(cang);
162 dir.setY(sang);
163 dir.setZ(0.0);
164
165 delDir.setX(-omega()*sang);
166 delDir.setY( omega()*cang);
167 delDir.setZ(0.);
168}
169
170void
171TrkCircleTraj::getInfo( double fltLen, HepPoint3D& pos, Hep3Vector& dir ) const
172{
173 double sphi0 = sin(phi0());
174 double cphi0 = cos(phi0());
175 double ang = angle(fltLen);
176 double cang = cos(ang);
177 double sang = sin(ang);
178 double xt = (sang-sphi0)/omega() - d0()*sphi0 + referencePoint().x();
179 double yt = -(cang-cphi0)/omega() + d0()*cphi0 + referencePoint().y();
180
181 pos.setX(xt);
182 pos.setY(yt);
183 pos.setZ(referencePoint().z());
184
185 dir.setX(cang);
186 dir.setY(sang);
187 dir.setZ(0.0);
188}
189
190void
192 dir) const
193{
194 //Provides difNum version of information for calculation of derivatives.
195
196 // Create difNumber versions of parameters
197 DifNumber phi0Df(phi0(), phi0Index()+1, nCirPrm());
198 DifNumber d0Df(d0(), d0Index()+1, nCirPrm());
199 DifNumber omegaDf(omega(), omegaIndex()+1, nCirPrm());
200 phi0Df.setIndepPar( parameters() );
201 d0Df.setIndepPar( parameters() );
202 omegaDf.setIndepPar( parameters() );
203
204 DifNumber sinPhi0, cosPhi0;
205 phi0Df.cosAndSin(cosPhi0, sinPhi0);
206
207 DifNumber alphaDf = omegaDf;
208 alphaDf *= fltLen;
209 alphaDf += phi0Df;
210
211 // This is not the prettiest line imaginable for this operation:
213 DifNumber sinAlpha, cosAlpha;
214 alphaDf.cosAndSin(cosAlpha, sinAlpha);
215
216 // DifNumber x = (sinAlpha - sinPhi0) / omegaDf - d0Df * sinPhi0 + px;
217 // DifNumber y = -(cosAlpha - cosPhi0) / omegaDf + d0Df * cosPhi0 + py;
218
219 DifNumber x = sinAlpha;
220 x -= sinPhi0;
221 x /= omegaDf;
222 x -= (d0Df * sinPhi0);
223
224 DifNumber y = -cosAlpha;
225 y += cosPhi0;
226 y /= omegaDf;
227 y += (d0Df * cosPhi0);
228
229
230 static DifNumber zNull(0.);
231
232 pos.x = x;
233 pos.y = y;
234 pos.z = zNull;
235
236 bool lref = (referencePoint().x() != 0. || referencePoint().y() != 0. ||
237 referencePoint().z() != 0.);
238 if (lref) {
239 DifNumber px(referencePoint().x());
240 DifNumber py(referencePoint().y());
241 DifNumber pz(referencePoint().z());
242 pos.x += px;
243 pos.y += py;
244 pos.z += pz;
245 }
246
247 dir.x = cosAlpha;
248 dir.y = sinAlpha;
249 dir.z = 0.;
250}
251
252void
254 DifVector& delDir) const
255{
256 //Provides difNum version of information for calculation of derivatives.
257
258 // Create difNumber versions of parameters
259 DifNumber phi0Df(phi0(), phi0Index()+1, nCirPrm());
260 DifNumber d0Df(d0(), d0Index()+1, nCirPrm());
261 DifNumber omegaDf(omega(), omegaIndex()+1, nCirPrm());
262 phi0Df.setIndepPar( parameters() );
263 d0Df.setIndepPar( parameters() );
264 omegaDf.setIndepPar( parameters() );
265
266 DifNumber sinPhi0, cosPhi0;
267 phi0Df.cosAndSin(cosPhi0, sinPhi0);
268
269 DifNumber alphaDf = omegaDf;
270 alphaDf *= flt;
271 alphaDf += phi0Df;
272
273 // This is not the prettiest line imaginable for this operation:
275 DifNumber sinAlpha, cosAlpha;
276 alphaDf.cosAndSin(cosAlpha, sinAlpha);
277
278 // DifNumber x = (sinAlpha - sinPhi0) / omegaDf - d0Df * sinPhi0 + px;
279 // DifNumber y = -(cosAlpha - cosPhi0) / omegaDf + d0Df * cosPhi0 + py;
280
281 DifNumber x = sinAlpha;
282 x -= sinPhi0;
283 x /= omegaDf;
284 x -= (d0Df * sinPhi0);
285
286 DifNumber y = -cosAlpha;
287 y += cosPhi0;
288 y /= omegaDf;
289 y += (d0Df * cosPhi0);
290
291
292 static DifNumber zNull(0.);
293
294 pos.x = x;
295 pos.y = y;
296 pos.z = zNull;
297
298 bool lref = (referencePoint().x() != 0. || referencePoint().y() != 0. ||
299 referencePoint().z() != 0.);
300 if (lref) {
301 DifNumber px(referencePoint().x());
302 DifNumber py(referencePoint().y());
303 DifNumber pz(referencePoint().z());
304 pos.x += px;
305 pos.y += py;
306 pos.z += pz;
307 }
308
309 dir.x = cosAlpha;
310 dir.y = sinAlpha;
311 dir.z = 0.;
312
313 delDir.x = -omegaDf;
314 delDir.x *= sinAlpha;
315
316 delDir.y = omegaDf;
317 delDir.y *= cosAlpha;
318
319 delDir.z = 0.;
320}
321HepMatrix
323{
324// This function computes the column matrix of derivatives for the change
325// in parameters for a change in the direction of a track at a point along
326// its flight, holding the momentum and position constant. The effects for
327// changes in 2 perpendicular directions (theta1 = dip and
328// theta2 = phi*cos(dip)) can sometimes be added, as scattering in these
329// are uncorrelated.
330
331 HepMatrix ddflct(nCirPrm(),1,0); // initialize with zeros
332
333// Compute some common things
334
335 double omeg = omega();
336 double arcl = arc(fltlen);
337 double dx = cos(arcl);
338 double dy = sin(arcl);
339 double darc = omeg*d0();
340
341// Go through the parameters
342
343 switch (idirect) {
344 case theta1:
345 break;
346 case theta2:
347 ddflct[d0Index()][0] = -dy/(omeg);
348 ddflct[phi0Index()][0] = dx/(1+darc);
349 }
350
351 return ddflct;
352}
353
354HepMatrix
356{
357// This function computes the column matrix of derivatives for the change
358// in parameters for a change in the position of a track at a point along
359// its flight, holding the momentum and direction constant. The effects for
360// changes in 2 perpendicular directions (theta1 = dip and
361// theta2 = phi*cos(dip)) can sometimes be added, as scattering in these
362// are uncorrelated.
363
364 HepMatrix ddflct(nCirPrm(),1,0); // initialize with zeros
365
366// Compute some common things
367
368 double omeg = omega();
369 double arcl = arc(fltlen);
370 double dx = cos(arcl);
371 double dy = sin(arcl);
372 double darc = omeg*d0();
373
374// Go through the parameters
375
376 switch (idirect) {
377 case theta1:
378 break;
379 case theta2:
380 ddflct[d0Index()][0] = dx;
381 ddflct[phi0Index()][0] = dy*omeg/(1+darc);
382 }
383
384 return ddflct;
385}
386
387HepMatrix
388TrkCircleTraj::derivPFract(double fltlen) const
389{
390//
391// This function computes the column matrix of derrivatives for the change
392// in parameters from a (fractional) change in the track momentum,
393// holding the direction and position constant. The momentum change can
394// come from energy loss or bfield inhomogeneities.
395//
396// For a helix, dp/P = -domega/omega,
397// dParam/d(domega/omega) = omega*dParam/ddomega
398
399 HepMatrix dmomfrac(nCirPrm(),1);
400
401// Compute some common things
402
403 double omeg = omega();
404 double arcl = arc(fltlen);
405 double dx = cos(arcl);
406 double dy = sin(arcl);
407 double darc = omeg*d0();
408
409// Go through the parameters
410// omega
411 dmomfrac[omegaIndex()][0] = -omeg;
412// d0
413 dmomfrac[d0Index()][0] = -(1-dx)/omeg;
414// phi0
415 dmomfrac[phi0Index()][0] = dy/(1+darc);
416
417 return dmomfrac;
418}
419
420double
422{
423// Compute the curvature as the magnitude of the 2nd derrivative
424// of the position function with respect to the 3-d flight distance
425
426 return fabs(omega());
427}
428
429double
431{
432 return BesAngle(parameters()->parameter()[phi0Index()]).rad();
433}
434
435void
436TrkCircleTraj::paramFunc(const HepPoint3D& oldpoint,const HepPoint3D& newpoint,
437 const HepVector& oldvec,const HepSymMatrix& oldcov,
438 HepVector& newvec,HepSymMatrix& newcov,
439 double fltlen)
440{
441// copy the input parameter vector, in case the input and output are the same
442 HepVector parvec(oldvec);
443// start with the input: omega doesn't change
444 newvec = parvec;
445//
446 double delx = newpoint.x()-oldpoint.x();
447 double dely = newpoint.y()-oldpoint.y();
448//
449 double rad = 1./parvec[omegaIndex()];
450 double rad2 = rad*rad;
451 double delta = rad + parvec[d0Index()];
452 double cos0 = cos(parvec[phi0Index()]);
453 double sin0 = sin(parvec[phi0Index()]);
454 double perp = delx*sin0-dely*cos0;
455 double para = delx*cos0+dely*sin0;
456 double oldphi = parvec[phi0Index()] + fltlen*parvec[omegaIndex()] ;
457// delta
458 double newdelta2 = delta*delta + delx*delx + dely*dely +
459 2.0*delta*perp;
460// assume delta, newdelta have the same sign
461 double newdelta = delta>0 ? sqrt(newdelta2) : -sqrt(newdelta2);
462 double invdelta = 1.0/newdelta;
463 double invdelta2 = 1.0/newdelta2;
464// d0
465 newvec[d0Index()] = newdelta - rad;
466// phi0; check that we don't get the wrong wrapping
467 double newphi = atan2(sin0+delx/delta,cos0-dely/delta);
468 while(fabs(newphi - oldphi)>M_PI)
469 if(newphi > oldphi)
470 newphi -= M_2PI;
471 else
472 newphi += M_2PI;
473 newvec[phi0Index()] = newphi;
474 //double delphi = newphi-parvec[phi0Index()];
475// now covariance: first, compute the rotation matrix
476 HepMatrix covrot(nCirPrm(),nCirPrm(),0); // start with 0: lots of terms are 0
477//
478// omega is diagonal
479 covrot[omegaIndex()][omegaIndex()] = 1.0;
480// d0
481 covrot[d0Index()][omegaIndex()] = rad2*(1.0 - invdelta*(delta + perp));
482 covrot[d0Index()][d0Index()] = invdelta*(delta + perp);
483 covrot[d0Index()][phi0Index()] = delta*para*invdelta;
484// phi0
485 covrot[phi0Index()][omegaIndex()] = rad2*para*invdelta2;
486 covrot[phi0Index()][d0Index()] = -para*invdelta2;
487 covrot[phi0Index()][phi0Index()] = delta*(delta + perp)*invdelta2;
488//
489// Apply the rotation
490 newcov = oldcov.similarity(covrot);
491// done
492}
493
494void
495TrkCircleTraj::invertParams(TrkParams* params, std::vector<bool>& flags) const
496{
497 // Inverts parameters and returns true if the parameter inversion
498 // requires a change in sign of elements in the covariance matrix
499
500 for (unsigned iparam = 0; iparam < NCIRPAR; iparam++) {
501 switch ( iparam ) {
502 case d0Ind: // changes sign
503 case omegaInd: // changes sign
504 params->parameter()[iparam] *= -1.0;
505 flags[iparam] = true;
506 break;
507 case phi0Ind: // changes by pi, but covariance matrix shouldn't change
508 params->parameter()[iparam] =
509 BesAngle(params->parameter()[iparam] + Constants::pi);
510 flags[iparam] = false;
511 }
512 }
513}
514//yzhang
515/*int
516TrkCircleTraj::nPar() const
517{
518 return NCIRPAR;
519}*/
520//zhangy
521void
523{
524// Visitor access--just use the TrkVisitor class member function
525 vis->trkVisitCircleTraj(this);
526}
527
528double
529TrkCircleTraj::angle(const double& f) const
530{
531 return BesAngle(phi0() + arc(f));
532}
const double delta
Double_t x[10]
double arg(const EvtComplex &c)
Definition: EvtComplex.hh:227
const double alpha
#define M_2PI
Definition: HelixTraj.cxx:25
double sin(const BesAngle a)
double cos(const BesAngle a)
************Class m_ypar INTEGER m_KeyWgt INTEGER m_KeyIHVP INTEGER m_KeyGPS INTEGER m_IsBeamPolarized INTEGER m_EvtGenInterface DOUBLE PRECISION m_Emin DOUBLE PRECISION m_sphot DOUBLE PRECISION m_Xenph DOUBLE PRECISION m_q2 DOUBLE PRECISION m_PolBeam2 DOUBLE PRECISION m_xErrPb *COMMON c_KK2f $ !CMS energy average $ !Spin Polarization vector first beam $ !Spin Polarization vector second beam $ !Beam energy spread[GeV] $ !minimum hadronization energy[GeV] $ !input parameters
Definition: KK2f.h:46
#define M_PI
Definition: TConstant.h:4
DifNumber & mod(double lo, double hi)
void cosAndSin(DifNumber &c, DifNumber &s) const
Trajectory & operator=(const Trajectory &)
Definition: Trajectory.cxx:86
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 &)
const HepPoint3D & referencePoint() const
virtual void trkVisitCircleTraj(const TrkCircleTraj *)=0
double y[1000]
TFile f("ana_bhabha660a_dqa_mcPat_zy_old.root")
double precision pisqo6 parameter(pi=3.14159265358979d0, pisq=pi *pi, pisqo6=pisq/6d0) double precision zip