Back to home page

sPhenix code displayed by LXR

 
 

    


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

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