Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Geant4DetectorSurfaceFactory.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file Geant4DetectorSurfaceFactory.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2022 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 
15 
16 #include <utility>
17 
18 #include "G4LogicalVolume.hh"
19 #include "G4VPhysicalVolume.hh"
20 
22  Cache& cache, const G4Transform3D& g4ToGlobal,
23  const G4VPhysicalVolume& g4PhysVol, const Options& option) {
24  // Get Rotation and translation
25  auto g4Translation = g4PhysVol.GetTranslation();
26  auto g4Rotation = g4PhysVol.GetRotation();
27 
28  G4Transform3D g4Transform =
29  (g4Rotation == nullptr)
30  ? G4Transform3D(CLHEP::HepRotation(), g4Translation)
31  : G4Transform3D(*g4Rotation, g4Translation);
32 
33  G4Transform3D newToGlobal = g4ToGlobal * g4Transform;
34 
35  // Get the logical volume
36  auto g4LogicalVolume = g4PhysVol.GetLogicalVolume();
37  std::size_t nDaughters = g4LogicalVolume->GetNoDaughters();
38  for (std::size_t d = 0; d < nDaughters; ++d) {
39  auto daughter = g4LogicalVolume->GetDaughter(d);
40  construct(cache, newToGlobal, *daughter, option);
41  }
42 
43  // Check if the volume is accepted by a sensitive or passive selector
44  bool sensitive = option.sensitiveSurfaceSelector != nullptr and
45  option.sensitiveSurfaceSelector->select(g4PhysVol);
46  bool passive = option.passiveSurfaceSelector != nullptr and
47  option.passiveSurfaceSelector->select(g4PhysVol);
48 
49  if (sensitive or passive) {
50  // Conversion and selection code
51  ++cache.matchedG4Volumes;
52 
53  // Attempt the conversion
55  g4PhysVol, Geant4AlgebraConverter{}.transform(newToGlobal),
57 
58  if (surface != nullptr) {
59  ++cache.convertedSurfaces;
60  // Count the material conversion
61  if (surface->surfaceMaterial() != nullptr) {
62  ++cache.convertedMaterials;
63  }
64 
65  if (sensitive) {
66  // empty geometry context is fine as the transform was just passed down
67  // without context before
68  auto detectorElement = std::make_shared<Acts::Geant4DetectorElement>(
69  surface, g4PhysVol, surface->transform({}), 0.1);
70  surface->assignDetectorElement(*detectorElement);
71 
72  cache.sensitiveSurfaces.push_back(
73  {std::move(detectorElement), std::move(surface)});
74  } else {
75  cache.passiveSurfaces.push_back(std::move(surface));
76  }
77  }
78  }
79 }