From 34feff751ac51e5e2f74af342e8e2889ee5c96dd Mon Sep 17 00:00:00 2001 From: "carina@hades" Date: Fri, 13 Oct 2023 18:02:19 -0400 Subject: [PATCH] polished QDC related things --- ClassData.h | 6 +- ClassDigitizer.cpp | 30 +++++++--- DataReaderScript.cpp | 1 + DigiSettingsPanel.cpp | 74 +++++++++++++++++------ FSUDAQ.cpp | 2 +- FSUDAQ_Qt6.pro | 7 ++- RegisterAddress.h | 2 +- Scope.cpp | 16 ++++- fsuReader.h | 135 ++++++++++++++++++++++++++++++++++++++++++ test.cpp | 117 ++++++++---------------------------- 10 files changed, 265 insertions(+), 125 deletions(-) create mode 100644 fsuReader.h diff --git a/ClassData.h b/ClassData.h index 301f7fb..b00fd42 100644 --- a/ClassData.h +++ b/ClassData.h @@ -77,7 +77,7 @@ class Data{ void DecodeBuffer(bool fastDecode, int verbose = 0); /// fastDecode will not save waveform void DecodeBuffer(char * &buffer, unsigned int size, bool fastDecode, int verbose = 0); // for outside data - void PrintStat() const; + void PrintStat(bool skipEmpty = true) const; void PrintAllData(bool tableMode = true, unsigned int maxRowDisplay = 0) const; @@ -288,7 +288,7 @@ inline void Data::CloseSaveFile(){ //^####################################################### //^####################################################### Print -inline void Data::PrintStat() const{ +inline void Data::PrintStat(bool skipEmpty) const{ printf("============================= Print Stat. Digi-%d\n", boardSN); if( !IsNotRollOverFakeAgg ) { @@ -298,6 +298,7 @@ inline void Data::PrintStat() const{ printf("%2s | %6s | %9s | %9s | %6s | %6s(%4s)\n", "ch", "# Evt.", "Rate [Hz]", "Accept", "Tot. Evt.", "index", "loop"); printf("---+--------+-----------+-----------+----------\n"); for(int ch = 0; ch < numInputCh; ch++){ + if( skipEmpty && TriggerRate[ch] == 0 ) continue; printf("%2d | %6d | %9.2f | %9.2f | %6lu | %6d(%2d)\n", ch, NumEventsDecoded[ch], TriggerRate[ch], NonPileUpRate[ch], TotNumNonPileUpEvents[ch], DataIndex[ch], LoopIndex[ch]); } printf("---+--------+-----------+-----------+----------\n"); @@ -1017,6 +1018,7 @@ inline int Data::DecodeQDCGroupedChannelBlock(unsigned int ChannelMask, bool fas if( verbose >= 3 ){ printf("%4d| %5d, %d, %d, %d, %d \n", 2*wi, (word & 0xFFF) , (( word >> 12 ) & 0x1 ), (( word >> 13 ) & 0x1 ), (( word >> 14 ) & 0x1 ), (( word >> 15 ) & 0x1 )); + printf("%-22s", ""); printf("%4d| %5d, %d, %d, %d, %d \n", 2*wi+1, (( word >> 16) & 0xFFF), (( word >> 28 ) & 0x1 ), (( word >> 29 ) & 0x1 ), (( word >> 30 ) & 0x1 ), (( word >> 31 ) & 0x1 )); } } diff --git a/ClassDigitizer.cpp b/ClassDigitizer.cpp index e64e013..c27e67e 100644 --- a/ClassDigitizer.cpp +++ b/ClassDigitizer.cpp @@ -148,6 +148,7 @@ int Digitizer::OpenDigitizer(int boardID, int portID, bool program, bool verbose } /// change address 0xEF08 (5 bits), this will reflected in the 2nd word of the Board Agg. header. ret = CAEN_DGTZ_WriteRegister(handle, DPP::BoardID, (DPPType & 0xF)); + if ( verbose ){ PrintBoard(); if (DPPType < 0x80 ) { @@ -210,7 +211,7 @@ int Digitizer::OpenDigitizer(int boardID, int portID, bool program, bool verbose ErrorMsg("end of OpenDigitizer"); if( isConnected ) isDummy = false; - + if( isConnected && program) { if( DPPType == DPPType::DPP_PHA_CODE ) ProgramBoard_PHA(); if( DPPType == DPPType::DPP_PSD_CODE ) ProgramBoard_PSD(); @@ -316,12 +317,16 @@ int Digitizer::ProgramBoard_PHA(){ ret |= CAEN_DGTZ_WriteRegister(handle, (uint32_t)(DPP::PreTrigger) + 0x7000 , 32 ); ret |= CAEN_DGTZ_WriteRegister(handle, (uint32_t)(DPP::InputDynamicRange) + 0x7000 , 0x0 ); - ret |= CAEN_DGTZ_WriteRegister(handle, (int32_t)(DPP::NumberEventsPerAggregate_G) + 0x7000, 511); + ret |= CAEN_DGTZ_WriteRegister(handle, (int32_t)(DPP::NumberEventsPerAggregate_G) + 0x7000, 10); ret |= CAEN_DGTZ_WriteRegister(handle, (int32_t)(DPP::AggregateOrganization), 2); - ret |= CAEN_DGTZ_WriteRegister(handle, (int32_t)(DPP::MaxAggregatePerBlockTransfer), 4); + ret |= CAEN_DGTZ_WriteRegister(handle, (int32_t)(DPP::MaxAggregatePerBlockTransfer), 100); ret |= CAEN_DGTZ_WriteRegister(handle, (int32_t)(DPP::DPPAlgorithmControl) + 0x7000, 0xC30200f); if( ret != 0 ) { printf("!!!!!!!! set channels error.\n");} + + /// change address 0xEF08 (5 bits), this will reflected in the 2nd word of the Board Agg. header. + ret = CAEN_DGTZ_WriteRegister(handle, DPP::BoardID, (DPPType & 0xF)); + //WriteRegister(DPP::BoardID, (DPPType & 0xF)); isSettingFilledinMemeory = false; /// unlock the ReadAllSettingsFromBoard(); @@ -372,6 +377,10 @@ int Digitizer::ProgramBoard_PSD(){ ret |= CAEN_DGTZ_WriteRegister(handle, (uint32_t)(DPP::PSD::GateOffset) + 0x7000 , 19 ); if( ret != 0 ) { printf("!!!!!!!! set channels error.\n");} + + /// change address 0xEF08 (5 bits), this will reflected in the 2nd word of the Board Agg. header. + ret = CAEN_DGTZ_WriteRegister(handle, DPP::BoardID, (DPPType & 0xF)); + //WriteRegister(DPP::BoardID, (DPPType & 0xF)); isSettingFilledinMemeory = false; /// unlock the ReadAllSettingsFromBoard(); @@ -388,9 +397,9 @@ int Digitizer::ProgramBoard_QDC(){ int ret = 0; - WriteRegister(DPP::QDC::NumberEventsPerAggregate, 0x100, -1); - WriteRegister(DPP::QDC::RecordLength, 4000/16, -1); - WriteRegister(DPP::QDC::PreTrigger, 1000/16, -1); + WriteRegister(DPP::QDC::NumberEventsPerAggregate, 0x10, -1); + WriteRegister(DPP::QDC::RecordLength, 31, -1); // 248 sample = 3968 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); @@ -417,12 +426,16 @@ int Digitizer::ProgramBoard_QDC(){ WriteRegister(DPP::BoardConfiguration, 0xC0110); WriteRegister(DPP::AggregateOrganization, 0x0); + WriteRegister(DPP::MaxAggregatePerBlockTransfer, 100); WriteRegister(DPP::AcquisitionControl, 0x0); WriteRegister(DPP::GlobalTriggerMask, 0x0); WriteRegister(DPP::FrontPanelTRGOUTEnableMask, 0x0); WriteRegister(DPP::FrontPanelIOControl, 0x0); WriteRegister(DPP::QDC::GroupEnableMask, 0xFF); - WriteRegister(DPP::MaxAggregatePerBlockTransfer, 0x4); + + /// change address 0xEF08 (5 bits), this will reflected in the 2nd word of the Board Agg. header. + ret = CAEN_DGTZ_WriteRegister(handle, DPP::BoardID, (DPPType & 0xF)); + //WriteRegister(DPP::BoardID, (DPPType & 0xF)); isSettingFilledinMemeory = false; /// unlock the ReadAllSettingsFromBoard(); @@ -758,6 +771,9 @@ void Digitizer::ReadAllSettingsFromBoard(bool force){ } + + printf("BoardID : 0x%X = DataFormat \n", GetSettingFromMemory(DPP::BoardID)); + isSettingFilledinMemeory = true; } diff --git a/DataReaderScript.cpp b/DataReaderScript.cpp index 35d5f82..ba54cd8 100644 --- a/DataReaderScript.cpp +++ b/DataReaderScript.cpp @@ -95,6 +95,7 @@ int main(int argc, char **argv){ printf("%s [inFile] [DPPType] \n", argv[0]); printf(" +-- PHA = %d\n", DPPType::DPP_PHA_CODE); printf(" +-- PSD = %d\n", DPPType::DPP_PSD_CODE); + printf(" +-- QDC = %d\n", DPPType::DPP_QDC_CODE); return 1; } diff --git a/DigiSettingsPanel.cpp b/DigiSettingsPanel.cpp index 3dc53b1..567e068 100644 --- a/DigiSettingsPanel.cpp +++ b/DigiSettingsPanel.cpp @@ -960,6 +960,7 @@ void DigiSettingsPanel::SetUpInquiryCopyTab(){ if( digi[index]->GetDPPType() == V1730_DPP_PHA_CODE ) chRegList = RegisterChannelList_PHA; if( digi[index]->GetDPPType() == V1730_DPP_PSD_CODE ) chRegList = RegisterChannelList_PSD; + if( digi[index]->GetDPPType() == V1740_DPP_QDC_CODE ) chRegList = RegisterChannelList_QDC; cbChReg->clear(); for( int i = 0; i < (int) chRegList.size(); i++ ){ @@ -973,25 +974,53 @@ void DigiSettingsPanel::SetUpInquiryCopyTab(){ connect(cbBdReg, &RComboBox::currentIndexChanged, this, [=](int index){ if( !enableSignalSlot ) return; - if( RegisterBoardList_PHAPSD[index].GetRWType() == RW::WriteONLY ) { - leBdRegRW->setText("Write ONLY" ); - leBdRegValue->setText(""); - leBdRegSet->setEnabled(true); - return; - } + int digiID = cbDigi->currentIndex(); - uint32_t value = digi[ cbDigi->currentIndex() ] ->ReadRegister(RegisterBoardList_PHAPSD[index]); - leBdRegValue->setText( "0x" + QString::number(value, 16).toUpper()); + if( digi[digiID]->GetDPPType() == V1740_DPP_QDC_CODE ){ - if( RegisterBoardList_PHAPSD[index].GetRWType() == RW::ReadONLY ) { - leBdRegRW->setText("Read ONLY" ); - leBdRegSet->setEnabled(false); - return; - } + if( RegisterBoardList_QDC[index].GetRWType() == RW::WriteONLY ) { + leBdRegRW->setText("Write ONLY" ); + leBdRegValue->setText(""); + leBdRegSet->setEnabled(true); + return; + } - if( RegisterBoardList_PHAPSD[index].GetRWType() == RW::ReadWrite ) { - leBdRegRW->setText("Read/Write" ); - leBdRegSet->setEnabled(true); + uint32_t value = digi[ digiID ] ->ReadRegister(RegisterBoardList_QDC[index]); + leBdRegValue->setText( "0x" + QString::number(value, 16).toUpper()); + + if( RegisterBoardList_QDC[index].GetRWType() == RW::ReadONLY ) { + leBdRegRW->setText("Read ONLY" ); + leBdRegSet->setEnabled(false); + return; + } + + if( RegisterBoardList_QDC[index].GetRWType() == RW::ReadWrite ) { + leBdRegRW->setText("Read/Write" ); + leBdRegSet->setEnabled(true); + } + + }else{ + + if( RegisterBoardList_PHAPSD[index].GetRWType() == RW::WriteONLY ) { + leBdRegRW->setText("Write ONLY" ); + leBdRegValue->setText(""); + leBdRegSet->setEnabled(true); + return; + } + + uint32_t value = digi[ digiID ] ->ReadRegister(RegisterBoardList_PHAPSD[index]); + leBdRegValue->setText( "0x" + QString::number(value, 16).toUpper()); + + if( RegisterBoardList_PHAPSD[index].GetRWType() == RW::ReadONLY ) { + leBdRegRW->setText("Read ONLY" ); + leBdRegSet->setEnabled(false); + return; + } + + if( RegisterBoardList_PHAPSD[index].GetRWType() == RW::ReadWrite ) { + leBdRegRW->setText("Read/Write" ); + leBdRegSet->setEnabled(true); + } } }); @@ -1043,7 +1072,12 @@ void DigiSettingsPanel::SetUpInquiryCopyTab(){ uint32_t value = std::stoul(text.toStdString(), nullptr, 16); int index = cbDigi->currentIndex(); int regID = cbBdReg->currentIndex(); - digi[index]->WriteRegister(RegisterBoardList_PHAPSD[regID], value); + + if( digi[index]->GetDPPType() == V1740_DPP_QDC_CODE ){ + digi[index]->WriteRegister(RegisterBoardList_QDC[regID], value); + }else{ + digi[index]->WriteRegister(RegisterBoardList_PHAPSD[regID], value); + } leBdRegSet->setStyleSheet(""); cbBdReg->currentIndexChanged(regID); @@ -1281,7 +1315,7 @@ void DigiSettingsPanel::SetUpChannelMask(unsigned int digiID){ } void DigiSettingsPanel::SetUpACQReadOutTab(){ - SetUpSpinBox(sbAggNum[ID], "Agg. Num. / read ", bdACQLayout[ID], 0, 0, DPP::MaxAggregatePerBlockTransfer, -1, true); + SetUpSpinBox(sbAggNum[ID], "Max Agg. Num. / read ", bdACQLayout[ID], 0, 0, DPP::MaxAggregatePerBlockTransfer, -1, true); SetUpComboBox(cbAggOrg[ID], "Aggregate Organization ", bdACQLayout[ID], 1, 0, DPP::AggregateOrganization, 0); SetUpComboBoxBit(cbStartStopMode[ID], "Start/Stop Mode ", bdACQLayout[ID], 2, 0, DPP::Bit_AcquistionControl::ListStartStopMode, @@ -3002,9 +3036,13 @@ void DigiSettingsPanel::SetUpChannel_QDC(){ if( i == 0 ){ if( ch == 0 ){ QLabel * lb3 = new QLabel("Test Pulse Rate", this); lb3->setAlignment(Qt::AlignHCenter); tabLayout->addWidget(lb3, 0, 3); + QLabel * lb4 = new QLabel("Event pre Agg.", this); lb4->setAlignment(Qt::AlignHCenter); tabLayout->addWidget(lb4, 0, 5); } SetUpCheckBox(chkTestPule[ID][ch], "Int. Test Pulse", tabLayout, ch + 1, 1, DPP::QDC::DPPAlgorithmControl, DPP::QDC::Bit_DPPAlgorithmControl::InternalTestPulse, ch); SetUpComboBoxBit(cbTestPulseRate[ID][ch], "", tabLayout, ch + 1, 2, DPP::QDC::Bit_DPPAlgorithmControl::ListTestPulseRate, DPP::QDC::DPPAlgorithmControl, DPP::QDC::Bit_DPPAlgorithmControl::TestPulseRate, 1, ch); + + SetUpSpinBox(sbNumEventAgg[ID][ch], "", tabLayout, ch + 1, 4, DPP::QDC::NumberEventsPerAggregate, ch); + } } } diff --git a/FSUDAQ.cpp b/FSUDAQ.cpp index fcdd2e6..5fc8b16 100644 --- a/FSUDAQ.cpp +++ b/FSUDAQ.cpp @@ -326,7 +326,7 @@ MainWindow::~MainWindow(){ scalarThread->quit(); scalarThread->exit(); CleanUpScalar(); - delete scalar; + //don't need to delete scalar, it is managed by this } if( digi ) CloseDigitizers(); diff --git a/FSUDAQ_Qt6.pro b/FSUDAQ_Qt6.pro index a23446b..46cef57 100644 --- a/FSUDAQ_Qt6.pro +++ b/FSUDAQ_Qt6.pro @@ -8,11 +8,12 @@ INCLUDEPATH += . QT += core widgets charts printsupport -QMAKE_CXXFLAGS += -g LIBS += -lCAENDigitizer -lcurl -QMAKE_CXXFLAGS_RELEASE = -O0 -QMAKE_CFLAGS_RELEASE = -O0 +#==== for enable GDB debug +#QMAKE_CXXFLAGS += -g +#QMAKE_CXXFLAGS_RELEASE = -O0 +#QMAKE_CFLAGS_RELEASE = -O0 # You can make your code fail to compile if you use deprecated APIs. # In order to do so, uncomment the following line. diff --git a/RegisterAddress.h b/RegisterAddress.h index 0f6440f..83b6f6d 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, 1); /// R/W + const Reg RecordLength ("Record Length" , 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 diff --git a/Scope.cpp b/Scope.cpp index abc8d9f..aa89fd0 100644 --- a/Scope.cpp +++ b/Scope.cpp @@ -782,7 +782,7 @@ void Scope::SetUpPanel_QDC() { SetUpSpinBox(sbGateOffset, "Gate Offset [ns] ", rowID, 2, DPP::QDC::GateOffset); - QLabel * lb = new QLabel("Threshold [LSB]", settingGroup); + QLabel * lb = new QLabel("Threshold [LSB] ", settingGroup); lb->setAlignment(Qt::AlignRight | Qt::AlignCenter); settingLayout->addWidget(lb, rowID, 4); @@ -1103,10 +1103,22 @@ void Scope::UpdatePanel_QDC(){ UpdateSpinBox(sbReordLength, DPP::QDC::RecordLength); UpdateSpinBox(sbPreTrigger, DPP::QDC::PreTrigger); - UpdateSpinBox(sbShortGate, DPP::QDC::GateWidth); UpdateSpinBox(sbGateOffset, DPP::QDC::GateOffset); + int subCh = ch%8; + uint32_t threshold = 0 ; + switch( subCh ){ + case 0 : threshold = digi[ID]->GetSettingFromMemory(DPP::QDC::TriggerThreshold_sub0, grp); break; + case 1 : threshold = digi[ID]->GetSettingFromMemory(DPP::QDC::TriggerThreshold_sub1, grp); break; + case 2 : threshold = digi[ID]->GetSettingFromMemory(DPP::QDC::TriggerThreshold_sub2, grp); break; + case 3 : threshold = digi[ID]->GetSettingFromMemory(DPP::QDC::TriggerThreshold_sub3, grp); break; + case 4 : threshold = digi[ID]->GetSettingFromMemory(DPP::QDC::TriggerThreshold_sub4, grp); break; + case 5 : threshold = digi[ID]->GetSettingFromMemory(DPP::QDC::TriggerThreshold_sub5, grp); break; + case 6 : threshold = digi[ID]->GetSettingFromMemory(DPP::QDC::TriggerThreshold_sub6, grp); break; + case 7 : threshold = digi[ID]->GetSettingFromMemory(DPP::QDC::TriggerThreshold_sub7, grp); break; + } + sbThreshold->setValue(threshold); uint32_t BdCfg = digi[ID]->GetSettingFromMemory(DPP::BoardConfiguration, 0); diff --git a/fsuReader.h b/fsuReader.h new file mode 100644 index 0000000..3c328dc --- /dev/null +++ b/fsuReader.h @@ -0,0 +1,135 @@ +#include "ClassData.h" + +class FSUReader{ + + public: + FSUReader(std::string fileName, unsigned short numCh); + ~FSUReader(); + + void ScanNumBlock(); + int ReadNextBlock(bool fast = false, int verbose = 0); + int ReadBlock(unsigned int ID, int verbose = 0); + + unsigned long GetTotNumBlock() const{ return totNumBlock;} + + Data * GetData() const{return data;} + + private: + + FILE * inFile; + Data * data; + + unsigned long inFileSize; + unsigned int filePos; + unsigned long totNumBlock; + unsigned int blockID; + + std::vector blockPos; + + unsigned int word[1]; /// 4 byte + size_t dummy; + char * buffer; + +}; + +inline FSUReader::FSUReader(std::string fileName, unsigned short numCh){ + + inFile = fopen(fileName.c_str(), "r"); + + if( inFile == NULL ){ + printf("Cannot open file : %s \n", fileName.c_str()); + return; + } + + fseek(inFile, 0L, SEEK_END); + inFileSize = ftell(inFile); + printf("%s | file size : %ld Byte = %.2f MB\n", fileName.c_str() , inFileSize, inFileSize/1024./1024.); + fseek(inFile, 0L, SEEK_SET); + filePos = 0; + + data = new Data(numCh); + + totNumBlock = 0; + blockID = 0; + blockPos.clear(); + + //ScanNumBlock(); + +} + +inline FSUReader::~FSUReader(){ + delete data; + +} + +inline int FSUReader::ReadNextBlock(bool fast, int verbose){ + if( inFile == NULL ) return -1; + if( feof(inFile) ) return -1; + if( filePos >= inFileSize) return -1; + + dummy = fread(word, 4, 1, inFile); + if( dummy != 1) { + printf("fread error, should read 4 bytes, but read %ld x 4 byte, file pos: %ld byte\n", dummy, ftell(inFile)); + return -10; + } + + fseek(inFile, -4, SEEK_CUR); + short header = ((word[0] >> 28 ) & 0xF); + if( header != 0xA ) { + printf("incorrect header.\n trminate."); + return -20; + } + + unsigned int aggSize = (word[0] & 0x0FFFFFFF) * 4; ///byte + buffer = new char[aggSize]; + dummy = fread(buffer, aggSize, 1, inFile); + filePos = ftell(inFile); + if( dummy != 1) { + printf("fread error, should read %d bytes, but read %ld x %d byte, file pos: %ld byte \n", aggSize, dummy, aggSize, ftell(inFile)); + return -30; + } + + data->DecodeBuffer(buffer, aggSize, fast, verbose); // data will own the buffer + data->ClearBuffer(); // this will clear the buffer. + + return 0; + +} + +inline int FSUReader::ReadBlock(unsigned int ID, int verbose){ + if( totNumBlock == 0 )return -1; + if( ID >= totNumBlock )return -1; + + data->ClearData(); + + fseek( inFile, 0L, SEEK_SET); + + if( verbose ) printf("Block index: %u, File Pos: %u byte\n", ID, blockPos[ID]); + + fseek(inFile, blockPos[ID], SEEK_CUR); + filePos = blockPos[ID]; + blockID = ID; + return ReadNextBlock(verbose); + +} + +inline void FSUReader::ScanNumBlock(){ + if( feof(inFile) ) return; + + blockID = 0; + blockPos.push_back(0); + + while( ReadNextBlock(true) == 0 ){ + blockPos.push_back(filePos); + blockID ++; + printf("%u, %.2f%% %u/%lu\n\033[A\r", blockID, filePos*100./inFileSize, filePos, inFileSize); + } + + totNumBlock = blockID; + printf("\nScan complete: number of data Block : %lu\n", totNumBlock); + + rewind(inFile); + blockID = 0; + filePos = 0; + +} \ No newline at end of file diff --git a/test.cpp b/test.cpp index f8cc37b..ecf928a 100644 --- a/test.cpp +++ b/test.cpp @@ -26,127 +26,62 @@ int getch(void); //^====================================== int main(int argc, char* argv[]){ - Digitizer * digi = new Digitizer(0, 2, false, true); - - Reg reg("test", 0x1020, RW::ReadWrite, false, 0xFFF, -1); - - digi->WriteRegister(reg, 0x13, -1); - - digi->ReadAllSettingsFromBoard(); - - digi->GetSettingFromMemory(DPP::QDC::NumberEventsPerAggregate); - - - // digi->Reset(); - // digi->ProgramBoard_PHA(); - - - for( int ch = 0; ch < 16; ch++){ - printf("%2d | 0x%X \n", ch, digi->GetSettingFromMemory(reg, ch)); - } - - //digi->SetBits(DPP::BoardConfiguration, DPP::Bit_BoardConfig::RecordTrace, 1, -1); - - // Data * data = digi->GetData(); - - //digi->StartACQ(); - - // for( int i = 0; i < 4; i ++ ){ - // usleep(1000*1000); - // digi->ReadData(); - // data->DecodeBuffer(false, 100); - // data->PrintStat(); - - // //data->SaveData(); - - // // int index = data->NumEventsDecoded[0]; - // // printf("-------------- %ld \n", data->Waveform1[0][index].size()); - - // //data->PrintAllData(); - - // } - - // digi->StopACQ(); - - - - digi->CloseDigitizer(); - delete digi; - - - - /********************** DPP-PHA + /********************** DPP-QDC */ Digitizer * digi = new Digitizer(0, 2, false, true); digi->Reset(); + + digi->ProgramBoard_QDC(); + digi->WriteRegister(DPP::SoftwareClear_W, 1); - digi->WriteRegister(DPP::QDC::RecordLength, 6000/16, -1); - digi->WriteRegister(DPP::QDC::PreTrigger, 1000/16, -1); - digi->WriteRegister(DPP::QDC::GateWidth, 200/16, -1); - digi->WriteRegister(DPP::QDC::GateOffset, 0, -1); - digi->WriteRegister(DPP::QDC::FixedBaseline, 0, -1); - //digi->WriteRegister(DPP::QDC::DPPAlgorithmControl, 0x300112); // with test pulse - digi->WriteRegister(DPP::QDC::DPPAlgorithmControl, 0x300102); // No test pulse - digi->WriteRegister(DPP::QDC::TriggerHoldOffWidth, 100/16, -1); - digi->WriteRegister(DPP::QDC::TRGOUTWidth, 100/16, -1); - //digi->WriteRegister(DPP::QDC::OverThresholdWidth, 100/16, -1); - //digi->WriteRegister(DPP::QDC::DCOffset, 100/16, -1); - digi->WriteRegister(DPP::QDC::SubChannelMask, 0xFF, -1); + digi->WriteRegister(DPP::QDC::RecordLength, 31, -1); // T = N * 8 * 16 + digi->WriteRegister(DPP::QDC::PreTrigger, 60, -1); - digi->WriteRegister(DPP::QDC::TriggerThreshold_sub0, 10, -1); - digi->WriteRegister(DPP::QDC::TriggerThreshold_sub1, 10, -1); - digi->WriteRegister(DPP::QDC::TriggerThreshold_sub2, 10, -1); - digi->WriteRegister(DPP::QDC::TriggerThreshold_sub3, 10, -1); - digi->WriteRegister(DPP::QDC::TriggerThreshold_sub4, 10, -1); - digi->WriteRegister(DPP::QDC::TriggerThreshold_sub5, 10, -1); - digi->WriteRegister(DPP::QDC::TriggerThreshold_sub6, 10, -1); - digi->WriteRegister(DPP::QDC::TriggerThreshold_sub7, 10, -1); + digi->WriteRegister(DPP::QDC::TriggerThreshold_sub2, 17, -1); + digi->SetBits(DPP::QDC::DPPAlgorithmControl, DPP::QDC::Bit_DPPAlgorithmControl::ChargeSensitivity, 0, -1); + digi->SetBits(DPP::QDC::DPPAlgorithmControl, DPP::QDC::Bit_DPPAlgorithmControl::InputSmoothingFactor, 4, -1); + digi->SetBits(DPP::QDC::DPPAlgorithmControl, DPP::QDC::Bit_DPPAlgorithmControl::BaselineAvg, 2, -1); + digi->WriteRegister(DPP::QDC::GateWidth, 608/16, -1); - digi->WriteRegister(DPP::BoardConfiguration, 0xC0110); - digi->WriteRegister(DPP::AggregateOrganization, 0x1); - digi->WriteRegister(DPP::QDC::NumberEventsPerAggregate, 0x4); - digi->WriteRegister(DPP::AcquisitionControl, 0x0); - digi->WriteRegister(DPP::GlobalTriggerMask, 0x0); - digi->WriteRegister(DPP::FrontPanelTRGOUTEnableMask, 0x0); - digi->WriteRegister(DPP::FrontPanelIOControl, 0x0); - digi->WriteRegister(DPP::QDC::GroupEnableMask, 0xFF); - digi->WriteRegister(DPP::MaxAggregatePerBlockTransfer, 0x3FF); + digi->WriteRegister(DPP::QDC::GroupEnableMask, 0x01); + digi->WriteRegister(DPP::QDC::NumberEventsPerAggregate, 10, -1); + digi->WriteRegister(DPP::AggregateOrganization, 0, -1); + digi->WriteRegister(DPP::MaxAggregatePerBlockTransfer, 100, -1); - //digi->WriteRegister(DPP::QDC::DPPAlgorithmControl, 0x300112, 0); // with pulse for grp 0 + digi->SetBits(DPP::QDC::DPPAlgorithmControl, DPP::QDC::Bit_DPPAlgorithmControl::Polarity, 0, -1); - digi->WriteRegister(DPP::BoardID, 0x7); - - // digi->PrintSettingFromMemory(); + digi->SetBits(DPP::BoardConfiguration, DPP::Bit_BoardConfig::EnableExtra2, 1, -1); + digi->SetBits(DPP::BoardConfiguration, DPP::Bit_BoardConfig::RecordTrace, 1, -1); Data * data = digi->GetData(); - data->ClearData(); - - data->PrintStat(); - + remove("haha_17121_QDC_000.fsu"); + data->OpenSaveFile("haha"); digi->StartACQ(); for( int i = 0; i < 10; i ++ ){ usleep(1000*1000); digi->ReadData(); - data->DecodeBuffer(false, 0); + data->DecodeBuffer(true, 0); + //data->DecodeBuffer(false, 2); + data->SaveData(); data->PrintStat(); - //data->SaveData(); // int index = data->NumEventsDecoded[0]; // printf("-------------- %ld \n", data->Waveform1[0][index].size()); - //data->PrintAllData(); } - digi->StopACQ(); + data->CloseSaveFile(); + + data->PrintAllData(); digi->CloseDigitizer(); delete digi;