File indexing completed on 2025-08-05 08:18:08
0001 #include "PHG4Detector.h"
0002
0003 #include "PHG4Subsystem.h"
0004
0005 #include <TSystem.h>
0006
0007 #include <Geant4/G4Colour.hh> // for G4Colour
0008 #include <Geant4/G4Element.hh>
0009 #include <Geant4/G4LogicalVolume.hh>
0010 #include <Geant4/G4Material.hh>
0011 #include <Geant4/G4NistManager.hh>
0012 #include <Geant4/G4PVPlacement.hh>
0013 #include <Geant4/G4RotationMatrix.hh> // for G4RotationMatrix
0014 #include <Geant4/G4ThreeVector.hh> // for G4ThreeVector
0015 #include <Geant4/G4VisAttributes.hh>
0016
0017 #pragma GCC diagnostic push
0018 #pragma GCC diagnostic ignored "-Wshadow"
0019 #include <boost/stacktrace.hpp>
0020 #pragma GCC diagnostic pop
0021
0022 #include <cstdlib>
0023
0024 PHG4Detector::PHG4Detector(PHG4Subsystem *subsys, PHCompositeNode *Node, const std::string &nam)
0025 : m_topNode(Node)
0026 , m_MySubsystem(subsys)
0027 , m_Name(nam)
0028 {
0029 }
0030
0031 void PHG4Detector::Construct(G4LogicalVolume *world)
0032 {
0033 PHG4Subsystem *MyMotherSubsystem = m_MySubsystem->GetMotherSubsystem();
0034 if (MyMotherSubsystem)
0035 {
0036 ConstructMe(MyMotherSubsystem->GetLogicalVolume());
0037 }
0038 else
0039 {
0040 ConstructMe(world);
0041 }
0042 return;
0043 }
0044
0045 int PHG4Detector::DisplayVolume(G4VSolid *volume, G4LogicalVolume *logvol, G4RotationMatrix *rotm)
0046 {
0047 G4LogicalVolume *checksolid = new G4LogicalVolume(volume, G4Material::GetMaterial("G4_POLYSTYRENE"), "DISPLAYLOGICAL", nullptr, nullptr, nullptr);
0048 int iret = DisplayVolume(checksolid, logvol, rotm);
0049 return iret;
0050 }
0051
0052 int PHG4Detector::DisplayVolume(G4LogicalVolume *checksolid, G4LogicalVolume *logvol, G4RotationMatrix *rotm)
0053 {
0054 G4VisAttributes *visattchk = new G4VisAttributes();
0055 visattchk->SetVisibility(true);
0056 visattchk->SetForceSolid(false);
0057 switch (m_ColorIndex)
0058 {
0059 case 0:
0060 visattchk->SetColour(G4Colour::Red());
0061 m_ColorIndex++;
0062 break;
0063 case 1:
0064 visattchk->SetColour(G4Colour::Magenta());
0065 m_ColorIndex++;
0066 break;
0067 case 2:
0068 visattchk->SetColour(G4Colour::Yellow());
0069 m_ColorIndex++;
0070 break;
0071 case 3:
0072 visattchk->SetColour(G4Colour::Blue());
0073 m_ColorIndex++;
0074 break;
0075 case 4:
0076 visattchk->SetColour(G4Colour::Cyan());
0077 m_ColorIndex++;
0078 break;
0079 default:
0080 visattchk->SetColour(G4Colour::Green());
0081 m_ColorIndex = 0;
0082 break;
0083 }
0084
0085 checksolid->SetVisAttributes(visattchk);
0086 new G4PVPlacement(rotm, G4ThreeVector(0, 0, 0), checksolid, "DISPLAYVOL", logvol, false, false, true);
0087 return 0;
0088 }
0089
0090 G4Material *PHG4Detector::GetDetectorMaterial(const std::string &name, const bool quit)
0091 {
0092 G4Material *thismaterial = G4Material::GetMaterial(name, false);
0093 if (thismaterial)
0094 {
0095 return thismaterial;
0096 }
0097 thismaterial = G4NistManager::Instance()->FindOrBuildMaterial(name);
0098 if (!thismaterial)
0099 {
0100 if (!quit)
0101 {
0102 return nullptr;
0103 }
0104 std::cout << "PHG4Detector::GetDetectorMaterial: Could not locate " << name << " in NIST DB or create it" << std::endl;
0105 std::cout << boost::stacktrace::stacktrace();
0106 std::cout << std::endl;
0107 std::cout << "read the above stack trace who is calling this material" << std::endl;
0108 gSystem->Exit(1);
0109 exit(1);
0110 }
0111 return thismaterial;
0112 }
0113
0114 G4Element *PHG4Detector::GetDetectorElement(const std::string &name, const bool quit)
0115 {
0116 G4Element *thiselement = G4Element::GetElement(name, false);
0117 if (thiselement)
0118 {
0119 return thiselement;
0120 }
0121 thiselement = G4NistManager::Instance()->FindOrBuildElement(name);
0122 if (!thiselement)
0123 {
0124 if (!quit)
0125 {
0126 return nullptr;
0127 }
0128 std::cout << "PHG4Detector::GetDetectorElement: Could not locate " << name << " in NIST DB or create it" << std::endl;
0129 std::cout << boost::stacktrace::stacktrace();
0130 std::cout << std::endl;
0131 std::cout << "read the above stack trace who is calling this material" << std::endl;
0132 gSystem->Exit(1);
0133 exit(1);
0134 }
0135 return thiselement;
0136 }