File indexing completed on 2025-08-05 08:18:10
0001 #include "PHG4PhenixDetector.h"
0002
0003 #include "PHG4Detector.h"
0004 #include "PHG4DisplayAction.h" // for PHG4DisplayAction
0005 #include "PHG4PhenixDisplayAction.h"
0006 #include "PHG4Reco.h"
0007 #include "PHG4RegionInformation.h"
0008
0009 #include <phool/recoConsts.h>
0010
0011 #include <Geant4/G4Box.hh>
0012 #include <Geant4/G4GeometryManager.hh>
0013 #include <Geant4/G4LogicalVolume.hh> // for G4LogicalVolume
0014 #include <Geant4/G4LogicalVolumeStore.hh>
0015 #include <Geant4/G4Material.hh>
0016 #include <Geant4/G4PVPlacement.hh>
0017 #include <Geant4/G4PhysicalVolumeStore.hh>
0018 #include <Geant4/G4Region.hh>
0019 #include <Geant4/G4RegionStore.hh>
0020 #include <Geant4/G4SolidStore.hh>
0021 #include <Geant4/G4String.hh> // for G4String
0022 #include <Geant4/G4SystemOfUnits.hh>
0023 #include <Geant4/G4ThreeVector.hh> // for G4ThreeVector
0024 #include <Geant4/G4Tubs.hh>
0025 #include <Geant4/G4VSolid.hh> // for G4GeometryType, G4VSolid
0026
0027 #include <cmath>
0028 #include <cstdlib> // for exit
0029 #include <iostream>
0030 #include <vector> // for vector
0031
0032
0033 PHG4PhenixDetector::PHG4PhenixDetector(PHG4Reco *subsys)
0034 : m_DisplayAction(dynamic_cast<PHG4PhenixDisplayAction *>(subsys->GetDisplayAction()))
0035 , m_Verbosity(0)
0036 , logicWorld(nullptr)
0037 , physiWorld(nullptr)
0038 , WorldSizeX(1000 * cm)
0039 , WorldSizeY(1000 * cm)
0040 , WorldSizeZ(1000 * cm)
0041 , worldshape("G4TUBS")
0042 , worldmaterial("G4_AIR")
0043 {
0044 }
0045
0046 PHG4PhenixDetector::~PHG4PhenixDetector()
0047 {
0048 while (m_DetectorList.begin() != m_DetectorList.end())
0049 {
0050 delete m_DetectorList.back();
0051 m_DetectorList.pop_back();
0052 }
0053 }
0054
0055
0056 G4VPhysicalVolume *PHG4PhenixDetector::Construct()
0057 {
0058 recoConsts *rc = recoConsts::instance();
0059 if (m_Verbosity > 0)
0060 {
0061 std::cout << "PHG4PhenixDetector::Construct." << std::endl;
0062 }
0063
0064 G4GeometryManager::GetInstance()->OpenGeometry();
0065 G4PhysicalVolumeStore::GetInstance()->Clean();
0066 G4LogicalVolumeStore::GetInstance()->Clean();
0067 G4SolidStore::GetInstance()->Clean();
0068 if (m_Verbosity > 0)
0069 {
0070 std::cout << "PHG4PhenixDetector::Construct - cleaning done." << std::endl;
0071 }
0072
0073
0074 G4VSolid *solidWorld = nullptr;
0075 if (worldshape == "G4BOX")
0076 {
0077 solidWorld = new G4Box("World", WorldSizeX / 2, WorldSizeY / 2, WorldSizeZ / 2);
0078 }
0079 else if (worldshape == "G4Tubs")
0080 {
0081 solidWorld = new G4Tubs("World", 0., WorldSizeY / 2, WorldSizeZ / 2, 0, 2 * M_PI);
0082 }
0083 else
0084 {
0085 std::cout << "Unknown world shape " << worldshape << std::endl;
0086 std::cout << "implemented are G4BOX, G4Tubs" << std::endl;
0087 exit(1);
0088 }
0089 rc->set_StringFlag("WorldShape", solidWorld->GetEntityType());
0090 logicWorld = new G4LogicalVolume(solidWorld, G4Material::GetMaterial(worldmaterial), "World");
0091 m_DisplayAction->AddVolume(logicWorld, "World");
0092 physiWorld = new G4PVPlacement(nullptr, G4ThreeVector(), logicWorld, "World", nullptr, false, 0);
0093
0094 G4Region *defaultRegion = (*(G4RegionStore::GetInstance()))[0];
0095 PHG4RegionInformation *info = new PHG4RegionInformation();
0096 info->SetWorld();
0097 defaultRegion->SetUserInformation(info);
0098 if (m_Verbosity > 0)
0099 {
0100 std::cout << "PHG4PhenixDetector::Construct " << solidWorld->GetEntityType() << " world "
0101 << "material " << logicWorld->GetMaterial()->GetName() << " done." << std::endl;
0102 }
0103
0104
0105 for (PHG4Detector *det : m_DetectorList)
0106 {
0107 if (det)
0108 {
0109 det->Construct(logicWorld);
0110 }
0111 }
0112
0113 if (m_Verbosity > 0)
0114 {
0115 std::cout << "PHG4PhenixDetector::Construct - done." << std::endl;
0116 }
0117
0118
0119 for (PHG4Detector *det : m_DetectorList)
0120 {
0121 if (det)
0122 {
0123 det->PostConstruction();
0124 }
0125 }
0126
0127 if (m_Verbosity > 0)
0128 {
0129 std::cout << "PHG4PhenixDetector::PostConstruction - done." << std::endl;
0130 }
0131
0132 return physiWorld;
0133 }