mirror of
https://github.com/gwm17/Specter.git
synced 2024-11-26 12:18:51 -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:
parent
2c4af3a0e0
commit
e930448180
2500
NavProject/Resources/amdc2016_mass.txt
Normal file
2500
NavProject/Resources/amdc2016_mass.txt
Normal file
File diff suppressed because it is too large
Load Diff
58
NavProject/src/MassMap.cpp
Normal file
58
NavProject/src/MassMap.cpp
Normal 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
23
NavProject/src/MassMap.h
Normal 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
|
|
@ -11,7 +11,7 @@ namespace Navigator {
|
|||
//Construct each NavParameter with their unique name. Then bind them to the SpectrumManager.
|
||||
SPSAnalysisStage::SPSAnalysisStage() :
|
||||
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();
|
||||
manager.BindParameter(delayFLTime);
|
||||
|
@ -23,6 +23,9 @@ namespace Navigator {
|
|||
manager.BindParameter(xavg);
|
||||
manager.BindParameter(scintLeft);
|
||||
manager.BindParameter(anodeBack);
|
||||
|
||||
manager.BindVariable(x1_weight);
|
||||
manager.BindVariable(x2_weight);
|
||||
}
|
||||
|
||||
SPSAnalysisStage::~SPSAnalysisStage() {}
|
||||
|
@ -66,5 +69,8 @@ namespace Navigator {
|
|||
|
||||
if(delayBLTime.IsValid() && delayBRTime.IsValid())
|
||||
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());
|
||||
}
|
||||
}
|
|
@ -28,9 +28,9 @@ namespace Navigator {
|
|||
NavParameter scintLeft;
|
||||
NavParameter anodeBack;
|
||||
|
||||
//some variables.
|
||||
double weight1 = 1.7;
|
||||
double weight2 = -0.7;
|
||||
//Create a few variables
|
||||
NavVariable x1_weight;
|
||||
NavVariable x2_weight;
|
||||
};
|
||||
|
||||
}
|
70
NavProject/src/SPSInputLayer.cpp
Normal file
70
NavProject/src/SPSInputLayer.cpp
Normal 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;
|
||||
|
||||
}
|
||||
}
|
46
NavProject/src/SPSInputLayer.h
Normal file
46
NavProject/src/SPSInputLayer.h
Normal 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
|
|
@ -6,6 +6,7 @@
|
|||
*/
|
||||
#include "Navigator.h"
|
||||
#include "SPSAnalysisStage.h"
|
||||
#include "SPSInputLayer.h"
|
||||
|
||||
//User application class. Pushes user analysis stages.
|
||||
class SPSApp : public Navigator::Application
|
||||
|
@ -14,6 +15,7 @@ public:
|
|||
SPSApp() :
|
||||
Navigator::Application()
|
||||
{
|
||||
PushLayer(new Navigator::SPSInputLayer());
|
||||
PushAnalysisStage(new Navigator::SPSAnalysisStage());
|
||||
}
|
||||
};
|
|
@ -68,8 +68,8 @@ namespace Navigator {
|
|||
//config.GlyphMinAdvanceX = 13.0f; // Use if you want to make the icon monospaced
|
||||
config.PixelSnapH = true;
|
||||
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("fonts/fa-solid-900.ttf", 16.0f, &config, icon_ranges);
|
||||
io.Fonts->AddFontFromFileTTF("Resources/fonts/Roboto-Regular.ttf", 16.0f, &latin_config, io.Fonts->GetGlyphRangesDefault());
|
||||
io.Fonts->AddFontFromFileTTF("Resources/fonts/fa-solid-900.ttf", 16.0f, &config, icon_ranges);
|
||||
|
||||
Application& app = Application::Get();
|
||||
GLFWwindow* window = static_cast<GLFWwindow*>(app.GetWindow().GetNativeWindow());
|
||||
|
|
|
@ -6,11 +6,7 @@
|
|||
is just an empty expression.
|
||||
*/
|
||||
#ifdef NAV_WINDOWS
|
||||
#ifdef NAV_EXPORT
|
||||
#define NAV_API __declspec(dllexport)
|
||||
#else
|
||||
#define NAV_API __declspec(dllimport)
|
||||
#endif
|
||||
#define NAV_API
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning (disable: 4127) // condition expression is constant
|
||||
|
|
|
@ -39,4 +39,15 @@ namespace Navigator {
|
|||
|
||||
NavParameter::~NavParameter() {}
|
||||
|
||||
NavVariable::NavVariable() :
|
||||
m_name(""), m_pdata(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
NavVariable::NavVariable(const std::string& name) :
|
||||
m_name(name), m_pdata(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
NavVariable::~NavVariable() {}
|
||||
}
|
||||
|
|
|
@ -22,8 +22,8 @@
|
|||
|
||||
GWM -- Feb 2022
|
||||
*/
|
||||
#ifndef PARAMETER_MAP_H
|
||||
#define PARAMETER_MAP_H
|
||||
#ifndef PARAMETER_H
|
||||
#define PARAMETER_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
|
||||
|
|
|
@ -224,6 +224,31 @@ namespace Navigator {
|
|||
|
||||
/*************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*************/
|
||||
|
||||
void SpectrumManager::RemoveCut(const std::string& name)
|
||||
|
|
|
@ -57,6 +57,11 @@ namespace Navigator {
|
|||
void BindParameter(NavParameter& param);
|
||||
void InvalidateParameters();
|
||||
std::vector<std::string> GetListOfParameters();
|
||||
/*********************/
|
||||
|
||||
/*Variable Functions*/
|
||||
void BindVariable(NavVariable& var);
|
||||
std::vector<std::string> GetListOfVariables();
|
||||
/********************/
|
||||
|
||||
/*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<Cut>> m_cutMap;
|
||||
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
|
||||
|
||||
|
|
36
premake5.lua
36
premake5.lua
|
@ -24,7 +24,7 @@ include "Navigator/vendor/imgui"
|
|||
include "Navigator/vendor/glad"
|
||||
project "Navigator"
|
||||
location "Navigator"
|
||||
kind "SharedLib"
|
||||
kind "StaticLib"
|
||||
language "C++"
|
||||
cppdialect "C++17"
|
||||
targetdir ("lib/" .. outputdir .. "/%{prj.name}")
|
||||
|
@ -107,17 +107,13 @@ project "Navigator"
|
|||
"IOKit.framework",
|
||||
"OpenGL.framework",
|
||||
"Carbon.framework",
|
||||
"dl",
|
||||
"dl"
|
||||
}
|
||||
linkoptions{
|
||||
"-pthread",
|
||||
"-undefined dynamic_lookup"
|
||||
}
|
||||
filter "system:windows"
|
||||
defines "NAV_EXPORT"
|
||||
postbuildcommands {
|
||||
("{COPY} %{cfg.buildtarget.relpath} \"../bin/" .. outputdir .. "/NavProject/\"")
|
||||
}
|
||||
links {
|
||||
"opengl32.lib"
|
||||
}
|
||||
|
@ -141,8 +137,8 @@ project "NavProject"
|
|||
objdir ("bin-int/" .. outputdir .. "/%{prj.name}")
|
||||
|
||||
files {
|
||||
"NavProject/*.h",
|
||||
"NavProject/*.cpp"
|
||||
"NavProject/src/*.h",
|
||||
"NavProject/src/*.cpp"
|
||||
}
|
||||
|
||||
includedirs {
|
||||
|
@ -165,7 +161,7 @@ project "NavProject"
|
|||
systemversion "latest"
|
||||
|
||||
postbuildcommands {
|
||||
(" {COPYDIR} fonts %{cfg.targetdir} ")
|
||||
(" {COPYDIR} Resources %{cfg.targetdir} ")
|
||||
}
|
||||
|
||||
filter "system:macosx"
|
||||
|
@ -180,10 +176,32 @@ project "NavProject"
|
|||
"%{IncludeDirs.asio}",
|
||||
"%{IncludeDirs.IconFonts}"
|
||||
}
|
||||
links {
|
||||
"Cocoa.framework",
|
||||
"CoreVideo.framework",
|
||||
"IOKit.framework",
|
||||
"OpenGL.framework",
|
||||
"Carbon.framework",
|
||||
"GLFW",
|
||||
"GLAD",
|
||||
"ImGui",
|
||||
"dl"
|
||||
}
|
||||
linkoptions {
|
||||
"-pthread"
|
||||
}
|
||||
filter "system:windows"
|
||||
defines "NAV_WINDOWS"
|
||||
filter "system:linux"
|
||||
defines "NAV_LINUX"
|
||||
links {
|
||||
"GL",
|
||||
"X11",
|
||||
"GLFW",
|
||||
"GLAD",
|
||||
"ImGui",
|
||||
"dl"
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user