From ab374ef4e85e87d9e0c3af2a8c88d80a696bbb7a Mon Sep 17 00:00:00 2001 From: Gordon McCann Date: Sun, 23 Jan 2022 21:32:30 -0500 Subject: [PATCH] Fixed logic for updating histograms and checking cuts. Implemented small test on single parameter. Validated --- Navigator/src/Navigator/Application.cpp | 5 +++- Navigator/src/Navigator/CutMap.cpp | 22 +++++++++++++---- Navigator/src/Navigator/CutMap.h | 8 +++--- Navigator/src/Navigator/Histogram.cpp | 28 ++++++++++++++++++--- Navigator/src/Navigator/Histogram.h | 6 ++--- Navigator/src/Navigator/HistogramMap.cpp | 31 +----------------------- 6 files changed, 53 insertions(+), 47 deletions(-) diff --git a/Navigator/src/Navigator/Application.cpp b/Navigator/src/Navigator/Application.cpp index 841cb8b..94f84bb 100644 --- a/Navigator/src/Navigator/Application.cpp +++ b/Navigator/src/Navigator/Application.cpp @@ -66,9 +66,9 @@ namespace Navigator { { //PhysicsStartEvent junk("/media/gordon/GordonData/gwm17/NavTests/data/", DataSource::SourceType::CompassOffline, 2000000); //OnEvent(junk); - HistogramMap::GetInstance().UpdateHistograms(); while(m_runFlag) { + HistogramMap::GetInstance().UpdateHistograms(); RenderCommand::SetClearColor(m_bckgnd_color); RenderCommand::Clear(); @@ -81,6 +81,9 @@ namespace Navigator { layer->OnImGuiRender(); m_imgui_layer->End(); m_window->OnUpdate(); + + ParameterMap::GetInstance().find("joseph")->second->validFlag = true; + ParameterMap::GetInstance().find("joseph")->second->value = 8.0; } } } diff --git a/Navigator/src/Navigator/CutMap.cpp b/Navigator/src/Navigator/CutMap.cpp index db7b565..6cf0c08 100644 --- a/Navigator/src/Navigator/CutMap.cpp +++ b/Navigator/src/Navigator/CutMap.cpp @@ -1,4 +1,5 @@ #include "CutMap.h" +#include "ParameterMap.h" #include "implot.h" namespace Navigator { @@ -11,9 +12,13 @@ namespace Navigator { Cut1D::~Cut1D() {} - bool Cut1D::IsInside(double x, double y) const + bool Cut1D::IsInside() const { - return x >= m_minVal && x <= m_maxVal; + ParameterMap& parMap = ParameterMap::GetInstance(); + auto iter = parMap.find(m_params.x_par); + if (iter == parMap.end() || !iter->second->validFlag) + return false; + return iter->second->value >= m_minVal && iter->second->value <= m_maxVal; } //Only within an ImPlot/ImGui context!!! @@ -38,8 +43,15 @@ namespace Navigator { 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 Cut2D::IsInside() const { + ParameterMap& parMap = ParameterMap::GetInstance(); + auto iterx = parMap.find(m_params.x_par); + auto itery = parMap.find(m_params.y_par); + if (iterx == parMap.end() || itery == parMap.end() || !iterx->second->validFlag || !itery->second->validFlag) + return false; + double x = iterx->second->value; + double y = itery->second->value; bool result = false; double slope; for(size_t i=0; i<(m_xpoints.size()-1); i++) @@ -78,12 +90,12 @@ namespace Navigator { iter->second->Draw(); } - bool CutMap::IsInsideCut(const std::string& name, double xval, double yval) + bool CutMap::IsInsideCut(const std::string& name) { bool result = false; auto iter = m_map.find(name); if(iter != m_map.end()) - result = iter->second->IsInside(xval, yval); + result = iter->second->IsInside(); return result; } diff --git a/Navigator/src/Navigator/CutMap.h b/Navigator/src/Navigator/CutMap.h index a9677bc..2d74ba3 100644 --- a/Navigator/src/Navigator/CutMap.h +++ b/Navigator/src/Navigator/CutMap.h @@ -30,7 +30,7 @@ namespace Navigator { virtual ~Cut() {} - virtual bool IsInside(double x, double y = 0) const = 0; + virtual bool IsInside() const = 0; virtual void Draw() const = 0; virtual bool Is1D() const = 0; virtual bool Is2D() const = 0; @@ -50,7 +50,7 @@ namespace Navigator { public: Cut1D(const CutParams& params, double min, double max); virtual ~Cut1D(); - virtual bool IsInside(double x, double y = 0) const override; + virtual bool IsInside() const override; virtual void Draw() const override; virtual bool Is1D() const override { return true; } virtual bool Is2D() const override { return false; } @@ -66,7 +66,7 @@ namespace Navigator { public: Cut2D(const CutParams& params, const std::vector& xpoints, const std::vector& ypoints); virtual ~Cut2D(); - virtual bool IsInside(double x, double y = 0) const override; + virtual bool IsInside() const override; virtual void Draw() const override; virtual bool Is1D() const override { return false; } virtual bool Is2D() const override { return true; } @@ -103,7 +103,7 @@ namespace Navigator { } void DrawCut(const std::string& name); - bool IsInsideCut(const std::string& name, double xval, double yval = 0); + bool IsInsideCut(const std::string& name); std::vector GetListOfCutParams(); inline Iter begin() { return m_map.begin(); } diff --git a/Navigator/src/Navigator/Histogram.cpp b/Navigator/src/Navigator/Histogram.cpp index c12668f..58c1760 100644 --- a/Navigator/src/Navigator/Histogram.cpp +++ b/Navigator/src/Navigator/Histogram.cpp @@ -1,5 +1,6 @@ #include "Histogram.h" #include "CutMap.h" +#include "ParameterMap.h" #include "implot.h" /* @@ -44,15 +45,23 @@ 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(double x, double y) + void Histogram1D::FillData() { + ParameterMap& parMap = ParameterMap::GetInstance(); + if (!parMap.IsParameterValid(m_params.x_par)) + return; + double x = parMap.GetParameterValue(m_params.x_par); if(x < m_params.min_x || x >= 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 - m_params.min_x)/(m_binWidth)); - auto& cutmap = CutMap::GetInstance(); - m_binCounts[bin] += 1.0; } @@ -107,10 +116,21 @@ namespace Navigator { m_initFlag = true; } - void Histogram2D::FillData(double x, double y) + void Histogram2D::FillData() { + ParameterMap& parMap = ParameterMap::GetInstance(); + CutMap& cutMap = CutMap::GetInstance(); + if (!parMap.IsParameterValid(m_params.x_par) || !parMap.IsParameterValid(m_params.y_par)) + return; + double x = parMap.GetParameterValue(m_params.x_par); + double y = parMap.GetParameterValue(m_params.y_par); if(x < m_params.min_x || x >= m_params.max_x || y < m_params.min_y || y >= m_params.max_y || !m_initFlag) return; + for (auto& cut : m_params.cutsAppliedTo) + { + if (!cutMap.IsInsideCut(cut)) + return; + } int bin_x = int((x - m_params.min_x)/m_binWidthX); int bin_y = int((m_params.max_y - y)/m_binWidthY); diff --git a/Navigator/src/Navigator/Histogram.h b/Navigator/src/Navigator/Histogram.h index fe3b360..ee9bf5b 100644 --- a/Navigator/src/Navigator/Histogram.h +++ b/Navigator/src/Navigator/Histogram.h @@ -45,7 +45,7 @@ namespace Navigator { } virtual ~Histogram() {}; - virtual void FillData(double x, double y = 0) { NAV_WARN("Trying to fill a default histogram!"); } + virtual void FillData() { NAV_WARN("Trying to fill a default histogram!"); } virtual void Draw() {} virtual void ClearData() {} inline virtual bool Is1D() const { return false; } @@ -67,7 +67,7 @@ namespace Navigator { public: Histogram1D(const HistogramParameters& params); virtual ~Histogram1D(); - virtual void FillData(double x, double y=0) override; + virtual void FillData() override; virtual void Draw() override; virtual void ClearData() override; inline virtual bool Is1D() const override { return true; } @@ -87,7 +87,7 @@ namespace Navigator { public: Histogram2D(const HistogramParameters& params); virtual ~Histogram2D(); - virtual void FillData(double x, double y=0) override; + virtual void FillData() override; virtual void Draw() override; virtual void ClearData() override; inline virtual bool Is1D() const override { return false; } diff --git a/Navigator/src/Navigator/HistogramMap.cpp b/Navigator/src/Navigator/HistogramMap.cpp index 16774aa..3e28a47 100644 --- a/Navigator/src/Navigator/HistogramMap.cpp +++ b/Navigator/src/Navigator/HistogramMap.cpp @@ -68,36 +68,7 @@ namespace Navigator { ParameterMap& pmap = ParameterMap::GetInstance(); for (auto& pair : m_map) { - - xpar = pair.second->GetXParam(); - ypar = pair.second->GetYParam(); - - if (pair.second->Is1D()) - { - auto iter = pmap.find(xpar); - if (iter == pmap.end() || !iter->second->validFlag) - { - continue; - } - else - { - pair.second->FillData(iter->second->value); - } - } - else - { - auto iterx = pmap.find(xpar); - auto itery = pmap.find(ypar); - if (iterx == pmap.end() || itery == pmap.end() || !iterx->second->validFlag || !itery->second->validFlag) - { - continue; - } - else - { - pair.second->FillData(iterx->second->value, itery->second->value); - } - - } + pair.second->FillData(); } }