2022-03-07 16:22:04 -05:00
|
|
|
#include <TApplication.h>
|
|
|
|
#include <TGClient.h>
|
|
|
|
#include <TCanvas.h>
|
|
|
|
#include <TF1.h>
|
|
|
|
#include <TRandom.h>
|
|
|
|
#include <TGButton.h>
|
|
|
|
#include <TRootEmbeddedCanvas.h>
|
2022-03-15 19:59:36 -04:00
|
|
|
#include <TGMenu.h>
|
|
|
|
#include <TGLabel.h>
|
|
|
|
#include <TGNumberEntry.h>
|
2022-03-15 14:38:58 -04:00
|
|
|
#include <TGraph.h>
|
2022-03-30 13:13:24 -04:00
|
|
|
#include <TGTextEditor.h>
|
2022-03-15 14:38:58 -04:00
|
|
|
#include <TAxis.h>
|
2022-04-11 18:56:48 -04:00
|
|
|
#include <TF1.h>
|
2022-03-30 13:13:24 -04:00
|
|
|
|
|
|
|
#include <unistd.h>
|
2022-03-31 20:10:38 -04:00
|
|
|
#include <ctime>
|
2022-03-30 13:13:24 -04:00
|
|
|
|
|
|
|
#include "Pixie16Class.h"
|
|
|
|
|
2022-03-07 16:22:04 -05:00
|
|
|
#include "pixieDAQ.h"
|
|
|
|
|
|
|
|
|
2022-03-15 19:59:36 -04:00
|
|
|
enum MenuIdentifiers{
|
|
|
|
|
|
|
|
M_FILE_OPEN,
|
|
|
|
M_EXIT,
|
2022-03-30 18:33:44 -04:00
|
|
|
M_CH_SETTINGS_SUMMARY,
|
2022-03-15 19:59:36 -04:00
|
|
|
M_CH_SETTING,
|
2022-03-30 18:33:44 -04:00
|
|
|
M_MODULE_SETTINGS
|
2022-03-15 19:59:36 -04:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2022-04-08 17:01:48 -04:00
|
|
|
//TODO timed Run, //pixie->SetDigitizerPresetRunTime(100000, 0);
|
|
|
|
|
2022-03-30 16:13:26 -04:00
|
|
|
///make static members
|
|
|
|
Pixie16 * MainWindow::pixie = NULL;
|
2022-03-31 20:10:38 -04:00
|
|
|
TGTextEdit * MainWindow::teLog = NULL;
|
|
|
|
TRootEmbeddedCanvas * MainWindow::fEcanvas = NULL;
|
|
|
|
TH1F * MainWindow::h1[13][16]={NULL};
|
2022-03-30 16:13:26 -04:00
|
|
|
|
2022-03-07 16:22:04 -05:00
|
|
|
MainWindow::MainWindow(const TGWindow *p,UInt_t w,UInt_t h) {
|
2022-03-15 14:38:58 -04:00
|
|
|
|
2022-03-30 16:13:26 -04:00
|
|
|
printf("Removing Pixie16Msg.log \n");
|
|
|
|
remove( "Pixie16Msg.log");
|
2022-03-31 20:10:38 -04:00
|
|
|
|
2022-03-30 16:13:26 -04:00
|
|
|
pixie = new Pixie16();
|
|
|
|
if ( pixie->GetStatus() < 0 ) {
|
|
|
|
printf("Exiting program... \n");
|
|
|
|
GoodBye();
|
|
|
|
}
|
2022-03-15 14:38:58 -04:00
|
|
|
|
2022-03-07 16:22:04 -05:00
|
|
|
/// Create a main frame
|
|
|
|
fMain = new TGMainFrame(p,w,h);
|
2022-03-15 14:38:58 -04:00
|
|
|
///fMain->SetWMPosition(500, 500); //does not work
|
2022-03-15 19:59:36 -04:00
|
|
|
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());
|
|
|
|
fMenuFile->AddEntry("&Open...", M_FILE_OPEN);
|
|
|
|
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));
|
|
|
|
|
|
|
|
fMenuSettings = new TGPopupMenu(gClient->GetRoot());
|
2022-03-30 18:33:44 -04:00
|
|
|
fMenuSettings->AddEntry("&Settings Summary", M_CH_SETTINGS_SUMMARY);
|
2022-03-15 19:59:36 -04:00
|
|
|
fMenuSettings->AddEntry("&Channel Setting", M_CH_SETTING);
|
|
|
|
fMenuSettings->AddSeparator();
|
2022-03-30 18:33:44 -04:00
|
|
|
fMenuSettings->AddEntry("Digitizer &Settings", M_MODULE_SETTINGS);
|
2022-03-15 19:59:36 -04:00
|
|
|
|
|
|
|
fMenuSettings->Connect("Activated(Int_t)", "MainWindow", this, "HandleMenu(Int_t)");
|
|
|
|
fMenuBar->AddPopup("&Settings", fMenuSettings, new TGLayoutHints(kLHintsTop | kLHintsLeft, 0, 4, 0, 0));
|
|
|
|
|
2022-03-07 16:22:04 -05:00
|
|
|
|
2022-03-30 18:33:44 -04:00
|
|
|
TGLayoutHints * uniLayoutHints = new TGLayoutHints(kLHintsNormal, 2,2,10,0); ///left, right, top, bottom
|
|
|
|
|
2022-03-07 16:22:04 -05:00
|
|
|
/// Create a horizontal frame widget with buttons
|
|
|
|
TGHorizontalFrame *hframe = new TGHorizontalFrame(fMain,200,40);
|
2022-03-16 21:10:12 -04:00
|
|
|
fMain->AddFrame(hframe, new TGLayoutHints(kLHintsCenterX,2,2,2,2));
|
|
|
|
|
|
|
|
///================= signal Channel group
|
|
|
|
TGGroupFrame * group1 = new TGGroupFrame(hframe, "Single Channel", kHorizontalFrame);
|
2022-03-30 18:33:44 -04:00
|
|
|
hframe->AddFrame(group1 );
|
2022-03-16 21:10:12 -04:00
|
|
|
|
|
|
|
TGHorizontalFrame *hframe1 = new TGHorizontalFrame(group1,200,30);
|
2022-03-30 18:33:44 -04:00
|
|
|
group1->AddFrame(hframe1 );
|
2022-03-07 16:22:04 -05:00
|
|
|
|
2022-03-16 21:10:12 -04:00
|
|
|
TGLabel * lb1 = new TGLabel(hframe1, "Module ID :");
|
2022-03-30 18:33:44 -04:00
|
|
|
hframe1->AddFrame(lb1, uniLayoutHints);
|
2022-03-15 19:59:36 -04:00
|
|
|
|
2022-03-16 21:10:12 -04:00
|
|
|
modIDEntry = new TGNumberEntry(hframe1, 0, 0, 0, TGNumberFormat::kNESInteger, TGNumberFormat::kNEANonNegative);
|
2022-03-15 19:59:36 -04:00
|
|
|
modIDEntry->SetWidth(50);
|
|
|
|
modIDEntry->SetLimits(TGNumberFormat::kNELLimitMinMax, 0, pixie->GetNumModule()-1);
|
2022-03-30 18:33:44 -04:00
|
|
|
hframe1->AddFrame(modIDEntry, uniLayoutHints);
|
2022-03-15 19:59:36 -04:00
|
|
|
|
2022-03-16 21:10:12 -04:00
|
|
|
TGLabel * lb2 = new TGLabel(hframe1, "Ch :");
|
2022-03-30 18:33:44 -04:00
|
|
|
hframe1->AddFrame(lb2, uniLayoutHints);
|
2022-03-15 19:59:36 -04:00
|
|
|
|
2022-03-16 21:10:12 -04:00
|
|
|
chEntry = new TGNumberEntry(hframe1, 0, 0, 0, TGNumberFormat::kNESInteger, TGNumberFormat::kNEANonNegative);
|
2022-03-15 19:59:36 -04:00
|
|
|
chEntry->SetWidth(50);
|
|
|
|
chEntry->SetLimits(TGNumberFormat::kNELLimitMinMax, 0, pixie->GetDigitizerNumChannel(0));
|
2022-03-30 18:33:44 -04:00
|
|
|
hframe1->AddFrame(chEntry, uniLayoutHints);
|
2022-03-15 19:59:36 -04:00
|
|
|
|
2022-03-16 21:10:12 -04:00
|
|
|
TGTextButton *bGetADCTrace = new TGTextButton(hframe1,"Get &ADC Trace");
|
2022-03-30 13:13:24 -04:00
|
|
|
bGetADCTrace->Connect("Clicked()","MainWindow",this,"GetADCTrace()");
|
2022-03-30 18:33:44 -04:00
|
|
|
hframe1->AddFrame(bGetADCTrace, uniLayoutHints);
|
2022-03-15 19:59:36 -04:00
|
|
|
|
2022-03-16 21:10:12 -04:00
|
|
|
TGTextButton *bGetBaseLine = new TGTextButton(hframe1,"Get &BaseLine");
|
2022-03-30 13:13:24 -04:00
|
|
|
bGetBaseLine->Connect("Clicked()","MainWindow",this,"GetBaseLine()");
|
2022-03-30 18:33:44 -04:00
|
|
|
hframe1->AddFrame(bGetBaseLine, uniLayoutHints);
|
2022-03-30 13:13:24 -04:00
|
|
|
|
|
|
|
TGTextButton *bScope = new TGTextButton(hframe1,"&Scope");
|
|
|
|
bScope->Connect("Clicked()","MainWindow",this,"Scope()");
|
2022-03-30 18:33:44 -04:00
|
|
|
hframe1->AddFrame(bScope, uniLayoutHints);
|
2022-03-15 19:59:36 -04:00
|
|
|
|
2022-04-11 18:56:48 -04:00
|
|
|
bFitTrace = new TGTextButton(hframe1,"&Fit");
|
|
|
|
bFitTrace->SetEnabled(false);
|
|
|
|
bFitTrace->Connect("Clicked()","MainWindow",this,"FitTrace()");
|
|
|
|
hframe1->AddFrame(bFitTrace, uniLayoutHints);
|
|
|
|
|
2022-03-16 21:10:12 -04:00
|
|
|
///================= Start Run group
|
|
|
|
TGGroupFrame * group2 = new TGGroupFrame(hframe, "Start run", kHorizontalFrame);
|
2022-03-30 18:33:44 -04:00
|
|
|
//hframe->AddFrame(group2, new TGLayoutHints(kLHintsCenterX, 5,5,3,3) );
|
|
|
|
hframe->AddFrame(group2);
|
2022-03-16 21:10:12 -04:00
|
|
|
|
|
|
|
TGHorizontalFrame *hframe2 = new TGHorizontalFrame(group2,200,30);
|
|
|
|
group2->AddFrame(hframe2);
|
|
|
|
|
2022-03-30 13:13:24 -04:00
|
|
|
tePath = new TGTextEntry(hframe2, new TGTextBuffer(10));
|
|
|
|
tePath->SetText("haha.evt");
|
2022-03-30 18:33:44 -04:00
|
|
|
hframe2->AddFrame(tePath, uniLayoutHints);
|
2022-03-30 13:13:24 -04:00
|
|
|
|
2022-03-30 18:33:44 -04:00
|
|
|
bStartRun = new TGTextButton(hframe2,"Start &Run");
|
2022-03-16 21:10:12 -04:00
|
|
|
bStartRun->Connect("Clicked()","MainWindow",this,"StartRun()");
|
2022-03-30 18:33:44 -04:00
|
|
|
hframe2->AddFrame(bStartRun, uniLayoutHints);
|
2022-03-16 21:10:12 -04:00
|
|
|
|
2022-03-30 18:33:44 -04:00
|
|
|
bStopRun = new TGTextButton(hframe2,"Stop Run");
|
2022-03-16 21:10:12 -04:00
|
|
|
bStopRun->Connect("Clicked()","MainWindow",this,"StopRun()");
|
2022-03-30 18:33:44 -04:00
|
|
|
hframe2->AddFrame(bStopRun, uniLayoutHints);
|
2022-03-16 21:10:12 -04:00
|
|
|
|
|
|
|
TGTextButton *bScalar = new TGTextButton(hframe2,"Scalar");
|
2022-03-30 16:09:12 -04:00
|
|
|
bScalar->Connect("Clicked()","MainWindow",this,"OpenScalar()");
|
2022-03-30 18:33:44 -04:00
|
|
|
hframe2->AddFrame(bScalar, uniLayoutHints);
|
2022-03-16 21:10:12 -04:00
|
|
|
|
|
|
|
|
|
|
|
///================= Read evt group
|
2022-03-30 18:33:44 -04:00
|
|
|
//TGGroupFrame * group3 = new TGGroupFrame(hframe, "Read Evt", kHorizontalFrame);
|
|
|
|
////hframe->AddFrame(group3, new TGLayoutHints(kLHintsCenterX, 5,5,3,3) );
|
|
|
|
//hframe->AddFrame(group3);
|
|
|
|
//
|
|
|
|
//TGHorizontalFrame *hframe3 = new TGHorizontalFrame(group3,200,30);
|
|
|
|
//group3->AddFrame(hframe3);
|
|
|
|
//
|
|
|
|
//TGTextButton *bOpenEVT = new TGTextButton(hframe3,"OpenEvt");
|
|
|
|
////bOpenEVT->Connect("Clicked()","MainWindow",this,"StartRun()");
|
|
|
|
//hframe3->AddFrame(bOpenEVT, uniLayoutHints);
|
2022-03-30 13:13:24 -04:00
|
|
|
|
2022-03-07 16:22:04 -05:00
|
|
|
|
2022-03-30 13:13:24 -04:00
|
|
|
///================= Create canvas widget
|
2022-03-30 18:33:44 -04:00
|
|
|
fEcanvas = new TRootEmbeddedCanvas("Ecanvas",fMain,900,400);
|
|
|
|
fMain->AddFrame(fEcanvas, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 10,10,10,10));
|
2022-03-15 19:59:36 -04:00
|
|
|
|
2022-03-30 13:13:24 -04:00
|
|
|
///================= Log massage
|
|
|
|
TGGroupFrame * groupLog = new TGGroupFrame(fMain, "Log Message", kHorizontalFrame);
|
2022-03-30 18:33:44 -04:00
|
|
|
fMain->AddFrame(groupLog, new TGLayoutHints(kLHintsCenterX, 5,5,0,5) );
|
2022-03-30 13:13:24 -04:00
|
|
|
|
2022-03-31 20:10:38 -04:00
|
|
|
teLog = new TGTextEdit(groupLog, w, 100);
|
2022-03-30 18:33:44 -04:00
|
|
|
groupLog->AddFrame(teLog, new TGLayoutHints(kLHintsNormal, 0,0,10,0));
|
2022-03-15 19:59:36 -04:00
|
|
|
|
|
|
|
|
2022-03-07 16:22:04 -05:00
|
|
|
/// Set a name to the main frame
|
2022-03-15 14:38:58 -04:00
|
|
|
fMain->SetWindowName("Pixie16 DAQ");
|
2022-03-07 16:22:04 -05:00
|
|
|
|
|
|
|
/// Map all subwindows of main frame
|
|
|
|
fMain->MapSubwindows();
|
|
|
|
|
|
|
|
/// Initialize the layout algorithm
|
|
|
|
fMain->Resize(fMain->GetDefaultSize());
|
2022-04-01 15:14:11 -04:00
|
|
|
fMain->SetWMPosition(200, 200); //does not work??
|
|
|
|
|
2022-03-07 16:22:04 -05:00
|
|
|
/// Map main frame
|
|
|
|
fMain->MapWindow();
|
2022-04-01 15:14:11 -04:00
|
|
|
|
|
|
|
|
2022-03-07 16:22:04 -05:00
|
|
|
|
2022-03-30 13:13:24 -04:00
|
|
|
/// setup thread
|
|
|
|
thread = new TThread("hahaha", SaveData, (void *) 1);
|
2022-03-31 20:10:38 -04:00
|
|
|
fillHistThread = new TThread("kakaka", FillHistogram, (void *) 1);
|
2022-03-16 16:13:18 -04:00
|
|
|
|
2022-03-30 18:33:44 -04:00
|
|
|
settingsSummary = NULL;
|
|
|
|
moduleSetting = NULL;
|
2022-03-30 18:48:58 -04:00
|
|
|
channelSetting = NULL;
|
2022-03-30 16:09:12 -04:00
|
|
|
scalarPanel = NULL;
|
2022-03-16 16:13:18 -04:00
|
|
|
|
2022-03-30 18:33:44 -04:00
|
|
|
bStopRun->SetEnabled(false);
|
|
|
|
|
2022-03-31 20:10:38 -04:00
|
|
|
LogMsg("Boot OK and ready to run.");
|
|
|
|
|
2022-04-11 18:56:48 -04:00
|
|
|
gTrace = new TGraph();
|
|
|
|
|
2022-03-30 18:33:44 -04:00
|
|
|
///HandleMenu(M_CH_SETTINGS_SUMMARY);
|
2022-03-30 13:13:24 -04:00
|
|
|
|
2022-03-07 16:22:04 -05:00
|
|
|
|
|
|
|
}
|
|
|
|
MainWindow::~MainWindow() {
|
2022-04-11 18:56:48 -04:00
|
|
|
|
2022-03-15 19:59:36 -04:00
|
|
|
delete fMenuBar;
|
|
|
|
delete fMenuFile;
|
|
|
|
delete fMenuSettings;
|
2022-04-11 18:56:48 -04:00
|
|
|
|
|
|
|
delete modIDEntry;
|
|
|
|
delete chEntry;
|
|
|
|
delete tePath;
|
|
|
|
delete teLog;
|
|
|
|
|
|
|
|
delete bStartRun;
|
|
|
|
delete bStopRun;
|
|
|
|
delete bFitTrace;
|
|
|
|
|
|
|
|
delete pixie;
|
|
|
|
|
|
|
|
delete settingsSummary;
|
|
|
|
delete moduleSetting;
|
|
|
|
delete channelSetting;
|
|
|
|
delete scalarPanel;
|
|
|
|
|
|
|
|
delete thread;
|
|
|
|
delete fillHistThread;
|
|
|
|
|
|
|
|
delete gTrace;
|
|
|
|
/// Clean up used widgets: frames, buttons, layout hints
|
|
|
|
fMain->Cleanup();
|
|
|
|
delete fMain;
|
2022-03-15 19:59:36 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MainWindow::HandleMenu(Int_t id){
|
|
|
|
switch(id){
|
|
|
|
|
2022-03-30 18:33:44 -04:00
|
|
|
///========================= File Open
|
2022-03-15 19:59:36 -04:00
|
|
|
case M_FILE_OPEN:{
|
|
|
|
|
|
|
|
}break;
|
|
|
|
|
2022-03-30 18:33:44 -04:00
|
|
|
///========================= Exit
|
2022-03-15 19:59:36 -04:00
|
|
|
case M_EXIT: GoodBye(); break;
|
|
|
|
|
2022-03-30 18:33:44 -04:00
|
|
|
///========================= Channel setting summary
|
|
|
|
case M_CH_SETTINGS_SUMMARY: {
|
|
|
|
if( settingsSummary == NULL ) {
|
|
|
|
settingsSummary = new SettingsSummary(gClient->GetRoot(), 600, 600, pixie);
|
2022-03-30 16:09:12 -04:00
|
|
|
}else{
|
2022-03-30 18:33:44 -04:00
|
|
|
if( !settingsSummary->isOpened ) {
|
|
|
|
settingsSummary = new SettingsSummary(gClient->GetRoot(), 600, 600, pixie);
|
2022-03-30 16:09:12 -04:00
|
|
|
}
|
|
|
|
}
|
2022-03-15 19:59:36 -04:00
|
|
|
}break;
|
|
|
|
|
2022-03-30 18:48:58 -04:00
|
|
|
case M_CH_SETTING:{
|
|
|
|
if( channelSetting == NULL ) {
|
|
|
|
channelSetting = new ChannelSetting(gClient->GetRoot(), 600, 600, pixie);
|
|
|
|
}else{
|
|
|
|
if( !channelSetting->isOpened ) {
|
|
|
|
channelSetting = new ChannelSetting(gClient->GetRoot(), 600, 600, pixie);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}break;
|
|
|
|
|
2022-03-30 18:33:44 -04:00
|
|
|
///========================= Module setting
|
|
|
|
case M_MODULE_SETTINGS:{
|
|
|
|
if( moduleSetting == NULL ) {
|
|
|
|
moduleSetting = new ModuleSetting(gClient->GetRoot(), 600, 600, pixie);
|
|
|
|
}else{
|
|
|
|
if( !moduleSetting->isOpened ) {
|
|
|
|
moduleSetting = new ModuleSetting(gClient->GetRoot(), 600, 600, pixie);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}break;
|
|
|
|
|
2022-03-15 19:59:36 -04:00
|
|
|
}
|
|
|
|
|
2022-03-07 16:22:04 -05:00
|
|
|
}
|
|
|
|
|
2022-03-15 14:38:58 -04:00
|
|
|
|
2022-03-30 13:13:24 -04:00
|
|
|
void MainWindow::GetADCTrace() {
|
2022-03-15 14:38:58 -04:00
|
|
|
|
2022-03-15 19:59:36 -04:00
|
|
|
int modID = modIDEntry->GetNumber();
|
|
|
|
int ch = chEntry->GetNumber();
|
2022-03-31 20:10:38 -04:00
|
|
|
|
|
|
|
LogMsg(Form("Get ADCTrace for mod:%d, ch-%02d", modID, ch));
|
|
|
|
|
|
|
|
pixie->CaptureADCTrace(modID, ch);
|
2022-03-15 14:38:58 -04:00
|
|
|
unsigned short * haha = pixie->GetADCTrace();
|
2022-03-15 19:59:36 -04:00
|
|
|
double dt = pixie->GetChannelSetting("XDT", modID, ch);
|
2022-03-15 14:38:58 -04:00
|
|
|
|
|
|
|
TGraph * gTrace = new TGraph();
|
2022-03-16 21:10:12 -04:00
|
|
|
|
2022-03-15 14:38:58 -04:00
|
|
|
for( int i = 0 ; i < pixie->GetADCTraceLength(); i++){
|
|
|
|
gTrace->SetPoint(i, i*dt, haha[i]);
|
|
|
|
}
|
|
|
|
gTrace->GetXaxis()->SetTitle("time [us]");
|
2022-04-01 18:54:59 -04:00
|
|
|
gTrace->GetXaxis()->SetRangeUser(0, pixie->GetADCTraceLength()*dt);
|
2022-03-16 21:10:12 -04:00
|
|
|
gTrace->Draw("APL");
|
2022-03-15 14:38:58 -04:00
|
|
|
|
2022-03-07 16:22:04 -05:00
|
|
|
TCanvas *fCanvas = fEcanvas->GetCanvas();
|
|
|
|
fCanvas->cd();
|
|
|
|
fCanvas->Update();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2022-03-30 13:13:24 -04:00
|
|
|
void MainWindow::GetBaseLine(){
|
2022-03-16 21:10:12 -04:00
|
|
|
|
|
|
|
int modID = modIDEntry->GetNumber();
|
|
|
|
int ch = chEntry->GetNumber();
|
2022-03-31 20:10:38 -04:00
|
|
|
|
|
|
|
LogMsg(Form("Get Baseline for mod:%d, ch-%02d", modID, ch));
|
|
|
|
|
2022-03-16 21:10:12 -04:00
|
|
|
pixie->CaptureBaseLine(modID, ch);
|
|
|
|
|
|
|
|
double * baseline = pixie->GetBasline();
|
|
|
|
double * baselineTime = pixie->GetBaselineTimestamp();
|
|
|
|
|
|
|
|
TGraph * gTrace = new TGraph();
|
|
|
|
|
|
|
|
for( int i = 0 ; i < pixie->GetBaslineLength(); i++){
|
|
|
|
gTrace->SetPoint(i, baselineTime[i]*1000, baseline[i]);
|
|
|
|
}
|
|
|
|
gTrace->GetXaxis()->SetTitle("time [ns]");
|
|
|
|
gTrace->Draw("APL");
|
|
|
|
|
|
|
|
TCanvas *fCanvas = fEcanvas->GetCanvas();
|
|
|
|
fCanvas->cd();
|
|
|
|
fCanvas->Update();
|
|
|
|
|
|
|
|
}
|
2022-03-07 16:22:04 -05:00
|
|
|
|
2022-03-30 13:13:24 -04:00
|
|
|
void MainWindow::Scope(){
|
|
|
|
|
|
|
|
int modID = modIDEntry->GetNumber();
|
|
|
|
int ch = chEntry->GetNumber();
|
|
|
|
|
|
|
|
if( pixie->GetChannelOnOff(modID, ch) == false ){
|
2022-03-31 20:10:38 -04:00
|
|
|
LogMsg(Form("mod:%d, ch-%d is disabled\n", modID, ch));
|
2022-03-30 13:13:24 -04:00
|
|
|
return;
|
2022-03-31 20:10:38 -04:00
|
|
|
}
|
2022-03-30 13:13:24 -04:00
|
|
|
|
2022-03-31 20:10:38 -04:00
|
|
|
LogMsg(Form("Get trace for mod:%d, ch-%02d", modID, ch));
|
2022-03-30 13:13:24 -04:00
|
|
|
|
|
|
|
double dt = pixie->GetCh2ns(modID);
|
|
|
|
|
|
|
|
DataBlock * data = pixie->GetData();
|
|
|
|
|
2022-04-01 18:54:59 -04:00
|
|
|
int runDuration = 200; ///msec
|
|
|
|
|
|
|
|
LogMsg(Form("[Scope] Take data for %d msec.", runDuration));
|
2022-03-30 13:13:24 -04:00
|
|
|
pixie->StartRun(1);
|
|
|
|
|
2022-04-01 18:54:59 -04:00
|
|
|
usleep(runDuration*1000);
|
2022-03-30 13:13:24 -04:00
|
|
|
pixie->ReadData(0);
|
|
|
|
pixie->StopRun();
|
|
|
|
|
2022-04-11 18:56:48 -04:00
|
|
|
delete gTrace;
|
|
|
|
gTrace = new TGraph();
|
2022-03-30 13:13:24 -04:00
|
|
|
|
2022-03-31 20:10:38 -04:00
|
|
|
///printf(" next word : %u\n", pixie->GetNextWord());
|
|
|
|
///printf("number of word received : %u\n", pixie->GetnFIFOWords());
|
2022-03-30 13:13:24 -04:00
|
|
|
|
2022-04-01 18:54:59 -04:00
|
|
|
while( pixie->ProcessSingleData() <= 1 ){ /// full set of dataBlack
|
2022-03-30 13:13:24 -04:00
|
|
|
|
|
|
|
if( pixie->GetNextWord() >= pixie->GetnFIFOWords() ) break;
|
|
|
|
if( data->slot < 2 ) break;
|
|
|
|
if( data->eventID >= pixie->GetnFIFOWords() ) break;
|
|
|
|
|
2022-03-31 20:10:38 -04:00
|
|
|
///printf("mod:%d, ch:%d, event:%llu, %u, %u\n", data->slot-2, data->ch, data->eventID, pixie->GetNextWord(), pixie->GetnFIFOWords() );
|
2022-03-30 13:13:24 -04:00
|
|
|
|
|
|
|
if( data->ch == ch && data->slot == modID + 2 ){
|
|
|
|
|
|
|
|
for( int i = 0 ; i < data->trace_length; i++){
|
|
|
|
gTrace->SetPoint(i, i*dt, (data->trace)[i]);
|
|
|
|
}
|
2022-04-11 18:56:48 -04:00
|
|
|
gTrace->GetXaxis()->SetTitle("time [ns]");
|
2022-04-01 18:54:59 -04:00
|
|
|
gTrace->GetXaxis()->SetRangeUser(0, data->trace_length * dt);
|
2022-03-31 20:10:38 -04:00
|
|
|
gTrace->SetTitle(Form("mod-%d, ch-%02d\n", modID, ch));
|
2022-03-30 13:13:24 -04:00
|
|
|
gTrace->Draw("APL");
|
|
|
|
|
|
|
|
TCanvas *fCanvas = fEcanvas->GetCanvas();
|
|
|
|
fCanvas->cd();
|
|
|
|
fCanvas->Update();
|
|
|
|
|
2022-04-11 18:56:48 -04:00
|
|
|
bFitTrace->SetEnabled(true);
|
|
|
|
|
2022-03-30 13:13:24 -04:00
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-31 20:10:38 -04:00
|
|
|
///printf("=============== finished \n");
|
2022-03-30 13:13:24 -04:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2022-04-11 18:56:48 -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::FitTrace(){
|
|
|
|
|
|
|
|
int modID = modIDEntry->GetNumber();
|
|
|
|
int ch = chEntry->GetNumber();
|
|
|
|
|
|
|
|
///estimation of parameter;
|
|
|
|
double t0 = pixie->GetChannelTraceDelay(modID, ch)*1000.;
|
|
|
|
|
|
|
|
double x, y;
|
|
|
|
double xMin = 1e10, xMax = 0, yMin = 1e10, yMax = 0;
|
|
|
|
int nData = gTrace->GetN();
|
|
|
|
for( int i = 0 ; i < nData ; i++){
|
|
|
|
gTrace->GetPoint(i, x, y);
|
|
|
|
if( x < xMin) xMin = x;
|
|
|
|
if( x > xMax) xMax = x;
|
|
|
|
if( y < yMin) yMin = y;
|
|
|
|
if( y > yMax) yMax = y;
|
|
|
|
}
|
2022-04-12 16:27:24 -04:00
|
|
|
|
2022-04-11 18:56:48 -04:00
|
|
|
double baseline = yMin;
|
|
|
|
double amp = yMax-yMin;
|
|
|
|
|
|
|
|
double riseTime = 200;
|
|
|
|
double decayTime = 40000;
|
|
|
|
|
|
|
|
TF1 * traceFunc = new TF1("fit", standardPulse, xMin + t0*0.1, xMax - t0*0.1, 5);
|
|
|
|
|
|
|
|
traceFunc->SetNpx(1000);
|
|
|
|
traceFunc->SetParameter(0, t0);
|
|
|
|
traceFunc->SetParameter(1, riseTime); /// ns
|
|
|
|
traceFunc->SetParameter(2, decayTime); /// ns
|
|
|
|
traceFunc->SetParameter(3, amp);
|
|
|
|
traceFunc->SetParameter(4, baseline);
|
|
|
|
|
|
|
|
traceFunc->SetParLimits(0, t0*0.9, t0*1.1);
|
|
|
|
traceFunc->SetParLimits(1, 10., 500);
|
|
|
|
traceFunc->SetParLimits(2, 10., 100000);
|
|
|
|
traceFunc->SetParLimits(3, 10., yMax);
|
|
|
|
traceFunc->SetParLimits(4, 10., 2*yMin);
|
|
|
|
|
|
|
|
gTrace->Fit("fit", "qR0");
|
|
|
|
|
|
|
|
traceFunc->Draw("same");
|
|
|
|
|
|
|
|
TCanvas *fCanvas = fEcanvas->GetCanvas();
|
|
|
|
fCanvas->cd();
|
|
|
|
fCanvas->Update();
|
|
|
|
|
|
|
|
LogMsg("========= fit result");
|
|
|
|
TString text[5] ={"start time", "rise time", "decay time", "amp", "baseline"};
|
|
|
|
TString unit[5] ={"ns", "ns", "ns", "unit", "unit"};
|
|
|
|
|
|
|
|
for( int i = 0; i < 5; i++){
|
|
|
|
LogMsg(Form(" %10s : %8.2f(%8.2f) %s", text[i].Data(), traceFunc->GetParameter(i), traceFunc->GetParError(i), unit[i].Data()));
|
|
|
|
}
|
|
|
|
|
|
|
|
delete traceFunc;
|
|
|
|
}
|
|
|
|
|
2022-03-30 13:13:24 -04:00
|
|
|
|
2022-03-15 19:59:36 -04:00
|
|
|
|
2022-03-07 16:22:04 -05:00
|
|
|
void MainWindow::GoodBye(){
|
2022-03-15 14:38:58 -04:00
|
|
|
|
|
|
|
pixie->CloseDigitizers();
|
|
|
|
|
2022-03-07 16:22:04 -05:00
|
|
|
printf("----- bye bye ---- \n");
|
2022-03-15 14:38:58 -04:00
|
|
|
|
2022-03-07 16:22:04 -05:00
|
|
|
gApplication->Terminate(0);
|
2022-03-15 14:38:58 -04:00
|
|
|
|
2022-03-07 16:22:04 -05:00
|
|
|
}
|
|
|
|
|
2022-03-16 21:10:12 -04:00
|
|
|
void MainWindow::StartRun(){
|
|
|
|
|
2022-03-30 13:13:24 -04:00
|
|
|
pixie->OpenFile(tePath->GetText(), false);
|
|
|
|
|
2022-03-30 16:09:12 -04:00
|
|
|
LogMsg(Form("Start Run. Save data at %s.\n", tePath->GetText()));
|
|
|
|
|
2022-03-16 21:10:12 -04:00
|
|
|
pixie->StartRun(1);
|
2022-03-30 18:33:44 -04:00
|
|
|
if( pixie->IsRunning() ) thread->Run(); /// call SaveData()
|
2022-03-30 13:13:24 -04:00
|
|
|
|
2022-03-30 18:33:44 -04:00
|
|
|
bStartRun->SetEnabled(false);
|
|
|
|
bStopRun->SetEnabled(true);
|
2022-03-30 13:13:24 -04:00
|
|
|
}
|
|
|
|
|
2022-03-16 21:10:12 -04:00
|
|
|
|
2022-03-31 20:10:38 -04:00
|
|
|
void MainWindow::StopRun(){
|
|
|
|
|
|
|
|
pixie->StopRun();
|
|
|
|
pixie->ReadData(0);
|
|
|
|
pixie->SaveData();
|
|
|
|
|
|
|
|
LogMsg("Stop Run");
|
|
|
|
LogMsg(Form("File Size : %.2f MB", pixie->GetFileSize()/1024./1024.));
|
|
|
|
pixie->CloseFile();
|
2022-04-01 18:54:59 -04:00
|
|
|
|
2022-03-31 20:10:38 -04:00
|
|
|
pixie->PrintStatistics(0);
|
|
|
|
bStartRun->SetEnabled(true);
|
|
|
|
bStopRun->SetEnabled(false);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MainWindow::OpenScalar(){
|
|
|
|
|
|
|
|
if( scalarPanel == NULL ) {
|
|
|
|
scalarPanel = new ScalarPanel(gClient->GetRoot(), 600, 600, pixie);
|
|
|
|
}else{
|
|
|
|
if( !scalarPanel->isOpened ) scalarPanel = new ScalarPanel(gClient->GetRoot(), 600, 600, pixie);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MainWindow::LogMsg(TString msg){
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
teLog->AddLine(Form("[%4d-%02d-%02d %02d:%02d:%02d] ", year, month, day, hour, minute, secound) + msg);
|
|
|
|
teLog->LineDown();
|
|
|
|
teLog->ShowBottom();
|
|
|
|
}
|
|
|
|
|
|
|
|
//############################################ Threads
|
|
|
|
|
2022-03-30 13:13:24 -04:00
|
|
|
void * MainWindow::SaveData(void* ptr){
|
|
|
|
|
|
|
|
printf("Save Data()\n");
|
|
|
|
|
2022-03-31 20:10:38 -04:00
|
|
|
double oldFileSize = 0, newFileSize = 0;
|
|
|
|
double oldTime = 0, newTime = 0;
|
|
|
|
TBenchmark localClock;
|
|
|
|
localClock.Reset();
|
|
|
|
localClock.Start("timer");
|
2022-04-01 15:14:11 -04:00
|
|
|
|
2022-04-08 17:01:48 -04:00
|
|
|
int pauseTime = 10 ; ///msec
|
2022-03-31 20:10:38 -04:00
|
|
|
|
2022-03-30 13:13:24 -04:00
|
|
|
while( pixie->IsRunning() ){
|
|
|
|
|
2022-04-01 15:14:11 -04:00
|
|
|
if( pauseTime > 10 ) usleep(pauseTime*1000);
|
2022-03-30 13:13:24 -04:00
|
|
|
|
2022-03-31 20:10:38 -04:00
|
|
|
if( !pixie->IsRunning() ) break;
|
|
|
|
|
2022-03-30 13:13:24 -04:00
|
|
|
pixie->ReadData(0);
|
2022-04-01 15:14:11 -04:00
|
|
|
|
2022-04-08 17:01:48 -04:00
|
|
|
if( pixie->GetnFIFOWords() > 0 ) {
|
|
|
|
pixie->SaveData();
|
2022-03-30 18:33:44 -04:00
|
|
|
|
2022-04-08 17:01:48 -04:00
|
|
|
localClock.Stop("timer");
|
|
|
|
newTime = localClock.GetRealTime("timer"); /// sec
|
|
|
|
localClock.Start("timer");
|
|
|
|
|
|
|
|
if( newTime - oldTime > 1 ) {
|
|
|
|
//double MByteRead = pixie->GetnFIFOWords()*4./1024./1024.;
|
|
|
|
//if( MByteRead > 70 && pauseTime > 10) pauseTime = pauseTime - 20;
|
|
|
|
|
|
|
|
//TODO Fill HISTORGRAM;
|
|
|
|
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;
|
|
|
|
|
|
|
|
newFileSize = pixie->GetFileSize()/1024./1024.;
|
|
|
|
|
|
|
|
double rate = (newFileSize - oldFileSize)/ (newTime-oldTime);
|
|
|
|
oldFileSize = newFileSize;
|
|
|
|
oldTime = newTime;
|
|
|
|
|
|
|
|
//teLog->AddLine(Form("[%4d-%02d-%02d %02d:%02d:%02d] File Size : %.2f MB [%.2f MB/s], %.2f MB readed",
|
|
|
|
// year, month, day, hour, minute, secound, newFileSize, rate, MByteRead));
|
|
|
|
teLog->AddLine(Form("[%4d-%02d-%02d %02d:%02d:%02d] File Size : %.2f MB [%.2f MB/s]",
|
|
|
|
year, month, day, hour, minute, secound, newFileSize, rate));
|
|
|
|
teLog->LineDown();
|
|
|
|
}
|
|
|
|
}
|
2022-03-30 13:13:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
pixie->ReadData(0);
|
|
|
|
pixie->SaveData();
|
|
|
|
|
|
|
|
printf("finished Save Data.\n");
|
|
|
|
|
|
|
|
return ptr;
|
2022-03-16 21:10:12 -04:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2022-03-31 20:10:38 -04:00
|
|
|
void * MainWindow::FillHistogram(void *ptr){
|
2022-03-16 21:10:12 -04:00
|
|
|
|
2022-03-31 20:10:38 -04:00
|
|
|
//using evtReader or process from ExtFIFOword, but in case in complete data
|
2022-03-16 21:10:12 -04:00
|
|
|
|
2022-03-30 13:13:24 -04:00
|
|
|
|
2022-03-30 16:09:12 -04:00
|
|
|
|
2022-03-31 20:10:38 -04:00
|
|
|
return ptr;
|
2022-03-30 13:13:24 -04:00
|
|
|
}
|
|
|
|
|
2022-03-07 16:22:04 -05:00
|
|
|
|
2022-03-31 20:10:38 -04:00
|
|
|
//############################################
|
2022-03-07 16:22:04 -05:00
|
|
|
int main(int argc, char **argv) {
|
|
|
|
printf(" Welcome to pixie16 DQ \n");
|
2022-03-15 14:38:58 -04:00
|
|
|
|
2022-03-07 16:22:04 -05:00
|
|
|
TApplication theApp("App",&argc,argv);
|
2022-03-30 13:13:24 -04:00
|
|
|
new MainWindow(gClient->GetRoot(),800,800);
|
2022-03-07 16:22:04 -05:00
|
|
|
theApp.Run();
|
|
|
|
return 0;
|
|
|
|
}
|