Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Geant4Simulation.hpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file Geant4Simulation.hpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2017-2021 CERN for the benefit of the Acts project
4 //
5 // This Source Code Form is subject to the terms of the Mozilla Public
6 // License, v. 2.0. If a copy of the MPL was not distributed with this
7 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 
9 #pragma once
10 
19 
20 #include <cstddef>
21 #include <memory>
22 #include <string>
23 #include <unordered_map>
24 
25 class G4RunManager;
26 class G4VUserPrimaryGeneratorAction;
27 class G4VUserDetectorConstruction;
28 class G4UserRunAction;
29 class G4UserEventAction;
30 class G4UserTrackingAction;
31 class G4UserSteppingAction;
32 class G4MagneticField;
33 class G4VUserPhysicsList;
34 class G4FieldManager;
35 
36 namespace Acts {
37 class TrackingGeometry;
38 class MagneticFieldProvider;
39 class Volume;
40 } // namespace Acts
41 
42 class G4VUserDetectorConstruction;
43 
44 namespace ActsExamples {
45 
46 class DetectorConstructionFactory;
47 class SensitiveSurfaceMapper;
48 struct EventStore;
49 struct Geant4Handle;
50 
53  public:
55  struct Config {
56  // Name of the input particle collection
58 
60  std::shared_ptr<const RandomNumbers> randomNumbers;
61 
64  std::shared_ptr<DetectorConstructionFactory> detectorConstructionFactory;
65 
67  std::shared_ptr<Geant4Handle> geant4Handle;
68  };
69 
72 
73  ~Geant4SimulationBase() override;
74 
76  ProcessCode initialize() final;
77 
81  ActsExamples::ProcessCode execute(
82  const ActsExamples::AlgorithmContext& ctx) const override;
83 
85  virtual const Config& config() const = 0;
86 
87  std::shared_ptr<Geant4Handle> geant4Handle() const;
88 
89  protected:
90  void commonInitialization();
91 
92  G4RunManager& runManager() const;
93 
94  EventStore& eventStore() const;
95 
96  std::unique_ptr<const Acts::Logger> m_logger;
97 
99 
101 
102  std::shared_ptr<Geant4Handle> m_geant4Instance;
103 
106  G4VUserDetectorConstruction* m_detectorConstruction{};
107 
109 };
110 
113  public:
117 
119  std::string outputParticlesInitial = "particles_initial";
120 
122  std::string outputParticlesFinal = "particles_final";
123 
125  std::shared_ptr<const Acts::TrackingGeometry> trackingGeometry;
126 
128  std::shared_ptr<const Acts::MagneticFieldProvider> magneticField;
129 
131  std::string physicsList = "FTFP_BERT";
132 
133  std::vector<std::string> volumeMappings;
134 
135  std::vector<std::string> materialMappings = {"Silicon"};
136 
137  std::shared_ptr<const Acts::Volume> killVolume;
138  double killAfterTime = std::numeric_limits<double>::infinity();
139  bool killSecondaries = false;
140 
142 
144  };
145 
150  Geant4Simulation(const Config& cfg,
152 
153  ~Geant4Simulation() override;
154 
159  const ActsExamples::AlgorithmContext& ctx) const final;
160 
162  const Config& config() const final { return m_cfg; }
163 
164  private:
166 
168  std::unique_ptr<G4MagneticField> m_magneticField;
169  std::unique_ptr<G4FieldManager> m_fieldManager;
170 
172  this, "OutputParticlesInitial"};
174  this, "OutputParticlesFinal"};
176 };
177 
179  public:
182  std::string outputMaterialTracks = "material_tracks";
183 
185  std::vector<std::string> excludeMaterials = {"Air", "Vacuum"};
186  };
187 
194 
195  ~Geant4MaterialRecording() override;
196 
201  const ActsExamples::AlgorithmContext& ctx) const final;
202 
204  const Config& config() const final { return m_cfg; }
205 
206  private:
208 
210  m_outputMaterialTracks{this, "OutputMaterialTracks"};
211 };
212 
213 } // namespace ActsExamples