From 54a33d512324763248a6f3d80f884d22096fa6da Mon Sep 17 00:00:00 2001 From: Gordon McCann Date: Sat, 1 Oct 2022 19:00:48 -0400 Subject: [PATCH] Make MassMap less bad, fix some typos --- SpecProject/src/MassMap.cpp | 26 ++++++++++++++------------ SpecProject/src/MassMap.h | 17 +++++++++++------ SpecProject/src/SPSAnalysisStage.cpp | 6 +++--- 3 files changed, 28 insertions(+), 21 deletions(-) diff --git a/SpecProject/src/MassMap.cpp b/SpecProject/src/MassMap.cpp index af18581..232e2e8 100644 --- a/SpecProject/src/MassMap.cpp +++ b/SpecProject/src/MassMap.cpp @@ -18,18 +18,18 @@ MassMap::MassMap() std::ifstream massfile("Assets/amdc2016_mass.txt"); if (massfile.is_open()) { - std::string junk, A, element; - int Z; + std::string junk, element; + uint32_t Z, A, key; double atomicMassBig, atomicMassSmall, isotopicMass; getline(massfile, junk); getline(massfile, junk); while (massfile >> junk) { massfile >> Z >> A >> element >> atomicMassBig >> atomicMassSmall; - isotopicMass = (atomicMassBig + atomicMassSmall * 1e-6 - Z * electron_mass) * u_to_mev; - std::string key = "(" + std::to_string(Z) + "," + A + ")"; + isotopicMass = (atomicMassBig + atomicMassSmall * 1e-6 - Z * s_eMass) * s_u2MeV; + key = GenerateID(Z, A); massTable[key] = isotopicMass; - elementTable[Z] = element; + elementTable[key] = std::to_string(A) + element; } } else @@ -41,10 +41,10 @@ MassMap::MassMap() MassMap::~MassMap() {} //Returns nuclear mass in MeV -double MassMap::FindMass(int Z, int A) +double MassMap::FindMass(uint32_t Z, uint32_t A) { SPEC_PROFILE_FUNCTION(); - std::string key = "(" + std::to_string(Z) + "," + std::to_string(A) + ")"; + uint32_t key = GenerateID(Z, A); auto data = massTable.find(key); if (data == massTable.end()) { @@ -55,15 +55,17 @@ double MassMap::FindMass(int Z, int A) } //returns element symbol -std::string MassMap::FindSymbol(int Z, int A) +std::string MassMap::FindSymbol(uint32_t Z, uint32_t A) { SPEC_PROFILE_FUNCTION(); - auto data = elementTable.find(Z); + static std::string nullResult = ""; + + uint32_t key = GenerateID(Z, A); + auto data = elementTable.find(key); if (data == elementTable.end()) { SPEC_ERROR("Invalid nucleus at MassMap::FindSymbol()! Z: {0} A: {1}", Z, A); - return ""; + return nullResult; } - std::string fullsymbol = std::to_string(A) + data->second; - return fullsymbol; + return data->second; } \ No newline at end of file diff --git a/SpecProject/src/MassMap.h b/SpecProject/src/MassMap.h index 398a378..7d57d58 100644 --- a/SpecProject/src/MassMap.h +++ b/SpecProject/src/MassMap.h @@ -16,16 +16,21 @@ class MassMap public: MassMap(); ~MassMap(); - double FindMass(int Z, int A); - std::string FindSymbol(int Z, int A); + double FindMass(uint32_t Z, uint32_t A); + std::string FindSymbol(uint32_t Z, uint32_t A); private: - std::unordered_map massTable; - std::unordered_map elementTable; + //As demonstrated elsewhere, using Szudzik pairing function to make unique id for two unsigned ints + uint32_t GenerateID(uint32_t Z, uint32_t A) + { + return Z >= A ? (Z * Z + Z + A) : (A * A + Z); + } + std::unordered_map massTable; + std::unordered_map elementTable; //constants - static constexpr double u_to_mev = 931.4940954; - static constexpr double electron_mass = 0.000548579909; + static constexpr double s_u2MeV = 931.4940954; + static constexpr double s_eMass = 0.000548579909; }; #endif diff --git a/SpecProject/src/SPSAnalysisStage.cpp b/SpecProject/src/SPSAnalysisStage.cpp index c3154e9..5411d60 100644 --- a/SpecProject/src/SPSAnalysisStage.cpp +++ b/SpecProject/src/SPSAnalysisStage.cpp @@ -38,12 +38,12 @@ namespace Specter { //a text file to get detector ID information, detector channel number, etc. std::vector sabre_list; //list of names will allow us to create a summary histogram. uint32_t uuid; - for (uint32_t board = 0; board < 7; board++) + for (uint32_t board = 0; board < 8; board++) { for (uint32_t channel = 0; channel < 16; channel++) { - //ImGui & spdlog come prepackaged with the fmt library, so make good use of it! - sabre_list.push_back(fmt::format("sabre_%d", board*16 + channel)); + //spdlog comes prepackaged with the fmt library, so make good use of it! + sabre_list.push_back(fmt::format("sabre_{}", board*16 + channel)); uuid = Utilities::GetBoardChannelUUID(board, channel); sabre[uuid] = Parameter(sabre_list.back()); manager->BindParameter(sabre[uuid]);