Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-18 09:09:02

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 celeritas/ext/detail/GeantProcessImporter.hh
0006 //---------------------------------------------------------------------------//
0007 #pragma once
0008 
0009 #include <memory>
0010 #include <unordered_map>
0011 #include <vector>
0012 
0013 #include "corecel/cont/Array.hh"
0014 #include "celeritas/inp/Grid.hh"
0015 #include "celeritas/io/ImportElement.hh"
0016 #include "celeritas/io/ImportMaterial.hh"
0017 #include "celeritas/io/ImportModel.hh"
0018 #include "celeritas/io/ImportProcess.hh"
0019 
0020 class G4VProcess;
0021 class G4VEmProcess;
0022 class G4VEmModel;
0023 class G4VEnergyLossProcess;
0024 class G4VMultipleScattering;
0025 class G4ParticleDefinition;
0026 class G4PhysicsTable;
0027 class G4PhysicsVector;
0028 class G4Physics2DVector;
0029 
0030 namespace celeritas
0031 {
0032 namespace detail
0033 {
0034 //---------------------------------------------------------------------------//
0035 /*!
0036  * Simplify the convoluted mechanism to store Geant4 process, model, and XS
0037  * table data.
0038  *
0039  * \c Operator() is expected to be used while looping over Geant4 particle and
0040  * process lists, and it returns a populated \c ImportProcess object. If said
0041  * process was already imported during a previous loop, it will return an
0042  * empty object. \c ImportProcess has an operator bool to check if said object
0043  * is not empty before adding it to the \c vector<ImportProcess> member of
0044  * \c ImportData .
0045  *
0046  * \code
0047  *  std::vector<ImportProcess> processes;
0048  *  GeantProcessImporter import(materials, elements);
0049  *
0050  *  G4ParticleTable::G4PTblDicIterator& particle_iterator
0051  *      = *(G4ParticleTable::GetParticleTable()->GetIterator());
0052  *  particle_iterator.reset();
0053  *
0054  *  while (particle_iterator())
0055  *  {
0056  *      const G4ParticleDefinition& g4_particle_def
0057  *          = *(particle_iterator.value());
0058  *      const G4ProcessVector& *process_list =
0059  *          *g4_particle_def.GetProcessManager()->GetProcessList();
0060  *
0061  *      for (int j = 0; j < process_list.size(); j++)
0062  *      {
0063  *          if (ImportProcess process
0064  *                  = import(g4_particle_def, *process_list[j]))
0065  *          {
0066  *              processes.push_back(std::move(process));
0067  *          }
0068  *      }
0069  *  }
0070  * \endcode
0071  */
0072 class GeantProcessImporter
0073 {
0074   public:
0075     // Construct with selected list of tables
0076     GeantProcessImporter(std::vector<ImportPhysMaterial> const& materials,
0077                          std::vector<ImportElement> const& elements,
0078                          inp::Interpolation interpolation);
0079 
0080     // Import processes
0081     ImportProcess operator()(G4ParticleDefinition const& particle,
0082                              G4VEmProcess const& process);
0083     ImportProcess operator()(G4ParticleDefinition const& particle,
0084                              G4VEnergyLossProcess const& process);
0085     std::vector<ImportMscModel>
0086     operator()(G4ParticleDefinition const& particle,
0087                G4VMultipleScattering const& process);
0088 
0089   private:
0090     //// TYPES ////
0091 
0092     struct PrevTable
0093     {
0094         int particle_pdg;
0095         celeritas::ImportProcessClass process_class;
0096         celeritas::ImportTableType table_type;
0097     };
0098 
0099     //// DATA ////
0100 
0101     // Store material and element information for the element selector tables
0102     std::vector<ImportPhysMaterial> const& materials_;
0103     std::vector<ImportElement> const& elements_;
0104     inp::Interpolation interpolation_;
0105 };
0106 
0107 //---------------------------------------------------------------------------//
0108 // FREE FUNCTIONS
0109 //---------------------------------------------------------------------------//
0110 // Import a uniform physics vector with the given x, y units
0111 inp::UniformGrid
0112 import_physics_log_vector(G4PhysicsVector const&, Array<ImportUnits, 2>);
0113 
0114 // Import a generic physics vector with the given x, y units
0115 inp::Grid import_physics_vector(G4PhysicsVector const&, Array<ImportUnits, 2>);
0116 
0117 // Import a 2D physics vector
0118 inp::TwodGrid
0119 import_physics_2dvector(G4Physics2DVector const&, Array<ImportUnits, 3>);
0120 
0121 //---------------------------------------------------------------------------//
0122 }  // namespace detail
0123 }  // namespace celeritas