Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-16 08:27:19

0001 //------------------------------- -*- C++ -*- -------------------------------//
0002 // Copyright Celeritas contributors: see top-level COPYRIGHT file for details
0003 // SPDX-License-Identifier: (Apache-2.0 OR MIT)
0004 //---------------------------------------------------------------------------//
0005 //! \file accel/TrackingManager.hh
0006 //---------------------------------------------------------------------------//
0007 #pragma once
0008 
0009 #include <G4Version.hh>
0010 #if G4VERSION_NUMBER < 1100
0011 #    error "Tracking manager offload requires Geant4 11.0 or higher"
0012 #endif
0013 
0014 #include <G4VTrackingManager.hh>
0015 
0016 namespace celeritas
0017 {
0018 //---------------------------------------------------------------------------//
0019 
0020 class SharedParams;
0021 class LocalTransporter;
0022 
0023 //---------------------------------------------------------------------------//
0024 /*!
0025  * Offload to Celeritas via the per-particle Geant4 "tracking manager".
0026  *
0027  * Tracking managers are to be created during worker action initialization and
0028  * are thus thread-local.  Construction/addition to \c G4ParticleDefinition
0029  * appears to take place on the master thread, typically
0030  * in the ConstructProcess method, but the tracking manager pointer is part of
0031  * the split-class data for the particle. It's observed that different threads
0032  * have distinct pointers to a LocalTransporter instance, and that these match
0033  * those of the global thread-local instances in test problems.
0034  *
0035  * \note As of Geant4 11.3, instances of this class (one per thread) will never
0036  * be deleted.
0037  */
0038 class TrackingManager final : public G4VTrackingManager
0039 {
0040   public:
0041     // Construct with shared (across threads) params, and thread-local
0042     // transporter.
0043     TrackingManager(SharedParams const* params, LocalTransporter* local);
0044 
0045     // Prepare cross-section tables for rebuild (e.g. if new materials have
0046     // been defined).
0047     void PreparePhysicsTable(G4ParticleDefinition const&) final;
0048 
0049     // Rebuild physics cross-section tables (e.g. if new materials have been
0050     // defined).
0051     void BuildPhysicsTable(G4ParticleDefinition const&) final;
0052 
0053     // Hand over passed track to this tracking manager.
0054     void HandOverOneTrack(G4Track* aTrack) final;
0055 
0056     // Complete processing of any buffered tracks.
0057     void FlushEvent() final;
0058 
0059     //// ACCESSORS ////
0060 
0061     //! Get the shared params associated with this TM
0062     SharedParams const* shared_params() const { return params_; }
0063 
0064     //! Get the thread-local transporter
0065     LocalTransporter* local_transporter() const { return transport_; }
0066 
0067   private:
0068     bool validated_{false};
0069     SharedParams const* params_{nullptr};
0070     LocalTransporter* transport_{nullptr};
0071 };
0072 
0073 //---------------------------------------------------------------------------//
0074 }  // namespace celeritas