1
0
Fork 0
mirror of https://github.com/gwm17/Specter.git synced 2025-01-30 18:28:51 -05:00

Small bugfixes from recent testing. Fix some naming in Parameter.h/cpp

This commit is contained in:
Gordon McCann 2022-06-06 21:02:48 -04:00
parent 2f92379804
commit afd17b780d
11 changed files with 66 additions and 64 deletions

View File

@ -18,24 +18,24 @@ namespace Navigator {
private:
//Create a bunch of parameters
NavParameter delayFLTime;
NavParameter delayFRTime;
NavParameter delayBLTime;
NavParameter delayBRTime;
NavParameter x1;
NavParameter x2;
NavParameter xavg;
NavParameter scintLeft;
NavParameter anodeBack;
NavParameter anodeFront;
NavParameter cathode;
NavParameter xavg_sabreCoinc;
Parameter delayFLTime;
Parameter delayFRTime;
Parameter delayBLTime;
Parameter delayBRTime;
Parameter x1;
Parameter x2;
Parameter xavg;
Parameter scintLeft;
Parameter anodeBack;
Parameter anodeFront;
Parameter cathode;
Parameter xavg_sabreCoinc;
std::vector<NavParameter> sabre;
std::vector<Parameter> sabre;
//Create a few variables
NavVariable x1_weight;
NavVariable x2_weight;
Variable x1_weight;
Variable x2_weight;
};
}

View File

@ -35,8 +35,8 @@ namespace Navigator {
void UpdateWeights();
//Variables for use in analysis
NavVariable x1_weight;
NavVariable x2_weight;
Variable x1_weight;
Variable x2_weight;
//UI facing inputs
double m_bfield; //kG

View File

@ -1,18 +1,18 @@
/*
Parameter.cpp
Contains two data related structures, ParameterData and NavParameter. Parameter here refers to a value which
Contains two data related structures, ParameterData and Parameter. Parameter here refers to a value which
can be associated with the axis of a histogram. ParameterData is a two component struct which represents the state of a single parameter, which is stored
in the global SpectrumManager (see SpectrumManager documentation). NavParameter is an access point class for use within analysis. It provides scoped access to
in the global SpectrumManager (see SpectrumManager documentation). Parameter is an access point class for use within analysis. It provides scoped access to
the managed data. There are several important caveats to using the parameters this way, which is mostly related to synchronization:
- NavParameter contains no guarantee of thread safety. THIS IS BY DESIGN. NavParameters should only be created within the context of an AnalysisStage (see AnalysisStage documentation).
- Parameter contains no guarantee of thread safety. THIS IS BY DESIGN. Parameters should only be created within the context of an AnalysisStage (see AnalysisStage documentation).
As long as this is true, there is no risk of accessing parameter data outside of the physics thread, and that thread explicitly handles calculation of parameters
and updating of histograms. DO NOT make a NavParameter outside of the AnalysisStage context.
- NavParameters must be bound to the active SpectrumManager. This is done using the BindParameter function of the manager; NavParameters are keyed based on their name string.
If two NavParameters are made that are both named "x1", they are in fact the same parameter. In this way, values can be passed from one AnalysisStage to another. If you make a stage
called InitialStage with a NavParameter named "x1" where x1 is set to 1.0, and then have a later stage called LaterStage with another NavParameter named x1, it implicitly has the value 1.0
and updating of histograms. DO NOT make a Parameter outside of the AnalysisStage context.
- Parameters must be bound to the active SpectrumManager. This is done using the BindParameter function of the manager; Parameters are keyed based on their name string.
If two Parameters are made that are both named "x1", they are in fact the same parameter. In this way, values can be passed from one AnalysisStage to another. If you make a stage
called InitialStage with a Parameter named "x1" where x1 is set to 1.0, and then have a later stage called LaterStage with another Parameter named x1, it implicitly has the value 1.0
due to it being set in the previous stage.
- Each NavParameter has a valid flag. This is a boolean which idicates whether or not the parameter is in a valid state (the data event contianed a value for this parameter). Before using a parameter
- Each Parameter has a valid flag. This is a boolean which idicates whether or not the parameter is in a valid state (the data event contianed a value for this parameter). Before using a parameter
in a calculation one should check if the parameter is valid using the IsValid() function. When a parameter is set using the SetValue() function, the valid flag is set to true. After the event is completely
processed (all analysis stages have been run and histograms have been updated) the manager should be called to run InvalidateParameters() to set all parameters as invalid (valid flag false).
@ -26,40 +26,39 @@
namespace Navigator {
NavParameter::NavParameter() :
Parameter::Parameter() :
m_name(""), m_pdata(nullptr)
{
}
NavParameter::NavParameter(const std::string& name) :
Parameter::Parameter(const std::string& name) :
m_name(name), m_pdata(nullptr)
{
NAV_INFO("Making a new parameter named {0}...",name);
}
NavParameter::~NavParameter() {}
Parameter::~Parameter() {}
//So that you can make arrays, std::vectors of NavParameters (useful for big detector arrays)
//So that you can make arrays, std::vectors of Parameters (useful for big detector arrays)
//SpectrumManager::BindParameter() still needs to be used after this!
void NavParameter::SetName(const std::string& name)
void Parameter::SetName(const std::string& name)
{
if (m_name != "")
{
NAV_ERROR("Attempting to change the name of an already bound NavParameter! Set name: {0} New name: {1}", m_name, name);
NAV_ERROR("Attempting to change the name of an already bound Parameter! Set name: {0} New name: {1}", m_name, name);
return;
}
m_name = name;
}
NavVariable::NavVariable() :
Variable::Variable() :
m_name(""), m_pdata(nullptr)
{
}
NavVariable::NavVariable(const std::string& name) :
Variable::Variable(const std::string& name) :
m_name(name), m_pdata(nullptr)
{
}
NavVariable::~NavVariable() {}
Variable::~Variable() {}
}

View File

@ -1,18 +1,18 @@
/*
Parameter.h
Contains two data related structures, ParameterData and NavParameter. Parameter here refers to a value which
Contains two data related structures, ParameterData and Parameter. Parameter here refers to a value which
can be associated with the axis of a histogram. ParameterData is a two component struct which represents the state of a single parameter, which is stored
in the global SpectrumManager (see SpectrumManager documentation). NavParameter is an access point class for use within analysis. It provides scoped access to
in the global SpectrumManager (see SpectrumManager documentation). Parameter is an access point class for use within analysis. It provides scoped access to
the managed data. There are several important caveats to using the parameters this way, which is mostly related to synchronization:
- NavParameter contains no guarantee of thread safety. THIS IS BY DESIGN. NavParameters should only be created within the context of an AnalysisStage (see AnalysisStage documentation).
- Parameter contains no guarantee of thread safety. THIS IS BY DESIGN. Parameters should only be created within the context of an AnalysisStage (see AnalysisStage documentation).
As long as this is true, there is no risk of accessing parameter data outside of the physics thread, and that thread explicitly handles calculation of parameters
and updating of histograms. DO NOT make a NavParameter outside of the AnalysisStage context.
- NavParameters must be bound to the active SpectrumManager. This is done using the BindParameter function of the manager; NavParameters are keyed based on their name string.
If two NavParameters are made that are both named "x1", they are in fact the same parameter. In this way, values can be passed from one AnalysisStage to another. If you make a stage
called InitialStage with a NavParameter named "x1" where x1 is set to 1.0, and then have a later stage called LaterStage with another NavParameter named x1, it implicitly has the value 1.0
and updating of histograms. DO NOT make a Parameter outside of the AnalysisStage context.
- Parameters must be bound to the active SpectrumManager. This is done using the BindParameter function of the manager; Parameters are keyed based on their name string.
If two Parameters are made that are both named "x1", they are in fact the same parameter. In this way, values can be passed from one AnalysisStage to another. If you make a stage
called InitialStage with a Parameter named "x1" where x1 is set to 1.0, and then have a later stage called LaterStage with another Parameter named x1, it implicitly has the value 1.0
due to it being set in the previous stage.
- Each NavParameter has a valid flag. This is a boolean which idicates whether or not the parameter is in a valid state (the data event contianed a value for this parameter). Before using a parameter
- Each Parameter has a valid flag. This is a boolean which idicates whether or not the parameter is in a valid state (the data event contianed a value for this parameter). Before using a parameter
in a calculation one should check if the parameter is valid using the IsValid() function. When a parameter is set using the SetValue() function, the valid flag is set to true. After the event is completely
processed (all analysis stages have been run and histograms have been updated) the manager should be called to run InvalidateParameters() to set all parameters as invalid (valid flag false).
@ -37,13 +37,13 @@ namespace Navigator {
};
//Interface to parameter data
class NAV_API NavParameter
class NAV_API Parameter
{
public:
NavParameter();
NavParameter(const std::string& name);
~NavParameter();
Parameter();
Parameter(const std::string& name);
~Parameter();
inline bool IsValid() const { return m_pdata->validFlag; }
inline void Invalidate() { m_pdata->validFlag = false; }
@ -61,15 +61,15 @@ namespace Navigator {
//Similar to parameters, sometimes you want to have a numeric input (in calculation terms, a constant)
//which you can use with your analysis. To be able to expose these numeric values to the UI, we need to implement them
//in the manager. To help with this, NavVariables are atomics. So unlike NavParameters they are implicity thread safe on read and write.
//in the manager. To help with this, Variables are atomics. So unlike Parameters they are implicity thread safe on read and write.
//However, this does not mean they can be modified in the analysis! To the AnalysisStage they should be treated as constant, while the UI
//should view them as modifiable. These are real god damn dangerous, but I think the power they offer outweighs the risk, for now.
class NAV_API NavVariable
class NAV_API Variable
{
public:
NavVariable();
NavVariable(const std::string& name);
~NavVariable();
Variable();
Variable(const std::string& name);
~Variable();
inline void SetValue(double value) { *(m_pdata) = value; }
inline double GetValue() { return *(m_pdata); }

View File

@ -242,8 +242,8 @@ namespace Navigator {
/*************Parameter Functions Begin*************/
//Bind a NavParameter instance to the manager. If the Parameter doesn't exist, make a new one, otherwise attach to extant memory
void SpectrumManager::BindParameter(NavParameter& param)
//Bind a Parameter instance to the manager. If the Parameter doesn't exist, make a new one, otherwise attach to extant memory
void SpectrumManager::BindParameter(Parameter& param)
{
NAV_PROFILE_FUNCTION();
std::scoped_lock<std::mutex> guard(m_managerMutex);
@ -256,9 +256,9 @@ namespace Navigator {
param.m_pdata = m_paramMap[param.GetName()];
}
//Bind a NavParameter instance to the manager. If the Parameter doesn't exist, make a new one, otherwise attach to extant memory
//Bind a Parameter instance to the manager. If the Parameter doesn't exist, make a new one, otherwise attach to extant memory
//Additionally, make a default 1D histogram for the parameter (histogram has same name as parameter)
void SpectrumManager::BindParameter(NavParameter& param, int nbins, double minVal, double maxVal)
void SpectrumManager::BindParameter(Parameter& param, int nbins, double minVal, double maxVal)
{
NAV_PROFILE_FUNCTION();
std::scoped_lock<std::mutex> guard(m_managerMutex);
@ -308,7 +308,7 @@ namespace Navigator {
/*************Variable Functions Begin*************/
void SpectrumManager::BindVariable(NavVariable& var)
void SpectrumManager::BindVariable(Variable& var)
{
NAV_PROFILE_FUNCTION();
std::scoped_lock<std::mutex> guard(m_managerMutex);

View File

@ -56,14 +56,14 @@ namespace Navigator {
/********************/
/*Parameter Functions*/
void BindParameter(NavParameter& param);
void BindParameter(NavParameter& param, int nbins, double maxVal, double minVal);
void BindParameter(Parameter& param);
void BindParameter(Parameter& param, int nbins, double maxVal, double minVal);
void InvalidateParameters();
std::vector<std::string> GetListOfParameters();
/*********************/
/*Variable Functions*/
void BindVariable(NavVariable& var);
void BindVariable(Variable& var);
std::vector<std::string> GetListOfVariables();
/********************/

View File

@ -87,7 +87,7 @@ namespace Navigator {
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));
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), ImPlotDragToolFlags_NoFit);
StatResults results = SpectrumManager::GetInstance().AnalyzeHistogramRegion(m_zoomedGram.name, region.region);
ImPlot::PlotText(GenerateStatString(region.name, results, m_zoomedGram.y_par != "None").c_str(), (region.region.X.Max + region.region.X.Min) * 0.5,
(region.region.Y.Min + region.region.Y.Max) * 0.5);

View File

@ -72,6 +72,9 @@ namespace Navigator {
io.Fonts->AddFontFromFileTTF("Assets/fonts/Roboto-Regular.ttf", 16.0f, &latin_config, io.Fonts->GetGlyphRangesDefault());
io.Fonts->AddFontFromFileTTF("Assets/fonts/fa-solid-900.ttf", 16.0f, &config, icon_ranges);
//ImPlot styling
ImPlot::GetStyle().FillAlpha = 0.75;
Application& app = Application::Get();
GLFWwindow* window = static_cast<GLFWwindow*>(app.GetWindow().GetNativeWindow());

View File

@ -1,6 +1,6 @@
/*
AnalysisStage.h
Represents a step in a chain of analyses that are run on a NavEvent. These stages are where NavParameters are set and validated. Users should use this base class
Represents a step in a chain of analyses that are run on a NavEvent. These stages are where Parameters are set and validated. Users should use this base class
to create their own analyses and inject them into their project. See template NavProject for an example of use.
GWM -- Feb 2022

View File

@ -91,7 +91,7 @@ namespace Navigator {
m_hitsize += 2;
if (Compass_IsEnergyCalibrated(m_header))
m_hitsize += 8;
if (Compass_IsWaves)
if (Compass_IsWaves(m_header))
{
m_hitsize += 5;
char* firstHit = new char[m_hitsize]; //Read chunk of first hit

View File

@ -134,7 +134,7 @@ namespace Navigator {
}
if (Compass_IsEnergyCalibrated(m_header))
{
m_currentHit.energyCalibrated + *((uint16_t*)m_bufferIter);
m_currentHit.energyCalibrated = *((uint16_t*)m_bufferIter);
m_bufferIter += 8;
}
if (Compass_IsEnergyShort(m_header))