tested the normal event builder. OK

This commit is contained in:
splitPoleDAQ 2023-11-21 18:03:10 -05:00
parent 4fdac4d29f
commit 967935d5e0
4 changed files with 48 additions and 269 deletions

View File

@ -29,9 +29,9 @@ MultiBuilder.o : ../MultiBuilder.cpp ../MultiBuilder.h
ClassDigitizer.o : ../ClassDigitizer.cpp ../ClassDigitizer.h ../RegisterAddress.h ../macro.h ../ClassData.h ClassDigitizer.o : ../ClassDigitizer.cpp ../ClassDigitizer.h ../RegisterAddress.h ../macro.h ../ClassData.h
$(CC) $(COPTS) -c ../ClassDigitizer.cpp $(CC) $(COPTS) -c ../ClassDigitizer.cpp
test : test.cpp ../ClassDigitizer.o test : test.cpp ../ClassDigitizer.o ../MultiBuilder.o
@echo "--------- making test" @echo "--------- making test"
$(CC) $(COPTS) -o test test.cpp ../ClassDigitizer.o $(CAENLIBS) $(ROOTLIBS) $(CC) $(COPTS) -o test test.cpp ../ClassDigitizer.o ../MultiBuilder.o $(CAENLIBS) $(ROOTLIBS)
test_indep : test_indep.cpp ../RegisterAddress.h ../macro.h test_indep : test_indep.cpp ../RegisterAddress.h ../macro.h
@echo "--------- making test_indep" @echo "--------- making test_indep"

View File

@ -1,6 +1,7 @@
#include "../macro.h" #include "../macro.h"
#include "../ClassData.h" #include "../ClassData.h"
#include "../ClassDigitizer.h" #include "../ClassDigitizer.h"
#include "../MultiBuilder.h"
#include <TROOT.h> #include <TROOT.h>
#include <TSystem.h> #include <TSystem.h>
@ -26,307 +27,72 @@ int getch(void);
//^====================================== //^======================================
int main(int argc, char* argv[]){ int main(int argc, char* argv[]){
/********************** DPP-QDC */ Digitizer * digi = new Digitizer(0, 0, false, true);
Digitizer * digi = new Digitizer(0, 2, false, true);
digi->Reset(); digi->Reset();
digi->ProgramBoard_QDC(); digi->ProgramBoard_PHA();
digi->WriteRegister(DPP::SoftwareClear_W, 1); digi->WriteRegister(DPP::SoftwareClear_W, 1);
digi->WriteRegister(DPP::QDC::RecordLength, 31, -1); // T = N * 8 * 16 // digi->WriteRegister(DPP::QDC::RecordLength, 31, -1); // T = N * 8 * 16
digi->WriteRegister(DPP::QDC::PreTrigger, 60, -1); // digi->WriteRegister(DPP::QDC::PreTrigger, 60, -1);
digi->WriteRegister(DPP::QDC::TriggerThreshold_sub2, 17, -1); // digi->WriteRegister(DPP::QDC::TriggerThreshold_sub2, 17, -1);
digi->SetBits(DPP::QDC::DPPAlgorithmControl, DPP::QDC::Bit_DPPAlgorithmControl::ChargeSensitivity, 0, -1); // digi->SetBits(DPP::QDC::DPPAlgorithmControl, DPP::QDC::Bit_DPPAlgorithmControl::ChargeSensitivity, 0, -1);
digi->SetBits(DPP::QDC::DPPAlgorithmControl, DPP::QDC::Bit_DPPAlgorithmControl::InputSmoothingFactor, 4, -1); // digi->SetBits(DPP::QDC::DPPAlgorithmControl, DPP::QDC::Bit_DPPAlgorithmControl::InputSmoothingFactor, 4, -1);
digi->SetBits(DPP::QDC::DPPAlgorithmControl, DPP::QDC::Bit_DPPAlgorithmControl::BaselineAvg, 2, -1); // digi->SetBits(DPP::QDC::DPPAlgorithmControl, DPP::QDC::Bit_DPPAlgorithmControl::BaselineAvg, 2, -1);
digi->WriteRegister(DPP::QDC::GateWidth, 608/16, -1); // digi->WriteRegister(DPP::QDC::GateWidth, 608/16, -1);
digi->WriteRegister(DPP::QDC::GroupEnableMask, 0x01); // digi->WriteRegister(DPP::QDC::GroupEnableMask, 0x01);
digi->WriteRegister(DPP::QDC::NumberEventsPerAggregate, 10, -1); // digi->WriteRegister(DPP::QDC::NumberEventsPerAggregate, 10, -1);
digi->WriteRegister(DPP::AggregateOrganization, 0, -1); // digi->WriteRegister(DPP::AggregateOrganization, 0, -1);
digi->WriteRegister(DPP::MaxAggregatePerBlockTransfer, 100, -1); // digi->WriteRegister(DPP::MaxAggregatePerBlockTransfer, 100, -1);
digi->SetBits(DPP::QDC::DPPAlgorithmControl, DPP::QDC::Bit_DPPAlgorithmControl::Polarity, 0, -1); // digi->SetBits(DPP::QDC::DPPAlgorithmControl, DPP::QDC::Bit_DPPAlgorithmControl::Polarity, 0, -1);
digi->SetBits(DPP::BoardConfiguration, DPP::Bit_BoardConfig::EnableExtra2, 1, -1); digi->SetBits(DPP::BoardConfiguration, DPP::Bit_BoardConfig::EnableExtra2, 1, -1);
digi->SetBits(DPP::BoardConfiguration, DPP::Bit_BoardConfig::RecordTrace, 1, -1); digi->SetBits(DPP::BoardConfiguration, DPP::Bit_BoardConfig::RecordTrace, 0, -1);
Data * data = digi->GetData(); Data * data = digi->GetData();
remove("haha_17121_QDC_000.fsu"); MultiBuilder * builder = new MultiBuilder(data, DPPType::DPP_PHA_CODE, digi->GetSerialNumber());
data->OpenSaveFile("haha"); builder->SetTimeWindow(100);
//remove("haha_*.fsu");
//data->OpenSaveFile("haha");
digi->StartACQ(); digi->StartACQ();
for( int i = 0; i < 10; i ++ ){ for( int i = 0; i < 5; i ++ ){
usleep(1000*1000); usleep(1000*1000);
digi->ReadData(); digi->ReadData();
data->DecodeBuffer(true, 0); data->DecodeBuffer(true, 0);
//data->DecodeBuffer(false, 2); //data->DecodeBuffer(false, 2);
data->SaveData(); //data->SaveData();
data->PrintStat(); //data->PrintStat();
data->PrintAllData(true);
builder->BuildEvents(false, true, true);
builder->PrintStat();
// int index = data->NumEventsDecoded[0]; // int index = data->NumEventsDecoded[0];
// printf("-------------- %ld \n", data->Waveform1[0][index].size()); // printf("-------------- %ld \n", data->Waveform1[0][index].size());
} }
digi->StopACQ(); digi->StopACQ();
//data->CloseSaveFile();
data->CloseSaveFile(); builder->BuildEvents(true, true, true);
data->PrintAllData(); data->PrintAllData();
builder->PrintAllEvent(); // TODO
digi->CloseDigitizer(); digi->CloseDigitizer();
delete digi; delete digi;
/*
const int nBoard = 1;
Digitizer **dig = new Digitizer *[nBoard];
for( int i = 0 ; i < nBoard; i++){
int board = i % 3;
int port = i/3;
dig[i] = new Digitizer(board, port, false, true);
}
// dig[i]->StopACQ();
// dig[0]->WriteRegister(DPP::SoftwareClear_W, 1);
// dig[0]->ProgramBoard();
// dig[0]->ProgramBoard_PSD();
// const float tick2ns = dig[0]->GetTick2ns();
//dig[2]->ReadRegister(DPP::QDC::RecordLength, 0, 0, "");
Data * data = dig[0]->GetData();
data->ClearData();
// data->OpenSaveFile("haha");
// printf("################# DPP Type : %d , %s\n", data->DPPType, data->DPPTypeStr.c_str());
dig[0]->StartACQ();
for( int i = 0; i < 9; i ++ ){
usleep(1000*1000);
dig[0]->ReadData();
data->DecodeBuffer(false, 0);
//data->PrintStat();
//data->SaveData();
// int index = data->NumEventsDecoded[0];
// printf("-------------- %ld \n", data->Waveform1[0][index].size());
//data->PrintAllData();
}
dig[0]->StopACQ();
*/
/*
TApplication * app = new TApplication("app", &argc, argv);
TCanvas * canvas = new TCanvas("c", "haha", 1200, 400);
canvas->Divide(3, 1);
TH1F * h1 = new TH1F("h1", "count", dig[0]->GetNChannel(), 0, dig[0]->GetNChannel());
TH1F * h2 = new TH1F("h2", "energy ch-0", 400, 0, 40000);
TGraph * g1 = new TGraph();
canvas->cd(1); h1->Draw("hist");
canvas->cd(2); h2->Draw();
canvas->cd(3); g1->Draw("AP");
Data * data = dig[0]->GetData();
data->Allocate80MBMemory();
remove("test.bin");
dig[0]->StartACQ();
std::vector<unsigned short> haha ;
uint32_t PreviousTime = get_time();
uint32_t CurrentTime = 0;
uint32_t ElapsedTime = 0;
int waveFormLength = dig[0]->ReadRegister(Register::DPP::RecordLength_G);
while(true){
if(keyboardhit()) {
break;
}
usleep(1000);
dig[0]->ReadData();
if( data->nByte > 0 ){
data->SaveBuffer("test");
data->DecodeBuffer(0);
unsigned short nData = data->DataIndex[0]; //channel-0
haha = data->Waveform1[0][nData-1];
for( int i = 0; i < waveFormLength; i++) g1->SetPoint(i, i*tick2ns, haha[i]);
canvas->cd(3); g1->Draw("AP");
canvas->Modified();
canvas->Update();
gSystem->ProcessEvents();
}
CurrentTime = get_time();
ElapsedTime = CurrentTime - PreviousTime; /// milliseconds
if( ElapsedTime > 1000 ){
int temp = system("clear");
data->PrintStat();
for(int i = 0; i < dig[0]->GetNChannel(); i++){
h1->Fill(i, data->DataIndex[i]);
}
for( int i = 0; i < data->DataIndex[0]; i++){
h2->Fill( data->Energy[0][i]);
}
data->ClearData();
canvas->cd(1); h1->Draw("hist");
canvas->cd(2); h2->Draw();
canvas->Modified();
canvas->Update();
gSystem->ProcessEvents();
PreviousTime = CurrentTime;
printf("Press any key to Stop\n");
}
}
app->Run();
*/
/*
printf("Closing digitizers..............\n");
for( int i = 0; i < nBoard; i++){
if(dig[i]->IsConnected()) dig[i]->StopACQ();
delete dig[i];
}
delete [] dig;
*/
////##################### Demo for loading and change setting without open a digitizer
/**
Digitizer * dig = new Digitizer();
dig->OpenDigitizer(0, 1, false, true);
dig->LoadSettingBinaryToMemory("expDir/settings/setting_323.bin");
//dig->ProgramBoard_PHA();
//dig->OpenSettingBinary("setting_323.bin");
//dig->ReadAllSettingsFromBoard();
//dig->PrintSettingFromMemory();
//dig->StopACQ();
//dig->WriteRegister(Register::DPP::SoftwareClear_W, 1);
printf("========== %d \n", dig->ReadSettingFromFile(Register::DPP::MaxAggregatePerBlockTransfer));
///dig->SaveSettingAsText("haha.txt");
///std::remove("Test_323_139_000.fsu");
//printf("========== %d \n", dig->ReadRegister(Register::DPP::MaxAggregatePerBlockTransfer));
delete dig;
{///============ Checking the buffer size calculation
unsigned short B = 10; /// BLT
unsigned short Eg = 511; /// Event / dual channel
bool DT = 1; /// dual trace
bool E2 = 1; /// extra 2;
bool Wr = 1; /// wave record;
unsigned short AP2 = 0; /// 00 = input, 01 = Threshold, 10 = Trapezoid - Baseline, 11 = baseline
unsigned short AP1 = 1; /// 00 = input, 01 = RC-CR, 10 = RC-CR2, 11 = Trapezoid
unsigned short DP1 = 0x0000; /// peaking,
unsigned short RL = 100; /// record Length
unsigned short AO = 0x0;
for( int i = 0; i < dig->GetNChannel(); i++){
dig->WriteRegister(Register::DPP::NumberEventsPerAggregate_G, Eg, i);
dig->WriteRegister(Register::DPP::RecordLength_G, RL, i);
}
dig->WriteRegister(Register::DPP::MaxAggregatePerBlockTransfer, B);
dig->WriteRegister(Register::DPP::AggregateOrganization, AO);
uint32_t bit = 0x0C0115;
bit += (DT << 11);
bit += (AP1 << 12);
bit += (AP2 << 14);
bit += (Wr << 16);
bit += (E2 << 17);
bit += (DP1 << 20);
printf("---- Bd Config : 0x%08X \n", bit);
dig->WriteRegister(Register::DPP::BoardConfiguration, bit);
unsigned int bSize = dig->CalByteForBuffer();
int bbbb = (((2 + E2 + Wr*RL*4) * Eg + 2)*8 + 2)*B *4 *2 + 4 * 4;
printf("=========== exp Buffer size : %8u byte \n", bbbb);
usleep(1e6);
///using CAEN method
char * buffer = NULL;
uint32_t size;
CAEN_DGTZ_MallocReadoutBuffer(dig->GetHandle(), (char **)& buffer, &size);
printf("CAEN calculated Buffer Size : %8u byte = %.2f MB \n", size, size/1024./1024.);
printf(" diff : %8u byte \n", size > 2*bSize ? size - 2*bSize : 2*bSize - size);
delete buffer;
}
*/
//dig->GetData()->SetSaveWaveToMemory(true);
//dig->StartACQ();
//
//for( int i = 0; i < 60; i++){
// usleep(500*1000);
// dig->ReadData();
// printf("------------------- %d\n", i);
// unsigned long time1 = get_time();
// dig->GetData()->DecodeBuffer(false,0);
// unsigned long time2 = get_time();
// printf("********************* decode time : %lu usec\n", time2-time1);
// dig->GetData()->PrintStat();
// //dig->GetData()->SaveBuffer("Test");
//}
//
//dig->StopACQ();
return 0; return 0;
} }

View File

@ -58,6 +58,18 @@ void MultiBuilder::PrintStat(){
} }
void MultiBuilder::PrintAllEvent(){
printf("Total number of evet built : %ld\n", totalEventBuilt);
for( int i = 0; i < totalEventBuilt; i++){
printf("%5d ------- size: %ld\n", i, events[i].size());
for( int j = 0; j < (int)events[i].size(); j++){
events[i][j].Print();
}
}
}
void MultiBuilder::FindEarlistTimeAndCh(bool verbose){ void MultiBuilder::FindEarlistTimeAndCh(bool verbose){
earlistTime = -1; earlistTime = -1;

View File

@ -56,6 +56,7 @@ public:
void ClearEvents(); void ClearEvents();
void PrintStat(); void PrintStat();
void PrintAllEvent();
long eventIndex; long eventIndex;
long eventBuilt; // reset once call BuildEvents() long eventBuilt; // reset once call BuildEvents()