1
0
Fork 0
mirror of https://github.com/gwm17/Specter.git synced 2024-11-26 20:28:49 -05:00

Structure overhaul. Revert to static linking, otherwise ImGui becomes really messy when making a new panel in the NavProject. Add a new example add-on panel for SPS, mass table.

This commit is contained in:
Gordon McCann 2022-03-08 22:44:13 -05:00
parent 2c4af3a0e0
commit e930448180
20 changed files with 2805 additions and 22 deletions

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,58 @@
#include "MassMap.h"
/*
Read in AMDC mass file, preformated to remove excess info. Here assumes that by default
the file is in a local directory etc/
*/
MassMap::MassMap()
{
std::ifstream massfile("Resources/amdc2016_mass.txt");
if (massfile.is_open())
{
std::string junk, A, element;
int Z;
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 + ")";
massTable[key] = isotopicMass;
elementTable[Z] = element;
}
}
else
{
NAV_ERROR("Unable to load mass file! Make sure that the Resources folder exists!");
}
}
MassMap::~MassMap() {}
//Returns nuclear mass in MeV
double MassMap::FindMass(int Z, int A)
{
std::string key = "(" + std::to_string(Z) + "," + std::to_string(A) + ")";
auto data = massTable.find(key);
if (data == massTable.end())
{
NAV_ERROR("Invalid nucleus at MassMap::FindMass()! Z: {0} A: {1}", Z, A);
return 0.0;
}
return data->second;
}
//returns element symbol
std::string MassMap::FindSymbol(int Z, int A)
{
auto data = elementTable.find(Z);
if (data == elementTable.end())
{
NAV_ERROR("Invalid nucleus at MassMap::FindSymbol()! Z: {0} A: {1}", Z, A);
return "";
}
std::string fullsymbol = std::to_string(A) + data->second;
return fullsymbol;
}

23
NavProject/src/MassMap.h Normal file
View File

@ -0,0 +1,23 @@
#ifndef MASS_MAP_H
#define MASS_MAP_H
#include "Navigator.h"
class MassMap
{
public:
MassMap();
~MassMap();
double FindMass(int Z, int A);
std::string FindSymbol(int Z, int A);
private:
std::unordered_map<std::string, double> massTable;
std::unordered_map<int, std::string> elementTable;
//constants
static constexpr double u_to_mev = 931.4940954;
static constexpr double electron_mass = 0.000548579909;
};
#endif

View File

@ -11,7 +11,7 @@ namespace Navigator {
//Construct each NavParameter with their unique name. Then bind them to the SpectrumManager. //Construct each NavParameter with their unique name. Then bind them to the SpectrumManager.
SPSAnalysisStage::SPSAnalysisStage() : SPSAnalysisStage::SPSAnalysisStage() :
AnalysisStage("SPSAnalysis"), delayFLTime("delayFLTime"), delayFRTime("delayFRTime"), delayBLTime("delayBLTime"), delayBRTime("delayBRTime"), x1("x1"), x2("x2"), xavg("xavg"), AnalysisStage("SPSAnalysis"), delayFLTime("delayFLTime"), delayFRTime("delayFRTime"), delayBLTime("delayBLTime"), delayBRTime("delayBRTime"), x1("x1"), x2("x2"), xavg("xavg"),
scintLeft("scintLeft"), anodeBack("anodeBack") scintLeft("scintLeft"), anodeBack("anodeBack"), x1_weight("x1_weight"), x2_weight("x2_weight")
{ {
SpectrumManager& manager = SpectrumManager::GetInstance(); SpectrumManager& manager = SpectrumManager::GetInstance();
manager.BindParameter(delayFLTime); manager.BindParameter(delayFLTime);
@ -23,6 +23,9 @@ namespace Navigator {
manager.BindParameter(xavg); manager.BindParameter(xavg);
manager.BindParameter(scintLeft); manager.BindParameter(scintLeft);
manager.BindParameter(anodeBack); manager.BindParameter(anodeBack);
manager.BindVariable(x1_weight);
manager.BindVariable(x2_weight);
} }
SPSAnalysisStage::~SPSAnalysisStage() {} SPSAnalysisStage::~SPSAnalysisStage() {}
@ -66,5 +69,8 @@ namespace Navigator {
if(delayBLTime.IsValid() && delayBRTime.IsValid()) if(delayBLTime.IsValid() && delayBRTime.IsValid())
x2.SetValue((delayBLTime.GetValue() - delayBRTime.GetValue())*0.5); x2.SetValue((delayBLTime.GetValue() - delayBRTime.GetValue())*0.5);
if (x1.IsValid() && x2.IsValid())
xavg.SetValue(x1_weight.GetValue() * x1.GetValue() + x2_weight.GetValue() * x2.GetValue());
} }
} }

View File

@ -28,9 +28,9 @@ namespace Navigator {
NavParameter scintLeft; NavParameter scintLeft;
NavParameter anodeBack; NavParameter anodeBack;
//some variables. //Create a few variables
double weight1 = 1.7; NavVariable x1_weight;
double weight2 = -0.7; NavVariable x2_weight;
}; };
} }

View File

@ -0,0 +1,70 @@
#include "SPSInputLayer.h"
#include "imgui.h"
namespace Navigator {
SPSInputLayer::SPSInputLayer() :
Layer("SPSInputLayer"), x1_weight("x1_weight"), x2_weight("x2_weight"), m_bfield(0.0), m_theta(0.0), m_beamKE(0.0),
m_targMass(0.0), m_projMass(0.0), m_ejectMass(0.0), m_residMass(0.0)
{
for (int i = 0; i < 2; i++)
{
m_targNums[i] = 0;
m_projNums[i] = 0;
m_ejectNums[i] = 0;
m_residNums[i] = 0;
}
SpectrumManager& manager = SpectrumManager::GetInstance();
manager.BindVariable(x1_weight);
manager.BindVariable(x2_weight);
}
SPSInputLayer::~SPSInputLayer() {}
void SPSInputLayer::OnAttach() {}
void SPSInputLayer::OnDetach() {}
void SPSInputLayer::OnUpdate() {}
void SPSInputLayer::OnEvent(Event& event) {}
void SPSInputLayer::OnImGuiRender()
{
ImGui::SetCurrentContext(ImGui::GetCurrentContext());
if (ImGui::Begin("SPS Input"))
{
ImGui::InputDouble("Bfield(kG)", &m_bfield, 0.01, 0.1);
ImGui::InputDouble("Theta(deg)", &m_theta, 0.1, 1.0);
ImGui::InputDouble("BeamKE(MeV)", &m_beamKE, 0.1, 1.0);
ImGui::InputInt2("Target Z,A", m_targNums);
ImGui::InputInt2("Projectile Z,A", m_projNums);
ImGui::InputInt2("Ejectile Z,A", m_ejectNums);
if (ImGui::Button("Set"))
{
UpdateWeights();
}
ImGui::End();
}
}
void SPSInputLayer::UpdateWeights()
{
for (int i = 0; i < 2; i++)
m_residNums[i] = m_targNums[i] + m_projNums[i] - m_ejectNums[i];
if (m_residNums[0] < 0 || m_residNums[1] <= 0)
{
NAV_ERROR("Invalid residual nucleus at SPSInputLayer::UpdateMasses()! ZR: {0} AR: {1}", m_residNums[0], m_residNums[1]);
return;
}
m_targMass = m_masses.FindMass(m_targNums[0], m_targNums[1]);
m_projMass = m_masses.FindMass(m_projNums[0], m_projNums[1]);
m_ejectMass = m_masses.FindMass(m_ejectNums[0], m_ejectNums[1]);
m_residMass = m_masses.FindMass(m_residNums[0], m_residNums[1]);
if (m_targMass == 0.0 || m_projMass == 0.0 || m_ejectMass == 0.0 || m_residMass == 0.0)
return;
}
}

View File

@ -0,0 +1,46 @@
#ifndef SPS_INPUT_LAYER_H
#define SPS_INPUT_LAYER_H
#include "Navigator.h"
#include "MassMap.h"
namespace Navigator {
class SPSInputLayer : public Layer
{
public:
SPSInputLayer();
~SPSInputLayer();
virtual void OnAttach() override;
virtual void OnDetach() override;
virtual void OnUpdate() override;
virtual void OnEvent(Event& event) override;
virtual void OnImGuiRender() override;
private:
void UpdateWeights();
//Variables for use in analysis
NavVariable x1_weight;
NavVariable x2_weight;
//UI facing inputs
double m_bfield; //kG
double m_theta; //deg
double m_beamKE; //MeV
int m_targNums[2];
int m_projNums[2];
int m_ejectNums[2];
int m_residNums[2];
//Internal values
double m_targMass, m_projMass, m_ejectMass, m_residMass;
//Map for mass table
MassMap m_masses;
};
}
#endif

View File

@ -6,6 +6,7 @@
*/ */
#include "Navigator.h" #include "Navigator.h"
#include "SPSAnalysisStage.h" #include "SPSAnalysisStage.h"
#include "SPSInputLayer.h"
//User application class. Pushes user analysis stages. //User application class. Pushes user analysis stages.
class SPSApp : public Navigator::Application class SPSApp : public Navigator::Application
@ -14,6 +15,7 @@ public:
SPSApp() : SPSApp() :
Navigator::Application() Navigator::Application()
{ {
PushLayer(new Navigator::SPSInputLayer());
PushAnalysisStage(new Navigator::SPSAnalysisStage()); PushAnalysisStage(new Navigator::SPSAnalysisStage());
} }
}; };

View File

@ -68,8 +68,8 @@ namespace Navigator {
//config.GlyphMinAdvanceX = 13.0f; // Use if you want to make the icon monospaced //config.GlyphMinAdvanceX = 13.0f; // Use if you want to make the icon monospaced
config.PixelSnapH = true; config.PixelSnapH = true;
static const ImWchar icon_ranges[] = { ICON_MIN_FA, ICON_MAX_FA, 0 }; static const ImWchar icon_ranges[] = { ICON_MIN_FA, ICON_MAX_FA, 0 };
io.Fonts->AddFontFromFileTTF("fonts/Roboto-Regular.ttf", 16.0f, &latin_config, io.Fonts->GetGlyphRangesDefault()); io.Fonts->AddFontFromFileTTF("Resources/fonts/Roboto-Regular.ttf", 16.0f, &latin_config, io.Fonts->GetGlyphRangesDefault());
io.Fonts->AddFontFromFileTTF("fonts/fa-solid-900.ttf", 16.0f, &config, icon_ranges); io.Fonts->AddFontFromFileTTF("Resources/fonts/fa-solid-900.ttf", 16.0f, &config, icon_ranges);
Application& app = Application::Get(); Application& app = Application::Get();
GLFWwindow* window = static_cast<GLFWwindow*>(app.GetWindow().GetNativeWindow()); GLFWwindow* window = static_cast<GLFWwindow*>(app.GetWindow().GetNativeWindow());

View File

@ -6,11 +6,7 @@
is just an empty expression. is just an empty expression.
*/ */
#ifdef NAV_WINDOWS #ifdef NAV_WINDOWS
#ifdef NAV_EXPORT #define NAV_API
#define NAV_API __declspec(dllexport)
#else
#define NAV_API __declspec(dllimport)
#endif
#ifdef _MSC_VER #ifdef _MSC_VER
#pragma warning (disable: 4127) // condition expression is constant #pragma warning (disable: 4127) // condition expression is constant

View File

@ -39,4 +39,15 @@ namespace Navigator {
NavParameter::~NavParameter() {} NavParameter::~NavParameter() {}
NavVariable::NavVariable() :
m_name(""), m_pdata(nullptr)
{
}
NavVariable::NavVariable(const std::string& name) :
m_name(name), m_pdata(nullptr)
{
}
NavVariable::~NavVariable() {}
} }

View File

@ -22,8 +22,8 @@
GWM -- Feb 2022 GWM -- Feb 2022
*/ */
#ifndef PARAMETER_MAP_H #ifndef PARAMETER_H
#define PARAMETER_MAP_H #define PARAMETER_H
#include "NavCore.h" #include "NavCore.h"
@ -58,6 +58,28 @@ namespace Navigator {
}; };
//Similar to parameters, sometimes you want to have a numeric input (in calculation terms, a constant)
//which you can use with your analysis. To be able to expose these numeric values to the UI, we need to implement them
//in the manager. To help with this, NavVariables are atomics. So unlike NavParameters they are implicity thread safe on read and write.
//However, this does not mean they can be modified in the analysis! To the AnalysisStage they should be treated as constant, while the UI
//should view them as modifiable. These are real god damn dangerous, but I think the power they offer outweighs the risk, for now.
class NAV_API NavVariable
{
public:
NavVariable();
NavVariable(const std::string& name);
~NavVariable();
inline void SetValue(double value) { *(m_pdata) = value; }
inline double GetValue() { return *(m_pdata); }
inline const std::string& GetName() { return m_name; }
friend class SpectrumManager;
private:
std::shared_ptr<std::atomic<double>> m_pdata;
std::string m_name;
};
} }
#endif #endif

View File

@ -224,6 +224,31 @@ namespace Navigator {
/*************Parameter Functions End*************/ /*************Parameter Functions End*************/
/*************Variable Functions Begin*************/
void SpectrumManager::BindVariable(NavVariable& var)
{
std::lock_guard<std::mutex> guard(m_managerMutex);
auto iter = m_varMap.find(var.GetName());
if (iter == m_varMap.end())
{
m_varMap[var.GetName()].reset(new std::atomic<double>(0.0));
}
var.m_pdata = m_varMap[var.GetName()];
}
std::vector<std::string> SpectrumManager::GetListOfVariables()
{
std::lock_guard<std::mutex> guard(m_managerMutex);
std::vector<std::string> list;
list.reserve(m_varMap.size());
for (auto iter : m_varMap)
list.push_back(iter.first);
return list;
}
/*************Variable Functions End*************/
/*************Cut Functions Begin*************/ /*************Cut Functions Begin*************/
void SpectrumManager::RemoveCut(const std::string& name) void SpectrumManager::RemoveCut(const std::string& name)

View File

@ -57,6 +57,11 @@ namespace Navigator {
void BindParameter(NavParameter& param); void BindParameter(NavParameter& param);
void InvalidateParameters(); void InvalidateParameters();
std::vector<std::string> GetListOfParameters(); std::vector<std::string> GetListOfParameters();
/*********************/
/*Variable Functions*/
void BindVariable(NavVariable& var);
std::vector<std::string> GetListOfVariables();
/********************/ /********************/
/*Cut Functions*/ /*Cut Functions*/
@ -88,6 +93,7 @@ namespace Navigator {
std::unordered_map<std::string, std::shared_ptr<Histogram>> m_histoMap; std::unordered_map<std::string, std::shared_ptr<Histogram>> m_histoMap;
std::unordered_map<std::string, std::shared_ptr<Cut>> m_cutMap; std::unordered_map<std::string, std::shared_ptr<Cut>> m_cutMap;
std::unordered_map<std::string, std::shared_ptr<ParameterData>> m_paramMap; std::unordered_map<std::string, std::shared_ptr<ParameterData>> m_paramMap;
std::unordered_map<std::string, std::shared_ptr<std::atomic<double>>> m_varMap;
HistogramParameters m_nullHistoResult; //For handling bad query HistogramParameters m_nullHistoResult; //For handling bad query

View File

@ -24,7 +24,7 @@ include "Navigator/vendor/imgui"
include "Navigator/vendor/glad" include "Navigator/vendor/glad"
project "Navigator" project "Navigator"
location "Navigator" location "Navigator"
kind "SharedLib" kind "StaticLib"
language "C++" language "C++"
cppdialect "C++17" cppdialect "C++17"
targetdir ("lib/" .. outputdir .. "/%{prj.name}") targetdir ("lib/" .. outputdir .. "/%{prj.name}")
@ -107,17 +107,13 @@ project "Navigator"
"IOKit.framework", "IOKit.framework",
"OpenGL.framework", "OpenGL.framework",
"Carbon.framework", "Carbon.framework",
"dl", "dl"
} }
linkoptions{ linkoptions{
"-pthread", "-pthread",
"-undefined dynamic_lookup" "-undefined dynamic_lookup"
} }
filter "system:windows" filter "system:windows"
defines "NAV_EXPORT"
postbuildcommands {
("{COPY} %{cfg.buildtarget.relpath} \"../bin/" .. outputdir .. "/NavProject/\"")
}
links { links {
"opengl32.lib" "opengl32.lib"
} }
@ -141,8 +137,8 @@ project "NavProject"
objdir ("bin-int/" .. outputdir .. "/%{prj.name}") objdir ("bin-int/" .. outputdir .. "/%{prj.name}")
files { files {
"NavProject/*.h", "NavProject/src/*.h",
"NavProject/*.cpp" "NavProject/src/*.cpp"
} }
includedirs { includedirs {
@ -165,7 +161,7 @@ project "NavProject"
systemversion "latest" systemversion "latest"
postbuildcommands { postbuildcommands {
(" {COPYDIR} fonts %{cfg.targetdir} ") (" {COPYDIR} Resources %{cfg.targetdir} ")
} }
filter "system:macosx" filter "system:macosx"
@ -180,10 +176,32 @@ project "NavProject"
"%{IncludeDirs.asio}", "%{IncludeDirs.asio}",
"%{IncludeDirs.IconFonts}" "%{IncludeDirs.IconFonts}"
} }
links {
"Cocoa.framework",
"CoreVideo.framework",
"IOKit.framework",
"OpenGL.framework",
"Carbon.framework",
"GLFW",
"GLAD",
"ImGui",
"dl"
}
linkoptions {
"-pthread"
}
filter "system:windows" filter "system:windows"
defines "NAV_WINDOWS" defines "NAV_WINDOWS"
filter "system:linux" filter "system:linux"
defines "NAV_LINUX" defines "NAV_LINUX"
links {
"GL",
"X11",
"GLFW",
"GLAD",
"ImGui",
"dl"
}