FSUDAQ/channelSetting.cpp
2022-08-26 17:18:43 -04:00

256 lines
11 KiB
C++

#include <TApplication.h>
#include <TGClient.h>
#include <TCanvas.h>
#include <TF1.h>
#include <TRandom.h>
#include <TGButton.h>
#include <TRootEmbeddedCanvas.h>
#include <TGTableContainer.h>
#include <TGFileDialog.h>
#include "channelSetting.h"
//TODO set MAX
///------------------------------------------------ NAME, DIGI, unit ... MAX
TString settingName[NUM_CHANNEL_SETTING][3] = {{"Record Length", "3", "us"},
{"Input Dynamic Range", "1", ""},
{"Events / Aggregate", "4", ""},
{"Pre-Trigger Length", "3", "us"},
{"Trigger Threshold", "5", "LSD"},
{"Trigger Holdoff Width", "3", "us"},
{"DPP Algorithm Control", "8", ""},
{"Channel DC offset", "2", "%"},
{"Temperature", "2", "C"},
{"Veto Width", "3", "us"},
{"Trigger Filter Smoothing", "3", "smp"},
{"Input Rising Time", "3", "ns"},
{"Trapezoid Rise Time", "4", "ns"},
{"Trapezoid Flat Top", "4", "ns"},
{"Peaking Time", "4", "ns"},
{"Decay Time", "4", "us"},
{"Rise Time Valid. Win.", "4", "us"},
{"Peak Holdoff", "4", "ns"},
{"Shaped Trigger Width", "4", "us"},
{"DPP Algorithm Control 2", "8", ""},
{"Fine Gain", "3", ""}
};
///const uint32_t RecordLength_G = 0x1020; /// R/W
///const uint32_t InputDynamicRange = 0x1028; /// R/W
///const uint32_t NumberEventsPerAggregate_G = 0x1034; /// R/W
///const uint32_t PreTrigger = 0x1038; /// R/W
///const uint32_t TriggerThreshold = 0x106C; /// R/W
///const uint32_t TriggerHoldOffWidth = 0x1074; /// R/W
///const uint32_t DPPAlgorithmControl = 0x1080; /// R/W
///const uint32_t ChannelDCOffset = 0x1098; /// R/W
///const uint32_t ChannelADCTemperature = 0x10A8; /// R
///const uint32_t VetoWidth = 0x10D4; /// R/W
/// const uint32_t RCCR2SmoothingFactor = 0x1054; /// R/W Trigger Filter smoothing, triggerSmoothingFactor
/// const uint32_t InputRiseTime = 0x1058; /// R/W OK
/// const uint32_t TrapezoidRiseTime = 0x105C; /// R/W OK
/// const uint32_t TrapezoidFlatTop = 0x1060; /// R/W OK
/// const uint32_t PeakingTime = 0x1064; /// R/W OK
/// const uint32_t DecayTime = 0x1068; /// R/W OK
/// const uint32_t RiseTimeValidationWindow = 0x1070; /// R/W OK
/// const uint32_t PeakHoldOff = 0x1078; /// R/W OK
/// const uint32_t ShapedTriggerWidth = 0x1084; /// R/W not sure
/// const uint32_t DPPAlgorithmControl2_G = 0x10A0; /// R/W OK
/// const uint32_t FineGain = 0x10C4; /// R/W OK
ChannelSetting::ChannelSetting(const TGWindow *p, UInt_t w, UInt_t h, Digitizer ** digi, int nDigi){
this->digi = digi;
fMain = new TGMainFrame(p,w,h);
fMain->SetWindowName("Channel Settings ");
fMain->Connect("CloseWindow()", "ChannelSetting", this, "CloseWindow()");
TGVerticalFrame * vframe = new TGVerticalFrame(fMain);
fMain->AddFrame(vframe, new TGLayoutHints(kLHintsCenterX, 2,2,2,2));
///==========Board choose
TGHorizontalFrame *hframe0 = new TGHorizontalFrame(vframe, w, 50 );
vframe->AddFrame(hframe0, new TGLayoutHints(kLHintsCenterX, 2,2,2,2));
TGLabel * lb0 = new TGLabel(hframe0, "Module ID :");
hframe0->AddFrame(lb0, new TGLayoutHints(kLHintsCenterX | kLHintsCenterY, 5, 5, 3, 4));
boardIDEntry = new TGNumberEntry(hframe0, 0, 0, 0, TGNumberFormat::kNESInteger, TGNumberFormat::kNEANonNegative);
boardIDEntry->SetWidth(50);
boardIDEntry->SetLimits(TGNumberFormat::kNELLimitMinMax, 0, nDigi);
boardIDEntry->Connect("Modified()", "ChannelSetting", this, "ChangeBoard()");
if( nDigi <= 1 ) boardIDEntry->SetState(false);
NChannel = 16 ;// digi[0]->GetNChannel();
hframe0->AddFrame(boardIDEntry, new TGLayoutHints(kLHintsCenterX , 5, 5, 3, 4));
TGLabel * lb1 = new TGLabel(hframe0, "Channel :");
hframe0->AddFrame(lb1, new TGLayoutHints(kLHintsCenterX | kLHintsCenterY, 5, 5, 3, 4));
chIDEntry = new TGNumberEntry(hframe0, 0, 0, 0, TGNumberFormat::kNESInteger, TGNumberFormat::kNEANonNegative);
chIDEntry->SetWidth(50);
chIDEntry->SetLimits(TGNumberFormat::kNELLimitMinMax, 0, NChannel-1);
chIDEntry->Connect("Modified()", "ChannelSetting", this, "ChangeCh()");
hframe0->AddFrame(chIDEntry, new TGLayoutHints(kLHintsCenterX , 5, 5, 3, 4));
int boardID = boardIDEntry->GetNumber();
int ch = chIDEntry->GetNumber();
int width = 80;
///----------- on/off
TGHorizontalFrame *hframeOnOff = new TGHorizontalFrame(vframe, 50, 50 );
vframe->AddFrame(hframeOnOff, new TGLayoutHints(kLHintsRight, 2,2,2,2));
cbOnOff = new TGComboBox(hframeOnOff);
cbOnOff->AddEntry("ON", 1);
cbOnOff->AddEntry("off", 0);
cbOnOff->Resize(width, 20);
//pixie->GetChannelOnOff(boardID, ch) ? cbOnOff->Select(1) : cbOnOff->Select(0);
cbOnOff->Connect("Selected(Int_t, Int_t)", "ChannelSetting", this, "ChangeOnOff()");
hframeOnOff->AddFrame(cbOnOff, new TGLayoutHints(kLHintsRight, 5,5,3,4));
TGLabel * lbOnOff = new TGLabel(hframeOnOff, "On/Off");
hframeOnOff->AddFrame(lbOnOff, new TGLayoutHints(kLHintsRight | kLHintsCenterY, 5, 5, 3, 4));
///----------- Polarity
TGHorizontalFrame *hframePol = new TGHorizontalFrame(vframe, 50, 50 );
vframe->AddFrame(hframePol, new TGLayoutHints(kLHintsRight, 2,2,2,2));
cbPolarity = new TGComboBox(hframePol);
cbPolarity->AddEntry("Positive +", 1);
cbPolarity->AddEntry("Negative -", 0);
cbPolarity->Resize(width, 20);
//pixie->GetChannelPolarity(boardID, ch) ? cbPolarity->Select(1) : cbPolarity->Select(0);
cbPolarity->Connect("Selected(Int_t, Int_t)", "ChannelSetting", this, "ChangeOnOff()");
hframePol->AddFrame(cbPolarity, new TGLayoutHints(kLHintsRight, 5,5,3,4));
TGLabel * lbPol = new TGLabel(hframePol, "Polarity");
hframePol->AddFrame(lbPol, new TGLayoutHints(kLHintsRight | kLHintsCenterY, 5, 5, 3, 4));
///----- all other
TGHorizontalFrame *hframe[NUM_CHANNEL_SETTING];
TGLabel * lb[NUM_CHANNEL_SETTING];
for( int i = 0 ; i < NUM_CHANNEL_SETTING; i++){
hframe[i] = new TGHorizontalFrame(vframe, 50, 50 );
vframe->AddFrame(hframe[i], new TGLayoutHints(kLHintsRight, 2,2,2,2));
///----------- Trace on/off
if(settingName[i][0] == "TAU"){
TGHorizontalFrame *hframeTraceOnOff = new TGHorizontalFrame(vframe, 50, 50 );
vframe->AddFrame(hframeTraceOnOff, new TGLayoutHints(kLHintsRight, 2,2,2,2));
cbTraceOnOff = new TGComboBox(hframeTraceOnOff);
cbTraceOnOff->AddEntry("On", 1);
cbTraceOnOff->AddEntry("Off", 0);
cbTraceOnOff->Resize(width, 20);
//pixie->GetChannelTraceOnOff(boardID, ch) ? cbTraceOnOff->Select(1) : cbTraceOnOff->Select(0);
cbTraceOnOff->Connect("Selected(Int_t, Int_t)", "ChannelSetting", this, "ChangeOnOff()");
hframeTraceOnOff->AddFrame(cbTraceOnOff, new TGLayoutHints(kLHintsRight, 5,5,3,4));
TGLabel * lbTraceOnOff = new TGLabel(hframeTraceOnOff, "Trace On/Off");
hframeTraceOnOff->AddFrame(lbTraceOnOff, new TGLayoutHints(kLHintsRight | kLHintsCenterY, 5, 5, 3, 4));
}
double temp = 0; // pixie->GetChannelSetting(settingName[i][0].Data(), boardID, ch, false);
TGNumberFormat::EStyle digi = TGNumberFormat::kNESInteger;
if( settingName[i][1] == "0" ) digi = TGNumberFormat::kNESInteger;
if( settingName[i][1] == "1" ) digi = TGNumberFormat::kNESRealOne;
if( settingName[i][1] == "2" ) digi = TGNumberFormat::kNESRealTwo;
if( settingName[i][1] == "3" ) digi = TGNumberFormat::kNESRealThree;
entry[i] = new TGNumberEntry(hframe[i], temp, 0, 0, digi, TGNumberFormat::kNEANonNegative);
entry[i]->Resize(width, 20);
if( i >= NUM_CHANNEL_SETTING - 3 ) {
entry[i]->SetState(false);
}else{
entry[i]->Connect("Modified()", "ChannelSetting", this, Form("ChangeID(=%d)", i));
}
hframe[i]->AddFrame(entry[i], new TGLayoutHints(kLHintsRight, 5,5,3,4));
lb[i] = new TGLabel(hframe[i], settingName[i][0] + (settingName[i][2] != "" ? " [" + settingName[i][2] + "]" : ""));
hframe[i]->AddFrame(lb[i], new TGLayoutHints(kLHintsRight | kLHintsCenterY, 5, 5, 3, 4));
}
fMain->MapSubwindows();
fMain->Resize(fMain->GetDefaultSize());
fMain->MapWindow();
isOpened = true;
}
ChannelSetting::~ChannelSetting(){
isOpened = false;
delete boardIDEntry;
delete cbOnOff;
delete cbTraceOnOff;
delete cbPolarity;
for ( int i = 0; i < NUM_CHANNEL_SETTING; i++){
delete entry[i];
}
/// fMain must be delete last;
fMain->Cleanup();
delete fMain;
}
void ChannelSetting::ChangeBoard(){
ChangeCh();
}
void ChannelSetting::ChangeCh(){
int boardID = boardIDEntry->GetNumber();
int ch = chIDEntry->GetNumber();
//pixie->GetChannelOnOff(boardID, ch) ? cbOnOff->Select(1) : cbOnOff->Select(0);
//pixie->GetChannelPolarity(boardID, ch) ? cbPolarity->Select(1) : cbPolarity->Select(0);
//pixie->GetChannelTraceOnOff(boardID, ch) ? cbTraceOnOff->Select(1) : cbTraceOnOff->Select(0);
for( int i = 0 ; i < NUM_CHANNEL_SETTING; i++){
double temp = 0 ;//pixie->GetChannelSetting(settingName[i][0].Data(), boardID, ch, false);
entry[i]->SetNumber(temp );
}
}
void ChannelSetting::ChangeOnOff(){
short boardID = boardIDEntry->GetNumber();
short ch = chIDEntry->GetNumber();
int val = cbOnOff->GetSelected();
//pixie->SetChannelOnOff(val, boardID, ch);
//pixie->SaveSettings(pixie->GetSettingFile(boardIDEntry->GetNumber()));
}
void ChannelSetting::ChangePolarity(){
short boardID = boardIDEntry->GetNumber();
short ch = chIDEntry->GetNumber();
int val = cbPolarity->GetSelected();
//pixie->SetChannelPositivePolarity(val, boardID, ch);
//pixie->SaveSettings(pixie->GetSettingFile(boardIDEntry->GetNumber()));
}
void ChannelSetting::ChangeTraceOnOff(){
short boardID = boardIDEntry->GetNumber();
short ch = chIDEntry->GetNumber();
int val = cbTraceOnOff->GetSelected();
//pixie->SetChannelTraceOnOff(val, boardID, ch);
//pixie->SaveSettings(pixie->GetSettingFile(boardIDEntry->GetNumber()));
}
void ChannelSetting::ChangeID(int id){
short boardID = boardIDEntry->GetNumber();
short ch = chIDEntry->GetNumber();
double val = entry[id]->GetNumber();
//pixie->SetChannelSetting(settingName[id][0].Data(), val, boardID, ch, 1);
//pixie->SaveSettings(pixie->GetSettingFile(boardIDEntry->GetNumber()));
}