280 lines
8.6 KiB
C++
280 lines
8.6 KiB
C++
#include "ConformityAnalysis.h"
|
||
#include "ui_ConformityAnalysis.h"
|
||
#include <QDebug>
|
||
#include <GlobalDefine.h>
|
||
|
||
ConformityAnalysis::ConformityAnalysis(QWidget *parent) :
|
||
MeasureAnalysisView(parent),
|
||
ui(new Ui::ConformityAnalysis)
|
||
{
|
||
ui->setupUi(this);
|
||
memset(m_boardChannel, 0, sizeof(m_boardChannel)); // 新增
|
||
connect(ui->widget,SIGNAL(Signal_ClickedBoard(int,int)),this,SLOT(slot_ClickedBoard(int,int)));
|
||
connect(ui->widget,SIGNAL(Signal_InitialState()),this,SLOT(slot_InitialState()));
|
||
|
||
}
|
||
|
||
ConformityAnalysis::~ConformityAnalysis()
|
||
{
|
||
qDeleteAll(_spectrumDataList);
|
||
_spectrumDataList.clear();
|
||
delete ui;
|
||
}
|
||
|
||
void ConformityAnalysis::InitViewWorkspace(const QString &project_name)
|
||
{
|
||
|
||
}
|
||
|
||
void ConformityAnalysis::SetAnalyzeDataFilename(const QMap<QString, QVariant> &data_files_set)
|
||
{
|
||
QStringList ch_count_data_name = data_files_set.keys();
|
||
int conformCount = ui->comboBox->currentIndex() + 2;
|
||
for (const QString& ch_count_data_name : ch_count_data_name) {
|
||
if(conformCount == ch_count_data_name.toInt())
|
||
{
|
||
setCsvFile(data_files_set[ch_count_data_name].toString());
|
||
readCsv();
|
||
handleBoard();
|
||
m_FirstParticle = statisticsFirstParticleQuantity();
|
||
setAllBoardData();
|
||
calculateFirstSecondRange();
|
||
setThreeUiData();
|
||
generateSurfaceData(_spectrumDataList);
|
||
}
|
||
}
|
||
}
|
||
|
||
void ConformityAnalysis::setCsvFile(QString fileName)
|
||
{
|
||
m_fileName = fileName;
|
||
}
|
||
|
||
void ConformityAnalysis::readCsv()
|
||
{
|
||
qDebug()<<m_fileName;
|
||
// 创建 CSVReader 对象,指定列数(5列)
|
||
io::CSVReader<5> reader(QStrToSysPath(m_fileName));
|
||
reader.read_header(io::ignore_extra_column, QStringLiteral(u"事件ID").toStdString(),QStringLiteral(u"板卡号").toStdString(), QStringLiteral(u"通道号").toStdString(), QStringLiteral(u"能量(KeV)").toStdString(), QStringLiteral(u"时间计数").toStdString());
|
||
// 逐行读取数据
|
||
while (true)
|
||
{
|
||
particleCoincidenceEvent *SpectrumData = new particleCoincidenceEvent;
|
||
bool flag = reader.read_row(SpectrumData->eventId,SpectrumData->board, SpectrumData->channel, SpectrumData->energy,SpectrumData->timeCounter);
|
||
|
||
if(!flag)
|
||
{
|
||
break;
|
||
}
|
||
_spectrumDataList.push_back(SpectrumData);
|
||
}
|
||
}
|
||
|
||
void ConformityAnalysis::slot_InitialState()
|
||
{
|
||
setAllBoardData();
|
||
calculateFirstSecondRange();
|
||
setThreeUiData();
|
||
generateSurfaceData(_spectrumDataList);
|
||
}
|
||
|
||
void ConformityAnalysis::slot_ClickedBoard(int board,int channel)
|
||
{
|
||
//获取当前板卡的初级粒子数据
|
||
QVector<particleCoincidenceEvent*> data = handleBasicSubordinate(board,channel);
|
||
if(data.size() <= 0) return;
|
||
generateSurfaceData(data);
|
||
m_subordinate = handleSubordinate(data, board, channel);
|
||
for (int i = 0; i < m_subordinate.keys().size();i++)
|
||
{
|
||
QString objectName =m_subordinate.keys().at(i);
|
||
QStringList parts = objectName.split('_');
|
||
int bd = parts[1].toInt();
|
||
int ch = parts[2].toInt();
|
||
ui->widget->setWidgetData(bd,ch,m_boardChannel[bd - 1][ch - 1],m_subordinate[objectName]);
|
||
}
|
||
ui->widget->setWidgetData(board,channel,m_boardChannel[board - 1][channel - 1],data.size());
|
||
}
|
||
|
||
void ConformityAnalysis::handleBoard()
|
||
{
|
||
for(auto spetruData:_spectrumDataList)
|
||
{
|
||
m_boardChannel[spetruData->board][spetruData->channel]++;
|
||
}
|
||
}
|
||
|
||
QMap<QString, int> ConformityAnalysis::statisticsFirstParticleQuantity()
|
||
{
|
||
QMap<QString, int> firstParticleCount;
|
||
for (int board = 1; board <= 8; ++board)
|
||
{
|
||
for (int channel = 1; channel <= 4; ++channel)
|
||
{
|
||
QString key = QStringLiteral(u"widget_%1_%2").arg(board).arg(channel);
|
||
firstParticleCount[key] = 0;
|
||
}
|
||
}
|
||
if (_spectrumDataList.empty()) return firstParticleCount;
|
||
|
||
int eventId = 0;
|
||
// 遍历所有符合事件
|
||
for (const auto& event : _spectrumDataList)
|
||
{
|
||
// 第一个事件是初级粒子
|
||
const auto& firstParticle = event;
|
||
int boardId = firstParticle->board + 1;
|
||
int channelId = firstParticle->channel + 1;
|
||
if(firstParticle->eventId == eventId) continue;
|
||
eventId = firstParticle->eventId;
|
||
if (boardId >= 1 && boardId <= 8 && channelId >= 1 && channelId <= 4) {
|
||
QString key = QStringLiteral(u"widget_%1_%2").arg(boardId).arg(channelId);
|
||
firstParticleCount[key]++;
|
||
}
|
||
}
|
||
return firstParticleCount;
|
||
}
|
||
|
||
QVector<particleCoincidenceEvent*> ConformityAnalysis::handleBasicSubordinate(int Board, int Channel)
|
||
{
|
||
QVector<particleCoincidenceEvent*> EventVector;//所有的初级粒子符合事件
|
||
int eventId = 0;
|
||
for(auto data:_spectrumDataList)
|
||
{
|
||
if(eventId == data->eventId)
|
||
{
|
||
EventVector.push_back(data);
|
||
}
|
||
|
||
if(data->board == Board - 1&& data->channel == Channel - 1)
|
||
{
|
||
m_beginVector.push_back(data);
|
||
EventVector.push_back(data);
|
||
eventId = data->eventId;
|
||
}
|
||
}
|
||
return EventVector;
|
||
}
|
||
|
||
QMap<QString, int> ConformityAnalysis::handleSubordinate(QVector<particleCoincidenceEvent*> &eventData,int Board, int Channel)
|
||
{
|
||
m_secondVector.clear();
|
||
QMap<QString, int> data;
|
||
for (int board = 1; board <= 8; ++board)
|
||
{
|
||
for (int channel = 1; channel <= 4; ++channel)
|
||
{
|
||
QString key = QStringLiteral(u"widget_%1_%2").arg(board).arg(channel);
|
||
data[key] = 0;
|
||
for(auto dataSpectrum : eventData)
|
||
{
|
||
if (dataSpectrum->board == Board - 1 && dataSpectrum->channel == Channel - 1)
|
||
continue;
|
||
if (dataSpectrum->board == board - 1 && dataSpectrum->channel == channel - 1)
|
||
{
|
||
data[key]++;
|
||
m_secondVector.push_back(dataSpectrum);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
return data;
|
||
}
|
||
|
||
int ConformityAnalysis::getMaxValue()
|
||
{
|
||
auto begin = &m_boardChannel[0][0];
|
||
auto end = begin + MAX_BOARD * MAX_CHANNEL;
|
||
return *std::max_element(begin, end);
|
||
}
|
||
|
||
void ConformityAnalysis::calculateFirstSecondRange()
|
||
{
|
||
//符合事件总计数
|
||
m_iComply = 0;
|
||
// 找出所有数值中的最小值和最大值
|
||
double minFirstVal = 11111111.1111;
|
||
double maxFirstVal = 0.0;
|
||
|
||
double minSecondVal = 11111111.1111;
|
||
double maxSecondVal = 0.0;
|
||
|
||
m_iComply = _spectrumDataList.size();
|
||
for (int j = 0; j < _spectrumDataList.size(); j++)
|
||
{
|
||
particleCoincidenceEvent *spectrum = _spectrumDataList.at(j);
|
||
if (j == 0)
|
||
{
|
||
if (spectrum->energy < minFirstVal) minFirstVal = spectrum->energy;
|
||
if (spectrum->energy > maxFirstVal) maxFirstVal = spectrum->energy;
|
||
continue;
|
||
}
|
||
if (spectrum->energy < minSecondVal) minSecondVal = spectrum->energy;
|
||
if (spectrum->energy > maxSecondVal) maxSecondVal = spectrum->energy;
|
||
}
|
||
|
||
m_dFirstStart = minFirstVal;
|
||
m_dFirstEnd = maxFirstVal;
|
||
m_dSecondStart = minSecondVal;
|
||
m_dSecondEnd = maxSecondVal;
|
||
}
|
||
|
||
void ConformityAnalysis::setAllBoardData()
|
||
{
|
||
for (int board = 1; board <= 8; ++board)
|
||
{
|
||
for (int channel = 1; channel <= 4; ++channel)
|
||
{
|
||
QString key = QStringLiteral(u"widget_%1_%2").arg(board).arg(channel);
|
||
qDebug()<<key;
|
||
if ( m_FirstParticle.contains(key) ) {
|
||
ui->widget->setInitWidgetData(board,channel,m_boardChannel[board - 1][channel-1],m_FirstParticle[key]);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
void ConformityAnalysis::setThreeUiData()
|
||
{
|
||
qDebug()<< m_dSecondStart << m_dSecondEnd;
|
||
ui->widget_3D->setBasicParticle(m_dFirstStart,m_dFirstEnd);
|
||
ui->widget_3D->setSecondParticle(m_dSecondStart,m_dSecondEnd);
|
||
ui->widget_3D->setComplyWithEvent(m_iComply);
|
||
}
|
||
|
||
void ConformityAnalysis::generateSurfaceData(const QVector<particleCoincidenceEvent*> events)
|
||
{
|
||
m_surfaceData.clear();
|
||
if (events.empty()) return;
|
||
int eventId = 0;
|
||
|
||
float primaryEnergy = 0.0f;
|
||
float secondaryEnergySum = 0.0f;
|
||
for (const auto& event : events)
|
||
{
|
||
|
||
if(eventId != event->eventId)
|
||
{
|
||
SurfacePoint point;
|
||
point.primaryEnergy = primaryEnergy;
|
||
point.secondaryEnergySum = secondaryEnergySum;
|
||
point.count = 1;
|
||
m_surfaceData.append(point);
|
||
primaryEnergy = 0.0f;
|
||
secondaryEnergySum = 0.0f;
|
||
primaryEnergy = event->energy;
|
||
eventId = event->eventId;
|
||
continue;
|
||
}
|
||
else
|
||
{
|
||
secondaryEnergySum += event->energy;
|
||
}
|
||
}
|
||
ui->widget_3D->setSurfaceData(m_surfaceData);
|
||
}
|
||
|
||
|
||
|