Compare commits
No commits in common. "c8e032390a178ec5e6dcccac5d0c919ff7814927" and "0371f0c560ee00e3c0ba42ccf7cf77d8cfcfb7c0" have entirely different histories.
c8e032390a
...
0371f0c560
|
@ -234,7 +234,7 @@ public:
|
||||||
UpdatePlot();
|
UpdatePlot();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetXTitle(QString xTitle) { xAxis->setLabel(xTitle);}
|
void SetXTitle(QString xTitle) { xAxis->setLabel(xTitle); }
|
||||||
|
|
||||||
void Rebin(int xbin, double xmin, double xmax){
|
void Rebin(int xbin, double xmin, double xmax){
|
||||||
// DebugPrint("%s", "Histogram1D");
|
// DebugPrint("%s", "Histogram1D");
|
||||||
|
|
511
Histogram2D.h
511
Histogram2D.h
|
@ -19,16 +19,200 @@ const QList<QPair<QColor, QString>> colorCycle = { {QColor(Qt::red), "Red"},
|
||||||
class Histogram2D : public QCustomPlot{
|
class Histogram2D : public QCustomPlot{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Histogram2D(QString title, QString xLabel, QString yLabel, int xbin, double xmin, double xmax, int ybin, double ymin, double ymax, QWidget * parent = nullptr);
|
Histogram2D(QString title, QString xLabel, QString yLabel, int xbin, double xmin, double xmax, int ybin, double ymin, double ymax, QWidget * parent = nullptr) : QCustomPlot(parent){
|
||||||
|
// DebugPrint("%s", "Histogram2D");
|
||||||
|
for( int i = 0; i < 3; i ++ ){
|
||||||
|
for( int j = 0; j < 3; j ++ ){
|
||||||
|
box[i][j] = nullptr;
|
||||||
|
txt[i][j] = nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void SetXTitle(QString xTitle) { xAxis->setLabel(xTitle);}
|
isChannelMap = false;
|
||||||
void SetYTitle(QString yTitle) { yAxis->setLabel(yTitle);}
|
tickStep = 1; // only used when isChannelMap = true
|
||||||
|
isLogZ = false;
|
||||||
|
|
||||||
|
axisRect()->setupFullAxesBox(true);
|
||||||
|
xAxis->setLabel(xLabel);
|
||||||
|
yAxis->setLabel(yLabel);
|
||||||
|
|
||||||
|
colorMap = new QCPColorMap(xAxis, yAxis);
|
||||||
|
Rebin(xbin, xmin, xmax, ybin, ymin, ymax);
|
||||||
|
colorMap->setInterpolate(false);
|
||||||
|
|
||||||
|
QCPTextElement *titleEle = new QCPTextElement(this, title, QFont("sans", 12));
|
||||||
|
plotLayout()->insertRow(0);
|
||||||
|
plotLayout()->addElement(0, 0, titleEle);
|
||||||
|
|
||||||
|
colorScale = new QCPColorScale(this);
|
||||||
|
plotLayout()->addElement(1, 1, colorScale);
|
||||||
|
colorScale->setType(QCPAxis::atRight);
|
||||||
|
colorMap->setColorScale(colorScale);
|
||||||
|
|
||||||
|
|
||||||
|
QCPColorGradient color;
|
||||||
|
color.setNanHandling(QCPColorGradient::NanHandling::nhNanColor);
|
||||||
|
color.setNanColor(QColor("white"));
|
||||||
|
color.clearColorStops();
|
||||||
|
// color.setColorStopAt( 0.0, QColor("white" ));
|
||||||
|
color.setColorStopAt( 0.0, QColor("purple" ));
|
||||||
|
color.setColorStopAt( 0.2, QColor("blue"));
|
||||||
|
color.setColorStopAt( 0.4, QColor("cyan"));
|
||||||
|
color.setColorStopAt( 0.6, QColor("green"));
|
||||||
|
color.setColorStopAt( 0.8, QColor("yellow"));
|
||||||
|
color.setColorStopAt( 1.0, QColor("red"));
|
||||||
|
colorMap->setGradient(color);
|
||||||
|
|
||||||
|
double xPosStart = 0.02;
|
||||||
|
double xPosStep = 0.07;
|
||||||
|
double yPosStart = 0.02;
|
||||||
|
double yPosStep = 0.05;
|
||||||
|
|
||||||
|
for( int i = 0; i < 3; i ++ ){
|
||||||
|
for( int j = 0; j < 3; j ++ ){
|
||||||
|
box[i][j] = new QCPItemRect(this);
|
||||||
|
|
||||||
|
box[i][j]->topLeft->setType(QCPItemPosition::ptAxisRectRatio);
|
||||||
|
box[i][j]->topLeft->setCoords(xPosStart + xPosStep*i, yPosStart + yPosStep*j);
|
||||||
|
box[i][j]->bottomRight->setType(QCPItemPosition::ptAxisRectRatio);
|
||||||
|
box[i][j]->bottomRight->setCoords(xPosStart + xPosStep*(i+1), yPosStart + yPosStep*(j+1));
|
||||||
|
|
||||||
|
txt[i][j] = new QCPItemText(this);
|
||||||
|
txt[i][j]->setPositionAlignment(Qt::AlignLeft);
|
||||||
|
txt[i][j]->position->setType(QCPItemPosition::ptAxisRectRatio);
|
||||||
|
txt[i][j]->position->setCoords(xPosStart + xPosStep/2 + xPosStep*i, yPosStart + yPosStep*j);;
|
||||||
|
txt[i][j]->setText("0");
|
||||||
|
txt[i][j]->setFont(QFont("Helvetica", 9));
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
cutList.clear();
|
||||||
|
cutEntryList.clear();
|
||||||
|
|
||||||
|
rescaleAxes();
|
||||||
|
|
||||||
|
usingMenu = false;
|
||||||
|
isDrawCut = false;
|
||||||
|
tempCutID = -1;
|
||||||
|
numCut = 0;
|
||||||
|
lastPlottableID = -1;
|
||||||
|
|
||||||
|
line = new QCPItemLine(this);
|
||||||
|
line->setPen(QPen(Qt::gray, 1, Qt::DashLine));
|
||||||
|
line->setVisible(false);
|
||||||
|
|
||||||
|
isBusy = false;
|
||||||
|
|
||||||
|
connect(this, &QCustomPlot::mouseMove, this, [=](QMouseEvent *event){
|
||||||
|
double x = xAxis->pixelToCoord(event->pos().x());
|
||||||
|
double y = yAxis->pixelToCoord(event->pos().y());
|
||||||
|
int xI, yI;
|
||||||
|
colorMap->data()->coordToCell(x, y, &xI, &yI);
|
||||||
|
double z = colorMap->data()->cell(xI, yI);
|
||||||
|
|
||||||
|
QString coordinates = QString("X: %1, Y: %2, Z: %3").arg(x).arg(y).arg(z);
|
||||||
|
QToolTip::showText(event->globalPosition().toPoint(), coordinates, this);
|
||||||
|
|
||||||
|
//when drawing cut, show dashhed line
|
||||||
|
if( isDrawCut && tempCut.size() > 0 ){
|
||||||
|
line->end->setCoords(x,y);
|
||||||
|
line->setVisible(true);
|
||||||
|
replot();
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
connect(this, &QCustomPlot::mousePress, this, [=](QMouseEvent * event){
|
||||||
|
|
||||||
|
if (event->button() == Qt::LeftButton && !usingMenu && !isDrawCut){
|
||||||
|
setSelectionRectMode(QCP::SelectionRectMode::srmZoom);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (event->button() == Qt::LeftButton && isDrawCut){
|
||||||
|
|
||||||
|
oldMouseX = xAxis->pixelToCoord(event->pos().x());
|
||||||
|
oldMouseY = yAxis->pixelToCoord(event->pos().y());
|
||||||
|
|
||||||
|
tempCut.push_back(QPointF(oldMouseX,oldMouseY));
|
||||||
|
|
||||||
|
line->start->setCoords(oldMouseX, oldMouseY);
|
||||||
|
line->end->setCoords(oldMouseX, oldMouseY);
|
||||||
|
line->setVisible(true);
|
||||||
|
|
||||||
|
DrawCut();
|
||||||
|
}
|
||||||
|
|
||||||
|
//^================= right click
|
||||||
|
if (event->button() == Qt::RightButton) rightMouseClickMenu(event);
|
||||||
|
});
|
||||||
|
|
||||||
|
//connect( this, &QCustomPlot::mouseDoubleClick, this, [=](QMouseEvent *event){
|
||||||
|
connect( this, &QCustomPlot::mouseDoubleClick, this, [=](){
|
||||||
|
if( isDrawCut) {
|
||||||
|
tempCut.push_back(tempCut[0]);
|
||||||
|
DrawCut();
|
||||||
|
isDrawCut = false;
|
||||||
|
line->setVisible(false);
|
||||||
|
|
||||||
|
plottableIDList.push_back(plottableCount() -1 );
|
||||||
|
|
||||||
|
cutNameList.push_back("Cut-" + QString::number(cutList.count()));
|
||||||
|
cutEntryList.push_back(0);
|
||||||
|
|
||||||
|
QCPItemText * text = new QCPItemText(this);
|
||||||
|
text->setText(cutNameList.last());
|
||||||
|
text->position->setCoords(tempCut[0].rx(), tempCut[0].ry());
|
||||||
|
int colorID = tempCutID% colorCycle.count();
|
||||||
|
text->setColor(colorCycle[colorID].first);
|
||||||
|
cutTextIDList.push_back(itemCount() - 1);
|
||||||
|
|
||||||
|
replot();
|
||||||
|
|
||||||
|
cutList.push_back(tempCut);
|
||||||
|
cutIDList.push_back(tempCutID);
|
||||||
|
|
||||||
|
// qDebug() << "----------- end of create cut";
|
||||||
|
// qDebug() << " cutIDList " << cutIDList ;
|
||||||
|
// qDebug() << "plottableIDList " << plottableIDList << ", " << plottableCount();
|
||||||
|
// qDebug() << " cutTextIDList " << cutTextIDList << ", " << itemCount();
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
connect(this, &QCustomPlot::mouseRelease, this, [=](){
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
//^===================================
|
||||||
|
|
||||||
|
void SetXTitle(QString xTitle) { xAxis->setLabel(xTitle); }
|
||||||
|
void SetYTitle(QString yTitle) { yAxis->setLabel(yTitle); }
|
||||||
void Rebin(int xbin, double xmin, double xmax, int ybin, double ymin, double ymax);
|
void Rebin(int xbin, double xmin, double xmax, int ybin, double ymin, double ymax);
|
||||||
void RebinY(int ybin, double ymin, double ymax);
|
void RebinY(int ybin, double ymin, double ymax);
|
||||||
|
|
||||||
void SetChannelMap(bool onOff, int tickStep = 1) { isChannelMap = onOff; this->tickStep = tickStep;}
|
void SetChannelMap(bool onOff, int tickStep = 1) { isChannelMap = onOff; this->tickStep = tickStep;}
|
||||||
|
|
||||||
void UpdatePlot(){ colorMap->rescaleDataRange(); replot(); }
|
void UpdatePlot(){
|
||||||
|
// QCPColorGradient color;
|
||||||
|
// color.clearColorStops();
|
||||||
|
// color.setNanColor(QColor("white"));
|
||||||
|
// // color.setColorStopAt( 0.0, QColor("white" ));
|
||||||
|
// // color.setColorStopAt( 1.0/entry[1][1], QColor("purple" ));
|
||||||
|
// color.setColorStopAt( 0.0, QColor("purple" ));
|
||||||
|
// color.setColorStopAt( 0.2, QColor("blue"));
|
||||||
|
// color.setColorStopAt( 0.4, QColor("cyan"));
|
||||||
|
// color.setColorStopAt( 0.6, QColor("green"));
|
||||||
|
// color.setColorStopAt( 0.8, QColor("yellow"));
|
||||||
|
// color.setColorStopAt( 1.0, QColor("red"));
|
||||||
|
// colorMap->setGradient(color);
|
||||||
|
|
||||||
|
colorMap->rescaleDataRange();
|
||||||
|
|
||||||
|
replot();
|
||||||
|
}
|
||||||
|
|
||||||
void Clear(); // Clear Data and histrogram
|
void Clear(); // Clear Data and histrogram
|
||||||
|
|
||||||
void Fill(double x, double y);
|
void Fill(double x, double y);
|
||||||
|
@ -48,9 +232,6 @@ public:
|
||||||
double GetYMin() const {return yMin;}
|
double GetYMin() const {return yMin;}
|
||||||
double GetYMax() const {return yMax;}
|
double GetYMax() const {return yMax;}
|
||||||
|
|
||||||
void SaveCuts(QString cutFileName);
|
|
||||||
void LoadCuts(QString cutFileName);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
double xMin, xMax, yMin, yMax;
|
double xMin, xMax, yMin, yMax;
|
||||||
int xBin, yBin;
|
int xBin, yBin;
|
||||||
|
@ -71,15 +252,15 @@ private:
|
||||||
|
|
||||||
QPolygonF tempCut;
|
QPolygonF tempCut;
|
||||||
int tempCutID; // only incresing;
|
int tempCutID; // only incresing;
|
||||||
int numCut;
|
|
||||||
QList<QPolygonF> cutList;
|
QList<QPolygonF> cutList;
|
||||||
QList<QString> cutNameList; // name of the cut
|
QList<int> cutIDList;
|
||||||
QList<int> cutEntryList; // number of entry inside the cut.
|
int numCut;
|
||||||
QList<int> cutIDList; // ID of the cut
|
|
||||||
QList<int> cutTextIDList; //
|
|
||||||
QList<int> plottableIDList;
|
|
||||||
bool isDrawCut;
|
bool isDrawCut;
|
||||||
int lastPlottableID;
|
int lastPlottableID;
|
||||||
|
QList<int> cutTextIDList;
|
||||||
|
QList<int> plottableIDList;
|
||||||
|
QList<QString> cutNameList;
|
||||||
|
QList<int> cutEntryList;
|
||||||
|
|
||||||
QCPItemLine * line;
|
QCPItemLine * line;
|
||||||
double oldMouseX = 0.0, oldMouseY = 0.0;
|
double oldMouseX = 0.0, oldMouseY = 0.0;
|
||||||
|
@ -94,174 +275,6 @@ private:
|
||||||
//^###############################################
|
//^###############################################
|
||||||
//^###############################################
|
//^###############################################
|
||||||
|
|
||||||
inline Histogram2D::Histogram2D(QString title, QString xLabel, QString yLabel, int xbin, double xmin, double xmax, int ybin, double ymin, double ymax, QWidget * parent) : QCustomPlot(parent){
|
|
||||||
// DebugPrint("%s", "Histogram2D");
|
|
||||||
for( int i = 0; i < 3; i ++ ){
|
|
||||||
for( int j = 0; j < 3; j ++ ){
|
|
||||||
box[i][j] = nullptr;
|
|
||||||
txt[i][j] = nullptr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
isChannelMap = false;
|
|
||||||
tickStep = 1; // only used when isChannelMap = true
|
|
||||||
isLogZ = false;
|
|
||||||
|
|
||||||
axisRect()->setupFullAxesBox(true);
|
|
||||||
xAxis->setLabel(xLabel);
|
|
||||||
yAxis->setLabel(yLabel);
|
|
||||||
|
|
||||||
colorMap = new QCPColorMap(xAxis, yAxis);
|
|
||||||
Rebin(xbin, xmin, xmax, ybin, ymin, ymax);
|
|
||||||
colorMap->setInterpolate(false);
|
|
||||||
|
|
||||||
QCPTextElement *titleEle = new QCPTextElement(this, title, QFont("sans", 12));
|
|
||||||
plotLayout()->insertRow(0);
|
|
||||||
plotLayout()->addElement(0, 0, titleEle);
|
|
||||||
|
|
||||||
colorScale = new QCPColorScale(this);
|
|
||||||
plotLayout()->addElement(1, 1, colorScale);
|
|
||||||
colorScale->setType(QCPAxis::atRight);
|
|
||||||
colorMap->setColorScale(colorScale);
|
|
||||||
|
|
||||||
|
|
||||||
QCPColorGradient color;
|
|
||||||
color.setNanHandling(QCPColorGradient::NanHandling::nhNanColor);
|
|
||||||
color.setNanColor(QColor("white"));
|
|
||||||
color.clearColorStops();
|
|
||||||
// color.setColorStopAt( 0.0, QColor("white" ));
|
|
||||||
color.setColorStopAt( 0.0, QColor("purple" ));
|
|
||||||
color.setColorStopAt( 0.2, QColor("blue"));
|
|
||||||
color.setColorStopAt( 0.4, QColor("cyan"));
|
|
||||||
color.setColorStopAt( 0.6, QColor("green"));
|
|
||||||
color.setColorStopAt( 0.8, QColor("yellow"));
|
|
||||||
color.setColorStopAt( 1.0, QColor("red"));
|
|
||||||
colorMap->setGradient(color);
|
|
||||||
|
|
||||||
double xPosStart = 0.02;
|
|
||||||
double xPosStep = 0.07;
|
|
||||||
double yPosStart = 0.02;
|
|
||||||
double yPosStep = 0.05;
|
|
||||||
|
|
||||||
for( int i = 0; i < 3; i ++ ){
|
|
||||||
for( int j = 0; j < 3; j ++ ){
|
|
||||||
box[i][j] = new QCPItemRect(this);
|
|
||||||
|
|
||||||
box[i][j]->topLeft->setType(QCPItemPosition::ptAxisRectRatio);
|
|
||||||
box[i][j]->topLeft->setCoords(xPosStart + xPosStep*i, yPosStart + yPosStep*j);
|
|
||||||
box[i][j]->bottomRight->setType(QCPItemPosition::ptAxisRectRatio);
|
|
||||||
box[i][j]->bottomRight->setCoords(xPosStart + xPosStep*(i+1), yPosStart + yPosStep*(j+1));
|
|
||||||
|
|
||||||
txt[i][j] = new QCPItemText(this);
|
|
||||||
txt[i][j]->setPositionAlignment(Qt::AlignLeft);
|
|
||||||
txt[i][j]->position->setType(QCPItemPosition::ptAxisRectRatio);
|
|
||||||
txt[i][j]->position->setCoords(xPosStart + xPosStep/2 + xPosStep*i, yPosStart + yPosStep*j);;
|
|
||||||
txt[i][j]->setText("0");
|
|
||||||
txt[i][j]->setFont(QFont("Helvetica", 9));
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
cutList.clear();
|
|
||||||
cutEntryList.clear();
|
|
||||||
|
|
||||||
rescaleAxes();
|
|
||||||
|
|
||||||
usingMenu = false;
|
|
||||||
isDrawCut = false;
|
|
||||||
tempCutID = -1;
|
|
||||||
numCut = 0;
|
|
||||||
lastPlottableID = -1;
|
|
||||||
|
|
||||||
line = new QCPItemLine(this);
|
|
||||||
line->setPen(QPen(Qt::gray, 1, Qt::DashLine));
|
|
||||||
line->setVisible(false);
|
|
||||||
|
|
||||||
isBusy = false;
|
|
||||||
|
|
||||||
connect(this, &QCustomPlot::mouseMove, this, [=](QMouseEvent *event){
|
|
||||||
double x = xAxis->pixelToCoord(event->pos().x());
|
|
||||||
double y = yAxis->pixelToCoord(event->pos().y());
|
|
||||||
int xI, yI;
|
|
||||||
colorMap->data()->coordToCell(x, y, &xI, &yI);
|
|
||||||
double z = colorMap->data()->cell(xI, yI);
|
|
||||||
|
|
||||||
QString coordinates = QString("X: %1, Y: %2, Z: %3").arg(x).arg(y).arg(z);
|
|
||||||
QToolTip::showText(event->globalPosition().toPoint(), coordinates, this);
|
|
||||||
|
|
||||||
//when drawing cut, show dashhed line
|
|
||||||
if( isDrawCut && tempCut.size() > 0 ){
|
|
||||||
line->end->setCoords(x,y);
|
|
||||||
line->setVisible(true);
|
|
||||||
replot();
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
connect(this, &QCustomPlot::mousePress, this, [=](QMouseEvent * event){
|
|
||||||
|
|
||||||
if (event->button() == Qt::LeftButton && !usingMenu && !isDrawCut){
|
|
||||||
setSelectionRectMode(QCP::SelectionRectMode::srmZoom);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (event->button() == Qt::LeftButton && isDrawCut){
|
|
||||||
|
|
||||||
oldMouseX = xAxis->pixelToCoord(event->pos().x());
|
|
||||||
oldMouseY = yAxis->pixelToCoord(event->pos().y());
|
|
||||||
|
|
||||||
tempCut.push_back(QPointF(oldMouseX,oldMouseY));
|
|
||||||
|
|
||||||
line->start->setCoords(oldMouseX, oldMouseY);
|
|
||||||
line->end->setCoords(oldMouseX, oldMouseY);
|
|
||||||
line->setVisible(true);
|
|
||||||
|
|
||||||
DrawCut();
|
|
||||||
}
|
|
||||||
|
|
||||||
//^================= right click
|
|
||||||
if (event->button() == Qt::RightButton) rightMouseClickMenu(event);
|
|
||||||
});
|
|
||||||
|
|
||||||
//connect( this, &QCustomPlot::mouseDoubleClick, this, [=](QMouseEvent *event){
|
|
||||||
connect( this, &QCustomPlot::mouseDoubleClick, this, [=](){
|
|
||||||
if( isDrawCut) {
|
|
||||||
tempCut.push_back(tempCut[0]);
|
|
||||||
DrawCut();
|
|
||||||
isDrawCut = false;
|
|
||||||
line->setVisible(false);
|
|
||||||
|
|
||||||
plottableIDList.push_back(plottableCount() -1 );
|
|
||||||
|
|
||||||
cutNameList.push_back("Cut-" + QString::number(cutList.count()));
|
|
||||||
cutEntryList.push_back(0);
|
|
||||||
|
|
||||||
QCPItemText * text = new QCPItemText(this);
|
|
||||||
text->setText(cutNameList.last());
|
|
||||||
text->position->setCoords(tempCut[0].rx(), tempCut[0].ry());
|
|
||||||
int colorID = tempCutID% colorCycle.count();
|
|
||||||
text->setColor(colorCycle[colorID].first);
|
|
||||||
cutTextIDList.push_back(itemCount() - 1);
|
|
||||||
|
|
||||||
replot();
|
|
||||||
|
|
||||||
cutList.push_back(tempCut);
|
|
||||||
cutIDList.push_back(tempCutID);
|
|
||||||
|
|
||||||
// qDebug() << "----------- end of create cut";
|
|
||||||
// qDebug() << " cutIDList " << cutIDList ;
|
|
||||||
// qDebug() << "plottableIDList " << plottableIDList << ", " << plottableCount();
|
|
||||||
// qDebug() << " cutTextIDList " << cutTextIDList << ", " << itemCount();
|
|
||||||
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
connect(this, &QCustomPlot::mouseRelease, this, [=](){
|
|
||||||
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
inline void Histogram2D::Fill(double x, double y){
|
inline void Histogram2D::Fill(double x, double y){
|
||||||
// DebugPrint("%s", "Histogram2D");
|
// DebugPrint("%s", "Histogram2D");
|
||||||
if( isBusy ) return;
|
if( isBusy ) return;
|
||||||
|
@ -378,7 +391,7 @@ inline void Histogram2D::ClearAllCuts(){
|
||||||
inline void Histogram2D::PrintCutEntry() const{
|
inline void Histogram2D::PrintCutEntry() const{
|
||||||
DebugPrint("%s", "Histogram2D");
|
DebugPrint("%s", "Histogram2D");
|
||||||
if( numCut == 0 ) return;
|
if( numCut == 0 ) return;
|
||||||
printf("=============== There are %d cuts. (%lld, %lld)\n", numCut, cutList.count(), cutEntryList.count());
|
printf("=============== There are %d cuts.\n", numCut);
|
||||||
for( int i = 0; i < cutList.count(); i++){
|
for( int i = 0; i < cutList.count(); i++){
|
||||||
if( cutList[i].isEmpty() ) continue;
|
if( cutList[i].isEmpty() ) continue;
|
||||||
printf("%10s | %d \n", cutNameList[i].toStdString().c_str(), cutEntryList[i]);
|
printf("%10s | %d \n", cutNameList[i].toStdString().c_str(), cutEntryList[i]);
|
||||||
|
@ -410,7 +423,7 @@ inline void Histogram2D::DrawCut(){
|
||||||
}
|
}
|
||||||
replot();
|
replot();
|
||||||
|
|
||||||
// qDebug() << "Plottable count : " << plottableCount() << ", cutList.count :" << cutList.count() << ", cutID :" << lastPlottableID;
|
//qDebug() << "Plottable count : " << plottableCount() << ", cutList.count :" << cutList.count() << ", cutID :" << lastPlottableID;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void Histogram2D::rightMouseClickMenu(QMouseEvent * event){
|
inline void Histogram2D::rightMouseClickMenu(QMouseEvent * event){
|
||||||
|
@ -426,11 +439,8 @@ inline void Histogram2D::rightMouseClickMenu(QMouseEvent * event){
|
||||||
QAction * a2 = menu->addAction("Clear hist.");
|
QAction * a2 = menu->addAction("Clear hist.");
|
||||||
QAction * a3 = menu->addAction("Toggle Stat.");
|
QAction * a3 = menu->addAction("Toggle Stat.");
|
||||||
QAction * a4 = menu->addAction("Rebin (clear histogram)");
|
QAction * a4 = menu->addAction("Rebin (clear histogram)");
|
||||||
QAction * a8 = menu->addAction("Load Cut(s)");
|
|
||||||
QAction * a5 = menu->addAction("Create a Cut");
|
QAction * a5 = menu->addAction("Create a Cut");
|
||||||
QAction * a7 = nullptr;
|
|
||||||
if( numCut > 0 ) {
|
if( numCut > 0 ) {
|
||||||
a7 = menu->addAction("Save Cut(s)");
|
|
||||||
menu->addSeparator();
|
menu->addSeparator();
|
||||||
menu->addAction("Add/Edit names to Cuts");
|
menu->addAction("Add/Edit names to Cuts");
|
||||||
menu->addAction("Clear all Cuts");
|
menu->addAction("Clear all Cuts");
|
||||||
|
@ -565,27 +575,6 @@ inline void Histogram2D::rightMouseClickMenu(QMouseEvent * event){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( selectedAction == a8 ){ // load Cuts
|
|
||||||
QString filePath = QFileDialog::getOpenFileName(this,
|
|
||||||
"Load Cuts from File",
|
|
||||||
QDir::homePath(),
|
|
||||||
"Text file (*.txt)");
|
|
||||||
|
|
||||||
if (!filePath.isEmpty()) LoadCuts(filePath);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
if( selectedAction == a7 ){ // Save Cuts
|
|
||||||
|
|
||||||
QString filePath = QFileDialog::getSaveFileName(this,
|
|
||||||
"Save Cuts to File",
|
|
||||||
QDir::homePath(),
|
|
||||||
"Text file (*.txt)");
|
|
||||||
|
|
||||||
if (!filePath.isEmpty()) SaveCuts(filePath);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -685,113 +674,5 @@ inline void Histogram2D::rightMouseClickRebin(){
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void Histogram2D::SaveCuts(QString cutFileName){
|
|
||||||
|
|
||||||
QFile file(cutFileName);
|
|
||||||
if (file.open(QIODevice::WriteOnly | QIODevice::Text)) {
|
|
||||||
QTextStream out(&file);
|
|
||||||
|
|
||||||
// Define the text to write
|
|
||||||
QStringList lines;
|
|
||||||
|
|
||||||
for( int i = 0; i < cutList.size(); i++){
|
|
||||||
lines << "====== "+ cutNameList[i];
|
|
||||||
for( int pt = 0 ; pt < cutList[i].size(); pt ++){
|
|
||||||
lines << QString::number(cutList[i][pt].rx(), 'g', 5) + "," + QString::number(cutList[i][pt].ry(), 'g', 5);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
lines << "#===== End of File";
|
|
||||||
|
|
||||||
// Write each line to the file
|
|
||||||
for (const QString &line : lines) out << line << "\n";
|
|
||||||
|
|
||||||
// Close the file
|
|
||||||
file.close();
|
|
||||||
qDebug() << "File written successfully to" << cutFileName;
|
|
||||||
}else{
|
|
||||||
qWarning() << "Unable to open file" << cutFileName;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void Histogram2D::LoadCuts(QString cutFileName){
|
|
||||||
|
|
||||||
QFile file(cutFileName);
|
|
||||||
QString cutNameTemp;
|
|
||||||
|
|
||||||
// Open the file in read mode
|
|
||||||
if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
|
||||||
QTextStream in(&file);
|
|
||||||
|
|
||||||
ClearAllCuts();
|
|
||||||
tempCut.clear();
|
|
||||||
|
|
||||||
// Read each line and append to the QStringList
|
|
||||||
|
|
||||||
while (!in.atEnd()) {
|
|
||||||
QString line = in.readLine();
|
|
||||||
|
|
||||||
if( line.contains("======") ){
|
|
||||||
if( !tempCut.isEmpty() ) {
|
|
||||||
DrawCut();
|
|
||||||
plottableIDList.push_back(plottableCount() -1 );
|
|
||||||
cutNameList.push_back(cutNameTemp);
|
|
||||||
cutEntryList.push_back(0);
|
|
||||||
QCPItemText * text = new QCPItemText(this);
|
|
||||||
text->setText(cutNameList.last());
|
|
||||||
text->position->setCoords(tempCut[0].rx(), tempCut[0].ry());
|
|
||||||
int colorID = tempCutID% colorCycle.count();
|
|
||||||
text->setColor(colorCycle[colorID].first);
|
|
||||||
cutTextIDList.push_back(itemCount() - 1);
|
|
||||||
// cutList.push_back(tempCut);
|
|
||||||
cutIDList.push_back(tempCutID);
|
|
||||||
}
|
|
||||||
tempCut.clear();
|
|
||||||
tempCutID ++;
|
|
||||||
numCut ++;
|
|
||||||
|
|
||||||
int spacePos = line.indexOf(' ');
|
|
||||||
cutNameTemp = line.mid(spacePos + 1);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if( line.contains("#==") ) {
|
|
||||||
DrawCut();
|
|
||||||
plottableIDList.push_back(plottableCount() -1 );
|
|
||||||
cutNameList.push_back(cutNameTemp);
|
|
||||||
cutEntryList.push_back(0);
|
|
||||||
QCPItemText * text = new QCPItemText(this);
|
|
||||||
text->setText(cutNameList.last());
|
|
||||||
text->position->setCoords(tempCut[0].rx(), tempCut[0].ry());
|
|
||||||
int colorID = tempCutID% colorCycle.count();
|
|
||||||
text->setColor(colorCycle[colorID].first);
|
|
||||||
cutTextIDList.push_back(itemCount() - 1);
|
|
||||||
cutList.push_back(tempCut);
|
|
||||||
cutIDList.push_back(tempCutID);
|
|
||||||
break;
|
|
||||||
}else{
|
|
||||||
QStringList haha = line.split(",");
|
|
||||||
// qDebug() << haha;
|
|
||||||
tempCut.push_back(QPointF(haha[0].toFloat(), haha[1].toFloat()));
|
|
||||||
DrawCut();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// Close the file
|
|
||||||
file.close();
|
|
||||||
qDebug() << "File read successfully from" << cutFileName;
|
|
||||||
|
|
||||||
// PrintCutEntry();
|
|
||||||
// DrawCut();
|
|
||||||
replot();
|
|
||||||
|
|
||||||
} else {
|
|
||||||
qWarning() << "Unable to open file" << cutFileName;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
|
@ -25,9 +25,12 @@ public:
|
||||||
dataBaseName = "testing";
|
dataBaseName = "testing";
|
||||||
|
|
||||||
allowSignalSlot = false;
|
allowSignalSlot = false;
|
||||||
|
printf("------------------- dasjkdsaldj\n");
|
||||||
SetUpCanvas();
|
SetUpCanvas();
|
||||||
|
|
||||||
|
printf("------------------- dasjkdsaldj###########\n");
|
||||||
LoadHistRange();
|
LoadHistRange();
|
||||||
|
printf("------------------- dasjkdsaldj##&&&&&&&&&#\n");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,7 +84,6 @@ private:
|
||||||
|
|
||||||
inline void CoincidentAnalyzer::SetUpCanvas(){
|
inline void CoincidentAnalyzer::SetUpCanvas(){
|
||||||
|
|
||||||
setWindowTitle("Online Coincident Analyzer");
|
|
||||||
setGeometry(0, 0, 1600, 1000);
|
setGeometry(0, 0, 1600, 1000);
|
||||||
|
|
||||||
{//^====== magnet and reaction setting
|
{//^====== magnet and reaction setting
|
||||||
|
@ -141,13 +143,12 @@ inline void CoincidentAnalyzer::SetUpCanvas(){
|
||||||
SetBackwardBuild(true, sbBackwardCount->value());
|
SetBackwardBuild(true, sbBackwardCount->value());
|
||||||
});
|
});
|
||||||
|
|
||||||
QLabel * lbBuildWindow = new QLabel("Event Window [ns]", this);
|
QLabel * lbBuildWindow = new QLabel("Event Window [tick]", this);
|
||||||
lbBuildWindow->setAlignment(Qt::AlignRight | Qt::AlignCenter);
|
lbBuildWindow->setAlignment(Qt::AlignRight | Qt::AlignCenter);
|
||||||
boxLayout->addWidget(lbBuildWindow, 2, 1);
|
boxLayout->addWidget(lbBuildWindow, 2, 1);
|
||||||
sbBuildWindow = new RSpinBox(this, 0);
|
sbBuildWindow = new RSpinBox(this, 0);
|
||||||
sbBuildWindow->setMinimum(1);
|
sbBuildWindow->setMinimum(1);
|
||||||
sbBuildWindow->setMaximum(9999999999);
|
sbBuildWindow->setMaximum(9999999999);
|
||||||
sbBuildWindow->setValue(1000);
|
|
||||||
boxLayout->addWidget(sbBuildWindow, 2, 2);
|
boxLayout->addWidget(sbBuildWindow, 2, 2);
|
||||||
|
|
||||||
connect(sbBuildWindow, &RSpinBox::valueChanged, this, [=](){
|
connect(sbBuildWindow, &RSpinBox::valueChanged, this, [=](){
|
||||||
|
@ -312,11 +313,11 @@ inline void CoincidentAnalyzer::SetUpCanvas(){
|
||||||
}
|
}
|
||||||
|
|
||||||
//============ histograms
|
//============ histograms
|
||||||
hMulti = new Histogram1D("Multiplicity", "", 16, 0, 16, this);
|
hMulti = new Histogram1D("Multiplicity", "", 10, 0, 10, this);
|
||||||
layout->addWidget(hMulti, 0, 1);
|
layout->addWidget(hMulti, 0, 1);
|
||||||
|
|
||||||
// the "this" make the histogram a child of the SplitPole class. When SplitPole destory, all childs destory as well.
|
// the "this" make the histogram a child of the SplitPole class. When SplitPole destory, all childs destory as well.
|
||||||
h2D = new Histogram2D("Coincident Plot", "XXX", "YYY", 200, 0, 30000, 200, 0, 30000, this);
|
h2D = new Histogram2D("Coincident Plot", "XXX", "YYY", 100, 0, 5000, 100, 0, 5000, this);
|
||||||
//layout is inheriatge from Analyzer
|
//layout is inheriatge from Analyzer
|
||||||
layout->addWidget(h2D, 1, 0, 2, 1);
|
layout->addWidget(h2D, 1, 0, 2, 1);
|
||||||
|
|
||||||
|
@ -328,16 +329,17 @@ inline void CoincidentAnalyzer::SetUpCanvas(){
|
||||||
h2D->SetYTitle("Digi-" + QString::number(digi[bd]->GetSerialNumber()) + ", Ch-" + QString::number(ch));
|
h2D->SetYTitle("Digi-" + QString::number(digi[bd]->GetSerialNumber()) + ", Ch-" + QString::number(ch));
|
||||||
h2D->UpdatePlot();
|
h2D->UpdatePlot();
|
||||||
|
|
||||||
h1 = new Histogram1D("1D Plot", "XXX", 300, 0, 30000, this);
|
h1 = new Histogram1D("1D Plot", "XXX", 300, 0, 5000, this);
|
||||||
h1->SetColor(Qt::darkGreen);
|
h1->SetColor(Qt::darkGreen);
|
||||||
// h1->AddDataList("Test", Qt::red); // add another histogram in h1, Max Data List is 10
|
h1->AddDataList("Test", Qt::red); // add another histogram in h1, Max Data List is 10
|
||||||
bd = aDigi->currentData().toInt();
|
bd = aDigi->currentData().toInt();
|
||||||
ch = aCh->currentData().toInt();
|
ch = aCh->currentData().toInt();
|
||||||
|
printf("%d\n", digi[bd]->GetSerialNumber());
|
||||||
h1->SetXTitle("Digi-" + QString::number(digi[bd]->GetSerialNumber()) + ", Ch-" + QString::number(ch));
|
h1->SetXTitle("Digi-" + QString::number(digi[bd]->GetSerialNumber()) + ", Ch-" + QString::number(ch));
|
||||||
h1->UpdatePlot();
|
h1->UpdatePlot();
|
||||||
layout->addWidget(h1, 1, 1);
|
layout->addWidget(h1, 1, 1);
|
||||||
|
|
||||||
h1g = new Histogram1D("1D Plot (PID gated)", "XXX", 300, 0, 30000, this);
|
h1g = new Histogram1D("1D Plot (PID gated)", "XXX", 300, 0, 5000, this);
|
||||||
h1g->SetXTitle("Digi-" + QString::number(digi[bd]->GetSerialNumber()) + ", Ch-" + QString::number(ch));
|
h1g->SetXTitle("Digi-" + QString::number(digi[bd]->GetSerialNumber()) + ", Ch-" + QString::number(ch));
|
||||||
h1g->UpdatePlot();
|
h1g->UpdatePlot();
|
||||||
layout->addWidget(h1g, 2, 1);
|
layout->addWidget(h1g, 2, 1);
|
||||||
|
@ -345,8 +347,6 @@ inline void CoincidentAnalyzer::SetUpCanvas(){
|
||||||
layout->setColumnStretch(0, 1);
|
layout->setColumnStretch(0, 1);
|
||||||
layout->setColumnStretch(1, 1);
|
layout->setColumnStretch(1, 1);
|
||||||
|
|
||||||
allowSignalSlot = true;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void CoincidentAnalyzer::UpdateHistograms(){
|
inline void CoincidentAnalyzer::UpdateHistograms(){
|
||||||
|
@ -376,10 +376,6 @@ inline void CoincidentAnalyzer::UpdateHistograms(){
|
||||||
int y_bd = yDigi->currentData().toInt();
|
int y_bd = yDigi->currentData().toInt();
|
||||||
int y_ch = yCh->currentData().toInt();
|
int y_ch = yCh->currentData().toInt();
|
||||||
|
|
||||||
int a_sn = digi[a_bd]->GetSerialNumber();
|
|
||||||
int x_sn = digi[x_bd]->GetSerialNumber();
|
|
||||||
int y_sn = digi[y_bd]->GetSerialNumber();
|
|
||||||
|
|
||||||
//============ Processing data and fill histograms
|
//============ Processing data and fill histograms
|
||||||
long eventIndex = evtbder->eventIndex;
|
long eventIndex = evtbder->eventIndex;
|
||||||
long eventStart = eventIndex - eventBuilt + 1;
|
long eventStart = eventIndex - eventBuilt + 1;
|
||||||
|
@ -396,16 +392,16 @@ inline void CoincidentAnalyzer::UpdateHistograms(){
|
||||||
unsigned long long xT = 0;
|
unsigned long long xT = 0;
|
||||||
for( int k = 0; k < (int) event.size(); k++ ){
|
for( int k = 0; k < (int) event.size(); k++ ){
|
||||||
//event[k].Print();
|
//event[k].Print();
|
||||||
if( event[k].sn == a_sn && event[k].ch == a_ch) {
|
if( event[k].sn == a_bd && event[k].ch == a_ch) {
|
||||||
h1->Fill(event[k].energy);
|
h1->Fill(event[k].energy);
|
||||||
aE = event[k].energy;
|
aE = event[k].energy;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( event[k].sn == x_sn && event[k].ch == x_ch) {
|
if( event[k].sn == x_bd && event[k].ch == x_ch) {
|
||||||
xE = event[k].energy;
|
xE = event[k].energy;
|
||||||
xT = event[k].timestamp;
|
xT = event[k].timestamp;
|
||||||
}
|
}
|
||||||
if( event[k].sn == y_sn && event[k].ch == y_ch) yE = event[k].energy;
|
if( event[k].sn == y_bd && event[k].ch == y_ch) yE = event[k].energy;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( xE >= 0 && yE >= 0 ) h2D->Fill(xE, yE);
|
if( xE >= 0 && yE >= 0 ) h2D->Fill(xE, yE);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user