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

Merge branch 'fielddata' into 'master'

Move Field Checking into Detector Class

See merge request allpix-squared/allpix-squared!582
parents 434a57f9 b54d79a5
Loading
Loading
Loading
Loading
+35 −0
Original line number Diff line number Diff line
@@ -153,9 +153,11 @@ FieldType Detector::getElectricFieldType() const {
 */
void Detector::setElectricFieldGrid(const std::shared_ptr<std::vector<double>>& field,
                                    std::array<size_t, 3> dimensions,
                                    std::array<double, 3> size,
                                    std::array<double, 2> scales,
                                    std::array<double, 2> offset,
                                    std::pair<double, double> thickness_domain) {
    check_field_match(size, scales, thickness_domain);
    electric_field_.setGrid(field, dimensions, scales, offset, thickness_domain);
}

@@ -194,9 +196,11 @@ FieldType Detector::getWeightingPotentialType() const {
 */
void Detector::setWeightingPotentialGrid(const std::shared_ptr<std::vector<double>>& potential,
                                         std::array<size_t, 3> dimensions,
                                         std::array<double, 3> size,
                                         std::array<double, 2> scales,
                                         std::array<double, 2> offset,
                                         std::pair<double, double> thickness_domain) {
    check_field_match(size, scales, thickness_domain);
    weighting_potential_.setGrid(potential, dimensions, scales, offset, thickness_domain);
}

@@ -256,9 +260,11 @@ FieldType Detector::getDopingProfileType() const {
 */
void Detector::setDopingProfileGrid(std::shared_ptr<std::vector<double>> field,
                                    std::array<size_t, 3> dimensions,
                                    std::array<double, 3> size,
                                    std::array<double, 2> scales,
                                    std::array<double, 2> offset,
                                    std::pair<double, double> thickness_domain) {
    check_field_match(size, scales, thickness_domain);
    doping_profile_.setGrid(std::move(field), dimensions, scales, offset, thickness_domain);
}

@@ -268,3 +274,32 @@ void Detector::setDopingProfileFunction(FieldFunction<double> function, FieldTyp
                                 model_->getSensorCenter().z() + model_->getSensorSize().z() / 2},
                                type);
}

void Detector::check_field_match(std::array<double, 3> size,
                                 std::array<double, 2> field_scale,
                                 std::pair<double, double> thickness_domain) const {

    // Check field dimension in z versus the requested thickness domain:
    auto eff_thickness = thickness_domain.second - thickness_domain.first;
    if(std::fabs(size[2] - eff_thickness) > std::numeric_limits<double>::epsilon()) {
        LOG(WARNING) << "Thickness of field is " << Units::display(size[2], "um") << " but the depleted region is "
                     << Units::display(eff_thickness, "um");
    }

    // Check that the total field size is n*pitch:
    if(std::fabs(std::remainder(size[0], field_scale[0] * model_->getPixelSize().x())) >
           std::numeric_limits<double>::epsilon() ||
       std::fabs(std::remainder(size[1], field_scale[1] * model_->getPixelSize().y())) >
           std::numeric_limits<double>::epsilon()) {
        LOG(WARNING) << "Field map size is (" << Units::display(size[0], {"um", "mm"}) << ","
                     << Units::display(size[1], {"um", "mm"}) << ") but expecting a multiple of the pixel pitch ("
                     << Units::display(model_->getPixelSize().x(), {"um", "mm"}) << ", "
                     << Units::display(model_->getPixelSize().y(), {"um", "mm"}) << ")" << std::endl
                     << "The area to which the field is applied can be changed using the field_scale parameter.";
    } else {
        LOG(INFO) << "Field map size is (" << Units::display(size[0], {"um", "mm"}) << ","
                  << Units::display(size[1], {"um", "mm"}) << "), matching detector model with pixel pitch ("
                  << Units::display(model_->getPixelSize().x(), {"um", "mm"}) << ", "
                  << Units::display(model_->getPixelSize().y(), {"um", "mm"}) << ")";
    }
}
+16 −1
Original line number Diff line number Diff line
@@ -24,7 +24,6 @@
#include <Math/Rotation3D.h>
#include <Math/Transform3D.h>

#include "Detector.hpp"
#include "DetectorField.hpp"
#include "DetectorModel.hpp"

@@ -123,12 +122,14 @@ namespace allpix {
         * @brief Set the electric field in a single pixel in the detector using a grid
         * @param field Flat array of the field vectors (see detailed description)
         * @param dimensions The dimensions of the flat electric field array
         * @param size Size of the electric field along the three dimensions of the field map
         * @param scales Scaling factors for the field size, given in fractions of a pixel unit cell in x and y
         * @param offset Offset of the field from the pixel border
         * @param thickness_domain Domain in local coordinates in the thickness direction where the field holds
         */
        void setElectricFieldGrid(const std::shared_ptr<std::vector<double>>& field,
                                  std::array<size_t, 3> dimensions,
                                  std::array<double, 3> size,
                                  std::array<double, 2> scales,
                                  std::array<double, 2> offset,
                                  std::pair<double, double> thickness_domain);
@@ -163,12 +164,14 @@ namespace allpix {
         * @brief Set the doping profile in a single pixel in the detector using a grid
         * @param field Flat array of the field (see detailed description)
         * @param dimensions The dimensions of the flat doping profile array
         * @param size Size of the doping profile along the three dimensions of the field map
         * @param scales Scaling factors for the field size, given in fractions of a pixel unit cell in x and y
         * @param offset Offset of the field from the pixel border
         * @param thickness_domain Domain in local coordinates in the thickness direction where the profile holds
         */
        void setDopingProfileGrid(std::shared_ptr<std::vector<double>> field,
                                  std::array<size_t, 3> dimensions,
                                  std::array<double, 3> size,
                                  std::array<double, 2> scales,
                                  std::array<double, 2> offset,
                                  std::pair<double, double> thickness_domain);
@@ -202,12 +205,14 @@ namespace allpix {
         * @brief Set the weighting potential in a single pixel in the detector using a grid
         * @param potential Flat array of the potential vectors (see detailed description)
         * @param dimensions The dimensions of the flat weighting potential array
         * @param size Size of the weighting potential along the three dimensions of the field map
         * @param scales Scaling factors for the field size, given in fractions of a pixel unit cell in x and y
         * @param offset Offset of the field from the pixel border
         * @param thickness_domain Domain in local coordinates in the thickness direction where the potential holds
         */
        void setWeightingPotentialGrid(const std::shared_ptr<std::vector<double>>& potential,
                                       std::array<size_t, 3> dimensions,
                                       std::array<double, 3> size,
                                       std::array<double, 2> scales,
                                       std::array<double, 2> offset,
                                       std::pair<double, double> thickness_domain);
@@ -265,6 +270,16 @@ namespace allpix {
         */
        void build_transform();

        /**
         * @brief Check validity of the field map for this detector
         * @param size Size of the field in the three dimensions
         * @param field_scale Scaling factors for the field
         * @param thickness_domain Thickness domain in which the field is defined in
         */
        void check_field_match(std::array<double, 3> size,
                               std::array<double, 2> field_scale,
                               std::pair<double, double> thickness_domain) const;

        std::string name_;
        std::shared_ptr<DetectorModel> model_;

+8 −37
Original line number Diff line number Diff line
@@ -58,9 +58,13 @@ void DopingProfileReaderModule::initialize() {
        LOG(DEBUG) << "Doping concentration map starts with offset " << offset << " to pixel boundary";
        std::array<double, 2> field_offset{{model->getPixelSize().x() * offset.x(), model->getPixelSize().y() * offset.y()}};

        auto field_data = read_field(field_scale);
        detector_->setDopingProfileGrid(
            field_data.getData(), field_data.getDimensions(), field_scale, field_offset, thickness_domain);
        auto field_data = read_field();
        detector_->setDopingProfileGrid(field_data.getData(),
                                        field_data.getDimensions(),
                                        field_data.getSize(),
                                        field_scale,
                                        field_offset,
                                        thickness_domain);

    } else if(field_model == DopingProfile::CONSTANT) {
        LOG(TRACE) << "Adding constant doping concentration";
@@ -112,7 +116,7 @@ void DopingProfileReaderModule::initialize() {
 * The field read from the INIT format are shared between module instantiations using the static FieldParser.
 */
FieldParser<double> DopingProfileReaderModule::field_parser_(FieldQuantity::SCALAR);
FieldData<double> DopingProfileReaderModule::read_field(std::array<double, 2> field_scale) {
FieldData<double> DopingProfileReaderModule::read_field() {

    try {
        LOG(TRACE) << "Fetching doping concentration map from mesh file";
@@ -120,9 +124,6 @@ FieldData<double> DopingProfileReaderModule::read_field(std::array<double, 2> fi
        // Get field from file
        auto field_data = field_parser_.getByFileName(config_.getPath("file_name", true), "/cm/cm/cm");

        // Check if doping concentration profile matches chip
        check_detector_match(field_data.getSize(), field_scale);

        LOG(INFO) << "Set doping concentration map with " << field_data.getDimensions().at(0) << "x"
                  << field_data.getDimensions().at(1) << "x" << field_data.getDimensions().at(2) << " cells";

@@ -268,33 +269,3 @@ void DopingProfileReaderModule::create_output_plots() {
    LOG(DEBUG) << "Maximum doping concentration within plotted cut: " << doping_concentration_histogram->GetMaximum()
               << " 1/cm3";
}

/**
 * @brief Check if the detector matches the file header
 */
void DopingProfileReaderModule::check_detector_match(std::array<double, 3> dimensions, std::array<double, 2> field_scale) {
    auto xpixsz = dimensions[0];
    auto ypixsz = dimensions[1];
    auto thickness = dimensions[2];

    auto model = detector_->getModel();
    // Do a several checks with the detector model
    if(model != nullptr) {
        // Check field dimension in z versus the sensor thickness:
        if(std::fabs(thickness - model->getSensorSize().z()) > std::numeric_limits<double>::epsilon()) {
            LOG(WARNING) << "Thickness of doping concentration map is " << Units::display(thickness, "um")
                         << " but sensor thickness is " << Units::display(model->getSensorSize().z(), "um");
        }

        // Check the field extent along the pixel pitch in x and y:
        if(std::fabs(xpixsz - model->getPixelSize().x() * field_scale[0]) > std::numeric_limits<double>::epsilon() ||
           std::fabs(ypixsz - model->getPixelSize().y() * field_scale[1]) > std::numeric_limits<double>::epsilon()) {
            LOG(WARNING) << "Doping concentration map size is (" << Units::display(xpixsz, {"um", "mm"}) << ","
                         << Units::display(ypixsz, {"um", "mm"}) << ") but current configuration results in an map area of ("
                         << Units::display(model->getPixelSize().x() * field_scale[0], {"um", "mm"}) << ","
                         << Units::display(model->getPixelSize().y() * field_scale[1], {"um", "mm"}) << ")" << std::endl
                         << "The size of the area to which the doping concentration is applied can be changes using the "
                            "field_scale parameter.";
        }
    }
}
+3 −10
Original line number Diff line number Diff line
@@ -50,22 +50,15 @@ namespace allpix {
        std::shared_ptr<Detector> detector_;

        /**
         * @brief Read field in the init format and apply it
         * @param field_scale Scaling parameters for the field size in x and y
         * @brief Read field from a file in init or apf format
         * @return Data of the field read from file
         */
        FieldData<double> read_field(std::array<double, 2> field_scale);
        FieldData<double> read_field();
        static FieldParser<double> field_parser_;

        /**
         * @brief Create output plots of the doping profile
         */
        void create_output_plots();

        /**
         * @brief Compare the dimensions of the detector with the field, print warnings
         * @param dimensions Dimensions of the field read from file
         * @param field_scale The configured scaling parameters of the electric field in x and y
         */
        void check_detector_match(std::array<double, 3> dimensions, std::array<double, 2> field_scale);
    };
} // namespace allpix
+8 −44
Original line number Diff line number Diff line
@@ -84,10 +84,13 @@ void ElectricFieldReaderModule::initialize() {
        LOG(DEBUG) << "Electric field starts with offset " << offset << " to pixel boundary";
        std::array<double, 2> field_offset{{model->getPixelSize().x() * offset.x(), model->getPixelSize().y() * offset.y()}};

        auto field_data = read_field(thickness_domain, field_scale);

        detector_->setElectricFieldGrid(
            field_data.getData(), field_data.getDimensions(), field_scale, field_offset, thickness_domain);
        auto field_data = read_field();
        detector_->setElectricFieldGrid(field_data.getData(),
                                        field_data.getDimensions(),
                                        field_data.getSize(),
                                        field_scale,
                                        field_offset,
                                        thickness_domain);
    } else if(field_model == ElectricField::CONSTANT) {
        LOG(TRACE) << "Adding constant electric field";
        auto field_z = config_.get<double>("bias_voltage") / getDetector()->getModel()->getSensorSize().z();
@@ -290,8 +293,7 @@ ElectricFieldReaderModule::get_custom_field_function(std::pair<double, double> t
 * FieldParser's getByFileName method.
 */
FieldParser<double> ElectricFieldReaderModule::field_parser_(FieldQuantity::VECTOR);
FieldData<double> ElectricFieldReaderModule::read_field(std::pair<double, double> thickness_domain,
                                                        std::array<double, 2> field_scale) {
FieldData<double> ElectricFieldReaderModule::read_field() {

    try {
        LOG(TRACE) << "Fetching electric field from mesh file";
@@ -299,9 +301,6 @@ FieldData<double> ElectricFieldReaderModule::read_field(std::pair<double, double
        // Get field from file
        auto field_data = field_parser_.getByFileName(config_.getPath("file_name", true), "V/cm");

        // Check if electric field matches chip
        check_detector_match(field_data.getSize(), thickness_domain, field_scale);

        // Warn at field values larger than 1MV/cm / 10 MV/mm. Simple lookup per vector component, not total field magnitude
        auto max_field = *std::max_element(std::begin(*field_data.getData()), std::end(*field_data.getData()));
        if(max_field > 10) {
@@ -501,38 +500,3 @@ void ElectricFieldReaderModule::create_output_plots() {
    histogram_z->Write();
    histogram1D->Write();
}

/**
 * @brief Check if the detector matches the file header
 */
void ElectricFieldReaderModule::check_detector_match(std::array<double, 3> dimensions,
                                                     std::pair<double, double> thickness_domain,
                                                     std::array<double, 2> field_scale) {
    auto xpixsz = dimensions[0];
    auto ypixsz = dimensions[1];
    auto thickness = dimensions[2];

    auto model = detector_->getModel();
    // Do a several checks with the detector model
    if(model != nullptr) {
        // Check field dimension in z versus the requested thickness domain:
        auto eff_thickness = thickness_domain.second - thickness_domain.first;
        if(std::fabs(thickness - eff_thickness) > std::numeric_limits<double>::epsilon()) {
            LOG(WARNING) << "Thickness of electric field is " << Units::display(thickness, "um")
                         << " but the depleted region is " << Units::display(eff_thickness, "um");
        }

        // Check the field extent along the pixel pitch in x and y:
        auto pitch = model->getPixelSize();
        if(std::fabs(xpixsz - field_scale[0] * pitch.x()) > std::numeric_limits<double>::epsilon() ||
           std::fabs(ypixsz - field_scale[1] * pitch.y()) > std::numeric_limits<double>::epsilon()) {
            LOG(WARNING) << "Electric field size is (" << Units::display(xpixsz, {"um", "mm"}) << ","
                         << Units::display(ypixsz, {"um", "mm"})
                         << ") but current configuration results in an field area of ("
                         << Units::display(field_scale[0] * pitch.x(), {"um", "mm"}) << ","
                         << Units::display(field_scale[1] * pitch.y(), {"um", "mm"}) << ")" << std::endl
                         << "The size of the area to which the electric field is applied can be changes using the "
                            "field_scale parameter.";
        }
    }
}
Loading