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