File indexing completed on 2025-12-17 09:22:03
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 , WorldSizeX(1000 * cm)
0036 , WorldSizeY(1000 * cm)
0037 , WorldSizeZ(1000 * cm)
0038 , worldshape("G4TUBS")
0039 , worldmaterial("G4_AIR")
0040 {
0041 return;
0042 }
0043
0044 PHG4PhenixDetector::~PHG4PhenixDetector()
0045 {
0046 while (m_DetectorList.begin() != m_DetectorList.end())
0047 {
0048 delete m_DetectorList.back();
0049 m_DetectorList.pop_back();
0050 }
0051 }
0052
0053
0054 G4VPhysicalVolume *PHG4PhenixDetector::Construct()
0055 {
0056 recoConsts *rc = recoConsts::instance();
0057 if (m_Verbosity > 0)
0058 {
0059 std::cout << "PHG4PhenixDetector::Construct." << std::endl;
0060 }
0061
0062 G4GeometryManager::GetInstance()->OpenGeometry();
0063 G4PhysicalVolumeStore::Clean();
0064 G4LogicalVolumeStore::Clean();
0065 G4SolidStore::Clean();
0066 if (m_Verbosity > 0)
0067 {
0068 std::cout << "PHG4PhenixDetector::Construct - cleaning done." << std::endl;
0069 }
0070
0071
0072 G4VSolid *solidWorld = nullptr;
0073 if (worldshape == "G4BOX")
0074 {
0075 solidWorld = new G4Box("World", WorldSizeX / 2, WorldSizeY / 2, WorldSizeZ / 2);
0076 }
0077 else if (worldshape == "G4Tubs")
0078 {
0079 solidWorld = new G4Tubs("World", 0., WorldSizeY / 2, WorldSizeZ / 2, 0, 2 * M_PI);
0080 }
0081 else
0082 {
0083 std::cout << "Unknown world shape " << worldshape << std::endl;
0084 std::cout << "implemented are G4BOX, G4Tubs" << std::endl;
0085 exit(1);
0086 }
0087 rc->set_StringFlag("WorldShape", solidWorld->GetEntityType());
0088 logicWorld = new G4LogicalVolume(solidWorld, G4Material::GetMaterial(worldmaterial), "World");
0089 m_DisplayAction->AddVolume(logicWorld, "World");
0090 physiWorld = new G4PVPlacement(nullptr, G4ThreeVector(), logicWorld, "World", nullptr, false, 0);
0091
0092 G4Region *defaultRegion = (*(G4RegionStore::GetInstance()))[0];
0093 PHG4RegionInformation *info = new PHG4RegionInformation();
0094 info->SetWorld();
0095 defaultRegion->SetUserInformation(info);
0096 if (m_Verbosity > 0)
0097 {
0098 std::cout << "PHG4PhenixDetector::Construct " << solidWorld->GetEntityType() << " world "
0099 << "material " << logicWorld->GetMaterial()->GetName() << " done." << std::endl;
0100 }
0101
0102
0103 for (PHG4Detector *det : m_DetectorList)
0104 {
0105 if (det)
0106 {
0107 det->Construct(logicWorld);
0108 }
0109 }
0110
0111 if (m_Verbosity > 0)
0112 {
0113 std::cout << "PHG4PhenixDetector::Construct - done." << std::endl;
0114 }
0115
0116
0117 for (PHG4Detector *det : m_DetectorList)
0118 {
0119 if (det)
0120 {
0121 det->PostConstruction();
0122 }
0123 }
0124
0125 if (m_Verbosity > 0)
0126 {
0127 std::cout << "PHG4PhenixDetector::PostConstruction - done." << std::endl;
0128 }
0129
0130 return physiWorld;
0131 }