5 #if defined(FLATTEN) && defined(__GNUC__)
7 #pragma GCC optimize "-fno-var-tracking-assignments"
19 #include <GaudiKernel/SystemOfUnits.h>
21 #include "Acts/Geometry/TrapezoidVolumeBounds.hpp"
22 #include "Acts/Geometry/TrackingGeometry.hpp"
23 #include "Acts/Surfaces/TrapezoidBounds.hpp"
37 return StatusCode::SUCCESS;
39 template <
class EnvelopeType>
40 #if defined(FLATTEN) && defined(__GNUC__)
49 const Acts::Volume& boundVol,
51 const std::string&
descr,
56 Acts::Vector3 posInVolFrame((boundVol.transform().inverse()) * point);
57 if (boundVol.volumeBounds().inside(posInVolFrame,
tolerance)) {
59 <<
", point "<<
descr <<
" is inside of the chamber "<<std::endl<<chamb<<std::endl
60 <<
"Local position:" <<
Amg::toString(boundVol.itransform() * point));
61 return StatusCode::SUCCESS;
66 planeTrapezoid.
defineTrapezoid(chamb.halfXShort(), chamb.halfXLong(), chamb.halfY());
70 if (std::abs(locPos.z()) - chamb.halfZ() < -
tolerance &&
71 planeTrapezoid.insideTrapezoid(axisSwap*locPos.block<2,1>(0,0))) {
72 return StatusCode::SUCCESS;
74 planeTrapezoid.defineStripLayout(locPos.y() * Amg::Vector2D::UnitX(), 1, 1, 1);
77 <<std::endl<<std::endl<<chamb<<std::endl<<
"Local position "<<
Amg::toString(locPos)
80 return StatusCode::FAILURE;
85 const std::string&
descr,
87 if (volume.inside(point)) {
88 return StatusCode::SUCCESS;
92 <<
descr <<
" "<<
Amg::toString(point)<<
" is not part of the chamber volume. The corners of the volume are:");
93 for(
const auto& corner : volumeCorners) {
96 return StatusCode::FAILURE;
99 template <
class EnvelopeType>
101 const EnvelopeType& envelope)
const {
102 std::shared_ptr<Acts::Volume> boundVol = envelope.boundingVolume(gctx);
105 if constexpr (std::is_same_v<EnvelopeType, SpectrometerSector>) {
106 if (readOut->msSector() != &envelope) {
108 <<std::endl<<(*readOut->msSector())<<std::endl<<envelope);
109 return StatusCode::FAILURE;
111 }
else if constexpr (std::is_same_v<EnvelopeType, Chamber>) {
112 if (readOut->chamber() != &envelope) {
114 <<std::endl<<(*readOut->chamber())<<std::endl<<envelope);
115 return StatusCode::FAILURE;
118 switch (readOut->detectorType()) {
142 return StatusCode::FAILURE;
146 ATH_MSG_DEBUG(
"All "<<reEles.size()<<
" readout elements are embedded in "<<envelope);
147 return StatusCode::SUCCESS;
152 unsigned int edgeIdx{0};
153 using BoundEnum = Acts::TrapezoidVolumeBounds::BoundValues;
154 const auto& bounds =
static_cast<const Acts::TrapezoidVolumeBounds&
>(volume.volumeBounds());
156 for (
const double signX : {-1., 1.}) {
157 for (
const double signY : { -1., 1.}) {
158 for (
const double signZ: {-1., 1.}) {
159 const Amg::Vector3D edge{signX* (signY>0 ? bounds.get(BoundEnum::eHalfLengthXposY) :
160 bounds.get(BoundEnum::eHalfLengthXnegY)),
161 signY*bounds.get(BoundEnum::eHalfLengthY),
162 signZ*bounds.get(BoundEnum::eHalfLengthZ)};
163 edges[edgeIdx] = volume.transform() * edge;
174 using BoundEnum = Acts::LineBounds::BoundValues;
175 const auto& bounds =
static_cast<const Acts::LineBounds&
>(surface.bounds());
176 unsigned int edgeIdx{0};
179 for (
const double signX : {-1., 1.}) {
180 for (
const double signY : { -1., 1.}) {
181 for (
const double signZ: {-1., 1.}) {
183 signY*bounds.get(BoundEnum::eR),
184 signZ*bounds.get(BoundEnum::eHalfLengthZ)};
185 edges[edgeIdx] = surface.transform(gctx) * edge;
196 if(surface.bounds().type() == Acts::SurfaceBounds::BoundsType::eRectangle) {
197 const Acts::RectangleBounds& bounds =
static_cast<const Acts::RectangleBounds&
>(surface.bounds());
198 using BoundEnum = Acts::RectangleBounds::BoundValues;
200 unsigned int edgeIdx{0};
201 for(
const double signX : {-1., 1.}) {
202 for (
const double signY : { -1., 1.}) {
203 const Amg::Vector3D edge{ signX < 0 ? bounds.get(BoundEnum::eMinX) : bounds.get(BoundEnum::eMaxX),
204 signY < 0 ? bounds.get(BoundEnum::eMinY) : bounds.get(BoundEnum::eMaxY),
206 edges[edgeIdx] = surface.transform(gctx) * edge;
212 }
else if(surface.bounds().type() == Acts::SurfaceBounds::BoundsType::eTrapezoid) {
213 using BoundEnum = Acts::TrapezoidBounds::BoundValues;
214 const auto& bounds =
static_cast<const Acts::TrapezoidBounds&
>(surface.bounds());
215 unsigned int edgeIdx{0};
219 for (
const double signX : {-1., 1.}) {
220 for (
const double signY : { -1., 1.}) {
224 Amg::Vector3D(signX*bounds.get(signY < 0 ? BoundEnum::eHalfLengthXnegY : BoundEnum::eHalfLengthXposY),
225 signY*bounds.get(BoundEnum::eHalfLengthY),
228 edges[edgeIdx] = surface.transform(gctx) * edge;
235 ATH_MSG_FATAL(
"The surface bounds are neither a rectangle nor a trapezoid, this is not supported yet");
245 std::shared_ptr<const Acts::TrackingGeometry> trackingGeometry =
m_trackingGeometrySvc->trackingGeometry();
252 const std::shared_ptr<Acts::Volume> secVolume = sector->boundingVolume(*gctx);
255 unsigned int edgeCount{0};
259 chamber->readoutEles().front()->identify()));
261 const Acts::TrackingVolume* trkGeoVol = trackingGeometry->lowestTrackingVolume(gctx->context(),
chamber->boundingVolume(*gctx)->center());
262 ATH_MSG_DEBUG(
"Found "<<trkGeoVol->volumeName()<<
" with " << trkGeoVol->volumes().size() <<
" sub volumes for chamber "<<
m_idHelperSvc->toString(
chamber->readoutEles().front()->identify()));
264 if(trkGeoVol->volumes().size() > 2)
continue;
266 trkGeoVol->visitVolumes([&](
const Acts::TrackingVolume* volume) {
271 std::map<Identifier, const std::array<Amg::Vector3D, 8>> strawCorners;
272 std::map<Identifier, const std::array<Amg::Vector3D, 4>> trapezoidCorners;
275 trkGeoVol->visitSurfaces([&](
const Acts::Surface* surface) {
277 const auto* planeSurface =
static_cast<const Acts::PlaneSurface*
>(surface);
278 ATH_MSG_DEBUG(
"Found plane surface with id" << planeSurface->geometryId());
279 if(planeSurface->associatedDetectorElement()){
281 trapezoidCorners.emplace(iDetElement->
identify(),
cornerPoints(gctx->context(), *planeSurface));
284 const auto* strawSurface =
static_cast<const Acts::StrawSurface*
>(surface);
285 if(strawSurface->associatedDetectorElement() ) {
297 ATH_MSG_DEBUG(
"Found "<<strawCorners.size()<<
" straw corners and "<<trapezoidCorners.size()<<
" trapezoid corners in chamber "<<
m_idHelperSvc->toString(
chamber->readoutEles().front()->identify()));
299 for (
const auto& [
id, corners] : strawCorners) {
301 for (
unsigned int i = 0;
i < corners.size(); ++
i) {
304 chamber->readoutEles().front()->identify()));
308 unsigned int surfaceCount{0};
309 for (
const auto& [
id, corners] : trapezoidCorners) {
311 if(strawCorners.size() != 0){
316 for (
unsigned int i = 0;
i < corners.size(); ++
i) {
318 std::format(
"Trapezoid corner {:} of surface {:}",
i, ++surfaceCount),
331 return StatusCode::SUCCESS;
333 template <
class EnvelopeType>
337 const Acts::Volume& detVol)
const {
355 "bottom of the tube box", measId));
357 "sealing of the tube box", measId));
360 "wall to the previous tube", measId));
362 "wall to the next tube", measId));
365 return StatusCode::SUCCESS;
367 template<
class EnvelopeType>
371 const Acts::Volume& detVol)
const {
378 for (
bool measPhi : {
false,
true}) {
380 for (
int strip = 1; strip <=
nStrips; ++strip) {
390 return StatusCode::SUCCESS;
392 template <
class EnevelopeType>
396 const Acts::Volume& detVol)
const {
407 return StatusCode::SUCCESS;
409 template <
class EnevelopeType>
413 const Acts::Volume& detVol)
const {
419 for(
unsigned int strip =
firstStrip; strip <=
mm.numStrips(gasGapHash); ++strip){
427 return StatusCode::SUCCESS;
429 template <
class EnvelopeType>
433 const Acts::Volume& detVol)
const{
438 for(
unsigned int nch = 1; nch <= stgc.
nChTypes(); ++nch){
443 for(
unsigned int strip = 1; strip <=
nStrips; ++strip){
447 if(channelType == sTgcReadoutElement::ReadoutChannelType::Wire || channelType == sTgcReadoutElement::ReadoutChannelType::Strip){
460 return StatusCode::SUCCESS;