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>
112 assert(cylinder_mat);
127 if (
get_geom_v3()->get_construction_verbose() >= 1)
129 cout <<
"PHG4FullProjSpacalDetector::Construct_AzimuthalSeg::" <<
GetName()
130 <<
" - construct end walls." << endl;
144 typedef map<int, double> z_locations_t;
145 z_locations_t z_locations;
151 BOOST_FOREACH (z_locations_t::value_type& val, 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;
173 if (
get_geom_v3()->get_construction_verbose() >= 1)
175 cout <<
"PHG4FullProjSpacalDetector::Construct_AzimuthalSeg::" <<
GetName()
176 <<
" - construct side walls." << endl;
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);
195 BOOST_FOREACH (sign_t::value_type& val, signs)
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
228 BOOST_FOREACH (
const SpacalGeom_t::tower_map_t::value_type& val,
get_geom_v3()->get_sector_tower_map())
239 g_tower.
id, overlapcheck_block);
246 cout <<
"PHG4FullProjSpacalDetector::Construct_AzimuthalSeg::" <<
GetName()
248 <<
" unique towers" << endl;
262 typedef map<int, pair<G4Vector3D, G4Vector3D> > fiber_par_map;
263 fiber_par_map fiber_par;
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);
307 fiber_par[fiber_ID] = make_pair(vector_fiber,
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;
327 BOOST_FOREACH (
const fiber_par_map::value_type& val, fiber_par)
329 const int fiber_ID = val.first;
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, "
366 name <<
GetName() + string(
"_Tower") << g_tower.
id <<
"_fiber"
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;
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);
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, "
467 name <<
GetName() + string(
"_Tower") << g_tower.
id <<
"_fiber"
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());
513 assert(cylinder_mat);
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;
550 G4Exception(
"PHG4FullProjSpacalDetector::Construct_Tower",
"Wrong",
559 cout <<
"PHG4FullProjSpacalDetector::Print::" <<
GetName()
560 <<
" - Print Geometry:" << endl;