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

Made 1D and 2D scans work as intended, by providing a combination of x,y,z to "scan_coordinates".

parent e29788b1
Loading
Loading
Loading
Loading
+36 −15
Original line number Diff line number Diff line
@@ -93,19 +93,23 @@ void DepositionPointChargeModule::initialize() {
        // Get the config manager and retrieve total number of events:
        ConfigManager* conf_manager = getConfigManager();
        auto events = conf_manager->getGlobalConfiguration().get<unsigned int>("number_of_events");
        auto scan_coordinates_ = config_.getArray<std::string>("scan_coordinates", {"x", "y", "z"});
        scan_coordinates_ = config_.getArray<std::string>("scan_coordinates", {"x", "y", "z"});

        scan_x_ = std::find(scan_coordinates_.begin(), scan_coordinates_.end(), "x") != scan_coordinates_.end();
        scan_y_ = std::find(scan_coordinates_.begin(), scan_coordinates_.end(), "y") != scan_coordinates_.end();
        scan_z_ = std::find(scan_coordinates_.begin(), scan_coordinates_.end(), "z") != scan_coordinates_.end();

        // Scan with points required 3D scanning, scan with MIPs only 2D:
        if(scan_coordinates_.size() == 1) {
            root_ = events;
            // Calculate voxel size:
            if(std::find(scan_coordinates_.begin(), scan_coordinates_.end(), "x") != scan_coordinates_.end()) {
            if(scan_x_) {
                voxel_ = ROOT::Math::XYZVector(
                    model->getPixelSize().x() / root_, model->getPixelSize().y(), model->getSensorSize().z());
            } else if(std::find(scan_coordinates_.begin(), scan_coordinates_.end(), "y") != scan_coordinates_.end()) {
            } else if(scan_y_) {
                voxel_ = ROOT::Math::XYZVector(
                    model->getPixelSize().x(), model->getPixelSize().y() / root_, model->getSensorSize().z());
            } else if(std::find(scan_coordinates_.begin(), scan_coordinates_.end(), "z") != scan_coordinates_.end()) {
            } else if(scan_z_) {
                voxel_ = ROOT::Math::XYZVector(
                    model->getPixelSize().x(), model->getPixelSize().y(), model->getSensorSize().z() / root_);
            } else {
@@ -113,21 +117,18 @@ void DepositionPointChargeModule::initialize() {
            }
        } else if(scan_coordinates_.size() == 2) {
            // Throw if we don't have a valid combination. Need 2 valid entries; x y, x z, or y z
            bool has_x = std::find(scan_coordinates_.begin(), scan_coordinates_.end(), "x") != scan_coordinates_.end();
            bool has_y = std::find(scan_coordinates_.begin(), scan_coordinates_.end(), "y") != scan_coordinates_.end();
            bool has_z = std::find(scan_coordinates_.begin(), scan_coordinates_.end(), "z") != scan_coordinates_.end();
            root_ = static_cast<unsigned int>(std::lround(std::sqrt(events)));
            if(events != root_ * root_) {
                LOG(WARNING) << "Number of events is not a square, pixel cell volume cannot fully be covered in scan. "
                             << "Closest square is " << root_ * root_;
            }
            if(has_x && has_y) {
            if(scan_x_ && scan_y_) {
                voxel_ = ROOT::Math::XYZVector(
                    model->getPixelSize().x() / root_, model->getPixelSize().y() / root_, model->getSensorSize().z());
            } else if(has_x && has_z) {
            } else if(scan_x_ && scan_z_) {
                voxel_ = ROOT::Math::XYZVector(
                    model->getPixelSize().x() / root_, model->getPixelSize().y(), model->getSensorSize().z() / root_);
            } else if(has_y && has_z) {
            } else if(scan_y_ && scan_z_) {
                voxel_ = ROOT::Math::XYZVector(
                    model->getPixelSize().x(), model->getPixelSize().y() / root_, model->getSensorSize().z() / root_);
            } else {
@@ -172,11 +173,31 @@ void DepositionPointChargeModule::run(Event* event) {
                   ROOT::Math::XYZVector(
                       model->getPixelSize().x() / 2.0, model->getPixelSize().y() / 2.0, model->getSensorSize().z() / 2.0);
        LOG(DEBUG) << "Reference: " << Units::display(ref, {"um", "mm"});
        position = ROOT::Math::XYZPoint(voxel_.x() * static_cast<double>((event->number - 1) % root_),
        if(scan_coordinates_.size() == 3) {
            position =
                ROOT::Math::XYZPoint(voxel_.x() * static_cast<double>((event->number - 1) % root_),
                                     voxel_.y() * static_cast<double>(((event->number - 1) / root_) % root_),
                                     voxel_.z() * static_cast<double>(((event->number - 1) / root_ / root_) % root_)) +
                ref;
        LOG(DEBUG) << "In-pixel deposition position: " << Units::display(position - ref, {"um", "mm"});
        } else {
            position = ref;
            if(scan_x_) {
                position.SetX(voxel_.x() * static_cast<double>((event->number - 1) % root_) + ref.x());
                if(scan_y_) {
                    position.SetY(voxel_.y() * static_cast<double>(((event->number - 1) / root_) % root_) + ref.y());
                } else if(scan_z_) {
                    position.SetZ(voxel_.z() * static_cast<double>(((event->number - 1) / root_) % root_) + ref.z());
                }
            } else if(scan_y_) {
                position.SetY(voxel_.y() * static_cast<double>((event->number - 1) % root_) + ref.y());
                if(scan_z_) {
                    position.SetZ(voxel_.z() * static_cast<double>(((event->number - 1) / root_) % root_) + ref.z());
                }
            } else {
                position.SetZ(voxel_.z() * static_cast<double>((event->number - 1) % root_) + ref.z());
            }
        }
        LOG(WARNING) << "Deposition position in local coordinates: " << Units::display(position, {"um", "mm"});
    } else {
        // Calculate random offset from configured position
        auto shift = [&](auto size) {
+5 −0
Original line number Diff line number Diff line
@@ -83,5 +83,10 @@ namespace allpix {
        double step_size_z_{};
        unsigned int root_{}, carriers_{};
        ROOT::Math::XYZVector position_{};
        std::vector<std::string> scan_coordinates_{};

        bool scan_x_;
        bool scan_y_;
        bool scan_z_;
    };
} // namespace allpix
+1 −1
Original line number Diff line number Diff line
@@ -33,7 +33,7 @@ All charge carriers are deposited at time zero, i.e. at the beginning of the eve
* `source_type`: Modeled source type for the deposition of charge carriers. For `point`, charge carriers are deposited at the position given by the `position` parameter. For `mip`, charge carriers are deposited along a line through the full sensor thickness. Defaults to `point`.
* `position`: Position in local coordinates of the sensor, where charge carriers should be deposited. Expects three values for local-x, local-y and local-z position in the sensor volume and defaults to `0um 0um 0um`, i.e. the center of first (lower left) pixel. When using source type `mip`, providing a 2D position is sufficient since it only uses the x and y coordinates. If used in scan mode, it allows you to shift the origin of each deposited charge by adding this value. If the scan is only performed in one or two dimensions, the remaining coordinate will constantly have the value given by `position`.
* `spot_size`: Width of the Gaussian distribution used to smear the position in the `spot` model. Only one value is taken and used for all three dimensions.
* `scan_coordinates`: Coordinates to scan over, a combiantion of x, y, z. Defaults to `xyz`, i.e. all three spatial coordinates. The `position`parameter is used to determine the value of the coordiantes that are not scanned over, if a partial scan is requested.
* `scan_coordinates`: Coordinates to scan over, a combiantion of x, y, z. Defaults to `x y z`, i.e. all three spatial coordinates. The `position`parameter is used to determine the value of the coordiantes that are not scanned over if a partial scan is requested, and the start offset of the scan for the other coordinates.

## Usage