Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-06 08:19:04

0001 /* vim: set sw=2 ft=cpp: */
0002 
0003 #include "PHG4EPDDetector.h"
0004 
0005 #include "PHG4EPDDisplayAction.h"
0006 
0007 #include <epd/EPDDefs.h>
0008 
0009 #include <g4main/PHG4Detector.h>
0010 #include <g4main/PHG4DisplayAction.h>  // for PHG4DisplayAction
0011 #include <g4main/PHG4Subsystem.h>
0012 
0013 #include <phparameter/PHParameters.h>
0014 
0015 #include <Geant4/G4ExtrudedSolid.hh>
0016 #include <Geant4/G4LogicalVolume.hh>
0017 #include <Geant4/G4PVPlacement.hh>
0018 #include <Geant4/G4RotationMatrix.hh>
0019 #include <Geant4/G4String.hh>  // for G4String
0020 #include <Geant4/G4SystemOfUnits.hh>
0021 #include <Geant4/G4ThreeVector.hh>
0022 #include <Geant4/G4TwoVector.hh>        // for G4TwoVector
0023 #include <Geant4/G4VPhysicalVolume.hh>  // for G4VPhysicalVolume
0024 
0025 #include <algorithm>  // for max
0026 #include <cmath>
0027 #include <vector>  // for vector
0028 class G4Material;
0029 
0030 PHG4EPDDetector::PHG4EPDDetector(PHG4Subsystem* subsys,
0031                                  PHCompositeNode* node,
0032                                  PHParameters* parameters,
0033                                  std::string const& name)
0034   : PHG4Detector(subsys, node, name)
0035   , m_DisplayAction(dynamic_cast<PHG4EPDDisplayAction*>(subsys->GetDisplayAction()))
0036   , m_Params(parameters)
0037   , m_ActiveFlag(m_Params->get_int_param("active"))
0038   , m_SupportActiveFlag(m_Params->get_int_param("supportactive"))
0039 {
0040 }
0041 
0042 void PHG4EPDDetector::ConstructMe(G4LogicalVolume* world)
0043 {
0044   G4Material* material = GetDetectorMaterial("G4_PLASTIC_SC_VINYLTOLUENE");
0045 
0046   G4ThreeVector positive(0., 0., m_Params->get_double_param("place_z") * cm);
0047   G4ThreeVector negative(0., 0., -m_Params->get_double_param("place_z") * cm);
0048 
0049   constexpr int32_t ntiles = 31;
0050   constexpr int32_t nsectors = 12;
0051 
0052   for (int32_t i = 0; i < ntiles; ++i)
0053   {
0054     std::string label = "EPD_tile_" + std::to_string(i);
0055 
0056     G4ExtrudedSolid* block = construct_block(i);
0057     G4LogicalVolume* volume = new G4LogicalVolume(block, material, label, nullptr, nullptr, nullptr);
0058 
0059     GetDisplayAction()->AddVolume(volume, volume->GetName());
0060     m_ActiveLogVolSet.insert(volume);
0061 
0062     for (int32_t k = 0; k < nsectors; ++k)
0063     {
0064       G4RotationMatrix* rotate = new G4RotationMatrix();
0065 
0066       double phi_shift = (k + 9) * 2 * M_PI / nsectors;
0067 
0068       if (phi_shift >= (2.0 * M_PI))
0069       {
0070         phi_shift -= (2.0 * M_PI);
0071       }
0072       else if (phi_shift < 0.0)
0073       {
0074         phi_shift += (2.0 * M_PI);
0075       }
0076 
0077       rotate->rotateZ(-1 * phi_shift);
0078 
0079       m_volumes.emplace(
0080           new G4PVPlacement(rotate, negative, volume, label, world, false, 2 * k + 0, OverlapCheck()),
0081           module_id_for(i, k, 0));
0082 
0083       m_volumes.emplace(
0084           new G4PVPlacement(rotate, positive, volume, label, world, false, 2 * k + 1, OverlapCheck()),
0085           module_id_for(i, k, 1));
0086     }
0087   }
0088 }
0089 
0090 int PHG4EPDDetector::IsInDetector(G4VPhysicalVolume* volume) const
0091 {
0092   G4LogicalVolume* mylogvol = volume->GetLogicalVolume();
0093   if (m_ActiveFlag)
0094   {
0095     if (m_ActiveLogVolSet.find(mylogvol) != m_ActiveLogVolSet.end())
0096     {
0097       return 1;
0098     }
0099   }
0100   if (m_SupportActiveFlag)
0101   {
0102     if (m_SupportLogVolSet.find(mylogvol) != m_SupportLogVolSet.end())
0103     {
0104       return -2;
0105     }
0106   }
0107   return 0;
0108 }
0109 
0110 uint32_t PHG4EPDDetector::module_id_for(uint32_t tile_id, uint32_t sector, uint32_t arm)
0111 {
0112   return EPDDefs::make_epd_key(arm, sector, tile_id);
0113 }
0114 
0115 uint32_t PHG4EPDDetector::module_id_for(G4VPhysicalVolume* volume)
0116 {
0117   return m_volumes[volume];
0118 }
0119 
0120 static constexpr double dz = 6.;
0121 
0122 static constexpr double coordinates[31][5][2] =
0123     {
0124         {{-22.43, 40.39}, {-44.41, 78.05}, {-23.29, 86.91}, {-0.57, 89.80}, {-0.77, 46.19}},
0125         {{-44.96, 79.66}, {-66.53, 116.62}, {-35.41, 129.51}, {-24.54, 88.12}, {0.00, 0.00}},
0126         {{-22.81, 88.58}, {-34.08, 129.86}, {-0.69, 134.26}, {-0.90, 91.47}, {0.00, 0.00}},
0127         {{-67.15, 118.09}, {-88.72, 155.05}, {-46.90, 172.37}, {-36.03, 130.98}, {0.00, 0.00}},
0128         {{-34.29, 131.45}, {-45.57, 172.73}, {-0.69, 178.64}, {-0.90, 135.85}, {0.00, 0.00}},
0129         {{-89.34, 156.53}, {-116.61, 203.35}, {-61.34, 226.25}, {-47.51, 173.85}, {0.00, 0.00}},
0130         {{-45.78, 174.32}, {-60.01, 226.61}, {-0.69, 234.42}, {-0.90, 180.22}, {0.00, 0.00}},
0131         {{-117.22, 204.83}, {-144.50, 251.66}, {-75.77, 280.13}, {-61.95, 227.73}, {0.00, 0.00}},
0132         {{-60.21, 228.19}, {-74.44, 280.48}, {-0.69, 290.19}, {-0.90, 236.00}, {0.00, 0.00}},
0133         {{-145.11, 253.14}, {-172.39, 299.96}, {-90.21, 334.00}, {-76.38, 281.60}, {0.00, 0.00}},
0134         {{-74.65, 282.07}, {-88.88, 334.36}, {-0.69, 345.97}, {-0.90, 291.78}, {0.00, 0.00}},
0135         {{-173.00, 301.44}, {-200.28, 348.27}, {-104.65, 387.88}, {-90.82, 335.48}, {0.00, 0.00}},
0136         {{-89.09, 335.95}, {-103.31, 388.24}, {-0.69, 401.75}, {-0.90, 347.56}, {0.00, 0.00}},
0137         {{-200.89, 349.75}, {-228.17, 396.57}, {-119.08, 441.76}, {-105.26, 389.36}, {0.00, 0.00}},
0138         {{-103.52, 389.82}, {-117.75, 442.11}, {-0.69, 457.52}, {-0.90, 403.33}, {0.00, 0.00}},
0139         {{-228.78, 398.05}, {-256.05, 444.88}, {-133.52, 495.63}, {-119.69, 443.23}, {0.00, 0.00}},
0140         {{-117.96, 443.70}, {-132.19, 495.99}, {-0.69, 513.30}, {-0.90, 459.11}, {0.00, 0.00}},
0141         {{-256.67, 446.35}, {-283.94, 493.18}, {-147.95, 549.51}, {-134.13, 497.11}, {0.00, 0.00}},
0142         {{-132.40, 497.58}, {-146.62, 549.87}, {-0.69, 569.08}, {-0.90, 514.89}, {0.00, 0.00}},
0143         {{-284.56, 494.66}, {-311.83, 541.49}, {-162.39, 603.39}, {-148.57, 550.99}, {0.00, 0.00}},
0144         {{-146.83, 551.45}, {-161.06, 603.74}, {-0.69, 624.86}, {-0.90, 570.66}, {0.00, 0.00}},
0145         {{-312.44, 542.96}, {-339.72, 589.79}, {-176.83, 657.26}, {-163.00, 604.86}, {0.00, 0.00}},
0146         {{-161.27, 605.33}, {-175.50, 657.62}, {-0.69, 680.63}, {-0.90, 626.44}, {0.00, 0.00}},
0147         {{-340.33, 591.27}, {-367.61, 638.09}, {-191.26, 711.14}, {-177.44, 658.74}, {0.00, 0.00}},
0148         {{-175.70, 659.21}, {-189.93, 711.50}, {-0.69, 736.41}, {-0.90, 682.22}, {0.00, 0.00}},
0149         {{-368.22, 639.57}, {-395.50, 686.40}, {-205.70, 765.02}, {-191.87, 712.62}, {0.00, 0.00}},
0150         {{-190.14, 713.08}, {-204.37, 765.37}, {-0.69, 792.19}, {-0.90, 738.00}, {0.00, 0.00}},
0151         {{-396.11, 687.88}, {-423.39, 734.70}, {-220.13, 818.89}, {-206.31, 766.49}, {0.00, 0.00}},
0152         {{-204.58, 766.96}, {-218.80, 819.25}, {-0.69, 847.96}, {-0.90, 793.77}, {0.00, 0.00}},
0153         {{-424.00, 736.18}, {-451.58, 783.75}, {-234.88, 873.51}, {-220.75, 820.37}, {0.00, 0.00}},
0154         {{-219.01, 820.84}, {-233.34, 873.92}, {-0.79, 904.53}, {-0.90, 849.55}, {0.00, 0.00}},
0155 };
0156 
0157 G4ExtrudedSolid* PHG4EPDDetector::construct_block(int32_t index)
0158 {
0159   std::string label("tile_" + std::to_string(index));
0160 
0161   const double(*coords)[5][2] = &coordinates[index];
0162 
0163   std::vector<G4TwoVector> vertices;
0164 
0165   for (int32_t i = 0; i < 5; ++i)
0166   {
0167     double x = (*coords)[i][0];
0168     double y = (*coords)[i][1];
0169 
0170     if (x == 0. && y == 0.)
0171     {
0172       continue;
0173     }
0174     vertices.emplace_back(x * mm, y * mm);
0175   }
0176 
0177   std::vector<G4ExtrudedSolid::ZSection> zsections = {
0178       G4ExtrudedSolid::ZSection(-dz, G4TwoVector(), 1.),
0179       G4ExtrudedSolid::ZSection(dz, G4TwoVector(), 1.),
0180   };
0181 
0182   return new G4ExtrudedSolid(label, vertices, zsections);
0183 }