ECCE @ EIC 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 #include <boost/stacktrace.hpp>
17 
18 PHG4Detector::PHG4Detector(PHG4Subsystem *subsys, PHCompositeNode *Node, const std::string &nam)
19  : m_topNode(Node)
20  , m_MySubsystem(subsys)
21  , m_Name(nam)
22 {
23 }
24 
26 {
27  PHG4Subsystem *MyMotherSubsystem = m_MySubsystem->GetMotherSubsystem();
28  if (MyMotherSubsystem)
29  {
30  ConstructMe(MyMotherSubsystem->GetLogicalVolume());
31  }
32  else
33  {
34  ConstructMe(world);
35  }
36  return;
37 }
38 
40 {
41  G4LogicalVolume *checksolid = new G4LogicalVolume(volume, G4Material::GetMaterial("G4_POLYSTYRENE"), "DISPLAYLOGICAL", 0, 0, 0);
42  int iret = DisplayVolume(checksolid, logvol, rotm);
43  return iret;
44 }
45 
47 {
48  G4VisAttributes *visattchk = new G4VisAttributes();
49  visattchk->SetVisibility(true);
50  visattchk->SetForceSolid(false);
51  switch (m_ColorIndex)
52  {
53  case 0:
54  visattchk->SetColour(G4Colour::Red());
55  m_ColorIndex++;
56  break;
57  case 1:
58  visattchk->SetColour(G4Colour::Magenta());
59  m_ColorIndex++;
60  break;
61  case 2:
62  visattchk->SetColour(G4Colour::Yellow());
63  m_ColorIndex++;
64  break;
65  case 3:
66  visattchk->SetColour(G4Colour::Blue());
67  m_ColorIndex++;
68  break;
69  case 4:
70  visattchk->SetColour(G4Colour::Cyan());
71  m_ColorIndex++;
72  break;
73  default:
74  visattchk->SetColour(G4Colour::Green());
75  m_ColorIndex = 0;
76  break;
77  }
78 
79  checksolid->SetVisAttributes(visattchk);
80  new G4PVPlacement(rotm, G4ThreeVector(0, 0, 0), checksolid, "DISPLAYVOL", logvol, 0, false, true);
81  return 0;
82 }
83 
84 G4Material *PHG4Detector::GetDetectorMaterial(const std::string &name, const bool quit)
85 {
86  G4Material *thismaterial = G4Material::GetMaterial(name,false);
87  if (thismaterial)
88  {
89  return thismaterial;
90  }
91  thismaterial = G4NistManager::Instance()->FindOrBuildMaterial(name);
92  if (!thismaterial)
93  {
94  if (!quit)
95  {
96  return nullptr;
97  }
98  std::cout << "PHG4Detector::GetDetectorMaterial: Could not locate " << name << " in NIST DB or create it" << std::endl;
99  std::cout << boost::stacktrace::stacktrace();
100  std::cout << std::endl;
101  std::cout << "read the above stack trace who is calling this material" << std::endl;
102  gSystem->Exit(1);
103  exit(1); // so coverity gets it
104  }
105  return thismaterial;
106 }
107 
108 
109 G4Element *PHG4Detector::GetDetectorElement(const std::string &name, const bool quit)
110 {
111  G4Element *thiselement = G4Element::GetElement(name,false);
112  if (thiselement)
113  {
114  return thiselement;
115  }
116  thiselement = G4NistManager::Instance()->FindOrBuildElement(name);
117  if (!thiselement)
118  {
119  if (!quit)
120  {
121  return nullptr;
122  }
123  std::cout << "PHG4Detector::GetDetectorElement: Could not locate " << name << " in NIST DB or create it" << std::endl;
124  std::cout << boost::stacktrace::stacktrace();
125  std::cout << std::endl;
126  std::cout << "read the above stack trace who is calling this material" << std::endl;
127  gSystem->Exit(1);
128  exit(1); // so coverity gets it
129  }
130  return thiselement;
131 }