11 #include "GaudiKernel/MsgStream.h"
51 std::unique_ptr<Amg::Transform3D> htrans,
52 std::shared_ptr<VolumeBounds> volbounds,
53 std::unique_ptr<LayerArray> subLayers,
54 std::unique_ptr<TrackingVolumeArray> subVolumes,
55 const std::string& volumeName)
56 :
Volume(std::move(htrans), std::move(volbounds))
58 , m_boundarySurfaces{}
59 , m_confinedLayers(std::move(subLayers))
60 , m_confinedVolumes(std::move(subVolumes))
63 createBoundarySurfaces();
64 createLayerAttemptsCalculator();
71 std::unique_ptr<LayerArray> subLayers,
72 std::unique_ptr<TrackingVolumeArray> subVolumes,
73 const std::string& volumeName)
76 , m_confinedLayers(std::move(subLayers))
77 , m_confinedVolumes(std::move(subVolumes))
87 std::unique_ptr<Amg::Transform3D> htrans,
88 std::shared_ptr<VolumeBounds> volbounds,
90 std::unique_ptr<LayerArray> subLayers,
91 std::unique_ptr<TrackingVolumeArray> subVolumes,
92 const std::string& volumeName)
93 :
Volume(std::move(htrans), std::move(volbounds))
95 , m_confinedLayers(std::move(subLayers))
96 , m_confinedVolumes(std::move(subVolumes))
106 std::unique_ptr<Amg::Transform3D> htrans,
107 std::shared_ptr<VolumeBounds> volbounds,
109 std::unique_ptr<std::vector<DetachedTrackingVolume*>> detachedSubVolumes,
110 const std::string& volumeName)
111 :
Volume(std::move(htrans), std::move(volbounds))
113 , m_confinedDetachedVolumes(std::move(detachedSubVolumes))
123 std::unique_ptr<std::vector<DetachedTrackingVolume*>> detachedSubVolumes,
124 const std::string& volumeName)
127 , m_confinedDetachedVolumes(std::move(detachedSubVolumes))
135 std::unique_ptr<Amg::Transform3D> htrans,
136 std::shared_ptr<VolumeBounds> volbounds,
138 std::unique_ptr<
const std::vector<TrackingVolume*>> unorderedSubVolumes,
139 const std::string& volumeName)
140 :
Volume(std::move(htrans), std::move(volbounds))
142 , m_confinedDenseVolumes(std::move(unorderedSubVolumes))
152 std::unique_ptr<
const std::vector<TrackingVolume*>> unorderedSubVolumes,
153 const std::string& volumeName)
156 , m_confinedDenseVolumes(std::move(unorderedSubVolumes))
164 std::unique_ptr<Amg::Transform3D> htrans,
165 std::shared_ptr<VolumeBounds> volbounds,
167 std::unique_ptr<
const std::vector<Layer*>>
layers,
168 const std::string& volumeName)
169 :
Volume(std::move(htrans), std::move(volbounds))
171 , m_confinedArbitraryLayers(std::move(
layers))
180 std::unique_ptr<
const std::vector<Layer*>>
layers,
181 const std::string& volumeName)
184 , m_confinedArbitraryLayers(std::move(
layers))
192 std::unique_ptr<Amg::Transform3D> htrans,
193 std::shared_ptr<VolumeBounds> volbounds,
194 std::unique_ptr<
const std::vector<Layer*>>
layers,
195 std::unique_ptr<
const std::vector<TrackingVolume*>> unorderedSubVolumes,
197 const std::string& volumeName)
198 :
Volume(std::move(htrans), std::move(volbounds))
200 , m_confinedDenseVolumes(std::move(unorderedSubVolumes))
201 , m_confinedArbitraryLayers(std::move(
layers))
210 std::unique_ptr<
const std::vector<Layer*>>
layers,
211 std::unique_ptr<
const std::vector<TrackingVolume*>> unorderedSubVolumes,
213 const std::string& volumeName)
216 , m_confinedDenseVolumes(std::move(unorderedSubVolumes))
217 , m_confinedArbitraryLayers(std::move(
layers))
227 , m_motherVolume(trVol.m_motherVolume)
228 , m_boundarySurfaces{}
230 , m_colorCode(trVol.m_colorCode)
233 m_boundarySurfaces.reserve(trVol.boundarySurfaces().size());
236 for (
size_t ib = 0;
ib < trVol.boundarySurfaces().
size();
ib++) {
238 out = in ==
nullptr ? this :
nullptr;
247 trVol.boundarySurfaces()[
ib]);
250 trVol.boundarySurfaces()[
ib]);
252 m_boundarySurfaces.push_back(
255 m_boundarySurfaces.push_back(
258 m_boundarySurfaces.push_back(
261 m_boundarySurfaces.push_back(
264 m_boundarySurfaces.push_back(
271 if (confinedLayers) {
273 std::vector<std::shared_ptr<Trk::Layer>> layerOrder;
274 layerOrder.reserve(
layers.size());
279 layerOrder.push_back(std::shared_ptr<Trk::Layer>(newlay));
285 m_confinedLayers = std::make_unique<Trk::NavBinnedArray1D<Trk::Layer>>(
287 std::vector<std::shared_ptr<Trk::Layer>>(layerOrder),
294 trVol.confinedArbitraryLayers();
295 if (!confinedArbitraryLayers.empty()) {
297 std::vector<Trk::Layer*> uLayers;
298 uLayers.reserve(confinedArbitraryLayers.size());
299 for (
const auto *confinedArbitraryLayer : confinedArbitraryLayers) {
302 confinedArbitraryLayer);
305 confinedArbitraryLayer);
313 uLayers.push_back(lay);
316 uLayers.push_back(lay);
317 }
else if (sclayer) {
319 uLayers.push_back(lay);
322 uLayers.push_back(lay);
325 m_confinedArbitraryLayers = std::make_unique<std::vector<Trk::Layer*>>(uLayers);
330 trVol.confinedVolumes();
331 if (confinedVolumes) {
333 std::span<Trk::TrackingVolume const * const > volumes =
335 std::vector<std::shared_ptr<Trk::TrackingVolume>> volOrder;
336 volOrder.reserve(volumes.size());
337 for (
const auto *volume : volumes) {
339 volOrder.push_back(std::shared_ptr<TrackingVolume>(vol));
345 m_confinedVolumes = std::make_unique<Trk::NavBinnedArray1D<Trk::TrackingVolume>>(
347 std::vector<std::shared_ptr<Trk::TrackingVolume>>(volOrder),
353 trVol.confinedDenseVolumes();
354 if (!confinedDenseVolumes.empty()) {
355 std::vector<Trk::TrackingVolume*> newVol;
356 newVol.reserve(confinedDenseVolumes.size());
358 for (
const auto *confinedDenseVolume : confinedDenseVolumes) {
360 newVol.push_back(vol);
362 m_confinedDenseVolumes = std::make_unique<const std::vector<Trk::TrackingVolume*>>(newVol);
369 if (m_confinedDenseVolumes) {
370 for (
auto * confinedDenseVolume : *m_confinedDenseVolumes){
371 delete confinedDenseVolume;
374 if (m_confinedArbitraryLayers) {
375 for (
auto * confinedArbitraryLayer : *m_confinedArbitraryLayers){
376 delete confinedArbitraryLayer;
385 if (m_confinedLayers){
386 return (confinedLayers()->
object(gp));
389 if (m_confinedArbitraryLayers) {
390 for (
auto* confinedArbitraryLayer : *m_confinedArbitraryLayers){
391 if (confinedArbitraryLayer->isOnLayer(gp)){
392 return confinedArbitraryLayer;
403 if (m_confinedLayers){
404 return (confinedLayers()->
object(gp));
407 if (m_confinedArbitraryLayers) {
408 for (
auto * confinedArbitraryLayer : *m_confinedArbitraryLayers){
409 if (confinedArbitraryLayer->isOnLayer(gp)){
410 return confinedArbitraryLayer;
420 bool associatedResult,
421 bool skipNavLayer)
const
424 if (m_confinedLayers){
425 nextLayer = (confinedLayers()->
nextObject(gp,
mom, associatedResult));
439 nextLayer = (confinedLayers()->
nextObject(gp,
mom, associatedResult));
451 std::vector<const Layer*> layerCandidates;
455 const auto& bSurfaces = boundarySurfaces();
456 for (
size_t ib = 0;
ib < bSurfaces.size(); ++
ib) {
457 if (bSurfaces[
ib]->surfaceRepresentation().materialLayer()){
458 layerCandidates.push_back(bSurfaces[
ib]->surfaceRepresentation().materialLayer());
463 if (m_confinedLayers) {
465 const Trk::Layer* assocLayer = associatedLayer(gp);
476 if (previousMatLayer){
477 layerCandidates.push_back(previousMatLayer);
480 layerCandidates.push_back(nextMatLayer);
483 layerCandidates.push_back(assocLayer);
490 if (!layerCandidates.empty()) {
491 const Layer* cLayer =
nullptr;
493 for (
auto& lcIter : layerCandidates) {
499 (*lcIter).surfaceRepresentation().straightLineIntersection(
500 gp, dirScalor *
dir, forceDir, bchk);
504 laySurfIntersection = sfI;
523 return (nVolume && nVolume !=
this)
526 laySurfIntersection,
nullptr,
nullptr,
nullptr, pDir);
532 if (m_confinedVolumes){
533 return (m_confinedVolumes->object(gp));
536 if (m_confinedDetachedVolumes) {
537 for (
auto *confinedDetachedVolume : *m_confinedDetachedVolumes) {
538 if (confinedDetachedVolume->trackingVolume()->inside(gp, 0.001)){
539 return confinedDetachedVolume->trackingVolume();
544 if (m_confinedDenseVolumes) {
545 for (
auto *confinedDenseVolume : *m_confinedDenseVolumes){
546 if (confinedDenseVolume->inside(gp, 0.001)){
547 return confinedDenseVolume;
558 if (m_confinedVolumes){
559 return (m_confinedVolumes->object(gp));
562 if (m_confinedDetachedVolumes) {
563 for (
auto *confinedDetachedVolume : *m_confinedDetachedVolumes) {
564 if (confinedDetachedVolume->trackingVolume()->inside(gp, 0.001)){
565 return confinedDetachedVolume->trackingVolume();
570 if (m_confinedDenseVolumes) {
571 for (
auto * confinedDenseVolume : *m_confinedDenseVolumes){
572 if (confinedDenseVolume->inside(gp, 0.001)){
573 return confinedDenseVolume;
593 double pathLength = 10e10;
595 const auto& bSurfaces = boundarySurfaces();
596 for (
size_t ib = 0;
ib < bSurfaces.size(); ++
ib) {
599 bSurfaces[
ib]->surfaceRepresentation().straightLineIntersection(
600 gp, cDir, forceDir,
true);
607 nVolume = bSurfaces[
ib]->attachedVolume(gp, cDir, attachedDir);
617 if (m_confinedVolumes){
618 return (m_confinedVolumes->nextObject(gp,
mom));
623 std::vector<const Trk::DetachedTrackingVolume*>
627 auto currVols = std::vector<const Trk::DetachedTrackingVolume*>();
630 confinedDetachedVolumes();
631 if (!detVols.empty()) {
632 for (
const auto *detVol : detVols) {
633 if (detVol->trackingVolume()->inside(gp, tol)){
634 currVols.push_back(detVol);
648 if (m_confinedLayers) {
653 if (layerptr && layerptr->layerIndex().value() < 0) {
656 layerptr->layerMaterialProperties()
661 layerptr->registerLayerIndex(layIndex);
667 auto& bSurfaces = boundarySurfaces();
668 for (
const auto& bsIter : bSurfaces) {
679 if (confinedVolumes()) {
680 std::span<Trk::TrackingVolume* const > volumes = confinedVolumes()->
arrayObjects();
681 for (
const auto& volumesIter : volumes) {
683 volumesIter->indexContainedStaticLayers(geoSig,
offset);
695 if (m_confinedLayers) {
703 std::span<Trk::Surface * const> layerSurfaces = surfArray->
arrayObjects();
726 if (confinedVolumes()) {
727 std::span<Trk::TrackingVolume * const> volumes = confinedVolumes()->
arrayObjects();
730 volumesIter->indexContainedMaterialLayers(geoSig,
offset);
739 float flin =
pow(fact, 0.33);
741 double invX0 =
X0 > 0. ? 1. /
X0 : 0.;
742 double sum_invX0 = invX0 + flin / mprop.
X0;
745 double invL0 =
L0 > 0. ? 1. /
L0 : 0.;
746 double sum_invL0 = invL0 + flin / mprop.
L0;
752 float n1 = Z > 0. ? rho1 / Z : 0.;
753 float n2 = fact * mprop.
rho / mprop.
Z;
756 n1 =
A > 0. ? rho1 /
A : 0.;
757 n2 = fact * mprop.
rho / mprop.
A;
762 dEdX += flin * mprop.
dEdX;
771 m_geometrySignature = geosign;
773 m_geometryType = geotype;
778 std::span<Trk::TrackingVolume* const> volumes =
780 for (
const auto& volumesIter : volumes){
782 volumesIter->sign(geosign, geotype);
788 confinedDetachedVolumes();
789 if (!confDetachedVolumes.empty()) {
790 for (
const auto& volumesIter : confDetachedVolumes) {
792 volumesIter->sign(geosign, geotype);
798 confinedDenseVolumes();
799 if (!confDenseVolumes.empty()) {
800 for (
const auto& volumesIter : confDenseVolumes) {
802 volumesIter->sign(geosign, geotype);
808 std::vector<std::shared_ptr<Trk::BoundarySurface<Trk::TrackingVolume>>>&
811 return m_boundarySurfaces;
824 return (std::as_const(m_boundarySurfaces)[oa]).get();
832 std::vector<std::shared_ptr<Trk::BoundarySurface<Trk::TrackingVolume>>>();
834 std::vector<std::unique_ptr<Trk::Surface>> surfaces =
836 auto surfIter = surfaces.begin();
839 unsigned int sfCounter = 0;
840 unsigned int sfNumber = surfaces.size();
843 m_boundarySurfaces.reserve(sfNumber + 1);
852 bool subtr = (subtrVol) ? 1 : 0;
853 bool comb = (combVol) ? 1 : 0;
855 if (!subtr && !comb) {
860 for (; surfIter != surfaces.end(); ++surfIter) {
873 if (spbVol && sfCounter == 1) {
877 m_boundarySurfaces.push_back(
883 m_boundarySurfaces.push_back(
891 m_boundarySurfaces.push_back(
902 (sfCounter == 4 && sfNumber > 3) ?
nullptr :
this;
904 m_boundarySurfaces.push_back(
910 (sfCounter == 4 && sfNumber > 3) ?
nullptr :
this;
912 m_boundarySurfaces.push_back(
914 inner, outer, *csf));
920 const std::vector<bool> bOrient =
923 for (; surfIter != surfaces.end(); ++surfIter) {
931 m_boundarySurfaces.push_back(
940 m_boundarySurfaces.push_back(
953 if (m_confinedLayers) {
958 m_layerAttemptsCalculator = std::make_unique<Trk::CylinderLayerAttemptsCalculator>(1, 5);
961 m_layerAttemptsCalculator = std::make_unique<Trk::DiscLayerAttemptsCalculator>(1, 5);
969 if (m_confinedLayers) {
970 std::span<Trk::Layer* const>
layers = m_confinedLayers->arrayObjects();
974 for (; layerIter !=
layers.end(); ++layerIter) {
977 (**layerIter).setBinUtility(confinedLayers()->binUtility()
978 ? confinedLayers()->binUtility()
980 (**layerIter).setPreviousLayer(lastLayer);
982 (**layerIter).encloseTrackingVolume(*
this);
984 lastLayer = (*layerIter);
990 for (;; --layerIter) {
992 (**layerIter).setNextLayer(lastLayer);
994 lastLayer = (*layerIter);
995 if (layerIter ==
layers.begin()) {
1006 return checkoutLayers;
1012 m_outsideGlueVolumes.store(std::unique_ptr<Trk::GlueVolumesDescriptor>(gvd));
1018 if (!m_outsideGlueVolumes) {
1019 m_outsideGlueVolumes.store(std::make_unique<Trk::GlueVolumesDescriptor>());
1021 return (*m_outsideGlueVolumes);
1027 if (!m_outsideGlueVolumes) {
1028 m_outsideGlueVolumes.set(std::make_unique<Trk::GlueVolumesDescriptor>());
1030 return (*m_outsideGlueVolumes);
1038 this->m_transform = std::make_unique<Amg::Transform3D>(transf);
1040 this->m_transform = std::make_unique<Amg::Transform3D>(shift);
1042 this->m_center = (m_transform->translation());
1053 first.surfaceRepresentation().straightLineDistanceEstimate(
pos,
dir);
1055 second.surfaceRepresentation().straightLineDistanceEstimate(
pos,
dir);
1077 confinedArbitraryLayers();
1078 if (!confArbLayers.empty()){
1095 if (!confDenseVolumes.empty())
1110 if (clay->surfaceRepresentation().type() ==
1112 !(center().isApprox(clay->surfaceRepresentation().center()))) {
1113 clay->resizeAndRepositionLayer(volumeBounds(), center(), envelope);
1115 clay->resizeLayer(volumeBounds(), envelope);
1118 msgstream << MSG::WARNING
1119 <<
" ---> found 0 pointer to layer in Volume [ "
1120 << volumeName() <<
" ], indicates problem." <<
endmsg;
1125 for (
const auto& cVolumesIter : confVolumes->
arrayObjects())
1126 cVolumesIter->synchronizeLayers(msgstream, envelope);
1137 for (
const auto& clayIter :
layers) {
1138 if (&(*clayIter) !=
nullptr){
1139 clayIter->compactify(cSurfaces, tSurfaces);
1142 std::cout <<
"WARNING: Attempt to compactify nullptr layer in volume : "
1143 << volumeName() << std::endl;
1149 if (!confArbLayers.empty()) {
1150 for (
const auto& calayIter : confArbLayers) {
1151 if (calayIter !=
nullptr) {
1152 calayIter->compactify(cSurfaces, tSurfaces);
1154 std::cout <<
"WARNING: Attempt to compactify nullptr layer."
1162 std::span<Trk::TrackingVolume* const> volumes =
1164 for (
const auto& cVolumesIter : volumes) {
1165 cVolumesIter->compactify(cSurfaces, tSurfaces);
1170 if (!confDenseVolumes.empty()){
1171 for (
const auto& cVolumesIter : (confDenseVolumes)) {
1172 cVolumesIter->compactify(cSurfaces, tSurfaces);
1177 if (m_confinedDetachedVolumes){
1178 for (
const auto& cdVolumesIter : (*m_confinedDetachedVolumes)) {
1179 cdVolumesIter->compactify(cSurfaces, tSurfaces);
1187 msg <<
"[[ Trk::TrackingVolume ]] called: " << volumeName() << std::endl;
1188 msg <<
'\t' <<
'\t' <<
"# position (x,y,z) : " << center().x() <<
", "
1189 << center().y() <<
", " << center().z() << std::endl;
1190 msg <<
'\t' <<
'\t' <<
"# bounds : " << volumeBounds() <<
endmsg;