Commit fc844e3d authored by Paul Schütze's avatar Paul Schütze
Browse files

Merge branch 'int_index' into 'master'

Make Pixel::Index Signed

See merge request allpix-squared/allpix-squared!606
parents 0d8d858d a4b1fbff
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -108,7 +108,7 @@ ROOT::Math::XYZPoint Detector::getGlobalPosition(const ROOT::Math::XYZPoint& loc
/**
 * The pixel has internal information about the size and location specific for this detector
 */
Pixel Detector::getPixel(unsigned int x, unsigned int y) const {
Pixel Detector::getPixel(int x, int y) const {
    Pixel::Index index(x, y);
    return getPixel(index);
}
+1 −1
Original line number Diff line number Diff line
@@ -93,7 +93,7 @@ namespace allpix {
         * @brief Return a pixel object from the x- and y-index values
         * @return Pixel object
         */
        Pixel getPixel(unsigned int x, unsigned int y) const;
        Pixel getPixel(int x, int y) const;

        /**
         * @brief Return a pixel object from the pixel index
+1 −2
Original line number Diff line number Diff line
@@ -418,8 +418,7 @@ namespace allpix {
         *
         * @note This method is purely virtual and must be implemented by the respective concrete detector model classes
         */
        virtual ROOT::Math::XYZPoint getPixelCenter(unsigned int x, unsigned int y) const = 0;

        virtual ROOT::Math::XYZPoint getPixelCenter(const int x, const int y) const = 0;
        /**
         * @brief Return X,Y indices of a pixel corresponding to a local position in a sensor.
         * @param local_pos Position in local coordinates of the detector model
+9 −8
Original line number Diff line number Diff line
@@ -49,7 +49,7 @@ bool PixelDetectorModel::isWithinSensor(const ROOT::Math::XYZPoint& local_pos) c
bool PixelDetectorModel::isWithinImplant(const ROOT::Math::XYZPoint& local_pos) const {

    auto [xpixel, ypixel] = getPixelIndex(local_pos);
    auto inPixelPos = local_pos - getPixelCenter(static_cast<unsigned int>(xpixel), static_cast<unsigned int>(ypixel));
    auto inPixelPos = local_pos - getPixelCenter(xpixel, ypixel);

    return (std::fabs(inPixelPos.x()) <= std::fabs(getImplantSize().x() / 2) &&
            std::fabs(inPixelPos.y()) <= std::fabs(getImplantSize().y() / 2));
@@ -59,7 +59,8 @@ bool PixelDetectorModel::isWithinImplant(const ROOT::Math::XYZPoint& local_pos)
 * The definition of the pixel grid size is determined by the detector model
 */
bool PixelDetectorModel::isWithinMatrix(const Pixel::Index& pixel_index) const {
    return !(pixel_index.x() >= number_of_pixels_.x() || pixel_index.y() >= number_of_pixels_.y());
    return !(pixel_index.x() < 0 || pixel_index.x() >= static_cast<int>(number_of_pixels_.x()) || pixel_index.y() < 0 ||
             pixel_index.y() >= static_cast<int>(number_of_pixels_.y()));
}

/**
@@ -69,7 +70,7 @@ 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()));
}

ROOT::Math::XYZPoint PixelDetectorModel::getPixelCenter(unsigned int x, unsigned int y) const {
ROOT::Math::XYZPoint PixelDetectorModel::getPixelCenter(const int x, const int y) const {
    auto size = getPixelSize();
    auto local_x = size.x() * x;
    auto local_y = size.y() * y;
@@ -85,12 +86,12 @@ std::pair<int, int> PixelDetectorModel::getPixelIndex(const ROOT::Math::XYZPoint
std::set<Pixel::Index> PixelDetectorModel::getNeighbors(const Pixel::Index& idx, const size_t distance) const {
    std::set<Pixel::Index> neighbors;

    for(int x = static_cast<int>(idx.x() - distance); x <= static_cast<int>(idx.x() + distance); x++) {
        for(int y = static_cast<int>(idx.y() - distance); y <= static_cast<int>(idx.y() + distance); y++) {
    for(int x = idx.x() - static_cast<int>(distance); x <= idx.x() + static_cast<int>(distance); x++) {
        for(int y = idx.y() - static_cast<int>(distance); y <= idx.y() + static_cast<int>(distance); y++) {
            if(!isWithinMatrix(x, y)) {
                continue;
            }
            neighbors.insert({static_cast<unsigned int>(x), static_cast<unsigned int>(y)});
            neighbors.insert({x, y});
        }
    }

@@ -98,6 +99,6 @@ std::set<Pixel::Index> PixelDetectorModel::getNeighbors(const Pixel::Index& idx,
}

bool PixelDetectorModel::areNeighbors(const Pixel::Index& seed, const Pixel::Index& entrant, const size_t distance) const {
    auto pixel_distance = [](unsigned int lhs, unsigned int rhs) { return (lhs > rhs ? lhs - rhs : rhs - lhs); };
    return (pixel_distance(seed.x(), entrant.x()) <= distance && pixel_distance(seed.y(), entrant.y()) <= distance);
    return (static_cast<size_t>(std::abs(seed.x() - entrant.x())) <= distance &&
            static_cast<size_t>(std::abs(seed.y() - entrant.y())) <= distance);
}
+1 −1
Original line number Diff line number Diff line
@@ -76,7 +76,7 @@ namespace allpix {
         * @param y Y- (or row-) coordinate of the pixel
         * @return Coordinates of the pixel center
         */
        ROOT::Math::XYZPoint getPixelCenter(unsigned int x, unsigned int y) const override;
        ROOT::Math::XYZPoint getPixelCenter(const int x, const int y) const override;

        /**
         * @brief Return X,Y indices of a pixel corresponding to a local position in a sensor.
Loading