EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4Example01Detector.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4Example01Detector.cc
1 #include "G4Example01Detector.h"
2 
3 #include <g4main/PHG4Detector.h> // for PHG4Detector
4 
5 #include <Geant4/G4Box.hh>
6 #include <Geant4/G4Color.hh>
7 #include <Geant4/G4LogicalVolume.hh>
8 #include <Geant4/G4Material.hh>
9 #include <Geant4/G4PVPlacement.hh>
10 #include <Geant4/G4SubtractionSolid.hh>
11 #include <Geant4/G4SystemOfUnits.hh>
12 #include <Geant4/G4ThreeVector.hh>
13 #include <Geant4/G4Tubs.hh>
14 #include <Geant4/G4VisAttributes.hh>
15 
16 #include <cmath>
17 #include <iostream> // for operator<<, endl, bas...
18 
19 class G4VSolid;
20 class PHCompositeNode;
21 
22 using namespace std;
23 
25  : PHG4Detector(subsys, Node, dnam)
26 {
27 }
28 
29 //_______________________________________________________________
30 //_______________________________________________________________
31 int G4Example01Detector::IsInDetector(G4VPhysicalVolume *volume) const
32 {
33  set<G4VPhysicalVolume *>::const_iterator iter = m_PhysicalVolumesSet.find(volume);
34  if (iter != m_PhysicalVolumesSet.end())
35  {
36  return 1;
37  }
38 
39  return 0;
40 }
41 
42 void G4Example01Detector::ConstructMe(G4LogicalVolume *logicWorld)
43 {
44  double xdim = 20 * cm;
45  double ydim = 20 * cm;
46  double zdim = 20 * cm;
47  G4VSolid *solidbox = new G4Box("Example01BoxSolid", xdim / 2., ydim / 2., zdim / 2.);
48  G4VSolid *cylcut = new G4Tubs("CylinderCutSolid", 0., xdim / 4., zdim, 0., M_PI * rad);
49  G4VSolid *subtract = new G4SubtractionSolid("HoleInBox", solidbox, cylcut);
50  G4LogicalVolume *logical = new G4LogicalVolume(subtract, G4Material::GetMaterial("G4_Al"), "BoxWithHoleLogical");
51 
52  G4VisAttributes *vis = new G4VisAttributes(G4Color(G4Colour::Grey())); // grey is good to see the tracks in the display
53  vis->SetForceSolid(true);
54  logical->SetVisAttributes(vis);
55  G4VPhysicalVolume *phy = new G4PVPlacement(nullptr, G4ThreeVector(0, 0, 0),
56  logical, "BoxWithHole",
57  logicWorld, 0, false, OverlapCheck());
58  // add it to the list of placed volumes so the IsInDetector method
59  // picks them up
60  m_PhysicalVolumesSet.insert(phy);
61  return;
62 }
63 
64 void G4Example01Detector::Print(const std::string &what) const
65 {
66  cout << "Example01 Detector:" << endl;
67  if (what == "ALL" || what == "VOLUME")
68  {
69  cout << "Version 0.1" << endl;
70  }
71  return;
72 }