reproduced BoxScore at test.cpp
This commit is contained in:
parent
7fee55a094
commit
826c54ed52
12
ClassData.h
12
ClassData.h
|
@ -83,7 +83,7 @@ inline Data::Data(){
|
|||
buffer = NULL;
|
||||
for ( int i = 0; i < MaxNChannels; i++) TotNumEvents[i] = 0;
|
||||
ClearData();
|
||||
SaveWaveformToMemory = false;
|
||||
SaveWaveformToMemory = true;
|
||||
nw = 0;
|
||||
}
|
||||
|
||||
|
@ -395,18 +395,18 @@ inline int Data::DecodePHADualChannelBlock(unsigned int ChannelMask, int verbose
|
|||
printf(" trapezoid sat. : %d \n", ((extra >> 10) & 0x1) );
|
||||
|
||||
}
|
||||
|
||||
|
||||
if( rollOver == 0 ) {
|
||||
Energy[channel][NumEvents[channel]] = energy;
|
||||
Timestamp[channel][NumEvents[channel]] = timeStamp;
|
||||
|
||||
NumEvents[channel] ++;
|
||||
TotNumEvents[channel] ++;
|
||||
}
|
||||
|
||||
if( verbose >= 1 ) printf("%4d | ch : %2d, PileUp : %d , energy : %d, roll-Over: %d, timestamp : %llu, triggerAt : %d, nSample : %d, %f\n",
|
||||
if( verbose >= 1 ) printf("%4d | ch : %2d, PileUp : %d , energy : %5d, roll-Over: %d, timestamp : %10llu, triggerAt : %d, nSample : %d, %f sec\n",
|
||||
NumEvents[channel], channel, pileUp, energy, rollOver, timeStamp, triggerAtSample, nSample , timeStamp * 4. / 1e9);
|
||||
|
||||
Energy[channel][NumEvents[channel]] = energy;
|
||||
Timestamp[channel][NumEvents[channel]] = timeStamp;
|
||||
|
||||
}
|
||||
|
||||
///=========== Key information
|
||||
|
|
|
@ -48,7 +48,11 @@ void Digitizer::Initalization(){
|
|||
|
||||
void Digitizer::Reset(){
|
||||
ret = CAEN_DGTZ_Reset(handle);
|
||||
if( ret != 0 ) ErrorMsg("Reset");
|
||||
if( ret != 0 ) ErrorMsg(__func__);
|
||||
|
||||
ret |= CAEN_DGTZ_WriteRegister(handle, Register::DPP::SoftwareClear, 1);
|
||||
if( ret != 0 ) ErrorMsg("Reset-SoftwareClear");
|
||||
|
||||
}
|
||||
|
||||
void Digitizer::PrintBoard(){
|
||||
|
@ -330,7 +334,7 @@ void Digitizer::ReadData(){
|
|||
|
||||
ret = CAEN_DGTZ_ReadData(handle, CAEN_DGTZ_SLAVE_TERMINATED_READOUT_MBLT, data->buffer, &(data->nByte));
|
||||
uint32_t EventSize = ReadRegister(Register::DPP::EventSize); // Is it as same as data->nByte?
|
||||
printf("Read Buffer size %d byte, Event Size : %d byte \n", data->nByte, EventSize);
|
||||
//printf("Read Buffer size %d byte, Event Size : %d byte \n", data->nByte, EventSize);
|
||||
|
||||
if (ret || data->nByte == 0) {
|
||||
ErrorMsg(__func__);
|
||||
|
|
|
@ -365,7 +365,7 @@ void MainWindow::LogMsg(char * msg){
|
|||
}
|
||||
|
||||
void MainWindow::PlotTrace(){
|
||||
|
||||
printf("=== %s\n", __func__);
|
||||
|
||||
}
|
||||
|
||||
|
|
2
Makefile
2
Makefile
|
@ -31,7 +31,7 @@ DigitizerPSD.o : DigitizerPSD.cpp DigitizerPSD.h ClassDigitizer.o
|
|||
|
||||
test : test.cpp ClassDigitizer.o DigitizerPHA.o DigitizerPSD.o
|
||||
@echo "--------- making test"
|
||||
$(CC) $(COPTS) -o test test.cpp ClassDigitizer.o DigitizerPHA.o DigitizerPSD.o $(CAENLIBS)
|
||||
$(CC) $(COPTS) -o test test.cpp ClassDigitizer.o DigitizerPHA.o DigitizerPSD.o $(CAENLIBS) $(ROOTLIBS)
|
||||
|
||||
test_indep : test_indep.cpp RegisterAddress.h macro.h
|
||||
@echo "--------- making test_indep"
|
||||
|
|
|
@ -246,7 +246,7 @@ ChannelSettingPHA::ChannelSettingPHA(const TGWindow *p, UInt_t w, UInt_t h, Digi
|
|||
|
||||
}
|
||||
|
||||
TGHorizontalFrame *hframe2 = new TGHorizontalFrame(vframe, w, 50 ); vframe->AddFrame(hframe2, new TGLayoutHints(kLHintsCenterX, 2,2,2,2));
|
||||
TGHorizontalFrame *hframe2 = new TGHorizontalFrame(vframe, w, 50 ); vframe->AddFrame(hframe2, new TGLayoutHints(kLHintsExpandX, 2,2,2,2));
|
||||
|
||||
{///================== const uint32_t DPPAlgorithmControl = 0x1080; /// R/W
|
||||
TGGroupFrame * gfDPPCtrl = new TGGroupFrame(hframe2, "DPP Algorithm Control 1 & 2", kHorizontalFrame); hframe2->AddFrame(gfDPPCtrl, new TGLayoutHints(kLHintsExpandX));
|
||||
|
@ -383,7 +383,7 @@ ChannelSettingPHA::ChannelSettingPHA(const TGWindow *p, UInt_t w, UInt_t h, Digi
|
|||
}
|
||||
|
||||
{///================== Commands Buttons
|
||||
TGGroupFrame * gfCmd = new TGGroupFrame(hframe2, "Commands", kHorizontalFrame); hframe2->AddFrame(gfCmd, new TGLayoutHints(kLHintsExpandX));
|
||||
TGGroupFrame * gfCmd = new TGGroupFrame(hframe2, "Commands", kHorizontalFrame); hframe2->AddFrame(gfCmd);
|
||||
TGVerticalFrame * vfCmd = new TGVerticalFrame(gfCmd); gfCmd->AddFrame(vfCmd, new TGLayoutHints(kLHintsExpandX));
|
||||
|
||||
TGTextButton * bReadSetting = new TGTextButton(vfCmd, "Read Settings"); vfCmd->AddFrame(bReadSetting, new TGLayoutHints(kLHintsExpandX, 5,5,3,4));
|
||||
|
@ -705,17 +705,7 @@ void ChannelSettingPHA::SetTriggerSmoothing(){
|
|||
}
|
||||
|
||||
void ChannelSettingPHA::ReadTrace(){
|
||||
|
||||
///Set Record Trace
|
||||
|
||||
///Set ChannelMask
|
||||
|
||||
///StartACQ
|
||||
|
||||
///Loop: check is there any data
|
||||
|
||||
///if data, Read data, DecodeData
|
||||
|
||||
printf("=== %s\n", __func__);
|
||||
///Send plot trace to MainWindows
|
||||
Emit("SendPlotTraceCmd()");
|
||||
|
||||
|
|
196
test.cpp
196
test.cpp
|
@ -1,14 +1,86 @@
|
|||
#include "DigitizerPHA.h"
|
||||
#include "DigitizerPSD.h"
|
||||
|
||||
#include "ClassData.h"
|
||||
#include "ClassDigitizer.h"
|
||||
|
||||
#include "TROOT.h"
|
||||
#include "TSystem.h"
|
||||
#include "TApplication.h"
|
||||
#include "TCanvas.h"
|
||||
#include "TGraph.h"
|
||||
#include "TH1.h"
|
||||
|
||||
#include <sys/time.h> /* struct timeval, select() */
|
||||
#include <termios.h> /* tcgetattr(), tcsetattr() */
|
||||
|
||||
static struct termios g_old_kbd_mode;
|
||||
|
||||
static void cooked(void){
|
||||
tcsetattr(0, TCSANOW, &g_old_kbd_mode);
|
||||
}
|
||||
|
||||
static void uncooked(void){
|
||||
struct termios new_kbd_mode;
|
||||
/* put keyboard (stdin, actually) in raw, unbuffered mode */
|
||||
tcgetattr(0, &g_old_kbd_mode);
|
||||
memcpy(&new_kbd_mode, &g_old_kbd_mode, sizeof(struct termios));
|
||||
new_kbd_mode.c_lflag &= ~(ICANON | ECHO);
|
||||
new_kbd_mode.c_cc[VTIME] = 0;
|
||||
new_kbd_mode.c_cc[VMIN] = 1;
|
||||
tcsetattr(0, TCSANOW, &new_kbd_mode);
|
||||
}
|
||||
|
||||
static void raw(void){
|
||||
|
||||
static char init;
|
||||
if(init) return;
|
||||
/* put keyboard (stdin, actually) in raw, unbuffered mode */
|
||||
uncooked();
|
||||
/* when we exit, go back to normal, "cooked" mode */
|
||||
atexit(cooked);
|
||||
|
||||
init = 1;
|
||||
}
|
||||
|
||||
int keyboardhit(){
|
||||
|
||||
struct timeval timeout;
|
||||
fd_set read_handles;
|
||||
int status;
|
||||
|
||||
raw();
|
||||
/* check stdin (fd 0) for activity */
|
||||
FD_ZERO(&read_handles);
|
||||
FD_SET(0, &read_handles);
|
||||
timeout.tv_sec = timeout.tv_usec = 0;
|
||||
status = select(0 + 1, &read_handles, NULL, NULL, &timeout);
|
||||
if(status < 0){
|
||||
printf("select() failed in keyboardhit()\n");
|
||||
exit(1);
|
||||
}
|
||||
return (status);
|
||||
}
|
||||
|
||||
int getch(void){
|
||||
unsigned char temp;
|
||||
|
||||
raw();
|
||||
/* stdin = fd 0 */
|
||||
if(read(0, &temp, 1) != 1) return 0;
|
||||
//printf("%s", &temp);
|
||||
return temp;
|
||||
}
|
||||
|
||||
|
||||
long get_time(){
|
||||
long time_ms;
|
||||
struct timeval t1;
|
||||
struct timezone tz;
|
||||
gettimeofday(&t1, &tz);
|
||||
time_ms = (t1.tv_sec) * 1000 + t1.tv_usec / 1000;
|
||||
return time_ms;
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[]){
|
||||
|
||||
|
||||
|
||||
/**************/
|
||||
|
||||
const int nBoard = 1;
|
||||
Digitizer **dig = new Digitizer *[nBoard];
|
||||
|
||||
|
@ -20,35 +92,99 @@ int main(int argc, char* argv[]){
|
|||
dig[i]->OpenSettingBinary("setting_" + to_string(dig[i]->GetSerialNumber()) + ".bin");
|
||||
}
|
||||
|
||||
dig[0]->Reset();
|
||||
dig[0]->ProgramPHABoard();
|
||||
|
||||
//DigitizerPHA * pha = dynamic_cast<DigitizerPHA*> (dig[0]);
|
||||
//pha->ProgramBoard();
|
||||
//pha->PrintBoardConfiguration();
|
||||
//pha->PrintChannelSettingFromDigitizer(0);
|
||||
//pha->PrintChannelSettingFromDigitizer(15);
|
||||
dig[0]->WriteRegister(Register::DPP::BoardConfiguration, 0x84F8115); /// enable wave form, pileup
|
||||
|
||||
unsigned int waveFormLength = 2000;
|
||||
unsigned int ch2ns = (unsigned int) dig[0]->GetCh2ns();
|
||||
|
||||
dig[0]->WriteRegister(Register::DPP::RecordLength_G, waveFormLength/ch2ns);
|
||||
dig[0]->WriteRegister(Register::DPP::DPPAlgorithmControl, 0xe30200e);
|
||||
|
||||
remove("test.bin");
|
||||
|
||||
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->AllocateMemory();
|
||||
data->DPPType = dig[0]->GetDPPType();
|
||||
|
||||
dig[0]->StartACQ();
|
||||
|
||||
std::vector<unsigned short> haha ;
|
||||
|
||||
for( int p = 0; p < 10; p++){
|
||||
sleep(1);
|
||||
uint32_t PreviousTime = get_time();
|
||||
uint32_t CurrentTime = 0;
|
||||
uint32_t ElapsedTime = 0;
|
||||
|
||||
while(true){
|
||||
|
||||
if(keyboardhit()) {
|
||||
break;
|
||||
}
|
||||
|
||||
usleep(50000);
|
||||
dig[0]->ReadData();
|
||||
data->SaveBuffer("test.bin");
|
||||
data->DecodeBuffer(2);
|
||||
data->PrintStat();
|
||||
data->ClearData();
|
||||
|
||||
if( data->nByte > 0 ){
|
||||
data->SaveBuffer("test.bin");
|
||||
data->DecodeBuffer(0);
|
||||
|
||||
for(int i = 0; i < dig[0]->GetNChannel(); i++){
|
||||
//printf("%2d | %d \n", i, data->NumEvents[i]);
|
||||
h1->Fill(i, data->NumEvents[i]);
|
||||
}
|
||||
|
||||
for( int i = 0; i < data->NumEvents[0]; i++){
|
||||
//printf("%2d | %d, %llu\n", i, data->Energy[0][i], data->Timestamp[0][i]);
|
||||
h2->Fill( data->Energy[0][i]);
|
||||
}
|
||||
|
||||
haha = data->Waveform1[0][0];
|
||||
for( int i = 0; i < waveFormLength; i++) g1->SetPoint(i, i*ch2ns, haha[i]);
|
||||
|
||||
data->ClearData();
|
||||
|
||||
|
||||
canvas->cd(1); h1->Draw("hist");
|
||||
canvas->cd(2); h2->Draw();
|
||||
canvas->cd(3); g1->Draw("AP");
|
||||
|
||||
canvas->Modified();
|
||||
canvas->Update();
|
||||
gSystem->ProcessEvents();
|
||||
|
||||
}
|
||||
|
||||
CurrentTime = get_time();
|
||||
ElapsedTime = CurrentTime - PreviousTime; /// milliseconds
|
||||
|
||||
if( ElapsedTime > 1000 ){
|
||||
system("clear");
|
||||
data->PrintStat();
|
||||
PreviousTime = CurrentTime;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
dig[0]->StopACQ();
|
||||
|
||||
app->Run();
|
||||
|
||||
//delete pha;
|
||||
delete [] dig;
|
||||
|
||||
/*********************/
|
||||
|
@ -86,25 +222,9 @@ int main(int argc, char* argv[]){
|
|||
|
||||
}while(!feof(haha) );
|
||||
|
||||
|
||||
|
||||
|
||||
fclose(haha);
|
||||
/*********************/
|
||||
|
||||
|
||||
///****************************** casting digitizer type
|
||||
///Digitizer ** dig = new Digitizer *[2] ;
|
||||
/////dig[0] = new Digitizer();
|
||||
///dig[0] = new DigitizerPHA();
|
||||
///dig[1] = new DigitizerPSD();
|
||||
///
|
||||
///printf("%d \n", dig[0]->GetDPPType());
|
||||
///printf("%d \n", dig[1]->GetDPPType());
|
||||
///
|
||||
///((DigitizerPHA *)dig[0])->PrintBoardConfiguration();
|
||||
///
|
||||
///((DigitizerPHA *)dig[0])->SetDPPAlgorithmControl2(0x10000);
|
||||
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user