some improvements

This commit is contained in:
carina@hades 2022-10-26 14:55:06 -04:00
parent b1b3402227
commit f713efbc41
12 changed files with 181 additions and 114 deletions

View File

@ -101,7 +101,7 @@ inline Data::Data(){
ch2ns = 2.0;
boardSN = 0;
DPPType = V1730_DPP_PHA_CODE;
IsNotRollOverFakeAgg = true;
IsNotRollOverFakeAgg = false;
buffer = NULL;
for ( int i = 0; i < MaxNChannels; i++) TotNumEvents[i] = 0;
ClearData();
@ -136,7 +136,7 @@ inline void Data::ClearTriggerRate(){
inline void Data::ClearData(){
nByte = 0;
AllocatedSize = 0;
IsNotRollOverFakeAgg = true;
IsNotRollOverFakeAgg = false;
for( int i = 0 ; i < MaxNChannels; i++){
NumEvents[i] = 0;
firstTimestamp[0] = -1;
@ -196,7 +196,7 @@ inline void Data::SaveBuffer(const char * fileName){
inline void Data::PrintStat() const{
if( IsNotRollOverFakeAgg ) {
if( !IsNotRollOverFakeAgg ) {
printf(" this is roll-over fake event or no events.\n");
return;
}
@ -267,9 +267,11 @@ inline void Data::DecodeBuffer(bool fastDecode, int verbose){
nw = nw + 1; word = ReadBuffer(nw, verbose);
unsigned int BoardID = ((word >> 27) & 0x1F);
unsigned short pattern = ((word >> 8 ) & 0x7FFF );
bool BoardFailFlag = ((word >> 26) & 0x1 );
unsigned int ChannelMask = ( word & 0xFF ) ;
if( verbose >= 1 ) printf("Board ID(type) : %d, FailFlag = %d, ChannelMask = 0x%X\n", BoardID, BoardFailFlag, ChannelMask);
if( verbose >= 1 ) printf("Board ID(type) : %d, FailFlag = %d, Patten = %u, ChannelMask = 0x%X\n",
BoardID, BoardFailFlag, pattern, ChannelMask);
if( BoardID > 0 ) {
switch(BoardID){
@ -278,9 +280,13 @@ inline void Data::DecodeBuffer(bool fastDecode, int verbose){
}
}
nw = nw + 2;
unsigned int AggCounter = ReadBuffer(nw, verbose);
if( verbose >= 2 ) printf("Agg Counter : %u \n", AggCounter);
nw = nw + 1;
unsigned int bdAggCounter = ReadBuffer(nw, verbose);
if( verbose >= 1 ) printf("Board Agg Counter : %u \n", bdAggCounter & 0x7FFFFF);
nw = nw + 1;
unsigned int bdAggTimeTag = ReadBuffer(nw, verbose);
if( verbose >= 2 ) printf("Agg Counter : %u \n", bdAggTimeTag);
for( int chMask = 0; chMask < MaxNChannels/2 ; chMask ++ ){
if( ((ChannelMask >> chMask) & 0x1 ) == 0 ) continue;
@ -304,7 +310,7 @@ inline void Data::DecodeBuffer(bool fastDecode, int verbose){
///Calculate trigger rate and first and last Timestamp
for(int ch = 0; ch < MaxNChannels; ch++){
if( NumEventsDecoded[ch] > 0 ) IsNotRollOverFakeAgg = false;
if( NumEventsDecoded[ch] > 0 ) IsNotRollOverFakeAgg = true;
unsigned long long dTime = Timestamp[ch][NumEvents[ch]-1] - Timestamp[ch][NumEvents[ch] - NumEventsDecoded[ch]];
double sec = dTime * ch2ns / 1e9;
TriggerRate[ch] = NumEventsDecoded[ch]/sec;

View File

@ -220,7 +220,7 @@ int main(int argc, char **argv) {
if( debug) printf("---------- event built : %llu \n", evID);
if( countBdAgg > 74) break;
//if( countBdAgg > 74) break;
}while(!feof(haha) && ftell(haha) < inFileSize);
@ -250,6 +250,7 @@ void EventBuilder(Data * data, const unsigned int timeWin, bool traceOn, bool is
unsigned long long firstTimeStamp = -1;
unsigned long long lastTimeStamp = 0;
unsigned long long smallestLastTimeStamp = -1;
unsigned int maxNumEvent = 0;
for( int chI = 0; chI < MaxNChannels ; chI ++){
if( data->NumEvents[chI] == 0 ) continue;
@ -260,15 +261,18 @@ void EventBuilder(Data * data, const unsigned int timeWin, bool traceOn, bool is
if( data->Timestamp[chI][ev] > lastTimeStamp ) {
lastTimeStamp = data->Timestamp[chI][ev];
}
if( ev + 1 > maxNumEvent ) maxNumEvent = ev + 1;
if( data->Timestamp[chI][ev] < smallestLastTimeStamp ){
smallestLastTimeStamp = data->Timestamp[chI][ev];
}
}
if( maxNumEvent == 0 ) return;
if( verbose) printf("================ time range : %llu - %llu, smallest Last %llu\n", firstTimeStamp, lastTimeStamp, smallestLastTimeStamp );
unsigned short lastEv[MaxNChannels] = {0}; /// store the last event number for each ch
unsigned short exhaustedCh = 0; /// to stop
bool breakFlag = false;
unsigned short exhaustedCh = 0; /// when exhaustedCh == MaxNChannels ==> stop
bool singleChannelExhaustedFlag = false; /// when a single ch has data but exhaused ==> stop
do {
@ -283,7 +287,7 @@ void EventBuilder(Data * data, const unsigned int timeWin, bool traceOn, bool is
ch1st = chI;
}
}
if( !isLastData && ((smallestLastTimeStamp - time1st) < NTimeWinForBuffer * timeWin) ) break;
if( !isLastData && ((smallestLastTimeStamp - time1st) < NTimeWinForBuffer * timeWin) && maxNumEvent < MaxNData * 0.6 ) break;
if( ch1st > MaxNChannels ) break;
multi ++;
@ -307,6 +311,7 @@ void EventBuilder(Data * data, const unsigned int timeWin, bool traceOn, bool is
/// build the rest of the event
exhaustedCh = 0;
singleChannelExhaustedFlag = false;
for( int chI = ch1st; chI < ch1st + MaxNChannels; chI ++){
unsigned short chX = chI % MaxNChannels;
if( data->NumEvents[chX] == 0 ) {
@ -315,6 +320,7 @@ void EventBuilder(Data * data, const unsigned int timeWin, bool traceOn, bool is
}
if( data->NumEvents[chX] <= lastEv[chX] ) {
exhaustedCh ++;
singleChannelExhaustedFlag = true;
continue;
}
if( timeWin == 0 ) continue;
@ -359,16 +365,7 @@ void EventBuilder(Data * data, const unsigned int timeWin, bool traceOn, bool is
evID++;
multi = 0;
/// Check Last event break;
breakFlag = false;
for( int chI = 0; chI < MaxNChannels ; chI++){
if( lastEv[chI] == 0 ) continue;
if( lastEv[chI] >= data->NumEvents[chI] ) {
breakFlag = true;
break;
}
}
}while( !breakFlag || (exhaustedCh < MaxNChannels) );
}while( !singleChannelExhaustedFlag || (exhaustedCh < MaxNChannels) );
///========== clear built data
/// move the last data to the top,

View File

@ -19,30 +19,6 @@
#include "FSUDAQ.h"
enum MenuIdentifiers{
M_DIGITIZER_OPEN,
M_FILE_OPEN,
M_EXIT,
M_LOAD_SETTINGS,
M_TRIGGER_SUMMARY,
M_CH_SETTING_PHA,
M_CH_SETTING_PSD,
M_REGISTER_SETTING,
M_BOARD_SETTINGS,
M_PROGRAM_SETTINGS,
M_FINDPEAKS
};
enum ModeIdentifiers{
Mode_EnergyHist,
Mode_CountHist,
Mode_Oscilloscope,
Mode_DataRun
};
long get_time(){
long time_ms;
struct timeval t1;
@ -52,6 +28,20 @@ long get_time(){
return time_ms;
}
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;
}
///============= Global variable
TH1F * hEnergy[MaxNBoards][MaxNChannels] = {NULL};
TH1F * hChannel[MaxNBoards] = {NULL};
@ -77,6 +67,29 @@ TGNumberEntry * MainWindow::runIDEntry = NULL;
BoardSetting * MainWindow::boardSetting = NULL;
enum MenuIdentifiers{
M_DIGITIZER_OPEN,
M_FILE_OPEN,
M_EXIT,
M_LOAD_SETTINGS,
M_TRIGGER_SUMMARY,
M_CH_SETTING_PHA,
M_CH_SETTING_PSD,
M_REGISTER_SETTING,
M_BOARD_SETTINGS,
M_PROGRAM_SETTINGS,
M_FINDPEAKS
};
enum ModeIdentifiers{
Mode_EnergyHist,
Mode_CountHist,
Mode_Oscilloscope,
Mode_DataRun
};
MainWindow::MainWindow(const TGWindow *p,UInt_t w,UInt_t h) {
@ -236,7 +249,7 @@ MainWindow::MainWindow(const TGWindow *p,UInt_t w,UInt_t h) {
LogMsg((char*)"The LogMsg is not complete for all actions. [update later]");
LogMsg((char*)"Please \"Open Digitizers\" to start.");
//HandleMenu(M_DIGITIZER_OPEN);
HandleMenu(M_DIGITIZER_OPEN);
//HandleMenu(M_BOARD_SETTINGS);
//HandleMenu(M_CH_SETTING_PHA);
//HandleMenu(M_CH_SETTING_PSD);
@ -261,6 +274,7 @@ MainWindow::MainWindow(const TGWindow *p,UInt_t w,UInt_t h) {
}
MainWindow::~MainWindow() {
delete fMenuBar;
delete fMenuFile;
delete fMenuDigitizers;
@ -697,21 +711,6 @@ 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(){
printf("=== %s not impletement.\n", __func__);
@ -823,7 +822,12 @@ void * MainWindow::RunThread(void * ptr){
fEcanvas->GetCanvas()->cd();
///Fill trace
CurrentTime = get_time();
ElapsedTime = CurrentTime - PreviousTime; /// milliseconds
if( ElapsedTime > 500 ){
/// use the last trace
if( cbMode->GetSelected() == Mode_Oscilloscope && hasTrace){
unsigned short nData = data->NumEvents[ch];
@ -847,10 +851,6 @@ void * MainWindow::RunThread(void * ptr){
}
}
CurrentTime = get_time();
ElapsedTime = CurrentTime - PreviousTime; /// milliseconds
if( ElapsedTime > 500 ){
///Fill Channel Count
for( int i = 0 ; i < digi[boardID]->GetNChannel(); i++){
@ -886,15 +886,7 @@ int main(int argc, char **argv) {
new MainWindow(gClient->GetRoot(),800,800);
theApp.Run();
delete gAnaTrace1;
delete gAnaTrace2;
delete gDigiTrace1;
delete gDigiTrace2;
for( int i = 0; i < MaxNBoards; i++){
delete hChannel[i];
for( int j = 0; j < MaxNChannels; j++) delete hEnergy[i][j];
}
printf("------ see you next time :) ------ \n");
return 0;
}

View File

@ -775,8 +775,17 @@ BoardSetting::~BoardSetting(){
printf("close BoardSetting window\n");
/// this is essential to delete any TGNumberEntry, when the focu on it and close the windows --> crash.
delete numAggBLT;
delete numRunStartStopDelay;
delete numMajorCoinWin;
delete numBufferOccpGain;
//delete numExtendVetoDelay;
for( int i = 0; i < 8; i++) delete TRGValMajorLevel[i];
delete TRGOUTMajorLevel;
delete GlbMajorLevel;
delete boardIDEntry;
for(int i = 0; i < NUM_BOARD_INFO; i++) delete entry[i];
fMain->Cleanup();
delete fMain;

View File

@ -92,7 +92,7 @@ class BoardSetting{
//TGCheckButton * bTRGValMskLVSDGLB;
//TGCheckButton * bTRGValMskLVSDLCL;
TGCheckButton * bEnableExtTRG;
TGNumberEntry * numExtendVetoDelay;
//TGNumberEntry * numExtendVetoDelay;
/// Trigger Validation Mask
TGCheckButton * cbTRGValMskCh[8][8];

View File

@ -209,6 +209,13 @@ ChannelSettingPHA::ChannelSettingPHA(const TGWindow *p, UInt_t w, UInt_t h, int
cbTriggerMode->AddEntry("Anti-Coin.", 3);
cbTriggerMode->Resize(width, 20);
cbTriggerMode->Connect("Changed()", "ChannelSettingPHA", this, "SetDPPAlgorithm1()");
/// ShapedTriggerWidth = 0x1084 /// R/W
TGLabel * lbShapeTrigWidth = new TGLabel(vfTrigger1, "Shaped Trigger Width [ns]"); vfTrigger1->AddFrame(lbShapeTrigWidth, layoutHintsR);
numShapedTriggerWidth = new TGNumberEntry(vfTrigger2, 20, 0, 0, TGNumberFormat::kNESInteger, TGNumberFormat::kNEANonNegative); vfTrigger2->AddFrame(numShapedTriggerWidth, layoutHints);
numShapedTriggerWidth->Resize(width, 20);
numShapedTriggerWidth->Connect("Modified()", "ChannelSettingPHA", this, "SetShaperTriggerWidth()");
}
{///================== Trapezoid Settings
@ -475,6 +482,7 @@ ChannelSettingPHA::~ChannelSettingPHA(){
delete numInputRiseTime;
delete numRiseTimeValidWin;
delete cbTriggerMode;
delete numShapedTriggerWidth;
delete numTrapRiseTime;
delete numTrapFlatTop;
@ -602,6 +610,7 @@ void ChannelSettingPHA::ChangeCh(){
cbTriggerSmoothing ->Select( digi[boardID]->GetSettingFromMemory(Register::DPP::PHA::RCCR2SmoothingFactor, ch), false);
numInputRiseTime ->SetNumber( digi[boardID]->GetSettingFromMemory(Register::DPP::PHA::InputRiseTime, ch) * 4 * ch2ns, false);
numRiseTimeValidWin->SetNumber( digi[boardID]->GetSettingFromMemory(Register::DPP::PHA::RiseTimeValidationWindow, ch) * ch2ns, false);
numShapedTriggerWidth->SetNumber( digi[boardID]->GetSettingFromMemory(Register::DPP::PHA::ShapedTriggerWidth, ch) * ch2ns, false);
numTrapRiseTime->SetNumber( digi[boardID]->GetSettingFromMemory(Register::DPP::PHA::TrapezoidRiseTime, ch) * 4 * ch2ns, false);
numTrapFlatTop->SetNumber( digi[boardID]->GetSettingFromMemory(Register::DPP::PHA::TrapezoidFlatTop, ch) * 4 * ch2ns, false);
@ -763,12 +772,13 @@ void ChannelSettingPHA::SetRecordLength() {printf("=== %s\n", __func__); Chan
void ChannelSettingPHA::SetPreTrigger() {printf("=== %s\n", __func__); ChangeAStep(numPreTrigger, 4, Register::DPP::PreTrigger);}
void ChannelSettingPHA::SetTriggerHoldOff() {printf("=== %s\n", __func__); ChangeAStep(numTriggerHoldOff, 4, Register::DPP::PHA::TriggerHoldOffWidth);}
void ChannelSettingPHA::SetInputRiseTime() {printf("=== %s\n", __func__); ChangeAStep(numInputRiseTime, 4, Register::DPP::PHA::InputRiseTime);}
void ChannelSettingPHA::SetRiseTimeValidWin(){printf("=== %s\n", __func__); ChangeAStep(numRiseTimeValidWin, 1, Register::DPP::PHA::RiseTimeValidationWindow);}
void ChannelSettingPHA::SetRiseTimeValidWin() {printf("=== %s\n", __func__); ChangeAStep(numRiseTimeValidWin, 1, Register::DPP::PHA::RiseTimeValidationWindow);}
void ChannelSettingPHA::SetTrapRiseTime() {printf("=== %s\n", __func__); ChangeAStep(numTrapRiseTime, 4, Register::DPP::PHA::TrapezoidRiseTime);}
void ChannelSettingPHA::SetTrapFlatTop() {printf("=== %s\n", __func__); ChangeAStep(numTrapFlatTop, 4, Register::DPP::PHA::TrapezoidFlatTop);}
void ChannelSettingPHA::SetDecay() {printf("=== %s\n", __func__); ChangeAStep(numDecay, 4, Register::DPP::PHA::DecayTime);}
void ChannelSettingPHA::SetPeaking() {printf("=== %s\n", __func__); ChangeAStep(numPeaking, 4, Register::DPP::PHA::PeakingTime);}
void ChannelSettingPHA::SetPeakHoldOff() {printf("=== %s\n", __func__); ChangeAStep(numPeakHoldOff, 4, Register::DPP::PHA::PeakHoldOff);}
void ChannelSettingPHA::SetShaperTriggerWidth() {printf("=== %s\n", __func__); ChangeAStep(numShapedTriggerWidth, 4, Register::DPP::PHA::ShapedTriggerWidth);}
void ChannelSettingPHA::SetEventAggregate() {
printf("=== %s\n", __func__);

View File

@ -41,6 +41,7 @@ class ChannelSettingPHA{
TGNumberEntry * numInputRiseTime;
TGNumberEntry * numRiseTimeValidWin;
TGComboBox * cbTriggerMode;
TGNumberEntry * numShapedTriggerWidth;
TGNumberEntry * numTrapRiseTime;
TGNumberEntry * numTrapFlatTop;
@ -105,6 +106,7 @@ class ChannelSettingPHA{
void SetTriggerSmoothing();
void SetInputRiseTime();
void SetRiseTimeValidWin();
void SetShaperTriggerWidth();
void SetTrapRiseTime();
void SetTrapFlatTop();

View File

@ -472,10 +472,62 @@ ChannelSettingPSD::~ChannelSettingPSD(){
isOpened = false;
delete boardIDEntry;
delete chIDEntry;
delete eTemp ;
delete cbOnOff;
delete cbInputDynamicRange;
delete cbPolarity;
delete cbInputDynamicRange;
delete numRecordLength;
delete numPreTrigger;
delete numEventAgg;
delete numTriggerThreshold;
delete numTriggerHoldOff;
delete numlbChargeZeroSupThreshold;
delete numTrigLatency;
delete numDCOffset;
delete numThresholdPSDCut;
delete numPURGAPThreshold;
delete cbTriggerMode;
delete numCFDDelay;
delete cbCFDFraction;
delete cbCFDInterPt;
delete numShortGateWidth;
delete numLongGateWidth;
delete numGateOffset;
delete numFixBaseline;
delete cbBaseLineAvg;
delete cbChargeSensitivity;
delete cbChargePedestal;
delete cbTriggerCount;
delete cbDiscrimationMode;
delete cbPileUpGate;
delete cbPileUp;
delete cbTestPulseRate;
delete cbBaselineLongGate;
delete cbDiscardQlongQthr;
delete cbOverRange;
delete cbTrigHysteresis;
delete cbInhibitOppostieParity;
delete cbLocalShapedTrigger;
delete cbLocalTriggerValid;
delete cbAddLocalTriggerValid;
delete cbVetoSource;
delete cbInputSmoothinFactor;
delete cbTriggerCounterRate;
delete cbMarkSaturatedPulse;
delete cbVetoMode;
delete cbResetTimeStamp;
delete cbDisableSelfTrigger;
delete cbExtraWordOption;
/// fMain must be delete last;
fMain->Cleanup();

View File

@ -75,7 +75,7 @@ class ChannelSettingPSD{
TGComboBox * cbDisableSelfTrigger;
TGComboBox * cbExtraWordOption;
int NChannel; // hard coded = 16
int NChannel; /// hard coded = 16 when no digitizer
bool isOpened;
int presentBoardID;

View File

@ -64,6 +64,7 @@ ProgramSetting::~ProgramSetting(){
delete txtIP;
delete txtDBName;
delete txtDataPath;
fMain->Cleanup();
delete fMain;

View File

@ -21,7 +21,6 @@ class RegisterSetting{
TGMainFrame * fMain;
TGNumberEntry * boardIDEntry;
TGTextEntry * txtAddress;
TGComboBox * cbName;

View File

@ -113,7 +113,6 @@ TriggerSummary::~TriggerSummary(){
delete numUpdateTime;
updateFlag = false;
thread->Join();
///delete thread; /// Don;t delete the thread, otherwise, thread will not run after close and reopen.