2023-11-16 19:20:29 -05:00
# ifndef COINCIDENTANLAYZER_H
# define COINCIDENTANLAYZER_H
# include "Analyser.h"
2024-06-28 15:08:58 -04:00
# include "FSUDAQ.h"
2023-11-16 19:20:29 -05:00
//^===========================================
class CoincidentAnalyzer : public Analyzer {
Q_OBJECT
public :
2024-06-28 15:08:58 -04:00
CoincidentAnalyzer ( Digitizer * * digi , unsigned int nDigi , QString rawDataPath , QMainWindow * parent = nullptr ) : Analyzer ( digi , nDigi , parent ) {
2023-11-16 19:20:29 -05:00
2024-06-28 15:08:58 -04:00
this - > rawDataPath = rawDataPath ;
2023-11-16 19:20:29 -05:00
SetUpdateTimeInSec ( 1.0 ) ;
//RedefineEventBuilder({0}); // only build for the 0-th digitizer, otherwise, it will build event accross all digitizers
SetBackwardBuild ( false , 100 ) ; // using normal building (acceding in time) or backward building, int the case of backward building, default events to be build is 100.
2024-08-29 15:47:07 -04:00
mb - > SetTimeWindow ( 500 ) ;
2023-11-16 19:20:29 -05:00
2023-11-21 16:50:22 -05:00
allowSignalSlot = false ;
2023-11-16 19:20:29 -05:00
SetUpCanvas ( ) ;
2023-11-21 16:50:22 -05:00
}
~ CoincidentAnalyzer ( ) {
2023-11-16 19:20:29 -05:00
}
void SetUpCanvas ( ) ;
public slots :
void UpdateHistograms ( ) ;
2024-10-22 16:38:01 -04:00
void ReplotHistograms ( ) ;
2023-11-16 19:20:29 -05:00
private :
2023-11-21 16:50:22 -05:00
bool allowSignalSlot ;
2024-08-26 15:25:19 -04:00
QLineEdit * leInfluxIP ;
QLineEdit * leDBName ;
2023-11-16 19:20:29 -05:00
// declaie histograms
Histogram2D * h2D ;
Histogram1D * h1 ;
Histogram1D * h1g ;
Histogram1D * hMulti ;
2023-11-17 16:47:11 -05:00
QCheckBox * chkRunAnalyzer ;
2023-11-16 19:20:29 -05:00
RSpinBox * sbUpdateTime ;
2023-11-17 16:47:11 -05:00
QCheckBox * chkBackWardBuilding ;
2023-11-16 19:20:29 -05:00
RSpinBox * sbBackwardCount ;
RSpinBox * sbBuildWindow ;
// data source for the h2D
RComboBox * xDigi ;
RComboBox * xCh ;
RComboBox * yDigi ;
RComboBox * yCh ;
// data source for the h1
RComboBox * aDigi ;
RComboBox * aCh ;
2024-06-28 15:08:58 -04:00
QString rawDataPath ;
2024-08-26 13:59:04 -04:00
void SaveSettings ( ) ;
void LoadSettings ( ) ;
2023-11-21 16:50:22 -05:00
2023-11-16 19:20:29 -05:00
} ;
inline void CoincidentAnalyzer : : SetUpCanvas ( ) {
2024-06-26 17:35:09 -04:00
setWindowTitle ( " Online Coincident Analyzer " ) ;
2023-11-16 19:20:29 -05:00
setGeometry ( 0 , 0 , 1600 , 1000 ) ;
2024-06-28 15:08:58 -04:00
{ //^====== channel settings
2023-11-16 19:20:29 -05:00
QGroupBox * box = new QGroupBox ( " Configuration " , this ) ;
layout - > addWidget ( box , 0 , 0 ) ;
QGridLayout * boxLayout = new QGridLayout ( box ) ;
boxLayout - > setAlignment ( Qt : : AlignTop | Qt : : AlignLeft ) ;
box - > setLayout ( boxLayout ) ;
2024-08-26 13:59:04 -04:00
int rowID = 0 ;
2023-11-21 16:50:22 -05:00
{
chkRunAnalyzer = new QCheckBox ( " Run Analyzer " , this ) ;
2024-08-26 13:59:04 -04:00
boxLayout - > addWidget ( chkRunAnalyzer , rowID , 0 ) ;
2023-11-21 16:50:22 -05:00
2024-08-29 15:47:07 -04:00
connect ( chkRunAnalyzer , & QCheckBox : : stateChanged , this , [ = ] ( int state ) {
sbBuildWindow - > setEnabled ( state ! = Qt : : Checked ) ;
sbUpdateTime - > setEnabled ( state ! = Qt : : Checked ) ;
chkBackWardBuilding - > setEnabled ( state ! = Qt : : Checked ) ;
sbBackwardCount - > setEnabled ( state ! = Qt : : Checked ) ;
} ) ;
2023-11-21 16:50:22 -05:00
QLabel * lbUpdateTime = new QLabel ( " Update Period [s] " , this ) ;
lbUpdateTime - > setAlignment ( Qt : : AlignRight | Qt : : AlignCenter ) ;
2024-08-26 13:59:04 -04:00
boxLayout - > addWidget ( lbUpdateTime , rowID , 1 ) ;
2023-11-21 16:50:22 -05:00
sbUpdateTime = new RSpinBox ( this , 1 ) ;
sbUpdateTime - > setMinimum ( 0.1 ) ;
sbUpdateTime - > setMaximum ( 5 ) ;
sbUpdateTime - > setValue ( 1 ) ;
2024-08-26 13:59:04 -04:00
boxLayout - > addWidget ( sbUpdateTime , rowID , 2 ) ;
2023-11-21 16:50:22 -05:00
2023-11-21 17:31:46 -05:00
connect ( sbUpdateTime , & RSpinBox : : valueChanged , this , [ = ] ( ) { sbUpdateTime - > setStyleSheet ( " color : blue " ) ; } ) ;
connect ( sbUpdateTime , & RSpinBox : : returnPressed , this , [ = ] ( ) {
sbUpdateTime - > setStyleSheet ( " " ) ;
SetUpdateTimeInSec ( sbUpdateTime - > value ( ) ) ;
} ) ;
2023-11-21 16:50:22 -05:00
2024-08-26 13:59:04 -04:00
QLabel * lbBuildWindow = new QLabel ( " Event Window [ns] " , this ) ;
lbBuildWindow - > setAlignment ( Qt : : AlignRight | Qt : : AlignCenter ) ;
boxLayout - > addWidget ( lbBuildWindow , rowID , 3 ) ;
sbBuildWindow = new RSpinBox ( this , 0 ) ;
sbBuildWindow - > setMinimum ( 1 ) ;
sbBuildWindow - > setMaximum ( 9999999999 ) ;
sbBuildWindow - > setValue ( 1000 ) ;
boxLayout - > addWidget ( sbBuildWindow , rowID , 4 ) ;
connect ( sbBuildWindow , & RSpinBox : : valueChanged , this , [ = ] ( ) {
sbBuildWindow - > setStyleSheet ( " color : blue; " ) ;
} ) ;
connect ( sbBuildWindow , & RSpinBox : : returnPressed , this , [ = ] ( ) {
sbBuildWindow - > setStyleSheet ( " " ) ;
2024-08-29 15:47:07 -04:00
mb - > SetTimeWindow ( ( int ) sbBuildWindow - > value ( ) ) ;
2024-08-26 13:59:04 -04:00
} ) ;
rowID + + ;
2023-11-21 16:50:22 -05:00
chkBackWardBuilding = new QCheckBox ( " Use Backward builder " , this ) ;
2024-08-26 13:59:04 -04:00
boxLayout - > addWidget ( chkBackWardBuilding , rowID , 0 ) ;
2023-11-21 16:50:22 -05:00
QLabel * lbBKWindow = new QLabel ( " Max No. Backward Event " , this ) ;
lbBKWindow - > setAlignment ( Qt : : AlignRight | Qt : : AlignCenter ) ;
2024-08-26 13:59:04 -04:00
boxLayout - > addWidget ( lbBKWindow , rowID , 1 ) ;
2023-11-21 16:50:22 -05:00
sbBackwardCount = new RSpinBox ( this , 0 ) ;
sbBackwardCount - > setMinimum ( 1 ) ;
sbBackwardCount - > setMaximum ( 9999 ) ;
sbBackwardCount - > setValue ( 100 ) ;
2024-08-26 13:59:04 -04:00
boxLayout - > addWidget ( sbBackwardCount , rowID , 2 ) ;
2023-11-21 16:50:22 -05:00
chkBackWardBuilding - > setChecked ( false ) ;
sbBackwardCount - > setEnabled ( false ) ;
connect ( chkBackWardBuilding , & QCheckBox : : stateChanged , this , [ = ] ( int status ) {
SetBackwardBuild ( status , sbBackwardCount - > value ( ) ) ;
sbBackwardCount - > setEnabled ( status ) ;
2023-11-21 17:31:46 -05:00
SetBackwardBuild ( true , sbBackwardCount - > value ( ) ) ;
} ) ;
connect ( sbBackwardCount , & RSpinBox : : valueChanged , this , [ = ] ( ) {
sbBackwardCount - > setStyleSheet ( " color : blue; " ) ;
2023-11-21 16:50:22 -05:00
} ) ;
2023-11-21 17:31:46 -05:00
connect ( sbBackwardCount , & RSpinBox : : returnPressed , this , [ = ] ( ) {
sbBackwardCount - > setStyleSheet ( " " ) ;
SetBackwardBuild ( true , sbBackwardCount - > value ( ) ) ;
2023-11-21 16:50:22 -05:00
} ) ;
2023-11-16 19:20:29 -05:00
}
2023-11-21 16:50:22 -05:00
{
2024-08-26 13:59:04 -04:00
rowID + + ;
QFrame * separator0 = new QFrame ( box ) ;
separator0 - > setFrameShape ( QFrame : : HLine ) ;
separator0 - > setFrameShadow ( QFrame : : Sunken ) ;
boxLayout - > addWidget ( separator0 , rowID , 0 , 1 , 4 ) ;
2023-11-21 16:50:22 -05:00
2024-08-26 13:59:04 -04:00
rowID + + ;
2023-11-21 16:50:22 -05:00
QLabel * lbXDigi = new QLabel ( " X-Digi " , this ) ;
lbXDigi - > setAlignment ( Qt : : AlignRight | Qt : : AlignCenter ) ;
2024-08-26 13:59:04 -04:00
boxLayout - > addWidget ( lbXDigi , rowID , 0 ) ;
2023-11-21 16:50:22 -05:00
xDigi = new RComboBox ( this ) ;
for ( unsigned int i = 0 ; i < nDigi ; i + + ) {
xDigi - > addItem ( " Digi- " + QString : : number ( digi [ i ] - > GetSerialNumber ( ) ) , i ) ;
}
2024-08-26 13:59:04 -04:00
boxLayout - > addWidget ( xDigi , rowID , 1 ) ;
2023-11-21 16:50:22 -05:00
QLabel * lbXCh = new QLabel ( " X-Ch " , this ) ;
lbXCh - > setAlignment ( Qt : : AlignRight | Qt : : AlignCenter ) ;
2024-08-26 13:59:04 -04:00
boxLayout - > addWidget ( lbXCh , rowID , 2 ) ;
2023-11-21 16:50:22 -05:00
xCh = new RComboBox ( this ) ;
for ( int i = 0 ; i < digi [ 0 ] - > GetNumInputCh ( ) ; i + + ) xCh - > addItem ( " Ch- " + QString : : number ( i ) , i ) ;
2024-08-26 13:59:04 -04:00
boxLayout - > addWidget ( xCh , rowID , 3 ) ;
2023-11-21 16:50:22 -05:00
2024-08-26 13:59:04 -04:00
rowID + + ;
2023-11-21 16:50:22 -05:00
QLabel * lbYDigi = new QLabel ( " Y-Digi " , this ) ;
lbYDigi - > setAlignment ( Qt : : AlignRight | Qt : : AlignCenter ) ;
2024-08-26 13:59:04 -04:00
boxLayout - > addWidget ( lbYDigi , rowID , 0 ) ;
2023-11-21 16:50:22 -05:00
yDigi = new RComboBox ( this ) ;
for ( unsigned int i = 0 ; i < nDigi ; i + + ) {
yDigi - > addItem ( " Digi- " + QString : : number ( digi [ i ] - > GetSerialNumber ( ) ) , i ) ;
}
2024-08-26 13:59:04 -04:00
boxLayout - > addWidget ( yDigi , rowID , 1 ) ;
2023-11-21 16:50:22 -05:00
QLabel * lbYCh = new QLabel ( " Y-Ch " , this ) ;
lbYCh - > setAlignment ( Qt : : AlignRight | Qt : : AlignCenter ) ;
2024-08-26 13:59:04 -04:00
boxLayout - > addWidget ( lbYCh , rowID , 2 ) ;
2023-11-21 16:50:22 -05:00
yCh = new RComboBox ( this ) ;
for ( int i = 0 ; i < digi [ 0 ] - > GetNumInputCh ( ) ; i + + ) yCh - > addItem ( " Ch- " + QString : : number ( i ) , i ) ;
2024-08-26 13:59:04 -04:00
boxLayout - > addWidget ( yCh , rowID , 3 ) ;
2023-11-21 16:50:22 -05:00
connect ( xDigi , & RComboBox : : currentIndexChanged , this , [ = ] ( ) {
allowSignalSlot = false ;
xCh - > clear ( ) ;
for ( int i = 0 ; i < digi [ 0 ] - > GetNumInputCh ( ) ; i + + ) xCh - > addItem ( " Ch- " + QString : : number ( i ) , i ) ;
allowSignalSlot = true ;
int bd = xDigi - > currentData ( ) . toInt ( ) ;
int ch = xCh - > currentData ( ) . toInt ( ) ;
h2D - > SetXTitle ( " Digi- " + QString : : number ( digi [ bd ] - > GetSerialNumber ( ) ) + " , Ch- " + QString : : number ( ch ) ) ;
h2D - > UpdatePlot ( ) ;
} ) ;
connect ( xCh , & RComboBox : : currentIndexChanged , this , [ = ] ( ) {
if ( ! allowSignalSlot ) return ;
int bd = xDigi - > currentData ( ) . toInt ( ) ;
int ch = xCh - > currentData ( ) . toInt ( ) ;
h2D - > SetXTitle ( " Digi- " + QString : : number ( digi [ bd ] - > GetSerialNumber ( ) ) + " , Ch- " + QString : : number ( ch ) ) ;
h2D - > UpdatePlot ( ) ;
} ) ;
connect ( yDigi , & RComboBox : : currentIndexChanged , this , [ = ] ( ) {
allowSignalSlot = false ;
yCh - > clear ( ) ;
for ( int i = 0 ; i < digi [ 0 ] - > GetNumInputCh ( ) ; i + + ) yCh - > addItem ( " Ch- " + QString : : number ( i ) , i ) ;
allowSignalSlot = true ;
int bd = yDigi - > currentData ( ) . toInt ( ) ;
int ch = yCh - > currentData ( ) . toInt ( ) ;
h2D - > SetYTitle ( " Digi- " + QString : : number ( digi [ bd ] - > GetSerialNumber ( ) ) + " , Ch- " + QString : : number ( ch ) ) ;
h2D - > UpdatePlot ( ) ;
} ) ;
connect ( yCh , & RComboBox : : currentIndexChanged , this , [ = ] ( ) {
if ( ! allowSignalSlot ) return ;
int bd = yDigi - > currentData ( ) . toInt ( ) ;
int ch = yCh - > currentData ( ) . toInt ( ) ;
h2D - > SetYTitle ( " Digi- " + QString : : number ( digi [ bd ] - > GetSerialNumber ( ) ) + " , Ch- " + QString : : number ( ch ) ) ;
h2D - > UpdatePlot ( ) ;
} ) ;
2023-11-16 19:20:29 -05:00
}
2023-11-21 16:50:22 -05:00
{
2024-08-26 13:59:04 -04:00
rowID + + ;
2023-11-21 16:50:22 -05:00
QFrame * separator1 = new QFrame ( box ) ;
separator1 - > setFrameShape ( QFrame : : HLine ) ;
separator1 - > setFrameShadow ( QFrame : : Sunken ) ;
2024-08-26 13:59:04 -04:00
boxLayout - > addWidget ( separator1 , rowID , 0 , 1 , 4 ) ;
2023-11-21 16:50:22 -05:00
2024-08-26 13:59:04 -04:00
rowID + + ;
2023-11-21 16:50:22 -05:00
QLabel * lbaDigi = new QLabel ( " ID-Digi " , this ) ;
lbaDigi - > setAlignment ( Qt : : AlignRight | Qt : : AlignCenter ) ;
2024-08-26 13:59:04 -04:00
boxLayout - > addWidget ( lbaDigi , rowID , 0 ) ;
2023-11-21 16:50:22 -05:00
aDigi = new RComboBox ( this ) ;
for ( unsigned int i = 0 ; i < nDigi ; i + + ) {
2024-06-26 16:40:40 -04:00
aDigi - > addItem ( " Digi- " + QString : : number ( digi [ i ] - > GetSerialNumber ( ) ) , i ) ;
2023-11-21 16:50:22 -05:00
}
2024-08-26 13:59:04 -04:00
boxLayout - > addWidget ( aDigi , rowID , 1 ) ;
2023-11-21 16:50:22 -05:00
QLabel * lbaCh = new QLabel ( " 1D-Ch " , this ) ;
lbaCh - > setAlignment ( Qt : : AlignRight | Qt : : AlignCenter ) ;
2024-08-26 13:59:04 -04:00
boxLayout - > addWidget ( lbaCh , rowID , 2 ) ;
2023-11-21 16:50:22 -05:00
aCh = new RComboBox ( this ) ;
for ( int i = 0 ; i < digi [ 0 ] - > GetNumInputCh ( ) ; i + + ) aCh - > addItem ( " Ch- " + QString : : number ( i ) , i ) ;
2024-08-26 13:59:04 -04:00
boxLayout - > addWidget ( aCh , rowID , 3 ) ;
2023-11-21 16:50:22 -05:00
connect ( aDigi , & RComboBox : : currentIndexChanged , this , [ = ] ( ) {
allowSignalSlot = false ;
aCh - > clear ( ) ;
for ( int i = 0 ; i < digi [ 0 ] - > GetNumInputCh ( ) ; i + + ) aCh - > addItem ( " Ch- " + QString : : number ( i ) , i ) ;
allowSignalSlot = true ;
int bd = aDigi - > currentData ( ) . toInt ( ) ;
int ch = aCh - > currentData ( ) . toInt ( ) ;
h1 - > SetXTitle ( " Digi- " + QString : : number ( digi [ bd ] - > GetSerialNumber ( ) ) + " , Ch- " + QString : : number ( ch ) ) ;
h1 - > UpdatePlot ( ) ;
h1g - > SetXTitle ( " Digi- " + QString : : number ( digi [ bd ] - > GetSerialNumber ( ) ) + " , Ch- " + QString : : number ( ch ) ) ;
h1g - > UpdatePlot ( ) ;
} ) ;
connect ( aCh , & RComboBox : : currentIndexChanged , this , [ = ] ( ) {
if ( ! allowSignalSlot ) return ;
int bd = aDigi - > currentData ( ) . toInt ( ) ;
int ch = aCh - > currentData ( ) . toInt ( ) ;
h1 - > SetXTitle ( " Digi- " + QString : : number ( digi [ bd ] - > GetSerialNumber ( ) ) + " , Ch- " + QString : : number ( ch ) ) ;
h1 - > UpdatePlot ( ) ;
h1g - > SetXTitle ( " Digi- " + QString : : number ( digi [ bd ] - > GetSerialNumber ( ) ) + " , Ch- " + QString : : number ( ch ) ) ;
h1g - > UpdatePlot ( ) ;
} ) ;
2023-11-16 19:20:29 -05:00
}
2023-11-21 16:50:22 -05:00
{
2024-08-26 13:59:04 -04:00
rowID + + ;
QFrame * separator2 = new QFrame ( box ) ;
separator2 - > setFrameShape ( QFrame : : HLine ) ;
separator2 - > setFrameShadow ( QFrame : : Sunken ) ;
boxLayout - > addWidget ( separator2 , rowID , 0 , 1 , 4 ) ;
rowID + + ;
QLabel * lbIP = new QLabel ( " Database IP : " , box ) ;
lbIP - > setAlignment ( Qt : : AlignRight | Qt : : AlignCenter ) ;
boxLayout - > addWidget ( lbIP , rowID , 0 ) ;
2024-08-26 15:25:19 -04:00
leInfluxIP = new QLineEdit ( box ) ;
2024-08-26 13:59:04 -04:00
leInfluxIP - > setReadOnly ( true ) ;
boxLayout - > addWidget ( leInfluxIP , rowID , 1 , 1 , 3 ) ;
QPushButton * bnInflux = new QPushButton ( " Set Influx " , box ) ;
2024-08-26 15:25:19 -04:00
boxLayout - > addWidget ( bnInflux , rowID , 4 ) ;
2024-08-26 13:59:04 -04:00
rowID + + ;
QLabel * lbDBName = new QLabel ( " Database name : " , box ) ;
lbDBName - > setAlignment ( Qt : : AlignRight | Qt : : AlignCenter ) ;
boxLayout - > addWidget ( lbDBName , rowID , 0 ) ;
2024-08-26 15:25:19 -04:00
leDBName = new QLineEdit ( box ) ;
2024-08-26 13:59:04 -04:00
leDBName - > setReadOnly ( true ) ;
boxLayout - > addWidget ( leDBName , rowID , 1 ) ;
2024-08-26 15:25:19 -04:00
connect ( bnInflux , & QPushButton : : clicked , this , [ = ] ( ) {
SetDatabaseButton ( ) ;
if ( influx ) {
leDBName - > setText ( dataBaseName ) ;
leInfluxIP - > setText ( dataBaseIP ) ;
}
} ) ;
2024-08-26 13:59:04 -04:00
// rowID ++;
// QFrame *separator3 = new QFrame(box);
// separator3->setFrameShape(QFrame::HLine);
// separator3->setFrameShadow(QFrame::Sunken);
// boxLayout->addWidget(separator3, rowID, 0, 1, 4);
2023-11-21 16:50:22 -05:00
2024-06-28 15:08:58 -04:00
QPushButton * bnClearHist = new QPushButton ( " Clear All Hist. " , this ) ;
2024-08-26 13:59:04 -04:00
boxLayout - > addWidget ( bnClearHist , rowID , 2 ) ;
2023-11-21 16:50:22 -05:00
connect ( bnClearHist , & QPushButton : : clicked , this , [ = ] ( ) {
h2D - > Clear ( ) ;
h1 - > Clear ( ) ;
h1g - > Clear ( ) ;
hMulti - > Clear ( ) ;
} ) ;
2024-06-28 15:08:58 -04:00
QPushButton * bnSaveSettings = new QPushButton ( " Save Settings " , this ) ;
2024-08-26 13:59:04 -04:00
boxLayout - > addWidget ( bnSaveSettings , rowID , 3 ) ;
2024-06-28 15:08:58 -04:00
2024-08-26 13:59:04 -04:00
connect ( bnSaveSettings , & QPushButton : : clicked , this , & CoincidentAnalyzer : : SaveSettings ) ;
2024-06-28 15:08:58 -04:00
QPushButton * bnLoadSettings = new QPushButton ( " Load Settings " , this ) ;
2024-08-26 13:59:04 -04:00
boxLayout - > addWidget ( bnLoadSettings , rowID , 4 ) ;
2024-06-28 15:08:58 -04:00
2024-08-26 13:59:04 -04:00
connect ( bnLoadSettings , & QPushButton : : clicked , this , & CoincidentAnalyzer : : LoadSettings ) ;
2024-06-28 15:08:58 -04:00
2023-11-21 16:50:22 -05:00
}
2023-11-16 19:20:29 -05:00
}
//============ histograms
2024-06-26 17:35:09 -04:00
hMulti = new Histogram1D ( " Multiplicity " , " " , 16 , 0 , 16 , this ) ;
2023-11-16 19:20:29 -05:00
layout - > addWidget ( hMulti , 0 , 1 ) ;
// the "this" make the histogram a child of the SplitPole class. When SplitPole destory, all childs destory as well.
2024-06-28 15:08:58 -04:00
h2D = new Histogram2D ( " Coincident Plot " , " XXX " , " YYY " , 200 , 0 , 30000 , 200 , 0 , 30000 , this , rawDataPath ) ;
2023-11-16 19:20:29 -05:00
//layout is inheriatge from Analyzer
layout - > addWidget ( h2D , 1 , 0 , 2 , 1 ) ;
2023-11-21 16:50:22 -05:00
int bd = xDigi - > currentData ( ) . toInt ( ) ;
int ch = xCh - > currentData ( ) . toInt ( ) ;
h2D - > SetXTitle ( " Digi- " + QString : : number ( digi [ bd ] - > GetSerialNumber ( ) ) + " , Ch- " + QString : : number ( ch ) ) ;
bd = yDigi - > currentData ( ) . toInt ( ) ;
ch = yCh - > currentData ( ) . toInt ( ) ;
h2D - > SetYTitle ( " Digi- " + QString : : number ( digi [ bd ] - > GetSerialNumber ( ) ) + " , Ch- " + QString : : number ( ch ) ) ;
h2D - > UpdatePlot ( ) ;
2024-06-26 17:35:09 -04:00
h1 = new Histogram1D ( " 1D Plot " , " XXX " , 300 , 0 , 30000 , this ) ;
2023-11-16 19:20:29 -05:00
h1 - > SetColor ( Qt : : darkGreen ) ;
2024-06-26 17:35:09 -04:00
// h1->AddDataList("Test", Qt::red); // add another histogram in h1, Max Data List is 10
2023-11-21 16:50:22 -05:00
bd = aDigi - > currentData ( ) . toInt ( ) ;
ch = aCh - > currentData ( ) . toInt ( ) ;
h1 - > SetXTitle ( " Digi- " + QString : : number ( digi [ bd ] - > GetSerialNumber ( ) ) + " , Ch- " + QString : : number ( ch ) ) ;
h1 - > UpdatePlot ( ) ;
2023-11-16 19:20:29 -05:00
layout - > addWidget ( h1 , 1 , 1 ) ;
2024-06-26 17:35:09 -04:00
h1g = new Histogram1D ( " 1D Plot (PID gated) " , " XXX " , 300 , 0 , 30000 , this ) ;
2023-11-21 16:50:22 -05:00
h1g - > SetXTitle ( " Digi- " + QString : : number ( digi [ bd ] - > GetSerialNumber ( ) ) + " , Ch- " + QString : : number ( ch ) ) ;
h1g - > UpdatePlot ( ) ;
2023-11-16 19:20:29 -05:00
layout - > addWidget ( h1g , 2 , 1 ) ;
layout - > setColumnStretch ( 0 , 1 ) ;
layout - > setColumnStretch ( 1 , 1 ) ;
2024-06-26 17:35:09 -04:00
allowSignalSlot = true ;
2023-11-16 19:20:29 -05:00
}
inline void CoincidentAnalyzer : : UpdateHistograms ( ) {
2024-08-29 14:45:11 -04:00
// printf(">>>>>>>>>>>>> CoincidentAnalyzer::%s | %d %d %d \n", __func__, this->isVisible(), chkRunAnalyzer->isChecked(), isWorking);
2023-11-16 19:20:29 -05:00
if ( this - > isVisible ( ) = = false ) return ;
2023-11-17 16:47:11 -05:00
if ( chkRunAnalyzer - > isChecked ( ) = = false ) return ;
2023-11-16 19:20:29 -05:00
2024-06-28 15:08:58 -04:00
unsigned long long t0 = getTime_ns ( ) ;
2024-08-29 14:45:11 -04:00
BuildEvents ( false ) ; // call the event builder to build events
2024-06-28 15:08:58 -04:00
// unsigned long long t1 = getTime_ns();
// printf("Event Build time : %llu ns = %.f msec\n", t1 - t0, (t1-t0)/1e6);
2023-11-16 19:20:29 -05:00
//============ Get events, and do analysis
2024-08-29 15:47:07 -04:00
long eventBuilt = mb - > eventBuilt ;
2024-08-29 14:45:11 -04:00
2023-11-16 19:20:29 -05:00
if ( eventBuilt = = 0 ) return ;
//============ Get the cut list, if any
QList < QPolygonF > cutList = h2D - > GetCutList ( ) ;
const int nCut = cutList . count ( ) ;
unsigned long long tMin [ nCut ] = { 0xFFFFFFFFFFFFFFFF } , tMax [ nCut ] = { 0 } ;
unsigned int count [ nCut ] = { 0 } ;
2023-11-21 16:50:22 -05:00
//============ Get the channel to plot
int a_bd = aDigi - > currentData ( ) . toInt ( ) ;
int a_ch = aCh - > currentData ( ) . toInt ( ) ;
int x_bd = xDigi - > currentData ( ) . toInt ( ) ;
int x_ch = xCh - > currentData ( ) . toInt ( ) ;
int y_bd = yDigi - > currentData ( ) . toInt ( ) ;
int y_ch = yCh - > currentData ( ) . toInt ( ) ;
2024-06-26 17:35:09 -04:00
int a_sn = digi [ a_bd ] - > GetSerialNumber ( ) ;
int x_sn = digi [ x_bd ] - > GetSerialNumber ( ) ;
int y_sn = digi [ y_bd ] - > GetSerialNumber ( ) ;
2023-11-16 19:20:29 -05:00
//============ Processing data and fill histograms
2024-08-29 15:47:07 -04:00
long eventIndex = mb - > eventIndex ;
2023-11-16 19:20:29 -05:00
long eventStart = eventIndex - eventBuilt + 1 ;
if ( eventStart < 0 ) eventStart + = MaxNEvent ;
for ( long i = eventStart ; i < = eventIndex ; i + + ) {
2024-08-29 15:47:07 -04:00
std : : vector < Hit > event = mb - > events [ i ] ;
2023-11-16 19:20:29 -05:00
hMulti - > Fill ( ( int ) event . size ( ) ) ;
if ( event . size ( ) = = 0 ) return ;
2023-11-21 16:50:22 -05:00
int aE = - 1 ;
int xE = - 1 , yE = - 1 ;
unsigned long long xT = 0 ;
2023-11-16 19:20:29 -05:00
for ( int k = 0 ; k < ( int ) event . size ( ) ; k + + ) {
2024-08-29 14:45:11 -04:00
// event[k].Print();
2024-06-26 17:35:09 -04:00
if ( event [ k ] . sn = = a_sn & & event [ k ] . ch = = a_ch ) {
2023-11-21 16:50:22 -05:00
h1 - > Fill ( event [ k ] . energy ) ;
aE = event [ k ] . energy ;
}
2024-06-26 17:35:09 -04:00
if ( event [ k ] . sn = = x_sn & & event [ k ] . ch = = x_ch ) {
2023-11-21 16:50:22 -05:00
xE = event [ k ] . energy ;
xT = event [ k ] . timestamp ;
}
2024-06-26 17:35:09 -04:00
if ( event [ k ] . sn = = y_sn & & event [ k ] . ch = = y_ch ) yE = event [ k ] . energy ;
2023-11-16 19:20:29 -05:00
}
2023-11-21 16:50:22 -05:00
if ( xE > = 0 & & yE > = 0 ) h2D - > Fill ( xE , yE ) ;
//check events inside any Graphical cut and extract the rate
2023-11-16 19:20:29 -05:00
for ( int p = 0 ; p < cutList . count ( ) ; p + + ) {
if ( cutList [ p ] . isEmpty ( ) ) continue ;
2023-11-21 16:50:22 -05:00
if ( cutList [ p ] . containsPoint ( QPointF ( xE , yE ) , Qt : : OddEvenFill ) & & xE > = 0 & & yE > = 0 ) {
if ( xT < tMin [ p ] ) tMin [ p ] = xT ;
if ( xT > tMax [ p ] ) tMax [ p ] = xT ;
count [ p ] + + ;
//printf(".... %d \n", count[p]);
if ( p = = 0 & & aE > = 0 ) h1g - > Fill ( aE ) ; // only for the 1st gate
}
2023-11-16 19:20:29 -05:00
}
2024-06-28 15:08:58 -04:00
unsigned long long ta = getTime_ns ( ) ;
2024-08-29 14:45:11 -04:00
if ( ta - t0 > sbUpdateTime - > value ( ) * 0.9 * GetUpdateTimeInSec ( ) * 1e9 ) break ;
2024-06-28 15:08:58 -04:00
2023-11-16 19:20:29 -05:00
}
2024-08-26 13:59:04 -04:00
if ( influx ) {
QList < QString > cutNameList = h2D - > GetCutNameList ( ) ;
for ( int p = 0 ; p < cutList . count ( ) ; p + + ) {
if ( cutList [ p ] . isEmpty ( ) ) continue ;
double dT = ( tMax [ p ] - tMin [ p ] ) / 1e9 ;
double rate = count [ p ] * 1.0 / ( dT ) ;
printf ( " %llu %llu, %f %d \n " , tMin [ p ] , tMax [ p ] , dT , count [ p ] ) ;
printf ( " %10s | %d | %f Hz \n " , cutNameList [ p ] . toStdString ( ) . c_str ( ) , count [ p ] , rate ) ;
influx - > AddDataPoint ( " Cut,name= " + cutNameList [ p ] . toStdString ( ) + " value= " + std : : to_string ( rate ) ) ;
}
2023-11-21 16:50:22 -05:00
2024-08-26 13:59:04 -04:00
influx - > WriteData ( dataBaseName . toStdString ( ) ) ;
influx - > ClearDataPointsBuffer ( ) ;
}
2024-08-29 14:45:11 -04:00
2023-11-21 16:50:22 -05:00
}
2024-10-22 16:38:01 -04:00
inline void CoincidentAnalyzer : : ReplotHistograms ( ) {
h2D - > UpdatePlot ( ) ;
h1 - > UpdatePlot ( ) ;
hMulti - > UpdatePlot ( ) ;
h1g - > UpdatePlot ( ) ;
}
2024-08-26 13:59:04 -04:00
inline void CoincidentAnalyzer : : SaveSettings ( ) {
2024-06-28 15:08:58 -04:00
QString filePath = QFileDialog : : getSaveFileName ( this ,
" Save Settings to File " ,
QDir : : toNativeSeparators ( rawDataPath + " /CoinAnaSettings.txt " ) ,
" Text file (*.txt) " ) ;
if ( ! filePath . isEmpty ( ) ) {
QFile file ( filePath ) ;
if ( file . open ( QIODevice : : WriteOnly | QIODevice : : Text ) ) {
QTextStream out ( & file ) ;
// Define the text to write
QStringList lines ;
lines < < QString : : number ( digi [ aDigi - > currentData ( ) . toInt ( ) ] - > GetSerialNumber ( ) ) ;
lines < < QString : : number ( aCh - > currentData ( ) . toInt ( ) ) ;
lines < < QString : : number ( h1 - > GetNBin ( ) ) ;
lines < < QString : : number ( h1 - > GetXMin ( ) ) ;
lines < < QString : : number ( h1 - > GetXMax ( ) ) ;
lines < < QString : : number ( digi [ xDigi - > currentData ( ) . toInt ( ) ] - > GetSerialNumber ( ) ) ;
lines < < QString : : number ( xCh - > currentData ( ) . toInt ( ) ) ;
lines < < QString : : number ( h2D - > GetXNBin ( ) ) ;
lines < < QString : : number ( h2D - > GetXMin ( ) ) ;
lines < < QString : : number ( h2D - > GetXMax ( ) ) ;
lines < < QString : : number ( digi [ yDigi - > currentData ( ) . toInt ( ) ] - > GetSerialNumber ( ) ) ;
lines < < QString : : number ( yCh - > currentData ( ) . toInt ( ) ) ;
lines < < QString : : number ( h2D - > GetYNBin ( ) ) ;
lines < < QString : : number ( h2D - > GetYMin ( ) ) ;
lines < < QString : : number ( h2D - > GetYMax ( ) ) ;
lines < < QString : : number ( sbUpdateTime - > value ( ) ) ;
lines < < QString : : number ( chkBackWardBuilding - > isChecked ( ) ) ;
lines < < QString : : number ( sbBackwardCount - > value ( ) ) ;
2024-08-26 13:59:04 -04:00
lines < < dataBaseIP ;
lines < < dataBaseName ;
lines < < dataBaseToken ;
2024-06-28 15:08:58 -04:00
lines < < " #===== End of File " ;
// Write each line to the file
for ( const QString & line : lines ) out < < line < < " \n " ;
// Close the file
file . close ( ) ;
qDebug ( ) < < " File written successfully to " < < filePath ;
} else {
qWarning ( ) < < " Unable to open file " < < filePath ;
}
2023-11-21 16:50:22 -05:00
2024-06-28 15:08:58 -04:00
}
2023-11-21 16:50:22 -05:00
}
2024-08-26 13:59:04 -04:00
inline void CoincidentAnalyzer : : LoadSettings ( ) {
2023-11-16 19:20:29 -05:00
2024-06-28 15:08:58 -04:00
QString filePath = QFileDialog : : getOpenFileName ( this ,
" Load Settings to File " ,
rawDataPath ,
" Text file (*.txt) " ) ;
int a_sn , a_ch , a_bin ;
float a_min , a_max ;
int x_sn , x_ch , x_bin ;
float x_min , x_max ;
int y_sn , y_ch , y_bin ;
float y_min , y_max ;
2024-07-26 15:21:16 -04:00
float updateTime = 1.0 ;
int bkCount = 100 ;
bool isBkEvtBuild = false ;
2024-06-28 15:08:58 -04:00
if ( ! filePath . isEmpty ( ) ) {
QFile file ( filePath ) ;
if ( file . open ( QIODevice : : ReadOnly | QIODevice : : Text ) ) {
QTextStream in ( & file ) ;
short count = 0 ;
while ( ! in . atEnd ( ) ) {
QString line = in . readLine ( ) ;
if ( count = = 0 ) a_sn = line . toInt ( ) ;
if ( count = = 1 ) a_ch = line . toInt ( ) ;
if ( count = = 2 ) a_bin = line . toInt ( ) ;
if ( count = = 3 ) a_min = line . toFloat ( ) ;
if ( count = = 4 ) a_max = line . toFloat ( ) ;
if ( count = = 5 ) x_sn = line . toFloat ( ) ;
if ( count = = 6 ) x_ch = line . toFloat ( ) ;
if ( count = = 7 ) x_bin = line . toFloat ( ) ;
if ( count = = 8 ) x_min = line . toFloat ( ) ;
if ( count = = 9 ) x_max = line . toFloat ( ) ;
if ( count = = 10 ) y_sn = line . toFloat ( ) ;
if ( count = = 11 ) y_ch = line . toFloat ( ) ;
if ( count = = 12 ) y_bin = line . toFloat ( ) ;
if ( count = = 13 ) y_min = line . toFloat ( ) ;
if ( count = = 14 ) y_max = line . toFloat ( ) ;
if ( count = = 15 ) updateTime = line . toFloat ( ) ;
if ( count = = 16 ) isBkEvtBuild = line . toInt ( ) ;
if ( count = = 17 ) bkCount = line . toInt ( ) ;
2024-08-26 13:59:04 -04:00
if ( count = = 18 ) dataBaseIP = line ;
if ( count = = 19 ) dataBaseName = line ;
if ( count = = 20 ) dataBaseToken = line ;
2024-06-28 15:08:58 -04:00
count + + ;
}
file . close ( ) ;
qDebug ( ) < < " File read successfully from " < < filePath ;
2024-08-26 13:59:04 -04:00
if ( count > = 21 ) {
2024-06-28 15:08:58 -04:00
sbUpdateTime - > setValue ( updateTime ) ;
chkBackWardBuilding - > setChecked ( isBkEvtBuild ) ;
sbBackwardCount - > setValue ( bkCount ) ;
int x_index = xDigi - > findText ( " Digi- " + QString : : number ( x_sn ) ) ;
int y_index = yDigi - > findText ( " Digi- " + QString : : number ( y_sn ) ) ;
int a_index = aDigi - > findText ( " Digi- " + QString : : number ( a_sn ) ) ;
if ( x_index = = - 1 ) qWarning ( ) < < " Cannot find digitizer " < < x_sn ;
if ( y_index = = - 1 ) qWarning ( ) < < " Cannot find digitizer " < < y_sn ;
if ( a_index = = - 1 ) qWarning ( ) < < " Cannot find digitizer " < < a_sn ;
xDigi - > setCurrentIndex ( x_index ) ;
yDigi - > setCurrentIndex ( y_index ) ;
aDigi - > setCurrentIndex ( a_index ) ;
xCh - > setCurrentIndex ( x_ch ) ;
yCh - > setCurrentIndex ( y_ch ) ;
aCh - > setCurrentIndex ( a_ch ) ;
h1 - > Rebin ( a_bin , a_min , a_max ) ;
h1g - > Rebin ( a_bin , a_min , a_max ) ;
h2D - > Rebin ( x_bin , x_min , x_max , y_bin , y_min , y_max ) ;
2024-08-26 13:59:04 -04:00
SetDatabase ( dataBaseIP , dataBaseName , dataBaseToken ) ;
2024-08-26 15:25:19 -04:00
if ( influx ) {
leDBName - > setText ( dataBaseName ) ;
leInfluxIP - > setText ( dataBaseIP ) ;
}
2024-08-26 13:59:04 -04:00
2024-06-28 15:08:58 -04:00
}
} else {
qWarning ( ) < < " Unable to open file " < < filePath ;
}
}
2023-11-16 19:20:29 -05:00
}
# endif