File indexing completed on 2025-08-06 08:18:55
0001 #include "PHG4ConeDetector.h"
0002 #include "PHG4ConeDisplayAction.h"
0003
0004 #include <phparameter/PHParameters.h>
0005
0006 #include <g4main/PHG4Detector.h> // for PHG4Detector
0007 #include <g4main/PHG4DisplayAction.h> // for PHG4DisplayAction
0008 #include <g4main/PHG4Subsystem.h>
0009
0010 #include <Geant4/G4Cons.hh>
0011 #include <Geant4/G4LogicalVolume.hh>
0012 #include <Geant4/G4PVPlacement.hh>
0013 #include <Geant4/G4RotationMatrix.hh> // for G4RotationMatrix
0014 #include <Geant4/G4String.hh> // for G4String
0015 #include <Geant4/G4SystemOfUnits.hh> // for cm
0016 #include <Geant4/G4ThreeVector.hh> // for G4ThreeVector
0017
0018 #include <iostream> // for operator<<, endl, basic_ostream
0019 #include <sstream>
0020
0021 class G4Material;
0022 class G4VSolid;
0023
0024
0025
0026 PHG4ConeDetector::PHG4ConeDetector(PHG4Subsystem *subsys, PHCompositeNode *Node, PHParameters *parameters, const std::string &dnam, const int lyr)
0027 : PHG4Detector(subsys, Node, dnam)
0028 , m_Params(parameters)
0029 , m_DisplayAction(dynamic_cast<PHG4ConeDisplayAction *>(subsys->GetDisplayAction()))
0030 , layer(lyr)
0031 {
0032 }
0033
0034
0035
0036 bool PHG4ConeDetector::IsInConeActive(G4VPhysicalVolume *volume)
0037 {
0038 if (volume == m_ConePhysVol)
0039 {
0040 return true;
0041 }
0042 return false;
0043 }
0044
0045
0046 void PHG4ConeDetector::ConstructMe(G4LogicalVolume *logicWorld)
0047 {
0048 G4Material *TrackerMaterial = GetDetectorMaterial(m_Params->get_string_param("material"));
0049
0050 G4VSolid *cone_solid = new G4Cons((GetName() + "_SOLID"),
0051 m_Params->get_double_param("rmin1") * cm,
0052 m_Params->get_double_param("rmax1") * cm,
0053 m_Params->get_double_param("rmin2") * cm,
0054 m_Params->get_double_param("rmax2") * cm,
0055 m_Params->get_double_param("length") * cm,
0056 m_Params->get_double_param("sphi") * deg,
0057 m_Params->get_double_param("dphi") * deg);
0058
0059 G4LogicalVolume *cone_logic = new G4LogicalVolume(cone_solid,
0060 TrackerMaterial,
0061 GetName() + "_LOGIC",
0062 nullptr, nullptr, nullptr);
0063 PHG4Subsystem *mysys = GetMySubsystem();
0064 mysys->SetLogicalVolume(cone_logic);
0065
0066 G4RotationMatrix *rotm = new G4RotationMatrix();
0067
0068 int nRotation(0);
0069 if (m_Params->get_double_param("rot_x") != 0)
0070 {
0071 ++nRotation;
0072 rotm->rotateX(m_Params->get_double_param("rot_x") * deg);
0073 }
0074 if (m_Params->get_double_param("rot_y") != 0)
0075 {
0076 ++nRotation;
0077 rotm->rotateY(m_Params->get_double_param("rot_y") * deg);
0078 }
0079 if (m_Params->get_double_param("rot_z") != 0)
0080 {
0081 ++nRotation;
0082 rotm->rotateZ(m_Params->get_double_param("rot_z") * deg);
0083 }
0084
0085 if (nRotation >= 2)
0086 {
0087 std::cout << __PRETTY_FUNCTION__ << ": Warning : " << GetName() << " is configured with more than one of the x-y-z rotations of "
0088 << "(" << m_Params->get_double_param("rot_x") << ", "
0089 << m_Params->get_double_param("rot_x") << ", "
0090 << m_Params->get_double_param("rot_x") << ") degrees. "
0091 << "The rotation is instruction is ambiguous and they are performed in the order of X->Y->Z rotations with result rotation matrix of:";
0092 rotm->print(std::cout);
0093 }
0094
0095 m_ConePhysVol = new G4PVPlacement(rotm,
0096 G4ThreeVector(m_Params->get_double_param("place_x") * cm,
0097 m_Params->get_double_param("place_y") * cm,
0098 m_Params->get_double_param("place_z") * cm),
0099 cone_logic,
0100 GetName(),
0101 logicWorld, false, false, OverlapCheck());
0102 m_DisplayAction->SetMyVolume(cone_logic);
0103 }