2023-06-02 15:41:26 -04:00
|
|
|
#include "Analyser.h"
|
2023-05-26 18:06:37 -04:00
|
|
|
|
|
|
|
#include <QRandomGenerator>
|
|
|
|
#include <random>
|
|
|
|
|
2023-06-02 15:41:26 -04:00
|
|
|
Analyzer::Analyzer(Digitizer ** digi, unsigned int nDigi, QMainWindow * parent ): QMainWindow(parent){
|
2023-05-26 18:06:37 -04:00
|
|
|
|
|
|
|
this->digi = digi;
|
|
|
|
this->nDigi = nDigi;
|
|
|
|
|
2023-06-12 15:45:16 -04:00
|
|
|
setWindowTitle("Online Analyzer");
|
|
|
|
setGeometry(0, 0, 1000, 800);
|
|
|
|
|
2023-05-26 18:06:37 -04:00
|
|
|
oeb = new OnlineEventBuilder * [nDigi];
|
|
|
|
for( unsigned int i = 0; i < nDigi; i++ ) oeb[i] = new OnlineEventBuilder(digi[i]);
|
|
|
|
|
|
|
|
buildTimerThread = new TimingThread(this);
|
|
|
|
buildTimerThread->SetWaitTimeinSec(1.0); //^Set event build interval
|
2023-06-02 15:41:26 -04:00
|
|
|
connect( buildTimerThread, &TimingThread::timeUp, this, &Analyzer::UpdateHistograms);
|
2023-05-26 18:06:37 -04:00
|
|
|
|
|
|
|
QWidget * layoutWidget = new QWidget(this);
|
|
|
|
setCentralWidget(layoutWidget);
|
|
|
|
layout = new QGridLayout(layoutWidget);
|
|
|
|
layoutWidget->setLayout(layout);
|
|
|
|
|
|
|
|
// QPushButton * bnSetting = new QPushButton("Settings", this);
|
|
|
|
// layout->addWidget(bnSetting);
|
|
|
|
|
|
|
|
SetUpCanvas();
|
|
|
|
}
|
|
|
|
|
2023-06-02 15:41:26 -04:00
|
|
|
Analyzer::~Analyzer(){
|
2023-05-26 18:06:37 -04:00
|
|
|
for( unsigned int i = 0; i < nDigi; i++ ) delete oeb[i];
|
|
|
|
delete [] oeb;
|
|
|
|
}
|
|
|
|
|
2023-06-02 15:41:26 -04:00
|
|
|
void Analyzer::StartThread(){
|
2023-06-12 15:45:16 -04:00
|
|
|
// printf("%s\n", __func__);
|
2023-06-09 13:51:02 -04:00
|
|
|
for( unsigned int i = 0; i < nDigi; i++) oeb[i]->ClearEvents();
|
2023-05-30 10:08:39 -04:00
|
|
|
buildTimerThread->start();
|
2023-05-26 18:06:37 -04:00
|
|
|
}
|
|
|
|
|
2023-06-02 15:41:26 -04:00
|
|
|
void Analyzer::StopThread(){
|
2023-06-12 15:45:16 -04:00
|
|
|
// printf("%s\n", __func__);
|
2023-05-30 10:08:39 -04:00
|
|
|
buildTimerThread->Stop();
|
|
|
|
buildTimerThread->quit();
|
|
|
|
buildTimerThread->wait();
|
2023-05-26 18:06:37 -04:00
|
|
|
}
|
|
|
|
|
2023-06-12 15:45:16 -04:00
|
|
|
//^####################################### below are open to customization
|
|
|
|
|
2023-06-02 15:41:26 -04:00
|
|
|
void Analyzer::SetUpCanvas(){
|
2023-05-26 18:06:37 -04:00
|
|
|
|
2023-06-02 18:13:47 -04:00
|
|
|
setGeometry(0, 0, 1600, 800);
|
|
|
|
|
2023-06-09 16:36:43 -04:00
|
|
|
h2 = new Histogram2D("testing", "x", "y", 400, 0, 10000, 400, 0, 10000, this);
|
2023-06-02 18:13:47 -04:00
|
|
|
layout->addWidget(h2, 0, 0);
|
2023-05-26 18:06:37 -04:00
|
|
|
|
2023-06-09 16:36:43 -04:00
|
|
|
h1 = new Histogram1D("testing", "x", 400, 0, 10000, this);
|
2023-06-02 18:13:47 -04:00
|
|
|
layout->addWidget(h1, 0, 1);
|
2023-05-30 10:08:39 -04:00
|
|
|
|
2023-05-26 18:06:37 -04:00
|
|
|
}
|
|
|
|
|
2023-06-02 15:41:26 -04:00
|
|
|
void Analyzer::UpdateHistograms(){
|
2023-05-26 18:06:37 -04:00
|
|
|
|
|
|
|
//Set with digitizer to be event build
|
|
|
|
digiMTX[0].lock();
|
2023-06-09 16:36:43 -04:00
|
|
|
oeb[0]->BuildEvents(100, false);
|
2023-05-26 18:06:37 -04:00
|
|
|
digiMTX[0].unlock();
|
|
|
|
|
2023-06-12 15:45:16 -04:00
|
|
|
//oeb[0]->PrintStat();
|
2023-06-09 16:36:43 -04:00
|
|
|
|
2023-05-26 18:06:37 -04:00
|
|
|
//============ Get events, and do analysis
|
2023-06-09 16:36:43 -04:00
|
|
|
long eventBuilt = oeb[0]->eventBuilt;
|
2023-05-30 10:08:39 -04:00
|
|
|
if( eventBuilt == 0 ) return;
|
|
|
|
|
|
|
|
long eventIndex = oeb[0]->eventIndex;
|
2023-05-26 18:06:37 -04:00
|
|
|
|
2023-05-30 10:08:39 -04:00
|
|
|
long eventStart = eventIndex - eventBuilt + 1;
|
|
|
|
if(eventStart < 0 ) eventStart += MaxNEvent;
|
|
|
|
|
|
|
|
unsigned short e1 = 0, e2 = 0;
|
|
|
|
|
|
|
|
for( long i = eventStart ; i <= eventIndex; i ++ ){
|
|
|
|
std::vector<dataPoint> event = oeb[0]->events[i];
|
|
|
|
|
|
|
|
for( int k = 0; k < (int) event.size(); k++ ){
|
2023-06-09 13:51:02 -04:00
|
|
|
if( event[k].ch == 9 ) e1 = event[k].energy;
|
|
|
|
if( event[k].ch == 10 ) e2 = event[k].energy;
|
2023-05-30 10:08:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
h2->Fill(e1, e2);
|
2023-06-09 13:51:02 -04:00
|
|
|
h1->Fill(e1);
|
2023-05-30 10:08:39 -04:00
|
|
|
}
|
2023-05-26 18:06:37 -04:00
|
|
|
|
2023-05-31 17:30:46 -04:00
|
|
|
h2->UpdatePlot();
|
2023-06-09 13:51:02 -04:00
|
|
|
h1->UpdatePlot();
|
|
|
|
|
|
|
|
h2->PrintCutEntry();
|
|
|
|
|
2023-05-31 17:30:46 -04:00
|
|
|
|
2023-05-26 18:06:37 -04:00
|
|
|
}
|