Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-11-07 10:11:32

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/g4/DetectorConstruction.hh
0006 //---------------------------------------------------------------------------//
0007 #pragma once
0008 
0009 #include <functional>
0010 #include <map>
0011 #include <memory>
0012 #include <string>
0013 #include <G4VUserDetectorConstruction.hh>
0014 
0015 #include "geocel/GeantGdmlLoader.hh"
0016 
0017 class G4VSensitiveDetector;
0018 class G4LogicalVolume;
0019 
0020 namespace celeritas
0021 {
0022 class GeantGeoParams;
0023 //---------------------------------------------------------------------------//
0024 /*!
0025  * Load a GDML file and construct sensitive detectors.
0026  *
0027  * - In \c Construct on the main thread, load the GDML file (including
0028  *   detectors) and construct a Celeritas geometry wrapper
0029  * - In \c ConstructSDandField on each worker thread, call the SDBuilder for
0030  *   each distinct SD name, for all LVs that share the SD name
0031  *
0032  * \internal
0033  * \todo This is extracted from app/celer-g4; it should be extended and will
0034  * replace the app/celer-g4 construction.
0035  */
0036 class DetectorConstruction : public G4VUserDetectorConstruction
0037 {
0038   public:
0039     //!@{
0040     //! \name Type aliases
0041     using UPSD = std::unique_ptr<G4VSensitiveDetector>;
0042     using SDBuilder = std::function<UPSD(std::string const&)>;
0043     using SPGeoParams = std::shared_ptr<GeantGeoParams>;
0044     //!@}
0045 
0046   public:
0047     // Build with a GDML filename and a function to construct sensitive dets
0048     DetectorConstruction(std::string const& filename,
0049                          SDBuilder build_worker_sd);
0050 
0051     // Load the geometry on the main thread
0052     G4VPhysicalVolume* Construct() override;
0053 
0054     // Build SDs on worker threads
0055     void ConstructSDandField() override;
0056 
0057     //! Get the filename used by the GDML loader
0058     std::string const& filename() const { return filename_; }
0059 
0060     //! Access the constructed geometry etc
0061     SPGeoParams const& geo() const { return geo_; }
0062 
0063   private:
0064     //// TYPES ////
0065 
0066     using MapDetectors = GeantGdmlLoader::MapDetectors;
0067     using MapDetCIter = MapDetectors::const_iterator;
0068 
0069     //// DATA ////
0070 
0071     // Construction arguments
0072     std::string filename_;
0073     SDBuilder build_worker_sd_;
0074 
0075     // Built during Construct
0076     std::shared_ptr<GeantGeoParams> geo_;
0077     MapDetectors detectors_;
0078 
0079     //// METHODS ////
0080 
0081     void build_worker_sd() const;
0082 };
0083 
0084 //---------------------------------------------------------------------------//
0085 }  // namespace celeritas