3#include "KalFitAlg/KalFitTrack.h"
4#include "CLHEP/Geometry/Transform3D.h"
5#include "CLHEP/Geometry/Vector3D.h"
6#include "CLHEP/Matrix/Matrix.h"
7#include "CLHEP/Matrix/SymMatrix.h"
8#include "CLHEP/Matrix/Vector.h"
9#include "CLHEP/Units/PhysicalConstants.h"
10#include "CLHEP/Vector/ThreeVector.h"
11#include "GaudiKernel/Bootstrap.h"
12#include "KalFitAlg/KalFitCylinder.h"
13#include "KalFitAlg/KalFitElement.h"
14#include "KalFitAlg/KalFitMaterial.h"
15#include "KalFitAlg/KalFitWire.h"
16#include "KalFitAlg/helix/Helix.h"
17#include "Math/Point3D.h"
18#include "Math/Point3Dfwd.h"
19#include "Math/Vector3D.h"
20#include "MdcGeomSvc/IMdcGeomSvc.h"
22using namespace ROOT::Math;
46int KalFitTrack::lead_ = 2;
47int KalFitTrack::back_ = 1;
64const double KalFitTrack::MASS[NMASS] = { 0.000510999, 0.105658, 0.139568, 0.493677,
74 unsigned int m,
double chisq,
unsigned int nhits )
75 :
Helix( pivot, a, Ea )
100 memset( PathL_, 0,
sizeof( PathL_ ) );
102 if ( m < NMASS ) mass_ = MASS[m];
103 else mass_ = MASS[2];
104 r0_ = fabs( center().perp() - fabs( radius() ) );
116 pivot_last_ =
pivot();
122 pivot_forMdc_ =
pivot();
129 double l =
center().perp();
131 double cosPhi = ( m_rad * m_rad + l * l - r * r ) / ( 2 * m_rad * l );
133 if ( cosPhi < -1 || cosPhi > 1 )
return 0;
135 double dPhi =
center().phi() - acos( cosPhi ) -
phi0();
137 if ( dPhi < -
M_PI ) dPhi += 2 *
M_PI;
143 HepPoint3D xc = plane *
center();
145 double d = r * r - ( y - xc.y() ) * ( y - xc.y() );
146 if ( d < 0 )
return 0;
149 if ( xx > 0 ) xx -= sqrt( d );
150 else xx += sqrt( d );
152 double l = ( plane.inverse() *
HepPoint3D( xx, y, 0 ) ).perp();
158 HepPoint3D xc = plane *
center();
160 double d = r * r - (
x - xc.x() ) * (
x - xc.x() );
161 if ( d < 0 )
return 0;
164 if ( yy > 0 ) yy -= sqrt( d );
165 else yy += sqrt( d );
167 double l = ( plane.inverse() *
HepPoint3D(
x, yy, 0 ) ).perp();
179 HepSymMatrix ea =
Ea();
188 double pmag = 1 / fabs( k ) * sqrt( pt2 );
189 double dth = material.
mcs_angle( mass_, path, pmag );
190 double dth2 = dth * dth;
191 double pt2dth2 = pt2 * dth2;
194 ea[2][2] += k2 * t2 * dth2;
195 ea[2][4] += k *
t * pt2dth2;
196 ea[4][4] += pt2 * pt2dth2;
198 ea[3][3] += dth2 * path * path / 3 / ( 1 + t2 );
199 ea[3][4] += dth2 * path / 2 * sqrt( 1 + t2 );
200 ea[3][2] += dth2 *
t / sqrt( 1 + t2 ) * k * path / 2;
201 ea[0][0] += dth2 * path * path / 3;
202 ea[0][1] += dth2 * sqrt( 1 + t2 ) * path / 2;
209 double x0 = material.
X0();
210 if ( x0 ) path_rd_ += path / x0;
220 double pmag = ( 1 / fabs( k ) ) * sqrt( 1 + t2 );
221 double psq = pmag * pmag;
232 0.0136 * sqrt( pathx * ( mass_ * mass_ + psq ) ) / psq * ( 1 + 0.038 * log( pathx ) );
234 HepSymMatrix ea =
Ea();
236 cout <<
"msgasmdc():path " << path <<
" pathx " << pathx << endl;
237 cout <<
"msgasmdc():dth " << dth << endl;
238 cout <<
"msgasmdc():ea before: " << ea << endl;
240 double dth2 = dth * dth;
242 ea[1][1] += ( 1 + t2 ) * dth2;
243 ea[2][2] += k2 * t2 * dth2;
244 ea[2][4] += k *
t * ( 1 + t2 ) * dth2;
245 ea[4][4] += ( 1 + t2 ) * ( 1 + t2 ) * dth2;
249 ea[3][3] += dth2 * path * path / 3 / ( 1 + t2 );
250 ea[3][4] += dth2 * path / 2 * sqrt( 1 + t2 );
251 ea[3][2] += dth2 *
t / sqrt( 1 + t2 ) * k * path / 2;
252 ea[0][0] += dth2 * path * path / 3;
253 ea[0][1] += dth2 * sqrt( 1 + t2 ) * path / 2;
257 cout <<
"msgasmdc():ea after: " <<
Ea() << endl;
264 path_rd_ += path / x0;
267 cout <<
"ms...pathip..." << pathip_ << endl;
274 cout <<
"eloss():ea before: " <<
Ea() << endl;
277 double v_a_2_2 = v_a[2] * v_a[2];
278 double v_a_4_2 = v_a[4] * v_a[4];
279 double pmag = 1 / fabs( v_a[2] ) * sqrt( 1 + v_a_4_2 );
280 double psq = pmag * pmag;
281 double E = sqrt( mass_ * mass_ + psq );
282 double dE = material.
dE( mass_, path, pmag );
285 if ( index > 0 ) psq += dE * ( dE + 2 * sqrt( mass_ * mass_ + psq ) );
288 double dE_max = E - mass_;
289 if ( dE < dE_max ) psq += dE * ( dE - 2 * sqrt( mass_ * mass_ + psq ) );
298 double psq_kaon = p_kaon_ * p_kaon_;
299 double dE_kaon = material.
dE( MASS[3], path, p_kaon_ );
300 psq_kaon += dE_kaon * ( dE_kaon - 2 * sqrt( MASS[3] * MASS[3] + psq_kaon ) );
301 if ( psq_kaon < 0 ) psq_kaon = 0;
302 p_kaon_ = sqrt( psq_kaon );
307 double psq_proton = p_proton_ * p_proton_;
308 double dE_proton = material.
dE( MASS[4], path, p_proton_ );
309 psq_proton += dE_proton * ( dE_proton - 2 * sqrt( MASS[4] * MASS[4] + psq_proton ) );
310 if ( psq_proton < 0 ) psq_proton = 0;
311 p_proton_ = sqrt( psq_proton );
317 if ( psq < 0 ) dpt = 9999;
318 else dpt = v_a[2] * pmag / sqrt( psq );
321 cout <<
"eloss():k: " << v_a[2] <<
" k' " << dpt << endl;
325 HepSymMatrix ea =
Ea();
326 double r_E_prim = ( E + dE ) / E;
333 else { del_E = material.
del_E( mass_, path, pmag ); }
335 ea[2][2] += ( v_a[2] * v_a[2] ) * E * E * del_E * del_E / ( psq * psq );
339 double dpt2 = dpt * dpt;
340 double A = dpt * dpt2 / ( v_a_2_2 * v_a[2] ) * r_E_prim;
341 double B = v_a[4] / ( 1 + v_a_4_2 ) * dpt * ( 1 - dpt2 / v_a_2_2 * r_E_prim );
343 double ea_2_0 = A * ea[2][0] + B * ea[4][0];
344 double ea_2_1 = A * ea[2][1] + B * ea[4][1];
345 double ea_2_2 = A * A * ea[2][2] + 2 * A * B * ea[2][4] + B * B * ea[4][4];
346 double ea_2_3 = A * ea[2][3] + B * ea[4][3];
347 double ea_2_4 = A * ea[2][4] + B * ea[4][4];
368 unsigned int nhit = HitsMdc_.size();
371 double* Rad =
new double[nhit];
372 double* Ypos =
new double[nhit];
373 for (
unsigned i = 0; i < nhit; i++ )
376 HepPoint3D fwd( HitsMdc_[i].wire().fwd() );
377 HepPoint3D bck( HitsMdc_[i].wire().bck() );
378 Hep3Vector wire = (CLHEP::Hep3Vector)fwd - (CLHEP::Hep3Vector)bck;
381 Helix work = tracktest;
383 work.
pivot( ( fwd + bck ) * .5 );
384 HepPoint3D x0 = ( work.
x( 0 ).z() - bck.z() ) / wire.z() * wire + bck;
386 tracktest.
pivot( x0 );
387 Rad[ind] = tracktest.
x( 0 ).perp();
395 for (
int j, k = nhit - 1; k >= 0; k = j )
398 for (
int i = 1; i <= k; i++ )
399 if ( Rad[i - 1] > Rad[i] )
402 std::swap( Rad[i], Rad[j] );
403 std::swap( HitsMdc_[i], HitsMdc_[j] );
407 for (
int j, k = nhit - 1; k >= 0; k = j )
410 for (
int i = 1; i <= k; i++ )
411 if ( Rad[i - 1] < Rad[i] )
414 std::swap( Rad[i], Rad[j] );
415 std::swap( HitsMdc_[i], HitsMdc_[j] );
419 for (
int j, k = nhit - 1; k >= 0; k = j )
422 for (
int i = 1; i <= k; i++ )
423 if ( Ypos[i - 1] > Ypos[i] )
426 std::swap( Ypos[i], Ypos[j] );
427 std::swap( HitsMdc_[i], HitsMdc_[j] );
435 for (
int it = 0; it <
HitsMdc().size() - 1; it++ )
437 if ( HitsMdc_[it].wire().layer().layerId() == HitsMdc_[it + 1].wire().layer().layerId() )
439 if ( (
kappa() < 0 ) &&
440 ( HitsMdc_[it].wire().localId() > HitsMdc_[it + 1].wire().localId() ) )
441 { std::swap( HitsMdc_[it], HitsMdc_[it + 1] ); }
442 if ( (
kappa() > 0 ) &&
443 ( HitsMdc_[it].wire().localId() < HitsMdc_[it + 1].wire().localId() ) )
444 { std::swap( HitsMdc_[it], HitsMdc_[it + 1] ); }
450 unsigned int nhit = HitsMdc_.size();
452 for (
unsigned i = 0; i < nhit; i++ ) Num[HitsMdc_[i].wire().layer().layerId()]++;
453 for (
unsigned i = 0; i < nhit; i++ )
454 if ( Num[HitsMdc_[i].wire().layer().layerId()] > 2 ) HitsMdc_[i].chi2( -2 );
458 double& dchi2,
int csmflag ) {
465 if ( wire_ID < 0 || wire_ID > 6796 )
467 std::cout <<
"KalFitTrack : wire_ID problem : " << wire_ID << std::endl;
477 double csf0 =
cos( phi );
478 double snf0 = ( 1. - csf0 ) * ( 1. + csf0 );
479 snf0 = sqrt( ( snf0 > 0. ) ? snf0 : 0. );
480 if ( phi >
M_PI ) snf0 = -snf0;
484 Hep3Vector ip( 0, 0, 0 );
488 double phi_ip = work.
phi0();
489 if ( fabs( phi - phi_ip ) >
M_PI )
491 if ( phi > phi_ip ) phi -= 2 *
M_PI;
492 else phi_ip -= 2 *
M_PI;
495 double l = fabs(
radius() * ( phi - phi_ip ) * sqrt( 1 +
t *
t ) );
496 double pmag( sqrt( 1.0 +
t *
t ) /
kappa() );
497 double mass_over_p( mass_ / pmag );
498 double beta( 1.0 / sqrt( 1.0 + mass_over_p * mass_over_p ) );
499 tofest = l / ( 29.9792458 * beta );
500 if ( csmflag == 1 &&
HitMdc.wire().y() > 0. ) tofest = -1. * tofest;
503 const HepSymMatrix& ea =
Ea();
504 const HepVector& v_a =
a();
508 double dchi2R( 99999999 ), dchi2L( 99999999 );
510 HepVector v_H( 5, 0 );
511 v_H[0] = -csf0 * meas.x() - snf0 * meas.y();
513 HepMatrix v_HT = v_H.T();
515 double estim = ( v_HT * v_a )[0];
516 HepVector ea_v_H = ea * v_H;
517 HepMatrix ea_v_HT = ( ea_v_H ).T();
518 HepVector v_H_T_ea_v_H = v_HT * ea_v_H;
520 HepSymMatrix eaNew( 5 );
542 double dmeas2[2] = { 0.1 * ddl, 0.1 * ddr };
543 double er_dmeas2[2] = { 0., 0. };
546 er_dmeas2[0] = 0.1 * erddl;
547 er_dmeas2[1] = 0.1 * erddr;
559 double er_dmeasL, dmeasL;
562 dmeasL = ( -1.0 ) * dmeas2[0];
563 er_dmeasL = er_dmeas2[0];
567 dmeasL = ( -1.0 ) * fabs(
HitMdc.dist()[0] );
569 er_dmeasL =
HitMdc.erdist()[0];
572 double AL = 1 / ( ( v_H_T_ea_v_H )[0] + er_dmeasL * er_dmeasL );
573 eaNew.assign( ea - ea_v_H * AL * ea_v_HT );
574 double RkL = 1 - ( v_H_T_ea_v_H )[0] * AL;
575 if ( 0. == RkL ) RkL = 1.e-4;
577 HepVector diffL = ea_v_H * AL * ( dmeasL - estim );
579 double sigL = ( dmeasL - ( v_HT * aNew )[0] );
580 dchi2L = ( sigL * sigL ) / ( RkL * er_dmeasL * er_dmeasL );
586 double er_dmeasR, dmeasR;
590 er_dmeasR = er_dmeas2[1];
594 dmeasR = fabs(
HitMdc.dist()[1] );
595 er_dmeasR =
HitMdc.erdist()[1];
598 double AR = 1 / ( ( v_H_T_ea_v_H )[0] + er_dmeasR * er_dmeasR );
599 eaNew.assign( ea - ea_v_H * AR * ea_v_HT );
600 double RkR = 1 - ( v_H_T_ea_v_H )[0] * AR;
601 if ( 0. == RkR ) RkR = 1.e-4;
603 HepVector diffR = ea_v_H * AR * ( dmeasR - estim );
605 double sigR = ( dmeasR - ( v_HT * aNew )[0] );
606 dchi2R = ( sigR * sigR ) / ( RkR * er_dmeasR * er_dmeasR );
611 cout <<
"in smoother_Mdc: lr= " << lr <<
" a: " << v_a <<
" a_NEW: " << aNew << endl;
613 double dchi2_loc( 0 );
619 if ( !( aNew[2] && fabs( aNew[2] -
a()[2] ) < 1.0 ) ) chge = 0;
622 chiSq_back_ += dchi2R;
628 chiSq_back_ += dchi2L;
643 Hep3Vector ip( 0, 0, 0 );
645 helixNew1.pivot( ip );
646 HepVector a_temp1 = helixNew1.a();
647 HepSymMatrix ea_temp1 = helixNew1.Ea();
653 KalFitTrack helixNew2( pivot_work, v_a, ea, 0, 0, 0 );
654 helixNew2.pivot( ip );
655 HepVector a_temp2 = helixNew2.a();
656 HepSymMatrix ea_temp2 = helixNew2.Ea();
679 int layerid = ( *HitMdc ).wire().layer().layerId();
680 int wire_ID =
HitMdc->wire().geoID();
681 double entrangle =
HitMdc->rechitptr()->getEntra();
683 if ( wire_ID < 0 || wire_ID > 6796 )
685 std::cout <<
"KalFitTrack : wire_ID problem : " << wire_ID << std::endl;
694 double csf0 =
cos( phi );
695 double snf0 = ( 1. - csf0 ) * ( 1. + csf0 );
696 snf0 = sqrt( ( snf0 > 0. ) ? snf0 : 0. );
697 if ( phi >
M_PI ) snf0 = -snf0;
701 Hep3Vector ip( 0, 0, 0 );
705 double phi_ip = work.
phi0();
706 if ( fabs( phi - phi_ip ) >
M_PI )
708 if ( phi > phi_ip ) phi -= 2 *
M_PI;
709 else phi_ip -= 2 *
M_PI;
712 double l = fabs(
radius() * ( phi - phi_ip ) * sqrt( 1 +
t *
t ) );
713 double pmag( sqrt( 1.0 +
t *
t ) /
kappa() );
714 double mass_over_p( mass_ / pmag );
715 double beta( 1.0 / sqrt( 1.0 + mass_over_p * mass_over_p ) );
716 tofest = l / ( 29.9792458 * beta );
717 if ( csmflag == 1 && ( *HitMdc ).wire().y() > 0. ) tofest = -1. * tofest;
720 const HepSymMatrix& ea =
Ea();
721 const HepVector& v_a =
a();
743 double dchi2R( 99999999 ), dchi2L( 99999999 );
744 HepVector v_H( 5, 0 );
745 v_H[0] = -csf0 * meas.x() - snf0 * meas.y();
747 HepMatrix v_HT = v_H.T();
749 double estim = ( v_HT * v_a )[0];
750 HepVector ea_v_H = ea * v_H;
751 HepMatrix ea_v_HT = ( ea_v_H ).T();
752 HepVector v_H_T_ea_v_H = v_HT * ea_v_H;
753 HepSymMatrix eaNew( 5 );
755 double time = ( *HitMdc ).tdc();
773 double dmeas2[2] = { 0.1 * ddl, 0.1 * ddr };
774 double er_dmeas2[2] = { 0., 0. };
777 er_dmeas2[0] = 0.1 * erddl;
778 er_dmeas2[1] = 0.1 * erddr;
785 double er_dmeasL, dmeasL;
788 dmeasL = ( -1.0 ) * dmeas2[0];
789 er_dmeasL = er_dmeas2[0];
793 dmeasL = ( -1.0 ) * fabs( ( *HitMdc ).dist()[0] );
794 er_dmeasL = ( *HitMdc ).erdist()[0];
799 double AL = 1 / ( ( v_H_T_ea_v_H )[0] + er_dmeasL * er_dmeasL );
800 eaNew.assign( ea - ea_v_H * AL * ea_v_HT );
801 double RkL = 1 - ( v_H_T_ea_v_H )[0] * AL;
802 if ( 0. == RkL ) RkL = 1.e-4;
804 HepVector diffL = ea_v_H * AL * ( dmeasL - estim );
806 double sigL = ( dmeasL - ( v_HT * aNew )[0] );
807 dchi2L = ( sigL * sigL ) / ( RkL * er_dmeasL * er_dmeasL );
813 double er_dmeasR, dmeasR;
817 er_dmeasR = er_dmeas2[1];
821 dmeasR = fabs( ( *HitMdc ).dist()[1] );
822 er_dmeasR = ( *HitMdc ).erdist()[1];
827 double AR = 1 / ( ( v_H_T_ea_v_H )[0] + er_dmeasR * er_dmeasR );
828 eaNew.assign( ea - ea_v_H * AR * ea_v_HT );
829 double RkR = 1 - ( v_H_T_ea_v_H )[0] * AR;
830 if ( 0. == RkR ) RkR = 1.e-4;
832 HepVector diffR = ea_v_H * AR * ( dmeasR - estim );
834 double sigR = ( dmeasR - ( v_HT * aNew )[0] );
835 dchi2R = ( sigR * sigR ) / ( RkR * er_dmeasR * er_dmeasR );
840 cout <<
"in smoother_Mdc: lr= " << lr <<
" a: " << v_a <<
" a_NEW: " << aNew << endl;
842 double dchi2_loc( 0 );
850 if ( !( aNew[2] && fabs( aNew[2] -
a()[2] ) < 1.0 ) ) chge = 0;
853 chiSq_back_ += dchi2R;
860 chiSq_back_ += dchi2L;
873 HepVector a_pre_fwd_temp = seg.
a_pre_fwd();
874 if ( ( a_pre_fwd_temp[1] - seg.
a_pre_bwd()[1] ) > 3. *
M_PI / 2. )
875 a_pre_fwd_temp[1] -=
M_PI2;
876 if ( ( a_pre_fwd_temp[1] - seg.
a_pre_bwd()[1] ) < -3. *
M_PI / 2. )
877 a_pre_fwd_temp[1] +=
M_PI2;
882 if ( ( a_pre_filt_temp[1] - seg.
a_pre_bwd()[1] ) > 3. *
M_PI / 2. )
883 a_pre_filt_temp[1] -=
M_PI2;
884 if ( ( a_pre_filt_temp[1] - seg.
a_pre_bwd()[1] ) < -3. *
M_PI / 2. )
885 a_pre_filt_temp[1] +=
M_PI2;
901 std::cout <<
"seg.Ea_pre_bwd().inverse(inv) ..." << seg.
Ea_pre_bwd().inverse( inv )
903 std::cout <<
"seg.Ea_pre_fwd().inverse(inv) ..." << seg.
Ea_pre_fwd().inverse( inv )
907 HepSymMatrix Ea_pre_comb =
913 std::cout <<
"Ea_pre_comb_ ... " << Ea_pre_comb << std::endl;
914 std::cout <<
"seg.a_pre_bwd()..." << seg.
a_pre_bwd() << std::endl;
915 std::cout <<
"seg.a_pre_fwd()..." << seg.
a_pre_fwd() << std::endl;
917 HepVector a_pre_comb =
924 std::cout <<
"seg.Ea_filt_fwd()..." << seg.
Ea_filt_fwd() << std::endl;
925 std::cout <<
"seg.Ea_filt_fwd().inverse(inv)..." << seg.
Ea_filt_fwd().inverse( inv )
935 std::cout <<
"seg.Ea() is ..." << seg.
Ea() << std::endl;
936 std::cout <<
"seg.Ea_filt_fwd().inverse(inv)*seg.a_filt_fwd() ..."
938 std::cout <<
"seg.Ea_pre_bwd().inverse(inv)*seg.a_pre_bwd() ... "
959 std::cout <<
"the dd in smoother_Mdc is " << dd <<
" the (v_HT*a_pre_comb)[0] is "
960 << ( v_HT * a_pre_comb )[0] << std::endl;
966 std::cout <<
"method 1 ..." << sqrt( seg.
a()[0] * seg.
a()[0] + seg.
a()[3] * seg.
a()[3] )
968 std::cout <<
"method 2 ..." << fabs( ( v_HT * seg.
a() )[0] ) << std::endl;
973 helixNew1.pivot( ip );
974 HepVector a_temp1 = helixNew1.a();
975 HepSymMatrix ea_temp1 = helixNew1.Ea();
982 helixNew2.pivot( ip );
983 HepVector a_temp2 = helixNew2.a();
984 HepSymMatrix ea_temp2 = helixNew2.Ea();
1004 double lr =
HitMdc->LR();
1007 int layerid = ( *HitMdc ).wire().layer().layerId();
1008 int wire_ID =
HitMdc->wire().geoID();
1009 double entrangle =
HitMdc->rechitptr()->getEntra();
1011 if ( wire_ID < 0 || wire_ID > 6796 )
1013 std::cout <<
"KalFitTrack : wire_ID problem : " << wire_ID << std::endl;
1022 double csf0 =
cos( phi );
1023 double snf0 = ( 1. - csf0 ) * ( 1. + csf0 );
1024 snf0 = sqrt( ( snf0 > 0. ) ? snf0 : 0. );
1025 if ( phi >
M_PI ) snf0 = -snf0;
1029 Hep3Vector ip( 0, 0, 0 );
1033 double phi_ip = work.
phi0();
1034 if ( fabs( phi - phi_ip ) >
M_PI )
1036 if ( phi > phi_ip ) phi -= 2 *
M_PI;
1037 else phi_ip -= 2 *
M_PI;
1040 double l = fabs(
radius() * ( phi - phi_ip ) * sqrt( 1 +
t *
t ) );
1041 double pmag( sqrt( 1.0 +
t *
t ) /
kappa() );
1042 double mass_over_p( mass_ / pmag );
1043 double beta( 1.0 / sqrt( 1.0 + mass_over_p * mass_over_p ) );
1044 tofest = l / ( 29.9792458 * beta );
1045 if ( csmflag == 1 && ( *HitMdc ).wire().y() > 0. ) tofest = -1. * tofest;
1048 const HepSymMatrix& ea =
Ea();
1049 const HepVector& v_a =
a();
1071 double dchi2R( 99999999 ), dchi2L( 99999999 );
1072 HepVector v_H( 5, 0 );
1073 v_H[0] = -csf0 * meas.x() - snf0 * meas.y();
1075 HepMatrix v_HT = v_H.T();
1077 double estim = ( v_HT * v_a )[0];
1078 HepVector ea_v_H = ea * v_H;
1079 HepMatrix ea_v_HT = ( ea_v_H ).T();
1080 HepVector v_H_T_ea_v_H = v_HT * ea_v_H;
1081 HepSymMatrix eaNew( 5 );
1082 HepVector aNew( 5 );
1083 double time = ( *HitMdc ).tdc();
1095 seg.
dt( drifttime );
1101 double dmeas2[2] = { 0.1 * ddl, 0.1 * ddr };
1102 double er_dmeas2[2] = { 0., 0. };
1105 er_dmeas2[0] = 0.1 * erddl;
1106 er_dmeas2[1] = 0.1 * erddr;
1113 double er_dmeasL, dmeasL;
1116 dmeasL = ( -1.0 ) * dmeas2[0];
1117 er_dmeasL = er_dmeas2[0];
1121 dmeasL = ( -1.0 ) * fabs( ( *HitMdc ).dist()[0] );
1122 er_dmeasL = ( *HitMdc ).erdist()[0];
1127 double AL = 1 / ( ( v_H_T_ea_v_H )[0] + er_dmeasL * er_dmeasL );
1128 eaNew.assign( ea - ea_v_H * AL * ea_v_HT );
1129 double RkL = 1 - ( v_H_T_ea_v_H )[0] * AL;
1130 if ( 0. == RkL ) RkL = 1.e-4;
1132 HepVector diffL = ea_v_H * AL * ( dmeasL - estim );
1134 double sigL = ( dmeasL - ( v_HT * aNew )[0] );
1135 dchi2L = ( sigL * sigL ) / ( RkL * er_dmeasL * er_dmeasL );
1141 double er_dmeasR, dmeasR;
1145 er_dmeasR = er_dmeas2[1];
1149 dmeasR = fabs( ( *HitMdc ).dist()[1] );
1150 er_dmeasR = ( *HitMdc ).erdist()[1];
1155 double AR = 1 / ( ( v_H_T_ea_v_H )[0] + er_dmeasR * er_dmeasR );
1156 eaNew.assign( ea - ea_v_H * AR * ea_v_HT );
1157 double RkR = 1 - ( v_H_T_ea_v_H )[0] * AR;
1158 if ( 0. == RkR ) RkR = 1.e-4;
1160 HepVector diffR = ea_v_H * AR * ( dmeasR - estim );
1162 double sigR = ( dmeasR - ( v_HT * aNew )[0] );
1163 dchi2R = ( sigR * sigR ) / ( RkR * er_dmeasR * er_dmeasR );
1168 cout <<
"in smoother_Mdc: lr= " << lr <<
" a: " << v_a <<
" a_NEW: " << aNew << endl;
1170 double dchi2_loc( 0 );
1178 if ( !( aNew[2] && fabs( aNew[2] -
a()[2] ) < 1.0 ) ) chge = 0;
1181 chiSq_back_ += dchi2R;
1186 else if ( lr == -1 )
1188 chiSq_back_ += dchi2L;
1201 HepVector a_pre_fwd_temp = seg.
a_pre_fwd();
1202 if ( ( a_pre_fwd_temp[1] - seg.
a_pre_bwd()[1] ) > 3. *
M_PI / 2. )
1203 a_pre_fwd_temp[1] -=
M_PI2;
1204 if ( ( a_pre_fwd_temp[1] - seg.
a_pre_bwd()[1] ) < -3. *
M_PI / 2. )
1205 a_pre_fwd_temp[1] +=
M_PI2;
1209 HepVector a_pre_filt_temp = seg.
a_filt_fwd();
1210 if ( ( a_pre_filt_temp[1] - seg.
a_pre_bwd()[1] ) > 3. *
M_PI / 2. )
1211 a_pre_filt_temp[1] -=
M_PI2;
1212 if ( ( a_pre_filt_temp[1] - seg.
a_pre_bwd()[1] ) < -3. *
M_PI / 2. )
1213 a_pre_filt_temp[1] +=
M_PI2;
1229 std::cout <<
"seg.Ea_pre_bwd().inverse(inv) ..." << seg.
Ea_pre_bwd().inverse( inv )
1231 std::cout <<
"seg.Ea_pre_fwd().inverse(inv) ..." << seg.
Ea_pre_fwd().inverse( inv )
1235 HepSymMatrix Ea_pre_comb =
1241 std::cout <<
"Ea_pre_comb_ ... " << Ea_pre_comb << std::endl;
1242 std::cout <<
"seg.a_pre_bwd()..." << seg.
a_pre_bwd() << std::endl;
1243 std::cout <<
"seg.a_pre_fwd()..." << seg.
a_pre_fwd() << std::endl;
1245 HepVector a_pre_comb =
1252 std::cout <<
"seg.Ea_filt_fwd()..." << seg.
Ea_filt_fwd() << std::endl;
1253 std::cout <<
"seg.Ea_filt_fwd().inverse(inv)..." << seg.
Ea_filt_fwd().inverse( inv )
1263 std::cout <<
"seg.Ea() is ..." << seg.
Ea() << std::endl;
1264 std::cout <<
"seg.Ea_filt_fwd().inverse(inv)*seg.a_filt_fwd() ..."
1266 std::cout <<
"seg.Ea_pre_bwd().inverse(inv)*seg.a_pre_bwd() ... "
1287 std::cout <<
"the dd in smoother_Mdc is " << dd <<
" the (v_HT*a_pre_comb)[0] is "
1288 << ( v_HT * a_pre_comb )[0] << std::endl;
1294 std::cout <<
"method 1 ..." << sqrt( seg.
a()[0] * seg.
a()[0] + seg.
a()[3] * seg.
a()[3] )
1296 std::cout <<
"method 2 ..." << fabs( ( v_HT * seg.
a() )[0] ) << std::endl;
1301 helixNew1.pivot( ip );
1302 HepVector a_temp1 = helixNew1.a();
1303 HepSymMatrix ea_temp1 = helixNew1.Ea();
1310 helixNew2.pivot( ip );
1311 HepVector a_temp2 = helixNew2.a();
1312 HepSymMatrix ea_temp2 = helixNew2.Ea();
1323 HepMatrix m_HT = m_H.T();
1330 HepMatrix m_XT = m_X.T();
1331 HepMatrix
m_C = m_X *
Ea() * m_XT;
1333 HepVector m_K = 1 / ( m_V + ( m_HT *
m_C * m_H )[0] ) * m_H;
1334 HepVector v_a =
a();
1335 HepSymMatrix ea =
Ea();
1336 HepMatrix mXTmK = m_XT * m_K;
1337 double v_r = v_m - v_d - ( m_HT * v_x )[0];
1338 v_a += ea * mXTmK * v_r;
1340 ea.assign( ea - ea * mXTmK * m_HT * m_X * ea );
1344 HepMatrix mCmK =
m_C * m_K;
1346 m_C -= mCmK * m_HT *
m_C;
1347 v_r = v_m - v_d - ( m_HT * v_x )[0];
1348 double m_R = m_V - ( m_HT *
m_C * m_H )[0];
1349 double chiSq = v_r * v_r / m_R;
1366 double light_speed( 29.9792458 );
1368 double pmag( sqrt( 1.0 +
t *
t ) /
kappa() );
1371 double mass_over_p( mass_ / pmag );
1372 double beta( 1.0 / sqrt( 1.0 + mass_over_p * mass_over_p ) );
1373 tof_ += path / ( light_speed * beta );
1380 double massk_over_p( MASS[3] / p_kaon_ );
1381 double beta_kaon( 1.0 / sqrt( 1.0 + massk_over_p * massk_over_p ) );
1382 tof_kaon_ += path / ( light_speed * beta_kaon );
1384 if ( p_proton_ > 0 )
1386 double massp_over_p( MASS[4] / p_proton_ );
1387 double beta_proton( 1.0 / sqrt( 1.0 + massp_over_p * massp_over_p ) );
1388 tof_proton_ += path / ( light_speed * beta_proton );
1400 double phi0 =
a()[1];
1403 double csf0 =
cos( phi );
1404 double snf0 = ( 1. - csf0 ) * ( 1. + csf0 );
1405 snf0 = sqrt( ( snf0 > 0. ) ? snf0 : 0. );
1406 if ( phi >
M_PI ) snf0 = -snf0;
1408 HepPoint3D x0( (
pivot().
x() +
dr * csf0 ), (
pivot().y() +
dr * snf0 ),
1416 MFSvc_->fieldVector( 10. * x0, b );
1423 if ( Bz == 0 ) Bz =
Bznom_;
1424 double ALPHA_loc = 10000. / 2.99792458 / Bz;
1425 return ALPHA_loc /
a()[2];
1438 HepPoint3D nextPivot(
pivot() + delta_x );
1439 double xnp( nextPivot.x() ), ynp( nextPivot.y() ), znp( nextPivot.z() );
1440 HepSymMatrix Ea_now =
Ea();
1441 HepPoint3D piv(
pivot() );
1442 double xp( piv.x() ), yp( piv.y() ), zp( piv.z() );
1444 double phi0 =
a()[1];
1447 double tanl =
a()[4];
1451 double rdr =
dr + m_rad;
1453 double csf0 =
cos( phi );
1454 double snf0 = ( 1. - csf0 ) * ( 1. + csf0 );
1455 snf0 = sqrt( ( snf0 > 0. ) ? snf0 : 0. );
1456 if ( phi >
M_PI ) snf0 = -snf0;
1458 double xc = xp + rdr * csf0;
1459 double yc = yp + rdr * snf0;
1460 double csf = ( xc - xnp ) / m_rad;
1461 double snf = ( yc - ynp ) / m_rad;
1462 double anrm = sqrt( csf * csf + snf * snf );
1465 phi = atan2( snf, csf );
1468 double drp = ( xp +
dr * csf0 + m_rad * ( csf0 - csf ) - xnp ) * csf +
1469 ( yp +
dr * snf0 + m_rad * ( snf0 - snf ) - ynp ) * snf;
1470 double dzp = zp +
dz - m_rad *
tanl * phid - znp;
1483 Hep3Vector x1( xp +
dr * csf0, yp +
dr * snf0, zp +
dz );
1484 double csf0p =
cos( ap[1] );
1485 double snf0p = ( 1. - csf0p ) * ( 1. + csf0p );
1486 snf0p = sqrt( ( snf0p > 0. ) ? snf0p : 0. );
1487 if ( ap[1] >
M_PI ) snf0p = -snf0p;
1489 Hep3Vector x2( xnp + drp * csf0p, ynp + drp * snf0p, znp + dzp );
1490 Hep3Vector dist( ( x1 - x2 ).
x() / 100.0, ( x1 - x2 ).y() / 100.0,
1491 ( x1 - x2 ).z() / 100.0 );
1492 HepPoint3D middlebis( ( x1.x() + x2.x() ) / 2, ( x1.y() + x2.y() ) / 2,
1493 ( x1.z() + x2.z() ) / 2 );
1495 MFSvc_->fieldVector( 10. * middlebis, field );
1496 field = 1000. * field;
1497 Hep3Vector dB( field.x(), field.y(), ( field.z() - 0.1 *
Bznom_ ) );
1500 double akappa( fabs(
kappa ) );
1501 double sign =
kappa / akappa;
1503 dp = 0.299792458 * sign * dB.cross( dist );
1505 dhp[0] = -akappa * ( dp[0] * csf0p + dp[1] * snf0p );
1506 dhp[1] =
kappa * akappa * ( dp[0] * snf0p - dp[1] * csf0p );
1507 dhp[2] = dp[2] * akappa + dhp[1] *
tanl /
kappa;
1508 if (
numfcor_ == 0 ) { ap[1] += dhp[0]; }
1514 Ea_now.assign( m_del * Ea_now * m_del.T() );
1528 double th = 90.0 - 180.0 * M_1_PI * atan( tl );
1546 HepPoint3D nextPivot(
pivot() + delta_x );
1547 double xnp( nextPivot.x() ), ynp( nextPivot.y() ), znp( nextPivot.z() );
1549 HepSymMatrix Ea_now =
Ea();
1550 HepPoint3D piv(
pivot() );
1551 double xp( piv.x() ), yp( piv.y() ), zp( piv.z() );
1554 double phi0 =
a()[1];
1557 double tanl =
a()[4];
1562 double rdr =
dr + m_rad;
1564 double csf0 =
cos( phi );
1565 double snf0 = ( 1. - csf0 ) * ( 1. + csf0 );
1566 snf0 = sqrt( ( snf0 > 0. ) ? snf0 : 0. );
1567 if ( phi >
M_PI ) snf0 = -snf0;
1569 double xc = xp + rdr * csf0;
1570 double yc = yp + rdr * snf0;
1571 double csf = ( xc - xnp ) / m_rad;
1572 double snf = ( yc - ynp ) / m_rad;
1573 double anrm = sqrt( csf * csf + snf * snf );
1576 phi = atan2( snf, csf );
1579 double drp = ( xp +
dr * csf0 + m_rad * ( csf0 - csf ) - xnp ) * csf +
1580 ( yp +
dr * snf0 + m_rad * ( snf0 - snf ) - ynp ) * snf;
1581 double dzp = zp +
dz - m_rad *
tanl * phid - znp;
1596 Hep3Vector x1( xp +
dr * csf0, yp +
dr * snf0, zp +
dz );
1598 double csf0p =
cos( ap[1] );
1599 double snf0p = ( 1. - csf0p ) * ( 1. + csf0p );
1600 snf0p = sqrt( ( snf0p > 0. ) ? snf0p : 0. );
1601 if ( ap[1] >
M_PI ) snf0p = -snf0p;
1603 Hep3Vector x2( xnp + drp * csf0p, ynp + drp * snf0p, znp + dzp );
1605 Hep3Vector dist( ( x1 - x2 ).
x() / 100.0, ( x1 - x2 ).y() / 100.0,
1606 ( x1 - x2 ).z() / 100.0 );
1608 HepPoint3D middlebis( ( x1.x() + x2.x() ) / 2, ( x1.y() + x2.y() ) / 2,
1609 ( x1.z() + x2.z() ) / 2 );
1612 MFSvc_->fieldVector( 10. * middlebis, field );
1613 field = 1000. * field;
1616 Hep3Vector dB( field.x(), field.y(), ( field.z() - 0.1 *
Bznom_ ) );
1622 double akappa( fabs(
kappa ) );
1623 double sign =
kappa / akappa;
1625 dp = 0.299792458 * sign * dB.cross( dist );
1630 dhp[0] = -akappa * ( dp[0] * csf0p + dp[1] * snf0p );
1631 dhp[1] =
kappa * akappa * ( dp[0] * snf0p - dp[1] * csf0p );
1632 dhp[2] = dp[2] * akappa + dhp[1] *
tanl /
kappa;
1642 Ea_now.assign( m_del * Ea_now * m_del.T() );
1652 double tanl_0( tracktest.
a()[4] );
1653 double phi0_0( tracktest.
a()[1] );
1654 double radius_0( tracktest.
radius() );
1655 tracktest.
pivot( newPivot );
1657 double phi0_1 = tracktest.
a()[1];
1658 if ( fabs( phi0_1 - phi0_0 ) >
M_PI )
1660 if ( phi0_1 > phi0_0 ) phi0_1 -= 2 *
M_PI;
1661 else phi0_0 -= 2 *
M_PI;
1663 if ( phi0_1 == phi0_0 ) phi0_1 = phi0_0 + 1.e-10;
1664 pathl = fabs( radius_0 * ( phi0_1 - phi0_0 ) * sqrt( 1 + tanl_0 * tanl_0 ) );
1774 Hep3Vector zvector( 0., 0., z_c-rho*dphi*tanl);
1776 double xcio, ycio, phip;
1778 double delrin = 2.0;
1779 if( m_zf-delrin > zvector.z() ){
1780 phip = z_c - m_zb + delrin;
1781 phip = phip/( rho*tanl );
1783 xcio = x_c - rho*cos( phip );
1784 ycio = y_c - rho*sin( phip );
1785 cell_IO[i].setX( xcio );
1786 cell_IO[i].setY( ycio );
1787 cell_IO[i].setZ( m_zb+delrin );
1790 else if( m_zb+delrin < zvector.z() ){
1791 phip = z_c - m_zf-delrin;
1792 phip = phip/( rho*tanl );
1794 xcio = x_c - rho*cos( phip );
1795 ycio = y_c - rho*sin( phip );
1796 cell_IO[i].setX( xcio );
1797 cell_IO[i].setY( ycio );
1798 cell_IO[i].setZ( m_zf-delrin );
1802 cell_IO[i] = iocand;
1803 cell_IO[i] += zvector;
1806 if( i == 0 ) phi_in = dphi;
1808// path length estimation
1810Hep3Vector cl = cell_IO[1] - cell_IO[0];
1812cout<<"cell_IO[0] "<<cell_IO[0]<<" cell_IO[1] "<<cell_IO[1]<<" cl "<<cl<<endl;
1818double ch_ltrk_rp = 0;
1819ch_dphi = cl.perp()*0.5/(ALPHA_loc*pt);
1820ch_dphi = 2.0 * asin( ch_dphi );
1821ch_ltrk_rp = ch_dphi*ALPHA_loc*pt;
1823cout<<"ch_dphi "<<ch_dphi<<" ch_ltrk_rp "<<ch_ltrk_rp<<" cl.z "<<cl.z()<<endl;
1825ch_ltrk = sqrt( ch_ltrk_rp*ch_ltrk_rp + cl.z()*cl.z() );
1826ch_theta = cl.theta();
1828if( ch_theta < theta*0.85 || 1.15*theta < ch_theta)
1829 ch_ltrk *= -1; /// miss calculation
1831if( epflag[0] == 1 || epflag [1] == 1 )
1832 ch_ltrk *= -1; /// invalid resion for dE/dx or outside of Mdc
1834 mom_[layer] = momentum( phi_in );
1835 PathL_[layer] = ch_ltrk;
1837 cout<<"ch_ltrk "<<ch_ltrk<<endl;
1847 j = (int)pow( 2., i );
1848 if ( !( pat1_ & j ) ) pat1_ = pat1_ | j;
1852 j = (int)pow( 2., ( i - 31 ) );
1853 if ( !( pat2_ & j ) ) pat2_ = pat2_ | j;
1884 double& dchi2out,
double& dtrack,
double& dtracknew,
1885 double& dtdc,
int csmflag ) {
1891 int wire_ID = Wire.
geoID();
1896 if ( wire_ID < 0 || wire_ID > 6796 )
1898 std::cout <<
" KalFitTrack: wire_ID problem : " << wire_ID << std::endl;
1901 int flag_ster = Wire.
stereo();
1906 double csf0 =
cos( phi );
1907 double snf0 = ( 1. - csf0 ) * ( 1. + csf0 );
1908 snf0 = sqrt( ( snf0 > 0. ) ? snf0 : 0. );
1909 if ( phi >
M_PI ) snf0 = -snf0;
1918 Hep3Vector ip( 0, 0, 0 );
1920 phi_ip = work.
phi0();
1921 if ( fabs( phi - phi_ip ) >
M_PI )
1923 if ( phi > phi_ip ) phi -= 2 *
M_PI;
1924 else phi_ip -= 2 *
M_PI;
1926 dphi = phi - phi_ip;
1927 double l = fabs(
radius() * dphi * sqrt( 1 +
t *
t ) );
1928 double pmag( sqrt( 1.0 +
t *
t ) /
kappa() );
1929 double mass_over_p( mass_ / pmag );
1930 double beta( 1.0 / sqrt( 1.0 + mass_over_p * mass_over_p ) );
1931 tofest = l / ( 29.9792458 * beta );
1932 if ( csmflag == 1 &&
HitMdc.wire().y() > 0. ) tofest = -1. * tofest;
1935 const HepSymMatrix& ea =
Ea();
1936 const HepVector& v_a =
a();
1937 double dchi2R( 99999999 ), dchi2L( 99999999 );
1939 HepVector v_H( 5, 0 );
1940 v_H[0] = -csf0 * meas.x() - snf0 * meas.y();
1942 HepMatrix v_HT = v_H.T();
1944 double estim = ( v_HT * v_a )[0];
1947 HepVector ea_v_H = ea * v_H;
1948 HepMatrix ea_v_HT = ( ea_v_H ).T();
1949 HepVector v_H_T_ea_v_H = v_HT * ea_v_H;
1951 HepSymMatrix eaNewL( 5 ), eaNewR( 5 );
1952 HepVector aNewL( 5 ), aNewR( 5 );
1962 std::cout <<
"drifttime in update_hits() for ananlysis is " << drifttime << std::endl;
1963 std::cout <<
"ddl in update_hits() for ananlysis is " << ddl << std::endl;
1964 std::cout <<
"ddr in update_hits() for ananlysis is " << ddr << std::endl;
1965 std::cout <<
"erddl in update_hits() for ananlysis is " << erddl << std::endl;
1966 std::cout <<
"erddr in update_hits() for ananlysis is " << erddr << std::endl;
1970 double dmeas2[2] = { 0.1 * ddl, 0.1 * ddr };
1971 double er_dmeas2[2] = { 0., 0. };
1974 er_dmeas2[0] = 0.1 * erddl;
1975 er_dmeas2[1] = 0.1 * erddr;
1985 if ( (
LR_ == 0 && lr != 1.0 ) || (
LR_ == 1 && lr == -1.0 ) )
1987 double er_dmeasL, dmeasL;
1990 dmeasL = ( -1.0 ) * fabs( dmeas2[0] );
1991 er_dmeasL = er_dmeas2[0];
1995 dmeasL = ( -1.0 ) * fabs(
HitMdc.dist()[0] );
1996 er_dmeasL =
HitMdc.erdist()[0];
1999 double AL = 1 / ( ( v_H_T_ea_v_H )[0] + er_dmeasL * er_dmeasL );
2000 eaNewL.assign( ea - ea_v_H * AL * ea_v_HT );
2001 double RkL = 1 - ( v_H_T_ea_v_H )[0] * AL;
2004 std::cout <<
" ea_v_H * AL * ea_v_HT is: " << ea_v_H * AL * ea_v_HT << std::endl;
2005 std::cout <<
" v_H is: " << v_H <<
" Ea is: " << ea
2006 <<
" v_H_T_ea_v_H is: " << v_H_T_ea_v_H << std::endl;
2007 std::cout <<
" AL is: " << AL
2008 <<
" (v_H_T_ea_v_H)[0] * AL is: " << ( v_H_T_ea_v_H )[0] * AL << std::endl;
2011 if ( 0. == RkL ) RkL = 1.e-4;
2013 HepVector diffL = ea_v_H * AL * ( dmeasL - estim );
2014 aNewL = v_a + diffL;
2015 double sigL = dmeasL - ( v_HT * aNewL )[0];
2016 dtracknew = ( v_HT * aNewL )[0];
2017 dchi2L = ( sigL * sigL ) / ( RkL * er_dmeasL * er_dmeasL );
2020 { std::cout <<
" fwd_filter : in left hypothesis dchi2L is " << dchi2L << std::endl; }
2023 if ( (
LR_ == 0 && lr != -1.0 ) || (
LR_ == 1 && lr == 1.0 ) )
2025 double er_dmeasR, dmeasR;
2029 er_dmeasR = er_dmeas2[1];
2033 dmeasR = fabs(
HitMdc.dist()[1] );
2034 er_dmeasR =
HitMdc.erdist()[1];
2037 double AR = 1 / ( ( v_H_T_ea_v_H )[0] + er_dmeasR * er_dmeasR );
2038 eaNewR.assign( ea - ea_v_H * AR * ea_v_HT );
2039 double RkR = 1 - ( v_H_T_ea_v_H )[0] * AR;
2043 std::cout <<
" ea_v_H * AR * ea_v_HT is: " << ea_v_H * AR * ea_v_HT << std::endl;
2044 std::cout <<
" v_H is: " << v_H <<
" Ea is: " << ea
2045 <<
" v_H_T_ea_v_H is: " << v_H_T_ea_v_H << std::endl;
2046 std::cout <<
" AR is: " << AR
2047 <<
" (v_H_T_ea_v_H)[0] * AR is: " << ( v_H_T_ea_v_H )[0] * AR << std::endl;
2050 if ( 0. == RkR ) RkR = 1.e-4;
2051 HepVector diffR = ea_v_H * AR * ( dmeasR - estim );
2052 aNewR = v_a + diffR;
2053 double sigR = dmeasR - ( v_HT * aNewR )[0];
2054 dtracknew = ( v_HT * aNewR )[0];
2055 dchi2R = ( sigR * sigR ) / ( RkR * er_dmeasR * er_dmeasR );
2057 { std::cout <<
" fwd_filter : in right hypothesis dchi2R is " << dchi2R << std::endl; }
2060 double dchi2_loc( 0 );
2061 if ( fabs( dchi2R - dchi2L ) < 10. && inext > 0 )
2063 KalFitHitMdc& HitMdc_next = HitsMdc_[inext];
2065 double chi2_fromR(
chi2_next( H_fromR, HitMdc_next, csmflag ) );
2067 double chi2_fromL(
chi2_next( H_fromL, HitMdc_next, csmflag ) );
2069 std::cout <<
" chi2_fromL = " << chi2_fromL <<
", chi2_fromR = " << chi2_fromR
2072 if ( fabs( chi2_fromR - chi2_fromL ) < 10. )
2075 if ( inext + 1 < HitsMdc_.size() )
2076 for (
int k = inext + 1; k < HitsMdc_.size(); k++ )
2077 if ( !( HitsMdc_[k].chi2() < 0 ) )
2085 KalFitHitMdc& HitMdc_next2 = HitsMdc_[inext2];
2086 double chi2_fromR2(
chi2_next( H_fromR, HitMdc_next2, csmflag ) );
2087 double chi2_fromL2(
chi2_next( H_fromL, HitMdc_next2, csmflag ) );
2089 std::cout <<
" chi2_fromL2 = " << chi2_fromL2 <<
", chi2_fromR2 = " << chi2_fromR2
2092 if ( fabs( dchi2R + chi2_fromR + chi2_fromR2 -
2093 ( dchi2L + chi2_fromL + chi2_fromL2 ) ) < 2 )
2095 if ( chi2_fromR2 < chi2_fromL2 ) dchi2L =
DBL_MAX;
2103 if ( dchi2R + chi2_fromR < dchi2L + chi2_fromL )
2107 std::cout <<
" choose right..." << std::endl;
2114 std::cout <<
" choose left..." << std::endl;
2123 if ( ( (
LR_ == 0 && dchi2R < dchi2L && lr != -1 ) || (
LR_ == 1 && lr == 1 ) ) &&
2124 fabs( aNewR[2] -
a()[2] ) < 1000. && aNewR[2] )
2129 if ( flag_ster ) nster_++;
2134 if ( l_mass_ == lead_ ) {
HitMdc.LR( 1 ); }
2138 else if ( ( (
LR_ == 0 && dchi2L <= dchi2R && lr != 1 ) || (
LR_ == 1 && lr == -1 ) ) &&
2139 fabs( aNewL[2] -
a()[2] ) < 1000. && aNewL[2] )
2144 if ( flag_ster ) nster_++;
2149 if ( l_mass_ == lead_ ) {
HitMdc.LR( -1 ); }
2154 if ( dchi2_loc > dchi2_max_ )
2156 dchi2_max_ = dchi2_loc;
2157 r_max_ =
pivot().perp();
2159 dchi2out = dchi2_loc;
2167 Hep3Vector& meas,
int way,
double& dchi2out,
2173 double lr =
HitMdc->LR();
2174 int layerid = ( *HitMdc ).wire().layer().layerId();
2176 double entrangle =
HitMdc->rechitptr()->getEntra();
2180 std::cout <<
"in update_hits(kalFitHelixSeg,...) : the layerid =" << layerid << std::endl;
2181 std::cout <<
" update_hits: lr= " << lr << std::endl;
2184 const KalFitWire& Wire =
HitMdc->wire();
2185 int wire_ID = Wire.
geoID();
2187 if ( wire_ID < 0 || wire_ID > 6796 )
2189 std::cout <<
" KalFitTrack: wire_ID problem : " << wire_ID << std::endl;
2192 int flag_ster = Wire.
stereo();
2197 double csf0 =
cos( phi );
2198 double snf0 = ( 1. - csf0 ) * ( 1. + csf0 );
2199 snf0 = sqrt( ( snf0 > 0. ) ? snf0 : 0. );
2200 if ( phi >
M_PI ) snf0 = -snf0;
2209 Hep3Vector ip( 0, 0, 0 );
2211 phi_ip = work.
phi0();
2212 if ( fabs( phi - phi_ip ) >
M_PI )
2214 if ( phi > phi_ip ) phi -= 2 *
M_PI;
2215 else phi_ip -= 2 *
M_PI;
2217 dphi = phi - phi_ip;
2219 double l = fabs(
radius() * dphi * sqrt( 1 +
t *
t ) );
2220 double pmag( sqrt( 1.0 +
t *
t ) /
kappa() );
2221 double mass_over_p( mass_ / pmag );
2222 double beta( 1.0 / sqrt( 1.0 + mass_over_p * mass_over_p ) );
2223 tofest = l / ( 29.9792458 * beta );
2224 if ( csmflag == 1 && ( *HitMdc ).wire().y() > 0. ) tofest = -1. * tofest;
2227 const HepSymMatrix& ea =
Ea();
2231 const HepVector& v_a =
a();
2255 double dchi2R( 99999999 ), dchi2L( 99999999 );
2257 HepVector v_H( 5, 0 );
2258 v_H[0] = -csf0 * meas.x() - snf0 * meas.y();
2260 HepMatrix v_HT = v_H.T();
2262 double estim = ( v_HT * v_a )[0];
2263 HepVector ea_v_H = ea * v_H;
2264 HepMatrix ea_v_HT = ( ea_v_H ).T();
2265 HepVector v_H_T_ea_v_H = v_HT * ea_v_H;
2267 HepSymMatrix eaNewL( 5 ), eaNewR( 5 );
2268 HepVector aNewL( 5 ), aNewR( 5 );
2270 cout <<
"phi " << phi <<
" snf0 " << snf0 <<
" csf0 " << csf0 << endl
2271 <<
" meas: " << meas << endl;
2272 cout <<
"the related matrix:" << endl;
2273 cout <<
"v_H " << v_H << endl;
2274 cout <<
"v_a " << v_a << endl;
2275 cout <<
"ea " << ea << endl;
2276 cout <<
"v_H_T_ea_v_H " << v_H_T_ea_v_H << endl;
2277 cout <<
"LR_= " <<
LR_ <<
"lr= " << lr << endl;
2280 double time = ( *HitMdc ).tdc();
2295 std::cout <<
"the pure drift time is " << drifttime << std::endl;
2296 std::cout <<
"the drift dist left hypothesis is " << ddl << std::endl;
2297 std::cout <<
"the drift dist right hypothesis is " << ddr << std::endl;
2298 std::cout <<
"the error sigma left hypothesis is " << erddl << std::endl;
2299 std::cout <<
"the error sigma right hypothesis is " << erddr << std::endl;
2301 double dmeas2[2] = { 0.1 * ddl, 0.1 * ddr };
2302 double er_dmeas2[2] = { 0., 0. };
2306 er_dmeas2[0] = 0.1 * erddl;
2307 er_dmeas2[1] = 0.1 * erddr;
2317 if ( (
LR_ == 0 && lr != 1.0 ) || (
LR_ == 1 && lr == -1.0 ) )
2320 double er_dmeasL, dmeasL;
2323 dmeasL = ( -1.0 ) * fabs( dmeas2[0] );
2324 er_dmeasL = er_dmeas2[0];
2328 dmeasL = ( -1.0 ) * fabs( ( *HitMdc ).dist()[0] );
2329 er_dmeasL = ( *HitMdc ).erdist()[0];
2332 double AL = 1 / ( ( v_H_T_ea_v_H )[0] + er_dmeasL * er_dmeasL );
2333 eaNewL.assign( ea - ea_v_H * AL * ea_v_HT );
2334 double RkL = 1 - ( v_H_T_ea_v_H )[0] * AL;
2335 if ( 0. == RkL ) RkL = 1.e-4;
2337 HepVector diffL = ea_v_H * AL * ( dmeasL - estim );
2339 aNewL = v_a + diffL;
2340 double sigL = dmeasL - ( v_HT * aNewL )[0];
2341 dchi2L = ( sigL * sigL ) / ( RkL * er_dmeasL * er_dmeasL );
2344 if ( (
LR_ == 0 && lr != -1.0 ) || (
LR_ == 1 && lr == 1.0 ) )
2347 double er_dmeasR, dmeasR;
2351 er_dmeasR = er_dmeas2[1];
2355 dmeasR = fabs( ( *HitMdc ).dist()[1] );
2356 er_dmeasR = ( *HitMdc ).erdist()[1];
2359 double AR = 1 / ( ( v_H_T_ea_v_H )[0] + er_dmeasR * er_dmeasR );
2360 eaNewR.assign( ea - ea_v_H * AR * ea_v_HT );
2361 double RkR = 1 - ( v_H_T_ea_v_H )[0] * AR;
2362 if ( 0. == RkR ) RkR = 1.e-4;
2364 HepVector diffR = ea_v_H * AR * ( dmeasR - estim );
2366 aNewR = v_a + diffR;
2367 double sigR = dmeasR - ( v_HT * aNewR )[0];
2368 dchi2R = ( sigR * sigR ) / ( RkR * er_dmeasR * er_dmeasR );
2372 double dchi2_loc( 0 );
2375 cout <<
" track::update_hits......" << endl;
2376 std::cout <<
" dchi2R = " << dchi2R <<
", dchi2L = " << dchi2L
2377 <<
" estimate = " << estim << std::endl;
2378 std::cout <<
" dmeasR = " << dmeas2[1] <<
", dmeasL = " << ( -1.0 ) * fabs( dmeas2[0] )
2379 <<
", check HitMdc.ddl = " << ( *HitMdc ).dist()[0] << std::endl;
2380 std::cout <<
"dchi2L : " << dchi2L <<
" ,dchi2R: " << dchi2R << std::endl;
2383 if ( fabs( dchi2R - dchi2L ) < 10. && inext > 0 )
2386 KalFitHitMdc& HitMdc_next = HitsMdc_[inext];
2389 double chi2_fromR(
chi2_next( H_fromR, HitMdc_next, csmflag ) );
2393 double chi2_fromL(
chi2_next( H_fromL, HitMdc_next, csmflag ) );
2396 std::cout <<
" chi2_fromL = " << chi2_fromL <<
", chi2_fromR = " << chi2_fromR
2399 if ( fabs( chi2_fromR - chi2_fromL ) < 10. )
2402 if ( inext + 1 < HitsMdc_.size() )
2403 for (
int k = inext + 1; k < HitsMdc_.size(); k++ )
2404 if ( !( HitsMdc_[k].chi2() < 0 ) )
2412 KalFitHitMdc& HitMdc_next2 = HitsMdc_[inext2];
2415 double chi2_fromR2(
chi2_next( H_fromR, HitMdc_next2, csmflag ) );
2416 double chi2_fromL2(
chi2_next( H_fromL, HitMdc_next2, csmflag ) );
2418 std::cout <<
" chi2_fromL2 = " << chi2_fromL2 <<
", chi2_fromR2 = " << chi2_fromR2
2421 if ( fabs( dchi2R + chi2_fromR + chi2_fromR2 -
2422 ( dchi2L + chi2_fromL + chi2_fromL2 ) ) < 2 )
2424 if ( chi2_fromR2 < chi2_fromL2 ) dchi2L =
DBL_MAX;
2432 if ( dchi2R + chi2_fromR < dchi2L + chi2_fromL )
2436 std::cout <<
" choose right..." << std::endl;
2443 std::cout <<
" choose left..." << std::endl;
2453 if ( ( (
LR_ == 0 && dchi2R < dchi2L && lr != -1 ) || (
LR_ == 1 && lr == 1 ) ) &&
2454 fabs( aNewR[2] -
a()[2] ) < 1000. && aNewR[2] )
2459 if ( flag_ster ) nster_++;
2485 if ( l_mass_ == lead_ )
2487 ( *HitMdc ).LR( 1 );
2490 update_bit( ( *HitMdc ).wire().layer().layerId() );
2493 else if ( ( (
LR_ == 0 && dchi2L <= dchi2R && lr != 1 ) || (
LR_ == 1 && lr == -1 ) ) &&
2494 fabs( aNewL[2] -
a()[2] ) < 1000. && aNewL[2] )
2499 if ( flag_ster ) nster_++;
2524 if ( l_mass_ == lead_ )
2526 ( *HitMdc ).LR( -1 );
2529 update_bit( ( *HitMdc ).wire().layer().layerId() );
2534 if ( dchi2_loc > dchi2_max_ )
2536 dchi2_max_ = dchi2_loc;
2537 r_max_ =
pivot().perp();
2539 dchi2out = dchi2_loc;
2547 int way,
double& dchi2out,
int csmflag ) {
2552 double lr =
HitMdc->LR();
2553 int layerid = ( *HitMdc ).wire().layer().layerId();
2554 double entrangle =
HitMdc->rechitptr()->getEntra();
2558 std::cout <<
"in update_hits(kalFitHelixSeg,...) : the layerid =" << layerid << std::endl;
2559 std::cout <<
" update_hits: lr= " << lr << std::endl;
2562 const KalFitWire& Wire =
HitMdc->wire();
2563 int wire_ID = Wire.
geoID();
2565 if ( wire_ID < 0 || wire_ID > 6796 )
2567 std::cout <<
" KalFitTrack: wire_ID problem : " << wire_ID << std::endl;
2570 int flag_ster = Wire.
stereo();
2575 double csf0 =
cos( phi );
2576 double snf0 = ( 1. - csf0 ) * ( 1. + csf0 );
2577 snf0 = sqrt( ( snf0 > 0. ) ? snf0 : 0. );
2578 if ( phi >
M_PI ) snf0 = -snf0;
2587 Hep3Vector ip( 0, 0, 0 );
2589 phi_ip = work.
phi0();
2590 if ( fabs( phi - phi_ip ) >
M_PI )
2592 if ( phi > phi_ip ) phi -= 2 *
M_PI;
2593 else phi_ip -= 2 *
M_PI;
2595 dphi = phi - phi_ip;
2597 double l = fabs(
radius() * dphi * sqrt( 1 +
t *
t ) );
2598 double pmag( sqrt( 1.0 +
t *
t ) /
kappa() );
2599 double mass_over_p( mass_ / pmag );
2600 double beta( 1.0 / sqrt( 1.0 + mass_over_p * mass_over_p ) );
2601 tofest = l / ( 29.9792458 * beta );
2602 if ( csmflag == 1 && ( *HitMdc ).wire().y() > 0. ) tofest = -1. * tofest;
2605 const HepSymMatrix& ea =
Ea();
2609 const HepVector& v_a =
a();
2633 double dchi2R( 99999999 ), dchi2L( 99999999 );
2635 HepVector v_H( 5, 0 );
2636 v_H[0] = -csf0 * meas.x() - snf0 * meas.y();
2638 HepMatrix v_HT = v_H.T();
2640 double estim = ( v_HT * v_a )[0];
2641 HepVector ea_v_H = ea * v_H;
2642 HepMatrix ea_v_HT = ( ea_v_H ).T();
2643 HepVector v_H_T_ea_v_H = v_HT * ea_v_H;
2645 HepSymMatrix eaNewL( 5 ), eaNewR( 5 );
2646 HepVector aNewL( 5 ), aNewR( 5 );
2648 cout <<
"phi " << phi <<
" snf0 " << snf0 <<
" csf0 " << csf0 << endl
2649 <<
" meas: " << meas << endl;
2650 cout <<
"the related matrix:" << endl;
2651 cout <<
"v_H " << v_H << endl;
2652 cout <<
"v_a " << v_a << endl;
2653 cout <<
"ea " << ea << endl;
2654 cout <<
"v_H_T_ea_v_H " << v_H_T_ea_v_H << endl;
2655 cout <<
"LR_= " <<
LR_ <<
"lr= " << lr << endl;
2658 double time = ( *HitMdc ).tdc();
2673 std::cout <<
"the pure drift time is " << drifttime << std::endl;
2674 std::cout <<
"the drift dist left hypothesis is " << ddl << std::endl;
2675 std::cout <<
"the drift dist right hypothesis is " << ddr << std::endl;
2676 std::cout <<
"the error sigma left hypothesis is " << erddl << std::endl;
2677 std::cout <<
"the error sigma right hypothesis is " << erddr << std::endl;
2679 double dmeas2[2] = { 0.1 * ddl, 0.1 * ddr };
2680 double er_dmeas2[2] = { 0., 0. };
2684 er_dmeas2[0] = 0.1 * erddl;
2685 er_dmeas2[1] = 0.1 * erddr;
2695 if ( (
LR_ == 0 && lr != 1.0 ) || (
LR_ == 1 && lr == -1.0 ) )
2698 double er_dmeasL, dmeasL;
2701 dmeasL = ( -1.0 ) * fabs( dmeas2[0] );
2702 er_dmeasL = er_dmeas2[0];
2706 dmeasL = ( -1.0 ) * fabs( ( *HitMdc ).dist()[0] );
2707 er_dmeasL = ( *HitMdc ).erdist()[0];
2710 double AL = 1 / ( ( v_H_T_ea_v_H )[0] + er_dmeasL * er_dmeasL );
2711 eaNewL.assign( ea - ea_v_H * AL * ea_v_HT );
2712 double RkL = 1 - ( v_H_T_ea_v_H )[0] * AL;
2713 if ( 0. == RkL ) RkL = 1.e-4;
2715 HepVector diffL = ea_v_H * AL * ( dmeasL - estim );
2717 aNewL = v_a + diffL;
2718 double sigL = dmeasL - ( v_HT * aNewL )[0];
2719 dchi2L = ( sigL * sigL ) / ( RkL * er_dmeasL * er_dmeasL );
2722 if ( (
LR_ == 0 && lr != -1.0 ) || (
LR_ == 1 && lr == 1.0 ) )
2725 double er_dmeasR, dmeasR;
2729 er_dmeasR = er_dmeas2[1];
2733 dmeasR = fabs( ( *HitMdc ).dist()[1] );
2734 er_dmeasR = ( *HitMdc ).erdist()[1];
2737 double AR = 1 / ( ( v_H_T_ea_v_H )[0] + er_dmeasR * er_dmeasR );
2738 eaNewR.assign( ea - ea_v_H * AR * ea_v_HT );
2739 double RkR = 1 - ( v_H_T_ea_v_H )[0] * AR;
2740 if ( 0. == RkR ) RkR = 1.e-4;
2742 HepVector diffR = ea_v_H * AR * ( dmeasR - estim );
2744 aNewR = v_a + diffR;
2745 double sigR = dmeasR - ( v_HT * aNewR )[0];
2746 dchi2R = ( sigR * sigR ) / ( RkR * er_dmeasR * er_dmeasR );
2750 double dchi2_loc( 0 );
2753 cout <<
" track::update_hits......" << endl;
2754 std::cout <<
" dchi2R = " << dchi2R <<
", dchi2L = " << dchi2L
2755 <<
" estimate = " << estim << std::endl;
2756 std::cout <<
" dmeasR = " << dmeas2[1] <<
", dmeasL = " << ( -1.0 ) * fabs( dmeas2[0] )
2757 <<
", check HitMdc.ddl = " << ( *HitMdc ).dist()[0] << std::endl;
2760 if ( fabs( dchi2R - dchi2L ) < 10. && inext > 0 )
2763 KalFitHitMdc& HitMdc_next = HitsMdc_[inext];
2766 double chi2_fromR(
chi2_next( H_fromR, HitMdc_next, csmflag ) );
2769 double chi2_fromL(
chi2_next( H_fromL, HitMdc_next, csmflag ) );
2771 std::cout <<
" chi2_fromL = " << chi2_fromL <<
", chi2_fromR = " << chi2_fromR
2774 if ( fabs( chi2_fromR - chi2_fromL ) < 10. )
2777 if ( inext + 1 < HitsMdc_.size() )
2778 for (
int k = inext + 1; k < HitsMdc_.size(); k++ )
2779 if ( !( HitsMdc_[k].chi2() < 0 ) )
2787 KalFitHitMdc& HitMdc_next2 = HitsMdc_[inext2];
2788 double chi2_fromR2(
chi2_next( H_fromR, HitMdc_next2, csmflag ) );
2789 double chi2_fromL2(
chi2_next( H_fromL, HitMdc_next2, csmflag ) );
2791 std::cout <<
" chi2_fromL2 = " << chi2_fromL2 <<
", chi2_fromR2 = " << chi2_fromR2
2794 if ( fabs( dchi2R + chi2_fromR + chi2_fromR2 -
2795 ( dchi2L + chi2_fromL + chi2_fromL2 ) ) < 2 )
2797 if ( chi2_fromR2 < chi2_fromL2 ) dchi2L =
DBL_MAX;
2805 if ( dchi2R + chi2_fromR < dchi2L + chi2_fromL )
2809 std::cout <<
" choose right..." << std::endl;
2816 std::cout <<
" choose left..." << std::endl;
2826 if ( ( (
LR_ == 0 && dchi2R < dchi2L && lr != -1 ) || (
LR_ == 1 && lr == 1 ) ) &&
2827 fabs( aNewR[2] -
a()[2] ) < 1000. && aNewR[2] )
2832 if ( flag_ster ) nster_++;
2857 if ( l_mass_ == lead_ )
2859 ( *HitMdc ).LR( 1 );
2862 update_bit( ( *HitMdc ).wire().layer().layerId() );
2865 else if ( ( (
LR_ == 0 && dchi2L <= dchi2R && lr != 1 ) || (
LR_ == 1 && lr == -1 ) ) &&
2866 fabs( aNewL[2] -
a()[2] ) < 1000. && aNewL[2] )
2871 if ( flag_ster ) nster_++;
2893 if ( l_mass_ == lead_ )
2895 ( *HitMdc ).LR( -1 );
2898 update_bit( ( *HitMdc ).wire().layer().layerId() );
2903 if ( dchi2_loc > dchi2_max_ )
2905 dchi2_max_ = dchi2_loc;
2906 r_max_ =
pivot().perp();
2908 dchi2out = dchi2_loc;
2919 int wire_ID = Wire.
geoID();
2920 int layerid =
HitMdc.wire().layer().layerId();
2921 double entrangle =
HitMdc.rechitptr()->getEntra();
2923 HepPoint3D fwd( Wire.
fwd() );
2924 HepPoint3D bck( Wire.
bck() );
2925 Hep3Vector wire = (Hep3Vector)fwd - (Hep3Vector)bck;
2928 work.
pivot( ( fwd + bck ) * .5 );
2929 HepPoint3D x0kal = ( work.
x( 0 ).z() - bck.z() ) / wire.z() * wire + bck;
2932 Hep3Vector meas =
H.momentum( 0 ).cross( wire ).unit();
2934 if ( wire_ID < 0 || wire_ID > 6796 )
2936 std::cout <<
"KalFitTrack : wire_ID problem : " << wire_ID << std::endl;
2944 double csf0 =
cos( phi );
2945 double snf0 = ( 1. - csf0 ) * ( 1. + csf0 );
2946 snf0 = sqrt( ( snf0 > 0. ) ? snf0 : 0. );
2947 if ( phi >
M_PI ) snf0 = -snf0;
2951 Hep3Vector ip( 0, 0, 0 );
2955 double phi_ip = work.
phi0();
2956 if ( fabs( phi - phi_ip ) >
M_PI )
2958 if ( phi > phi_ip ) phi -= 2 *
M_PI;
2959 else phi_ip -= 2 *
M_PI;
2962 double l = fabs(
radius() * ( phi - phi_ip ) * sqrt( 1 +
t *
t ) );
2963 double pmag( sqrt( 1.0 +
t *
t ) /
kappa() );
2964 double mass_over_p( mass_ / pmag );
2965 double beta( 1.0 / sqrt( 1.0 + mass_over_p * mass_over_p ) );
2966 tofest = l / ( 29.9792458 * beta );
2970 const HepSymMatrix& ea =
H.Ea();
2971 const HepVector& v_a =
H.a();
2974 HepVector v_H( 5, 0 );
2975 v_H[0] = -csf0 * meas.x() - snf0 * meas.y();
2977 HepMatrix v_HT = v_H.T();
2979 double estim = ( v_HT * v_a )[0];
2980 HepVector ea_v_H = ea * v_H;
2981 HepMatrix ea_v_HT = ( ea_v_H ).T();
2982 HepVector v_H_T_ea_v_H = v_HT * ea_v_H;
2984 HepSymMatrix eaNewL( 5 ), eaNewR( 5 );
2985 HepVector aNewL( 5 ), aNewR( 5 );
2996 double dmeas2[2] = { 0.1 * ddl, 0.1 * ddr };
2997 double er_dmeas2[2] = { 0., 0. };
3000 er_dmeas2[0] = 0.1 * erddl;
3001 er_dmeas2[1] = 0.1 * erddr;
3010 if ( (
LR_ == 0 && lr != 1.0 ) || (
LR_ == 1 && lr == -1.0 ) )
3013 double er_dmeasL, dmeasL;
3016 dmeasL = ( -1.0 ) * fabs( dmeas2[0] );
3017 er_dmeasL = er_dmeas2[0];
3021 dmeasL = ( -1.0 ) * fabs(
HitMdc.dist()[0] );
3022 er_dmeasL =
HitMdc.erdist()[0];
3025 double AL = 1 / ( ( v_H_T_ea_v_H )[0] + er_dmeasL * er_dmeasL );
3026 eaNewL.assign( ea - ea_v_H * AL * ea_v_HT );
3027 double RkL = 1 - ( v_H_T_ea_v_H )[0] * AL;
3028 if ( 0. == RkL ) RkL = 1.e-4;
3030 HepVector diffL = ea_v_H * AL * ( dmeasL - estim );
3031 aNewL = v_a + diffL;
3032 double sigL = dmeasL - ( v_HT * aNewL )[0];
3033 dchi2L = ( sigL * sigL ) / ( RkL * er_dmeasL * er_dmeasL );
3036 if ( (
LR_ == 0 && lr != -1.0 ) || (
LR_ == 1 && lr == 1.0 ) )
3039 double er_dmeasR, dmeasR;
3043 er_dmeasR = er_dmeas2[1];
3047 dmeasR = fabs(
HitMdc.dist()[1] );
3048 er_dmeasR =
HitMdc.erdist()[1];
3051 double AR = 1 / ( ( v_H_T_ea_v_H )[0] + er_dmeasR * er_dmeasR );
3052 eaNewR.assign( ea - ea_v_H * AR * ea_v_HT );
3053 double RkR = 1 - ( v_H_T_ea_v_H )[0] * AR;
3054 if ( 0. == RkR ) RkR = 1.e-4;
3056 HepVector diffR = ea_v_H * AR * ( dmeasR - estim );
3057 aNewR = v_a + diffR;
3058 double sigR = dmeasR - ( v_HT * aNewR )[0];
3059 dchi2R = ( sigR * sigR ) / ( RkR * er_dmeasR * er_dmeasR );
3062 if ( dchi2R < dchi2L )
3072 return ( ( dchi2R < dchi2L ) ? dchi2R : dchi2L );
3079 int wire_ID = Wire.
geoID();
3080 int layerid =
HitMdc.wire().layer().layerId();
3081 double entrangle =
HitMdc.rechitptr()->getEntra();
3083 HepPoint3D fwd( Wire.
fwd() );
3084 HepPoint3D bck( Wire.
bck() );
3085 Hep3Vector wire = (Hep3Vector)fwd - (Hep3Vector)bck;
3088 work.
pivot( ( fwd + bck ) * .5 );
3089 HepPoint3D x0kal = ( work.
x( 0 ).z() - bck.z() ) / wire.z() * wire + bck;
3092 Hep3Vector meas =
H.momentum( 0 ).cross( wire ).unit();
3094 if ( wire_ID < 0 || wire_ID > 6796 )
3096 std::cout <<
"KalFitTrack : wire_ID problem : " << wire_ID << std::endl;
3104 double csf0 =
cos( phi );
3105 double snf0 = ( 1. - csf0 ) * ( 1. + csf0 );
3106 snf0 = sqrt( ( snf0 > 0. ) ? snf0 : 0. );
3107 if ( phi >
M_PI ) snf0 = -snf0;
3111 Hep3Vector ip( 0, 0, 0 );
3115 double phi_ip = work.
phi0();
3116 if ( fabs( phi - phi_ip ) >
M_PI )
3118 if ( phi > phi_ip ) phi -= 2 *
M_PI;
3119 else phi_ip -= 2 *
M_PI;
3122 double l = fabs(
radius() * ( phi - phi_ip ) * sqrt( 1 +
t *
t ) );
3123 double pmag( sqrt( 1.0 +
t *
t ) /
kappa() );
3124 double mass_over_p( mass_ / pmag );
3125 double beta( 1.0 / sqrt( 1.0 + mass_over_p * mass_over_p ) );
3126 tofest = l / ( 29.9792458 * beta );
3127 if ( csmflag == 1 &&
HitMdc.wire().y() > 0. ) tofest = -1. * tofest;
3130 const HepSymMatrix& ea =
H.Ea();
3131 const HepVector& v_a =
H.a();
3134 HepVector v_H( 5, 0 );
3135 v_H[0] = -csf0 * meas.x() - snf0 * meas.y();
3137 HepMatrix v_HT = v_H.T();
3139 double estim = ( v_HT * v_a )[0];
3140 HepVector ea_v_H = ea * v_H;
3141 HepMatrix ea_v_HT = ( ea_v_H ).T();
3142 HepVector v_H_T_ea_v_H = v_HT * ea_v_H;
3144 HepSymMatrix eaNewL( 5 ), eaNewR( 5 );
3145 HepVector aNewL( 5 ), aNewR( 5 );
3156 double dmeas2[2] = { 0.1 * ddl, 0.1 * ddr };
3157 double er_dmeas2[2] = { 0., 0. };
3160 er_dmeas2[0] = 0.1 * erddl;
3161 er_dmeas2[1] = 0.1 * erddr;
3170 if ( (
LR_ == 0 && lr != 1.0 ) || (
LR_ == 1 && lr == -1.0 ) )
3173 double er_dmeasL, dmeasL;
3176 dmeasL = ( -1.0 ) * fabs( dmeas2[0] );
3177 er_dmeasL = er_dmeas2[0];
3181 dmeasL = ( -1.0 ) * fabs(
HitMdc.dist()[0] );
3182 er_dmeasL =
HitMdc.erdist()[0];
3185 double AL = 1 / ( ( v_H_T_ea_v_H )[0] + er_dmeasL * er_dmeasL );
3186 eaNewL.assign( ea - ea_v_H * AL * ea_v_HT );
3187 double RkL = 1 - ( v_H_T_ea_v_H )[0] * AL;
3188 if ( 0. == RkL ) RkL = 1.e-4;
3190 HepVector diffL = ea_v_H * AL * ( dmeasL - estim );
3191 aNewL = v_a + diffL;
3192 double sigL = dmeasL - ( v_HT * aNewL )[0];
3193 dchi2L = ( sigL * sigL ) / ( RkL * er_dmeasL * er_dmeasL );
3196 if ( (
LR_ == 0 && lr != -1.0 ) || (
LR_ == 1 && lr == 1.0 ) )
3199 double er_dmeasR, dmeasR;
3203 er_dmeasR = er_dmeas2[1];
3207 dmeasR = fabs(
HitMdc.dist()[1] );
3208 er_dmeasR =
HitMdc.erdist()[1];
3211 double AR = 1 / ( ( v_H_T_ea_v_H )[0] + er_dmeasR * er_dmeasR );
3212 eaNewR.assign( ea - ea_v_H * AR * ea_v_HT );
3213 double RkR = 1 - ( v_H_T_ea_v_H )[0] * AR;
3214 if ( 0. == RkR ) RkR = 1.e-4;
3216 HepVector diffR = ea_v_H * AR * ( dmeasR - estim );
3217 aNewR = v_a + diffR;
3218 double sigR = dmeasR - ( v_HT * aNewR )[0];
3219 dchi2R = ( sigR * sigR ) / ( RkR * er_dmeasR * er_dmeasR );
3222 if ( dchi2R < dchi2L )
3232 return ( ( dchi2R < dchi2L ) ? dchi2R : dchi2L );
3236 double sigma1, sigma2,
f;
3240 if ( driftDist < 0.5 )
3246 else if ( driftDist < 1. )
3252 else if ( driftDist < 1.5 )
3258 else if ( driftDist < 2. )
3264 else if ( driftDist < 2.5 )
3270 else if ( driftDist < 3. )
3276 else if ( driftDist < 3.5 )
3282 else if ( driftDist < 4. )
3288 else if ( driftDist < 4.5 )
3294 else if ( driftDist < 5. )
3300 else if ( driftDist < 5.5 )
3315 if ( driftDist < 0.5 )
3321 else if ( driftDist < 1. )
3327 else if ( driftDist < 1.5 )
3333 else if ( driftDist < 2. )
3339 else if ( driftDist < 2.5 )
3345 else if ( driftDist < 3. )
3351 else if ( driftDist < 3.5 )
3357 else if ( driftDist < 4. )
3363 else if ( driftDist < 4.5 )
3369 else if ( driftDist < 5. )
3375 else if ( driftDist < 5.5 )
3381 else if ( driftDist < 6. )
3387 else if ( driftDist < 6.5 )
3393 else if ( driftDist < 7. )
3399 else if ( driftDist < 7.5 )
3412 double sigmax = sqrt(
f * sigma1 * sigma1 + ( 1 -
f ) * sigma2 * sigma2 ) * 0.1;
HepGeom::Vector3D< double > HepVector3D
**********INTEGER nmxhep !maximum number of particles DOUBLE PRECISION vhep INTEGER jdahep COMMON hepevt $ !serial number $ !number of particles $ !status code $ !particle ident KF $ !parent particles $ !childreen particles $ !four momentum
HepGeom::Point3D< double > HepPoint3D
TFile f("ana_bhabha660a_dqa_mcPat_zy_old.root")
HepGeom::Transform3D HepTransform3D
double cos(const BesAngle a)
********INTEGER modcns REAL m_C
CLHEP::HepVector a_pre_fwd(void)
CLHEP::HepSymMatrix Ea_filt_fwd(void)
CLHEP::HepVector a_filt_bwd(void)
CLHEP::HepVector a_include(void)
CLHEP::HepSymMatrix Ea_pre_bwd(void)
double doca_include(void)
CLHEP::HepVector a_filt_fwd(void)
double doca_exclude(void)
CLHEP::HepVector a_pre_bwd(void)
CLHEP::HepSymMatrix & Ea_pre_fwd(void)
CLHEP::HepVector a_exclude(void)
CLHEP::HepSymMatrix Ea_filt_bwd(void)
double residual_exclude(void)
CLHEP::HepSymMatrix Ea_include(void)
CLHEP::HepSymMatrix Ea_exclude(void)
KalFitHitMdc * HitMdc(void)
double residual_include(void)
Description of a Hit in Mdc.
RecMdcHit * rechitptr(void)
const KalFitWire & wire(void) const
const int layerId(void) const
returns layer ID
double X0(void) const
Extractor.
double del_E(double mass, double path, double p) const
Calculate the straggling of energy loss.
double mcs_angle(double mass, double path, double p) const
Calculate Multiple Scattering angle.
double dE(double mass, double path, double p) const
Calculate energy loss.
~KalFitTrack(void)
destructor
double chi2_next(Helix &H, KalFitHitMdc &HitMdc, int csmflag)
static int lead(void)
Magnetic field map.
double getDriftTime(KalFitHitMdc &hitmdc, double toftime) const
static double chi2_hitf_
Cut chi2 for each hit.
KalFitTrack(const HepPoint3D &pivot, const CLHEP::HepVector &a, const CLHEP::HepSymMatrix &Ea, unsigned int m, double chiSq, unsigned int nhits)
constructor
static double dchi2cuts_anal[43]
static double dchi2cuts_calib[43]
static int debug_
for debug
double filter(double v_m, const CLHEP::HepVector &m_H, double v_d, double m_V)
void order_wirhit(int index)
static int nmdc_hit2_
Cut chi2 for each hit.
double getSigma(int layerId, double driftDist) const
KalFitHelixSeg & HelixSeg(int i)
void addTofSM(double time)
static int resolflag_
wire resoltion flag
static double factor_strag_
factor of energy loss straggling for electron
const HepPoint3D & pivot_numf(const HepPoint3D &newPivot)
Sets pivot position in a given mag field.
void ms(double path, const KalFitMaterial &m, int index)
static int Tof_correc_
Flag for TOF correction.
double intersect_cylinder(double r) const
Intersection with different geometry.
vector< KalFitHitMdc > & HitsMdc(void)
static int numf_
Flag for treatment of non-uniform mag field.
void path_add(double path)
Update the path length estimation.
double update_hits_csmalign(KalFitHelixSeg &HelixSeg, int inext, CLHEP::Hep3Vector &meas, int way, double &dchi2, int csmflag)
static int drifttime_choice_
the drifttime choice
double smoother_Mdc(KalFitHelixSeg &seg, CLHEP::Hep3Vector &meas, int &flg, int csmflag)
Kalman smoother for Mdc.
void msgasmdc(double path, int index)
Calculate multiple scattering angle.
void appendHitsMdc(KalFitHitMdc h)
Functions for Mdc hits list.
void addPathSM(double path)
static double mdcGasRadlen_
static double dchi2cutf_calib[43]
void eloss(double path, const KalFitMaterial &m, int index)
Calculate total energy lost in material.
void update_last(void)
Record the current parameters as ..._last information :
double getDriftDist(KalFitHitMdc &hitmdc, double drifttime, int lr) const
double intersect_yz_plane(const HepTransform3D &plane, double x) const
double intersect_zx_plane(const HepTransform3D &plane, double y) const
static int numfcor_
NUMF treatment improved.
double intersect_xy_plane(double z) const
double radius_numf(void) const
Estimation of the radius in a given mag field.
double smoother_Mdc_csmalign(KalFitHelixSeg &seg, CLHEP::Hep3Vector &meas, int &flg, int csmflag)
double update_hits(KalFitHitMdc &HitMdc, int inext, CLHEP::Hep3Vector &meas, int way, double &dchi2, double &dtrack, double &dtracknew, double &dtdc, int csmflag)
Include the Mdc wire hits.
static double dchi2cutf_anal[43]
static int LR_
Use L/R decision from MdcRecHit information :
KalFitHitMdc & HitMdc(int i)
static int strag_
Flag to take account of energy loss straggling :
Description of a Wire class.
unsigned int geoID(void) const
HepPoint3D bck(void) const
HepPoint3D fwd(void) const
Geometry :
const KalFitLayer_Mdc & layer(void) const
unsigned int stereo(void) const
HepMatrix delApDelA(const HepVector &ap) const
const HepPoint3D & center(void) const
returns position of helix center(z = 0.);
void ignoreErrorMatrix(void)
const HepSymMatrix & Ea(void) const
returns error matrix.
HepPoint3D x(double dPhi=0.) const
returns position after rotating angle dPhi in phi direction.
HepMatrix delXDelA(double phi) const
double radius(void) const
returns radious of helix.
double dr(void) const
returns an element of parameters.
const HepVector & a(void) const
returns helix parameters.
Helix(const HepPoint3D &pivot, const HepVector &a, const HepSymMatrix &Ea)
Constructor with pivot, helix parameter a, and its error matrix.
const HepPoint3D & pivot(void) const
returns pivot position.
const double getEntra(void) const