Skip to content

Commit

Permalink
Update for det eff functions from GammaQuant.
Browse files Browse the repository at this point in the history
  • Loading branch information
wcjohns committed Oct 11, 2024
1 parent e4d6b20 commit bfd3567
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 9 deletions.
3 changes: 2 additions & 1 deletion InterSpec/DetectorPeakResponse.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::shared_ptr<DetectorPeakResponse>> &drfs,
std::vector<std::shared_ptr<DetectorPeakResponse>> &drfs,
std::vector<std::string> &credits,
std::vector<std::string> &warnings );


Expand Down
27 changes: 23 additions & 4 deletions src/DetectorPeakResponse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1275,6 +1275,7 @@ void DetectorPeakResponse::parseMultipleRelEffDrfCsv( std::istream &input,

void DetectorPeakResponse::parseGammaQuantRelEffDrfCsv( std::istream &input,
std::vector<std::shared_ptr<DetectorPeakResponse>> &drfs,
std::vector<std::string> &credits,
std::vector<std::string> &warnings )
{
drfs.clear();
Expand All @@ -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<unsigned char>(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" );
Expand Down Expand Up @@ -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 + "'" );

Expand All @@ -1353,7 +1367,7 @@ void DetectorPeakResponse::parseGammaQuantRelEffDrfCsv( std::istream &input,
const vector<string> lower_energy = get_row(false, "Lower Energy Cutoff (keV)");
const vector<string> 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<string> keV_or_MeV = get_row(false, "keV or MeV");
const vector<string> coef_a = get_row(false, "Coefficient a");
const vector<string> coef_b = get_row(false, "Coefficient b");
Expand All @@ -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() )
Expand Down Expand Up @@ -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" );
Expand All @@ -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 );
Expand Down
35 changes: 31 additions & 4 deletions src/SpecMeasManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2506,8 +2506,8 @@ bool SpecMeasManager::handleMultipleDrfCsv( std::istream &input,
string creditsHtml;
if( credits.size() )
{
for( string &s : credits )
creditsHtml += "<div>" + s + "</div>";
for( const string &s : credits )
creditsHtml += "<div>" + Wt::Utils::htmlEncode(s) + "</div>";
}//if( credits.size() )


Expand All @@ -2521,12 +2521,12 @@ bool SpecMeasManager::handleGammaQuantDrfCsv( std::istream &input,
const std::string &displayName,
const std::string &fileLocation )
{
vector<string> warnings;
vector<string> credits, warnings;
vector<shared_ptr<DetectorPeakResponse>> drfs;

try
{
DetectorPeakResponse::parseGammaQuantRelEffDrfCsv( input, drfs, warnings );
DetectorPeakResponse::parseGammaQuantRelEffDrfCsv( input, drfs, credits, warnings );
}catch( std::exception &e )
{
return false;
Expand All @@ -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<void()> 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 += "<div>" + Wt::Utils::htmlEncode(s) + "</div>";
}
}//if( credits.size() )

if( !warnings.empty() )
{
if( !creditsHtml.empty() )
creditsHtml += "<br />";
for( const string &s : warnings )
{
if( !s.empty() )
creditsHtml += "<div style=\"color: red\"><b>Warning</b>: " + Wt::Utils::htmlEncode(s) + "</div>";
}
}//if( !warnings.empty() )

DrfSelect::createChooseDrfDialog( drfs, dialogmsg, creditsHtml, saveDrfFile );

return true;
Expand Down

0 comments on commit bfd3567

Please sign in to comment.