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