BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
TrkDifLineTraj.cxx
Go to the documentation of this file.
1//--------------------------------------------------------------------------
2// File and Version Information:
3// $Id: TrkDifLineTraj.cxx,v 1.5 2007/12/07 07:06:34 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/TrkDifLineTraj.h"
13#include "MdcGeom/BesAngle.h"
14#include "MdcRecoUtil/DifNumber.h"
15#include "MdcRecoUtil/DifPoint.h"
16#include "MdcRecoUtil/DifVector.h"
17#include "TrkBase/TrkExchangePar.h"
18#include "TrkBase/TrkVisitor.h"
19#include "TrkFitter/TrkDifLineTraj.h"
20#include <assert.h>
21#include <math.h>
22
23using CLHEP::Hep3Vector;
24
25TrkDifLineTraj::TrkDifLineTraj( const HepVector& pvec, const HepSymMatrix& pcov, double lowlim,
26 double hilim, const HepPoint3D& refpoint )
27 : TrkSimpTraj( pvec, pcov, lowlim, hilim, refpoint ) {}
28
29TrkDifLineTraj::TrkDifLineTraj( const TrkExchangePar& inpar, double lowlim, double hilim,
30 const HepPoint3D& refpoint )
31 : TrkSimpTraj( HepVector( NLINPRM, 1 ), HepSymMatrix( NLINPRM, 1 ), lowlim, hilim,
32 refpoint ) {
33 // the above constructor actually screws up z0 and tandip. I can't fix it in
34 // the initializer, so I'll just overwrite the track here. Ugly and inefficient
35 HepVector subvect( NLINPRM, 1 );
36 HepSymMatrix submat( NLINPRM, 1 );
37 const HepSymMatrix covar = inpar.covariance();
38 subvect[d0Ind] = inpar.d0();
39 subvect[phi0Ind] = inpar.phi0();
40 subvect[z0Ind] = inpar.z0();
41 subvect[tanDipInd] = inpar.tanDip();
42
43 submat.fast( d0Ind + 1, d0Ind + 1 ) =
44 covar.fast( TrkExchangePar::ex_d0 + 1, TrkExchangePar::ex_d0 + 1 );
45 submat.fast( d0Ind + 1, phi0Ind + 1 ) =
47 submat.fast( d0Ind + 1, z0Ind + 1 ) =
48 covar.fast( TrkExchangePar::ex_d0 + 1, TrkExchangePar::ex_z0 + 1 );
49 submat.fast( d0Ind + 1, tanDipInd + 1 ) =
51 submat.fast( phi0Ind + 1, phi0Ind + 1 ) =
53 submat.fast( phi0Ind + 1, z0Ind + 1 ) =
55 submat.fast( phi0Ind + 1, tanDipInd + 1 ) =
57 submat.fast( z0Ind + 1, z0Ind + 1 ) =
58 covar.fast( TrkExchangePar::ex_z0 + 1, TrkExchangePar::ex_z0 + 1 );
59 submat.fast( z0Ind + 1, tanDipInd + 1 ) =
61 submat.fast( tanDipInd + 1, tanDipInd + 1 ) =
63 // reset the track
64 ( *parameters() ) = TrkParams( subvect, submat );
65}
66
68 : TrkSimpTraj( h.parameters()->parameter(), h.parameters()->covariance(), h.lowRange(),
69 h.hiRange(), h.referencePoint() ) {}
70
71TrkDifLineTraj* TrkDifLineTraj::clone() const { return new TrkDifLineTraj( *this ); }
72
74 if ( &h != this )
75 {
77 _dtparams = *h.parameters();
79 }
80 return *this;
81}
82
84
85double TrkDifLineTraj::x( const double& f ) const {
86 return -d0() * sin( phi0() ) + f * cos( phi0() ) * cosDip() + referencePoint().x();
87}
88
89double TrkDifLineTraj::y( const double& f ) const {
90 return d0() * cos( phi0() ) + f * sin( phi0() ) * cosDip() + referencePoint().y();
91}
92
93double TrkDifLineTraj::z( const double& f ) const {
94 return z0() + f * tanDip() * cosDip() + referencePoint().z();
95}
96
98 double cosd = cosDip();
99 double cp = cos( phi0() );
100 double sp = sin( phi0() );
101 return HepPoint3D( -d0() * sp + f * cp * cosd + referencePoint().x(),
102 d0() * cp + f * sp * cosd + referencePoint().y(),
103 z0() + f * tanDip() * cosd + referencePoint().z() );
104}
105
106Hep3Vector TrkDifLineTraj::direction( double ) const {
107 double cdip = cosDip();
108 return Hep3Vector( cos( phi0() ) * cdip, sin( phi0() ) * cdip, tanDip() * cdip );
109}
110
111Hep3Vector TrkDifLineTraj::delDirect( double ) const { return Hep3Vector( 0.0, 0.0, 0.0 ); }
112
113double TrkDifLineTraj::distTo1stError( double, double, int ) const { return 999.e4; }
114
115double TrkDifLineTraj::distTo2ndError( double, double, int ) const { return 999.e4; }
116
117void TrkDifLineTraj::getInfo( double fltLen, HepPoint3D& pos, Hep3Vector& dir,
118 Hep3Vector& delDir ) const {
119 // This could be made much more efficient!!!!!!
120 pos = position( fltLen );
121 dir = direction( fltLen );
122 delDir = delDirect( fltLen );
123}
124
125void TrkDifLineTraj::getInfo( double fltLen, HepPoint3D& pos, Hep3Vector& dir ) const {
126 // This could be made much more efficient!!!!!
127 pos = position( fltLen );
128 dir = direction( fltLen );
129}
130
131void TrkDifLineTraj::getDFInfo( double flt, DifPoint& pos, DifVector& dir,
132 DifVector& delDir ) const {
133 // Provides difNum version of information for calculation of derivatives.
134
135 // Create difNumber versions of parameters
136 // enum index (phi0Index(), etc) is from TrkLineParams.hh
137 DifNumber phi0Df( phi0(), phi0Index() + 1, nLinPrm() );
138 DifNumber d0Df( d0(), d0Index() + 1, nLinPrm() );
139 DifNumber z0Df( z0(), z0Index() + 1, nLinPrm() );
140 DifNumber tanDipDf( tanDip(), tanDipIndex() + 1, nLinPrm() );
141 DifNumber zero( 0.0, nLinPrm() );
142 phi0Df.setIndepPar( parameters() );
143 d0Df.setIndepPar( parameters() );
144 z0Df.setIndepPar( parameters() );
145 tanDipDf.setIndepPar( parameters() );
146 zero.setIndepPar( parameters() );
147
148 DifNumber sphi0, cphi0;
149 phi0Df.cosAndSin( cphi0, sphi0 );
150
151 DifNumber px( referencePoint().x() );
152 DifNumber py( referencePoint().y() );
153 DifNumber pz( referencePoint().z() );
154
155 DifNumber cdip = 1. / sqrt( 1. + tanDipDf * tanDipDf );
156 DifNumber xx = -d0Df * sphi0 + flt * cphi0 * cdip + px;
157 DifNumber yy = d0Df * cphi0 + flt * sphi0 * cdip + py;
158 DifNumber zz = z0Df + flt * tanDipDf * cdip + pz;
159
160 pos = DifPoint( xx, yy, zz );
161 dir = DifVector( cphi0 * cdip, sphi0 * cdip, tanDipDf * cdip );
162
163 delDir = DifVector( zero, zero, zero );
164}
165
166double TrkDifLineTraj::curvature( double ) const { return 0.; }
167
168double TrkDifLineTraj::phi0() const {
169 return BesAngle( parameters()->parameter()[phi0Index()] ).rad();
170}
171
172HepMatrix TrkDifLineTraj::derivDeflect( double fltlen, deflectDirection idirect ) const {
173 // This function computes the column matrix of derivatives for the change
174 // in parameters for a change in the direction of a track at a point along
175 // its flight, holding the momentum and position constant. The effects for
176 // changes in 2 perpendicular directions (theta1 = dip and
177 // theta2 = phi*cos(dip)) are uncorrelated.
178
179 HepMatrix ddflct( nLinPrm(), 1 );
180 // Compute some common things
181 double cosd = cosDip();
182 // Go through the parameters
183 switch ( idirect )
184 {
185 case theta1:
186 ddflct[tanDipIndex()][0] = 1.0 / ( cosd * cosd );
187 ddflct[d0Index()][0] = 0.0;
188 ddflct[phi0Index()][0] = 0.0;
189 ddflct[z0Index()][0] = -fltlen / cosd;
190 ;
191 break;
192 case theta2:
193 ddflct[tanDipIndex()][0] = 0;
194 ddflct[d0Index()][0] = -fltlen;
195 ddflct[phi0Index()][0] = 1.0 / cosd;
196 ddflct[z0Index()][0] = -( tanDip() / cosd ) * d0();
197 break;
198 }
199 return ddflct;
200}
201
202HepMatrix TrkDifLineTraj::derivDisplace( double fltlen, deflectDirection idirect ) const {
203 // This function computes the column matrix of derivatives for the change
204 // in parameters for a change in the position of a track at a point along
205 // its flight, holding the momentum and direction constant. The effects for
206 // changes in 2 perpendicular directions (theta1 = dip and
207 // theta2 = phi*cos(dip)) are uncorrelated.
208
209 HepMatrix ddflct( nLinPrm(), 1 );
210 // Compute some common things
211 double cosd = cosDip();
212 // Go through the parameters
213 switch ( idirect )
214 {
215 case theta1:
216 ddflct[tanDipIndex()][0] = 0.0;
217 ddflct[d0Index()][0] = 0.0;
218 ddflct[phi0Index()][0] = 0.0;
219 ddflct[z0Index()][0] = 1.0 / cosd;
220 break;
221 case theta2:
222 ddflct[tanDipIndex()][0] = 0;
223 ddflct[d0Index()][0] = 1.0;
224 ddflct[phi0Index()][0] = 0.0;
225 ddflct[z0Index()][0] = 0.0;
226 break;
227 }
228 return ddflct;
229}
230
231HepMatrix TrkDifLineTraj::derivPFract( double ) const {
232 // This function computes the column matrix of derrivatives for the change
233 // in parameters from a (fractional) change in the track momentum,
234 // holding the direction and position constant. The momentum change can
235 // come from energy loss or bfield inhomogeneities. Line Trajs have no
236 // geometric change from energy loss.
237
238 return HepMatrix( nLinPrm(), 1, 0 );
239}
240
241void TrkDifLineTraj::paramFunc( const HepPoint3D& oldpoint, const HepPoint3D& newpoint,
242 const HepVector& oldvec, const HepSymMatrix& oldcov,
243 HepVector& newvec, HepSymMatrix& newcov, double fltlen ) {
244 // not yet implemented
245 std::cout << "ErrMsg(fatal)"
246 << "TrkDifLineTraj::paramFunc() is not implemented!" << std::endl;
247}
248
249void TrkDifLineTraj::invertParams( TrkParams* params, std::vector<bool>& flags ) const {
250 // Inverts parameters and returns true if the parameter inversion
251 // requires a change in sign of elements in the covariance matrix
252 for ( unsigned iparam = 0; iparam < NLINPRM; iparam++ )
253 {
254 switch ( iparam )
255 {
256 case d0Ind: // changes sign
257 case tanDipInd: // changes sign
258 params->parameter()[iparam] *= -1.0;
259 flags[iparam] = true;
260 break;
261 case phi0Ind: // changes by pi, but covariance matrix shouldn't change
262 params->parameter()[iparam] = BesAngle( params->parameter()[iparam] + Constants::pi );
263 flags[iparam] = false;
264 break;
265 case z0Ind: // no change
266 flags[iparam] = false;
267 }
268 }
269 return;
270}
271
273 // Visitor access--just use the TrkVisitor class member function
274 vis->trkVisitLineTraj( this );
275}
HepGeom::Point3D< double > HepPoint3D
TFile f("ana_bhabha660a_dqa_mcPat_zy_old.root")
Double_t x[10]
const DifNumber zero
void cosAndSin(DifNumber &c, DifNumber &s) const
Trajectory & operator=(const Trajectory &)
virtual void getInfo(double fltLen, HepPoint3D &pos, Hep3Vector &dir) const
virtual void visitAccept(TrkVisitor *vis) const
virtual Hep3Vector direction(double fltLen) const
virtual double distTo1stError(double flt, double tol, int pathDir) const
TrkDifLineTraj(const HepVector &, const HepSymMatrix &, double lowlim=-99999., double hilim=99999., const HepPoint3D &refpoint=_theOrigin)
TrkDifLineTraj * clone() const
virtual Hep3Vector delDirect(double) const
double phi0() const
virtual void getDFInfo(double fltLen, DifPoint &, DifVector &dir, DifVector &delDir) const
void invertParams(TrkParams *params, std::vector< bool > &flags) const
virtual double distTo2ndError(double flt, double tol, int pathDir) const
HepMatrix derivDeflect(double fltlen, deflectDirection) const
TrkDifLineTraj & operator=(const TrkDifLineTraj &)
HepMatrix derivDisplace(double fltlen, deflectDirection) const
virtual double curvature(double fltLen) const
virtual HepPoint3D position(double fltLen) const
HepMatrix derivPFract(double fltlen) const
TrkSimpTraj(const HepVector &params, const HepSymMatrix &cov, const double startRange=-99999., const double endRange=99999., const HepPoint3D &refpoint=_theOrigin)
virtual void trkVisitLineTraj(const TrkDifLineTraj *)=0