1
0
Fork 0
mirror of https://github.com/gwm17/Specter.git synced 2024-11-22 18:28:52 -05:00

Added SpectrumDialog to Editor. Fixed histogram classes to use parameter struct as construction input.

This commit is contained in:
Gordon McCann 2022-01-19 22:45:14 -05:00
parent ccaae99472
commit 88502eec77
16 changed files with 233 additions and 97 deletions

View File

@ -24,8 +24,8 @@ namespace Navigator {
m_imgui_layer = new ImGuiLayer();
PushOverlay(m_imgui_layer);
HistogramMap& histMap = HistogramMap::GetInstance();
histMap.AddHistogram("myHisto", "joseph", 100, 0, 10);
histMap.AddHistogram("myHisto2D", "joseph", "joseph", 100, 0, 10, 100, 0, 10);
histMap.AddHistogram(HistogramParameters("myHisto", "joseph", 100, 0, 10));
histMap.AddHistogram(HistogramParameters("myHisto2D", "joseph", "joseph", 100, 0, 10, 100, 0, 10));
CutMap::GetInstance().AddCut("joe_cut","joseph",0.0, 7.0);
CutMap::GetInstance().AddCut("joe2D_cut", "joseph", "joseph", { 1.0, 3.0, 3.0, 1.0, 1.0}, { 1.0, 1.0, 3.0, 3.0, 1.0});
@ -40,13 +40,6 @@ namespace Navigator {
{
}
void Application::SetParameterList()
{
m_parameterList = ParameterMap::GetInstance().GetListOfParameters();
PhysicsParamEvent event;
OnEvent(event);
}
void Application::OnEvent(Event& event)
{
EventDispatcher dispatch(event);

View File

@ -26,12 +26,8 @@ namespace Navigator {
void PushLayer(Layer* layer);
inline void PushAnalysisStage(AnalysisStage* stage) { m_physicsLayer->PushStage(stage); }
void PushOverlay(Layer* layer);
void SetParameterList();
inline const std::vector<std::string>& GetParameterList() { return m_parameterList; }
inline static Application& Get() { return *s_instance; }
inline static void LinkParameterList() { s_instance->SetParameterList(); }
inline Window& GetWindow() { return *m_window; }
@ -42,7 +38,6 @@ namespace Navigator {
std::unique_ptr<Window> m_window;
ImGuiLayer* m_imgui_layer;
PhysicsLayer* m_physicsLayer;
std::vector<std::string> m_parameterList;
bool m_runFlag;
float m_bckgnd_color[4] = {0.1, 0.1, 0.1, 1.0};

View File

@ -74,6 +74,8 @@ namespace Navigator {
class NAV_API CutMap
{
public:
using Iter = std::unordered_map<std::string, std::unique_ptr<Cut>>::iterator;
CutMap();
~CutMap();
@ -92,6 +94,9 @@ namespace Navigator {
bool IsInsideCut(const std::string& name, double xval, double yval = 0);
std::vector<CutParams> GetListOfCutParams();
inline Iter begin() { return m_map.begin(); }
inline Iter end() { return m_map.end(); }
private:
std::unordered_map<std::string, std::unique_ptr<Cut>> m_map;
std::mutex m_cutMutex;

View File

@ -27,25 +27,14 @@ namespace Navigator {
void EditorLayer::OnEvent(Event& e)
{
EventDispatcher dispatch(e);
dispatch.Dispatch<PhysicsParamEvent>(BIND_EVENT_FUNCTION(EditorLayer::OnPhysicsParamEvent));
}
void EditorLayer::UpdateHistogramLists()
{
m_histoList = HistogramMap::GetInstance().GetListOfHistogramParams();
m_spectrumPanel.UpdateActiveList(m_histoList);
}
void EditorLayer::UpdateCutLists()
{
m_cutList = CutMap::GetInstance().GetListOfCutParams();
}
void EditorLayer::OnImGuiRender()
{
// We are using the ImGuiWindowFlags_NoDocking flag to make the parent window not dockable into,
// because it would be confusing to have two docking targets within each others.
HistogramMap& histoMap = HistogramMap::GetInstance();
CutMap& cutMap = CutMap::GetInstance();
if (opt_fullscreen)
{
ImGuiViewport* viewport = ImGui::GetMainViewport();
@ -118,6 +107,7 @@ namespace Navigator {
{
if (ImGui::MenuItem("Spectrum"))
{
m_spectrumDialog.SetSpectrumDialog();
}
ImGui::EndMenu();
}
@ -142,15 +132,15 @@ namespace Navigator {
else if (!save_file_result.empty())
NAV_INFO("Found a Save File!");
m_spectrumDialog.ImGuiRenderSpectrumDialog();
UpdateHistogramLists();
UpdateCutLists();
m_spectrumPanel.OnImGuiRender();
if (ImGui::Begin("Spectra"))
{
for (auto& params : m_histoList)
for (auto& gram : histoMap)
{
auto& params = gram.second->GetParameters();
if (ImGui::TreeNode(params.name.c_str()))
{
ImGui::BulletText("X Parameter: %s", params.x_par.c_str());
@ -180,8 +170,9 @@ namespace Navigator {
if(ImGui::Begin("Cuts"))
{
for(auto& params : m_cutList)
for(auto& cut : cutMap)
{
auto& params = cut.second->GetCutParams();
if(ImGui::TreeNode(params.name.c_str()))
{
ImGui::BulletText("X Parameter: %s", params.x_par.c_str());
@ -195,11 +186,4 @@ namespace Navigator {
ImGui::End();
}
bool EditorLayer::OnPhysicsParamEvent(PhysicsParamEvent& event)
{
NAV_INFO("{0}", event.ToString());
m_paramList = Application::Get().GetParameterList();
return true;
}
}

View File

@ -8,6 +8,7 @@
#include "Navigator/CutMap.h"
#include "SpectrumPanel.h"
#include "FileDialog.h"
#include "SpectrumDialog.h"
namespace Navigator {
@ -25,14 +26,9 @@ namespace Navigator {
private:
void UpdateHistogramLists();
void UpdateCutLists();
bool OnPhysicsParamEvent(PhysicsParamEvent& event);
std::vector<HistogramParameters> m_histoList;
std::vector<CutParams> m_cutList;
std::vector<std::string> m_paramList;
SpectrumPanel m_spectrumPanel;
FileDialog m_fileDialog;
SpectrumDialog m_spectrumDialog;
//ImGui Settings
bool dockspaceOpen = true;

View File

@ -1,5 +1,5 @@
#include "FileDialog.h"
#include "misc/cpp/imgui_stdlib.cpp"
#include "misc/cpp/imgui_stdlib.h"
namespace Navigator {

View File

@ -0,0 +1,128 @@
#include "SpectrumDialog.h"
#include "misc/cpp/imgui_stdlib.h"
namespace Navigator {
SpectrumDialog::SpectrumDialog()
{
selectFlags = ImGuiSelectableFlags_DontClosePopups;
}
SpectrumDialog::~SpectrumDialog()
{
}
void SpectrumDialog::ImGuiRenderSpectrumDialog()
{
static int dims = 1;
static std::string selectedCut = "";
if (m_openFlag)
{
m_newParams = m_blank;
m_openFlag = false;
dims = 1;
ImGui::OpenPopup("New Spectrum Dialog");
}
if (ImGui::BeginPopupModal("New Spectrum Dialog"))
{
ParameterMap& parMap = ParameterMap::GetInstance();
ImGui::InputText("Spectrum Name", &m_newParams.name);
ImGui::SliderInt("Dimensions", &dims, 1, 2);
if (ImGui::BeginTable("SpecParamsTable", 4))
{
ImGui::TableNextRow();
ImGui::TableNextColumn();
if (ImGui::BeginCombo("X Parameter", m_newParams.x_par.c_str()))
{
for (auto& params : parMap)
{
if (ImGui::Selectable(params.first.c_str(), params.first == m_newParams.x_par, selectFlags))
m_newParams.x_par = params.first;
}
ImGui::EndCombo();
}
ImGui::TableNextColumn();
ImGui::InputInt("X Bins", &m_newParams.nbins_x);
ImGui::TableNextColumn();
ImGui::InputDouble("Min X", &m_newParams.min_x);
ImGui::TableNextColumn();
ImGui::InputDouble("Max X", &m_newParams.max_x);
if (dims == 2)
{
ImGui::TableNextRow();
ImGui::TableNextColumn();
if (ImGui::BeginCombo("Y Parameter", m_newParams.y_par.c_str()))
{
for (auto& params : parMap)
{
if (ImGui::Selectable(params.first.c_str(), params.first == m_newParams.y_par, selectFlags))
m_newParams.y_par = params.first;
}
ImGui::EndCombo();
}
ImGui::TableNextColumn();
ImGui::InputInt("Y Bins", &m_newParams.nbins_y);
ImGui::TableNextColumn();
ImGui::InputDouble("Min Y", &m_newParams.min_y);
ImGui::TableNextColumn();
ImGui::InputDouble("Max Y", &m_newParams.max_y);
}
ImGui::EndTable();
}
if (ImGui::TreeNode("Applied Cuts"))
{
for (auto& name : m_newParams.cutsAppliedTo)
{
ImGui::BulletText(name.c_str());
}
ImGui::TreePop();
}
if (ImGui::Button("Apply Cuts"))
{
selectedCut = "";
ImGui::OpenPopup("Cut List");
}
if (ImGui::BeginPopup("Cut List"))
{
CutMap& cutMap = CutMap::GetInstance();
for (auto& cut : cutMap)
{
if (ImGui::Selectable(cut.first.c_str(), cut.first == selectedCut, selectFlags))
selectedCut = cut.first;
}
ImGui::InputText("Selected Cut", &selectedCut);
if (ImGui::Button("Ok"))
{
m_newParams.cutsAppliedTo.push_back(selectedCut);
ImGui::CloseCurrentPopup();
}
ImGui::SameLine();
if (ImGui::Button("Cancel"))
{
ImGui::CloseCurrentPopup();
}
ImGui::EndPopup();
}
if (ImGui::Button("Ok"))
{
HistogramMap::GetInstance().AddHistogram(m_newParams);
ImGui::CloseCurrentPopup();
}
ImGui::SameLine();
if (ImGui::Button("Cancel"))
{
ImGui::CloseCurrentPopup();
}
ImGui::EndPopup();
}
}
}

View File

@ -0,0 +1,32 @@
#ifndef SPECTRUM_DIALOG_H
#define SPECTRUM_DIALOG_H
#include "Navigator/HistogramMap.h"
#include "Navigator/ParameterMap.h"
#include "Navigator/CutMap.h"
#include "imgui.h"
namespace Navigator {
class NAV_API SpectrumDialog
{
public:
SpectrumDialog();
~SpectrumDialog();
void ImGuiRenderSpectrumDialog();
inline void SetSpectrumDialog() { m_openFlag = true; }
private:
bool m_openFlag;
HistogramParameters m_newParams;
HistogramParameters m_blank;
ImGuiSelectableFlags selectFlags;
};
}
#endif

View File

@ -16,7 +16,7 @@ namespace Navigator {
HistogramMap& histMap = HistogramMap::GetInstance();
if (ImGui::Begin("Active View"))
{
if (m_activeList.size() > 0)
if (histMap.size() > 0)
{
if (m_zoomedFlag && m_zoomedGram != "")
{
@ -51,9 +51,12 @@ namespace Navigator {
label = "Histogram" + std::to_string(this_gram);
if (ImGui::BeginCombo(label.c_str(), m_selectedGrams[this_gram].c_str()))
{
for (auto& params : m_activeList)
for (auto& gram : histMap)
{
auto& params = gram.second->GetParameters();
if (ImGui::Selectable(params.name.c_str(), params.name == m_selectedGrams[this_gram]))
m_selectedGrams[this_gram] = params.name;
}
ImGui::EndCombo();
}
}

View File

@ -15,10 +15,8 @@ namespace Navigator {
void OnImGuiRender();
inline const std::string& GetZoomedOnHistogram() { return m_zoomedGram; }
inline const bool IsZoomed() { return m_zoomedFlag; }
inline void UpdateActiveList(const std::vector<HistogramParameters>& list) { m_activeList = list; }
private:
std::vector<HistogramParameters> m_activeList; //This is where we get our info from. Reduces thread crossings
std::vector<std::string> m_selectedGrams;
bool m_zoomedFlag;
std::string m_zoomedGram;

View File

@ -12,19 +12,16 @@ namespace Navigator {
/*
1D Histogram class
*/
Histogram1D::Histogram1D(const std::string& name, const std::string& param, int bins, double min, double max) :
Histogram(name, param)
Histogram1D::Histogram1D(const HistogramParameters& params) :
Histogram(params)
{
InitBins(bins, min, max);
InitBins();
}
Histogram1D::~Histogram1D() {}
void Histogram1D::InitBins(int bins, double min, double max)
void Histogram1D::InitBins()
{
m_params.nbins_x = bins;
m_params.min_x = min;
m_params.max_x = max;
if(m_params.nbins_x == 0 || (m_params.min_x >= m_params.max_x))
{
NAV_WARN("Attempting to create an illegal Histogram1D {0} with {1} bins and a range from {2} to {3}. Historgram not initialized.", m_params.name, m_params.nbins_x, m_params.min_x, m_params.max_x);
@ -79,24 +76,16 @@ namespace Navigator {
/*
2D Histogram class
*/
Histogram2D::Histogram2D(const std::string& name, const std::string& param_x, const std::string& param_y, int bins_x, double min_x, double max_x,
int bins_y, double min_y, double max_y) :
Histogram(name, param_x, param_y)
Histogram2D::Histogram2D(const HistogramParameters& params) :
Histogram(params)
{
InitBins(bins_x, min_x, max_x, bins_y, min_y, max_y);
InitBins();
}
Histogram2D::~Histogram2D() {}
void Histogram2D::InitBins(int bins_x, double min_x, double max_x, int bins_y, double min_y, double max_y)
void Histogram2D::InitBins()
{
m_params.nbins_x = bins_x;
m_params.min_x = min_x;
m_params.max_x = max_x;
m_params.nbins_y = bins_y;
m_params.min_y = min_y;
m_params.max_y = max_y;
if(m_params.nbins_x <= 0 || m_params.nbins_y <= 0 || m_params.min_x >= m_params.max_x || m_params.min_y >= m_params.max_y)
{
NAV_WARN("Attempting to create illegal Histogram2D {0} with {1} x bins, {2} y bins, an x range of {3} to {4}, and a y range of {5} to {6}. Not initialized.", m_params.name, m_params.nbins_x, m_params.nbins_y,

View File

@ -7,13 +7,21 @@ namespace Navigator {
struct NAV_API HistogramParameters
{
HistogramParameters(const std::string& n, const std::string& x, const std::string& y) :
name(n), x_par(x), y_par(y)
HistogramParameters() {}
HistogramParameters(const std::string& n, const std::string& x, int bins, double min, double max) :
name(n), x_par(x), nbins_x(bins), min_x(min), max_x(max)
{
}
std::string name;
std::string x_par;
std::string y_par;
HistogramParameters(const std::string& n, const std::string& x, const std::string& y, int binsx, double minx, double maxx, int binsy, double miny, double maxy) :
name(n), x_par(x), y_par(y), nbins_x(binsx), min_x(minx), max_x(maxx), nbins_y(binsy), min_y(miny), max_y(maxy)
{
}
std::string name = "None";
std::string x_par = "None";
std::string y_par = "None";
std::vector<std::string> cutsDrawnUpon;
std::vector<std::string> cutsAppliedTo;
int nbins_x = 0;
@ -28,11 +36,11 @@ namespace Navigator {
{
public:
Histogram() :
m_params("None", "None", "None"), m_initFlag(false)
m_initFlag(false)
{
}
Histogram(const std::string& name, const std::string& param_x, const std::string& param_y="None") :
m_params(name, param_x, param_y), m_initFlag(false)
Histogram(const HistogramParameters& params) :
m_params(params), m_initFlag(false)
{
}
@ -57,7 +65,7 @@ namespace Navigator {
class NAV_API Histogram1D : public Histogram
{
public:
Histogram1D(const std::string& name, const std::string& param, int bins, double min, double max);
Histogram1D(const HistogramParameters& params);
virtual ~Histogram1D();
virtual void FillData(double x, double y=0) override;
virtual void Draw() override;
@ -66,7 +74,7 @@ namespace Navigator {
inline virtual bool Is2D() const override { return false; }
private:
void InitBins(int bins, double min, double max);
void InitBins();
std::vector<double> m_binCenters;
std::vector<double> m_binCounts;
@ -77,8 +85,7 @@ namespace Navigator {
class NAV_API Histogram2D : public Histogram
{
public:
Histogram2D(const std::string& name, const std::string& param_x, const std::string& param_y, int bins_x, double min_x, double max_x,
int bins_y, double min_y, double max_y);
Histogram2D(const HistogramParameters& params);
virtual ~Histogram2D();
virtual void FillData(double x, double y=0) override;
virtual void Draw() override;
@ -87,7 +94,7 @@ namespace Navigator {
inline virtual bool Is2D() const override { return true; }
private:
void InitBins(int bins_x, double min_x, double max_x, int bins_y, double min_y, double max_y);
void InitBins();
std::vector<double> m_binCounts;
int m_nBinsTotal;

View File

@ -13,6 +13,14 @@ namespace Navigator {
{
}
void HistogramMap::AddHistogram(const HistogramParameters& params)
{
if (params.y_par == "None")
m_map[params.name].reset(new Histogram1D(params));
else
m_map[params.name].reset(new Histogram2D(params));
}
void HistogramMap::AddCutToHistogramDraw(const std::string &cutname, const std::string &histoname)
{
auto iter = m_map.find(histoname);

View File

@ -9,18 +9,12 @@ namespace Navigator {
class NAV_API HistogramMap
{
public:
using Iter = std::unordered_map<std::string, std::shared_ptr<Histogram>>::iterator;
HistogramMap();
~HistogramMap();
inline void AddHistogram(const std::string& name, const std::string& param, int bins, double min, double max)
{
m_map[name].reset(new Histogram1D(name, param, bins, min, max));
}
inline void AddHistogram(const std::string& name, const std::string& paramx, const std::string& paramy, int bins_x, double min_x, double max_x,
int bins_y, double min_y, double max_y)
{
m_map[name].reset(new Histogram2D(name, paramx, paramy, bins_x, min_x, max_x, bins_y, min_y, max_y));
}
void AddHistogram(const HistogramParameters& params);
void AddCutToHistogramDraw(const std::string& cutname, const std::string& histoname);
void AddCutToHistogramApplied(const std::string& cutname, const std::string& histoname);
@ -33,6 +27,10 @@ namespace Navigator {
static HistogramMap& GetInstance() { return *s_instance; }
inline Iter begin() { return m_map.begin(); }
inline Iter end() { return m_map.end(); }
inline size_t size() { return m_map.size(); }
private:
std::unordered_map<std::string, std::shared_ptr<Histogram>> m_map;

View File

@ -0,0 +1,3 @@
#include "misc/cpp/imgui_stdlib.cpp"

View File

@ -11,10 +11,6 @@ namespace Navigator {
bool validFlag=false;
};
/*
For use inside of the physics thread only!!!!!! Do not use elsewhere as complex operations on parameter values are !not!
guaranteed to be thread-safe, only the accesing is!
*/
class NAV_API NavParameter
{
@ -50,7 +46,8 @@ namespace Navigator {
double GetParameterValue(const std::string& name);
bool IsParameterValid(const std::string& name);
void InvalidateParameters();
std::vector<std::string> GetListOfParameters(); //Dangerous! Should only be used when GUARANTEED no phys thread is running.
std::vector<std::string> GetListOfParameters();
inline Iter end() { return m_map.end(); }
inline Iter begin() { return m_map.begin(); }
inline Iter find(const std::string& name) { return m_map.find(name); }