add Toggle line display on histogram 1D

This commit is contained in:
Ryan Tang 2024-08-20 12:22:26 -04:00
parent a58ddbc6d4
commit 6faeaf7c9b
2 changed files with 65 additions and 20 deletions

View File

@ -15,6 +15,8 @@ public:
// DebugPrint("%s", "Histogram1D"); // DebugPrint("%s", "Histogram1D");
isLogY = false; isLogY = false;
for( int i = 0; i < MaxNHist; i++ ) showHist[i] = true;
for( int i = 0; i < 3; i ++) txt[i] = nullptr; for( int i = 0; i < 3; i ++) txt[i] = nullptr;
nData = 1; nData = 1;
Rebin(xbin, xmin, xmax); Rebin(xbin, xmin, xmax);
@ -86,12 +88,15 @@ public:
QAction * a1 = menu.addAction("UnZoom"); QAction * a1 = menu.addAction("UnZoom");
QAction * a5 = menu.addAction("Set/UnSet Log-y"); QAction * a5 = menu.addAction("Set/UnSet Log-y");
QAction * a6 = nullptr;
if( nData > 1 ) a6 = menu.addAction("Toggle lines display");
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)");
//TODO fitGuass //TODO fitGuass
QAction *selectedAction = menu.exec(event->globalPosition().toPoint()); QAction *selectedAction = menu.exec(event->globalPosition().toPoint());
//*========================================== UnZoom
if( selectedAction == a1 ){ if( selectedAction == a1 ){
xAxis->setRangeLower(xMin); xAxis->setRangeLower(xMin);
xAxis->setRangeUpper(xMax); xAxis->setRangeUpper(xMax);
@ -101,11 +106,13 @@ public:
usingMenu = false; usingMenu = false;
} }
//*========================================== Clear Hist
if( selectedAction == a2 ){ if( selectedAction == a2 ){
Clear(); Clear();
usingMenu = false; usingMenu = false;
} }
//*========================================== Toggle Stat.
if( selectedAction == a3 ){ if( selectedAction == a3 ){
for( int i = 0; i < 3; i++){ for( int i = 0; i < 3; i++){
txt[i]->setVisible( !txt[i]->visible()); txt[i]->setVisible( !txt[i]->visible());
@ -113,6 +120,7 @@ public:
replot(); replot();
usingMenu = false; usingMenu = false;
} }
//*========================================== Rebin
if( selectedAction == a4 ){ if( selectedAction == a4 ){
QDialog dialog(this); QDialog dialog(this);
dialog.setWindowTitle("Rebin histogram"); dialog.setWindowTitle("Rebin histogram");
@ -145,25 +153,25 @@ public:
double number[3]; double number[3];
QObject::connect(&buttonBox, &QDialogButtonBox::accepted, [&]() { QObject::connect(&buttonBox, &QDialogButtonBox::accepted, [&]() {
int OKcount = 0; int OKcount = 0;
bool conversionOk = true; bool conversionOk = true;
for( int i = 0; i < 3; i++ ){ for( int i = 0; i < 3; i++ ){
number[i] = lineEdit[i]->text().toDouble(&conversionOk); number[i] = lineEdit[i]->text().toDouble(&conversionOk);
if( conversionOk ){ if( conversionOk ){
OKcount++; OKcount++;
}else{ }else{
msg->setText(nameList[i] + " is invalid."); msg->setText(nameList[i] + " is invalid.");
return; return;
}
} }
}
if( OKcount == 3 ) { if( OKcount == 3 ) {
if( number[2] > number[1] ) { if( number[2] > number[1] ) {
dialog.accept(); dialog.accept();
}else{ }else{
msg->setText(nameList[2] + " is smaller than " + nameList[1]); msg->setText(nameList[2] + " is smaller than " + nameList[1]);
}
} }
}
}); });
QObject::connect(&buttonBox, &QDialogButtonBox::rejected, [&]() { dialog.reject();}); QObject::connect(&buttonBox, &QDialogButtonBox::rejected, [&]() { dialog.reject();});
@ -174,8 +182,38 @@ public:
} }
} }
if( selectedAction == a5 ){
//*========================================== Toggle line Display
if( selectedAction == a6 ){
QDialog dialog(this);
dialog.setWindowTitle("Toggle lines Display");
QFormLayout layout(&dialog);
QCheckBox ** cbline = new QCheckBox *[nData];
for( int i = 0; i < nData; i++ ){
cbline[i] = new QCheckBox(graph(i)->name(), &dialog);
layout.addRow(cbline[i]);
if( showHist[i] ) cbline[i]->setChecked(true);
}
QDialogButtonBox buttonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, &dialog);
layout.addRow(&buttonBox);
QObject::connect(&buttonBox, &QDialogButtonBox::accepted, [&]() {
for( int i = 0; i < nData; i++ ){
showHist[i] = cbline[i]->isChecked();
}
dialog.accept();
});
QObject::connect(&buttonBox, &QDialogButtonBox::rejected, [&]() { dialog.reject();});
if( dialog.exec() == QDialog::Accepted ){
UpdatePlot();
}
}
//*========================================== Set Log y
if( selectedAction == a5 ){
if( !isLogY ){ if( !isLogY ){
this->yAxis->setScaleType(QCPAxis::stLogarithmic); this->yAxis->setScaleType(QCPAxis::stLogarithmic);
isLogY = true; isLogY = true;
@ -211,7 +249,10 @@ public:
void UpdatePlot(){ void UpdatePlot(){
DebugPrint("%s", "Histogram1D"); DebugPrint("%s", "Histogram1D");
for( int ID = 0 ; ID < nData; ID ++) graph(ID)->setData(xList, yList[ID]); for( int ID = 0 ; ID < nData; ID ++) {
graph(ID)->setVisible(showHist[ID]);
graph(ID)->setData(xList, yList[ID]);
}
xAxis->setRangeLower(xMin); xAxis->setRangeLower(xMin);
xAxis->setRangeUpper(xMax); xAxis->setRangeUpper(xMax);
yAxis->setRangeLower(0); yAxis->setRangeLower(0);
@ -324,6 +365,8 @@ private:
bool usingMenu; bool usingMenu;
bool showHist[MaxNHist];
}; };

View File

@ -212,7 +212,7 @@ SingleSpectra::SingleSpectra(Digitizer ** digi, unsigned int nDigi, QString rawD
if( i < nDigi ) { if( i < nDigi ) {
hist[i][j] = new Histogram1D("Digi-" + QString::number(digi[i]->GetSerialNumber()) +", Ch-" + QString::number(j), "Raw Energy [ch]", nBin, eMin, eMax); hist[i][j] = new Histogram1D("Digi-" + QString::number(digi[i]->GetSerialNumber()) +", Ch-" + QString::number(j), "Raw Energy [ch]", nBin, eMin, eMax);
if( digi[i]->GetDPPType() == DPPTypeCode::DPP_PSD_CODE ){ if( digi[i]->GetDPPType() == DPPTypeCode::DPP_PSD_CODE ){
hist[i][j]->AddDataList("Long Energy", Qt::green); hist[i][j]->AddDataList("Short Energy", Qt::green);
} }
}else{ }else{
hist[i][j] = nullptr; hist[i][j] = nullptr;
@ -367,7 +367,9 @@ void SingleSpectra::FillHistograms(){
hist[ID][ch]->Fill( data ); hist[ID][ch]->Fill( data );
if( digi[i]->GetDPPType() == DPPTypeCode::DPP_PSD_CODE ){ if( digi[i]->GetDPPType() == DPPTypeCode::DPP_PSD_CODE ){
hist[ID][ch]->Fill( digi[ID]->GetData()->GetEnergy2(ch, lastFilledIndex[ID][ch]), 1); uShort e2 = digi[ID]->GetData()->GetEnergy2(ch, lastFilledIndex[ID][ch]);
// printf("%u \n", e2);
hist[ID][ch]->Fill( e2, 1);
} }
hist2D[ID]->Fill(ch, data); hist2D[ID]->Fill(ch, data);
} }