From bfd356760ad68872d65df8c966a2a821c9b0dddc Mon Sep 17 00:00:00 2001 From: William Johnson Date: Thu, 10 Oct 2024 18:32:25 -0700 Subject: [PATCH] Update for det eff functions from GammaQuant. --- InterSpec/DetectorPeakResponse.h | 3 ++- src/DetectorPeakResponse.cpp | 27 ++++++++++++++++++++---- src/SpecMeasManager.cpp | 35 ++++++++++++++++++++++++++++---- 3 files changed, 56 insertions(+), 9 deletions(-) diff --git a/InterSpec/DetectorPeakResponse.h b/InterSpec/DetectorPeakResponse.h index 25c326b5..f2717c68 100644 --- a/InterSpec/DetectorPeakResponse.h +++ b/InterSpec/DetectorPeakResponse.h @@ -424,7 +424,8 @@ class DetectorPeakResponse Throws std::exception on format error, or now det eff functions found */ static void parseGammaQuantRelEffDrfCsv( std::istream &input, - std::vector> &drfs, + std::vector> &drfs, + std::vector &credits, std::vector &warnings ); diff --git a/src/DetectorPeakResponse.cpp b/src/DetectorPeakResponse.cpp index eba5016f..e3c7e50f 100644 --- a/src/DetectorPeakResponse.cpp +++ b/src/DetectorPeakResponse.cpp @@ -1275,6 +1275,7 @@ void DetectorPeakResponse::parseMultipleRelEffDrfCsv( std::istream &input, void DetectorPeakResponse::parseGammaQuantRelEffDrfCsv( std::istream &input, std::vector> &drfs, + std::vector &credits, std::vector &warnings ) { drfs.clear(); @@ -1290,10 +1291,23 @@ void DetectorPeakResponse::parseGammaQuantRelEffDrfCsv( std::istream &input, while( SpecUtils::safe_get_line( input, line, 128*1024 ) ) { SpecUtils::trim( line ); + + // Remove any leading non-ascii characters - e.g., UTF-8 BOM + while( line.size() && (static_cast(line.front()) > 127) ) + line.erase( begin(line) ); + + if( SpecUtils::istarts_with( line, "#credit:") ) + credits.push_back( SpecUtils::trim_copy( line.substr(8) ) ); + if( line.empty() || (line[0] == '#') ) continue; + + const size_t pos = line.find_first_not_of(" \t,"); + if( pos == string::npos ) + continue; + break; - } + }//while( SpecUtils::safe_get_line( input, line, 128*1024 ) ) if( line.empty() ) throw runtime_error( "No content" ); @@ -1329,7 +1343,7 @@ void DetectorPeakResponse::parseGammaQuantRelEffDrfCsv( std::istream &input, while( SpecUtils::icontains(cols[0], " ") ) SpecUtils::ireplace_all(cols[0], " ", " "); - if( !SpecUtils::icontains(cols[0], expected_title) ) + if( !expected_title.empty() && !SpecUtils::icontains(cols[0], expected_title) ) warnings.push_back( "Warning: row " + std::to_string(row_num) + " doesnt have expected header '" + expected_title + "'" ); @@ -1353,7 +1367,7 @@ void DetectorPeakResponse::parseGammaQuantRelEffDrfCsv( std::istream &input, const vector lower_energy = get_row(false, "Lower Energy Cutoff (keV)"); const vector upper_energy = get_row(false, "Upper Energy Cutoff (keV)"); get_row(true, ""); - get_row(true, "y = exp (a + b(lnx) + c(lnx)2 + d(lnx)3 + e(lnx)4 + f(lnx)5 + g(lnx)6 + h(lnx)7)"); + get_row(true, ""); //Actual header: "y = exp (a + b(lnx) + c(lnx)2 + d(lnx)3 + e(lnx)4 + f(lnx)5 + g(lnx)6 + h(lnx)7)" const vector keV_or_MeV = get_row(false, "keV or MeV"); const vector coef_a = get_row(false, "Coefficient a"); const vector coef_b = get_row(false, "Coefficient b"); @@ -1378,6 +1392,7 @@ void DetectorPeakResponse::parseGammaQuantRelEffDrfCsv( std::istream &input, continue; const string &comment = comments[col]; + const string &cal_geom = calibration_geometry[col]; const string &far_field = is_far_field[col]; if( far_field.empty() ) @@ -1521,6 +1536,9 @@ void DetectorPeakResponse::parseGammaQuantRelEffDrfCsv( std::istream &input, }else if( SpecUtils::icontains(name, "OnContact") || SpecUtils::icontains(comment, "OnContact") ) { geometry_type = EffGeometryType::FixedGeomTotalAct; + }else if( SpecUtils::icontains(name, "Bq-g") ) + { + geometry_type = EffGeometryType::FixedGeomActPerGram; }else { warnings.push_back( "Couldnt determine fixed-geometry type for detector '" + name + "' - skipping detector" ); @@ -1537,7 +1555,8 @@ void DetectorPeakResponse::parseGammaQuantRelEffDrfCsv( std::istream &input, throw runtime_error( "Not valid" ); det->setName( name ); - det->setDescription( comment ); + string desc = comment + ((!comment.empty() && !cal_geom.empty()) ? ", " : "") + cal_geom; + det->setDescription( desc ); det->setDrfSource( DetectorPeakResponse::DrfSource::UserImportedIntrisicEfficiencyDrf ); drfs.push_back( det ); diff --git a/src/SpecMeasManager.cpp b/src/SpecMeasManager.cpp index e1d82099..af39615d 100644 --- a/src/SpecMeasManager.cpp +++ b/src/SpecMeasManager.cpp @@ -2506,8 +2506,8 @@ bool SpecMeasManager::handleMultipleDrfCsv( std::istream &input, string creditsHtml; if( credits.size() ) { - for( string &s : credits ) - creditsHtml += "
" + s + "
"; + for( const string &s : credits ) + creditsHtml += "
" + Wt::Utils::htmlEncode(s) + "
"; }//if( credits.size() ) @@ -2521,12 +2521,12 @@ bool SpecMeasManager::handleGammaQuantDrfCsv( std::istream &input, const std::string &displayName, const std::string &fileLocation ) { - vector warnings; + vector credits, warnings; vector> drfs; try { - DetectorPeakResponse::parseGammaQuantRelEffDrfCsv( input, drfs, warnings ); + DetectorPeakResponse::parseGammaQuantRelEffDrfCsv( input, drfs, credits, warnings ); }catch( std::exception &e ) { return false; @@ -2535,10 +2535,37 @@ bool SpecMeasManager::handleGammaQuantDrfCsv( std::istream &input, if( drfs.empty() ) return false; + // Print out as URL - for version of InterSpec pre 20241010 + //cout << "\n\n\n"; + //for( const auto &drf : drfs ) + // cout << drf->name() << " UrlEncoded " << drf->toAppUrl() << endl; + //cout << "-------- done ---------" << endl; + + std::function saveDrfFile; WString dialogmsg = WString::tr( (drfs.size()==1) ? "smm-file-is-drf" : "smm-file-is-multi-drf"); string creditsHtml; + if( credits.size() ) + { + for( const string &s : credits ) + { + if( !s.empty() ) + creditsHtml += "
" + Wt::Utils::htmlEncode(s) + "
"; + } + }//if( credits.size() ) + + if( !warnings.empty() ) + { + if( !creditsHtml.empty() ) + creditsHtml += "
"; + for( const string &s : warnings ) + { + if( !s.empty() ) + creditsHtml += "
Warning: " + Wt::Utils::htmlEncode(s) + "
"; + } + }//if( !warnings.empty() ) + DrfSelect::createChooseDrfDialog( drfs, dialogmsg, creditsHtml, saveDrfFile ); return true;