From cc2f336a6cf027f31b252184f01bdd5196fa258c Mon Sep 17 00:00:00 2001 From: splitPoleDAQ Date: Mon, 19 Feb 2024 16:42:04 -0500 Subject: [PATCH] added Trapazoid Rescaling and fine Gate calculation for PHA --- ClassDigitizer.cpp | 38 ++++++++++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 10 deletions(-) diff --git a/ClassDigitizer.cpp b/ClassDigitizer.cpp index cc9a872..30731fc 100644 --- a/ClassDigitizer.cpp +++ b/ClassDigitizer.cpp @@ -502,16 +502,6 @@ void Digitizer::StartACQ(){ } data->AllocateMemory(bufferSize); - ret = CAEN_DGTZ_SWStartAcquisition(handle); - - if( ret != 0 ) { - ErrorMsg("Start ACQ"); - return; - } - - printf("\e[1m\e[33m======= Acquisition Started for %d | Board %d, Port %d\e[0m\n", BoardInfo.SerialNumber, boardID, portID); - AcqRun = true; - data->ClearTriggerRate(); unsigned int acqID = ExtractBits(GetSettingFromMemory(DPP::AcquisitionControl), DPP::Bit_AcquistionControl::StartStopMode); unsigned int trgOutID = ExtractBits(GetSettingFromMemory(DPP::FrontPanelIOControl), DPP::Bit_FrontPanelIOControl::TRGOUTConfig); @@ -529,7 +519,35 @@ void Digitizer::StartACQ(){ } } + if( DPPType == DPPType::DPP_PHA_CODE ) { + + printf(" Setting Trapzoid Scaling Factor and Fine Gain \n"); + for( int ch = 0; ch < NumRegChannel; ch++){ + unsigned int riseTime = GetSettingFromMemory(DPP::PHA::TrapezoidRiseTime, ch); + unsigned int decayTime = GetSettingFromMemory(DPP::PHA::DecayTime, ch); + unsigned int SHF = std::floor(std::log2(riseTime * decayTime)); + SetBits(DPP::DPPAlgorithmControl, DPP::Bit_DPPAlgorithmControl_PHA::TrapRescaling, SHF, ch); + + //Always fix the fineGate = fg = 1 + unsigned int f = 0xFFFF * pow(2, SHF)/ riseTime / decayTime; + WriteRegister(DPP::PHA::FineGain, f, ch); + + } + + } + printf(" ACQ mode : %s (%d), TRG-OUT mode : %s (%d) \n", acqStr.c_str(), acqID, trgOutStr.c_str(), trgOutID); + + ret = CAEN_DGTZ_SWStartAcquisition(handle); + if( ret != 0 ) { + ErrorMsg("Start ACQ"); + return; + } + + printf("\e[1m\e[33m======= Acquisition Started for %d | Board %d, Port %d\e[0m\n", BoardInfo.SerialNumber, boardID, portID); + AcqRun = true; + data->ClearTriggerRate(); + } void Digitizer::StopACQ(){