3#include "KalFitAlg/helix/Helix.h"
4#include "KalFitAlg/KalFitWire.h"
5#include "KalFitAlg/KalFitTrack.h"
6#include "KalFitAlg/KalFitMaterial.h"
7#include "KalFitAlg/KalFitElement.h"
8#include "KalFitAlg/KalFitCylinder.h"
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"
19#include "CgemGeomSvc/ICgemGeomSvc.h"
20#include "CgemGeomSvc/CgemGeomSvc.h"
21#include "CgemCalibFunSvc/CgemCalibFunSvc.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)
88:
Helix(pivot, a, Ea), type_(0), insist_(0), chiSq_(0),
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];
99 r0_ = fabs(center().perp() - fabs(radius()));
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;
137 double dPhi =
center().phi() - acos(cosPhi) -
phi0();
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();
385 double* Rad =
new double[nhit];
386 double* Ypos =
new double[nhit];
387 for(
unsigned i=0 ; i < nhit; i++ ){
391 Hep3Vector wire = (CLHEP::Hep3Vector)fwd -(CLHEP::Hep3Vector)bck;
394 Helix work = tracktest;
396 work.
pivot((fwd + bck) * .5);
398 / wire.z() * wire + bck;
401 Rad[ind] = tracktest.
x(0).perp();
409 for(
int j, k = nhit - 1; k >= 0; k = j){
411 for(
int i = 1; i <= k; i++)
412 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){
421 for(
int i = 1; i <= k; i++)
422 if(Rad[i - 1] < Rad[i]){
424 std::swap(Rad[i], Rad[j]);
425 std::swap(HitsMdc_[i], HitsMdc_[j]);
429 for(
int j, k = nhit - 1; k >= 0; k = j){
431 for(
int i = 1; i <= k; i++)
432 if(Ypos[i - 1] > Ypos[i]){
434 std::swap(Ypos[i], Ypos[j]);
435 std::swap(HitsMdc_[i], HitsMdc_[j]);
443 for(
int it=0; it<
HitsMdc().size()-1; it++){
444 if(HitsMdc_[it].wire().layer().layerId() == HitsMdc_[it+1].wire().layer().layerId())
446 if((
kappa()<0)&&(HitsMdc_[it].wire().localId() > HitsMdc_[it+1].wire().localId())){
447 std::swap(HitsMdc_[it], HitsMdc_[it+1]);
449 if((
kappa()>0)&&(HitsMdc_[it].wire().localId() < HitsMdc_[it+1].wire().localId())){
450 std::swap(HitsMdc_[it], HitsMdc_[it+1]);
459 unsigned int nhit = HitsMdc_.size();
461 for(
unsigned i=0 ; i < nhit; i++ )
462 Num[HitsMdc_[i].wire().layer().layerId()]++;
463 for(
unsigned i=0 ; i < nhit; i++ )
464 if (Num[HitsMdc_[i].wire().layer().layerId()]>2)
465 HitsMdc_[i].chi2(-2);
477 if (wire_ID<0 || wire_ID>6796){
478 std::cout <<
"KalFitTrack : wire_ID problem : " << wire_ID << std::endl;
488 double csf0 =
cos(phi);
489 double snf0 = (1. - csf0) * (1. + csf0);
490 snf0 = sqrt((snf0 > 0.) ? snf0 : 0.);
491 if(phi >
M_PI) snf0 = - snf0;
494 Hep3Vector ip(0, 0, 0);
498 double phi_ip = work.
phi0();
499 if (fabs(phi - phi_ip) >
M_PI) {
500 if (phi > phi_ip) phi -= 2 *
M_PI;
501 else phi_ip -= 2 *
M_PI;
504 double l = fabs(
radius() * (phi - phi_ip) * sqrt(1 +
t *
t));
505 double pmag( sqrt( 1.0 +
t*
t ) /
kappa());
506 double mass_over_p( mass_ / pmag );
507 double beta( 1.0 / sqrt( 1.0 + mass_over_p * mass_over_p ) );
508 tofest = l / ( 29.9792458 * beta );
509 if(csmflag==1 &&
HitMdc.
wire().
y()>0.) tofest= -1. * tofest;
512 const HepSymMatrix& ea =
Ea();
513 const HepVector& v_a =
a();
517 double dchi2R(99999999), dchi2L(99999999);
520 v_H[0] = -csf0 * meas.x() - snf0 * meas.y();
522 HepMatrix v_HT = v_H.T();
524 double estim = (v_HT * v_a)[0];
525 HepVector ea_v_H = ea * v_H;
526 HepMatrix ea_v_HT = (ea_v_H).T();
527 HepVector v_H_T_ea_v_H = v_HT * ea_v_H;
529 HepSymMatrix eaNew(5);
551 double dmeas2[2] = { 0.1*ddl, 0.1*ddr };
552 double er_dmeas2[2] = {0. , 0.};
554 er_dmeas2[0] = 0.1*erddl;
555 er_dmeas2[1] = 0.1*erddr;
565 double er_dmeasL, dmeasL;
567 dmeasL = (-1.0)*dmeas2[0];
568 er_dmeasL = er_dmeas2[0];
574 double AL = 1 / ((v_H_T_ea_v_H)[0] + er_dmeasL*er_dmeasL);
575 eaNew.assign(ea - ea_v_H * AL * ea_v_HT);
576 double RkL = 1 - (v_H_T_ea_v_H)[0] * AL;
577 if(0. == RkL) RkL = 1.e-4;
579 HepVector diffL = ea_v_H * AL * (dmeasL - estim);
581 double sigL = (dmeasL - (v_HT * aNew)[0]);
582 dchi2L = (sigL*sigL) / (RkL * er_dmeasL*er_dmeasL);
583 }
else if (lr == 1) {
586 double er_dmeasR, dmeasR;
589 er_dmeasR = er_dmeas2[1];
596 double AR = 1 / ((v_H_T_ea_v_H)[0] + er_dmeasR*er_dmeasR);
597 eaNew.assign(ea - ea_v_H * AR * ea_v_HT);
598 double RkR = 1 - (v_H_T_ea_v_H)[0] * AR;
599 if(0. == RkR) RkR = 1.e-4;
601 HepVector diffR = ea_v_H * AR * (dmeasR - estim);
603 double sigR = (dmeasR- (v_HT * aNew)[0]);
604 dchi2R = (sigR*sigR) / (RkR * er_dmeasR*er_dmeasR);
609 cout<<
"in smoother_Mdc: lr= "<<lr<<
" a: "<<v_a<<
" a_NEW: "<<aNew<<endl;
616 if ( !( aNew[2] && fabs(aNew[2]-
a()[2]) < 1.0 ) ) chge=0;
618 chiSq_back_ += dchi2R;
621 }
else if (lr == -1) {
622 chiSq_back_ += dchi2L;
636 Hep3Vector ip(0, 0, 0);
639 HepVector a_temp1 = helixNew1.a();
640 HepSymMatrix ea_temp1 = helixNew1.Ea();
646 KalFitTrack helixNew2(pivot_work, v_a, ea, 0, 0, 0);
648 HepVector a_temp2 = helixNew2.a();
649 HepSymMatrix ea_temp2 = helixNew2.Ea();
673 int layerid = (*HitMdc).wire().layer().layerId();
677 if (wire_ID<0 || wire_ID>6796){
678 std::cout <<
"KalFitTrack : wire_ID problem : " << wire_ID << std::endl;
687 double csf0 =
cos(phi);
688 double snf0 = (1. - csf0) * (1. + csf0);
689 snf0 = sqrt((snf0 > 0.) ? snf0 : 0.);
690 if(phi >
M_PI) snf0 = - snf0;
693 Hep3Vector ip(0, 0, 0);
697 double phi_ip = work.
phi0();
698 if (fabs(phi - phi_ip) >
M_PI) {
699 if (phi > phi_ip) phi -= 2 *
M_PI;
700 else phi_ip -= 2 *
M_PI;
703 double l = fabs(
radius() * (phi - phi_ip) * sqrt(1 +
t *
t));
704 double pmag( sqrt( 1.0 +
t*
t ) /
kappa());
705 double mass_over_p( mass_ / pmag );
706 double beta( 1.0 / sqrt( 1.0 + mass_over_p * mass_over_p ) );
707 tofest = l / ( 29.9792458 * beta );
708 if(csmflag==1 && (*HitMdc).wire().y()>0.) tofest= -1. * tofest;
711 const HepSymMatrix& ea =
Ea();
712 const HepVector& v_a =
a();
735 double dchi2R(99999999), dchi2L(99999999);
737 v_H[0] = -csf0 * meas.x() - snf0 * meas.y();
739 HepMatrix v_HT = v_H.T();
741 double estim = (v_HT * v_a)[0];
742 HepVector ea_v_H = ea * v_H;
743 HepMatrix ea_v_HT = (ea_v_H).T();
744 HepVector v_H_T_ea_v_H = v_HT * ea_v_H;
745 HepSymMatrix eaNew(5);
747 double time = (*HitMdc).tdc();
765 double dmeas2[2] = { 0.1*ddl, 0.1*ddr };
766 double er_dmeas2[2] = {0., 0.};
768 er_dmeas2[0] = 0.1*erddl;
769 er_dmeas2[1] = 0.1*erddr;
776 double er_dmeasL, dmeasL;
778 dmeasL = (-1.0)*dmeas2[0];
779 er_dmeasL = er_dmeas2[0];
781 dmeasL = (-1.0)*fabs((*HitMdc).dist()[0]);
782 er_dmeasL = (*HitMdc).erdist()[0];
788 double AL = 1 / ((v_H_T_ea_v_H)[0] + er_dmeasL*er_dmeasL);
789 eaNew.assign(ea - ea_v_H * AL * ea_v_HT);
790 double RkL = 1 - (v_H_T_ea_v_H)[0] * AL;
791 if(0. == RkL) RkL = 1.e-4;
793 HepVector diffL = ea_v_H * AL * (dmeasL - estim);
795 double sigL = (dmeasL - (v_HT * aNew)[0]);
796 dchi2L = (sigL*sigL) / (RkL * er_dmeasL*er_dmeasL);
797 }
else if (lr == 1) {
800 double er_dmeasR, dmeasR;
803 er_dmeasR = er_dmeas2[1];
805 dmeasR = fabs((*HitMdc).dist()[1]);
806 er_dmeasR = (*HitMdc).erdist()[1];
813 double AR = 1 / ((v_H_T_ea_v_H)[0] + er_dmeasR*er_dmeasR);
814 eaNew.assign(ea - ea_v_H * AR * ea_v_HT);
815 double RkR = 1 - (v_H_T_ea_v_H)[0] * AR;
816 if(0. == RkR) RkR = 1.e-4;
818 HepVector diffR = ea_v_H * AR * (dmeasR - estim);
820 double sigR = (dmeasR- (v_HT * aNew)[0]);
821 dchi2R = (sigR*sigR) / (RkR * er_dmeasR*er_dmeasR);
826 cout<<
"in smoother_Mdc: lr= "<<lr<<
" a: "<<v_a<<
" a_NEW: "<<aNew<<endl;
835 if (!(aNew[2] && fabs(aNew[2]-
a()[2]) < 1.0)) chge = 0;
837 chiSq_back_ += dchi2R;
842 }
else if (lr == -1) {
843 chiSq_back_ += dchi2L;
856 HepVector a_pre_fwd_temp=seg.
a_pre_fwd();
857 if( (a_pre_fwd_temp[1]-seg.
a_pre_bwd()[1]) > 3. *
M_PI /2.) a_pre_fwd_temp[1]-=
M_PI2;
858 if( (a_pre_fwd_temp[1]-seg.
a_pre_bwd()[1]) < -3. *
M_PI /2. ) a_pre_fwd_temp[1]+=
M_PI2;
863 if( (a_pre_filt_temp[1]-seg.
a_pre_bwd()[1]) > 3. *
M_PI /2. ) a_pre_filt_temp[1] -=
M_PI2;
864 if( (a_pre_filt_temp[1]-seg.
a_pre_bwd()[1]) < -3. *
M_PI /2.) a_pre_filt_temp[1] +=
M_PI2;
879 std::cout<<
"seg.Ea_pre_bwd().inverse(inv) ..."<<seg.
Ea_pre_bwd().inverse(inv)<<std::endl;
880 std::cout<<
"seg.Ea_pre_fwd().inverse(inv) ..."<<seg.
Ea_pre_fwd().inverse(inv)<<std::endl;
883 HepSymMatrix Ea_pre_comb = (seg.
Ea_pre_bwd().inverse(inv)+seg.
Ea_pre_fwd().inverse(inv)).inverse(inv);
888 std::cout<<
"Ea_pre_comb_ ... "<<Ea_pre_comb<<std::endl;
889 std::cout<<
"seg.a_pre_bwd()..."<<seg.
a_pre_bwd()<<std::endl;
890 std::cout<<
"seg.a_pre_fwd()..."<<seg.
a_pre_fwd()<<std::endl;
896 std::cout<<
"seg.Ea_filt_fwd()..."<<seg.
Ea_filt_fwd()<<std::endl;
897 std::cout<<
"seg.Ea_filt_fwd().inverse(inv)..."<<seg.
Ea_filt_fwd().inverse(inv)<<std::endl;
903 std::cout<<
"seg.Ea() is ..."<<seg.
Ea()<<std::endl;
904 std::cout<<
"seg.Ea_filt_fwd().inverse(inv)*seg.a_filt_fwd() ..."<<seg.
Ea_filt_fwd().inverse(inv)*seg.
a_filt_fwd()<<std::endl;
905 std::cout<<
"seg.Ea_pre_bwd().inverse(inv)*seg.a_pre_bwd() ... "<<seg.
Ea_pre_bwd().inverse(inv)*seg.
a_pre_bwd()<<std::endl;
921 std::cout<<
"the dd in smoother_Mdc is "<<dd
922 <<
" the (v_HT*a_pre_comb)[0] is "<<(v_HT*a_pre_comb)[0]<<std::endl;
927 std::cout<<
"method 1 ..."<<sqrt(seg.
a()[0]*seg.
a()[0]+seg.
a()[3]*seg.
a()[3])<<std::endl;
928 std::cout<<
"method 2 ..."<<fabs((v_HT*seg.
a())[0])<<std::endl;
935 HepVector a_temp1 = helixNew1.a();
936 HepSymMatrix ea_temp1 = helixNew1.Ea();
944 HepVector a_temp2 = helixNew2.a();
945 HepSymMatrix ea_temp2 = helixNew2.Ea();
970 int layerid = (*HitMdc).wire().layer().layerId();
974 if (wire_ID<0 || wire_ID>6796){
975 std::cout <<
"KalFitTrack : wire_ID problem : " << wire_ID << std::endl;
984 double csf0 =
cos(phi);
985 double snf0 = (1. - csf0) * (1. + csf0);
986 snf0 = sqrt((snf0 > 0.) ? snf0 : 0.);
987 if(phi >
M_PI) snf0 = - snf0;
990 Hep3Vector ip(0, 0, 0);
994 double phi_ip = work.
phi0();
995 if (fabs(phi - phi_ip) >
M_PI) {
996 if (phi > phi_ip) phi -= 2 *
M_PI;
997 else phi_ip -= 2 *
M_PI;
1000 double l = fabs(
radius() * (phi - phi_ip) * sqrt(1 +
t *
t));
1001 double pmag( sqrt( 1.0 +
t*
t ) /
kappa());
1002 double mass_over_p( mass_ / pmag );
1003 double beta( 1.0 / sqrt( 1.0 + mass_over_p * mass_over_p ) );
1004 tofest = l / ( 29.9792458 * beta );
1005 if(csmflag==1 && (*HitMdc).wire().y()>0.) tofest= -1. * tofest;
1008 const HepSymMatrix& ea =
Ea();
1009 const HepVector& v_a =
a();
1033 double dchi2R(99999999), dchi2L(99999999);
1034 HepVector v_H(5, 0);
1035 v_H[0] = -csf0 * meas.x() - snf0 * meas.y();
1037 HepMatrix v_HT = v_H.T();
1039 double estim = (v_HT * v_a)[0];
1040 HepVector ea_v_H = ea * v_H;
1041 HepMatrix ea_v_HT = (ea_v_H).T();
1042 HepVector v_H_T_ea_v_H = v_HT * ea_v_H;
1043 HepSymMatrix eaNew(5);
1045 double time = (*HitMdc).tdc();
1063 double dmeas2[2] = { 0.1*ddl, 0.1*ddr };
1064 double er_dmeas2[2] = {0., 0.};
1066 er_dmeas2[0] = 0.1*erddl;
1067 er_dmeas2[1] = 0.1*erddr;
1074 double er_dmeasL, dmeasL;
1076 dmeasL = (-1.0)*dmeas2[0];
1077 er_dmeasL = er_dmeas2[0];
1079 dmeasL = (-1.0)*fabs((*HitMdc).dist()[0]);
1080 er_dmeasL = (*HitMdc).erdist()[0];
1086 double AL = 1 / ((v_H_T_ea_v_H)[0] + er_dmeasL*er_dmeasL);
1087 eaNew.assign(ea - ea_v_H * AL * ea_v_HT);
1088 double RkL = 1 - (v_H_T_ea_v_H)[0] * AL;
1089 if(0. == RkL) RkL = 1.e-4;
1091 HepVector diffL = ea_v_H * AL * (dmeasL - estim);
1093 double sigL = (dmeasL - (v_HT * aNew)[0]);
1094 dchi2L = (sigL*sigL) / (RkL * er_dmeasL*er_dmeasL);
1095 }
else if (lr == 1) {
1098 double er_dmeasR, dmeasR;
1101 er_dmeasR = er_dmeas2[1];
1103 dmeasR = fabs((*HitMdc).dist()[1]);
1104 er_dmeasR = (*HitMdc).erdist()[1];
1111 double AR = 1 / ((v_H_T_ea_v_H)[0] + er_dmeasR*er_dmeasR);
1112 eaNew.assign(ea - ea_v_H * AR * ea_v_HT);
1113 double RkR = 1 - (v_H_T_ea_v_H)[0] * AR;
1114 if(0. == RkR) RkR = 1.e-4;
1116 HepVector diffR = ea_v_H * AR * (dmeasR - estim);
1118 double sigR = (dmeasR- (v_HT * aNew)[0]);
1119 dchi2R = (sigR*sigR) / (RkR * er_dmeasR*er_dmeasR);
1124 cout<<
"in smoother_Mdc: lr= "<<lr<<
" a: "<<v_a<<
" a_NEW: "<<aNew<<endl;
1126 double dchi2_loc(0);
1133 if (!(aNew[2] && fabs(aNew[2]-
a()[2]) < 1.0)) chge = 0;
1135 chiSq_back_ += dchi2R;
1140 }
else if (lr == -1) {
1141 chiSq_back_ += dchi2L;
1154 HepVector a_pre_fwd_temp=seg.
a_pre_fwd();
1155 if( (a_pre_fwd_temp[1]-seg.
a_pre_bwd()[1]) > 3. *
M_PI /2.) a_pre_fwd_temp[1]-=
M_PI2;
1156 if( (a_pre_fwd_temp[1]-seg.
a_pre_bwd()[1]) < -3. *
M_PI /2. ) a_pre_fwd_temp[1]+=
M_PI2;
1161 if( (a_pre_filt_temp[1]-seg.
a_pre_bwd()[1]) > 3. *
M_PI /2. ) a_pre_filt_temp[1] -=
M_PI2;
1162 if( (a_pre_filt_temp[1]-seg.
a_pre_bwd()[1]) < -3. *
M_PI /2.) a_pre_filt_temp[1] +=
M_PI2;
1177 std::cout<<
"seg.Ea_pre_bwd().inverse(inv) ..."<<seg.
Ea_pre_bwd().inverse(inv)<<std::endl;
1178 std::cout<<
"seg.Ea_pre_fwd().inverse(inv) ..."<<seg.
Ea_pre_fwd().inverse(inv)<<std::endl;
1181 HepSymMatrix Ea_pre_comb = (seg.
Ea_pre_bwd().inverse(inv)+seg.
Ea_pre_fwd().inverse(inv)).inverse(inv);
1186 std::cout<<
"Ea_pre_comb_ ... "<<Ea_pre_comb<<std::endl;
1187 std::cout<<
"seg.a_pre_bwd()..."<<seg.
a_pre_bwd()<<std::endl;
1188 std::cout<<
"seg.a_pre_fwd()..."<<seg.
a_pre_fwd()<<std::endl;
1195 std::cout<<
"seg.Ea_filt_fwd()..."<<seg.
Ea_filt_fwd()<<std::endl;
1196 std::cout<<
"seg.Ea_filt_fwd().inverse(inv)..."<<seg.
Ea_filt_fwd().inverse(inv)<<std::endl;
1202 std::cout<<
"seg.Ea() is ..."<<seg.
Ea()<<std::endl;
1203 std::cout<<
"seg.Ea_filt_fwd().inverse(inv)*seg.a_filt_fwd() ..."<<seg.
Ea_filt_fwd().inverse(inv)*seg.
a_filt_fwd()<<std::endl;
1204 std::cout<<
"seg.Ea_pre_bwd().inverse(inv)*seg.a_pre_bwd() ... "<<seg.
Ea_pre_bwd().inverse(inv)*seg.
a_pre_bwd()<<std::endl;
1220 std::cout<<
"the dd in smoother_Mdc is "<<dd
1221 <<
" the (v_HT*a_pre_comb)[0] is "<<(v_HT*a_pre_comb)[0]<<std::endl;
1226 std::cout<<
"method 1 ..."<<sqrt(seg.
a()[0]*seg.
a()[0]+seg.
a()[3]*seg.
a()[3])<<std::endl;
1227 std::cout<<
"method 2 ..."<<fabs((v_HT*seg.
a())[0])<<std::endl;
1233 helixNew1.pivot(ip);
1234 HepVector a_temp1 = helixNew1.a();
1235 HepSymMatrix ea_temp1 = helixNew1.Ea();
1242 helixNew2.pivot(ip);
1243 HepVector a_temp2 = helixNew2.a();
1244 HepSymMatrix ea_temp2 = helixNew2.Ea();
1260 double v_d,
double m_V)
1262 HepMatrix m_HT = m_H.T();
1269 HepMatrix m_XT = m_X.T();
1270 HepMatrix
m_C = m_X *
Ea() * m_XT;
1272 HepVector m_K = 1 / (m_V + (m_HT *
m_C * m_H)[0]) * m_H;
1273 HepVector v_a =
a();
1274 HepSymMatrix ea =
Ea();
1275 HepMatrix mXTmK = m_XT * m_K;
1276 double v_r = v_m - v_d - (m_HT * v_x)[0];
1277 v_a += ea * mXTmK * v_r;
1279 ea.assign(ea - ea * mXTmK * m_HT * m_X * ea);
1283 HepMatrix mCmK =
m_C * m_K;
1285 m_C -= mCmK * m_HT *
m_C;
1286 v_r = v_m - v_d - (m_HT * v_x)[0];
1287 double m_R = m_V - (m_HT *
m_C * m_H)[0];
1288 double chiSq = v_r * v_r / m_R;
1318 double light_speed( 29.9792458 );
1320 double pmag( sqrt( 1.0 +
t*
t ) /
kappa());
1322 double mass_over_p( mass_ / pmag );
1323 double beta( 1.0 / sqrt( 1.0 + mass_over_p * mass_over_p ) );
1324 tof_ += path / ( light_speed * beta );
1329 double massk_over_p( MASS[3] / p_kaon_ );
1330 double beta_kaon( 1.0 / sqrt( 1.0 + massk_over_p * massk_over_p ) );
1331 tof_kaon_ += path / (light_speed * beta_kaon);
1334 double massp_over_p( MASS[4] / p_proton_ );
1335 double beta_proton( 1.0 / sqrt( 1.0 + massp_over_p * massp_over_p ) );
1336 tof_proton_ += path / (light_speed * beta_proton);
1347 double phi0 =
a()[1];
1350 double csf0 =
cos(phi);
1351 double snf0 = (1. - csf0) * (1. + csf0);
1352 snf0 = sqrt((snf0 > 0.) ? snf0 : 0.);
1353 if(phi >
M_PI) snf0 = - snf0;
1374 double ALPHA_loc = 10000./2.99792458/Bz;
1375 return ALPHA_loc /
a()[2];
1389 double xnp(nextPivot.x()), ynp(nextPivot.y()), znp(nextPivot.z());
1390 HepSymMatrix Ea_now =
Ea();
1392 double xp(piv.x()), yp(piv.y()), zp(piv.z());
1394 double phi0 =
a()[1];
1397 double tanl =
a()[4];
1403 double rdr =
dr + m_rad;
1405 double csf0 =
cos(phi);
1406 double snf0 = (1. - csf0) * (1. + csf0);
1407 snf0 = sqrt((snf0 > 0.) ? snf0 : 0.);
1408 if(phi >
M_PI) snf0 = - snf0;
1410 double xc = xp + rdr * csf0;
1411 double yc = yp + rdr * snf0;
1412 double csf = (xc - xnp) / m_rad;
1413 double snf = (yc - ynp) / m_rad;
1414 double anrm = sqrt(csf * csf + snf * snf);
1417 phi = atan2(snf, csf);
1420 double drp = (xp +
dr * csf0 + m_rad * (csf0 - csf) - xnp)
1422 + (yp +
dr * snf0 + m_rad * (snf0 - snf) - ynp) * snf;
1423 double dzp = zp +
dz - m_rad *
tanl * phid - znp;
1435 Hep3Vector x1(xp +
dr*csf0, yp +
dr*snf0, zp +
dz);
1436 double csf0p =
cos(ap[1]);
1437 double snf0p = (1. - csf0p) * (1. + csf0p);
1438 snf0p = sqrt((snf0p > 0.) ? snf0p : 0.);
1439 if(ap[1] >
M_PI) snf0p = - snf0p;
1441 Hep3Vector x2(xnp + drp*csf0p,
1444 Hep3Vector dist((x1 - x2).
x()/100.0,
1445 (x1 - x2).y()/100.0,
1446 (x1 - x2).z()/100.0);
1448 (x1.y() + x2.y())/2,
1449 (x1.z() + x2.z())/2);
1452 field = 1000.*field;
1453 Hep3Vector dB(field.x(),
1457 double akappa(fabs(
kappa));
1458 double sign =
kappa/akappa;
1460 dp = 0.299792458 * sign * dB.cross(dist);
1462 dhp[0] = -akappa*(dp[0]*csf0p+dp[1]*snf0p);
1463 dhp[1] =
kappa*akappa*(dp[0]*snf0p-dp[1]*csf0p);
1464 dhp[2] = dp[2]*akappa+dhp[1]*
tanl/
kappa;
1473 Ea_now.assign(m_del * Ea_now * m_del.T());
1488 double th = 90.0 - 180.0*M_1_PI*atan( tl );
1506 double xnp(nextPivot.x()), ynp(nextPivot.y()), znp(nextPivot.z());
1508 HepSymMatrix Ea_now =
Ea();
1510 double xp(piv.x()), yp(piv.y()), zp(piv.z());
1513 double phi0 =
a()[1];
1516 double tanl =
a()[4];
1521 double rdr =
dr + m_rad;
1523 double csf0 =
cos(phi);
1524 double snf0 = (1. - csf0) * (1. + csf0);
1525 snf0 = sqrt((snf0 > 0.) ? snf0 : 0.);
1526 if(phi >
M_PI) snf0 = - snf0;
1528 double xc = xp + rdr * csf0;
1529 double yc = yp + rdr * snf0;
1530 double csf = (xc - xnp) / m_rad;
1531 double snf = (yc - ynp) / m_rad;
1532 double anrm = sqrt(csf * csf + snf * snf);
1535 phi = atan2(snf, csf);
1538 double drp = (xp +
dr * csf0 + m_rad * (csf0 - csf) - xnp)
1540 + (yp +
dr * snf0 + m_rad * (snf0 - snf) - ynp) * snf;
1541 double dzp = zp +
dz - m_rad *
tanl * phid - znp;
1555 Hep3Vector x1(xp +
dr*csf0, yp +
dr*snf0, zp +
dz);
1557 double csf0p =
cos(ap[1]);
1558 double snf0p = (1. - csf0p) * (1. + csf0p);
1559 snf0p = sqrt((snf0p > 0.) ? snf0p : 0.);
1560 if(ap[1] >
M_PI) snf0p = - snf0p;
1562 Hep3Vector x2(xnp + drp*csf0p,
1566 Hep3Vector dist((x1 - x2).
x()/100.0,
1567 (x1 - x2).y()/100.0,
1568 (x1 - x2).z()/100.0);
1571 (x1.y() + x2.y())/2,
1572 (x1.z() + x2.z())/2);
1576 field = 1000.*field;
1579 Hep3Vector dB(field.x(),
1588 double akappa(fabs(
kappa));
1589 double sign =
kappa/akappa;
1591 dp = 0.299792458 * sign * dB.cross(dist);
1596 dhp[0] = -akappa*(dp[0]*csf0p+dp[1]*snf0p);
1597 dhp[1] =
kappa*akappa*(dp[0]*snf0p-dp[1]*csf0p);
1598 dhp[2] = dp[2]*akappa+dhp[1]*
tanl/
kappa;
1610 Ea_now.assign(m_del * Ea_now * m_del.T());
1620 double tanl_0(tracktest.
a()[4]);
1621 double phi0_0(tracktest.
a()[1]);
1622 double radius_0(tracktest.
radius());
1623 tracktest.
pivot(newPivot);
1625 double phi0_1 = tracktest.
a()[1];
1626 if (fabs(phi0_1 - phi0_0) >
M_PI) {
1627 if (phi0_1 > phi0_0) phi0_1 -= 2 *
M_PI;
1628 else phi0_0 -= 2 *
M_PI;
1630 if(phi0_1 == phi0_0) phi0_1 = phi0_0 + 1.e-10;
1631 pathl = fabs(radius_0 * (phi0_1 - phi0_0)
1632 * sqrt(1 + tanl_0 * tanl_0));
1742 Hep3Vector zvector( 0., 0., z_c-rho*dphi*tanl);
1744 double xcio, ycio, phip;
1746 double delrin = 2.0;
1747 if( m_zf-delrin > zvector.z() ){
1748 phip = z_c - m_zb + delrin;
1749 phip = phip/( rho*tanl );
1751 xcio = x_c - rho*cos( phip );
1752 ycio = y_c - rho*sin( phip );
1753 cell_IO[i].setX( xcio );
1754 cell_IO[i].setY( ycio );
1755 cell_IO[i].setZ( m_zb+delrin );
1758 else if( m_zb+delrin < zvector.z() ){
1759 phip = z_c - m_zf-delrin;
1760 phip = phip/( rho*tanl );
1762 xcio = x_c - rho*cos( phip );
1763 ycio = y_c - rho*sin( phip );
1764 cell_IO[i].setX( xcio );
1765 cell_IO[i].setY( ycio );
1766 cell_IO[i].setZ( m_zf-delrin );
1770 cell_IO[i] = iocand;
1771 cell_IO[i] += zvector;
1774 if( i == 0 ) phi_in = dphi;
1776// path length estimation
1778Hep3Vector cl = cell_IO[1] - cell_IO[0];
1780cout<<"cell_IO[0] "<<cell_IO[0]<<" cell_IO[1] "<<cell_IO[1]<<" cl "<<cl<<endl;
1786double ch_ltrk_rp = 0;
1787ch_dphi = cl.perp()*0.5/(ALPHA_loc*pt);
1788ch_dphi = 2.0 * asin( ch_dphi );
1789ch_ltrk_rp = ch_dphi*ALPHA_loc*pt;
1791cout<<"ch_dphi "<<ch_dphi<<" ch_ltrk_rp "<<ch_ltrk_rp<<" cl.z "<<cl.z()<<endl;
1793ch_ltrk = sqrt( ch_ltrk_rp*ch_ltrk_rp + cl.z()*cl.z() );
1794ch_theta = cl.theta();
1796if( ch_theta < theta*0.85 || 1.15*theta < ch_theta)
1797 ch_ltrk *= -1; /// miss calculation
1799if( epflag[0] == 1 || epflag [1] == 1 )
1800 ch_ltrk *= -1; /// invalid resion for dE/dx or outside of Mdc
1802 mom_[layer] = momentum( phi_in );
1803 PathL_[layer] = ch_ltrk;
1805 cout<<"ch_ltrk "<<ch_ltrk<<endl;
1815 j = (int) pow(2.,i);
1818 }
else if (i < 50) {
1819 j = (int) pow(2.,(i-31));
1857 int wire_ID = Wire.
geoID();
1862 if (wire_ID<0 || wire_ID>6796){
1863 std::cout <<
" KalFitTrack: wire_ID problem : " << wire_ID
1867 int flag_ster = Wire.
stereo();
1872 double csf0 =
cos(phi);
1873 double snf0 = (1. - csf0) * (1. + csf0);
1874 snf0 = sqrt((snf0 > 0.) ? snf0 : 0.);
1875 if(phi >
M_PI) snf0 = - snf0;
1883 Hep3Vector ip(0, 0, 0);
1885 phi_ip = work.
phi0();
1886 if (fabs(phi - phi_ip) >
M_PI) {
1887 if (phi > phi_ip) phi -= 2 *
M_PI;
1888 else phi_ip -= 2 *
M_PI;
1890 dphi = phi - phi_ip;
1891 double l = fabs(
radius() * dphi * sqrt(1 +
t *
t));
1892 double pmag( sqrt( 1.0 +
t*
t ) /
kappa());
1893 double mass_over_p( mass_ / pmag );
1894 double beta( 1.0 / sqrt( 1.0 + mass_over_p * mass_over_p ) );
1895 tofest = l / ( 29.9792458 * beta );
1896 if(csmflag==1 &&
HitMdc.
wire().
y()>0.) tofest= -1. * tofest;
1899 const HepSymMatrix& ea =
Ea();
1900 const HepVector& v_a =
a();
1901 double dchi2R(99999999), dchi2L(99999999);
1903 HepVector v_H(5, 0);
1904 v_H[0] = -csf0 * meas.x() - snf0 * meas.y();
1906 HepMatrix v_HT = v_H.T();
1908 double estim = (v_HT * v_a)[0];
1911 HepVector ea_v_H = ea * v_H;
1912 HepMatrix ea_v_HT = (ea_v_H).T();
1913 HepVector v_H_T_ea_v_H = v_HT * ea_v_H;
1915 HepSymMatrix eaNewL(5), eaNewR(5);
1916 HepVector aNewL(5), aNewR(5);
1925 std::cout<<
"drifttime in update_hits() for ananlysis is "<<drifttime<<std::endl;
1926 std::cout<<
"ddl in update_hits() for ananlysis is "<<ddl<<std::endl;
1927 std::cout<<
"ddr in update_hits() for ananlysis is "<<ddr<<std::endl;
1928 std::cout<<
"erddl in update_hits() for ananlysis is "<<erddl<<std::endl;
1929 std::cout<<
"erddr in update_hits() for ananlysis is "<<erddr<<std::endl;
1933 double dmeas2[2] = { 0.1*ddl, 0.1*ddr };
1934 double er_dmeas2[2] = {0.,0.};
1936 er_dmeas2[0] = 0.1*erddl;
1937 er_dmeas2[1] = 0.1*erddr;
1946 if ((
LR_==0 && lr != 1.0) ||
1947 (
LR_==1 && lr == -1.0)) {
1948 double er_dmeasL, dmeasL;
1950 dmeasL = (-1.0)*fabs(dmeas2[0]);
1951 er_dmeasL = er_dmeas2[0];
1957 double AL = 1 / ((v_H_T_ea_v_H)[0] + er_dmeasL*er_dmeasL);
1958 eaNewL.assign(ea - ea_v_H * AL * ea_v_HT);
1959 double RkL = 1 - (v_H_T_ea_v_H)[0] * AL;
1961 std::cout<<
" ea_v_H * AL * ea_v_HT is: "<<ea_v_H * AL * ea_v_HT<<std::endl;
1962 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;
1963 std::cout<<
" AL is: "<<AL<<
" (v_H_T_ea_v_H)[0] * AL is: "<<(v_H_T_ea_v_H)[0]*AL<<std::endl;
1966 if(0. == RkL) RkL = 1.e-4;
1968 HepVector diffL = ea_v_H * AL * (dmeasL - estim);
1969 aNewL = v_a + diffL;
1970 double sigL = dmeasL -(v_HT * aNewL)[0];
1971 dtracknew = (v_HT * aNewL)[0];
1972 dchi2L = (sigL * sigL)/(RkL * er_dmeasL*er_dmeasL);
1975 std::cout<<
" fwd_filter : in left hypothesis dchi2L is "<<dchi2L<<std::endl;
1979 if ((
LR_==0 && lr != -1.0) ||
1980 (
LR_==1 && lr == 1.0)) {
1981 double er_dmeasR, dmeasR;
1984 er_dmeasR = er_dmeas2[1];
1990 double AR = 1 / ((v_H_T_ea_v_H)[0] + er_dmeasR*er_dmeasR);
1991 eaNewR.assign(ea - ea_v_H * AR * ea_v_HT);
1992 double RkR = 1 - (v_H_T_ea_v_H)[0] * AR;
1995 std::cout<<
" ea_v_H * AR * ea_v_HT is: "<<ea_v_H * AR * ea_v_HT<<std::endl;
1996 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;
1997 std::cout<<
" AR is: "<<AR<<
" (v_H_T_ea_v_H)[0] * AR is: "<<(v_H_T_ea_v_H)[0]*AR<<std::endl;
2000 if(0. == RkR) RkR = 1.e-4;
2001 HepVector diffR = ea_v_H * AR * (dmeasR - estim);
2002 aNewR = v_a + diffR;
2003 double sigR = dmeasR -(v_HT * aNewR)[0];
2004 dtracknew = (v_HT * aNewR)[0];
2005 dchi2R = (sigR*sigR)/(RkR * er_dmeasR*er_dmeasR);
2007 std::cout<<
" fwd_filter : in right hypothesis dchi2R is "<<dchi2R<<std::endl;
2011 double dchi2_loc(0);
2012 if (fabs(dchi2R-dchi2L)<10. && inext>0) {
2015 double chi2_fromR(
chi2_next(H_fromR, HitMdc_next, csmflag));
2017 double chi2_fromL(
chi2_next(H_fromL, HitMdc_next, csmflag));
2019 std::cout <<
" chi2_fromL = " << chi2_fromL
2020 <<
", chi2_fromR = " << chi2_fromR << std::endl;
2022 if (fabs(chi2_fromR-chi2_fromL)<10.){
2024 if (inext+1<HitsMdc_.size())
2025 for(
int k=inext+1 ; k < HitsMdc_.size(); k++ )
2026 if (!(HitsMdc_[k].chi2()<0)) {
2033 double chi2_fromR2(
chi2_next(H_fromR, HitMdc_next2, csmflag));
2034 double chi2_fromL2(
chi2_next(H_fromL, HitMdc_next2, csmflag));
2036 std::cout <<
" chi2_fromL2 = " << chi2_fromL2
2037 <<
", chi2_fromR2 = " << chi2_fromR2 << std::endl;
2039 if (fabs(dchi2R+chi2_fromR+chi2_fromR2-(dchi2L+chi2_fromL+chi2_fromL2))<2) {
2040 if (chi2_fromR2<chi2_fromL2)
2049 if (dchi2R+chi2_fromR < dchi2L+chi2_fromL){
2052 std::cout <<
" choose right..." << std::endl;
2057 std::cout <<
" choose left..." << std::endl;
2065 if (((
LR_==0 && dchi2R < dchi2L && lr != -1) ||
2066 (
LR_==1 && lr == 1)) &&
2067 fabs(aNewR[2]-
a()[2]) < 1000. && aNewR[2]) {
2070 if (flag_ster) nster_++;
2076 if (l_mass_ == lead_){
2081 }
else if (((
LR_==0 && dchi2L <= dchi2R && lr != 1) ||
2082 (
LR_==1 && lr == -1)) &&
2083 fabs(aNewL[2]-
a()[2]) < 1000. && aNewL[2]){
2086 if (flag_ster) nster_++;
2092 if (l_mass_ == lead_){
2100 if (dchi2_loc > dchi2_max_) {
2101 dchi2_max_ = dchi2_loc ;
2102 r_max_ =
pivot().perp();
2104 dchi2out = dchi2_loc;
2119 int layerid = (*HitMdc).wire().layer().layerId();
2124 std::cout<<
"in update_hits(kalFitHelixSeg,...) : the layerid ="<<layerid<<std::endl;
2125 std::cout<<
" update_hits: lr= " << lr <<std::endl;
2129 int wire_ID = Wire.
geoID();
2131 if (wire_ID<0 || wire_ID>6796){
2132 std::cout <<
" KalFitTrack: wire_ID problem : " << wire_ID
2136 int flag_ster = Wire.
stereo();
2141 double csf0 =
cos(phi);
2142 double snf0 = (1. - csf0) * (1. + csf0);
2143 snf0 = sqrt((snf0 > 0.) ? snf0 : 0.);
2144 if(phi >
M_PI) snf0 = - snf0;
2152 Hep3Vector ip(0, 0, 0);
2154 phi_ip = work.
phi0();
2155 if (fabs(phi - phi_ip) >
M_PI) {
2156 if (phi > phi_ip) phi -= 2 *
M_PI;
2157 else phi_ip -= 2 *
M_PI;
2159 dphi = phi - phi_ip;
2161 double l = fabs(
radius() * dphi * sqrt(1 +
t *
t));
2162 double pmag( sqrt( 1.0 +
t*
t ) /
kappa());
2163 double mass_over_p( mass_ / pmag );
2164 double beta( 1.0 / sqrt( 1.0 + mass_over_p * mass_over_p ) );
2165 tofest = l / ( 29.9792458 * beta );
2166 if(csmflag==1 && (*HitMdc).wire().y()>0.) tofest= -1. * tofest;
2169 const HepSymMatrix& ea =
Ea();
2174 const HepVector& v_a =
a();
2198 double dchi2R(99999999), dchi2L(99999999);
2200 HepVector v_H(5, 0);
2201 v_H[0] = -csf0 * meas.x() - snf0 * meas.y();
2203 HepMatrix v_HT = v_H.T();
2205 double estim = (v_HT * v_a)[0];
2206 HepVector ea_v_H = ea * v_H;
2207 HepMatrix ea_v_HT = (ea_v_H).T();
2208 HepVector v_H_T_ea_v_H = v_HT * ea_v_H;
2210 HepSymMatrix eaNewL(5), eaNewR(5);
2211 HepVector aNewL(5), aNewR(5);
2213 cout<<
"phi "<<phi<<
" snf0 "<<snf0<<
" csf0 "<<csf0<<endl
2214 <<
" meas: "<<meas <<endl;
2215 cout<<
"the related matrix:"<<endl;
2216 cout<<
"v_H "<<v_H<<endl;
2217 cout<<
"v_a "<<v_a<<endl;
2218 cout<<
"ea "<<ea<<endl;
2219 cout<<
"v_H_T_ea_v_H "<<v_H_T_ea_v_H<<endl;
2220 cout<<
"LR_= "<<
LR_ <<
"lr= " << lr <<endl;
2223 double time = (*HitMdc).tdc();
2237 std::cout<<
"the pure drift time is "<<drifttime<<std::endl;
2238 std::cout<<
"the drift dist left hypothesis is "<<ddl<<std::endl;
2239 std::cout<<
"the drift dist right hypothesis is "<<ddr<<std::endl;
2240 std::cout<<
"the error sigma left hypothesis is "<<erddl<<std::endl;
2241 std::cout<<
"the error sigma right hypothesis is "<<erddr<<std::endl;
2243 double dmeas2[2] = { 0.1*ddl , 0.1*ddr };
2244 double er_dmeas2[2] = {0. , 0.} ;
2247 er_dmeas2[0] = 0.1*erddl;
2248 er_dmeas2[1] = 0.1*erddr;
2257 if ((
LR_==0 && lr != 1.0) ||
2258 (
LR_==1 && lr == -1.0)) {
2260 double er_dmeasL, dmeasL;
2262 dmeasL = (-1.0)*fabs(dmeas2[0]);
2263 er_dmeasL = er_dmeas2[0];
2265 dmeasL = (-1.0)*fabs((*HitMdc).dist()[0]);
2266 er_dmeasL = (*HitMdc).erdist()[0];
2269 double AL = 1 / ((v_H_T_ea_v_H)[0] + er_dmeasL*er_dmeasL);
2270 eaNewL.assign(ea - ea_v_H * AL * ea_v_HT);
2271 double RkL = 1 - (v_H_T_ea_v_H)[0] * AL;
2272 if(0. == RkL) RkL = 1.e-4;
2274 HepVector diffL = ea_v_H * AL * (dmeasL - estim);
2276 aNewL = v_a + diffL;
2277 double sigL = dmeasL -(v_HT * aNewL)[0];
2278 dchi2L = (sigL * sigL) / (RkL * er_dmeasL*er_dmeasL);
2281 if ((
LR_==0 && lr != -1.0) ||
2282 (
LR_==1 && lr == 1.0)) {
2284 double er_dmeasR, dmeasR;
2287 er_dmeasR = er_dmeas2[1];
2289 dmeasR = fabs((*HitMdc).dist()[1]);
2290 er_dmeasR = (*HitMdc).erdist()[1];
2293 double AR = 1 / ((v_H_T_ea_v_H)[0] + er_dmeasR*er_dmeasR);
2294 eaNewR.assign(ea - ea_v_H * AR * ea_v_HT);
2295 double RkR = 1 - (v_H_T_ea_v_H)[0] * AR;
2296 if(0. == RkR) RkR = 1.e-4;
2298 HepVector diffR = ea_v_H * AR * (dmeasR - estim);
2300 aNewR = v_a + diffR;
2301 double sigR = dmeasR -(v_HT * aNewR)[0];
2302 dchi2R = (sigR*sigR) / (RkR * er_dmeasR*er_dmeasR);
2306 double dchi2_loc(0);
2309 cout<<
" track::update_hits......"<<endl;
2310 std::cout <<
" dchi2R = " << dchi2R <<
", dchi2L = " << dchi2L
2311 <<
" estimate = "<<estim<< std::endl;
2312 std::cout <<
" dmeasR = " << dmeas2[1]
2313 <<
", dmeasL = " << (-1.0)*fabs(dmeas2[0]) <<
", check HitMdc.ddl = "
2314 << (*HitMdc).dist()[0] << std::endl;
2315 std::cout<<
"dchi2L : "<<dchi2L<<
" ,dchi2R: "<<dchi2R<<std::endl;
2319 if (fabs(dchi2R-dchi2L)<10. && inext>0) {
2324 double chi2_fromR(
chi2_next(H_fromR, HitMdc_next,csmflag));
2328 double chi2_fromL(
chi2_next(H_fromL, HitMdc_next,csmflag));
2331 std::cout <<
" chi2_fromL = " << chi2_fromL
2332 <<
", chi2_fromR = " << chi2_fromR << std::endl;
2334 if (fabs(chi2_fromR-chi2_fromL)<10.){
2336 if (inext+1<HitsMdc_.size())
2337 for(
int k=inext+1 ; k < HitsMdc_.size(); k++ )
2338 if (!(HitsMdc_[k].chi2()<0)) {
2347 double chi2_fromR2(
chi2_next(H_fromR, HitMdc_next2, csmflag));
2348 double chi2_fromL2(
chi2_next(H_fromL, HitMdc_next2, csmflag));
2350 std::cout <<
" chi2_fromL2 = " << chi2_fromL2
2351 <<
", chi2_fromR2 = " << chi2_fromR2 << std::endl;
2353 if (fabs(dchi2R+chi2_fromR+chi2_fromR2-(dchi2L+chi2_fromL+chi2_fromL2))<2) {
2354 if (chi2_fromR2<chi2_fromL2)
2363 if (dchi2R+chi2_fromR < dchi2L+chi2_fromL){
2366 std::cout <<
" choose right..." << std::endl;
2371 std::cout <<
" choose left..." << std::endl;
2380 if (((
LR_==0 && dchi2R < dchi2L && lr != -1) ||
2381 (
LR_==1 && lr == 1)) &&
2382 fabs(aNewR[2]-
a()[2]) < 1000. && aNewR[2]) {
2385 if (flag_ster) nster_++;
2410 if (l_mass_ == lead_){
2414 update_bit((*HitMdc).wire().layer().layerId());
2416 }
else if (((
LR_==0 && dchi2L <= dchi2R && lr != 1) ||
2417 (
LR_==1 && lr == -1)) &&
2418 fabs(aNewL[2]-
a()[2]) < 1000. && aNewL[2]){
2421 if (flag_ster) nster_++;
2445 if (l_mass_ == lead_){
2449 update_bit((*HitMdc).wire().layer().layerId());
2454 if (dchi2_loc > dchi2_max_) {
2455 dchi2_max_ = dchi2_loc ;
2456 r_max_ =
pivot().perp();
2458 dchi2out = dchi2_loc;
2473 int layerid = (*HitMdc).wire().layer().layerId();
2477 std::cout<<
"in update_hits(kalFitHelixSeg,...) : the layerid ="<<layerid<<std::endl;
2478 std::cout<<
" update_hits: lr= " << lr <<std::endl;
2482 int wire_ID = Wire.
geoID();
2484 if (wire_ID<0 || wire_ID>6796){
2485 std::cout <<
" KalFitTrack: wire_ID problem : " << wire_ID
2489 int flag_ster = Wire.
stereo();
2494 double csf0 =
cos(phi);
2495 double snf0 = (1. - csf0) * (1. + csf0);
2496 snf0 = sqrt((snf0 > 0.) ? snf0 : 0.);
2497 if(phi >
M_PI) snf0 = - snf0;
2505 Hep3Vector ip(0, 0, 0);
2507 phi_ip = work.
phi0();
2508 if (fabs(phi - phi_ip) >
M_PI) {
2509 if (phi > phi_ip) phi -= 2 *
M_PI;
2510 else phi_ip -= 2 *
M_PI;
2512 dphi = phi - phi_ip;
2514 double l = fabs(
radius() * dphi * sqrt(1 +
t *
t));
2515 double pmag( sqrt( 1.0 +
t*
t ) /
kappa());
2516 double mass_over_p( mass_ / pmag );
2517 double beta( 1.0 / sqrt( 1.0 + mass_over_p * mass_over_p ) );
2518 tofest = l / ( 29.9792458 * beta );
2519 if(csmflag==1 && (*HitMdc).wire().y()>0.) tofest= -1. * tofest;
2522 const HepSymMatrix& ea =
Ea();
2527 const HepVector& v_a =
a();
2552 double dchi2R(99999999), dchi2L(99999999);
2554 HepVector v_H(5, 0);
2555 v_H[0] = -csf0 * meas.x() - snf0 * meas.y();
2557 HepMatrix v_HT = v_H.T();
2559 double estim = (v_HT * v_a)[0];
2560 HepVector ea_v_H = ea * v_H;
2561 HepMatrix ea_v_HT = (ea_v_H).T();
2562 HepVector v_H_T_ea_v_H = v_HT * ea_v_H;
2564 HepSymMatrix eaNewL(5), eaNewR(5);
2565 HepVector aNewL(5), aNewR(5);
2567 cout<<
"phi "<<phi<<
" snf0 "<<snf0<<
" csf0 "<<csf0<<endl
2568 <<
" meas: "<<meas <<endl;
2569 cout<<
"the related matrix:"<<endl;
2570 cout<<
"v_H "<<v_H<<endl;
2571 cout<<
"v_a "<<v_a<<endl;
2572 cout<<
"ea "<<ea<<endl;
2573 cout<<
"v_H_T_ea_v_H "<<v_H_T_ea_v_H<<endl;
2574 cout<<
"LR_= "<<
LR_ <<
"lr= " << lr <<endl;
2577 double time = (*HitMdc).tdc();
2591 std::cout<<
"the pure drift time is "<<drifttime<<std::endl;
2592 std::cout<<
"the drift dist left hypothesis is "<<ddl<<std::endl;
2593 std::cout<<
"the drift dist right hypothesis is "<<ddr<<std::endl;
2594 std::cout<<
"the error sigma left hypothesis is "<<erddl<<std::endl;
2595 std::cout<<
"the error sigma right hypothesis is "<<erddr<<std::endl;
2597 double dmeas2[2] = { 0.1*ddl , 0.1*ddr };
2598 double er_dmeas2[2] = {0. , 0.} ;
2601 er_dmeas2[0] = 0.1*erddl;
2602 er_dmeas2[1] = 0.1*erddr;
2611 if ((
LR_==0 && lr != 1.0) ||
2612 (
LR_==1 && lr == -1.0)) {
2614 double er_dmeasL, dmeasL;
2616 dmeasL = (-1.0)*fabs(dmeas2[0]);
2617 er_dmeasL = er_dmeas2[0];
2619 dmeasL = (-1.0)*fabs((*HitMdc).dist()[0]);
2620 er_dmeasL = (*HitMdc).erdist()[0];
2623 double AL = 1 / ((v_H_T_ea_v_H)[0] + er_dmeasL*er_dmeasL);
2624 eaNewL.assign(ea - ea_v_H * AL * ea_v_HT);
2625 double RkL = 1 - (v_H_T_ea_v_H)[0] * AL;
2626 if(0. == RkL) RkL = 1.e-4;
2628 HepVector diffL = ea_v_H * AL * (dmeasL - estim);
2630 aNewL = v_a + diffL;
2631 double sigL = dmeasL -(v_HT * aNewL)[0];
2632 dchi2L = (sigL * sigL) / (RkL * er_dmeasL*er_dmeasL);
2635 if ((
LR_==0 && lr != -1.0) ||
2636 (
LR_==1 && lr == 1.0)) {
2638 double er_dmeasR, dmeasR;
2641 er_dmeasR = er_dmeas2[1];
2643 dmeasR = fabs((*HitMdc).dist()[1]);
2644 er_dmeasR = (*HitMdc).erdist()[1];
2647 double AR = 1 / ((v_H_T_ea_v_H)[0] + er_dmeasR*er_dmeasR);
2648 eaNewR.assign(ea - ea_v_H * AR * ea_v_HT);
2649 double RkR = 1 - (v_H_T_ea_v_H)[0] * AR;
2650 if(0. == RkR) RkR = 1.e-4;
2652 HepVector diffR = ea_v_H * AR * (dmeasR - estim);
2654 aNewR = v_a + diffR;
2655 double sigR = dmeasR -(v_HT * aNewR)[0];
2656 dchi2R = (sigR*sigR) / (RkR * er_dmeasR*er_dmeasR);
2660 double dchi2_loc(0);
2663 cout<<
" track::update_hits......"<<endl;
2664 std::cout <<
" dchi2R = " << dchi2R <<
", dchi2L = " << dchi2L
2665 <<
" estimate = "<<estim<< std::endl;
2666 std::cout <<
" dmeasR = " << dmeas2[1]
2667 <<
", dmeasL = " << (-1.0)*fabs(dmeas2[0]) <<
", check HitMdc.ddl = "
2668 << (*HitMdc).dist()[0] << std::endl;
2671 if (fabs(dchi2R-dchi2L)<10. && inext>0) {
2676 double chi2_fromR(
chi2_next(H_fromR, HitMdc_next,csmflag));
2679 double chi2_fromL(
chi2_next(H_fromL, HitMdc_next,csmflag));
2681 std::cout <<
" chi2_fromL = " << chi2_fromL
2682 <<
", chi2_fromR = " << chi2_fromR << std::endl;
2684 if (fabs(chi2_fromR-chi2_fromL)<10.){
2686 if (inext+1<HitsMdc_.size())
2687 for(
int k=inext+1 ; k < HitsMdc_.size(); k++ )
2688 if (!(HitsMdc_[k].chi2()<0)) {
2695 double chi2_fromR2(
chi2_next(H_fromR, HitMdc_next2, csmflag));
2696 double chi2_fromL2(
chi2_next(H_fromL, HitMdc_next2, csmflag));
2698 std::cout <<
" chi2_fromL2 = " << chi2_fromL2
2699 <<
", chi2_fromR2 = " << chi2_fromR2 << std::endl;
2701 if (fabs(dchi2R+chi2_fromR+chi2_fromR2-(dchi2L+chi2_fromL+chi2_fromL2))<2) {
2702 if (chi2_fromR2<chi2_fromL2)
2711 if (dchi2R+chi2_fromR < dchi2L+chi2_fromL){
2714 std::cout <<
" choose right..." << std::endl;
2719 std::cout <<
" choose left..." << std::endl;
2728 if (((
LR_==0 && dchi2R < dchi2L && lr != -1) ||
2729 (
LR_==1 && lr == 1)) &&
2730 fabs(aNewR[2]-
a()[2]) < 1000. && aNewR[2]) {
2733 if (flag_ster) nster_++;
2758 if (l_mass_ == lead_){
2762 update_bit((*HitMdc).wire().layer().layerId());
2764 }
else if (((
LR_==0 && dchi2L <= dchi2R && lr != 1) ||
2765 (
LR_==1 && lr == -1)) &&
2766 fabs(aNewL[2]-
a()[2]) < 1000. && aNewL[2]){
2769 if (flag_ster) nster_++;
2792 if (l_mass_ == lead_){
2796 update_bit((*HitMdc).wire().layer().layerId());
2801 if (dchi2_loc > dchi2_max_) {
2802 dchi2_max_ = dchi2_loc ;
2803 r_max_ =
pivot().perp();
2805 dchi2out = dchi2_loc;
2821 double recZ = Cluster->
getRecZ()/10;
2823 while(recPhi >
M_PI) recPhi-=2*
M_PI;
2824 while(recPhi <-
M_PI) recPhi+=2*
M_PI;
2825 HepVector v_measu(2,0);
2826 v_measu(1) = recPhi;
2833 HepVector v_estim(2,0);
2834 v_estim(1) = x0kal.phi();
2835 v_estim(2) = x0kal.z();
2837 const HepSymMatrix& ea =
Ea();
2838 HepVector v_a =
a();
2843 double phi0 = v_a(2);
2844 double kappa = v_a(3);
2845 double tanl = v_a(5);
2846 double x0 = x0kal.x();
2847 double y0 = x0kal.y();
2848 double Alpha =
alpha();
2849 HepMatrix
H(2, 5, 0);
2855 H(2,5) = -1*(Alpha/
kappa)*dPhi;
2859 ISvcLocator* svcLocator = Gaudi::svcLocator();
2861 StatusCode Cgem_sc=svcLocator->service(
"CgemGeomSvc", ISvc);
2869 StatusCode sc = svcLocator->service (
"CgemCalibFunSvc", CgemCalibSvc);
2870 int iView(0), mode(2);
2871 double Q(100), T(100);
2872 double Phi_momentum =
momentum(dPhi).phi();
2873 double Phi_position = x0kal.phi();
2874 double delta_phi=Phi_momentum - Phi_position;
2875 while(delta_phi>
M_PI) delta_phi-=CLHEP::twopi;
2876 while(delta_phi<-
M_PI) delta_phi+=CLHEP::twopi;
2877 double sigma_X = CgemCalibSvc->
getSigma(layer,iView,mode,delta_phi,Q,T);
2878 double sigma_V = CgemCalibSvc->
getSigma(layer,iView,mode,delta_phi,Q,T);
2880 HepSymMatrix V(2,0);
2883 V(1,1) = pow(sigma_X/R_x,2);
2887 HepMatrix K = ea*
H.T()*(V+
H*ea*
H.T()).inverse(ierr);
2888 if(ierr != 0)cout<<
"errer in inverse operation of matrix!"<<endl;
2891 HepSymMatrix EaNew(5,0);
2892 EaNew.assign(ea-K*
H*ea);
2896 HepVector v_diff = v_measu - v_estim;
2897 while(v_diff(1) >
M_PI) v_diff(1)-=2*
M_PI;
2898 while(v_diff(1) <-
M_PI) v_diff(1)+=2*
M_PI;
2906 HepVector v_estim_new(2,0);
2907 v_estim_new(1) = x0kal_new.phi();
2908 v_estim_new(2) = x0kal_new.z();
2911 v_diff = v_measu - v_estim_new;
2912 while(v_diff(1) >
M_PI) v_diff(1)-=2*
M_PI;
2913 while(v_diff(1) <-
M_PI) v_diff(1)+=2*
M_PI;
2921 HepSymMatrix R(2,0);
2922 R.assign(V-
H*EaNew*
H.T());
2923 HepVector dChi2 = v_diff.T()*R.inverse(ierr)*v_diff;
2924 if(ierr != 0)cout<<
"errer in inverse operation of matrix!"<<endl;
2935 int wire_ID = Wire.
geoID();
2941 Hep3Vector wire = (Hep3Vector)fwd -(Hep3Vector)bck;
2944 work.
pivot((fwd + bck) * .5);
2945 HepPoint3D x0kal = (work.
x(0).z() - bck.z())/ wire.z() * wire + bck;
2948 Hep3Vector meas =
H.momentum(0).cross(wire).unit();
2950 if (wire_ID<0 || wire_ID>6796){
2951 std::cout <<
"KalFitTrack : wire_ID problem : " << wire_ID
2960 double csf0 =
cos(phi);
2961 double snf0 = (1. - csf0) * (1. + csf0);
2962 snf0 = sqrt((snf0 > 0.) ? snf0 : 0.);
2963 if(phi >
M_PI) snf0 = - snf0;
2966 Hep3Vector ip(0, 0, 0);
2970 double phi_ip = work.
phi0();
2971 if (fabs(phi - phi_ip) >
M_PI) {
2972 if (phi > phi_ip) phi -= 2 *
M_PI;
2973 else phi_ip -= 2 *
M_PI;
2976 double l = fabs(
radius() * (phi - phi_ip) * sqrt(1 +
t *
t));
2977 double pmag( sqrt( 1.0 +
t*
t ) /
kappa());
2978 double mass_over_p( mass_ / pmag );
2979 double beta( 1.0 / sqrt( 1.0 + mass_over_p * mass_over_p ) );
2980 tofest = l / ( 29.9792458 * beta );
2984 const HepSymMatrix& ea =
H.Ea();
2985 const HepVector& v_a =
H.a();
2988 HepVector v_H(5, 0);
2989 v_H[0] = -csf0 * meas.x() - snf0 * meas.y();
2991 HepMatrix v_HT = v_H.T();
2993 double estim = (v_HT * v_a)[0];
2994 HepVector ea_v_H = ea * v_H;
2995 HepMatrix ea_v_HT = (ea_v_H).T();
2996 HepVector v_H_T_ea_v_H = v_HT * ea_v_H;
2998 HepSymMatrix eaNewL(5), eaNewR(5);
2999 HepVector aNewL(5), aNewR(5);
3010 double dmeas2[2] = { 0.1*ddl, 0.1*ddr };
3011 double er_dmeas2[2] = {0. , 0.};
3013 er_dmeas2[0] = 0.1*erddl;
3014 er_dmeas2[1] = 0.1*erddr;
3022 if ((
LR_==0 && lr != 1.0) ||
3023 (
LR_==1 && lr == -1.0)) {
3025 double er_dmeasL, dmeasL;
3027 dmeasL = (-1.0)*fabs(dmeas2[0]);
3028 er_dmeasL = er_dmeas2[0];
3034 double AL = 1 / ((v_H_T_ea_v_H)[0] + er_dmeasL*er_dmeasL);
3035 eaNewL.assign(ea - ea_v_H * AL * ea_v_HT);
3036 double RkL = 1 - (v_H_T_ea_v_H)[0] * AL;
3037 if(0. == RkL) RkL = 1.e-4;
3039 HepVector diffL = ea_v_H * AL * (dmeasL - estim);
3040 aNewL = v_a + diffL;
3041 double sigL = dmeasL -(v_HT * aNewL)[0];
3042 dchi2L = (sigL * sigL) / (RkL * er_dmeasL*er_dmeasL);
3045 if ((
LR_==0 && lr != -1.0) ||
3046 (
LR_==1 && lr == 1.0)) {
3048 double er_dmeasR, dmeasR;
3051 er_dmeasR = er_dmeas2[1];
3057 double AR = 1 / ((v_H_T_ea_v_H)[0] + er_dmeasR*er_dmeasR);
3058 eaNewR.assign(ea - ea_v_H * AR * ea_v_HT);
3059 double RkR = 1 - (v_H_T_ea_v_H)[0] * AR;
3060 if(0. == RkR) RkR = 1.e-4;
3062 HepVector diffR = ea_v_H * AR * (dmeasR - estim);
3063 aNewR = v_a + diffR;
3064 double sigR = dmeasR -(v_HT * aNewR)[0];
3065 dchi2R = (sigR*sigR) / (RkR * er_dmeasR*er_dmeasR);
3068 if (dchi2R < dchi2L){
3069 H.a(aNewR);
H.Ea(eaNewR);
3071 H.a(aNewL);
H.Ea(eaNewL);
3073 return ((dchi2R < dchi2L) ? dchi2R : dchi2L);
3080 int wire_ID = Wire.
geoID();
3086 Hep3Vector wire = (Hep3Vector)fwd -(Hep3Vector)bck;
3089 work.
pivot((fwd + bck) * .5);
3090 HepPoint3D x0kal = (work.
x(0).z() - bck.z())/ wire.z() * wire + bck;
3093 Hep3Vector meas =
H.momentum(0).cross(wire).unit();
3095 if (wire_ID<0 || wire_ID>6796){
3096 std::cout <<
"KalFitTrack : wire_ID problem : " << wire_ID
3105 double csf0 =
cos(phi);
3106 double snf0 = (1. - csf0) * (1. + csf0);
3107 snf0 = sqrt((snf0 > 0.) ? snf0 : 0.);
3108 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) {
3117 if (phi > phi_ip) phi -= 2 *
M_PI;
3118 else phi_ip -= 2 *
M_PI;
3121 double l = fabs(
radius() * (phi - phi_ip) * sqrt(1 +
t *
t));
3122 double pmag( sqrt( 1.0 +
t*
t ) /
kappa());
3123 double mass_over_p( mass_ / pmag );
3124 double beta( 1.0 / sqrt( 1.0 + mass_over_p * mass_over_p ) );
3125 tofest = l / ( 29.9792458 * beta );
3126 if(csmflag==1 &&
HitMdc.
wire().
y()>0.) tofest= -1. * tofest;
3129 const HepSymMatrix& ea =
H.Ea();
3130 const HepVector& v_a =
H.a();
3133 HepVector v_H(5, 0);
3134 v_H[0] = -csf0 * meas.x() - snf0 * meas.y();
3136 HepMatrix v_HT = v_H.T();
3138 double estim = (v_HT * v_a)[0];
3139 HepVector ea_v_H = ea * v_H;
3140 HepMatrix ea_v_HT = (ea_v_H).T();
3141 HepVector v_H_T_ea_v_H = v_HT * ea_v_H;
3143 HepSymMatrix eaNewL(5), eaNewR(5);
3144 HepVector aNewL(5), aNewR(5);
3155 double dmeas2[2] = { 0.1*ddl, 0.1*ddr };
3156 double er_dmeas2[2] = {0. , 0.};
3158 er_dmeas2[0] = 0.1*erddl;
3159 er_dmeas2[1] = 0.1*erddr;
3167 if ((
LR_==0 && lr != 1.0) ||
3168 (
LR_==1 && lr == -1.0)) {
3170 double er_dmeasL, dmeasL;
3172 dmeasL = (-1.0)*fabs(dmeas2[0]);
3173 er_dmeasL = er_dmeas2[0];
3179 double AL = 1 / ((v_H_T_ea_v_H)[0] + er_dmeasL*er_dmeasL);
3180 eaNewL.assign(ea - ea_v_H * AL * ea_v_HT);
3181 double RkL = 1 - (v_H_T_ea_v_H)[0] * AL;
3182 if(0. == RkL) RkL = 1.e-4;
3184 HepVector diffL = ea_v_H * AL * (dmeasL - estim);
3185 aNewL = v_a + diffL;
3186 double sigL = dmeasL -(v_HT * aNewL)[0];
3187 dchi2L = (sigL * sigL) / (RkL * er_dmeasL*er_dmeasL);
3190 if ((
LR_==0 && lr != -1.0) ||
3191 (
LR_==1 && lr == 1.0)) {
3193 double er_dmeasR, dmeasR;
3196 er_dmeasR = er_dmeas2[1];
3202 double AR = 1 / ((v_H_T_ea_v_H)[0] + er_dmeasR*er_dmeasR);
3203 eaNewR.assign(ea - ea_v_H * AR * ea_v_HT);
3204 double RkR = 1 - (v_H_T_ea_v_H)[0] * AR;
3205 if(0. == RkR) RkR = 1.e-4;
3207 HepVector diffR = ea_v_H * AR * (dmeasR - estim);
3208 aNewR = v_a + diffR;
3209 double sigR = dmeasR -(v_HT * aNewR)[0];
3210 dchi2R = (sigR*sigR) / (RkR * er_dmeasR*er_dmeasR);
3213 if (dchi2R < dchi2L){
3214 H.a(aNewR);
H.Ea(eaNewR);
3216 H.a(aNewL);
H.Ea(eaNewL);
3218 return ((dchi2R < dchi2L) ? dchi2R : dchi2L);
3223 double sigma1,sigma2,f;
3227 sigma1=0.112784; sigma2=0.229274; f=0.666;
3228 }
else if(driftDist<1.){
3229 sigma1=0.103123; sigma2=0.269797; f=0.934;
3230 }
else if(driftDist<1.5){
3231 sigma1=0.08276; sigma2=0.17493; f=0.89;
3232 }
else if(driftDist<2.){
3233 sigma1=0.070109; sigma2=0.149859; f=0.89;
3234 }
else if(driftDist<2.5){
3235 sigma1=0.064453; sigma2=0.130149; f=0.886;
3236 }
else if(driftDist<3.){
3237 sigma1=0.062383; sigma2=0.138806; f=0.942;
3238 }
else if(driftDist<3.5){
3239 sigma1=0.061873; sigma2=0.145696; f=0.946;
3240 }
else if(driftDist<4.){
3241 sigma1=0.061236; sigma2=0.119584; f=0.891;
3242 }
else if(driftDist<4.5){
3243 sigma1=0.066292; sigma2=0.148426; f=0.917;
3244 }
else if(driftDist<5.){
3245 sigma1=0.078074; sigma2=0.188148; f=0.911;
3246 }
else if(driftDist<5.5){
3247 sigma1=0.088657; sigma2=0.27548; f=0.838;
3249 sigma1=0.093089; sigma2=0.115556; f=0.367;
3253 sigma1=0.112433; sigma2=0.327548; f=0.645;
3254 }
else if(driftDist<1.){
3255 sigma1=0.096703; sigma2=0.305206; f=0.897;
3256 }
else if(driftDist<1.5){
3257 sigma1=0.082518; sigma2=0.248913; f= 0.934;
3258 }
else if(driftDist<2.){
3259 sigma1=0.072501; sigma2=0.153868; f= 0.899;
3260 }
else if(driftDist<2.5){
3261 sigma1= 0.065535; sigma2=0.14246; f=0.914;
3262 }
else if(driftDist<3.){
3263 sigma1=0.060497; sigma2=0.126489; f=0.918;
3264 }
else if(driftDist<3.5){
3265 sigma1=0.057643; sigma2= 0.112927; f=0.892;
3266 }
else if(driftDist<4.){
3267 sigma1=0.055266; sigma2=0.094833; f=0.887;
3268 }
else if(driftDist<4.5){
3269 sigma1=0.056263; sigma2=0.124419; f= 0.932;
3270 }
else if(driftDist<5.){
3271 sigma1=0.056599; sigma2=0.124248; f=0.923;
3272 }
else if(driftDist<5.5){
3273 sigma1= 0.061377; sigma2=0.146147; f=0.964;
3274 }
else if(driftDist<6.){
3275 sigma1=0.063978; sigma2=0.150591; f=0.942;
3276 }
else if(driftDist<6.5){
3277 sigma1=0.072951; sigma2=0.15685; f=0.913;
3278 }
else if(driftDist<7.){
3279 sigma1=0.085438; sigma2=0.255109; f=0.931;
3280 }
else if(driftDist<7.5){
3281 sigma1=0.101635; sigma2=0.315529; f=0.878;
3283 sigma1=0.149529; sigma2=0.374697; f=0.89;
3286 double sigmax = sqrt(f*sigma1*sigma1+(1 - f)*sigma2*sigma2)*0.1;
**********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
double tan(const BesAngle a)
double sin(const BesAngle a)
double cos(const BesAngle a)
********INTEGER modcns REAL m_C
HepGeom::Transform3D HepTransform3D
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
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.
double chiSq_back(void) const
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)
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.
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