1
0
Fork 0
mirror of https://github.com/gwm17/Specter.git synced 2024-12-03 07:28:50 -05:00

Added colorbar and adjustable color scale to zoomed in 2D histograms

This commit is contained in:
Gordon McCann 2022-02-22 20:11:08 -05:00
parent 41dedeef25
commit e27d537788
7 changed files with 59 additions and 15 deletions

View File

@ -3,7 +3,8 @@
namespace Navigator { namespace Navigator {
SPSAnalysisStage::SPSAnalysisStage() : SPSAnalysisStage::SPSAnalysisStage() :
AnalysisStage("SPSAnalysis"), delayFLTime("delayFLTime"), delayFRTime("delayFRTime"), delayBLTime("delayBLTime"), delayBRTime("delayBRTime"), x1("x1"), x2("x2"), xavg("xavg") AnalysisStage("SPSAnalysis"), delayFLTime("delayFLTime"), delayFRTime("delayFRTime"), delayBLTime("delayBLTime"), delayBRTime("delayBRTime"), x1("x1"), x2("x2"), xavg("xavg"),
scintLeft("scintLeft"), anodeBack("anodeBack")
{ {
SpectrumManager& manager = SpectrumManager::GetInstance(); SpectrumManager& manager = SpectrumManager::GetInstance();
manager.BindParameter(delayFLTime); manager.BindParameter(delayFLTime);
@ -13,6 +14,8 @@ namespace Navigator {
manager.BindParameter(x1); manager.BindParameter(x1);
manager.BindParameter(x2); manager.BindParameter(x2);
manager.BindParameter(xavg); manager.BindParameter(xavg);
manager.BindParameter(scintLeft);
manager.BindParameter(anodeBack);
} }
SPSAnalysisStage::~SPSAnalysisStage() {} SPSAnalysisStage::~SPSAnalysisStage() {}
@ -23,20 +26,33 @@ namespace Navigator {
for(auto& hit : event) for(auto& hit : event)
{ {
if(hit.id == 136) switch (hit.id)
delayFLTime.SetValue(hit.timestamp/1.0e3); {
else if(hit.id == 137) case 129:
delayFRTime.SetValue(hit.timestamp/1.0e3); scintLeft.SetValue(hit.longEnergy);
else if(hit.id == 138) break;
delayBLTime.SetValue(hit.timestamp/1.0e3); case 136:
else if(hit.id == 139) delayFLTime.SetValue(hit.timestamp / 1.0e3);
delayBRTime.SetValue(hit.timestamp/1.0e3); break;
case 137:
delayFRTime.SetValue(hit.timestamp / 1.0e3);
break;
case 138:
delayBLTime.SetValue(hit.timestamp / 1.0e3);
break;
case 139:
delayBRTime.SetValue(hit.timestamp / 1.0e3);
break;
case 143:
anodeBack.SetValue(hit.longEnergy);
break;
}
} }
if(delayFLTime.IsValid() && delayFRTime.IsValid()) if(delayFLTime.IsValid() && delayFRTime.IsValid())
x1.SetValue((delayFLTime.GetValue() - delayFRTime.GetValue())*0.5); x1.SetValue((delayFLTime.GetValue() - delayFRTime.GetValue())*0.5);
if(delayBLTime.IsValid() && delayBRTime.IsValid()) if(delayBLTime.IsValid() && delayBRTime.IsValid())
x1.SetValue((delayBLTime.GetValue() - delayBRTime.GetValue())*0.5); x2.SetValue((delayBLTime.GetValue() - delayBRTime.GetValue())*0.5);
} }
} }

View File

@ -18,6 +18,8 @@ namespace Navigator {
NavParameter x1; NavParameter x1;
NavParameter x2; NavParameter x2;
NavParameter xavg; NavParameter xavg;
NavParameter scintLeft;
NavParameter anodeBack;
double weight1 = 1.7; double weight1 = 1.7;
double weight2 = -0.7; double weight2 = -0.7;

View File

@ -43,7 +43,13 @@ namespace Navigator {
} }
ImGui::SameLine(); ImGui::SameLine();
RenderRemoveRegionButton(); RenderRemoveRegionButton();
if (m_zoomedGram.y_par != "None")
{
float* scale = SpectrumManager::GetInstance().GetColorScaleRange(m_zoomedGram.name);
ImGui::DragFloatRange2("Min / Max", &(scale[0]), &(scale[1]), 0.01f);
ImPlot::ColormapScale("##HistogramScale", scale[0], scale[1], ImVec2(0, -1), ImPlotColormap_Viridis);
ImGui::SameLine();
}
if (ImPlot::BeginPlot(m_zoomedGram.name.c_str(), ImVec2(-1, -1))) if (ImPlot::BeginPlot(m_zoomedGram.name.c_str(), ImVec2(-1, -1)))
{ {
SpectrumManager::GetInstance().DrawHistogram(m_zoomedGram.name); SpectrumManager::GetInstance().DrawHistogram(m_zoomedGram.name);
@ -104,6 +110,7 @@ namespace Navigator {
} }
ImPlot::EndPlot(); ImPlot::EndPlot();
} }
if (acceptCutFlag) if (acceptCutFlag)
{ {
acceptCutFlag = false; acceptCutFlag = false;

View File

@ -54,7 +54,7 @@ namespace Navigator {
//Can only be used within an ImGui / ImPlot context!! //Can only be used within an ImGui / ImPlot context!!
void Histogram1D::Draw() void Histogram1D::Draw()
{ {
ImPlot::SetupAxes(m_params.x_par.c_str(), "Counts",0, ImPlotAxisFlags_LockMin); ImPlot::SetupAxes(m_params.x_par.c_str(), "Counts",0, ImPlotAxisFlags_LockMin | ImPlotAxisFlags_AutoFit);
ImPlot::PlotBars(m_params.name.c_str(), &m_binCenters.data()[0], &m_binCounts.data()[0], m_params.nbins_x, m_binWidth); ImPlot::PlotBars(m_params.name.c_str(), &m_binCenters.data()[0], &m_binCounts.data()[0], m_params.nbins_x, m_binWidth);
} }
@ -100,6 +100,8 @@ namespace Navigator {
Histogram2D::Histogram2D(const HistogramParameters& params) : Histogram2D::Histogram2D(const HistogramParameters& params) :
Histogram(params) Histogram(params)
{ {
m_colorScaleRange[0] = 0.0f;
m_colorScaleRange[1] = 0.0f;
InitBins(); InitBins();
} }
@ -130,7 +132,7 @@ namespace Navigator {
void Histogram2D::FillData(double x, double y) void Histogram2D::FillData(double x, double y)
{ {
if (x < m_params.min_x || x >= m_params.max_x || y < m_params.min_y || y >= m_params.max_y) if (x < m_params.min_x || x >= m_params.max_x || y <= m_params.min_y || y > m_params.max_y)
return; 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);
@ -138,7 +140,7 @@ namespace Navigator {
m_binCounts[bin] += 1.0; m_binCounts[bin] += 1.0;
m_maxBinContent = m_binCounts[bin] > m_maxBinContent ? (m_binCounts[bin]*2) : m_maxBinContent; m_maxBinContent = m_binCounts[bin] > m_maxBinContent ? (m_binCounts[bin]) : m_maxBinContent;
} }
//Can only be used within an ImGui / ImPlot context!! //Can only be used within an ImGui / ImPlot context!!
@ -146,7 +148,7 @@ namespace Navigator {
{ {
ImPlot::SetupAxes(m_params.x_par.c_str(), m_params.y_par.c_str()); ImPlot::SetupAxes(m_params.x_par.c_str(), m_params.y_par.c_str());
ImPlot::PushColormap(ImPlotColormap_Viridis); ImPlot::PushColormap(ImPlotColormap_Viridis);
ImPlot::PlotHeatmap(m_params.name.c_str(), &m_binCounts.data()[0], m_params.nbins_y, m_params.nbins_x, 0.0, m_maxBinContent, NULL, ImPlot::PlotHeatmap(m_params.name.c_str(), &m_binCounts.data()[0], m_params.nbins_y, m_params.nbins_x, m_colorScaleRange[0], m_colorScaleRange[1], NULL,
ImPlotPoint(m_params.min_x, m_params.min_y), ImPlotPoint(m_params.max_x, m_params.max_y)); ImPlotPoint(m_params.min_x, m_params.min_y), ImPlotPoint(m_params.max_x, m_params.max_y));
ImPlot::PopColormap(); ImPlot::PopColormap();
} }

View File

@ -60,6 +60,7 @@ namespace Navigator {
virtual StatResults AnalyzeRegion(double x_min, double x_max, double y_min = 0.0, double y_max = 0.0) { return StatResults(); } virtual StatResults AnalyzeRegion(double x_min, double x_max, double y_min = 0.0, double y_max = 0.0) { return StatResults(); }
inline virtual bool Is1D() const { return false; } inline virtual bool Is1D() const { return false; }
inline virtual bool Is2D() const { return false; } inline virtual bool Is2D() const { return false; }
inline virtual float* GetColorScaleRange() { return nullptr; }
inline HistogramParameters& GetParameters() { return m_params; } inline HistogramParameters& GetParameters() { return m_params; }
inline const std::string& GetXParam() const { return m_params.x_par; }; inline const std::string& GetXParam() const { return m_params.x_par; };
inline const std::string& GetYParam() const { return m_params.y_par; }; inline const std::string& GetYParam() const { return m_params.y_par; };
@ -105,6 +106,8 @@ namespace Navigator {
inline virtual bool Is1D() const override { return false; } inline virtual bool Is1D() const override { return false; }
inline virtual bool Is2D() const override { return true; } inline virtual bool Is2D() const override { return true; }
inline virtual float* GetColorScaleRange() override { return m_colorScaleRange; }
private: private:
void InitBins(); void InitBins();
@ -113,6 +116,7 @@ namespace Navigator {
double m_binWidthY; double m_binWidthY;
double m_binWidthX; double m_binWidthX;
double m_maxBinContent; double m_maxBinContent;
float m_colorScaleRange[2];
}; };
} }

View File

@ -116,6 +116,18 @@ namespace Navigator {
return m_nullHistoResult; return m_nullHistoResult;
} }
float* SpectrumManager::GetColorScaleRange(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->GetColorScaleRange();
}
return nullptr;
}
StatResults SpectrumManager::AnalyzeHistogramRegion(const std::string& name, const ImPlotRect& region) StatResults SpectrumManager::AnalyzeHistogramRegion(const std::string& name, const ImPlotRect& region)
{ {
std::lock_guard<std::mutex> guard(m_managerMutex); std::lock_guard<std::mutex> guard(m_managerMutex);

View File

@ -28,6 +28,7 @@ namespace Navigator {
void ClearHistogram(const std::string& name); void ClearHistogram(const std::string& name);
void DrawHistogram(const std::string& name); void DrawHistogram(const std::string& name);
const HistogramParameters& GetHistogramParams(const std::string& name); const HistogramParameters& GetHistogramParams(const std::string& name);
float* GetColorScaleRange(const std::string& name);
StatResults AnalyzeHistogramRegion(const std::string& name, const ImPlotRect& region); StatResults AnalyzeHistogramRegion(const std::string& name, const ImPlotRect& region);
std::vector<HistogramParameters> GetListOfHistograms(); std::vector<HistogramParameters> GetListOfHistograms();