29 m_samestrip = m_gapid[0] == m_nearesthit->Part() && m_gapid[1] == m_nearesthit->Seg() &&
30 m_gapid[2] == m_nearesthit->Gap() && m_iStrip == m_nearesthit->Strip();
36 Hep3Vector mom_unit = m_CurrentMomentum;
37 mom_unit.setMag( 1.0 );
38 Hep3Vector IntrPos_loc = m_nearesthit->GetGap()->TransformToGap( m_CurrentInsct );
39 Hep3Vector mom_loc = m_nearesthit->GetGap()->RotateToGap( m_CurrentMomentum );
40 MucGeoGap* nearestGap = m_nearesthit->GetGap();
42 m_orient = nearestGap->
Orient();
44 m_nearesthit->GetStrip()->GetCenterSigma( sx, sy, sz );
45 if ( m_orient == 1 ) m_sigma = sx / sqrt( 12. );
46 if ( m_orient == 0 ) m_sigma = sy / sqrt( 12. );
49 HepSymMatrix IntrErr_loc( 6, 0 );
50 IntrErr_loc.assign( rotation * m_CurrentInsctXPErr * rotation.T() );
51 Hep3Vector modpos_loc;
52 Hep3Vector modmom_loc;
53 HepSymMatrix moderr_loc( 6, 0 );
55 double chisq =
Fit( IntrPos_loc, mom_loc, IntrErr_loc );
56 modpos_loc.setX( m_bm[0] );
57 modpos_loc.setY( m_bm[1] );
58 modpos_loc.setZ( m_bm[2] );
59 modmom_loc.setX( m_bm[3] );
60 modmom_loc.setY( m_bm[4] );
61 modmom_loc.setZ( m_bm[5] );
63 bool direction =
false;
64 double dirchange = ( modmom_loc.theta() - 1.5707963 ) * ( mom_loc.theta() - 1.5707963 );
70 Hep3Vector modpos_glob = m_nearesthit->GetGap()->TransformToGlobal( modpos_loc );
71 Hep3Vector modmom_glob = m_nearesthit->GetGap()->RotateToGlobal( modmom_loc );
72 HepSymMatrix moderr_glob( 6, 0 );
73 moderr_glob.assign( rotation.T() * moderr_loc * rotation );
75 if ( chisq > 0. && chisq < 100. && !direction )
80 m_err_mod = moderr_glob;
81 m_pos_mod = modpos_glob;
82 m_mom_mod = modmom_glob;
94 vector<MucRecHit*> hitvec;
95 vector<MucRecHit*> HitInGap =
GapHit();
96 int hitsize = HitInGap.size();
97 double dist_nearest = 9999.;
98 for (
int h = 0; h < hitsize; h++ )
107 HepSymMatrix IntrErr_loc( 6, 0 );
108 IntrErr_loc.assign( rotation * m_CurrentInsctXPErr * rotation.T() );
112 double window = -9999.;
115 window = n_sigm * sqrt( IntrErr_loc( 1, 1 ) + sx * sx / 12. );
119 if ( myorient == 0 ) window = n_sigm * sqrt( IntrErr_loc( 2, 2 ) + sy * sy / 12. );
126 if ( fabs( distance ) < window )
128 hitvec.push_back( myhit );
129 if ( dist_nearest > fabs( distance ) )
133 dist_nearest = fabs( distance );
134 m_nearesthit = HitInGap[h];
145 cout <<
"RecMucTrack:GetHitDistance-E1 null hit pointer!" << endl;
149 int part = hit->
Part();
150 int gap = hit->
Gap();
153 cout <<
"RecMucTrack::GetHitDistance() bad gap number = " << gap << endl;
161 float distance = -9990;
162 if ( orient == 1 ) distance = ( posHitLocal.x() - posInsctLocal.x() );
163 if ( orient == 0 ) distance = ( posHitLocal.y() - posInsctLocal.y() );
174 Hep3Vector mom_unit = m_CurrentMomentum;
175 mom_unit.setMag( 1.0 );
177 m_CurrentInsct = _interc;
179 int iStrip = box->
GuessStrip( m_CurrentInsct_loc.x(), m_CurrentInsct_loc.y(),
180 m_CurrentInsct_loc.z() );
201 m_CurrentInsctXPErr = m_CurrentXPErr.similarity( m_jcb );
220 vector<MucRecHit*> gaphit;
222 MucDigiCol::iterator digiIter = m_MucDigiCol->begin();
223 for ( ; digiIter != m_MucDigiCol->end(); digiIter++ )
230 int m_part = (int)m_gapid[0];
231 int m_seg = (int)m_gapid[1];
232 int m_gap = (int)m_gapid[2];
235 if ( m_part == part && m_gap == layer )
236 for (
int s = 0;
s < 3;
s++ )
242 if ( iSeg == segment )
245 gaphit.push_back( hit );
260 HepMatrix m_xp_jcb( 6, 6, 0 );
261 double dx( ( m_CurrentInsct - m_CurrentPosition ).mag() );
263 double p2( m_CurrentMomentum.mag2() );
264 double p_abs( sqrt(
p2 ) );
267 if ( p_abs > Small && m_CurrentMomentum.mag() > Small ) { p_inv = 1.0 / p_abs; }
273 double p2inv( p_inv * p_inv );
274 double p3inv( p2inv * p_inv );
275 double fdx( dx * p3inv );
277 double fdp( dp * p_inv );
278 double px( m_CurrentMomentum.x() );
279 double py( m_CurrentMomentum.y() );
280 double pz( m_CurrentMomentum.z() );
281 double px2( px * px );
282 double py2( py * py );
283 double pz2( pz * pz );
284 double pxy( px * py );
285 double pyz( py * pz );
286 double pzx( pz * px );
287 m_xp_jcb( 1, 1 ) = 1.0;
288 m_xp_jcb( 1, 4 ) = fdx * ( py2 + pz2 );
289 m_xp_jcb( 1, 5 ) = -fdx * pxy;
290 m_xp_jcb( 1, 6 ) = -fdx * pzx;
291 m_xp_jcb( 2, 2 ) = 1.0;
292 m_xp_jcb( 2, 4 ) = -fdx * pxy;
293 m_xp_jcb( 2, 5 ) = fdx * ( pz2 + px2 );
294 m_xp_jcb( 2, 6 ) = -fdx * pyz;
296 m_xp_jcb( 3, 3 ) = 1.0;
297 m_xp_jcb( 3, 4 ) = -fdx * pzx;
298 m_xp_jcb( 3, 5 ) = -fdx * pyz;
299 m_xp_jcb( 3, 6 ) = fdx * ( px2 + py2 );
301 m_xp_jcb( 4, 4 ) = 1.0 - fdp;
302 m_xp_jcb( 5, 5 ) = 1.0 - fdp;
303 m_xp_jcb( 6, 6 ) = 1.0 - fdp;
314 float thetaX, phiX, thetaY, phiY, thetaZ, phiZ;
317 thetaX = thetaX /
kRad;
318 thetaY = thetaY /
kRad;
319 thetaZ = thetaZ /
kRad;
323 Hep3Vector colX, colY, colZ;
324 colX.setRThetaPhi( 1., thetaX, phiX );
325 colY.setRThetaPhi( 1., thetaY, phiY );
326 colZ.setRThetaPhi( 1., thetaZ, phiZ );
328 HepMatrix rotation( 6, 6, 0 );
329 rotation( 1, 1 ) = colX.x();
330 rotation( 1, 2 ) = colX.y();
331 rotation( 1, 3 ) = colX.z();
332 rotation( 2, 1 ) = colY.x();
333 rotation( 2, 2 ) = colY.y();
334 rotation( 2, 3 ) = colY.z();
335 rotation( 3, 1 ) = colZ.x();
336 rotation( 3, 2 ) = colZ.y();
337 rotation( 3, 3 ) = colZ.z();
339 rotation( 4, 4 ) = colX.x();
340 rotation( 4, 5 ) = colX.y();
341 rotation( 4, 6 ) = colX.z();
342 rotation( 5, 4 ) = colY.x();
343 rotation( 5, 5 ) = colY.y();
344 rotation( 5, 6 ) = colY.z();
345 rotation( 6, 4 ) = colZ.x();
346 rotation( 6, 5 ) = colZ.y();
347 rotation( 6, 6 ) = colZ.z();
352 static HepVector a( 6, 0 );
362 HepMatrix V_meas( 1, 1, 0 );
363 V_meas( 1, 1 ) = m_sigma * m_sigma;
364 double mag2( m_bm[5] * m_bm[5] + m_bm[4] * m_bm[4] + m_bm[3] * m_bm[3] );
366 HepSymMatrix ebm( 6, 0 );
369 HepVector v_bm( 6, 0 );
374 HepMatrix
H( 1, 6, 0 );
379 HepMatrix ebm_HT( 6, 1, 0 );
380 ebm_HT = ebm *
H.T();
382 HepMatrix R( 1, 1, 0 );
384 HepMatrix R2( 1, 1, 0 );
385 HepMatrix Aii( 1, 1, 0 );
386 Aii( 1, 1 ) = (
H * ebm_HT )( 1, 1 );
387 R =
H * ebm_HT + V_meas;
390 double aii = Aii( 1, 1 );
392 HepMatrix K( 6, 1, 0 );
394 K = ebm_HT * R.inverse( ierr );
396 double r = R2( 1, 1 );
398 if ( r == 0. ) pull = 9999;
399 else pull = dist / sqrt( r );
403 HepVector diff_v_bm( 6, 0 );
404 diff_v_bm = K * dist;
408 if ( ( fabs( diff_v_bm[0] ) > 2 * n_sigm * sqrt( V_meas( 1, 1 ) + fabs( m_Ebm( 1, 1 ) ) ) &&
410 ( fabs( diff_v_bm[1] ) > 2 * n_sigm * sqrt( V_meas( 1, 1 ) + fabs( m_Ebm( 2, 2 ) ) ) &&
414 cout <<
"KLMK:WARNING! Huge diff_v_bm found!Discard this fit!: " << endl;
418 HepVector v_bm_mod = v_bm + diff_v_bm;
420 static const HepSymMatrix Id( 6, 1 );
421 HepMatrix ebm_mod( 6, 6, 0 );
422 ebm_mod = ( Id - K *
H ) * ebm;
424 r_bm = ( 1 - (
H * K )( 1, 1 ) ) * dist;
427 Rk = ( V_meas -
H * ebm_mod *
H.T() )( 1, 1 );
429 if ( Rk == 0. ) chi2 = 99999;
430 else chi2 = pull * pull;
432 if ( chi2 > 0 && chi2 < chi2lim_ )
434 HepSymMatrix ebm_replace;
435 ebm_replace.assign( ebm_mod );
436 HepVector v_bm_replace;
437 v_bm_replace = v_bm_mod;
443 double mag2mod( m_bm[5] * m_bm[5] + m_bm[4] * m_bm[4] + m_bm[3] * m_bm[3] );
444 v_bm_replace[3] = v_bm_replace[3] * sqrt( mag2 ) / sqrt( mag2mod );
445 v_bm_replace[4] = v_bm_replace[4] * sqrt( mag2 ) / sqrt( mag2mod );
446 v_bm_replace[5] = v_bm_replace[5] * sqrt( mag2 ) / sqrt( mag2mod );
void GetRotationMatrix(float &thetaX, float &phiX, float &thetaY, float &phiY, float &thetaZ, float &phiZ) const
Get the rotation angles (in degrees) of the gap in global coordinate.
MucGeoGap * GetGap(const int part, const int seg, const int gap) const
Get a pointer to the gap identified by (part,seg,gap).