mirror of
https://github.com/gwm17/Specter.git
synced 2024-11-22 18:28:52 -05:00
Added colorbar and adjustable color scale to zoomed in 2D histograms
This commit is contained in:
parent
41dedeef25
commit
e27d537788
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -18,6 +18,8 @@ namespace Navigator {
|
|||
NavParameter x1;
|
||||
NavParameter x2;
|
||||
NavParameter xavg;
|
||||
NavParameter scintLeft;
|
||||
NavParameter anodeBack;
|
||||
|
||||
double weight1 = 1.7;
|
||||
double weight2 = -0.7;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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];
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -116,6 +116,18 @@ namespace Navigator {
|
|||
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)
|
||||
{
|
||||
std::lock_guard<std::mutex> guard(m_managerMutex);
|
||||
|
|
|
@ -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<HistogramParameters> GetListOfHistograms();
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user