17 #include <Geant4/G4Box.hh>
18 #include <Geant4/G4Exception.hh>
19 #include <Geant4/G4ExceptionSeverity.hh>
20 #include <Geant4/G4LogicalVolume.hh>
21 #include <Geant4/G4Material.hh>
22 #include <Geant4/G4PVPlacement.hh>
23 #include <Geant4/G4PhysicalConstants.hh>
24 #include <Geant4/G4String.hh>
25 #include <Geant4/G4SystemOfUnits.hh>
26 #include <Geant4/G4Trap.hh>
27 #include <Geant4/G4Tubs.hh>
28 #include <Geant4/G4Types.hh>
29 #include <Geant4/G4Vector3D.hh>
33 #include <boost/foreach.hpp>
55 assert(
_geom ==
nullptr);
61 <<
"PHG4FullProjSpacalDetector::Constructor - Fatal Error - invalid geometry object!"
82 cout <<
"PHG4FullProjSpacalDetector::Construct::" <<
GetName()
83 <<
" - start with PHG4SpacalDetector::Construct()." << endl;
90 cout <<
"PHG4FullProjSpacalDetector::Construct::" <<
GetName()
91 <<
" - Completed." << endl;
95 std::pair<G4LogicalVolume*, G4Transform3D>
104 G4Tubs* sec_solid =
new G4Tubs(G4String(
GetName() +
string(
"_sec")),
112 assert(cylinder_mat);
114 G4LogicalVolume* sec_logic =
new G4LogicalVolume(sec_solid, cylinder_mat,
115 G4String(G4String(
GetName() +
string(
"_sec"))), 0, 0);
127 if (
get_geom_v3()->get_construction_verbose() >= 1)
129 cout <<
"PHG4FullProjSpacalDetector::Construct_AzimuthalSeg::" <<
GetName()
130 <<
" - construct end walls." << endl;
132 G4Tubs* wall_solid =
new G4Tubs(G4String(
GetName() +
string(
"_EndWall")),
139 G4LogicalVolume* wall_logic =
new G4LogicalVolume(wall_solid, wall_mat,
140 G4String(G4String(
GetName() +
string(
"_EndWall"))), 0, 0,
144 typedef map<int, double> z_locations_t;
145 z_locations_t z_locations;
153 if (
get_geom_v3()->get_construction_verbose() >= 2)
154 cout <<
"PHG4FullProjSpacalDetector::Construct_AzimuthalSeg::"
155 <<
GetName() <<
" - constructed End Wall ID " << val.first
156 <<
" @ Z = " << val.second << endl;
158 G4Transform3D wall_trans = G4TranslateZ3D(val.second);
160 G4PVPlacement* wall_phys =
new G4PVPlacement(wall_trans, wall_logic,
161 G4String(
GetName().c_str()) + G4String(
"_EndWall"), sec_logic,
173 if (
get_geom_v3()->get_construction_verbose() >= 1)
175 cout <<
"PHG4FullProjSpacalDetector::Construct_AzimuthalSeg::" <<
GetName()
176 <<
" - construct side walls." << endl;
178 G4Box* wall_solid =
new G4Box(G4String(
GetName() +
string(
"_SideWall")),
183 G4LogicalVolume* wall_logic =
new G4LogicalVolume(wall_solid, wall_mat,
184 G4String(G4String(
GetName() +
string(
"_SideWall"))), 0, 0,
188 typedef map<int, pair<int, int> > sign_t;
190 signs[2000] = make_pair(+1, +1);
191 signs[2001] = make_pair(+1, -1);
192 signs[2100] = make_pair(-1, +1);
193 signs[2101] = make_pair(-1, -1);
197 const int sign_z = val.second.first;
198 const int sign_azimuth = val.second.second;
200 if (
get_geom_v3()->get_construction_verbose() >= 2)
201 cout <<
"PHG4FullProjSpacalDetector::Construct_AzimuthalSeg::"
202 <<
GetName() <<
" - constructed Side Wall ID " << val.first
211 G4Transform3D wall_trans = G4RotateZ3D(
215 G4PVPlacement* wall_phys =
new G4PVPlacement(wall_trans, wall_logic,
216 G4String(
GetName().c_str()) + G4String(
"_EndWall"), sec_logic,
237 G4PVPlacement* block_phys =
new G4PVPlacement(block_trans, LV_tower,
238 G4String(
GetName().c_str()) + G4String(
"_Tower"), sec_logic,
false,
239 g_tower.
id, overlapcheck_block);
246 cout <<
"PHG4FullProjSpacalDetector::Construct_AzimuthalSeg::" <<
GetName()
248 <<
" unique towers" << endl;
250 return make_pair(sec_logic, G4Transform3D::Identity);
256 G4LogicalVolume* LV_tower)
262 typedef map<int, pair<G4Vector3D, G4Vector3D> > fiber_par_map;
263 fiber_par_map fiber_par;
264 G4double min_fiber_length = g_tower.
pDz *
cm * 4;
266 G4Vector3D v_zshift = G4Vector3D(tan(g_tower.
pTheta) *
cos(g_tower.
pPhi),
270 for (
int ix = 0; ix < g_tower.
NFiberX; ix++)
273 const double weighted_ix =
static_cast<double>(ix) / (g_tower.
NFiberX - 1.);
281 for (
int iy = 0; iy < g_tower.
NFiberY; iy++)
284 if ((ix + iy) % 2 == 1)
287 const double weighted_iy =
static_cast<double>(iy) / (g_tower.
NFiberY - 1.);
292 const double weighted_pDx12 = weighted_pDx1 * (1 - weighted_iy) + weighted_pDx2 * (weighted_iy) + weighted_pDy1 * tan(g_tower.
pAlp1);
293 const double weighted_pDx34 = weighted_pDx3 * (1 - weighted_iy) + weighted_pDx4 * (weighted_iy) + weighted_pDy1 * tan(g_tower.
pAlp2);
295 G4Vector3D
v1 = G4Vector3D(weighted_pDx12, weighted_pDy1, 0) - v_zshift;
296 G4Vector3D
v2 = G4Vector3D(weighted_pDx34, weighted_pDy2, 0) + v_zshift;
298 G4Vector3D vector_fiber = (v2 -
v1);
300 G4Vector3D center_fiber = (v2 +
v1) / 2;
307 fiber_par[fiber_ID] = make_pair(vector_fiber,
310 const G4double fiber_length = vector_fiber.mag();
312 min_fiber_length =
min(fiber_length, min_fiber_length);
320 const G4double fiber_length = min_fiber_length;
321 vector<G4double> fiber_cut;
324 ss << string(
"_Tower") << g_tower.
id;
325 G4LogicalVolume* fiber_logic =
Construct_Fiber(fiber_length, ss.str());
329 const int fiber_ID = val.first;
330 G4Vector3D vector_fiber = val.second.first;
331 G4Vector3D center_fiber = val.second.second;
332 const G4double optimal_fiber_length = vector_fiber.mag();
334 const G4Vector3D
v1 = center_fiber - 0.5 * vector_fiber;
337 assert(optimal_fiber_length - fiber_length >= 0);
338 fiber_cut.push_back(optimal_fiber_length - fiber_length);
340 center_fiber += (fiber_length / optimal_fiber_length - 1) * 0.5 * vector_fiber;
341 vector_fiber *= fiber_length / optimal_fiber_length;
346 cout <<
"PHG4FullProjSpacalDetector::Construct_Fibers_SameLengthFiberPerTower::" <<
GetName()
347 <<
" - constructed fiber " << fiber_ID << ss.str()
348 <<
", Length = " << optimal_fiber_length <<
"-"
349 << (optimal_fiber_length - fiber_length) <<
"mm, "
350 <<
"x = " << center_fiber.x() <<
"mm, "
351 <<
"y = " << center_fiber.y() <<
"mm, "
352 <<
"z = " << center_fiber.z() <<
"mm, "
353 <<
"vx = " << vector_fiber.x() <<
"mm, "
354 <<
"vy = " << vector_fiber.y() <<
"mm, "
355 <<
"vz = " << vector_fiber.z() <<
"mm, "
358 const G4double rotation_angle = G4Vector3D(0, 0, 1).angle(vector_fiber);
359 const G4Vector3D rotation_axis =
360 rotation_angle == 0 ? G4Vector3D(1, 0, 0) : G4Vector3D(0, 0, 1).cross(vector_fiber);
362 G4Transform3D fiber_place(
363 G4Translate3D(center_fiber.x(), center_fiber.y(), center_fiber.z()) * G4Rotate3D(rotation_angle, rotation_axis));
366 name <<
GetName() + string(
"_Tower") << g_tower.
id <<
"_fiber"
370 G4PVPlacement* fiber_physi =
new G4PVPlacement(fiber_place, fiber_logic,
371 G4String(name.str().c_str()), LV_tower,
false, fiber_ID,
381 if (
get_geom_v3()->get_construction_verbose() >= 2)
383 <<
"PHG4FullProjSpacalDetector::Construct_Fibers_SameLengthFiberPerTower::"
384 <<
GetName() <<
" - constructed tower ID " << g_tower.
id <<
" with "
385 << fiber_count <<
" fibers. Average fiber length cut = "
386 << accumulate(fiber_cut.begin(), fiber_cut.end(), 0.0) / fiber_cut.size() <<
" mm" << endl;
394 G4LogicalVolume* LV_tower)
396 G4Vector3D v_zshift = G4Vector3D(tan(g_tower.
pTheta) *
cos(g_tower.
pPhi),
400 for (
int ix = 0; ix < g_tower.
NFiberX; ix++)
402 const double weighted_ix =
static_cast<double>(ix) / (g_tower.
NFiberX - 1.);
410 for (
int iy = 0; iy < g_tower.
NFiberY; iy++)
412 if ((ix + iy) % 2 == 1)
416 const double weighted_iy =
static_cast<double>(iy) / (g_tower.
NFiberY - 1.);
421 const double weighted_pDx12 = weighted_pDx1 * (1 - weighted_iy) + weighted_pDx2 * (weighted_iy) + weighted_pDy1 * tan(g_tower.
pAlp1);
422 const double weighted_pDx34 = weighted_pDx3 * (1 - weighted_iy) + weighted_pDx4 * (weighted_iy) + weighted_pDy1 * tan(g_tower.
pAlp2);
424 G4Vector3D
v1 = G4Vector3D(weighted_pDx12, weighted_pDy1, 0) - v_zshift;
425 G4Vector3D
v2 = G4Vector3D(weighted_pDx34, weighted_pDy2, 0) + v_zshift;
427 G4Vector3D vector_fiber = (v2 -
v1);
429 G4Vector3D center_fiber = (v2 +
v1) / 2;
435 const G4double fiber_length = vector_fiber.mag();
438 ss << string(
"_Tower") << g_tower.
id;
445 cout <<
"PHG4FullProjSpacalDetector::Construct_Fibers::" <<
GetName()
446 <<
" - constructed fiber " << fiber_ID << ss.str()
447 <<
", Length = " << fiber_length <<
"mm, "
448 <<
"x = " << center_fiber.x() <<
"mm, "
449 <<
"y = " << center_fiber.y() <<
"mm, "
450 <<
"z = " << center_fiber.z() <<
"mm, "
451 <<
"vx = " << vector_fiber.x() <<
"mm, "
452 <<
"vy = " << vector_fiber.y() <<
"mm, "
453 <<
"vz = " << vector_fiber.z() <<
"mm, "
456 const G4double rotation_angle = G4Vector3D(0, 0, 1).angle(
458 const G4Vector3D rotation_axis =
459 rotation_angle == 0 ? G4Vector3D(1, 0, 0) : G4Vector3D(0, 0, 1).cross(vector_fiber);
461 G4Transform3D fiber_place(
462 G4Translate3D(center_fiber.x(), center_fiber.y(),
464 G4Rotate3D(rotation_angle, rotation_axis));
467 name <<
GetName() + string(
"_Tower") << g_tower.
id <<
"_fiber"
471 G4PVPlacement* fiber_physi =
new G4PVPlacement(fiber_place,
472 fiber_logic, G4String(name.str().c_str()), LV_tower,
false,
473 fiber_ID, overlapcheck_fiber);
483 if (
get_geom_v3()->get_construction_verbose() >= 3)
484 cout <<
"PHG4FullProjSpacalDetector::Construct_Fibers::" <<
GetName()
485 <<
" - constructed tower ID " << g_tower.
id <<
" with " << fiber_cnt
486 <<
" fibers" << endl;
496 std::stringstream sout;
497 sout <<
"_" << g_tower.
id;
498 const G4String sTowerID(sout.str());
502 G4Trap* block_solid =
new G4Trap(
503 G4String(
GetName().c_str()) + sTowerID,
513 assert(cylinder_mat);
515 G4LogicalVolume* block_logic =
new G4LogicalVolume(block_solid, cylinder_mat,
516 G4String(G4String(
GetName()) +
string(
"_Tower") + sTowerID), 0, 0,
529 if (
get_geom_v3()->get_construction_verbose() >= 2)
530 cout <<
"PHG4FullProjSpacalDetector::Construct_Tower::" <<
GetName()
531 <<
" - constructed tower ID " << g_tower.
id <<
" with "
532 << fiber_count <<
" fibers using Construct_Fibers" << endl;
539 if (
get_geom_v3()->get_construction_verbose() >= 2)
540 cout <<
"PHG4FullProjSpacalDetector::Construct_Tower::" <<
GetName()
541 <<
" - constructed tower ID " << g_tower.
id <<
" with "
543 <<
" fibers using Construct_Fibers_SameLengthFiberPerTower" << endl;
547 G4ExceptionDescription message;
550 G4Exception(
"PHG4FullProjSpacalDetector::Construct_Tower",
"Wrong",
551 FatalException, message,
"");
559 cout <<
"PHG4FullProjSpacalDetector::Print::" <<
GetName()
560 <<
" - Print Geometry:" << endl;