10 #include "CaloDetDescr/CaloDetDescrElement.h"
13 #include "Acts/Geometry/TrackingVolume.hpp"
14 #include "Acts/Geometry/VolumeBounds.hpp"
15 #include "Acts/Geometry/GlueVolumesDescriptor.hpp"
18 #include "Acts/Geometry/GenericCuboidVolumeBounds.hpp"
19 #include "Acts/Geometry/CutoutCylinderVolumeBounds.hpp"
20 #include "Acts/Geometry/CylinderVolumeBounds.hpp"
21 #include "Acts/Utilities/Helpers.hpp"
22 #include "Acts/Geometry/TrackingVolumeArrayCreator.hpp"
23 #include "Acts/Utilities/BinnedArrayXD.hpp"
24 #include "Acts/Geometry/CylinderVolumeHelper.hpp"
28 using Box = Acts::Volume::BoundingBox;
30 using CVBBV = Acts::CylinderVolumeBounds::BoundValues;
31 using CCVBBV = Acts::CutoutCylinderVolumeBounds::BoundValues;
34 const std::string&
name,
51 return StatusCode::SUCCESS;
54 std::shared_ptr<Acts::TrackingVolume>
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;
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());
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"};
351 std::shared_ptr<Acts::CutoutCylinderVolumeBounds>
353 std::shared_ptr<const Acts::TrackingVolume> insideVolume)
const
355 using namespace Acts::VectorHelpers;
360 double rmax = std::numeric_limits<double>::lowest();
362 double zmax = std::numeric_limits<double>::lowest();
369 for (
const auto& box : boxStore) {
370 Acts::Vector3
vmin = box->min().cast<
double>();
371 Acts::Vector3
vmax = box->max().cast<
double>();
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>();
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()));
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()))) < 1
e-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);
506 eta_to_theta(
double eta)
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;
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);
551 Acts::Vector3 center;
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);
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;
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));
700 std::vector<std::unique_ptr<Acts::Volume>>
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;
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());