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

Merge branch 'backport_g4_tracks' into 'v2.2-stable'

[v2.2-stable] DepositionGeant4: Enable Recording of All Tracks

See merge request allpix-squared/allpix-squared!677
parents 8de4db0a 0205454d
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -73,6 +73,8 @@ DepositionGeant4Module::DepositionGeant4Module(Configuration& config, Messenger*
    config_.setDefault<double>("max_step_length", Units::get(1.0, "um"));
    // Default value chosen to ensure proper gamma generation for Cs137 decay
    config_.setDefault<double>("cutoff_time", 2.21e+11);
    // By default, only record MCTracks connected to MCParticles in the sensitive volume
    config_.setDefault<bool>("record_all_tracks", false);

    // Create user limits for maximum step length and maximum event time in the sensor
    user_limits_ =
@@ -254,7 +256,7 @@ void DepositionGeant4Module::initialize() {
    // Construct the sensitive detectors and fields.
    if(run_manager_mt == nullptr) {
        // Create the info track manager for the main thread before creating the Sensitive detectors.
        track_info_manager_ = std::make_unique<TrackInfoManager>();
        track_info_manager_ = std::make_unique<TrackInfoManager>(config_.get<bool>("record_all_tracks"));
        construct_sensitive_detectors_and_fields(fano_factor, charge_creation_energy, cutoff_time);
    } else {
        // In MT-mode we register a builder that will be called for each thread to construct the SD when needed.
@@ -284,7 +286,7 @@ void DepositionGeant4Module::initializeThread() {
        // In MT-mode the sensitive detectors will be created with the calls to BeamOn. So we construct the
        // track manager for each calling thread here.
        if(track_info_manager_ == nullptr) {
            track_info_manager_ = std::make_unique<TrackInfoManager>();
            track_info_manager_ = std::make_unique<TrackInfoManager>(config_.get<bool>("record_all_tracks"));
        }

        run_manager_mt->InitializeForThread();
+1 −0
Original line number Diff line number Diff line
@@ -81,6 +81,7 @@ This module requires an installation Geant4.
* `source_type` : Shape of the source: **beam** (default), **point**, **square**, **sphere**, **macro**.
* `cutoff_time` : Maximum lifetime of particles to be propagated in the simulation. This setting is passed to Geant4 as user limit and assigned to all sensitive volumes. Particles and decay products are only propagated and decayed up the this time limit and all remaining kinetic energy is deposited in the sensor it reached the time limit in. Defaults to 221s (to ensure proper gamma creation for the Cs137 decay).
Note: Neutrons have a lifetime of 882 seconds and will not be propagated in the simulation with the default `cutoff_time`.
* `record_all_tracks` : Switch to enable the recording of all Geant4 tracks in the event. By default, this parameter is set to `false` and MCTrack objects are only generated for particles interacting with sensor material, not those that never interact with any detector.
* `number_of_particles` : Number of particles to generate in a single event. Defaults to one particle.
* `output_plots` : Enables output histograms to be be generated from the data in every step (slows down simulation considerably). Disabled by default.
* `output_plots_scale` : Set the x-axis scale of the output plot, defaults to 100ke.
+9 −2
Original line number Diff line number Diff line
@@ -11,7 +11,7 @@

using namespace allpix;

TrackInfoManager::TrackInfoManager() : counter_(1) {}
TrackInfoManager::TrackInfoManager(bool record_all) : counter_(1), record_all_(record_all) {}

std::unique_ptr<TrackInfoG4> TrackInfoManager::makeTrackInfo(const G4Track* const track) {
    auto custom_id = counter_++;
@@ -33,8 +33,15 @@ void TrackInfoManager::setTrackInfoToBeStored(int track_id) {
void TrackInfoManager::storeTrackInfo(std::unique_ptr<TrackInfoG4> the_track_info) {
    auto track_id = the_track_info->getID();
    auto element = std::find(to_store_track_ids_.begin(), to_store_track_ids_.end(), track_id);
    if(element != to_store_track_ids_.end()) {

    if(record_all_ || element != to_store_track_ids_.end()) {
        LOG(DEBUG) << "Storing MCTrack with ID " << track_id;
        stored_track_infos_.push_back(std::move(the_track_info));
    } else {
        LOG(DEBUG) << "Not storing MCTrack with ID " << track_id;
    }

    if(element != to_store_track_ids_.end()) {
        to_store_track_ids_.erase(element);
    }
}
+5 −1
Original line number Diff line number Diff line
@@ -29,7 +29,7 @@ namespace allpix {
        /**
         * @brief Default constructor
         */
        TrackInfoManager();
        explicit TrackInfoManager(bool record_all);

        /**
         * @brief Factory method for TrackInfoG4 instances
@@ -99,6 +99,10 @@ namespace allpix {

        // Counter to store highest assigned track id
        int counter_{};

        // Store configuration whether all tracks or only those connected to sensor should be stored
        bool record_all_{};

        // Geant4 id to custom id translation
        std::map<int, int> g4_to_custom_id_{};
        // Custom id to custom parent id tracking
+32 −0
Original line number Diff line number Diff line
# SPDX-FileCopyrightText: 2017-2022 CERN and the Allpix Squared authors
# SPDX-License-Identifier: MIT

#DESC runs a single Geant4 event and retrieves all tracks from the event, including those without connection to the sensor volume.
[Allpix]
detectors_file = "detector_scattering.conf"
number_of_events = 1
random_seed = 1

[GeometryBuilderGeant4]
world_material = "air"

[DepositionGeant4]
log_level = DEBUG
particle_type = "e-"
number_of_particles = 1
source_energy = 12GeV
source_position = 0um 0um -200mm
beam_size = 0
beam_direction = 0 0 1
record_all_tracks = true

[ElectricFieldReader]
model = "linear"
bias_voltage = 100V
depletion_voltage = 150V

[ProjectionPropagation]
temperature = 293K
propagate_holes = true

#PASS MCTrack originates at: (-2.19um,4.985um,-3.47689mm) and terminates at: (-2.711um,10.562um,-3.47454mm)
Loading