mirror of
https://github.com/gwm17/Specter.git
synced 2024-11-26 12:18:51 -05:00
Fixed logic for updating histograms and checking cuts. Implemented small test on single parameter. Validated
This commit is contained in:
parent
343424ead7
commit
ab374ef4e8
|
@ -66,9 +66,9 @@ namespace Navigator {
|
||||||
{
|
{
|
||||||
//PhysicsStartEvent junk("/media/gordon/GordonData/gwm17/NavTests/data/", DataSource::SourceType::CompassOffline, 2000000);
|
//PhysicsStartEvent junk("/media/gordon/GordonData/gwm17/NavTests/data/", DataSource::SourceType::CompassOffline, 2000000);
|
||||||
//OnEvent(junk);
|
//OnEvent(junk);
|
||||||
HistogramMap::GetInstance().UpdateHistograms();
|
|
||||||
while(m_runFlag)
|
while(m_runFlag)
|
||||||
{
|
{
|
||||||
|
HistogramMap::GetInstance().UpdateHistograms();
|
||||||
|
|
||||||
RenderCommand::SetClearColor(m_bckgnd_color);
|
RenderCommand::SetClearColor(m_bckgnd_color);
|
||||||
RenderCommand::Clear();
|
RenderCommand::Clear();
|
||||||
|
@ -81,6 +81,9 @@ namespace Navigator {
|
||||||
layer->OnImGuiRender();
|
layer->OnImGuiRender();
|
||||||
m_imgui_layer->End();
|
m_imgui_layer->End();
|
||||||
m_window->OnUpdate();
|
m_window->OnUpdate();
|
||||||
|
|
||||||
|
ParameterMap::GetInstance().find("joseph")->second->validFlag = true;
|
||||||
|
ParameterMap::GetInstance().find("joseph")->second->value = 8.0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
#include "CutMap.h"
|
#include "CutMap.h"
|
||||||
|
#include "ParameterMap.h"
|
||||||
#include "implot.h"
|
#include "implot.h"
|
||||||
|
|
||||||
namespace Navigator {
|
namespace Navigator {
|
||||||
|
@ -11,9 +12,13 @@ namespace Navigator {
|
||||||
|
|
||||||
Cut1D::~Cut1D() {}
|
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!!!
|
//Only within an ImPlot/ImGui context!!!
|
||||||
|
@ -38,8 +43,15 @@ namespace Navigator {
|
||||||
If odd number of intersections, point is inside. Even, point is outside.
|
If odd number of intersections, point is inside. Even, point is outside.
|
||||||
Edge cases of point is a vertex or on a side considered.
|
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;
|
bool result = false;
|
||||||
double slope;
|
double slope;
|
||||||
for(size_t i=0; i<(m_xpoints.size()-1); i++)
|
for(size_t i=0; i<(m_xpoints.size()-1); i++)
|
||||||
|
@ -78,12 +90,12 @@ namespace Navigator {
|
||||||
iter->second->Draw();
|
iter->second->Draw();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CutMap::IsInsideCut(const std::string& name, double xval, double yval)
|
bool CutMap::IsInsideCut(const std::string& name)
|
||||||
{
|
{
|
||||||
bool result = false;
|
bool result = false;
|
||||||
auto iter = m_map.find(name);
|
auto iter = m_map.find(name);
|
||||||
if(iter != m_map.end())
|
if(iter != m_map.end())
|
||||||
result = iter->second->IsInside(xval, yval);
|
result = iter->second->IsInside();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,7 @@ namespace Navigator {
|
||||||
|
|
||||||
virtual ~Cut() {}
|
virtual ~Cut() {}
|
||||||
|
|
||||||
virtual bool IsInside(double x, double y = 0) const = 0;
|
virtual bool IsInside() const = 0;
|
||||||
virtual void Draw() const = 0;
|
virtual void Draw() const = 0;
|
||||||
virtual bool Is1D() const = 0;
|
virtual bool Is1D() const = 0;
|
||||||
virtual bool Is2D() const = 0;
|
virtual bool Is2D() const = 0;
|
||||||
|
@ -50,7 +50,7 @@ namespace Navigator {
|
||||||
public:
|
public:
|
||||||
Cut1D(const CutParams& params, double min, double max);
|
Cut1D(const CutParams& params, double min, double max);
|
||||||
virtual ~Cut1D();
|
virtual ~Cut1D();
|
||||||
virtual bool IsInside(double x, double y = 0) const override;
|
virtual bool IsInside() const override;
|
||||||
virtual void Draw() const override;
|
virtual void Draw() const override;
|
||||||
virtual bool Is1D() const override { return true; }
|
virtual bool Is1D() const override { return true; }
|
||||||
virtual bool Is2D() const override { return false; }
|
virtual bool Is2D() const override { return false; }
|
||||||
|
@ -66,7 +66,7 @@ namespace Navigator {
|
||||||
public:
|
public:
|
||||||
Cut2D(const CutParams& params, const std::vector<double>& xpoints, const std::vector<double>& ypoints);
|
Cut2D(const CutParams& params, const std::vector<double>& xpoints, const std::vector<double>& ypoints);
|
||||||
virtual ~Cut2D();
|
virtual ~Cut2D();
|
||||||
virtual bool IsInside(double x, double y = 0) const override;
|
virtual bool IsInside() const override;
|
||||||
virtual void Draw() const override;
|
virtual void Draw() const override;
|
||||||
virtual bool Is1D() const override { return false; }
|
virtual bool Is1D() const override { return false; }
|
||||||
virtual bool Is2D() const override { return true; }
|
virtual bool Is2D() const override { return true; }
|
||||||
|
@ -103,7 +103,7 @@ namespace Navigator {
|
||||||
}
|
}
|
||||||
|
|
||||||
void DrawCut(const std::string& name);
|
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<CutParams> GetListOfCutParams();
|
std::vector<CutParams> GetListOfCutParams();
|
||||||
|
|
||||||
inline Iter begin() { return m_map.begin(); }
|
inline Iter begin() { return m_map.begin(); }
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
#include "Histogram.h"
|
#include "Histogram.h"
|
||||||
#include "CutMap.h"
|
#include "CutMap.h"
|
||||||
|
#include "ParameterMap.h"
|
||||||
#include "implot.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
|
//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)
|
if(x < m_params.min_x || x >= m_params.max_x || !m_initFlag)
|
||||||
return;
|
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));
|
int bin = int((x - m_params.min_x)/(m_binWidth));
|
||||||
|
|
||||||
auto& cutmap = CutMap::GetInstance();
|
|
||||||
|
|
||||||
m_binCounts[bin] += 1.0;
|
m_binCounts[bin] += 1.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -107,10 +116,21 @@ namespace Navigator {
|
||||||
m_initFlag = true;
|
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)
|
if(x < m_params.min_x || x >= m_params.max_x || y < m_params.min_y || y >= m_params.max_y || !m_initFlag)
|
||||||
return;
|
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_x = int((x - m_params.min_x)/m_binWidthX);
|
||||||
int bin_y = int((m_params.max_y - y)/m_binWidthY);
|
int bin_y = int((m_params.max_y - y)/m_binWidthY);
|
||||||
|
|
|
@ -45,7 +45,7 @@ namespace Navigator {
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual ~Histogram() {};
|
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 Draw() {}
|
||||||
virtual void ClearData() {}
|
virtual void ClearData() {}
|
||||||
inline virtual bool Is1D() const { return false; }
|
inline virtual bool Is1D() const { return false; }
|
||||||
|
@ -67,7 +67,7 @@ namespace Navigator {
|
||||||
public:
|
public:
|
||||||
Histogram1D(const HistogramParameters& params);
|
Histogram1D(const HistogramParameters& params);
|
||||||
virtual ~Histogram1D();
|
virtual ~Histogram1D();
|
||||||
virtual void FillData(double x, double y=0) override;
|
virtual void FillData() override;
|
||||||
virtual void Draw() override;
|
virtual void Draw() override;
|
||||||
virtual void ClearData() override;
|
virtual void ClearData() override;
|
||||||
inline virtual bool Is1D() const override { return true; }
|
inline virtual bool Is1D() const override { return true; }
|
||||||
|
@ -87,7 +87,7 @@ namespace Navigator {
|
||||||
public:
|
public:
|
||||||
Histogram2D(const HistogramParameters& params);
|
Histogram2D(const HistogramParameters& params);
|
||||||
virtual ~Histogram2D();
|
virtual ~Histogram2D();
|
||||||
virtual void FillData(double x, double y=0) override;
|
virtual void FillData() override;
|
||||||
virtual void Draw() override;
|
virtual void Draw() override;
|
||||||
virtual void ClearData() override;
|
virtual void ClearData() override;
|
||||||
inline virtual bool Is1D() const override { return false; }
|
inline virtual bool Is1D() const override { return false; }
|
||||||
|
|
|
@ -68,36 +68,7 @@ namespace Navigator {
|
||||||
ParameterMap& pmap = ParameterMap::GetInstance();
|
ParameterMap& pmap = ParameterMap::GetInstance();
|
||||||
for (auto& pair : m_map)
|
for (auto& pair : m_map)
|
||||||
{
|
{
|
||||||
|
pair.second->FillData();
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user