BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
NeutTraj.cxx
Go to the documentation of this file.
1#include <assert.h>
2#include <math.h>
3
4#include "CLHEP/Geometry/Point3D.h"
5#include "CLHEP/Matrix/SymMatrix.h"
6#include "CLHEP/Vector/ThreeVector.h"
7#include "MdcGeom/BesAngle.h"
8#include "MdcGeom/Constants.h"
9#include "MdcRecoUtil/DifNumber.h"
10#include "MdcRecoUtil/DifPoint.h"
11#include "MdcRecoUtil/DifVector.h"
12#include "TrkBase/NeutTraj.h"
13#include "TrkBase/TrkVisitor.h"
14
15NeutTraj::NeutTraj( const NeutParams& np, double lowlim, double hilim,
16 const HepPoint3D& refpoint )
17 : TrkSimpTraj( np.parameter(), np.covariance(), lowlim, hilim ) {}
18
20 : TrkSimpTraj( n.parameters()->parameter(), n.parameters()->covariance(), n.lowRange(),
21 n.hiRange() ) {}
22
23// Simple cloning function
24NeutTraj* NeutTraj::clone() const { return new NeutTraj( *this ); }
25
27 if ( &n != this )
28 {
29 for ( int iend = 0; iend < 2; iend++ ) flightrange[iend] = n.flightrange[iend];
30 _dtparams = *n._np();
31 }
32 return *this;
33}
34
35//-----------------------------------------------------------------
37
38//-----------------------------------------------------------------
39double NeutTraj::x( const double& f ) const {
40 //-----------------------------------------------------------------
41 return cosDip() * f * cos( phi0() ) - d0() * sin( phi0() );
42}
43
44//-----------------------------------------------------------------
45double NeutTraj::y( const double& f ) const {
46 //-----------------------------------------------------------------
47 return cosDip() * f * sin( phi0() ) + d0() * cos( phi0() );
48}
49
50//-----------------------------------------------------------------
51double NeutTraj::z( const double& f ) const {
52 //-----------------------------------------------------------------
53 return ( z0() + f * sinDip() );
54}
55
56//-----------------------------------------------------------------
58 //-----------------------------------------------------------------
59 double cdip = cosDip();
60 double sphi0 = sin( phi0() );
61 double cphi0 = cos( phi0() );
62
63 return HepPoint3D( cdip * f * cphi0 - d0() * sphi0, cdip * f * sphi0 + d0() * cphi0,
64 z0() + f * tanDip() * cdip );
65}
66
67//-----------------------------------------------------------------
68Hep3Vector NeutTraj::direction( double f ) const {
69 //-----------------------------------------------------------------
70 return Hep3Vector( cos( phi0() ) * cosDip(), sin( phi0() ) * cosDip(), sinDip() );
71}
72//-----------------------------------------------------------------
73Hep3Vector NeutTraj::delDirect( double fltLen ) const {
74 //-----------------------------------------------------------------
75 return Hep3Vector( 0.0, 0.0, 0.0 );
76}
77
78//-----------------------------------------------------------------
79double NeutTraj::distTo1stError( double, double tol, int ) const {
80 //-----------------------------------------------------------------
81 return 9999.;
82}
83
84//-----------------------------------------------------------------
85double NeutTraj::distTo2ndError( double, double tol, int ) const {
86 //-----------------------------------------------------------------
87 return 9999.;
88}
89
90void NeutTraj::getInfo( double fltLen, HepPoint3D& pos, Hep3Vector& dir,
91 Hep3Vector& delDir ) const {
92 // This could be made much more efficient!!!!!!
93 pos = position( fltLen );
94 dir = direction( fltLen );
95 delDir = delDirect( fltLen );
96}
97
98void NeutTraj::getInfo( double fltLen, HepPoint3D& pos, Hep3Vector& dir ) const {
99 // This could be made much more efficient!!!!!
100 pos = position( fltLen );
101 dir = direction( fltLen );
102 return;
103}
104
105void NeutTraj::getDFInfo( double flt, DifPoint& pos, DifVector& dir,
106 DifVector& delDir ) const {
107 // Provides difNum version of information for calculation of derivatives.
108 // Some of this duplicate code could be reduced if we had member
109 // function templates. Maybe.
110
111 // Create difNumber versions of parameters
112 // enum index (phi0(), etc) is from HelixParams.hh
116 DifNumber tanDipDf( tanDip(), NeutParams::_tanDip + 1, NeutParams::_nneutprm );
118 // RF 03/25/99
119 // the flight lenght has an error, which is the error along the trajectory
120 // in the creation point
122 phi0Df.setIndepPar( parameters() );
123 d0Df.setIndepPar( parameters() );
124 z0Df.setIndepPar( parameters() );
125 tanDipDf.setIndepPar( parameters() );
126 pDf.setIndepPar( parameters() );
127 s0Df.setIndepPar( parameters() );
128 DifNumber dipDf = atan( tanDipDf );
129
130 DifNumber sDip, cDip;
131 dipDf.cosAndSin( cDip, sDip );
132 DifNumber sinPhi0, cosPhi0;
133 phi0Df.cosAndSin( cosPhi0, sinPhi0 );
134
135 DifNumber x = cDip * s0Df * cosPhi0 - d0Df * sinPhi0;
136 DifNumber y = cDip * s0Df * sinPhi0 + d0Df * cosPhi0;
137 DifNumber z = z0Df + s0Df * sDip;
138 pos = DifPoint( x, y, z );
139 dir = DifVector( cosPhi0 * cDip, sinPhi0 * cDip, sDip );
140 delDir = DifVector( 0., 0., 0. );
141}
142
143HepMatrix NeutTraj::derivDeflect( double fltlen, deflectDirection idirect ) const {
144 //
145 // This function computes the column matrix of derivatives for the change
146 // in parameters for a change in the direction of a track at a point along
147 // its flight, holding the momentum and position constant. The effects for
148 // changes in 2 perpendicular directions (theta1 = dip and
149 // theta2 = phi*cos(dip)) can sometimes be added, as scattering in these
150 // are uncorrelated.
151 //
152 HepMatrix ddflct( NeutParams::_nneutprm, 1 );
153 //
154 // Compute some common things
155 //
156 double tand = tanDip();
157 double cosd = cosDip();
158 //
159 // Go through the parameters
160 //
161 switch ( idirect )
162 {
163 case theta1:
164 ddflct[NeutParams::_p][0] = 0.;
165 ddflct[NeutParams::_tanDip][0] = 1.0 / ( cosd * cosd );
166 ddflct[NeutParams::_d0][0] = 0.;
167 ddflct[NeutParams::_phi0][0] = 0.;
168 ddflct[NeutParams::_s0][0] = 0.;
169 ddflct[NeutParams::_z0][0] = translen( fltlen ) * ( -1. - ( tand * tand ) );
170 break;
171 case theta2:
172 ddflct[NeutParams::_p][0] = 0;
173 ddflct[NeutParams::_tanDip][0] = 0;
174 ddflct[NeutParams::_d0][0] = -translen( fltlen ) / cosd;
175 ddflct[NeutParams::_phi0][0] = 1. / cosd;
176 ddflct[NeutParams::_z0][0] = 0.;
177 ddflct[NeutParams::_s0][0] = 0.;
178 break;
179 }
180 return ddflct;
181}
182
183HepMatrix NeutTraj::derivDisplace( double fltlen, deflectDirection idirect ) const {
184 //
185 // This function computes the column matrix of derivatives for the change
186 // in parameters for a change in the transvers position of a track at a point along
187 // its flight, holding the momentum and direction constant. The effects for
188 // changes in 2 perpendicular directions (theta1 = dip and
189 // theta2 = phi*cos(dip)) are uncorrelated. The sign convention has been
190 // chosen so that correlated scattering and displacement effects may be added
191 //
192 HepMatrix ddflct( NeutParams::_nneutprm, 1 );
193 //
194 // Compute some common things
195 //
196 double cosd = cosDip();
197 //
198 // Go through the parameters
199 //
200 switch ( idirect )
201 {
202 case theta1:
203 ddflct[NeutParams::_p][0] = 0.;
204 ddflct[NeutParams::_tanDip][0] = 0.0;
205 ddflct[NeutParams::_d0][0] = 0.;
206 ddflct[NeutParams::_phi0][0] = 0.;
207 ddflct[NeutParams::_s0][0] = 0.;
208 ddflct[NeutParams::_z0][0] = 1.0 / cosd;
209 break;
210 case theta2:
211 ddflct[NeutParams::_p][0] = 0;
212 ddflct[NeutParams::_tanDip][0] = 0;
213 ddflct[NeutParams::_d0][0] = 1.0;
214 ddflct[NeutParams::_phi0][0] = 0.0;
215 ddflct[NeutParams::_z0][0] = 0.;
216 ddflct[NeutParams::_s0][0] = 0.;
217 break;
218 }
219 return ddflct;
220}
221
222HepMatrix NeutTraj::derivPFract( double fltlen ) const {
223 // This function computes the column matrix of derivatives for the change
224 // in parameters from a (fractional) change in the track momentum,
225 // holding the direction and position constant. The momentum change can
226 // come from energy loss or bfield inhomogeneities.
227 //
228 // For a helix, dp/P = -domega/omega,
229 // dParam/d(domega/omega) = -omega*dParam/ddomega
230 //
231 HepMatrix dmomfrac( NeutParams::_nneutprm, 1 );
232
233 // Go through the parameters
234 dmomfrac[NeutParams::_p][0] = p(); // momentum
235 dmomfrac[NeutParams::_tanDip][0] = 0.0; // tanDip
236 dmomfrac[NeutParams::_d0][0] = 0.0; // d0
237 dmomfrac[NeutParams::_phi0][0] = 0.0; // phi0
238 dmomfrac[NeutParams::_z0][0] = 0.0; // z0
239 dmomfrac[NeutParams::_s0][0] = 0.0; // s0
240 return dmomfrac;
241}
242
243double NeutTraj::phi0() const { return BesAngle( _np()->phi0() ).rad(); }
244
245void NeutTraj::paramFunc( const HepPoint3D& oldpoint, const HepPoint3D& newpoint,
246 const HepVector& oldvec, const HepSymMatrix& oldcov,
247 HepVector& newvec, HepSymMatrix& newcov, double fltlen ) {
248
249 // copy the input parameter vector, in case the input and output are the same
250 HepVector parvec( oldvec );
251 // start with the input: momentum and tandip don't change
252 newvec = parvec;
253 //
254 double delx = newpoint.x() - oldpoint.x();
255 double dely = newpoint.y() - oldpoint.y();
256 double delz = newpoint.z() - oldpoint.z();
257 //
258 double cos0 = cos( parvec[NeutParams::_phi0] );
259 double sin0 = sin( parvec[NeutParams::_phi0] );
260 double perp = delx * sin0 - dely * cos0;
261 double para = delx * cos0 + dely * sin0;
262 double tand = parvec[NeutParams::_tanDip];
263 // delta
264 // assume delta, newdelta have the same sign
265 // d0
266 newvec[NeutParams::_d0] = parvec[NeutParams::_d0] + perp;
267 // phi0; check that we don't get the wrong wrapping
268 newvec[NeutParams::_phi0] = parvec[NeutParams::_phi0];
269 // z0
270 newvec[NeutParams::_z0] +=
271 parvec[NeutParams::_tanDip] * ( delx / cos0 ) * ( 1. + ( sin0 / cos0 ) ) - delz;
272 // now covariance: first, compute the rotation matrix
274 0 ); // start with 0: lots of terms are zero
275 //
276 // momentum is diagonal
277 covrot[NeutParams::_p][NeutParams::_p] = 1.0;
278 // tandip is diagonal
280 // d0
281 covrot[NeutParams::_d0][NeutParams::_d0] = 1.;
282 covrot[NeutParams::_d0][NeutParams::_phi0] = para;
283 // phi0
284 covrot[NeutParams::_phi0][NeutParams::_p] = para;
286 // z0
287 covrot[NeutParams::_z0][NeutParams::_phi0] = tand * -2. * perp;
288 covrot[NeutParams::_z0][NeutParams::_tanDip] = ( delx / cos0 ) * ( 1. + ( sin0 / cos0 ) );
289 covrot[NeutParams::_z0][NeutParams::_z0] = 1.0;
290 covrot[NeutParams::_s0][NeutParams::_s0] = 1.0;
291 //
292 // Apply the rotation
293 newcov = oldcov.similarity( covrot );
294 // done
295}
296
297void NeutTraj::invertParams( TrkParams* newparams, std::vector<bool>& flags ) const {
298 assert( 1 == 0 );
299
300 // // Inverts parameters and returns true if the parameter inversion
301 // // requires a change in sign of elements in the covariance matrix
302 //
303 // for (unsigned iparam = 0; iparam < NeutParams::_nneutprm; iparam++) {
304 // switch ( iparam ) {
305 // case NeutParams::_d0: // changes sign
306 // case NeutParams::_tanDip: // changes sign
307 // newparams->parameter()[iparam] *= -1.0;
308 // flags[iparam] = true;
309 // break;
310 // case NeutParams::_phi0: // changes by pi, but covariance
311 // // matrix shouldn't changed
312 // newparams->parameter()[iparam] =
313 // BesAngle(newparams->parameter()[iparam] + Constants::pi);
314 // flags[iparam] = false;
315 // break;
316 // case NeutParams::_p: // no change sign
317 // case NeutParams::_z0: // no change
318 // flags[iparam] = false;
319 // }
320 // }
321 // return;
322}
323
325 // Visitor access--just use the Visitor class member function
326 vis->trkVisitNeutTraj( this );
327}
HepGeom::Point3D< double > HepPoint3D
TFile f("ana_bhabha660a_dqa_mcPat_zy_old.root")
const Int_t n
HepGeom::Point3D< double > HepPoint3D
void cosAndSin(DifNumber &c, DifNumber &s) const
HepMatrix derivDeflect(double fltlen, deflectDirection) const
Definition NeutTraj.cxx:143
virtual Hep3Vector delDirect(double) const
Definition NeutTraj.cxx:73
virtual double distTo1stError(double s, double tol, int pathDir) const
Definition NeutTraj.cxx:79
HepMatrix derivDisplace(double fltlen, deflectDirection idir) const
Definition NeutTraj.cxx:183
virtual void visitAccept(TrkVisitor *vis) const
Definition NeutTraj.cxx:324
void getDFInfo(double fltLen, DifPoint &, DifVector &dir, DifVector &delDir) const
Definition NeutTraj.cxx:105
HepMatrix derivPFract(double fltlen) const
Definition NeutTraj.cxx:222
NeutTraj & operator=(const NeutTraj &)
Definition NeutTraj.cxx:26
virtual double distTo2ndError(double s, double tol, int pathDir) const
Definition NeutTraj.cxx:85
virtual HepPoint3D position(double fltLen) const
Definition NeutTraj.cxx:57
virtual ~NeutTraj()
Definition NeutTraj.cxx:36
NeutTraj * clone() const
Definition NeutTraj.cxx:24
void invertParams(TrkParams *newparams, std::vector< bool > &flags) const
Definition NeutTraj.cxx:297
virtual Hep3Vector direction(double fltLen) const
Definition NeutTraj.cxx:68
NeutTraj(const NeutParams &, double lowlim=-99999., double hilim=99999., const HepPoint3D &refpoint=_theOrigin)
Definition NeutTraj.cxx:15
void getInfo(double fltLen, HepPoint3D &pos, Hep3Vector &dir) const
Definition NeutTraj.cxx:98
TrkSimpTraj(const HepVector &params, const HepSymMatrix &cov, const double startRange=-99999., const double endRange=99999., const HepPoint3D &refpoint=_theOrigin)
virtual void trkVisitNeutTraj(const NeutTraj *)=0