ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PHG4PhenixDetector.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file PHG4PhenixDetector.cc
1 #include "PHG4PhenixDetector.h"
2 
3 #include "PHG4Detector.h"
4 #include "PHG4DisplayAction.h" // for PHG4DisplayAction
6 #include "PHG4Reco.h"
8 
9 #include <phool/recoConsts.h>
10 
11 #include <Geant4/G4Box.hh>
12 #include <Geant4/G4GeometryManager.hh>
13 #include <Geant4/G4LogicalVolume.hh> // for G4LogicalVolume
14 #include <Geant4/G4LogicalVolumeStore.hh>
15 #include <Geant4/G4Material.hh>
16 #include <Geant4/G4PVPlacement.hh>
17 #include <Geant4/G4PhysicalVolumeStore.hh>
18 #include <Geant4/G4Region.hh>
19 #include <Geant4/G4RegionStore.hh>
20 #include <Geant4/G4String.hh> // for G4String
21 #include <Geant4/G4SolidStore.hh>
22 #include <Geant4/G4SystemOfUnits.hh>
23 #include <Geant4/G4ThreeVector.hh> // for G4ThreeVector
24 #include <Geant4/G4Tubs.hh>
25 #include <Geant4/G4VSolid.hh> // for G4GeometryType, G4VSolid
26 
27 #include <boost/foreach.hpp>
28 
29 #include <cmath>
30 #include <cstdlib> // for exit
31 #include <iostream>
32 #include <vector> // for vector
33 
34 using namespace std;
35 
36 //____________________________________________________________________________
38  : m_DisplayAction(dynamic_cast<PHG4PhenixDisplayAction *>(subsys->GetDisplayAction()))
39  , m_Verbosity(0)
40  , logicWorld(nullptr)
41  , physiWorld(nullptr)
42  , WorldSizeX(1000 * cm)
43  , WorldSizeY(1000 * cm)
44  , WorldSizeZ(1000 * cm)
45  , worldshape("G4TUBS")
46  , worldmaterial("G4_AIR")
47 {
48 }
49 
51 {
52  while (m_DetectorList.begin() != m_DetectorList.end())
53  {
54  delete m_DetectorList.back();
55  m_DetectorList.pop_back();
56  }
57 }
58 
59 //_______________________________________________________________________________________________
61 {
63  if (m_Verbosity > 0) std::cout << "PHG4PhenixDetector::Construct." << std::endl;
64  // Clean old geometry, if any
69  if (m_Verbosity > 0) std::cout << "PHG4PhenixDetector::Construct - cleaning done." << std::endl;
70 
71  // World
72  G4VSolid *solidWorld = nullptr;
73  if (worldshape == "G4BOX")
74  {
75  solidWorld = new G4Box("World", WorldSizeX / 2, WorldSizeY / 2, WorldSizeZ / 2);
76  }
77  else if (worldshape == "G4Tubs")
78  {
79  solidWorld = new G4Tubs("World", 0., WorldSizeY / 2, WorldSizeZ / 2, 0, 2 * M_PI);
80  }
81  else
82  {
83  cout << "Unknown world shape " << worldshape << endl;
84  cout << "implemented are G4BOX, G4Tubs" << endl;
85  exit(1);
86  }
87  rc->set_CharFlag("WorldShape", solidWorld->GetEntityType()); // needed for checks if a particle is inside or outside of our world
90  physiWorld = new G4PVPlacement(0, G4ThreeVector(), logicWorld, "World", 0, false, 0);
91 
92  G4Region *defaultRegion = (*(G4RegionStore::GetInstance()))[0];
94  info->SetWorld();
95  defaultRegion->SetUserInformation(info);
96  if (m_Verbosity > 0)
97  {
98  std::cout << "PHG4PhenixDetector::Construct " << solidWorld->GetEntityType() << " world "
99  << "material " << logicWorld->GetMaterial()->GetName() << " done." << std::endl;
100  }
101 
102  // construct all detectors
103  BOOST_FOREACH (PHG4Detector *det, m_DetectorList)
104  {
105  if (det)
106  {
107  det->Construct(logicWorld);
108  }
109  }
110 
111  if (m_Verbosity > 0) std::cout << "PHG4PhenixDetector::Construct - done." << std::endl;
112 
113 
114  //Optional PostConstruction call after all geometry is constructed
115  for (PHG4Detector *det: m_DetectorList)
116  {
117  if (det)
118  {
119  det->PostConstruction();
120  }
121  }
122 
123  if (m_Verbosity > 0) std::cout << "PHG4PhenixDetector::PostConstruction - done." << std::endl;
124 
125  return physiWorld;
126 }