40 if(myIsInitialized)
return;
43 ISvcLocator* svcLocator = Gaudi::svcLocator();
45 StatusCode Cgem_sc=svcLocator->service(
"CgemGeomSvc", ISvc);
46 if(Cgem_sc.isSuccess()) myCgemGeomSvc=
dynamic_cast<CgemGeomSvc *
>(ISvc);
47 else cout<<
"DotsHelixFitter::initialize(): can not get CgemGeomSvc"<<endl;
50 cout<<
"DotsHelixFitter::initialize(): nLayerCgem!=3 !!!"<<endl;
53 for(
int i=0; i<nLayerCgem; i++)
58 myR2midDGapCgem[i]=pow(myRmidDGapCgem[i],2);
66 cout<<
"CGEM layer "<<i<<
": "
67 <<
" Rmid="<<myRmidDGapCgem[i]<<
" cm "
68 <<
" RV ="<<myRVCgem[i]<<
" cm "
69 <<
" RX ="<<myRXCgem[i]<<
" cm "
70 <<
" , stereo angle = "<<myAngStereoCgem[i]<<
" radian "
71 <<myNSheets[i]<<
" sheets"
79 StatusCode mdc_sc=svcLocator->service(
"MdcGeomSvc", ISvc2);
80 if(mdc_sc.isSuccess()) myMdcGeomSvc=
dynamic_cast<MdcGeomSvc *
>(ISvc2);
81 else cout<<
"DotsHelixFitter::initialize(): can not get MdcGeomSvc"<<endl;
83 if(nLayer!=43) cout<<
"DotsHelixFitter::initialize(): MDC nLayer = "<<nLayer<<
" !=43 !!!"<<endl;
84 for(
int i=0; i<nLayer; i++)
87 myRWires[i]=0.1*(aLayer->
Radius());
88 cout<<
"MDC layer "<<i<<
" R = "<<myRWires[i]<<endl;
90 if(nomShift>0) myWireFlag[i]=1;
91 else if(nomShift<0) myWireFlag[i]=-1;
93 int nWires=aLayer->
NCell();
95 for(
int j=0; j<nWires; j++)
99 double* aPointArray =
new double[3]{aPointEast.x(),aPointEast.y(),aPointEast.z()};
100 myWestPosWires[i].push_back(aPointArray);
102 aPointArray =
new double[3]{aPointWest.x(),aPointWest.y(),aPointWest.z()};
103 myEastPosWires[i].push_back(aPointArray);
104 HepPoint3D aPointMiddle = 0.5*(aPointEast+aPointWest);
105 aPointArray =
new double[3]{aPointMiddle.x(),aPointMiddle.y(),aPointMiddle.z()};
106 myPosWires[i].push_back(aPointArray);
108 myPhiWires[i].push_back(aPointMiddle.phi());
109 myTensionWires[i].push_back(aWire->
Tension());;
115 StatusCode sc = svcLocator->service(
"MdcCalibFunSvc", imdcCalibSvc);
116 if ( sc.isSuccess() ){
120 cout<<
"DotsHelixFitter::initialize(): can not get MdcCalibFunSvc"<<endl;
124 sc = svcLocator->service(
"CgemCalibFunSvc", myCgemCalibSvc);
125 if ( !(sc.isSuccess()) )
127 cout<<
"DotsHelixFitter::initialize(): can not get CgemCalibFunSvc"<<endl;
137 myIsInitialized=
true;
140 sc = svcLocator->service(
"MdcUtilitySvc", myMdcUtilitySvc);
141 if ( !(sc.isSuccess()) )
143 cout<<
"DotsHelixFitter::initialize(): can not get MdcUtilitySvc"<<endl;
265 double tension = 9999.;
268 if(myFitCircleOnly) nPar=3;
269 if(myFitCircleOriginOnly) nPar=2;
273 for(
int i=0; i<43; i++) myNumMdcDigiPerLayer[i]=0;
276 int nXHits[3]={0,0,0}, nVHits[3]={0,0,0};
277 int nDigi=myVecMdcDigi.size();
279 vector<double> vec_zini(nDigi);
282 vector<const MdcDigi*>::iterator iter_mdcDigi = myVecMdcDigi.begin();
283 for(; iter_mdcDigi!=myVecMdcDigi.end(); iter_mdcDigi++, i_digi++)
292 if(myMdcDigiIsActive[i_digi]==1)
296 int hitFlag = myWireFlag[layer];
308 if(maxLayer<layer) maxLayer=layer;
309 int nHits = myNumMdcDigiPerLayer[layer];
311 myIdxMdcDigiNeighbour[layer][nHits]=i_digi;
312 myWireIdMdcDigiNeighbour[layer][nHits]=wire;
314 myNumMdcDigiPerLayer[layer]++;
318 double maxRTrk = farPoint.perp();
319 for(
int i=0; i<43; i++)
321 if(maxRTrk<myRWires[i]+2)
break;
322 if(myNumMdcDigiPerLayer[i]==2)
324 int wire_1 = myWireIdMdcDigiNeighbour[i][0];
325 int wire_2 = myWireIdMdcDigiNeighbour[i][1];
326 int delta_n =
abs(wire_1-wire_2);
331 ambi_1 = wire_1>wire_2? 1:-1;
332 ambi_2 = wire_1>wire_2? -1:1;
334 else if(delta_n==myNWire[i]-1)
336 ambi_1 = wire_1<=1? 1:-1;
337 ambi_2 = wire_2<=1? 1:-1;
353 vector<const RecCgemCluster*>::iterator iter_cluster = myVecCgemCluster.begin();
354 for(; iter_cluster!=myVecCgemCluster.end(); iter_cluster++, i_digi++)
356 int flag = (*iter_cluster)->getflag();
371 if(nXHits[0]<myMinXhitsInCircleFit)
return 1;
375 if((nXHits[0]+nVHits[0])<myMinHitsInHelixFit)
return 2;
376 if(nVHits[0]<myMinVhitsInHelixFit)
return 3;
383 double lastTotChi2 = 999999;
384 double secLastTotChi2 = 999999;
385 double thirdLastTotChi2 = 999999;
387 int n_chi2_increase = 0;
393 myMapFlylenIdx.clear();
395 HepSymMatrix U(nPar, 0);
399 HepMatrix
P(nPar,1,0);
400 HepMatrix J(nPar,1,0), JT(1,nPar,0);
401 HepMatrix J_dmdx(1,3,0), J_dxda(3,nPar,0);
406 vector<const MdcDigi*>::iterator iter_mdcDigi = myVecMdcDigi.begin();
407 for(; iter_mdcDigi!=myVecMdcDigi.end(); iter_mdcDigi++, i_digi++)
413 double charge = (*iter_mdcDigi)->getChargeChannel();
417 double wpos[7]={myEastPosWires[layer][wire][0], myEastPosWires[layer][wire][1], myEastPosWires[layer][wire][2]
418 , myWestPosWires[layer][wire][0], myWestPosWires[layer][wire][1], myWestPosWires[layer][wire][2], tension};
424 cout<<
"* layer "<<layer<<
", wire "<<wire<<
", is active "<<myMdcDigiIsActive[i_digi] <<endl;
436 leftRight=int(doca_trk/fabs(doca_trk));
444 signDoca=leftRight/fabs(leftRight);
447 if(leftRight==1) leftRight=0;
451 vec_zini[i_digi] = whitPos[2];
455 double tprop = myMdcCalibFunSvc->
getTprop(layer, vec_zini[i_digi]);
456 double T0Walk = myMdcCalibFunSvc->
getT0(layer,wire) + myMdcCalibFunSvc->
getTimeWalk(layer, charge);
460 HepPoint3D aNewPivot(whitPos[0],whitPos[1],whitPos[2]);
462 aHelix.
pivot(aNewPivot);
464 double newPhi0 = aHelix.
phi0();
466 double dphi = newPhi0-myHelix->
phi0();
470 if(dphi<-M_PI||dphi>
M_PI) dphi=atan2(
sin(dphi),
cos(dphi));
471 double flightLength = fabs(dphi*myHelix->
radius())*sqrt(1+myHelix->
tanl()*myHelix->
tanl());
473 myMapFlylenIdx[flightLength]=i_digi;
474 HepLorentzVector p4_pi = myHelix->
momentum(dphi, 0.13957);
476 double TOF = flightLength/speed*1.e9;
479 double driftT = rawTime - myEventT0 - TOF - T0Walk - tprop;
482 double phiWire = atan2(whitPos[1],whitPos[0]);
483 double phiP = p4_pi.phi();
484 double entranceAngle = phiP-phiWire;
487 if(entranceAngle<-M_PI||entranceAngle>
M_PI) entranceAngle=atan2(
sin(entranceAngle),
cos(entranceAngle));
489 double doca_hit = 0.1 * myMdcCalibFunSvc->
driftTimeToDist(driftT,layer,wire,leftRight, entranceAngle);
491 double docaErr_hit = 0.1 * myMdcCalibFunSvc->
getSigma(layer, leftRight, doca_hit, entranceAngle, myHelix_a[4], vec_zini[i_digi], charge);
497 double delD = doca_hit-doca_trk;
498 double chi = delD/docaErr_hit;
499 if(debug) cout<<
"delta_m, err_m, chi = "<<delD<<
", "<<docaErr_hit<<
", "<<chi<<endl;
500 myChiVecMdcDigi[i_digi]=chi;
502 if(myMdcDigiIsActive[i_digi]!=1)
continue;
503 if(myUseAxialHitsOnly && myWireFlag[layer]!=0)
continue;
507 for(
int ipar=0; ipar<nPar; ipar++)
517 P(ipar+1,1) += J(ipar+1,1)*(doca_hit-doca_trk)/(docaErr_hit*docaErr_hit*scale);
518 for(
int ipar2=0; ipar2<=ipar; ipar2++)
521 U(ipar+1,ipar2+1)+=J(ipar+1,1)*J(ipar2+1,1)/(docaErr_hit*docaErr_hit*scale);
526 if(debug) cout<<
"end of MDC hits loop"<<endl;
531 vector<const RecCgemCluster*>::iterator iter_cluster = myVecCgemCluster.begin();
532 for(; iter_cluster!=myVecCgemCluster.end(); iter_cluster++, i_digi++)
535 int layer = (*iter_cluster)->getlayerid();
536 int flag = (*iter_cluster)->getflag();
537 if(myUseAxialHitsOnly && flag!=0)
continue;
538 if(myUseMdcHitsOnly)
continue;
539 int sheet = (*iter_cluster)->getsheetid();
543 cout<<endl<<
"layer, sheet, flag = "<<setw(5)<<layer<<setw(5)<<sheet<<setw(5)<<flag<<endl;
548 if(fabs(dphi)<1e-10) {
549 myChiVecCgemCluster[i_digi]=-9999;
553 double flightLength = fabs(dphi*myHelix->
radius())*sqrt(1+myHelix->
tanl()*myHelix->
tanl());
554 myMapFlylenIdx[flightLength]=-(i_digi+1);
556 if(debug) cout<<
"dphi="<<dphi<<
", pos="<<pos<<endl;
557 double phi_trk = pos.phi();
558 double z_trk = pos.z();
560 Hep3Vector p3_trk = myHelix->
momentum(dphi);
561 double phi_p3trk = p3_trk.phi();
562 double incidentPhi = phi_p3trk-phi_trk;
565 if(incidentPhi<-M_PI||incidentPhi>
M_PI) incidentPhi=atan2(
sin(incidentPhi),
cos(incidentPhi));
569 double X_CC(0.), V_CC(0.);
570 double delta_m, err_m;
574 Q=(*iter_cluster)->getenergydeposit();
576 phi_CC = (*iter_cluster)->getrecphi();
578 double del_phi = phi_CC-phi_trk;
581 if(del_phi<-M_PI||del_phi>
M_PI) del_phi=atan2(
sin(del_phi),
cos(del_phi));
582 X_CC=phi_CC*myRmidDGapCgem[layer];
583 if(debug) cout<<
"phi_trk, phi_rec = "<<phi_trk<<
", "<<phi_CC<<endl;
587 err_m=myCgemCalibSvc->
getSigma(layer,flag,mode,incidentPhi,Q,T)/10.;
588 err_m/=myRmidDGapCgem[layer];
589 J_dmdx(1,1)=-1*pos.y()/myR2midDGapCgem[layer];
590 J_dmdx(1,2)=pos.x()/myR2midDGapCgem[layer];
594 double V_trk = readoutPlane->
getVFromPhiZ(phi_trk,z_trk*10,
false)/10.0;
595 V_CC=(*iter_cluster)->getrecv()/10.;
597 if(debug) cout<<
"V_trk, V_rec = "<<V_trk<<
", "<<V_CC<<endl;
599 if(fabs(delta_m)>5) {
608 double delta_m_2=V_CC-V_trk_nearPhiMin;
609 if(fabs(delta_m_2)<fabs(delta_m)) delta_m=delta_m_2;
610 if(debug) cout<<
"V_trk_nearPhiMin= "<<V_trk_nearPhiMin<<endl;
612 err_m=myCgemCalibSvc->
getSigma(layer,flag,mode,incidentPhi,Q,T)/10.;
613 J_dmdx(1,1)=-myRVCgem[layer]*
cos(myAngStereoCgem[layer])*pos.y()/myR2midDGapCgem[layer];
614 J_dmdx(1,2)= myRVCgem[layer]*
cos(myAngStereoCgem[layer])*pos.x()/myR2midDGapCgem[layer];
615 J_dmdx(1,3)= -
sin(myAngStereoCgem[layer]);
618 cout<<
"flag ="<<flag<<
", DotsHelixFitter::calculateNewHelix() is not ready for it!"<<endl;
628 double chi = delta_m/err_m;
629 myChiVecCgemCluster[i_digi]=chi;
630 if(debug) cout<<
"delta_m, err_m, chi = "<<delta_m<<
", "<<err_m<<
", "<<chi<<endl;
633 for(
int ipar=0; ipar<nPar; ipar++)
637 P(ipar+1,1) += J(ipar+1,1)*chi/err_m;
638 for(
int ipar2=0; ipar2<=ipar; ipar2++)
640 U(ipar+1,ipar2+1)+=J(ipar+1,1)*J(ipar2+1,1)/(err_m*err_m);
643 if(debug) cout<<
"U="<<U<<endl;
646 cout<<
"end of CGEM cluster loop"<<endl;
663 for(
int ipar=0; ipar<nPar; ipar++)
665 myHelix_a[ipar]+=da[ipar];
666 if(ipar==1&&(myHelix_a[ipar]>2*
M_PI||myHelix_a[ipar]<0))
668 double aphi=myHelix_a[ipar];
669 aphi=atan2(
sin(aphi),
cos(aphi));
670 if(aphi<0) aphi+=2*
M_PI;
671 myHelix_a[ipar]=aphi;
673 myHelix_aVec[ipar]=myHelix_a[ipar];
675 myHelix->
a(myHelix_aVec);
678 cout<<
"aNew = "<<myHelix_aVec
679 <<
" chi2 = "<<totChi2
687 if(debug) cout<<
" iteration "<<nIterations<<
", chi2="<<totChi2<<endl;
688 if(fabs(lastTotChi2-totChi2)<myDchi2Converge) {
690 cout<<
"DotsHelixFitter::calculateNewHelix(): converge after "<<nIterations<<
" iterations"
691 <<
" with lastTotChi2="<<lastTotChi2<<
", totChi2="<<totChi2
701 else if(totChi2-lastTotChi2>myDchi2Diverge) {
703 if(n_chi2_increase>myMaxNChi2Increase||totChi2>myChi2Diverge)
706 if( nIterations>3 && fabs(secLastTotChi2-totChi2)<(0.1*myDchi2Converge) && fabs(thirdLastTotChi2-lastTotChi2)<(0.1*myDchi2Converge) ) {
709 if(n_oscillation>0&&totChi2<lastTotChi2) {
714 if(debug) cout<<
"DotsHelixFitter::calculateNewHelix(): oscillation happened, thirdLastTotChi2, secLastTotChi2, lastTotChi2 = "<<thirdLastTotChi2<<
", "<<secLastTotChi2<<
", "<<lastTotChi2<<endl;
718 if(nIterations>myMaxIteration) {
719 if(debug) cout<<
"DotsHelixFitter::calculateNewHelix(): "<<nIterations
720 <<
" iterations, break with lastTotChi2, totChi2 = "<<lastTotChi2<<
", "<<totChi2<<endl;
724 thirdLastTotChi2=secLastTotChi2;
725 secLastTotChi2=lastTotChi2;
969 double phiWire = atan2(myPosOnWire[1],myPosOnWire[0]);
972 cout<<
"DotsHelixFitter::UpdateDcDigiInfo(): "<<endl;
973 cout<<
"doca = "<<myDocaFromTrk<<endl;
974 cout<<
"point on wire: "<<myPosOnWire[0]<<
", "<<myPosOnWire[1]<<
", "<<myPosOnWire[2]<<endl;
979 HepPoint3D aNewPivot(myPosOnWire[0],myPosOnWire[1],myPosOnWire[2]);
980 aHelix.
pivot(aNewPivot);
981 double newPhi0 = aHelix.
phi0();
982 double dphi = newPhi0-myHelix->
phi0();
985 if(dphi<-M_PI||dphi>
M_PI) dphi=atan2(
sin(dphi),
cos(dphi));
986 myFlightLength = fabs(dphi*myHelix->
radius())*sqrt(1+myHelix->
tanl()*myHelix->
tanl());
990 myPosOnTrk[0]=posOnTrk.x();
991 myPosOnTrk[1]=posOnTrk.y();
992 myPosOnTrk[2]=posOnTrk.z();
993 double phiPosOnTrk=atan2(myPosOnTrk[1],myPosOnTrk[0]);
1000 myLeftRight=int(myDocaFromTrk/fabs(myDocaFromTrk));
1001 signDoca=myLeftRight;
1005 if(myLeftRight==1) myLeftRight=0;
1007 double dphiLR=phiWire-phiPosOnTrk;
1010 if(dphiLR<-M_PI||dphiLR>
M_PI) dphiLR=atan2(
sin(dphiLR),
cos(dphiLR));
1015 if(debug) cout<<
"myLeftRight = "<<myLeftRight<<endl;
1018 HepLorentzVector p4_pi = myHelix->
momentum(dphi, 0.13957);
1020 double TOF = myFlightLength/speed*1.e9;
1024 double tprop = myMdcCalibFunSvc->
getTprop(myLayer, myPosOnWire[2]);
1025 double T0Walk = myMdcCalibFunSvc->
getT0(myLayer,myWire) + myMdcCalibFunSvc->
getTimeWalk(myLayer, myCharge);
1028 myDriftTime = rawTime - myEventT0 - TOF - T0Walk - tprop;
1029 if(debug) cout<<
"driftT = "<<myDriftTime<<endl;
1031 double phiP = p4_pi.phi();
1032 double entranceAngle = phiP-phiWire;
1035 if(entranceAngle<-M_PI||entranceAngle>
M_PI) entranceAngle=atan2(
sin(entranceAngle),
cos(entranceAngle));
1036 myEntranceAngle = entranceAngle;
1038 myDocaFromDigi = 0.1 * myMdcCalibFunSvc->
driftTimeToDist(myDriftTime,myLayer,myWire,myLeftRight,entranceAngle);
1039 myDriftDist[myLeftRight]=myDocaFromDigi;
1040 myDriftDist[1-myLeftRight]=0.1 * myMdcCalibFunSvc->
driftTimeToDist(myDriftTime,myLayer,myWire,1-myLeftRight,entranceAngle);
1042 double docaErr_hit = 0.1 * myMdcCalibFunSvc->
getSigma(myLayer, myLeftRight, myDocaFromDigi, myEntranceAngle, myHelix_a[4], myPosOnWire[2], myCharge);
1044 myDriftDistErr[myLeftRight]=docaErr_hit;
1045 myDriftDistErr[1-myLeftRight] = 0.1 * myMdcCalibFunSvc->
getSigma(myLayer, 1-myLeftRight, myDocaFromDigi, myEntranceAngle, myHelix_a[4], myPosOnWire[2], myCharge);
1048 myDocaFromDigi*=signDoca;
1049 if(debug) cout<<
"doca_hit = "<<myDocaFromDigi<<endl;
1050 double delD = myDocaFromDigi-myDocaFromTrk;
1051 myDcChi = delD/docaErr_hit;
1432 double dr_fit = myHelix_a[0];
1433 double phi0_fit = myHelix_a[1];
1434 double kappa_fit= myHelix_a[2];
1445 vector< pair<double, double> > pos_hits;
1446 vector< pair<double, double> > CGEM_pos_hits;
1450 vector<const RecCgemCluster*>::iterator iter_cluster = myVecCgemCluster.begin();
1451 for(; iter_cluster!=myVecCgemCluster.end(); iter_cluster++, i_digi++)
1453 int layer = (*iter_cluster)->getlayerid();
1454 int flag = (*iter_cluster)->getflag();
1456 if(flag!=0)
continue;
1457 if(myCgemClusterIsActive[i_digi]!=1)
continue;
1458 double phi_cluster = (*iter_cluster)->getrecphi();
1459 pair<double, double> aHitPos(myRmidDGapCgem[layer]*
cos(phi_cluster), myRmidDGapCgem[layer]*
sin(phi_cluster));
1460 pos_hits.push_back(aHitPos);
1464 CGEM_pos_hits=pos_hits;
1469 vector<int> vecLayer, vecWire;
1470 int nDigi = myVecMdcDigi.size();
1471 vecLayer.resize(nDigi);
1472 vecWire.resize(nDigi);
1473 bool layerFilled=
false;
1474 double converged=-1.0;
1475 double lastChi2=-99.0;
1476 double last2Chi2=-99.0;
1478 myNActiveOuterXHits=0;
1481 pos_hits=CGEM_pos_hits;
1483 for(
int i=0; i<43; i++) myNumMdcDigiPerLayer[i]=0;
1485 myMapFlylenIdx.clear();
1501 double phi_trk, phi_clu;
1503 iter_cluster = myVecCgemCluster.begin();
1504 for(; iter_cluster!=myVecCgemCluster.end(); iter_cluster++, i_digi++)
1506 int layer = (*iter_cluster)->getlayerid();
1507 int flag = (*iter_cluster)->getflag();
1509 if(flag!=0)
continue;
1510 if(myCgemClusterIsActive[i_digi]!=1)
continue;
1512 if(fabs(dphi)<1e-10) {
1513 myChiVecCgemCluster[i_digi]=-9999;
1514 if(debug) cout<<
"trk has no intersection with CGEM layer "<<layer<<endl;
1517 pos = myHelix->
x(dphi);
1518 myFlightLength = fabs(dphi*myHelix->
radius());
1519 myMapFlylenIdx[myFlightLength]=-(i_digi+1);
1521 phi_trk = pos.phi();
1522 phi_clu = (*iter_cluster)->getrecphi();
1523 double del_phi = phi_clu-phi_trk;
1524 if(del_phi<-M_PI||del_phi>
M_PI) del_phi=atan2(
sin(del_phi),
cos(del_phi));
1529 Q=(*iter_cluster)->getenergydeposit();
1530 Hep3Vector p3_trk = myHelix->
momentum(dphi);
1531 double phi_p3trk = p3_trk.phi();
1532 double incidentPhi = phi_p3trk-phi_trk;
1535 if(incidentPhi<-M_PI||incidentPhi>
M_PI) incidentPhi=atan2(
sin(incidentPhi),
cos(incidentPhi));
1536 double err_m=myCgemCalibSvc->
getSigma(layer,flag,mode,incidentPhi,Q,T)/10.;
1537 double chi_clu = del_X/err_m;
1538 if(debug) cout<<
"CGEM cluster "<<i_digi<<
", layer "<<layer
1539 <<
", phi_clu, phi_trk = "<<phi_clu<<
", "<<phi_trk
1540 <<
", del_phi="<<del_phi<<
", chi="<<chi_clu<<endl;
1541 myChiVecCgemCluster[i_digi]=chi_clu;
1542 totChi2+=chi_clu*chi_clu;
1547 std::vector<Hep2Vector> wirePos;
1548 vector<const MdcDigi*>::iterator iter_mdcDigi = myVecMdcDigi.begin();
1549 for(; iter_mdcDigi!=myVecMdcDigi.end(); iter_mdcDigi++, i_digi++)
1557 vecLayer[i_digi]=layer;
1558 vecWire[i_digi]=wire;
1562 myNumMdcDigiPerLayer[layer]++;
1565 double xpos(0), ypos(0);
1566 if(!useIniHelix&&n_iter==0)
1568 xpos=myEastPosWires[layer][wire][0];
1569 ypos=myEastPosWires[layer][wire][1];
1572 double phiLR = myPhiAmbiVecMdcDigi.at(i_digi);
1575 xpos += myDocaFromDigi*
cos(phiLR);
1576 ypos += myDocaFromDigi*
sin(phiLR);
1582 myMapFlylenIdx[myFlightLength]=i_digi;
1583 myChiVecMdcDigi[i_digi]=myDcChi;
1584 HepPoint3D newPivot(myEastPosWires[layer][wire][0],myEastPosWires[layer][wire][1],0);
1585 aHelix.
pivot(newPivot);
1586 double phi0_new = aHelix.
phi0();
1587 double dr_new = aHelix.
dr();
1588 double d_measured = myDriftDist[myLeftRight];
1590 double phiLR = myPhiAmbiVecMdcDigi.at(i_digi);
1591 double dphi =
dPhi(phi0_new,phiLR);
1592 if(fabs(dphi)>0.5*
M_PI) phi0_new+=
M_PI;
1595 d_measured=dr_new/fabs(dr_new)*d_measured;
1597 xpos = myEastPosWires[layer][wire][0]+d_measured*
cos(phi0_new);
1598 ypos = myEastPosWires[layer][wire][1]+d_measured*
sin(phi0_new);
1600 if(myWireFlag[layer]!=0)
continue;
1601 if(layer<layerMin||layer>layerMax)
continue;
1603 if(layer>=36) myNOuterXHits++;
1604 else myNInnerXHits++;
1606 if(myMdcDigiIsActive[i_digi]!=1)
continue;
1609 wirePos.push_back(Hep2Vector(myEastPosWires[layer][wire][0],myEastPosWires[layer][wire][1]));
1613 pair<double, double> aHitPos(xpos,ypos);
1614 pos_hits.push_back(aHitPos);
1615 totChi2+=myDcChi*myDcChi;
1616 if(layer>=36) myNActiveOuterXHits++;
1621 if(pos_hits.size()<3) {
1622 if(debug) cout<<
"DotsHelixFitter::"<<__FUNCTION__<<
": N_xhits<3"<<endl;
1626 if(useExtraPoints&&(n_iter==0||myWireCrossPointPersistent)) {
1627 pos_hits.insert(pos_hits.end(), myExtraPoints.begin(), myExtraPoints.end() );
1632 cout<<
" Taubin not converge after "<< n_iter<<
" iterations "<<endl;
1633 cout<<
" Circle par from last Taubin fit: "<<a[0]
1642 double dPhi0=phi0_fit-a(2);
1643 dPhi0=fabs(atan2(
sin(dPhi0),
cos(dPhi0)));
1644 double dKappa=fabs((kappa_fit-a(3))/kappa_fit);
1646 if(n_iter>90)
if(debug) cout<<
"diff: "<<dr_fit-a(1)<<
", "<<dPhi0<<
", "<<dKappa<<
", "<<lastChi2-totChi2<<endl;
1647 if(fabs(dr_fit-a(1))<0.0001&&dPhi0<0.0001&&dKappa<0.0001&&(fabs(lastChi2-totChi2)<0.2||fabs(last2Chi2-totChi2)<0.2))
1649 if(debug) cout<<
"Taubin converges at iteration "<<n_iter<<endl;
1659 double xc_fit = par_new[0];
1660 double yc_fit = par_new[1];
1661 double r_fit = par_new[2];
1662 dr_fit = sqrt(xc_fit*xc_fit+yc_fit*yc_fit)-r_fit;
1663 phi0_fit = atan2(yc_fit,xc_fit);
1664 kappa_fit= myAlpha/r_fit;
1666 double xmean = par_new[4];
1667 double ymean = par_new[5];
1668 Hep3Vector pos_mean(xmean, ymean);
1669 Hep3Vector pos_center(xc_fit, yc_fit);
1670 Hep3Vector vec_z=pos_mean.cross(pos_center);
1671 double charge=vec_z.z()/fabs(vec_z.z());
1676 kappa_fit = -kappa_fit;
1678 while(phi0_fit< 0 ) phi0_fit+=2*
M_PI;
1679 while(phi0_fit> 2*
M_PI) phi0_fit-=2*
M_PI;
1680 if(debug) cout<<
"iter "<<n_iter<<
", circlr par = "<<dr_fit<<
", "<<phi0_fit<<
", "<<kappa_fit<<
", chi2 = "<<totChi2<<
" , circle aka center=("<<xc_fit<<
","<<yc_fit<<
"), radius = "<<r_fit<<endl;
1683 cout<<
"\twirePos: ";
1684 for (
size_t i=0; i<wirePos.size(); i++){
1685 cout<<wirePos[i]<<
" ";
1688 cout<<
"\tusedPos: ";
1689 for (
size_t i=0; i<pos_hits.size();i++){
1690 cout<<
"("<<pos_hits[i].first<<
","<<pos_hits[i].second<<
") ";
1697 myNActiveHits=pos_hits.size();
1700 if(debug) cout<<setw(20)<<
"hit chi (fitted): ";
1703 iter_cluster = myVecCgemCluster.begin();
1704 for(; iter_cluster!=myVecCgemCluster.end(); iter_cluster++, i_digi++)
1706 int layer = (*iter_cluster)->getlayerid();
1707 int flag = (*iter_cluster)->getflag();
1709 if(flag!=0)
continue;
1710 if(debug) cout<<
" "<<myChiVecCgemCluster[i_digi]<<
"("<<myCgemClusterIsActive[i_digi]<<
")Cgem"<<layer;
1715 int n_idx=myMapFlylenIdx.size();
1716 map<double, int>::iterator iter_idx = myMapFlylenIdx.begin();
1721 for(; iter_idx!=myMapFlylenIdx.end(); iter_idx++, i_idx++)
1723 if(debug)
if(i_idx>0&&i_idx%4==0) cout<<endl<<setw(20)<<
" ";
1724 int i_hit = iter_idx->second;
1726 if(debug) cout<<
" (L"<<vecLayer[i_hit]<<
",W"<<vecWire[i_hit]<<
")Chi"<<myChiVecMdcDigi[i_hit]<<
"("<<myMdcDigiIsActive[i_hit]<<
")S"<<iter_idx->first;
1727 if(myMdcDigiIsActive[i_hit]<=0) gapSize++;
1729 if(gapMax<gapSize) gapMax=gapSize;
1730 if(gapSize>=2&&Stmp<Smax) Smax=Stmp;
1731 Stmp=iter_idx->first;
1736 if(gapMax<gapSize) gapMax=gapSize;
1737 if(gapSize>=2&&Stmp<Smax) Smax=Stmp;
1741 cout<<
"Smax="<<Smax<<endl;
1756 vector<double> par_fit;
1757 par_fit.push_back(dr_fit);
1758 par_fit.push_back(phi0_fit);
1759 par_fit.push_back(kappa_fit);
1760 par_fit.push_back(converged);