Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PHG4CylinderDetector.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file PHG4CylinderDetector.cc
1 #include "PHG4CylinderDetector.h"
3 
4 #include <phparameter/PHParameters.h>
5 
6 #include <g4main/PHG4Detector.h> // for PHG4Detector
7 #include <g4main/PHG4DisplayAction.h> // for PHG4DisplayAction
8 #include <g4main/PHG4Subsystem.h>
9 
10 #include <phool/phool.h>
11 
12 #include <Geant4/G4LogicalVolume.hh>
13 #include <Geant4/G4PVPlacement.hh>
14 #include <Geant4/G4PhysicalConstants.hh>
15 #include <Geant4/G4RotationMatrix.hh> // for G4RotationMatrix
16 #include <Geant4/G4String.hh> // for G4String
17 #include <Geant4/G4SystemOfUnits.hh>
18 #include <Geant4/G4ThreeVector.hh> // for G4ThreeVector
19 #include <Geant4/G4Tubs.hh>
20 #include <Geant4/G4UserLimits.hh>
21 
22 #include <TSystem.h>
23 
24 #include <cmath>
25 #include <iostream> // for operator<<, endl, basic_ost...
26 #include <sstream>
27 
28 class G4Material;
29 class G4VSolid;
30 class PHCompositeNode;
31 
32 //_______________________________________________________________
34  : PHG4Detector(subsys, Node, dnam)
35  , m_Params(parameters)
36  , m_CylinderPhysicalVolume(nullptr)
37  , m_DisplayAction(dynamic_cast<PHG4CylinderDisplayAction *>(subsys->GetDisplayAction()))
38  , m_Layer(lyr)
39 {
40 }
41 
42 //_______________________________________________________________
44 {
45  if (volume == m_CylinderPhysicalVolume)
46  {
47  return true;
48  }
49  return false;
50 }
51 
52 //_______________________________________________________________
53 void PHG4CylinderDetector::ConstructMe(G4LogicalVolume *logicWorld)
54 {
55  G4Material *TrackerMaterial = GetDetectorMaterial(m_Params->get_string_param("material"));
56 
57  // determine length of cylinder using PHENIX's rapidity coverage if flag is true
58  double radius = m_Params->get_double_param("radius") * cm;
59  double thickness = m_Params->get_double_param("thickness") * cm;
60  double length = m_Params->get_double_param("length") * cm;
61 
62  double start_phi_rad = m_Params->get_double_param("start_phi_rad") * rad;
63  double delta_phi_rad = m_Params->get_double_param("delta_phi_rad") * rad;
64 
65  if (!std::isfinite(radius) || !std::isfinite(thickness) || !std::isfinite(length))
66  {
67  std::cout << PHWHERE << ": Bad Parameters for " << GetName() << std::endl;
68  std::cout << "Radius: " << radius << std::endl;
69  std::cout << "Thickness: " << thickness << std::endl;
70  std::cout << "Length: " << length << std::endl;
71  gSystem->Exit(1);
72  }
73  G4VSolid *cylinder_solid = new G4Tubs(G4String(GetName()),
74  radius,
75  radius + thickness,
76  length / 2., start_phi_rad, delta_phi_rad);
77  double steplimits = m_Params->get_double_param("steplimits") * cm;
78  G4UserLimits *g4userlimits = nullptr;
79  if (std::isfinite(steplimits))
80  {
81  g4userlimits = new G4UserLimits(steplimits);
82  }
83 
84  G4LogicalVolume *cylinder_logic = new G4LogicalVolume(cylinder_solid,
85  TrackerMaterial,
86  G4String(GetName()),
87  nullptr, nullptr, g4userlimits);
88  PHG4Subsystem *mysys = GetMySubsystem();
89  mysys->SetLogicalVolume(cylinder_logic);
90 
91  G4RotationMatrix *rotm = new G4RotationMatrix();
92  int nRotation(0);
93  if (m_Params->get_double_param("rot_x") != 0)
94  {
95  ++nRotation;
96  rotm->rotateX(m_Params->get_double_param("rot_x") * deg);
97  }
98  if (m_Params->get_double_param("rot_y") != 0)
99  {
100  ++nRotation;
101  rotm->rotateY(m_Params->get_double_param("rot_y") * deg);
102  }
103  if (m_Params->get_double_param("rot_z") != 0)
104  {
105  ++nRotation;
106  rotm->rotateZ(m_Params->get_double_param("rot_z") * deg);
107  }
108 
109  if (nRotation >= 2)
110  {
111  std::cout << __PRETTY_FUNCTION__ << ": Warning : " << GetName() << " is configured with more than one of the x-y-z rotations of "
112  << "(" << m_Params->get_double_param("rot_x") << ", "
113  << m_Params->get_double_param("rot_x") << ", "
114  << m_Params->get_double_param("rot_x") << ") degrees. "
115  << "The rotation is instruction is ambiguous and they are performed in the order of X->Y->Z rotations with result rotation matrix of:";
116  rotm->print(std::cout);
117  }
118 
119  m_CylinderPhysicalVolume = new G4PVPlacement(rotm,
120  G4ThreeVector(m_Params->get_double_param("place_x") * cm,
121  m_Params->get_double_param("place_y") * cm,
122  m_Params->get_double_param("place_z") * cm),
123  cylinder_logic,
124  G4String(GetName()),
125  logicWorld, false, false, OverlapCheck());
126  m_DisplayAction->SetMyVolume(cylinder_logic);
127 }