#include "DigitizerPHA.h" DigitizerPHA::DigitizerPHA(){ } DigitizerPHA::DigitizerPHA(int boardID, int portID){ OpenDigitizer(boardID, portID); } DigitizerPHA::~DigitizerPHA(){ } int DigitizerPHA::ProgramBoard(){ Digitizer::ProgramBoard(); /// 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::BoardConfiguration , 0x000E8114); /// Channel Control Reg (indiv trg, seq readout) ?? ErrorMsg("PHA-ProgramBoard"); return ret; } void DigitizerPHA::SetAnalogProbe1(unsigned int bit) { SetBits(Register::BoardConfiguration, bit, 2, 12); ErrorMsg("PHA-SetAnalogProbe1"); } void DigitizerPHA::SetAnalogProbe2(unsigned int bit) { SetBits(Register::BoardConfiguration, bit, 2, 14); ErrorMsg("PHA-SetAnalogProbe1"); } void DigitizerPHA::SetWaveFormRecording(bool OnOff) { SetBits(Register::BoardConfiguration, OnOff, 1, 16); ErrorMsg("PHA-SetWaveFormRecording"); } void DigitizerPHA::SetExtra2WordOutput(bool OnOff) { SetBits(Register::BoardConfiguration, OnOff, 1, 17); ErrorMsg("PHA-SetExtra2WordOutput");} void DigitizerPHA::SetTimeStampRecording(bool OnOff) { SetBits(Register::BoardConfiguration, OnOff, 1, 18); ErrorMsg("PHA-SetTimeStampRecording"); } void DigitizerPHA::SetEnergyRecording(bool OnOff) { SetBits(Register::BoardConfiguration, OnOff, 1, 19); ErrorMsg("PHA-SetEnergyRecording");} void DigitizerPHA::SetVirtualProbe1(unsigned int bit){ SetBits(Register::BoardConfiguration, bit, 4, 20); ErrorMsg("PHA-SetVirtualProbe1"); } void DigitizerPHA::SetTrapezoidRescaling(unsigned int rightShiftBits, int ch ){ SetBits(Register::DPP::DPPAlgorithmControl, rightShiftBits, 5, 0, ch); ErrorMsg("SetTrapezoidRescaling"); } void DigitizerPHA::SetPeakSampling(unsigned int bit, int ch) { SetBits(Register::DPP::DPPAlgorithmControl, bit, 2, 12, ch); ErrorMsg("SetPeakSampling");} void DigitizerPHA::SetPulsePolarity(bool PositiveIsZero, int ch) { SetBits(Register::DPP::DPPAlgorithmControl, PositiveIsZero, 1, 16, ch); ErrorMsg("SetPulsePolarity");} void DigitizerPHA::SetBaselineSampling(unsigned int bit, int ch) { SetBits(Register::DPP::DPPAlgorithmControl, bit, 3, 20, ch); ErrorMsg("SetBaselineSampling"); } void DigitizerPHA::SetRollOverFlag(bool isRollOver, int ch) { SetBits(Register::DPP::DPPAlgorithmControl, isRollOver, 1, 26, ch); ErrorMsg("SetRollOverFlag");} void DigitizerPHA::SetPileUpFlag(bool isPileUpFlag, int ch) { SetBits(Register::DPP::DPPAlgorithmControl, isPileUpFlag, 1, 27, ch); ErrorMsg("SetPileUpFlag");} void DigitizerPHA::SetExtra2WordOption(unsigned int bit, int ch) { SetBits(Register::DPP::PHA::DPPAlgorithmControl2, bit, 3, 8, ch); ErrorMsg("PHA-SetExtra2WordOption");} void DigitizerPHA::SetTriggerThreshold(unsigned int threshold, int ch ) { WriteRegister(Register::DPP::PHA::TriggerThreshold, threshold & 0x03FF, ch); ErrorMsg("PHA-SetTriggerThreshold");} void DigitizerPHA::SetTriggerHoldOff(unsigned int nSample, int ch ) { WriteRegister(Register::DPP::PHA::TriggerHoldOffWidth, nSample & 0x03FF, ch); ErrorMsg("PHA-SetTriggerHoldOff"); } void DigitizerPHA::SetTriggerSmoothingFactor(unsigned int bit, int ch ) { WriteRegister(Register::DPP::PHA::RCCR2SmoothingFactor, bit & 0x0001, ch); ErrorMsg("PHA-SetTriggerSmoothingFactor");} void DigitizerPHA::SetInputRiseTime(unsigned int nSample, int ch ) { WriteRegister(Register::DPP::PHA::InputRiseTime, nSample & 0x00FF, ch); ErrorMsg("PHA-SetInputRiseTime");} void DigitizerPHA::SetTrapezoidRiseTime(unsigned int nSample, int ch ) { WriteRegister(Register::DPP::PHA::TrapezoidRiseTime, nSample & 0x0FFF, ch); ErrorMsg("PHA-SetTrapezoidRiseTime");} void DigitizerPHA::SetTrapezoidFlatTop(unsigned int nSample, int ch ) { WriteRegister(Register::DPP::PHA::TrapezoidFlatTop, nSample & 0x0FFF, ch); ErrorMsg("PHA-SetTrapezoidFlatTop");} void DigitizerPHA::SetDecayTime(unsigned int nSample, int ch ) { WriteRegister(Register::DPP::PHA::DecayTime, nSample & 0xFFFF, ch); ErrorMsg("PHA-SetDecayTime");} void DigitizerPHA::SetPeakingTime(unsigned int nSample, int ch ) { WriteRegister(Register::DPP::PHA::PeakingTime, nSample & 0x0FFF, ch); ErrorMsg("PHA-SetPeakingTime");} void DigitizerPHA::SetPeakingHoldOff(unsigned int nSample, int ch ) { WriteRegister(Register::DPP::PHA::PeakHoldOff, nSample & 0x03FF, ch); ErrorMsg("PHA-SetPeakingHoldOff");} void DigitizerPHA::SetEnergyFineGain(unsigned int gain, int ch ) { WriteRegister(Register::DPP::PHA::FineGain, gain & 0xFFFF, ch); ErrorMsg("PHA-SetEnergyFineGain");} void DigitizerPHA::SetRiseTimeValidWindow(unsigned int nSample, int ch ){ WriteRegister(Register::DPP::PHA::RiseTimeValidationWindow,nSample & 0x03FF, ch); ErrorMsg("PHA-SetRiseTimeValidWindow");} void DigitizerPHA::PrintBoardConfiguration(){ if( !isConnected ) return; 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(" 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"); } void DigitizerPHA::GetChannelSettingFromDigitizer(int ch){ if( !isConnected ) return; uint32_t * value = new uint32_t[NChannel]; printf("\e[33m================================================\n"); printf("================ Setting for channel %d \n", ch); printf("================================================\e[0m\n"); ///DPP algorithm Control CAEN_DGTZ_ReadRegister(handle, Register::DPP::DPPAlgorithmControl + (ch << 8), value); printf(" 32 28 24 20 16 12 8 4 0\n"); printf(" | | | | | | | | |\n"); cout <<" DPP algorithm Control : 0b" << bitset<32>(value[0]) << endl; int trapRescaling = int(value[0]) & 0x1f ; int polarity = int(value[0] >> 16) & 0x1; /// in bit[16] int baseline = int(value[0] >> 20) & 0x7; /// in bit[22:20] int NsPeak = int(value[0] >> 12) & 0x3; /// in bit[13:12] int rollOver = int(value[0] >> 26) & 0x1; int pileUp = int(value[0] >> 27) & 0x1; ///DPP algorithm Control 2 CAEN_DGTZ_ReadRegister(handle, Register::DPP::PHA::DPPAlgorithmControl2 + (ch << 8), value); cout <<" DPP algorithm Control 2: 0b" << bitset<32>(value[0]) << endl; int extras2WordOption = int(value[0] >> 8) & 0x3; string extra2WordOptStr = ""; switch (extras2WordOption){ case 0 : extra2WordOptStr = "[0:15] Baseline *4 [16:31] Extended Time Stamp"; break; case 2 : extra2WordOptStr = "[0:15] Fine Time Stamp [16:31] Extended Time Stamp"; break; case 4 : extra2WordOptStr = "[0:15] Total Trigger Counter [16:31] Lost Trigger Counter"; break; case 5 : extra2WordOptStr = "[0:15] Event After the Zero Crossing [16:31] Event Before the Zero Crossing"; break; default: extra2WordOptStr = "Reserved"; break; } printf(" ch2ns : %.0f ns\n", ch2ns); printf("==========----- input \n"); CAEN_DGTZ_ReadRegister(handle, Register::DPP::RecordLength + (ch << 8), value); printf("%24s %5d samples = %5.0f ns \n", "Record Length", ((value[0] * 8) & MaxRecordLength), ((value[0] * 8) & MaxRecordLength) * ch2ns); ///Record length CAEN_DGTZ_ReadRegister(handle, Register::DPP::PreTrigger + (ch << 8), value); printf("%24s %5d samples = %5.0f ns \n", "Pre-tigger", value[0] * 4, value[0] * 4 * ch2ns); ///Pre-trigger printf("%24s %5.0f samples, DPP-[20:22]\n", "baseline mean", pow(4, 1 + baseline)); ///Ns baseline CAEN_DGTZ_ReadRegister(handle, Register::DPP::ChannelDCOffset + (ch << 8), value); printf("%24s %.2f %% of %d\n", "DC offset", value[0] * 100./ ADCFullSize, ADCFullSize); ///DC offset CAEN_DGTZ_ReadRegister(handle, Register::DPP::InputDynamicRange + (ch << 8), value); printf("%24s %.1f Vpp \n", "input Dynamic", value[0] == 0 ? 2 : 0.5); ///InputDynamic printf("%24s %s, DPP-[16]\n", "polarity", polarity == 0 ? "Positive" : "negative"); ///Polarity CAEN_DGTZ_TriggerPolarity_t * triggerPolarity; CAEN_DGTZ_GetTriggerPolarity(handle, ch, triggerPolarity); printf("%24s %s \n", "trigger polarity", triggerPolarity[0] == 0 ? "Positive" : "negative"); ///Polarity printf("==========----- discriminator \n"); CAEN_DGTZ_ReadRegister(handle, Register::DPP::PHA::TriggerThreshold + (ch << 8), value); printf("%24s %4d LSB\n", "Threshold", value[0]); ///Threshold CAEN_DGTZ_ReadRegister(handle, Register::DPP::PHA::TriggerHoldOffWidth + (ch << 8), value); printf("%24s %4d samples, %5.0f ns \n", "trigger hold off", value[0], value[0] * 4 * ch2ns); ///Trigger Hold off CAEN_DGTZ_ReadRegister(handle, Register::DPP::PHA::RCCR2SmoothingFactor + (ch << 8), value); printf("%24s %4d samples, %5.0f ns \n", "Fast Dis. smoothing", (value[0] & 0x1f) * 2, (value[0] & 0x1f) * 2 * ch2ns ); ///Fast Discriminator smoothing CAEN_DGTZ_ReadRegister(handle, Register::DPP::PHA::ShapedTriggerWidth + (ch << 8), value); printf("%24s %4d samples, %5.0f ns \n", "Fast Dis. output width", value[0], value[0] * 4 * ch2ns); ///Fast Dis. output width CAEN_DGTZ_ReadRegister(handle, Register::DPP::PHA::InputRiseTime + (ch << 8), value); printf("%24s %4d samples, %5.0f ns \n", "Input rise time ", value[0], value[0] * 4 * ch2ns); ///Input rise time printf("==========----- Trapezoid \n"); printf("%24s %4d bit = Floor( rise x decay / 64 ), DPP-[0:5]\n", "Trap. Rescaling", trapRescaling ); ///Trap. Rescaling Factor CAEN_DGTZ_ReadRegister(handle, Register::DPP::PHA::TrapezoidRiseTime + (ch << 8), value); printf("%24s %4d samples, %5.0f ns \n", "Trap. rise time", value[0], value[0] * 4 * ch2ns); ///Trap. rise time, 2 for 1 ch to 2ns CAEN_DGTZ_ReadRegister(handle, Register::DPP::PHA::TrapezoidFlatTop + (ch << 8), value); printf("%24s %4d samples, %5.0f ns \n", "Trap. flat time", value[0], value[0] * 4 * ch2ns); ///Trap. flat time int flatTopTime = value[0] * 4 * ch2ns; CAEN_DGTZ_ReadRegister(handle, Register::DPP::PHA::DecayTime + (ch << 8), value); printf("%24s %4d samples, %5.0f ns \n", "Decay time", value[0], value[0] * 4 * ch2ns); ///Trap. pole zero CAEN_DGTZ_ReadRegister(handle, Register::DPP::PHA::PeakingTime + (ch << 8), value); printf("%24s %4d samples, %5.0f ns = %.2f %% of FlatTop\n", "Peaking time", value[0], value[0] * 4 * ch2ns, value[0] * 400. * ch2ns / flatTopTime ); ///Peaking time CAEN_DGTZ_ReadRegister(handle, Register::DPP::PHA::PeakHoldOff + (ch << 8), value); printf("%24s %4d samples, %5.0f ns \n", "Peak hole off", value[0], value[0] * 4 *ch2ns ); ///Peak hold off printf("%24s %4.0f samples, DPP-[12:13]\n", "Peak mean", pow(4, NsPeak)); ///Ns peak printf("==========----- Other \n"); CAEN_DGTZ_ReadRegister(handle, Register::DPP::PHA::FineGain + (ch << 8), value); printf("%24s %d \n", "Energy fine gain", value[0]); ///Energy fine gain CAEN_DGTZ_ReadRegister(handle, Register::DPP::ChannelADCTemperature + (ch << 8), value); printf("%24s %d C\n", "Temperature", value[0]); ///Temperature CAEN_DGTZ_ReadRegister(handle, Register::DPP::PHA::RiseTimeValidationWindow + (ch << 8), value); printf("%24s %.0f ns \n", "RiseTime Vaild Win.", value[0] * ch2ns); CAEN_DGTZ_ReadRegister(handle, Register::DPP::NumberEventsPerAggregate + (ch << 8), value); printf("%24s %d \n", "Event Aggregate", value[0] & 0x3FF); CAEN_DGTZ_ReadRegister(handle, Register::DPP::PHA::ChannelStopAcquisition + (ch << 8), value); printf("%24s %d = %s \n", "Stop Acq bit", value[0] & 1 , (value[0] & 1 ) == 0 ? "Run" : "Stop"); CAEN_DGTZ_ReadRegister(handle, Register::DPP::ChannelStatus + (ch << 8), value); printf("%24s 0x%x \n", "Status bit", (value[0] & 0xff) ); CAEN_DGTZ_ReadRegister(handle, Register::DPP::AMCFirmwareRevision + (ch << 8), value); printf("%24s 0x%x \n", "AMC firmware rev.", value[0] ); CAEN_DGTZ_ReadRegister(handle, Register::DPP::VetoWidth + (ch << 8), value); printf("%24s 0x%x \n", "VetoWidth bit", value[0] ); printf("%24s %d = %s\n", "RollOverFlag, DPP-[26]", rollOver, rollOver ? "enable" : "disable" ); printf("%24s %d = %s\n", "Pile-upFlag, DPP-[27]", pileUp, pileUp ? "enable" : "disable" ); printf("%24s %d, %s \n", "Extra2 opt, DPP2-[8:10]", extras2WordOption, extra2WordOptStr.c_str()); printf("========================================= end of ch-%d\n", ch); }