Selection of Neighbor Channels Relies on Rectangular Grid
Summary
The current implementation of selecting neighboring channels, e.g. in TransientPropagation
on in the clustering of DetectorHistogrammer
is not independent of the sensor geometry since it relies on a rectangular grid and simply increments/decrements indices to form a region around the pixel in question. This is incompatible with current projects working towards supporting different geometries (radial strips, hexagonal pixels).
Possible Solution
I would suggest to move this functionality into the DetectorModel
where everything about the local-coordinates-to-channel transformation is known. A possible interface could look like this (pseudo code):
std::set<Pixel::Index> getNeighborPixels(Pixel::Index idx, size_t distance = 1) {
std::set<Pixel::Index> neighbors
// Calculate all neigboring pixels, e.g. for a rectangular pixel detector simply:
for(int x = idx.x() - distance; x <= dx.x() + distance; x++) {
for(int y = idx.y() - distance; y <= idx.y() + distance; y++) {
if(!isWithinPixelGrid(x, y) {
continue;
}
neighbors.add({x, y});
}
}
return neighbors;
}
The beauty of using a std::set
is that every entry is guaranteed to be unique, and multiple sets can be combined without duplicating the respective neighbor indices, and we can loop directly over the function return:
for(const auto& index : model_->getNeighborPixels(pixel)) {
// loop over all neighbors
}
Whether the distance
parameter makes sense we can discuss I guess, but having this recursively feels quite inefficient - especially since this will be called in inner loops, potentially thousands of times per event.
(cc) @rprivara @rmoriya @kdort @pschutze
Who takes this over, @rmoriya, is this on your to do list currently?