Commit cd18ce9a authored by Simon Spannagel's avatar Simon Spannagel
Browse files

DetectorField: start modularizing class to allow also generating field

parent 9828209a
Loading
Loading
Loading
Loading
+17 −0
Original line number Diff line number Diff line
@@ -174,6 +174,23 @@ namespace allpix {
         */
        void setModel(const std::shared_ptr<DetectorModel>& model) { model_ = model; }

    protected:
        /**
         * @brief Helper to calculate field size normalization factors and configure them
         * @param bins The bins of the flat field array
         * @param size Physical extent of the field
         * @param mapping Specification of the mapping of the field onto the pixel plane
         * @param scales Scaling factors for the field size, given in fractions of the field size in x and y
         * @param offset Offset of the field from the pixel center, given in fractions of the field size in x and y
         * @param thickness_domain Domain in local coordinates in the thickness direction where the field holds
         */
        void set_grid_parameters(std::array<size_t, 3> bins,
                                 std::array<double, 3> size,
                                 FieldMapping mapping,
                                 std::array<double, 2> scales,
                                 std::array<double, 2> offset,
                                 std::pair<double, double> thickness_domain);

    private:
        /**
         * @brief Helper function to retrieve the return type from a calculated index of the field data vector
+17 −4
Original line number Diff line number Diff line
@@ -232,12 +232,26 @@ namespace allpix {
                                      std::array<double, 2> scales,
                                      std::array<double, 2> offset,
                                      std::pair<double, double> thickness_domain) {
        if(model_ == nullptr) {
            throw std::invalid_argument("field not initialized with detector model parameters");
        }
        set_grid_parameters(bins, size, mapping, scales, offset, std::move(thickness_domain));

        if(bins[0] * bins[1] * bins[2] * N != field->size()) {
            throw std::invalid_argument("field does not match the given dimensions");
        }

        // Store the field
        field_ = std::move(field);
    };

    template <typename T, size_t N>
    void DetectorField<T, N>::set_grid_parameters(std::array<size_t, 3> bins,
                                 std::array<double, 3> size,
                                 FieldMapping mapping,
                                 std::array<double, 2> scales,
                                 std::array<double, 2> offset,
                                 std::pair<double, double> thickness_domain) {
        if(model_ == nullptr) {
            throw std::invalid_argument("field not initialized with detector model parameters");
        }
        if(thickness_domain.first + 1e-9 < model_->getSensorCenter().z() - model_->getSensorSize().z() / 2.0 ||
           model_->getSensorCenter().z() + model_->getSensorSize().z() / 2.0 < thickness_domain.second - 1e-9) {
            throw std::invalid_argument("thickness domain is outside sensor dimensions");
@@ -246,7 +260,6 @@ namespace allpix {
            throw std::invalid_argument("end of thickness domain is before begin");
        }

        field_ = std::move(field);
        bins_ = bins;
        mapping_ = mapping;