diff --git a/SpecProject/src/SPSAnalysisStage.cpp b/SpecProject/src/SPSAnalysisStage.cpp index dff1576..80cf0d7 100644 --- a/SpecProject/src/SPSAnalysisStage.cpp +++ b/SpecProject/src/SPSAnalysisStage.cpp @@ -11,7 +11,8 @@ namespace Specter { //Construct each NavParameter with their unique name. Then bind them to the SpectrumManager. SPSAnalysisStage::SPSAnalysisStage() : AnalysisStage("SPSAnalysis"), delayFLTime("delayFLTime"), delayFRTime("delayFRTime"), delayBLTime("delayBLTime"), delayBRTime("delayBRTime"), x1("x1"), x2("x2"), xavg("xavg"), - scintLeft("scintLeft"), anodeBack("anodeBack"), anodeFront("anodeFront"), cathode("cathode"), xavg_sabreCoinc("xavg_sabreCoinc"), x1_weight("x1_weight"), x2_weight("x2_weight") + scintLeft("scintLeft"), anodeBack("anodeBack"), anodeFront("anodeFront"), cathode("cathode"), xavg_sabreCoinc("xavg_sabreCoinc"), x1_weight("x1_weight"), x2_weight("x2_weight"), + beamIntegrator("beamIntegrator") { SPEC_PROFILE_FUNCTION(); SpectrumManager& manager = SpectrumManager::GetInstance(); @@ -43,6 +44,8 @@ namespace Specter { manager.BindVariable(x1_weight); manager.BindVariable(x2_weight); + + manager.BindScaler(beamIntegrator); } SPSAnalysisStage::~SPSAnalysisStage() {} @@ -72,6 +75,11 @@ namespace Specter { scintLeft.SetValue(hit.longEnergy); break; } + case 133: + { + beamIntegrator.Increment(); + break; + } case 135: { if (hit.longEnergy > cathode.GetValue()) diff --git a/SpecProject/src/SPSAnalysisStage.h b/SpecProject/src/SPSAnalysisStage.h index 0113b06..4b7fd88 100644 --- a/SpecProject/src/SPSAnalysisStage.h +++ b/SpecProject/src/SPSAnalysisStage.h @@ -36,6 +36,9 @@ namespace Specter { //Create a few variables Variable x1_weight; Variable x2_weight; + + //Create a scaler + Scaler beamIntegrator; }; } \ No newline at end of file diff --git a/Specter/src/CMakeLists.txt b/Specter/src/CMakeLists.txt index b174a61..10c0472 100644 --- a/Specter/src/CMakeLists.txt +++ b/Specter/src/CMakeLists.txt @@ -84,6 +84,8 @@ target_sources(Specter PRIVATE Specter/Editor/SpectrumDialog.h Specter/Editor/SpectrumPanel.cpp Specter/Editor/SpectrumPanel.h + Specter/Editor/ScalerPanel.h + Specter/Editor/ScalerPanel.cpp Specter/Utils/Instrumentor.h Specter/Utils/TCPClient.cpp Specter/Utils/TCPClient.h diff --git a/Specter/src/Specter/Core/Graph.cpp b/Specter/src/Specter/Core/Graph.cpp index a294549..eda649f 100644 --- a/Specter/src/Specter/Core/Graph.cpp +++ b/Specter/src/Specter/Core/Graph.cpp @@ -6,6 +6,8 @@ namespace Specter { ScalerGraph::ScalerGraph(const GraphArgs& args) : m_args(args), m_lastScalerVal(0) { + if (m_args.maxPoints < 2) //saftey check guaranteeing we have enough points to make a graph + m_args.maxPoints = 2; m_xPoints.reserve(m_args.maxPoints); m_xPoints.reserve(m_args.maxPoints); } @@ -27,7 +29,7 @@ namespace Specter { m_xPoints[i] = m_xPoints[i + 1]; m_yPoints[i] = m_yPoints[i + 1]; } - m_xPoints[m_args.maxPoints - 1] = timeStep; + m_xPoints[m_args.maxPoints - 1] = m_xPoints[m_args.maxPoints - 2] + timeStep; m_yPoints[m_args.maxPoints - 1] = rate; } diff --git a/Specter/src/Specter/Core/SpectrumManager.cpp b/Specter/src/Specter/Core/SpectrumManager.cpp index a2cc18f..1c5a86f 100644 --- a/Specter/src/Specter/Core/SpectrumManager.cpp +++ b/Specter/src/Specter/Core/SpectrumManager.cpp @@ -414,6 +414,13 @@ namespace Specter { m_scalerMap[scaler.GetName()].reset(new std::atomic(0)); } scaler.m_pdata = m_scalerMap[scaler.GetName()]; + + GraphArgs args; + args.name = scaler.GetName() + "_graph"; + args.maxPoints = 10; + args.scalerName = scaler.GetName(); + + m_graphMap[args.name].reset(new ScalerGraph(args)); } void SpectrumManager::ResetScalers() diff --git a/Specter/src/Specter/Editor/EditorLayer.cpp b/Specter/src/Specter/Editor/EditorLayer.cpp index 6c0315a..8f439ee 100644 --- a/Specter/src/Specter/Editor/EditorLayer.cpp +++ b/Specter/src/Specter/Editor/EditorLayer.cpp @@ -40,6 +40,7 @@ namespace Specter { void EditorLayer::OnUpdate(Timestep& step) { + SpectrumManager::GetInstance().UpdateGraphs(step); } void EditorLayer::OnEvent(Event& e) @@ -65,6 +66,18 @@ namespace Specter { std::sort(m_paramList.begin(), m_paramList.end(), SortByString); } + void EditorLayer::UpdateScalerList() + { + m_scalerList = SpectrumManager::GetInstance().GetListOfScalers(); + std::sort(m_scalerList.begin(), m_scalerList.end(), SortByString); + } + + void EditorLayer::UpdateGraphList() + { + m_graphList = SpectrumManager::GetInstance().GetListOfGraphs(); + std::sort(m_graphList.begin(), m_graphList.end(), SortByName); + } + //The main function void EditorLayer::OnImGuiRender() { @@ -75,6 +88,8 @@ namespace Specter { UpdateParameterList(); UpdateHistogramList(); UpdateCutList(); + UpdateScalerList(); + UpdateGraphList(); startFlag = false; } // We are using the ImGuiWindowFlags_NoDocking flag to make the parent window not dockable into, @@ -210,6 +225,8 @@ namespace Specter { if(m_spectrumDialog.ImGuiRenderSpectrumDialog(m_histoList, m_cutList, m_paramList)) UpdateHistogramList(); + m_scalerPanel.OnImGuiRender(m_scalerList, m_graphList); + m_sourceDialog.ImGuiRenderSourceDialog(); RemoveHistogramDialog(); diff --git a/Specter/src/Specter/Editor/EditorLayer.h b/Specter/src/Specter/Editor/EditorLayer.h index d2bb572..a7048cc 100644 --- a/Specter/src/Specter/Editor/EditorLayer.h +++ b/Specter/src/Specter/Editor/EditorLayer.h @@ -13,7 +13,9 @@ #include "Specter/Events/PhysicsEvent.h" #include "Specter/Core/Histogram.h" #include "Specter/Core/Cut.h" +#include "Specter/Core/Graph.h" #include "SpectrumPanel.h" +#include "ScalerPanel.h" #include "FileDialog.h" #include "SpectrumDialog.h" #include "SourceDialog.h" @@ -44,11 +46,14 @@ namespace Specter { void UpdateHistogramList(); void UpdateCutList(); void UpdateParameterList(); //Currently not really used, only once. Params all made at construction time of PhysicsLayer + void UpdateScalerList(); //Currently not really used, only once. Scalers all made at construction time of PhysicsLayer + void UpdateGraphList(); //Same void ExportHistogram(HistogramArgs selectedGram, const std::string& filename); EventCallbackFunc m_callbackFunc; SpectrumPanel m_spectrumPanel; + ScalerPanel m_scalerPanel; FileDialog m_fileDialog; SpectrumDialog m_spectrumDialog; SourceDialog m_sourceDialog; @@ -57,6 +62,8 @@ namespace Specter { std::vector m_histoList; std::vector m_cutList; std::vector m_paramList; + std::vector m_scalerList; + std::vector m_graphList; //ImGui Settings bool dockspaceOpen = true; diff --git a/Specter/src/Specter/Editor/ScalerPanel.cpp b/Specter/src/Specter/Editor/ScalerPanel.cpp new file mode 100644 index 0000000..86a1196 --- /dev/null +++ b/Specter/src/Specter/Editor/ScalerPanel.cpp @@ -0,0 +1,43 @@ +#include "ScalerPanel.h" +#include "Specter/Core/SpectrumManager.h" + +#include "imgui.h" +#include "implot.h" + +namespace Specter { + + ScalerPanel::ScalerPanel() {} + + ScalerPanel::~ScalerPanel() {} + + void ScalerPanel::OnImGuiRender(const std::vector& scalerList, const std::vector& graphList) + { + SpectrumManager& manager = SpectrumManager::GetInstance(); + if (ImGui::Begin("ScalerPanel")) + { + if (ImGui::TreeNode("Scalers")) + { + for (auto& scaler : scalerList) + { + ImGui::BulletText("%s", scaler.c_str()); + } + ImGui::TreePop(); + } + if (ImGui::BeginCombo("Graph to Plot", m_selectedGraph.name.c_str())) + { + for (auto& graph : graphList) + { + if (ImGui::Selectable(graph.name.c_str(), m_selectedGraph.name == graph.name)) + m_selectedGraph = graph; + } + ImGui::EndCombo(); + } + if (ImPlot::BeginPlot("Scaler Graphs")) + { + manager.DrawGraph(m_selectedGraph.name); + ImPlot::EndPlot(); + } + } + ImGui::End(); + } +} \ No newline at end of file diff --git a/Specter/src/Specter/Editor/ScalerPanel.h b/Specter/src/Specter/Editor/ScalerPanel.h new file mode 100644 index 0000000..06ea58f --- /dev/null +++ b/Specter/src/Specter/Editor/ScalerPanel.h @@ -0,0 +1,22 @@ +#ifndef SCALER_PANEL_H +#define SCALER_PANEL_H + +#include "Specter/Core/Graph.h" + +namespace Specter { + + class ScalerPanel + { + public: + ScalerPanel(); + ~ScalerPanel(); + + void OnImGuiRender(const std::vector& scalerList, const std::vector& graphList); + + private: + GraphArgs m_selectedGraph; + }; + +} + +#endif \ No newline at end of file