mirror of
https://github.com/gwm17/Specter.git
synced 2025-01-31 02:38:50 -05:00
Added new cut types, CutSummaryAll and CutSummaryAny for use with HistogramSummary. Tested for creation, drawing, and serialization. Needs testing for cut functionality.
This commit is contained in:
parent
ac074f99c4
commit
51d6782755
|
@ -19,6 +19,19 @@
|
||||||
|
|
||||||
namespace Navigator {
|
namespace Navigator {
|
||||||
|
|
||||||
|
std::string ConvertCutTypeToString(CutType type)
|
||||||
|
{
|
||||||
|
switch(type)
|
||||||
|
{
|
||||||
|
case CutType::Cut1D: return "Cut1D";
|
||||||
|
case CutType::Cut2D: return "Cut2D";
|
||||||
|
case CutType::CutSummaryAll: return "CutSummaryAll";
|
||||||
|
case CutType::CutSummaryAny: return "CutSummaryAny";
|
||||||
|
case CutType::None: return "None";
|
||||||
|
}
|
||||||
|
return "None";
|
||||||
|
}
|
||||||
|
|
||||||
/*1D Cuts -- Can be made on and applied to either 1D or 2D histograms*/
|
/*1D Cuts -- Can be made on and applied to either 1D or 2D histograms*/
|
||||||
Cut1D::Cut1D(const CutArgs& params, double min, double max) :
|
Cut1D::Cut1D(const CutArgs& params, double min, double max) :
|
||||||
Cut(params), m_minVal(min), m_maxVal(max)
|
Cut(params), m_minVal(min), m_maxVal(max)
|
||||||
|
@ -89,4 +102,25 @@ namespace Navigator {
|
||||||
ImPlot::PlotLine(m_params.name.c_str(), m_xpoints.data(), m_ypoints.data(), (int)m_xpoints.size());
|
ImPlot::PlotLine(m_params.name.c_str(), m_xpoints.data(), m_ypoints.data(), (int)m_xpoints.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*CutSummaryAll -- Can only be made on a HistogramSummary but can be applied to any*/
|
||||||
|
CutSummary::CutSummary(const CutArgs& params, const std::vector<std::string>& subhistos, double min, double max) :
|
||||||
|
Cut(params), m_subhistos(subhistos), m_minVal(min), m_maxVal(max)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
CutSummary::~CutSummary()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void CutSummary::IsInside(double x, double y)
|
||||||
|
{
|
||||||
|
m_isValid = x >= m_minVal && x <= m_maxVal;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Only within an ImPlot/ImGui context!!!
|
||||||
|
void CutSummary::Draw() const
|
||||||
|
{
|
||||||
|
double points[2] = { m_minVal, m_maxVal };
|
||||||
|
ImPlot::PlotVLines(m_params.name.c_str(), points, 2);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,9 +26,13 @@ namespace Navigator {
|
||||||
{
|
{
|
||||||
Cut1D,
|
Cut1D,
|
||||||
Cut2D,
|
Cut2D,
|
||||||
|
CutSummaryAny,
|
||||||
|
CutSummaryAll,
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
|
|
||||||
|
std::string ConvertCutTypeToString(CutType type);
|
||||||
|
|
||||||
struct NAV_API CutArgs
|
struct NAV_API CutArgs
|
||||||
{
|
{
|
||||||
CutArgs() {}
|
CutArgs() {}
|
||||||
|
@ -99,6 +103,24 @@ namespace Navigator {
|
||||||
std::vector<double> m_xpoints;
|
std::vector<double> m_xpoints;
|
||||||
std::vector<double> m_ypoints;
|
std::vector<double> m_ypoints;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class NAV_API CutSummary : public Cut
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
CutSummary(const CutArgs& params, const std::vector<std::string>& subhistos, double min, double max);
|
||||||
|
virtual ~CutSummary();
|
||||||
|
virtual void IsInside(double x, double y) override;
|
||||||
|
virtual void Draw() const override;
|
||||||
|
virtual std::vector<double> GetXValues() const override { return std::vector<double>({ m_minVal, m_maxVal }); }
|
||||||
|
virtual std::vector<double> GetYValues() const override { return std::vector<double>(); }
|
||||||
|
|
||||||
|
inline const std::vector<std::string>& GetSubHistograms() const { return m_subhistos; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
double m_minVal, m_maxVal;
|
||||||
|
std::vector<std::string> m_subhistos;
|
||||||
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -345,6 +345,18 @@ namespace Navigator {
|
||||||
return null_result;
|
return null_result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<std::string> SpectrumManager::GetCutSubHistograms(const std::string& cutname)
|
||||||
|
{
|
||||||
|
std::lock_guard<std::mutex> guard(m_managerMutex);
|
||||||
|
auto iter = m_cutMap.find(cutname);
|
||||||
|
if (iter != m_cutMap.end() && iter->second->GetType() == CutType::CutSummaryAny || iter->second->GetType() == CutType::CutSummaryAll)
|
||||||
|
{
|
||||||
|
auto cut = std::static_pointer_cast<CutSummary>(iter->second);
|
||||||
|
return cut->GetSubHistograms();
|
||||||
|
}
|
||||||
|
return std::vector<std::string>();
|
||||||
|
}
|
||||||
|
|
||||||
//Similar to GetListOfHistograms, see that documentation
|
//Similar to GetListOfHistograms, see that documentation
|
||||||
std::vector<CutArgs> SpectrumManager::GetListOfCuts()
|
std::vector<CutArgs> SpectrumManager::GetListOfCuts()
|
||||||
{
|
{
|
||||||
|
@ -419,6 +431,36 @@ namespace Navigator {
|
||||||
iter.second->IsInside(iterX->second->value, iterY->second->value);
|
iter.second->IsInside(iterX->second->value, iterY->second->value);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case CutType::CutSummaryAll:
|
||||||
|
{
|
||||||
|
std::vector<std::string> paramlist = std::static_pointer_cast<CutSummary>(iter.second)->GetSubHistograms();
|
||||||
|
for (auto& param : paramlist)
|
||||||
|
{
|
||||||
|
auto iterX = m_paramMap.find(param);
|
||||||
|
if (iterX != m_paramMap.end() && iterX->second->validFlag)
|
||||||
|
{
|
||||||
|
iter.second->IsInside(iterX->second->value);
|
||||||
|
if (!iter.second->IsValid())
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case CutType::CutSummaryAny:
|
||||||
|
{
|
||||||
|
std::vector<std::string> paramlist = std::static_pointer_cast<CutSummary>(iter.second)->GetSubHistograms();
|
||||||
|
for (auto& param : paramlist)
|
||||||
|
{
|
||||||
|
auto iterX = m_paramMap.find(param);
|
||||||
|
if (iterX != m_paramMap.end() && iterX->second->validFlag)
|
||||||
|
{
|
||||||
|
iter.second->IsInside(iterX->second->value);
|
||||||
|
if (iter.second->IsValid())
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
case CutType::None:
|
case CutType::None:
|
||||||
{
|
{
|
||||||
NAV_WARN("Found a cut with None type!");
|
NAV_WARN("Found a cut with None type!");
|
||||||
|
|
|
@ -78,9 +78,15 @@ namespace Navigator {
|
||||||
std::lock_guard<std::mutex> guard(m_managerMutex);
|
std::lock_guard<std::mutex> guard(m_managerMutex);
|
||||||
m_cutMap[params.name].reset(new Cut2D(params, xpoints, ypoints));
|
m_cutMap[params.name].reset(new Cut2D(params, xpoints, ypoints));
|
||||||
}
|
}
|
||||||
|
inline void AddCut(const CutArgs& params, const std::vector<std::string>& subhistos, double min, double max)
|
||||||
|
{
|
||||||
|
std::lock_guard<std::mutex> guard(m_managerMutex);
|
||||||
|
m_cutMap[params.name].reset(new CutSummary(params, subhistos, min, max));
|
||||||
|
}
|
||||||
void RemoveCut(const std::string& name);
|
void RemoveCut(const std::string& name);
|
||||||
std::vector<double> GetCutXPoints(const std::string& name);
|
std::vector<double> GetCutXPoints(const std::string& name);
|
||||||
std::vector<double> GetCutYPoints(const std::string& name);
|
std::vector<double> GetCutYPoints(const std::string& name);
|
||||||
|
std::vector<std::string> GetCutSubHistograms(const std::string& cutname);
|
||||||
std::vector<CutArgs> GetListOfCuts();
|
std::vector<CutArgs> GetListOfCuts();
|
||||||
/**************/
|
/**************/
|
||||||
|
|
||||||
|
|
|
@ -71,6 +71,38 @@ namespace Navigator {
|
||||||
output << "\t\tend_yvalues" << std::endl;
|
output << "\t\tend_yvalues" << std::endl;
|
||||||
output << "\tend_cut2D" << std::endl;
|
output << "\tend_cut2D" << std::endl;
|
||||||
}
|
}
|
||||||
|
else if (cut.type == CutType::CutSummaryAll)
|
||||||
|
{
|
||||||
|
std::vector<std::string> subhistos = manager.GetCutSubHistograms(cut.name);
|
||||||
|
std::vector<double> xpoints = manager.GetCutXPoints(cut.name);
|
||||||
|
output << "\tbegin_cutSummaryAll" << std::endl;
|
||||||
|
output << "\t\tname: " << cut.name << std::endl;
|
||||||
|
output << "\t\tminValue: " << xpoints[0] << std::endl;
|
||||||
|
output << "\t\tmaxValue: " << xpoints[1] << std::endl;
|
||||||
|
output << "\t\tbegin_parameters" << std::endl;
|
||||||
|
for (auto& par : subhistos)
|
||||||
|
{
|
||||||
|
output << "\t\t\t" << par << std::endl;
|
||||||
|
}
|
||||||
|
output << "\t\tend_parameters" << std::endl;
|
||||||
|
output << "\tend_cutSummaryAll" << std::endl;
|
||||||
|
}
|
||||||
|
else if (cut.type == CutType::CutSummaryAny)
|
||||||
|
{
|
||||||
|
std::vector<std::string> subhistos = manager.GetCutSubHistograms(cut.name);
|
||||||
|
std::vector<double> xpoints = manager.GetCutXPoints(cut.name);
|
||||||
|
output << "\tbegin_cutSummaryAny" << std::endl;
|
||||||
|
output << "\t\tname: " << cut.name << std::endl;
|
||||||
|
output << "\t\tminValue: " << xpoints[0] << std::endl;
|
||||||
|
output << "\t\tmaxValue: " << xpoints[1] << std::endl;
|
||||||
|
output << "\t\tbegin_parameters" << std::endl;
|
||||||
|
for (auto& par : subhistos)
|
||||||
|
{
|
||||||
|
output << "\t\t\t" << par << std::endl;
|
||||||
|
}
|
||||||
|
output << "\t\tend_parameters" << std::endl;
|
||||||
|
output << "\tend_cutSummaryAny" << std::endl;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
output << "end_cuts" << std::endl;
|
output << "end_cuts" << std::endl;
|
||||||
|
|
||||||
|
@ -189,6 +221,7 @@ namespace Navigator {
|
||||||
cut_data = reset_cut;
|
cut_data = reset_cut;
|
||||||
cut_xdata.clear();
|
cut_xdata.clear();
|
||||||
cut_ydata.clear();
|
cut_ydata.clear();
|
||||||
|
subhistos.clear();
|
||||||
if (check == "begin_cut1D")
|
if (check == "begin_cut1D")
|
||||||
{
|
{
|
||||||
cut_data.type = CutType::Cut1D;
|
cut_data.type = CutType::Cut1D;
|
||||||
|
@ -228,6 +261,46 @@ namespace Navigator {
|
||||||
input >> check;
|
input >> check;
|
||||||
manager.AddCut(cut_data, cut_xdata, cut_ydata);
|
manager.AddCut(cut_data, cut_xdata, cut_ydata);
|
||||||
}
|
}
|
||||||
|
else if (check == "begin_cutSummaryAll")
|
||||||
|
{
|
||||||
|
cut_data.type = CutType::CutSummaryAll;
|
||||||
|
input >> check >> cut_data.name;
|
||||||
|
input >> check >> value_doub;
|
||||||
|
cut_xdata.push_back(value_doub);
|
||||||
|
input >> check >> value_doub;
|
||||||
|
cut_xdata.push_back(value_doub);
|
||||||
|
while (input >> check)
|
||||||
|
{
|
||||||
|
if (check == "begin_parameters")
|
||||||
|
continue;
|
||||||
|
else if (check == "end_parameters")
|
||||||
|
break;
|
||||||
|
else
|
||||||
|
subhistos.push_back(check);
|
||||||
|
}
|
||||||
|
input >> check;
|
||||||
|
manager.AddCut(cut_data, subhistos, cut_xdata[0], cut_xdata[1]);
|
||||||
|
}
|
||||||
|
else if (check == "begin_cutSummaryAny")
|
||||||
|
{
|
||||||
|
cut_data.type = CutType::CutSummaryAny;
|
||||||
|
input >> check >> cut_data.name;
|
||||||
|
input >> check >> value_doub;
|
||||||
|
cut_xdata.push_back(value_doub);
|
||||||
|
input >> check >> value_doub;
|
||||||
|
cut_xdata.push_back(value_doub);
|
||||||
|
while (input >> check)
|
||||||
|
{
|
||||||
|
if (check == "begin_parameters")
|
||||||
|
continue;
|
||||||
|
else if (check == "end_parameters")
|
||||||
|
break;
|
||||||
|
else
|
||||||
|
subhistos.push_back(check);
|
||||||
|
}
|
||||||
|
input >> check;
|
||||||
|
manager.AddCut(cut_data, subhistos, cut_xdata[0], cut_xdata[1]);
|
||||||
|
}
|
||||||
else if (check == "end_cuts")
|
else if (check == "end_cuts")
|
||||||
break;
|
break;
|
||||||
else
|
else
|
||||||
|
|
|
@ -43,12 +43,9 @@ namespace Navigator {
|
||||||
if (histoList.size() > 0)
|
if (histoList.size() > 0)
|
||||||
{
|
{
|
||||||
if (m_zoomedFlag && m_zoomedGram.type != SpectrumType::None)
|
if (m_zoomedFlag && m_zoomedGram.type != SpectrumType::None)
|
||||||
{
|
|
||||||
if (m_zoomedGram.type == SpectrumType::Histo1D || m_zoomedGram.type == SpectrumType::Histo2D)
|
|
||||||
{
|
{
|
||||||
RenderCutButton();
|
RenderCutButton();
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
}
|
|
||||||
if(ImGui::Button("Clear"))
|
if(ImGui::Button("Clear"))
|
||||||
{
|
{
|
||||||
SpectrumManager::GetInstance().ClearHistogram(m_zoomedGram.name);
|
SpectrumManager::GetInstance().ClearHistogram(m_zoomedGram.name);
|
||||||
|
@ -203,6 +200,24 @@ namespace Navigator {
|
||||||
ImPlot::PlotLine(m_newCutArgs.name.c_str(), m_newCutX.data(), m_newCutY.data(), int(m_newCutX.size()));
|
ImPlot::PlotLine(m_newCutArgs.name.c_str(), m_newCutX.data(), m_newCutY.data(), int(m_newCutX.size()));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case SpectrumType::Summary:
|
||||||
|
{
|
||||||
|
if (m_newCutX.size() == 2)
|
||||||
|
{
|
||||||
|
m_acceptCutFlag = true;
|
||||||
|
}
|
||||||
|
else if (ImPlot::IsPlotHovered() && ImGui::IsMouseClicked(ImGuiMouseButton_Left))
|
||||||
|
{
|
||||||
|
m_newCutX.push_back(ImPlot::GetPlotMousePos().x);
|
||||||
|
}
|
||||||
|
ImPlot::PlotVLines(m_newCutArgs.name.c_str(), m_newCutX.data(), int(m_newCutX.size()));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case SpectrumType::None:
|
||||||
|
{
|
||||||
|
m_cutModeFlag = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -219,16 +234,44 @@ namespace Navigator {
|
||||||
ImGui::Text("Save this Cut?");
|
ImGui::Text("Save this Cut?");
|
||||||
if (ImGui::Button("Yes"))
|
if (ImGui::Button("Yes"))
|
||||||
{
|
{
|
||||||
if (m_newCutArgs.y_par == "None")
|
SpectrumManager& manager = SpectrumManager::GetInstance();
|
||||||
|
switch (m_newCutArgs.type)
|
||||||
|
{
|
||||||
|
case CutType::Cut1D:
|
||||||
{
|
{
|
||||||
std::sort(m_newCutX.begin(), m_newCutX.end());
|
std::sort(m_newCutX.begin(), m_newCutX.end());
|
||||||
SpectrumManager::GetInstance().AddCut(m_newCutArgs, m_newCutX[0], m_newCutX[1]);
|
manager.AddCut(m_newCutArgs, m_newCutX[0], m_newCutX[1]);
|
||||||
|
manager.AddCutToHistogramDraw(m_newCutArgs.name, m_zoomedGram.name);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
else
|
case CutType::Cut2D:
|
||||||
{
|
{
|
||||||
SpectrumManager::GetInstance().AddCut(m_newCutArgs, m_newCutX, m_newCutY);
|
manager.AddCut(m_newCutArgs, m_newCutX, m_newCutY);
|
||||||
|
manager.AddCutToHistogramDraw(m_newCutArgs.name, m_zoomedGram.name);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case CutType::CutSummaryAny:
|
||||||
|
{
|
||||||
|
std::sort(m_newCutX.begin(), m_newCutX.end());
|
||||||
|
std::vector<std::string> subhistos = manager.GetSubHistograms(m_zoomedGram.name);
|
||||||
|
manager.AddCut(m_newCutArgs, subhistos, m_newCutX[0], m_newCutX[1]);
|
||||||
|
manager.AddCutToHistogramDraw(m_newCutArgs.name, m_zoomedGram.name);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case CutType::CutSummaryAll:
|
||||||
|
{
|
||||||
|
std::sort(m_newCutX.begin(), m_newCutX.end());
|
||||||
|
std::vector<std::string> subhistos = manager.GetSubHistograms(m_zoomedGram.name);
|
||||||
|
manager.AddCut(m_newCutArgs, subhistos, m_newCutX[0], m_newCutX[1]);
|
||||||
|
manager.AddCutToHistogramDraw(m_newCutArgs.name, m_zoomedGram.name);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case CutType::None:
|
||||||
|
{
|
||||||
|
NAV_ERROR("Trying to add None type cut to manager at SpectrumPanel::RenderAcceptCutDialog!");
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
SpectrumManager::GetInstance().AddCutToHistogramDraw(m_newCutArgs.name, m_zoomedGram.name);
|
|
||||||
ImGui::CloseCurrentPopup();
|
ImGui::CloseCurrentPopup();
|
||||||
m_result = true;
|
m_result = true;
|
||||||
}
|
}
|
||||||
|
@ -271,8 +314,16 @@ namespace Navigator {
|
||||||
ImGui::BulletText("%s", ("Y Parameter: " + m_newCutArgs.y_par).c_str());
|
ImGui::BulletText("%s", ("Y Parameter: " + m_newCutArgs.y_par).c_str());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case SpectrumType::Summary:
|
||||||
|
{
|
||||||
|
if (ImGui::RadioButton("CutSummaryAny", m_newCutArgs.type == CutType::CutSummaryAny))
|
||||||
|
m_newCutArgs.type = CutType::CutSummaryAny;
|
||||||
|
ImGui::SameLine();
|
||||||
|
if (ImGui::RadioButton("CutSummaryAll", m_newCutArgs.type == CutType::CutSummaryAll))
|
||||||
|
m_newCutArgs.type = CutType::CutSummaryAll;
|
||||||
|
break;
|
||||||
|
}
|
||||||
case SpectrumType::None: m_newCutArgs.type = CutType::None; break;
|
case SpectrumType::None: m_newCutArgs.type = CutType::None; break;
|
||||||
case SpectrumType::Summary: m_newCutArgs.type = CutType::None; break;
|
|
||||||
}
|
}
|
||||||
ImGui::InputText("Cut Name", &m_newCutArgs.name);
|
ImGui::InputText("Cut Name", &m_newCutArgs.name);
|
||||||
if (ImGui::Button("Accept & Draw"))
|
if (ImGui::Button("Accept & Draw"))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user