Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-05 08:17:45

0001 #include "PHG4CylinderDetector.h"
0002 #include "PHG4CylinderDisplayAction.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 <phool/phool.h>
0011 
0012 #include <Geant4/G4LogicalVolume.hh>
0013 #include <Geant4/G4PVPlacement.hh>
0014 #include <Geant4/G4PhysicalConstants.hh>
0015 #include <Geant4/G4RotationMatrix.hh>  // for G4RotationMatrix
0016 #include <Geant4/G4String.hh>          // for G4String
0017 #include <Geant4/G4SystemOfUnits.hh>
0018 #include <Geant4/G4ThreeVector.hh>  // for G4ThreeVector
0019 #include <Geant4/G4Tubs.hh>
0020 #include <Geant4/G4UserLimits.hh>
0021 
0022 #include <TSystem.h>
0023 
0024 #include <cmath>
0025 #include <iostream>  // for operator<<, endl, basic_ost...
0026 #include <sstream>
0027 
0028 class G4Material;
0029 class G4VSolid;
0030 class PHCompositeNode;
0031 
0032 //_______________________________________________________________
0033 PHG4CylinderDetector::PHG4CylinderDetector(PHG4Subsystem *subsys, PHCompositeNode *Node, PHParameters *parameters, const std::string &dnam, const int lyr)
0034   : PHG4Detector(subsys, Node, dnam)
0035   , m_Params(parameters)
0036   , m_CylinderPhysicalVolume(nullptr)
0037   , m_DisplayAction(dynamic_cast<PHG4CylinderDisplayAction *>(subsys->GetDisplayAction()))
0038   , m_Layer(lyr)
0039 {
0040 }
0041 
0042 //_______________________________________________________________
0043 bool PHG4CylinderDetector::IsInCylinder(const G4VPhysicalVolume *volume) const
0044 {
0045   if (volume == m_CylinderPhysicalVolume)
0046   {
0047     return true;
0048   }
0049   return false;
0050 }
0051 
0052 //_______________________________________________________________
0053 void PHG4CylinderDetector::ConstructMe(G4LogicalVolume *logicWorld)
0054 {
0055   G4Material *TrackerMaterial = GetDetectorMaterial(m_Params->get_string_param("material"));
0056 
0057   // determine length of cylinder using PHENIX's rapidity coverage if flag is true
0058   double radius = m_Params->get_double_param("radius") * cm;
0059   double thickness = m_Params->get_double_param("thickness") * cm;
0060   double length = m_Params->get_double_param("length") * cm;
0061 
0062   double start_phi_rad = m_Params->get_double_param("start_phi_rad") * rad;
0063   double delta_phi_rad = m_Params->get_double_param("delta_phi_rad") * rad;
0064 
0065   if (!std::isfinite(radius) || !std::isfinite(thickness) || !std::isfinite(length))
0066   {
0067     std::cout << PHWHERE << ": Bad Parameters for " << GetName() << std::endl;
0068     std::cout << "Radius: " << radius << std::endl;
0069     std::cout << "Thickness: " << thickness << std::endl;
0070     std::cout << "Length: " << length << std::endl;
0071     gSystem->Exit(1);
0072   }
0073   G4VSolid *cylinder_solid = new G4Tubs(G4String(GetName()),
0074                                         radius,
0075                                         radius + thickness,
0076                                         length / 2., start_phi_rad, delta_phi_rad);
0077   double steplimits = m_Params->get_double_param("steplimits") * cm;
0078   G4UserLimits *g4userlimits = nullptr;
0079   if (std::isfinite(steplimits))
0080   {
0081     g4userlimits = new G4UserLimits(steplimits);
0082   }
0083 
0084   G4LogicalVolume *cylinder_logic = new G4LogicalVolume(cylinder_solid,
0085                                                         TrackerMaterial,
0086                                                         G4String(GetName()),
0087                                                         nullptr, nullptr, g4userlimits);
0088   PHG4Subsystem *mysys = GetMySubsystem();
0089   mysys->SetLogicalVolume(cylinder_logic);
0090 
0091   G4RotationMatrix *rotm = new G4RotationMatrix();
0092   int nRotation(0);
0093   if (m_Params->get_double_param("rot_x") != 0)
0094   {
0095     ++nRotation;
0096     rotm->rotateX(m_Params->get_double_param("rot_x") * deg);
0097   }
0098   if (m_Params->get_double_param("rot_y") != 0)
0099   {
0100     ++nRotation;
0101     rotm->rotateY(m_Params->get_double_param("rot_y") * deg);
0102   }
0103   if (m_Params->get_double_param("rot_z") != 0)
0104   {
0105     ++nRotation;
0106     rotm->rotateZ(m_Params->get_double_param("rot_z") * deg);
0107   }
0108 
0109   if (nRotation >= 2)
0110   {
0111     std::cout << __PRETTY_FUNCTION__ << ": Warning : " << GetName() << " is configured with more than one of the x-y-z rotations of "
0112               << "(" << m_Params->get_double_param("rot_x") << ", "
0113               << m_Params->get_double_param("rot_x") << ", "
0114               << m_Params->get_double_param("rot_x") << ") degrees. "
0115               << "The rotation is instruction is ambiguous and they are performed in the order of X->Y->Z rotations with result rotation matrix of:";
0116     rotm->print(std::cout);
0117   }
0118 
0119   m_CylinderPhysicalVolume = new G4PVPlacement(rotm,
0120                                                G4ThreeVector(m_Params->get_double_param("place_x") * cm,
0121                                                              m_Params->get_double_param("place_y") * cm,
0122                                                              m_Params->get_double_param("place_z") * cm),
0123                                                cylinder_logic,
0124                                                G4String(GetName()),
0125                                                logicWorld, false, false, OverlapCheck());
0126   m_DisplayAction->SetMyVolume(cylinder_logic);
0127 }