Commit 13316e68 authored by Simon Spannagel's avatar Simon Spannagel
Browse files

DetectorField: do not calculate transforms if not necessary

parent f6618bc2
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -90,7 +90,7 @@ namespace allpix {
    /**
     * @brief Field instance of a detector
     *
     * Contains the a pointer to the field dat along with the field sizes, binning and potential field distortions such as
     * Contains the a pointer to the field data along with the field sizes, binning and potential field distortions such as
     * scaling or offset parameters.
     */
    template <typename T, size_t N = 3> class DetectorField {
+57 −38
Original line number Diff line number Diff line
@@ -28,6 +28,25 @@ namespace allpix {
            return {};
        }

        auto z = pos.z();

        if(type_ == FieldType::CONSTANT) {
            // Constant field - return value
            return function_(pos);
        } else if(type_ == FieldType::LINEAR) {
            // Linear field - return value at given depth

            // Check if we need to extrapolate along the z axis or if is inside thickness domain:
            if(extrapolate_z) {
                z = std::clamp(z, thickness_domain_.first, thickness_domain_.second);
            } else if(z < thickness_domain_.first || thickness_domain_.second < z) {
                return {};
            }

            // Calculate the field from the configured function:
            return function_(ROOT::Math::XYZPoint(0, 0, z));
        } else {

            // For per-pixel fields, resort to getRelativeTo with current pixel as reference:
            if(mapping_ != FieldMapping::SENSOR) {
                // Calculate center of current pixel from index as reference point:
@@ -41,7 +60,6 @@ namespace allpix {
            // Shift the coordinates by the offset configured for the field:
            auto x = pos.x() + offset_[0];
            auto y = pos.y() + offset_[1];
        auto z = pos.z();

            auto pitch = model_->getPixelSize();

@@ -58,8 +76,8 @@ namespace allpix {
            x *= ((replica_x % 2) == 1 ? -1 : 1);
            y *= ((replica_y % 2) == 1 ? -1 : 1);

        // Compute using the grid or a function depending on the setting
            T ret_val;
            // Compute using the grid or a function depending on the setting
            if(type_ == FieldType::GRID) {
                ret_val = get_field_from_grid(
                    ROOT::Math::XYZPoint(x * normalization_[0] + 0.5, y * normalization_[1] + 0.5, pos.z()), extrapolate_z);
@@ -79,6 +97,7 @@ namespace allpix {
            flip_vector_components(ret_val, replica_x % 2, replica_y % 2);
            return ret_val;
        }
    }

    /**
     * Get a value from the field assigned to a specific pixel. This means, we cannot wrap around at the pixel edges and
+1 −1
Original line number Diff line number Diff line
@@ -39,7 +39,7 @@ namespace allpix {
     * @brief Field quantities
     */
    enum class FieldQuantity : size_t {
        UNKNOWN = 0, ///< Unknown fiield quantity
        UNKNOWN = 0, ///< Unknown field quantity
        SCALAR = 1,  ///< Scalar field, i.e. one entry per field position
        VECTOR = 3,  ///< Vector field, i.e. three entries per field position
    };