Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PHG4EPDDetector.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file PHG4EPDDetector.cc
1 /* vim: set sw=2 ft=cpp: */
2 
3 #include "PHG4EPDDetector.h"
4 
5 #include "PHG4EPDDisplayAction.h"
6 
7 #include <epd/EPDDefs.h>
8 
9 #include <g4main/PHG4Detector.h>
10 #include <g4main/PHG4DisplayAction.h> // for PHG4DisplayAction
11 #include <g4main/PHG4Subsystem.h>
12 
13 #include <phparameter/PHParameters.h>
14 
15 #include <Geant4/G4ExtrudedSolid.hh>
16 #include <Geant4/G4LogicalVolume.hh>
17 #include <Geant4/G4PVPlacement.hh>
18 #include <Geant4/G4RotationMatrix.hh>
19 #include <Geant4/G4String.hh> // for G4String
20 #include <Geant4/G4SystemOfUnits.hh>
21 #include <Geant4/G4ThreeVector.hh>
22 #include <Geant4/G4TwoVector.hh> // for G4TwoVector
23 #include <Geant4/G4VPhysicalVolume.hh> // for G4VPhysicalVolume
24 
25 #include <algorithm> // for max
26 #include <cmath>
27 #include <vector> // for vector
28 class G4Material;
29 
33  std::string const& name)
34  : PHG4Detector(subsys, node, name)
35  , m_DisplayAction(dynamic_cast<PHG4EPDDisplayAction*>(subsys->GetDisplayAction()))
36  , m_Params(parameters)
37  , m_ActiveFlag(m_Params->get_int_param("active"))
38  , m_SupportActiveFlag(m_Params->get_int_param("supportactive"))
39 {
40 }
41 
42 void PHG4EPDDetector::ConstructMe(G4LogicalVolume* world)
43 {
44  G4Material* material = GetDetectorMaterial("G4_PLASTIC_SC_VINYLTOLUENE");
45 
46  G4ThreeVector positive(0., 0., m_Params->get_double_param("place_z") * cm);
47  G4ThreeVector negative(0., 0., -m_Params->get_double_param("place_z") * cm);
48 
49  constexpr int32_t ntiles = 31;
50  constexpr int32_t nsectors = 12;
51 
52  for (int32_t i = 0; i < ntiles; ++i)
53  {
54  std::string label = "EPD_tile_" + std::to_string(i);
55 
56  G4ExtrudedSolid* block = construct_block(i);
57  G4LogicalVolume* volume = new G4LogicalVolume(block, material, label, nullptr, nullptr, nullptr);
58 
59  GetDisplayAction()->AddVolume(volume, volume->GetName());
60  m_ActiveLogVolSet.insert(volume);
61 
62  for (int32_t k = 0; k < nsectors; ++k)
63  {
64  G4RotationMatrix* rotate = new G4RotationMatrix();
65 
66  double phi_shift = (k + 9) * 2 * M_PI / nsectors;
67 
68  if (phi_shift >= (2.0 * M_PI))
69  {
70  phi_shift -= (2.0 * M_PI);
71  }
72  else if (phi_shift < 0.0)
73  {
74  phi_shift += (2.0 * M_PI);
75  }
76 
77  rotate->rotateZ(-1 * phi_shift);
78 
79  m_volumes.emplace(
80  new G4PVPlacement(rotate, negative, volume, label, world, false, 2 * k + 0, OverlapCheck()),
81  module_id_for(i, k, 0));
82 
83  m_volumes.emplace(
84  new G4PVPlacement(rotate, positive, volume, label, world, false, 2 * k + 1, OverlapCheck()),
85  module_id_for(i, k, 1));
86  }
87  }
88 }
89 
91 {
92  G4LogicalVolume* mylogvol = volume->GetLogicalVolume();
93  if (m_ActiveFlag)
94  {
95  if (m_ActiveLogVolSet.find(mylogvol) != m_ActiveLogVolSet.end())
96  {
97  return 1;
98  }
99  }
101  {
102  if (m_SupportLogVolSet.find(mylogvol) != m_SupportLogVolSet.end())
103  {
104  return -2;
105  }
106  }
107  return 0;
108 }
109 
110 uint32_t PHG4EPDDetector::module_id_for(uint32_t tile_id, uint32_t sector, uint32_t arm)
111 {
112  return EPDDefs::make_epd_key(arm, sector, tile_id);
113 }
114 
116 {
117  return m_volumes[volume];
118 }
119 
120 static constexpr double dz = 6.;
121 
122 static constexpr double coordinates[31][5][2] =
123  {
124  {{-22.43, 40.39}, {-44.41, 78.05}, {-23.29, 86.91}, {-0.57, 89.80}, {-0.77, 46.19}},
125  {{-44.96, 79.66}, {-66.53, 116.62}, {-35.41, 129.51}, {-24.54, 88.12}, {0.00, 0.00}},
126  {{-22.81, 88.58}, {-34.08, 129.86}, {-0.69, 134.26}, {-0.90, 91.47}, {0.00, 0.00}},
127  {{-67.15, 118.09}, {-88.72, 155.05}, {-46.90, 172.37}, {-36.03, 130.98}, {0.00, 0.00}},
128  {{-34.29, 131.45}, {-45.57, 172.73}, {-0.69, 178.64}, {-0.90, 135.85}, {0.00, 0.00}},
129  {{-89.34, 156.53}, {-116.61, 203.35}, {-61.34, 226.25}, {-47.51, 173.85}, {0.00, 0.00}},
130  {{-45.78, 174.32}, {-60.01, 226.61}, {-0.69, 234.42}, {-0.90, 180.22}, {0.00, 0.00}},
131  {{-117.22, 204.83}, {-144.50, 251.66}, {-75.77, 280.13}, {-61.95, 227.73}, {0.00, 0.00}},
132  {{-60.21, 228.19}, {-74.44, 280.48}, {-0.69, 290.19}, {-0.90, 236.00}, {0.00, 0.00}},
133  {{-145.11, 253.14}, {-172.39, 299.96}, {-90.21, 334.00}, {-76.38, 281.60}, {0.00, 0.00}},
134  {{-74.65, 282.07}, {-88.88, 334.36}, {-0.69, 345.97}, {-0.90, 291.78}, {0.00, 0.00}},
135  {{-173.00, 301.44}, {-200.28, 348.27}, {-104.65, 387.88}, {-90.82, 335.48}, {0.00, 0.00}},
136  {{-89.09, 335.95}, {-103.31, 388.24}, {-0.69, 401.75}, {-0.90, 347.56}, {0.00, 0.00}},
137  {{-200.89, 349.75}, {-228.17, 396.57}, {-119.08, 441.76}, {-105.26, 389.36}, {0.00, 0.00}},
138  {{-103.52, 389.82}, {-117.75, 442.11}, {-0.69, 457.52}, {-0.90, 403.33}, {0.00, 0.00}},
139  {{-228.78, 398.05}, {-256.05, 444.88}, {-133.52, 495.63}, {-119.69, 443.23}, {0.00, 0.00}},
140  {{-117.96, 443.70}, {-132.19, 495.99}, {-0.69, 513.30}, {-0.90, 459.11}, {0.00, 0.00}},
141  {{-256.67, 446.35}, {-283.94, 493.18}, {-147.95, 549.51}, {-134.13, 497.11}, {0.00, 0.00}},
142  {{-132.40, 497.58}, {-146.62, 549.87}, {-0.69, 569.08}, {-0.90, 514.89}, {0.00, 0.00}},
143  {{-284.56, 494.66}, {-311.83, 541.49}, {-162.39, 603.39}, {-148.57, 550.99}, {0.00, 0.00}},
144  {{-146.83, 551.45}, {-161.06, 603.74}, {-0.69, 624.86}, {-0.90, 570.66}, {0.00, 0.00}},
145  {{-312.44, 542.96}, {-339.72, 589.79}, {-176.83, 657.26}, {-163.00, 604.86}, {0.00, 0.00}},
146  {{-161.27, 605.33}, {-175.50, 657.62}, {-0.69, 680.63}, {-0.90, 626.44}, {0.00, 0.00}},
147  {{-340.33, 591.27}, {-367.61, 638.09}, {-191.26, 711.14}, {-177.44, 658.74}, {0.00, 0.00}},
148  {{-175.70, 659.21}, {-189.93, 711.50}, {-0.69, 736.41}, {-0.90, 682.22}, {0.00, 0.00}},
149  {{-368.22, 639.57}, {-395.50, 686.40}, {-205.70, 765.02}, {-191.87, 712.62}, {0.00, 0.00}},
150  {{-190.14, 713.08}, {-204.37, 765.37}, {-0.69, 792.19}, {-0.90, 738.00}, {0.00, 0.00}},
151  {{-396.11, 687.88}, {-423.39, 734.70}, {-220.13, 818.89}, {-206.31, 766.49}, {0.00, 0.00}},
152  {{-204.58, 766.96}, {-218.80, 819.25}, {-0.69, 847.96}, {-0.90, 793.77}, {0.00, 0.00}},
153  {{-424.00, 736.18}, {-451.58, 783.75}, {-234.88, 873.51}, {-220.75, 820.37}, {0.00, 0.00}},
154  {{-219.01, 820.84}, {-233.34, 873.92}, {-0.79, 904.53}, {-0.90, 849.55}, {0.00, 0.00}},
155 };
156 
157 G4ExtrudedSolid* PHG4EPDDetector::construct_block(int32_t index)
158 {
159  std::string label("tile_" + std::to_string(index));
160 
161  const double(*coords)[5][2] = &coordinates[index];
162 
163  std::vector<G4TwoVector> vertices;
164 
165  for (int32_t i = 0; i < 5; ++i)
166  {
167  double x = (*coords)[i][0];
168  double y = (*coords)[i][1];
169 
170  if (x == 0. && y == 0.)
171  {
172  continue;
173  }
174  vertices.emplace_back(x * mm, y * mm);
175  }
176 
177  std::vector<G4ExtrudedSolid::ZSection> zsections = {
178  G4ExtrudedSolid::ZSection(-dz, G4TwoVector(), 1.),
179  G4ExtrudedSolid::ZSection(dz, G4TwoVector(), 1.),
180  };
181 
182  return new G4ExtrudedSolid(label, vertices, zsections);
183 }