src/modules/DepositionGeant4/DepositionGeant4Module.hpp

Definition of Geant4 deposition module. More…

Namespaces

Name
allpix
Helper class to hold support layers for a detector model.

Classes

Name
class allpix::DepositionGeant4Module
Module to simulate the particle beam and generating the charge deposits in the sensor.

Detailed Description

Definition of Geant4 deposition module.

Copyright: Copyright (c) 2017-2024 CERN and the Allpix Squared authors. This software is distributed under the terms of the MIT License, copied verbatim in the file “LICENSE.md”. In applying this license, CERN does not waive the privileges and immunities granted to it by virtue of its status as an Intergovernmental Organization or submit itself to any jurisdiction. SPDX-License-Identifier: MIT

Source code


#ifndef ALLPIX_SIMPLE_DEPOSITION_MODULE_H
#define ALLPIX_SIMPLE_DEPOSITION_MODULE_H

#include <atomic>
#include <memory>
#include <string>

#include <G4UserLimits.hh>

#include "core/config/Configuration.hpp"
#include "core/geometry/GeometryManager.hpp"
#include "core/messenger/Messenger.hpp"
#include "core/module/Event.hpp"
#include "core/module/Module.hpp"

#include "SensitiveDetectorActionG4.hpp"
#include "TrackInfoManager.hpp"

#include "tools/ROOT.h"

#include <TH1D.h>
#include <TH2D.h>

class G4UserLimits;
class G4RunManager;

namespace allpix {
    class DepositionGeant4Module : public SequentialModule {
        friend class SDAndFieldConstruction;
        friend class SetTrackInfoUserHookG4;

    public:
        DepositionGeant4Module(Configuration& config, Messenger* messenger, GeometryManager* geo_manager);

        void initialize() override;

        void initializeThread() override;

        void run(Event*) override;

        void finalizeThread() override;

        void finalize() override;

    protected:
        Messenger* messenger_;
        GeometryManager* geo_manager_;

        // Pointer to the Geant4 manager (owned by GeometryBuilderGeant4)
        G4RunManager* run_manager_g4_{nullptr};

        virtual void initialize_g4_action();

    private:
        void construct_sensitive_detectors_and_fields();

        void record_module_statistics();

        // Configuration parameters:
        bool output_plots_{};
        unsigned int number_of_particles_{};

        // The track manager which this module uses to assign custom track IDs and manage & create MCTracks
        static thread_local std::unique_ptr<TrackInfoManager> track_info_manager_;

        // Handling of the charge deposition in all the sensitive devices
        static thread_local std::vector<SensitiveDetectorActionG4*> sensors_;

        // Number of the last event
        std::atomic_uint64_t last_event_num_{0};

        // Class holding the limits for the step size
        std::unique_ptr<G4UserLimits> user_limits_;
        std::unique_ptr<G4UserLimits> user_limits_world_;

        // Vector of histogram pointers for debugging plots
        std::map<std::string, Histogram<TH1D>> charge_per_event_;
        std::map<std::string, Histogram<TH1D>> energy_per_event_;
        std::map<std::string, Histogram<TH2D>> incident_track_position_;

        // Total deposited charges
        std::atomic_uint total_charges_{0};

        std::atomic_size_t number_of_sensors_{0};

        // Mutex used for the construction of histograms
        std::mutex histogram_mutex_;
    };
} // namespace allpix

#endif /* ALLPIX_SIMPLE_DEPOSITION_MODULE_H */

Updated on 2025-02-27 at 14:14:46 +0000