302 lines
10 KiB
C++
302 lines
10 KiB
C++
|
|
#include "ConformityAnalysis.h"
|
|||
|
|
#include "ui_ConformityAnalysis.h"
|
|||
|
|
#include <QDebug>
|
|||
|
|
ConformityAnalysis::ConformityAnalysis(QWidget *parent) :
|
|||
|
|
MeasureAnalysisView(parent),
|
|||
|
|
ui(new Ui::ConformityAnalysis)
|
|||
|
|
{
|
|||
|
|
ui->setupUi(this);
|
|||
|
|
memset(m_boardChannel, 0, sizeof(m_boardChannel)); // 新增
|
|||
|
|
//// // 获取当前可执行文件的路径
|
|||
|
|
//// QString executablePath = QCoreApplication::applicationDirPath() + "/test.csv";
|
|||
|
|
// connect(ui->widget,SIGNAL(Signal_ClickedBoard(int,int)),this,SLOT(slot_ClickedBoard(int,int)));
|
|||
|
|
// connect(ui->widget,SIGNAL(Signal_InitialState()),this,SLOT(slot_InitialState()));
|
|||
|
|
//// qDebug()<<"可执行文件:"<< executablePath;
|
|||
|
|
// setCsvFile(m_fileName);
|
|||
|
|
// readCsv();
|
|||
|
|
// handleBoard();
|
|||
|
|
// m_FirstParticle = statisticsFirstParticleQuantity();
|
|||
|
|
// setAllBoardData();
|
|||
|
|
// calculateFirstSecondRange();
|
|||
|
|
// setThreeUiData();
|
|||
|
|
// generateSurfaceData(m_CoincidenceEventVector);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
ConformityAnalysis::~ConformityAnalysis()
|
|||
|
|
{
|
|||
|
|
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) {
|
|||
|
|
qDebug()<<data_files_set[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(m_CoincidenceEventVector);
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// QString path = data_files_set.first().toString();
|
|||
|
|
// qDebug()<<path;
|
|||
|
|
// setCsvFile(path);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void ConformityAnalysis::setCsvFile(QString fileName)
|
|||
|
|
{
|
|||
|
|
m_fileName = fileName;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void ConformityAnalysis::readCsv()
|
|||
|
|
{
|
|||
|
|
qDebug()<<m_fileName;
|
|||
|
|
// 创建 CSVReader 对象,指定列数(5列)
|
|||
|
|
io::CSVReader<5> reader(m_fileName.toStdString());
|
|||
|
|
qDebug()<<"板卡号:";
|
|||
|
|
// 符合事件变量
|
|||
|
|
int id = 0;
|
|||
|
|
std::vector<F2t9Order::SpectrumData> SpectrumDataList;
|
|||
|
|
// 逐行读取数据
|
|||
|
|
while (true)
|
|||
|
|
{
|
|||
|
|
int comply = 0;
|
|||
|
|
F2t9Order::SpectrumData SpectrumData;
|
|||
|
|
bool flag = reader.read_row(/*EventData.coincidence_order*/comply,SpectrumData.board_id, SpectrumData.channel_id, SpectrumData.energy,SpectrumData.timestamp);
|
|||
|
|
qDebug()<<"符合事件:"<<comply<<"板卡号:"<<SpectrumData.board_id<<"通道号:"<<SpectrumData.board_id<<"能量:"<<SpectrumData.energy<<"时间戳:"<<SpectrumData.timestamp;
|
|||
|
|
if(!flag)
|
|||
|
|
{
|
|||
|
|
break;
|
|||
|
|
}
|
|||
|
|
SpectrumDataList.push_back(SpectrumData);
|
|||
|
|
if(comply != id)
|
|||
|
|
{
|
|||
|
|
F2t9Order::CoincidenceEvent EventData;
|
|||
|
|
EventData.coincidence_order = comply;
|
|||
|
|
EventData.events = SpectrumDataList;
|
|||
|
|
m_CoincidenceEventVector.push_back(EventData);
|
|||
|
|
qDebug()<<"符合事件里面的vector:"<<EventData.events.size();
|
|||
|
|
id = EventData.coincidence_order;
|
|||
|
|
SpectrumDataList.clear();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
qDebug()<<"符合事件数:"<<m_CoincidenceEventVector.size();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void ConformityAnalysis::slot_InitialState()
|
|||
|
|
{
|
|||
|
|
setAllBoardData();
|
|||
|
|
calculateFirstSecondRange();
|
|||
|
|
setThreeUiData();
|
|||
|
|
generateSurfaceData(m_CoincidenceEventVector);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void ConformityAnalysis::slot_ClickedBoard(int board,int channel)
|
|||
|
|
{
|
|||
|
|
//获取当前板卡的初级粒子数据
|
|||
|
|
std::vector<F2t9Order::CoincidenceEvent> data = handleBasicSubordinate(m_CoincidenceEventVector,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 (int i = 0; i < m_CoincidenceEventVector.size(); i++)
|
|||
|
|
{
|
|||
|
|
for(auto spetruData:m_CoincidenceEventVector.at(i).events)
|
|||
|
|
{
|
|||
|
|
m_boardChannel[spetruData.channel_id][spetruData.board_id]++;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
QMap<QString, int> ConformityAnalysis::statisticsFirstParticleQuantity()
|
|||
|
|
{
|
|||
|
|
QMap<QString, int> firstParticleCount;
|
|||
|
|
// 初始化所有板卡通道的计数为0
|
|||
|
|
for (int board = 1; board <= 8; ++board)
|
|||
|
|
{
|
|||
|
|
for (int channel = 1; channel <= 4; ++channel)
|
|||
|
|
{
|
|||
|
|
QString key = QString("widget_%1_%2").arg(board).arg(channel);
|
|||
|
|
firstParticleCount[key] = 0;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
// 遍历所有符合事件
|
|||
|
|
for (const auto& event : m_CoincidenceEventVector)
|
|||
|
|
{
|
|||
|
|
if (event.events.empty()) continue;
|
|||
|
|
|
|||
|
|
// 第一个事件是初级粒子
|
|||
|
|
const auto& firstParticle = event.events[0];
|
|||
|
|
int boardId = firstParticle.board_id + 1; // 转换为1-based
|
|||
|
|
int channelId = firstParticle.channel_id + 1; // 转换为1-based
|
|||
|
|
|
|||
|
|
if (boardId >= 1 && boardId <= 8 && channelId >= 1 && channelId <= 4) {
|
|||
|
|
QString key = QString("widget_%1_%2").arg(boardId).arg(channelId);
|
|||
|
|
firstParticleCount[key]++;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
return firstParticleCount;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
std::vector<F2t9Order::CoincidenceEvent> ConformityAnalysis::handleBasicSubordinate(std::vector<F2t9Order::CoincidenceEvent> &eventData, int Board, int Channel)
|
|||
|
|
{
|
|||
|
|
std::vector<F2t9Order::CoincidenceEvent> EventVector;//所有的初级粒子符合事件
|
|||
|
|
for (int i = 0; i < eventData.size(); i++)
|
|||
|
|
{
|
|||
|
|
F2t9Order::CoincidenceEvent EventData = eventData.at(i);
|
|||
|
|
F2t9Order::SpectrumData data = EventData.events.at(0);
|
|||
|
|
if (data.board_id == Board - 1&& data.channel_id == Channel - 1)
|
|||
|
|
{
|
|||
|
|
EventVector.push_back(EventData);
|
|||
|
|
m_beginVector.push_back(data);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
return EventVector;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
QMap<QString, int> ConformityAnalysis::handleSubordinate(std::vector<F2t9Order::CoincidenceEvent> &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 = QString("widget_%1_%2").arg(board).arg(channel);
|
|||
|
|
data[key] = 0;
|
|||
|
|
for (int j = 0; j < eventData.size(); j++)
|
|||
|
|
{
|
|||
|
|
std::vector<F2t9Order::SpectrumData> dataVector = eventData.at(j).events;
|
|||
|
|
for (int k = 0; k < dataVector.size(); k++)
|
|||
|
|
{
|
|||
|
|
F2t9Order::SpectrumData dataSpectrum = dataVector.at(k);
|
|||
|
|
if (dataSpectrum.board_id == Board - 1 && dataSpectrum.channel_id == Channel - 1)
|
|||
|
|
continue;
|
|||
|
|
if (dataSpectrum.board_id == board - 1 && dataSpectrum.channel_id == 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;
|
|||
|
|
for (int i = 0; i < m_CoincidenceEventVector.size(); i++)
|
|||
|
|
{
|
|||
|
|
F2t9Order::CoincidenceEvent data = m_CoincidenceEventVector.at(i);
|
|||
|
|
m_iComply += data.events.size();
|
|||
|
|
for (int j = 0; j < data.events.size(); j++)
|
|||
|
|
{
|
|||
|
|
F2t9Order::SpectrumData spectrum = data.events.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 = QString("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 std::vector<F2t9Order::CoincidenceEvent>& events)
|
|||
|
|
{
|
|||
|
|
m_surfaceData.clear();
|
|||
|
|
for (const auto& event : events)
|
|||
|
|
{
|
|||
|
|
if (event.events.empty()) continue;
|
|||
|
|
|
|||
|
|
float primaryEnergy = event.events[0].energy;
|
|||
|
|
|
|||
|
|
float secondaryEnergySum = 0.0f;
|
|||
|
|
for (size_t i = 1; i < event.events.size(); i++) {
|
|||
|
|
secondaryEnergySum += event.events[i].energy;
|
|||
|
|
}
|
|||
|
|
SurfacePoint point;
|
|||
|
|
point.primaryEnergy = primaryEnergy;
|
|||
|
|
point.secondaryEnergySum = secondaryEnergySum;
|
|||
|
|
point.count = 1;
|
|||
|
|
|
|||
|
|
m_surfaceData.append(point);
|
|||
|
|
}
|
|||
|
|
ui->widget_3D->setSurfaceData(m_surfaceData);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
|