add DataReaderScript.cpp, updtae ClassData.h

This commit is contained in:
splitPoleDAQ 2023-05-16 11:26:22 -04:00
parent 715c2277b0
commit ee85dd4fce
4 changed files with 183 additions and 118 deletions

View File

@ -14,7 +14,7 @@
#include "CAENDigitizerType.h" #include "CAENDigitizerType.h"
#include "macro.h" #include "macro.h"
#define MaxNData 10000 /// 10k events per channels #define MaxNData 10000 /// store 100k events per channels
class Data{ class Data{
@ -30,7 +30,6 @@ class Data{
double TriggerRate[MaxNChannels]; /// Hz double TriggerRate[MaxNChannels]; /// Hz
double NonPileUpRate[MaxNChannels]; /// Hz double NonPileUpRate[MaxNChannels]; /// Hz
short calIndexes[MaxNChannels][2]; /// the index for trigger rate calculation
unsigned long TotNumEvents[MaxNChannels]; unsigned long TotNumEvents[MaxNChannels];
unsigned short NumEventsDecoded[MaxNChannels]; /// reset at every decode unsigned short NumEventsDecoded[MaxNChannels]; /// reset at every decode
unsigned short NumNonPileUpDecoded[MaxNChannels]; /// reset at every decode unsigned short NumNonPileUpDecoded[MaxNChannels]; /// reset at every decode
@ -57,7 +56,9 @@ class Data{
void Allocate80MBMemory(); void Allocate80MBMemory();
void AllocateMemory(uint32_t size); void AllocateMemory(uint32_t size);
void SetSaveWaveToMemory(bool OnOff) { this->SaveWaveToMemory = OnOff; } void SetSaveWaveToMemory(bool OnOff) { // store the waveform in memory
this->SaveWaveToMemory = OnOff;
}
void ClearData(); void ClearData();
void ClearTriggerRate(); void ClearTriggerRate();
@ -65,9 +66,8 @@ class Data{
void CopyBuffer( const char * buffer, const unsigned int size); void CopyBuffer( const char * buffer, const unsigned int size);
void PrintBuffer() const; //Incorrect
void DecodeBuffer(bool fastDecode, int verbose = 0); /// fastDecode will not save waveform 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 DecodeBuffer(char * &buffer, unsigned int size, bool fastDecode, int verbose = 0); // for outside data
void PrintStat() const; void PrintStat() const;
@ -99,6 +99,7 @@ class Data{
std::string outFileName; std::string outFileName;
unsigned int outFileSize; // should be max at 2 GB unsigned int outFileSize; // should be max at 2 GB
short calIndexes[MaxNChannels][2]; /// the index for trigger rate calculation
unsigned int ReadBuffer(unsigned int nWord, int verbose = 0); unsigned int ReadBuffer(unsigned int nWord, int verbose = 0);
@ -159,21 +160,24 @@ inline void Data::ClearData(){
nByte = 0; nByte = 0;
AllocatedSize = 0; AllocatedSize = 0;
IsNotRollOverFakeAgg = false; IsNotRollOverFakeAgg = false;
for( int i = 0 ; i < MaxNChannels; i++){ for( int ch = 0 ; ch < MaxNChannels; ch++){
NumEvents[i] = 0; NumEvents[ch] = 0;
for( int j = 0; j < MaxNData; j++){ for( int j = 0; j < MaxNData; j++){
Timestamp[i][j] = 0; Timestamp[ch][j] = 0;
fineTime[i][j] = 0; fineTime[ch][j] = 0;
Energy[i][j] = 0; Energy[ch][j] = 0;
Energy2[i][j] = 0; Energy2[ch][j] = 0;
Waveform1[i][j].clear(); Waveform1[ch][j].clear();
Waveform2[i][j].clear(); Waveform2[ch][j].clear();
DigiWaveform1[i][j].clear(); DigiWaveform1[ch][j].clear();
DigiWaveform2[i][j].clear(); DigiWaveform2[ch][j].clear();
} }
calIndexes[i][0] = -1; NumEventsDecoded[ch] = 0;
calIndexes[i][1] = -1; NumNonPileUpDecoded[ch] = 0;
calIndexes[ch][0] = -1;
calIndexes[ch][1] = -1;
} }
tempWaveform1.clear(); tempWaveform1.clear();
@ -193,6 +197,8 @@ inline void Data::CopyBuffer(const char * buffer, const unsigned int size){
std::memcpy(this->buffer, buffer, size); std::memcpy(this->buffer, buffer, size);
} }
//^###############################################
//^############################################### Save fsu file
inline void Data::OpenSaveFile(std::string fileNamePrefix){ inline void Data::OpenSaveFile(std::string fileNamePrefix){
outFilePrefix = fileNamePrefix; outFilePrefix = fileNamePrefix;
@ -222,7 +228,6 @@ inline void Data::SaveData(){
outFileSize = ftell(outFile); outFileSize = ftell(outFile);
} }
inline void Data::CloseSaveFile(){ inline void Data::CloseSaveFile(){
if( outFile != NULL ){ if( outFile != NULL ){
fclose(outFile); fclose(outFile);
@ -231,6 +236,8 @@ inline void Data::CloseSaveFile(){
} }
} }
//^#######################################################
//^####################################################### Print
inline void Data::PrintStat() const{ inline void Data::PrintStat() const{
if( !IsNotRollOverFakeAgg ) { if( !IsNotRollOverFakeAgg ) {
@ -245,13 +252,6 @@ inline void Data::PrintStat() const{
printf("---+--------+-----------+-----------+----------\n"); printf("---+--------+-----------+-----------+----------\n");
} }
inline void Data::PrintBuffer() const{
unsigned int length = sizeof(buffer);
for( unsigned int i = 0; i < length; i++){
printf("%3d | 0x%08x \n", i, buffer[i]);
}
}
inline void Data::PrintAllData() const{ inline void Data::PrintAllData() const{
printf("============================= Print Data\n"); printf("============================= Print Data\n");
for( int ch = 0; ch < MaxNChannels ; ch++){ for( int ch = 0; ch < MaxNChannels ; ch++){
@ -263,7 +263,8 @@ inline void Data::PrintAllData() const{
} }
} }
//####################################################### Decode //^#######################################################
//^####################################################### Decode
inline unsigned int Data::ReadBuffer(unsigned int nWord, int verbose){ inline unsigned int Data::ReadBuffer(unsigned int nWord, int verbose){
if( buffer == NULL ) return 0; if( buffer == NULL ) return 0;
@ -273,7 +274,7 @@ inline unsigned int Data::ReadBuffer(unsigned int nWord, int verbose){
return word; return word;
} }
inline void Data::DecodeBuffer(char * buffer, unsigned int size, bool fastDecode, int verbose){ inline void Data::DecodeBuffer(char * &buffer, unsigned int size, bool fastDecode, int verbose){
this->buffer = buffer; this->buffer = buffer;
this->nByte = size; this->nByte = size;
DecodeBuffer(fastDecode, verbose); DecodeBuffer(fastDecode, verbose);
@ -289,8 +290,6 @@ inline void Data::DecodeBuffer(bool fastDecode, int verbose){
if( nByte == 0 ) return; if( nByte == 0 ) return;
nw = 0; nw = 0;
//TODO === wen very fast rate, can ClearTriggerRate, but is it nesscary?
//ClearTriggerRate();
do{ do{
if( verbose >= 1 ) printf("Data::DecodeBuffer ######################################### Board Agg.\n"); if( verbose >= 1 ) printf("Data::DecodeBuffer ######################################### Board Agg.\n");
@ -322,6 +321,11 @@ inline void Data::DecodeBuffer(bool fastDecode, int verbose){
unsigned int bdAggTimeTag = ReadBuffer(nw, verbose); unsigned int bdAggTimeTag = ReadBuffer(nw, verbose);
if( verbose >= 2 ) printf("Agg Counter : %u \n", bdAggTimeTag); if( verbose >= 2 ) printf("Agg Counter : %u \n", bdAggTimeTag);
for( int ch = 0; ch < MaxNChannels; ch ++) {
NumEventsDecoded[ch] = 0;
NumNonPileUpDecoded[ch] = 0;
}
for( int chMask = 0; chMask < MaxNChannels/2 ; chMask ++ ){ for( int chMask = 0; chMask < MaxNChannels/2 ; chMask ++ ){
if( ((ChannelMask >> chMask) & 0x1 ) == 0 ) continue; if( ((ChannelMask >> chMask) & 0x1 ) == 0 ) continue;
if( verbose >= 2 ) printf("==================== Dual Channel Block, ch Mask : %d, nw : %d\n", chMask *2, nw); if( verbose >= 2 ) printf("==================== Dual Channel Block, ch Mask : %d, nw : %d\n", chMask *2, nw);
@ -356,14 +360,17 @@ inline void Data::DecodeBuffer(bool fastDecode, int verbose){
} }
//TODO ====== when NumEventsDecoded is too small, the trigger rate is not reliable? //TODO ====== when NumEventsDecoded is too small, the trigger rate is not reliable?
if( NumEventsDecoded[ch] > 4 ){
//TODO ===== for very high rate, use a simpler code. printf("%d %d| %d %d \n", NumEvents[ch], NumEventsDecoded[ch], NumEvents[ch] - NumEventsDecoded[ch], NumEvents[ch]-1);
// unsigned long long dTime = Timestamp[ch][NumEvents[ch]-1] - Timestamp[ch][NumEvents[ch] - NumEventsDecoded[ch]];
// double sec = dTime * ch2ns / 1e9; unsigned long long dTime = Timestamp[ch][NumEvents[ch]-1] - Timestamp[ch][NumEvents[ch] - NumEventsDecoded[ch]];
// if( sec != 0 && NumEventsDecoded[ch] > 1 ){ double sec = dTime * ch2ns / 1e9;
// TriggerRate[ch] = NumEventsDecoded[ch]/sec;
// NonPileUpRate[ch] = NumNonPileUpDecoded[ch]/sec; TriggerRate[ch] = NumEventsDecoded[ch]/sec;
// } NonPileUpRate[ch] = NumNonPileUpDecoded[ch]/sec;
}else{ // look in to the data in the memory, not just this agg.
if( calIndexes[ch][0] == -1 ) calIndexes[ch][0] = 0; if( calIndexes[ch][0] == -1 ) calIndexes[ch][0] = 0;
if( calIndexes[ch][0] > -1 && calIndexes[ch][1] == -1 ) calIndexes[ch][1] = NumEvents[ch]-1; if( calIndexes[ch][0] > -1 && calIndexes[ch][1] == -1 ) calIndexes[ch][1] = NumEvents[ch]-1;
@ -377,7 +384,6 @@ inline void Data::DecodeBuffer(bool fastDecode, int verbose){
//printf(" %10llu %10llu, %f = %f sec, rate = %f \n", Timestamp[ch][calIndexes[ch][0]], Timestamp[ch][calIndexes[ch][1]], ch2ns, sec, nEvent / sec); //printf(" %10llu %10llu, %f = %f sec, rate = %f \n", Timestamp[ch][calIndexes[ch][0]], Timestamp[ch][calIndexes[ch][1]], ch2ns, sec, nEvent / sec);
if( sec > 0.1 ){ /// at least 100 msec
TriggerRate[ch] = nEvent / sec; TriggerRate[ch] = nEvent / sec;
short pileUpCount = 0; short pileUpCount = 0;
@ -390,15 +396,16 @@ inline void Data::DecodeBuffer(bool fastDecode, int verbose){
calIndexes[ch][0] = calIndexes[ch][1]; calIndexes[ch][0] = calIndexes[ch][1];
calIndexes[ch][1] = -1; calIndexes[ch][1] = -1;
}
}else{ }else{
calIndexes[ch][1] = -1; calIndexes[ch][1] = -1;
} }
}
} }
} }
//*=================================================
inline int Data::DecodePHADualChannelBlock(unsigned int ChannelMask, bool fastDecode, int verbose){ inline int Data::DecodePHADualChannelBlock(unsigned int ChannelMask, bool fastDecode, int verbose){
nw = nw + 1; nw = nw + 1;
@ -591,7 +598,7 @@ inline int Data::DecodePHADualChannelBlock(unsigned int ChannelMask, bool fastDe
printf("PileUp or RollOver : %d\n", pileUpOrRollOver); printf("PileUp or RollOver : %d\n", pileUpOrRollOver);
printf("PileUp : %d , extra : 0x%03x, energy : %d \n", pileUp, extra, energy); printf("PileUp : %d , extra : 0x%03x, energy : %d \n", pileUp, extra, energy);
printf(" lost event : %d \n", ((extra >> 0) & 0x1) ); printf(" lost event : %d \n", ((extra >> 0) & 0x1) );
printf(" roll-over : %d (is fake event)\n", ((extra >> 1) & 0x1) ); printf(" roll-over : %d (is fake event ?)\n", ((extra >> 1) & 0x1) );
printf(" fake-event : %d \n", ((extra >> 3) & 0x1) ); printf(" fake-event : %d \n", ((extra >> 3) & 0x1) );
printf(" input sat. : %d \n", ((extra >> 4) & 0x1) ); printf(" input sat. : %d \n", ((extra >> 4) & 0x1) );
printf(" lost trg : %d \n", ((extra >> 5) & 0x1) ); printf(" lost trg : %d \n", ((extra >> 5) & 0x1) );
@ -617,9 +624,9 @@ inline int Data::DecodePHADualChannelBlock(unsigned int ChannelMask, bool fastDe
} }
} }
if( NumEvents[channel] >= MaxNData ) ClearData(); if( NumEvents[channel] >= MaxNData ) ClearData(); // if any channel has more data then MaxNData, clear all stored data
if( verbose >= 1 ) printf("%4d | ch : %2d, PileUp : %d , energy : %5d, rollOver: %d, timestamp : %10llu, triggerAt : %d, nSample : %d, %f sec\n", if( verbose >= 1 ) printf("evt %4d | ch : %2d, PileUp : %d , energy : %5d, rollOver: %d, timestamp : %10llu, triggerAt : %d, nSample : %d, %f sec\n",
NumEvents[channel], channel, pileUp, energy, rollOver, timeStamp, triggerAtSample, nSample , timeStamp * 4. / 1e9); NumEvents[channel], channel, pileUp, energy, rollOver, timeStamp, triggerAtSample, nSample , timeStamp * 4. / 1e9);
} }
@ -631,6 +638,7 @@ inline int Data::DecodePHADualChannelBlock(unsigned int ChannelMask, bool fastDe
return nw; return nw;
} }
//*=================================================
inline int Data::DecodePSDDualChannelBlock(unsigned int ChannelMask, bool fastDecode, int verbose){ inline int Data::DecodePSDDualChannelBlock(unsigned int ChannelMask, bool fastDecode, int verbose){
nw = nw + 1; nw = nw + 1;

58
DataReaderScript.cpp Normal file
View File

@ -0,0 +1,58 @@
#include "ClassData.h"
void DataReaderScript(){
Data * data = new Data();
data->DPPType = V1730_DPP_PHA_CODE;
data->ch2ns = 4.0;
std::string fileName = "data/temp_324_PHA_000.fsu";
FILE * haha = fopen(fileName.c_str(), "r");
fseek(haha, 0L, SEEK_END);
const long inFileSize = ftell(haha);
printf("%s | file size : %ld Byte = %.2f MB\n", fileName.c_str() , inFileSize, inFileSize/1024./1024.);
fseek(haha, 0, SEEK_SET);
char * buffer = nullptr;
int countBdAgg = 0;
do{
long fPos1 = ftell(haha);
unsigned int word[1]; /// 4 bytes
size_t dump = fread(word, 4, 1, haha);
fseek(haha, -4, SEEK_CUR);
short header = ((word[0] >> 28 ) & 0xF);
if( header != 0xA ) break;
unsigned int aggSize = (word[0] & 0x0FFFFFFF) * 4; ///byte
buffer = new char[aggSize];
dump = fread(buffer, aggSize, 1, haha);
long fPos2 = ftell(haha);
printf("Board Agg. has %d word = %d bytes | %ld - %ld\n", aggSize/4, aggSize, fPos1, fPos2);
countBdAgg ++;
printf("==================== %d Agg\n", countBdAgg);
data->DecodeBuffer(buffer, aggSize, false, 0); // data own the buffer
data->ClearBuffer(); // this will clear the buffer.
if( !data->IsNotRollOverFakeAgg ) continue;
//if( countBdAgg % 100 == 0)
data->PrintStat();
//data->ClearData();
}while(!feof(haha) && ftell(haha) < inFileSize);
//data->PrintAllData();
fclose(haha);
delete data;
}

View File

@ -38,26 +38,25 @@ int main(int argc, char* argv[]){
const float ch2ns = dig[0]->GetCh2ns(); const float ch2ns = dig[0]->GetCh2ns();
Data * data = dig[0]->GetData();
// Data * data = dig[0]->GetData(); dig[0]->StartACQ();
// dig[0]->StartACQ(); for( int i = 0; i < 50; i ++ ){
usleep(100*1000);
dig[0]->ReadData();
data->DecodeBuffer(false, 3);
data->PrintStat();
// for( int i = 0; i < 50; i ++ ){ int index = data->NumEventsDecoded[0];
// usleep(100*1000); printf("-------------- %ld \n", data->Waveform1[0][index].size());
// dig[0]->ReadData();
// data->DecodeBuffer(false);
// data->PrintStat();
// int index = data->NumEventsDecoded[0]; }
// printf("-------------- %ld \n", data->Waveform1[0][index].size());
// } dig[0]->StopACQ();
// dig[0]->StopACQ();
//data->PrintAllData(); data->PrintAllData();

View File

@ -20,7 +20,7 @@ void PrintChannelSettingFromDigitizer(int handle, int ch, float ch2ns){
printf("================================================\e[0m\n"); printf("================================================\e[0m\n");
///DPP algorithm Control ///DPP algorithm Control
uint32_t * value = new uint32_t[16]; uint32_t * value = new uint32_t[16];
CAEN_DGTZ_ReadRegister(handle, Register::DPP::DPPAlgorithmControl + (ch << 8), value); CAEN_DGTZ_ReadRegister(handle, DPP::DPPAlgorithmControl + (ch << 8), value);
printf(" 32 28 24 20 16 12 8 4 0\n"); printf(" 32 28 24 20 16 12 8 4 0\n");
printf(" | | | | | | | | |\n"); printf(" | | | | | | | | |\n");
cout <<" DPP algorithm Control : 0b" << bitset<32>(value[0]); cout <<" DPP algorithm Control : 0b" << bitset<32>(value[0]);
@ -34,7 +34,7 @@ void PrintChannelSettingFromDigitizer(int handle, int ch, float ch2ns){
int pileUp = int(value[0] >> 27) & 0x1; int pileUp = int(value[0] >> 27) & 0x1;
///DPP algorithm Control 2 ///DPP algorithm Control 2
CAEN_DGTZ_ReadRegister(handle, Register::DPP::PHA::DPPAlgorithmControl2_G + (ch << 8), value); CAEN_DGTZ_ReadRegister(handle, DPP::PHA::DPPAlgorithmControl2_G + (ch << 8), value);
cout <<" DPP algorithm Control 2: 0b" << bitset<32>(value[0]) ; cout <<" DPP algorithm Control 2: 0b" << bitset<32>(value[0]) ;
printf(" = 0x%x\n", value[0]); printf(" = 0x%x\n", value[0]);
@ -51,47 +51,47 @@ void PrintChannelSettingFromDigitizer(int handle, int ch, float ch2ns){
printf(" ch2ns : %.0f ns\n", ch2ns); printf(" ch2ns : %.0f ns\n", ch2ns);
printf("==========----- input \n"); printf("==========----- input \n");
CAEN_DGTZ_ReadRegister(handle, Register::DPP::RecordLength_G + (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, DPP::RecordLength_G + (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 CAEN_DGTZ_ReadRegister(handle, 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 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 %% \n", "DC offset", 100.0 - value[0] * 100./ 0xFFFF); ///DC offset CAEN_DGTZ_ReadRegister(handle, DPP::ChannelDCOffset + (ch << 8), value); printf("%24s %.2f %% \n", "DC offset", 100.0 - value[0] * 100./ 0xFFFF); ///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 CAEN_DGTZ_ReadRegister(handle, 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 printf("%24s %s, DPP-[16]\n", "polarity", polarity == 0 ? "Positive" : "negative"); ///Polarity
printf("==========----- discriminator \n"); 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, 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, 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, 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, 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 CAEN_DGTZ_ReadRegister(handle, 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("==========----- Trapezoid \n");
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, 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
int riseTime = value[0] * 4 * ch2ns; int riseTime = value[0] * 4 * ch2ns;
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 CAEN_DGTZ_ReadRegister(handle, 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; int flatTopTime = value[0] * 4 * ch2ns;
double shift = log(riseTime * flatTopTime ) / log(2) - 2; double shift = log(riseTime * flatTopTime ) / log(2) - 2;
printf("%24s %4d bit =? %.1f = Ceil( Log(rise [ns] x decay [ns])/Log(2) ), DPP-[0:5]\n", "Trap. Rescaling", trapRescaling, shift ); ///Trap. Rescaling Factor printf("%24s %4d bit =? %.1f = Ceil( Log(rise [ns] x decay [ns])/Log(2) ), DPP-[0:5]\n", "Trap. Rescaling", trapRescaling, shift ); ///Trap. Rescaling Factor
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, 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, 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 CAEN_DGTZ_ReadRegister(handle, 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("%24s %4.0f samples, DPP-[12:13]\n", "Peak mean", pow(4, NsPeak)); ///Ns peak
printf("==========----- Other \n"); printf("==========----- Other \n");
CAEN_DGTZ_ReadRegister(handle, Register::DPP::PHA::FineGain + (ch << 8), value); printf("%24s %d = 0x%x\n", "Energy fine gain", value[0], value[0]); ///Energy fine gain CAEN_DGTZ_ReadRegister(handle, DPP::PHA::FineGain + (ch << 8), value); printf("%24s %d = 0x%x\n", "Energy fine gain", value[0], value[0]); ///Energy fine gain
CAEN_DGTZ_ReadRegister(handle, Register::DPP::ChannelADCTemperature_R + (ch << 8), value); printf("%24s %d C\n", "Temperature", value[0]); ///Temperature CAEN_DGTZ_ReadRegister(handle, DPP::ChannelADCTemperature_R + (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, DPP::PHA::RiseTimeValidationWindow + (ch << 8), value); printf("%24s %.0f ns \n", "RiseTime Vaild Win.", value[0] * ch2ns);
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, 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_R + (ch << 8), value); printf("%24s 0x%x \n", "Status bit", (value[0] & 0xff) ); CAEN_DGTZ_ReadRegister(handle, DPP::ChannelStatus_R + (ch << 8), value); printf("%24s 0x%x \n", "Status bit", (value[0] & 0xff) );
CAEN_DGTZ_ReadRegister(handle, Register::DPP::AMCFirmwareRevision_R + (ch << 8), value); printf("%24s 0x%x \n", "AMC firmware rev.", value[0] ); CAEN_DGTZ_ReadRegister(handle, DPP::AMCFirmwareRevision_R + (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] ); CAEN_DGTZ_ReadRegister(handle, 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", "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", "Pile-upFlag, DPP-[27]", pileUp, pileUp ? "enable" : "disable" );
printf("%24s %d, %s \n", "Extra2 opt, DPP2-[8:10]", extras2WordOption, extra2WordOptStr.c_str()); printf("%24s %d, %s \n", "Extra2 opt, DPP2-[8:10]", extras2WordOption, extra2WordOptStr.c_str());
printf("========= events storage and transfer\n"); printf("========= events storage and transfer\n");
CAEN_DGTZ_ReadRegister(handle, Register::DPP::NumberEventsPerAggregate_G + (ch << 8), value); printf("%24s %d \n", "Event Aggregate", value[0] & 0x3FF); CAEN_DGTZ_ReadRegister(handle, DPP::NumberEventsPerAggregate_G + (ch << 8), value); printf("%24s %d \n", "Event Aggregate", value[0] & 0x3FF);
CAEN_DGTZ_ReadRegister(handle, Register::DPP::AggregateOrganization, value); printf("%24s %d \n", "Buffer Division", ((value[0] & 0x007) < 2 ? 0 : (int)pow(2, value[0] & 7))); CAEN_DGTZ_ReadRegister(handle, DPP::AggregateOrganization, value); printf("%24s %d \n", "Buffer Division", ((value[0] & 0x007) < 2 ? 0 : (int)pow(2, value[0] & 7)));
CAEN_DGTZ_ReadRegister(handle, Register::DPP::MaxAggregatePerBlockTransfer , value); printf("%24s %d \n", "Num of Agg. / ReadData", value[0] & 0x1FF); CAEN_DGTZ_ReadRegister(handle, DPP::MaxAggregatePerBlockTransfer , value); printf("%24s %d \n", "Num of Agg. / ReadData", value[0] & 0x1FF);
printf("========================================= end of ch-%d\n", ch); printf("========================================= end of ch-%d\n", ch);
@ -103,7 +103,7 @@ void PrintBoardConfiguration(int handle){
printf("================ Setting for Board \n"); printf("================ Setting for Board \n");
printf("================================================\e[0m\n"); printf("================================================\e[0m\n");
uint32_t * value = new uint32_t[1]; uint32_t * value = new uint32_t[1];
CAEN_DGTZ_ReadRegister(handle, (uint32_t) Register::BoardConfiguration, value); CAEN_DGTZ_ReadRegister(handle, (uint32_t) BoardConfiguration, value);
printf(" 32 28 24 20 16 12 8 4 0\n"); printf(" 32 28 24 20 16 12 8 4 0\n");
printf(" | | | | | | | | |\n"); printf(" | | | | | | | | |\n");
cout <<" Board Configuration : 0b" << bitset<32>(value[0]) << endl; cout <<" Board Configuration : 0b" << bitset<32>(value[0]) << endl;
@ -199,12 +199,12 @@ int main(int argc, char* argv[]){
///ret |= CAEN_DGTZ_SetDPPAcquisitionMode(handle, CAEN_DGTZ_DPP_ACQ_MODE_Mixed, CAEN_DGTZ_DPP_SAVE_PARAM_EnergyAndTime); /// Board Configure can do that ///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 /// Set the number of samples for each waveform
ret = CAEN_DGTZ_WriteRegister(handle, Register::DPP::RecordLength_G + 0x7000, 625); ret = CAEN_DGTZ_WriteRegister(handle, DPP::RecordLength_G + 0x7000, 625);
if( ret != 0 ) { printf("==== set Record Length.\n"); return 0;} 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, DPP::BoardConfiguration, 0x4F8115); // with wave
ret |= CAEN_DGTZ_WriteRegister(handle, Register::DPP::BoardConfiguration, 0x4E8115); // with-out wave ret |= CAEN_DGTZ_WriteRegister(handle, DPP::BoardConfiguration, 0x4E8115); // with-out wave
/// Set the digitizer acquisition mode (CAEN_DGTZ_SW_CONTROLLED or CAEN_DGTZ_S_IN_CONTROLLED) /// Set the digitizer acquisition mode (CAEN_DGTZ_SW_CONTROLLED or CAEN_DGTZ_S_IN_CONTROLLED)
@ -261,29 +261,29 @@ int main(int argc, char* argv[]){
///} ///}
///ret = CAEN_DGTZ_SetDPPParameters(handle, channelMask, &DPPParams); ///ret = CAEN_DGTZ_SetDPPParameters(handle, channelMask, &DPPParams);
ret |= CAEN_DGTZ_WriteRegister(handle, Register::DPP::PHA::DecayTime + 0x7000 , 5000 ); ret |= CAEN_DGTZ_WriteRegister(handle, DPP::PHA::DecayTime + 0x7000 , 5000 );
ret |= CAEN_DGTZ_WriteRegister(handle, Register::DPP::PHA::TrapezoidFlatTop + 0x7000 , 62 ); ret |= CAEN_DGTZ_WriteRegister(handle, DPP::PHA::TrapezoidFlatTop + 0x7000 , 62 );
ret |= CAEN_DGTZ_WriteRegister(handle, Register::DPP::PHA::TrapezoidRiseTime + 0x7000 , 6 ); ret |= CAEN_DGTZ_WriteRegister(handle, DPP::PHA::TrapezoidRiseTime + 0x7000 , 6 );
ret |= CAEN_DGTZ_WriteRegister(handle, Register::DPP::PHA::PeakingTime + 0x7000 , 6 ); ret |= CAEN_DGTZ_WriteRegister(handle, DPP::PHA::PeakingTime + 0x7000 , 6 );
ret |= CAEN_DGTZ_WriteRegister(handle, Register::DPP::PHA::RCCR2SmoothingFactor + 0x7000 , 4 ); ret |= CAEN_DGTZ_WriteRegister(handle, DPP::PHA::RCCR2SmoothingFactor + 0x7000 , 4 );
ret |= CAEN_DGTZ_WriteRegister(handle, Register::DPP::PHA::InputRiseTime + 0x7000 , 6 ); ret |= CAEN_DGTZ_WriteRegister(handle, DPP::PHA::InputRiseTime + 0x7000 , 6 );
ret |= CAEN_DGTZ_WriteRegister(handle, Register::DPP::PHA::TriggerThreshold + 0x7000 , 64 ); ret |= CAEN_DGTZ_WriteRegister(handle, DPP::PHA::TriggerThreshold + 0x7000 , 64 );
ret |= CAEN_DGTZ_WriteRegister(handle, Register::DPP::PHA::PeakHoldOff + 0x7000 , 0x3E ); ret |= CAEN_DGTZ_WriteRegister(handle, DPP::PHA::PeakHoldOff + 0x7000 , 0x3E );
ret |= CAEN_DGTZ_WriteRegister(handle, Register::DPP::PHA::TriggerHoldOffWidth + 0x7000 , 0x3E ); ret |= CAEN_DGTZ_WriteRegister(handle, DPP::PHA::TriggerHoldOffWidth + 0x7000 , 0x3E );
ret |= CAEN_DGTZ_WriteRegister(handle, Register::DPP::PHA::RiseTimeValidationWindow + 0x7000 , 0x0 ); ret |= CAEN_DGTZ_WriteRegister(handle, DPP::PHA::RiseTimeValidationWindow + 0x7000 , 0x0 );
ret |= CAEN_DGTZ_WriteRegister(handle, Register::DPP::ChannelDCOffset + 0x7000 , 0xEEEE ); ret |= CAEN_DGTZ_WriteRegister(handle, DPP::ChannelDCOffset + 0x7000 , 0xEEEE );
ret |= CAEN_DGTZ_WriteRegister(handle, Register::DPP::PreTrigger + 0x7000 , 124 ); ret |= CAEN_DGTZ_WriteRegister(handle, DPP::PreTrigger + 0x7000 , 124 );
ret |= CAEN_DGTZ_WriteRegister(handle, Register::DPP::InputDynamicRange + 0x7000 , 0x0 ); ret |= CAEN_DGTZ_WriteRegister(handle, DPP::InputDynamicRange + 0x7000 , 0x0 );
//ret |= CAEN_DGTZ_WriteRegister(handle, Register::DPP::BoardConfiguration , 0x10E0114 ); //ret |= CAEN_DGTZ_WriteRegister(handle, DPP::BoardConfiguration , 0x10E0114 );
ret |= CAEN_DGTZ_WriteRegister(handle, Register::DPP::NumberEventsPerAggregate_G + 0x7000, 5); ret |= CAEN_DGTZ_WriteRegister(handle, DPP::NumberEventsPerAggregate_G + 0x7000, 5);
ret |= CAEN_DGTZ_WriteRegister(handle, Register::DPP::AggregateOrganization, 0); ret |= CAEN_DGTZ_WriteRegister(handle, DPP::AggregateOrganization, 0);
ret |= CAEN_DGTZ_WriteRegister(handle, Register::DPP::MaxAggregatePerBlockTransfer, 40); ret |= CAEN_DGTZ_WriteRegister(handle, DPP::MaxAggregatePerBlockTransfer, 40);
ret |= CAEN_DGTZ_WriteRegister(handle, Register::DPP::DPPAlgorithmControl + 0x7000, 0xe30200f); ret |= CAEN_DGTZ_WriteRegister(handle, DPP::DPPAlgorithmControl + 0x7000, 0xe30200f);
if( ret != 0 ) { printf("==== set channels error.\n"); return 0;} if( ret != 0 ) { printf("==== set channels error.\n"); return 0;}