diff --git a/Navigator/src/Navigator/Editor/SpectrumPanel.cpp b/Navigator/src/Navigator/Editor/SpectrumPanel.cpp index bccd8ef..a4dfa7b 100644 --- a/Navigator/src/Navigator/Editor/SpectrumPanel.cpp +++ b/Navigator/src/Navigator/Editor/SpectrumPanel.cpp @@ -83,7 +83,7 @@ namespace Navigator { } if (ImPlot::IsPlotSelected()) { - auto& select = ImPlot::GetPlotSelection(); + auto select = ImPlot::GetPlotSelection(); if (ImGui::IsMouseClicked(ImPlot::GetInputMap().SelectCancel)) { ImPlot::CancelPlotSelection(); m_integralRegions.emplace_back(select, "integralRegion_"+std::to_string(m_nRegions), m_zoomedGram.name); @@ -92,7 +92,7 @@ namespace Navigator { } for (size_t i = 0; i < m_integralRegions.size(); i++) { - auto region = m_integralRegions[i]; + auto& region = m_integralRegions[i]; if (m_zoomedGram.name == region.histogram_name) { ImPlot::DragRect(int(i), ®ion.region.X.Min, ®ion.region.Y.Min, ®ion.region.X.Max, ®ion.region.Y.Max, ImVec4(1, 0, 1, 1)); diff --git a/Navigator/src/Navigator/ImGui/ImGuiLayer.cpp b/Navigator/src/Navigator/ImGui/ImGuiLayer.cpp index d9d5019..d926695 100644 --- a/Navigator/src/Navigator/ImGui/ImGuiLayer.cpp +++ b/Navigator/src/Navigator/ImGui/ImGuiLayer.cpp @@ -51,7 +51,7 @@ namespace Navigator { //io.Fonts->AddFontDefault(); ImFontConfig latin_config; - latin_config.RasterizerMultiply = 1.3; + latin_config.RasterizerMultiply = 1.3f; ImFontConfig config; config.MergeMode = true; //config.GlyphMinAdvanceX = 13.0f; // Use if you want to make the icon monospaced diff --git a/Navigator/src/Navigator/Physics/AnalysisStage.h b/Navigator/src/Navigator/Physics/AnalysisStage.h index 3021609..16bdfa7 100644 --- a/Navigator/src/Navigator/Physics/AnalysisStage.h +++ b/Navigator/src/Navigator/Physics/AnalysisStage.h @@ -3,19 +3,17 @@ #include "Navigator/NavCore.h" #include "Navigator/ParameterMap.h" -#include "CompassHit.h" +#include "NavData.h" namespace Navigator { class NAV_API AnalysisStage { public: - using RawPhysicsEvent = std::vector; - AnalysisStage(const std::string& name="AnalysisStage"); virtual ~AnalysisStage(); - virtual void AnalyzeRawPhysicsEvent(const RawPhysicsEvent& event) {}; + virtual void AnalyzePhysicsEvent(const NavEvent& event) {}; inline std::string GetName() { return m_name; } private: diff --git a/Navigator/src/Navigator/Physics/CompassFile.cpp b/Navigator/src/Navigator/Physics/Caen/CompassFile.cpp similarity index 100% rename from Navigator/src/Navigator/Physics/CompassFile.cpp rename to Navigator/src/Navigator/Physics/Caen/CompassFile.cpp diff --git a/Navigator/src/Navigator/Physics/CompassFile.h b/Navigator/src/Navigator/Physics/Caen/CompassFile.h similarity index 98% rename from Navigator/src/Navigator/Physics/CompassFile.h rename to Navigator/src/Navigator/Physics/Caen/CompassFile.h index 34484d3..0912547 100644 --- a/Navigator/src/Navigator/Physics/CompassFile.h +++ b/Navigator/src/Navigator/Physics/Caen/CompassFile.h @@ -13,7 +13,7 @@ #include "Navigator/NavCore.h" #include "CompassHit.h" -#include "ShiftMap.h" +#include "Navigator/Physics/ShiftMap.h" namespace Navigator { diff --git a/Navigator/src/Navigator/Physics/CompassHit.h b/Navigator/src/Navigator/Physics/Caen/CompassHit.h similarity index 100% rename from Navigator/src/Navigator/Physics/CompassHit.h rename to Navigator/src/Navigator/Physics/Caen/CompassHit.h diff --git a/Navigator/src/Navigator/Physics/CompassOnlineSource.cpp b/Navigator/src/Navigator/Physics/Caen/CompassOnlineSource.cpp similarity index 86% rename from Navigator/src/Navigator/Physics/CompassOnlineSource.cpp rename to Navigator/src/Navigator/Physics/Caen/CompassOnlineSource.cpp index 7ffdc94..bbfae59 100644 --- a/Navigator/src/Navigator/Physics/CompassOnlineSource.cpp +++ b/Navigator/src/Navigator/Physics/Caen/CompassOnlineSource.cpp @@ -30,13 +30,13 @@ namespace Navigator { m_validFlag = true; } - const CompassHit& CompassOnlineSource::GetData() + const NavData& CompassOnlineSource::GetData() { if (!IsValid()) { NAV_ERROR("Attempting to access invalid source at CompassOnlineSource!"); - m_currentHit = CompassHit(); - return m_currentHit; + m_datum = NavData(); + return m_datum; } else if (m_bufferIter == nullptr || m_bufferIter == m_bufferEnd) { @@ -44,15 +44,19 @@ namespace Navigator { } if (m_bufferIter != m_bufferEnd) - { GetHit(); - return m_currentHit; - } else { - m_currentHit = CompassHit(); - return m_currentHit; + m_datum = NavData(); + return m_datum; } + + m_datum.longEnergy = m_currentHit.lgate; + m_datum.shortEnergy = m_currentHit.sgate; + m_datum.timestamp = m_currentHit.timestamp; + m_datum.id = m_currentHit.board * 16 + m_currentHit.channel; + + return m_datum; } void CompassOnlineSource::FillBuffer() diff --git a/Navigator/src/Navigator/Physics/CompassOnlineSource.h b/Navigator/src/Navigator/Physics/Caen/CompassOnlineSource.h similarity index 85% rename from Navigator/src/Navigator/Physics/CompassOnlineSource.h rename to Navigator/src/Navigator/Physics/Caen/CompassOnlineSource.h index 584145b..bb018ff 100644 --- a/Navigator/src/Navigator/Physics/CompassOnlineSource.h +++ b/Navigator/src/Navigator/Physics/Caen/CompassOnlineSource.h @@ -1,7 +1,8 @@ #ifndef COMPASS_ONLINE_SOURCE_H #define COMPASS_ONLINE_SOURCE_H -#include "DataSource.h" +#include "Navigator/Physics/DataSource.h" +#include "CompassHit.h" #include "asio.hpp" namespace Navigator { @@ -12,7 +13,7 @@ namespace Navigator { CompassOnlineSource(const std::string& hostname, const std::string& port); virtual ~CompassOnlineSource() override; - virtual const CompassHit& GetData() override; + virtual const NavData& GetData() override; private: void InitSocket(const std::string& hostname, const std::string& port); diff --git a/Navigator/src/Navigator/Physics/CompassRun.cpp b/Navigator/src/Navigator/Physics/Caen/CompassRun.cpp similarity index 91% rename from Navigator/src/Navigator/Physics/CompassRun.cpp rename to Navigator/src/Navigator/Physics/Caen/CompassRun.cpp index 2393a2b..61b10fc 100644 --- a/Navigator/src/Navigator/Physics/CompassRun.cpp +++ b/Navigator/src/Navigator/Physics/Caen/CompassRun.cpp @@ -73,6 +73,7 @@ namespace Navigator { m_validFlag = true; } } + /* GetHitsFromFiles() is the function which actually retrieves and sorts the data from the individual files. There are several tricks which allow this to happen. First is that, after sorting, it is impossible @@ -114,22 +115,29 @@ namespace Navigator { return true; } - const CompassHit& CompassRun::GetData() + const NavData& CompassRun::GetData() { if(!IsValid()) { NAV_ERROR("Trying to access CompassRun data when invalid, bug detected!"); - m_hit = CompassHit(); - return m_hit; + m_datum = NavData(); + return m_datum; } - if(GetHitsFromFiles()) - return m_hit; - else + if (!GetHitsFromFiles()) { m_validFlag = false; - return m_hit; + m_datum = NavData(); } + else + { + m_datum.longEnergy = m_hit.lgate; + m_datum.shortEnergy = m_hit.sgate; + m_datum.timestamp = m_hit.timestamp; + m_datum.id = m_hit.board * 16 + m_hit.channel; + } + + return m_datum; } } \ No newline at end of file diff --git a/Navigator/src/Navigator/Physics/CompassRun.h b/Navigator/src/Navigator/Physics/Caen/CompassRun.h similarity index 90% rename from Navigator/src/Navigator/Physics/CompassRun.h rename to Navigator/src/Navigator/Physics/Caen/CompassRun.h index 4738f1b..4e08753 100644 --- a/Navigator/src/Navigator/Physics/CompassRun.h +++ b/Navigator/src/Navigator/Physics/Caen/CompassRun.h @@ -11,9 +11,9 @@ #define COMPASSRUN_H #include "Navigator/NavCore.h" -#include "DataSource.h" +#include "Navigator/Physics/DataSource.h" #include "CompassFile.h" -#include "ShiftMap.h" +#include "Navigator/Physics/ShiftMap.h" #include namespace Navigator { @@ -25,7 +25,7 @@ namespace Navigator { CompassRun(); CompassRun(const std::string& dir); virtual ~CompassRun(); - virtual const CompassHit& GetData() override; + virtual const NavData& GetData() override; inline void SetDirectory(const std::string& dir) { m_directory = dir; CollectFiles(); } inline void SetShiftMap(const std::string& filename) { m_smap.SetFile(filename); } @@ -36,8 +36,10 @@ namespace Navigator { std::filesystem::path m_directory; const std::string m_extension = ".bin"; + std::vector m_datafiles; unsigned int startIndex; //this is the file we start looking at; increases as we finish files. + ShiftMap m_smap; CompassHit m_hit; diff --git a/Navigator/src/Navigator/Physics/DataSource.cpp b/Navigator/src/Navigator/Physics/DataSource.cpp index 6e76c06..39a2705 100644 --- a/Navigator/src/Navigator/Physics/DataSource.cpp +++ b/Navigator/src/Navigator/Physics/DataSource.cpp @@ -1,6 +1,6 @@ #include "DataSource.h" -#include "CompassRun.h" -#include "CompassOnlineSource.h" +#include "Caen/CompassRun.h" +#include "Caen/CompassOnlineSource.h" namespace Navigator { diff --git a/Navigator/src/Navigator/Physics/DataSource.h b/Navigator/src/Navigator/Physics/DataSource.h index 68cb39d..58a9e75 100644 --- a/Navigator/src/Navigator/Physics/DataSource.h +++ b/Navigator/src/Navigator/Physics/DataSource.h @@ -2,10 +2,10 @@ #define DATA_SOURCE_H #include "Navigator/NavCore.h" -#include "CompassHit.h" +#include "NavData.h" namespace Navigator { - + class NAV_API DataSource { public: @@ -22,11 +22,12 @@ namespace Navigator { } virtual ~DataSource() {}; - virtual const CompassHit& GetData() = 0; + virtual const NavData& GetData() = 0; inline bool IsValid() { return m_validFlag; } protected: bool m_validFlag; + NavData m_datum; }; NAV_API DataSource* CreateDataSource(const std::string& loc, const std::string& port, DataSource::SourceType type); diff --git a/Navigator/src/Navigator/Physics/NavData.h b/Navigator/src/Navigator/Physics/NavData.h new file mode 100644 index 0000000..0f3758f --- /dev/null +++ b/Navigator/src/Navigator/Physics/NavData.h @@ -0,0 +1,18 @@ +#ifndef NAVDATA_H +#define NAVDATA_H + +namespace Navigator { + + struct NavData + { + uint32_t longEnergy; + uint32_t shortEnergy; + uint64_t timestamp; + uint32_t id; + }; + + using NavEvent = std::vector; + +} + +#endif \ No newline at end of file diff --git a/Navigator/src/Navigator/Physics/PhysicsEventBuilder.cpp b/Navigator/src/Navigator/Physics/PhysicsEventBuilder.cpp new file mode 100644 index 0000000..459956e --- /dev/null +++ b/Navigator/src/Navigator/Physics/PhysicsEventBuilder.cpp @@ -0,0 +1,42 @@ +#include "PhysicsEventBuilder.h" + +namespace Navigator { + + PhysicsEventBuilder::PhysicsEventBuilder(uint64_t windowSize) : + m_coincWindow(windowSize), m_eventStartTime(0) + { + } + + PhysicsEventBuilder::~PhysicsEventBuilder() + { + } + + bool PhysicsEventBuilder::AddDatumToEvent(const NavData& datum) + { + if (m_eventStartTime == 0) + { + m_eventStartTime = datum.timestamp; + m_event.push_back(datum); + return false; + } + else if (datum.timestamp - m_eventStartTime < m_coincWindow) + { + m_event.push_back(datum); + return false; + } + else + { + m_readyEvent = m_event; + m_event.clear(); + m_eventStartTime = datum.timestamp; + m_event.push_back(datum); + return true; + } + } + + const NavEvent& PhysicsEventBuilder::GetReadyEvent() const + { + return m_readyEvent; + } + +} \ No newline at end of file diff --git a/Navigator/src/Navigator/Physics/PhysicsEventBuilder.h b/Navigator/src/Navigator/Physics/PhysicsEventBuilder.h new file mode 100644 index 0000000..4f94173 --- /dev/null +++ b/Navigator/src/Navigator/Physics/PhysicsEventBuilder.h @@ -0,0 +1,26 @@ +#ifndef PHYSICS_EVENT_BUILDER_H +#define PHYSICS_EVENT_BUILDER_H + +#include "NavData.h" + +namespace Navigator { + + class NAV_API PhysicsEventBuilder + { + public: + PhysicsEventBuilder(uint64_t windowSize); + ~PhysicsEventBuilder(); + inline void SetCoincidenceWindow(uint64_t windowSize) { m_coincWindow = windowSize; } + bool AddDatumToEvent(const NavData& datum); + const NavEvent& GetReadyEvent() const; + + private: + NavEvent m_event; + NavEvent m_readyEvent; + uint64_t m_coincWindow; + uint64_t m_eventStartTime; + }; + +} + +#endif \ No newline at end of file diff --git a/Navigator/src/Navigator/Physics/PhysicsHitSort.cpp b/Navigator/src/Navigator/Physics/PhysicsHitSort.cpp deleted file mode 100644 index 833f963..0000000 --- a/Navigator/src/Navigator/Physics/PhysicsHitSort.cpp +++ /dev/null @@ -1,31 +0,0 @@ -#include "PhysicsHitSort.h" - -namespace Navigator { - - PhysicsHitSort::PhysicsHitSort(uint64_t window) : - m_coincidenceWindow(window), m_startTime(0) - { - } - - PhysicsHitSort::~PhysicsHitSort() {} - - - bool PhysicsHitSort::IsHitInWindow(const CompassHit& hit) - { - if(m_startTime == 0) - return true; - else if( (hit.timestamp - m_startTime) < m_coincidenceWindow) - return true; - else - return false; - } - - void PhysicsHitSort::AddHit(const CompassHit& hit) - { - if(m_event.size() == 0) - m_startTime = hit.timestamp; - - m_event.emplace_back(hit); - } - -} \ No newline at end of file diff --git a/Navigator/src/Navigator/Physics/PhysicsHitSort.h b/Navigator/src/Navigator/Physics/PhysicsHitSort.h deleted file mode 100644 index d50f872..0000000 --- a/Navigator/src/Navigator/Physics/PhysicsHitSort.h +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef PHYSICS_HIT_SORT_H -#define PHYSICS_HIT_SORT_H - -#include "Navigator/NavCore.h" -#include "CompassHit.h" - -namespace Navigator { - - class NAV_API PhysicsHitSort - { - public: - using RawPhysicsEvent = std::vector; - - PhysicsHitSort(uint64_t window=1500000); - ~PhysicsHitSort(); - - bool IsHitInWindow(const CompassHit& hit); - void AddHit(const CompassHit& hit); - - inline void ClearRawPhysicsEvent() { m_event.clear(); } - inline RawPhysicsEvent GetRawPhysicsEvent() { m_startTime = 0; return m_event; } - - inline void SetCoincidenceWindow(uint64_t window) { m_coincidenceWindow = window; } - - private: - RawPhysicsEvent m_event; - uint64_t m_coincidenceWindow; - uint64_t m_startTime; - }; - -} - -#endif \ No newline at end of file diff --git a/Navigator/src/Navigator/Physics/PhysicsLayer.cpp b/Navigator/src/Navigator/Physics/PhysicsLayer.cpp index 2f0de82..8f21dcc 100644 --- a/Navigator/src/Navigator/Physics/PhysicsLayer.cpp +++ b/Navigator/src/Navigator/Physics/PhysicsLayer.cpp @@ -2,12 +2,12 @@ #include "Navigator/ParameterMap.h" //temp -#include "CompassHit.h" +#include "NavData.h" namespace Navigator { PhysicsLayer::PhysicsLayer() : - m_activeFlag(false), m_source(nullptr), m_physThread(nullptr) + m_activeFlag(false), m_source(nullptr), m_eventBuilder(0), m_physThread(nullptr) { } @@ -94,8 +94,8 @@ namespace Navigator { void PhysicsLayer::AttachDataSource(PhysicsStartEvent& event) { std::lock_guard guard(m_sourceMutex); - m_rawSort.SetCoincidenceWindow(event.GetCoincidenceWindow()); m_source.reset(CreateDataSource(event.GetSourceLocation(), event.GetSourcePort(), event.GetSourceType())); + m_eventBuilder.SetCoincidenceWindow(event.GetCoincidenceWindow()); if (m_source->IsValid()) { NAV_INFO("Attach successful. Enabling data pull..."); @@ -121,8 +121,8 @@ namespace Navigator { { HistogramMap& histMap = HistogramMap::GetInstance(); - CompassHit hit; - + NavEvent event; + NavData datum; while(m_activeFlag) { { @@ -137,7 +137,7 @@ namespace Navigator { Looks funny, but two conditions lead to !IsValid(). Either source prev. shutdown, OR we reached end of source, indicated after prev. data grab */ - hit = m_source->GetData(); + datum = m_source->GetData(); if(!m_source->IsValid()) { NAV_INFO("End of data source."); @@ -145,26 +145,19 @@ namespace Navigator { return; } } + //NAV_INFO("Doing a physics"); - if(m_rawSort.IsHitInWindow(hit)) + + if (m_eventBuilder.AddDatumToEvent(datum)) { - //NAV_INFO("Adding hit to event with timestamp {0}", hit.timestamp); - m_rawSort.AddHit(hit); - } - else - { - //NAV_INFO("Obtaining built event..."); - auto event = m_rawSort.GetRawPhysicsEvent(); + event = m_eventBuilder.GetReadyEvent(); //NAV_INFO("Built event size: {0}", event.size()); for (auto& stage : m_physStack) - stage->AnalyzeRawPhysicsEvent(event); + stage->AnalyzePhysicsEvent(event); + histMap.UpdateHistograms(); - //Cleanup to be ready for next event ParameterMap::GetInstance().InvalidateParameters(); - m_rawSort.ClearRawPhysicsEvent(); - //Need to add hit in hand, start new event - m_rawSort.AddHit(hit); } } } diff --git a/Navigator/src/Navigator/Physics/PhysicsLayer.h b/Navigator/src/Navigator/Physics/PhysicsLayer.h index d4f3ff8..37c753d 100644 --- a/Navigator/src/Navigator/Physics/PhysicsLayer.h +++ b/Navigator/src/Navigator/Physics/PhysicsLayer.h @@ -1,5 +1,5 @@ -#ifndef PHYSICS_EVENT_BUILDER_H -#define PHYSICS_EVENT_BUILDER_H +#ifndef PHYSICS_LAYER_H +#define PHYSICS_LAYER_H #include "Navigator/NavCore.h" #include "Navigator/HistogramMap.h" @@ -7,8 +7,8 @@ #include "Navigator/Events/PhysicsEvent.h" #include "AnalysisStack.h" #include "AnalysisStage.h" -#include "PhysicsHitSort.h" #include "DataSource.h" +#include "PhysicsEventBuilder.h" #include #include @@ -42,11 +42,11 @@ namespace Navigator { AnalysisStack m_physStack; std::atomic m_activeFlag; - PhysicsHitSort m_rawSort; std::mutex m_sourceMutex; std::unique_ptr m_source; + PhysicsEventBuilder m_eventBuilder; std::thread* m_physThread;