diff --git a/Analyser.cpp b/Analyser.cpp index 17b91c9..11b2aaa 100644 --- a/Analyser.cpp +++ b/Analyser.cpp @@ -35,6 +35,7 @@ Analyzer::~Analyzer(){ } void Analyzer::StartThread(){ + for( unsigned int i = 0; i < nDigi; i++) oeb[i]->ClearEvents(); buildTimerThread->start(); } @@ -56,17 +57,16 @@ void Analyzer::SetUpCanvas(){ h1 = new Histogram1D("testing", "x", 400, 0, 4000, this); layout->addWidget(h1, 0, 1); - std::random_device rd; - std::mt19937 gen(rd()); - std::normal_distribution distribution(2000.0, 1000); - for( int i = 0; i < 1000 ; i++ ){ - double x = distribution(gen); - double y = distribution(gen); - h2->Fill(x, y); - h1->Fill(x); - } - - h1->UpdatePlot(); + // std::random_device rd; + // std::mt19937 gen(rd()); + // std::normal_distribution distribution(2000.0, 1000); + // for( int i = 0; i < 1000 ; i++ ){ + // double x = distribution(gen); + // double y = distribution(gen); + // h2->Fill(x, y); + // h1->Fill(x); + // } + // h1->UpdatePlot(); } @@ -74,7 +74,7 @@ void Analyzer::UpdateHistograms(){ //Set with digitizer to be event build digiMTX[0].lock(); - oeb[0]->BuildEvents(100, false); + oeb[0]->BuildEvents(100, true); digiMTX[0].unlock(); //============ Get events, and do analysis @@ -92,15 +92,18 @@ void Analyzer::UpdateHistograms(){ std::vector event = oeb[0]->events[i]; for( int k = 0; k < (int) event.size(); k++ ){ - if( event[k].ch == 3 ) e1 = event[k].energy; - if( event[k].ch == 4 ) e2 = event[k].energy; + if( event[k].ch == 9 ) e1 = event[k].energy; + if( event[k].ch == 10 ) e2 = event[k].energy; } h2->Fill(e1, e2); - - //h1->Fill(e1); + h1->Fill(e1); } h2->UpdatePlot(); + h1->UpdatePlot(); + + h2->PrintCutEntry(); + } \ No newline at end of file diff --git a/ClassData.h b/ClassData.h index 0f8ef12..cb00466 100644 --- a/ClassData.h +++ b/ClassData.h @@ -14,7 +14,7 @@ #include "CAENDigitizerType.h" #include "macro.h" -#define MaxNData 10000 /// store 10k events per channels +#define MaxNData 50 /// store 10k events per channels class Data{ @@ -37,8 +37,10 @@ class Data{ /// store data for event building and deduce the trigger rate. //it is a circular memory bool IsNotRollOverFakeAgg; + int LoopIndex[MaxNChannels]; /// number of loop in the circular memory int DataIndex[MaxNChannels]; + unsigned long long Timestamp[MaxNChannels][MaxNData]; /// 47 bit unsigned short fineTime[MaxNChannels][MaxNData]; /// 10 bits, in unit of ch2ns / 1000 = ps unsigned short Energy[MaxNChannels][MaxNData]; /// 15 bit @@ -68,7 +70,7 @@ class Data{ void PrintStat() const; - void PrintAllData() const; + void PrintAllData(bool tableMode = true) const; //^================= Saving data bool OpenSaveFile(std::string fileNamePrefix); // return false when fail @@ -84,6 +86,7 @@ class Data{ unsigned int nw; //bool SaveWaveToMemory; + ///for temperary std::vector tempWaveform1; std::vector tempWaveform2; @@ -225,6 +228,8 @@ inline void Data::SaveData(){ return; } + if( outFile == nullptr ) return; + if( outFileSize > (unsigned int) MaxSaveFileSize){ FinishedOutFilesSize += ftell(outFile); CloseSaveFile(); @@ -263,14 +268,44 @@ inline void Data::PrintStat() const{ printf("---+--------+-----------+-----------+----------\n"); } -inline void Data::PrintAllData() const{ +inline void Data::PrintAllData(bool tableMode) const{ printf("============================= Print Data\n"); - for( int ch = 0; ch < MaxNChannels ; ch++){ - if( DataIndex[ch] < 0 ) continue; - printf("------------ ch : %d, DataIndex : %d, loop : %d\n", ch, DataIndex[ch], LoopIndex[ch]); - for( int ev = 0; ev <= (LoopIndex[ch] > 0 ? MaxNData : DataIndex[ch]) ; ev++){ - if( DPPType == V1730_DPP_PHA_CODE ) printf("%4d, %5u, %15llu, %5u \n", ev, Energy[ch][ev], Timestamp[ch][ev], fineTime[ch][ev]); - if( DPPType == V1730_DPP_PSD_CODE ) printf("%4d, %5u, %5u, %15llu, %5u \n", ev, Energy[ch][ev], Energy2[ch][ev], Timestamp[ch][ev], fineTime[ch][ev]); + + if( tableMode ){ + int entry = 0; + + int MaxEntry = 0; + printf("%4s|", ""); + for( int ch = 0; ch < MaxNChannels; ch++){ + if( LoopIndex[ch] > 0 ) { + MaxEntry = MaxNData-1; + }else{ + if( DataIndex[ch] > MaxEntry ) MaxEntry = DataIndex[ch]; + } + if( DataIndex[ch] < 0 ) continue; + printf(" %5s-%02d,%-9d |", "ch", ch, DataIndex[ch]); + } + printf("\n"); + + + do{ + printf("%4d|", entry ); + for( int ch = 0; ch < MaxNChannels; ch++){ + if( DataIndex[ch] < 0 ) continue; + printf(" %5d,%12lld |", Energy[ch][entry], Timestamp[ch][entry]); + } + printf("\n"); + entry ++; + }while(entry <= MaxEntry); + + }else{ + for( int ch = 0; ch < MaxNChannels ; ch++){ + if( DataIndex[ch] < 0 ) continue; + printf("------------ ch : %d, DataIndex : %d, loop : %d\n", ch, DataIndex[ch], LoopIndex[ch]); + for( int ev = 0; ev <= (LoopIndex[ch] > 0 ? MaxNData : DataIndex[ch]) ; ev++){ + if( DPPType == V1730_DPP_PHA_CODE ) printf("%4d, %5u, %15llu, %5u \n", ev, Energy[ch][ev], Timestamp[ch][ev], fineTime[ch][ev]); + if( DPPType == V1730_DPP_PSD_CODE ) printf("%4d, %5u, %5u, %15llu, %5u \n", ev, Energy[ch][ev], Energy2[ch][ev], Timestamp[ch][ev], fineTime[ch][ev]); + } } } } @@ -616,7 +651,7 @@ inline int Data::DecodePHADualChannelBlock(unsigned int ChannelMask, bool fastDe if( rollOver == 0 ) { // non-time roll over fake event DataIndex[channel] ++; - if( DataIndex[channel] > MaxNData ) { + if( DataIndex[channel] >= MaxNData ) { LoopIndex[channel] ++; DataIndex[channel] = 0; } @@ -803,7 +838,7 @@ inline int Data::DecodePSDDualChannelBlock(unsigned int ChannelMask, bool fastDe if( isEnergyCorrect == 0 ) { DataIndex[channel] ++; - if( DataIndex[channel] > MaxNData ) { + if( DataIndex[channel] >= MaxNData ) { LoopIndex[channel] ++; DataIndex[channel] = 0; } diff --git a/EventBuilder.cpp b/EventBuilder.cpp index af2a502..191a07a 100644 --- a/EventBuilder.cpp +++ b/EventBuilder.cpp @@ -183,7 +183,6 @@ int main(int argc, char **argv) { Data * data = new Data(); data->DPPType = typeCat[0][0]; data->boardSN = idCat[0]; - data->SetSaveWaveToMemory(true); ///============= Main Loop haha = fopen(inFileName[0], "r"); diff --git a/FSUDAQ.cpp b/FSUDAQ.cpp index e29d23b..875a394 100644 --- a/FSUDAQ.cpp +++ b/FSUDAQ.cpp @@ -766,6 +766,8 @@ void MainWindow::UpdateScalar(){ if( scalar == nullptr ) return; //if( !scalar->isVisible() ) return; + digi[0]->GetData()->PrintAllData(); + lbLastUpdateTime->setText("Last update: " + QDateTime::currentDateTime().toString("MM.dd hh:mm:ss")); //printf("----------------------\n"); @@ -826,6 +828,8 @@ void MainWindow::StartACQ(){ readDataThread[i]->SetSaveData(chkSaveData->isChecked()); LogMsg("Digi-" + QString::number(digi[i]->GetSerialNumber()) + " is starting ACQ." ); digi[i]->WriteRegister(DPP::SoftwareClear_W, 1); + digi[i]->GetData()->ClearData(); + digi[i]->StartACQ(); readDataThread[i]->start(); } diff --git a/Histogram1D.h b/Histogram1D.h index ed77aa4..c1b3010 100644 --- a/Histogram1D.h +++ b/Histogram1D.h @@ -9,6 +9,8 @@ class Histogram1D : public QCustomPlot{ Q_OBJECT public: Histogram1D(QString title, QString xLabel, int xbin, double xmin, double xmax, QWidget * parent = nullptr) : QCustomPlot(parent){ + + for( int i = 0; i < 3; i ++) txt[i] = nullptr; Rebin(xbin, xmin, xmax); xAxis->setLabel(xLabel); @@ -50,10 +52,10 @@ public: txt[i]->position->setType(QCPItemPosition::ptAxisRectRatio); txt[i]->position->setCoords(0.1, 0.1 + 0.1*i);; txt[i]->setFont(QFont("Helvetica", 9)); - if( i == 0 ) txt[i]->setText("Under Flow : 0"); - if( i == 1 ) txt[i]->setText("Total Entry : 0"); - if( i == 2 ) txt[i]->setText("Over Flow : 0"); } + txt[0]->setText("Under Flow : 0"); + txt[1]->setText("Total Entry : 0"); + txt[2]->setText("Over Flow : 0"); usingMenu = false; @@ -122,6 +124,9 @@ public: lineEdit[i] = new QLineEdit(&dialog); layout.addRow(nameList[i] + " : ", lineEdit[i]); } + lineEdit[0]->setText(QString::number(xBin)); + lineEdit[1]->setText(QString::number(xMin)); + lineEdit[2]->setText(QString::number(xMax)); QLabel * msg = new QLabel(&dialog); msg->setStyleSheet("color:red;"); @@ -211,7 +216,10 @@ public: totalEntry = 0; underFlow = 0; overFlow = 0; - + + if( txt[0] ) txt[0]->setText("Under Flow : 0"); + if( txt[1] ) txt[1]->setText("Total Entry : 0"); + if( txt[2] ) txt[2]->setText("Over Flow : 0"); } void Fill(double value){ diff --git a/Histogram2D.h b/Histogram2D.h index e1fa410..bd4331d 100644 --- a/Histogram2D.h +++ b/Histogram2D.h @@ -19,20 +19,20 @@ 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){ - xMin = xmin; - xMax = xmax; - yMin = ymin; - yMax = ymax; - xBin = xbin; - yBin = ybin; + + for( int i = 0; i < 3; i ++ ){ + for( int j = 0; j < 3; j ++ ){ + box[i][j] = nullptr; + txt[i][j] = nullptr; + } + } axisRect()->setupFullAxesBox(true); xAxis->setLabel(xLabel); yAxis->setLabel(yLabel); colorMap = new QCPColorMap(xAxis, yAxis); - colorMap->data()->setSize(xBin, yBin); - colorMap->data()->setRange(QCPRange(xMin, xMax), QCPRange(yMin, yMax)); + Rebin(xbin, xmin, xmax, ybin, ymin, ymax); colorMap->setInterpolate(false); QCPTextElement *titleEle = new QCPTextElement(this, title, QFont("sans", 12)); @@ -52,8 +52,6 @@ public: color.setColorStopAt( 1.0, QColor("yellow")); colorMap->setGradient(color); - cutList.clear(); - double xPosStart = 0.02; double xPosStep = 0.07; double yPosStart = 0.02; @@ -61,7 +59,6 @@ public: for( int i = 0; i < 3; i ++ ){ for( int j = 0; j < 3; j ++ ){ - entry[i][j] = 0; box[i][j] = new QCPItemRect(this); box[i][j]->topLeft->setType(QCPItemPosition::ptAxisRectRatio); @@ -79,6 +76,9 @@ public: } } + cutList.clear(); + cutEntryList.clear(); + rescaleAxes(); usingMenu = false; @@ -91,6 +91,7 @@ public: 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()); @@ -112,9 +113,11 @@ public: }); 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()); @@ -140,7 +143,8 @@ public: QAction * a1 = menu->addAction("UnZoom"); QAction * a2 = menu->addAction("Clear hist."); QAction * a3 = menu->addAction("Toggle Stat."); - QAction * a4 = menu->addAction("Create a Cut"); + QAction * a4 = menu->addAction("Rebin (clear histogram)"); + QAction * a5 = menu->addAction("Create a Cut"); if( numCut > 0 ) { menu->addSeparator(); menu->addAction("Add/Edit names to Cuts"); @@ -179,16 +183,21 @@ public: usingMenu = false; } - if( selectedAction == a4 ){ + if( selectedAction == a4){ + rightMouseClickRebin(); + usingMenu = false; + } + + if( selectedAction == a5 ){ tempCut.clear(); tempCutID ++; isDrawCut= true; usingMenu = false; numCut ++; - qDebug() << "#### Create Cut Plottable count : " << plottableCount() << ", numCut :" << numCut << ", " << lastPlottableID; } - if( selectedAction && selectedAction->text().contains("Delete ") ){ + if( selectedAction && numCut > 0 && selectedAction->text().contains("Delete ") ){ + QString haha = selectedAction->text(); int index1 = haha.indexOf("-"); int index2 = haha.indexOf("["); @@ -204,6 +213,7 @@ public: cutTextIDList[cutID] = -1; plottableIDList[cutID] = -1; cutNameList[cutID] = ""; + cutEntryList[cutID] = -1; for( int i = cutID + 1; i < cutTextIDList.count() ; i++){ cutTextIDList[i] --; @@ -211,21 +221,19 @@ public: } if( numCut == 0 ){ + tempCutID = -1; + lastPlottableID = -1; cutList.clear(); cutIDList.clear(); cutTextIDList.clear(); plottableIDList.clear(); cutNameList.clear(); + cutEntryList.clear(); } - qDebug() << "================= delete Cut-" << cutID; - qDebug() << " cutIDList " << cutIDList ; - qDebug() << "plottableIDList " << plottableIDList << ", " << plottableCount(); - qDebug() << " cutTextIDList " << cutTextIDList << ", " << itemCount(); - } - if( selectedAction && selectedAction->text().contains("Clear all Cuts") ){ + if( selectedAction && numCut > 0 && selectedAction->text().contains("Clear all Cuts") ){ numCut = 0; tempCutID = -1; lastPlottableID = -1; @@ -241,10 +249,11 @@ public: cutTextIDList.clear(); plottableIDList.clear(); cutNameList.clear(); + cutEntryList.clear(); } - if( selectedAction && selectedAction->text().contains("Add/Edit names to Cuts") ){ + if( selectedAction && numCut > 0 && selectedAction->text().contains("Add/Edit names to Cuts") ){ QDialog dialog(this); dialog.setWindowTitle("Add/Edit name of cuts "); @@ -266,12 +275,6 @@ public: replot(); }); } - - // QDialogButtonBox buttonBox(QDialogButtonBox::Cancel, Qt::Horizontal, &dialog); - // layout.addRow(&buttonBox); - - // QObject::connect(&buttonBox, &QDialogButtonBox::rejected, [&]() { dialog.reject();}); - dialog.exec(); } @@ -289,7 +292,8 @@ public: plottableIDList.push_back(plottableCount() -1 ); cutNameList.push_back("Cut-" + QString::number(cutList.count())); - //QCPItemText is not a plottable + cutEntryList.push_back(0); + QCPItemText * text = new QCPItemText(this); text->setText(cutNameList.last()); text->position->setCoords(tempCut[0].rx(), tempCut[0].ry()); @@ -302,10 +306,10 @@ public: cutList.push_back(tempCut); cutIDList.push_back(tempCutID); - qDebug() << "----------- end of create cut"; - qDebug() << " cutIDList " << cutIDList ; - qDebug() << "plottableIDList " << plottableIDList << ", " << plottableCount(); - qDebug() << " cutTextIDList " << cutTextIDList << ", " << itemCount(); + // qDebug() << "----------- end of create cut"; + // qDebug() << " cutIDList " << cutIDList ; + // qDebug() << "plottableIDList " << plottableIDList << ", " << plottableCount(); + // qDebug() << " cutTextIDList " << cutTextIDList << ", " << itemCount(); } }); @@ -316,14 +320,37 @@ public: }); } + //^=================================== + + void Rebin(int xbin, double xmin, double xmax, int ybin, double ymin, double ymax){ + xMin = xmin; + xMax = xmax; + yMin = ymin; + yMax = ymax; + xBin = xbin; + yBin = ybin; + + colorMap->data()->clear(); + colorMap->data()->setSize(xBin, yBin); + colorMap->data()->setRange(QCPRange(xMin, xMax), QCPRange(yMin, yMax)); + + for( int i = 0; i < 3; i ++){ + for( int j = 0; j < 3; j ++){ + entry[i][j] = 0; + if( txt[i][j] ) txt[i][j]->setText("0"); + } + } + + } + void UpdatePlot(){ colorMap->rescaleDataRange(); - rescaleAxes(); + //rescaleAxes(); replot(); } void Clear(){ - colorMap->data()->clear(); + for( int i = 0; i < 3; i ++){ for( int j = 0; j < 3; j ++){ entry[i][j] = 0; @@ -334,6 +361,7 @@ public: } void Fill(double x, double y){ + if( isBusy ) return; int xIndex, yIndex; colorMap->data()->coordToCell(x, y, &xIndex, &yIndex); //printf("%f, %d %d| %f, %d %d\n", x, xIndex, xBin, y, yIndex, yBin); @@ -350,6 +378,11 @@ public: if( xk == 1 && yk == 1 ) { double value = colorMap->data()->cell(xIndex, yIndex); colorMap->data()->setCell(xIndex, yIndex, value + 1); + + for( int i = 0; i < cutList.count(); i++){ + if( cutList[i].isEmpty() ) continue; + if( cutList[i].containsPoint(QPointF(x,y), Qt::OddEvenFill) ) cutEntryList[i] ++; + } } } @@ -378,10 +411,19 @@ public: } replot(); - qDebug() << "Plottable count : " << plottableCount() << ", cutList.count :" << cutList.count() << ", cutID :" << lastPlottableID; + //qDebug() << "Plottable count : " << plottableCount() << ", cutList.count :" << cutList.count() << ", cutID :" << lastPlottableID; } QList GetCutList() const{return cutList;} // this list may contain empty element + QList GetCutEntryList() const{ return cutEntryList;} + void PrintCutEntry() const{ + if( numCut == 0 ) return; + printf("=============== There are %d cuts.\n", numCut); + for( int i = 0; i < cutList.count(); i++){ + if( cutList[i].isEmpty() ) continue; + printf("%10s | %d \n", cutNameList[i].toStdString().c_str(), cutEntryList[i]); + } + } private: double xMin, xMax, yMin, yMax; @@ -407,10 +449,111 @@ private: QList cutTextIDList; QList plottableIDList; QList cutNameList; + QList cutEntryList; QCPItemLine * line; double oldMouseX = 0.0, oldMouseY = 0.0; + bool isBusy; + + //^======================== Right Mouse click action + void rightMouseClickRebin(){ + QDialog dialog(this); + dialog.setWindowTitle("Rebin histogram"); + + QFormLayout layout(&dialog); + + QLabel * info = new QLabel(&dialog); + info->setStyleSheet("color:red;"); + info->setText("This will also clear histogram!!"); + layout.addRow(info); + + QStringList nameListX = {"Num. x-Bin", "x-Min", "x-Max"}; + QLineEdit* lineEditX[3]; + for (int i = 0; i < 3; ++i) { + lineEditX[i] = new QLineEdit(&dialog); + layout.addRow(nameListX[i] + " : ", lineEditX[i]); + } + lineEditX[0]->setText(QString::number(xBin)); + lineEditX[1]->setText(QString::number(xMin)); + lineEditX[2]->setText(QString::number(xMax)); + + QStringList nameListY = {"Num. y-Bin", "y-Min", "y-Max"}; + QLineEdit* lineEditY[3]; + for (int i = 0; i < 3; ++i) { + lineEditY[i] = new QLineEdit(&dialog); + layout.addRow(nameListY[i] + " : ", lineEditY[i]); + } + lineEditY[0]->setText(QString::number(yBin)); + lineEditY[1]->setText(QString::number(yMin)); + lineEditY[2]->setText(QString::number(yMax)); + + QLabel * msg = new QLabel(&dialog); + msg->setStyleSheet("color:red;"); + layout.addRow(msg); + + QDialogButtonBox buttonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, &dialog); + layout.addRow(&buttonBox); + + double number[3][2]; + + QObject::connect(&buttonBox, &QDialogButtonBox::accepted, [&]() { + int OKcount = 0; + bool conversionOk = true; + for( int i = 0; i < 3; i++ ){ + number[i][0] = lineEditX[i]->text().toDouble(&conversionOk); + if( conversionOk ){ + OKcount++; + }else{ + msg->setText(nameListX[i] + " is invalid."); + return; + } + } + for( int i = 0; i < 3; i++ ){ + number[i][1] = lineEditY[i]->text().toDouble(&conversionOk); + if( conversionOk ){ + OKcount++; + }else{ + msg->setText(nameListY[i] + " is invalid."); + return; + } + } + + if( OKcount == 6 ) { + if( number[0][0] <= 0 ) { + msg->setText( nameListX[0] + " is zero or negative" ); + return; + } + if( number[0][0] <= 0 ) { + msg->setText( nameListX[0] + " is zero or negative" ); + return; + } + + if( number[2][0] > number[1][0] && number[2][1] > number[1][1] ) { + dialog.accept(); + }else{ + if( number[2][0] > number[1][0] ){ + msg->setText(nameListX[2] + " is smaller than " + nameListX[1]); + } + if( number[2][1] > number[1][1] ){ + msg->setText(nameListY[2] + " is smaller than " + nameListY[1]); + } + } + } + }); + + QObject::connect(&buttonBox, &QDialogButtonBox::rejected, [&]() { dialog.reject();}); + + if( dialog.exec() == QDialog::Accepted ){ + isBusy = true; + Rebin((int)number[0][0], number[1][0], number[2][0], (int)number[0][1], number[1][1], number[2][1]); + rescaleAxes(); + UpdatePlot(); + isBusy = false; + } + + } + }; #endif \ No newline at end of file diff --git a/OnlineEventBuilder.cpp b/OnlineEventBuilder.cpp index 92e2d58..681fd6b 100644 --- a/OnlineEventBuilder.cpp +++ b/OnlineEventBuilder.cpp @@ -7,6 +7,15 @@ OnlineEventBuilder::OnlineEventBuilder(Digitizer * digi){ data = digi->GetData(); nCh = digi->GetNChannels(); + ClearEvents(); +} + +OnlineEventBuilder::~OnlineEventBuilder(){ + + +} + +void OnlineEventBuilder::ClearEvents(){ eventIndex = -1; for( int i = 0; i < MaxNEvent; i++ ) events[i].clear(); @@ -19,12 +28,6 @@ OnlineEventBuilder::OnlineEventBuilder(Digitizer * digi){ earlistCh = -1; nExhaushedCh = 0; - -} - -OnlineEventBuilder::~OnlineEventBuilder(){ - - } void OnlineEventBuilder::FindEarlistTimeAndCh(){ @@ -79,11 +82,15 @@ void OnlineEventBuilder::BuildEvents(unsigned short timeWindow, bool verbose){ eventbuilt = 0; + data->PrintAllData(); + //======= Start building event do{ eventIndex ++; if( eventIndex >= MaxNEvent ) eventIndex = 0; + + events[eventIndex].clear(); eventbuilt ++; @@ -91,7 +98,7 @@ void OnlineEventBuilder::BuildEvents(unsigned short timeWindow, bool verbose){ dataPoint dp = {0, 0, 0}; for( unsigned int i = 0; i < nCh; i++){ int ch = (i + earlistCh ) % nCh; - + //printf("------ %d | %d | %d | %d\n", ch, data->DataIndex[ch], nextIndex[ch], chExhaused[ch]); if( chExhaused[ch] ) continue; if( nextIndex[ch] > data->DataIndex[ch]) { nExhaushedCh ++; @@ -103,7 +110,7 @@ void OnlineEventBuilder::BuildEvents(unsigned short timeWindow, bool verbose){ unsigned long long time = data->Timestamp[ch][nextIndex[ch]]; - if( time - earlistTime < timeWindow ){ + if( time >= earlistTime && (time - earlistTime < timeWindow) ){ dp.ch = ch; dp.energy = data->Energy[ch][nextIndex[ch]]; dp.timeStamp = time; @@ -127,21 +134,23 @@ void OnlineEventBuilder::BuildEvents(unsigned short timeWindow, bool verbose){ FindEarlistTimeAndCh(); if( verbose ){ - printf(">>>>>>>>>>>>>>>>>>>>>>>>> Event ID : %ld\n", eventIndex); + printf(">>>>>>>>>>>>>>>>>>>>>>>>> Event ID : %ld, multiplicity : %ld\n", eventIndex, events[eventIndex].size()); for( int i = 0; i <(int) events[eventIndex].size(); i++){ - printf("%02d | %5d %llu \n", events[eventIndex][i].ch, events[eventIndex][i].energy, events[eventIndex][i].timeStamp); + int chxxx = events[eventIndex][i].ch; + printf("%02d | %d | %5d %llu \n", chxxx, nextIndex[chxxx], events[eventIndex][i].energy, events[eventIndex][i].timeStamp); } if( nExhaushedCh == nCh ) { printf("######################### no more event to be built\n"); break; - } - printf("----- next ch : %d, next earlist Time : %llu \n", earlistCh, earlistTime); + } + printf("----- next ch : %d, next earlist Time : %llu.\n", earlistCh, earlistTime); + } if( latestTime - earlistTime <= timeWindow ) { if( verbose ) { - printf("######################### left over data for next build\n"); + printf("######################### left over data for next build, latesTime : %llu.\n", latestTime); } break; } diff --git a/OnlineEventBuilder.h b/OnlineEventBuilder.h index 62f4cb5..57971bc 100644 --- a/OnlineEventBuilder.h +++ b/OnlineEventBuilder.h @@ -14,7 +14,7 @@ Use another class to hold the event data and methods. #include "macro.h" #include "ClassDigitizer.h" -#define MaxNEvent 10000 +#define MaxNEvent 30 struct dataPoint{ unsigned short ch; @@ -28,6 +28,7 @@ public: OnlineEventBuilder(Digitizer * digi); ~OnlineEventBuilder(); + void ClearEvents(); void BuildEvents(unsigned short timeWindow, bool verbose = false); long eventIndex; diff --git a/Scope.cpp b/Scope.cpp index 2d4691c..37ff8a1 100644 --- a/Scope.cpp +++ b/Scope.cpp @@ -240,7 +240,7 @@ void Scope::StartScope(){ for( unsigned int iDigi = 0; iDigi < nDigi; iDigi ++){ traceOn[iDigi] = digi[iDigi]->IsRecordTrace(); //remember setting - + digi[iDigi]->GetData()->ClearData(); digi[iDigi]->SetBits(DPP::BoardConfiguration, DPP::Bit_BoardConfig::RecordTrace, 1, -1); digi[iDigi]->StartACQ(); @@ -330,15 +330,15 @@ void Scope::UpdateScope(){ if( digi[ID]->GetDPPType() == V1730_DPP_PHA_CODE ) { for( int i = 0; i < (int) (data->Waveform1[ch][index]).size() ; i++ ) { points[0].append(QPointF(ch2ns * i * factor, (data->Waveform1[ch][index])[i])); - points[1].append(QPointF(ch2ns * i * factor, (data->Waveform2[ch][index])[i])); - points[2].append(QPointF(ch2ns * i * factor, (data->DigiWaveform1[ch][index])[i] * 1000)); - points[3].append(QPointF(ch2ns * i * factor, (data->DigiWaveform2[ch][index])[i] * 1000 + 500)); + if( i < (int) data->Waveform2[ch][index].size() ) points[1].append(QPointF(ch2ns * i * factor, (data->Waveform2[ch][index])[i])); + if( i < (int) data->DigiWaveform1[ch][index].size() ) points[2].append(QPointF(ch2ns * i * factor, (data->DigiWaveform1[ch][index])[i] * 1000)); + if( i < (int) data->DigiWaveform2[ch][index].size() ) points[3].append(QPointF(ch2ns * i * factor, (data->DigiWaveform2[ch][index])[i] * 1000 + 500)); } } if( digi[ID]->GetDPPType() == V1730_DPP_PSD_CODE ) { for( int i = 0; i < (int) (data->DigiWaveform1[ch][index]).size() ; i++ ) { - if( i < (int) data->Waveform1[ch][index].size() ) points[0].append(QPointF(ch2ns * i * factor, (data->Waveform1[ch][index])[i])); + points[0].append(QPointF(ch2ns * i * factor, (data->Waveform1[ch][index])[i])); if( i < (int) data->Waveform2[ch][index].size() ) points[1].append(QPointF(ch2ns * i * factor, (data->Waveform2[ch][index])[i])); if( i < (int) data->DigiWaveform1[ch][index].size() ) points[2].append(QPointF(ch2ns * i, (data->DigiWaveform1[ch][index])[i] * 1000)); if( i < (int) data->DigiWaveform2[ch][index].size() ) points[3].append(QPointF(ch2ns * i, (data->DigiWaveform2[ch][index])[i] * 1000 + 500)); diff --git a/test.cpp b/test.cpp index 174ec89..c66639c 100644 --- a/test.cpp +++ b/test.cpp @@ -48,10 +48,11 @@ int main(int argc, char* argv[]){ OnlineEventBuilder * eb = new OnlineEventBuilder( dig[0] ); Data * data = dig[0]->GetData(); + data->ClearData(); - data->OpenSaveFile("haha"); + // data->OpenSaveFile("haha"); - printf("################# DPP Type : %d , %s\n", data->DPPType, data->DPPTypeStr.c_str()); + // printf("################# DPP Type : %d , %s\n", data->DPPType, data->DPPTypeStr.c_str()); dig[0]->StartACQ(); @@ -66,6 +67,7 @@ int main(int argc, char* argv[]){ // int index = data->NumEventsDecoded[0]; // printf("-------------- %ld \n", data->Waveform1[0][index].size()); + data->PrintAllData(); eb->BuildEvents(100); } @@ -73,7 +75,6 @@ int main(int argc, char* argv[]){ dig[0]->StopACQ(); - data->PrintAllData();