From 4a77f5c6d96e9ba2898c7e7b97f7c26c1de81f29 Mon Sep 17 00:00:00 2001 From: YannickSoehngen <60179883+YannickSoehngen@users.noreply.github.com> Date: Thu, 12 Sep 2024 17:19:58 +0200 Subject: [PATCH] Fix match flag and efficiency (#703) New match flag scheme for picoDsts and fix of overlap matching Comments regarding functionality were addressed, changes addressing style will be taken care of in full scale in follow up PR. --------- Co-authored-by: Yannick Soehngen Co-authored-by: Yannick Soehngen Co-authored-by: Dmitri Smirnov Co-authored-by: Yannick Soehngen Co-authored-by: Yannick Soehngen Co-authored-by: Yannick Soehngen Co-authored-by: Yannick Soehngen Co-authored-by: Yannick Soehngen Co-authored-by: Yannick Soehngen Co-authored-by: Gene Van Buren <85305093+genevb@users.noreply.github.com> --- StRoot/StETofMatchMaker/StETofMatchMaker.cxx | 238 ++++++++++++++----- StRoot/StETofMatchMaker/StETofMatchMaker.h | 1 + 2 files changed, 175 insertions(+), 64 deletions(-) diff --git a/StRoot/StETofMatchMaker/StETofMatchMaker.cxx b/StRoot/StETofMatchMaker/StETofMatchMaker.cxx index ac1472fcfa4..f497589bf49 100644 --- a/StRoot/StETofMatchMaker/StETofMatchMaker.cxx +++ b/StRoot/StETofMatchMaker/StETofMatchMaker.cxx @@ -3234,8 +3234,7 @@ void StETofMatchMaker::checkClockJumps() //--------------------------------------------------------------------------- void StETofMatchMaker::sortMatchCases( eTofHitVec inputVec , std::map< Int_t, eTofHitVec >& outputMap ) -{ - +{ // sort & flag Match candidates @@ -3248,77 +3247,59 @@ StETofMatchMaker::sortMatchCases( eTofHitVec inputVec , std::map< Int_t, eTofHi MMMap.clear(); eTofHitVec ssVec; - - // get multi Hit sets - // int deltaSize = 0; + // get multi Hit sets eTofHitVecIter tempIter = tempVec.begin(); - eTofHitVecIter erasedIter = erasedVec.begin(); - if(tempVec.size() < 1 ) return; + + eTofHitVec storeVecTmp; + + while(tempVec.size() > 0){ + + std::vector< int > trackIdVec; + std::vector< int > hitIdVec; + trackIdVec.clear(); + hitIdVec.clear(); + tempIter = tempVec.begin(); + storeVecTmp.push_back(tempVec.at(0)); + trackIdVec.push_back(tempVec.at(0).trackId); + hitIdVec.push_back(tempVec.at(0).index2ETofHit); + tempVec.erase(tempVec.begin()); + bool done = false; + + while(!done){ + + unsigned int sizeOld = storeVecTmp.size(); + unsigned int size = tempVec.size(); + tempIter= tempVec.begin(); + + for(unsigned int i=0; i < size; i++){ + + if( (std::find(trackIdVec.begin(), trackIdVec.end(), tempVec.at(i).trackId) != trackIdVec.end()) || (std::find(hitIdVec.begin(), hitIdVec.end(), tempVec.at(i).index2ETofHit) != hitIdVec.end()) ){ + + storeVecTmp.push_back(tempVec.at(i)); + trackIdVec.push_back(tempVec.at(i).trackId); + hitIdVec.push_back(tempVec.at(i).index2ETofHit); + tempVec.erase(tempIter); + + i = 0; + size = tempVec.size(); + tempIter = tempVec.begin(); + }else{ + tempIter++; + } + } + done = ( sizeOld == storeVecTmp.size() ); - while( tempVec.size() != 0 ) { - - tempIter = tempVec.begin(); - erasedIter = erasedVec.begin(); - - - tempMMVec.push_back(*tempIter); - erasedVec.erase( erasedIter ); - - // int sizeOld = tempMMVec.size(); - int count =0; - int countwhile = 0; - - for(unsigned int s =0; s < tempMMVec.size(); s++){ - - count++; - - erasedIter = erasedVec.begin(); - - if(erasedVec.size() <= 0 ) continue; - - countwhile = 0; - - while( erasedIter != erasedVec.end() ) { - - countwhile++; - - if(tempMMVec.at(s).trackId == erasedIter->trackId && tempMMVec.at(s).index2ETofHit == erasedIter->index2ETofHit){ - - erasedVec.erase( erasedIter ); - erasedIter++; - continue;} - if(tempMMVec.at(s).trackId == erasedIter->trackId || tempMMVec.at(s).index2ETofHit == erasedIter->index2ETofHit){ - if(!mIsSim){ - // erasedIter->matchFlag = 0; - } - tempMMVec.push_back(*erasedIter); - - erasedVec.erase( erasedIter ); - - } - if( erasedVec.size() <= 0 ) break; - if( erasedIter == erasedVec.end()) break; - erasedIter++; - - } //while inner - - }// for - - // deltaSize = sizeOld - tempMMVec.size(); + }// while done - MMMap[tempMMVec.begin()->trackId] = tempMMVec; - tempMMVec.clear(); + MMMap[storeVecTmp.begin()->trackId] = storeVecTmp; + storeVecTmp.clear(); - tempVec = erasedVec; - } - + }// while all hits on counter outputMap = MMMap; - - } //--------------------------------------------------------------------------- void @@ -3926,4 +3907,133 @@ StETofMatchMaker::sortandcluster(eTofHitVec& matchCandVec , eTofHitVec& detector } }// loop over MMMap }//loop over counters + + sortOutOlDoubles(finalMatchVec); +} + +void +StETofMatchMaker::sortOutOlDoubles(eTofHitVec& finalMatchVec){ + + eTofHitVec overlapHitVec; + + eTofHitVec tempVecOL = finalMatchVec; + + std::vector trackIdVec; + + for(unsigned int i =0; i< finalMatchVec.size(); i++){ + + if( !(std::find(trackIdVec.begin(), trackIdVec.end(), finalMatchVec.at(i).trackId) != trackIdVec.end())){ + + trackIdVec.push_back(finalMatchVec.at(i).trackId); + + int counterId1 = (finalMatchVec.at(i).sector*100) + (finalMatchVec.at(i).plane*10) + (finalMatchVec.at(i).counter); + + for(unsigned int j =0; j< finalMatchVec.size(); j++){ + + int counterId2 = (finalMatchVec.at(j).sector*100) + (finalMatchVec.at(j).plane*10) + (finalMatchVec.at(j).counter); + + if(counterId1 != counterId2 && finalMatchVec.at(i).trackId == finalMatchVec.at(j).trackId){ + + if(!(finalMatchVec.at(j).matchFlag % 2)) finalMatchVec.at(j).matchFlag++; + if(!(finalMatchVec.at(i).matchFlag % 2)) finalMatchVec.at(i).matchFlag++; + + } + } + } + } + + eTofHitVec tmpVec; + eTofHitVec OlVec; + std::map< int , eTofHitVec > overlapHitMap; + + tmpVec = finalMatchVec; + finalMatchVec.clear(); + finalMatchVec.resize(0); + + for(unsigned int i=0; i< tmpVec.size(); i++){ + + if(tmpVec.at(i).matchFlag%2 == 0){ + finalMatchVec.push_back(tmpVec.at(i)); + }else{ + OlVec.push_back(tmpVec.at(i)); + } + } + + // sort out OlVec + for(unsigned int i =0; i < OlVec.size(); i++){ + overlapHitMap[OlVec.at(i).trackId].push_back(OlVec.at(i)); + } + + map::iterator it; + + for (it = overlapHitMap.begin(); it != overlapHitMap.end(); it++){ + + eTofHitVec trackVec = it->second; + int ind_best = 0; + int dr_best = 9999; + + for(unsigned int n=0; n< trackVec.size();n++){ + + float dr = sqrt((trackVec.at(n).deltaX * trackVec.at(n).deltaX ) + (trackVec.at(n).deltaY * trackVec.at(n).deltaY )); + + if(dr < dr_best){ + dr_best=dr; + ind_best=n; + } + } + finalMatchVec.push_back(trackVec.at(ind_best)); + } + + //fix matchFlags + // New match-flag scheme provides information on hit-type, match case, and overlap + // 0: no valid match, otherwise 3 digits encode at first position hit type , at second position overlap info and at third position match type + // hit types : 0 = single sided hits only (time resolution about 25 ps lower than for normal hits) + // hit types : 1 = single sided and normal hits got merged into "mixed hit" for matching + // hit types : 2 = normal hits only (best quality , most common case) + // overlap info : 0 = hit has no contribution from overlap + // overlap info : 1 = hit has only contributions from overlap + // overlap info : 2 = hit has contributions from inside and outside of overlap region + // match case : 0 = no match + // match case : 1 = match from cluster of multiple hits and multiple tracks close in space ( ambiguities leave room for missmatches -> frequent case for most central events!!) + // match case : 2 = single hit could have been matched to multiple tracks + // match case : 3 = single track could have been matched to multiple hits + // match case : 4 = single track matched to single hit ( no ambiguity -> best quality) + // example :: matchFlag = 204 -> 2 = only normal hits, 0 = not in overlap, 4 = single track single hit match + + for(unsigned int i =0; i< finalMatchVec.size(); i++){ + + char singlemixdouble = 9; + char matchcase = 9; + char isOl = 9; + + switch (finalMatchVec.at(i).matchFlag / 100) { + case 1 : matchcase = 4; break; + case 2 : matchcase = 3; break; + case 3 : matchcase = 2; break; + case 4 : matchcase = 1; break; + default : { LOG_WARN << "Errant ETOF match flag for matchcase!" << endm; } + } + + isOl = 1 - ( finalMatchVec.at(i).matchFlag % 2 ); + + switch (finalMatchVec.at(i).matchFlag % 100) { + case 10 : + case 11 : + case 30 : + case 31 : singlemixdouble = 2; break; + case 20 : + case 21 : + case 40 : + case 41 : singlemixdouble = 0; break; + case 50 : + case 51 : singlemixdouble = 1; break; + default : { LOG_WARN << "Errant ETOF match flag for singlemixdouble!" << endm; } + } + + char newFlag = (singlemixdouble*100) + (isOl*10) + (matchcase); + + if(singlemixdouble == 9 || isOl == 9 || matchcase == 9) newFlag = 0; + + finalMatchVec.at(i).matchFlag = newFlag; + } } diff --git a/StRoot/StETofMatchMaker/StETofMatchMaker.h b/StRoot/StETofMatchMaker/StETofMatchMaker.h index ecd274085eb..df198ab880a 100644 --- a/StRoot/StETofMatchMaker/StETofMatchMaker.h +++ b/StRoot/StETofMatchMaker/StETofMatchMaker.h @@ -166,6 +166,7 @@ class StETofMatchMaker : public StMaker { void sortandcluster(eTofHitVec& matchCandVec , eTofHitVec& detectorHitVec , eTofHitVec& intersectionVec , eTofHitVec& finalMatchVec); void sortMatchCases( eTofHitVec inputVec , std::map< Int_t, eTofHitVec >& outputMap ); + void sortOutOlDoubles( eTofHitVec& finalMatchVec); double startTimeBTof(); double startTimeETof( const eTofHitVec& finalMatchVec, unsigned int& nCand_etofT0 );