Commit 098f971c authored by Håkan Wennlöf's avatar Håkan Wennlöf
Browse files

Refactored to use the existing Liang-Barsky code to find the intersections.

On the sensor boundary is a special case, but it is now handled as well.
parent b01464cf
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -349,6 +349,15 @@ namespace allpix {
         */
        virtual bool isWithinSensor(const ROOT::Math::XYZPoint& local_pos) const = 0;

        /**
         * @brief Returns if a local position is on the sensor boundary
         * @param local_pos Position in local coordinates of the detector model
         * @return True if a local position is on the sensor boundary, false otherwise
         *
         * @note This method is purely virtual and must be implemented by the respective concrete detector model classes
         */
        virtual bool isOnSensorBoundary(const ROOT::Math::XYZPoint& local_pos) const = 0;

        /**
         * @brief Calculate exit point of step outside sensor volume from one point inside the sensor (before step) and one
         * point outside (after step).
+9 −0
Original line number Diff line number Diff line
@@ -63,6 +63,15 @@ bool PixelDetectorModel::isWithinSensor(const ROOT::Math::XYZPoint& local_pos) c
           (2 * std::fabs(local_pos.x() - sensor_center.x()) <= sensor_size.x());
}

/**
 * The definition of the sensor boundary is determined by the detector model
 */
bool PixelDetectorModel::isOnSensorBoundary(const ROOT::Math::XYZPoint& local_pos) const {
    auto sensor_size = getSensorSize();
    return (2 * std::fabs(local_pos.z()) == sensor_size.z()) || (2 * std::fabs(local_pos.y()) == sensor_size.y()) ||
           (2 * std::fabs(local_pos.x()) == sensor_size.x());
}

/**
 * The definition of the pixel grid size is determined by the detector model
 */
+7 −0
Original line number Diff line number Diff line
@@ -54,6 +54,13 @@ namespace allpix {
         */
        bool isWithinSensor(const ROOT::Math::XYZPoint& local_pos) const override;

        /**
         * @brief Returns if a local position is on the sensor boundary
         * @param local_pos Position in local coordinates of the detector model
         * @return True if a local position is on the sensor boundary, false otherwise
         */
        bool isOnSensorBoundary(const ROOT::Math::XYZPoint& local_pos) const override;

        /**
         * @brief Calculate exit point of step outside sensor volume from one point inside the sensor (before step) and one
         * point outside (after step).
+18 −0
Original line number Diff line number Diff line
@@ -112,6 +112,24 @@ bool RadialStripDetectorModel::isWithinSensor(const ROOT::Math::XYZPoint& local_
    return false;
}

bool RadialStripDetectorModel::isOnSensorBoundary(const ROOT::Math::XYZPoint& local_pos) const {
    // Convert local position to polar coordinates
    auto polar_pos = getPositionPolar(local_pos);
    // Check if radial coordinate is on the sensor edge
    if(2 * std::fabs(local_pos.z()) == getSensorSize().z() ||
       (polar_pos.r() == row_radius_.back() || polar_pos.r() == row_radius_.front())) {
        return true;
    }
    // Find which strip row the position belongs to
    for(unsigned int row = 0; row < getNPixels().y(); row++) {
        if(polar_pos.r() > row_radius_.at(row) && polar_pos.r() <= row_radius_.at(row + 1)) {
            // Check if the angular coordinate is on the edge of strip row
            return (std::fabs(polar_pos.phi() + stereo_angle_) == angular_pitch_.at(row) * number_of_strips_.at(row) / 2);
        }
    }
    return false;
}

bool RadialStripDetectorModel::isWithinMatrix(const Pixel::Index& strip_index) const {
    return !(strip_index.y() < 0 || strip_index.y() >= static_cast<int>(getNPixels().y()) || strip_index.x() < 0 ||
             strip_index.x() >= static_cast<int>(number_of_strips_.at(static_cast<unsigned int>(strip_index.y()))));
+7 −0
Original line number Diff line number Diff line
@@ -172,6 +172,13 @@ namespace allpix {
         */
        bool isWithinSensor(const ROOT::Math::XYZPoint& position) const override;

        /**
         * @brief Returns if a local position is on the sensor boundary
         * @param local_pos Position in local coordinates of the detector model
         * @return True if a local position is on the sensor boundary, false otherwise
         */
        bool isOnSensorBoundary(const ROOT::Math::XYZPoint& local_pos) const override;

        /**
         * @brief Calculate exit point of step outside sensor volume from one point inside the sensor (before step) and one
         * point outside (after step).
Loading