1
0
Fork 0
mirror of https://github.com/gwm17/Specter.git synced 2024-11-22 18:28:52 -05:00

Major overhaul of the Physics side. Isolate CAEN classes, create NavData. Re-name HitSort to PhysicsEventBuilder.

This commit is contained in:
Gordon McCann 2022-02-19 11:30:46 -05:00
parent e9700170e7
commit 6dd5f7f1c6
19 changed files with 149 additions and 120 deletions

View File

@ -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), &region.region.X.Min, &region.region.Y.Min, &region.region.X.Max, &region.region.Y.Max, ImVec4(1, 0, 1, 1));

View File

@ -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

View File

@ -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<CompassHit>;
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:

View File

@ -13,7 +13,7 @@
#include "Navigator/NavCore.h"
#include "CompassHit.h"
#include "ShiftMap.h"
#include "Navigator/Physics/ShiftMap.h"
namespace Navigator {

View File

@ -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()

View File

@ -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);

View File

@ -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;
}
}

View File

@ -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 <filesystem>
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<CompassFile> m_datafiles;
unsigned int startIndex; //this is the file we start looking at; increases as we finish files.
ShiftMap m_smap;
CompassHit m_hit;

View File

@ -1,6 +1,6 @@
#include "DataSource.h"
#include "CompassRun.h"
#include "CompassOnlineSource.h"
#include "Caen/CompassRun.h"
#include "Caen/CompassOnlineSource.h"
namespace Navigator {

View File

@ -2,7 +2,7 @@
#define DATA_SOURCE_H
#include "Navigator/NavCore.h"
#include "CompassHit.h"
#include "NavData.h"
namespace Navigator {
@ -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);

View File

@ -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<NavData>;
}
#endif

View File

@ -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;
}
}

View File

@ -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

View File

@ -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);
}
}

View File

@ -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<CompassHit>;
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

View File

@ -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<std::mutex> 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);
histMap.UpdateHistograms();
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);
}
}
}

View File

@ -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 <thread>
#include <mutex>
@ -42,11 +42,11 @@ namespace Navigator {
AnalysisStack m_physStack;
std::atomic<bool> m_activeFlag;
PhysicsHitSort m_rawSort;
std::mutex m_sourceMutex;
std::unique_ptr<DataSource> m_source;
PhysicsEventBuilder m_eventBuilder;
std::thread* m_physThread;