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