change histogram2D with qcustomplot
This commit is contained in:
parent
c8a2912182
commit
c342f7c8e6
|
@ -1298,6 +1298,6 @@ void MainWindow::LogMsg(QString msg){
|
||||||
}
|
}
|
||||||
QScrollBar *v = logInfo->verticalScrollBar();
|
QScrollBar *v = logInfo->verticalScrollBar();
|
||||||
v->setValue(v->maximum());
|
v->setValue(v->maximum());
|
||||||
qDebug() << outputStr;
|
//qDebug() << outputStr;
|
||||||
logInfo->repaint();
|
logInfo->repaint();
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,11 +6,13 @@ TEMPLATE = app
|
||||||
TARGET = FSUDAQ_Qt6
|
TARGET = FSUDAQ_Qt6
|
||||||
INCLUDEPATH += .
|
INCLUDEPATH += .
|
||||||
|
|
||||||
#QT += core widgets charts webenginewidgets
|
QT += core widgets charts printsupport
|
||||||
QT += core widgets charts
|
|
||||||
|
|
||||||
QMAKE_CXXFLAGS += -g `root-config --cflags --glibs`
|
#QMAKE_CXXFLAGS += -g `root-config --cflags --glibs`
|
||||||
LIBS += -lCAENDigitizer -lcurl `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.
|
# You can make your code fail to compile if you use deprecated APIs.
|
||||||
# In order to do so, uncomment the following line.
|
# In order to do so, uncomment the following line.
|
||||||
|
@ -32,7 +34,8 @@ HEADERS += ClassData.h \
|
||||||
Scope.h \
|
Scope.h \
|
||||||
CanvasClass.h \
|
CanvasClass.h \
|
||||||
OnlineEventBuilder.h \
|
OnlineEventBuilder.h \
|
||||||
OnlineAnalyser.h
|
OnlineAnalyser.h \
|
||||||
|
qcustomplot.h
|
||||||
SOURCES += ClassDigitizer.cpp \
|
SOURCES += ClassDigitizer.cpp \
|
||||||
DigiSettingsPanel.cpp \
|
DigiSettingsPanel.cpp \
|
||||||
FSUDAQ.cpp \
|
FSUDAQ.cpp \
|
||||||
|
@ -41,4 +44,5 @@ SOURCES += ClassDigitizer.cpp \
|
||||||
Scope.cpp \
|
Scope.cpp \
|
||||||
CanvasClass.cpp \
|
CanvasClass.cpp \
|
||||||
OnlineEventBuilder.cpp \
|
OnlineEventBuilder.cpp \
|
||||||
OnlineAnalyser.cpp
|
OnlineAnalyser.cpp \
|
||||||
|
qcustomplot.cpp
|
||||||
|
|
|
@ -51,25 +51,19 @@ void OnlineAnalyzer::StopThread(){
|
||||||
|
|
||||||
void OnlineAnalyzer::SetUpCanvas(){
|
void OnlineAnalyzer::SetUpCanvas(){
|
||||||
|
|
||||||
//TODO a simple way to set it at once
|
h2 = new Histogram2D("testing", "x", "y", 100, 0, 4000, 100, 0, 4000, this);
|
||||||
h2 = new Histogram2D("testing", 0, 4000, 0, 4000);
|
layout->addWidget(h2);
|
||||||
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);
|
|
||||||
|
|
||||||
|
|
||||||
//Histogram * h1 = new Histogram("h1", 0, 5000, 200);
|
//Histogram * h1 = new Histogram("h1", 0, 5000, 200);
|
||||||
|
|
||||||
|
|
||||||
// std::random_device rd;
|
std::random_device rd;
|
||||||
// std::mt19937 gen(rd());
|
std::mt19937 gen(rd());
|
||||||
// std::normal_distribution<double> distribution(0.0, 2.0);
|
std::normal_distribution<double> distribution(2000.0, 500);
|
||||||
// for( int i = 0; i < 1000 ; i++ ){
|
for( int i = 0; i < 1000 ; i++ ){
|
||||||
// h2->Fill(distribution(gen), distribution(gen));
|
h2->Fill(distribution(gen), distribution(gen));
|
||||||
// }
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,7 +72,7 @@ void OnlineAnalyzer::UpdateHistograms(){
|
||||||
//Set with digitizer to be event build
|
//Set with digitizer to be event build
|
||||||
digiMTX[0].lock();
|
digiMTX[0].lock();
|
||||||
//digi[0]->GetData()->PrintAllData();
|
//digi[0]->GetData()->PrintAllData();
|
||||||
oeb[0]->BuildEvents(100, true);
|
oeb[0]->BuildEvents(100, false);
|
||||||
digiMTX[0].unlock();
|
digiMTX[0].unlock();
|
||||||
|
|
||||||
//============ Get events, and do analysis
|
//============ Get events, and do analysis
|
||||||
|
|
112
OnlineAnalyser.h
112
OnlineAnalyser.h
|
@ -29,59 +29,107 @@ derivative class should define the SetUpCanvas() and UpdateHistogram();
|
||||||
|
|
||||||
***************************************/
|
***************************************/
|
||||||
|
|
||||||
|
#include "qcustomplot.h"
|
||||||
#include <QScatterSeries>
|
|
||||||
|
|
||||||
//^==============================================
|
//^==============================================
|
||||||
//^==============================================
|
//^==============================================
|
||||||
class Histogram2D{ //TODO, cannot handle more then 3000 datapoint
|
class Histogram1D : public QCustomPlot{
|
||||||
public:
|
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->xMin = xMin;
|
||||||
this->xMax = xMax;
|
this->xMax = xMax;
|
||||||
this->yMin = yMin;
|
this->yMin = yMin;
|
||||||
this->yMax = yMax;
|
this->yMax = yMax;
|
||||||
|
this->xBin = xBin;
|
||||||
|
this->yBin = yBin;
|
||||||
|
|
||||||
plot = new RChart();
|
axisRect()->setupFullAxesBox(true);
|
||||||
scatterSeries = new QScatterSeries();
|
this->xAxis->setLabel(xLabel);
|
||||||
scatterSeries->setName(title);
|
this->yAxis->setLabel(yLabel);
|
||||||
scatterSeries->setMarkerShape(QScatterSeries::MarkerShapeCircle);
|
|
||||||
scatterSeries->setBorderColor(QColor(0,0,0,0));
|
|
||||||
scatterSeries->setMarkerSize(5.0);
|
|
||||||
|
|
||||||
plot->addSeries(scatterSeries);
|
colorMap = new QCPColorMap(this->xAxis, this->yAxis);
|
||||||
plot->createDefaultAxes();
|
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());
|
colorScale = new QCPColorScale(this);
|
||||||
xaxis->setRange(xMin, xMax);
|
this->plotLayout()->addElement(0, 1, colorScale);
|
||||||
|
colorScale->setType(QCPAxis::atRight);
|
||||||
|
colorMap->setColorScale(colorScale);
|
||||||
|
|
||||||
QValueAxis * yaxis = qobject_cast<QValueAxis*> (plot->axes(Qt::Vertical).first());
|
QCPColorGradient color;
|
||||||
yaxis->setRange(yMin, yMax);
|
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(){
|
void Fill(double x, double y){
|
||||||
delete scatterSeries;
|
int xIndex, yIndex;
|
||||||
delete plot;
|
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:
|
private:
|
||||||
double xMin, xMax, yMin, yMax;
|
double xMin, xMax, yMin, yMax;
|
||||||
|
int xBin, yBin;
|
||||||
|
|
||||||
RChart * plot;
|
QCPColorMap * colorMap;
|
||||||
QScatterSeries * scatterSeries;
|
QCPColorScale *colorScale;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -16,13 +16,15 @@ CAENCOmm_v1.5.3
|
||||||
|
|
||||||
CAENDigitizer_v2.17.1
|
CAENDigitizer_v2.17.1
|
||||||
|
|
||||||
|
CAEN A3818 Driver
|
||||||
|
|
||||||
`sudo apt install qt6-base-dev libcurl4-openssl-dev libqt6charts6-dev qt6-webengine-dev elog`
|
`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 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 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
|
# Compile
|
||||||
|
|
||||||
|
|
35529
qcustomplot.cpp
Normal file
35529
qcustomplot.cpp
Normal file
File diff suppressed because it is too large
Load Diff
7774
qcustomplot.h
Normal file
7774
qcustomplot.h
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user