From 25d074a3932401738f6e8fd92ac156ab594363bd Mon Sep 17 00:00:00 2001 From: "Ryan@SOLARIS_testStation" Date: Mon, 30 Sep 2024 18:38:48 -0400 Subject: [PATCH] update the master branch from 0ee20bc --- DigiSettingsPanel.cpp | 2 +- FSUDAQ | 6 +- FSUDAQ.cpp | 30 ++-- FSUDAQ_Qt6.pro | 23 +-- Histogram1D.h | 2 + Histogram2D.h | 6 +- MultiBuilder.cpp | 180 +++++++++++++----------- SingleSpectra.cpp | 17 +++ SingleSpectra.h | 2 + analyzers/Analyser.cpp | 11 +- analyzers/Analyser.h | 6 +- analyzers/Cross.h | 311 +++++++++++++++++++++++++++++++++++++++++ macro.h | 9 ++ 13 files changed, 490 insertions(+), 115 deletions(-) create mode 100644 analyzers/Cross.h diff --git a/DigiSettingsPanel.cpp b/DigiSettingsPanel.cpp index 264a8a2..8d682cf 100644 --- a/DigiSettingsPanel.cpp +++ b/DigiSettingsPanel.cpp @@ -3634,7 +3634,7 @@ void DigiSettingsPanel::SyncCheckBox(QCheckBox *(&chk)[][MaxRegChannel+1]){ } void DigiSettingsPanel::EnableButtons(bool enable){ - for( int i = 0; i < nDigi; i++ ){ + for( unsigned int i = 0; i < nDigi; i++ ){ if( !enable ) { leSaveFilePath[i]->setText("changing setting is disabled due to ACQ is running."); leSaveFilePath[i]->setStyleSheet("color:red;"); diff --git a/FSUDAQ b/FSUDAQ index 04a3b23..a990aef 100755 --- a/FSUDAQ +++ b/FSUDAQ @@ -2,6 +2,10 @@ timestamp=$(date +%Y%m%d_%H%M%S) -outFile=program_${timestamp}.log +outFile=log/program_${timestamp}.log + +mkdir -p "$(dirname "$outFile")" + +echo "FSUDAQ, save stdout to $outFile" stdbuf -oL ./FSUDAQ_Qt6 | tee $outFile \ No newline at end of file diff --git a/FSUDAQ.cpp b/FSUDAQ.cpp index e4a74bf..676fc7d 100644 --- a/FSUDAQ.cpp +++ b/FSUDAQ.cpp @@ -19,10 +19,10 @@ #include "analyzers/SplitPoleAnalyzer.h" #include "analyzers/EncoreAnalyzer.h" #include "analyzers/MUSICAnalyzer.h" -#include "analyzers/RAISOR.h" #include "analyzers/NeutronGamma.h" +#include "analyzers/Cross.h" -std::vector onlineAnalyzerList = {"Coincident","Splie-Pole", "Encore", "RAISOR", "MUSICS", "Neutron-Gamma"}; +std::vector onlineAnalyzerList = {"Coincident","Splie-Pole", "Encore", "MUSICS", "Neutron-Gamma", "Cross"}; FSUDAQ::FSUDAQ(QWidget *parent) : QMainWindow(parent){ DebugPrint("%s", "FSUDAQ"); @@ -684,9 +684,6 @@ void FSUDAQ::OpenDigitizers(){ digi[i] = new Digitizer(portList[i].first, portList[i].second); //digi[i]->Reset(); - //===== set no trace, even when FSQDAQ segfault at scope, the digitizer will save no trace - digi[i]->SetTrace(false); - if( cbOpenMethod->currentData().toInt() == 2 ) { digi[i]->ProgramBoard(); } @@ -731,6 +728,10 @@ void FSUDAQ::OpenDigitizers(){ } digi[i]->ReadAllSettingsFromBoard(true); + //===== set no trace, even when FSQDAQ segfault at scope, the digitizer will save no trace + digi[i]->SetTrace(false); + // if( digi[i]->GetDPPType() == V1730_DPP_PHA_CODE) digi[i]->WriteRegister(DPP::BoardConfiguration, 0xE8915); + readDataThread[i] = new ReadDataThread(digi[i], i); connect(readDataThread[i], &ReadDataThread::sendMsg, this, &FSUDAQ::LogMsg); @@ -1207,7 +1208,7 @@ void FSUDAQ::StartACQ(){ influx->ClearDataPointsBuffer(); } - if( elogID > 0 && !chkElog->isChecked() && chkSaveData->isChecked() ){ + if( elogID > 0 && chkElog->isChecked() && chkSaveData->isChecked() ){ QString msg = "================================= Run-" + QString::number(runID).rightJustified(3, '0') + "

" + QDateTime::currentDateTime().toString("MM.dd hh:mm:ss") + "

" + startComment + "

" @@ -1297,7 +1298,7 @@ void FSUDAQ::StopACQ(){ influx->ClearDataPointsBuffer(); } - if( elogID > 0 && !chkElog->isChecked() && chkSaveData->isChecked()){ + if( elogID > 0 && chkElog->isChecked() && chkSaveData->isChecked()){ QString msg = QDateTime::currentDateTime().toString("MM.dd hh:mm:ss") + "

" + stopComment + "

"; uint64_t totalFileSize = 0; for(unsigned int i = 0 ; i < nDigi; i++){ @@ -1837,9 +1838,11 @@ void FSUDAQ::OpenAnalyzer(){ if( id == 0 ) onlineAnalyzer = new CoincidentAnalyzer(digi, nDigi, rawDataPath); if( id == 1 ) onlineAnalyzer = new SplitPole(digi, nDigi); if( id == 2 ) onlineAnalyzer = new Encore(digi, nDigi); - if( id == 3 ) onlineAnalyzer = new RAISOR(digi, nDigi); - if( id == 4 ) onlineAnalyzer = new MUSIC(digi, nDigi); - if( id == 5 ) onlineAnalyzer = new NeutronGamma(digi, nDigi, rawDataPath); + if( id == 3 ) onlineAnalyzer = new MUSIC(digi, nDigi); + if( id == 4 ) onlineAnalyzer = new NeutronGamma(digi, nDigi, rawDataPath); + + if( id == 5 ) onlineAnalyzer = new Cross(digi, nDigi); + if( id >= 0 ) onlineAnalyzer->show(); if( isACQStarted ) onlineAnalyzer->startTimer(); @@ -1851,9 +1854,10 @@ void FSUDAQ::OpenAnalyzer(){ if( id == 0 ) onlineAnalyzer = new CoincidentAnalyzer(digi, nDigi, rawDataPath); if( id == 1 ) onlineAnalyzer = new SplitPole(digi, nDigi); if( id == 2 ) onlineAnalyzer = new Encore(digi, nDigi); - if( id == 3 ) onlineAnalyzer = new RAISOR(digi, nDigi); - if( id == 4 ) onlineAnalyzer = new MUSIC(digi, nDigi); - if( id == 5 ) onlineAnalyzer = new NeutronGamma(digi, nDigi, rawDataPath); + if( id == 3 ) onlineAnalyzer = new MUSIC(digi, nDigi); + if( id == 4 ) onlineAnalyzer = new NeutronGamma(digi, nDigi, rawDataPath); + + if( id == 5 ) onlineAnalyzer = new Cross(digi, nDigi); if( id >= 0 ){ onlineAnalyzer->show(); diff --git a/FSUDAQ_Qt6.pro b/FSUDAQ_Qt6.pro index c0ca0bd..0846a1b 100644 --- a/FSUDAQ_Qt6.pro +++ b/FSUDAQ_Qt6.pro @@ -25,28 +25,29 @@ QMAKE_CFLAGS_RELEASE = -O0 # Input HEADERS += ClassData.h \ ClassDigitizer.h \ + ClassInfluxDB.h\ CustomThreads.h \ CustomWidgets.h \ - Histogram1D.h \ - Histogram2D.h \ DigiSettingsPanel.h \ FSUDAQ.h \ - macro.h \ - RegisterAddress.h \ - ClassInfluxDB.h\ - Scope.h \ - SingleSpectra.h \ + Histogram1D.h \ + Histogram2D.h \ Hit.h \ + macro.h \ MultiBuilder.h \ qcustomplot.h \ - analyzers/Isotope.h \ + RegisterAddress.h \ + Scope.h \ + SingleSpectra.h \ analyzers/Analyser.h \ analyzers/CoincidentAnalyzer.h \ - analyzers/SplitPoleAnalyzer.h \ + analyzers/Cross.h\ analyzers/EncoreAnalyzer.h \ + analyzers/Isotope.h \ + analyzers/SplitPoleAnalyzer.h \ analyzers/MUSICAnalyzer.h \ - analyzers/NeutronGamma.h \ - analyzers/RAISOR.h + analyzers/NeutronGamma.h + SOURCES += ClassDigitizer.cpp \ DigiSettingsPanel.cpp \ FSUDAQ.cpp \ diff --git a/Histogram1D.h b/Histogram1D.h index a0f5704..4c6cdc1 100644 --- a/Histogram1D.h +++ b/Histogram1D.h @@ -276,6 +276,7 @@ public: UpdatePlot(); } + void SetLineTitle(QString title, int lineID = 0) { graph(lineID)->setName(title); } void SetXTitle(QString xTitle) { xAxis->setLabel(xTitle);} void Rebin(int xbin, double xmin, double xmax){ @@ -283,6 +284,7 @@ public: xMin = xmin; xMax = xmax; xBin = xbin; + if( xBin > 1000) xBin = 1000; dX = (xMax - xMin)/(xBin); diff --git a/Histogram2D.h b/Histogram2D.h index 33492b6..0392a24 100644 --- a/Histogram2D.h +++ b/Histogram2D.h @@ -310,6 +310,9 @@ inline void Histogram2D::Rebin(int xbin, double xmin, double xmax, int ybin, do xBin = xbin + 2; yBin = ybin + 2; + if( xBin > 1002) xBin = 1002; + if( yBin > 1002) yBin = 1002; + colorMap->data()->clear(); colorMap->data()->setSize(xBin, yBin); colorMap->data()->setRange(QCPRange(xMin, xMax), QCPRange(yMin, yMax)); @@ -752,7 +755,7 @@ inline void Histogram2D::LoadCuts(QString cutFileName){ int colorID = tempCutID% colorCycle.count(); text->setColor(colorCycle[colorID].first); cutTextIDList.push_back(itemCount() - 1); - // cutList.push_back(tempCut); + cutList.push_back(tempCut); cutIDList.push_back(tempCutID); } tempCut.clear(); @@ -792,6 +795,7 @@ inline void Histogram2D::LoadCuts(QString cutFileName){ // Close the file file.close(); qDebug() << "File read successfully from" << cutFileName; + qDebug() << " Number of cut loaded " << numCut << ", " << cutList.count(); // PrintCutEntry(); // DrawCut(); diff --git a/MultiBuilder.cpp b/MultiBuilder.cpp index 88d0e8d..874db37 100644 --- a/MultiBuilder.cpp +++ b/MultiBuilder.cpp @@ -95,6 +95,8 @@ void MultiBuilder::PrintAllEvent(){ } } +//^############################################### forward event builder + void MultiBuilder::FindEarlistTimeAndCh(bool verbose){ DebugPrint("%s", "MultiBuilder"); earlistTime = -1; @@ -103,9 +105,7 @@ void MultiBuilder::FindEarlistTimeAndCh(bool verbose){ nExhaushedCh = 0; for( int i = 0; i < nData; i++){ - for( int j = 0; j < data[i]->GetNChannel(); j++ ) { - chExhaused[i][j] = false; - } + for( int j = 0; j < data[i]->GetNChannel(); j++ ) chExhaused[i][j] = false; for(unsigned int ch = 0; ch < data[i]->GetNChannel(); ch ++){ @@ -118,7 +118,7 @@ void MultiBuilder::FindEarlistTimeAndCh(bool verbose){ } if( data[i]->GetTimestamp(ch, index) == 0 || - loopIndex[i][ch] * dataSize[i] > data[i]->GetLoopIndex(ch) * dataSize[i] + data[i]->GetDataIndex(ch)) { + loopIndex[i][ch] * dataSize[i] + nextIndex[i][ch] > data[i]->GetLoopIndex(ch) * dataSize[i] + data[i]->GetDataIndex(ch)) { nExhaushedCh ++; chExhaused[i][ch] = true; continue; @@ -138,42 +138,6 @@ void MultiBuilder::FindEarlistTimeAndCh(bool verbose){ } if( verbose ) printf("%s | bd : %d, ch : %d, %llu\n", __func__, earlistDigi, earlistCh, earlistTime); - -} - -void MultiBuilder::FindLatestTimeAndCh(bool verbose){ - DebugPrint("%s", "MultiBuilder"); - latestTime = 0; - latestDigi = -1; - latestCh = -1; - - nExhaushedCh = 0; - - for( int i = 0; i < nData; i++){ - - for( int j = 0; j < data[i]->GetNChannel(); j++ ) chExhaused[i][j] = false; - - for(unsigned int ch = 0; ch < data[i]->GetNChannel(); ch ++){ - - if( nextIndex[i][ch] < 0 || data[i]->GetDataIndex(ch) < 0 || nextIndex[i][ch] <= lastBackWardIndex[i][ch] ) { - nExhaushedCh ++; - chExhaused[i][ch] = true; - // printf(", exhanshed. %d \n", nExhaushedCh); - continue; - } - - unsigned long long time = data[i]->GetTimestamp(ch, nextIndex[i][ch]); - // printf(", time : %llu\n", time ); - if( time > latestTime ) { - latestTime = time; - latestDigi = i; - latestCh = ch; - } - } - } - - if( verbose ) printf("%s | bd : %d, ch : %d, %llu\n", __func__, latestDigi, latestCh, latestTime); - } void MultiBuilder::FindEarlistTimeAmongLastData(bool verbose){ @@ -195,35 +159,16 @@ void MultiBuilder::FindEarlistTimeAmongLastData(bool verbose){ } if( verbose ) printf("%s | bd : %d, ch : %d, %lld \n", __func__, latestDigi, latestCh, latestTime); } - -void MultiBuilder::FindLatestTimeOfData(bool verbose){ - DebugPrint("%s", "MultiBuilder"); - latestTime = 0; - latestCh = -1; - latestDigi = -1; - for( int i = 0; i < nData; i++){ - // printf("%s | digi-%d-th | %d\n", __func__, i, data[i]->GetNChannel()); - for( unsigned ch = 0; ch < data[i]->GetNChannel(); ch++ ){ - int index = data[i]->GetDataIndex(ch); - // printf("ch-%2d | index : %d \n", ch, index); - if( index == -1 ) continue; - if( data[i]->GetTimestamp(ch, index) > latestTime ) { - latestTime = data[i]->GetTimestamp(ch, index); - latestCh = ch; - latestDigi = i; - } - } - } - if( verbose ) printf("%s | bd : %d, ch : %d, %lld \n", __func__, latestDigi, latestCh, latestTime); -} + void MultiBuilder::BuildEvents(bool isFinal, bool skipTrace, bool verbose){ DebugPrint("%s", "MultiBuilder"); + FindEarlistTimeAndCh(verbose); //Give the earliest time, ch, digi + FindEarlistTimeAmongLastData(verbose); // give lastest Time, Ch, and Digi for event building - FindEarlistTimeAndCh(verbose); //Give the earliest time, ch, digi - if( earlistCh == -1 || nExhaushedCh == nData * MaxNChannels) return; /// no data + if( earlistCh == -1 || nExhaushedCh == numTotCh) return; /// no data eventBuilt = 0; //======= Start building event @@ -235,14 +180,13 @@ void MultiBuilder::BuildEvents(bool isFinal, bool skipTrace, bool verbose){ eventIndex ++; if( eventIndex >= MaxNEvent ) eventIndex = 0; events[eventIndex].clear(); - em.Clear(); for( int k = 0; k < nData; k++){ int bd = (k + earlistDigi) % nData; - // printf("##### %d/%d | ", k, nData); - // data[k]->PrintAllData(true, 10); + // printf("##### %d/%d | ", bd, nData); + // data[bd]->PrintAllData(true); const int numCh = data[bd]->GetNChannel(); @@ -250,16 +194,22 @@ void MultiBuilder::BuildEvents(bool isFinal, bool skipTrace, bool verbose){ int ch = (i + earlistCh ) % numCh; // printf("ch : %d | exhaused ? %s \n", ch, chExhaused[bd][ch] ? "Yes" : "No"); if( chExhaused[bd][ch] ) continue; - if( loopIndex[bd][ch] * dataSize[bd] + nextIndex[bd][ch] > data[bd]->GetLoopIndex(ch) * dataSize[bd] + data[bd]->GetDataIndex(ch)) { + + // printf(" ch : %2d | %d(%d) | %d(%d)\n", ch, loopIndex[bd][ch], nextIndex[bd][ch], data[bd]->GetLoopIndex(ch), data[bd]->GetDataIndex(ch) ); + + if( nextIndex[bd][ch] == -1 + || loopIndex[bd][ch] * dataSize[bd] + nextIndex[bd][ch] > data[bd]->GetLoopIndex(ch) * dataSize[bd] + data[bd]->GetDataIndex(ch)) { nExhaushedCh ++; chExhaused[bd][ch] = true; + + // printf(" ch : %d exhaused\n", ch); continue; } do { unsigned long long time = data[bd]->GetTimestamp(ch, nextIndex[bd][ch]); - //printf("%6ld, sn: %5d, ch: %2d, timestamp : %16llu | earlistTime : %16llu | timeWindow : %u \n", eventIndex, data[bd]->boardSN, ch, time, earlistTime, timeWindow); + // printf("%6d, sn: %5d, ch: %2d, timestamp : %16llu | earlistTime : %16llu | timeWindow : %u \n", nextIndex[bd][ch], data[bd]->boardSN, ch, time, earlistTime, timeWindow); if( time >= earlistTime && (time - earlistTime <= timeWindow) ){ em.sn = snList[bd]; @@ -280,14 +230,21 @@ void MultiBuilder::BuildEvents(bool isFinal, bool skipTrace, bool verbose){ }else{ break; } - if( timeWindow <= 0 ) break; + if( timeWindow == 0 ) break; }while( true ); - if( timeWindow <= 0 ) break; + if( timeWindow == 0 ) break; } - if( timeWindow <= 0 ) break; + if( timeWindow == 0 ) break; } - if( events[eventIndex].size() == 0 ) continue; + if( events[eventIndex].size() == 0 ) { + if( eventIndex > 1) { + eventIndex --; + }else{ + eventIndex = MaxNEvent - 1; + } + continue; + } if( events[eventIndex].size() > 1) { std::sort(events[eventIndex].begin(), events[eventIndex].end(), [](const Hit& a, const Hit& b) { @@ -295,21 +252,21 @@ void MultiBuilder::BuildEvents(bool isFinal, bool skipTrace, bool verbose){ }); } - lastEventTime = events[eventIndex].back().timestamp; + // lastEventTime = events[eventIndex].back().timestamp; ///Find the next earlist FindEarlistTimeAndCh(false); // //if there is a time jump, say, bigger than TimeJump. break - if( earlistTime - lastEventTime > timeJump ) { - if( verbose ){ - printf("!!!!!!!! Time Jump detected stop event building and get more data.\n"); - printf("event index : %6lu, earlist time : %16llu\n", eventIndex, earlistTime); - printf(" %6s last event time : %16llu \n", "", lastEventTime); - printf(" %6s time jump > %16llu \n", "", timeJump); - } - return; - } + // if( earlistTime - lastEventTime > timeJump ) { + // if( verbose ){ + // printf("!!!!!!!! Time Jump detected stop event building and get more data.\n"); + // printf("event index : %6lu, last event time : %16llu\n", eventIndex, lastEventTime); + // printf(" %6s earilest time : %16llu \n", "", earlistTime); + // printf(" %6s time jump > %16llu \n", "", timeJump); + // } + // return; + // } eventBuilt ++; totalEventBuilt ++; @@ -329,7 +286,7 @@ void MultiBuilder::BuildEvents(bool isFinal, bool skipTrace, bool verbose){ printf("%05d, %02d | %5d | %5d %llu \n", sn, chxxx, nextIndex[bd][chxxx], events[eventIndex][i].energy, events[eventIndex][i].timestamp); } - if( nExhaushedCh == nData * MaxNChannels ) { + if( nExhaushedCh == numTotCh ) { printf("######################### no more event to be built\n"); break; } @@ -348,12 +305,67 @@ void MultiBuilder::BuildEvents(bool isFinal, bool skipTrace, bool verbose){ break; } } - }while(nExhaushedCh < nData * MaxNChannels); + }while(nExhaushedCh < numTotCh); forceStop = false; } +//^############################################### backward event builder + +void MultiBuilder::FindLatestTimeAndCh(bool verbose){ + DebugPrint("%s", "MultiBuilder"); + latestTime = 0; + latestDigi = -1; + latestCh = -1; + + nExhaushedCh = 0; + + for( int i = 0; i < nData; i++){ + for( int j = 0; j < data[i]->GetNChannel(); j++ ) chExhaused[i][j] = false; + + for(unsigned int ch = 0; ch < data[i]->GetNChannel(); ch ++){ + if( nextIndex[i][ch] < 0 || data[i]->GetDataIndex(ch) < 0 || nextIndex[i][ch] <= lastBackWardIndex[i][ch] ) { + nExhaushedCh ++; + chExhaused[i][ch] = true; + // printf(", exhanshed. %d \n", nExhaushedCh); + continue; + } + + unsigned long long time = data[i]->GetTimestamp(ch, nextIndex[i][ch]); + // printf(", time : %llu\n", time ); + if( time > latestTime ) { + latestTime = time; + latestDigi = i; + latestCh = ch; + } + } + } + + if( verbose ) printf("%s | bd : %d, ch : %d, %llu\n", __func__, latestDigi, latestCh, latestTime); +} + +void MultiBuilder::FindLatestTimeOfData(bool verbose){ + DebugPrint("%s", "MultiBuilder"); + latestTime = 0; + latestCh = -1; + latestDigi = -1; + for( int i = 0; i < nData; i++){ + // printf("%s | digi-%d-th | %d\n", __func__, i, data[i]->GetNChannel()); + for( unsigned ch = 0; ch < data[i]->GetNChannel(); ch++ ){ + int index = data[i]->GetDataIndex(ch); + // printf("ch-%2d | index : %d \n", ch, index); + if( index == -1 ) continue; + if( data[i]->GetTimestamp(ch, index) > latestTime ) { + latestTime = data[i]->GetTimestamp(ch, index); + latestCh = ch; + latestDigi = i; + } + } + } + if( verbose ) printf("%s | bd : %d, ch : %d, %lld \n", __func__, latestDigi, latestCh, latestTime); +} + void MultiBuilder::BuildEventsBackWard(int maxNumEvent, bool verbose){ DebugPrint("%s", "MultiBuilder"); //skip trace, and only build for maxNumEvent events max diff --git a/SingleSpectra.cpp b/SingleSpectra.cpp index bc08501..95a1081 100644 --- a/SingleSpectra.cpp +++ b/SingleSpectra.cpp @@ -151,6 +151,9 @@ SingleSpectra::SingleSpectra(Digitizer ** digi, unsigned int nDigi, QString rawD // Setup the timer to trigger every second connect(timer, &QTimer::timeout, histWorker, &HistWorker::FillHistograms); + + connect( histWorker, &HistWorker::workDone, this, &SingleSpectra::ReplotHistograms); + workerThread->start(); } @@ -314,6 +317,20 @@ void SingleSpectra::FillHistograms(){ } +void SingleSpectra::ReplotHistograms(){ + + int ID = cbDigi->currentData().toInt(); + int ch = cbCh->currentData().toInt(); + + if( ch == digi[ID]->GetNumInputCh()) { + if( hist2DVisibility[ID] ) hist2D[ID]->UpdatePlot(); + return; + } + + if( histVisibility[ID][ch] ) hist[ID][ch]->UpdatePlot(); + +} + void SingleSpectra::SaveSetting(){ DebugPrint("%s", "SingleSpectra"); diff --git a/SingleSpectra.h b/SingleSpectra.h index 9a0d19d..60cb25d 100644 --- a/SingleSpectra.h +++ b/SingleSpectra.h @@ -43,6 +43,8 @@ public: QVector generateNonRepeatedCombination(int size); + void ReplotHistograms(); + public slots: void FillHistograms(); void ChangeHistView(); diff --git a/analyzers/Analyser.cpp b/analyzers/Analyser.cpp index 38330d0..bcfd5ed 100644 --- a/analyzers/Analyser.cpp +++ b/analyzers/Analyser.cpp @@ -60,6 +60,8 @@ Analyzer::Analyzer(Digitizer ** digi, unsigned int nDigi, QMainWindow * parent ) // printf(" --------- work Done\n"); // }); + connect( anaWorker, &AnalyzerWorker::workDone, this, &Analyzer::ReplotHistograms); + anaThread->start(); } @@ -138,12 +140,12 @@ void Analyzer::SetDatabase(QString IP, QString Name, QString Token){ influx = nullptr; } }else{ - printf("Database name : %s NOT found.\n", dataBaseName.toStdString().c_str()); + printf(RED "Database name : %s NOT found.\n" RESET, dataBaseName.toStdString().c_str()); delete influx; influx = nullptr; } }else{ - printf("InfluxDB URL (%s) is NOT Valid. \n", dataBaseIP.toStdString().c_str()); + printf(RED "InfluxDB URL (%s) is NOT Valid. \n" RESET, dataBaseIP.toStdString().c_str()); delete influx; influx = nullptr; } @@ -242,4 +244,9 @@ void Analyzer::SetUpCanvas(){ void Analyzer::UpdateHistograms(){ +} + +void Analyzer::ReplotHistograms(){ + + } \ No newline at end of file diff --git a/analyzers/Analyser.h b/analyzers/Analyser.h index 75dade6..8c1a677 100644 --- a/analyzers/Analyser.h +++ b/analyzers/Analyser.h @@ -17,6 +17,7 @@ #include "CustomWidgets.h" #include "MultiBuilder.h" #include "ClassInfluxDB.h" +#include "math.h" /************************************** @@ -62,18 +63,19 @@ public: virtual void SetUpCanvas(); virtual void UpdateHistograms(); // where event-building, analysis, and ploting + virtual void ReplotHistograms(); public slots: void startTimer(){ // printf("start timer\n"); mb->ForceStop(false); - mb->ClearEvents(); anaTimer->start(waitTimeinSec*1000); } void stopTimer(){ // printf("stop worker\n"); anaTimer->stop(); mb->ForceStop(true); + mb->ClearEvents(); } private slots: @@ -130,4 +132,4 @@ private: Analyzer * SS; }; -#endif \ No newline at end of file +#endif diff --git a/analyzers/Cross.h b/analyzers/Cross.h new file mode 100644 index 0000000..c2060f0 --- /dev/null +++ b/analyzers/Cross.h @@ -0,0 +1,311 @@ +#ifndef Cross_h +#define Cross_h + +/********************************************* + * This is online analyzer for PID, ANL + * + * Created by Khushi @ 2024-09-03 + * + * ******************************************/ +#include "Analyser.h" + +class Cross : public Analyzer{ + +public: + Cross(Digitizer ** digi, unsigned int nDigi, QMainWindow * parent = nullptr): Analyzer(digi, nDigi, parent){ + + SetUpdateTimeInSec(1.0); + + RedefineEventBuilder({0}); // only builder for the 0-th digitizer. + tick2ns = digi[0]->GetTick2ns(); + + 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. + evtbder = GetEventBuilder(); + evtbder->SetTimeWindow(500); + + SetDatabase("http://localhost:8086/", "testing", "zKhzKk4Yhf1l9QU-yE2GsIZ1RazqUgoW3NlF8LJqq_xDMwatOJwg1sKrjgq36uLEsQf8Fmn4sJALP7Kkilk14A=="); + + SetUpCanvas(); // see below + + }; + + void SetUpCanvas(); + +public slots: + void UpdateHistograms(); + void ReplotHistograms(); + +private: + + MultiBuilder *evtbder; + + //Histogram2D * hPID; + + Histogram1D * hdE; // raw dE (ch=1): ch1 + Histogram1D * hE; // raw E (ch=4) : ch4 + Histogram1D * hdT; // raw dT (ch=7): ch7 + + Histogram1D * hTotE; // total energy (dE+E): ch1+ch4 + Histogram1D * hTWin; // coincidence time window TWin: (t4-t1)*1e9 + + Histogram2D * hdEE; // dE versus E : ch1 versus ch4 + Histogram2D * hdEtotE; // dE versus totE : ch1 versus (ch1+ch4) + + Histogram2D * hdEdT; // dE versus TOF: ch1 versus (t7-t1)*1e9 + + Histogram1D * hMulti; //Multiplicity of an event + + int tick2ns; + + int chDE, chE; + float energyDE, energyE, ch7; + unsigned long long t1, t4, t7; + + QPushButton * bnClearHist; + QLabel * lbInfluxIP; + RComboBox * cbLocation; + QCheckBox * chkDEFourTime; + +}; + +inline void Cross::ReplotHistograms(){ + + hdE->UpdatePlot(); + hE->UpdatePlot(); + hdT->UpdatePlot(); + hTotE->UpdatePlot(); + hdEE->UpdatePlot(); + hdEtotE->UpdatePlot(); + hdEdT->UpdatePlot(); + hTWin->UpdatePlot(); + hMulti->UpdatePlot(); + +} + +inline void Cross::SetUpCanvas(){ + + setGeometry(0, 0, 2000, 1000); + + //============ histograms + + //hPID = new Histogram2D("RAISOR", "E", "dE", 100, 0, 5000, 100, 0, 5000, this); + //layout->addWidget(hPID, 2, 0); + + int row = 0; + cbLocation = new RComboBox(this); + cbLocation->addItem("Cross", 0); + cbLocation->addItem("Target", 1); + layout->addWidget(cbLocation, row, 0); + + connect(cbLocation, &RComboBox::currentIndexChanged, this, [=](){ + switch (cbLocation->currentData().toInt() ) { + case 0 : { + hdE->SetLineTitle("raw dE (ch = 0)"); + hE->SetLineTitle("raw E (ch = 2)"); + hdE->replot(); + hE->replot(); + chDE = 0; + chE = 2; + //Can also set histograms range + + } + break; + case 1 : { + hdE->SetLineTitle("raw dE (ch = 1)"); + hE->SetLineTitle("raw E (ch = 4)"); + hdE->replot(); + hE->replot(); + chDE = 1; + chE = 4; + //Can also set histograms range + } + } + }); + + chkDEFourTime = new QCheckBox("dE channel / 4", this); + layout->addWidget(chkDEFourTime, row, 1); + + bnClearHist = new QPushButton("Clear All Hist.", this); + layout->addWidget(bnClearHist, row, 2); + + connect( bnClearHist, &QPushButton::clicked, this, [=](){ + hdE->Clear(); + hE->Clear(); + hdT->Clear(); + hTotE->Clear(); + hdEE->Clear(); + hdEtotE->Clear(); + hdEdT->Clear(); + hTWin->Clear(); + hMulti->Clear(); + }); + + + QString haha; + if( influx ) { + haha = dataBaseIP + ", DB : " + dataBaseName; + }else{ + haha = "No influxDB connection."; + } + lbInfluxIP = new QLabel( haha , this); + if( influx == nullptr ) lbInfluxIP->setStyleSheet("color : red;"); + layout->addWidget(lbInfluxIP, row, 3, 1, 3); + + row ++; + hdEE = new Histogram2D("dE vs E", "E[ch]", "dE[ch]", 500, -100, 5000, 500, -100, 5000, this); + layout->addWidget(hdEE, row, 0, 1, 2); + + hdE = new Histogram1D("raw dE (ch=0)", "dE [ch]", 300, 0, 5000, this); + layout->addWidget(hdE, row, 2); + + hE = new Histogram1D("raw E (ch=2)", "E [ch]", 300, 0, 10000, this); + layout->addWidget(hE, row, 3); + + hTotE = new Histogram1D("total energy (dE+E)", "TotE [ch]", 300, 0, 16000, this); + layout->addWidget(hTotE, row, 4); + + hMulti = new Histogram1D("Multiplicity", "", 10, 0, 10, this); + layout->addWidget(hMulti, row, 5); + + row ++; + hdEtotE = new Histogram2D("dE vs TotE", "TotE[ch]", "dE[ch]", 500, 0, 10000, 500, 0, 5000, this); + layout->addWidget(hdEtotE, row, 0, 1, 2); + + hdT = new Histogram1D("raw dT (ch=7)", "dT [ch]", 300, 0, 1000, this); + layout->addWidget(hdT, row, 2); + + hdEdT = new Histogram2D("dE vs TOF", "TOF [ns]", "dE", 100, 0, 500, 100, 0, 4000, this); + layout->addWidget(hdEdT, row, 3); + + hTWin = new Histogram1D("coincidence time window", "TWin [ns]", 100, 0, 100, this); + layout->addWidget(hTWin, row, 4); + + +} + +inline void Cross::UpdateHistograms(){ + + if( this->isVisible() == false ) return; + + BuildEvents(false); // call the event builder to build events + + //============ Get events, and do analysis + long eventBuilt = evtbder->eventBuilt; + if( eventBuilt == 0 ) return; + + //============ Get the cut list, if any + QList cutList1 = hdEE->GetCutList(); + const int nCut1 = cutList1.count(); + unsigned long long tMin1[nCut1], tMax1[nCut1]; + unsigned int count1[nCut1]; + + QList cutList2 = hdEtotE->GetCutList(); + const int nCut2 = cutList2.count(); + unsigned long long tMin2[nCut2], tMax2[nCut2]; + unsigned int count2[nCut2]; + + //============ Processing data and fill histograms + long eventIndex = evtbder->eventIndex; + long eventStart = eventIndex - eventBuilt + 1; + if(eventStart < 0 ) eventStart += MaxNEvent; + + for( int i = 0; i < nCut1; i++) { + tMin1[i] = -1; + tMax1[i] = 0; + count1[i] = 0; + } + + for( int i = 0; i < nCut2; i++) { + tMin2[i] = -1; + tMax2[i] = 0; + count2[i] = 0; + } + + for( long i = eventStart ; i <= eventIndex; i ++ ){ + + std::vector event = evtbder->events[i]; + //printf("-------------- %ld\n", i); + + if( event.size() == 0 ) return; + + hMulti->Fill(event.size()); + + energyDE = -100; t1 = 0; + energyE = -100; t4 = 0; + ch7 = -100; t7 = 0; + + for( int k = 0; k < (int) event.size(); k++ ){ + //event[k].Print(); + if( event[k].ch == chDE ) {energyDE = event[k].energy; t1 = event[k].timestamp;} // Reads channel 0 of the digitizer corresponding to dE + if( event[k].ch == chE ) {energyE = event[k].energy; t4 = event[k].timestamp;} // Reads channel 2 of the digitizer corresponding to E + if( event[k].ch == 7 ) {ch7 = event[k].energy; t7 = event[k].timestamp;} //RF Timing if setup + + } + + // printf("(E, dE) = (%f, %f)\n", E, dE); + //hPID->Fill(ch4 , ch1); // x, y + //etotal = ch1*0.25*0.25 + ch4 + if( energyDE > 0 ) hdE->Fill(energyDE); + if( energyE > 0 ) hE->Fill(energyE); + if( ch7 > 0 ) hdT->Fill(ch7); + if( energyDE > 0 && energyE > 0 ){ + hTotE->Fill(0.25 * energyDE + energyE); + hdEE->Fill(energyE,energyDE); + if( t4 > t1 ) { + hTWin->Fill((t4-t1)); + }else{ + hTWin->Fill((t1-t4)); + } + hdEtotE->Fill( (chkDEFourTime->isChecked() ? 0.25 : 1) * energyDE + energyE,energyDE); + } + + if( energyDE > 0 && ch7 > 0) hdEdT->Fill((t7-t1)*1e9,energyDE); + + //check events inside any Graphical cut and extract the rate + // if( ch1 == 0 && ch4 == 0 ) continue; + for(int p = 0; p < cutList1.count(); p++ ){ + if( cutList1[p].isEmpty() ) continue; + if( cutList1[p].containsPoint(QPointF(energyE, energyDE), Qt::OddEvenFill) ){ + if( t1 < tMin1[p] ) tMin1[p] = t1; + if( t1 > tMax1[p] ) tMax1[p] = t1; + count1[p] ++; + //printf("hdEE.... %d \n", count1[p]); + } + } + + for(int p = 0; p < cutList2.count(); p++ ){ + if( cutList2[p].isEmpty() ) continue; + if( cutList2[p].containsPoint(QPointF(energyDE+energyE,energyDE), Qt::OddEvenFill) ){ + if( t1 < tMin2[p] ) tMin2[p] = t1; + if( t1 > tMax2[p] ) tMax2[p] = t1; + count2[p] ++; + //printf("hdEtotE.... %d \n", count2[p]); + } + } + } + + + for(int p = 0; p < cutList2.count(); p++ ){ + printf("hdEE.... %d %d \n", p, count1[p]); + } + + //========== output to Influx + QList cutNameList1 = hdEE->GetCutNameList(); + for( int p = 0; p < cutList1.count(); p ++){ + if( cutList1[p].isEmpty() ) continue; + double dT = (tMax1[p]-tMin1[p]) / 1e9; // tick to sec + double rate = count1[p]*1.0/(dT); + //printf("%llu %llu, %f %d\n", tMin1[p], tMax1[p], dT, count1[p]); + printf("%10s | %d | %f Hz \n", cutNameList1[p].toStdString().c_str(), count1[p], rate); + + if( influx ){ + influx->AddDataPoint("Cut,name=" + cutNameList1[p].toStdString()+ " value=" + std::to_string(rate)); + influx->WriteData("testing"); + influx->ClearDataPointsBuffer(); + } + } + +} + + +#endif diff --git a/macro.h b/macro.h index 34c802d..d734ec6 100644 --- a/macro.h +++ b/macro.h @@ -19,6 +19,15 @@ #define SETTINGSIZE 2048 +#define RESET "\033[0m" +#define RED "\033[31m" +#define GREEN "\033[32m" +#define YELLOW "\033[33m" +#define BLUE "\033[34m" +#define MAGENTA "\033[35m" +#define CYAN "\033[36m" +#define WHITE "\033[37m" + #define DAQLockFile "DAQLock.dat" #define PIDFile "pid.dat"