新增计数率分析
This commit is contained in:
parent
ec38d506fd
commit
e69629e203
|
|
@ -1,177 +0,0 @@
|
|||
#include "CountRateAnalysis.h"
|
||||
#include "ui_CountRateAnalysis.h"
|
||||
#include <QVBoxLayout>
|
||||
#include <QPushButton>
|
||||
#include <QMessageBox>
|
||||
#include <QwtPlotCurve>
|
||||
#include <QwtPlotMarker>
|
||||
#include <QwtPlotZoneItem>
|
||||
#include <QwtPlotCanvas>
|
||||
#include <QwtLegend>
|
||||
#include <QwtText>
|
||||
#include <cmath>
|
||||
#include <QtMath>
|
||||
#include "CustomQwtPlot.h"
|
||||
#include <QDebug>
|
||||
#include <GlobalDefine.h>
|
||||
|
||||
CountRateAnalysis::CountRateAnalysis(QWidget *parent) :
|
||||
MeasureAnalysisView(parent),
|
||||
ui(new Ui::CountRateAnalysis)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
InitUi();
|
||||
|
||||
}
|
||||
|
||||
CountRateAnalysis::~CountRateAnalysis()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void CountRateAnalysis::InitViewWorkspace(const QString &project_name)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void CountRateAnalysis::SetAnalyzeDataFilename(const QMap<QString, QVariant> &data_files_set)
|
||||
{
|
||||
if(!data_files_set.isEmpty())
|
||||
{
|
||||
m_AllData = getParticleInjectTimeData(data_files_set.first().toString());
|
||||
setData(m_AllData);
|
||||
}
|
||||
}
|
||||
|
||||
void CountRateAnalysis::setData(QVector<ParticleInjectTime> data)
|
||||
{
|
||||
int energyStart = ui->label_energyStart->text().toInt();
|
||||
int energyEnd = ui->label_energyEnd->text().toInt();
|
||||
int nInv = 1;
|
||||
constexpr qint64 NS_PER_SECOND = 1000000000; // 纳秒转秒的基数
|
||||
|
||||
if (data.isEmpty()) return; // 添加空列表保护
|
||||
QVector<double> x;
|
||||
QVector<double> y;
|
||||
|
||||
const ParticleInjectTime& lostdt = data.last();
|
||||
const qint64 totalNanoseconds = lostdt.dTime * 5;
|
||||
const int nAllS = static_cast<int>(totalNanoseconds / NS_PER_SECOND) + 1;
|
||||
const int nVecSize = nAllS / nInv;
|
||||
QVector<double> vec(nVecSize); // 默认初始化为0
|
||||
|
||||
|
||||
double minValue = 0;
|
||||
double maxValue = 0;
|
||||
for(auto info : data)
|
||||
{
|
||||
const qint64 ns = (info.dTime * 5) / NS_PER_SECOND;
|
||||
const int nidx = static_cast<int>(ns / nInv); // 整数除法,速度快
|
||||
if (nidx < nVecSize)
|
||||
++vec[nidx]; // 使用 ++ 而非 vec[nidx]++
|
||||
}
|
||||
|
||||
QVector<double> vecXpt(vec.size());
|
||||
for (int i = 0; i < vec.size(); ++i)
|
||||
vecXpt[i] = static_cast<double>(i);
|
||||
|
||||
// 创建曲线并设置数据
|
||||
QwtPlotCurve *curve = new QwtPlotCurve();
|
||||
curve->setSamples(vecXpt, vec);
|
||||
// 将曲线添加到 CustomQwtPlot 中(会自动分配颜色)
|
||||
plot->AddCurve(curve);
|
||||
// 设置坐标轴范围和标题
|
||||
// plot->setAxisScale(QwtPlot::xBottom, 0, x.last());
|
||||
// plot->setAxisScale(QwtPlot::yLeft,minValue , maxValue);
|
||||
|
||||
LOG_INFO(QStringLiteral(u"%1数据读取完毕.").arg(this->GetViewName()));
|
||||
|
||||
// 刷新绘图
|
||||
plot->replot();
|
||||
|
||||
}
|
||||
|
||||
QVector<ParticleInjectTime> CountRateAnalysis::getParticleInjectTimeData(QString path)
|
||||
{
|
||||
QVector<ParticleInjectTime> records;
|
||||
QFile file(path);
|
||||
|
||||
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||
qWarning() << "无法打开文件:" << file.errorString();
|
||||
return records;
|
||||
}
|
||||
QTextStream stream(&file);
|
||||
stream.setCodec("UTF-8");
|
||||
int lineNumber = 0;
|
||||
while (!stream.atEnd())
|
||||
{
|
||||
QString line = stream.readLine().trimmed();
|
||||
lineNumber++;
|
||||
|
||||
// 跳过空行
|
||||
if (line.isEmpty())
|
||||
continue;
|
||||
|
||||
// 按逗号分割
|
||||
QStringList fields = line.split(',');
|
||||
|
||||
// 检查字段数量是否正确(应该为4)
|
||||
if (fields.size() != 4) {
|
||||
qWarning() << "行" << lineNumber << "字段数量不正确,跳过:" << line;
|
||||
continue;
|
||||
}
|
||||
|
||||
//获取板卡号通道号
|
||||
int bd = fields[0].toInt();
|
||||
int ch = fields[1].toInt();
|
||||
int detector = bd + ch * 8;
|
||||
if(detector >= 32)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
bool ok;
|
||||
ParticleInjectTime rec;
|
||||
rec.bd = bd;
|
||||
rec.ch = ch;
|
||||
rec.index = lineNumber;
|
||||
rec.dEnergy = fields[2].toDouble(&ok);
|
||||
rec.dTime = fields[3].toLongLong(&ok);
|
||||
records.append(rec);
|
||||
}
|
||||
|
||||
file.close();
|
||||
|
||||
return records;
|
||||
}
|
||||
|
||||
void CountRateAnalysis::InitUi()
|
||||
{
|
||||
plot = new CustomQwtPlot();
|
||||
plot->SetXaxisDragScale(true);
|
||||
setupPlot();
|
||||
ui->verticalLayout_2->addWidget(plot);
|
||||
}
|
||||
|
||||
void CountRateAnalysis::setupPlot()
|
||||
{
|
||||
plot->setCanvasBackground(Qt::white);
|
||||
QwtPlotCanvas* canvas = qobject_cast<QwtPlotCanvas*>(plot->canvas());
|
||||
canvas->setFrameStyle(QFrame::NoFrame);
|
||||
|
||||
plot->setAxisTitle(QwtPlot::xBottom, QStringLiteral(u"时间"));
|
||||
plot->setAxisTitle(QwtPlot::yLeft, QStringLiteral(u"计数"));
|
||||
// set axis auto scale
|
||||
plot->setAxisAutoScale(QwtPlot::xBottom, true);
|
||||
plot->setAxisAutoScale(QwtPlot::yLeft, true);
|
||||
// 启用网格线
|
||||
plot->enableAxis(QwtPlot::xBottom);
|
||||
plot->enableAxis(QwtPlot::yLeft);
|
||||
|
||||
// 设置QWT图例
|
||||
// QwtLegend* legend = new QwtLegend();
|
||||
// legend->setDefaultItemMode(QwtLegendData::ReadOnly);
|
||||
// plot->insertLegend(legend, QwtPlot::RightLegend);
|
||||
|
||||
plot->SetXaxisDragScale(true);
|
||||
}
|
||||
|
|
@ -1,42 +0,0 @@
|
|||
#ifndef COUNTRATEANALYSIS_H
|
||||
#define COUNTRATEANALYSIS_H
|
||||
|
||||
#include <QWidget>
|
||||
#include "qwt.h"
|
||||
#include "CustomQwtPlot.h"
|
||||
#include <QFile>
|
||||
#include <QTextStream>
|
||||
#include "MeasureAnalysisView.h"
|
||||
|
||||
|
||||
|
||||
namespace Ui {
|
||||
class CountRateAnalysis;
|
||||
}
|
||||
|
||||
class CountRateAnalysis : public MeasureAnalysisView
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit CountRateAnalysis(QWidget *parent = nullptr);
|
||||
virtual ~CountRateAnalysis();
|
||||
|
||||
virtual void InitViewWorkspace(const QString& project_name) override final;
|
||||
virtual void SetAnalyzeDataFilename(const QMap<QString, QVariant>& data_files_set);
|
||||
|
||||
void setData(QVector<ParticleInjectTime> data);
|
||||
|
||||
//获取数据
|
||||
QVector<ParticleInjectTime> getParticleInjectTimeData(QString path);
|
||||
private:
|
||||
void InitUi();
|
||||
void setupPlot();
|
||||
|
||||
private:
|
||||
Ui::CountRateAnalysis *ui;
|
||||
CustomQwtPlot *plot;
|
||||
QVector<ParticleInjectTime> m_AllData;//存储的所有的粒子入射时间数据
|
||||
};
|
||||
|
||||
#endif //COUNTRATEANALYSIS_H
|
||||
|
|
@ -1,184 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>CountRateAnalysis</class>
|
||||
<widget class="QWidget" name="CountRateAnalysis">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>997</width>
|
||||
<height>307</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>ParticleInjectTimeAnalysis</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<property name="spacing">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>统计时间间隔:</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_energyStart">
|
||||
<property name="text">
|
||||
<string>1</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_4">
|
||||
<property name="text">
|
||||
<string>s</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_5">
|
||||
<property name="text">
|
||||
<string> 统计目标:</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_8">
|
||||
<property name="text">
|
||||
<string>特征峰</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_6">
|
||||
<property name="text">
|
||||
<string> 特征峰能量:</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_energyEnd">
|
||||
<property name="text">
|
||||
<string>45</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_7">
|
||||
<property name="text">
|
||||
<string>KeV</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="pushButton">
|
||||
<property name="text">
|
||||
<string>计数率统计时间设置</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QWidget" name="widget" native="true">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true"/>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_3">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<layoutdefault spacing="6" margin="11"/>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
|
|
@ -14,12 +14,15 @@
|
|||
#include "CustomQwtPlot.h"
|
||||
#include <QDebug>
|
||||
#include <GlobalDefine.h>
|
||||
#include "csv.h"
|
||||
|
||||
CountRateAnalysisView::CountRateAnalysisView(QWidget *parent) :
|
||||
MeasureAnalysisView(parent),
|
||||
ui(new Ui::CountRateAnalysisView)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
this->setViewType(PlotFrame);
|
||||
|
||||
InitUi();
|
||||
|
||||
}
|
||||
|
|
@ -94,53 +97,29 @@ void CountRateAnalysisView::setData(QVector<ParticleInjectTime> data)
|
|||
QVector<ParticleInjectTime> CountRateAnalysisView::getParticleInjectTimeData(QString path)
|
||||
{
|
||||
QVector<ParticleInjectTime> records;
|
||||
QFile file(path);
|
||||
io::CSVReader<4> in(QStrToSysPath(path));
|
||||
in.read_header(io::ignore_extra_column, "板卡号", "通道号", "能量(KeV)", "时间计数");
|
||||
|
||||
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||
qWarning() << "无法打开文件:" << file.errorString();
|
||||
return records;
|
||||
}
|
||||
QTextStream stream(&file);
|
||||
stream.setCodec("UTF-8");
|
||||
int board, channel;
|
||||
double energy, time_count;
|
||||
int lineNumber = 0;
|
||||
while (!stream.atEnd())
|
||||
{
|
||||
QString line = stream.readLine().trimmed();
|
||||
lineNumber++;
|
||||
|
||||
// 跳过空行
|
||||
if (line.isEmpty())
|
||||
continue;
|
||||
|
||||
// 按逗号分割
|
||||
QStringList fields = line.split(',');
|
||||
|
||||
// 检查字段数量是否正确(应该为4)
|
||||
if (fields.size() != 4) {
|
||||
qWarning() << "行" << lineNumber << "字段数量不正确,跳过:" << line;
|
||||
continue;
|
||||
}
|
||||
|
||||
//获取板卡号通道号
|
||||
int bd = fields[0].toInt();
|
||||
int ch = fields[1].toInt();
|
||||
int detector = bd + ch * 8;
|
||||
if(detector >= 32)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
bool ok;
|
||||
ParticleInjectTime rec;
|
||||
rec.bd = bd;
|
||||
rec.ch = ch;
|
||||
rec.index = lineNumber;
|
||||
rec.dEnergy = fields[2].toDouble(&ok);
|
||||
rec.dTime = fields[3].toLongLong(&ok);
|
||||
records.append(rec);
|
||||
// 逐行读取
|
||||
while (in.read_row(board, channel, energy, time_count))
|
||||
{
|
||||
int detector = board + channel * 8;
|
||||
lineNumber++;
|
||||
if(detector >= 32)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
ParticleInjectTime rec;
|
||||
rec.index = lineNumber;
|
||||
rec.dEnergy = energy;
|
||||
rec.dTime = time_count;
|
||||
records.append(rec);
|
||||
}
|
||||
|
||||
file.close();
|
||||
return records;
|
||||
|
||||
return records;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -184,6 +184,15 @@ void MeasureAnalysisTreeView::onNodeDoubleClicked(const QModelIndex& index)
|
|||
data_files_set[QStringLiteral(u"计数率")] = file_name;
|
||||
}
|
||||
}
|
||||
} break;
|
||||
case AnalysisType::ParticleTimeDiffView: {
|
||||
MeasureAnalysisProjectModel* project_model = _model->GetProjectModel(project_name);
|
||||
if (project_model) {
|
||||
auto file_name = project_model->GetAllChannelParticleDataFilename();
|
||||
if ( !file_name.isEmpty() ) {
|
||||
data_files_set[QStringLiteral(u"粒子时间差")] = file_name;
|
||||
}
|
||||
}
|
||||
} break;
|
||||
default:
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
#include "ParticleInjectTimeAnalysisView.h"
|
||||
#include "CountRateAnalysisView.h"
|
||||
#include "EnergyCountPlotView.h"
|
||||
|
||||
#include "ParticleTimePoorView.h"
|
||||
MeasureAnalysisView *MeasureAnalysisView::NewAnalyzeView(AnalysisType view_type)
|
||||
{
|
||||
MeasureAnalysisView* new_view = nullptr;
|
||||
|
|
@ -83,8 +83,8 @@ MeasureAnalysisView *MeasureAnalysisView::NewAnalyzeView(AnalysisType view_type)
|
|||
new_view->setDeleteOnClose(false);
|
||||
} break;
|
||||
case AnalysisType::ParticleTimeDiffView: {
|
||||
// new_view = new MeasureAnalysisParticleCountPlotView;
|
||||
// new_view->setDeleteOnClose(false);
|
||||
new_view = new ParticleTimePoorView;
|
||||
new_view->setDeleteOnClose(false);
|
||||
} break;
|
||||
case AnalysisType::CoincidenceEventTimeView: {
|
||||
// new_view = new MeasureAnalysisParticleCountPlotView;
|
||||
|
|
|
|||
|
|
@ -1,165 +0,0 @@
|
|||
#include "ParticleInjectTimeAnalysis.h"
|
||||
#include "ui_ParticleInjectTimeAnalysis.h"
|
||||
#include <QVBoxLayout>
|
||||
#include <QPushButton>
|
||||
#include <QMessageBox>
|
||||
#include <QwtPlotCurve>
|
||||
#include <QwtPlotMarker>
|
||||
#include <QwtPlotZoneItem>
|
||||
#include <QwtPlotCanvas>
|
||||
#include <QwtLegend>
|
||||
#include <QwtText>
|
||||
#include <cmath>
|
||||
#include <QtMath>
|
||||
#include "CustomQwtPlot.h"
|
||||
#include <QDebug>
|
||||
#include <GlobalDefine.h>
|
||||
|
||||
ParticleInjectTimeAnalysis::ParticleInjectTimeAnalysis(QWidget *parent) :
|
||||
MeasureAnalysisView(parent),
|
||||
ui(new Ui::ParticleInjectTimeAnalysis)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
InitUi();
|
||||
|
||||
}
|
||||
|
||||
ParticleInjectTimeAnalysis::~ParticleInjectTimeAnalysis()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void ParticleInjectTimeAnalysis::InitViewWorkspace(const QString &project_name)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void ParticleInjectTimeAnalysis::SetAnalyzeDataFilename(const QMap<QString, QVariant> &data_files_set)
|
||||
{
|
||||
if(!data_files_set.isEmpty())
|
||||
{
|
||||
m_AllData = getParticleInjectTimeData(data_files_set.first().toString());
|
||||
setData(m_AllData);
|
||||
}
|
||||
}
|
||||
|
||||
void ParticleInjectTimeAnalysis::setData(QVector<ParticleInjectTime> data)
|
||||
{
|
||||
int energyStart = ui->label_energyStart->text().toInt();
|
||||
int energyEnd = ui->label_energyEnd->text().toInt();
|
||||
|
||||
QVector<double> x;
|
||||
QVector<double> y;
|
||||
|
||||
double minValue = 0;
|
||||
double maxValue = 0;
|
||||
for(auto info : data)
|
||||
{
|
||||
if(info.dEnergy <= energyStart || info.dEnergy >= energyEnd)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
x.append(info.index);
|
||||
y.append(info.dTime);
|
||||
minValue = qMin(minValue, info.dTime);
|
||||
maxValue = qMax(maxValue, info.dTime);
|
||||
}
|
||||
|
||||
// 创建曲线并设置数据
|
||||
QwtPlotCurve *curve = new QwtPlotCurve();
|
||||
curve->setSamples(x, y);
|
||||
// 将曲线添加到 CustomQwtPlot 中(会自动分配颜色)
|
||||
plot->AddCurve(curve);
|
||||
// 设置坐标轴范围和标题
|
||||
// plot->setAxisScale(QwtPlot::xBottom, 0, x.last());
|
||||
// plot->setAxisScale(QwtPlot::yLeft,minValue , maxValue);
|
||||
|
||||
LOG_INFO(QStringLiteral(u"%1数据读取完毕.").arg(this->GetViewName()));
|
||||
|
||||
// 刷新绘图
|
||||
plot->replot();
|
||||
|
||||
}
|
||||
|
||||
QVector<ParticleInjectTime> ParticleInjectTimeAnalysis::getParticleInjectTimeData(QString path)
|
||||
{
|
||||
QVector<ParticleInjectTime> records;
|
||||
QFile file(path);
|
||||
|
||||
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||
qWarning() << "无法打开文件:" << file.errorString();
|
||||
return records;
|
||||
}
|
||||
QTextStream stream(&file);
|
||||
stream.setCodec("UTF-8");
|
||||
int lineNumber = 0;
|
||||
while (!stream.atEnd())
|
||||
{
|
||||
QString line = stream.readLine().trimmed();
|
||||
lineNumber++;
|
||||
|
||||
// 跳过空行
|
||||
if (line.isEmpty())
|
||||
continue;
|
||||
|
||||
// 按逗号分割
|
||||
QStringList fields = line.split(',');
|
||||
|
||||
// 检查字段数量是否正确(应该为4)
|
||||
if (fields.size() != 4) {
|
||||
qWarning() << "行" << lineNumber << "字段数量不正确,跳过:" << line;
|
||||
continue;
|
||||
}
|
||||
|
||||
//获取板卡号通道号
|
||||
int bd = fields[0].toInt();
|
||||
int ch = fields[1].toInt();
|
||||
int detector = bd + ch * 8;
|
||||
if(detector >= 32)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
bool ok;
|
||||
ParticleInjectTime rec;
|
||||
rec.index = lineNumber;
|
||||
rec.dEnergy = fields[2].toDouble(&ok);
|
||||
rec.dTime = fields[3].toLongLong(&ok);
|
||||
records.append(rec);
|
||||
}
|
||||
|
||||
file.close();
|
||||
|
||||
return records;
|
||||
}
|
||||
|
||||
void ParticleInjectTimeAnalysis::InitUi()
|
||||
{
|
||||
plot = new CustomQwtPlot();
|
||||
plot->SetXaxisDragScale(true);
|
||||
setupPlot();
|
||||
ui->verticalLayout_2->addWidget(plot);
|
||||
}
|
||||
|
||||
void ParticleInjectTimeAnalysis::setupPlot()
|
||||
{
|
||||
plot->setCanvasBackground(Qt::white);
|
||||
QwtPlotCanvas* canvas = qobject_cast<QwtPlotCanvas*>(plot->canvas());
|
||||
canvas->setFrameStyle(QFrame::NoFrame);
|
||||
|
||||
plot->setAxisTitle(QwtPlot::xBottom, QStringLiteral(u"粒子序号"));
|
||||
plot->setAxisTitle(QwtPlot::yLeft, QStringLiteral(u"粒子时间"));
|
||||
// set axis auto scale
|
||||
plot->setAxisAutoScale(QwtPlot::xBottom, true);
|
||||
plot->setAxisAutoScale(QwtPlot::yLeft, true);
|
||||
// 启用网格线
|
||||
plot->enableAxis(QwtPlot::xBottom);
|
||||
plot->enableAxis(QwtPlot::yLeft);
|
||||
|
||||
// // 设置QWT图例
|
||||
// QwtLegend* legend = new QwtLegend();
|
||||
// legend->setDefaultItemMode(QwtLegendData::ReadOnly);
|
||||
// plot->insertLegend(legend, QwtPlot::RightLegend);
|
||||
|
||||
plot->SetXaxisDragScale(true);
|
||||
}
|
||||
|
|
@ -1,41 +0,0 @@
|
|||
#ifndef PARTICLEINJECTTIMEANALYSIS_H
|
||||
#define PARTICLEINJECTTIMEANALYSIS_H
|
||||
|
||||
#include <QWidget>
|
||||
#include "qwt.h"
|
||||
#include "CustomQwtPlot.h"
|
||||
#include <QFile>
|
||||
#include <QTextStream>
|
||||
#include "MeasureAnalysisView.h"
|
||||
|
||||
|
||||
namespace Ui {
|
||||
class ParticleInjectTimeAnalysis;
|
||||
}
|
||||
|
||||
class ParticleInjectTimeAnalysis : public MeasureAnalysisView
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit ParticleInjectTimeAnalysis(QWidget *parent = nullptr);
|
||||
virtual ~ParticleInjectTimeAnalysis();
|
||||
|
||||
virtual void InitViewWorkspace(const QString& project_name) override final;
|
||||
virtual void SetAnalyzeDataFilename(const QMap<QString, QVariant>& data_files_set);
|
||||
|
||||
void setData(QVector<ParticleInjectTime> data);
|
||||
|
||||
//获取数据
|
||||
QVector<ParticleInjectTime> getParticleInjectTimeData(QString path);
|
||||
private:
|
||||
void InitUi();
|
||||
void setupPlot();
|
||||
|
||||
private:
|
||||
Ui::ParticleInjectTimeAnalysis *ui;
|
||||
CustomQwtPlot *plot;
|
||||
QVector<ParticleInjectTime> m_AllData;//存储的所有的粒子入射时间数据
|
||||
};
|
||||
|
||||
#endif // PARTICLEINJECTTIMEANALYSIS_H
|
||||
|
|
@ -1,157 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>ParticleInjectTimeAnalysis</class>
|
||||
<widget class="QWidget" name="ParticleInjectTimeAnalysis">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>997</width>
|
||||
<height>307</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>ParticleInjectTimeAnalysis</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<item>
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>粒子入射设置</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>起始能量:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_energyStart">
|
||||
<property name="text">
|
||||
<string>50</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_4">
|
||||
<property name="text">
|
||||
<string>KeV</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_5">
|
||||
<property name="text">
|
||||
<string>~</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_6">
|
||||
<property name="text">
|
||||
<string>终止能量:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_energyEnd">
|
||||
<property name="text">
|
||||
<string>100</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_7">
|
||||
<property name="text">
|
||||
<string>KeV</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="pushButton">
|
||||
<property name="text">
|
||||
<string>感兴趣区域(ROI)选择</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QWidget" name="widget" native="true">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true"/>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_3">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<layoutdefault spacing="6" margin="11"/>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
|
|
@ -19,6 +19,7 @@ ParticleInjectTimeAnalysisView::ParticleInjectTimeAnalysisView(QWidget *parent)
|
|||
MeasureAnalysisView(parent),
|
||||
ui(new Ui::ParticleInjectTimeAnalysisView)
|
||||
{
|
||||
this->setViewType(PlotFrame);
|
||||
ui->setupUi(this);
|
||||
InitUi();
|
||||
|
||||
|
|
@ -36,14 +37,59 @@ void ParticleInjectTimeAnalysisView::InitViewWorkspace(const QString &project_na
|
|||
|
||||
void ParticleInjectTimeAnalysisView::SetAnalyzeDataFilename(const QMap<QString, QVariant> &data_files_set)
|
||||
{
|
||||
int energyStart = ui->label_energyStart->text().toInt();
|
||||
int energyEnd = ui->label_energyEnd->text().toInt();
|
||||
if(!data_files_set.isEmpty())
|
||||
{
|
||||
m_AllData = getParticleInjectTimeData(data_files_set.first().toString());
|
||||
setData(m_AllData);
|
||||
io::CSVReader<4> in(QStrToSysPath(data_files_set.first().toString()));
|
||||
in.read_header(io::ignore_extra_column, "板卡号", "通道号", "能量(KeV)", "时间计数");
|
||||
|
||||
int board, channel;
|
||||
double energy, time_count;
|
||||
int lineNumber = 0;
|
||||
QVector<double> x;
|
||||
QVector<double> y;
|
||||
double minValue = 0;
|
||||
double maxValue = 0;
|
||||
// 逐行读取
|
||||
while (in.read_row(board, channel, energy, time_count))
|
||||
{
|
||||
// qDebug()<<QStringLiteral(u"板卡号:")<<board<<QStringLiteral(u"通道号")<<channel<<QStringLiteral(u"能量(KeV)")<<energy<<QStringLiteral(u"时间计数")<<time_count;
|
||||
int detector = board + channel * 8;
|
||||
lineNumber++;
|
||||
if(detector > 32)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if(energy <= energyStart || energy >= energyEnd)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
x.append(lineNumber);
|
||||
y.append(time_count);
|
||||
minValue = qMin(minValue, time_count);
|
||||
maxValue = qMax(maxValue, time_count);
|
||||
}
|
||||
// 创建曲线并设置数据
|
||||
QwtPlotCurve *curve = new QwtPlotCurve();
|
||||
curve->setSamples(x, y);
|
||||
// 将曲线添加到 CustomQwtPlot 中(会自动分配颜色)
|
||||
plot->AddCurve(curve);
|
||||
// 设置坐标轴范围和标题
|
||||
// plot->setAxisScale(QwtPlot::xBottom, 0, x.last());
|
||||
// plot->setAxisScale(QwtPlot::yLeft,minValue , maxValue);
|
||||
|
||||
LOG_INFO(QStringLiteral(u"%1数据读取完毕.").arg(this->GetViewName()));
|
||||
|
||||
// 刷新绘图
|
||||
plot->replot();
|
||||
// m_AllData = getParticleInjectTimeData(data_files_set.first().toString());
|
||||
// setData(m_AllData);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void ParticleInjectTimeAnalysisView::setData(QVector<ParticleInjectTime> data)
|
||||
void ParticleInjectTimeAnalysisView::setData(QVector<ParticleInjectTime *> data)
|
||||
{
|
||||
int energyStart = ui->label_energyStart->text().toInt();
|
||||
int energyEnd = ui->label_energyEnd->text().toInt();
|
||||
|
|
@ -55,18 +101,19 @@ void ParticleInjectTimeAnalysisView::setData(QVector<ParticleInjectTime> data)
|
|||
double maxValue = 0;
|
||||
for(auto info : data)
|
||||
{
|
||||
if(info.dEnergy <= energyStart || info.dEnergy >= energyEnd)
|
||||
if(info->dEnergy <= energyStart || info->dEnergy >= energyEnd)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
x.append(info.index);
|
||||
y.append(info.dTime);
|
||||
minValue = qMin(minValue, info.dTime);
|
||||
maxValue = qMax(maxValue, info.dTime);
|
||||
x.append(info->index);
|
||||
y.append(info->dTime);
|
||||
minValue = qMin(minValue, info->dTime);
|
||||
maxValue = qMax(maxValue, info->dTime);
|
||||
}
|
||||
|
||||
// 创建曲线并设置数据
|
||||
QwtPlotCurve *curve = new QwtPlotCurve();
|
||||
// curve->setRawSamples(x.data(),y.data(),x.size());
|
||||
curve->setSamples(x, y);
|
||||
// 将曲线添加到 CustomQwtPlot 中(会自动分配颜色)
|
||||
plot->AddCurve(curve);
|
||||
|
|
@ -81,55 +128,33 @@ void ParticleInjectTimeAnalysisView::setData(QVector<ParticleInjectTime> data)
|
|||
|
||||
}
|
||||
|
||||
QVector<ParticleInjectTime> ParticleInjectTimeAnalysisView::getParticleInjectTimeData(QString path)
|
||||
QVector<ParticleInjectTime *> ParticleInjectTimeAnalysisView::getParticleInjectTimeData(QString path)
|
||||
{
|
||||
QVector<ParticleInjectTime> records;
|
||||
QFile file(path);
|
||||
QVector<ParticleInjectTime *> records;
|
||||
|
||||
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||
qWarning() << "无法打开文件:" << file.errorString();
|
||||
return records;
|
||||
}
|
||||
QTextStream stream(&file);
|
||||
stream.setCodec("UTF-8");
|
||||
io::CSVReader<4> in(QStrToSysPath(path));
|
||||
in.read_header(io::ignore_extra_column, "板卡号", "通道号", "能量(KeV)", "时间计数");
|
||||
|
||||
int board, channel;
|
||||
double energy, time_count;
|
||||
int lineNumber = 0;
|
||||
while (!stream.atEnd())
|
||||
{
|
||||
QString line = stream.readLine().trimmed();
|
||||
lineNumber++;
|
||||
|
||||
// 跳过空行
|
||||
if (line.isEmpty())
|
||||
continue;
|
||||
|
||||
// 按逗号分割
|
||||
QStringList fields = line.split(',');
|
||||
|
||||
// 检查字段数量是否正确(应该为4)
|
||||
if (fields.size() != 4) {
|
||||
qWarning() << "行" << lineNumber << "字段数量不正确,跳过:" << line;
|
||||
continue;
|
||||
}
|
||||
|
||||
//获取板卡号通道号
|
||||
int bd = fields[0].toInt();
|
||||
int ch = fields[1].toInt();
|
||||
int detector = bd + ch * 8;
|
||||
if(detector >= 32)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
bool ok;
|
||||
ParticleInjectTime rec;
|
||||
rec.index = lineNumber;
|
||||
rec.dEnergy = fields[2].toDouble(&ok);
|
||||
rec.dTime = fields[3].toLongLong(&ok);
|
||||
records.append(rec);
|
||||
// 逐行读取
|
||||
while (in.read_row(board, channel, energy, time_count))
|
||||
{
|
||||
// qDebug()<<QStringLiteral(u"板卡号:")<<board<<QStringLiteral(u"通道号")<<channel<<QStringLiteral(u"能量(KeV)")<<energy<<QStringLiteral(u"时间计数")<<time_count;
|
||||
int detector = board + channel * 8;
|
||||
lineNumber++;
|
||||
if(detector > 32)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
ParticleInjectTime *rec = new ParticleInjectTime;
|
||||
rec->index = lineNumber;
|
||||
rec->dEnergy = energy;
|
||||
rec->dTime = time_count;
|
||||
records.append(rec);
|
||||
}
|
||||
|
||||
file.close();
|
||||
|
||||
return records;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -7,6 +7,8 @@
|
|||
#include <QFile>
|
||||
#include <QTextStream>
|
||||
#include "MeasureAnalysisView.h"
|
||||
#include "csv.h"
|
||||
|
||||
|
||||
|
||||
namespace Ui {
|
||||
|
|
@ -24,10 +26,10 @@ public:
|
|||
virtual void InitViewWorkspace(const QString& project_name) override final;
|
||||
virtual void SetAnalyzeDataFilename(const QMap<QString, QVariant>& data_files_set);
|
||||
|
||||
void setData(QVector<ParticleInjectTime> data);
|
||||
void setData(QVector<ParticleInjectTime *> data);
|
||||
|
||||
//获取数据
|
||||
QVector<ParticleInjectTime> getParticleInjectTimeData(QString path);
|
||||
QVector<ParticleInjectTime *> getParticleInjectTimeData(QString path);
|
||||
private:
|
||||
void InitUi();
|
||||
void setupPlot();
|
||||
|
|
@ -35,7 +37,7 @@ private:
|
|||
private:
|
||||
Ui::ParticleInjectTimeAnalysisView *ui;
|
||||
CustomQwtPlot *plot;
|
||||
QVector<ParticleInjectTime> m_AllData;//存储的所有的粒子入射时间数据
|
||||
QVector<ParticleInjectTime *> m_AllData;//存储的所有的粒子入射时间数据
|
||||
};
|
||||
|
||||
#endif // PARTICLEINJECTTIMEANALYSIS_H
|
||||
|
|
|
|||
15
src/src.pro
15
src/src.pro
|
|
@ -35,14 +35,17 @@ INCLUDEPATH += \
|
|||
$${PWD}/ParticleCountPlotView \
|
||||
$${PWD}/ParticleInjectTimeView \
|
||||
$${PWD}/EnergyCountPlotView \
|
||||
$${PWD}/CountRateAnalysisView
|
||||
$${PWD}/CountRateAnalysisView \
|
||||
$${PWD}/ParticleTimePoorView
|
||||
|
||||
DEPENDPATH += \
|
||||
$${PWD}/MeasureAnalysisParticleCountPlotView \
|
||||
$${PWD}/ParticleCountPlotView \
|
||||
$${PWD}/ParticleInjectTimeView\
|
||||
$${PWD}/EnergyCountPlotView \
|
||||
$${PWD}/CountRateAnalysisView
|
||||
$${PWD}/CountRateAnalysisView \
|
||||
$${PWD}/ParticleTimePoorView
|
||||
|
||||
|
||||
SOURCES += \
|
||||
AboutDlg.cpp \
|
||||
|
|
@ -68,6 +71,7 @@ SOURCES += \
|
|||
VirtualTable/SampleDataSource.cpp \
|
||||
VirtualTable/VirtualTableModel.cpp \
|
||||
VirtualTable/VirtualTableView.cpp \
|
||||
ParticleTimePoorView/ParticleTimePoorView.cpp\
|
||||
main.cpp
|
||||
|
||||
HEADERS += \
|
||||
|
|
@ -96,7 +100,8 @@ HEADERS += \
|
|||
VirtualTable/DataSource.h \
|
||||
VirtualTable/SampleDataSource.h \
|
||||
VirtualTable/VirtualTableModel.h \
|
||||
VirtualTable/VirtualTableView.h
|
||||
VirtualTable/VirtualTableView.h\
|
||||
ParticleTimePoorView/ParticleTimePoorView.h
|
||||
|
||||
|
||||
FORMS += \
|
||||
|
|
@ -108,7 +113,9 @@ FORMS += \
|
|||
ParticleCountPlotView/BatchEnergyScaleDialog.ui \
|
||||
MeasureDeviceParamsCfgForm.ui \
|
||||
NewMeasureAnalysisDlg.ui \
|
||||
ParticleInjectTimeView/ParticleInjectTimeAnalysisView.ui
|
||||
ParticleInjectTimeView/ParticleInjectTimeAnalysisView.ui\
|
||||
ParticleTimePoorView/ParticleTimePoorView.ui
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user