14 #include "StChain/StMaker.h"
15 #include "StEvent/StEvent.h"
16 #include "StEvent/StRunInfo.h"
17 #include "StEvent/StTrack.h"
18 #include "StEvent/StTrackDetectorInfo.h"
19 #include "StEvent/StTrackGeometry.h"
20 #include "StEvent/StTrackNode.h"
21 #include "StGenericVertexMaker/StppLMVVertexFinder.h"
22 #include "St_base/StMessMgr.h"
23 #include "StarClassLibrary/StThreeVectorD.hh"
24 #include "tables/St_g2t_vertex_Table.h"
29 StppLMVVertexFinder::StppLMVVertexFinder() {
30 LOG_INFO <<
"StppLMVVertexFinder::StppLMVVertexFinder is in use." << endm;
32 mVertexConstrain =
false;
40 StppLMVVertexFinder::Init() {
44 LOG_INFO <<
"The ppLMV4 cuts have been activated" << endm;
47 mMinNumberOfFitPointsOnTrack = 15;
52 mMatchCtbMax_eta = mCtbEtaSeg/2.+0.02;
53 mMatchCtbMax_phi = mCtbPhiSeg/2.+M_PI*1./180.;
55 LOG_INFO <<
"The ppLMV5 cuts have been activated" << endm;
58 mMinNumberOfFitPointsOnTrack = 15;
63 mMatchCtbMax_eta = mCtbEtaSeg/2.+0.02;
64 mMatchCtbMax_phi = mCtbPhiSeg/2.+M_PI*0./180.;
71 StppLMVVertexFinder::Clear(){
72 StGenericVertexFinder::Clear();
75 LOG_INFO <<
"StppLMVVertexFinder::Clear() ..." << endm;
81 StppLMVVertexFinder::addFakeVerex(
float z){
83 Float_t cov[6] = {1,0.0,2,0.0,0.0,3 };
85 primV.setPosition(XVertex);
86 primV.setCovariantMatrix(cov);
87 primV.setVertexFinderId(pplmvVertexFinder);
89 primV.setRanking(444);
96 StppLMVVertexFinder::~StppLMVVertexFinder() {
97 delete mBeamHelix;mBeamHelix=0;
103 StppLMVVertexFinder::fit(
StEvent* event) {
104 LOG_INFO <<
"StppLMVVertexFinder::fit() START ..." << endm;
107 n1=0,n2=0,n3=0, n4=0,n5=0,n6=0;
113 mBfield =
event->runInfo()->magneticField();
114 LOG_INFO << Form(
"ppLMV5:: mBfield[Tesla]=%e ",mBfield)<<endm;
117 gMessMgr->Message(
"",
"I") <<
"ppLMV5::cuts"
118 <<
"\n CtbThres_ch (real)="<<mCtbThres_ch
120 <<
"\n MinNumberOfFitPointsOnTrack="<<mMinNumberOfFitPointsOnTrack
121 <<
"\n MaxTrkDcaRxy/cm="<<mMaxTrkDcaRxy
122 <<
"\n MinTrkPt GeV/c ="<<mMinTrkPt
123 <<
"\n MatchCtbMax_eta="<<mMatchCtbMax_eta
124 <<
"\n MatchCtbMax_phi/deg="<<mMatchCtbMax_phi/3.1416*180
125 <<
"\n BeamLequivNtr="<<mBLequivNtr
126 <<
"\n DVtxMax (dz/sig)="<<mDVtxMax
127 <<
"\n MinMatchTr ="<< mMinMatchTr
128 <<
"\n MaxZrange (cm) ="<< mMaxZrange
129 <<
"\n VertexConstrain="<<mVertexConstrain
134 if(event->runId()<100000){
135 St_DataSet *gds=StMaker::GetChain()->GetDataSet(
"geant");
136 collectCTBhitsMC(gds);
139 collectCTBhitsData(trgD);
143 if(mCtbHits.size()<=0){
144 LOG_WARN <<
"StppLMVVertexFinder::fit() no valid CTB hits found, quit" << endm;
152 StSPtrVecTrackNode& nodes =
event->trackNodes();
153 for (
unsigned int k=0; k<nodes.size(); k++) {
154 StTrack* g = nodes[k]->track(global);
156 if( !matchTrack2CTB(g,sigma))
continue;;
158 x.helix=g->geometry()->helix();
160 mPrimCand.push_back(x);
166 LOG_DEBUG <<
", now n1=" << n1 <<
" n2=" << n2 <<
" n3=" << n3 <<
" n4=" << n4 <<
"n6=" << n6 << endm;
172 if (mPrimCand.size() < mMinMatchTr){
173 LOG_WARN <<
"StppLMVVertexFinder::fit() only "<< mPrimCand.size() <<
"tracks to fit - too few, quit ppLMV" << endm;
176 LOG_INFO <<
"StppLMVVertexFinder::fit() size of helix vector: " << mPrimCand.size() << endm;
179 if(mVertexConstrain ) {
182 for(
unsigned int j=0;j<mPrimCand.size();j++) {
183 float sig=mPrimCand[j].sigma;
184 if(sigMin>sig) sigMin=sig;
186 float sigma=sigMin/::sqrt(mBLequivNtr);
190 mPrimCand.push_back(x);
192 LOG_WARN <<
"ppLMV: nominal beam line added with sigma=" << sigma
193 <<
", now nTrack=" << mPrimCand.size() << endm;
199 LOG_DEBUG <<
"PrimCand before ppLMV for eveID=" << eveID <<
"tracks at first point" << endm;
202 for(
unsigned int j=0;j<mPrimCand.size();j++) {
204 printf(
"j=%d sig=%f pT=%f eta=%f phi/deg=%f\n",j,mPrimCand[j].sigma,p.perp(),p.pseudoRapidity(), p.phi()/M_PI*180);
210 LOG_DEBUG <<
"ppLMV did not found vertex"<< endm;
215 LOG_INFO <<
"Prim tr used by ppLMV for eveID=" << eveID
216 <<
", tracks at vertex=" << mPrimCand.size()<<endm;
219 for(
unsigned int j=0;j<mPrimCand.size();j++) {
220 double spath = mPrimCand[j].helix.pathLength( getVertex(0)->position().x(),getVertex(0)->position().y());
221 StThreeVectorD p=mPrimCand[j].helix.momentumAt(spath,mBfield*tesla);
225 gMessMgr->Message(
"",
"I") <<
"Prim ppLMV Vertex at " << getVertex(0)->position()<<endm;
233 StppLMVVertexFinder::printInfo(ostream& os)
const
235 os <<
"StppLMVVertexFinder - Fit Statistics:" << endl;
236 os <<
"found prim vertices ................ " <<size() << endl;
237 os <<
"no more info printed at the moment, Jan"<<endl;
244 StppLMVVertexFinder::UseVertexConstraint() {
245 mVertexConstrain =
true;
250 LOG_INFO <<
"StppLMVVertexFinder::Using Constrained Vertex" << endm;
252 double pt = 88889999;
253 double nxy=::sqrt(mdxdz*mdxdz + mdydz*mdydz);
255 LOG_WARN <<
"StppLMVVertexFinder:: Beam line must be tilted!" << endm;
259 double px = p0*mdxdz;
260 double py = p0*mdydz;
273 StppLMVVertexFinder::matchTrack2CTB (
StTrack*
track,
float & sigma) {
282 const double Rctb=213.6;
283 unsigned int nFitP=0;
285 if (!track)
return false;
286 if(!finite(track->geometry()->helix().curvature())){
287 LOG_WARN <<
"StppLMVVertexFinder::matchTrack2CTB: helix.curvature not finite, fix tracker, ppLMV aborting" << endm;
293 if( track->flag()<0)
return false;
294 if( track->topologyMap().trackFtpc() )
return false;
304 double x_m = posDCA.x(), y_m = posDCA.y();
305 double dmin = ::sqrt(x_m*x_m + y_m*y_m);
306 if( dmin > mMaxTrkDcaRxy )
return false;
307 if (fabs(posDCA.z()) >mMaxZrange)
return false;
310 nFitP = track->detectorInfo()->numberOfPoints(kTpcId);
312 if( nFitP <= mMinNumberOfFitPointsOnTrack)
return false;
315 if(track->geometry()->momentum().perp() <mMinTrkPt )
return false;
322 double beta = pmom.mag()/::sqrt(pmom.mag()*pmom.mag()+0.139*0.139);
328 float pmomM=pmom.mag();
329 float spathL=fabs(spath);
333 if (pmomM >4 ) pmomM=4;
334 if( spathL<40) spathL=40;
338 if( spathL<60) spathL=60;
341 float strag=0.0136/beta/pmomM*spathL;
342 if(fabs(mBfield)<0.01) strag=0.0136*spathL;
347 if ( !track->outerGeometry() )
return false;
355 if(d2.first>=0 || d2.second<=0) {
357 gMessMgr->Message(
"",
"W") <<
"ppLMV::matchTrack2CTB ()"
358 " unexpected solution for track crossing CTB, TrkHlxOut="<< TrkHlxOut<<endm;
367 float phi=atan2(posCTB.y(),posCTB.x());
368 if(phi<0) phi+=2*M_PI;
373 for(ih=0;ih<mCtbHits.size();ih++) {
376 float del_phi=phi-mCtbHits[ih].phi;
377 if(del_phi>M_PI) del_phi-=2*M_PI;
378 if(del_phi<-M_PI) del_phi+=2*M_PI;
381 if(fabs(del_phi) >mMatchCtbMax_phi)
continue;
384 float eta=posCTB.pseudoRapidity();
385 float del_eta=eta-mCtbHits[ih].eta;
387 if(fabs(del_eta) >mMatchCtbMax_eta)
continue;
404 StppLMVVertexFinder::ppLMV5() {
406 if(mMode == 0) LOG_WARN<<
"ppLMV4 cuts have been activated"<<endm;
408 int totTr=mPrimCand.size();
409 unsigned int minTr=mMinMatchTr;
410 if(mVertexConstrain) minTr++;
412 LOG_DEBUG <<
"passed " << totTr <<
" tracks match to CTB, BeamLine=" << mVertexConstrain << endm;
418 double A11=0.0,A12=0.0,A13=0.0;
419 double A21=0.0,A22=0.0,A23=0.0;
420 double A31=0.0,A32=0.0,A33=0.0;
422 double C11=0.0,C12=0.0,C13=0.0;
423 double C21=0.0,C22=0.0,C23=0.0;
424 double C31=0.0,C32=0.0,C33=0.0;
433 if( mPrimCand.size() < minTr ){
434 LOG_WARN <<
"ppLMV5: below "<<minTr<<
" track remains. No vertex found." << endm;
439 A11=0.0,A12=0.0,A13=0.0;
440 A21=0.0,A22=0.0,A23=0.0;
441 A31=0.0,A32=0.0,A33=0.0;
443 C11=0.0,C12=0.0,C13=0.0;
444 C21=0.0,C22=0.0,C23=0.0;
445 C31=0.0,C32=0.0,C33=0.0;
447 double b1=0.0,b2=0.0,b3=0.0;
450 for(
unsigned int itr=0; itr < mPrimCand.size(); itr++){
452 double spath = mPrimCand[itr].helix.pathLength(xo,yo);
454 StThreeVectorD XMomAtClosest = mPrimCand[itr].helix.momentumAt(spath,mBfield*tesla );
456 double xp = XClosest.x();
double yp= XClosest.y();
double zp= XClosest.z();
459 double xhat = XMomAtClosest.x()/XMomAtClosest.mag();
460 double yhat = XMomAtClosest.y()/XMomAtClosest.mag();
461 double zhat = XMomAtClosest.z()/XMomAtClosest.mag();
462 float sig=mPrimCand[itr].sigma;
463 A11=A11+(yhat*yhat+zhat*zhat)/sig;
464 A12=A12-(xhat*yhat)/sig;
465 A13=A13-(xhat*zhat)/sig;
466 A22=A22+(xhat*xhat+zhat*zhat)/sig;
467 A23=A23-(yhat*zhat)/sig;
468 A33=A33+(xhat*xhat+yhat*yhat)/sig;
469 b1=b1 + ( (yhat*yhat+zhat*zhat)*xp - xhat*yhat*yp - xhat*zhat*zp )/sig;
470 b2=b2 + ( (xhat*xhat+zhat*zhat)*yp - xhat*yhat*xp - yhat*zhat*zp )/sig;
471 b3=b3 + ( (xhat*xhat+yhat*yhat)*zp - xhat*zhat*xp - yhat*zhat*yp )/sig;
473 A21 = A12; A31=A13; A32=A23;
476 double detA = A11*A22*A33 + A12*A23*A31 + A13*A21*A32;
477 detA = detA - A31*A22*A13 - A32*A23*A11 - A33*A21*A12;
483 C11=(A22*A33-A23*A32)/detA; C12=(A13*A32-A12*A33)/detA; C13=(A12*A23-A13*A22)/detA;
484 C21=C12; C22=(A11*A33-A13*A31)/detA; C23=(A13*A21-A11*A23)/detA;
485 C31=C13; C32=C23; C33=(A11*A22-A12*A21)/detA;
488 double Xv = C11*b1 + C12*b2 + C13*b3;
489 double Yv = C21*b1 + C22*b2 + C23*b3;
490 double Zv = C31*b1 + C32*b2 + C33*b3;
491 XVertex.setX(Xv); XVertex.setY(Yv); XVertex.setZ(Zv);
492 LOG_DEBUG <<vertIter<<
" Vertex Position : "<<XVertex.x()<<
" "<<XVertex.y()<<
" "<<XVertex.z()<<endm;
493 LOG_DEBUG <<
"Error in Position : "<<::sqrt(C11)<<
" "<<::sqrt(C22)<<
" "<<::sqrt(C33)<<endm;
500 vector<JHelix>::iterator itehlx, end, ikeep;
502 if(mVertexConstrain )end--;
504 for( itehlx=mPrimCand.begin(); itehlx <end; itehlx++) {
506 double sig = (*itehlx).sigma;
507 double spath = hlx.
pathLength(XVertex.x(),XVertex.y());
509 double d=(XHel.x()-XVertex.x())*(XHel.x()-XVertex.x());
510 d = d+(XHel.y()-XVertex.y())*(XHel.y()-XVertex.y());
511 d = d+(XHel.z()-XVertex.z())*(XHel.z()-XVertex.z());
513 chi2 = chi2 + (d*d)/(sig*sig);
522 if( dmax > mDVtxMax ){
523 LOG_INFO <<
"Removing a track! dmax=" << dmax << endm;
524 mPrimCand.erase(ikeep);
535 Float_t cov[6] = {(Float_t) C11, 0.0,
537 0.0, (Float_t) C33 };
539 primV.setPosition(XVertex);
540 primV.setCovariantMatrix(cov);
541 primV.setVertexFinderId(pplmvVertexFinder);
542 primV.setNumTracksUsedInFinder(mPrimCand.size());
543 primV.setNumMatchesWithCTB(mPrimCand.size());
550 primV.setRanking(555);
564 if(eveID%2) addFakeVerex(XVertex.z()+20);
569 mFitError.setX(sqrt(C11)); mFitError.setY(sqrt(C22)); mFitError.setZ(sqrt(C33));
573 LOG_DEBUG <<
"ppLMV5: Primary Vertex found!\nVert position: "<<XVertex<<
", accepted tracks "<<mPrimCand.size()<<
" of "<<totTr<<
" eveID="<<eveID<<endm;
574 printf(
"##V %6d %d %f %f %f %d %d %d\n",eveID,mTotEve,XVertex.x(),XVertex.y(),XVertex.z(),mCtbHits.size(),n1,NCtbMatches());
578 St_DataSet *gds=StMaker::GetChain()->GetDataSet(
"geant");
580 St_g2t_vertex *g2t_ver=( St_g2t_vertex *)gds->
Find(
"g2t_vertex");
583 g2t_vertex_st *GVER= g2t_ver->GetTable();
588 printf(
"Z Geant-found=%.2f, dx=%.2f, dy=%.2f nCtbSl=%d n1=%d eveID=%d\n",GVER->ge_x[2]-XVertex.z(),GVER->ge_x[0]-XVertex.x(),GVER->ge_x[1]-XVertex.y(),mCtbHits.size(),n1,eveID);
589 printf(
"##G %6d %d %f %f %d %d %d\n",eveID,mTotEve,GVER->ge_x[2],XVertex.z(),mCtbHits.size(),n1,NCtbMatches());
594 LOG_DEBUG <<
"StppLMVVertexFinder::ppLMV5() ends" << endm;
601 int StppLMVVertexFinder::NCtbMatches() {
602 int nTr=mPrimCand.size();
603 if(mVertexConstrain ) nTr--;
pair< double, double > pathLength(double r) const
path length at given r (cylindrical r)
virtual TDataSet * Find(const char *path) const