Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-03 08:20:25

0001 #ifndef MACRO_G4MAGNET_C
0002 #define MACRO_G4MAGNET_C
0003 
0004 #include <GlobalVariables.C>
0005 
0006 #include <g4detectors/PHG4CylinderSubsystem.h>
0007 
0008 #include <g4detectors/PHG4sPHENIXMagnetSubsystem.h>
0009 
0010 #include <g4main/PHG4Reco.h>
0011 
0012 #include <TSystem.h>
0013 
0014 #include <cmath>
0015 
0016 R__LOAD_LIBRARY(libg4detectors.so)
0017 
0018 namespace Enable
0019 {
0020   bool MAGNET = false;
0021   bool MAGNET_OLD = false;
0022   bool MAGNET_ABSORBER = false;
0023   bool MAGNET_OVERLAPCHECK = false;
0024   int MAGNET_VERBOSITY = 0;
0025 }  // namespace Enable
0026 
0027 namespace G4MAGNET
0028 {
0029   double magnet_outer_cryostat_wall_radius = 174.5;
0030   double magnet_outer_cryostat_wall_thickness = 2.5;
0031   double magnet_length = 379.;
0032 }  // namespace G4MAGNET
0033 
0034 void MagnetFieldInit()
0035 {
0036   if (!std::isfinite(G4MAGNET::magfield_rescale))
0037   {
0038     G4MAGNET::magfield_rescale = 1.;
0039   }
0040   if (G4MAGNET::magfield.empty())
0041   {
0042     G4MAGNET::magfield = "FIELDMAP_GAP";
0043   }
0044   if (G4MAGNET::magfield_OHCAL_steel.empty())
0045   {
0046     G4MAGNET::magfield_OHCAL_steel = "FIELDMAP_STEEL";
0047   }
0048   if (G4MAGNET::magfield_tracking.empty())
0049   {
0050     G4MAGNET::magfield_tracking = "FIELDMAP_TRACKING";
0051   }
0052 }
0053 
0054 void MagnetInit()
0055 {
0056   MagnetFieldInit();
0057   BlackHoleGeometry::max_radius = std::max(BlackHoleGeometry::max_radius, G4MAGNET::magnet_outer_cryostat_wall_radius + G4MAGNET::magnet_outer_cryostat_wall_thickness);
0058   BlackHoleGeometry::max_z = std::max(BlackHoleGeometry::max_z, G4MAGNET::magnet_length / 2.);
0059   BlackHoleGeometry::min_z = std::min(BlackHoleGeometry::min_z, -G4MAGNET::magnet_length / 2.);
0060 }
0061 
0062 double Magnet(PHG4Reco* g4Reco, double radius)
0063 {
0064   bool AbsorberActive = Enable::ABSORBER || Enable::MAGNET_ABSORBER;
0065   bool OverlapCheck = Enable::OVERLAPCHECK || Enable::MAGNET_OVERLAPCHECK;
0066   int verbosity = std::max(Enable::VERBOSITY, Enable::MAGNET_VERBOSITY);
0067 
0068   if (!Enable::MAGNET_OLD)
0069   {
0070     PHG4sPHENIXMagnetSubsystem* mag = new PHG4sPHENIXMagnetSubsystem("MAGNET", 0);
0071     mag->SuperDetector("MAGNET");
0072     if (AbsorberActive) mag->SetActive();
0073     // mag->OverlapCheck(OverlapCheck);
0074     mag->OverlapCheck(OverlapCheck);
0075     g4Reco->registerSubsystem(mag);
0076     radius = 170.0;
0077   }
0078   else
0079   {
0080     double magnet_inner_cryostat_wall_radius = 142;
0081     double magnet_inner_cryostat_wall_thickness = 1;
0082     double magnet_coil_radius = 150.8;
0083     double magnet_coil_thickness = 9.38;
0084     double magnet_length = 379.;
0085     double coil_length = 361.5;
0086     if (radius > magnet_inner_cryostat_wall_radius)
0087     {
0088       std::cout << "inconsistency: radius: " << radius
0089                 << " larger than Magnet inner radius: " << magnet_inner_cryostat_wall_radius << std::endl;
0090       gSystem->Exit(-1);
0091     }
0092 
0093     radius = magnet_inner_cryostat_wall_radius;
0094     PHG4CylinderSubsystem* cyl = new PHG4CylinderSubsystem("MAGNET", 0);
0095     cyl->set_double_param("radius", magnet_inner_cryostat_wall_radius);
0096     cyl->set_int_param("lengthviarapidity", 0);
0097     cyl->set_double_param("length", G4MAGNET::magnet_length);
0098     cyl->set_double_param("thickness", magnet_inner_cryostat_wall_thickness);
0099     cyl->set_string_param("material", "Al5083");  // use 1 radiation length Al for magnet thickness
0100     cyl->SuperDetector("MAGNET");
0101     if (AbsorberActive) cyl->SetActive();
0102     cyl->OverlapCheck(OverlapCheck);
0103     g4Reco->registerSubsystem(cyl);
0104 
0105     cyl = new PHG4CylinderSubsystem("MAGNET", 1);
0106     cyl->set_double_param("radius", magnet_coil_radius);
0107     cyl->set_int_param("lengthviarapidity", 0);
0108     cyl->set_double_param("length", coil_length);
0109     cyl->set_double_param("thickness", magnet_coil_thickness);
0110     cyl->set_string_param("material", "Al5083");  // use 1 radiation length Al for magnet thickness
0111     cyl->SuperDetector("MAGNET");
0112     if (AbsorberActive) cyl->SetActive();
0113     cyl->OverlapCheck(OverlapCheck);
0114     g4Reco->registerSubsystem(cyl);
0115 
0116     cyl = new PHG4CylinderSubsystem("MAGNET", 2);
0117     cyl->set_double_param("radius", G4MAGNET::magnet_outer_cryostat_wall_radius);
0118     cyl->set_int_param("lengthviarapidity", 0);
0119     cyl->set_double_param("length", G4MAGNET::magnet_length);
0120     cyl->set_double_param("thickness", G4MAGNET::magnet_outer_cryostat_wall_thickness);
0121     cyl->set_string_param("material", "Al5083");  // use 1 radiation length Al for magnet thickness
0122     cyl->SuperDetector("MAGNET");
0123     if (AbsorberActive) cyl->SetActive();
0124     cyl->OverlapCheck(OverlapCheck);
0125     g4Reco->registerSubsystem(cyl);
0126 
0127     radius = G4MAGNET::magnet_outer_cryostat_wall_radius + G4MAGNET::magnet_outer_cryostat_wall_thickness;  // outside of magnet
0128 
0129     if (verbosity > 0)
0130     {
0131       std::cout << "========================= G4_Magnet.C::Magnet() ===========================" << std::endl;
0132       std::cout << " MAGNET Material Description:" << std::endl;
0133       std::cout << "  inner radius = " << magnet_inner_cryostat_wall_radius << " cm" << std::endl;
0134       std::cout << "  outer radius = " << G4MAGNET::magnet_outer_cryostat_wall_radius + G4MAGNET::magnet_outer_cryostat_wall_thickness << " cm" << std::endl;
0135       std::cout << "  length = " << G4MAGNET::magnet_length << " cm" << std::endl;
0136       std::cout << "===========================================================================" << std::endl;
0137     }
0138 
0139     radius += no_overlapp;
0140   }
0141   return radius;
0142 }
0143 #endif