Commit 8327fd32 authored by Simon Spannagel's avatar Simon Spannagel
Browse files

Explicitly round to integer, might allow compiler to optimize more than round to double

parent 3e295421
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -20,7 +20,7 @@ namespace allpix {

        // Return empty field if outside the matrix or no field is set
        auto [px, py] = model_->getPixelIndex(pos);
        if(!model_->isWithinMatrix(px, py) || type_ == FieldType::NONE) {
        if(type_ == FieldType::NONE || !model_->isWithinMatrix(px, py)) {
            return {};
        }

+3 −3
Original line number Diff line number Diff line
@@ -127,9 +127,9 @@ bool HexagonalPixelDetectorModel::areNeighbors(const Pixel::Index& seed,
// Rounding is more easy in cubic coordinates, so we need to reconstruct the third coordinate from the other two as z = - x -
// y:
std::pair<int, int> HexagonalPixelDetectorModel::round_to_nearest_hex(double x, double y) const {
    auto q = static_cast<int>(std::round(x));
    auto r = static_cast<int>(std::round(y));
    auto s = static_cast<int>(std::round(-x - y));
    auto q = static_cast<int>(std::lround(x));
    auto r = static_cast<int>(std::lround(y));
    auto s = static_cast<int>(std::lround(-x - y));
    double q_diff = std::abs(q - x);
    double r_diff = std::abs(r - y);
    double s_diff = std::abs(s - (-x - y));
+2 −2
Original line number Diff line number Diff line
@@ -85,8 +85,8 @@ ROOT::Math::XYZPoint PixelDetectorModel::getPixelCenter(const int x, const int y
}

std::pair<int, int> PixelDetectorModel::getPixelIndex(const ROOT::Math::XYZPoint& position) const {
    auto pixel_x = static_cast<int>(std::round(position.x() / pixel_size_.x()));
    auto pixel_y = static_cast<int>(std::round(position.y() / pixel_size_.y()));
    auto pixel_x = static_cast<int>(std::lround(position.x() / pixel_size_.x()));
    auto pixel_y = static_cast<int>(std::lround(position.y() / pixel_size_.y()));
    return {pixel_x, pixel_y};
}

+2 −2
Original line number Diff line number Diff line
@@ -87,7 +87,7 @@ void DepositionPointChargeModule::initialize() {

        // Scan with points required 3D scanning, scan with MIPs only 2D:
        if(type_ == SourceType::MIP) {
            root_ = static_cast<unsigned int>(std::round(std::sqrt(events)));
            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_;
@@ -96,7 +96,7 @@ void DepositionPointChargeModule::initialize() {
            voxel_ = ROOT::Math::XYZVector(
                model->getPixelSize().x() / root_, model->getPixelSize().y() / root_, model->getSensorSize().z());
        } else {
            root_ = static_cast<unsigned int>(std::round(std::cbrt(events)));
            root_ = static_cast<unsigned int>(std::lround(std::cbrt(events)));
            if(events != root_ * root_ * root_) {
                LOG(WARNING) << "Number of events is not a cube, pixel cell volume cannot fully be covered in scan. "
                             << "Closest cube is " << root_ * root_ * root_;
+1 −1
Original line number Diff line number Diff line
@@ -349,7 +349,7 @@ void GenericPropagationModule::run(Event* event) {
            PropagatedCharge propagated_charge(final_position,
                                               global_position,
                                               deposit.getType(),
                                               static_cast<unsigned int>(std::round(charge_per_step * gain)),
                                               static_cast<unsigned int>(std::lround(charge_per_step * gain)),
                                               deposit.getLocalTime() + time,
                                               deposit.getGlobalTime() + time,
                                               state,
Loading