diff --git a/NavProject/SPSAnalysisStage.cpp b/NavProject/SPSAnalysisStage.cpp index 79f55ba..203d79a 100644 --- a/NavProject/SPSAnalysisStage.cpp +++ b/NavProject/SPSAnalysisStage.cpp @@ -3,7 +3,8 @@ namespace Navigator { 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(); manager.BindParameter(delayFLTime); @@ -13,6 +14,8 @@ namespace Navigator { manager.BindParameter(x1); manager.BindParameter(x2); manager.BindParameter(xavg); + manager.BindParameter(scintLeft); + manager.BindParameter(anodeBack); } SPSAnalysisStage::~SPSAnalysisStage() {} @@ -23,20 +26,33 @@ namespace Navigator { for(auto& hit : event) { - if(hit.id == 136) - delayFLTime.SetValue(hit.timestamp/1.0e3); - else if(hit.id == 137) - delayFRTime.SetValue(hit.timestamp/1.0e3); - else if(hit.id == 138) - delayBLTime.SetValue(hit.timestamp/1.0e3); - else if(hit.id == 139) - delayBRTime.SetValue(hit.timestamp/1.0e3); + switch (hit.id) + { + case 129: + scintLeft.SetValue(hit.longEnergy); + break; + case 136: + delayFLTime.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()) x1.SetValue((delayFLTime.GetValue() - delayFRTime.GetValue())*0.5); if(delayBLTime.IsValid() && delayBRTime.IsValid()) - x1.SetValue((delayBLTime.GetValue() - delayBRTime.GetValue())*0.5); + x2.SetValue((delayBLTime.GetValue() - delayBRTime.GetValue())*0.5); } } \ No newline at end of file diff --git a/NavProject/SPSAnalysisStage.h b/NavProject/SPSAnalysisStage.h index 1fdd8e1..a7e7b9e 100644 --- a/NavProject/SPSAnalysisStage.h +++ b/NavProject/SPSAnalysisStage.h @@ -18,6 +18,8 @@ namespace Navigator { NavParameter x1; NavParameter x2; NavParameter xavg; + NavParameter scintLeft; + NavParameter anodeBack; double weight1 = 1.7; double weight2 = -0.7; diff --git a/Navigator/src/Navigator/Editor/SpectrumPanel.cpp b/Navigator/src/Navigator/Editor/SpectrumPanel.cpp index 69f02ae..50d3bf6 100644 --- a/Navigator/src/Navigator/Editor/SpectrumPanel.cpp +++ b/Navigator/src/Navigator/Editor/SpectrumPanel.cpp @@ -43,7 +43,13 @@ namespace Navigator { } ImGui::SameLine(); 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))) { SpectrumManager::GetInstance().DrawHistogram(m_zoomedGram.name); @@ -104,6 +110,7 @@ namespace Navigator { } ImPlot::EndPlot(); } + if (acceptCutFlag) { acceptCutFlag = false; diff --git a/Navigator/src/Navigator/Histogram.cpp b/Navigator/src/Navigator/Histogram.cpp index 19d08b6..29ee8fd 100644 --- a/Navigator/src/Navigator/Histogram.cpp +++ b/Navigator/src/Navigator/Histogram.cpp @@ -54,7 +54,7 @@ namespace Navigator { //Can only be used within an ImGui / ImPlot context!! 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); } @@ -100,6 +100,8 @@ namespace Navigator { Histogram2D::Histogram2D(const HistogramParameters& params) : Histogram(params) { + m_colorScaleRange[0] = 0.0f; + m_colorScaleRange[1] = 0.0f; InitBins(); } @@ -130,7 +132,7 @@ namespace Navigator { 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; int bin_x = int((x - m_params.min_x)/m_binWidthX); int bin_y = int((m_params.max_y - y)/m_binWidthY); @@ -138,7 +140,7 @@ namespace Navigator { 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!! @@ -146,7 +148,7 @@ namespace Navigator { { ImPlot::SetupAxes(m_params.x_par.c_str(), m_params.y_par.c_str()); 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)); ImPlot::PopColormap(); } diff --git a/Navigator/src/Navigator/Histogram.h b/Navigator/src/Navigator/Histogram.h index 6d75433..b626d5f 100644 --- a/Navigator/src/Navigator/Histogram.h +++ b/Navigator/src/Navigator/Histogram.h @@ -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(); } inline virtual bool Is1D() const { return false; } inline virtual bool Is2D() const { return false; } + inline virtual float* GetColorScaleRange() { return nullptr; } inline HistogramParameters& GetParameters() { return m_params; } inline const std::string& GetXParam() const { return m_params.x_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 Is2D() const override { return true; } + inline virtual float* GetColorScaleRange() override { return m_colorScaleRange; } + private: void InitBins(); @@ -113,6 +116,7 @@ namespace Navigator { double m_binWidthY; double m_binWidthX; double m_maxBinContent; + float m_colorScaleRange[2]; }; } diff --git a/Navigator/src/Navigator/SpectrumManager.cpp b/Navigator/src/Navigator/SpectrumManager.cpp index 97a1790..a2795e1 100644 --- a/Navigator/src/Navigator/SpectrumManager.cpp +++ b/Navigator/src/Navigator/SpectrumManager.cpp @@ -116,6 +116,18 @@ namespace Navigator { return m_nullHistoResult; } + float* SpectrumManager::GetColorScaleRange(const std::string& name) + { + std::lock_guard 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) { std::lock_guard guard(m_managerMutex); diff --git a/Navigator/src/Navigator/SpectrumManager.h b/Navigator/src/Navigator/SpectrumManager.h index da888d8..6aa685d 100644 --- a/Navigator/src/Navigator/SpectrumManager.h +++ b/Navigator/src/Navigator/SpectrumManager.h @@ -28,6 +28,7 @@ namespace Navigator { void ClearHistogram(const std::string& name); void DrawHistogram(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); std::vector GetListOfHistograms();