mirror of
https://github.com/gwm17/Specter.git
synced 2024-11-22 18:28:52 -05:00
Major overall of internal resource management. Unify maps of histos, cuts, and params to one single static SpectrumManager. Change a bunch of stuff to reflect this
This commit is contained in:
parent
d1412560ff
commit
5f716b74e6
|
@ -5,6 +5,14 @@ namespace Navigator {
|
|||
SPSAnalysisStage::SPSAnalysisStage() :
|
||||
AnalysisStage("SPSAnalysis"), delayFLTime("delayFLTime"), delayFRTime("delayFRTime"), delayBLTime("delayBLTime"), delayBRTime("delayBRTime"), x1("x1"), x2("x2"), xavg("xavg")
|
||||
{
|
||||
SpectrumManager& manager = SpectrumManager::GetInstance();
|
||||
manager.BindParameter(delayFLTime);
|
||||
manager.BindParameter(delayFRTime);
|
||||
manager.BindParameter(delayBLTime);
|
||||
manager.BindParameter(delayBRTime);
|
||||
manager.BindParameter(x1);
|
||||
manager.BindParameter(x2);
|
||||
manager.BindParameter(xavg);
|
||||
}
|
||||
|
||||
SPSAnalysisStage::~SPSAnalysisStage() {}
|
||||
|
|
|
@ -21,7 +21,8 @@
|
|||
#include "Navigator/Application.h"
|
||||
#include "Navigator/Physics/PhysicsLayer.h"
|
||||
#include "Navigator/Physics/AnalysisStage.h"
|
||||
#include "Navigator/ParameterMap.h"
|
||||
#include "Navigator/Parameter.h"
|
||||
#include "Navigator/SpectrumManager.h"
|
||||
#include "Navigator/Layer.h"
|
||||
#include "Navigator/Events/Event.h"
|
||||
#include "Navigator/Renderer/Renderer.h"
|
||||
|
|
|
@ -3,9 +3,6 @@
|
|||
#include "Renderer/RenderCommand.h"
|
||||
#include "Editor/EditorLayer.h"
|
||||
|
||||
//temp
|
||||
#include "CutMap.h"
|
||||
|
||||
namespace Navigator {
|
||||
|
||||
Application* Application::s_instance = nullptr;
|
||||
|
@ -66,8 +63,6 @@ namespace Navigator {
|
|||
{
|
||||
while(m_runFlag)
|
||||
{
|
||||
HistogramMap::GetInstance().UpdateHistograms();
|
||||
|
||||
RenderCommand::SetClearColor(m_bckgnd_color);
|
||||
RenderCommand::Clear();
|
||||
|
||||
|
|
|
@ -10,7 +10,6 @@
|
|||
#include "Navigator/Window.h"
|
||||
#include "Navigator/ImGui/ImGuiLayer.h"
|
||||
#include "Navigator/Physics/PhysicsLayer.h"
|
||||
#include "Navigator/HistogramMap.h"
|
||||
#include "glm/vec4.hpp"
|
||||
|
||||
namespace Navigator {
|
||||
|
|
67
Navigator/src/Navigator/Cut.cpp
Normal file
67
Navigator/src/Navigator/Cut.cpp
Normal file
|
@ -0,0 +1,67 @@
|
|||
#include "Cut.h"
|
||||
#include "implot.h"
|
||||
|
||||
namespace Navigator {
|
||||
|
||||
/*1D Cuts -- Can be made on and applied to either 1D or 2D histograms*/
|
||||
Cut1D::Cut1D(const CutParams& params, double min, double max) :
|
||||
Cut(params), m_minVal(min), m_maxVal(max)
|
||||
{
|
||||
}
|
||||
|
||||
Cut1D::~Cut1D() {}
|
||||
|
||||
bool Cut1D::IsInside(double x, double y) const
|
||||
{
|
||||
return x >= m_minVal && x <= m_maxVal;
|
||||
}
|
||||
|
||||
//Only within an ImPlot/ImGui context!!!
|
||||
void Cut1D::Draw() const
|
||||
{
|
||||
double points[2] = { m_minVal, m_maxVal };
|
||||
ImPlot::PlotVLines(m_params.name.c_str(), points, 2);
|
||||
}
|
||||
|
||||
/*2D Cuts -- Can only be made on 2D histogram, but applied to either 1D or 2D histograms*/
|
||||
Cut2D::Cut2D(const CutParams& params, const std::vector<double>& xpoints, const std::vector<double>& ypoints) :
|
||||
Cut(params), m_xpoints(xpoints), m_ypoints(ypoints)
|
||||
{
|
||||
}
|
||||
|
||||
Cut2D::~Cut2D() {}
|
||||
|
||||
/*
|
||||
Even-odd point in polygon algorithm (see Wikipedia)
|
||||
Walk around the sides of the polygon and check intersection with each of the sides.
|
||||
Cast a ray from the point to infinity in any direction and check the number of intersections.
|
||||
If odd number of intersections, point is inside. Even, point is outside.
|
||||
Edge cases of point is a vertex or on a side considered.
|
||||
*/
|
||||
bool Cut2D::IsInside(double x, double y) const
|
||||
{
|
||||
bool result = false;
|
||||
double slope;
|
||||
for(size_t i=0; i<(m_xpoints.size()-1); i++)
|
||||
{
|
||||
if(x == m_xpoints[i+1] && y == m_ypoints[i+1])
|
||||
return true;
|
||||
else if((m_ypoints[i+1] > y) != (m_ypoints[i] > y))
|
||||
{
|
||||
slope = (x - m_xpoints[i+1])*(m_ypoints[i] - m_ypoints[i+1]) - (m_xpoints[i] - m_xpoints[i+1])*(y - m_ypoints[i+1]);
|
||||
if(slope == 0.0)
|
||||
return true;
|
||||
else if ((slope < 0.0) != (m_ypoints[i] < m_ypoints[i+1]))
|
||||
result = !result;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
//Only in ImPlot/ImGui context!!!!
|
||||
void Cut2D::Draw() const
|
||||
{
|
||||
ImPlot::PlotLine(m_params.name.c_str(), m_xpoints.data(), m_ypoints.data(), (int)m_xpoints.size());
|
||||
}
|
||||
|
||||
}
|
|
@ -32,7 +32,7 @@ namespace Navigator {
|
|||
|
||||
virtual ~Cut() {}
|
||||
|
||||
virtual bool IsInside() const = 0;
|
||||
virtual bool IsInside(double x, double y=0.0) const = 0;
|
||||
virtual void Draw() const = 0;
|
||||
virtual bool Is1D() const = 0;
|
||||
virtual bool Is2D() const = 0;
|
||||
|
@ -52,7 +52,7 @@ namespace Navigator {
|
|||
public:
|
||||
Cut1D(const CutParams& params, double min, double max);
|
||||
virtual ~Cut1D();
|
||||
virtual bool IsInside() const override;
|
||||
virtual bool IsInside(double x, double y=0.0) const override;
|
||||
virtual void Draw() const override;
|
||||
virtual bool Is1D() const override { return true; }
|
||||
virtual bool Is2D() const override { return false; }
|
||||
|
@ -68,7 +68,7 @@ namespace Navigator {
|
|||
public:
|
||||
Cut2D(const CutParams& params, const std::vector<double>& xpoints, const std::vector<double>& ypoints);
|
||||
virtual ~Cut2D();
|
||||
virtual bool IsInside() const override;
|
||||
virtual bool IsInside(double x, double y) const override;
|
||||
virtual void Draw() const override;
|
||||
virtual bool Is1D() const override { return false; }
|
||||
virtual bool Is2D() const override { return true; }
|
||||
|
@ -80,40 +80,6 @@ namespace Navigator {
|
|||
std::vector<double> m_ypoints;
|
||||
const ImVec4 colorVec = {1.0, 0.0, 0.0, 0.5};
|
||||
};
|
||||
|
||||
class NAV_API CutMap
|
||||
{
|
||||
public:
|
||||
CutMap();
|
||||
~CutMap();
|
||||
|
||||
inline static CutMap& GetInstance() { return *s_instance; }
|
||||
|
||||
inline void AddCut(const CutParams& params, double min, double max)
|
||||
{
|
||||
m_map[params.name].reset(new Cut1D(params, min, max));
|
||||
}
|
||||
inline void AddCut(const CutParams& params, const std::vector<double>& xpoints, const std::vector<double>& ypoints)
|
||||
{
|
||||
m_map[params.name].reset(new Cut2D(params, xpoints, ypoints));
|
||||
}
|
||||
inline void RemoveCut(const std::string& name)
|
||||
{
|
||||
m_map.erase(name);
|
||||
}
|
||||
|
||||
void DrawCut(const std::string& name);
|
||||
bool IsInsideCut(const std::string& name);
|
||||
std::vector<double> GetCutXPoints(const std::string& name);
|
||||
std::vector<double> GetCutYPoints(const std::string& name);
|
||||
std::vector<CutParams> GetListOfCutParams();
|
||||
|
||||
private:
|
||||
std::mutex m_cutMutex;
|
||||
std::unordered_map<std::string, std::shared_ptr<Cut>> m_map;
|
||||
|
||||
static CutMap* s_instance;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
|
@ -1,133 +0,0 @@
|
|||
#include "CutMap.h"
|
||||
#include "ParameterMap.h"
|
||||
#include "implot.h"
|
||||
|
||||
namespace Navigator {
|
||||
|
||||
/*1D Cuts -- Can be made on and applied to either 1D or 2D histograms*/
|
||||
Cut1D::Cut1D(const CutParams& params, double min, double max) :
|
||||
Cut(params), m_minVal(min), m_maxVal(max)
|
||||
{
|
||||
}
|
||||
|
||||
Cut1D::~Cut1D() {}
|
||||
|
||||
bool Cut1D::IsInside() const
|
||||
{
|
||||
ParameterMap& parMap = ParameterMap::GetInstance();
|
||||
ParameterData param = parMap.GetParameter(m_params.x_par);
|
||||
if (!param.validFlag)
|
||||
return false;
|
||||
return param.value >= m_minVal && param.value <= m_maxVal;
|
||||
}
|
||||
|
||||
//Only within an ImPlot/ImGui context!!!
|
||||
void Cut1D::Draw() const
|
||||
{
|
||||
double points[2] = { m_minVal, m_maxVal };
|
||||
ImPlot::PlotVLines(m_params.name.c_str(), points, 2);
|
||||
}
|
||||
|
||||
/*2D Cuts -- Can only be made on 2D histogram, but applied to either 1D or 2D histograms*/
|
||||
Cut2D::Cut2D(const CutParams& params, const std::vector<double>& xpoints, const std::vector<double>& ypoints) :
|
||||
Cut(params), m_xpoints(xpoints), m_ypoints(ypoints)
|
||||
{
|
||||
}
|
||||
|
||||
Cut2D::~Cut2D() {}
|
||||
|
||||
/*
|
||||
Even-odd point in polygon algorithm (see Wikipedia)
|
||||
Walk around the sides of the polygon and check intersection with each of the sides.
|
||||
Cast a ray from the point to infinity in any direction and check the number of intersections.
|
||||
If odd number of intersections, point is inside. Even, point is outside.
|
||||
Edge cases of point is a vertex or on a side considered.
|
||||
*/
|
||||
bool Cut2D::IsInside() const
|
||||
{
|
||||
ParameterMap& parMap = ParameterMap::GetInstance();
|
||||
ParameterData paramx = parMap.GetParameter(m_params.x_par);
|
||||
ParameterData paramy = parMap.GetParameter(m_params.y_par);
|
||||
if (!paramx.validFlag || !paramy.validFlag)
|
||||
return false;
|
||||
double x = paramx.value;
|
||||
double y = paramy.value;
|
||||
bool result = false;
|
||||
double slope;
|
||||
for(size_t i=0; i<(m_xpoints.size()-1); i++)
|
||||
{
|
||||
if(x == m_xpoints[i+1] && y == m_ypoints[i+1])
|
||||
return true;
|
||||
else if((m_ypoints[i+1] > y) != (m_ypoints[i] > y))
|
||||
{
|
||||
slope = (x - m_xpoints[i+1])*(m_ypoints[i] - m_ypoints[i+1]) - (m_xpoints[i] - m_xpoints[i+1])*(y - m_ypoints[i+1]);
|
||||
if(slope == 0.0)
|
||||
return true;
|
||||
else if ((slope < 0.0) != (m_ypoints[i] < m_ypoints[i+1]))
|
||||
result = !result;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
//Only in ImPlot/ImGui context!!!!
|
||||
void Cut2D::Draw() const
|
||||
{
|
||||
ImPlot::PlotLine(m_params.name.c_str(), m_xpoints.data(), m_ypoints.data(), (int)m_xpoints.size());
|
||||
}
|
||||
|
||||
/* CutMap */
|
||||
CutMap* CutMap::s_instance = new CutMap(); //Guarantee existance for duration of program.
|
||||
|
||||
CutMap::CutMap() {}
|
||||
|
||||
CutMap::~CutMap() {}
|
||||
|
||||
void CutMap::DrawCut(const std::string& name)
|
||||
{
|
||||
std::lock_guard<std::mutex> guard(m_cutMutex);
|
||||
auto iter = m_map.find(name);
|
||||
if(iter != m_map.end())
|
||||
iter->second->Draw();
|
||||
}
|
||||
|
||||
bool CutMap::IsInsideCut(const std::string& name)
|
||||
{
|
||||
std::lock_guard<std::mutex> guard(m_cutMutex);
|
||||
bool result = false;
|
||||
auto iter = m_map.find(name);
|
||||
if(iter != m_map.end())
|
||||
result = iter->second->IsInside();
|
||||
return result;
|
||||
}
|
||||
|
||||
std::vector<double> CutMap::GetCutXPoints(const std::string& name)
|
||||
{
|
||||
std::lock_guard<std::mutex> guard(m_cutMutex);
|
||||
std::vector<double> null_result;
|
||||
auto iter = m_map.find(name);
|
||||
if(iter != m_map.end())
|
||||
return iter->second->GetXValues();
|
||||
return null_result;
|
||||
}
|
||||
|
||||
std::vector<double> CutMap::GetCutYPoints(const std::string& name)
|
||||
{
|
||||
std::lock_guard<std::mutex> guard(m_cutMutex);
|
||||
std::vector<double> null_result;
|
||||
auto iter = m_map.find(name);
|
||||
if(iter != m_map.end())
|
||||
return iter->second->GetYValues();
|
||||
return null_result;
|
||||
}
|
||||
|
||||
std::vector<CutParams> CutMap::GetListOfCutParams()
|
||||
{
|
||||
std::lock_guard<std::mutex> guard(m_cutMutex);
|
||||
std::vector<CutParams> list;
|
||||
list.reserve(m_map.size());
|
||||
for(auto& entry : m_map)
|
||||
list.push_back(entry.second->GetCutParams());
|
||||
return list;
|
||||
}
|
||||
}
|
|
@ -4,6 +4,7 @@
|
|||
#include "FileDialog.h"
|
||||
#include "Navigator/Application.h"
|
||||
#include "Navigator/SpectrumSerializer.h"
|
||||
#include "Navigator/SpectrumManager.h"
|
||||
|
||||
#include "IconsFontAwesome5.h"
|
||||
|
||||
|
@ -34,20 +35,17 @@ namespace Navigator {
|
|||
|
||||
void EditorLayer::UpdateHistogramList()
|
||||
{
|
||||
HistogramMap& histoMap = HistogramMap::GetInstance();
|
||||
m_histoList = histoMap.GetListOfHistograms();
|
||||
m_histoList = SpectrumManager::GetInstance().GetListOfHistograms();
|
||||
}
|
||||
|
||||
void EditorLayer::UpdateCutList()
|
||||
{
|
||||
CutMap& cutMap = CutMap::GetInstance();
|
||||
m_cutList = cutMap.GetListOfCutParams();
|
||||
m_cutList = SpectrumManager::GetInstance().GetListOfCuts();
|
||||
}
|
||||
|
||||
void EditorLayer::UpdateParameterList()
|
||||
{
|
||||
ParameterMap& parMap = ParameterMap::GetInstance();
|
||||
m_paramList = parMap.GetListOfParameters();
|
||||
m_paramList = SpectrumManager::GetInstance().GetListOfParameters();
|
||||
}
|
||||
|
||||
void EditorLayer::OnImGuiRender()
|
||||
|
@ -260,7 +258,7 @@ namespace Navigator {
|
|||
}
|
||||
if (ImGui::Button("Ok"))
|
||||
{
|
||||
HistogramMap::GetInstance().RemoveHistogram(selectedGram);
|
||||
SpectrumManager::GetInstance().RemoveHistogram(selectedGram);
|
||||
UpdateHistogramList();
|
||||
ImGui::CloseCurrentPopup();
|
||||
}
|
||||
|
@ -295,8 +293,7 @@ namespace Navigator {
|
|||
}
|
||||
if (ImGui::Button("Ok"))
|
||||
{
|
||||
HistogramMap::GetInstance().RemoveCutFromHistograms(selectedCut);
|
||||
CutMap::GetInstance().RemoveCut(selectedCut);
|
||||
SpectrumManager::GetInstance().RemoveCut(selectedCut);
|
||||
UpdateHistogramList();
|
||||
UpdateCutList();
|
||||
ImGui::CloseCurrentPopup();
|
||||
|
|
|
@ -4,8 +4,8 @@
|
|||
#include "Navigator/Layer.h"
|
||||
#include "Navigator/Events/Event.h"
|
||||
#include "Navigator/Events/PhysicsEvent.h"
|
||||
#include "Navigator/HistogramMap.h"
|
||||
#include "Navigator/CutMap.h"
|
||||
#include "Navigator/Histogram.h"
|
||||
#include "Navigator/Cut.h"
|
||||
#include "SpectrumPanel.h"
|
||||
#include "FileDialog.h"
|
||||
#include "SpectrumDialog.h"
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include "SpectrumDialog.h"
|
||||
#include "Navigator/SpectrumManager.h"
|
||||
|
||||
#include "misc/cpp/imgui_stdlib.h"
|
||||
|
||||
|
@ -115,7 +116,7 @@ namespace Navigator {
|
|||
|
||||
if (ImGui::Button("Ok"))
|
||||
{
|
||||
HistogramMap::GetInstance().AddHistogram(m_newParams);
|
||||
SpectrumManager::GetInstance().AddHistogram(m_newParams);
|
||||
ImGui::CloseCurrentPopup();
|
||||
result = true;
|
||||
}
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
#ifndef SPECTRUM_DIALOG_H
|
||||
#define SPECTRUM_DIALOG_H
|
||||
|
||||
#include "Navigator/HistogramMap.h"
|
||||
#include "Navigator/ParameterMap.h"
|
||||
#include "Navigator/CutMap.h"
|
||||
#include "Navigator/Histogram.h"
|
||||
#include "Navigator/Cut.h"
|
||||
|
||||
#include "imgui.h"
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include "SpectrumPanel.h"
|
||||
#include "Navigator/SpectrumManager.h"
|
||||
#include "misc/cpp/imgui_stdlib.h"
|
||||
#include "IconsFontAwesome5.h"
|
||||
|
||||
|
@ -38,14 +39,14 @@ namespace Navigator {
|
|||
ImGui::SameLine();
|
||||
if(ImGui::Button("Clear"))
|
||||
{
|
||||
HistogramMap::GetInstance().ClearHistogram(m_zoomedGram.name);
|
||||
SpectrumManager::GetInstance().ClearHistogram(m_zoomedGram.name);
|
||||
}
|
||||
ImGui::SameLine();
|
||||
RenderRemoveRegionButton();
|
||||
|
||||
if (ImPlot::BeginPlot(m_zoomedGram.name.c_str(), ImVec2(-1, -1)))
|
||||
{
|
||||
HistogramMap::GetInstance().DrawHistogram(m_zoomedGram.name);
|
||||
SpectrumManager::GetInstance().DrawHistogram(m_zoomedGram.name);
|
||||
if (!m_cutModeFlag && ImPlot::IsPlotHovered() && ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left))
|
||||
{
|
||||
NAV_INFO("We lost 'em, de-zoom and enhance!");
|
||||
|
@ -96,7 +97,7 @@ namespace Navigator {
|
|||
if (m_zoomedGram.name == region.histogram_name)
|
||||
{
|
||||
ImPlot::DragRect(int(i), ®ion.region.X.Min, ®ion.region.Y.Min, ®ion.region.X.Max, ®ion.region.Y.Max, ImVec4(1, 0, 1, 1));
|
||||
StatResults results = HistogramMap::GetInstance().AnalyzeHistogramRegion(m_zoomedGram.name, region.region);
|
||||
StatResults results = SpectrumManager::GetInstance().AnalyzeHistogramRegion(m_zoomedGram.name, region.region);
|
||||
ImPlot::PlotText(GenerateStatString(region.name, results, m_zoomedGram.y_par != "None").c_str(), (region.region.X.Max + region.region.X.Min) * 0.5,
|
||||
(region.region.Y.Min + region.region.Y.Max) * 0.5);
|
||||
}
|
||||
|
@ -117,13 +118,13 @@ namespace Navigator {
|
|||
if (m_newCutParams.y_par == "None")
|
||||
{
|
||||
std::sort(m_newCutX.begin(), m_newCutX.end());
|
||||
CutMap::GetInstance().AddCut(m_newCutParams, m_newCutX[0], m_newCutX[1]);
|
||||
SpectrumManager::GetInstance().AddCut(m_newCutParams, m_newCutX[0], m_newCutX[1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
CutMap::GetInstance().AddCut(m_newCutParams, m_newCutX, m_newCutY);
|
||||
SpectrumManager::GetInstance().AddCut(m_newCutParams, m_newCutX, m_newCutY);
|
||||
}
|
||||
HistogramMap::GetInstance().AddCutToHistogramDraw(m_newCutParams.name, m_zoomedGram.name);
|
||||
SpectrumManager::GetInstance().AddCutToHistogramDraw(m_newCutParams.name, m_zoomedGram.name);
|
||||
ImGui::CloseCurrentPopup();
|
||||
result = true;
|
||||
}
|
||||
|
@ -142,7 +143,7 @@ namespace Navigator {
|
|||
ImGui::SameLine();
|
||||
if(ImGui::Button("Clear All"))
|
||||
{
|
||||
HistogramMap::GetInstance().ClearHistograms();
|
||||
SpectrumManager::GetInstance().ClearHistograms();
|
||||
}
|
||||
m_totalSlots = m_tableSizes[0] * m_tableSizes[1];
|
||||
m_selectedGrams.resize(m_totalSlots);
|
||||
|
@ -179,7 +180,7 @@ namespace Navigator {
|
|||
{
|
||||
if (ImPlot::BeginPlot(spec.name.c_str()))
|
||||
{
|
||||
HistogramMap::GetInstance().DrawHistogram(spec.name);
|
||||
SpectrumManager::GetInstance().DrawHistogram(spec.name);
|
||||
if (ImPlot::IsPlotHovered() && ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left))
|
||||
{
|
||||
NAV_INFO("We got'em boys, they're in plot {0}. Zoom and enhance!", i);
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
#ifndef SPECTRUM_PANEL_H
|
||||
#define SPECTRUM_PANEL_H
|
||||
|
||||
#include "Navigator/HistogramMap.h"
|
||||
#include "Navigator/ParameterMap.h"
|
||||
#include "Navigator/CutMap.h"
|
||||
#include "Navigator/Histogram.h"
|
||||
#include "Navigator/Cut.h"
|
||||
#include "imgui.h"
|
||||
#include "implot.h"
|
||||
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
#include "Histogram.h"
|
||||
#include "CutMap.h"
|
||||
#include "ParameterMap.h"
|
||||
#include "implot.h"
|
||||
|
||||
/*
|
||||
|
@ -45,21 +43,9 @@ namespace Navigator {
|
|||
}
|
||||
|
||||
//Note: only x is used here, y is simply present to maintain compliance with 2D case and can be ignored
|
||||
void Histogram1D::FillData()
|
||||
void Histogram1D::FillData(double x, double y)
|
||||
{
|
||||
ParameterMap& parMap = ParameterMap::GetInstance();
|
||||
ParameterData x = parMap.GetParameter(m_params.x_par);
|
||||
if(!x.validFlag || x.value < m_params.min_x || x.value >= m_params.max_x || !m_initFlag)
|
||||
return;
|
||||
auto& cutmap = CutMap::GetInstance();
|
||||
for (auto& cut : m_params.cutsAppliedTo)
|
||||
{
|
||||
if (!cutmap.IsInsideCut(cut))
|
||||
return;
|
||||
}
|
||||
|
||||
int bin = int((x.value - m_params.min_x)/(m_binWidth));
|
||||
|
||||
int bin = int((x - m_params.min_x)/(m_binWidth));
|
||||
m_binCounts[bin] += 1.0;
|
||||
}
|
||||
|
||||
|
@ -68,9 +54,6 @@ namespace Navigator {
|
|||
{
|
||||
ImPlot::SetupAxes(m_params.x_par.c_str(), "Counts",0, ImPlotAxisFlags_LockMin);
|
||||
ImPlot::PlotBars(m_params.name.c_str(), &m_binCenters.data()[0], &m_binCounts.data()[0], m_params.nbins_x, m_binWidth);
|
||||
auto& cutmap = CutMap::GetInstance();
|
||||
for(auto& cut : m_params.cutsDrawnUpon)
|
||||
cutmap.DrawCut(cut);
|
||||
}
|
||||
|
||||
void Histogram1D::ClearData()
|
||||
|
@ -143,24 +126,10 @@ namespace Navigator {
|
|||
m_initFlag = true;
|
||||
}
|
||||
|
||||
void Histogram2D::FillData()
|
||||
void Histogram2D::FillData(double x, double y)
|
||||
{
|
||||
ParameterMap& parMap = ParameterMap::GetInstance();
|
||||
CutMap& cutMap = CutMap::GetInstance();
|
||||
if (!parMap.IsParameterValid(m_params.x_par) || !parMap.IsParameterValid(m_params.y_par))
|
||||
return;
|
||||
ParameterData x = parMap.GetParameter(m_params.x_par);
|
||||
ParameterData y = parMap.GetParameter(m_params.y_par);
|
||||
if(!x.validFlag || !y.validFlag || x.value < m_params.min_x || x.value >= m_params.max_x || y.value < m_params.min_y || y.value >= m_params.max_y || !m_initFlag)
|
||||
return;
|
||||
for (auto& cut : m_params.cutsAppliedTo)
|
||||
{
|
||||
if (!cutMap.IsInsideCut(cut))
|
||||
return;
|
||||
}
|
||||
|
||||
int bin_x = int((x.value - m_params.min_x)/m_binWidthX);
|
||||
int bin_y = int((m_params.max_y - y.value)/m_binWidthY);
|
||||
int bin_x = int((x - m_params.min_x)/m_binWidthX);
|
||||
int bin_y = int((m_params.max_y - y)/m_binWidthY);
|
||||
int bin = bin_y*m_params.nbins_x + bin_x;
|
||||
|
||||
m_binCounts[bin] += 1.0;
|
||||
|
@ -176,9 +145,6 @@ namespace Navigator {
|
|||
ImPlot::PlotHeatmap(m_params.name.c_str(), &m_binCounts.data()[0], m_params.nbins_y, m_params.nbins_x, 0.0, m_maxBinContent, NULL,
|
||||
ImPlotPoint(m_params.min_x, m_params.min_y), ImPlotPoint(m_params.max_x, m_params.max_y));
|
||||
ImPlot::PopColormap();
|
||||
auto& cutmap = CutMap::GetInstance();
|
||||
for(auto& cut : m_params.cutsDrawnUpon)
|
||||
cutmap.DrawCut(cut);
|
||||
}
|
||||
|
||||
void Histogram2D::ClearData()
|
||||
|
|
|
@ -54,7 +54,7 @@ namespace Navigator {
|
|||
}
|
||||
|
||||
virtual ~Histogram() {};
|
||||
virtual void FillData() { NAV_WARN("Trying to fill a default histogram!"); }
|
||||
virtual void FillData(double x, double y=0.0) { NAV_WARN("Trying to fill a default histogram!"); }
|
||||
virtual void Draw() {}
|
||||
virtual void ClearData() {}
|
||||
virtual StatResults AnalyzeRegion(double x_min, double x_max, double y_min = 0.0, double y_max = 0.0) { return StatResults(); }
|
||||
|
@ -77,7 +77,7 @@ namespace Navigator {
|
|||
public:
|
||||
Histogram1D(const HistogramParameters& params);
|
||||
virtual ~Histogram1D();
|
||||
virtual void FillData() override;
|
||||
virtual void FillData(double x, double y=0.0) override;
|
||||
virtual void Draw() override;
|
||||
virtual void ClearData() override;
|
||||
virtual StatResults AnalyzeRegion(double x_min, double x_max, double y_min = 0.0, double y_max = 0.0) override;
|
||||
|
@ -98,7 +98,7 @@ namespace Navigator {
|
|||
public:
|
||||
Histogram2D(const HistogramParameters& params);
|
||||
virtual ~Histogram2D();
|
||||
virtual void FillData() override;
|
||||
virtual void FillData(double x, double y) override;
|
||||
virtual void Draw() override;
|
||||
virtual void ClearData() override;
|
||||
virtual StatResults AnalyzeRegion(double x_min, double x_max, double y_min = 0.0, double y_max = 0.0) override;
|
||||
|
|
|
@ -1,143 +0,0 @@
|
|||
#include "HistogramMap.h"
|
||||
#include "ParameterMap.h"
|
||||
|
||||
#include "implot.h"
|
||||
|
||||
namespace Navigator {
|
||||
|
||||
HistogramMap* HistogramMap::s_instance = new HistogramMap();
|
||||
|
||||
HistogramMap::HistogramMap()
|
||||
{
|
||||
}
|
||||
|
||||
HistogramMap::~HistogramMap()
|
||||
{
|
||||
}
|
||||
|
||||
void HistogramMap::AddHistogram(const HistogramParameters& params)
|
||||
{
|
||||
std::lock_guard<std::mutex> guard(m_histoMutex);
|
||||
if (params.y_par == "None")
|
||||
m_map[params.name].reset(new Histogram1D(params));
|
||||
else
|
||||
m_map[params.name].reset(new Histogram2D(params));
|
||||
}
|
||||
|
||||
void HistogramMap::RemoveHistogram(const std::string& name)
|
||||
{
|
||||
std::lock_guard<std::mutex> guard(m_histoMutex);
|
||||
m_map.erase(name);
|
||||
}
|
||||
|
||||
void HistogramMap::AddCutToHistogramDraw(const std::string& cutname, const std::string& histoname)
|
||||
{
|
||||
std::lock_guard<std::mutex> guard(m_histoMutex);
|
||||
auto iter = m_map.find(histoname);
|
||||
if(iter != m_map.end())
|
||||
iter->second->AddCutToBeDrawn(cutname);
|
||||
}
|
||||
|
||||
void HistogramMap::AddCutToHistogramApplied(const std::string& cutname, const std::string& histoname)
|
||||
{
|
||||
std::lock_guard<std::mutex> guard(m_histoMutex);
|
||||
auto iter = m_map.find(histoname);
|
||||
if(iter != m_map.end())
|
||||
iter->second->AddCutToBeApplied(cutname);
|
||||
}
|
||||
|
||||
void HistogramMap::RemoveCutFromHistograms(const std::string& cutname)
|
||||
{
|
||||
std::lock_guard<std::mutex> guard(m_histoMutex);
|
||||
for (auto& gram : m_map)
|
||||
{
|
||||
auto& params = gram.second->GetParameters();
|
||||
for (size_t i = 0; i < params.cutsDrawnUpon.size(); ++i)
|
||||
{
|
||||
if (params.cutsDrawnUpon[i] == cutname)
|
||||
{
|
||||
params.cutsDrawnUpon.erase(params.cutsDrawnUpon.begin() + i);
|
||||
}
|
||||
}
|
||||
for (size_t i = 0; i < params.cutsAppliedTo.size(); ++i)
|
||||
{
|
||||
if (params.cutsAppliedTo[i] == cutname)
|
||||
{
|
||||
params.cutsAppliedTo.erase(params.cutsAppliedTo.begin() + i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void HistogramMap::UpdateHistograms()
|
||||
{
|
||||
std::lock_guard<std::mutex> guard(m_histoMutex);
|
||||
for (auto& pair : m_map)
|
||||
pair.second->FillData();
|
||||
}
|
||||
|
||||
void HistogramMap::ClearHistograms()
|
||||
{
|
||||
std::lock_guard<std::mutex> guard(m_histoMutex);
|
||||
for(auto& pair : m_map)
|
||||
pair.second->ClearData();
|
||||
}
|
||||
|
||||
void HistogramMap::ClearHistogram(const std::string& name)
|
||||
{
|
||||
std::lock_guard<std::mutex> guard(m_histoMutex);
|
||||
auto iter = m_map.find(name);
|
||||
if(iter != m_map.end())
|
||||
iter->second->ClearData();
|
||||
}
|
||||
|
||||
const HistogramParameters& HistogramMap::GetHistogramParams(const std::string& name)
|
||||
{
|
||||
|
||||
std::lock_guard<std::mutex> guard(m_histoMutex);
|
||||
auto iter = m_map.find(name);
|
||||
if (iter != m_map.end())
|
||||
return iter->second->GetParameters();
|
||||
else
|
||||
return m_nullResult;
|
||||
}
|
||||
|
||||
StatResults HistogramMap::AnalyzeHistogramRegion(const std::string& name, const ImPlotRect& region)
|
||||
{
|
||||
std::lock_guard<std::mutex> guard(m_histoMutex);
|
||||
auto iter = m_map.find(name);
|
||||
if (iter != m_map.end())
|
||||
return iter->second->AnalyzeRegion(region.X.Min, region.X.Max, region.Y.Min, region.Y.Max);
|
||||
else
|
||||
return StatResults();
|
||||
}
|
||||
|
||||
std::vector<HistogramParameters> HistogramMap::GetListOfHistograms()
|
||||
{
|
||||
std::lock_guard<std::mutex> guard(m_histoMutex);
|
||||
std::vector<HistogramParameters> list;
|
||||
list.reserve(m_map.size());
|
||||
for(auto& gram : m_map)
|
||||
{
|
||||
list.push_back(gram.second->GetParameters());
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
//Only to be used within ImGui context!!
|
||||
void Navigator::HistogramMap::DrawHistograms()
|
||||
{
|
||||
std::lock_guard<std::mutex> guard(m_histoMutex);
|
||||
for (auto& pair : m_map)
|
||||
pair.second->Draw();
|
||||
}
|
||||
|
||||
//Only to be used within ImGui context!!
|
||||
void Navigator::HistogramMap::DrawHistogram(const std::string& name)
|
||||
{
|
||||
std::lock_guard<std::mutex> guard(m_histoMutex);
|
||||
auto iter = m_map.find(name);
|
||||
if (iter != m_map.end())
|
||||
iter->second->Draw();
|
||||
}
|
||||
}
|
|
@ -1,52 +0,0 @@
|
|||
#ifndef HISTOGRAM_MAP_H
|
||||
#define HISTOGRAM_MAP_H
|
||||
|
||||
#include "NavCore.h"
|
||||
#include "Histogram.h"
|
||||
|
||||
#include <thread>
|
||||
|
||||
struct ImPlotRect;
|
||||
|
||||
namespace Navigator {
|
||||
|
||||
class NAV_API HistogramMap
|
||||
{
|
||||
public:
|
||||
HistogramMap();
|
||||
~HistogramMap();
|
||||
|
||||
void AddHistogram(const HistogramParameters& params);
|
||||
|
||||
void RemoveHistogram(const std::string& name);
|
||||
|
||||
void AddCutToHistogramDraw(const std::string& cutname, const std::string& histoname);
|
||||
void AddCutToHistogramApplied(const std::string& cutname, const std::string& histoname);
|
||||
void RemoveCutFromHistograms(const std::string& cutname);
|
||||
|
||||
void UpdateHistograms();
|
||||
void ClearHistograms();
|
||||
void ClearHistogram(const std::string& name);
|
||||
|
||||
void DrawHistograms();
|
||||
void DrawHistogram(const std::string& name);
|
||||
|
||||
const HistogramParameters& GetHistogramParams(const std::string& name);
|
||||
StatResults AnalyzeHistogramRegion(const std::string& name, const ImPlotRect& region);
|
||||
|
||||
std::vector<HistogramParameters> GetListOfHistograms();
|
||||
|
||||
static HistogramMap& GetInstance() { return *s_instance; }
|
||||
|
||||
private:
|
||||
std::mutex m_histoMutex;
|
||||
std::unordered_map<std::string, std::shared_ptr<Histogram>> m_map;
|
||||
|
||||
HistogramParameters m_nullResult;
|
||||
|
||||
static HistogramMap* s_instance;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
18
Navigator/src/Navigator/Parameter.cpp
Normal file
18
Navigator/src/Navigator/Parameter.cpp
Normal file
|
@ -0,0 +1,18 @@
|
|||
#include "Parameter.h"
|
||||
|
||||
namespace Navigator {
|
||||
|
||||
NavParameter::NavParameter() :
|
||||
m_name(""), m_pdata(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
NavParameter::NavParameter(const std::string& name) :
|
||||
m_name(name), m_pdata(nullptr)
|
||||
{
|
||||
NAV_INFO("Making a new parameter named {0}...",name);
|
||||
}
|
||||
|
||||
NavParameter::~NavParameter() {}
|
||||
|
||||
}
|
38
Navigator/src/Navigator/Parameter.h
Normal file
38
Navigator/src/Navigator/Parameter.h
Normal file
|
@ -0,0 +1,38 @@
|
|||
#ifndef PARAMETER_MAP_H
|
||||
#define PARAMETER_MAP_H
|
||||
|
||||
#include "NavCore.h"
|
||||
#include <thread>
|
||||
|
||||
namespace Navigator {
|
||||
|
||||
struct NAV_API ParameterData
|
||||
{
|
||||
double value=0.0;
|
||||
bool validFlag=false;
|
||||
};
|
||||
|
||||
class NAV_API NavParameter
|
||||
{
|
||||
|
||||
public:
|
||||
NavParameter();
|
||||
NavParameter(const std::string& name);
|
||||
~NavParameter();
|
||||
|
||||
inline bool IsValid() const { return m_pdata->validFlag; }
|
||||
inline void Invalidate() { m_pdata->validFlag = false; }
|
||||
inline void SetValue(double value) { m_pdata->validFlag = true; m_pdata->value = value; }
|
||||
inline double GetValue() const { return m_pdata->value; }
|
||||
inline const std::string& GetName() const { return m_name; }
|
||||
|
||||
friend class SpectrumManager;
|
||||
private:
|
||||
std::string m_name;
|
||||
std::shared_ptr<ParameterData> m_pdata;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
|
@ -1,97 +0,0 @@
|
|||
//
|
||||
// ParameterMap.cpp
|
||||
// Navigator
|
||||
//
|
||||
// Created by Gordon McCann on 1/7/22.
|
||||
//
|
||||
|
||||
#include "ParameterMap.h"
|
||||
|
||||
namespace Navigator {
|
||||
|
||||
NavParameter::NavParameter() :
|
||||
m_name(""), m_pdata(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
NavParameter::NavParameter(const std::string& name) :
|
||||
m_name(name)
|
||||
{
|
||||
NAV_INFO("Making a new parameter named {0}...",name);
|
||||
m_pdata = nullptr;
|
||||
ParameterMap& map = ParameterMap::GetInstance();
|
||||
NAV_INFO("Setting the memory...");
|
||||
map.SetParameter(name, m_pdata);
|
||||
}
|
||||
|
||||
NavParameter::~NavParameter() {}
|
||||
|
||||
void NavParameter::SetParameter(const std::string& name)
|
||||
{
|
||||
ParameterMap& map = ParameterMap::GetInstance();
|
||||
map.SetParameter(name, m_pdata);
|
||||
}
|
||||
|
||||
ParameterMap* ParameterMap::s_instance = new ParameterMap();
|
||||
|
||||
ParameterMap::ParameterMap()
|
||||
{
|
||||
}
|
||||
|
||||
ParameterMap::~ParameterMap() {}
|
||||
|
||||
void ParameterMap::SetParameter(const std::string& name, std::shared_ptr<ParameterData>& param)
|
||||
{
|
||||
std::lock_guard<std::mutex> guard(m_paramMutex);
|
||||
auto iter = m_map.find(name);
|
||||
if(iter == m_map.end())
|
||||
{
|
||||
m_map[name].reset(new ParameterData());
|
||||
}
|
||||
|
||||
param = m_map[name];
|
||||
}
|
||||
|
||||
ParameterData ParameterMap::GetParameter(const std::string& name)
|
||||
{
|
||||
std::lock_guard<std::mutex> guard(m_paramMutex);
|
||||
auto iter = m_map.find(name);
|
||||
if(iter != m_map.end())
|
||||
return *(iter->second);
|
||||
else
|
||||
return ParameterData();
|
||||
}
|
||||
|
||||
bool ParameterMap::IsParameterValid(const std::string& name)
|
||||
{
|
||||
std::lock_guard<std::mutex> guard(m_paramMutex);
|
||||
auto iter = m_map.find(name);
|
||||
if(iter != m_map.end())
|
||||
return iter->second->validFlag;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
void ParameterMap::InvalidateParameters()
|
||||
{
|
||||
std::lock_guard<std::mutex> guard(m_paramMutex);
|
||||
for(auto& iter : m_map)
|
||||
{
|
||||
iter.second->validFlag = false;
|
||||
iter.second->value = 0.0;
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<std::string> ParameterMap::GetListOfParameters()
|
||||
{
|
||||
std::lock_guard<std::mutex> guard(m_paramMutex);
|
||||
std::vector<std::string> list;
|
||||
list.reserve(m_map.size());
|
||||
for (auto iter : m_map)
|
||||
{
|
||||
list.push_back(iter.first);
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
}
|
|
@ -1,67 +0,0 @@
|
|||
#ifndef PARAMETER_MAP_H
|
||||
#define PARAMETER_MAP_H
|
||||
|
||||
#include "NavCore.h"
|
||||
#include <thread>
|
||||
|
||||
namespace Navigator {
|
||||
|
||||
struct NAV_API ParameterData
|
||||
{
|
||||
double value=0.0;
|
||||
bool validFlag=false;
|
||||
};
|
||||
|
||||
class NAV_API NavParameter
|
||||
{
|
||||
|
||||
public:
|
||||
NavParameter();
|
||||
NavParameter(const std::string& name);
|
||||
~NavParameter();
|
||||
|
||||
void SetParameter(const std::string& name);
|
||||
|
||||
inline bool IsValid() const { return m_pdata->validFlag; }
|
||||
inline void Invalidate() { m_pdata->validFlag = false; }
|
||||
inline void SetValue(double value) { m_pdata->validFlag = true; m_pdata->value = value; }
|
||||
inline double GetValue() const { return m_pdata->value; }
|
||||
inline const std::string& GetName() const { return m_name; }
|
||||
|
||||
private:
|
||||
std::string m_name;
|
||||
std::shared_ptr<ParameterData> m_pdata;
|
||||
|
||||
};
|
||||
|
||||
/*
|
||||
Global parameter accesing, storage
|
||||
*/
|
||||
class NAV_API ParameterMap
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
using Iter = std::unordered_map<std::string, std::shared_ptr<ParameterData>>::iterator;
|
||||
|
||||
ParameterMap();
|
||||
~ParameterMap();
|
||||
void SetParameter(const std::string& name, std::shared_ptr<ParameterData>& param);
|
||||
ParameterData GetParameter(const std::string& name);
|
||||
bool IsParameterValid(const std::string& name);
|
||||
void InvalidateParameters();
|
||||
std::vector<std::string> GetListOfParameters();
|
||||
|
||||
inline static ParameterMap& GetInstance() { return *s_instance; }
|
||||
|
||||
private:
|
||||
std::unordered_map<std::string, std::shared_ptr<ParameterData>> m_map;
|
||||
static ParameterMap* s_instance;
|
||||
|
||||
std::mutex m_paramMutex;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
|
@ -2,7 +2,7 @@
|
|||
#define ANALYSIS_STAGE_H
|
||||
|
||||
#include "Navigator/NavCore.h"
|
||||
#include "Navigator/ParameterMap.h"
|
||||
#include "Navigator/Parameter.h"
|
||||
#include "NavData.h"
|
||||
|
||||
namespace Navigator {
|
||||
|
|
|
@ -11,6 +11,12 @@ namespace Navigator {
|
|||
PhysicsEventBuilder(uint64_t windowSize);
|
||||
~PhysicsEventBuilder();
|
||||
inline void SetCoincidenceWindow(uint64_t windowSize) { m_coincWindow = windowSize; }
|
||||
inline void ClearAll()
|
||||
{
|
||||
m_event.clear();
|
||||
m_readyEvent.clear();
|
||||
m_eventStartTime = 0;
|
||||
}
|
||||
bool AddDatumToEvent(const NavData& datum);
|
||||
const NavEvent& GetReadyEvent() const;
|
||||
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
#include "PhysicsLayer.h"
|
||||
#include "Navigator/ParameterMap.h"
|
||||
|
||||
//temp
|
||||
#include "Navigator/SpectrumManager.h"
|
||||
#include "NavData.h"
|
||||
|
||||
namespace Navigator {
|
||||
|
@ -96,6 +94,7 @@ namespace Navigator {
|
|||
std::lock_guard<std::mutex> guard(m_sourceMutex);
|
||||
m_source.reset(CreateDataSource(event.GetSourceLocation(), event.GetSourcePort(), event.GetSourceType()));
|
||||
m_eventBuilder.SetCoincidenceWindow(event.GetCoincidenceWindow());
|
||||
m_eventBuilder.ClearAll();
|
||||
if (m_source->IsValid())
|
||||
{
|
||||
NAV_INFO("Attach successful. Enabling data pull...");
|
||||
|
@ -119,7 +118,7 @@ namespace Navigator {
|
|||
|
||||
void PhysicsLayer::RunSource()
|
||||
{
|
||||
HistogramMap& histMap = HistogramMap::GetInstance();
|
||||
SpectrumManager& manager = SpectrumManager::GetInstance();
|
||||
|
||||
NavEvent event;
|
||||
NavData datum;
|
||||
|
@ -151,8 +150,8 @@ namespace Navigator {
|
|||
for (auto& stage : m_physStack)
|
||||
stage->AnalyzePhysicsEvent(event);
|
||||
|
||||
histMap.UpdateHistograms();
|
||||
ParameterMap::GetInstance().InvalidateParameters();
|
||||
manager.UpdateHistograms();
|
||||
manager.InvalidateParameters();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
#define PHYSICS_LAYER_H
|
||||
|
||||
#include "Navigator/NavCore.h"
|
||||
#include "Navigator/HistogramMap.h"
|
||||
#include "Navigator/Layer.h"
|
||||
#include "Navigator/Events/PhysicsEvent.h"
|
||||
#include "AnalysisStack.h"
|
||||
|
|
273
Navigator/src/Navigator/SpectrumManager.cpp
Normal file
273
Navigator/src/Navigator/SpectrumManager.cpp
Normal file
|
@ -0,0 +1,273 @@
|
|||
#include "SpectrumManager.h"
|
||||
|
||||
#include "implot.h"
|
||||
|
||||
namespace Navigator {
|
||||
|
||||
SpectrumManager* SpectrumManager::s_instance = new SpectrumManager();
|
||||
|
||||
SpectrumManager::SpectrumManager()
|
||||
{
|
||||
}
|
||||
|
||||
SpectrumManager::~SpectrumManager()
|
||||
{
|
||||
}
|
||||
|
||||
void SpectrumManager::AddHistogram(const HistogramParameters& params)
|
||||
{
|
||||
std::lock_guard<std::mutex> guard(m_managerMutex);
|
||||
if (params.y_par == "None")
|
||||
m_histoMap[params.name].reset(new Histogram1D(params));
|
||||
else
|
||||
m_histoMap[params.name].reset(new Histogram2D(params));
|
||||
}
|
||||
|
||||
void SpectrumManager::RemoveHistogram(const std::string& name)
|
||||
{
|
||||
std::lock_guard<std::mutex> guard(m_managerMutex);
|
||||
m_histoMap.erase(name);
|
||||
}
|
||||
|
||||
void SpectrumManager::AddCutToHistogramDraw(const std::string& cutname, const std::string& histoname)
|
||||
{
|
||||
std::lock_guard<std::mutex> guard(m_managerMutex);
|
||||
auto iter = m_histoMap.find(histoname);
|
||||
if (iter != m_histoMap.end())
|
||||
iter->second->AddCutToBeDrawn(cutname);
|
||||
}
|
||||
|
||||
void SpectrumManager::AddCutToHistogramApplied(const std::string& cutname, const std::string& histoname)
|
||||
{
|
||||
std::lock_guard<std::mutex> guard(m_managerMutex);
|
||||
auto iter = m_histoMap.find(histoname);
|
||||
if (iter != m_histoMap.end())
|
||||
iter->second->AddCutToBeApplied(cutname);
|
||||
}
|
||||
|
||||
void SpectrumManager::UpdateHistograms()
|
||||
{
|
||||
std::lock_guard<std::mutex> guard(m_managerMutex);
|
||||
bool cutFlag;
|
||||
for (auto& pair : m_histoMap)
|
||||
{
|
||||
cutFlag = true;
|
||||
for (auto& cutname : pair.second->GetParameters().cutsAppliedTo)
|
||||
{
|
||||
if (!IsInsideCut(cutname))
|
||||
{
|
||||
cutFlag = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!cutFlag)
|
||||
continue;
|
||||
|
||||
if (pair.second->Is1D())
|
||||
{
|
||||
auto iterX = m_paramMap.find(pair.second->GetXParam());
|
||||
if (iterX != m_paramMap.end() && iterX->second->validFlag)
|
||||
pair.second->FillData(iterX->second->value);
|
||||
}
|
||||
else if (pair.second->Is2D())
|
||||
{
|
||||
auto iterX = m_paramMap.find(pair.second->GetXParam());
|
||||
auto iterY = m_paramMap.find(pair.second->GetYParam());
|
||||
if (iterX != m_paramMap.end() && iterY != m_paramMap.end() && iterX->second->validFlag && iterY->second->validFlag)
|
||||
pair.second->FillData(iterX->second->value, iterY->second->value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SpectrumManager::ClearHistograms()
|
||||
{
|
||||
std::lock_guard<std::mutex> guard(m_managerMutex);
|
||||
for (auto& pair : m_histoMap)
|
||||
pair.second->ClearData();
|
||||
}
|
||||
|
||||
void SpectrumManager::ClearHistogram(const std::string& name)
|
||||
{
|
||||
std::lock_guard<std::mutex> guard(m_managerMutex);
|
||||
auto iter = m_histoMap.find(name);
|
||||
if (iter != m_histoMap.end())
|
||||
iter->second->ClearData();
|
||||
}
|
||||
|
||||
void SpectrumManager::DrawHistogram(const std::string& name)
|
||||
{
|
||||
std::lock_guard<std::mutex> guard(m_managerMutex);
|
||||
auto iter = m_histoMap.find(name);
|
||||
if (iter != m_histoMap.end())
|
||||
{
|
||||
iter->second->Draw();
|
||||
for (auto& cutname : iter->second->GetParameters().cutsDrawnUpon)
|
||||
DrawCut(cutname);
|
||||
}
|
||||
}
|
||||
|
||||
const HistogramParameters& SpectrumManager::GetHistogramParams(const std::string& name)
|
||||
{
|
||||
std::lock_guard<std::mutex> guard(m_managerMutex);
|
||||
auto iter = m_histoMap.find(name);
|
||||
if (iter != m_histoMap.end())
|
||||
return iter->second->GetParameters();
|
||||
else
|
||||
return m_nullHistoResult;
|
||||
}
|
||||
|
||||
StatResults SpectrumManager::AnalyzeHistogramRegion(const std::string& name, const ImPlotRect& region)
|
||||
{
|
||||
std::lock_guard<std::mutex> guard(m_managerMutex);
|
||||
auto iter = m_histoMap.find(name);
|
||||
if (iter != m_histoMap.end())
|
||||
return iter->second->AnalyzeRegion(region.X.Min, region.X.Max, region.Y.Min, region.Y.Max);
|
||||
else
|
||||
return StatResults();
|
||||
}
|
||||
|
||||
std::vector<HistogramParameters> SpectrumManager::GetListOfHistograms()
|
||||
{
|
||||
std::lock_guard<std::mutex> guard(m_managerMutex);
|
||||
std::vector<HistogramParameters> list;
|
||||
list.reserve(m_histoMap.size());
|
||||
for (auto& gram : m_histoMap)
|
||||
{
|
||||
list.push_back(gram.second->GetParameters());
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
void SpectrumManager::BindParameter(NavParameter& param)
|
||||
{
|
||||
std::lock_guard<std::mutex> guard(m_managerMutex);
|
||||
auto iter = m_paramMap.find(param.GetName());
|
||||
if (iter == m_paramMap.end())
|
||||
{
|
||||
m_paramMap[param.GetName()].reset(new ParameterData());
|
||||
}
|
||||
|
||||
param.m_pdata = m_paramMap[param.GetName()];
|
||||
}
|
||||
|
||||
void SpectrumManager::InvalidateParameters()
|
||||
{
|
||||
std::lock_guard<std::mutex> guard(m_managerMutex);
|
||||
for (auto& param : m_paramMap)
|
||||
{
|
||||
param.second->validFlag = false;
|
||||
param.second->value = 0.0;
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<std::string> SpectrumManager::GetListOfParameters()
|
||||
{
|
||||
std::lock_guard<std::mutex> guard(m_managerMutex);
|
||||
std::vector<std::string> list;
|
||||
list.reserve(m_paramMap.size());
|
||||
for (auto iter : m_paramMap)
|
||||
{
|
||||
list.push_back(iter.first);
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
void SpectrumManager::RemoveCut(const std::string& name)
|
||||
{
|
||||
std::lock_guard<std::mutex> guard(m_managerMutex);
|
||||
m_cutMap.erase(name);
|
||||
RemoveCutFromHistograms(name);
|
||||
}
|
||||
|
||||
std::vector<double> SpectrumManager::GetCutXPoints(const std::string& name)
|
||||
{
|
||||
std::lock_guard<std::mutex> guard(m_managerMutex);
|
||||
std::vector<double> null_result;
|
||||
auto iter = m_cutMap.find(name);
|
||||
if (iter != m_cutMap.end())
|
||||
return iter->second->GetXValues();
|
||||
return null_result;
|
||||
}
|
||||
|
||||
std::vector<double> SpectrumManager::GetCutYPoints(const std::string& name)
|
||||
{
|
||||
std::lock_guard<std::mutex> guard(m_managerMutex);
|
||||
std::vector<double> null_result;
|
||||
auto iter = m_cutMap.find(name);
|
||||
if (iter != m_cutMap.end())
|
||||
return iter->second->GetYValues();
|
||||
return null_result;
|
||||
}
|
||||
|
||||
std::vector<CutParams> SpectrumManager::GetListOfCuts()
|
||||
{
|
||||
std::lock_guard<std::mutex> guard(m_managerMutex);
|
||||
std::vector<CutParams> list;
|
||||
list.reserve(m_cutMap.size());
|
||||
for (auto& entry : m_cutMap)
|
||||
list.push_back(entry.second->GetCutParams());
|
||||
return list;
|
||||
}
|
||||
|
||||
/*
|
||||
Private Functions
|
||||
Can only be called from within the SpectrumManager, therefore the lock should already have been aquired by
|
||||
whatever parent function calls them
|
||||
*/
|
||||
|
||||
//private helper function; does not need thread-locked
|
||||
void SpectrumManager::RemoveCutFromHistograms(const std::string& cutname)
|
||||
{
|
||||
for (auto& gram : m_histoMap)
|
||||
{
|
||||
auto& params = gram.second->GetParameters();
|
||||
for (size_t i = 0; i < params.cutsDrawnUpon.size(); ++i)
|
||||
{
|
||||
if (params.cutsDrawnUpon[i] == cutname)
|
||||
{
|
||||
params.cutsDrawnUpon.erase(params.cutsDrawnUpon.begin() + i);
|
||||
}
|
||||
}
|
||||
for (size_t i = 0; i < params.cutsAppliedTo.size(); ++i)
|
||||
{
|
||||
if (params.cutsAppliedTo[i] == cutname)
|
||||
{
|
||||
params.cutsAppliedTo.erase(params.cutsAppliedTo.begin() + i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SpectrumManager::DrawCut(const std::string& name)
|
||||
{
|
||||
auto iter = m_cutMap.find(name);
|
||||
if (iter != m_cutMap.end())
|
||||
iter->second->Draw();
|
||||
}
|
||||
|
||||
bool SpectrumManager::IsInsideCut(const std::string& name)
|
||||
{
|
||||
bool result = false;
|
||||
auto iter = m_cutMap.find(name);
|
||||
if (iter != m_cutMap.end())
|
||||
{
|
||||
const std::string& xpar = iter->second->GetXParameter();
|
||||
const std::string& ypar = iter->second->GetYParameter();
|
||||
if (iter->second->Is1D())
|
||||
{
|
||||
auto iterX = m_paramMap.find(xpar);
|
||||
if (iterX != m_paramMap.end() && iterX->second->validFlag)
|
||||
result = iter->second->IsInside(iterX->second->value);
|
||||
}
|
||||
else if (iter->second->Is2D())
|
||||
{
|
||||
auto iterX = m_paramMap.find(xpar);
|
||||
auto iterY = m_paramMap.find(ypar);
|
||||
if (iterX != m_paramMap.end() && iterX->second->validFlag && iterY != m_paramMap.end() && iterY->second->validFlag)
|
||||
result = iter->second->IsInside(iterX->second->value, iterY->second->value);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
71
Navigator/src/Navigator/SpectrumManager.h
Normal file
71
Navigator/src/Navigator/SpectrumManager.h
Normal file
|
@ -0,0 +1,71 @@
|
|||
#ifndef SPECTRUM_MANAGER_H
|
||||
#define SPECTRUM_MANAGER_H
|
||||
|
||||
#include "Histogram.h"
|
||||
#include "Cut.h"
|
||||
#include "Parameter.h"
|
||||
|
||||
#include <thread>
|
||||
|
||||
struct ImPlotRect;
|
||||
|
||||
namespace Navigator {
|
||||
|
||||
class NAV_API SpectrumManager
|
||||
{
|
||||
public:
|
||||
SpectrumManager();
|
||||
~SpectrumManager();
|
||||
|
||||
inline static SpectrumManager& GetInstance() { return *s_instance; }
|
||||
|
||||
void AddHistogram(const HistogramParameters& params);
|
||||
void RemoveHistogram(const std::string& name);
|
||||
void AddCutToHistogramDraw(const std::string& cutname, const std::string& histoname);
|
||||
void AddCutToHistogramApplied(const std::string& cutname, const std::string& histoname);
|
||||
void UpdateHistograms();
|
||||
void ClearHistograms();
|
||||
void ClearHistogram(const std::string& name);
|
||||
void DrawHistogram(const std::string& name);
|
||||
const HistogramParameters& GetHistogramParams(const std::string& name);
|
||||
StatResults AnalyzeHistogramRegion(const std::string& name, const ImPlotRect& region);
|
||||
std::vector<HistogramParameters> GetListOfHistograms();
|
||||
|
||||
void BindParameter(NavParameter& param);
|
||||
void InvalidateParameters();
|
||||
std::vector<std::string> GetListOfParameters();
|
||||
|
||||
inline void AddCut(const CutParams& params, double min, double max)
|
||||
{
|
||||
std::lock_guard<std::mutex> guard(m_managerMutex);
|
||||
m_cutMap[params.name].reset(new Cut1D(params, min, max));
|
||||
}
|
||||
inline void AddCut(const CutParams& params, const std::vector<double>& xpoints, const std::vector<double>& ypoints)
|
||||
{
|
||||
std::lock_guard<std::mutex> guard(m_managerMutex);
|
||||
m_cutMap[params.name].reset(new Cut2D(params, xpoints, ypoints));
|
||||
}
|
||||
void RemoveCut(const std::string& name);
|
||||
std::vector<double> GetCutXPoints(const std::string& name);
|
||||
std::vector<double> GetCutYPoints(const std::string& name);
|
||||
std::vector<CutParams> GetListOfCuts();
|
||||
|
||||
private:
|
||||
void RemoveCutFromHistograms(const std::string& cutname);
|
||||
void DrawCut(const std::string& name);
|
||||
bool IsInsideCut(const std::string& name);
|
||||
|
||||
static SpectrumManager* s_instance;
|
||||
|
||||
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;
|
||||
|
||||
HistogramParameters m_nullHistoResult;
|
||||
|
||||
std::mutex m_managerMutex;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
|
@ -1,4 +1,5 @@
|
|||
#include "SpectrumSerializer.h"
|
||||
#include "SpectrumManager.h"
|
||||
|
||||
#include <fstream>
|
||||
|
||||
|
@ -13,8 +14,7 @@ namespace Navigator {
|
|||
|
||||
void SpectrumSerializer::SerializeData(const std::vector<HistogramParameters>& histoList, const std::vector<CutParams>& cutList)
|
||||
{
|
||||
//HistogramMap& histMap = HistogramMap::GetInstance();
|
||||
CutMap& cutMap = CutMap::GetInstance();
|
||||
SpectrumManager& manager = SpectrumManager::GetInstance();
|
||||
|
||||
std::ofstream output(m_filename);
|
||||
if (!output.is_open())
|
||||
|
@ -28,7 +28,7 @@ namespace Navigator {
|
|||
{
|
||||
if (cut.y_par == "None")
|
||||
{
|
||||
auto xpoints = cutMap.GetCutXPoints(cut.name);
|
||||
std::vector<double> xpoints = manager.GetCutXPoints(cut.name);
|
||||
output << "\tbegin_cut1D" << std::endl;
|
||||
output << "\t\tname: " << cut.name << std::endl;
|
||||
output << "\t\txparam: " << cut.x_par << std::endl;
|
||||
|
@ -38,8 +38,8 @@ namespace Navigator {
|
|||
}
|
||||
else
|
||||
{
|
||||
auto xpoints = cutMap.GetCutXPoints(cut.name);
|
||||
auto ypoints = cutMap.GetCutYPoints(cut.name);
|
||||
std::vector<double> xpoints = manager.GetCutXPoints(cut.name);
|
||||
std::vector<double> ypoints = manager.GetCutYPoints(cut.name);
|
||||
output << "\tbegin_cut2D" << std::endl;
|
||||
output << "\t\tname: " << cut.name << std::endl;
|
||||
output << "\t\txparam: " << cut.x_par << std::endl;
|
||||
|
@ -121,8 +121,7 @@ namespace Navigator {
|
|||
|
||||
void SpectrumSerializer::DeserializeData()
|
||||
{
|
||||
HistogramMap& histMap = HistogramMap::GetInstance();
|
||||
CutMap& cutMap = CutMap::GetInstance();
|
||||
SpectrumManager& manager = SpectrumManager::GetInstance();
|
||||
|
||||
std::ifstream input(m_filename);
|
||||
if (!input.is_open())
|
||||
|
@ -156,7 +155,7 @@ namespace Navigator {
|
|||
input >> check >> value_doub;
|
||||
cut_xdata.push_back(value_doub);
|
||||
input >> check;
|
||||
cutMap.AddCut(cut_data, cut_xdata[0], cut_xdata[1]);
|
||||
manager.AddCut(cut_data, cut_xdata[0], cut_xdata[1]);
|
||||
}
|
||||
else if (check == "begin_cut2D")
|
||||
{
|
||||
|
@ -182,7 +181,7 @@ namespace Navigator {
|
|||
cut_ydata.push_back(std::stod(check));
|
||||
}
|
||||
input >> check;
|
||||
cutMap.AddCut(cut_data, cut_xdata, cut_ydata);
|
||||
manager.AddCut(cut_data, cut_xdata, cut_ydata);
|
||||
}
|
||||
else if (check == "end_cuts")
|
||||
break;
|
||||
|
@ -229,7 +228,7 @@ namespace Navigator {
|
|||
}
|
||||
}
|
||||
input >> check;
|
||||
histMap.AddHistogram(hist_data);
|
||||
manager.AddHistogram(hist_data);
|
||||
}
|
||||
else if (check == "begin_histogram2D")
|
||||
{
|
||||
|
@ -265,7 +264,7 @@ namespace Navigator {
|
|||
}
|
||||
}
|
||||
input >> check;
|
||||
histMap.AddHistogram(hist_data);
|
||||
manager.AddHistogram(hist_data);
|
||||
}
|
||||
else if (check == "end_histograms")
|
||||
break;
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
#ifndef SPECTRUM_SERIALIZER_H
|
||||
#define SPECTRUM_SERIALIZER_H
|
||||
|
||||
#include "HistogramMap.h"
|
||||
#include "CutMap.h"
|
||||
#include "Histogram.h"
|
||||
#include "Cut.h"
|
||||
|
||||
namespace Navigator {
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user