56 const Acts::GeometryContext& gctx,
57 std::shared_ptr<const Acts::TrackingVolume> insideVolume,
58 std::shared_ptr<const Acts::VolumeBounds> )
const
63 std::vector<std::unique_ptr<Acts::Volume>> cells;
70 std::vector<std::unique_ptr<Box>> boxStore;
71 std::vector<Box*> prims;
72 for (
const auto& cell : cells) {
74 std::make_unique<Box>(cell->boundingBox({0.1, 0.1, 0.1})));
75 prims.push_back(boxStore.back().get());
83 std::shared_ptr<Acts::CutoutCylinderVolumeBounds> caloVolBounds
94 std::vector<std::unique_ptr<const Acts::Volume>> cellVols;
95 cellVols.reserve(cells.size());
96 for(
auto& cell : cells) {
97 std::unique_ptr<const Acts::Volume> up;
99 up = std::unique_ptr<const Acts::Volume>(
dynamic_cast<const Acts::Volume*
>(cell.release()));
100 cellVols.push_back(std::move(up));
106 throw std::runtime_error{
"Calo building for ACTS currently disabled"};
353 std::shared_ptr<const Acts::TrackingVolume> insideVolume)
const
355 using namespace Acts::VectorHelpers;
358 double rmin_at_center = std::numeric_limits<double>::max();
359 double rmin_at_choke = std::numeric_limits<double>::max();
360 double rmax = std::numeric_limits<double>::lowest();
361 double zmin = std::numeric_limits<double>::max();
362 double zmax = std::numeric_limits<double>::lowest();
363 double cutout_zmin_abs = std::numeric_limits<double>::max();
369 for (
const auto& box : boxStore) {
370 Acts::Vector3 vmin = box->min().cast<
double>();
371 Acts::Vector3 vmax = box->max().cast<
double>();
373 double vrmin =
perp(vmin);
374 double vrmax =
perp(vmax);
376 rmin_at_choke = std::min(rmin_at_choke, std::min(vrmin, vrmax));
378 rmax = std::max(rmax, std::max(vrmin, vrmax));
379 zmin = std::min(zmin, std::min(vmin.z(), vmax.z()));
380 zmax = std::max(zmax, std::max(vmin.z(), vmax.z()));
382 if (std::abs(vmin.z()) < 100) {
383 rmin_at_center = std::min(vrmin, rmin_at_center);
385 if (std::abs(vmax.z()) < 100) {
386 rmin_at_center = std::min(vrmax, rmin_at_center);
390 for (
const auto& box : boxStore) {
391 Acts::Vector3 vmin = box->min().cast<
double>();
392 Acts::Vector3 vmax = box->max().cast<
double>();
393 double vrmin =
perp(vmin);
394 double vrmax =
perp(vmax);
396 if (vrmin < rmin_at_center * 0.9) {
397 cutout_zmin_abs = std::min(cutout_zmin_abs, std::abs(vmin.z()));
399 if (vrmax < rmin_at_center * 0.9) {
400 cutout_zmin_abs = std::min(cutout_zmin_abs, std::abs(vmax.z()));
404 double dz1 = (zmax - zmin) / 2.;
405 double dz2 = cutout_zmin_abs;
413 if(rmin_at_choke > envR) rmin_at_choke -= envR;
414 rmin_at_center -= envR;
418 <<
" rmin at choke: " << rmin_at_choke
419 <<
" rmax: " << rmax <<
" zmin: " << zmin <<
" zmax: " << zmax
420 <<
" coutout_zmin_abs: " << cutout_zmin_abs);
428 =
dynamic_cast<const Acts::CylinderVolumeBounds*
>(&insideVolume->volumeBounds());
429 if (idCylBds ==
nullptr) {
430 ATH_MSG_ERROR(
"Unable to dynamic cast volume bounds to Acts::CylinderVolumeBounds");
431 throw std::runtime_error(
"Error casting to CylinderVolumeBounds");
434 double idRMax = idCylBds->get(CVBBV::eMaxR);
435 double idRMin = idCylBds->get(CVBBV::eMinR);
436 double idHlZ = idCylBds->get(CVBBV::eHalfLengthZ);
440 ATH_MSG_VERBOSE(
"Inside volume transform: \n" << insideVolume->transform().matrix());
442 if (!insideVolume->transform().isApprox(Acts::Transform3::Identity())) {
448 const auto& trf = insideVolume->transform();
450 Acts::RotationMatrix3 rot = trf.rotation();
451 bool unityRot = rot.isApprox(Acts::RotationMatrix3::Identity());
456 const Acts::Vector3 trl = trf.translation();
457 bool transZOnly = std::abs(1 - std::abs(Acts::Vector3::UnitZ().
dot(trl.normalized()))) < 1e-6;
460 ATH_MSG_VERBOSE(
"TRL "<< trl.normalized().dot(Acts::Vector3::UnitZ()));
462 if(!unityRot || !transZOnly) {
463 ATH_MSG_ERROR(
"The ID appears to be shifted from the origin. I cannot handle this.");
465 throw std::runtime_error(
"Error building calo");
468 ATH_MSG_VERBOSE(
"Checked: non unitarity is ONLY due to shift along z axis: that's ok");
469 double prevIdHlZ = idHlZ;
470 idHlZ += std::abs(trl.z());
471 ATH_MSG_VERBOSE(
"Modifying effective half length of ID cylinder: " << prevIdHlZ <<
" => " << idHlZ);
476 if (idRMax > rmin_at_center || idHlZ > dz2 || (idRMin > rmin_at_choke && idRMin != 0.)) {
478 ATH_MSG_ERROR(
"This can be because the ID overlaps into the calo volume");
479 ATH_MSG_ERROR(
"Or because the Calo choke radius is SMALLER than the ID inner radius");
480 ATH_MSG_ERROR(
"Currently, I can only make the choke radius smaller, I can not make it larger");
481 ATH_MSG_ERROR(
"nor can I manipulate the ID volume bounds at this point.");
482 ATH_MSG_ERROR(
"ID rMax: " << idRMax <<
" Calo rMin@center: " << rmin_at_center);
483 ATH_MSG_ERROR(
"ID hlZ: " << idHlZ <<
" Calo inner Z hl: " << dz2);
484 ATH_MSG_ERROR(
"ID rMin: " << idRMin <<
" Calo rMin@choke: " << rmin_at_choke);
486 throw std::runtime_error(
"Error building calo");
492 rmin_at_choke = idRMin;
494 std::shared_ptr<Acts::CutoutCylinderVolumeBounds> volBds =
nullptr;
495 volBds = std::make_shared<Acts::CutoutCylinderVolumeBounds>(
496 rmin_at_choke, rmin_at_center, rmax, dz1, dz2);
520 double eta_max =
eta + deta * 0.5;
521 double eta_min =
eta - deta * 0.5;
522 double theta_max = eta_to_theta(eta_max);
524 double theta_min = eta_to_theta(eta_min);
525 double phi_max =
phi + dphi * 0.5;
526 double phi_min =
phi - dphi * 0.5;
527 double z_min =
z - dz;
528 double z_max =
z + dz;
533 r_min = std::tan(theta_min) * z_min;
534 r_max = std::tan(theta_max) * z_min;
536 Acts::Vector3 p1(r_min * std::cos(phi_min), r_min * std::sin(phi_min), z_min);
537 Acts::Vector3 p2(r_min * std::cos(phi_max), r_min * std::sin(phi_max), z_min);
538 Acts::Vector3 p3(r_max * std::cos(phi_max), r_max * std::sin(phi_max), z_min);
539 Acts::Vector3 p4(r_max * std::cos(phi_min), r_max * std::sin(phi_min), z_min);
542 r_min = std::tan(theta_min) * z_max;
543 r_max = std::tan(theta_max) * z_max;
545 Acts::Vector3 p5(r_min * std::cos(phi_min), r_min * std::sin(phi_min), z_max);
546 Acts::Vector3 p6(r_min * std::cos(phi_max), r_min * std::sin(phi_max), z_max);
547 Acts::Vector3 p7(r_max * std::cos(phi_max), r_max * std::sin(phi_max), z_max);
548 Acts::Vector3 p8(r_max * std::cos(phi_min), r_max * std::sin(phi_min), z_max);
550 double r_mid = std::tan(
theta) * z_min;
551 Acts::Vector3 center;
552 center.x() = r_mid * std::cos(
phi);
553 center.y() = r_mid * std::sin(
phi);
556 Acts::Transform3 glob2vol = Acts::Transform3::Identity();
557 glob2vol *= Acts::AngleAxis3(-
phi, Acts::Vector3::UnitZ());
558 glob2vol *= Acts::AngleAxis3(
559 -
theta, Acts::Vector3::UnitZ().cross(center).normalized());
561 *= Acts::Translation3(-(p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8) / 8.);
572 auto globalToLocal = glob2vol.inverse();
574 auto cubo = std::make_shared<Acts::GenericCuboidVolumeBounds>(
575 std::array<Acts::Vector3, 8>({{p1, p2, p3, p4, p5, p6, p7, p8}}));
576 Acts::Volume vol(globalToLocal, std::move(cubo));
591 double eta_max =
eta + deta * 0.5;
592 double eta_min =
eta - deta * 0.5;
594 double theta_max = eta_to_theta(eta_max);
595 double theta_min = eta_to_theta(eta_min);
596 double phi_max =
phi + dphi * 0.5;
597 double phi_min =
phi - dphi * 0.5;
599 double r_min =
r - dr;
600 double r_max =
r + dr;
605 z_min = r_min / std::tan(theta_min);
606 z_max = r_min / std::tan(theta_max);
608 Acts::Vector3 p1(r_min * std::cos(phi_min), r_min * std::sin(phi_min), z_min);
609 Acts::Vector3 p2(r_min * std::cos(phi_min), r_min * std::sin(phi_min), z_max);
610 Acts::Vector3 p3(r_min * std::cos(phi_max), r_min * std::sin(phi_max), z_max);
611 Acts::Vector3 p4(r_min * std::cos(phi_max), r_min * std::sin(phi_max), z_min);
614 z_min = r_max / std::tan(theta_min);
615 z_max = r_max / std::tan(theta_max);
617 Acts::Vector3 p5(r_max * std::cos(phi_min), r_max * std::sin(phi_min), z_min);
618 Acts::Vector3 p6(r_max * std::cos(phi_min), r_max * std::sin(phi_min), z_max);
619 Acts::Vector3 p7(r_max * std::cos(phi_max), r_max * std::sin(phi_max), z_max);
620 Acts::Vector3 p8(r_max * std::cos(phi_max), r_max * std::sin(phi_max), z_min);
622 Acts::Vector3 center;
623 center.x() =
r * std::cos(
phi);
624 center.y() =
r * std::sin(
phi);
625 center.z() =
r / std::tan(
theta);
627 Acts::Transform3 glob2vol = Acts::Transform3::Identity();
628 glob2vol *= Acts::AngleAxis3(-
phi, Acts::Vector3::UnitZ());
629 glob2vol *= Acts::AngleAxis3(
630 -
theta, Acts::Vector3::UnitZ().cross(center).normalized());
632 *= Acts::Translation3(-(p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8) / 8.);
643 auto globalToLocal = glob2vol.inverse();
645 auto cubo = std::make_shared<Acts::GenericCuboidVolumeBounds>(
646 std::array<Acts::Vector3, 8>({{p1, p2, p3, p4, p5, p6, p7, p8}}));
648 Acts::Volume vol(globalToLocal, std::move(cubo));
658 double x_min, x_max, y_min, y_max, z_min, z_max;
667 Acts::Vector3 p1(x_min, y_min, z_min);
668 Acts::Vector3 p2(x_min, y_max, z_min);
669 Acts::Vector3 p3(x_max, y_max, z_min);
670 Acts::Vector3 p4(x_max, y_min, z_min);
673 Acts::Vector3 p5(x_min, y_min, z_max);
674 Acts::Vector3 p6(x_min, y_max, z_max);
675 Acts::Vector3 p7(x_max, y_max, z_max);
676 Acts::Vector3 p8(x_max, y_min, z_max);
678 Acts::Transform3 glob2vol = Acts::Transform3::Identity();
680 *= Acts::Translation3(-(p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8) / 8.);
691 auto globalToLocal = glob2vol.inverse();
693 auto cubo = std::make_shared<Acts::GenericCuboidVolumeBounds>(
694 std::array<Acts::Vector3, 8>({{p1, p2, p3, p4, p5, p6, p7, p8}}));
695 Acts::Volume vol(globalToLocal, std::move(cubo));
708 float z, dz, eta_raw, deta, phi_raw, dphi,
r, dr,
x,
y, dx, dy;
713 std::vector<std::unique_ptr<Acts::Volume>> cells;
714 cells.reserve(
m_caloMgr->element_size());
716 for(
auto it =
m_caloMgr->element_begin();it < m_caloMgr->element_end();++it) {
735 if (calosample >= 12 && calosample <= 20) {
749 switch (calosample) {
760 cells.push_back(std::make_unique<Acts::Volume>(
776 cells.push_back(std::make_unique<Acts::Volume>(
786 cells.push_back(std::make_unique<Acts::Volume>(
790 std::stringstream
ss;
791 ss <<
"Unkown calo sample " << calosample;
792 std::runtime_error(
ss.str());