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:
parent
ccaae99472
commit
88502eec77
|
@ -24,8 +24,8 @@ namespace Navigator {
|
||||||
m_imgui_layer = new ImGuiLayer();
|
m_imgui_layer = new ImGuiLayer();
|
||||||
PushOverlay(m_imgui_layer);
|
PushOverlay(m_imgui_layer);
|
||||||
HistogramMap& histMap = HistogramMap::GetInstance();
|
HistogramMap& histMap = HistogramMap::GetInstance();
|
||||||
histMap.AddHistogram("myHisto", "joseph", 100, 0, 10);
|
histMap.AddHistogram(HistogramParameters("myHisto", "joseph", 100, 0, 10));
|
||||||
histMap.AddHistogram("myHisto2D", "joseph", "joseph", 100, 0, 10, 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("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});
|
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)
|
void Application::OnEvent(Event& event)
|
||||||
{
|
{
|
||||||
EventDispatcher dispatch(event);
|
EventDispatcher dispatch(event);
|
||||||
|
|
|
@ -26,12 +26,8 @@ namespace Navigator {
|
||||||
void PushLayer(Layer* layer);
|
void PushLayer(Layer* layer);
|
||||||
inline void PushAnalysisStage(AnalysisStage* stage) { m_physicsLayer->PushStage(stage); }
|
inline void PushAnalysisStage(AnalysisStage* stage) { m_physicsLayer->PushStage(stage); }
|
||||||
void PushOverlay(Layer* layer);
|
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 Application& Get() { return *s_instance; }
|
||||||
inline static void LinkParameterList() { s_instance->SetParameterList(); }
|
|
||||||
|
|
||||||
inline Window& GetWindow() { return *m_window; }
|
inline Window& GetWindow() { return *m_window; }
|
||||||
|
|
||||||
|
@ -42,7 +38,6 @@ namespace Navigator {
|
||||||
std::unique_ptr<Window> m_window;
|
std::unique_ptr<Window> m_window;
|
||||||
ImGuiLayer* m_imgui_layer;
|
ImGuiLayer* m_imgui_layer;
|
||||||
PhysicsLayer* m_physicsLayer;
|
PhysicsLayer* m_physicsLayer;
|
||||||
std::vector<std::string> m_parameterList;
|
|
||||||
bool m_runFlag;
|
bool m_runFlag;
|
||||||
|
|
||||||
float m_bckgnd_color[4] = {0.1, 0.1, 0.1, 1.0};
|
float m_bckgnd_color[4] = {0.1, 0.1, 0.1, 1.0};
|
||||||
|
|
|
@ -74,6 +74,8 @@ namespace Navigator {
|
||||||
class NAV_API CutMap
|
class NAV_API CutMap
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
using Iter = std::unordered_map<std::string, std::unique_ptr<Cut>>::iterator;
|
||||||
|
|
||||||
CutMap();
|
CutMap();
|
||||||
~CutMap();
|
~CutMap();
|
||||||
|
|
||||||
|
@ -92,6 +94,9 @@ namespace Navigator {
|
||||||
bool IsInsideCut(const std::string& name, double xval, double yval = 0);
|
bool IsInsideCut(const std::string& name, double xval, double yval = 0);
|
||||||
std::vector<CutParams> GetListOfCutParams();
|
std::vector<CutParams> GetListOfCutParams();
|
||||||
|
|
||||||
|
inline Iter begin() { return m_map.begin(); }
|
||||||
|
inline Iter end() { return m_map.end(); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::unordered_map<std::string, std::unique_ptr<Cut>> m_map;
|
std::unordered_map<std::string, std::unique_ptr<Cut>> m_map;
|
||||||
std::mutex m_cutMutex;
|
std::mutex m_cutMutex;
|
||||||
|
|
|
@ -27,25 +27,14 @@ namespace Navigator {
|
||||||
|
|
||||||
void EditorLayer::OnEvent(Event& e)
|
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()
|
void EditorLayer::OnImGuiRender()
|
||||||
{
|
{
|
||||||
// We are using the ImGuiWindowFlags_NoDocking flag to make the parent window not dockable into,
|
// 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.
|
// because it would be confusing to have two docking targets within each others.
|
||||||
|
HistogramMap& histoMap = HistogramMap::GetInstance();
|
||||||
|
CutMap& cutMap = CutMap::GetInstance();
|
||||||
if (opt_fullscreen)
|
if (opt_fullscreen)
|
||||||
{
|
{
|
||||||
ImGuiViewport* viewport = ImGui::GetMainViewport();
|
ImGuiViewport* viewport = ImGui::GetMainViewport();
|
||||||
|
@ -118,6 +107,7 @@ namespace Navigator {
|
||||||
{
|
{
|
||||||
if (ImGui::MenuItem("Spectrum"))
|
if (ImGui::MenuItem("Spectrum"))
|
||||||
{
|
{
|
||||||
|
m_spectrumDialog.SetSpectrumDialog();
|
||||||
}
|
}
|
||||||
ImGui::EndMenu();
|
ImGui::EndMenu();
|
||||||
}
|
}
|
||||||
|
@ -141,16 +131,16 @@ namespace Navigator {
|
||||||
NAV_INFO("Found a Open File!");
|
NAV_INFO("Found a Open File!");
|
||||||
else if (!save_file_result.empty())
|
else if (!save_file_result.empty())
|
||||||
NAV_INFO("Found a Save File!");
|
NAV_INFO("Found a Save File!");
|
||||||
|
|
||||||
|
m_spectrumDialog.ImGuiRenderSpectrumDialog();
|
||||||
|
|
||||||
|
|
||||||
UpdateHistogramLists();
|
|
||||||
UpdateCutLists();
|
|
||||||
m_spectrumPanel.OnImGuiRender();
|
m_spectrumPanel.OnImGuiRender();
|
||||||
|
|
||||||
if (ImGui::Begin("Spectra"))
|
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()))
|
if (ImGui::TreeNode(params.name.c_str()))
|
||||||
{
|
{
|
||||||
ImGui::BulletText("X Parameter: %s", params.x_par.c_str());
|
ImGui::BulletText("X Parameter: %s", params.x_par.c_str());
|
||||||
|
@ -180,8 +170,9 @@ namespace Navigator {
|
||||||
|
|
||||||
if(ImGui::Begin("Cuts"))
|
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()))
|
if(ImGui::TreeNode(params.name.c_str()))
|
||||||
{
|
{
|
||||||
ImGui::BulletText("X Parameter: %s", params.x_par.c_str());
|
ImGui::BulletText("X Parameter: %s", params.x_par.c_str());
|
||||||
|
@ -195,11 +186,4 @@ namespace Navigator {
|
||||||
|
|
||||||
ImGui::End();
|
ImGui::End();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool EditorLayer::OnPhysicsParamEvent(PhysicsParamEvent& event)
|
|
||||||
{
|
|
||||||
NAV_INFO("{0}", event.ToString());
|
|
||||||
m_paramList = Application::Get().GetParameterList();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
#include "Navigator/CutMap.h"
|
#include "Navigator/CutMap.h"
|
||||||
#include "SpectrumPanel.h"
|
#include "SpectrumPanel.h"
|
||||||
#include "FileDialog.h"
|
#include "FileDialog.h"
|
||||||
|
#include "SpectrumDialog.h"
|
||||||
|
|
||||||
namespace Navigator {
|
namespace Navigator {
|
||||||
|
|
||||||
|
@ -25,14 +26,9 @@ namespace Navigator {
|
||||||
|
|
||||||
|
|
||||||
private:
|
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;
|
SpectrumPanel m_spectrumPanel;
|
||||||
FileDialog m_fileDialog;
|
FileDialog m_fileDialog;
|
||||||
|
SpectrumDialog m_spectrumDialog;
|
||||||
|
|
||||||
//ImGui Settings
|
//ImGui Settings
|
||||||
bool dockspaceOpen = true;
|
bool dockspaceOpen = true;
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#include "FileDialog.h"
|
#include "FileDialog.h"
|
||||||
#include "misc/cpp/imgui_stdlib.cpp"
|
#include "misc/cpp/imgui_stdlib.h"
|
||||||
|
|
||||||
namespace Navigator {
|
namespace Navigator {
|
||||||
|
|
||||||
|
|
128
Navigator/src/Navigator/Editor/SpectrumDialog.cpp
Normal file
128
Navigator/src/Navigator/Editor/SpectrumDialog.cpp
Normal 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
32
Navigator/src/Navigator/Editor/SpectrumDialog.h
Normal file
32
Navigator/src/Navigator/Editor/SpectrumDialog.h
Normal 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
|
|
@ -16,7 +16,7 @@ namespace Navigator {
|
||||||
HistogramMap& histMap = HistogramMap::GetInstance();
|
HistogramMap& histMap = HistogramMap::GetInstance();
|
||||||
if (ImGui::Begin("Active View"))
|
if (ImGui::Begin("Active View"))
|
||||||
{
|
{
|
||||||
if (m_activeList.size() > 0)
|
if (histMap.size() > 0)
|
||||||
{
|
{
|
||||||
if (m_zoomedFlag && m_zoomedGram != "")
|
if (m_zoomedFlag && m_zoomedGram != "")
|
||||||
{
|
{
|
||||||
|
@ -51,9 +51,12 @@ namespace Navigator {
|
||||||
label = "Histogram" + std::to_string(this_gram);
|
label = "Histogram" + std::to_string(this_gram);
|
||||||
if (ImGui::BeginCombo(label.c_str(), m_selectedGrams[this_gram].c_str()))
|
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]))
|
if (ImGui::Selectable(params.name.c_str(), params.name == m_selectedGrams[this_gram]))
|
||||||
m_selectedGrams[this_gram] = params.name;
|
m_selectedGrams[this_gram] = params.name;
|
||||||
|
}
|
||||||
ImGui::EndCombo();
|
ImGui::EndCombo();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,10 +15,8 @@ namespace Navigator {
|
||||||
void OnImGuiRender();
|
void OnImGuiRender();
|
||||||
inline const std::string& GetZoomedOnHistogram() { return m_zoomedGram; }
|
inline const std::string& GetZoomedOnHistogram() { return m_zoomedGram; }
|
||||||
inline const bool IsZoomed() { return m_zoomedFlag; }
|
inline const bool IsZoomed() { return m_zoomedFlag; }
|
||||||
inline void UpdateActiveList(const std::vector<HistogramParameters>& list) { m_activeList = list; }
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<HistogramParameters> m_activeList; //This is where we get our info from. Reduces thread crossings
|
|
||||||
std::vector<std::string> m_selectedGrams;
|
std::vector<std::string> m_selectedGrams;
|
||||||
bool m_zoomedFlag;
|
bool m_zoomedFlag;
|
||||||
std::string m_zoomedGram;
|
std::string m_zoomedGram;
|
||||||
|
|
|
@ -12,19 +12,16 @@ namespace Navigator {
|
||||||
/*
|
/*
|
||||||
1D Histogram class
|
1D Histogram class
|
||||||
*/
|
*/
|
||||||
Histogram1D::Histogram1D(const std::string& name, const std::string& param, int bins, double min, double max) :
|
Histogram1D::Histogram1D(const HistogramParameters& params) :
|
||||||
Histogram(name, param)
|
Histogram(params)
|
||||||
{
|
{
|
||||||
InitBins(bins, min, max);
|
InitBins();
|
||||||
}
|
}
|
||||||
|
|
||||||
Histogram1D::~Histogram1D() {}
|
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))
|
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);
|
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
|
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,
|
Histogram2D::Histogram2D(const HistogramParameters& params) :
|
||||||
int bins_y, double min_y, double max_y) :
|
Histogram(params)
|
||||||
Histogram(name, param_x, param_y)
|
|
||||||
{
|
{
|
||||||
InitBins(bins_x, min_x, max_x, bins_y, min_y, max_y);
|
InitBins();
|
||||||
}
|
}
|
||||||
|
|
||||||
Histogram2D::~Histogram2D() {}
|
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)
|
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,
|
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,
|
||||||
|
|
|
@ -7,13 +7,21 @@ namespace Navigator {
|
||||||
|
|
||||||
struct NAV_API HistogramParameters
|
struct NAV_API HistogramParameters
|
||||||
{
|
{
|
||||||
HistogramParameters(const std::string& n, const std::string& x, const std::string& y) :
|
HistogramParameters() {}
|
||||||
name(n), x_par(x), y_par(y)
|
|
||||||
|
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;
|
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) :
|
||||||
std::string y_par;
|
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> cutsDrawnUpon;
|
||||||
std::vector<std::string> cutsAppliedTo;
|
std::vector<std::string> cutsAppliedTo;
|
||||||
int nbins_x = 0;
|
int nbins_x = 0;
|
||||||
|
@ -28,11 +36,11 @@ namespace Navigator {
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Histogram() :
|
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") :
|
Histogram(const HistogramParameters& params) :
|
||||||
m_params(name, param_x, param_y), m_initFlag(false)
|
m_params(params), m_initFlag(false)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,7 +65,7 @@ namespace Navigator {
|
||||||
class NAV_API Histogram1D : public Histogram
|
class NAV_API Histogram1D : public Histogram
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Histogram1D(const std::string& name, const std::string& param, int bins, double min, double max);
|
Histogram1D(const HistogramParameters& params);
|
||||||
virtual ~Histogram1D();
|
virtual ~Histogram1D();
|
||||||
virtual void FillData(double x, double y=0) override;
|
virtual void FillData(double x, double y=0) override;
|
||||||
virtual void Draw() override;
|
virtual void Draw() override;
|
||||||
|
@ -66,7 +74,7 @@ namespace Navigator {
|
||||||
inline virtual bool Is2D() const override { return false; }
|
inline virtual bool Is2D() const override { return false; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void InitBins(int bins, double min, double max);
|
void InitBins();
|
||||||
|
|
||||||
std::vector<double> m_binCenters;
|
std::vector<double> m_binCenters;
|
||||||
std::vector<double> m_binCounts;
|
std::vector<double> m_binCounts;
|
||||||
|
@ -77,8 +85,7 @@ namespace Navigator {
|
||||||
class NAV_API Histogram2D : public Histogram
|
class NAV_API Histogram2D : public Histogram
|
||||||
{
|
{
|
||||||
public:
|
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,
|
Histogram2D(const HistogramParameters& params);
|
||||||
int bins_y, double min_y, double max_y);
|
|
||||||
virtual ~Histogram2D();
|
virtual ~Histogram2D();
|
||||||
virtual void FillData(double x, double y=0) override;
|
virtual void FillData(double x, double y=0) override;
|
||||||
virtual void Draw() override;
|
virtual void Draw() override;
|
||||||
|
@ -87,7 +94,7 @@ namespace Navigator {
|
||||||
inline virtual bool Is2D() const override { return true; }
|
inline virtual bool Is2D() const override { return true; }
|
||||||
|
|
||||||
private:
|
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;
|
std::vector<double> m_binCounts;
|
||||||
int m_nBinsTotal;
|
int m_nBinsTotal;
|
||||||
|
|
|
@ -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)
|
void HistogramMap::AddCutToHistogramDraw(const std::string &cutname, const std::string &histoname)
|
||||||
{
|
{
|
||||||
auto iter = m_map.find(histoname);
|
auto iter = m_map.find(histoname);
|
||||||
|
|
|
@ -9,19 +9,13 @@ namespace Navigator {
|
||||||
class NAV_API HistogramMap
|
class NAV_API HistogramMap
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
using Iter = std::unordered_map<std::string, std::shared_ptr<Histogram>>::iterator;
|
||||||
|
|
||||||
HistogramMap();
|
HistogramMap();
|
||||||
~HistogramMap();
|
~HistogramMap();
|
||||||
|
|
||||||
inline void AddHistogram(const std::string& name, const std::string& param, int bins, double min, double max)
|
void AddHistogram(const HistogramParameters& params);
|
||||||
{
|
|
||||||
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 AddCutToHistogramDraw(const std::string& cutname, const std::string& histoname);
|
void AddCutToHistogramDraw(const std::string& cutname, const std::string& histoname);
|
||||||
void AddCutToHistogramApplied(const std::string& cutname, const std::string& histoname);
|
void AddCutToHistogramApplied(const std::string& cutname, const std::string& histoname);
|
||||||
void UpdateHistograms();
|
void UpdateHistograms();
|
||||||
|
@ -33,6 +27,10 @@ namespace Navigator {
|
||||||
|
|
||||||
static HistogramMap& GetInstance() { return *s_instance; }
|
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:
|
private:
|
||||||
std::unordered_map<std::string, std::shared_ptr<Histogram>> m_map;
|
std::unordered_map<std::string, std::shared_ptr<Histogram>> m_map;
|
||||||
|
|
3
Navigator/src/Navigator/ImGui/ImGuiExtensions.cpp
Normal file
3
Navigator/src/Navigator/ImGui/ImGuiExtensions.cpp
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
|
||||||
|
|
||||||
|
#include "misc/cpp/imgui_stdlib.cpp"
|
|
@ -11,10 +11,6 @@ namespace Navigator {
|
||||||
bool validFlag=false;
|
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
|
class NAV_API NavParameter
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -50,7 +46,8 @@ namespace Navigator {
|
||||||
double GetParameterValue(const std::string& name);
|
double GetParameterValue(const std::string& name);
|
||||||
bool IsParameterValid(const std::string& name);
|
bool IsParameterValid(const std::string& name);
|
||||||
void InvalidateParameters();
|
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 end() { return m_map.end(); }
|
||||||
inline Iter begin() { return m_map.begin(); }
|
inline Iter begin() { return m_map.begin(); }
|
||||||
inline Iter find(const std::string& name) { return m_map.find(name); }
|
inline Iter find(const std::string& name) { return m_map.find(name); }
|
||||||
|
|
Loading…
Reference in New Issue
Block a user