adjust the defalut PHA parameter

This commit is contained in:
Ryan Tang 2023-01-13 16:12:43 -05:00
parent 6cf0d30d8b
commit 82623988ab
4 changed files with 201 additions and 87 deletions

View File

@ -75,11 +75,15 @@ std::string Digitizer2Gen::GetPath(uint64_t handle){
} }
//########################################### Read Write //########################################### Read Write
std::string Digitizer2Gen::ReadValue(const char * parameter){ std::string Digitizer2Gen::ReadValue(const char * parameter, bool verbose = false){
if( !isConnected ) return "not connected"; if( !isConnected ) return "not connected";
//printf(" %s|%s \n", __func__, parameter); //printf(" %s|%s \n", __func__, parameter);
ret = CAEN_FELib_GetValue(handle, parameter, retValue); ret = CAEN_FELib_GetValue(handle, parameter, retValue);
if (ret != CAEN_FELib_Success) return ErrorMsg(__func__); if (ret != CAEN_FELib_Success) {
return ErrorMsg(__func__);
}else{
if( verbose ) printf("%s : %s\n", parameter, retValue.c_str());
}
return retValue; return retValue;
} }
@ -150,7 +154,6 @@ int Digitizer2Gen::OpenDigitizer(const char * url){
///SendCommand("/cmd/reset"); ///SendCommand("/cmd/reset");
return 0; return 0;
} }
@ -169,7 +172,7 @@ int Digitizer2Gen::CloseDigitizer(){
//########################################### DAQ //########################################### DAQ
void Digitizer2Gen::StartACQ(){ void Digitizer2Gen::StartACQ(){
SendCommand("/cmd/armacquisition"); SendCommand("/cmd/armacquisition"); // this will also clear data
SendCommand("/cmd/swstartacquisition"); SendCommand("/cmd/swstartacquisition");
} }
@ -303,6 +306,47 @@ void Digitizer2Gen::SetPHADataFormat(unsigned short dataFormat){
ErrorMsg("Set Read Data Format"); ErrorMsg("Set Read Data Format");
return; return;
} }
//TODO Statistic handle and endpoint
ret = CAEN_FELib_GetHandle(handle, "/endpoint/dpppha/stats", &stat_handle);
ret |= CAEN_FELib_SetReadDataFormat(stat_handle,
" [ \
{ \"name\": \"REAL_TIME\", \"type\": \"U64\", \"dim\": 1 }, \
{ \"name\": \"DEAD_TIME\", \"type\": \"U64\", \"dim\": 1 }, \
{ \"name\": \"LIVE_TIME\", \"type\": \"U64\", \"dim\": 1 }, \
{ \"name\": \"TRIGGER_CNT\", \"type\": \"U32\", \"dim\": 1 }, \
{ \"name\": \"SAVED_EVENT_CNT\", \"type\": \"U32\", \"dim\": 1 } \
]"
);
if (ret != CAEN_FELib_Success) {
ErrorMsg("Set Statistics");
return;
}
}
int Digitizer2Gen::ReadStat(){
ret = CAEN_FELib_ReadData(stat_handle, 100,
realTime,
deadTime,
liveTime,
triggerCount,
savedEventCount
);
if (ret != CAEN_FELib_Success) ErrorMsg("Read Statistics");
return ret;
}
void Digitizer2Gen::PrintStat(){
printf("ch | Real Time | Dead Time | Live Time | Trigger | Saved \n");
for( int i = 0; i < MaxNumberOfChannel; i++){
printf("%02d | %9lu | %9lu | %9lu | %7u | %7u \n",
i, realTime[i], deadTime[i], liveTime[i], triggerCount[i], savedEventCount[i]);
}
} }
int Digitizer2Gen::ReadData(){ int Digitizer2Gen::ReadData(){
@ -391,9 +435,6 @@ int Digitizer2Gen::ReadData(){
} }
} }
void Digitizer2Gen::ReadDataRaw(){
}
//########################################### //###########################################
void Digitizer2Gen::OpenOutFile(std::string fileName){ void Digitizer2Gen::OpenOutFile(std::string fileName){
@ -486,58 +527,87 @@ void Digitizer2Gen::ProgramPHA(bool testPulse){
// Global trigger configuration // Global trigger configuration
if( testPulse ) { if( testPulse ) {
WriteValue("/par/GlobalTriggerSource", "SwTrg | TestPulse"); WriteValue("/par/GlobalTriggerSource", "SwTrg | TestPulse");
WriteValue("/par/TestPulsePeriod" , "500000"); // 0.5 msec = 2kHz
WriteValue("/par/TestPulseWidth" , "1000"); // nsec
WriteValue("/par/TestPulseLowLevel" , "0");
WriteValue("/par/TestPulseHighLevel" , "10000");
}else{ }else{
WriteValue("/par/GlobalTriggerSource", "SwTrg"); WriteValue("/par/GlobalTriggerSource", "SwTrg");
} }
WriteValue("/par/TestPulsePeriod" , "500000"); // 0.5 msec = 2kHz
WriteValue("/par/TestPulseWidth" , "16");
// Wave configuration // Wave configuration
WriteValue("/ch/0..63/par/WaveTriggerSource" , "GlobalTriggerSource"); WriteValue("/ch/0..63/par/WaveTriggerSource" , "ChSelfTrigger");
WriteValue("/ch/0..63/par/ChRecordLengthS" , "512"); WriteValue("/ch/0..63/par/ChRecordLengthS" , "512"); /// 4096 ns
WriteValue("/ch/0..63/par/ChPreTriggerS" , "100"); WriteValue("/ch/0..63/par/ChPreTriggerS" , "125"); /// 1000 ns
WriteValue("/ch/0..63/par/WaveResolution" , "RES8"); /// 8 ns WriteValue("/ch/0..63/par/WaveResolution" , "RES8"); /// 8 ns
WriteValue("/ch/0..63/par/DCOffset" , "10"); /// 10%
WriteValue("/ch/0..63/par/WaveAnalogProbe0" , "ADCInput"); WriteValue("/ch/0..63/par/WaveAnalogProbe0" , "ADCInput");
WriteValue("/ch/0..63/par/WaveAnalogProbe1" , "EnergyFilter"); WriteValue("/ch/0..63/par/WaveAnalogProbe1" , "EnergyFilterMinusBaseline");
WriteValue("/ch/0..63/par/WaveDigitalProbe0" , "Trigger"); WriteValue("/ch/0..63/par/WaveDigitalProbe0" , "Trigger");
WriteValue("/ch/0..63/par/WaveDigitalProbe1" , "TimeFilterArmed"); WriteValue("/ch/0..63/par/WaveDigitalProbe1" , "EnergyFilterPeaking");
WriteValue("/ch/0..63/par/WaveDigitalProbe2" , "EnergyFilterPeaking"); WriteValue("/ch/0..63/par/WaveDigitalProbe2" , "TimeFilterArmed");
WriteValue("/ch/0..63/par/WaveDigitalProbe3" , "EnergyFilterPeakReady"); WriteValue("/ch/0..63/par/WaveDigitalProbe3" , "EnergyFilterPeakReady");
// Event configuration // Event configuration
WriteValue("/ch/0..63/par/EventTriggerSource", "GlobalTriggerSource"); //WriteValue("/ch/0..63/par/EventTriggerSource", "GlobalTriggerSource");
WriteValue("/ch/0..63/par/EventTriggerSource", "ChSelfTrigger");
// Filter parameters // Filter parameters
WriteValue("/ch/0..63/par/TimeFilterRiseTimeS" , "10"); WriteValue("/ch/0..63/par/TimeFilterRiseTimeS" , "10"); // 80 ns
WriteValue("/ch/0..63/par/TriggerThr" , "100"); WriteValue("/ch/0..63/par/TriggerThr" , "1000");
WriteValue("/ch/0..63/par/PulsePolarity" , "Positive"); WriteValue("/ch/0..63/par/PulsePolarity" , "Positive");
WriteValue("/ch/0..63/par/EnergyFilterBaselineAvg" , "Medium"); WriteValue("/ch/0..63/par/EnergyFilterBaselineAvg" , "Medium"); // 1024 sample
WriteValue("/ch/0..63/par/EnergyFilterFineGain" , "1.0"); WriteValue("/ch/0..63/par/EnergyFilterFineGain" , "1.0");
WriteValue("/ch/0..63/par/EnergyFilterRiseTimeS" , "100"); WriteValue("/ch/0..63/par/EnergyFilterRiseTimeS" , "62"); // 496 ns
WriteValue("/ch/0..63/par/EnergyFilterFlatTopS" , "100"); WriteValue("/ch/0..63/par/EnergyFilterFlatTopS" , "200"); // 1600 ns
WriteValue("/ch/0..63/par/EnergyFilterPoleZeroS" , "1000"); WriteValue("/ch/0..63/par/EnergyFilterPoleZeroS" , "6250"); // 50 us
WriteValue("/ch/0..63/par/EnergyFilterPeakingPosition" , "80"); WriteValue("/ch/0..63/par/EnergyFilterPeakingPosition" , "20"); // 20 % = Flatup * 20% = 320 ns
WriteValue("/ch/0..63/par/TimeFilterRetriggerGuardS" , "10"); WriteValue("/ch/0..63/par/TimeFilterRetriggerGuardS" , "10"); // 80 ns
WriteValue("/ch/0..63/par/EnergyFilterPileupGuardT" , "10"); WriteValue("/ch/0..63/par/EnergyFilterPileupGuardS" , "10"); // 80 ns
WriteValue("/ch/0..63/par/EnergyFilterBaselineGuardS" , "100"); WriteValue("/ch/0..63/par/EnergyFilterBaselineGuardS" , "100"); // 800 ns
WriteValue("/ch/0..63/par/EnergyFilterLFLimitation" , "Off"); WriteValue("/ch/0..63/par/EnergyFilterLFLimitation" , "Off");
// Other Setting
WriteValue("/par/TrgOutMode", "SwTrg");
WriteValue("/par/IOlevel", "NIM");
ret = CAEN_FELib_SetValue(handle, "/par/EnStatEvents", "true");
if( ret != CAEN_FELib_Success){
ErrorMsg("Enable stats");
}
}
void Digitizer2Gen::ReadDigitizerSettings(){
ReadValue("/ch/4/par/ChRecordLengthS" , true);
ReadValue("/ch/4/par/ChPreTriggerS" , true);
ReadValue("/ch/4/par/WaveResolution" , true);
ReadValue("/ch/4/par/WaveAnalogProbe0" , true);
ReadValue("/ch/4/par/WaveAnalogProbe1" , true);
ReadValue("/ch/4/par/WaveDigitalProbe0", true);
ReadValue("/ch/4/par/WaveDigitalProbe1", true);
ReadValue("/ch/4/par/WaveDigitalProbe2", true);
ReadValue("/ch/4/par/WaveDigitalProbe3", true);
} }
std::string Digitizer2Gen::ErrorMsg(const char * funcName){ std::string Digitizer2Gen::ErrorMsg(const char * funcName){
printf("======== %s | %s\n",__func__, funcName); printf("======== %s | %s\n",__func__, funcName);
char msg[1024]; char msg[1024];
int ec = CAEN_FELib_GetLastError(msg); int ec = CAEN_FELib_GetErrorDescription((CAEN_FELib_ErrorCode) ret, msg);
if (ec != CAEN_FELib_Success) { if (ec != CAEN_FELib_Success) {
std::string errMsg = __func__; std::string errMsg = __func__;
errMsg += " failed"; errMsg += " failed";
printf("%s failed\n", __func__); printf("%s failed\n", __func__);
return errMsg; return errMsg;
} }
printf("last error: %s\n", msg); printf("Error msg (%d): %s\n", ret, msg);
return msg; return msg;
} }

View File

@ -10,12 +10,17 @@
//#include "Parameter.h" //#include "Parameter.h"
#define MaxOutFileSize 2*1024*1024*1024 #define MaxOutFileSize 2*1024*1024*1024
#define MaxNumberOfChannel 64
class Digitizer2Gen { class Digitizer2Gen {
private: private:
uint64_t handle; uint64_t handle;
uint64_t ep_handle; ///end point handle uint64_t ep_handle; ///end point handle
uint64_t ep_folder_handle; ///end point folder handle uint64_t ep_folder_handle; ///end point folder handle
uint64_t stat_handle;
//uint64_t stat_folder_handle;
bool isConnected; bool isConnected;
int ret; int ret;
@ -37,7 +42,11 @@ class Digitizer2Gen {
void Initialization(); void Initialization();
std::string ErrorMsg(const char * funcName); uint64_t realTime[MaxNumberOfChannel];
uint64_t deadTime[MaxNumberOfChannel];
uint64_t liveTime[MaxNumberOfChannel];
uint32_t triggerCount[MaxNumberOfChannel];
uint32_t savedEventCount[MaxNumberOfChannel];
unsigned short outFileIndex; unsigned short outFileIndex;
unsigned short dataStartIndetifier; unsigned short dataStartIndetifier;
@ -46,7 +55,6 @@ class Digitizer2Gen {
FILE * outFile; FILE * outFile;
unsigned int outFileSize; unsigned int outFileSize;
public: public:
Digitizer2Gen(); Digitizer2Gen();
~Digitizer2Gen(); ~Digitizer2Gen();
@ -54,7 +62,7 @@ class Digitizer2Gen {
int OpenDigitizer(const char * url); int OpenDigitizer(const char * url);
int CloseDigitizer(); int CloseDigitizer();
std::string ReadValue(const char * parameter); std::string ReadValue(const char * parameter, bool verbose);
void WriteValue(const char * parameter, std::string value); void WriteValue(const char * parameter, std::string value);
void SendCommand(const char * parameter); void SendCommand(const char * parameter);
@ -62,6 +70,8 @@ class Digitizer2Gen {
uint64_t GetParentHandle(uint64_t handle); uint64_t GetParentHandle(uint64_t handle);
std::string GetPath(uint64_t handle); std::string GetPath(uint64_t handle);
std::string ErrorMsg(const char * funcName);
void StartACQ(); void StartACQ();
void StopACQ(); void StopACQ();
@ -71,15 +81,17 @@ class Digitizer2Gen {
// 3 = only ch, energy, timestamp, minimum // 3 = only ch, energy, timestamp, minimum
// 15 = raw data // 15 = raw data
int ReadData(); int ReadData();
void ReadDataRaw(); //not impletmented int ReadStat();
void PrintStat();
void ProgramPHA(bool testPulse = false); void ProgramPHA(bool testPulse = false);
void ReadDigitizerSettings();
unsigned short GetNChannels() {return nChannels;} unsigned short GetNChannels() {return nChannels;}
unsigned short GetCh2ns() {return ch2ns;} unsigned short GetCh2ns() {return ch2ns;}
uint64_t GetHandle() {return handle;} uint64_t GetHandle() {return handle;}
Event *evt; Event *evt; // should be evt[MaxNumber], when full or stopACQ, save into file
void OpenOutFile(std::string fileName); void OpenOutFile(std::string fileName);
void CloseOutFile(); void CloseOutFile();
void SaveDataToFile(); void SaveDataToFile();

15
Event.h
View File

@ -114,6 +114,21 @@ class Event {
} }
} }
std::string HighPriority(uint16_t prio){
std::string output;
bool pileup = prio & 0x1;
bool pileupGuard = (prio >> 1) & 0x1;
bool eventSaturated = (prio >> 2) & 0x1;
bool postSatEvent = (prio >> 3) & 0x1;
bool trapSatEvent = (prio >> 4) & 0x1;
bool SCA_Event = (prio >> 5) & 0x1;
return output;
}
//TODO LowPriority
void PrintAll(){ void PrintAll(){
printf("============= Type : %u\n", dataType); printf("============= Type : %u\n", dataType);
printf("ch : %2d (0x%02X), fail: %d, flush: %d\n", channel, channel, board_fail, flush); printf("ch : %2d (0x%02X), fail: %d, flush: %d\n", channel, channel, board_fail, flush);

View File

@ -19,7 +19,7 @@ int main(int argc, char* argv[]){
Digitizer2Gen * digi = new Digitizer2Gen(); Digitizer2Gen * digi = new Digitizer2Gen();
digi->OpenDigitizer(url); digi->OpenDigitizer(url);
digi->ProgramPHA(true); digi->ProgramPHA(false);
//printf("%s \n", digi->ReadValue("/ch/0/par/ChRealtimeMonitor").c_str()); //printf("%s \n", digi->ReadValue("/ch/0/par/ChRealtimeMonitor").c_str());
//printf("%s \n", digi->ReadValue("/ch/0/par/Energy_Nbit").c_str()); //printf("%s \n", digi->ReadValue("/ch/0/par/Energy_Nbit").c_str());
@ -49,10 +49,12 @@ int main(int argc, char* argv[]){
printf("%s\n", digi->GetPath(parHandle).c_str()); printf("%s\n", digi->GetPath(parHandle).c_str());
*/ */
//digi->ReadDigitizerSettings();
digi->SetPHADataFormat(0); digi->SetPHADataFormat(0);
//printf("0x%X \n", atoi(digi->ReadValue("/par/AcquisitionStatus").c_str()) & 0x3F );
digi->OpenOutFile("haha"); digi->OpenOutFile("haha");
digi->StartACQ(); digi->StartACQ();
@ -60,9 +62,15 @@ int main(int argc, char* argv[]){
timespec t0, t1; timespec t0, t1;
clock_gettime(CLOCK_REALTIME, &t0); clock_gettime(CLOCK_REALTIME, &t0);
for( int i = 0; i < 64*20; i++){ for( int i = 0; i < 20; i++){
usleep(100000);
int ret = digi->ReadData(); int ret = digi->ReadData();
//if( i% 2 == 0 ) printf("0x%X \n", atoi(digi->ReadValue("/par/AcquisitionStatus").c_str()) & 0x3F );
if( ret == CAEN_FELib_Success){ if( ret == CAEN_FELib_Success){
//digi->evt.PrintAll(); //digi->evt.PrintAll();
//digi->evt.PrintTrace(); //digi->evt.PrintTrace();
@ -74,17 +82,26 @@ int main(int argc, char* argv[]){
digi->SaveDataToFile(); digi->SaveDataToFile();
if( digi->evt->channel == 63 ) { if( digi->evt->channel == 63 ) {
//if( i % 10 == 0 ) {
clock_gettime(CLOCK_REALTIME, &t1); clock_gettime(CLOCK_REALTIME, &t1);
printf("%5d | t1-t0 : %10ld\n", i, t1.tv_nsec-t0.tv_nsec); printf("%5d | t1-t0 : %10ld\n", i, t1.tv_nsec-t0.tv_nsec);
t0 = t1; t0 = t1;
//digi->ReadStat();
//digi->PrintStat();
} }
}else{ }else{
printf("something wrong when ReadData()"); printf("something wrong when ReadData() | ret = %d \n", ret);
digi->ErrorMsg("ReadData()");
} }
} }
digi->StopACQ(); digi->StopACQ();
//digi->ReadStat();
digi->PrintStat();
digi->CloseOutFile(); digi->CloseOutFile();