9#include "MdcGeomSvc/MdcGeomSvc.h"
10#include "GaudiKernel/Bootstrap.h"
11#include "CLHEP/Matrix/Vector.h"
12#include "CLHEP/Matrix/Matrix.h"
13#include "CLHEP/Matrix/SymMatrix.h"
14#include "CLHEP/Vector/ThreeVector.h"
15#include "CLHEP/Units/PhysicalConstants.h"
16#include "Math/Point3Dfwd.h"
17#include "Math/Point3D.h"
18#include "Math/Vector3D.h"
23using namespace ROOT::Math;
46int KalFitTrack::lead_ = 2;
47int KalFitTrack::back_ = 1;
67const double KalFitTrack::MASS[NMASS] = { 0.000510999,
86 const HepSymMatrix& Ea,
87 unsigned int m,
double chisq,
unsigned int nhits)
89 nchits_(0), nster_(0), ncath_(0),
90 ndf_back_(0), chiSq_back_(0), pathip_(0),
91 path_rd_(0), path_ab_(0), tof_(0), dchi2_max_(0), r_max_(0),
92 tof_kaon_(0), tof_proton_(0), pat1_(0), pat2_(0), layer_prec_(0),
93 trasan_id_(0), nhit_r_(0), nhit_z_(0),pathSM_(0),tof2_(0)
95 memset(PathL_, 0,
sizeof(PathL_));
97 if (m < NMASS) mass_ = MASS[m];
116 pivot_last_ =
pivot();
123 pivot_forMdc_ =
pivot();
131 double l =
center().perp();
133 double cosPhi = (m_rad * m_rad + l * l - r * r) / (2 * m_rad * l);
135 if(cosPhi < -1 || cosPhi > 1)
return 0;
149 double d = r * r - (y - xc.y()) * (y - xc.y());
153 if(xx > 0) xx -= sqrt(d);
156 double l = (plane.inverse() *
167 double d = r * r - (
x - xc.x()) * (
x - xc.x());
171 if(yy > 0) yy -= sqrt(d);
174 double l = (plane.inverse() *
190 HepSymMatrix ea =
Ea();
199 double pmag = 1 / fabs(k) * sqrt(pt2);
200 double dth = material.
mcs_angle(mass_, path, pmag);
201 double dth2 = dth * dth;
202 double pt2dth2 = pt2 * dth2;
205 ea[2][2] += k2 * t2 * dth2;
206 ea[2][4] += k *
t * pt2dth2;
207 ea[4][4] += pt2 * pt2dth2;
209 ea[3][3] += dth2 * path * path /3 / (1 + t2);
210 ea[3][4] += dth2 * path/2 * sqrt(1 + t2);
211 ea[3][2] += dth2 *
t / sqrt(1 + t2) * k * path/2;
212 ea[0][0] += dth2 * path * path/3;
213 ea[0][1] += dth2 * sqrt(1 + t2) * path/2;
219 double x0 = material.
X0();
220 if (x0) path_rd_ += path/x0;
231 double pmag = ( 1 / fabs(k) ) * sqrt(1 + t2);
232 double psq = pmag*pmag;
242 double dth = 0.0136* sqrt(pathx * (mass_*mass_ + psq))/psq
243 *(1 + 0.038 * log(pathx));;
244 HepSymMatrix ea =
Ea();
246 cout<<
"msgasmdc():path "<<path<<
" pathx "<<pathx<<endl;
247 cout<<
"msgasmdc():dth "<<dth<<endl;
248 cout<<
"msgasmdc():ea before: "<<ea<<endl;
250 double dth2 = dth * dth;
252 ea[1][1] += (1 + t2) * dth2;
253 ea[2][2] += k2 * t2 * dth2;
254 ea[2][4] += k *
t * (1 + t2) * dth2;
255 ea[4][4] += (1 + t2) * (1 + t2) * dth2;
259 ea[3][3] += dth2 * path * path /3 / (1 + t2);
260 ea[3][4] += dth2 * path/2 * sqrt(1 + t2);
261 ea[3][2] += dth2 *
t / sqrt(1 + t2) * k * path/2;
262 ea[0][0] += dth2 * path * path/3;
263 ea[0][1] += dth2 * sqrt(1 + t2) * path/2;
267 cout<<
"msgasmdc():ea after: "<<
Ea()<<endl;
276 cout<<
"ms...pathip..."<<pathip_<<endl;
285 cout<<
"eloss():ea before: "<<
Ea()<<endl;
288 double v_a_2_2 = v_a[2] * v_a[2];
289 double v_a_4_2 = v_a[4] * v_a[4];
290 double pmag = 1 / fabs(v_a[2]) * sqrt(1 + v_a_4_2);
291 double psq = pmag * pmag;
292 double E = sqrt(mass_ * mass_ + psq);
293 double dE = material.
dE(mass_, path, pmag);
297 psq += dE * (dE + 2 * sqrt(mass_ * mass_ + psq));
299 double dE_max = E - mass_;
300 if( dE<dE_max ) psq += dE * (dE - 2 * sqrt(mass_ * mass_ + psq));
307 double psq_kaon = p_kaon_ * p_kaon_;
308 double dE_kaon = material.
dE(MASS[3], path, p_kaon_);
309 psq_kaon += dE_kaon * (dE_kaon -
310 2 * sqrt(MASS[3] * MASS[3] + psq_kaon));
311 if (psq_kaon < 0) psq_kaon = 0;
312 p_kaon_ = sqrt(psq_kaon);
316 double psq_proton = p_proton_ * p_proton_;
317 double dE_proton = material.
dE(MASS[4], path, p_proton_);
318 psq_proton += dE_proton * (dE_proton -
319 2 * sqrt(MASS[4] * MASS[4] + psq_proton));
320 if (psq_proton < 0) psq_proton = 0;
321 p_proton_ = sqrt(psq_proton);
327 if(psq < 0) dpt = 9999;
328 else dpt = v_a[2] * pmag / sqrt(psq);
331 cout<<
"eloss():k: "<<v_a[2]<<
" k' "<<dpt<<endl;
335 HepSymMatrix ea =
Ea();
336 double r_E_prim = (E + dE)/E;
344 del_E = material.
del_E(mass_, path, pmag);
347 ea[2][2] += (v_a[2] * v_a[2]) * E * E * del_E * del_E / (psq*psq);
351 double dpt2 = dpt*dpt;
352 double A = dpt*dpt2/(v_a_2_2*v_a[2])*r_E_prim;
353 double B = v_a[4]/(1+v_a_4_2)*
354 dpt*(1-dpt2/v_a_2_2*r_E_prim);
356 double ea_2_0 = A*ea[2][0] + B*ea[4][0];
357 double ea_2_1 = A*ea[2][1] + B*ea[4][1];
358 double ea_2_2 = A*A*ea[2][2] + 2*A*B*ea[2][4] + B*B*ea[4][4];
359 double ea_2_3 = A*ea[2][3] + B*ea[4][3];
360 double ea_2_4 = A*ea[2][4] + B*ea[4][4];
382 unsigned int nhit = HitsMdc_.size();
390 double* Rad =
new double[nhit];
391 double* Ypos =
new double[nhit];
392 for(
unsigned i=0 ; i < nhit; i++ ){
396 Hep3Vector wire = (CLHEP::Hep3Vector)fwd -(CLHEP::Hep3Vector)bck;
401 work.
pivot((fwd + bck) * .5);
403 / wire.z() * wire + bck;
406 Rad[ind] = tracktest.
x(0).perp();
416 for(
int j, k = nhit - 1; k >= 0; k = j){
418 for(
int i = 1; i <= k; i++)
419 if(Rad[i - 1] > Rad[i]){
421 std::swap(Rad[i], Rad[j]);
422 std::swap(HitsMdc_[i], HitsMdc_[j]);
426 for(
int j, k = nhit - 1; k >= 0; k = j){
428 for(
int i = 1; i <= k; i++)
429 if(Rad[i - 1] < Rad[i]){
431 std::swap(Rad[i], Rad[j]);
432 std::swap(HitsMdc_[i], HitsMdc_[j]);
436 for(
int j, k = nhit - 1; k >= 0; k = j){
438 for(
int i = 1; i <= k; i++)
439 if(Ypos[i - 1] > Ypos[i]){
441 std::swap(Ypos[i], Ypos[j]);
442 std::swap(HitsMdc_[i], HitsMdc_[j]);
450 for(
int it=0; it<
HitsMdc().size()-1; it++){
451 if(HitsMdc_[it].wire().layer().layerId() == HitsMdc_[it+1].wire().layer().layerId())
453 if((
kappa()<0)&&(HitsMdc_[it].wire().localId() > HitsMdc_[it+1].wire().localId())){
454 std::swap(HitsMdc_[it], HitsMdc_[it+1]);
456 if((
kappa()>0)&&(HitsMdc_[it].wire().localId() < HitsMdc_[it+1].wire().localId())){
457 std::swap(HitsMdc_[it], HitsMdc_[it+1]);
466 unsigned int nhit = HitsMdc_.size();
468 for(
unsigned i=0 ; i < nhit; i++ )
469 Num[HitsMdc_[i].wire().layer().layerId()]++;
470 for(
unsigned i=0 ; i < nhit; i++ )
471 if (Num[HitsMdc_[i].wire().layer().layerId()]>2)
472 HitsMdc_[i].chi2(-2);
484 if (wire_ID<0 || wire_ID>6796){
485 std::cout <<
"KalFitTrack : wire_ID problem : " << wire_ID << std::endl;
495 double csf0 =
cos(phi);
496 double snf0 = (1. - csf0) * (1. + csf0);
497 snf0 = sqrt((snf0 > 0.) ? snf0 : 0.);
498 if(phi >
M_PI) snf0 = - snf0;
501 Hep3Vector ip(0, 0, 0);
505 double phi_ip = work.
phi0();
506 if (fabs(phi - phi_ip) >
M_PI) {
507 if (phi > phi_ip) phi -= 2 *
M_PI;
508 else phi_ip -= 2 *
M_PI;
511 double l = fabs(
radius() * (phi - phi_ip) * sqrt(1 +
t *
t));
512 double pmag( sqrt( 1.0 +
t*
t ) /
kappa());
513 double mass_over_p( mass_ / pmag );
514 double beta( 1.0 / sqrt( 1.0 + mass_over_p * mass_over_p ) );
515 tofest = l / ( 29.9792458 * beta );
516 if(csmflag==1 &&
HitMdc.
wire().
y()>0.) tofest= -1. * tofest;
519 const HepSymMatrix& ea =
Ea();
520 const HepVector& v_a =
a();
524 double dchi2R(99999999), dchi2L(99999999);
527 v_H[0] = -csf0 * meas.x() - snf0 * meas.y();
529 HepMatrix v_HT = v_H.T();
531 double estim = (v_HT * v_a)[0];
532 HepVector ea_v_H = ea * v_H;
533 HepMatrix ea_v_HT = (ea_v_H).T();
534 HepVector v_H_T_ea_v_H = v_HT * ea_v_H;
536 HepSymMatrix eaNew(5);
558 double dmeas2[2] = { 0.1*ddl, 0.1*ddr };
559 double er_dmeas2[2] = {0. , 0.};
561 er_dmeas2[0] = 0.1*erddl;
562 er_dmeas2[1] = 0.1*erddr;
572 double er_dmeasL, dmeasL;
574 dmeasL = (-1.0)*dmeas2[0];
575 er_dmeasL = er_dmeas2[0];
581 double AL = 1 / ((v_H_T_ea_v_H)[0] + er_dmeasL*er_dmeasL);
582 eaNew.assign(ea - ea_v_H * AL * ea_v_HT);
583 double RkL = 1 - (v_H_T_ea_v_H)[0] * AL;
584 if(0. == RkL) RkL = 1.e-4;
586 HepVector diffL = ea_v_H * AL * (dmeasL - estim);
588 double sigL = (dmeasL - (v_HT * aNew)[0]);
589 dchi2L = (sigL*sigL) / (RkL * er_dmeasL*er_dmeasL);
590 }
else if (lr == 1) {
593 double er_dmeasR, dmeasR;
596 er_dmeasR = er_dmeas2[1];
603 double AR = 1 / ((v_H_T_ea_v_H)[0] + er_dmeasR*er_dmeasR);
604 eaNew.assign(ea - ea_v_H * AR * ea_v_HT);
605 double RkR = 1 - (v_H_T_ea_v_H)[0] * AR;
606 if(0. == RkR) RkR = 1.e-4;
608 HepVector diffR = ea_v_H * AR * (dmeasR - estim);
610 double sigR = (dmeasR- (v_HT * aNew)[0]);
611 dchi2R = (sigR*sigR) / (RkR * er_dmeasR*er_dmeasR);
616 cout<<
"in smoother_Mdc: lr= "<<lr<<
" a: "<<v_a<<
" a_NEW: "<<aNew<<endl;
623 if ( !( aNew[2] && fabs(aNew[2]-
a()[2]) < 1.0 ) ) chge=0;
625 chiSq_back_ += dchi2R;
628 }
else if (lr == -1) {
629 chiSq_back_ += dchi2L;
643 Hep3Vector ip(0, 0, 0);
646 HepVector a_temp1 = helixNew1.a();
647 HepSymMatrix ea_temp1 = helixNew1.Ea();
653 KalFitTrack helixNew2(pivot_work, v_a, ea, 0, 0, 0);
655 HepVector a_temp2 = helixNew2.a();
656 HepSymMatrix ea_temp2 = helixNew2.Ea();
680 int layerid = (*HitMdc).wire().layer().layerId();
684 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;
700 Hep3Vector ip(0, 0, 0);
704 double phi_ip = work.
phi0();
705 if (fabs(phi - phi_ip) >
M_PI) {
706 if (phi > phi_ip) phi -= 2 *
M_PI;
707 else phi_ip -= 2 *
M_PI;
710 double l = fabs(
radius() * (phi - phi_ip) * sqrt(1 +
t *
t));
711 double pmag( sqrt( 1.0 +
t*
t ) /
kappa());
712 double mass_over_p( mass_ / pmag );
713 double beta( 1.0 / sqrt( 1.0 + mass_over_p * mass_over_p ) );
714 tofest = l / ( 29.9792458 * beta );
715 if(csmflag==1 && (*HitMdc).wire().y()>0.) tofest= -1. * tofest;
718 const HepSymMatrix& ea =
Ea();
719 const HepVector& v_a =
a();
742 double dchi2R(99999999), dchi2L(99999999);
744 v_H[0] = -csf0 * meas.x() - snf0 * meas.y();
746 HepMatrix v_HT = v_H.T();
748 double estim = (v_HT * v_a)[0];
749 HepVector ea_v_H = ea * v_H;
750 HepMatrix ea_v_HT = (ea_v_H).T();
751 HepVector v_H_T_ea_v_H = v_HT * ea_v_H;
752 HepSymMatrix eaNew(5);
754 double time = (*HitMdc).tdc();
772 double dmeas2[2] = { 0.1*ddl, 0.1*ddr };
773 double er_dmeas2[2] = {0., 0.};
775 er_dmeas2[0] = 0.1*erddl;
776 er_dmeas2[1] = 0.1*erddr;
783 double er_dmeasL, dmeasL;
785 dmeasL = (-1.0)*dmeas2[0];
786 er_dmeasL = er_dmeas2[0];
788 dmeasL = (-1.0)*fabs((*HitMdc).dist()[0]);
789 er_dmeasL = (*HitMdc).erdist()[0];
795 double AL = 1 / ((v_H_T_ea_v_H)[0] + er_dmeasL*er_dmeasL);
796 eaNew.assign(ea - ea_v_H * AL * ea_v_HT);
797 double RkL = 1 - (v_H_T_ea_v_H)[0] * AL;
798 if(0. == RkL) RkL = 1.e-4;
800 HepVector diffL = ea_v_H * AL * (dmeasL - estim);
802 double sigL = (dmeasL - (v_HT * aNew)[0]);
803 dchi2L = (sigL*sigL) / (RkL * er_dmeasL*er_dmeasL);
804 }
else if (lr == 1) {
807 double er_dmeasR, dmeasR;
810 er_dmeasR = er_dmeas2[1];
812 dmeasR = fabs((*HitMdc).dist()[1]);
813 er_dmeasR = (*HitMdc).erdist()[1];
820 double AR = 1 / ((v_H_T_ea_v_H)[0] + er_dmeasR*er_dmeasR);
821 eaNew.assign(ea - ea_v_H * AR * ea_v_HT);
822 double RkR = 1 - (v_H_T_ea_v_H)[0] * AR;
823 if(0. == RkR) RkR = 1.e-4;
825 HepVector diffR = ea_v_H * AR * (dmeasR - estim);
827 double sigR = (dmeasR- (v_HT * aNew)[0]);
828 dchi2R = (sigR*sigR) / (RkR * er_dmeasR*er_dmeasR);
833 cout<<
"in smoother_Mdc: lr= "<<lr<<
" a: "<<v_a<<
" a_NEW: "<<aNew<<endl;
842 if (!(aNew[2] && fabs(aNew[2]-
a()[2]) < 1.0)) chge = 0;
844 chiSq_back_ += dchi2R;
849 }
else if (lr == -1) {
850 chiSq_back_ += dchi2L;
863 HepVector a_pre_fwd_temp=seg.
a_pre_fwd();
864 if( (a_pre_fwd_temp[1]-seg.
a_pre_bwd()[1]) > 3. *
M_PI /2.) a_pre_fwd_temp[1]-=
M_PI2;
865 if( (a_pre_fwd_temp[1]-seg.
a_pre_bwd()[1]) < -3. *
M_PI /2. ) a_pre_fwd_temp[1]+=
M_PI2;
870 if( (a_pre_filt_temp[1]-seg.
a_pre_bwd()[1]) > 3. *
M_PI /2. ) a_pre_filt_temp[1] -=
M_PI2;
871 if( (a_pre_filt_temp[1]-seg.
a_pre_bwd()[1]) < -3. *
M_PI /2.) a_pre_filt_temp[1] +=
M_PI2;
886 std::cout<<
"seg.Ea_pre_bwd().inverse(inv) ..."<<seg.
Ea_pre_bwd().inverse(inv)<<std::endl;
887 std::cout<<
"seg.Ea_pre_fwd().inverse(inv) ..."<<seg.
Ea_pre_fwd().inverse(inv)<<std::endl;
890 HepSymMatrix Ea_pre_comb = (seg.
Ea_pre_bwd().inverse(inv)+seg.
Ea_pre_fwd().inverse(inv)).inverse(inv);
895 std::cout<<
"Ea_pre_comb_ ... "<<Ea_pre_comb<<std::endl;
896 std::cout<<
"seg.a_pre_bwd()..."<<seg.
a_pre_bwd()<<std::endl;
897 std::cout<<
"seg.a_pre_fwd()..."<<seg.
a_pre_fwd()<<std::endl;
903 std::cout<<
"seg.Ea_filt_fwd()..."<<seg.
Ea_filt_fwd()<<std::endl;
904 std::cout<<
"seg.Ea_filt_fwd().inverse(inv)..."<<seg.
Ea_filt_fwd().inverse(inv)<<std::endl;
910 std::cout<<
"seg.Ea() is ..."<<seg.
Ea()<<std::endl;
911 std::cout<<
"seg.Ea_filt_fwd().inverse(inv)*seg.a_filt_fwd() ..."<<seg.
Ea_filt_fwd().inverse(inv)*seg.
a_filt_fwd()<<std::endl;
912 std::cout<<
"seg.Ea_pre_bwd().inverse(inv)*seg.a_pre_bwd() ... "<<seg.
Ea_pre_bwd().inverse(inv)*seg.
a_pre_bwd()<<std::endl;
928 std::cout<<
"the dd in smoother_Mdc is "<<dd
929 <<
" the (v_HT*a_pre_comb)[0] is "<<(v_HT*a_pre_comb)[0]<<std::endl;
934 std::cout<<
"method 1 ..."<<sqrt(seg.
a()[0]*seg.
a()[0]+seg.
a()[3]*seg.
a()[3])<<std::endl;
935 std::cout<<
"method 2 ..."<<fabs((v_HT*seg.
a())[0])<<std::endl;
942 HepVector a_temp1 = helixNew1.
a();
943 HepSymMatrix ea_temp1 = helixNew1.
Ea();
951 HepVector a_temp2 = helixNew2.
a();
952 HepSymMatrix ea_temp2 = helixNew2.
Ea();
977 int layerid = (*HitMdc).wire().layer().layerId();
981 if (wire_ID<0 || wire_ID>6796){
982 std::cout <<
"KalFitTrack : wire_ID problem : " << wire_ID << std::endl;
991 double csf0 =
cos(phi);
992 double snf0 = (1. - csf0) * (1. + csf0);
993 snf0 = sqrt((snf0 > 0.) ? snf0 : 0.);
994 if(phi >
M_PI) snf0 = - snf0;
997 Hep3Vector ip(0, 0, 0);
1001 double phi_ip = work.
phi0();
1002 if (fabs(phi - phi_ip) >
M_PI) {
1003 if (phi > phi_ip) phi -= 2 *
M_PI;
1004 else phi_ip -= 2 *
M_PI;
1007 double l = fabs(
radius() * (phi - phi_ip) * sqrt(1 +
t *
t));
1008 double pmag( sqrt( 1.0 +
t*
t ) /
kappa());
1009 double mass_over_p( mass_ / pmag );
1010 double beta( 1.0 / sqrt( 1.0 + mass_over_p * mass_over_p ) );
1011 tofest = l / ( 29.9792458 * beta );
1012 if(csmflag==1 && (*HitMdc).wire().y()>0.) tofest= -1. * tofest;
1015 const HepSymMatrix& ea =
Ea();
1016 const HepVector& v_a =
a();
1040 double dchi2R(99999999), dchi2L(99999999);
1041 HepVector v_H(5, 0);
1042 v_H[0] = -csf0 * meas.x() - snf0 * meas.y();
1044 HepMatrix v_HT = v_H.T();
1046 double estim = (v_HT * v_a)[0];
1047 HepVector ea_v_H = ea * v_H;
1048 HepMatrix ea_v_HT = (ea_v_H).T();
1049 HepVector v_H_T_ea_v_H = v_HT * ea_v_H;
1050 HepSymMatrix eaNew(5);
1052 double time = (*HitMdc).tdc();
1070 double dmeas2[2] = { 0.1*ddl, 0.1*ddr };
1071 double er_dmeas2[2] = {0., 0.};
1073 er_dmeas2[0] = 0.1*erddl;
1074 er_dmeas2[1] = 0.1*erddr;
1081 double er_dmeasL, dmeasL;
1083 dmeasL = (-1.0)*dmeas2[0];
1084 er_dmeasL = er_dmeas2[0];
1086 dmeasL = (-1.0)*fabs((*HitMdc).dist()[0]);
1087 er_dmeasL = (*HitMdc).erdist()[0];
1093 double AL = 1 / ((v_H_T_ea_v_H)[0] + er_dmeasL*er_dmeasL);
1094 eaNew.assign(ea - ea_v_H * AL * ea_v_HT);
1095 double RkL = 1 - (v_H_T_ea_v_H)[0] * AL;
1096 if(0. == RkL) RkL = 1.e-4;
1098 HepVector diffL = ea_v_H * AL * (dmeasL - estim);
1100 double sigL = (dmeasL - (v_HT * aNew)[0]);
1101 dchi2L = (sigL*sigL) / (RkL * er_dmeasL*er_dmeasL);
1102 }
else if (lr == 1) {
1105 double er_dmeasR, dmeasR;
1108 er_dmeasR = er_dmeas2[1];
1110 dmeasR = fabs((*HitMdc).dist()[1]);
1111 er_dmeasR = (*HitMdc).erdist()[1];
1118 double AR = 1 / ((v_H_T_ea_v_H)[0] + er_dmeasR*er_dmeasR);
1119 eaNew.assign(ea - ea_v_H * AR * ea_v_HT);
1120 double RkR = 1 - (v_H_T_ea_v_H)[0] * AR;
1121 if(0. == RkR) RkR = 1.e-4;
1123 HepVector diffR = ea_v_H * AR * (dmeasR - estim);
1125 double sigR = (dmeasR- (v_HT * aNew)[0]);
1126 dchi2R = (sigR*sigR) / (RkR * er_dmeasR*er_dmeasR);
1131 cout<<
"in smoother_Mdc: lr= "<<lr<<
" a: "<<v_a<<
" a_NEW: "<<aNew<<endl;
1133 double dchi2_loc(0);
1140 if (!(aNew[2] && fabs(aNew[2]-
a()[2]) < 1.0)) chge = 0;
1142 chiSq_back_ += dchi2R;
1147 }
else if (lr == -1) {
1148 chiSq_back_ += dchi2L;
1161 HepVector a_pre_fwd_temp=seg.
a_pre_fwd();
1162 if( (a_pre_fwd_temp[1]-seg.
a_pre_bwd()[1]) > 3. *
M_PI /2.) a_pre_fwd_temp[1]-=
M_PI2;
1163 if( (a_pre_fwd_temp[1]-seg.
a_pre_bwd()[1]) < -3. *
M_PI /2. ) a_pre_fwd_temp[1]+=
M_PI2;
1168 if( (a_pre_filt_temp[1]-seg.
a_pre_bwd()[1]) > 3. *
M_PI /2. ) a_pre_filt_temp[1] -=
M_PI2;
1169 if( (a_pre_filt_temp[1]-seg.
a_pre_bwd()[1]) < -3. *
M_PI /2.) a_pre_filt_temp[1] +=
M_PI2;
1184 std::cout<<
"seg.Ea_pre_bwd().inverse(inv) ..."<<seg.
Ea_pre_bwd().inverse(inv)<<std::endl;
1185 std::cout<<
"seg.Ea_pre_fwd().inverse(inv) ..."<<seg.
Ea_pre_fwd().inverse(inv)<<std::endl;
1188 HepSymMatrix Ea_pre_comb = (seg.
Ea_pre_bwd().inverse(inv)+seg.
Ea_pre_fwd().inverse(inv)).inverse(inv);
1193 std::cout<<
"Ea_pre_comb_ ... "<<Ea_pre_comb<<std::endl;
1194 std::cout<<
"seg.a_pre_bwd()..."<<seg.
a_pre_bwd()<<std::endl;
1195 std::cout<<
"seg.a_pre_fwd()..."<<seg.
a_pre_fwd()<<std::endl;
1202 std::cout<<
"seg.Ea_filt_fwd()..."<<seg.
Ea_filt_fwd()<<std::endl;
1203 std::cout<<
"seg.Ea_filt_fwd().inverse(inv)..."<<seg.
Ea_filt_fwd().inverse(inv)<<std::endl;
1209 std::cout<<
"seg.Ea() is ..."<<seg.
Ea()<<std::endl;
1210 std::cout<<
"seg.Ea_filt_fwd().inverse(inv)*seg.a_filt_fwd() ..."<<seg.
Ea_filt_fwd().inverse(inv)*seg.
a_filt_fwd()<<std::endl;
1211 std::cout<<
"seg.Ea_pre_bwd().inverse(inv)*seg.a_pre_bwd() ... "<<seg.
Ea_pre_bwd().inverse(inv)*seg.
a_pre_bwd()<<std::endl;
1227 std::cout<<
"the dd in smoother_Mdc is "<<dd
1228 <<
" the (v_HT*a_pre_comb)[0] is "<<(v_HT*a_pre_comb)[0]<<std::endl;
1233 std::cout<<
"method 1 ..."<<sqrt(seg.
a()[0]*seg.
a()[0]+seg.
a()[3]*seg.
a()[3])<<std::endl;
1234 std::cout<<
"method 2 ..."<<fabs((v_HT*seg.
a())[0])<<std::endl;
1240 helixNew1.pivot(ip);
1241 HepVector a_temp1 = helixNew1.a();
1242 HepSymMatrix ea_temp1 = helixNew1.Ea();
1249 helixNew2.pivot(ip);
1250 HepVector a_temp2 = helixNew2.a();
1251 HepSymMatrix ea_temp2 = helixNew2.Ea();
1267 double v_d,
double m_V)
1269 HepMatrix m_HT = m_H.T();
1276 HepMatrix m_XT = m_X.T();
1277 HepMatrix
m_C = m_X *
Ea() * m_XT;
1279 HepVector m_K = 1 / (m_V + (m_HT *
m_C * m_H)[0]) * m_H;
1280 HepVector v_a =
a();
1281 HepSymMatrix ea =
Ea();
1282 HepMatrix mXTmK = m_XT * m_K;
1283 double v_r = v_m - v_d - (m_HT * v_x)[0];
1284 v_a += ea * mXTmK * v_r;
1286 ea.assign(ea - ea * mXTmK * m_HT * m_X * ea);
1290 HepMatrix mCmK =
m_C * m_K;
1292 m_C -= mCmK * m_HT *
m_C;
1293 v_r = v_m - v_d - (m_HT * v_x)[0];
1294 double m_R = m_V - (m_HT *
m_C * m_H)[0];
1295 double chiSq = v_r * v_r / m_R;
1325 double light_speed( 29.9792458 );
1327 double pmag( sqrt( 1.0 +
t*
t ) /
kappa());
1329 double mass_over_p( mass_ / pmag );
1330 double beta( 1.0 / sqrt( 1.0 + mass_over_p * mass_over_p ) );
1331 tof_ += path / ( light_speed * beta );
1336 double massk_over_p( MASS[3] / p_kaon_ );
1337 double beta_kaon( 1.0 / sqrt( 1.0 + massk_over_p * massk_over_p ) );
1338 tof_kaon_ += path / (light_speed * beta_kaon);
1341 double massp_over_p( MASS[4] / p_proton_ );
1342 double beta_proton( 1.0 / sqrt( 1.0 + massp_over_p * massp_over_p ) );
1343 tof_proton_ += path / (light_speed * beta_proton);
1354 double phi0 =
a()[1];
1357 double csf0 =
cos(phi);
1358 double snf0 = (1. - csf0) * (1. + csf0);
1359 snf0 = sqrt((snf0 > 0.) ? snf0 : 0.);
1360 if(phi >
M_PI) snf0 = - snf0;
1381 double ALPHA_loc = 10000./2.99792458/Bz;
1382 return ALPHA_loc /
a()[2];
1396 double xnp(nextPivot.x()), ynp(nextPivot.y()), znp(nextPivot.z());
1397 HepSymMatrix Ea_now =
Ea();
1399 double xp(piv.x()), yp(piv.y()), zp(piv.z());
1401 double phi0 =
a()[1];
1404 double tanl =
a()[4];
1410 double rdr =
dr + m_rad;
1412 double csf0 =
cos(phi);
1413 double snf0 = (1. - csf0) * (1. + csf0);
1414 snf0 = sqrt((snf0 > 0.) ? snf0 : 0.);
1415 if(phi >
M_PI) snf0 = - snf0;
1417 double xc = xp + rdr * csf0;
1418 double yc = yp + rdr * snf0;
1419 double csf = (xc - xnp) / m_rad;
1420 double snf = (yc - ynp) / m_rad;
1421 double anrm = sqrt(csf * csf + snf * snf);
1424 phi = atan2(snf, csf);
1427 double drp = (xp +
dr * csf0 + m_rad * (csf0 - csf) - xnp)
1429 + (yp +
dr * snf0 + m_rad * (snf0 - snf) - ynp) * snf;
1430 double dzp = zp +
dz - m_rad *
tanl * phid - znp;
1442 Hep3Vector x1(xp +
dr*csf0, yp +
dr*snf0, zp +
dz);
1443 double csf0p =
cos(ap[1]);
1444 double snf0p = (1. - csf0p) * (1. + csf0p);
1445 snf0p = sqrt((snf0p > 0.) ? snf0p : 0.);
1446 if(ap[1] >
M_PI) snf0p = - snf0p;
1448 Hep3Vector x2(xnp + drp*csf0p,
1451 Hep3Vector dist((x1 - x2).
x()/100.0,
1452 (x1 - x2).y()/100.0,
1453 (x1 - x2).z()/100.0);
1455 (x1.y() + x2.y())/2,
1456 (x1.z() + x2.z())/2);
1459 field = 1000.*field;
1460 Hep3Vector dB(field.x(),
1464 double akappa(fabs(
kappa));
1465 double sign =
kappa/akappa;
1467 dp = 0.299792458 * sign * dB.cross(dist);
1469 dhp[0] = -akappa*(dp[0]*csf0p+dp[1]*snf0p);
1470 dhp[1] =
kappa*akappa*(dp[0]*snf0p-dp[1]*csf0p);
1471 dhp[2] = dp[2]*akappa+dhp[1]*
tanl/
kappa;
1480 Ea_now.assign(m_del * Ea_now * m_del.T());
1495 double th = 90.0 - 180.0*M_1_PI*atan( tl );
1513 double xnp(nextPivot.x()), ynp(nextPivot.y()), znp(nextPivot.z());
1515 HepSymMatrix Ea_now =
Ea();
1517 double xp(piv.x()), yp(piv.y()), zp(piv.z());
1520 double phi0 =
a()[1];
1523 double tanl =
a()[4];
1528 double rdr =
dr + m_rad;
1530 double csf0 =
cos(phi);
1531 double snf0 = (1. - csf0) * (1. + csf0);
1532 snf0 = sqrt((snf0 > 0.) ? snf0 : 0.);
1533 if(phi >
M_PI) snf0 = - snf0;
1535 double xc = xp + rdr * csf0;
1536 double yc = yp + rdr * snf0;
1537 double csf = (xc - xnp) / m_rad;
1538 double snf = (yc - ynp) / m_rad;
1539 double anrm = sqrt(csf * csf + snf * snf);
1542 phi = atan2(snf, csf);
1545 double drp = (xp +
dr * csf0 + m_rad * (csf0 - csf) - xnp)
1547 + (yp +
dr * snf0 + m_rad * (snf0 - snf) - ynp) * snf;
1548 double dzp = zp +
dz - m_rad *
tanl * phid - znp;
1562 Hep3Vector x1(xp +
dr*csf0, yp +
dr*snf0, zp +
dz);
1564 double csf0p =
cos(ap[1]);
1565 double snf0p = (1. - csf0p) * (1. + csf0p);
1566 snf0p = sqrt((snf0p > 0.) ? snf0p : 0.);
1567 if(ap[1] >
M_PI) snf0p = - snf0p;
1569 Hep3Vector x2(xnp + drp*csf0p,
1573 Hep3Vector dist((x1 - x2).
x()/100.0,
1574 (x1 - x2).y()/100.0,
1575 (x1 - x2).z()/100.0);
1578 (x1.y() + x2.y())/2,
1579 (x1.z() + x2.z())/2);
1583 field = 1000.*field;
1586 Hep3Vector dB(field.x(),
1595 double akappa(fabs(
kappa));
1596 double sign =
kappa/akappa;
1598 dp = 0.299792458 * sign * dB.cross(dist);
1603 dhp[0] = -akappa*(dp[0]*csf0p+dp[1]*snf0p);
1604 dhp[1] =
kappa*akappa*(dp[0]*snf0p-dp[1]*csf0p);
1605 dhp[2] = dp[2]*akappa+dhp[1]*
tanl/
kappa;
1617 Ea_now.assign(m_del * Ea_now * m_del.T());
1627 double tanl_0(tracktest.
a()[4]);
1628 double phi0_0(tracktest.
a()[1]);
1629 double radius_0(tracktest.
radius());
1630 tracktest.
pivot(newPivot);
1632 double phi0_1 = tracktest.
a()[1];
1633 if (fabs(phi0_1 - phi0_0) >
M_PI) {
1634 if (phi0_1 > phi0_0) phi0_1 -= 2 *
M_PI;
1635 else phi0_0 -= 2 *
M_PI;
1637 if(phi0_1 == phi0_0) phi0_1 = phi0_0 + 1.e-10;
1638 pathl = fabs(radius_0 * (phi0_1 - phi0_0)
1639 * sqrt(1 + tanl_0 * tanl_0));
1749 Hep3Vector zvector( 0., 0., z_c-rho*dphi*tanl);
1751 double xcio, ycio, phip;
1753 double delrin = 2.0;
1754 if( m_zf-delrin > zvector.z() ){
1755 phip = z_c - m_zb + delrin;
1756 phip = phip/( rho*tanl );
1758 xcio = x_c - rho*cos( phip );
1759 ycio = y_c - rho*sin( phip );
1760 cell_IO[i].setX( xcio );
1761 cell_IO[i].setY( ycio );
1762 cell_IO[i].setZ( m_zb+delrin );
1765 else if( m_zb+delrin < zvector.z() ){
1766 phip = z_c - m_zf-delrin;
1767 phip = phip/( rho*tanl );
1769 xcio = x_c - rho*cos( phip );
1770 ycio = y_c - rho*sin( phip );
1771 cell_IO[i].setX( xcio );
1772 cell_IO[i].setY( ycio );
1773 cell_IO[i].setZ( m_zf-delrin );
1777 cell_IO[i] = iocand;
1778 cell_IO[i] += zvector;
1781 if( i == 0 ) phi_in = dphi;
1783// path length estimation
1785Hep3Vector cl = cell_IO[1] - cell_IO[0];
1787cout<<"cell_IO[0] "<<cell_IO[0]<<" cell_IO[1] "<<cell_IO[1]<<" cl "<<cl<<endl;
1793double ch_ltrk_rp = 0;
1794ch_dphi = cl.perp()*0.5/(ALPHA_loc*pt);
1795ch_dphi = 2.0 * asin( ch_dphi );
1796ch_ltrk_rp = ch_dphi*ALPHA_loc*pt;
1798cout<<"ch_dphi "<<ch_dphi<<" ch_ltrk_rp "<<ch_ltrk_rp<<" cl.z "<<cl.z()<<endl;
1800ch_ltrk = sqrt( ch_ltrk_rp*ch_ltrk_rp + cl.z()*cl.z() );
1801ch_theta = cl.theta();
1803if( ch_theta < theta*0.85 || 1.15*theta < ch_theta)
1804 ch_ltrk *= -1; /// miss calculation
1806if( epflag[0] == 1 || epflag [1] == 1 )
1807 ch_ltrk *= -1; /// invalid resion for dE/dx or outside of Mdc
1809 mom_[layer] = momentum( phi_in );
1810 PathL_[layer] = ch_ltrk;
1812 cout<<"ch_ltrk "<<ch_ltrk<<endl;
1822 j = (int) pow(2.,i);
1825 }
else if (i < 50) {
1826 j = (int) pow(2.,(i-31));
1864 int wire_ID = Wire.
geoID();
1867 if(
debug_ == 4) std::cout<<endl<<
"update_hits(): layer, wire = "<<layerid<<
", "<<wire_ID<<std::endl;
1870 if (wire_ID<0 || wire_ID>6796){
1871 std::cout <<
" KalFitTrack: wire_ID problem : " << wire_ID
1875 int flag_ster = Wire.
stereo();
1880 double csf0 =
cos(phi);
1881 double snf0 = (1. - csf0) * (1. + csf0);
1882 snf0 = sqrt((snf0 > 0.) ? snf0 : 0.);
1883 if(phi >
M_PI) snf0 = - snf0;
1891 Hep3Vector ip(0, 0, 0);
1893 phi_ip = work.
phi0();
1894 if (fabs(phi - phi_ip) >
M_PI) {
1895 if (phi > phi_ip) phi -= 2 *
M_PI;
1896 else phi_ip -= 2 *
M_PI;
1898 dphi = phi - phi_ip;
1899 double l = fabs(
radius() * dphi * sqrt(1 +
t *
t));
1900 double pmag( sqrt( 1.0 +
t*
t ) /
kappa());
1901 double mass_over_p( mass_ / pmag );
1902 double beta( 1.0 / sqrt( 1.0 + mass_over_p * mass_over_p ) );
1903 tofest = l / ( 29.9792458 * beta );
1904 if(csmflag==1 &&
HitMdc.
wire().
y()>0.) tofest= -1. * tofest;
1907 const HepSymMatrix& ea =
Ea();
1908 if(
debug_ == 4) std::cout<<endl<<
"update_hits(): Ea = "<<ea<<std::endl;
1909 const HepVector& v_a =
a();
1910 double dchi2R(99999999), dchi2L(99999999);
1912 HepVector v_H(5, 0);
1913 v_H[0] = -csf0 * meas.x() - snf0 * meas.y();
1915 HepMatrix v_HT = v_H.T();
1917 double estim = (v_HT * v_a)[0];
1920 HepVector ea_v_H = ea * v_H;
1921 HepMatrix ea_v_HT = (ea_v_H).T();
1922 HepVector v_H_T_ea_v_H = v_HT * ea_v_H;
1924 HepSymMatrix eaNewL(5), eaNewR(5);
1925 HepVector aNewL(5), aNewR(5);
1935 std::cout<<
"drifttime in update_hits() for ananlysis is "<<drifttime<<std::endl;
1936 std::cout<<
"ddl in update_hits() for ananlysis is "<<0.1*ddl<<std::endl;
1937 std::cout<<
"ddr in update_hits() for ananlysis is "<<0.1*ddr<<std::endl;
1938 std::cout<<
"erddl in update_hits() for ananlysis is "<<0.1*erddl<<std::endl;
1939 std::cout<<
"erddr in update_hits() for ananlysis is "<<0.1*erddr<<std::endl;
1940 std::cout<<
"in update_hits estim is "<<estim<<std::endl;
1944 double dmeas2[2] = { 0.1*ddl, 0.1*ddr };
1945 double er_dmeas2[2] = {0.,0.};
1947 er_dmeas2[0] = 0.1*erddl;
1948 er_dmeas2[1] = 0.1*erddr;
1957 if ((
LR_==0 && lr != 1.0) ||
1958 (
LR_==1 && lr == -1.0)) {
1959 double er_dmeasL, dmeasL;
1961 dmeasL = (-1.0)*fabs(dmeas2[0]);
1962 er_dmeasL = er_dmeas2[0];
1968 double AL = 1 / ((v_H_T_ea_v_H)[0] + er_dmeasL*er_dmeasL);
1969 eaNewL.assign(ea - ea_v_H * AL * ea_v_HT);
1970 double RkL = 1 - (v_H_T_ea_v_H)[0] * AL;
1973 std::cout<<
" ea_v_H * AL * ea_v_HT is: "<<ea_v_H * AL * ea_v_HT<<std::endl;
1974 std::cout<<
" v_H is: "<<v_H<<
" Ea is: "<<ea<<
" v_H_T_ea_v_H is: "<<v_H_T_ea_v_H<<std::endl;
1975 std::cout<<
" AL is: "<<AL<<
" (v_H_T_ea_v_H)[0] * AL is: "<<(v_H_T_ea_v_H)[0]*AL<<std::endl;
1978 if(0. == RkL) RkL = 1.e-4;
1980 HepVector diffL = ea_v_H * AL * (dmeasL - estim);
1981 aNewL = v_a + diffL;
1982 double sigL = dmeasL -(v_HT * aNewL)[0];
1983 dtracknew = (v_HT * aNewL)[0];
1984 dchi2L = (sigL * sigL)/(RkL * er_dmeasL*er_dmeasL);
1988 std::cout<<
" fwd_filter : in left hypothesis dchi2L is "<<dchi2L<<std::endl;
1989 std::cout<<
" diffL="<<diffL<<std::endl;
1993 if ((
LR_==0 && lr != -1.0) ||
1994 (
LR_==1 && lr == 1.0)) {
1995 double er_dmeasR, dmeasR;
1998 er_dmeasR = er_dmeas2[1];
2004 double AR = 1 / ((v_H_T_ea_v_H)[0] + er_dmeasR*er_dmeasR);
2005 eaNewR.assign(ea - ea_v_H * AR * ea_v_HT);
2006 double RkR = 1 - (v_H_T_ea_v_H)[0] * AR;
2010 std::cout<<
" ea_v_H * AR * ea_v_HT is: "<<ea_v_H * AR * ea_v_HT<<std::endl;
2011 std::cout<<
" v_H is: "<<v_H<<
" Ea is: "<<ea<<
" v_H_T_ea_v_H is: "<<v_H_T_ea_v_H<<std::endl;
2012 std::cout<<
" AR is: "<<AR<<
" (v_H_T_ea_v_H)[0] * AR is: "<<(v_H_T_ea_v_H)[0]*AR<<std::endl;
2015 if(0. == RkR) RkR = 1.e-4;
2016 HepVector diffR = ea_v_H * AR * (dmeasR - estim);
2017 aNewR = v_a + diffR;
2018 double sigR = dmeasR -(v_HT * aNewR)[0];
2019 dtracknew = (v_HT * aNewR)[0];
2020 dchi2R = (sigR*sigR)/(RkR * er_dmeasR*er_dmeasR);
2023 std::cout<<
" fwd_filter : in right hypothesis dchi2R is "<<dchi2R<<std::endl;
2024 std::cout<<
" diffR="<<diffR<<std::endl;
2028 double dchi2_loc(0);
2029 double dchi2_beforeCut(9999);
2030 if (fabs(dchi2R-dchi2L)<10. && inext>0) {
2033 double chi2_fromR(
chi2_next(H_fromR, HitMdc_next, csmflag));
2035 double chi2_fromL(
chi2_next(H_fromL, HitMdc_next, csmflag));
2037 std::cout <<
" chi2_fromL = " << chi2_fromL
2038 <<
", chi2_fromR = " << chi2_fromR << std::endl;
2040 if (fabs(chi2_fromR-chi2_fromL)<10.){
2042 if (inext+1<HitsMdc_.size())
2043 for(
int k=inext+1 ; k < HitsMdc_.size(); k++ )
2044 if (!(HitsMdc_[k].chi2()<0)) {
2051 double chi2_fromR2(
chi2_next(H_fromR, HitMdc_next2, csmflag));
2052 double chi2_fromL2(
chi2_next(H_fromL, HitMdc_next2, csmflag));
2054 std::cout <<
" chi2_fromL2 = " << chi2_fromL2
2055 <<
", chi2_fromR2 = " << chi2_fromR2 << std::endl;
2057 if (fabs(dchi2R+chi2_fromR+chi2_fromR2-(dchi2L+chi2_fromL+chi2_fromL2))<2) {
2058 if (chi2_fromR2<chi2_fromL2)
2067 if (dchi2R+chi2_fromR < dchi2L+chi2_fromL){
2070 std::cout <<
" choose right..." << std::endl;
2075 std::cout <<
" choose left..." << std::endl;
2081 if(
LR_==1 && lr == -1) dchi2_beforeCut=dchi2L;
2082 if(
LR_==1 && lr == 1) dchi2_beforeCut=dchi2R;
2087 if (((
LR_==0 && dchi2R < dchi2L && lr != -1) ||
2088 (
LR_==1 && lr == 1)) &&
2089 fabs(aNewR[2]-
a()[2]) < 1000. && aNewR[2]) {
2092 if (flag_ster) nster_++;
2098 if (l_mass_ == lead_){
2103 }
else if (((
LR_==0 && dchi2L <= dchi2R && lr != 1) ||
2104 (
LR_==1 && lr == -1)) &&
2105 fabs(aNewL[2]-
a()[2]) < 1000. && aNewL[2]){
2108 if (flag_ster) nster_++;
2114 if (l_mass_ == lead_){
2122 std::cout<<
"a from "<<v_a
2127 if (dchi2_loc > dchi2_max_) {
2128 dchi2_max_ = dchi2_loc ;
2129 r_max_ =
pivot().perp();
2131 dchi2out = dchi2_loc;
2132 if(dchi2out==0) dchi2out = -dchi2_beforeCut;
2147 int layerid = (*HitMdc).wire().layer().layerId();
2152 std::cout<<
"in update_hits(kalFitHelixSeg,...) : the layerid ="<<layerid<<std::endl;
2153 std::cout<<
" update_hits: lr= " << lr <<std::endl;
2157 int wire_ID = Wire.
geoID();
2159 if (wire_ID<0 || wire_ID>6796){
2160 std::cout <<
" KalFitTrack: wire_ID problem : " << wire_ID
2164 int flag_ster = Wire.
stereo();
2169 double csf0 =
cos(phi);
2170 double snf0 = (1. - csf0) * (1. + csf0);
2171 snf0 = sqrt((snf0 > 0.) ? snf0 : 0.);
2172 if(phi >
M_PI) snf0 = - snf0;
2180 Hep3Vector ip(0, 0, 0);
2182 phi_ip = work.
phi0();
2183 if (fabs(phi - phi_ip) >
M_PI) {
2184 if (phi > phi_ip) phi -= 2 *
M_PI;
2185 else phi_ip -= 2 *
M_PI;
2187 dphi = phi - phi_ip;
2189 double l = fabs(
radius() * dphi * sqrt(1 +
t *
t));
2190 double pmag( sqrt( 1.0 +
t*
t ) /
kappa());
2191 double mass_over_p( mass_ / pmag );
2192 double beta( 1.0 / sqrt( 1.0 + mass_over_p * mass_over_p ) );
2193 tofest = l / ( 29.9792458 * beta );
2194 if(csmflag==1 && (*HitMdc).wire().y()>0.) tofest= -1. * tofest;
2197 const HepSymMatrix& ea =
Ea();
2202 const HepVector& v_a =
a();
2226 double dchi2R(99999999), dchi2L(99999999);
2228 HepVector v_H(5, 0);
2229 v_H[0] = -csf0 * meas.x() - snf0 * meas.y();
2231 HepMatrix v_HT = v_H.T();
2233 double estim = (v_HT * v_a)[0];
2234 HepVector ea_v_H = ea * v_H;
2235 HepMatrix ea_v_HT = (ea_v_H).T();
2236 HepVector v_H_T_ea_v_H = v_HT * ea_v_H;
2238 HepSymMatrix eaNewL(5), eaNewR(5);
2239 HepVector aNewL(5), aNewR(5);
2241 cout<<
"phi "<<phi<<
" snf0 "<<snf0<<
" csf0 "<<csf0<<endl
2242 <<
" meas: "<<meas <<endl;
2243 cout<<
"the related matrix:"<<endl;
2244 cout<<
"v_H "<<v_H<<endl;
2245 cout<<
"v_a "<<v_a<<endl;
2246 cout<<
"ea "<<ea<<endl;
2247 cout<<
"v_H_T_ea_v_H "<<v_H_T_ea_v_H<<endl;
2248 cout<<
"LR_= "<<
LR_ <<
"lr= " << lr <<endl;
2251 double time = (*HitMdc).tdc();
2265 std::cout<<
"the pure drift time is "<<drifttime<<std::endl;
2266 std::cout<<
"the drift dist left hypothesis is "<<ddl<<std::endl;
2267 std::cout<<
"the drift dist right hypothesis is "<<ddr<<std::endl;
2268 std::cout<<
"the error sigma left hypothesis is "<<erddl<<std::endl;
2269 std::cout<<
"the error sigma right hypothesis is "<<erddr<<std::endl;
2271 double dmeas2[2] = { 0.1*ddl , 0.1*ddr };
2272 double er_dmeas2[2] = {0. , 0.} ;
2275 er_dmeas2[0] = 0.1*erddl;
2276 er_dmeas2[1] = 0.1*erddr;
2285 if ((
LR_==0 && lr != 1.0) ||
2286 (
LR_==1 && lr == -1.0)) {
2288 double er_dmeasL, dmeasL;
2290 dmeasL = (-1.0)*fabs(dmeas2[0]);
2291 er_dmeasL = er_dmeas2[0];
2293 dmeasL = (-1.0)*fabs((*HitMdc).dist()[0]);
2294 er_dmeasL = (*HitMdc).erdist()[0];
2297 double AL = 1 / ((v_H_T_ea_v_H)[0] + er_dmeasL*er_dmeasL);
2298 eaNewL.assign(ea - ea_v_H * AL * ea_v_HT);
2299 double RkL = 1 - (v_H_T_ea_v_H)[0] * AL;
2300 if(0. == RkL) RkL = 1.e-4;
2302 HepVector diffL = ea_v_H * AL * (dmeasL - estim);
2304 aNewL = v_a + diffL;
2305 double sigL = dmeasL -(v_HT * aNewL)[0];
2306 dchi2L = (sigL * sigL) / (RkL * er_dmeasL*er_dmeasL);
2309 if ((
LR_==0 && lr != -1.0) ||
2310 (
LR_==1 && lr == 1.0)) {
2312 double er_dmeasR, dmeasR;
2315 er_dmeasR = er_dmeas2[1];
2317 dmeasR = fabs((*HitMdc).dist()[1]);
2318 er_dmeasR = (*HitMdc).erdist()[1];
2321 double AR = 1 / ((v_H_T_ea_v_H)[0] + er_dmeasR*er_dmeasR);
2322 eaNewR.assign(ea - ea_v_H * AR * ea_v_HT);
2323 double RkR = 1 - (v_H_T_ea_v_H)[0] * AR;
2324 if(0. == RkR) RkR = 1.e-4;
2326 HepVector diffR = ea_v_H * AR * (dmeasR - estim);
2328 aNewR = v_a + diffR;
2329 double sigR = dmeasR -(v_HT * aNewR)[0];
2330 dchi2R = (sigR*sigR) / (RkR * er_dmeasR*er_dmeasR);
2334 double dchi2_loc(0);
2337 cout<<
" track::update_hits......"<<endl;
2338 std::cout <<
" dchi2R = " << dchi2R <<
", dchi2L = " << dchi2L
2339 <<
" estimate = "<<estim<< std::endl;
2340 std::cout <<
" dmeasR = " << dmeas2[1]
2341 <<
", dmeasL = " << (-1.0)*fabs(dmeas2[0]) <<
", check HitMdc.ddl = "
2342 << (*HitMdc).dist()[0] << std::endl;
2343 std::cout<<
"dchi2L : "<<dchi2L<<
" ,dchi2R: "<<dchi2R<<std::endl;
2347 if (fabs(dchi2R-dchi2L)<10. && inext>0) {
2352 double chi2_fromR(
chi2_next(H_fromR, HitMdc_next,csmflag));
2356 double chi2_fromL(
chi2_next(H_fromL, HitMdc_next,csmflag));
2359 std::cout <<
" chi2_fromL = " << chi2_fromL
2360 <<
", chi2_fromR = " << chi2_fromR << std::endl;
2362 if (fabs(chi2_fromR-chi2_fromL)<10.){
2364 if (inext+1<HitsMdc_.size())
2365 for(
int k=inext+1 ; k < HitsMdc_.size(); k++ )
2366 if (!(HitsMdc_[k].chi2()<0)) {
2375 double chi2_fromR2(
chi2_next(H_fromR, HitMdc_next2, csmflag));
2376 double chi2_fromL2(
chi2_next(H_fromL, HitMdc_next2, csmflag));
2378 std::cout <<
" chi2_fromL2 = " << chi2_fromL2
2379 <<
", chi2_fromR2 = " << chi2_fromR2 << std::endl;
2381 if (fabs(dchi2R+chi2_fromR+chi2_fromR2-(dchi2L+chi2_fromL+chi2_fromL2))<2) {
2382 if (chi2_fromR2<chi2_fromL2)
2391 if (dchi2R+chi2_fromR < dchi2L+chi2_fromL){
2394 std::cout <<
" choose right..." << std::endl;
2399 std::cout <<
" choose left..." << std::endl;
2408 if (((
LR_==0 && dchi2R < dchi2L && lr != -1) ||
2409 (
LR_==1 && lr == 1)) &&
2410 fabs(aNewR[2]-
a()[2]) < 1000. && aNewR[2]) {
2413 if (flag_ster) nster_++;
2438 if (l_mass_ == lead_){
2442 update_bit((*HitMdc).wire().layer().layerId());
2444 }
else if (((
LR_==0 && dchi2L <= dchi2R && lr != 1) ||
2445 (
LR_==1 && lr == -1)) &&
2446 fabs(aNewL[2]-
a()[2]) < 1000. && aNewL[2]){
2449 if (flag_ster) nster_++;
2473 if (l_mass_ == lead_){
2477 update_bit((*HitMdc).wire().layer().layerId());
2482 if (dchi2_loc > dchi2_max_) {
2483 dchi2_max_ = dchi2_loc ;
2484 r_max_ =
pivot().perp();
2486 dchi2out = dchi2_loc;
2501 int layerid = (*HitMdc).wire().layer().layerId();
2505 std::cout<<
"in update_hits(kalFitHelixSeg,...) : the layerid ="<<layerid<<std::endl;
2506 std::cout<<
" update_hits: lr= " << lr <<std::endl;
2510 int wire_ID = Wire.
geoID();
2512 if (wire_ID<0 || wire_ID>6796){
2513 std::cout <<
" KalFitTrack: wire_ID problem : " << wire_ID
2517 int flag_ster = Wire.
stereo();
2522 double csf0 =
cos(phi);
2523 double snf0 = (1. - csf0) * (1. + csf0);
2524 snf0 = sqrt((snf0 > 0.) ? snf0 : 0.);
2525 if(phi >
M_PI) snf0 = - snf0;
2533 Hep3Vector ip(0, 0, 0);
2535 phi_ip = work.
phi0();
2536 if (fabs(phi - phi_ip) >
M_PI) {
2537 if (phi > phi_ip) phi -= 2 *
M_PI;
2538 else phi_ip -= 2 *
M_PI;
2540 dphi = phi - phi_ip;
2542 double l = fabs(
radius() * dphi * sqrt(1 +
t *
t));
2543 double pmag( sqrt( 1.0 +
t*
t ) /
kappa());
2544 double mass_over_p( mass_ / pmag );
2545 double beta( 1.0 / sqrt( 1.0 + mass_over_p * mass_over_p ) );
2546 tofest = l / ( 29.9792458 * beta );
2547 if(csmflag==1 && (*HitMdc).wire().y()>0.) tofest= -1. * tofest;
2550 const HepSymMatrix& ea =
Ea();
2555 const HepVector& v_a =
a();
2580 double dchi2R(99999999), dchi2L(99999999);
2582 HepVector v_H(5, 0);
2583 v_H[0] = -csf0 * meas.x() - snf0 * meas.y();
2585 HepMatrix v_HT = v_H.T();
2587 double estim = (v_HT * v_a)[0];
2588 HepVector ea_v_H = ea * v_H;
2589 HepMatrix ea_v_HT = (ea_v_H).T();
2590 HepVector v_H_T_ea_v_H = v_HT * ea_v_H;
2592 HepSymMatrix eaNewL(5), eaNewR(5);
2593 HepVector aNewL(5), aNewR(5);
2595 cout<<
"phi "<<phi<<
" snf0 "<<snf0<<
" csf0 "<<csf0<<endl
2596 <<
" meas: "<<meas <<endl;
2597 cout<<
"the related matrix:"<<endl;
2598 cout<<
"v_H "<<v_H<<endl;
2599 cout<<
"v_a "<<v_a<<endl;
2600 cout<<
"ea "<<ea<<endl;
2601 cout<<
"v_H_T_ea_v_H "<<v_H_T_ea_v_H<<endl;
2602 cout<<
"LR_= "<<
LR_ <<
"lr= " << lr <<endl;
2605 double time = (*HitMdc).tdc();
2619 std::cout<<
"the pure drift time is "<<drifttime<<std::endl;
2620 std::cout<<
"the drift dist left hypothesis is "<<ddl<<std::endl;
2621 std::cout<<
"the drift dist right hypothesis is "<<ddr<<std::endl;
2622 std::cout<<
"the error sigma left hypothesis is "<<erddl<<std::endl;
2623 std::cout<<
"the error sigma right hypothesis is "<<erddr<<std::endl;
2625 double dmeas2[2] = { 0.1*ddl , 0.1*ddr };
2626 double er_dmeas2[2] = {0. , 0.} ;
2629 er_dmeas2[0] = 0.1*erddl;
2630 er_dmeas2[1] = 0.1*erddr;
2639 if ((
LR_==0 && lr != 1.0) ||
2640 (
LR_==1 && lr == -1.0)) {
2642 double er_dmeasL, dmeasL;
2644 dmeasL = (-1.0)*fabs(dmeas2[0]);
2645 er_dmeasL = er_dmeas2[0];
2647 dmeasL = (-1.0)*fabs((*HitMdc).dist()[0]);
2648 er_dmeasL = (*HitMdc).erdist()[0];
2651 double AL = 1 / ((v_H_T_ea_v_H)[0] + er_dmeasL*er_dmeasL);
2652 eaNewL.assign(ea - ea_v_H * AL * ea_v_HT);
2653 double RkL = 1 - (v_H_T_ea_v_H)[0] * AL;
2654 if(0. == RkL) RkL = 1.e-4;
2656 HepVector diffL = ea_v_H * AL * (dmeasL - estim);
2658 aNewL = v_a + diffL;
2659 double sigL = dmeasL -(v_HT * aNewL)[0];
2660 dchi2L = (sigL * sigL) / (RkL * er_dmeasL*er_dmeasL);
2663 if ((
LR_==0 && lr != -1.0) ||
2664 (
LR_==1 && lr == 1.0)) {
2666 double er_dmeasR, dmeasR;
2669 er_dmeasR = er_dmeas2[1];
2671 dmeasR = fabs((*HitMdc).dist()[1]);
2672 er_dmeasR = (*HitMdc).erdist()[1];
2675 double AR = 1 / ((v_H_T_ea_v_H)[0] + er_dmeasR*er_dmeasR);
2676 eaNewR.assign(ea - ea_v_H * AR * ea_v_HT);
2677 double RkR = 1 - (v_H_T_ea_v_H)[0] * AR;
2678 if(0. == RkR) RkR = 1.e-4;
2680 HepVector diffR = ea_v_H * AR * (dmeasR - estim);
2682 aNewR = v_a + diffR;
2683 double sigR = dmeasR -(v_HT * aNewR)[0];
2684 dchi2R = (sigR*sigR) / (RkR * er_dmeasR*er_dmeasR);
2688 double dchi2_loc(0);
2691 cout<<
" track::update_hits......"<<endl;
2692 std::cout <<
" dchi2R = " << dchi2R <<
", dchi2L = " << dchi2L
2693 <<
" estimate = "<<estim<< std::endl;
2694 std::cout <<
" dmeasR = " << dmeas2[1]
2695 <<
", dmeasL = " << (-1.0)*fabs(dmeas2[0]) <<
", check HitMdc.ddl = "
2696 << (*HitMdc).dist()[0] << std::endl;
2699 if (fabs(dchi2R-dchi2L)<10. && inext>0) {
2704 double chi2_fromR(
chi2_next(H_fromR, HitMdc_next,csmflag));
2707 double chi2_fromL(
chi2_next(H_fromL, HitMdc_next,csmflag));
2709 std::cout <<
" chi2_fromL = " << chi2_fromL
2710 <<
", chi2_fromR = " << chi2_fromR << std::endl;
2712 if (fabs(chi2_fromR-chi2_fromL)<10.){
2714 if (inext+1<HitsMdc_.size())
2715 for(
int k=inext+1 ; k < HitsMdc_.size(); k++ )
2716 if (!(HitsMdc_[k].chi2()<0)) {
2723 double chi2_fromR2(
chi2_next(H_fromR, HitMdc_next2, csmflag));
2724 double chi2_fromL2(
chi2_next(H_fromL, HitMdc_next2, csmflag));
2726 std::cout <<
" chi2_fromL2 = " << chi2_fromL2
2727 <<
", chi2_fromR2 = " << chi2_fromR2 << std::endl;
2729 if (fabs(dchi2R+chi2_fromR+chi2_fromR2-(dchi2L+chi2_fromL+chi2_fromL2))<2) {
2730 if (chi2_fromR2<chi2_fromL2)
2739 if (dchi2R+chi2_fromR < dchi2L+chi2_fromL){
2742 std::cout <<
" choose right..." << std::endl;
2747 std::cout <<
" choose left..." << std::endl;
2756 if (((
LR_==0 && dchi2R < dchi2L && lr != -1) ||
2757 (
LR_==1 && lr == 1)) &&
2758 fabs(aNewR[2]-
a()[2]) < 1000. && aNewR[2]) {
2761 if (flag_ster) nster_++;
2786 if (l_mass_ == lead_){
2790 update_bit((*HitMdc).wire().layer().layerId());
2792 }
else if (((
LR_==0 && dchi2L <= dchi2R && lr != 1) ||
2793 (
LR_==1 && lr == -1)) &&
2794 fabs(aNewL[2]-
a()[2]) < 1000. && aNewL[2]){
2797 if (flag_ster) nster_++;
2820 if (l_mass_ == lead_){
2824 update_bit((*HitMdc).wire().layer().layerId());
2829 if (dchi2_loc > dchi2_max_) {
2830 dchi2_max_ = dchi2_loc ;
2831 r_max_ =
pivot().perp();
2833 dchi2out = dchi2_loc;
2849 double recZ = Cluster->
getRecZ()/10;
2851 while(recPhi >
M_PI) recPhi-=2*
M_PI;
2852 while(recPhi <-
M_PI) recPhi+=2*
M_PI;
2853 HepVector v_measu(2,0);
2854 v_measu(1) = recPhi;
2861 HepVector v_estim(2,0);
2862 v_estim(1) = x0kal.phi();
2863 v_estim(2) = x0kal.z();
2865 const HepSymMatrix& ea =
Ea();
2866 HepVector v_a =
a();
2871 double phi0 = v_a(2);
2872 double kappa = v_a(3);
2873 double tanl = v_a(5);
2874 double x0 = x0kal.x();
2875 double y0 = x0kal.y();
2876 double Alpha =
alpha();
2877 HepMatrix
H(2, 5, 0);
2887 ISvcLocator* svcLocator = Gaudi::svcLocator();
2889 StatusCode Cgem_sc=svcLocator->service(
"CgemGeomSvc", ISvc);
2897 StatusCode sc = svcLocator->service (
"CgemCalibFunSvc", CgemCalibSvc);
2898 int iView(0), mode(2);
2899 double Q(100), T(100);
2901 double Phi_position = x0kal.phi();
2902 double delta_phi=Phi_momentum - Phi_position;
2903 while(delta_phi>
M_PI) delta_phi-=CLHEP::twopi;
2904 while(delta_phi<-
M_PI) delta_phi+=CLHEP::twopi;
2905 double sigma_X = CgemCalibSvc->
getSigma(layer,iView,mode,delta_phi,Q,T);
2906 double sigma_V = CgemCalibSvc->
getSigma(layer,iView,mode,delta_phi,Q,T);
2908 HepSymMatrix V(2,0);
2911 V(1,1) = pow(sigma_X/R_x,2);
2918 HepMatrix K = ea*
H.T()*(V+
H*ea*
H.T()).inverse(ierr);
2919 if(ierr != 0) cout<<
"KalFitTrack::update_hits(cluster) errer in inverse operation of gain matrix!"<<endl;
2922 HepSymMatrix EaNew(5,0);
2923 EaNew.assign(ea-K*
H*ea);
2927 HepVector v_diff = v_measu - v_estim;
2928 while(v_diff(1) >
M_PI) v_diff(1)-=2*
M_PI;
2929 while(v_diff(1) <-
M_PI) v_diff(1)+=2*
M_PI;
2932 HepVector aNew = v_a + K*v_diff;
2937 HepVector v_estim_new(2,0);
2938 v_estim_new(1) = x0kal_new.phi();
2939 v_estim_new(2) = x0kal_new.z();
2942 v_diff = v_measu - v_estim_new;
2943 while(v_diff(1) >
M_PI) v_diff(1)-=2*
M_PI;
2944 while(v_diff(1) <-
M_PI) v_diff(1)+=2*
M_PI;
2952 HepSymMatrix R(2,0);
2953 R.assign(V-
H*EaNew*
H.T());
2954 HepVector dChi2 = v_diff.T()*R.inverse(ierr)*v_diff;
2955 if(ierr != 0) cout<<
"KalFitTrack::update_hits(cluster) errer in inverse operation of R matrix!"<<endl;
2959 if(dChi2(1)>0 && fabs(aNew[2]-
a()[2]) < 1000. && aNew[2] && dChi2(1) < 2.0*
dchi2cutf_anal[layerid])
2990 int wire_ID = Wire.
geoID();
2996 Hep3Vector wire = (Hep3Vector)fwd -(Hep3Vector)bck;
2999 work.
pivot((fwd + bck) * .5);
3000 HepPoint3D x0kal = (work.
x(0).z() - bck.z())/ wire.z() * wire + bck;
3003 Hep3Vector meas =
H.momentum(0).cross(wire).unit();
3005 if (wire_ID<0 || wire_ID>6796){
3006 std::cout <<
"KalFitTrack : wire_ID problem : " << wire_ID
3015 double csf0 =
cos(phi);
3016 double snf0 = (1. - csf0) * (1. + csf0);
3017 snf0 = sqrt((snf0 > 0.) ? snf0 : 0.);
3018 if(phi >
M_PI) snf0 = - snf0;
3021 Hep3Vector ip(0, 0, 0);
3025 double phi_ip = work.
phi0();
3026 if (fabs(phi - phi_ip) >
M_PI) {
3027 if (phi > phi_ip) phi -= 2 *
M_PI;
3028 else phi_ip -= 2 *
M_PI;
3031 double l = fabs(
radius() * (phi - phi_ip) * sqrt(1 +
t *
t));
3032 double pmag( sqrt( 1.0 +
t*
t ) /
kappa());
3033 double mass_over_p( mass_ / pmag );
3034 double beta( 1.0 / sqrt( 1.0 + mass_over_p * mass_over_p ) );
3035 tofest = l / ( 29.9792458 * beta );
3039 const HepSymMatrix& ea =
H.Ea();
3040 const HepVector& v_a =
H.a();
3043 HepVector v_H(5, 0);
3044 v_H[0] = -csf0 * meas.x() - snf0 * meas.y();
3046 HepMatrix v_HT = v_H.T();
3048 double estim = (v_HT * v_a)[0];
3049 HepVector ea_v_H = ea * v_H;
3050 HepMatrix ea_v_HT = (ea_v_H).T();
3051 HepVector v_H_T_ea_v_H = v_HT * ea_v_H;
3053 HepSymMatrix eaNewL(5), eaNewR(5);
3054 HepVector aNewL(5), aNewR(5);
3065 double dmeas2[2] = { 0.1*ddl, 0.1*ddr };
3066 double er_dmeas2[2] = {0. , 0.};
3068 er_dmeas2[0] = 0.1*erddl;
3069 er_dmeas2[1] = 0.1*erddr;
3077 if ((
LR_==0 && lr != 1.0) ||
3078 (
LR_==1 && lr == -1.0)) {
3080 double er_dmeasL, dmeasL;
3082 dmeasL = (-1.0)*fabs(dmeas2[0]);
3083 er_dmeasL = er_dmeas2[0];
3089 double AL = 1 / ((v_H_T_ea_v_H)[0] + er_dmeasL*er_dmeasL);
3090 eaNewL.assign(ea - ea_v_H * AL * ea_v_HT);
3091 double RkL = 1 - (v_H_T_ea_v_H)[0] * AL;
3092 if(0. == RkL) RkL = 1.e-4;
3094 HepVector diffL = ea_v_H * AL * (dmeasL - estim);
3095 aNewL = v_a + diffL;
3096 double sigL = dmeasL -(v_HT * aNewL)[0];
3097 dchi2L = (sigL * sigL) / (RkL * er_dmeasL*er_dmeasL);
3100 if ((
LR_==0 && lr != -1.0) ||
3101 (
LR_==1 && lr == 1.0)) {
3103 double er_dmeasR, dmeasR;
3106 er_dmeasR = er_dmeas2[1];
3112 double AR = 1 / ((v_H_T_ea_v_H)[0] + er_dmeasR*er_dmeasR);
3113 eaNewR.assign(ea - ea_v_H * AR * ea_v_HT);
3114 double RkR = 1 - (v_H_T_ea_v_H)[0] * AR;
3115 if(0. == RkR) RkR = 1.e-4;
3117 HepVector diffR = ea_v_H * AR * (dmeasR - estim);
3118 aNewR = v_a + diffR;
3119 double sigR = dmeasR -(v_HT * aNewR)[0];
3120 dchi2R = (sigR*sigR) / (RkR * er_dmeasR*er_dmeasR);
3123 if (dchi2R < dchi2L){
3124 H.a(aNewR);
H.Ea(eaNewR);
3126 H.a(aNewL);
H.Ea(eaNewL);
3128 return ((dchi2R < dchi2L) ? dchi2R : dchi2L);
3135 int wire_ID = Wire.
geoID();
3141 Hep3Vector wire = (Hep3Vector)fwd -(Hep3Vector)bck;
3144 work.
pivot((fwd + bck) * .5);
3145 HepPoint3D x0kal = (work.
x(0).z() - bck.z())/ wire.z() * wire + bck;
3148 Hep3Vector meas =
H.momentum(0).cross(wire).unit();
3150 if (wire_ID<0 || wire_ID>6796){
3151 std::cout <<
"KalFitTrack : wire_ID problem : " << wire_ID
3160 double csf0 =
cos(phi);
3161 double snf0 = (1. - csf0) * (1. + csf0);
3162 snf0 = sqrt((snf0 > 0.) ? snf0 : 0.);
3163 if(phi >
M_PI) snf0 = - snf0;
3166 Hep3Vector ip(0, 0, 0);
3170 double phi_ip = work.
phi0();
3171 if (fabs(phi - phi_ip) >
M_PI) {
3172 if (phi > phi_ip) phi -= 2 *
M_PI;
3173 else phi_ip -= 2 *
M_PI;
3176 double l = fabs(
radius() * (phi - phi_ip) * sqrt(1 +
t *
t));
3177 double pmag( sqrt( 1.0 +
t*
t ) /
kappa());
3178 double mass_over_p( mass_ / pmag );
3179 double beta( 1.0 / sqrt( 1.0 + mass_over_p * mass_over_p ) );
3180 tofest = l / ( 29.9792458 * beta );
3181 if(csmflag==1 &&
HitMdc.
wire().
y()>0.) tofest= -1. * tofest;
3184 const HepSymMatrix& ea =
H.Ea();
3185 const HepVector& v_a =
H.a();
3188 HepVector v_H(5, 0);
3189 v_H[0] = -csf0 * meas.x() - snf0 * meas.y();
3191 HepMatrix v_HT = v_H.T();
3193 double estim = (v_HT * v_a)[0];
3194 HepVector ea_v_H = ea * v_H;
3195 HepMatrix ea_v_HT = (ea_v_H).T();
3196 HepVector v_H_T_ea_v_H = v_HT * ea_v_H;
3198 HepSymMatrix eaNewL(5), eaNewR(5);
3199 HepVector aNewL(5), aNewR(5);
3210 double dmeas2[2] = { 0.1*ddl, 0.1*ddr };
3211 double er_dmeas2[2] = {0. , 0.};
3213 er_dmeas2[0] = 0.1*erddl;
3214 er_dmeas2[1] = 0.1*erddr;
3222 if ((
LR_==0 && lr != 1.0) ||
3223 (
LR_==1 && lr == -1.0)) {
3225 double er_dmeasL, dmeasL;
3227 dmeasL = (-1.0)*fabs(dmeas2[0]);
3228 er_dmeasL = er_dmeas2[0];
3234 double AL = 1 / ((v_H_T_ea_v_H)[0] + er_dmeasL*er_dmeasL);
3235 eaNewL.assign(ea - ea_v_H * AL * ea_v_HT);
3236 double RkL = 1 - (v_H_T_ea_v_H)[0] * AL;
3237 if(0. == RkL) RkL = 1.e-4;
3239 HepVector diffL = ea_v_H * AL * (dmeasL - estim);
3240 aNewL = v_a + diffL;
3241 double sigL = dmeasL -(v_HT * aNewL)[0];
3242 dchi2L = (sigL * sigL) / (RkL * er_dmeasL*er_dmeasL);
3245 if ((
LR_==0 && lr != -1.0) ||
3246 (
LR_==1 && lr == 1.0)) {
3248 double er_dmeasR, dmeasR;
3251 er_dmeasR = er_dmeas2[1];
3257 double AR = 1 / ((v_H_T_ea_v_H)[0] + er_dmeasR*er_dmeasR);
3258 eaNewR.assign(ea - ea_v_H * AR * ea_v_HT);
3259 double RkR = 1 - (v_H_T_ea_v_H)[0] * AR;
3260 if(0. == RkR) RkR = 1.e-4;
3262 HepVector diffR = ea_v_H * AR * (dmeasR - estim);
3263 aNewR = v_a + diffR;
3264 double sigR = dmeasR -(v_HT * aNewR)[0];
3265 dchi2R = (sigR*sigR) / (RkR * er_dmeasR*er_dmeasR);
3268 if (dchi2R < dchi2L){
3269 H.a(aNewR);
H.Ea(eaNewR);
3271 H.a(aNewL);
H.Ea(eaNewL);
3273 return ((dchi2R < dchi2L) ? dchi2R : dchi2L);
3282 sigma1=0.112784;
sigma2=0.229274; f=0.666;
3283 }
else if(driftDist<1.){
3284 sigma1=0.103123;
sigma2=0.269797; f=0.934;
3285 }
else if(driftDist<1.5){
3286 sigma1=0.08276;
sigma2=0.17493; f=0.89;
3287 }
else if(driftDist<2.){
3288 sigma1=0.070109;
sigma2=0.149859; f=0.89;
3289 }
else if(driftDist<2.5){
3290 sigma1=0.064453;
sigma2=0.130149; f=0.886;
3291 }
else if(driftDist<3.){
3292 sigma1=0.062383;
sigma2=0.138806; f=0.942;
3293 }
else if(driftDist<3.5){
3294 sigma1=0.061873;
sigma2=0.145696; f=0.946;
3295 }
else if(driftDist<4.){
3296 sigma1=0.061236;
sigma2=0.119584; f=0.891;
3297 }
else if(driftDist<4.5){
3298 sigma1=0.066292;
sigma2=0.148426; f=0.917;
3299 }
else if(driftDist<5.){
3300 sigma1=0.078074;
sigma2=0.188148; f=0.911;
3301 }
else if(driftDist<5.5){
3302 sigma1=0.088657;
sigma2=0.27548; f=0.838;
3304 sigma1=0.093089;
sigma2=0.115556; f=0.367;
3308 sigma1=0.112433;
sigma2=0.327548; f=0.645;
3309 }
else if(driftDist<1.){
3310 sigma1=0.096703;
sigma2=0.305206; f=0.897;
3311 }
else if(driftDist<1.5){
3312 sigma1=0.082518;
sigma2=0.248913; f= 0.934;
3313 }
else if(driftDist<2.){
3314 sigma1=0.072501;
sigma2=0.153868; f= 0.899;
3315 }
else if(driftDist<2.5){
3316 sigma1= 0.065535;
sigma2=0.14246; f=0.914;
3317 }
else if(driftDist<3.){
3318 sigma1=0.060497;
sigma2=0.126489; f=0.918;
3319 }
else if(driftDist<3.5){
3320 sigma1=0.057643;
sigma2= 0.112927; f=0.892;
3321 }
else if(driftDist<4.){
3322 sigma1=0.055266;
sigma2=0.094833; f=0.887;
3323 }
else if(driftDist<4.5){
3324 sigma1=0.056263;
sigma2=0.124419; f= 0.932;
3325 }
else if(driftDist<5.){
3326 sigma1=0.056599;
sigma2=0.124248; f=0.923;
3327 }
else if(driftDist<5.5){
3328 sigma1= 0.061377;
sigma2=0.146147; f=0.964;
3329 }
else if(driftDist<6.){
3330 sigma1=0.063978;
sigma2=0.150591; f=0.942;
3331 }
else if(driftDist<6.5){
3332 sigma1=0.072951;
sigma2=0.15685; f=0.913;
3333 }
else if(driftDist<7.){
3334 sigma1=0.085438;
sigma2=0.255109; f=0.931;
3335 }
else if(driftDist<7.5){
3336 sigma1=0.101635;
sigma2=0.315529; f=0.878;
3338 sigma1=0.149529;
sigma2=0.374697; f=0.89;
3341 double sigmax = sqrt(f*sigma1*sigma1+(1 - f)*
sigma2*
sigma2)*0.1;
double tan(const BesAngle a)
double sin(const BesAngle a)
double cos(const BesAngle a)
**********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
HepGeom::Transform3D HepTransform3D
********INTEGER modcns REAL m_C
double getAngleOfStereo() const
double getOuterROfAnodeCu2() const
double getInnerROfAnodeCu2() const
CgemGeoLayer * getCgemLayer(int i) const
virtual double getSigma(int layer, int xvFlag, int readoutMode, double angle, double Q, double T) const =0
virtual StatusCode fieldVector(const HepGeom::Point3D< double > &xyz, HepGeom::Vector3D< double > &fvec) const =0
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 double * erdist(void) const
const double * dist(void) const
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.
Description of a track class (<- Helix.cc)
~KalFitTrack(void)
destructor
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.
double chiSq_back(void) const
vector< KalFitHitMdc > & HitsMdc(void)
double chi2_next(KalmanFit::Helix &H, KalFitHitMdc &HitMdc, int csmflag)
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
double dPhi(HepPoint3D &hit) const
const HepPoint3D & center(void) const
returns position of helix center(z = 0.);
void ignoreErrorMatrix(void)
unsets error matrix. Error calculations will be ignored after this function call until an error matri...
const HepSymMatrix & Ea(void) const
returns error matrix.
HepPoint3D x(double dPhi=0.) const
returns position after rotating angle dPhi in phi direction.
double bFieldZ(void) const
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.
const HepPoint3D & pivot(void) const
returns pivot position.
double getRecZ(void) const
int getlayerid(void) const
double getrecphi(void) const
const double getEntra(void) const