2022-08-04 17:27:33 -04:00
|
|
|
#include <TApplication.h>
|
|
|
|
#include <TGClient.h>
|
|
|
|
#include <TCanvas.h>
|
|
|
|
#include <TF1.h>
|
|
|
|
#include <TRandom.h>
|
|
|
|
#include <TGButton.h>
|
|
|
|
#include <TRootEmbeddedCanvas.h>
|
|
|
|
#include <TGMenu.h>
|
|
|
|
#include <TGLabel.h>
|
|
|
|
#include <TGNumberEntry.h>
|
|
|
|
#include <TGraph.h>
|
|
|
|
#include <TAxis.h>
|
|
|
|
#include <TF1.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <ctime>
|
|
|
|
#include "DigitizerPHA.h"
|
|
|
|
#include "DigitizerPSD.h"
|
|
|
|
#include "FSUDAQ.h"
|
2022-08-23 13:43:05 -04:00
|
|
|
|
|
|
|
|
2022-08-04 17:27:33 -04:00
|
|
|
enum MenuIdentifiers{
|
|
|
|
|
2022-08-23 13:43:05 -04:00
|
|
|
M_DIGITIZER_SCAN,
|
2022-08-04 17:27:33 -04:00
|
|
|
M_FILE_OPEN,
|
|
|
|
M_EXIT,
|
2022-08-26 17:18:43 -04:00
|
|
|
M_TRIGGER_SUMMARY,
|
2022-08-04 17:27:33 -04:00
|
|
|
M_CH_SETTING,
|
2022-08-23 13:43:05 -04:00
|
|
|
M_BOARD_SETTINGS,
|
2022-08-04 17:27:33 -04:00
|
|
|
M_PROGRAM_SETTINGS,
|
|
|
|
M_FINDPEAKS,
|
|
|
|
M_SHOW_CHANNELS_RATE
|
|
|
|
|
|
|
|
};
|
|
|
|
///make static members
|
2022-08-23 13:43:05 -04:00
|
|
|
Digitizer ** MainWindow::digi = NULL;
|
2022-09-16 17:53:57 -04:00
|
|
|
DigitizerPHA ** MainWindow::pha = NULL;
|
|
|
|
DigitizerPSD ** MainWindow::psd = NULL;
|
2022-08-04 17:27:33 -04:00
|
|
|
TGTextEdit * MainWindow::teLog = NULL;
|
|
|
|
TRootEmbeddedCanvas * MainWindow::fEcanvas = NULL;
|
2022-08-04 18:02:03 -04:00
|
|
|
|
2022-08-04 17:27:33 -04:00
|
|
|
MainWindow::MainWindow(const TGWindow *p,UInt_t w,UInt_t h) {
|
|
|
|
|
2022-08-23 13:43:05 -04:00
|
|
|
nDigi = 0;
|
2022-09-16 17:53:57 -04:00
|
|
|
nPSD = 0;
|
|
|
|
nPHA = 0;
|
2022-08-04 18:02:03 -04:00
|
|
|
|
2022-08-04 17:27:33 -04:00
|
|
|
/// Create a main frame
|
|
|
|
fMain = new TGMainFrame(p,w,h);
|
|
|
|
///fMain->SetWMPosition(500, 500); //does not work
|
|
|
|
fMain->Connect("CloseWindow()", "MainWindow", this, "GoodBye()");
|
|
|
|
///======================= menu
|
|
|
|
fMenuBar = new TGMenuBar(fMain, 1, 1, kHorizontalFrame);
|
|
|
|
fMain->AddFrame(fMenuBar, new TGLayoutHints(kLHintsTop | kLHintsExpandX));
|
|
|
|
fMenuFile = new TGPopupMenu(gClient->GetRoot());
|
2022-08-04 18:02:03 -04:00
|
|
|
fMenuFile->AddEntry("&Open File", M_FILE_OPEN);
|
2022-08-04 17:27:33 -04:00
|
|
|
fMenuFile->AddSeparator();
|
|
|
|
fMenuFile->AddEntry("E&xit", M_EXIT);
|
|
|
|
fMenuFile->Connect("Activated(Int_t)", "MainWindow", this, "HandleMenu(Int_t)");
|
|
|
|
fMenuBar->AddPopup("&File", fMenuFile, new TGLayoutHints(kLHintsTop | kLHintsLeft, 0, 4, 0, 0));
|
|
|
|
|
2022-08-26 17:18:43 -04:00
|
|
|
fMenuDigitizers = new TGPopupMenu(gClient->GetRoot());
|
|
|
|
fMenuDigitizers->AddEntry("Scan &Digitizers", M_DIGITIZER_SCAN);
|
|
|
|
fMenuDigitizers->AddEntry("&Trigger Summary", M_TRIGGER_SUMMARY);
|
|
|
|
fMenuDigitizers->AddSeparator();
|
|
|
|
fMenuDigitizers->AddEntry("Digitizer &Settings", M_BOARD_SETTINGS);
|
|
|
|
fMenuDigitizers->AddEntry("&Channel Settings", M_CH_SETTING);
|
|
|
|
fMenuDigitizers->AddSeparator();
|
|
|
|
fMenuDigitizers->AddEntry("&Program Settings", M_PROGRAM_SETTINGS);
|
|
|
|
fMenuDigitizers->Connect("Activated(Int_t)", "MainWindow", this, "HandleMenu(Int_t)");
|
|
|
|
fMenuBar->AddPopup("&Digitizers", fMenuDigitizers, new TGLayoutHints(kLHintsTop | kLHintsLeft, 0, 4, 0, 0));
|
2022-09-19 12:46:27 -04:00
|
|
|
|
2022-09-20 15:15:52 -04:00
|
|
|
//fMenuDigitizers->DisableEntry( M_TRIGGER_SUMMARY);
|
|
|
|
//fMenuDigitizers->DisableEntry( M_BOARD_SETTINGS);
|
|
|
|
//fMenuDigitizers->DisableEntry( M_CH_SETTING);
|
2022-08-26 17:18:43 -04:00
|
|
|
|
2022-08-04 17:27:33 -04:00
|
|
|
fMenuUtility = new TGPopupMenu(gClient->GetRoot());
|
|
|
|
fMenuUtility->AddEntry("Plot Channels Rate", M_SHOW_CHANNELS_RATE);
|
2022-08-26 17:18:43 -04:00
|
|
|
fMenuDigitizers->AddSeparator();
|
2022-08-04 17:27:33 -04:00
|
|
|
fMenuUtility->AddEntry("Find &Peaks", M_FINDPEAKS);
|
|
|
|
fMenuUtility->Connect("Activated(Int_t)", "MainWindow", this, "HandleMenu(Int_t)");
|
|
|
|
fMenuBar->AddPopup("&Utility", fMenuUtility, new TGLayoutHints(kLHintsTop | kLHintsLeft, 0, 4, 0, 0));
|
|
|
|
TGLayoutHints * uniLayoutHints = new TGLayoutHints(kLHintsNormal, 2,2,10,0); ///left, right, top, bottom
|
2022-08-04 18:02:03 -04:00
|
|
|
|
|
|
|
///================= Create a horizontal frame widget with buttons
|
2022-08-04 17:27:33 -04:00
|
|
|
TGHorizontalFrame *hframe = new TGHorizontalFrame(fMain,200,40);
|
|
|
|
fMain->AddFrame(hframe, new TGLayoutHints(kLHintsCenterX,2,2,2,2));
|
|
|
|
|
2022-08-23 13:43:05 -04:00
|
|
|
///================= Open digitizers
|
|
|
|
TGTextButton *bOpenDigitizers = new TGTextButton(hframe,"Open Digitizers");
|
|
|
|
bOpenDigitizers->Connect("Clicked()","MainWindow",this,"DetectDigitizer()");
|
|
|
|
hframe->AddFrame(bOpenDigitizers, uniLayoutHints);
|
2022-09-16 17:53:57 -04:00
|
|
|
|
|
|
|
///================= Start Run
|
|
|
|
TGTextButton *bStartRun = new TGTextButton(hframe,"Start Run"); hframe->AddFrame(bStartRun, uniLayoutHints);
|
|
|
|
|
|
|
|
///================= Stop Run
|
|
|
|
TGTextButton *bStopRun = new TGTextButton(hframe,"Stop Run"); hframe->AddFrame(bStopRun, uniLayoutHints);
|
2022-08-23 13:43:05 -04:00
|
|
|
|
2022-08-04 17:27:33 -04:00
|
|
|
///================= signal Channel group
|
|
|
|
TGGroupFrame * group1 = new TGGroupFrame(hframe, "Single Channel", kHorizontalFrame);
|
|
|
|
hframe->AddFrame(group1 );
|
|
|
|
|
|
|
|
TGHorizontalFrame *hframe1 = new TGHorizontalFrame(group1,200,30);
|
|
|
|
group1->AddFrame(hframe1 );
|
|
|
|
|
|
|
|
///================= Create canvas widget
|
|
|
|
fEcanvas = new TRootEmbeddedCanvas("Ecanvas",fMain,900,400);
|
|
|
|
fMain->AddFrame(fEcanvas, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 10,10,10,10));
|
|
|
|
///================= Log massage
|
|
|
|
TGGroupFrame * groupLog = new TGGroupFrame(fMain, "Log Message", kHorizontalFrame);
|
|
|
|
fMain->AddFrame(groupLog, new TGLayoutHints(kLHintsCenterX, 5,5,0,5) );
|
|
|
|
|
|
|
|
teLog = new TGTextEdit(groupLog, w, 100);
|
|
|
|
groupLog->AddFrame(teLog, new TGLayoutHints(kLHintsNormal, 0,0,10,0));
|
|
|
|
/// Set a name to the main frame
|
2022-08-04 18:02:03 -04:00
|
|
|
fMain->SetWindowName("FSU DAQ");
|
2022-08-04 17:27:33 -04:00
|
|
|
/// Map all subwindows of main frame
|
|
|
|
fMain->MapSubwindows();
|
|
|
|
/// Initialize the layout algorithm
|
|
|
|
fMain->Resize(fMain->GetDefaultSize());
|
|
|
|
fMain->SetWMPosition(200, 200); //does not work??
|
|
|
|
|
|
|
|
/// Map main frame
|
|
|
|
fMain->MapWindow();
|
|
|
|
|
|
|
|
/// setup thread
|
|
|
|
//saveDataThread = new TThread("hahaha", SaveData, (void *) 1);
|
|
|
|
//fillHistThread = new TThread("kakaka", FillHistogram, (void *) 1);
|
|
|
|
|
|
|
|
///settingsSummary = NULL;
|
2022-08-23 13:43:05 -04:00
|
|
|
boardSetting = NULL;
|
|
|
|
channelSetting = NULL;
|
2022-08-04 17:27:33 -04:00
|
|
|
///scalarPanel = NULL;
|
|
|
|
|
2022-08-04 18:02:03 -04:00
|
|
|
LogMsg("Ready to run.");
|
2022-08-04 17:27:33 -04:00
|
|
|
|
2022-09-19 12:46:27 -04:00
|
|
|
//HandleMenu(M_DIGITIZER_SCAN);
|
|
|
|
//
|
2022-09-21 17:40:47 -04:00
|
|
|
//HandleMenu(M_BOARD_SETTINGS);
|
|
|
|
HandleMenu(M_CH_SETTING);
|
2022-08-04 17:27:33 -04:00
|
|
|
|
|
|
|
}
|
|
|
|
MainWindow::~MainWindow() {
|
|
|
|
delete fMenuBar;
|
|
|
|
delete fMenuFile;
|
2022-08-26 17:18:43 -04:00
|
|
|
delete fMenuDigitizers;
|
2022-08-04 17:27:33 -04:00
|
|
|
delete fMenuUtility;
|
|
|
|
|
2022-08-23 13:43:05 -04:00
|
|
|
//delete boardIDEntry;
|
2022-08-04 17:27:33 -04:00
|
|
|
//delete chEntry;
|
|
|
|
//delete tePath;
|
|
|
|
delete teLog;
|
|
|
|
|
2022-08-23 13:43:05 -04:00
|
|
|
if( digi != NULL ) delete [] digi;
|
|
|
|
|
|
|
|
delete boardSetting;
|
|
|
|
delete channelSetting;
|
2022-08-04 17:27:33 -04:00
|
|
|
|
|
|
|
//delete settingsSummary;
|
|
|
|
//delete scalarPanel;
|
|
|
|
//
|
|
|
|
//delete saveDataThread;
|
|
|
|
//delete fillHistThread;
|
|
|
|
//
|
|
|
|
//delete gTrace;
|
|
|
|
|
|
|
|
/// Clean up used widgets: frames, buttons, layout hints
|
|
|
|
fMain->Cleanup();
|
|
|
|
delete fMain;
|
|
|
|
}
|
|
|
|
void MainWindow::HandleMenu(Int_t id){
|
|
|
|
switch(id){
|
|
|
|
|
2022-08-23 13:43:05 -04:00
|
|
|
///========================= Scan digitizers
|
|
|
|
case M_DIGITIZER_SCAN:{
|
|
|
|
|
2022-09-19 12:46:27 -04:00
|
|
|
LogMsg("============= detect digitizers \n");
|
2022-09-16 17:53:57 -04:00
|
|
|
DetectDigitizer();
|
2022-08-23 13:43:05 -04:00
|
|
|
printf("============= Connect %d digitizers...\n", nDigi);
|
2022-09-16 17:53:57 -04:00
|
|
|
|
2022-08-23 13:43:05 -04:00
|
|
|
if( nDigi > 0 ) {
|
2022-09-16 17:53:57 -04:00
|
|
|
|
|
|
|
digi = new Digitizer * [nDigi];
|
|
|
|
|
|
|
|
//pha = new DigitizerPHA * [nPHA];
|
|
|
|
//psd = new DigitizerPHA * [nPSD];
|
|
|
|
//
|
|
|
|
//iPHA = 0;
|
|
|
|
//iPSD = 0;
|
|
|
|
|
2022-08-23 13:43:05 -04:00
|
|
|
for( int i = 0; i < nDigi; i++){
|
2022-09-16 17:53:57 -04:00
|
|
|
printf("------------ %d \n", i);
|
2022-08-23 13:43:05 -04:00
|
|
|
if( DPPType[i] == V1730_DPP_PSD_CODE ) {
|
|
|
|
digi[i] = new DigitizerPSD(boardID[i], portID[i]);
|
2022-09-16 17:53:57 -04:00
|
|
|
printf("Open as PSD\n");
|
2022-08-23 13:43:05 -04:00
|
|
|
}else if( DPPType[i] == V1730_DPP_PHA_CODE ){
|
|
|
|
digi[i] = new DigitizerPHA(boardID[i], portID[i]);
|
2022-09-16 17:53:57 -04:00
|
|
|
printf("Open as PHA\n");
|
2022-08-23 13:43:05 -04:00
|
|
|
}else{
|
|
|
|
digi[i] = new Digitizer(boardID[i], portID[i]);
|
2022-09-16 17:53:57 -04:00
|
|
|
printf("Open as Ordinary Digitizer\n");
|
2022-08-23 13:43:05 -04:00
|
|
|
}
|
2022-09-22 16:26:33 -04:00
|
|
|
digi[i]->CreateAndSaveSettingBinary("setting_" + to_string(digi[i]->GetSerialNumber()) + ".bin");
|
2022-08-23 13:43:05 -04:00
|
|
|
}
|
2022-09-19 12:46:27 -04:00
|
|
|
|
|
|
|
//fMenuDigitizers->EnableEntry( M_TRIGGER_SUMMARY);
|
2022-09-22 16:26:33 -04:00
|
|
|
//fMenuDigitizers->EnableEntry( M_BOARD_SETTINGS);
|
|
|
|
//fMenuDigitizers->EnableEntry( M_CH_SETTING);
|
2022-09-19 12:46:27 -04:00
|
|
|
|
2022-08-23 13:43:05 -04:00
|
|
|
}
|
2022-09-16 17:53:57 -04:00
|
|
|
|
2022-08-23 13:43:05 -04:00
|
|
|
}break;
|
|
|
|
|
2022-08-04 17:27:33 -04:00
|
|
|
///========================= File Open
|
|
|
|
case M_FILE_OPEN:{
|
|
|
|
|
|
|
|
|
|
|
|
}break;
|
|
|
|
|
|
|
|
///========================= Exit
|
|
|
|
case M_EXIT: GoodBye(); break;
|
|
|
|
|
|
|
|
///========================= Channel setting summary
|
2022-08-26 17:18:43 -04:00
|
|
|
case M_TRIGGER_SUMMARY: {
|
2022-08-04 17:27:33 -04:00
|
|
|
|
|
|
|
}break;
|
2022-09-19 12:46:27 -04:00
|
|
|
|
|
|
|
///========================= Channel setting
|
|
|
|
case M_CH_SETTING:
|
|
|
|
channelSetting = new ChannelSetting(gClient->GetRoot(), 600, 600, digi, nDigi);
|
2022-09-23 12:36:31 -04:00
|
|
|
channelSetting->Connect("LogMsg(char*)", "MainWindow", this, "LogMsg(char*)");
|
2022-09-22 16:26:33 -04:00
|
|
|
|
2022-09-19 12:46:27 -04:00
|
|
|
break;
|
2022-08-04 17:27:33 -04:00
|
|
|
|
2022-08-23 13:43:05 -04:00
|
|
|
///========================= Board setting
|
2022-09-21 16:05:51 -04:00
|
|
|
case M_BOARD_SETTINGS:{
|
|
|
|
if( boardSetting == NULL ) {
|
|
|
|
boardSetting = new BoardSetting(gClient->GetRoot(), 600, 600, digi, nDigi);
|
2022-09-23 12:36:31 -04:00
|
|
|
boardSetting->Connect("LogMsg(char*)", "MainWindow", this, "LogMsg(char*)");
|
2022-09-21 16:05:51 -04:00
|
|
|
}else{
|
|
|
|
if ( boardSetting->IsOpen() == false ){
|
|
|
|
boardSetting = new BoardSetting(gClient->GetRoot(), 600, 600, digi, nDigi);
|
2022-09-23 12:36:31 -04:00
|
|
|
//boardSetting->Connect("BdLogMsg(TString)", "MainWindow", this, "LogMsg(TString)");
|
2022-09-21 16:05:51 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}break;
|
2022-08-04 17:27:33 -04:00
|
|
|
|
|
|
|
///========================= Program setting
|
|
|
|
case M_PROGRAM_SETTINGS:{
|
|
|
|
LogMsg("[Program settings] Not impelmented");
|
|
|
|
}break;
|
|
|
|
|
|
|
|
///====================== Show channel rate;
|
|
|
|
case M_SHOW_CHANNELS_RATE:{
|
|
|
|
|
|
|
|
}break;
|
|
|
|
|
|
|
|
|
|
|
|
///====================== Fit Gaussian
|
|
|
|
case M_FINDPEAKS:{
|
|
|
|
|
|
|
|
LogMsg("[Find Peaks] Not impelmented");
|
|
|
|
|
|
|
|
}break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2022-08-04 18:02:03 -04:00
|
|
|
void MainWindow::DetectDigitizer(){
|
|
|
|
|
2022-08-23 13:43:05 -04:00
|
|
|
DPPType.clear();
|
|
|
|
portID.clear();
|
|
|
|
boardID.clear();
|
|
|
|
nDigi = 0;
|
|
|
|
|
|
|
|
Digitizer * dig = new Digitizer();
|
2022-08-04 18:02:03 -04:00
|
|
|
|
|
|
|
for( int port = 0; port < 4 ; port ++){
|
|
|
|
for( int board = 0; board < 3 ; board ++){
|
|
|
|
dig->OpenDigitizer(board, port);
|
|
|
|
if ( dig->GetConnectionStatus() ) {
|
|
|
|
nDigi++;
|
|
|
|
DPPType.push_back(dig->GetDPPType());
|
|
|
|
portID.push_back(port);
|
|
|
|
boardID.push_back(board);
|
2022-08-23 13:43:05 -04:00
|
|
|
serialNum.push_back(dig->GetSerialNumber());
|
2022-08-04 18:02:03 -04:00
|
|
|
dig->CloseDigitizer();
|
2022-09-16 17:53:57 -04:00
|
|
|
if( dig->GetDPPType() == V1730_DPP_PHA_CODE ) nPHA ++;
|
|
|
|
if( dig->GetDPPType() == V1730_DPP_PSD_CODE ) nPSD ++;
|
2022-08-04 18:02:03 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-19 12:46:27 -04:00
|
|
|
LogMsg(Form("========== found %d digitizer \n", nDigi));
|
2022-08-04 18:02:03 -04:00
|
|
|
for( int i = 0 ; i < nDigi ; i++){
|
2022-09-19 12:46:27 -04:00
|
|
|
LogMsg(Form("port: %d, board: %d, DPP Type : %d \n", portID[i], boardID[i], DPPType[i]));
|
2022-08-04 18:02:03 -04:00
|
|
|
}
|
2022-09-19 12:46:27 -04:00
|
|
|
LogMsg(Form("Number of PHA : %d \n", nPHA));
|
|
|
|
LogMsg(Form("Number of PSD : %d \n", nPSD));
|
2022-08-04 18:02:03 -04:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2022-08-04 17:27:33 -04:00
|
|
|
Double_t standardPulse(Double_t *x, Double_t * par){
|
|
|
|
|
|
|
|
/// par[0] = start time
|
|
|
|
/// par[1] = rise time
|
|
|
|
/// par[2] = decay time
|
|
|
|
/// par[3] = amplitude
|
|
|
|
/// par[4] = baseline
|
|
|
|
|
|
|
|
Double_t z = x[0] - par[0];
|
|
|
|
|
|
|
|
if( z <= 0 ) {
|
|
|
|
return par[4];
|
|
|
|
}else{
|
|
|
|
return par[3]*(1-TMath::Exp(-1*z/par[1]))*TMath::Exp(-1*z/par[2]) + par[4];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::GoodBye(){
|
|
|
|
|
|
|
|
printf("----- bye bye ---- \n");
|
|
|
|
|
|
|
|
gApplication->Terminate(0);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2022-09-23 12:36:31 -04:00
|
|
|
void MainWindow::LogMsg(char * msg){
|
2022-08-04 17:27:33 -04:00
|
|
|
|
|
|
|
time_t now = time(0);
|
|
|
|
tm * ltm = localtime(&now);
|
|
|
|
int year = 1900 + ltm->tm_year;
|
|
|
|
int month = 1 + ltm->tm_mon;
|
|
|
|
int day = ltm->tm_mday;
|
|
|
|
int hour = ltm->tm_hour;
|
|
|
|
int minute = ltm->tm_min;
|
|
|
|
int secound = ltm->tm_sec;
|
|
|
|
|
2022-09-23 12:36:31 -04:00
|
|
|
TString outMsg = Form("[%4d-%02d-%02d %02d:%02d:%02d] %s", year, month, day, hour, minute, secound, msg);
|
2022-09-19 12:46:27 -04:00
|
|
|
|
|
|
|
teLog->AddLine(outMsg);
|
2022-09-23 12:36:31 -04:00
|
|
|
printf("%s\n", outMsg.Data());
|
2022-08-04 17:27:33 -04:00
|
|
|
teLog->LineDown();
|
|
|
|
teLog->ShowBottom();
|
2022-09-19 12:46:27 -04:00
|
|
|
|
2022-08-04 17:27:33 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
//############################################
|
|
|
|
int main(int argc, char **argv) {
|
2022-08-04 18:02:03 -04:00
|
|
|
printf(" Welcome to FSU DQ \n");
|
2022-08-04 17:27:33 -04:00
|
|
|
|
|
|
|
TApplication theApp("App",&argc,argv);
|
|
|
|
new MainWindow(gClient->GetRoot(),800,800);
|
|
|
|
theApp.Run();
|
|
|
|
return 0;
|
|
|
|
}
|