2023-06-02 15:41:26 -04:00
|
|
|
#ifndef SINGLE_SPECTR_H
|
|
|
|
#define SINGLE_SPECTR_H
|
2023-05-17 17:40:32 -04:00
|
|
|
|
|
|
|
#include <QMainWindow>
|
|
|
|
#include <QChart>
|
|
|
|
#include <QChartView>
|
|
|
|
#include <QLabel>
|
|
|
|
#include <QPushButton>
|
|
|
|
#include <QCheckBox>
|
|
|
|
#include <QLineEdit>
|
|
|
|
#include <QGridLayout>
|
|
|
|
#include <QGroupBox>
|
2024-04-05 22:33:05 -04:00
|
|
|
#include <QVector>
|
|
|
|
#include <QRandomGenerator>
|
2023-05-17 17:40:32 -04:00
|
|
|
|
|
|
|
#include "macro.h"
|
|
|
|
#include "ClassDigitizer.h"
|
|
|
|
#include "CustomThreads.h"
|
|
|
|
#include "CustomWidgets.h"
|
2023-06-02 18:13:47 -04:00
|
|
|
#include "Histogram1D.h"
|
2023-11-06 17:46:43 -05:00
|
|
|
#include "Histogram2D.h"
|
2023-05-17 17:40:32 -04:00
|
|
|
|
2024-08-28 16:45:23 -04:00
|
|
|
class HistWorker; //Forward decalration
|
2023-05-17 17:40:32 -04:00
|
|
|
|
|
|
|
//^====================================================
|
|
|
|
//^====================================================
|
2023-06-02 15:41:26 -04:00
|
|
|
class SingleSpectra : public QMainWindow{
|
2023-05-17 17:40:32 -04:00
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2023-06-02 15:41:26 -04:00
|
|
|
SingleSpectra(Digitizer ** digi, unsigned int nDigi, QString rawDataPath, QMainWindow * parent = nullptr);
|
|
|
|
~SingleSpectra();
|
|
|
|
|
2023-08-16 17:54:35 -04:00
|
|
|
void ClearInternalDataCount();
|
2024-08-28 16:45:23 -04:00
|
|
|
// void SetFillHistograms(bool onOff) { fillHistograms = onOff;}
|
|
|
|
// bool IsFillHistograms() const {return fillHistograms;}
|
2023-06-02 15:41:26 -04:00
|
|
|
|
|
|
|
void LoadSetting();
|
|
|
|
void SaveSetting();
|
2023-05-17 17:40:32 -04:00
|
|
|
|
2024-03-22 12:43:17 -04:00
|
|
|
void SetMaxFillTime(unsigned short milliSec) { maxFillTimeinMilliSec = milliSec;}
|
|
|
|
unsigned short GetMaxFillTime() const {return maxFillTimeinMilliSec;};
|
|
|
|
|
2024-04-05 22:33:05 -04:00
|
|
|
QVector<int> generateNonRepeatedCombination(int size);
|
|
|
|
|
2023-05-17 17:40:32 -04:00
|
|
|
|
2024-08-28 16:45:23 -04:00
|
|
|
/// This should be private....
|
|
|
|
int lastFilledIndex[MaxNDigitizer][MaxNChannels];
|
|
|
|
int loopFilledIndex[MaxNDigitizer][MaxNChannels];
|
|
|
|
bool histVisibility[MaxNDigitizer][MaxNChannels];
|
|
|
|
bool hist2DVisibility[MaxNDigitizer];
|
|
|
|
unsigned short maxFillTimePerDigi;
|
|
|
|
|
|
|
|
bool isFillingHistograms;
|
|
|
|
Histogram1D * hist[MaxNDigitizer][MaxNChannels];
|
|
|
|
Histogram2D * hist2D[MaxNDigitizer];
|
2023-05-17 17:40:32 -04:00
|
|
|
|
|
|
|
Digitizer ** digi;
|
|
|
|
unsigned short nDigi;
|
|
|
|
|
2024-08-28 16:45:23 -04:00
|
|
|
void startWork(){
|
|
|
|
printf("timer start\n");
|
|
|
|
timer->start(maxFillTimeinMilliSec);
|
|
|
|
}
|
|
|
|
void stopWork(){
|
|
|
|
printf("timer stop\n");
|
|
|
|
timer->stop();
|
|
|
|
ClearInternalDataCount();
|
|
|
|
}
|
|
|
|
|
|
|
|
QCheckBox * chkIsFillHistogram;
|
|
|
|
|
|
|
|
public slots:
|
|
|
|
// void FillHistograms();
|
|
|
|
void ChangeHistView();
|
|
|
|
|
|
|
|
private:
|
2023-11-06 17:46:43 -05:00
|
|
|
|
2023-05-19 16:23:04 -04:00
|
|
|
|
|
|
|
RComboBox * cbDivision;
|
|
|
|
|
|
|
|
RComboBox * cbDigi;
|
|
|
|
RComboBox * cbCh;
|
|
|
|
|
|
|
|
QGroupBox * histBox;
|
|
|
|
QGridLayout * histLayout;
|
|
|
|
int oldBd, oldCh;
|
2023-05-17 17:40:32 -04:00
|
|
|
|
2024-06-17 17:44:31 -04:00
|
|
|
QString settingPath;
|
2023-06-02 15:41:26 -04:00
|
|
|
|
2024-03-22 12:43:17 -04:00
|
|
|
unsigned short maxFillTimeinMilliSec;
|
|
|
|
|
2023-10-26 17:57:06 -04:00
|
|
|
bool isSignalSlotActive;
|
|
|
|
|
2024-08-28 16:45:23 -04:00
|
|
|
QThread * workerThread;
|
|
|
|
HistWorker * histWorker;
|
|
|
|
QTimer * timer;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
//^#======================================================== HistWorker
|
|
|
|
class HistWorker : public QObject{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
HistWorker(SingleSpectra * parent): SS(parent){}
|
|
|
|
|
|
|
|
public slots:
|
|
|
|
void FillHistograms(){
|
|
|
|
|
|
|
|
// printf("%s | %d %d \n", __func__, SS->chkIsFillHistogram->checkState(), SS->isFillingHistograms);
|
|
|
|
if( SS->chkIsFillHistogram->checkState() == Qt::Unchecked ) return;
|
|
|
|
if( SS->isFillingHistograms) return;
|
|
|
|
|
|
|
|
SS->isFillingHistograms = true;
|
|
|
|
timespec t0, t1;
|
|
|
|
|
|
|
|
QVector<int> randomDigiList = SS->generateNonRepeatedCombination(SS->nDigi);
|
|
|
|
|
|
|
|
// qDebug() << randomDigiList;
|
|
|
|
|
|
|
|
for( int i = 0; i < SS->nDigi; i++){
|
|
|
|
int ID = randomDigiList[i];
|
|
|
|
|
|
|
|
QVector<int> randomChList = SS->generateNonRepeatedCombination(SS->digi[ID]->GetNumInputCh());
|
|
|
|
|
|
|
|
// qDebug() << randomChList;
|
|
|
|
// digiMTX[ID].lock();
|
|
|
|
// digi[ID]->GetData()->PrintAllData();
|
|
|
|
|
|
|
|
clock_gettime(CLOCK_REALTIME, &t0);
|
|
|
|
for( int k = 0; k < SS->digi[ID]->GetNumInputCh(); k ++ ){
|
|
|
|
int ch = randomChList[k];
|
|
|
|
int lastIndex = SS->digi[ID]->GetData()->GetDataIndex(ch);
|
|
|
|
if( lastIndex < 0 ) continue;
|
|
|
|
printf("--- ch %2d | last index %d \n", ch, lastIndex);
|
|
|
|
|
|
|
|
int loopIndex = SS->digi[ID]->GetData()->GetLoopIndex(ch);
|
|
|
|
|
|
|
|
int temp1 = lastIndex + loopIndex * SS->digi[ID]->GetData()->GetDataSize();
|
|
|
|
int temp2 = SS->lastFilledIndex[ID][ch] + SS->loopFilledIndex[ID][ch] * SS->digi[ID]->GetData()->GetDataSize() + 1;
|
|
|
|
|
|
|
|
// printf("loopIndx : %d | ID now : %d, ID old : %d \n", loopIndex, temp1, temp2);
|
|
|
|
|
|
|
|
if( temp1 <= temp2 ) continue;
|
|
|
|
|
|
|
|
if( temp1 - temp2 > SS->digi[ID]->GetData()->GetDataSize() ) { //DefaultDataSize = 10k
|
|
|
|
temp2 = temp1 - SS->digi[ID]->GetData()->GetDataSize();
|
|
|
|
SS->lastFilledIndex[ID][ch] = lastIndex;
|
|
|
|
SS->lastFilledIndex[ID][ch] = loopIndex - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// printf("ch %d | regulated ID now %d new %d | last fill idx %d\n", ch, temp2, temp1, lastFilledIndex[ID][ch]);
|
|
|
|
|
|
|
|
for( int j = 0 ; j <= temp1 - temp2; j ++){
|
|
|
|
SS->lastFilledIndex[ID][ch] ++;
|
|
|
|
if( SS->lastFilledIndex[ID][ch] > SS->digi[ID]->GetData()->GetDataSize() ) {
|
|
|
|
SS->lastFilledIndex[ID][ch] = 0;
|
|
|
|
SS->loopFilledIndex[ID][ch] ++;
|
|
|
|
}
|
|
|
|
|
|
|
|
uShort data = SS->digi[ID]->GetData()->GetEnergy(ch, SS->lastFilledIndex[ID][ch]);
|
|
|
|
|
|
|
|
// printf(" ch: %d, last fill idx : %d | %d \n", ch, lastFilledIndex[ID][ch], data);
|
|
|
|
|
|
|
|
SS->hist[ID][ch]->Fill( data );
|
|
|
|
if( SS->digi[i]->GetDPPType() == DPPTypeCode::DPP_PSD_CODE ){
|
|
|
|
uShort e2 = SS->digi[ID]->GetData()->GetEnergy2(ch, SS->lastFilledIndex[ID][ch]);
|
|
|
|
// printf("%u \n", e2);
|
|
|
|
SS->hist[ID][ch]->Fill( e2, 1);
|
|
|
|
}
|
|
|
|
SS->hist2D[ID]->Fill(ch, data);
|
|
|
|
}
|
|
|
|
if( SS->histVisibility[ID][ch] ) SS->hist[ID][ch]->UpdatePlot();
|
|
|
|
|
|
|
|
clock_gettime(CLOCK_REALTIME, &t1);
|
|
|
|
if( t1.tv_nsec - t0.tv_nsec + (t1.tv_sec - t0.tv_sec)*1e9 > SS->maxFillTimePerDigi * 1e6 ) break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( SS->hist2DVisibility[ID] ) SS->hist2D[ID]->UpdatePlot();
|
|
|
|
// digiMTX[ID].unlock();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
SS->isFillingHistograms = false;
|
|
|
|
emit workDone();
|
|
|
|
}
|
|
|
|
|
|
|
|
signals:
|
|
|
|
void workDone();
|
|
|
|
|
|
|
|
private:
|
|
|
|
SingleSpectra * SS;
|
2023-05-17 17:40:32 -04:00
|
|
|
};
|
2024-08-28 16:45:23 -04:00
|
|
|
|
2023-05-17 17:40:32 -04:00
|
|
|
#endif
|