2023-05-26 18:06:37 -04:00
|
|
|
#ifndef ONLINE_ANALYZER_H
|
|
|
|
#define ONLINE_ANALYZER_H
|
|
|
|
|
|
|
|
#include <QMainWindow>
|
|
|
|
#include <QChart>
|
|
|
|
#include <QChartView>
|
|
|
|
#include <QLabel>
|
|
|
|
#include <QPushButton>
|
|
|
|
#include <QCheckBox>
|
|
|
|
#include <QLineEdit>
|
|
|
|
#include <QGridLayout>
|
|
|
|
#include <QGroupBox>
|
|
|
|
|
|
|
|
#include "macro.h"
|
|
|
|
#include "ClassDigitizer.h"
|
|
|
|
#include "CustomThreads.h"
|
|
|
|
#include "CustomWidgets.h"
|
|
|
|
#include "OnlineEventBuilder.h"
|
|
|
|
|
|
|
|
/**************************************
|
|
|
|
|
|
|
|
This class is for, obviously, Online analysis.
|
|
|
|
|
|
|
|
It provides essential event building, histograms, and filling.
|
|
|
|
|
|
|
|
This is the mother of all other derivative analysis class.
|
|
|
|
|
|
|
|
derivative class should define the SetUpCanvas() and UpdateHistogram();
|
|
|
|
|
|
|
|
***************************************/
|
|
|
|
|
2023-05-30 13:57:45 -04:00
|
|
|
#include "qcustomplot.h"
|
2023-05-26 18:06:37 -04:00
|
|
|
|
|
|
|
//^==============================================
|
|
|
|
//^==============================================
|
2023-05-30 13:57:45 -04:00
|
|
|
class Histogram1D : public QCustomPlot{
|
2023-05-26 18:06:37 -04:00
|
|
|
public:
|
2023-05-30 13:57:45 -04:00
|
|
|
Histogram1D(QString title, QString xLabel, int xBin, double xMin, double xMax, QWidget * parent = nullptr) : QCustomPlot(parent){
|
|
|
|
this->xMin = xMin;
|
|
|
|
this->xMax = xMax;
|
|
|
|
this->xBin = xBin;
|
|
|
|
|
|
|
|
this->xAxis->setLabel(xLabel);
|
|
|
|
|
|
|
|
bars = new QCPBars(this->xAxis, this->yAxis);
|
|
|
|
bars->setWidth((xMax- xMin)/xBin);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
double xMin, xMax, xBin;
|
2023-05-26 18:06:37 -04:00
|
|
|
|
2023-05-30 13:57:45 -04:00
|
|
|
QCPBars *bars;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
//^==============================================
|
|
|
|
//^==============================================
|
|
|
|
class Histogram2D : public QCustomPlot{
|
|
|
|
public:
|
|
|
|
Histogram2D(QString title, QString xLabel, QString yLabel, int xBin, double xMin, double xMax, int yBin, double yMin, double yMax, QWidget * parent = nullptr) : QCustomPlot(parent){
|
2023-05-26 18:06:37 -04:00
|
|
|
this->xMin = xMin;
|
|
|
|
this->xMax = xMax;
|
|
|
|
this->yMin = yMin;
|
|
|
|
this->yMax = yMax;
|
2023-05-30 13:57:45 -04:00
|
|
|
this->xBin = xBin;
|
|
|
|
this->yBin = yBin;
|
2023-05-26 18:06:37 -04:00
|
|
|
|
2023-05-30 13:57:45 -04:00
|
|
|
axisRect()->setupFullAxesBox(true);
|
|
|
|
this->xAxis->setLabel(xLabel);
|
|
|
|
this->yAxis->setLabel(yLabel);
|
2023-05-26 18:06:37 -04:00
|
|
|
|
2023-05-30 13:57:45 -04:00
|
|
|
colorMap = new QCPColorMap(this->xAxis, this->yAxis);
|
|
|
|
colorMap->data()->setSize(xBin, yBin);
|
|
|
|
colorMap->data()->setRange(QCPRange(xMin, xMax), QCPRange(yMin, yMax));
|
|
|
|
colorMap->setInterpolate(false);
|
2023-05-26 18:06:37 -04:00
|
|
|
|
2023-05-30 13:57:45 -04:00
|
|
|
colorScale = new QCPColorScale(this);
|
|
|
|
this->plotLayout()->addElement(0, 1, colorScale);
|
|
|
|
colorScale->setType(QCPAxis::atRight);
|
|
|
|
colorMap->setColorScale(colorScale);
|
2023-05-26 18:06:37 -04:00
|
|
|
|
2023-05-30 13:57:45 -04:00
|
|
|
QCPColorGradient color;
|
|
|
|
color.clearColorStops();
|
|
|
|
color.setColorStopAt( 0, QColor("white" ));
|
|
|
|
color.setColorStopAt( 1, QColor("blue"));
|
|
|
|
colorMap->setGradient(color);
|
2023-05-26 18:06:37 -04:00
|
|
|
|
2023-05-30 13:57:45 -04:00
|
|
|
this->rescaleAxes();
|
|
|
|
|
|
|
|
connect(this, &QCustomPlot::mouseMove, this, [=](QMouseEvent *event){
|
|
|
|
double x = this->xAxis->pixelToCoord(event->pos().x());
|
|
|
|
double y = this->yAxis->pixelToCoord(event->pos().y());
|
|
|
|
int xI, yI;
|
|
|
|
colorMap->data()->coordToCell(x, y, &xI, &yI);
|
|
|
|
double z = colorMap->data()->cell(xI, yI);
|
|
|
|
|
|
|
|
// Format the coordinates as desired
|
|
|
|
QString coordinates = QString("X: %1, Y: %2, Z: %3").arg(x).arg(y).arg(z);
|
|
|
|
|
|
|
|
// Show the coordinates as a tooltip
|
|
|
|
QToolTip::showText(event->globalPosition().toPoint(), coordinates, this);
|
|
|
|
});
|
2023-05-26 18:06:37 -04:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2023-05-30 13:57:45 -04:00
|
|
|
void Fill(double x, double y){
|
|
|
|
int xIndex, yIndex;
|
|
|
|
colorMap->data()->coordToCell(x, y, &xIndex, &yIndex);
|
|
|
|
//printf("%d %d\n", xIndex, yIndex);
|
|
|
|
if( xIndex < 0 || xBin < xIndex || yIndex < 0 || yBin < yIndex ) return;
|
|
|
|
double value = colorMap->data()->cell(xIndex, yIndex);
|
|
|
|
colorMap->data()->setCell(xIndex, yIndex, value + 1);
|
|
|
|
|
|
|
|
// rescale the data dimension (color) such that all data points lie in the span visualized by the color gradient:
|
|
|
|
colorMap->rescaleDataRange();
|
|
|
|
|
|
|
|
// make sure the axis rect and color scale synchronize their bottom and top margins (so they line up):
|
|
|
|
// QCPMarginGroup *marginGroup = new QCPMarginGroup(this);
|
|
|
|
// this->axisRect()->setMarginGroup(QCP::msBottom|QCP::msTop, marginGroup);
|
|
|
|
// colorScale->setMarginGroup(QCP::msBottom|QCP::msTop, marginGroup);
|
|
|
|
|
|
|
|
// rescale the key (x) and value (y) axes so the whole color map is visible:
|
|
|
|
this->rescaleAxes();
|
2023-05-26 18:06:37 -04:00
|
|
|
|
2023-05-30 13:57:45 -04:00
|
|
|
}
|
2023-05-26 18:06:37 -04:00
|
|
|
|
|
|
|
private:
|
|
|
|
double xMin, xMax, yMin, yMax;
|
2023-05-30 13:57:45 -04:00
|
|
|
int xBin, yBin;
|
2023-05-26 18:06:37 -04:00
|
|
|
|
2023-05-30 13:57:45 -04:00
|
|
|
QCPColorMap * colorMap;
|
|
|
|
QCPColorScale *colorScale;
|
2023-05-26 18:06:37 -04:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
//^==============================================
|
|
|
|
//^==============================================
|
|
|
|
class OnlineAnalyzer : public QMainWindow{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
OnlineAnalyzer(Digitizer ** digi, unsigned int nDigi, QMainWindow * parent = nullptr);
|
|
|
|
virtual ~OnlineAnalyzer();
|
|
|
|
|
|
|
|
virtual void SetUpCanvas();
|
|
|
|
|
|
|
|
public slots:
|
|
|
|
void StartThread();
|
|
|
|
void StopThread();
|
|
|
|
|
|
|
|
private slots:
|
|
|
|
|
|
|
|
virtual void UpdateHistograms(); // where event-building, analysis, and ploting
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
Digitizer ** digi;
|
|
|
|
unsigned short nDigi;
|
|
|
|
|
|
|
|
OnlineEventBuilder ** oeb;
|
|
|
|
TimingThread * buildTimerThread;
|
|
|
|
|
|
|
|
QGridLayout * layout;
|
|
|
|
|
2023-05-30 10:08:39 -04:00
|
|
|
//======================== custom histograms
|
|
|
|
Histogram2D * h2;
|
|
|
|
|
2023-05-26 18:06:37 -04:00
|
|
|
};
|
|
|
|
#endif
|