change histogram2D with qcustomplot

This commit is contained in:
splitPoleDAQ 2023-05-30 13:57:45 -04:00
parent c8a2912182
commit c342f7c8e6
7 changed files with 43406 additions and 55 deletions

View File

@ -1298,6 +1298,6 @@ void MainWindow::LogMsg(QString msg){
}
QScrollBar *v = logInfo->verticalScrollBar();
v->setValue(v->maximum());
qDebug() << outputStr;
//qDebug() << outputStr;
logInfo->repaint();
}

View File

@ -6,11 +6,13 @@ TEMPLATE = app
TARGET = FSUDAQ_Qt6
INCLUDEPATH += .
#QT += core widgets charts webenginewidgets
QT += core widgets charts
QT += core widgets charts printsupport
QMAKE_CXXFLAGS += -g `root-config --cflags --glibs`
LIBS += -lCAENDigitizer -lcurl `root-config --cflags --glibs`
#QMAKE_CXXFLAGS += -g `root-config --cflags --glibs`
#LIBS += -lCAENDigitizer -lcurl `root-config --cflags --glibs`
QMAKE_CXXFLAGS += -g
LIBS += -lCAENDigitizer -lcurl
# You can make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
@ -32,7 +34,8 @@ HEADERS += ClassData.h \
Scope.h \
CanvasClass.h \
OnlineEventBuilder.h \
OnlineAnalyser.h
OnlineAnalyser.h \
qcustomplot.h
SOURCES += ClassDigitizer.cpp \
DigiSettingsPanel.cpp \
FSUDAQ.cpp \
@ -41,4 +44,5 @@ SOURCES += ClassDigitizer.cpp \
Scope.cpp \
CanvasClass.cpp \
OnlineEventBuilder.cpp \
OnlineAnalyser.cpp
OnlineAnalyser.cpp \
qcustomplot.cpp

View File

@ -51,25 +51,19 @@ void OnlineAnalyzer::StopThread(){
void OnlineAnalyzer::SetUpCanvas(){
//TODO a simple way to set it at once
h2 = new Histogram2D("testing", 0, 4000, 0, 4000);
RChartView * h2View = new RChartView(h2->GetChart());
h2->SetMarkerSize(2);
h2View->SetVRange(0, 4000); // this only set the reset key 'r'
h2View->SetHRange(0, 4000);
layout->addWidget(h2View);
h2 = new Histogram2D("testing", "x", "y", 100, 0, 4000, 100, 0, 4000, this);
layout->addWidget(h2);
//Histogram * h1 = new Histogram("h1", 0, 5000, 200);
// std::random_device rd;
// std::mt19937 gen(rd());
// std::normal_distribution<double> distribution(0.0, 2.0);
// for( int i = 0; i < 1000 ; i++ ){
// h2->Fill(distribution(gen), distribution(gen));
// }
std::random_device rd;
std::mt19937 gen(rd());
std::normal_distribution<double> distribution(2000.0, 500);
for( int i = 0; i < 1000 ; i++ ){
h2->Fill(distribution(gen), distribution(gen));
}
}
@ -78,7 +72,7 @@ void OnlineAnalyzer::UpdateHistograms(){
//Set with digitizer to be event build
digiMTX[0].lock();
//digi[0]->GetData()->PrintAllData();
oeb[0]->BuildEvents(100, true);
oeb[0]->BuildEvents(100, false);
digiMTX[0].unlock();
//============ Get events, and do analysis

View File

@ -29,59 +29,107 @@ derivative class should define the SetUpCanvas() and UpdateHistogram();
***************************************/
#include <QScatterSeries>
#include "qcustomplot.h"
//^==============================================
//^==============================================
class Histogram2D{ //TODO, cannot handle more then 3000 datapoint
class Histogram1D : public QCustomPlot{
public:
Histogram2D(QString title, double xMin, double xMax, double yMin, double yMax){
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;
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){
this->xMin = xMin;
this->xMax = xMax;
this->yMin = yMin;
this->yMax = yMax;
this->xBin = xBin;
this->yBin = yBin;
plot = new RChart();
scatterSeries = new QScatterSeries();
scatterSeries->setName(title);
scatterSeries->setMarkerShape(QScatterSeries::MarkerShapeCircle);
scatterSeries->setBorderColor(QColor(0,0,0,0));
scatterSeries->setMarkerSize(5.0);
axisRect()->setupFullAxesBox(true);
this->xAxis->setLabel(xLabel);
this->yAxis->setLabel(yLabel);
plot->addSeries(scatterSeries);
plot->createDefaultAxes();
colorMap = new QCPColorMap(this->xAxis, this->yAxis);
colorMap->data()->setSize(xBin, yBin);
colorMap->data()->setRange(QCPRange(xMin, xMax), QCPRange(yMin, yMax));
colorMap->setInterpolate(false);
QValueAxis * xaxis = qobject_cast<QValueAxis*> (plot->axes(Qt::Horizontal).first());
xaxis->setRange(xMin, xMax);
colorScale = new QCPColorScale(this);
this->plotLayout()->addElement(0, 1, colorScale);
colorScale->setType(QCPAxis::atRight);
colorMap->setColorScale(colorScale);
QValueAxis * yaxis = qobject_cast<QValueAxis*> (plot->axes(Qt::Vertical).first());
yaxis->setRange(yMin, yMax);
QCPColorGradient color;
color.clearColorStops();
color.setColorStopAt( 0, QColor("white" ));
color.setColorStopAt( 1, QColor("blue"));
colorMap->setGradient(color);
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);
});
}
~Histogram2D(){
delete scatterSeries;
delete plot;
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();
}
double GetXMin() const {return xMin;}
double GetXMax() const {return xMax;}
double GetyMin() const {return yMin;}
double GetyMax() const {return yMax;}
RChart * GetChart() {return plot;}
void SetMarkerColor(QColor color) { scatterSeries->setColor(color); }
void SetMarkerSize(qreal size) { scatterSeries->setMarkerSize(size);}
void Clear(){ scatterSeries->clear();}
void Fill(double x, double y) { scatterSeries->append(x, y); }
private:
double xMin, xMax, yMin, yMax;
int xBin, yBin;
RChart * plot;
QScatterSeries * scatterSeries;
QCPColorMap * colorMap;
QCPColorScale *colorScale;
};

View File

@ -16,13 +16,15 @@ CAENCOmm_v1.5.3
CAENDigitizer_v2.17.1
CAEN A3818 Driver
`sudo apt install qt6-base-dev libcurl4-openssl-dev libqt6charts6-dev qt6-webengine-dev elog`
The elog installed using apt is 3.1.3. If a higher version is needed. Please go to https://elog.psi.ch/elog/
The libcurl4 is need for pushing data to InfluxDB v1.8
The QCustomPlot (https://www.qcustomplot.com/index.php/introduction) source files are already included in the repository.
# Compile

35529
qcustomplot.cpp Normal file

File diff suppressed because it is too large Load Diff

7774
qcustomplot.h Normal file

File diff suppressed because it is too large Load Diff