diff --git a/StRoot/StPicoDstMaker/StPicoDstMaker.cxx b/StRoot/StPicoDstMaker/StPicoDstMaker.cxx index 0401b3ec9d6..9aaf963a7ce 100644 --- a/StRoot/StPicoDstMaker/StPicoDstMaker.cxx +++ b/StRoot/StPicoDstMaker/StPicoDstMaker.cxx @@ -2574,11 +2574,9 @@ bool StPicoDstMaker::selectVertex() { } //if (mBTofHeader && fabs(mBTofHeader->vpdVz()) < 200) } //else if (mVtxMode == PicoVtxMode::Vpd || mVtxMode == PicoVtxMode::VpdOrDefault) else if ( mVtxMode == PicoVtxMode::Mtd ) { - + // Set the first primary vertex as a default vertex - mMuDst->setVertexIndex(0); - // Set pointer to the first primary vertex - selectedVertex = mMuDst->primaryVertex(); + int VtxIndex = 0; // Loop over primary vertices for(unsigned int iVtx=0; iVtxnumberOfPrimaryVertices(); iVtx++) { @@ -2592,30 +2590,33 @@ bool StPicoDstMaker::selectVertex() { // Loop over primary tracks for(unsigned int iTrk=0; iTrknumberOfPrimaryTracks(); iTrk++) { - // Retrieve i-th primary track from that belongs - // to the current primary vertex - StMuTrack* pTrack = mMuDst->primaryTracks( iTrk ); - // Track must exist - if( !pTrack ) continue; + // Retrieve i-th primary track from that belongs + // to the current primary vertex + StMuTrack* pTrack = mMuDst->primaryTracks( iTrk ); + // Track must exist + if( !pTrack ) continue; + + // Check if track matches MTD + if( pTrack->index2MtdHit()<0 ) continue; + // Increment number of tracks that matched MTD + nMtdMatched++; - // Check if track matches MTD - if( pTrack->index2MtdHit()<0 ) continue; - // Increment number of tracks that matched MTD - nMtdMatched++; - } // for(unsigned int iTrk=0; iTrknumberOfPrimaryTracks(); iTrk++) - // Take the first primary vertex that has at least 2 tracks - // that matched MTD + // Take the first primary vertex that has at least 2 tracks + // that matched MTD if( nMtdMatched >= 2 ) { - // Reset vertex index - mMuDst->setVertexIndex( iVtx ); - // Reset pointer to the primary vertex - selectedVertex = mMuDst->primaryVertex(); - // Quit vertex loop - break; + // Change vertex index + VtxIndex = iVtx; + // Quit vertex loop + break; } // if( nMtdMatched >= 2 ) } // for(unsigned int iVtx=0; iVtxnumberOfPrimaryVertices(); iVtx++) + + // Set the vertex index + mMuDst->setVertexIndex(VtxIndex); + // Set pointer to the primary vertex + selectedVertex = mMuDst->primaryVertex(); } // else if ( mVtxMode == PicoVtxMode::Mtd ) else { // default case LOG_ERROR << "Pico Vtx Mode not set!" << endm;