Error in clustering algo of DetectorHistogrammer
The clustering algorithm sometime produces separate clusters instead of one. The problem comes from the following section in src/modules/DetectorHistogrammer/DetectorHistogrammerModule.cpp
:
// Keep adding pixels to the cluster:
for(auto other_pixel = pixel_it + 1; other_pixel != pixels_message_->getData().end(); other_pixel++) {
const PixelHit* neighbor = &(*other_pixel);
// Check if neighbor has been used or if it touches the current cluster:
if(usedPixel[neighbor] || !touching(neighbor)) {
continue;
}
cluster.addPixelHit(neighbor);
LOG(TRACE) << "Adding pixel: " << neighbor->getPixel().getIndex();
usedPixel[neighbor] = true;
}
Here the 'neighbor' might not touch the cluster with its current (uncomplete) composition but it might touch it later (when it is complete) ! In which case the neighbor is skipped in the loop (and not added to usedPixel[]), thus it will start a separate cluster later. We then have 2 clusters that touch each other...
Possible solution: Add
other_pixel = pixel_it;
at the end of the loop. This is probably not the most optimal solution because it increases the number of iterations through the hit list, but the module stays relatively fast compare to the others.