Commit 9b0b5f52 authored by Simon Spannagel's avatar Simon Spannagel
Browse files

PixelDetectorModel: implement isWithinMatrix that doesn't need getPixelIndex

parent f090d33e
Loading
Loading
Loading
Loading
+14 −0
Original line number Diff line number Diff line
@@ -78,6 +78,20 @@ bool PixelDetectorModel::isWithinMatrix(const int x, const int y) const {
    return !(x < 0 || x >= static_cast<int>(number_of_pixels_.x()) || y < 0 || y >= static_cast<int>(number_of_pixels_.y()));
}

/**
 * Faster implementation of matrix lookup for local coordinate positions than going through the pixel index
 * This is quite easy for rectangular pixels and matrices.
 */
bool PixelDetectorModel::isWithinMatrix(const ROOT::Math::XYZPoint& position) const {
    if(position.x() < 0.5 * pixel_size_.x() || position.x() > (number_of_pixels_.x() - 0.5) * pixel_size_.x()) {
        return false;
    }
    if(position.y() < 0.5 * pixel_size_.y() || position.y() > (number_of_pixels_.y() - 0.5) * pixel_size_.y()) {
        return false;
    }
    return true;
}

ROOT::Math::XYZPoint PixelDetectorModel::getPixelCenter(const int x, const int y) const {
    auto size = getPixelSize();
    auto local_x = size.x() * x;
+7 −0
Original line number Diff line number Diff line
@@ -80,6 +80,13 @@ namespace allpix {
         */
        bool isWithinMatrix(const int x, const int y) const override;

        /**
         * @brief Returns if a position is within the grid of pixels defined for the device
         * @param position Position in local coordinates of the detector model
         * @return True if position within the pixel grid, false otherwise
         */
        bool isWithinMatrix(const ROOT::Math::XYZPoint& position) const override;

        /**
         * @brief Returns a pixel center in local coordinates
         * @param x X- (or column-) coordinate of the pixel