Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-22 10:31:20

0001 //----------------------------------*-C++-*----------------------------------//
0002 // Copyright 2020-2024 UT-Battelle, LLC, and other Celeritas developers.
0003 // See the top-level COPYRIGHT file for details.
0004 // SPDX-License-Identifier: (Apache-2.0 OR MIT)
0005 //---------------------------------------------------------------------------//
0006 //! \file celeritas/ext/detail/GeantProcessImporter.hh
0007 //---------------------------------------------------------------------------//
0008 #pragma once
0009 
0010 #include <memory>
0011 #include <unordered_map>
0012 #include <vector>
0013 
0014 #include "corecel/cont/Array.hh"
0015 #include "celeritas/io/ImportElement.hh"
0016 #include "celeritas/io/ImportMaterial.hh"
0017 #include "celeritas/io/ImportModel.hh"
0018 #include "celeritas/io/ImportPhysicsVector.hh"
0019 #include "celeritas/io/ImportProcess.hh"
0020 
0021 class G4VProcess;
0022 class G4VEmProcess;
0023 class G4VEmModel;
0024 class G4VEnergyLossProcess;
0025 class G4VMultipleScattering;
0026 class G4ParticleDefinition;
0027 class G4PhysicsTable;
0028 class G4PhysicsVector;
0029 class G4Physics2DVector;
0030 
0031 namespace celeritas
0032 {
0033 namespace detail
0034 {
0035 //---------------------------------------------------------------------------//
0036 /*!
0037  * Simplify the convoluted mechanism to store Geant4 process, model, and XS
0038  * table data.
0039  *
0040  * \c Operator() is expected to be used while looping over Geant4 particle and
0041  * process lists, and it returns a populated \c ImportProcess object. If said
0042  * process was already imported during a previous loop, it will return an
0043  * empty object. \c ImportProcess has an operator bool to check if said object
0044  * is not empty before adding it to the \c vector<ImportProcess> member of
0045  * \c ImportData .
0046  *
0047  * \code
0048  *  std::vector<ImportProcess> processes;
0049  *  GeantProcessImporter import(materials, elements);
0050  *
0051  *  G4ParticleTable::G4PTblDicIterator& particle_iterator
0052  *      = *(G4ParticleTable::GetParticleTable()->GetIterator());
0053  *  particle_iterator.reset();
0054  *
0055  *  while (particle_iterator())
0056  *  {
0057  *      const G4ParticleDefinition& g4_particle_def
0058  *          = *(particle_iterator.value());
0059  *      const G4ProcessVector& *process_list =
0060  *          *g4_particle_def.GetProcessManager()->GetProcessList();
0061  *
0062  *      for (int j = 0; j < process_list.size(); j++)
0063  *      {
0064  *          if (ImportProcess process
0065  *                  = import(g4_particle_def, *process_list[j]))
0066  *          {
0067  *              processes.push_back(std::move(process));
0068  *          }
0069  *      }
0070  *  }
0071  * \endcode
0072  */
0073 class GeantProcessImporter
0074 {
0075   public:
0076     // Construct with selected list of tables
0077     GeantProcessImporter(std::vector<ImportPhysMaterial> const& materials,
0078                          std::vector<ImportElement> const& elements);
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 };
0105 
0106 //---------------------------------------------------------------------------//
0107 // FREE FUNCTIONS
0108 //---------------------------------------------------------------------------//
0109 // Import a physics vector with the given x, y units
0110 ImportPhysicsVector
0111 import_physics_vector(G4PhysicsVector const& g4v, Array<ImportUnits, 2> units);
0112 
0113 // Import a 2D physics vector
0114 ImportPhysics2DVector import_physics_2dvector(G4Physics2DVector const& g4pv,
0115                                               Array<ImportUnits, 3> units);
0116 
0117 //---------------------------------------------------------------------------//
0118 }  // namespace detail
0119 }  // namespace celeritas