Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Geant4DetectorSurfaceFactoryTests.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file Geant4DetectorSurfaceFactoryTests.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 
9 #include <boost/test/unit_test.hpp>
10 
13 
14 #include <memory>
15 #include <string>
16 
17 #include "G4Box.hh"
18 #include "G4LogicalVolume.hh"
19 #include "G4PVPlacement.hh"
20 #include "G4RotationMatrix.hh"
21 #include "G4SystemOfUnits.hh"
22 #include "G4ThreeVector.hh"
23 #include "G4Transform3D.hh"
24 #include "G4Tubs.hh"
25 
26 class G4VPhysicalVolume;
27 
28 BOOST_AUTO_TEST_SUITE(Geant4Plugin)
29 
30 BOOST_AUTO_TEST_CASE(Geant4DetecturSurfaceFactory_box) {
31  G4Box* worldS = new G4Box("world", 100, 100, 100);
32 
33  G4LogicalVolume* worldLV = new G4LogicalVolume(worldS, nullptr, "World");
34 
35  G4Box* boxS = new G4Box("box", 10, 20, 20);
36  G4LogicalVolume* boxLV = new G4LogicalVolume(boxS, nullptr, "World");
37  G4VPhysicalVolume* boxPV = new G4PVPlacement(nullptr, G4ThreeVector(), boxLV,
38  "Box", worldLV, false, 0, true);
39 
40  G4Transform3D nominal;
41 
42  // Get the box
43  auto nameSelector =
44  std::make_shared<Acts::Geant4PhysicalVolumeSelectors::NameSelector>(
45  std::vector<std::string>{"ox"}, false);
46 
49  options.sensitiveSurfaceSelector = nameSelector;
50 
52  factory.construct(cache, nominal, *boxPV, options);
53 
54  BOOST_CHECK_EQUAL(cache.sensitiveSurfaces.size(), 1u);
55  BOOST_CHECK_EQUAL(cache.passiveSurfaces.size(), 0u);
56 
57  auto [element, surface] = cache.sensitiveSurfaces.front();
58  BOOST_CHECK(surface->type() == Acts::Surface::SurfaceType::Plane);
59 }
60 
61 BOOST_AUTO_TEST_CASE(Geant4DetecturSurfaceFactory_Cylinder) {
62  G4Box* worldS = new G4Box("world", 1000, 1000, 1000);
63 
64  G4LogicalVolume* worldLV = new G4LogicalVolume(worldS, nullptr, "World");
65 
66  G4Tubs* cylinderS =
67  new G4Tubs("cylinder", 99, 100, 100, -M_PI * CLHEP::radian,
68  2 * M_PI * CLHEP::radian);
69 
70  G4LogicalVolume* cylinderLV =
71  new G4LogicalVolume(cylinderS, nullptr, "World");
72  G4VPhysicalVolume* cylinderPV =
73  new G4PVPlacement(nullptr, G4ThreeVector(), cylinderLV, "Cylinder",
74  worldLV, false, 0, true);
75 
76  G4Transform3D nominal;
77 
78  // Get the box
79  auto nameSelector =
80  std::make_shared<Acts::Geant4PhysicalVolumeSelectors::NameSelector>(
81  std::vector<std::string>{"yl"}, false);
82 
85  options.sensitiveSurfaceSelector = nameSelector;
86 
88  factory.construct(cache, nominal, *cylinderPV, options);
89 
90  BOOST_CHECK_EQUAL(cache.sensitiveSurfaces.size(), 1u);
91  BOOST_CHECK_EQUAL(cache.passiveSurfaces.size(), 0u);
92 
93  auto [element, surface] = cache.sensitiveSurfaces.front();
94  BOOST_CHECK(surface->type() == Acts::Surface::SurfaceType::Cylinder);
95 }
96 
97 BOOST_AUTO_TEST_SUITE_END()