38 if(myIsInitialized)
return;
41 ISvcLocator* svcLocator = Gaudi::svcLocator();
43 StatusCode Cgem_sc=svcLocator->service(
"CgemGeomSvc", ISvc);
44 if(Cgem_sc.isSuccess()) myCgemGeomSvc=
dynamic_cast<CgemGeomSvc *
>(ISvc);
45 else cout<<
"DotsHelixFitter::initialize(): can not get CgemGeomSvc"<<endl;
48 cout<<
"DotsHelixFitter::initialize(): nLayerCgem!=3 !!!"<<endl;
51 for(
int i=0; i<nLayerCgem; i++)
56 myR2midDGapCgem[i]=pow(myRmidDGapCgem[i],2);
64 cout<<
"CGEM layer "<<i<<
": "
65 <<
" Rmid="<<myRmidDGapCgem[i]<<
" cm "
66 <<
" RV ="<<myRVCgem[i]<<
" cm "
67 <<
" RX ="<<myRXCgem[i]<<
" cm "
68 <<
" , stereo angle = "<<myAngStereoCgem[i]<<
" radian "
69 <<myNSheets[i]<<
" sheets"
77 StatusCode mdc_sc=svcLocator->service(
"MdcGeomSvc", ISvc2);
78 if(mdc_sc.isSuccess()) myMdcGeomSvc=
dynamic_cast<MdcGeomSvc *
>(ISvc2);
79 else cout<<
"DotsHelixFitter::initialize(): can not get MdcGeomSvc"<<endl;
81 if(nLayer!=43) cout<<
"DotsHelixFitter::initialize(): MDC nLayer = "<<nLayer<<
" !=43 !!!"<<endl;
82 for(
int i=0; i<nLayer; i++)
85 myRWires[i]=0.1*(aLayer->
Radius());
86 cout<<
"MDC layer "<<i<<
" R = "<<myRWires[i]<<endl;
88 if(nomShift>0) myWireFlag[i]=1;
89 else if(nomShift<0) myWireFlag[i]=-1;
91 int nWires=aLayer->
NCell();
93 for(
int j=0; j<nWires; j++)
97 double* aPointArray =
new double[3]{aPointEast.x(),aPointEast.y(),aPointEast.z()};
98 myWestPosWires[i].push_back(aPointArray);
100 aPointArray =
new double[3]{aPointWest.x(),aPointWest.y(),aPointWest.z()};
101 myEastPosWires[i].push_back(aPointArray);
102 HepPoint3D aPointMiddle = 0.5*(aPointEast+aPointWest);
103 aPointArray =
new double[3]{aPointMiddle.x(),aPointMiddle.y(),aPointMiddle.z()};
104 myPosWires[i].push_back(aPointArray);
106 myPhiWires[i].push_back(aPointMiddle.phi());
107 myTensionWires[i].push_back(aWire->
Tension());;
113 StatusCode sc = svcLocator->service(
"MdcCalibFunSvc", imdcCalibSvc);
114 if ( sc.isSuccess() ){
118 cout<<
"DotsHelixFitter::initialize(): can not get MdcCalibFunSvc"<<endl;
122 sc = svcLocator->service(
"CgemCalibFunSvc", myCgemCalibSvc);
123 if ( !(sc.isSuccess()) )
125 cout<<
"DotsHelixFitter::initialize(): can not get CgemCalibFunSvc"<<endl;
130 myAlpha=aHelix.
alpha();
132 myIsInitialized=
true;
135 sc = svcLocator->service(
"MdcUtilitySvc", myMdcUtilitySvc);
136 if ( !(sc.isSuccess()) )
138 cout<<
"DotsHelixFitter::initialize(): can not get MdcUtilitySvc"<<endl;
238 double tension = 9999.;
241 if(myFitCircleOnly) nPar=3;
245 for(
int i=0; i<43; i++) myNumMdcDigiPerLayer[i]=0;
248 int nXHits[3]={0,0,0}, nVHits[3]={0,0,0};
249 int nDigi=myVecMdcDigi.size();
251 vector<double> vec_zini(nDigi);
254 vector<const MdcDigi*>::iterator iter_mdcDigi = myVecMdcDigi.begin();
255 for(; iter_mdcDigi!=myVecMdcDigi.end(); iter_mdcDigi++, i_digi++)
264 if(myMdcDigiIsActive[i_digi]==1)
268 int hitFlag = myWireFlag[layer];
280 if(maxLayer<layer) maxLayer=layer;
281 int nHits = myNumMdcDigiPerLayer[layer];
283 myIdxMdcDigiNeighbour[layer][nHits]=i_digi;
284 myWireIdMdcDigiNeighbour[layer][nHits]=wire;
286 myNumMdcDigiPerLayer[layer]++;
290 double maxRTrk = farPoint.perp();
291 for(
int i=0; i<43; i++)
293 if(maxRTrk<myRWires[i]+2)
break;
294 if(myNumMdcDigiPerLayer[i]==2)
296 int wire_1 = myWireIdMdcDigiNeighbour[i][0];
297 int wire_2 = myWireIdMdcDigiNeighbour[i][1];
298 int delta_n =
abs(wire_1-wire_2);
303 ambi_1 = wire_1>wire_2? 1:-1;
304 ambi_2 = wire_1>wire_2? -1:1;
306 else if(delta_n==myNWire[i]-1)
308 ambi_1 = wire_1<=1? 1:-1;
309 ambi_2 = wire_2<=1? 1:-1;
325 vector<const RecCgemCluster*>::iterator iter_cluster = myVecCgemCluster.begin();
326 for(; iter_cluster!=myVecCgemCluster.end(); iter_cluster++, i_digi++)
328 int flag = (*iter_cluster)->getflag();
343 if(nXHits[0]<myMinXhitsInCircleFit)
return 1;
347 if((nXHits[0]+nVHits[0])<myMinHitsInHelixFit)
return 2;
348 if(nVHits[0]<myMinVhitsInHelixFit)
return 3;
355 double lastTotChi2 = 999999;
356 double secLastTotChi2 = 999999;
357 double thirdLastTotChi2 = 999999;
359 int n_chi2_increase = 0;
365 myMapFlylenIdx.clear();
367 HepSymMatrix U(nPar, 0);
371 HepMatrix
P(nPar,1,0);
372 HepMatrix J(nPar,1,0), JT(1,nPar,0);
373 HepMatrix J_dmdx(1,3,0), J_dxda(3,nPar,0);
378 vector<const MdcDigi*>::iterator iter_mdcDigi = myVecMdcDigi.begin();
379 for(; iter_mdcDigi!=myVecMdcDigi.end(); iter_mdcDigi++, i_digi++)
385 double charge = (*iter_mdcDigi)->getChargeChannel();
389 double wpos[7]={myEastPosWires[layer][wire][0], myEastPosWires[layer][wire][1], myEastPosWires[layer][wire][2]
390 , myWestPosWires[layer][wire][0], myWestPosWires[layer][wire][1], myWestPosWires[layer][wire][2], tension};
396 cout<<
"* layer "<<layer<<
", wire "<<wire<<
", is active "<<myMdcDigiIsActive[i_digi] <<endl;
400 getDoca(myHelix_a, wpos, doca_trk, whitPos, vec_zini[i_digi]);
408 leftRight=int(doca_trk/fabs(doca_trk));
416 signDoca=leftRight/fabs(leftRight);
419 if(leftRight==1) leftRight=0;
423 vec_zini[i_digi] = whitPos[2];
427 double tprop = myMdcCalibFunSvc->
getTprop(layer, vec_zini[i_digi]);
428 double T0Walk = myMdcCalibFunSvc->
getT0(layer,wire) + myMdcCalibFunSvc->
getTimeWalk(layer, charge);
432 HepPoint3D aNewPivot(whitPos[0],whitPos[1],whitPos[2]);
434 aHelix.
pivot(aNewPivot);
436 double newPhi0 = aHelix.
phi0();
438 double dphi = newPhi0-myHelix->
phi0();
442 if(dphi<-M_PI||dphi>
M_PI) dphi=atan2(
sin(dphi),
cos(dphi));
443 double flightLength = fabs(dphi*myHelix->
radius())*sqrt(1+myHelix->
tanl()*myHelix->
tanl());
445 myMapFlylenIdx[flightLength]=i_digi;
446 HepLorentzVector p4_pi = myHelix->
momentum(dphi, 0.13957);
447 double speed = p4_pi.beta()*
CC;
448 double TOF = flightLength/speed*1.e9;
451 double driftT = rawTime - myEventT0 - TOF - T0Walk - tprop;
454 double phiWire = atan2(whitPos[1],whitPos[0]);
455 double phiP = p4_pi.phi();
456 double entranceAngle = phiP-phiWire;
459 if(entranceAngle<-M_PI||entranceAngle>
M_PI) entranceAngle=atan2(
sin(entranceAngle),
cos(entranceAngle));
461 double doca_hit = 0.1 * myMdcCalibFunSvc->
driftTimeToDist(driftT,layer,wire,leftRight, entranceAngle);
463 double docaErr_hit = 0.1 * myMdcCalibFunSvc->
getSigma(layer, leftRight, doca_hit, entranceAngle, myHelix_a[4], vec_zini[i_digi], charge);
469 double delD = doca_hit-doca_trk;
470 double chi = delD/docaErr_hit;
471 if(debug) cout<<
"delta_m, err_m, chi = "<<delD<<
", "<<docaErr_hit<<
", "<<chi<<endl;
472 myChiVecMdcDigi[i_digi]=chi;
474 if(myMdcDigiIsActive[i_digi]!=1)
continue;
475 if(myUseAxialHitsOnly && myWireFlag[layer]!=0)
continue;
479 for(
int ipar=0; ipar<nPar; ipar++)
483 getDeriLoc(ipar,myHelix_a, deri, wpos, vec_zini[i_digi]);
489 P(ipar+1,1) += J(ipar+1,1)*(doca_hit-doca_trk)/(docaErr_hit*docaErr_hit*scale);
490 for(
int ipar2=0; ipar2<=ipar; ipar2++)
493 U(ipar+1,ipar2+1)+=J(ipar+1,1)*J(ipar2+1,1)/(docaErr_hit*docaErr_hit*scale);
498 if(debug) cout<<
"end of MDC hits loop"<<endl;
503 vector<const RecCgemCluster*>::iterator iter_cluster = myVecCgemCluster.begin();
504 for(; iter_cluster!=myVecCgemCluster.end(); iter_cluster++, i_digi++)
507 int layer = (*iter_cluster)->getlayerid();
508 int flag = (*iter_cluster)->getflag();
509 if(myUseAxialHitsOnly && flag!=0)
continue;
510 if(myUseMdcHitsOnly)
continue;
511 int sheet = (*iter_cluster)->getsheetid();
515 cout<<endl<<
"layer, sheet, flag = "<<setw(5)<<layer<<setw(5)<<sheet<<setw(5)<<flag<<endl;
520 if(fabs(dphi)<1e-10) {
521 myChiVecCgemCluster[i_digi]=-9999;
525 double flightLength = fabs(dphi*myHelix->
radius())*sqrt(1+myHelix->
tanl()*myHelix->
tanl());
526 myMapFlylenIdx[flightLength]=-(i_digi+1);
528 if(debug) cout<<
"dphi="<<dphi<<
", pos="<<pos<<endl;
529 double phi_trk = pos.phi();
530 double z_trk = pos.z();
532 Hep3Vector p3_trk = myHelix->
momentum(dphi);
533 double phi_p3trk = p3_trk.phi();
534 double incidentPhi = phi_p3trk-phi_trk;
537 if(incidentPhi<-M_PI||incidentPhi>
M_PI) incidentPhi=atan2(
sin(incidentPhi),
cos(incidentPhi));
541 double X_CC(0.), V_CC(0.);
542 double delta_m, err_m;
546 Q=(*iter_cluster)->getenergydeposit();
548 phi_CC = (*iter_cluster)->getrecphi();
550 double del_phi = phi_CC-phi_trk;
553 if(del_phi<-M_PI||del_phi>
M_PI) del_phi=atan2(
sin(del_phi),
cos(del_phi));
554 X_CC=phi_CC*myRmidDGapCgem[layer];
555 if(debug) cout<<
"phi_trk, phi_rec = "<<phi_trk<<
", "<<phi_CC<<endl;
559 err_m=myCgemCalibSvc->
getSigma(layer,flag,mode,incidentPhi,Q,T)/10.;
560 err_m/=myRmidDGapCgem[layer];
561 J_dmdx(1,1)=-1*pos.y()/myR2midDGapCgem[layer];
562 J_dmdx(1,2)=pos.x()/myR2midDGapCgem[layer];
566 double V_trk = readoutPlane->
getVFromPhiZ(phi_trk,z_trk*10,
false)/10.0;
567 V_CC=(*iter_cluster)->getrecv()/10.;
569 if(debug) cout<<
"V_trk, V_rec = "<<V_trk<<
", "<<V_CC<<endl;
571 if(fabs(delta_m)>5) {
580 double delta_m_2=V_CC-V_trk_nearPhiMin;
581 if(fabs(delta_m_2)<fabs(delta_m)) delta_m=delta_m_2;
582 if(debug) cout<<
"V_trk_nearPhiMin= "<<V_trk_nearPhiMin<<endl;
584 err_m=myCgemCalibSvc->
getSigma(layer,flag,mode,incidentPhi,Q,T)/10.;
585 J_dmdx(1,1)=-myRVCgem[layer]*
cos(myAngStereoCgem[layer])*pos.y()/myR2midDGapCgem[layer];
586 J_dmdx(1,2)= myRVCgem[layer]*
cos(myAngStereoCgem[layer])*pos.x()/myR2midDGapCgem[layer];
587 J_dmdx(1,3)= -
sin(myAngStereoCgem[layer]);
590 cout<<
"flag ="<<flag<<
", DotsHelixFitter::calculateNewHelix() is not ready for it!"<<endl;
600 double chi = delta_m/err_m;
601 myChiVecCgemCluster[i_digi]=chi;
602 if(debug) cout<<
"delta_m, err_m, chi = "<<delta_m<<
", "<<err_m<<
", "<<chi<<endl;
605 for(
int ipar=0; ipar<nPar; ipar++)
609 P(ipar+1,1) += J(ipar+1,1)*chi/err_m;
610 for(
int ipar2=0; ipar2<=ipar; ipar2++)
612 U(ipar+1,ipar2+1)+=J(ipar+1,1)*J(ipar2+1,1)/(err_m*err_m);
615 if(debug) cout<<
"U="<<U<<endl;
618 cout<<
"end of CGEM cluster loop"<<endl;
635 for(
int ipar=0; ipar<nPar; ipar++)
637 myHelix_a[ipar]+=da[ipar];
638 if(ipar==1&&(myHelix_a[ipar]>2*
M_PI||myHelix_a[ipar]<0))
640 double aphi=myHelix_a[ipar];
641 aphi=atan2(
sin(aphi),
cos(aphi));
642 if(aphi<0) aphi+=2*
M_PI;
643 myHelix_a[ipar]=aphi;
645 myHelix_aVec[ipar]=myHelix_a[ipar];
647 myHelix->
a(myHelix_aVec);
650 cout<<
"aNew = "<<myHelix_aVec
651 <<
" chi2 = "<<totChi2
659 if(debug) cout<<
" iteration "<<nIterations<<
", chi2="<<totChi2<<endl;
660 if(fabs(lastTotChi2-totChi2)<myDchi2Converge) {
662 cout<<
"DotsHelixFitter::calculateNewHelix(): converge after "<<nIterations<<
" iterations"
663 <<
" with lastTotChi2="<<lastTotChi2<<
", totChi2="<<totChi2
673 else if(totChi2-lastTotChi2>myDchi2Diverge) {
675 if(n_chi2_increase>myMaxNChi2Increase||totChi2>myChi2Diverge)
678 if( nIterations>3 && fabs(secLastTotChi2-totChi2)<(0.1*myDchi2Converge) && fabs(thirdLastTotChi2-lastTotChi2)<(0.1*myDchi2Converge) ) {
681 if(n_oscillation>0&&totChi2<lastTotChi2) {
686 if(debug) cout<<
"DotsHelixFitter::calculateNewHelix(): oscillation happened, thirdLastTotChi2, secLastTotChi2, lastTotChi2 = "<<thirdLastTotChi2<<
", "<<secLastTotChi2<<
", "<<lastTotChi2<<endl;
690 if(nIterations>myMaxIteration) {
691 if(debug) cout<<
"DotsHelixFitter::calculateNewHelix(): "<<nIterations
692 <<
" iterations, break with lastTotChi2, totChi2 = "<<lastTotChi2<<
", "<<totChi2<<endl;
696 thirdLastTotChi2=secLastTotChi2;
697 secLastTotChi2=lastTotChi2;
940 getDoca(myHelix_a, myWirePos, myDocaFromTrk, myPosOnWire, myPosOnWire[2]);
941 double phiWire = atan2(myPosOnWire[1],myPosOnWire[0]);
944 cout<<
"DotsHelixFitter::UpdateDcDigiInfo(): "<<endl;
945 cout<<
"doca = "<<myDocaFromTrk<<endl;
946 cout<<
"point on wire: "<<myPosOnWire[0]<<
", "<<myPosOnWire[1]<<
", "<<myPosOnWire[2]<<endl;
951 HepPoint3D aNewPivot(myPosOnWire[0],myPosOnWire[1],myPosOnWire[2]);
952 aHelix.
pivot(aNewPivot);
953 double newPhi0 = aHelix.
phi0();
954 double dphi = newPhi0-myHelix->
phi0();
957 if(dphi<-M_PI||dphi>
M_PI) dphi=atan2(
sin(dphi),
cos(dphi));
958 myFlightLength = fabs(dphi*myHelix->
radius())*sqrt(1+myHelix->
tanl()*myHelix->
tanl());
962 myPosOnTrk[0]=posOnTrk.x();
963 myPosOnTrk[1]=posOnTrk.y();
964 myPosOnTrk[2]=posOnTrk.z();
965 double phiPosOnTrk=atan2(myPosOnTrk[1],myPosOnTrk[0]);
972 myLeftRight=int(myDocaFromTrk/fabs(myDocaFromTrk));
973 signDoca=myLeftRight;
977 if(myLeftRight==1) myLeftRight=0;
979 double dphiLR=phiWire-phiPosOnTrk;
982 if(dphiLR<-M_PI||dphiLR>
M_PI) dphiLR=atan2(
sin(dphiLR),
cos(dphiLR));
987 if(debug) cout<<
"myLeftRight = "<<myLeftRight<<endl;
990 HepLorentzVector p4_pi = myHelix->
momentum(dphi, 0.13957);
991 double speed = p4_pi.beta()*
CC;
992 double TOF = myFlightLength/speed*1.e9;
996 double tprop = myMdcCalibFunSvc->
getTprop(myLayer, myPosOnWire[2]);
997 double T0Walk = myMdcCalibFunSvc->
getT0(myLayer,myWire) + myMdcCalibFunSvc->
getTimeWalk(myLayer, myCharge);
1000 myDriftTime = rawTime - myEventT0 - TOF - T0Walk - tprop;
1001 if(debug) cout<<
"driftT = "<<myDriftTime<<endl;
1003 double phiP = p4_pi.phi();
1004 double entranceAngle = phiP-phiWire;
1007 if(entranceAngle<-M_PI||entranceAngle>
M_PI) entranceAngle=atan2(
sin(entranceAngle),
cos(entranceAngle));
1008 myEntranceAngle = entranceAngle;
1010 myDocaFromDigi = 0.1 * myMdcCalibFunSvc->
driftTimeToDist(myDriftTime,myLayer,myWire,myLeftRight,entranceAngle);
1011 myDriftDist[myLeftRight]=myDocaFromDigi;
1012 myDriftDist[1-myLeftRight]=0.1 * myMdcCalibFunSvc->
driftTimeToDist(myDriftTime,myLayer,myWire,1-myLeftRight,entranceAngle);
1014 double docaErr_hit = 0.1 * myMdcCalibFunSvc->
getSigma(myLayer, myLeftRight, myDocaFromDigi, myEntranceAngle, myHelix_a[4], myPosOnWire[2], myCharge);
1016 myDriftDistErr[myLeftRight]=docaErr_hit;
1017 myDriftDistErr[1-myLeftRight] = 0.1 * myMdcCalibFunSvc->
getSigma(myLayer, 1-myLeftRight, myDocaFromDigi, myEntranceAngle, myHelix_a[4], myPosOnWire[2], myCharge);
1020 myDocaFromDigi*=signDoca;
1021 if(debug) cout<<
"doca_hit = "<<myDocaFromDigi<<endl;
1022 double delD = myDocaFromDigi-myDocaFromTrk;
1023 myDcChi = delD/docaErr_hit;
1403 double dr_fit = myHelix_a[0];
1404 double phi0_fit = myHelix_a[1];
1405 double kappa_fit= myHelix_a[2];
1416 vector< pair<double, double> > pos_hits;
1417 vector< pair<double, double> > CGEM_pos_hits;
1421 vector<const RecCgemCluster*>::iterator iter_cluster = myVecCgemCluster.begin();
1422 for(; iter_cluster!=myVecCgemCluster.end(); iter_cluster++, i_digi++)
1424 int layer = (*iter_cluster)->getlayerid();
1425 int flag = (*iter_cluster)->getflag();
1427 if(flag!=0)
continue;
1428 if(myCgemClusterIsActive[i_digi]!=1)
continue;
1429 double phi_cluster = (*iter_cluster)->getrecphi();
1430 pair<double, double> aHitPos(myRmidDGapCgem[layer]*
cos(phi_cluster), myRmidDGapCgem[layer]*
sin(phi_cluster));
1431 pos_hits.push_back(aHitPos);
1435 CGEM_pos_hits=pos_hits;
1440 vector<int> vecLayer, vecWire;
1441 int nDigi = myVecMdcDigi.size();
1442 vecLayer.resize(nDigi);
1443 vecWire.resize(nDigi);
1444 bool layerFilled=
false;
1446 double lastChi2=-99.0;
1447 double last2Chi2=-99.0;
1449 myNActiveOuterXHits=0;
1452 pos_hits=CGEM_pos_hits;
1454 for(
int i=0; i<43; i++) myNumMdcDigiPerLayer[i]=0;
1456 myMapFlylenIdx.clear();
1472 double phi_trk, phi_clu;
1474 iter_cluster = myVecCgemCluster.begin();
1475 for(; iter_cluster!=myVecCgemCluster.end(); iter_cluster++, i_digi++)
1477 int layer = (*iter_cluster)->getlayerid();
1478 int flag = (*iter_cluster)->getflag();
1480 if(flag!=0)
continue;
1481 if(myCgemClusterIsActive[i_digi]!=1)
continue;
1483 if(fabs(dphi)<1e-10) {
1484 myChiVecCgemCluster[i_digi]=-9999;
1485 if(debug) cout<<
"trk has no intersection with CGEM layer "<<layer<<endl;
1488 pos = myHelix->
x(dphi);
1489 myFlightLength = fabs(dphi*myHelix->
radius());
1490 myMapFlylenIdx[myFlightLength]=-(i_digi+1);
1492 phi_trk = pos.phi();
1493 phi_clu = (*iter_cluster)->getrecphi();
1494 double del_phi = phi_clu-phi_trk;
1495 if(del_phi<-M_PI||del_phi>
M_PI) del_phi=atan2(
sin(del_phi),
cos(del_phi));
1500 Q=(*iter_cluster)->getenergydeposit();
1501 Hep3Vector p3_trk = myHelix->
momentum(dphi);
1502 double phi_p3trk = p3_trk.phi();
1503 double incidentPhi = phi_p3trk-phi_trk;
1506 if(incidentPhi<-M_PI||incidentPhi>
M_PI) incidentPhi=atan2(
sin(incidentPhi),
cos(incidentPhi));
1507 double err_m=myCgemCalibSvc->
getSigma(layer,flag,mode,incidentPhi,Q,T)/10.;
1508 double chi_clu = del_X/err_m;
1509 if(debug) cout<<
"CGEM cluster "<<i_digi<<
", layer "<<layer
1510 <<
", phi_clu, phi_trk = "<<phi_clu<<
", "<<phi_trk
1511 <<
", del_phi="<<del_phi<<
", chi="<<chi_clu<<endl;
1512 myChiVecCgemCluster[i_digi]=chi_clu;
1513 totChi2+=chi_clu*chi_clu;
1518 std::vector<Hep2Vector> wirePos;
1519 vector<const MdcDigi*>::iterator iter_mdcDigi = myVecMdcDigi.begin();
1520 for(; iter_mdcDigi!=myVecMdcDigi.end(); iter_mdcDigi++, i_digi++)
1528 vecLayer[i_digi]=layer;
1529 vecWire[i_digi]=wire;
1533 myNumMdcDigiPerLayer[layer]++;
1536 double xpos(0), ypos(0);
1537 if(!useIniHelix&&n_iter==0)
1539 xpos=myEastPosWires[layer][wire][0];
1540 ypos=myEastPosWires[layer][wire][1];
1543 double phiLR = myPhiAmbiVecMdcDigi.at(i_digi);
1546 xpos += myDocaFromDigi*
cos(phiLR);
1547 ypos += myDocaFromDigi*
sin(phiLR);
1553 myMapFlylenIdx[myFlightLength]=i_digi;
1554 myChiVecMdcDigi[i_digi]=myDcChi;
1555 HepPoint3D newPivot(myEastPosWires[layer][wire][0],myEastPosWires[layer][wire][1],0);
1556 aHelix.
pivot(newPivot);
1557 double phi0_new = aHelix.
phi0();
1558 double dr_new = aHelix.
dr();
1559 double d_measured = myDriftDist[myLeftRight];
1561 double phiLR = myPhiAmbiVecMdcDigi.at(i_digi);
1562 double dphi =
dPhi(phi0_new,phiLR);
1563 if(fabs(dphi)>0.5*
M_PI) phi0_new+=
M_PI;
1566 d_measured=dr_new/fabs(dr_new)*d_measured;
1568 xpos = myEastPosWires[layer][wire][0]+d_measured*
cos(phi0_new);
1569 ypos = myEastPosWires[layer][wire][1]+d_measured*
sin(phi0_new);
1571 if(myWireFlag[layer]!=0)
continue;
1572 if(layer<layerMin||layer>layerMax)
continue;
1574 if(layer>=36) myNOuterXHits++;
1575 else myNInnerXHits++;
1577 if(myMdcDigiIsActive[i_digi]!=1)
continue;
1580 wirePos.push_back(Hep2Vector(myEastPosWires[layer][wire][0],myEastPosWires[layer][wire][1]));
1584 pair<double, double> aHitPos(xpos,ypos);
1585 pos_hits.push_back(aHitPos);
1586 totChi2+=myDcChi*myDcChi;
1587 if(layer>=36) myNActiveOuterXHits++;
1592 if(pos_hits.size()<3) {
1593 if(debug) cout<<
"DotsHelixFitter::"<<__FUNCTION__<<
": N_xhits<3"<<endl;
1596 if(useExtraPoints&&(n_iter==0||myWireCrossPointPersistent)) {
1597 pos_hits.insert(pos_hits.end(), myExtraPoints.begin(), myExtraPoints.end() );
1601 cout<<
" Taubin not converge after "<< n_iter<<
" iterations "<<endl;
1602 cout<<
" Circle par from last Taubin fit: "<<a[0]
1610 double dPhi0=phi0_fit-a(2);
1611 dPhi0=fabs(atan2(
sin(dPhi0),
cos(dPhi0)));
1612 double dKappa=fabs((kappa_fit-a(3))/kappa_fit);
1614 if(n_iter>90)
if(debug) cout<<
"diff: "<<dr_fit-a(1)<<
", "<<dPhi0<<
", "<<dKappa<<
", "<<lastChi2-totChi2<<endl;
1615 if(fabs(dr_fit-a(1))<0.0001&&dPhi0<0.0001&&dKappa<0.0001&&(fabs(lastChi2-totChi2)<0.2||fabs(last2Chi2-totChi2)<0.2))
1617 if(debug) cout<<
"Taubin converges at iteration "<<n_iter<<endl;
1626 double xc_fit = par_new[0];
1627 double yc_fit = par_new[1];
1628 double r_fit = par_new[2];
1629 dr_fit = sqrt(xc_fit*xc_fit+yc_fit*yc_fit)-r_fit;
1630 phi0_fit = atan2(yc_fit,xc_fit);
1631 kappa_fit= myAlpha/r_fit;
1633 double xmean = par_new[4];
1634 double ymean = par_new[5];
1635 Hep3Vector pos_mean(xmean, ymean);
1636 Hep3Vector pos_center(xc_fit, yc_fit);
1637 Hep3Vector vec_z=pos_mean.cross(pos_center);
1638 double charge=vec_z.z()/fabs(vec_z.z());
1643 kappa_fit = -kappa_fit;
1645 while(phi0_fit< 0 ) phi0_fit+=2*
M_PI;
1646 while(phi0_fit> 2*
M_PI) phi0_fit-=2*
M_PI;
1647 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;
1650 cout<<
"\twirePos: ";
1651 for (
size_t i=0; i<wirePos.size(); i++){
1652 cout<<wirePos[i]<<
" ";
1655 cout<<
"\tusedPos: ";
1656 for (
size_t i=0; i<pos_hits.size();i++){
1657 cout<<
"("<<pos_hits[i].first<<
","<<pos_hits[i].second<<
") ";
1664 myNActiveHits=pos_hits.size();
1667 if(debug) cout<<setw(20)<<
"hit chi (fitted): ";
1670 iter_cluster = myVecCgemCluster.begin();
1671 for(; iter_cluster!=myVecCgemCluster.end(); iter_cluster++, i_digi++)
1673 int layer = (*iter_cluster)->getlayerid();
1674 int flag = (*iter_cluster)->getflag();
1676 if(flag!=0)
continue;
1677 if(debug) cout<<
" "<<myChiVecCgemCluster[i_digi]<<
"("<<myCgemClusterIsActive[i_digi]<<
")Cgem"<<layer;
1682 int n_idx=myMapFlylenIdx.size();
1683 map<double, int>::iterator iter_idx = myMapFlylenIdx.begin();
1688 for(; iter_idx!=myMapFlylenIdx.end(); iter_idx++, i_idx++)
1690 if(debug)
if(i_idx>0&&i_idx%4==0) cout<<endl<<setw(20)<<
" ";
1691 int i_hit = iter_idx->second;
1693 if(debug) cout<<
" (L"<<vecLayer[i_hit]<<
",W"<<vecWire[i_hit]<<
")Chi"<<myChiVecMdcDigi[i_hit]<<
"("<<myMdcDigiIsActive[i_hit]<<
")S"<<iter_idx->first;
1694 if(myMdcDigiIsActive[i_hit]<=0) gapSize++;
1696 if(gapMax<gapSize) gapMax=gapSize;
1697 if(gapSize>=2&&Stmp<Smax) Smax=Stmp;
1698 Stmp=iter_idx->first;
1703 if(gapMax<gapSize) gapMax=gapSize;
1704 if(gapSize>=2&&Stmp<Smax) Smax=Stmp;
1708 cout<<
"Smax="<<Smax<<endl;
1723 vector<double> par_fit;
1724 par_fit.push_back(dr_fit);
1725 par_fit.push_back(phi0_fit);
1726 par_fit.push_back(kappa_fit);