EIC 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 using namespace std;
33 
34 //_______________________________________________________________
35 PHG4CylinderDetector::PHG4CylinderDetector(PHG4Subsystem *subsys, PHCompositeNode *Node, PHParameters *parameters, const std::string &dnam, const int lyr)
36  : PHG4Detector(subsys, Node, dnam)
37  , m_Params(parameters)
38  , m_CylinderPhysicalVolume(nullptr)
39  , m_DisplayAction(dynamic_cast<PHG4CylinderDisplayAction *>(subsys->GetDisplayAction()))
40  , m_Layer(lyr)
41 {
42 }
43 
44 //_______________________________________________________________
45 bool PHG4CylinderDetector::IsInCylinder(const G4VPhysicalVolume *volume) const
46 {
47  if (volume == m_CylinderPhysicalVolume)
48  {
49  return true;
50  }
51  return false;
52 }
53 
54 //_______________________________________________________________
55 void PHG4CylinderDetector::ConstructMe(G4LogicalVolume *logicWorld)
56 {
57  G4Material *TrackerMaterial = GetDetectorMaterial(m_Params->get_string_param("material"));
58 
59  // determine length of cylinder using PHENIX's rapidity coverage if flag is true
60  double radius = m_Params->get_double_param("radius") * cm;
61  double thickness = m_Params->get_double_param("thickness") * cm;
62  double length = m_Params->get_double_param("length") * cm;
63  if (!isfinite(radius) || !isfinite(thickness) || !isfinite(length))
64  {
65  cout << PHWHERE << ": Bad Parameters for " << GetName() << endl;
66  cout << "Radius: " << radius << endl;
67  cout << "Thickness: " << thickness << endl;
68  cout << "Length: " << length << endl;
69  gSystem->Exit(1);
70  }
71  G4VSolid *cylinder_solid = new G4Tubs(G4String(GetName()),
72  radius,
73  radius + thickness,
74  length / 2., 0, twopi);
75  double steplimits = m_Params->get_double_param("steplimits") * cm;
76  G4UserLimits *g4userlimits = nullptr;
77  if (isfinite(steplimits))
78  {
79  g4userlimits = new G4UserLimits(steplimits);
80  }
81 
82  G4LogicalVolume *cylinder_logic = new G4LogicalVolume(cylinder_solid,
83  TrackerMaterial,
84  G4String(GetName()),
85  nullptr, nullptr, g4userlimits);
86  PHG4Subsystem *mysys = GetMySubsystem();
87  mysys->SetLogicalVolume(cylinder_logic);
88 
89  G4RotationMatrix *rotm = new G4RotationMatrix();
90  int nRotation(0);
91  if (m_Params->get_double_param("rot_x") !=0 )
92  {
93  ++ nRotation;
94  rotm->rotateX(m_Params->get_double_param("rot_x") * deg);
95  }
96  if (m_Params->get_double_param("rot_y") !=0 )
97  {
98  ++ nRotation;
99  rotm->rotateY(m_Params->get_double_param("rot_y") * deg);
100  }
101  if (m_Params->get_double_param("rot_z") !=0 )
102  {
103  ++ nRotation;
104  rotm->rotateZ(m_Params->get_double_param("rot_z") * deg);
105  }
106 
107  if (nRotation>=2)
108  {
109  cout <<__PRETTY_FUNCTION__<<": Warning : " <<GetName()<<" is configured with more than one of the x-y-z rotations of "
110  <<"("<<m_Params->get_double_param("rot_x")<<", "
111  <<m_Params->get_double_param("rot_x")<<", "
112  <<m_Params->get_double_param("rot_x")<<") degrees. "
113  <<"The rotation is instruction is ambiguous and they are performed in the order of X->Y->Z rotations with result rotation matrix of:";
114  rotm->print(cout);
115  }
116 
117  m_CylinderPhysicalVolume = new G4PVPlacement(rotm,
118  G4ThreeVector(m_Params->get_double_param("place_x") * cm,
119  m_Params->get_double_param("place_y") * cm,
120  m_Params->get_double_param("place_z") * cm),
121  cylinder_logic,
122  G4String(GetName()),
123  logicWorld, 0, false, OverlapCheck());
124  m_DisplayAction->SetMyVolume(cylinder_logic);
125 }