1 #include "StFgtStraightTrackMaker.h"
3 #include "StRoot/StEvent/StFgtCollection.h"
4 #include "StRoot/StEvent/StFgtHitCollection.h"
5 #include "StRoot/StEvent/StFgtHit.h"
6 #include "StRoot/StFgtUtil/geometry/StFgtGeom.h"
7 #include "StRoot/StEvent/StEvent.h"
8 #include "StRoot/StEvent/StEventInfo.h"
9 #include "StRoot/StFgtUtil/geometry/StFgtGeom.h"
11 #include "StMuDSTMaker/COMMON/StMuDstMaker.h"
12 #include "StMuDSTMaker/COMMON/StMuPrimaryVertex.h"
13 #include "StMuDSTMaker/COMMON/StMuDst.h"
14 #include "StMuDSTMaker/COMMON/StMuEvent.h"
15 #include "StarClassLibrary/StThreeVectorF.hh"
32 #include "StFgtCosmicAlignment.h"
33 #define CHARGE_MEASURE clusterCharge
34 #include "StRoot/StFgtUtil/geometry/StFgtGeom.h"
38 #include "StRoot/StEvent/StEvent.h"
39 #include "StRoot/StEvent/StFgtCollection.h"
43 #define MAX_CHARGE_RATIO
44 #define MIN_CHARGE_RATIO
47 #define MY_PI 3.14159265359
50 #define NUM_EFF_BIN 100
60 for(
float z=-100;z<100;z=z+zStep)
62 float x=it->mx*z+it->ax;
63 float y=it->my*z+it->ay;
75 return pair<double,double>(optZ,sqrt(dist));
81 pair<Double_t,Double_t> StFgtStraightTrackMaker::findCluChargeSize(Int_t iD,Char_t layer, Double_t ordinate)
85 return pair<Double_t,Double_t>(-99999,-99999);
87 vector<generalCluster> &hitVec=*(pClusters[iD]);
88 Double_t charge=-99999;
89 Double_t cluSize=-9999;
90 Double_t minDist=99999;
91 for(vector<generalCluster>::iterator it=hitVec.begin();it!=hitVec.end();it++)
103 if(fabs(ordinate-(ord+MY_PI))<fabs(ord-ordinate))
105 if(fabs(ordinate-(ord-MY_PI))<fabs(ord-ordinate))
109 if((fabs(ordinate-ord)<minDist) && (!useChargeMatch || it->hasMatch))
111 charge=it->clusterCharge;
112 cluSize=it->clusterSize;
113 minDist=fabs(ordinate-ord);
116 return pair<Double_t,Double_t>(charge,cluSize);
126 vector<generalCluster> &hitVec=*(pClusters[iD]);
127 Double_t dist2=99999;
128 for(vector<generalCluster>::iterator it=hitVec.begin();it!=hitVec.end();it++)
130 for(vector<generalCluster>::iterator it2=hitVec.begin();it2!=hitVec.end();it2++)
133 if(useChargeMatch && !StFgtGeneralBase::arePointsMatched(it,it2))
136 if(it->layer==it2->layer)
139 Float_t phi=it2->posPhi;
146 Float_t x=r*cos(phi);
147 Float_t y=r*sin(phi);
149 Double_t mDist=(x-xE)*(x-xE)+(y-yE)*(y-yE);
154 float tmpX, tmpY,tmpZ,tmpP,tmpR;
158 getAlign(iD,phi,r,tmpX,tmpY,tmpZ,tmpP,tmpR);
159 Double_t xExpUpdate=mx*tmpZ+bx;
160 Double_t yExpUpdate=my*tmpZ+by;
163 mDist=(tmpX-xExpUpdate)*(tmpX-xExpUpdate)+(tmpY-yExpUpdate)*(tmpY-yExpUpdate);
183 cout <<
"do not use this function!!!" <<endl;
198 pair<Double_t,Double_t> StFgtStraightTrackMaker::getChargeRatio(Float_t r, Float_t phi, Int_t iD, Int_t iq)
201 Double_t maxRCharge=-9999;
202 Double_t maxPhiCharge=-9999;
205 for(
unsigned int i=0;i< pStrips[iD*4+iq].size();i++)
207 Int_t geoId=pStrips[iD*4+iq][i].geoId;
209 Short_t disc, quadrant,strip;
211 Double_t ordinate, lowerSpan, upperSpan;
212 StFgtGeom::getPhysicalCoordinate(geoId,disc,quadrant,layer,ordinate,lowerSpan,upperSpan);
213 StFgtGeom::decodeGeoId(geoId,disc, quadrant, layer, strip);
216 if(disc==iD && iq==quadrant && ((layer ==
'R' && fabs(ordinate-r)<0.7) || (layer==
'P' && fabs(ordinate-phi)<0.03) || (layer==
'P' && fabs(ordinate-phi+2*MY_PI)<0.03 ) || (layer==
'P' && fabs(ordinate-phi-2*MY_PI)<0.03)|| (layer==
'P' && fabs(ordinate-phi+MY_PI)<0.03 ) || (layer==
'P' && fabs(ordinate-phi-MY_PI)<0.03)))
220 if(pStrip.charge>maxPhiCharge)
222 maxPhiCharge=pStrip.charge;
228 if(pStrip.charge>maxRCharge)
230 maxRCharge=pStrip.charge;
236 if(maxRInd>=0 && maxPInd>=0)
238 if(maxRCharge>1000 && maxPhiCharge>1000)
242 maxRCharge+=pStrips[iD*4+iq][maxRInd-1].charge;
243 if(maxRInd< (
int)(pStrips[iD*4+iq].size()-1))
244 maxRCharge+=pStrips[iD*4+iq][maxRInd+1].charge;
246 maxPhiCharge+=pStrips[iD*4+iq][maxPInd-1].charge;
247 if(maxPInd< (
int)(pStrips[iD*4+iq].size()-1))
248 maxPhiCharge+=pStrips[iD*4+iq][maxPInd+1].charge;
250 return pair<Double_t,Double_t>(maxRCharge,maxPhiCharge);
254 return pair<Double_t,Double_t>(-9999,-9999);
267 Int_t vtxRank=fgtGenMkr->vtxRank;
268 vector<AVPoint>::iterator iter=points.begin();
269 Double_t A = 0, B = 0, Cx = 0, Cy = 0, D = 0, Ex = 0, Ey = 0;
278 float tmpX, tmpY,tmpZ,tmpP,tmpR;
279 for( ; iter != points.end(); ++iter ){
280 getAlign(iter->dID,iter->phi,iter->r,tmpX,tmpY,tmpZ,tmpP,tmpR);
296 for( iter=points.begin(); iter != points.end(); ++iter ){
298 Double_t x = iter->x;
299 Double_t y = iter->y;
300 Double_t z = iter->z;
319 if(isMuDst && vtxRank>0&&ipZ>-100 && ipZ<100)
321 cout <<
"fit with vertex!!" <<endl;
328 Double_t denom = D*A - B*B;
331 Double_t bx = (-B*Cx + A*Ex)/denom;
332 Double_t by = (-B*Cy + A*Ey)/denom;
333 Double_t mx = ( D*Cx - B*Ex)/denom;
334 Double_t my = ( D*Cy - B*Ey)/denom;
338 vector<AVPoint> redPoints;
340 for(
int iDx=0;iDx<6;iDx++)
342 Double_t minDistance=9999;
345 for( iter = points.begin(); iter != points.end(); ++iter ){
347 Double_t distX=fabs((iter->z*mx+bx)-(iter->x));
348 Double_t distY=fabs((iter->z*my+by)-(iter->y));
350 Double_t distance=distX*distX+distY*distY;
352 if((iDx==dId)&&(distance<minDistance))
354 minDistance=distance;
363 redPoints.push_back(points[pointIdx]);
378 for(vector<AVPoint>::iterator iterR=redPoints.begin() ; iterR != redPoints.end(); ++iterR )
380 Double_t x = iterR->x;
381 Double_t y = iterR->y;
382 Double_t z = iterR->z;
391 D = redPoints.size();
392 if(doRefitWithVertex)
394 if(isMuDst && vtxRank>0&&ipZ>-100 && ipZ<100)
396 cout <<
"refit with vertex! " <<endl;
403 Double_t denom = D*A - B*B;
407 bx = (-B*Cx + A*Ex)/denom;
408 by = (-B*Cy + A*Ey)/denom;
409 mx = ( D*Cx - B*Ex)/denom;
410 my = ( D*Cy - B*Ey)/denom;
415 for(vector<AVPoint>::iterator iterR = redPoints.begin(); iterR != redPoints.end(); ++iterR )
417 Double_t distX, distY;
418 distX=fabs((iterR->z*mx+bx)-(iterR->x));
419 distY=fabs((iterR->z*my+by)-(iterR->y));
421 dist += (distX*distX+distY*distY);
429 m_tracks.push_back(
AVTrack(mx,my,bx,by,ipZ,dist));
431 (m_tracks.back()).vtxRank=vtxRank;
433 for(vector<AVPoint>::iterator it=redPoints.begin();it!=redPoints.end();it++)
435 points.push_back(*it);
438 for(vector<AVPoint>::iterator iter = points.begin(); iter != points.end(); ++iter ){
447 vector<AVTrack>::iterator it_lastTrack=m_tracks.end();
449 pair<double,double> dca=
getDca(it_lastTrack);
450 Double_t vertZ = ( -( it_lastTrack->mx*it_lastTrack->ax + it_lastTrack->my*it_lastTrack->ay )/(it_lastTrack->mx*it_lastTrack->mx+it_lastTrack->my*it_lastTrack->my));
451 (it_lastTrack)->trkZ=vertZ;
453 it_lastTrack->dca=dca.second;
454 it_lastTrack->ipZ=dca.first;
465 Double_t StFgtStraightTrackMaker::getRPhiRatio(vector<generalCluster>::iterator hitIterBegin, vector<generalCluster>::iterator hitIterEnd)
471 vector<generalCluster>::iterator hitIter=hitIterBegin;
472 for(;hitIter!=hitIterEnd;hitIter++)
475 layer=hitIter->layer;
484 return (numR-numPhi)/((Double_t)(numR+numPhi));
495 for(vector<AVTrack>::iterator it=m_tracks.begin();it!=m_tracks.end();it++)
507 pClusters=fgtGenMkr->getClusters();
511 for(
int j=0;j<pClusters[i]->size();j++)
519 Double_t posPhi=(*(pClusters[i]))[j].posPhi;
520 Double_t posR=(*(pClusters[i]))[j].posR;
521 Int_t clusSize=(*(pClusters[i]))[j].clusterSize;
522 Double_t charge=(*(pClusters[i]))[j].clusterCharge;
523 Int_t cntGeoId=(*(pClusters[i]))[j].centralStripGeoId;
524 Int_t seedType=(*(pClusters[i]))[j].seedType;
528 pStrips=fgtGenMkr->getStrips();
547 set<Int_t> usedPoints;
548 Double_t D1Pos=StFgtGeneralBase::getLocDiscZ(0);
549 Double_t D6Pos=StFgtGeneralBase::getLocDiscZ(5);
550 Double_t zArm=D6Pos-D1Pos;
551 vector<generalCluster>::reverse_iterator hitIterD1,hitIterD6;
552 vector<generalCluster>::iterator hitIterD1R, hitIterD6R, hitIter, hitIter2;
559 for(
int locMinNumFitPoints=6;locMinNumFitPoints>=minNumFitPoints;locMinNumFitPoints--)
562 for(
int iSeed1=0;iSeed1<5;iSeed1++)
564 for(
int iSeed2=iSeed1+1;iSeed2<6;iSeed2++)
566 if((iSeed2-iSeed1)<1)
568 if(iSeed1==m_effDisk || iSeed2==m_effDisk)
570 if(pClusters[iSeed1]->size() > maxClusters || pClusters[iSeed2]->size() > maxClusters)
577 vector<generalCluster> &hitVecSeed1=*(pClusters[iSeed1]);
578 vector<generalCluster> &hitVecSeed2=*(pClusters[iSeed2]);
580 D1Pos=StFgtGeneralBase::getLocDiscZ(iSeed1);
581 D6Pos=StFgtGeneralBase::getLocDiscZ(iSeed2);
585 for(hitIterD1=hitVecSeed1.rbegin();hitIterD1 != hitVecSeed1.rend();hitIterD1++)
588 if(useChargeMatch && !hitIterD1->hasMatch)
590 Short_t quadP=hitIterD1->quad;
591 Char_t layer=hitIterD1->layer;
593 Double_t seed1ChargePhi=hitIterD1->CHARGE_MEASURE;
594 Double_t seed1SizePhi=hitIterD1->clusterSize;
599 Int_t geoIdSeed1=hitIterD1->centralStripGeoId;
600 if(usedPoints.find(geoIdSeed1)!=usedPoints.end())
605 Float_t phiD1=hitIterD1->posPhi;
606 fgtHitD1Phi=hitIterD1->fgtHit;
607 for(hitIterD6=hitVecSeed2.rbegin();hitIterD6 != hitVecSeed2.rend();hitIterD6++)
609 if(useChargeMatch && !hitIterD6->hasMatch)
612 Int_t geoIdSeed2=hitIterD6->centralStripGeoId;
613 Short_t quadP_2=hitIterD6->quad;
616 Char_t layer=hitIterD6->layer;
617 Double_t seed2ChargePhi=hitIterD6->CHARGE_MEASURE;
618 Double_t seed2SizePhi=hitIterD6->clusterSize;
621 if(usedPoints.find(geoIdSeed2)!=usedPoints.end())
623 Float_t phiD6=hitIterD6->posPhi;
624 fgtHitD6Phi=hitIterD6->fgtHit;
625 if(fabs(phiD6-phiD1)>maxPhiDiff)
628 for(hitIterD1R=hitVecSeed1.begin();hitIterD1R != hitVecSeed1.end();hitIterD1R++)
630 if(useChargeMatch && !hitIterD1R->hasMatch)
632 Int_t geoIdSeed1R=hitIterD1R->centralStripGeoId;
633 Short_t quadR=hitIterD1R->quad;
636 Char_t layer=hitIterD1R->layer;
637 Double_t seed1ChargeR=hitIterD1R->CHARGE_MEASURE;
638 Double_t seed1SizeR=hitIterD1R->clusterSize;
640 fgtHitD1R=hitIterD1R->fgtHit;
646 if(usedPoints.find(geoIdSeed1R)!=usedPoints.end())
649 Float_t rD1=hitIterD1R->posR;
650 Float_t xD1=rD1*cos(phiD1);
651 Float_t yD1=rD1*sin(phiD1);
656 for(hitIterD6R=hitVecSeed2.begin();hitIterD6R != hitVecSeed2.end();hitIterD6R++)
658 if(useChargeMatch && !hitIterD6R->hasMatch)
660 Int_t geoIdSeed2R=hitIterD6R->centralStripGeoId;
661 Short_t quadR_2=hitIterD6R->quad;
664 Char_t layer=hitIterD6R->layer;
665 Double_t seed2ChargeR=hitIterD6R->CHARGE_MEASURE;
667 Double_t seed2SizeR=hitIterD6R->clusterSize;
669 fgtHitD6R=hitIterD6R->fgtHit;
677 if(usedPoints.find(geoIdSeed2R)!=usedPoints.end())
679 Float_t rD6=hitIterD6R->posR;
686 vector<AVPoint>* v_points=
new vector<AVPoint>;
687 vvPoints.push_back(v_points);
690 Double_t xD6=rD6*cos(phiD6);
691 Double_t yD6=rD6*sin(phiD6);
693 AVPoint avp1(xD1,yD1,D1Pos,rD1,phiD1,iSeed1,quadSeed1,seed1ChargeR, seed1ChargePhi, seed1SizeR, seed1SizePhi);
694 avp1.fgtHitR=fgtHitD1R;
695 avp1.fgtHitPhi=fgtHitD1Phi;
696 v_points->push_back(avp1);
697 AVPoint avp2(xD6,yD6,D6Pos,rD6,phiD6,iSeed2,quadSeed2,seed2ChargeR, seed2ChargePhi, seed2SizeR, seed2SizePhi);
698 avp2.fgtHitR=fgtHitD6R;
699 avp2.fgtHitPhi=fgtHitD6Phi;
700 v_points->push_back(avp2);
715 vector<generalCluster>::iterator iterClosestPhi;
716 vector<generalCluster>::iterator iterClosestR;
718 Double_t closestDist=999999;
722 for(
int iD=0;iD<6;iD++)
725 if(iD==iSeed1 || iD==iSeed2 || iD==m_effDisk)
733 Double_t diskZ=StFgtGeneralBase::getLocDiscZ(iD);
736 Double_t xPosExp=xD1+(xD6-xD1)*(diskZ-D1Pos)/zArm;
737 Double_t yPosExp=yD1+(yD6-yD1)*(diskZ-D1Pos)/zArm;
739 Double_t rPosExp=rD1+(rD6-rD1)*(diskZ-D1Pos)/zArm;
740 vector<generalCluster> &hitVec=*(pClusters[iD]);
741 for(hitIter=hitVec.begin();hitIter!=hitVec.end();hitIter++)
743 if(useChargeMatch && !hitIter->hasMatch)
746 Int_t geoIdPhi=hitIter->centralStripGeoId;
747 Short_t quad=hitIter->quad;
748 Int_t quadTestPhi=quad;
749 Short_t disc=hitIter->disc;
750 Short_t strip=hitIter->strip;
751 Char_t layer=hitIter->layer;
753 if(usedPoints.find(geoIdPhi)!=usedPoints.end())
757 Float_t phi=hitIter->posPhi;
759 StFgtHit* fgtHitPhi=hitIter->fgtHit;
760 if(fabs(phi-phiD1)>maxPhiDiff)
762 if(fabs(phi-phiD6)>maxPhiDiff)
773 for(hitIter2=hitVec.begin();hitIter2!=hitVec.end();hitIter2++)
775 if(useChargeMatch && !hitIter2->hasMatch)
777 Int_t geoIdR=hitIter2->centralStripGeoId;
778 StFgtGeom::decodeGeoId(geoIdR,disc, quad, layer, strip);
780 if(usedPoints.find(geoIdR)!=usedPoints.end())
786 if(quadTestR!=quadTestPhi)
788 Float_t r=hitIter2->posR;
800 Double_t dist2=(x-xPosExp)*(x-xPosExp)+(y-yPosExp)*(y-yPosExp);
803 if(doAddMultiplePoints)
807 Double_t rCharge=hitIter2->CHARGE_MEASURE;
808 Double_t phiCharge=hitIter->CHARGE_MEASURE;
809 Int_t clusterSizeR=hitIter2->clusterSize;
810 Int_t clusterSizePhi=hitIter->clusterSize;
811 AVPoint avp(x,y,diskZ,r,phi,iD,quadTestR, rCharge,phiCharge, clusterSizeR,clusterSizePhi);
813 avp.fgtHitPhi=fgtHitPhi;
814 v_points->push_back(avp);
818 if(dist2<closestDist)
821 closestQuad=quadTestR;
822 iterClosestPhi=hitIter;
823 iterClosestR=hitIter2;
829 if(closestDist<1000 && closestDist<maxDist2)
833 double r=iterClosestR->posR;
834 double phi=iterClosestPhi->posPhi;
835 StFgtHit* fgtHitR=iterClosestR->fgtHit;
836 StFgtHit* fgtHitPhi=iterClosestPhi->fgtHit;
838 Int_t geoIdR=iterClosestR->centralStripGeoId;
839 Int_t geoIdPhi=iterClosestPhi->centralStripGeoId;
844 Double_t rCharge=iterClosestR->CHARGE_MEASURE;
845 Double_t phiCharge=iterClosestPhi->CHARGE_MEASURE;
846 Int_t clusterSizeR=iterClosestR->clusterSize;
847 Int_t clusterSizePhi=iterClosestPhi->clusterSize;
851 if(!doAddMultiplePoints)
853 AVPoint avp(x,y,diskZ,r,phi,iD,closestQuad, rCharge,phiCharge, clusterSizeR,clusterSizePhi);
856 avp.fgtHitPhi=fgtHitPhi;
857 v_points->push_back(avp);
884 if(iFound>=(locMinNumFitPoints-2))
887 Bool_t validTrack=
false;
888 Bool_t passQCuts=
true;
896 validTrack=
getTrack(*v_points, ipZ);
899 if(m_tracks.size()>0)
901 passQCuts=trackQCuts(m_tracks.back());
904 if(validTrack && passQCuts)
907 (m_tracks.back()).points=v_points;
909 usedPoints.insert(geoIdSeed1);
910 usedPoints.insert(geoIdSeed1R);
911 usedPoints.insert(geoIdSeed2);
912 usedPoints.insert(geoIdSeed2R);
914 for(vector<AVPoint>::iterator it=v_points->begin();it!=v_points->end();it++)
916 usedPoints.insert(it->geoIdR);
917 usedPoints.insert(it->geoIdPhi);
957 bool StFgtStraightTrackMaker::trackQCuts(
AVTrack& trk)
960 if(trk.chi2>maxChi2 || trk.trkZ> vertexCutPos || trk.trkZ< vertexCutNeg|| trk.dca> dcaCut )
967 StFgtStraightTrackMaker::StFgtStraightTrackMaker(
const Char_t* name):
StMaker( name ),useChargeMatch(false),runningEvtNr(0),hitCounter(0),hitCounterR(0),maxChi2(2),dcaCut(1),vertexCutPos(70),vertexCutNeg(-120)
976 doFitWithVertex=
false;
977 doRefitWithVertex=
false;
978 doAddMultiplePoints=
false;
984 StFgtStraightTrackMaker::~StFgtStraightTrackMaker()
1009 Int_t StFgtStraightTrackMaker::Init(){
Double_t findClosestPoint(float mx, float bx, float my, float by, double xE, double yE, Int_t iD)
pair< double, double > getDca(vector< AVTrack >::iterator it)
Short_t getQuadFromCoo(Double_t x, Double_t y)
this is too naive..., assumes non-rotated quads
Bool_t getTrack(vector< AVPoint > &points, Double_t ipZ)