allow ploting of energy, count, and trace when start run. next, enable save data

This commit is contained in:
carina@hades 2022-10-03 14:17:15 -04:00
parent e0b922000b
commit d119ebefd4
10 changed files with 185 additions and 43 deletions

View File

@ -100,7 +100,8 @@ inline Data::~Data(){
inline void Data::AllocateMemory(){ inline void Data::AllocateMemory(){
//delete buffer; delete buffer;
//TODO calculate Suitable buffer size
BufferSize = 1000000; /// 1M byte BufferSize = 1000000; /// 1M byte
buffer = (char *) malloc( BufferSize); buffer = (char *) malloc( BufferSize);
printf("Allocated %d byte for buffer \n", BufferSize); printf("Allocated %d byte for buffer \n", BufferSize);

View File

@ -44,16 +44,31 @@ enum ModeIdentifiers{
}; };
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;
}
///make static members ///make static members
Digitizer ** MainWindow::digi = NULL; Digitizer ** MainWindow::digi = NULL;
TGTextEdit * MainWindow::teLog = NULL; TGTextEdit * MainWindow::teLog = NULL;
TRootEmbeddedCanvas * MainWindow::fEcanvas = NULL; TRootEmbeddedCanvas * MainWindow::fEcanvas = NULL;
TGNumberEntry * MainWindow::boardIDEntry = NULL; TGNumberEntry * MainWindow::boardIDEntry = NULL;
TGNumberEntry * MainWindow::chIDEntry = NULL; TGNumberEntry * MainWindow::chIDEntry = NULL;
TGComboBox* MainWindow::cbMode = NULL;
TH1F * MainWindow::hEnergy[MaxNBoards][MaxNChannels] = {NULL}; TH1F * MainWindow::hEnergy[MaxNBoards][MaxNChannels] = {NULL};
TH1F * MainWindow::hChannel[MaxNBoards] = {NULL}; TH1F * MainWindow::hChannel[MaxNBoards] = {NULL};
TGraph * MainWindow::gAnaTrace1 = NULL ;
TGraph * MainWindow::gAnaTrace2 = NULL ;
TGraph * MainWindow::gDigiTrace1 = NULL ;
TGraph * MainWindow::gDigiTrace2 = NULL ;
MainWindow::MainWindow(const TGWindow *p,UInt_t w,UInt_t h) { MainWindow::MainWindow(const TGWindow *p,UInt_t w,UInt_t h) {
nDigi = 0; nDigi = 0;
@ -142,7 +157,7 @@ MainWindow::MainWindow(const TGWindow *p,UInt_t w,UInt_t h) {
} }
{///================= single Channel group {///================= single Channel group
TGGroupFrame * group1 = new TGGroupFrame(hframe, "Single Channel", kHorizontalFrame); hframe->AddFrame(group1 ); TGGroupFrame * group1 = new TGGroupFrame(hframe, "Single Channel", kHorizontalFrame); hframe->AddFrame(group1, new TGLayoutHints(kLHintsExpandY));
TGHorizontalFrame *hfg1 = new TGHorizontalFrame(group1,200,30); group1->AddFrame(hfg1 ,new TGLayoutHints(kLHintsLeft, 0, 0, 0, 0)); TGHorizontalFrame *hfg1 = new TGHorizontalFrame(group1,200,30); group1->AddFrame(hfg1 ,new TGLayoutHints(kLHintsLeft, 0, 0, 0, 0));
TGLayoutHints * haha = new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 2, 2, 10, 0); ///left, right, top, bottom TGLayoutHints * haha = new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 2, 2, 10, 0); ///left, right, top, bottom
@ -206,10 +221,10 @@ MainWindow::MainWindow(const TGWindow *p,UInt_t w,UInt_t h) {
//HandleMenu(M_CH_SETTING_PHA); //HandleMenu(M_CH_SETTING_PHA);
//HandleMenu(M_CH_SETTING_PSD); //HandleMenu(M_CH_SETTING_PSD);
gAnaTrace1 = NULL; gAnaTrace1 = new TGraph();
gAnaTrace2 = NULL; gAnaTrace2 = new TGraph();
gDigiTrace1 = NULL; gDigiTrace1 = new TGraph();
gDigiTrace2 = NULL; gDigiTrace2 = new TGraph();
gStyle->SetOptStat("neiou"); gStyle->SetOptStat("neiou");
@ -293,13 +308,13 @@ void MainWindow::HandleMenu(Int_t id){
case M_CH_SETTING_PHA: case M_CH_SETTING_PHA:
channelSettingPHA = new ChannelSettingPHA(gClient->GetRoot(), 600, 600, digi, nDigi, 0); channelSettingPHA = new ChannelSettingPHA(gClient->GetRoot(), 600, 600, digi, nDigi, 0);
channelSettingPHA->Connect("LogMsg(char*)", "MainWindow", this, "LogMsg(char*)"); channelSettingPHA->Connect("LogMsg(char*)", "MainWindow", this, "LogMsg(char*)");
channelSettingPHA->Connect("SendPlotTraceCmd()", "MainWindow", this, "PlotSingleTrace()");
break; break;
case M_CH_SETTING_PSD: case M_CH_SETTING_PSD:
channelSettingPSD = new ChannelSettingPSD(gClient->GetRoot(), 600, 600, digi, nDigi, 0); channelSettingPSD = new ChannelSettingPSD(gClient->GetRoot(), 600, 600, digi, nDigi, 0);
channelSettingPSD->Connect("LogMsg(char*)", "MainWindow", this, "LogMsg(char*)"); channelSettingPSD->Connect("LogMsg(char*)", "MainWindow", this, "LogMsg(char*)");
//channelSettingPSD->Connect("SendPlotTraceCmd()", "MainWindow", this, "PlotSingleTrace()");
break; break;
///========================= Board setting ///========================= Board setting
@ -382,7 +397,7 @@ void MainWindow::OpenDigitizers(){
bStartRun->SetEnabled(true); bStartRun->SetEnabled(true);
boardIDEntry->SetState(true); if( nDigi <= 1) boardIDEntry->SetState(true);
chIDEntry->SetState(true); chIDEntry->SetState(true);
boardIDEntry->SetLimits(TGNumberFormat::kNELLimitMinMax, 0, nDigi-1); boardIDEntry->SetLimits(TGNumberFormat::kNELLimitMinMax, 0, nDigi-1);
@ -390,9 +405,10 @@ void MainWindow::OpenDigitizers(){
chIDEntry->SetLimits(TGNumberFormat::kNELLimitMinMax, 0, digi[0]->GetNChannel() -1 ); chIDEntry->SetLimits(TGNumberFormat::kNELLimitMinMax, 0, digi[0]->GetNChannel() -1 );
bPlotSingleTrace->SetEnabled(true); bPlotSingleTrace->SetEnabled(true);
bFitTrace->SetEnabled(true);
for( int i = 0; i < nDigi; i++){ for( int i = 0; i < nDigi; i++){
hChannel[i] = new TH1F(Form("hBd%02d", i),Form("hBd%02d; ch; count", i), digi[i]->GetNChannel(), 0, digi[i]->GetNChannel()-1); hChannel[i] = new TH1F(Form("hBd%02d", i),Form("hBd%02d; ch; count", i), digi[i]->GetNChannel(), 0, digi[i]->GetNChannel());
for( int j = 0; j < MaxNChannels; j++) hEnergy[i][j] = new TH1F(Form("hE%02dch%02d", i, j),Form("hE bd-%02d ch-%02d; Energy[ch]; count", i, j), 400, 0, 20000); for( int j = 0; j < MaxNChannels; j++) hEnergy[i][j] = new TH1F(Form("hE%02dch%02d", i, j),Form("hE bd-%02d ch-%02d; Energy[ch]; count", i, j), 400, 0, 20000);
} }
@ -425,12 +441,22 @@ void MainWindow::StartRun(){
bStartRun->SetEnabled(false); bStartRun->SetEnabled(false);
bStopRun->SetEnabled(true); bStopRun->SetEnabled(true);
dataPrefix->SetEnabled(false);
runIDEntry->SetState(false);
bPlotSingleTrace->SetEnabled(false);
bFitTrace->SetEnabled(false);
digi[0]->StartACQ(); digi[0]->StartACQ();
if( digi[0]->IsRunning() ) fillHistThread->Run(); if( digi[0]->IsRunning() ) {
int mode = cbMode->GetSelected();
if( mode == Mode_DataRun){
}else{
fillHistThread->Run();
}
}
} }
void MainWindow::StopRun(){ void MainWindow::StopRun(){
@ -441,6 +467,10 @@ void MainWindow::StopRun(){
bStartRun->SetEnabled(true); bStartRun->SetEnabled(true);
bStopRun->SetEnabled(false); bStopRun->SetEnabled(false);
dataPrefix->SetEnabled(true);
runIDEntry->SetState(true);
bPlotSingleTrace->SetEnabled(true);
bFitTrace->SetEnabled(true);
if( cbMode->GetSelected() == Mode_DataRun ){ if( cbMode->GetSelected() == Mode_DataRun ){
int runID = runIDEntry->GetNumber(); int runID = runIDEntry->GetNumber();
@ -461,6 +491,7 @@ void MainWindow::OpenChannelSetting(Int_t boardID){
if( digi[boardID]->GetDPPType() == V1730_DPP_PSD_CODE ){ if( digi[boardID]->GetDPPType() == V1730_DPP_PSD_CODE ){
channelSettingPSD = new ChannelSettingPSD(gClient->GetRoot(), 600, 600, digi, nDigi, boardID); channelSettingPSD = new ChannelSettingPSD(gClient->GetRoot(), 600, 600, digi, nDigi, boardID);
channelSettingPSD->Connect("LogMsg(char*)", "MainWindow", this, "LogMsg(char*)"); channelSettingPSD->Connect("LogMsg(char*)", "MainWindow", this, "LogMsg(char*)");
//channelSettingPSD->Connect("SendPlotTraceCmd()", "MainWindow", this, "PlotSingleTrace()");
} }
} }
@ -509,8 +540,7 @@ void MainWindow::PlotSingleTrace(){
data->DecodeBuffer(0); data->DecodeBuffer(0);
data->PrintStat(); data->PrintStat();
delete gAnaTrace1; gAnaTrace1 = new TGraph(); gDigiTrace1->SetLineColor(4);
delete gDigiTrace1; gDigiTrace1 = new TGraph(); gDigiTrace1->SetLineColor(4);
int traceLength = (data->Waveform1[chID][0]).size(); int traceLength = (data->Waveform1[chID][0]).size();
@ -520,9 +550,21 @@ void MainWindow::PlotSingleTrace(){
LogMsg((char *)"no trace"); LogMsg((char *)"no trace");
bFitTrace->SetEnabled(false); bFitTrace->SetEnabled(false);
}else{ }else{
for( int i = 0; i < traceLength ; i++) { for( int i = 0; i < traceLength ; i++) {
gAnaTrace1->SetPoint(i, i*ch2ns, (data->Waveform1[chID][0])[i]); gAnaTrace1->SetPoint(i, i*ch2ns, (data->Waveform1[chID][0])[i]);
gDigiTrace1->SetPoint(i, i*ch2ns, 2000*(data->DigiWaveform1[chID][0])[i] + 2000); }
if( traceLength <= gAnaTrace1->GetN() ){
for( int i = gAnaTrace1->GetN() -1 ; i >= traceLength ; i--){
gAnaTrace1->RemovePoint(i);
gDigiTrace1->RemovePoint(i);
}
}
double xmin, xmax, ymin, ymax;
gAnaTrace1->ComputeRange(xmin, ymin, xmax, ymax);
for( int i = 0; i < traceLength ; i++) {
gDigiTrace1->SetPoint(i, i*ch2ns, (ymax-ymin)*(data->DigiWaveform1[chID][0])[i] + ymin);
} }
} }
data->ClearData(); data->ClearData();
@ -545,8 +587,48 @@ void MainWindow::PlotSingleTrace(){
} }
Double_t traceFunc(Double_t *x, Double_t *par){
///par[0] = baseline
///par[1] = start time
///par[2] = rise time
///par[3] = Amp
///par[4] = decay time
Double_t result = par[0];
if(x[0] > par[1]){
Double_t y = x[0]-par[1];
result += par[3] *(1 - TMath::Exp( - y / par[2])) * TMath::Exp(-y / par[4]);
}
return result;
}
void MainWindow::FitTrace(){ void MainWindow::FitTrace(){
printf("=== %s not impletement.\n", __func__); printf("=== %s not impletement.\n", __func__);
if( gAnaTrace1->GetN() == 0 ) return;
double xmin, xmax, ymin, ymax;
gAnaTrace1->ComputeRange(xmin, ymin, xmax, ymax);
TF1 * f1 = new TF1("f1", traceFunc, xmin, xmax, 5);
f1->SetLineWidth(3);
f1->SetLineColor(1);
f1->SetNpx(1000);
f1->SetParameter(0, ymin);
f1->SetParameter(1, 1000); //TODO get from digi[Board]->PreTrigger * 4 * ch2ns
f1->SetParameter(2, 20);
f1->SetParameter(3, ymax-ymin);
f1->SetParameter(4, 50000);
gAnaTrace1->Fit("f1", "R");
fEcanvas->GetCanvas()->Update();
gSystem->ProcessEvents();
const Double_t* paraE = f1->GetParErrors();
const Double_t* paraA = f1->GetParameters();
LogMsg((char*)"---------- Fit result");
} }
void * MainWindow::FillHistogram(void * ptr){ void * MainWindow::FillHistogram(void * ptr){
@ -558,35 +640,90 @@ void * MainWindow::FillHistogram(void * ptr){
//int ch = chIDEntry->GetNumber(); //int ch = chIDEntry->GetNumber();
int boardID = 0; int boardID = 0;
int ch = 0; int ch = 0;
int ch2ns = 4;
int traceLength = 0;
uint32_t PreviousTime = get_time();
uint32_t CurrentTime = 0;
uint32_t ElapsedTime = 0;
Data * data = digi[boardID]->GetData(); Data * data = digi[boardID]->GetData();
data->AllocateMemory(); data->AllocateMemory();
while(digi[boardID]->IsRunning()){ while(digi[boardID]->IsRunning()){
usleep(100*1000); /// wait half sec usleep(100*1000); /// wait 100 msec
digi[boardID]->ReadData(); digi[boardID]->ReadData();
if( data->nByte > 0 ){ ch2ns = (int) digi[boardID]->GetCh2ns();
data->DecodeBuffer(0); ch = chIDEntry->GetNumber();
data->PrintStat();
if( data->nByte > 0 ){
//data->PrintStat();
if( cbMode->GetSelected() == Mode_DataRun ){
// Rate graph?
}else{
data->DecodeBuffer(0);
fEcanvas->GetCanvas()->cd();
///Fill trace
if( cbMode->GetSelected() == Mode_Oscilloscope){
unsigned short nData = data->NumEvents[ch];
traceLength = (data->Waveform1[ch][nData-1]).size();
if( traceLength > 0 ){
for( int i = 0; i < traceLength; i++) {
gAnaTrace1->SetPoint(i, i*ch2ns, (data->Waveform1[ch][nData-1])[i]);
}
if( traceLength <= gAnaTrace1->GetN() ){
for( int i = gAnaTrace1->GetN() -1 ; i >= traceLength ; i--){
gAnaTrace1->RemovePoint(i);
}
}
gAnaTrace1->Draw("APL");
}
}
}
}
CurrentTime = get_time();
ElapsedTime = CurrentTime - PreviousTime; /// milliseconds
if( ElapsedTime > 500 ){
///Fill Channel Count
for( int i = 0 ; i < digi[boardID]->GetNChannel(); i++){
hChannel[boardID]->Fill(i, data->NumEvents[i]);
}
///Fill Energy histogram
//for( int ch = 0; ch < digi[boardID]->GetNChannel(); ch++){ //for( int ch = 0; ch < digi[boardID]->GetNChannel(); ch++){
for( int i = 0; i < data->NumEvents[ch]; i++){ for( int i = 0; i < data->NumEvents[ch]; i++){
hEnergy[boardID][ch]->Fill( data->Energy[ch][i]); hEnergy[boardID][ch]->Fill( data->Energy[ch][i]);
} }
//} //}
data->ClearData(); if( cbMode->GetSelected() == Mode_EnergyHist ) hEnergy[boardID][ch]->Draw("hist");
if( cbMode->GetSelected() == Mode_CountHist ) hChannel[boardID]->Draw("hist");
data->ClearData();
PreviousTime = CurrentTime;
}
fEcanvas->GetCanvas()->cd();
hEnergy[boardID][ch]->Draw();
fEcanvas->GetCanvas()->Update(); fEcanvas->GetCanvas()->Update();
gSystem->ProcessEvents(); gSystem->ProcessEvents();
} }
}
return ptr; return ptr;
} }

View File

@ -45,7 +45,7 @@ private:
TGTextButton *bOpenDigitizers; TGTextButton *bOpenDigitizers;
TGTextButton *bStartRun; TGTextButton *bStartRun;
TGTextButton *bStopRun; TGTextButton *bStopRun;
TGComboBox* cbMode; static TGComboBox* cbMode;
TGTextEntry * dataPrefix; TGTextEntry * dataPrefix;
TGNumberEntry * runIDEntry; TGNumberEntry * runIDEntry;
@ -71,10 +71,10 @@ private:
static TH1F * hEnergy [MaxNBoards][MaxNChannels]; static TH1F * hEnergy [MaxNBoards][MaxNChannels];
static TH1F * hChannel[MaxNBoards]; static TH1F * hChannel[MaxNBoards];
TGraph * gAnaTrace1; /// analogy trace 1 static TGraph * gAnaTrace1; /// analogy trace 1
TGraph * gAnaTrace2; /// analogy trace 2 static TGraph * gAnaTrace2; /// analogy trace 2
TGraph * gDigiTrace1; /// digital trace 1 static TGraph * gDigiTrace1; /// digital trace 1
TGraph * gDigiTrace2; /// digital trace 1 static TGraph * gDigiTrace2; /// digital trace 1
public: public:
MainWindow(const TGWindow *p, UInt_t w, UInt_t h); MainWindow(const TGWindow *p, UInt_t w, UInt_t h);

View File

@ -11,7 +11,8 @@ CAENLIBS = -lCAENDigitizer
ROOTLIBS = `root-config --cflags --glibs` ROOTLIBS = `root-config --cflags --glibs`
OBJS = channelSettingPSD.o channelSettingPHA.o boardSetting.o ClassDigitizer.o DigitizerPHA.o DigitizerPSD.o FSUDAQ.o #OBJS = channelSettingPSD.o channelSettingPHA.o boardSetting.o ClassDigitizer.o DigitizerPHA.o DigitizerPSD.o FSUDAQ.o
OBJS = channelSettingPSD.o channelSettingPHA.o boardSetting.o ClassDigitizer.o FSUDAQ.o
######################################################################### #########################################################################
@ -23,15 +24,15 @@ clean :
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
DigitizerPHA.o : DigitizerPHA.cpp DigitizerPHA.h ClassDigitizer.o #DigitizerPHA.o : DigitizerPHA.cpp DigitizerPHA.h ClassDigitizer.o
$(CC) $(COPTS) -c DigitizerPHA.cpp # $(CC) $(COPTS) -c DigitizerPHA.cpp
#
#DigitizerPSD.o : DigitizerPSD.cpp DigitizerPSD.h ClassDigitizer.o
# $(CC) $(COPTS) -c DigitizerPSD.cpp
DigitizerPSD.o : DigitizerPSD.cpp DigitizerPSD.h ClassDigitizer.o test : test.cpp ClassDigitizer.o
$(CC) $(COPTS) -c DigitizerPSD.cpp
test : test.cpp ClassDigitizer.o DigitizerPHA.o DigitizerPSD.o
@echo "--------- making test" @echo "--------- making test"
$(CC) $(COPTS) -o test test.cpp ClassDigitizer.o DigitizerPHA.o DigitizerPSD.o $(CAENLIBS) $(ROOTLIBS) $(CC) $(COPTS) -o test test.cpp ClassDigitizer.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"
@ -48,7 +49,7 @@ FSUDAQDict.cxx : FSUDAQ.h FSUDAQLinkDef.h
FSUDAQ.o : FSUDAQ.h FSUDAQ.cpp FSUDAQDict.cxx FSUDAQ.o : FSUDAQ.h FSUDAQ.cpp FSUDAQDict.cxx
@echo "----------- creating FSUDAQ.o" @echo "----------- creating FSUDAQ.o"
$(CC) $(COPTS) -c FSUDAQ.cpp ClassDigitizer.cpp DigitizerPHA.cpp DigitizerPSD.cpp $(ROOTLIBS) $(CC) $(COPTS) -c FSUDAQ.cpp ClassDigitizer.cpp $(ROOTLIBS)
boardSetting.o : boardSetting.h boardSetting.cpp boardSetting.o : boardSetting.h boardSetting.cpp
@echo "----------- creating boardSetting.o" @echo "----------- creating boardSetting.o"

View File

@ -8,8 +8,7 @@
#include <TGComboBox.h> #include <TGComboBox.h>
#include <TThread.h> #include <TThread.h>
#include <TGLabel.h> #include <TGLabel.h>
#include "DigitizerPHA.h" #include "ClassDigitizer.h"
#include "DigitizerPSD.h"
#include "macro.h" #include "macro.h"
#define NUM_BOARD_INFO 9 #define NUM_BOARD_INFO 9

View File

@ -707,6 +707,10 @@ void ChannelSettingPHA::SetTriggerSmoothing(){
void ChannelSettingPHA::ReadTrace(){ void ChannelSettingPHA::ReadTrace(){
printf("=== %s\n", __func__); printf("=== %s\n", __func__);
///Send plot trace to MainWindows ///Send plot trace to MainWindows
Emit("SendPlotTraceCmd()"); SendPlotTraceCmd();
}
void ChannelSettingPHA::SendPlotTraceCmd(){
printf("=== %s\n", __func__);
Emit("SendPlotTraceCmd()");
} }