added rebin Histogram1D by right click

This commit is contained in:
splitPoleDAQ 2023-06-05 19:06:07 -04:00
parent 37fdeaedbc
commit 02d5964de7
2 changed files with 71 additions and 2 deletions

View File

@ -6,6 +6,7 @@
//^==============================================
//^==============================================
class Histogram1D : public QCustomPlot{
Q_OBJECT
public:
Histogram1D(QString title, QString xLabel, int xbin, double xmin, double xmax, QWidget * parent = nullptr) : QCustomPlot(parent){
Rebin(xbin, xmin, xmax);
@ -78,8 +79,7 @@ public:
QAction * a1 = menu.addAction("UnZoom");
QAction * a2 = menu.addAction("Clear hist.");
QAction * a3 = menu.addAction("Toggle Stat.");
//TODO rebin
QAction * a4 = menu.addAction("Rebin (clear histogram)");
//TODO fitGuass
QAction *selectedAction = menu.exec(event->globalPosition().toPoint());
@ -104,6 +104,65 @@ public:
replot();
usingMenu = false;
}
if( selectedAction == a4 ){
QDialog dialog(this);
dialog.setWindowTitle("Rebin histogram");
QFormLayout layout(&dialog);
layout.setAlignment(Qt::AlignRight);
QLabel * info = new QLabel(&dialog);
info->setStyleSheet("color:red;");
info->setText("This will also clear histogram!!");
layout.addRow(info);
QStringList nameList = {"Num. Bin", "x-Min", "x-Max"};
QLineEdit* lineEdit[3];
for (int i = 0; i < 3; ++i) {
lineEdit[i] = new QLineEdit(&dialog);
layout.addRow(nameList[i] + " : ", lineEdit[i]);
}
QLabel * msg = new QLabel(&dialog);
msg->setStyleSheet("color:red;");
layout.addRow(msg);
QDialogButtonBox buttonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, &dialog);
layout.addRow(&buttonBox);
double number[3];
QObject::connect(&buttonBox, &QDialogButtonBox::accepted, [&]() {
int OKcount = 0;
bool conversionOk = true;
for( int i = 0; i < 3; i++ ){
number[i] = lineEdit[i]->text().toDouble(&conversionOk);
if( conversionOk ){
OKcount++;
}else{
msg->setText(nameList[i] + " is invalid.");
return;
}
}
if( OKcount == 3 ) {
if( number[2] > number[1] ) {
dialog.accept();
}else{
msg->setText(nameList[2] + " is smaller than " + nameList[1]);
}
}
});
QObject::connect(&buttonBox, &QDialogButtonBox::rejected, [&]() { dialog.reject();});
if( dialog.exec() == QDialog::Accepted ){
Rebin((int)number[0], number[1], number[2]);
emit ReBinned();
UpdatePlot();
}
}
}
});
@ -187,6 +246,9 @@ public:
}
}
signals:
void ReBinned(); //ONLY for right click rebin
private:
double xMin, xMax, dX;
int xBin;

View File

@ -121,6 +121,13 @@ SingleSpectra::SingleSpectra(Digitizer ** digi, unsigned int nDigi, QString rawD
for( int j = 0; j < digi[i]->GetNChannels(); j++){
if( i < nDigi ) {
hist[i][j] = new Histogram1D("Digi-" + QString::number(digi[i]->GetSerialNumber()) +", Ch-" + QString::number(j), "Raw Energy [ch]", nBin, xMin, xMax);
connect(hist[i][j], &Histogram1D::ReBinned , this, [=](){
enableSignalSlot = false;
sbNBin->setValue(hist[i][j]->GetNBin());
sbXMin->setValue(hist[i][j]->GetXMin());
sbXMax->setValue(hist[i][j]->GetXMax());
enableSignalSlot = true;
});
}else{
hist[i][j] = nullptr;
}