Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PHG4Detector.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file PHG4Detector.cc
1 #include "PHG4Detector.h"
2 
3 #include "PHG4Subsystem.h"
4 
5 #include <TSystem.h>
6 
7 #include <Geant4/G4Colour.hh> // for G4Colour
8 #include <Geant4/G4LogicalVolume.hh>
9 #include <Geant4/G4Material.hh>
10 #include <Geant4/G4NistManager.hh>
11 #include <Geant4/G4PVPlacement.hh>
12 #include <Geant4/G4RotationMatrix.hh> // for G4RotationMatrix
13 #include <Geant4/G4ThreeVector.hh> // for G4ThreeVector
14 #include <Geant4/G4VisAttributes.hh>
15 
16 #pragma GCC diagnostic push
17 #pragma GCC diagnostic ignored "-Wshadow"
18 #include <boost/stacktrace.hpp>
19 #pragma GCC diagnostic pop
20 
22  : m_topNode(Node)
23  , m_MySubsystem(subsys)
24  , m_Name(nam)
25 {
26 }
27 
28 void PHG4Detector::Construct(G4LogicalVolume *world)
29 {
30  PHG4Subsystem *MyMotherSubsystem = m_MySubsystem->GetMotherSubsystem();
31  if (MyMotherSubsystem)
32  {
33  ConstructMe(MyMotherSubsystem->GetLogicalVolume());
34  }
35  else
36  {
37  ConstructMe(world);
38  }
39  return;
40 }
41 
42 int PHG4Detector::DisplayVolume(G4VSolid *volume, G4LogicalVolume *logvol, G4RotationMatrix *rotm)
43 {
44  G4LogicalVolume *checksolid = new G4LogicalVolume(volume, G4Material::GetMaterial("G4_POLYSTYRENE"), "DISPLAYLOGICAL", 0, 0, 0);
45  int iret = DisplayVolume(checksolid, logvol, rotm);
46  return iret;
47 }
48 
49 int PHG4Detector::DisplayVolume(G4LogicalVolume *checksolid, G4LogicalVolume *logvol, G4RotationMatrix *rotm)
50 {
51  G4VisAttributes *visattchk = new G4VisAttributes();
52  visattchk->SetVisibility(true);
53  visattchk->SetForceSolid(false);
54  switch (m_ColorIndex)
55  {
56  case 0:
57  visattchk->SetColour(G4Colour::Red());
58  m_ColorIndex++;
59  break;
60  case 1:
61  visattchk->SetColour(G4Colour::Magenta());
62  m_ColorIndex++;
63  break;
64  case 2:
65  visattchk->SetColour(G4Colour::Yellow());
66  m_ColorIndex++;
67  break;
68  case 3:
69  visattchk->SetColour(G4Colour::Blue());
70  m_ColorIndex++;
71  break;
72  case 4:
73  visattchk->SetColour(G4Colour::Cyan());
74  m_ColorIndex++;
75  break;
76  default:
77  visattchk->SetColour(G4Colour::Green());
78  m_ColorIndex = 0;
79  break;
80  }
81 
82  checksolid->SetVisAttributes(visattchk);
83  new G4PVPlacement(rotm, G4ThreeVector(0, 0, 0), checksolid, "DISPLAYVOL", logvol, 0, false, true);
84  return 0;
85 }
86 
87 G4Material *PHG4Detector::GetDetectorMaterial(const std::string &name, const bool quit)
88 {
89  G4Material *thismaterial = G4Material::GetMaterial(name,false);
90  if (thismaterial)
91  {
92  return thismaterial;
93  }
94  thismaterial = G4NistManager::Instance()->FindOrBuildMaterial(name);
95  if (!thismaterial)
96  {
97  if (!quit)
98  {
99  return nullptr;
100  }
101  std::cout << "PHG4Detector::GetDetectorMaterial: Could not locate " << name << " in NIST DB or create it" << std::endl;
102  std::cout << boost::stacktrace::stacktrace();
103  std::cout << std::endl;
104  std::cout << "read the above stack trace who is calling this material" << std::endl;
105  gSystem->Exit(1);
106  exit(1); // so coverity gets it
107  }
108  return thismaterial;
109 }
110 
111 
112 G4Element *PHG4Detector::GetDetectorElement(const std::string &name, const bool quit)
113 {
114  G4Element *thiselement = G4Element::GetElement(name,false);
115  if (thiselement)
116  {
117  return thiselement;
118  }
119  thiselement = G4NistManager::Instance()->FindOrBuildElement(name);
120  if (!thiselement)
121  {
122  if (!quit)
123  {
124  return nullptr;
125  }
126  std::cout << "PHG4Detector::GetDetectorElement: Could not locate " << name << " in NIST DB or create it" << std::endl;
127  std::cout << boost::stacktrace::stacktrace();
128  std::cout << std::endl;
129  std::cout << "read the above stack trace who is calling this material" << std::endl;
130  gSystem->Exit(1);
131  exit(1); // so coverity gets it
132  }
133  return thiselement;
134 }