From c5fd1b1f657e1b65afac86ee77bcb8b9be3ecbfd Mon Sep 17 00:00:00 2001 From: "carina@hades" Date: Thu, 18 Aug 2022 17:34:28 -0400 Subject: [PATCH] now have proper energy. testing timestamp roll over --- ClassData.h | 80 ++++++++------- ClassDigitizer.cpp | 12 +-- DigitizerPHA.cpp | 249 ++++++++++++++++----------------------------- test.cpp | 24 +++-- test_indep.cpp | 82 +++++++++++++-- 5 files changed, 223 insertions(+), 224 deletions(-) diff --git a/ClassData.h b/ClassData.h index 2be0d7b..c18dc8b 100644 --- a/ClassData.h +++ b/ClassData.h @@ -62,40 +62,44 @@ class Data{ printf("======= Free memory, not impletment yet \n"); } - void ReadAllBuffer(){ + void ReadAllBuffer(int verbose = 0){ + + /// verbose : 0 = off, 1 = only energy + timestamp, 2 = show header, 3 = wave + if( buffer == NULL ) return; unsigned int nw = 0; do{ - printf("#########################################\n"); - unsigned int word = ReadBuffer(nw); + if( verbose >= 2 ) printf("######################################### Board Agg.\n"); + unsigned int word = ReadBuffer(nw, verbose); if( ( (word >> 28) & 0xF ) == 0xA ) { /// start of Board Agg unsigned int nWord = word & 0x0FFFFFFF ; - printf(" number of words in this Agg : %d \n", nWord); + if( verbose >= 2 ) printf(" number of words in this Agg : %d \n", nWord); - nw = nw + 1; word = ReadBuffer(nw); + nw = nw + 1; word = ReadBuffer(nw, verbose); unsigned int BoardID = ((word >> 27) & 0x1F); bool BoardFailFlag = ((word >> 26) & 0x1 ); unsigned int ChannelMask = ( word & 0xFF ) ; - printf("Board ID : %d, FailFlag = %d, ChannelMask = 0x%x\n", BoardID, BoardFailFlag, ChannelMask); + if( verbose >= 2 ) printf("Board ID : %d, FailFlag = %d, ChannelMask = 0x%x\n", BoardID, BoardFailFlag, ChannelMask); nw = nw + 2; - unsigned int AggCounter = ReadBuffer(nw); - printf("Agg Counter : %d \n", AggCounter); + unsigned int AggCounter = ReadBuffer(nw, verbose); + if( verbose >= 2 ) printf("Agg Counter : %d \n", AggCounter); - printf("----------------------\n"); + - nw = nw + 1; - do{ - word = ReadBuffer(nw); + for( int chMask = 0; chMask < 8 ; chMask ++ ){ + if( ((ChannelMask >> chMask) & 0x1 ) == 0 ) continue; + if( verbose >= 2 ) printf("---------------------- Dual Channel Block : %d\n", chMask *2 ); + nw = nw + 1; word = ReadBuffer(nw, verbose); bool hasFormatInfo = ((word >> 31) & 0x1); unsigned int aggSize = ( word & 0x3FFFFFF ) ; - printf(" size : %d \n", aggSize); + if( verbose >= 2 ) printf(" size : %d \n", aggSize); unsigned int nSample = 0; /// wave form; unsigned int nEvents = 0; if( hasFormatInfo ){ - nw = nw + 1; word = ReadBuffer(nw); + nw = nw + 1; word = ReadBuffer(nw, verbose); nSample = ( word & 0xFFFF ) * 8; unsigned int digitalProbe = ( (word >> 16 ) & 0xF ); unsigned int analogProbe2 = ( (word >> 20 ) & 0x3 ); @@ -107,68 +111,70 @@ class Data{ bool hasEnergy = ( (word >> 30 ) & 0x1 ); bool hasDualTrace = ( (word >> 31 ) & 0x1 ); - printf("dualTrace : %d, Energy : %d, Time: %d, Wave : %d, Extra2: %d, Extra2Option: %d \n", - hasDualTrace, hasEnergy, hasTimeStamp, hasWaveForm, hasExtra2, extra2Option); - printf("Ana Probe 1 & 2: %d %d , Digi Probe: %d, nSample : %d \n", - analogProbe1, analogProbe2, digitalProbe, nSample); + if( verbose >= 2 ) printf("dualTrace : %d, Energy : %d, Time: %d, Wave : %d, Extra2: %d, Extra2Option: %d \n", + hasDualTrace, hasEnergy, hasTimeStamp, hasWaveForm, hasExtra2, extra2Option); + if( verbose >= 2 ) printf("Ana Probe 1 & 2: %d %d , Digi Probe: %d, nSample : %d \n", + analogProbe1, analogProbe2, digitalProbe, nSample); nEvents = aggSize / (nSample/2 + 2 + hasExtra2 ); - printf("=========== nEvents : %d \n", nEvents); + if( verbose >= 2 ) printf("=========== nEvents : %d \n", nEvents); }else{ - printf("does not has format info. unable to read buffer.\n"); + if( verbose >= 2 ) printf("does not has format info. unable to read buffer.\n"); break; } for( int ev = 0; ev < nEvents ; ev++){ - printf("=================================== event : %d\n", ev); - nw = nw +1 ; word = ReadBuffer(nw); + if( verbose >= 2 ) printf("=================================== event : %d\n", ev); + nw = nw +1 ; word = ReadBuffer(nw, verbose); bool channelTag = ((word >> 31) & 0x1); unsigned int timeStamp = (word & 0x7FFFFFFF); - int channel = log(ChannelMask)/log(2) *2 + channelTag; - printf("ch : %d, timeStamp %u \n", channel, timeStamp); + int channel = chMask*2 + channelTag; + if( verbose >= 2 ) printf("ch : %d, timeStamp %u \n", channel, timeStamp); ///===== read waveform for( int wi = 0; wi < nSample/2; wi++){ - nw = nw +1 ; word = ReadBuffer(nw, false); + nw = nw +1 ; word = ReadBuffer(nw, verbose - 2); bool isTrigger1 = (( word >> 31 ) & 0x1 ); unsigned int wave1 = (( word >> 16) & 0x3FFF); bool isTrigger0 = (( word >> 15 ) & 0x1 ); unsigned int wave0 = ( word & 0x3FFF); - if( ev == 0 ){ - printf(" %5d, %d \n", wave0, isTrigger0); - printf(" %5d, %d \n", wave1, isTrigger1); + if( verbose >= 3 && ev == 0 ){ + printf("%4d| %5d, %d \n", 2*wi, wave0, isTrigger0); + printf("%4d| %5d, %d \n", 2*wi+1, wave1, isTrigger1); } } - nw = nw +1 ; word = ReadBuffer(nw); + nw = nw +1 ; word = ReadBuffer(nw, verbose); unsigned int extra2 = word; - nw = nw +1 ; word = ReadBuffer(nw); + nw = nw +1 ; word = ReadBuffer(nw, verbose); unsigned int extra = (( word >> 16) & 0x3FF); unsigned int energy = (word & 0x7FFF); bool pileUp = ((word >> 15) & 0x1); - printf("PileUp : %d , extra : 0x%4x, energy : %d \n", pileUp, extra, energy); + if( verbose >= 2 ) printf("PileUp : %d , extra : 0x%04x, energy : %d \n", pileUp, extra, energy); + + if( verbose >= 1 ) printf("ch : %2d, PileUp : %d , energy : %d, timestamp : %u\n", + channel, pileUp, energy, timeStamp); } - - nw ++; - }while( nw < nWord); + } }else{ - printf("incorrect buffer header. \n"); + if( verbose >= 2 ) printf("incorrect buffer header. \n"); break; } + nw++; }while(true); } - unsigned int ReadBuffer(unsigned int nWord, bool verbose = true){ + unsigned int ReadBuffer(unsigned int nWord, int verbose = 0){ if( buffer == NULL ) return 0; unsigned int word = 0; for( int i = 0 ; i < 4 ; i++) word += ((buffer[i + 4 * nWord] & 0xFF) << 8*i); - if( verbose) printf("%d | 0x%08x\n", nWord, word); + if( verbose >= 2) printf("%d | 0x%08x\n", nWord, word); return word; } diff --git a/ClassDigitizer.cpp b/ClassDigitizer.cpp index 91b8ece..d2c49dd 100644 --- a/ClassDigitizer.cpp +++ b/ClassDigitizer.cpp @@ -364,12 +364,12 @@ void Digitizer::ReadData(){ return; } - //ret = CAEN_DGTZ_ReadData(handle, CAEN_DGTZ_SLAVE_TERMINATED_READOUT_MBLT, data->buffer, &(data->nByte)); - //printf("Read Buffer size %d byte \n", data->nByte); - //if (ret || data->nByte == 0) { - // ErrorMsg("ReadData"); - // return; - //} + ret = CAEN_DGTZ_ReadData(handle, CAEN_DGTZ_SLAVE_TERMINATED_READOUT_MBLT, data->buffer, &(data->nByte)); + printf("Read Buffer size %d byte \n", data->nByte); + if (ret || data->nByte == 0) { + ErrorMsg("ReadData"); + return; + } ret = (CAEN_DGTZ_ErrorCode) CAEN_DGTZ_GetDPPEvents(handle, data->buffer, data->BufferSize, reinterpret_cast(&(data->Events)), data->NumEvents); for( int i = 0 ; i < MaxNChannels; i++){ diff --git a/DigitizerPHA.cpp b/DigitizerPHA.cpp index 78445c8..e50bb92 100644 --- a/DigitizerPHA.cpp +++ b/DigitizerPHA.cpp @@ -13,146 +13,56 @@ DigitizerPHA::~DigitizerPHA(){ } int DigitizerPHA::ProgramBoard(){ - Digitizer::ProgramBoard(); - printf("----- program PHA\n"); - /// Set trigger propagation - /// Set analog probe 1 to input - /// Set analog probe 2 to Tranpedoiz - Baseline - /// disable waveform recording - /// enable extrac 2 word - /// record time stamp - /// record energy - /// digitial virtual probe 1 = Peaking - /// digitial virtual probe 2 = trigger - ///ret |= CAEN_DGTZ_WriteRegister(handle, Register::DPP::BoardConfiguration , 0x000F8114); - ret |= CAEN_DGTZ_WriteRegister(handle, Register::DPP::BoardConfiguration , 0x014F8905); - ErrorMsg("PHA-ProgramBoard"); + ret = CAEN_DGTZ_Reset(handle); + printf("======== program board\n"); + + ret = CAEN_DGTZ_WriteRegister(handle, Register::DPP::RecordLength_G + 0x7000, 625); + if( ret != 0 ) { printf("==== set Record Length.\n"); return 0;} + + ret |= CAEN_DGTZ_WriteRegister(handle, Register::DPP::BoardConfiguration, 0x4E8115); + + ret = CAEN_DGTZ_SetAcquisitionMode(handle, CAEN_DGTZ_SW_CONTROLLED); /// software command + + ret |= CAEN_DGTZ_SetIOLevel(handle, CAEN_DGTZ_IOLevel_NIM); + + ret |= CAEN_DGTZ_SetExtTriggerInputMode(handle, CAEN_DGTZ_TRGMODE_ACQ_ONLY); + if( ret != 0 ) { printf("==== CAEN_DGTZ_SetExtTriggerInputMode.\n"); return 0;} + + ret = CAEN_DGTZ_SetChannelEnableMask(handle, 0xFFFF); + if( ret != 0 ) { printf("==== CAEN_DGTZ_SetChannelEnableMask.\n"); return 0;} - /* - ///==================== Set default Channel setting using CAEN function - CAEN_DGTZ_DPP_PHA_Params_t DPPParams; - memset(&DPPParams, 0, sizeof(CAEN_DGTZ_DPP_PHA_Params_t)); + ret = CAEN_DGTZ_SetNumEventsPerAggregate(handle, 0); + if( ret != 0 ) { printf("==== CAEN_DGTZ_SetNumEventsPerAggregate. %d\n", ret); return 0;} - for(int i = 0; i < NChannel; i++){ - DPPParams.M[i] = 100000; /// decay time [ns] - DPPParams.m[i] = 992; /// flat-top [ns] - DPPParams.k[i] = 96; /// rise-time [ns] - DPPParams.ftd[i] = 192; /// flat-top delay, peaking time [ns] - DPPParams.a[i] = 4; /// Trigger Filter smoothing factor, 1, 2, 3, 4, 16, 32 - DPPParams.b[i] = 96; /// input rise time [ns] - DPPParams.thr[i] = 100; /// Threshold [LSB] - DPPParams.nsbl[i] = 3; /// Baseline samples, 0 = 0, when > 0, pow(4, n+1) - DPPParams.nspk[i] = 2; /// peak samples, 4^n - DPPParams.pkho[i] = 992 ; /// peak hold off [ns] - DPPParams.trgho[i] = 480 ; /// trigger hold off [ns] - DPPParams.twwdt[i] = 0 ; /// rise time validation window, 0x1070 - DPPParams.trgwin[i] = 0 ; /// trigger coincident window - DPPParams.dgain[i] = 0; /// digial gain for digial probe, 2^n - DPPParams.enf[i] = 1 ; /// energy normalization factor (fine gain?) - DPPParams.decimation[i] = 0 ; /// waveform decimation, 2^n, when n = 0, disable - DPPParams.blho[i] = 0; /// not use - } + ret = CAEN_DGTZ_SetRunSynchronizationMode(handle, CAEN_DGTZ_RUN_SYNC_Disabled); + if( ret != 0 ) { printf("==== set board error.\n"); return 0;} + + printf("======== program Channels\n"); + + ret |= CAEN_DGTZ_WriteRegister(handle, Register::DPP::PHA::DecayTime + 0x7000 , 5000 ); + ret |= CAEN_DGTZ_WriteRegister(handle, Register::DPP::PHA::TrapezoidFlatTop + 0x7000 , 62 ); + ret |= CAEN_DGTZ_WriteRegister(handle, Register::DPP::PHA::TrapezoidRiseTime + 0x7000 , 6 ); + ret |= CAEN_DGTZ_WriteRegister(handle, Register::DPP::PHA::PeakingTime + 0x7000 , 6 ); + ret |= CAEN_DGTZ_WriteRegister(handle, Register::DPP::PHA::RCCR2SmoothingFactor + 0x7000 , 4 ); + ret |= CAEN_DGTZ_WriteRegister(handle, Register::DPP::PHA::InputRiseTime + 0x7000 , 6 ); + ret |= CAEN_DGTZ_WriteRegister(handle, Register::DPP::PHA::TriggerThreshold + 0x7000 , 64 ); + ret |= CAEN_DGTZ_WriteRegister(handle, Register::DPP::PHA::PeakHoldOff + 0x7000 , 0x3E ); + ret |= CAEN_DGTZ_WriteRegister(handle, Register::DPP::PHA::TriggerHoldOffWidth + 0x7000 , 0x3E ); + ret |= CAEN_DGTZ_WriteRegister(handle, Register::DPP::PHA::RiseTimeValidationWindow + 0x7000 , 0x0 ); - ret = CAEN_DGTZ_SetDPPParameters(handle, channelMask, &DPPParams); - ErrorMsg("PHA-CAEN_DGTZ_SetDPPParameters"); - for(int i=0; ibuffer), &(data->AllocatedSize)); - //ret |= CAEN_DGTZ_MallocDPPEvents(handle, reinterpret_cast(&(data->Events)), &(data->AllocatedSize)) ; + ret |= CAEN_DGTZ_WriteRegister(handle, Register::DPP::NumberEventsPerAggregate_G + 0x7000, 5); + ret |= CAEN_DGTZ_WriteRegister(handle, Register::DPP::AggregateOrganization, 0); + ret |= CAEN_DGTZ_WriteRegister(handle, Register::DPP::MaxNumberOfAggregatePerBlackTransfer, 40); + ret |= CAEN_DGTZ_WriteRegister(handle, Register::DPP::DPPAlgorithmControl + 0x7000, 0xe30200f); + if( ret != 0 ) { printf("==== set channels error.\n"); return 0;} - //WriteRegister(Register::DPP::RecordLength_G, 0x138); - //WriteRegister(Register::DPP::InputDynamicRange, 0x0); - //WriteRegister(Register::DPP::NumberEventsPerAggregate_G, 0x1A); - //WriteRegister(Register::DPP::PreTrigger, 0x1F); - // - //WriteRegister(Register::DPP::PHA::RCCR2SmoothingFactor, 0x2); - //WriteRegister(Register::DPP::PHA::InputRiseTime, 0x6); - //WriteRegister(Register::DPP::PHA::TrapezoidRiseTime, 0x6); - //WriteRegister(Register::DPP::PHA::TrapezoidFlatTop, 0x3E); - //WriteRegister(Register::DPP::PHA::PeakingTime, 0xC); - //WriteRegister(Register::DPP::PHA::DecayTime, 0x186A); - //WriteRegister(Register::DPP::PHA::TriggerThreshold, 0x64); - //WriteRegister(Register::DPP::PHA::RiseTimeValidationWindow, 0x0); - //WriteRegister(Register::DPP::PHA::TriggerHoldOffWidth, 0x1E); - //WriteRegister(Register::DPP::PHA::PeakHoldOff, 0x3E); - //WriteRegister(Register::DPP::DPPAlgorithmControl, 0x0C30200F); - //WriteRegister(Register::DPP::PHA::ShapedTriggerWidth, 0x6); - //WriteRegister(Register::DPP::ChannelDCOffset, 0xCCCC); - //WriteRegister(Register::DPP::PHA::DPPAlgorithmControl2_G, 0x0); - //WriteRegister(Register::DPP::PHA::FineGain, 0xDFB1); - //WriteRegister(Register::DPP::VetoWidth, 0xA); - // - // - //WriteRegister(Register::DPP::BoardConfiguration, 0x14F8905); - //WriteRegister(Register::DPP::AggregateOrganization, 0x2); - //WriteRegister(Register::DPP::AcquisitionControl, 0x0); - //WriteRegister(Register::DPP::GlobalTriggerMask, 0x80000000); - //WriteRegister(Register::DPP::ReadoutControl, 0x10); - - SetRecordLength(4096*4); - SetPreTriggerDuration(1000*4); - SetBaselineSampling(3); - SetDCOffset(0.2); - SetInputDynamicRange(0); - SetPulsePolarity(0); - - SetTriggerThreshold(400); - SetTriggerHoldOff(248); - SetTriggerSmoothingFactor(2); - SetTriggerOutputWidth(6); - SetInputRiseTime(6); - - //SetTrapezoidRescaling(23); - SetTrapezoidRiseTime(31); - SetTrapezoidFlatTop(31); - - SetDecayTime(312); - SetPeakingTime(3); - SetPeakingHoldOff(25); - SetPeakSampling(8); - - SetRiseTimeValidWindow(0); - - SetTrapezoidRescaling(13); - SetEnergyFineGain(30000); - - //AutoSetTrapezoidRescalingAndFindGate(1.0); - - //SetDPPAlgorithmControl(0xC30200E); - //SetEnergyFineGain(0xDFB1); - - SetEventAggregation(2); /// max 511 - SetMaxNumberOfAggregatePerBlackTransfer(4); - SetAggregateOrganization(0); ///0 or 1 = no division in buffer, n = 2^n divsions - - SetRollOverFlag(1); - SetPileUpFlag(1); - SetExtra2WordOption(2); - - ErrorMsg("PHA-ProgramBoard"); printf("End of program board and channels\n"); return ret; @@ -227,35 +137,52 @@ void DigitizerPHA::PrintBoardConfiguration(){ printf(" | | | | | | | | |\n"); cout <<" Board Configuration : 0b" << bitset<32>(value[0]) << endl; printf(" : 0x%x\n", value[0]); - printf(" Bit[ 0] = Auto Data Flush \n"); - printf(" Bit[ 1] = Save decimated waveform \n"); - printf(" Bit[ 2] = Trigger propagation \n"); - printf(" Bit[ 3:10] = must be 001 0001 0 \n"); - printf(" Bit[ 11] = Dual Trace \n"); - printf(" Bit[12:13] = Analog probe 1 : 00 = input, 01 = RC-CR (1st derivative), 10 = RC-CR2 (2nd derivative), 11 = Trapezoid.\n"); - printf(" Bit[14:15] = Analog probe 2 : 00 = input, 01 = Threshold, 10 = Trapezoid - Baseline, 11 = baseline.\n"); - printf(" Bit[ 16] = WaveForm Recording \n"); - printf(" Bit[ 17] = Extras 2 word enable \n"); - printf(" Bit[ 18] = Record Time Stamp \n"); - printf(" Bit[ 19] = Record Energy \n"); - printf(" Bit[20:23] = Digital Virtual probe 1 : \n"); - printf(" 0000: Peaking, shows where the energy is calculated; \n"); - printf(" 0001: ”Armed”, digital input showing where the RC‐CR2 crosses the Threshold\n"); - printf(" 0010: ”Peak Run”, starts with the trigger and last for the whole event\n"); - printf(" 0011: ”Pile‐up”, shows where a pile‐up event occurred\n"); - printf(" 0100: ”Peaking”, shows where the energy is calculated\n"); - printf(" 0101: ”TRG Validation Win”, digital input showing the trigger validation acceptance window TVAW\n"); - printf(" 0110: ”Baseline freeze”, shows where the algorithm stops calculating the baseline and its value is frozen\n"); - printf(" 0111: ”TRG Holdoff”, shows the trigger hold‐off parameter\n"); - printf(" 1000: ”TRG Validation”, shows the trigger validation signal TRG_VAL \n"); - printf(" 1001: ”Acq Busy”, this is 1 when the board is busy (saturated input signal or full memory board) or there is a veto\n"); - printf(" 1010: ”Zero Cross. Win.”, shows the RT Discrimination Width\n"); - printf(" 1011: ”Ext TRG”, shows the external trigger, when available\n"); - printf(" 1100: ”Busy”, shows when the memory board is full.\n"); - printf(" Bit[26:28] = Digital Virtual probe 2 : \n"); - printf(" 000: Trigger\n"); - printf(" other: Reserved\n"); - printf("====================================== \n"); + + printf(" Bit[ 0] = %d = Auto Data Flush \n", value[0] & 0x1); + printf(" Bit[ 1] = %d = Decimated waveform \n", (value[0] >> 1) & 0x1 ); + printf(" Bit[ 2] = %d = Trigger propagation \n", (value[0] >> 2) & 0x1 ); + printf(" Bit[ 3:10] = %d = must be 001 0001 0 = 22 \n", (value[0] >> 3) & 0xFF ); + printf(" Bit[ 11] = %d = Dual Trace \n", (value[0] >> 11) & 0x1 ); + printf(" Bit[12:13] = %d = Analog probe 1 : ",((value[0] >> 12) & 0x3 )); + switch ( ((value[0] >> 12) & 0x3 ) ){ + case 0 : printf("input\n"); break; + case 1 : printf("RC-CR (1st derivative)\n");break; + case 2 : printf("RC-CR2 (2nd derivative)\n"); break; + case 3 : printf("Trapezoid \n"); break; + } + printf(" Bit[14:15] = %d = Analog probe 2 : ", ((value[0] >> 14) & 0x3 )); + switch ( ((value[0] >> 14) & 0x3 ) ){ + case 0 : printf("input\n"); break; + case 1 : printf("Threshold\n"); break; + case 2 : printf("Trapezoid - Baseline\n"); break; + case 3 : printf("baseline.\n"); break; + } + printf(" Bit[ 16] = %d = WaveForm Recording \n",((value[0] >> 16) & 0x1 ) ); + printf(" Bit[ 17] = %d = Extras 2 word enable \n", ((value[0] >> 17) & 0x1 )); + printf(" Bit[ 18] = %d = Record Time Stamp \n", ((value[0] >> 18) & 0x1 )); + printf(" Bit[ 19] = %d = Record Energy \n", ((value[0] >> 19) & 0x1 )); + printf(" Bit[20:23] = %d = Digital Virtual probe 1 : ", ((value[0] >> 20) & 0x7 )); + switch (((value[0] >> 20) & 0xF )) { + case 0: printf("Peaking, shows where the energy is calculated; \n"); break; + case 1: printf("”Armed”, digital input showing where the RC‐CR2 crosses the Threshold\n"); + case 2: printf("”Peak Run”, starts with the trigger and last for the whole event\n"); + case 3: printf("”Pile‐up”, shows where a pile‐up event occurred\n"); + case 4: printf("”Peaking”, shows where the energy is calculated\n"); + case 5: printf("”TRG Validation Win”, digital input showing the trigger validation acceptance window TVAW\n"); + case 6: printf("”Baseline freeze”, shows where the algorithm stops calculating the baseline and its value is frozen\n"); + case 7: printf("”TRG Holdoff”, shows the trigger hold‐off parameter\n"); + case 8: printf("”TRG Validation”, shows the trigger validation signal TRG_VAL \n"); + case 9: printf("”Acq Busy”, this is 1 when the board is busy (saturated input signal or full memory board) or there is a veto\n"); + case 10: printf("”Zero Cross. Win.”, shows the RT Discrimination Width\n"); + case 11: printf("”Ext TRG”, shows the external trigger, when available\n"); + case 12: printf("”Busy”, shows when the memory board is full.\n"); + } + printf(" Bit[26:28] = %d = Digital Virtual probe 2 : ", ((value[0] >> 26) & 0x7 )); + if( ((value[0] >> 26) & 0x7 ) == 0 ) { + printf("Trigger\n"); + }else{ + printf("Reserved\n"); + } } void DigitizerPHA::PrintChannelSettingFromDigitizer(int ch){ diff --git a/test.cpp b/test.cpp index d2d6e94..ee74b21 100644 --- a/test.cpp +++ b/test.cpp @@ -11,9 +11,10 @@ int main(int argc, char* argv[]){ int board = i % 3; int port = i/3; dig[i].OpenDigitizer(board, port, true); - dig[i].OpenSettingBinary("setting_" + to_string(dig[i].GetSerialNumber()) + ".bin"); - dig[i].SetAcqMode("list"); - dig[i].PrintACQStatue(); + dig[i].CreateAndSaveSettingBinary("setting_" + to_string(dig[i].GetSerialNumber()) + ".bin"); + //dig[i].OpenSettingBinary("setting_" + to_string(dig[i].GetSerialNumber()) + ".bin"); + //dig[i].SetAcqMode("list"); + //dig[i].PrintACQStatue(); } //dig[0].WriteRegister(Register::DPP::FrontPanelTRGOUTEnableMask, 0xFF, -1); @@ -34,6 +35,8 @@ int main(int argc, char* argv[]){ //dig[0].PrintChannelSettingFromDigitizer(8); //dig[0].PrintChannelSettingFromDigitizer(9); //dig[0].PrintChannelSettingFromDigitizer(10); + + dig[0].PrintBoardConfiguration(); dig[0].PrintChannelSettingFromDigitizer(4); //dig[0].ReadRegister(Register::DPP::PHA::DPPAlgorithmControl2_G, 13, "DPP Control 2"); //dig[0].ReadRegister(Register::DPP::AcquisitionControl, -1, "Acq control"); // [0:1] @@ -43,25 +46,24 @@ int main(int argc, char* argv[]){ //dig[0].ReadRegister(Register::DPP::DisableExternalTrigger, -1, "Disable External Trigger"); //dig[0].ReadRegister(Register::DPP::TriggerValidationMask, -1, "Trigger validation Mask"); - - - //dig[0].PrintChannelSettingFromDigitizer(15); Data * data = dig[0].data; data->AllocateMemory(); dig[0].StartACQ(); - - sleep(1); - - dig[0].ReadData(); + + for( int p = 0; p < 11; p++){ + sleep(1); + dig[0].ReadData(); + } //printf("|%s|\n", data->buffer); dig[0].StopACQ(); - data->ReadAllBuffer(); + data->ReadAllBuffer(1); + delete [] dig; //delete psd; diff --git a/test_indep.cpp b/test_indep.cpp index dc396ce..0f322bc 100644 --- a/test_indep.cpp +++ b/test_indep.cpp @@ -98,6 +98,65 @@ void PrintChannelSettingFromDigitizer(int handle, int ch, float ch2ns){ } +void PrintBoardConfiguration(int handle){ + printf("\e[33m================================================\n"); + printf("================ Setting for Board \n"); + printf("================================================\e[0m\n"); + uint32_t * value = new uint32_t[1]; + CAEN_DGTZ_ReadRegister(handle, (uint32_t) Register::BoardConfiguration, value); + printf(" 32 28 24 20 16 12 8 4 0\n"); + printf(" | | | | | | | | |\n"); + cout <<" Board Configuration : 0b" << bitset<32>(value[0]) << endl; + printf(" : 0x%x\n", value[0]); + + printf(" Bit[ 0] = %d = Auto Data Flush \n", value[0] & 0x1); + printf(" Bit[ 1] = %d = Decimated waveform \n", (value[0] >> 1) & 0x1 ); + printf(" Bit[ 2] = %d = Trigger propagation \n", (value[0] >> 2) & 0x1 ); + printf(" Bit[ 3:10] = %d = must be 001 0001 0 = 22 \n", (value[0] >> 3) & 0xFF ); + printf(" Bit[ 11] = %d = Dual Trace \n", (value[0] >> 11) & 0x1 ); + printf(" Bit[12:13] = %d = Analog probe 1 : ",((value[0] >> 12) & 0x3 )); + switch ( ((value[0] >> 12) & 0x3 ) ){ + case 0 : printf("input\n"); break; + case 1 : printf("RC-CR (1st derivative)\n");break; + case 2 : printf("RC-CR2 (2nd derivative)\n"); break; + case 3 : printf("Trapezoid \n"); break; + } + printf(" Bit[14:15] = %d = Analog probe 2 : ", ((value[0] >> 14) & 0x3 )); + switch ( ((value[0] >> 14) & 0x3 ) ){ + case 0 : printf("input\n"); break; + case 1 : printf("Threshold\n"); break; + case 2 : printf("Trapezoid - Baseline\n"); break; + case 3 : printf("baseline.\n"); break; + } + printf(" Bit[ 16] = %d = WaveForm Recording \n",((value[0] >> 16) & 0x1 ) ); + printf(" Bit[ 17] = %d = Extras 2 word enable \n", ((value[0] >> 17) & 0x1 )); + printf(" Bit[ 18] = %d = Record Time Stamp \n", ((value[0] >> 18) & 0x1 )); + printf(" Bit[ 19] = %d = Record Energy \n", ((value[0] >> 19) & 0x1 )); + printf(" Bit[20:23] = %d = Digital Virtual probe 1 : ", ((value[0] >> 20) & 0x7 )); + switch (((value[0] >> 20) & 0xF )) { + case 0: printf("Peaking, shows where the energy is calculated; \n"); break; + case 1: printf("”Armed”, digital input showing where the RC‐CR2 crosses the Threshold\n"); + case 2: printf("”Peak Run”, starts with the trigger and last for the whole event\n"); + case 3: printf("”Pile‐up”, shows where a pile‐up event occurred\n"); + case 4: printf("”Peaking”, shows where the energy is calculated\n"); + case 5: printf("”TRG Validation Win”, digital input showing the trigger validation acceptance window TVAW\n"); + case 6: printf("”Baseline freeze”, shows where the algorithm stops calculating the baseline and its value is frozen\n"); + case 7: printf("”TRG Holdoff”, shows the trigger hold‐off parameter\n"); + case 8: printf("”TRG Validation”, shows the trigger validation signal TRG_VAL \n"); + case 9: printf("”Acq Busy”, this is 1 when the board is busy (saturated input signal or full memory board) or there is a veto\n"); + case 10: printf("”Zero Cross. Win.”, shows the RT Discrimination Width\n"); + case 11: printf("”Ext TRG”, shows the external trigger, when available\n"); + case 12: printf("”Busy”, shows when the memory board is full.\n"); + } + printf(" Bit[26:28] = %d = Digital Virtual probe 2 : ", ((value[0] >> 26) & 0x7 )); + if( ((value[0] >> 26) & 0x7 ) == 0 ) { + printf("Trigger\n"); + }else{ + printf("Reserved\n"); + } + printf("====================================== \n"); +} + unsigned int ReadBuffer(unsigned int nWord, char * buffer, bool verbose = true){ if( buffer == NULL ) return 0; @@ -136,15 +195,18 @@ int main(int argc, char* argv[]){ printf("======== program board\n"); - //ret |= CAEN_DGTZ_SetDPPAcquisitionMode(handle, CAEN_DGTZ_DPP_ACQ_MODE_List, CAEN_DGTZ_DPP_SAVE_PARAM_EnergyAndTime); - ret |= CAEN_DGTZ_SetDPPAcquisitionMode(handle, CAEN_DGTZ_DPP_ACQ_MODE_Mixed, CAEN_DGTZ_DPP_SAVE_PARAM_EnergyAndTime); - - ret |= CAEN_DGTZ_WriteRegister(handle, 0x8000, 0x01000114); /// Channel Control Reg (indiv trg, seq readout) ?? + ///ret |= CAEN_DGTZ_SetDPPAcquisitionMode(handle, CAEN_DGTZ_DPP_ACQ_MODE_List, CAEN_DGTZ_DPP_SAVE_PARAM_EnergyAndTime); + ///ret |= CAEN_DGTZ_SetDPPAcquisitionMode(handle, CAEN_DGTZ_DPP_ACQ_MODE_Mixed, CAEN_DGTZ_DPP_SAVE_PARAM_EnergyAndTime); /// Board Configure can do that /// Set the number of samples for each waveform - ret |= CAEN_DGTZ_SetRecordLength(handle, 1000); + ret = CAEN_DGTZ_WriteRegister(handle, Register::DPP::RecordLength_G + 0x7000, 625); if( ret != 0 ) { printf("==== set Record Length.\n"); return 0;} + + //ret |= CAEN_DGTZ_WriteRegister(handle, Register::DPP::BoardConfiguration, 0x4F8115); // with wave + ret |= CAEN_DGTZ_WriteRegister(handle, Register::DPP::BoardConfiguration, 0x4E8115); // with-out wave + + /// Set the digitizer acquisition mode (CAEN_DGTZ_SW_CONTROLLED or CAEN_DGTZ_S_IN_CONTROLLED) ret = CAEN_DGTZ_SetAcquisitionMode(handle, CAEN_DGTZ_SW_CONTROLLED); /// software command @@ -216,7 +278,7 @@ int main(int argc, char* argv[]){ ret |= CAEN_DGTZ_WriteRegister(handle, Register::DPP::InputDynamicRange + 0x7000 , 0x0 ); - ret |= CAEN_DGTZ_WriteRegister(handle, Register::DPP::BoardConfiguration , 0x10E0114 ); + //ret |= CAEN_DGTZ_WriteRegister(handle, Register::DPP::BoardConfiguration , 0x10E0114 ); ret |= CAEN_DGTZ_WriteRegister(handle, Register::DPP::NumberEventsPerAggregate_G + 0x7000, 5); ret |= CAEN_DGTZ_WriteRegister(handle, Register::DPP::AggregateOrganization, 0); ret |= CAEN_DGTZ_WriteRegister(handle, Register::DPP::MaxNumberOfAggregatePerBlackTransfer, 40); @@ -246,6 +308,7 @@ int main(int argc, char* argv[]){ if( ret != 0 ) { printf("==== memory allocation error.\n"); return 0;} + PrintBoardConfiguration(handle); PrintChannelSettingFromDigitizer(handle, 4, ch2ns); printf("============ Start ACQ \n"); @@ -324,10 +387,11 @@ int main(int argc, char* argv[]){ unsigned int AggCounter = ReadBuffer(nw, buffer); printf("Agg Counter : %d \n", AggCounter); - printf("---------------------- Dual Channel Block\n"); + for( int chMask = 0; chMask < 8 ; chMask ++ ){ if( ((ChannelMask >> chMask) & 0x1 ) == 0 ) continue; + printf("---------------------- Dual Channel Block : %d\n", chMask *2 ); nw = nw + 1; word = ReadBuffer(nw, buffer); bool hasFormatInfo = ((word >> 31) & 0x1); unsigned int aggSize = ( word & 0x3FFFFFF ) ; @@ -377,8 +441,8 @@ int main(int argc, char* argv[]){ unsigned int wave0 = ( word & 0x3FFF); if( ev == 0 ){ - printf(" %5d, %d \n", wave0, isTrigger0); - printf(" %5d, %d \n", wave1, isTrigger1); + printf("%4d| %5d, %d \n", 2*wi, wave0, isTrigger0); + printf("%4d| %5d, %d \n", 2*wi+1, wave1, isTrigger1); } }