diff --git a/Histogram1D.h b/Histogram1D.h index a0f5704..911d614 100644 --- a/Histogram1D.h +++ b/Histogram1D.h @@ -283,6 +283,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..1998236 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)); @@ -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; // PrintCutEntry(); // DrawCut(); diff --git a/MultiBuilder.cpp b/MultiBuilder.cpp index 88d0e8d..f3dd729 100644 --- a/MultiBuilder.cpp +++ b/MultiBuilder.cpp @@ -258,6 +258,7 @@ void MultiBuilder::BuildEvents(bool isFinal, bool skipTrace, bool verbose){ do { + if ( nextIndex[bd][ch] < 0 ) break; // hotfix 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); 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..be55a88 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(); } @@ -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 305b015..8f67dd0 100644 --- a/analyzers/Analyser.h +++ b/analyzers/Analyser.h @@ -63,6 +63,7 @@ public: virtual void SetUpCanvas(); virtual void UpdateHistograms(); // where event-building, analysis, and ploting + virtual void ReplotHistograms(); public slots: void startTimer(){ diff --git a/analyzers/Cross.h b/analyzers/Cross.h index 288cb17..795ab25 100644 --- a/analyzers/Cross.h +++ b/analyzers/Cross.h @@ -12,13 +12,11 @@ class Cross : public Analyzer{ - - public: Cross(Digitizer ** digi, unsigned int nDigi, QMainWindow * parent = nullptr): Analyzer(digi, nDigi, parent){ - SetUpdateTimeInSec(2.0); + SetUpdateTimeInSec(1.0); RedefineEventBuilder({0}); // only builder for the 0-th digitizer. tick2ns = digi[0]->GetTick2ns(); @@ -39,7 +37,7 @@ public: public slots: void UpdateHistograms(); - + void ReplotHistograms(); private: @@ -59,16 +57,30 @@ private: Histogram2D * hdEdT; // dE versus TOF: ch1 versus (t7-t1)*1e9 + Histogram1D * hMulti; //Multiplicity of an event int tick2ns; float ch1, ch4, ch7; unsigned long long t1, t4, t7; - + + QPushButton * bnClearHist; }; +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(){ @@ -78,30 +90,52 @@ inline void Cross::SetUpCanvas(){ //hPID = new Histogram2D("RAISOR", "E", "dE", 100, 0, 5000, 100, 0, 5000, this); //layout->addWidget(hPID, 2, 0); + + int row = 0; + bnClearHist = new QPushButton("Clear All Hist.", this); + layout->addWidget(bnClearHist, row, 0); + + connect( bnClearHist, &QPushButton::clicked, this, [=](){ + hdE->Clear(); + hE->Clear(); + hdT->Clear(); + hTotE->Clear(); + hdEE->Clear(); + hdEtotE->Clear(); + hdEdT->Clear(); + hTWin->Clear(); + hMulti->Clear(); + }); + + 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); - hdEE = new Histogram2D("dE vs E", "E[ch]", "dE[ch]", 500, -100, 10000, 500, -100, 10000, this); - layout->addWidget(hdEE, 0, 0, 1, 2); + hdE = new Histogram1D("raw dE (ch=0)", "dE [ch]", 300, 0, 5000, this); + layout->addWidget(hdE, row, 2); - hdE = new Histogram1D("raw dE (ch=1)", "dE [ch]", 300, 0, 8000, this); - layout->addWidget(hdE, 0, 2); - - hdEdT = new Histogram2D("dE vs TOF", "TOF [ns]", "dE", 100, 0, 500, 100, 0, 4000, this); - layout->addWidget(hdEdT, 1, 3); - - hE = new Histogram1D("raw E (ch=4)", "E [ch]", 300, 0, 10000, this); - layout->addWidget(hE, 0, 3); - - hdEtotE = new Histogram2D("dE vs TotE", "TotE[ch]", "dE[ch]", 500, 0, 10000, 500, 0, 10000, this); - layout->addWidget(hdEtotE, 1, 0, 1, 2); - - hdT = new Histogram1D("raw dT (ch=7)", "dT [ch]", 300, 0, 1000, this); - layout->addWidget(hdT, 1, 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, 0, 4); + layout->addWidget(hTotE, row, 4); + + hMulti = new Histogram1D("Multiplicity", "", 10, 0, 10, this); + layout->addWidget(hMulti, row, 5); - hTWin = new Histogram1D("coincidence time window", "TWin [ns]", 300, 0, 500, this); - layout->addWidget(hTWin, 1, 4); + 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); + } @@ -124,24 +158,38 @@ inline void Cross::UpdateHistograms(){ */ QList cutList1 = hdEE->GetCutList(); const int nCut1 = cutList1.count(); - unsigned long long tMin1[nCut1] = {0xFFFFFFFFFFFFFFFF}, tMax1[nCut1] = {0}; - unsigned int count1[nCut1]={0}; + printf(" >>>>>> num of cut = %d, event Size : %ld\n", nCut1, eventBuilt); + 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] = {0xFFFFFFFFFFFFFFFF}, tMax2[nCut2] = {0}; + unsigned long long tMin2[nCut2] = {0xFFFFFFFFFFFFFFFF}, tMax2[nCut2] = {0}; // not a proper way to initialized unsigned int count2[nCut2]={0}; //============ 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( 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()); + + ch1 = -100; t1 = 0; + ch4 = -100; t4 = 0; + ch7 = -100; t7 = 0; for( int k = 0; k < (int) event.size(); k++ ){ //event[k].Print(); @@ -154,27 +202,24 @@ inline void Cross::UpdateHistograms(){ // printf("(E, dE) = (%f, %f)\n", E, dE); //hPID->Fill(ch4 , ch1); // x, y //etotal = ch1*0.25*0.25 + ch4 - hdE->Fill(ch1); - hE->Fill(ch4); - hdT->Fill(ch7); - hTotE->Fill(ch1 + ch4); - hdEE->Fill(ch4,ch1); - hdEtotE->Fill(ch1 + ch4,ch1); - hdEdT->Fill((t7-t1)*1e9,ch1); - hTWin->Fill((t4-t1)*1e9); + if( ch1 > 0 ) hdE->Fill(ch1); + if( ch4 > 0 ) hE->Fill(ch4); + if( ch7 > 0 ) hdT->Fill(ch7); + if( ch1 > 0 && ch4 > 0 ){ + hTotE->Fill(0.25 * ch1 + ch4); + hdEE->Fill(ch4,ch1); + if( t4 > t1 ) { + hTWin->Fill((t4-t1)); + }else{ + hTWin->Fill((t1-t4)); + } + hdEtotE->Fill(0.25 * ch1 + ch4,ch1); + } + + if( ch1 > 0 && ch7 > 0) hdEdT->Fill((t7-t1)*1e9,ch1); //check events inside any Graphical cut and extract the rate - /* - for(int p = 0; p < cutList.count(); p++ ){ - if( cutList[p].isEmpty() ) continue; - if( cutList[p].containsPoint(QPointF(ch4, ch1), Qt::OddEvenFill) ){ - if( t1 < tMin[p] ) tMin[p] = t1; - if( t1 > tMax[p] ) tMax[p] = t1; - count[p] ++; - //printf(".... %d \n", count[p]); - } - } - */ + // if( ch1 == 0 && ch4 == 0 ) continue; for(int p = 0; p < cutList1.count(); p++ ){ if( cutList1[p].isEmpty() ) continue; if( cutList1[p].containsPoint(QPointF(ch4, ch1), Qt::OddEvenFill) ){ @@ -198,18 +243,8 @@ inline void Cross::UpdateHistograms(){ for(int p = 0; p < cutList2.count(); p++ ){ - printf("hdEE.... %d %d \n", p, count1[p]); + printf("hdEE.... %d %d \n", p, count1[p]); } - - //hPID->UpdatePlot(); - hdE->UpdatePlot(); - hE->UpdatePlot(); - hdT->UpdatePlot(); - hTotE->UpdatePlot(); - hdEE->UpdatePlot(); - hdEtotE->UpdatePlot(); - hdEdT->UpdatePlot(); - hTWin->UpdatePlot(); //========== output to Influx QList cutNameList1 = hdEE->GetCutNameList(); diff --git a/analyzers/MCP.h b/analyzers/MCP.h index 569dcbc..4050960 100644 --- a/analyzers/MCP.h +++ b/analyzers/MCP.h @@ -31,7 +31,6 @@ public: evtbder = GetEventBuilder(); evtbder->SetTimeWindow(500); //ns - influx = new InfluxDB(); SetDatabase("https://localhost:8086", "testing", "zKhzKk4Yhf1l9QU-yE2GsIZ1RazqUgoW3NlF8LJqq_xDMwatOJwg1sKrjgq36uLEsQf8Fmn4sJALP7Kkilk14A=="); SetUpCanvas(); // see below diff --git a/analyzers/MCPandPSD.h b/analyzers/MCPandPSD.h index cd82b96..8c1a5dc 100644 --- a/analyzers/MCPandPSD.h +++ b/analyzers/MCPandPSD.h @@ -28,7 +28,6 @@ public: evtbder = GetEventBuilder(); evtbder->SetTimeWindow(500); - influx = new InfluxDB(); SetDatabase("https://localhost:8086", "testing", "zKhzKk4Yhf1l9QU-yE2GsIZ1RazqUgoW3NlF8LJqq_xDMwatOJwg1sKrjgq36uLEsQf8Fmn4sJALP7Kkilk14A=="); SetUpCanvas(); // see below diff --git a/analyzers/RAISOR1.h b/analyzers/RAISOR1.h index 7303860..7263117 100644 --- a/analyzers/RAISOR1.h +++ b/analyzers/RAISOR1.h @@ -25,7 +25,6 @@ public: evtbder = GetEventBuilder(); evtbder->SetTimeWindow(500); - influx = new InfluxDB(); SetDatabase("https://localhost:8086", "testing", "zKhzKk4Yhf1l9QU-yE2GsIZ1RazqUgoW3NlF8LJqq_xDMwatOJwg1sKrjgq36uLEsQf8Fmn4sJALP7Kkilk14A=="); SetUpCanvas(); // see below diff --git a/analyzers/RAISOR2.h b/analyzers/RAISOR2.h index 966fd04..99bfb84 100644 --- a/analyzers/RAISOR2.h +++ b/analyzers/RAISOR2.h @@ -26,7 +26,6 @@ public: evtbder->SetTimeWindow(500); //========== use the influx from the Analyzer - influx = new InfluxDB(); SetDatabase("https://localhost:8086", "testing", "zKhzKk4Yhf1l9QU-yE2GsIZ1RazqUgoW3NlF8LJqq_xDMwatOJwg1sKrjgq36uLEsQf8Fmn4sJALP7Kkilk14A=="); SetUpCanvas(); // see below diff --git a/analyzers/README.md b/analyzers/README.md index 634104d..f1ac9b9 100644 --- a/analyzers/README.md +++ b/analyzers/README.md @@ -8,9 +8,10 @@ The AnalyzerWorker moves to the QThread. QTimer::timeout will trigger AnalyzerWo There is an important bool 'isWorking'. This boolean variable is true when AnalyzerWorker::UpdateHistograms() is running, and it is false when finsihed. This prevent UpdateHistograms() runs twice at the same time. -There are two virual methods +There are three virual methods - SetupCanvas() - UpdateHistograms() +- ReplotHistograms() Users must implement these two methods in theie custom analyzer. @@ -33,6 +34,7 @@ public: void SetUpCanvas(); public slots: void UpdateHistograms(); + void ReplotHistograms(); private: @@ -84,10 +86,14 @@ inline void CustomAnalyzer::UpdateHistograms(){ //analysis and fill historgam } +} +``` +4. implement the ReplotHistograms() method +```cpp +inline void CustomAnalyzer::ReplotHistograms(){ //Render histograms h2D->UpdatePlot(); h1D->UpdatePlot(); - } ``` \ No newline at end of file diff --git a/analyzers/Target.h b/analyzers/Target.h index 47ccf26..9372b46 100644 --- a/analyzers/Target.h +++ b/analyzers/Target.h @@ -27,7 +27,6 @@ public: evtbder = GetEventBuilder(); evtbder->SetTimeWindow(500); - influx = new InfluxDB(); SetDatabase("https://localhost:8086", "testing", "zKhzKk4Yhf1l9QU-yE2GsIZ1RazqUgoW3NlF8LJqq_xDMwatOJwg1sKrjgq36uLEsQf8Fmn4sJALP7Kkilk14A=="); SetUpCanvas(); // see below