FSUDAQ_Qt6/CanvasClass.cpp

120 lines
3.3 KiB
C++
Raw Normal View History

#include "CanvasClass.h"
#include <QValueAxis>
#include <QRandomGenerator>
#include <QGroupBox>
#include <QStandardItemModel>
#include <QLabel>
2023-05-19 16:23:04 -04:00
#include <QRandomGenerator>
Canvas::Canvas(Digitizer ** digi, unsigned int nDigi, QMainWindow * parent) : QMainWindow(parent){
this->digi = digi;
this->nDigi = nDigi;
setWindowTitle("Canvas");
setGeometry(0, 0, 1000, 800);
//setWindowFlags( this->windowFlags() & ~Qt::WindowCloseButtonHint );
QWidget * layoutWidget = new QWidget(this);
setCentralWidget(layoutWidget);
QVBoxLayout * layout = new QVBoxLayout(layoutWidget);
layoutWidget->setLayout(layout);
//========================
QGroupBox * controlBox = new QGroupBox("Control", this);
layout->addWidget(controlBox);
QGridLayout * ctrlLayout = new QGridLayout(controlBox);
controlBox->setLayout(ctrlLayout);
QPushButton * bnClearHist = new QPushButton("Clear Hist.", this);
ctrlLayout->addWidget(bnClearHist, 0, 0);
2023-05-19 16:23:04 -04:00
connect(bnClearHist, &QPushButton::clicked, this, [=](){
for( int i = 0; i < MaxNDigitizer; i++){
for( int j = 0; j < MaxNChannels; j++){
if( hist[i][j] ) hist[i][j]->Clear();
}
}
});
cbDigi = new RComboBox(this);
for( unsigned int i = 0; i < nDigi; i++) cbDigi->addItem("Digi-" + QString::number( digi[i]->GetSerialNumber() ), i);
ctrlLayout->addWidget(cbDigi, 1, 0);
connect( cbDigi, &RComboBox::currentIndexChanged, this, &Canvas::ChangeHistView);
cbCh = new RComboBox(this);
for( int i = 0; i < MaxNChannels; i++) cbCh->addItem("ch-" + QString::number( i ), i);
ctrlLayout->addWidget(cbCh, 1, 1);
connect( cbCh, &RComboBox::currentIndexChanged, this, &Canvas::ChangeHistView);
//========================
2023-05-19 16:23:04 -04:00
histBox = new QGroupBox("Histgrams", this);
layout->addWidget(histBox);
2023-05-19 16:23:04 -04:00
histLayout = new QGridLayout(histBox);
histBox->setLayout(histLayout);
double xMax = 4000;
double xMin = 0;
double nBin = 100;
2023-05-19 16:23:04 -04:00
for( unsigned int i = 0; i < MaxNDigitizer; i++){
for( int j = 0; j < digi[i]->GetNChannels(); j++){
2023-05-19 16:23:04 -04:00
if( i < nDigi ) {
hist[i][j] = new Histogram1D("Digi-" + QString::number(digi[i]->GetSerialNumber()) +", Ch-" + QString::number(j), "Raw Energy [ch]", nBin, xMin, xMax);
2023-05-19 16:23:04 -04:00
}else{
hist[i][j] = nullptr;
}
}
}
histLayout->addWidget(hist[0][0], 0, 0);
2023-05-19 16:23:04 -04:00
oldBd = -1;
oldCh = -1;
}
Canvas::~Canvas(){
for( unsigned int i = 0; i < nDigi; i++ ){
for( int ch = 0; ch < digi[i]->GetNChannels(); ch++){
delete hist[i][ch];
2023-05-19 16:23:04 -04:00
}
}
}
void Canvas::ChangeHistView(){
2023-05-19 16:23:04 -04:00
if( oldCh >= 0 ) {
histLayout->removeWidget(hist[oldBd][oldCh]);
hist[oldBd][oldCh]->setParent(nullptr);
2023-05-19 16:23:04 -04:00
}
int bd = cbDigi->currentIndex();
int ch = cbCh->currentIndex();
histLayout->addWidget(hist[bd][ch], 0, 0);
2023-05-19 16:23:04 -04:00
oldBd = bd;
oldCh = ch;
}
void Canvas::UpdateCanvas(){
2023-05-19 16:23:04 -04:00
for( int i = 0; i < nDigi; i++){
2023-05-19 16:23:04 -04:00
digiMTX[i].lock();
for( int ch = 0; ch < digi[i]->GetNChannels(); ch ++ ){
int lastIndex = digi[i]->GetData()->DataIndex[ch];
2023-05-19 16:23:04 -04:00
int nDecoded = digi[i]->GetData()->NumEventsDecoded[ch];
if( nDecoded == 0 ) continue;
2023-05-19 16:23:04 -04:00
for( int j = lastIndex - nDecoded + 1; j <= lastIndex; j ++){
hist[i][ch]->Fill( digi[i]->GetData()->Energy[ch][j]);
}
hist[i][ch]->UpdatePlot();
2023-05-19 16:23:04 -04:00
}
digiMTX[i].unlock();
2023-05-19 16:23:04 -04:00
}
}