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

Merge branch 'p-cosmics-area' into 'master'

p-cosmics-area

Closes #256

See merge request allpix-squared/allpix-squared!931
parents 7fbe1edf 5fad07e0
Loading
Loading
Loading
Loading
+30 −4
Original line number Diff line number Diff line
@@ -16,6 +16,9 @@
#include "tools/geant4/RunManager.hpp"
#include "tools/geant4/geant4.h"

#include <G4Box.hh>
#include <G4LogicalVolume.hh>

#include "../DepositionGeant4/ActionInitializationG4.hpp"

#include <filesystem>
@@ -110,25 +113,48 @@ DepositionCosmicsModule::DepositionCosmicsModule(Configuration& config, Messenge
    cry_config << " nParticlesMin " << config_.get<unsigned int>("min_particles") << " nParticlesMax "
               << config_.get<unsigned int>("max_particles");

    // Get G4 world size to check the subbox size
    double min_world_size_meters{0};
    auto world_log_volume = geo_manager_->getExternalObject<G4LogicalVolume>("", "world_log");
    if(world_log_volume != nullptr) {
        auto* world_box = static_cast<G4Box*>(world_log_volume->GetSolid());
        min_world_size_meters = 2e-3 * std::min(world_box->GetXHalfLength(), world_box->GetYHalfLength());
    }

    if(!config_.has("area")) {
        // Calculate subbox length required from the maximum coordinates of the setup:
        // Use maximum coordinate instead of setup size to make sure that off-center setups are fully covered
        LOG(DEBUG) << "Calculating subbox length from setup size";
        auto min = geo_manager_->getMinimumCoordinate();
        auto max = geo_manager_->getMaximumCoordinate();
        auto size = std::max(max.x() - min.x(), max.y() - min.y());
        auto size_meters = static_cast<unsigned int>(std::ceil(Units::convert(size, "m")));
        std::vector<double> max_candidates = {
            std::fabs(max.x()), std::fabs(max.y()), std::fabs(min.x()), std::fabs(min.y())};
        auto max_abs_coord = *std::max_element(begin(max_candidates), end(max_candidates));

        // Round margins up to 10 cm
        auto size_meters = static_cast<double>(std::ceil(Units::convert(2 * max_abs_coord, "m") * 10.0)) / 10.0;
        if(size_meters > 300) {
            throw ModuleError("Size of the setup too large, tabulated data only available for areas up to 300m");
        }
        LOG(DEBUG) << "Maximum side length (in x,y): " << Units::display(size, {"mm", "cm", "m"})

        if(min_world_size_meters < size_meters) {
            LOG(WARNING) << "Calculated subbox size does not fit in Geant4 world; undefined behaviour possible for "
                            "primaries generated outside the world box";
        }

        LOG(DEBUG) << "Maximum absolute coordinate (in x,y): " << Units::display(max_abs_coord, {"mm", "cm", "m"})
                   << ", selecting subbox of size " << size_meters << "m";
        cry_config << " subboxLength " << size_meters;
    } else {
        auto area = Units::convert(config_.get<int>("area"), "m");
        auto area = Units::convert(config_.get<double>("area"), "m");
        if(area > 300) {
            throw InvalidValueError(config_, "area", "only areas with side lengths of up to 300m are supported");
        }
        LOG(DEBUG) << "Configuring subbox of size " << area << "m from configuration parameter";
        if(min_world_size_meters < area) {
            LOG(WARNING) << "User-defined subbox size does not fit in Geant4 world; undefined behaviour possible for "
                            "primaries generated outside the world box";
        }
        cry_config << " subboxLength " << area;
    }

+1 −0
Original line number Diff line number Diff line
@@ -12,6 +12,7 @@ world_material = "air"

[DepositionCosmics]
physics_list = FTFP_BERT_LIV
area = 1m
number_of_particles = 1
log_level = DEBUG

+1 −0
Original line number Diff line number Diff line
@@ -12,6 +12,7 @@ world_material = "air"

[DepositionCosmics]
physics_list = FTFP_BERT_LIV
area = 1m
number_of_particles = 1
log_level = DEBUG

+2 −2
Original line number Diff line number Diff line
@@ -4,7 +4,7 @@
#DESC test if the correct subbox letngth for the simulated shower is calculated from the detector model and world volume
[AllPix]
number_of_events = 1
detectors_file = "detector_large.conf"
detectors_file = "detector_large_shifted.conf"
random_seed = 0
model_paths = "./"

@@ -15,5 +15,5 @@ world_material = "air"
physics_list = FTFP_BERT_LIV
log_level = DEBUG

#PASS Maximum side length (in x,y): 1.2445m, selecting subbox of size 2m
#PASS Maximum absolute coordinate (in x,y): 82.225cm, selecting subbox of size 1.7m
#FAIL FATAL
+1 −0
Original line number Diff line number Diff line
@@ -13,6 +13,7 @@ world_material = "air"
[DepositionCosmics]
physics_list = FTFP_BERT_LIV
number_of_particles = 1
area = 1m
log_level = DEBUG
altitude = 2100m

Loading