Skip to content

Commit

Permalink
added Offset to configuration, if valid offset is subtracted and disc…
Browse files Browse the repository at this point in the history
…arded pixels are counted
  • Loading branch information
mortenjc committed Aug 11, 2021
1 parent a44a3ee commit 8388c5b
Show file tree
Hide file tree
Showing 20 changed files with 89 additions and 30 deletions.
9 changes: 9 additions & 0 deletions source/daqlite/Configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ void Configuration::print() {
fmt::print(" Topic {}\n", Kafka.Topic);
fmt::print("[Geometry]\n");
fmt::print(" Dimensions ({}, {}, {})\n", Geometry.XDim, Geometry.YDim, Geometry.ZDim);
fmt::print(" Pixel Offset {}\n", Geometry.Offset);
fmt::print("[Plot]\n");
fmt::print(" WindowTitle {}\n", Plot.WindowTitle);
fmt::print(" Plot type {}\n", Plot.PlotType);
Expand Down Expand Up @@ -50,6 +51,14 @@ void Configuration::fromJsonFile(std::string fname)
throw std::runtime_error("Config error: invalid 'geometry' field");
}

/// 'geometry' offset field is optional
try {
Geometry.Offset = j["geometry"]["offset"];
} catch (nlohmann::json::exception& e) {
fmt::print("Noncritical error in Geometry configuration - using default value for offset\n");
fmt::print("{}\n", e.what());
}

/// 'kafka' field is mandatory. 'broker' and 'topic' must be specified
try {
Kafka.Broker = j["kafka"]["broker"];
Expand Down
5 changes: 3 additions & 2 deletions source/daqlite/Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@ class Configuration {
} TOF;

struct {
int XDim{256};
int YDim{256};
int XDim{1};
int YDim{1};
int ZDim{1};
int Offset{0};
} Geometry;

struct {
Expand Down
3 changes: 1 addition & 2 deletions source/daqlite/Custom2DPlot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ Custom2DPlot::Custom2DPlot(Configuration &Config, int Projection) :
auto & geom = mConfig.Geometry;

LogicalGeometry = new ESSGeometry(geom.XDim, geom.YDim, geom.ZDim, 1);
HistogramData.resize(
LogicalGeometry->nx() * LogicalGeometry->ny() * LogicalGeometry->nz() + 1);
HistogramData.resize(LogicalGeometry->max_pixel() + 1);

// this will also allow rescaling the color scale by dragging/zooming
setInteractions(QCP::iRangeDrag | QCP::iRangeZoom);
Expand Down
27 changes: 18 additions & 9 deletions source/daqlite/ESSConsumer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@
ESSConsumer::ESSConsumer(Configuration &Config) : mConfig(Config) {
const int OVERHEAD{1};
auto & geom = mConfig.Geometry;
mMaxPixel = geom.XDim * geom.YDim * geom.ZDim;
uint32_t NumPixels = geom.XDim * geom.YDim * geom.ZDim;
mMinPixel = geom.Offset;
mMaxPixel = NumPixels + geom.Offset;
assert(mMaxPixel != 0);
mHistogram.resize(mMaxPixel + OVERHEAD);
assert(mMinPixel < mMaxPixel);
mHistogram.resize(NumPixels + OVERHEAD);
mHistogramTof.resize(mConfig.TOF.BinSize + OVERHEAD);

mConsumer = subscribeTopic();
Expand Down Expand Up @@ -66,22 +69,28 @@ uint32_t ESSConsumer::processEV42Data(RdKafka::Message *Msg) {
auto EvMsg = GetEventMessage(Msg->payload());
auto PixelIds = EvMsg->detector_id();
auto TOFs = EvMsg->time_of_flight();

if (PixelIds->size() != TOFs->size()) {
return 0;
}

for (int i = 0; i < PixelIds->size(); i++) {
uint32_t Pixel = (*PixelIds)[i];
uint32_t Tof = (*TOFs)[i]/mConfig.TOF.Scale; // ns to us
if (Pixel > mMaxPixel) {
printf("Error: invalid pixel id: %d > %d\n", Pixel, mMaxPixel);
exit(0);

if ((Pixel > mMaxPixel) or (Pixel < mMinPixel)) {
// printf("Error: invalid pixel id: %d, min: %d, max: %d\n",
// Pixel, mMinPixel, mMaxPixel);
// exit(0);
PixelDiscard++;
} else {
Pixel -= mMinPixel;
mHistogram[Pixel]++;
Tof = std::min(Tof, mConfig.TOF.MaxValue);
mHistogramTof[Tof * mConfig.TOF.BinSize / mConfig.TOF.MaxValue]++;
}
mHistogram[Pixel]++;
Tof = std::min(Tof, mConfig.TOF.MaxValue);
mHistogramTof[Tof * mConfig.TOF.BinSize / mConfig.TOF.MaxValue]++;
}
mCounts += PixelIds->size();
PixelCount += PixelIds->size();
return PixelIds->size();
}

Expand Down
7 changes: 4 additions & 3 deletions source/daqlite/ESSConsumer.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ class ESSConsumer {
std::vector<uint32_t> mHistogram;
std::vector<uint32_t> mHistogramTofPlot;
std::vector<uint32_t> mHistogramTof;
uint64_t mCounts{0};

uint64_t PixelCount{0};
uint64_t PixelDiscard{0};

private:
RdKafka::Conf *mConf;
Expand All @@ -65,5 +65,6 @@ class ESSConsumer {
} mKafkaStats;


uint32_t mMaxPixel{0}; /// \brief Number of pixels
uint32_t mMinPixel{0}; ///< Offset
uint32_t mMaxPixel{0}; ///< Number of pixels + offset
};
2 changes: 2 additions & 0 deletions source/daqlite/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ void MainWindow::startKafkaConsumerThread() {
// SLOT
void MainWindow::handleKafkaData(int EventRate) {
ui->lblEventRateText->setText(QString::number(EventRate));
ui->lblDiscardedPixelsText->setText(QString::number(KafkaConsumerThread->consumer()->PixelDiscard));

KafkaConsumerThread->mutex.lock();
if (!TOF) {
Plot2DXY->addData(KafkaConsumerThread->consumer()->mHistogramPlot);
Expand Down
26 changes: 26 additions & 0 deletions source/daqlite/MainWindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,32 @@
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="lblDiscardedPixels">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Discarded:</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="lblDiscardedPixelsText">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="lblGradient">
<property name="sizePolicy">
Expand Down
4 changes: 2 additions & 2 deletions source/daqlite/WorkerThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ void WorkerThread::run() {
Consumer->mHistogramTofPlot = Consumer->mHistogramTof;
mutex.unlock();

uint64_t Rate = (uint64_t)((Consumer->mCounts * 1000000000ULL)/elapsed.count());
uint64_t Rate = (uint64_t)((Consumer->PixelCount * 1000000000ULL)/elapsed.count());
emit resultReady(Rate);

Consumer->mCounts = 0;
Consumer->PixelCount = 0;
std::fill(Consumer->mHistogram.begin(), Consumer->mHistogram.end(), 0);
std::fill(Consumer->mHistogramTof.begin(), Consumer->mHistogramTof.end(), 0);
t1 = std::chrono::high_resolution_clock::now();
Expand Down
3 changes: 2 additions & 1 deletion source/daqlite/configs/amor.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"geometry" : {
"xdim" : 32,
"ydim" : 160,
"zdim" : 1
"zdim" : 1,
"offset" : 0
},

"plot": {
Expand Down
3 changes: 2 additions & 1 deletion source/daqlite/configs/dreamoffice.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"geometry" : {
"xdim" : 1288,
"ydim" : 256,
"zdim" : 1
"zdim" : 1,
"offset" : 0
},

"plot": {
Expand Down
3 changes: 2 additions & 1 deletion source/daqlite/configs/lokioffice.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"geometry" : {
"xdim" : 512,
"ydim" : 56,
"zdim" : 1
"zdim" : 1,
"offset" : 0
},

"plot": {
Expand Down
3 changes: 2 additions & 1 deletion source/daqlite/configs/vipcspec2d.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"geometry" : {
"xdim" : 36,
"ydim" : 800,
"zdim" : 1
"zdim" : 1,
"offset" : 0
},

"plot": {
Expand Down
3 changes: 2 additions & 1 deletion source/daqlite/configs/vipcspec3d.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"geometry" : {
"xdim" : 36,
"ydim" : 40,
"zdim" : 20
"zdim" : 20,
"offset" : 0
},

"plot": {
Expand Down
3 changes: 2 additions & 1 deletion source/daqlite/configs/vipdream.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"geometry" : {
"xdim" : 1288,
"ydim" : 256,
"zdim" : 1
"zdim" : 1,
"offset" : 0
},

"plot": {
Expand Down
3 changes: 2 additions & 1 deletion source/daqlite/configs/vipfreia.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"geometry" : {
"xdim" : 32,
"ydim" : 192,
"zdim" : 1
"zdim" : 1,
"offset" : 0
},

"plot": {
Expand Down
3 changes: 2 additions & 1 deletion source/daqlite/configs/vipfreiatof.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"geometry" : {
"xdim" : 32,
"ydim" : 192,
"zdim" : 1
"zdim" : 1,
"offset" : 0
},

"tof" : {
Expand Down
3 changes: 2 additions & 1 deletion source/daqlite/configs/viploki.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"geometry" : {
"xdim" : 512,
"ydim" : 1344,
"zdim" : 1
"zdim" : 1,
"offset" : 0
},

"plot": {
Expand Down
3 changes: 2 additions & 1 deletion source/daqlite/configs/viploki4amp.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"geometry" : {
"xdim" : 512,
"ydim" : 1344,
"zdim" : 1
"zdim" : 1,
"offset" : 0
},

"tof" : {
Expand Down
3 changes: 2 additions & 1 deletion source/daqlite/configs/viplokitof.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"geometry" : {
"xdim" : 512,
"ydim" : 1344,
"zdim" : 1
"zdim" : 1,
"offset" : 0
},

"plot": {
Expand Down
3 changes: 2 additions & 1 deletion source/daqlite/configs/vipnmx.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"geometry" : {
"xdim" : 256,
"ydim" : 256,
"zdim" : 1
"zdim" : 1,
"offset" : 0
},

"plot": {
Expand Down

0 comments on commit 8388c5b

Please sign in to comment.