Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Geant4Detector.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file Geant4Detector.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2022-2023 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 
10 
19 
20 #include <ostream>
21 #include <stdexcept>
22 
23 #include "G4VPhysicalVolume.hh"
24 
27  const Acts::Logger& logger)
28  -> std::tuple<DetectorPtr, ContextDecorators, DetectorElements> {
29  if (cfg.g4World == nullptr) {
30  throw std::invalid_argument(
31  "Geant4Detector: no world Geant4 volume provided");
32  }
33 
34  ACTS_INFO("Building an Acts::Detector called '"
35  << cfg.name << "' from the Geant4PhysVolume '"
36  << cfg.g4World->GetName());
37 
38  DetectorPtr detector = nullptr;
40 
41  auto [surfaces, elements] = convertGeant4Volumes(cfg, logger);
42 
43  return std::tie(detector, decorators, elements);
44 }
45 
48  const Acts::Logger& logger)
49  -> std::tuple<TrackingGeometryPtr, ContextDecorators, DetectorElements> {
50  if (cfg.g4World == nullptr) {
51  throw std::invalid_argument(
52  "Geant4Detector: no world Geant4 volume provided");
53  }
54 
55  ACTS_INFO("Building an Acts::TrackingGeometry called '"
56  << cfg.name << "' from the Geant4PhysVolume '"
57  << cfg.g4World->GetName());
58 
60 
61  auto [surfaces, elements] = convertGeant4Volumes(cfg, logger);
62 
63  // Surface array creator
64  auto surfaceArrayCreator = std::make_shared<const Acts::SurfaceArrayCreator>(
65  Acts::SurfaceArrayCreator::Config(), logger.clone("SurfaceArrayCreator"));
66  // Layer Creator
68  lcConfig.surfaceArrayCreator = surfaceArrayCreator;
69  auto layerCreator = std::make_shared<Acts::LayerCreator>(
70  lcConfig, logger.clone("LayerCreator"));
71  // Layer array creator
73  auto layerArrayCreator = std::make_shared<const Acts::LayerArrayCreator>(
74  lacConfig, logger.clone("LayerArrayCreator"));
75  // Tracking volume array creator
77  auto tVolumeArrayCreator =
78  std::make_shared<const Acts::TrackingVolumeArrayCreator>(
79  tvacConfig, logger.clone("TrackingVolumeArrayCreator"));
80  // configure the cylinder volume helper
82  cvhConfig.layerArrayCreator = layerArrayCreator;
83  cvhConfig.trackingVolumeArrayCreator = tVolumeArrayCreator;
84  auto cylinderVolumeHelper =
85  std::make_shared<const Acts::CylinderVolumeHelper>(
86  cvhConfig, logger.clone("CylinderVolumeHelper"));
87 
88  // Configure the tracking geometry builder, copy the surfaces in
90  kdtCfg.surfaces = surfaces;
91  kdtCfg.layerCreator = layerCreator;
92  kdtCfg.trackingVolumeHelper = cylinderVolumeHelper;
93  kdtCfg.protoDetector = cfg.protoDetector;
94  kdtCfg.geometryIdentifierHook = cfg.geometryIdentifierHook;
95 
96  // The KDT tracking geometry builder
97  auto kdtBuilder = Acts::KDTreeTrackingGeometryBuilder(
98  kdtCfg, logger.clone("KDTreeTrackingGeometryBuilder"));
99 
101  TrackingGeometryPtr trackingGeometry = kdtBuilder.trackingGeometry(tContext);
102 
103  return std::tie(trackingGeometry, decorators, elements);
104 }
105 
107  const Geant4Detector::Config& cfg, const Acts::Logger& logger) const
110  // Generate the surface cache
112  G4Transform3D g4ToWorld;
113 
115  g4SurfaceCache, g4ToWorld, *cfg.g4World, cfg.g4SurfaceOptions);
116 
117  ACTS_INFO("Found " << g4SurfaceCache.matchedG4Volumes
118  << " matching Geant4 Physical volumes.");
119  ACTS_INFO("Found " << g4SurfaceCache.sensitiveSurfaces.size()
120  << " converted sensitive Geant4 Physical volumes.");
121  ACTS_INFO("Found " << g4SurfaceCache.passiveSurfaces.size()
122  << " converted passive Geant4 Physical volumes.");
123  ACTS_INFO("Found " << g4SurfaceCache.convertedMaterials
124  << " converted Geant4 Material slabs.");
125 
126  Surfaces surfaces = {};
127  DetectorElements elements = {};
128 
129  // Reserve the right amount of surfaces
130  surfaces.reserve(g4SurfaceCache.sensitiveSurfaces.size() +
131  g4SurfaceCache.passiveSurfaces.size());
132  elements.reserve(g4SurfaceCache.sensitiveSurfaces.size());
133 
134  // Add the sensitive surfaces
135  for (const auto& [e, s] : g4SurfaceCache.sensitiveSurfaces) {
136  elements.push_back(e);
137  surfaces.push_back(s);
138  }
139  // Add the passive surfaces
140  surfaces.insert(surfaces.end(), g4SurfaceCache.passiveSurfaces.begin(),
141  g4SurfaceCache.passiveSurfaces.end());
142 
143  return std::tie(surfaces, elements);
144 }