improved Histogram2D color map, set every cell to nan = white; improve the SingleSpectrum filling algorithm, fill random digi and random ch
This commit is contained in:
parent
1af2bd4ce9
commit
bedbe44164
|
@ -49,10 +49,13 @@ public:
|
||||||
colorScale->setType(QCPAxis::atRight);
|
colorScale->setType(QCPAxis::atRight);
|
||||||
colorMap->setColorScale(colorScale);
|
colorMap->setColorScale(colorScale);
|
||||||
|
|
||||||
|
|
||||||
QCPColorGradient color;
|
QCPColorGradient color;
|
||||||
|
color.setNanHandling(QCPColorGradient::NanHandling::nhNanColor);
|
||||||
|
color.setNanColor(QColor("white"));
|
||||||
color.clearColorStops();
|
color.clearColorStops();
|
||||||
color.setColorStopAt( 0.0, QColor("white" ));
|
// color.setColorStopAt( 0.0, QColor("white" ));
|
||||||
color.setColorStopAt( 0.000001, QColor("purple" ));
|
color.setColorStopAt( 0.0, QColor("purple" ));
|
||||||
color.setColorStopAt( 0.2, QColor("blue"));
|
color.setColorStopAt( 0.2, QColor("blue"));
|
||||||
color.setColorStopAt( 0.4, QColor("cyan"));
|
color.setColorStopAt( 0.4, QColor("cyan"));
|
||||||
color.setColorStopAt( 0.6, QColor("green"));
|
color.setColorStopAt( 0.6, QColor("green"));
|
||||||
|
@ -191,16 +194,18 @@ public:
|
||||||
void SetChannelMap(bool onOff, int tickStep = 1) { isChannelMap = onOff; this->tickStep = tickStep;}
|
void SetChannelMap(bool onOff, int tickStep = 1) { isChannelMap = onOff; this->tickStep = tickStep;}
|
||||||
|
|
||||||
void UpdatePlot(){
|
void UpdatePlot(){
|
||||||
QCPColorGradient color;
|
// QCPColorGradient color;
|
||||||
color.clearColorStops();
|
// color.clearColorStops();
|
||||||
color.setColorStopAt( 0.0, QColor("white" ));
|
// color.setNanColor(QColor("white"));
|
||||||
color.setColorStopAt( 1.0/entry[1][1], QColor("purple" ));
|
// // color.setColorStopAt( 0.0, QColor("white" ));
|
||||||
color.setColorStopAt( 0.2, QColor("blue"));
|
// // color.setColorStopAt( 1.0/entry[1][1], QColor("purple" ));
|
||||||
color.setColorStopAt( 0.4, QColor("cyan"));
|
// color.setColorStopAt( 0.0, QColor("purple" ));
|
||||||
color.setColorStopAt( 0.6, QColor("green"));
|
// color.setColorStopAt( 0.2, QColor("blue"));
|
||||||
color.setColorStopAt( 0.8, QColor("yellow"));
|
// color.setColorStopAt( 0.4, QColor("cyan"));
|
||||||
color.setColorStopAt( 1.0, QColor("red"));
|
// color.setColorStopAt( 0.6, QColor("green"));
|
||||||
colorMap->setGradient(color);
|
// color.setColorStopAt( 0.8, QColor("yellow"));
|
||||||
|
// color.setColorStopAt( 1.0, QColor("red"));
|
||||||
|
// colorMap->setGradient(color);
|
||||||
|
|
||||||
colorMap->rescaleDataRange();
|
colorMap->rescaleDataRange();
|
||||||
|
|
||||||
|
@ -309,6 +314,12 @@ inline void Histogram2D::Rebin(int xbin, double xmin, double xmax, int ybin, do
|
||||||
colorMap->data()->setSize(xBin, yBin);
|
colorMap->data()->setSize(xBin, yBin);
|
||||||
colorMap->data()->setRange(QCPRange(xMin, xMax), QCPRange(yMin, yMax));
|
colorMap->data()->setRange(QCPRange(xMin, xMax), QCPRange(yMin, yMax));
|
||||||
|
|
||||||
|
for( int i = 0; i < xBin; i++){
|
||||||
|
for( int j = 0; j < yBin; j++){
|
||||||
|
colorMap->data()->setCell(i, j, NAN);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if( isChannelMap ){
|
if( isChannelMap ){
|
||||||
QCPAxis * xAxis = colorMap->keyAxis();
|
QCPAxis * xAxis = colorMap->keyAxis();
|
||||||
xAxis->ticker()->setTickCount(xbin/tickStep);
|
xAxis->ticker()->setTickCount(xbin/tickStep);
|
||||||
|
|
|
@ -1,11 +1,9 @@
|
||||||
#include "SingleSpectra.h"
|
#include "SingleSpectra.h"
|
||||||
|
|
||||||
#include <QValueAxis>
|
#include <QValueAxis>
|
||||||
#include <QRandomGenerator>
|
|
||||||
#include <QGroupBox>
|
#include <QGroupBox>
|
||||||
#include <QStandardItemModel>
|
#include <QStandardItemModel>
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
#include <QRandomGenerator>
|
|
||||||
|
|
||||||
SingleSpectra::SingleSpectra(Digitizer ** digi, unsigned int nDigi, QString rawDataPath, QMainWindow * parent) : QMainWindow(parent){
|
SingleSpectra::SingleSpectra(Digitizer ** digi, unsigned int nDigi, QString rawDataPath, QMainWindow * parent) : QMainWindow(parent){
|
||||||
DebugPrint("%s", "SingleSpectra");
|
DebugPrint("%s", "SingleSpectra");
|
||||||
|
@ -13,7 +11,8 @@ SingleSpectra::SingleSpectra(Digitizer ** digi, unsigned int nDigi, QString rawD
|
||||||
this->nDigi = nDigi;
|
this->nDigi = nDigi;
|
||||||
this->rawDataPath = rawDataPath;
|
this->rawDataPath = rawDataPath;
|
||||||
|
|
||||||
maxFillTimeinMilliSec = 500;
|
maxFillTimeinMilliSec = 1000;
|
||||||
|
maxFillTimePerDigi = maxFillTimeinMilliSec/nDigi;
|
||||||
|
|
||||||
isSignalSlotActive = true;
|
isSignalSlotActive = true;
|
||||||
|
|
||||||
|
@ -205,47 +204,52 @@ void SingleSpectra::FillHistograms(){
|
||||||
// DebugPrint("%s", "SingleSpectra");
|
// DebugPrint("%s", "SingleSpectra");
|
||||||
if( !fillHistograms ) return;
|
if( !fillHistograms ) return;
|
||||||
|
|
||||||
unsigned short maxFillTimePerDigi = maxFillTimeinMilliSec/nDigi;
|
|
||||||
timespec t0, t1;
|
timespec t0, t1;
|
||||||
|
|
||||||
for( int i = 0; i < nDigi; i++){
|
QVector<int> randomDigiList = generateNonRepeatedCombination(nDigi);
|
||||||
|
|
||||||
digiMTX[i].lock();
|
for( int i = 0; i < nDigi; i++){
|
||||||
|
int ID = randomDigiList[i];
|
||||||
|
|
||||||
|
QVector<int> randomChList = generateNonRepeatedCombination(digi[ID]->GetNumInputCh());
|
||||||
|
|
||||||
|
digiMTX[ID].lock();
|
||||||
clock_gettime(CLOCK_REALTIME, &t0);
|
clock_gettime(CLOCK_REALTIME, &t0);
|
||||||
for( int ch = 0; ch < digi[i]->GetNumInputCh(); ch ++ ){
|
for( int k = 0; k < digi[ID]->GetNumInputCh(); k ++ ){
|
||||||
int lastIndex = digi[i]->GetData()->GetDataIndex(ch);
|
int ch = randomChList[k];
|
||||||
|
int lastIndex = digi[ID]->GetData()->GetDataIndex(ch);
|
||||||
if( lastIndex < 0 ) continue;
|
if( lastIndex < 0 ) continue;
|
||||||
|
|
||||||
int loopIndex = digi[i]->GetData()->GetLoopIndex(ch);
|
int loopIndex = digi[ID]->GetData()->GetLoopIndex(ch);
|
||||||
|
|
||||||
int temp1 = lastIndex + loopIndex * digi[i]->GetData()->GetDataSize();
|
int temp1 = lastIndex + loopIndex * digi[ID]->GetData()->GetDataSize();
|
||||||
int temp2 = lastFilledIndex[i][ch] + loopFilledIndex[i][ch] * digi[i]->GetData()->GetDataSize();
|
int temp2 = lastFilledIndex[ID][ch] + loopFilledIndex[ID][ch] * digi[ID]->GetData()->GetDataSize();
|
||||||
|
|
||||||
// printf("%d |%d %d \n", ch, temp2, temp1);
|
// printf("%d |%d %d \n", ch, temp2, temp1);
|
||||||
if( temp1 <= temp2 ) continue;
|
if( temp1 <= temp2 ) continue;
|
||||||
|
|
||||||
if( temp1 - temp2 > digi[i]->GetData()->GetDataSize() ) { //DefaultDataSize = 10k
|
if( temp1 - temp2 > digi[ID]->GetData()->GetDataSize() ) { //DefaultDataSize = 10k
|
||||||
temp2 = temp1 - digi[i]->GetData()->GetDataSize();
|
temp2 = temp1 - digi[ID]->GetData()->GetDataSize();
|
||||||
lastFilledIndex[i][ch] = lastIndex;
|
lastFilledIndex[ID][ch] = lastIndex;
|
||||||
lastFilledIndex[i][ch] = loopIndex - 1;
|
lastFilledIndex[ID][ch] = loopIndex - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
for( int j = 0 ; j <= temp1 - temp2; j ++){
|
for( int j = 0 ; j <= temp1 - temp2; j ++){
|
||||||
lastFilledIndex[i][ch] ++;
|
lastFilledIndex[ID][ch] ++;
|
||||||
if( lastFilledIndex[i][ch] > digi[i]->GetData()->GetDataSize() ) {
|
if( lastFilledIndex[ID][ch] > digi[ID]->GetData()->GetDataSize() ) {
|
||||||
lastFilledIndex[i][ch] = 0;
|
lastFilledIndex[ID][ch] = 0;
|
||||||
loopFilledIndex[i][ch] ++;
|
loopFilledIndex[ID][ch] ++;
|
||||||
}
|
}
|
||||||
hist[i][ch]->Fill( digi[i]->GetData()->GetEnergy(ch, lastFilledIndex[i][ch]));
|
hist[ID][ch]->Fill( digi[ID]->GetData()->GetEnergy(ch, lastFilledIndex[ID][ch]));
|
||||||
hist2D[i]->Fill(ch, digi[i]->GetData()->GetEnergy(ch, lastFilledIndex[i][ch]));
|
hist2D[ID]->Fill(ch, digi[ID]->GetData()->GetEnergy(ch, lastFilledIndex[ID][ch]));
|
||||||
}
|
}
|
||||||
if( histVisibility[i][ch] ) hist[i][ch]->UpdatePlot();
|
if( histVisibility[ID][ch] ) hist[ID][ch]->UpdatePlot();
|
||||||
if( hist2DVisibility[i] ) hist2D[i]->UpdatePlot();
|
if( hist2DVisibility[ID] ) hist2D[ID]->UpdatePlot();
|
||||||
|
|
||||||
clock_gettime(CLOCK_REALTIME, &t1);
|
clock_gettime(CLOCK_REALTIME, &t1);
|
||||||
if( t1.tv_nsec - t0.tv_nsec + (t1.tv_sec - t0.tv_sec)*1e9 > maxFillTimePerDigi * 1e6 ) break;
|
if( t1.tv_nsec - t0.tv_nsec + (t1.tv_sec - t0.tv_sec)*1e9 > maxFillTimePerDigi * 1e6 ) break;
|
||||||
}
|
}
|
||||||
digiMTX[i].unlock();
|
digiMTX[ID].unlock();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -339,4 +343,15 @@ void SingleSpectra::LoadSetting(){
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
QVector<int> SingleSpectra::generateNonRepeatedCombination(int size) {
|
||||||
|
QVector<int> combination;
|
||||||
|
for (int i = 0; i < size; ++i) combination.append(i);
|
||||||
|
|
||||||
|
for (int i = 0; i < size - 1; ++i) {
|
||||||
|
int j = QRandomGenerator::global()->bounded(i, size);
|
||||||
|
combination.swapItemsAt(i, j);
|
||||||
|
}
|
||||||
|
return combination;
|
||||||
}
|
}
|
|
@ -10,6 +10,8 @@
|
||||||
#include <QLineEdit>
|
#include <QLineEdit>
|
||||||
#include <QGridLayout>
|
#include <QGridLayout>
|
||||||
#include <QGroupBox>
|
#include <QGroupBox>
|
||||||
|
#include <QVector>
|
||||||
|
#include <QRandomGenerator>
|
||||||
|
|
||||||
#include "macro.h"
|
#include "macro.h"
|
||||||
#include "ClassDigitizer.h"
|
#include "ClassDigitizer.h"
|
||||||
|
@ -38,6 +40,8 @@ public:
|
||||||
void SetMaxFillTime(unsigned short milliSec) { maxFillTimeinMilliSec = milliSec;}
|
void SetMaxFillTime(unsigned short milliSec) { maxFillTimeinMilliSec = milliSec;}
|
||||||
unsigned short GetMaxFillTime() const {return maxFillTimeinMilliSec;};
|
unsigned short GetMaxFillTime() const {return maxFillTimeinMilliSec;};
|
||||||
|
|
||||||
|
QVector<int> generateNonRepeatedCombination(int size);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void FillHistograms();
|
void FillHistograms();
|
||||||
void ChangeHistView();
|
void ChangeHistView();
|
||||||
|
@ -70,6 +74,7 @@ private:
|
||||||
QString rawDataPath;
|
QString rawDataPath;
|
||||||
|
|
||||||
unsigned short maxFillTimeinMilliSec;
|
unsigned short maxFillTimeinMilliSec;
|
||||||
|
unsigned short maxFillTimePerDigi;
|
||||||
|
|
||||||
bool isSignalSlotActive;
|
bool isSignalSlotActive;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user