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

Coverity: fix some possible division by zero & floating point division

parent 412c8de4
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -145,7 +145,7 @@ void DetectorHistogrammerModule::initialize() {
    // Create cluster size plots, preventing a zero-bin histogram by scaling with integer ceiling: (x + y - 1) / y
    std::string cluster_size_title = "Cluster size for " + detector_->getName() + ";cluster size [px];clusters";
    cluster_size = CreateHistogram<TH1D>(
        "cluster_size", cluster_size_title.c_str(), (xpixels * ypixels + 9) / 10, 0.5, (xpixels * ypixels + 9) / 10 + 0.5);
        "cluster_size", cluster_size_title.c_str(), (xpixels * ypixels + 9) / 10, 0.5, (xpixels * ypixels + 9.0) / 10 + 0.5);

    std::string cluster_size_x_title = "Cluster size X for " + detector_->getName() + ";cluster size x [px];clusters";
    cluster_size_x = CreateHistogram<TH1D>("cluster_size_x", cluster_size_x_title.c_str(), xpixels, 0.5, xpixels + 0.5);
+2 −2
Original line number Diff line number Diff line
@@ -341,8 +341,8 @@ void ProjectionPropagationModule::run(Event* event) {
    }
    charge_lost = total_charge - total_projected_charge;

    LOG(INFO) << "Total charge: " << total_charge << " (lost: " << charge_lost << ", " << (charge_lost / total_charge * 100.)
              << "%)";
    LOG(INFO) << "Total charge: " << total_charge << " (lost: " << charge_lost << ", "
              << (charge_lost / (total_charge == 0 ? 1 : total_charge) * 100.) << "%)";
    LOG(DEBUG) << "Total count of propagated charge carriers: " << propagated_charges.size();

    if(output_plots_) {
+2 −2
Original line number Diff line number Diff line
@@ -231,8 +231,8 @@ void TransientPropagationModule::run(Event* event) {
    }

    if(output_plots_) {
        recombine_histo_->Fill(static_cast<double>(recombined_charges_count) /
                               (propagated_charges_count + recombined_charges_count));
        auto total = (propagated_charges_count + recombined_charges_count);
        recombine_histo_->Fill(static_cast<double>(recombined_charges_count) / (total == 0 ? 1 : total));
    }

    // Create a new message with propagated charges