add software Trapezoide filter, updated SplitPoleAnalyzer UI

This commit is contained in:
carina@hades 2023-10-23 12:53:51 -04:00
parent f1e6034128
commit b1d0253e4f
5 changed files with 137 additions and 23 deletions

View File

@ -28,10 +28,22 @@ public:
~MainWindow();
void closeEvent(QCloseEvent * event){
if( scope ) scope->close();
if( digiSettings ) digiSettings->close();
if( canvas ) canvas->close();
if( onlineAnalyzer ) onlineAnalyzer->close();
if( scope ) {
delete scope;
scope = nullptr;
}
if( digiSettings ) {
delete digiSettings;
digiSettings = nullptr;
}
if( canvas ) {
delete canvas;
canvas = nullptr;
}
if( onlineAnalyzer ) {
delete onlineAnalyzer;
onlineAnalyzer = nullptr;
}
event->accept();
}

View File

@ -6,6 +6,44 @@
#include <QStandardItemModel>
#include <QLabel>
QVector<QPointF> Scope::TrapezoidFilter(QVector<QPointF> data, int baseLineEndS, int riseTimeS, int flatTopS, float decayTime_ns){
QVector<QPointF> trapezoid;
trapezoid.clear();
///find baseline;
double baseline = 0;
for( int i = 0; i < baseLineEndS; i++){
baseline += data[i].y();
}
baseline = baseline*1./baseLineEndS;
int length = data.size();
double pn = 0.;
double sn = 0.;
for( int i = 0; i < length ; i++){
double dlk = data[i].y() - baseline;
if( i - riseTimeS >= 0 ) dlk -= data[i - riseTimeS].y() - baseline;
if( i - flatTopS - riseTimeS >= 0 ) dlk -= data[i - flatTopS - riseTimeS].y() - baseline;
if( i - flatTopS - 2*riseTimeS >= 0) dlk += data[i - flatTopS - 2*riseTimeS].y() - baseline;
if( i == 0 ){
pn = dlk;
sn = pn + dlk*decayTime_ns;
}else{
pn = pn + dlk;
sn = sn + pn + dlk*decayTime_ns;
}
trapezoid.append(QPointF(data[i].x(), sn / decayTime_ns / riseTimeS));
}
return trapezoid;
}
Scope::Scope(Digitizer ** digi, unsigned int nDigi, ReadDataThread ** readDataThread, QMainWindow * parent) : QMainWindow(parent){
@ -29,6 +67,31 @@ Scope::Scope(Digitizer ** digi, unsigned int nDigi, ReadDataThread ** readDataTh
plot->addSeries(dataTrace[i]);
}
// testing software trapezoid filter
// FILE * fileIn = fopen("wave.txt", "r");
// if( fileIn != nullptr ){
// char buf[500];
// int v1, v2;
// QVector<QPointF> points;
// QVector<QPointF> points1;
// while( fgets(buf, sizeof(buf), fileIn) != nullptr ){
// if (sscanf(buf, "%d, %d", &v1, &v2) == 2) {
// points.append(QPointF(v1, v2 + 7000));
// }
// }
// fclose(fileIn);
// points1 = TrapezoidFilter(points, 400/16, 100, 200, 1000);
// dataTrace[0]->replace(points);
// dataTrace[1]->replace(points1);
// }
dataTrace[0]->setPen(QPen(Qt::red, 2));
dataTrace[1]->setPen(QPen(Qt::blue, 2));
dataTrace[2]->setPen(QPen(Qt::darkYellow, 1));
@ -955,7 +1018,7 @@ void Scope::UpdateSpinBox(RSpinBox * &sb, const Reg para){
void Scope::UpdatePanelFromMomeory(){
enableSignalSlot = false;
printf("==== %s \n", __func__);
printf("==== Scope::%s \n", __func__);
int ch = cbScopeCh->currentIndex();

View File

@ -37,6 +37,8 @@ public:
event->accept();
}
QVector<QPointF> TrapezoidFilter(QVector<QPointF> data, int baseLineEndS, int riseTimeS, int flatTopS, float decayTime_ns );
public slots:
void StartScope();
void StopScope();

View File

@ -51,7 +51,9 @@ public:
hit.CalZoffset(sbBfield->value());
hit.Clear();
FillConstants();
hit.ClearData();
}
@ -92,11 +94,14 @@ private:
QLineEdit * leGSRho;
QLineEdit * leZoffset;
RSpinBox * sbRhoOffset;
RSpinBox * sbRhoScale;
};
inline void SplitPole::FillConstants(){
leQValue->setText(QString::number(hit.GetQ0()));
leGSRho->setText(QString::number(hit.GetRho0()));
leGSRho->setText(QString::number(hit.GetRho0()*1000));
leZoffset->setText(QString::number(hit.GetZoffset()));
}
@ -211,34 +216,66 @@ inline void SplitPole::SetUpCanvas(){
boxLayout->addWidget(runAnalyzer, 4, 1);
QFrame *separator = new QFrame(box);
separator->setFrameShape(QFrame::HLine);
separator->setFrameShadow(QFrame::Sunken);
boxLayout->addWidget(separator, 5, 0, 1, 4);
QLabel * lbMassTablePath = new QLabel("Mass Table Path : ", box);
lbMassTablePath->setAlignment(Qt::AlignRight | Qt::AlignCenter);
boxLayout->addWidget(lbMassTablePath, 5, 0);
boxLayout->addWidget(lbMassTablePath, 6, 0);
leMassTablePath = new QLineEdit(QString::fromStdString(massData),box);
leMassTablePath->setEnabled(false);
boxLayout->addWidget(leMassTablePath, 5, 1, 1, 3);
leMassTablePath->setReadOnly(true);
boxLayout->addWidget(leMassTablePath, 6, 1, 1, 3);
QLabel * lbQValue = new QLabel("Q-Value [MeV] ", box);
lbQValue->setAlignment(Qt::AlignRight | Qt::AlignCenter);
boxLayout->addWidget(lbQValue, 6, 0);
boxLayout->addWidget(lbQValue, 7, 0);
leQValue = new QLineEdit(box);
leQValue->setEnabled(false);
boxLayout->addWidget(leQValue, 6, 1);
leQValue->setReadOnly(true);
boxLayout->addWidget(leQValue, 7, 1);
QLabel * lbGDRho = new QLabel("G.S. Rho [mm] ", box);
lbGDRho->setAlignment(Qt::AlignRight | Qt::AlignCenter);
boxLayout->addWidget(lbGDRho, 6, 2);
boxLayout->addWidget(lbGDRho, 7, 2);
leGSRho = new QLineEdit(box);
leGSRho->setEnabled(false);
boxLayout->addWidget(leGSRho, 6, 3);
leGSRho->setReadOnly(true);
boxLayout->addWidget(leGSRho, 7, 3);
QLabel * lbZoffset = new QLabel("Z-offset [mm] ", box);
lbZoffset->setAlignment(Qt::AlignRight | Qt::AlignCenter);
boxLayout->addWidget(lbZoffset, 7, 0);
boxLayout->addWidget(lbZoffset, 8, 0);
leZoffset = new QLineEdit(box);
leZoffset->setEnabled(false);
boxLayout->addWidget(leZoffset, 7, 1);
leZoffset->setReadOnly(true);
boxLayout->addWidget(leZoffset, 8, 1);
QFrame *separator1 = new QFrame(box);
separator1->setFrameShape(QFrame::HLine);
separator1->setFrameShadow(QFrame::Sunken);
boxLayout->addWidget(separator1, 9, 0, 1, 4);
QLabel * lbRhoOffset = new QLabel("Rho-offset [mm] ", box);
lbRhoOffset->setAlignment(Qt::AlignRight | Qt::AlignCenter);
boxLayout->addWidget(lbRhoOffset, 10, 0);
sbRhoOffset = new RSpinBox(box);
sbRhoOffset->setDecimals(2);
sbRhoOffset->setSingleStep(1);
sbRhoOffset->setValue(0);
boxLayout->addWidget(sbRhoOffset, 10, 1);
QLabel * lbRhoScale = new QLabel("Rho-Scaling ", box);
lbRhoScale->setAlignment(Qt::AlignRight | Qt::AlignCenter);
boxLayout->addWidget(lbRhoScale, 10, 2);
sbRhoScale = new RSpinBox(box);
sbRhoScale->setDecimals(2);
sbRhoScale->setSingleStep(0.01);
sbRhoScale->setMinimum(0.5);
sbRhoScale->setMaximum(1.5);
sbRhoScale->setValue(1.0);
boxLayout->addWidget(sbRhoScale, 10, 3);
}
//============ histograms
@ -255,7 +292,7 @@ inline void SplitPole::SetUpCanvas(){
h1->AddDataList("Test", Qt::red); // add another histogram in h1, Max Data List is 10
layout->addWidget(h1, 1, 1);
h1g = new Histogram1D("Spectrum (gated)", "x", 300, 30, 70, this);
h1g = new Histogram1D("Spectrum (PID gated)", "Ex", 300, -2, 10, this);
layout->addWidget(h1g, 2, 1);
layout->setColumnStretch(0, 1);
@ -293,7 +330,7 @@ inline void SplitPole::UpdateHistograms(){
//if( event.size() < 9 ) return;
if( event.size() == 0 ) return;
hit.Clear();
hit.ClearData();
for( int k = 0; k < (int) event.size(); k++ ){
//event[k].Print();

View File

@ -61,7 +61,7 @@ class SplitPoleHit{
public:
SplitPoleHit(){
Clear();
ClearData();
}
unsigned int eSR; unsigned long long tSR;
@ -163,7 +163,7 @@ public:
}
void Clear(){
void ClearData(){
eSR = 0; tSR = 0;
eSL = 0; tSL = 0;
eFR = 0; tFR = 0;