Skip to content

Commit

Permalink
Fix match flag and efficiency (#703)
Browse files Browse the repository at this point in the history
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 <[email protected]>
Co-authored-by: Yannick Soehngen <[email protected]>
Co-authored-by: Dmitri Smirnov <[email protected]>
Co-authored-by: Yannick Soehngen <[email protected]>
Co-authored-by: Yannick Soehngen <[email protected]>
Co-authored-by: Yannick Soehngen <[email protected]>
Co-authored-by: Yannick Soehngen <[email protected]>
Co-authored-by: Yannick Soehngen <[email protected]>
Co-authored-by: Yannick Soehngen <[email protected]>
Co-authored-by: Gene Van Buren <[email protected]>
  • Loading branch information
11 people authored Sep 12, 2024
1 parent 50de453 commit 4a77f5c
Show file tree
Hide file tree
Showing 2 changed files with 175 additions and 64 deletions.
238 changes: 174 additions & 64 deletions StRoot/StETofMatchMaker/StETofMatchMaker.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -3234,8 +3234,7 @@ void StETofMatchMaker::checkClockJumps()
//---------------------------------------------------------------------------
void
StETofMatchMaker::sortMatchCases( eTofHitVec inputVec , std::map< Int_t, eTofHitVec >& outputMap )
{

{

// sort & flag Match candidates

Expand All @@ -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
Expand Down Expand Up @@ -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<int> 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<Int_t, eTofHitVec >::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;
}
}
1 change: 1 addition & 0 deletions StRoot/StETofMatchMaker/StETofMatchMaker.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down

0 comments on commit 4a77f5c

Please sign in to comment.