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