From 3819e422bd474bcd08d22cbf37483c3a7942b45d Mon Sep 17 00:00:00 2001 From: "carina@hades" Date: Thu, 19 Oct 2023 14:29:28 -0400 Subject: [PATCH] bugs fix for QDC --- ClassData.h | 34 +++----------------------- ClassDigitizer.cpp | 10 ++++---- CustomThreads.h | 3 ++- DigiSettingsPanel.cpp | 56 +++++++++++++++++++++++++------------------ DigiSettingsPanel.h | 5 +++- FSUDAQ.cpp | 53 ++++++++++++++++++++++++---------------- FSUDAQ.h | 2 +- README.md | 1 + RegisterAddress.h | 7 +++--- 9 files changed, 85 insertions(+), 86 deletions(-) diff --git a/ClassData.h b/ClassData.h index fc7a54c..358d0fe 100644 --- a/ClassData.h +++ b/ClassData.h @@ -503,6 +503,9 @@ inline void Data::DecodeBuffer(bool fastDecode, int verbose){ unsigned long long t0 = Timestamp[ch][(calIndexes[ch][0]) % MaxNData]; // earlier unsigned long long t1 = Timestamp[ch][(calIndexes[ch][1]) % MaxNData];; // latest + + if( t0 > t1 ) printf("data is not in time order"); + double sec = ( t1 - t0 ) * tick2ns / 1e9; TriggerRate[ch] = nEvent / sec; @@ -516,37 +519,6 @@ inline void Data::DecodeBuffer(bool fastDecode, int verbose){ //printf("%2d | %10llu %10llu, %.0f = %f sec, rate = %f, nEvent %d pileUp %d \n", ch, tList.front() ,tList.back(), tick2ns, sec, nEvent / sec, nEvent, pileUpCount); } - - - // if( calIndexes[ch][0] == -1 ) calIndexes[ch][0] = 0; - // if( calIndexes[ch][0] > -1 && calIndexes[ch][1] == -1 ) calIndexes[ch][1] = DataIndex[ch]; - - // short nEvent = calIndexes[ch][1] - calIndexes[ch][0] ; - // if( nEvent < 0 ) nEvent += MaxNData; - // printf("ch %2d ----- %d %d | %d \n", ch, calIndexes[ch][0], calIndexes[ch][1], nEvent); - - // if( calIndexes[ch][0] > -1 && calIndexes[ch][1] > -1 && nEvent > 2 ){ - // unsigned long long dTime = Timestamp[ch][calIndexes[ch][1]] - Timestamp[ch][calIndexes[ch][0]]; - // double sec = dTime * tick2ns / 1e9; - - - // TriggerRate[ch] = nEvent / sec; - - // short pileUpCount = 0; - // for( int i = calIndexes[ch][0] ; i <= calIndexes[ch][0] + nEvent; i++ ) { - // if( PileUp[ch][i % MaxNData] ) pileUpCount ++; - // } - // printf("%2d | %10llu %10llu, %.0f = %f sec, rate = %f, nEvent %d pileUp %d \n", ch, Timestamp[ch][calIndexes[ch][0]], Timestamp[ch][calIndexes[ch][1]], tick2ns, sec, nEvent / sec, nEvent, pileUpCount); - - // NonPileUpRate[ch] = (nEvent - pileUpCount)/sec; - - // calIndexes[ch][0] = calIndexes[ch][1]; - // calIndexes[ch][1] = -1; - - // }else{ - // calIndexes[ch][1] = -1; - // } - } diff --git a/ClassDigitizer.cpp b/ClassDigitizer.cpp index c27e67e..c5b5f1f 100644 --- a/ClassDigitizer.cpp +++ b/ClassDigitizer.cpp @@ -398,15 +398,16 @@ int Digitizer::ProgramBoard_QDC(){ int ret = 0; WriteRegister(DPP::QDC::NumberEventsPerAggregate, 0x10, -1); - WriteRegister(DPP::QDC::RecordLength, 31, -1); // 248 sample = 3968 ns + WriteRegister(DPP::QDC::RecordLength_W, 16, -1); // 128 sample = 2048 ns WriteRegister(DPP::QDC::PreTrigger, 60, -1); // at 60 sample = 960 ns WriteRegister(DPP::QDC::GateWidth, 100/16, -1); WriteRegister(DPP::QDC::GateOffset, 0, -1); WriteRegister(DPP::QDC::FixedBaseline, 0, -1); - //WriteRegister(DPP::QDC::DPPAlgorithmControl, 0x300112); // with test pulse - WriteRegister(DPP::QDC::DPPAlgorithmControl, 0x300102); // No test pulse + //WriteRegister(DPP::QDC::DPPAlgorithmControl, 0x300112); // with test pulse, positive + //WriteRegister(DPP::QDC::DPPAlgorithmControl, 0x300102); // No test pulse, positive + WriteRegister(DPP::QDC::DPPAlgorithmControl, 0x310102); // No test pulse, negative WriteRegister(DPP::QDC::TriggerHoldOffWidth, 100/16, -1); WriteRegister(DPP::QDC::TRGOUTWidth, 100/16, -1); @@ -770,9 +771,8 @@ void Digitizer::ReadAllSettingsFromBoard(bool force){ } } - - printf("BoardID : 0x%X = DataFormat \n", GetSettingFromMemory(DPP::BoardID)); + //printf("BoardID : 0x%X = DataFormat \n", GetSettingFromMemory(DPP::BoardID)); isSettingFilledinMemeory = true; diff --git a/CustomThreads.h b/CustomThreads.h index d180b72..23e80ea 100644 --- a/CustomThreads.h +++ b/CustomThreads.h @@ -4,6 +4,7 @@ #include #include #include +#include #include "macro.h" #include "ClassDigitizer.h" @@ -116,7 +117,7 @@ class TimingThread : public QThread { Q_OBJECT public: TimingThread(QObject * parent = 0 ) : QThread(parent){ - waitTime = 20; // 10 x 100 milisec + waitTime = 20; // multiple of 100 mili sec stop = false; } void Stop() { this->stop = true;} diff --git a/DigiSettingsPanel.cpp b/DigiSettingsPanel.cpp index 567e068..e8e1faa 100644 --- a/DigiSettingsPanel.cpp +++ b/DigiSettingsPanel.cpp @@ -3051,15 +3051,12 @@ void DigiSettingsPanel::SetUpChannel_QDC(){ } //&########################################################### -void DigiSettingsPanel::UpdateBoardAndChannelsStatus(){ +void DigiSettingsPanel::UpdateACQStatus(uint32_t status){ - //*======================================== - uint32_t AcqStatus = digi[ID]->ReadRegister(DPP::AcquisitionStatus_R); - - leACQStatus[ID]->setText( "0x" + QString::number(AcqStatus, 16).toUpper()); + leACQStatus[ID]->setText( "0x" + QString::number(status, 16).toUpper()); for( int i = 0; i < 9; i++){ - if( Digitizer::ExtractBits(AcqStatus, {1, ACQToolTip[i].second}) == 0 ){ + if( Digitizer::ExtractBits(status, {1, ACQToolTip[i].second}) == 0 ){ bnACQStatus[ID][i]->setStyleSheet(""); bnACQStatus[ID][i]->setToolTip(ACQToolTip[i].first.first); if(ACQToolTip[i].second == 19 ) bnACQStatus[ID][i]->setStyleSheet("background-color: green;"); @@ -3070,26 +3067,14 @@ void DigiSettingsPanel::UpdateBoardAndChannelsStatus(){ } } - //*======================================== - uint32_t BdFailStatus = digi[ID]->ReadRegister(DPP::BoardFailureStatus_R); - leBdFailStatus[ID]->setText( "0x" + QString::number(BdFailStatus, 16).toUpper()); - - for( int i = 0; i < 3; i++){ - if( Digitizer::ExtractBits(BdFailStatus, {1, BdFailToolTip[i].second}) == 0 ){ - bnBdFailStatus[ID][i]->setStyleSheet("background-color: green;"); - bnBdFailStatus[ID][i]->setToolTip(BdFailToolTip[i].first.first); - }else{ - bnBdFailStatus[ID][i]->setStyleSheet("background-color: red;"); - bnBdFailStatus[ID][i]->setToolTip(BdFailToolTip[i].first.second); - } - } +} - //*======================================== - uint32_t ReadoutStatus = digi[ID]->ReadRegister(DPP::ReadoutStatus_R); - leReadOutStatus[ID]->setText( "0x" + QString::number(ReadoutStatus, 16).toUpper()); +void DigiSettingsPanel::UpdateReadOutStatus(uint32_t status){ + + leReadOutStatus[ID]->setText( "0x" + QString::number(status, 16).toUpper()); for( int i = 0; i < 3; i++){ - if( Digitizer::ExtractBits(ReadoutStatus, {1, ReadoutToolTip[i].second}) == 0 ){ + if( Digitizer::ExtractBits(status, {1, ReadoutToolTip[i].second}) == 0 ){ if( ReadoutToolTip[i].second != 2 ) { bnReadOutStatus[ID][i]->setStyleSheet(""); }else{ @@ -3105,6 +3090,31 @@ void DigiSettingsPanel::UpdateBoardAndChannelsStatus(){ bnReadOutStatus[ID][i]->setToolTip(ReadoutToolTip[i].first.second); } } +} + +void DigiSettingsPanel::UpdateBoardAndChannelsStatus(){ + + //*======================================== + uint32_t AcqStatus = digi[ID]->ReadRegister(DPP::AcquisitionStatus_R); + UpdateACQStatus(AcqStatus); + + //*======================================== + uint32_t ReadoutStatus = digi[ID]->ReadRegister(DPP::ReadoutStatus_R); + UpdateReadOutStatus(ReadoutStatus); + + //*======================================== + uint32_t BdFailStatus = digi[ID]->ReadRegister(DPP::BoardFailureStatus_R); + leBdFailStatus[ID]->setText( "0x" + QString::number(BdFailStatus, 16).toUpper()); + + for( int i = 0; i < 3; i++){ + if( Digitizer::ExtractBits(BdFailStatus, {1, BdFailToolTip[i].second}) == 0 ){ + bnBdFailStatus[ID][i]->setStyleSheet("background-color: green;"); + bnBdFailStatus[ID][i]->setToolTip(BdFailToolTip[i].first.first); + }else{ + bnBdFailStatus[ID][i]->setStyleSheet("background-color: red;"); + bnBdFailStatus[ID][i]->setToolTip(BdFailToolTip[i].first.second); + } + } //*========================================== Channel Status for( int i = 0; i < digi[ID]->GetNumRegChannels(); i++){ diff --git a/DigiSettingsPanel.h b/DigiSettingsPanel.h index d62a237..7dc9029 100644 --- a/DigiSettingsPanel.h +++ b/DigiSettingsPanel.h @@ -21,10 +21,13 @@ public: DigiSettingsPanel(Digitizer ** digi, unsigned int nDigi, QString rawDataPath, QMainWindow * parent = nullptr); ~DigiSettingsPanel(); + public slots: void UpdatePanelFromMemory(); void ReadSettingsFromBoard(); - void UpdateBoardAndChannelsStatus(); // will ReadRegister + void UpdateACQStatus(uint32_t status); + void UpdateReadOutStatus(uint32_t status); + void UpdateBoardAndChannelsStatus(); // directly read from register void SaveSetting(int opt); void LoadSetting(); diff --git a/FSUDAQ.cpp b/FSUDAQ.cpp index 63f4694..50b3c5f 100644 --- a/FSUDAQ.cpp +++ b/FSUDAQ.cpp @@ -39,7 +39,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent){ runRecord = nullptr; model = nullptr; influx = nullptr; - + QWidget * mainLayoutWidget = new QWidget(this); setCentralWidget(mainLayoutWidget); QVBoxLayout * layoutMain = new QVBoxLayout(mainLayoutWidget); @@ -234,16 +234,16 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent){ connect( bnStartACQ, &QPushButton::clicked, this, &MainWindow::AutoRun); bnStopACQ = new QPushButton("Stop ACQ", this); connect( bnStopACQ, &QPushButton::clicked, this, [=](){ - if( runTimer->isActive() ){ - runTimer->stop(); - runTimer->disconnect(runTimerConnection); - }else{ - breakAutoRepeat = true; - runTimer->disconnect(runTimerConnection); - } - needManualComment = true; - StopACQ(); - }); + if( runTimer->isActive() ){ + runTimer->stop(); + runTimer->disconnect(runTimerConnection); + }else{ + breakAutoRepeat = true; + runTimer->disconnect(runTimerConnection); + } + needManualComment = true; + StopACQ(); + }); layout->addWidget(lbPrefix, rowID, 0); layout->addWidget(lePrefix, rowID, 1); @@ -381,7 +381,7 @@ void MainWindow::OpenDataPath(){ SaveProgramSettings(); - //TODO Check us the dataPath empty, check is the lastRun.sh exist and load the last run. + LoadLastRunFile(); } @@ -695,7 +695,7 @@ void MainWindow::OpenDigitizers(){ SetupScalar(); -} + } void MainWindow::CloseDigitizers(){ @@ -968,8 +968,6 @@ void MainWindow::UpdateScalar(){ } } - //if( digiSettings && digiSettings->isVisible()) digiSettings->UpdateBoardAndChannelsStatus(); - digiMTX[iDigi].unlock(); } @@ -1017,7 +1015,7 @@ void MainWindow::StartACQ(){ readDataThread[i]->start(); } - if( chkSaveData->isChecked() ) SaveLastRunFile(); +if( chkSaveData->isChecked() ) SaveLastRunFile(); // printf("------------ wait for 2 sec \n"); // usleep(1000*1000); @@ -1225,20 +1223,23 @@ void MainWindow::SetSyncMode(){ QPushButton * bnNoSync = new QPushButton("No Sync"); QPushButton * bnMethod1 = new QPushButton("Software TRG-OUT --> TRG-IN "); QPushButton * bnMethod2 = new QPushButton("Software TRG-OUT --> S-IN "); - QPushButton * bnMethod3 = new QPushButton("External TRG-OUT --> S-IN "); + QPushButton * bnMethod3 = new QPushButton("External --> 1st S-IN,\nTRG-OUT --> S-IN "); + QPushButton * bnMethod4 = new QPushButton("External All S-IN "); layout->addWidget(lbInfo1, 0); layout->addWidget( bnNoSync, 2); layout->addWidget(bnMethod1, 3); layout->addWidget(bnMethod2, 4); layout->addWidget(bnMethod3, 5); + layout->addWidget(bnMethod4, 6); bnNoSync->setFixedHeight(40); bnMethod1->setFixedHeight(40); bnMethod2->setFixedHeight(40); bnMethod3->setFixedHeight(40); + bnMethod4->setFixedHeight(40); - connect(bnNoSync, &QPushButton::clicked, [&](){ + connect(bnNoSync, &QPushButton::clicked, [&](){ /// No Sync for(unsigned int i = 0; i < nDigi; i++){ digi[i]->WriteRegister(DPP::AcquisitionControl, 0); digi[i]->WriteRegister(DPP::FrontPanelIOControl, 0); @@ -1247,7 +1248,7 @@ void MainWindow::SetSyncMode(){ dialog.accept(); }); - connect(bnMethod1, &QPushButton::clicked, [&](){ + connect(bnMethod1, &QPushButton::clicked, [&](){ /// Software TRG-OUT --> TRG-IN digi[0]->WriteRegister(DPP::AcquisitionControl, 0); digi[0]->WriteRegister(DPP::FrontPanelIOControl, 0x10000); //RUN for(unsigned int i = 1; i < nDigi; i++){ @@ -1258,7 +1259,7 @@ void MainWindow::SetSyncMode(){ dialog.accept(); }); - connect(bnMethod2, &QPushButton::clicked, [&](){ + connect(bnMethod2, &QPushButton::clicked, [&](){ /// Software TRG-OUT --> S-IN digi[0]->WriteRegister(DPP::AcquisitionControl, 0); digi[0]->WriteRegister(DPP::FrontPanelIOControl, 0x10000); //RUN for(unsigned int i = 1; i < nDigi; i++){ @@ -1269,7 +1270,8 @@ void MainWindow::SetSyncMode(){ dialog.accept(); }); - connect(bnMethod3, &QPushButton::clicked, [&](){ + connect(bnMethod3, &QPushButton::clicked, [&](){ ///External TRG-OUT --> S-IN + digi[0]->WriteRegister(DPP::AcquisitionControl, 0x01); for(unsigned int i = 0; i < nDigi; i++){ digi[i]->WriteRegister(DPP::AcquisitionControl, 0x41); digi[i]->WriteRegister(DPP::FrontPanelIOControl, 0x30000); // S-IN @@ -1278,6 +1280,15 @@ void MainWindow::SetSyncMode(){ dialog.accept(); }); + connect(bnMethod4, &QPushButton::clicked, [&](){ /// External All S-IN + digi[0]->WriteRegister(DPP::AcquisitionControl, 0x01); + for(unsigned int i = 1; i < nDigi; i++){ + digi[i]->WriteRegister(DPP::AcquisitionControl, 0x41); + } + if( digiSettings && digiSettings->isVisible() ) digiSettings->UpdatePanelFromMemory(); + dialog.accept(); + }); + dialog.exec(); } diff --git a/FSUDAQ.h b/FSUDAQ.h index 88851f4..a156b41 100644 --- a/FSUDAQ.h +++ b/FSUDAQ.h @@ -160,7 +160,7 @@ private: //@----- ACQ ReadDataThread ** readDataThread; - + //@----- Scope Scope * scope; diff --git a/README.md b/README.md index 76d5b86..7df68a7 100644 --- a/README.md +++ b/README.md @@ -108,6 +108,7 @@ Those file can be compiled using * DC offset issue. When porgram default settings, the DC offset is not the same for all channels. * for PHA firmware, when the trigger average changed, the Events per Agg need to be changed. * Sometimes, the buffer is not in time order, and make the trigger/Accept rate to be nagative. This is nothing to do with the program but the digitizer settings. Recommand reporgram the digitizer. +* for 1740 QDC, RecordLenght is board setting, but readout is indivuial group. # Known Bugs diff --git a/RegisterAddress.h b/RegisterAddress.h index 83b6f6d..06b6d22 100644 --- a/RegisterAddress.h +++ b/RegisterAddress.h @@ -787,7 +787,7 @@ namespace DPP { namespace QDC { // Register already grouped in channel. and there no control for indiviual channel except the Fine DC offset and threshold, so it is like no group const Reg NumberEventsPerAggregate ("Number of Events per Aggregate", 0x1020, RW::ReadWrite, false, 0x3FF, -1); /// R/W - const Reg RecordLength ("Record Length" , 0x1024, RW::ReadWrite, false, 0x1FFF, 8); /// R/W + const Reg RecordLength ("Record Length_R" , 0x1024, RW::ReadWrite, false, 0x1FFF, 8); /// R/W const Reg GateWidth ("GateWidth" , 0x1030, RW::ReadWrite, false, 0xFFF, 1); /// R/W const Reg GateOffset ("GateOfset" , 0x1034, RW::ReadWrite, false, 0xFF, 1); /// R/W const Reg FixedBaseline ("FixedBaseline" , 0x1038, RW::ReadWrite, false, 0xFFF, -1); /// R/W @@ -811,8 +811,8 @@ namespace DPP { const Reg TriggerThreshold_sub6 ("Trigger Threshold sub6" , 0x10E8, RW::ReadWrite, false, 0xFFF, -1); /// R/W const Reg TriggerThreshold_sub7 ("Trigger Threshold sub7" , 0x10EC, RW::ReadWrite, false, 0xFFF, -1); /// R/W - - const Reg GroupEnableMask ("Group Enable Mask" , 0x8120, RW::ReadWrite, false, 0xFF, -1); /// R/W + const Reg RecordLength_W ("Record Length_W" , 0x8024, RW::WriteONLY, false, 0x1FFF, 8); /// /W + const Reg GroupEnableMask ("Group Enable Mask" , 0x8120, RW::ReadWrite, false, 0xFF, -1); /// R/W namespace Bit_DPPAlgorithmControl { const std::pair ChargeSensitivity = {3, 0} ; /// length, smallest pos @@ -1025,6 +1025,7 @@ const std::vector RegisterBoardList_QDC = { DPP::BoardConfiguration , DPP::AggregateOrganization, DPP::QDC::NumberEventsPerAggregate, + DPP::QDC::RecordLength_W, DPP::AcquisitionControl, DPP::AcquisitionStatus_R, DPP::SoftwareTrigger_W,