10 #include "GaudiKernel/MsgStream.h"
51 , m_motherVolume(nullptr)
52 , m_boundarySurfaces{}
53 , m_confinedLayers(
nullptr)
54 , m_confinedVolumes(
nullptr)
55 , m_confinedDetachedVolumes(
nullptr)
56 , m_confinedDenseVolumes(
nullptr)
57 , m_confinedArbitraryLayers(
nullptr)
58 , m_outsideGlueVolumes(
nullptr)
59 , m_layerAttemptsCalculator(
nullptr)
64 , m_redoNavigation(
false)
72 const std::string& volumeName)
73 :
Volume(htrans, volbounds)
75 , m_motherVolume(nullptr)
76 , m_boundarySurfaces{}
77 , m_confinedLayers(subLayers)
78 , m_confinedVolumes(subVolumes)
79 , m_confinedDetachedVolumes(
nullptr)
80 , m_confinedDenseVolumes(
nullptr)
81 , m_confinedArbitraryLayers(
nullptr)
82 , m_outsideGlueVolumes(
nullptr)
83 , m_layerAttemptsCalculator(
nullptr)
88 , m_redoNavigation(
false)
90 createBoundarySurfaces();
91 createLayerAttemptsCalculator();
100 const std::string& volumeName)
103 , m_motherVolume(nullptr)
104 , m_boundarySurfaces{}
105 , m_confinedLayers(subLayers)
106 , m_confinedVolumes(subVolumes)
107 , m_confinedDetachedVolumes(
nullptr)
108 , m_confinedDenseVolumes(
nullptr)
109 , m_confinedArbitraryLayers(
nullptr)
110 , m_outsideGlueVolumes(
nullptr)
111 , m_layerAttemptsCalculator(
nullptr)
116 , m_redoNavigation(
false)
118 createBoundarySurfaces();
119 createLayerAttemptsCalculator();
129 const std::string& volumeName)
130 :
Volume(htrans, volbounds)
132 , m_motherVolume(nullptr)
133 , m_confinedLayers(subLayers)
134 , m_confinedVolumes(subVolumes)
135 , m_confinedDetachedVolumes(nullptr)
136 , m_confinedDenseVolumes(nullptr)
137 , m_confinedArbitraryLayers(nullptr)
138 , m_outsideGlueVolumes(nullptr)
139 , m_layerAttemptsCalculator(nullptr)
144 , m_redoNavigation(false)
156 std::vector<DetachedTrackingVolume*>* detachedSubVolumes,
157 const std::string& volumeName)
158 :
Volume(htrans, volbounds)
160 , m_motherVolume(nullptr)
161 , m_confinedLayers(nullptr)
162 , m_confinedVolumes(nullptr)
163 , m_confinedDetachedVolumes(detachedSubVolumes)
164 , m_confinedDenseVolumes(nullptr)
165 , m_confinedArbitraryLayers(nullptr)
166 , m_outsideGlueVolumes(nullptr)
167 , m_layerAttemptsCalculator(nullptr)
172 , m_redoNavigation(false)
181 std::vector<DetachedTrackingVolume*>* detachedSubVolumes,
182 const std::string& volumeName)
185 , m_motherVolume(nullptr)
186 , m_confinedLayers(nullptr)
187 , m_confinedVolumes(nullptr)
188 , m_confinedDetachedVolumes(detachedSubVolumes)
189 , m_confinedDenseVolumes(nullptr)
190 , m_confinedArbitraryLayers(nullptr)
191 , m_outsideGlueVolumes(nullptr)
192 , m_layerAttemptsCalculator(nullptr)
197 , m_redoNavigation(false)
207 const std::vector<TrackingVolume*>* unorderedSubVolumes,
208 const std::string& volumeName)
209 :
Volume(htrans, volbounds)
211 , m_motherVolume(nullptr)
212 , m_confinedLayers(nullptr)
213 , m_confinedVolumes(nullptr)
214 , m_confinedDetachedVolumes(nullptr)
215 , m_confinedDenseVolumes(unorderedSubVolumes)
216 , m_confinedArbitraryLayers(nullptr)
217 , m_outsideGlueVolumes(nullptr)
218 , m_layerAttemptsCalculator(nullptr)
223 , m_redoNavigation(false)
232 const std::vector<TrackingVolume*>* unorderedSubVolumes,
233 const std::string& volumeName)
236 , m_motherVolume(nullptr)
237 , m_confinedLayers(nullptr)
238 , m_confinedVolumes(nullptr)
239 , m_confinedDetachedVolumes(nullptr)
240 , m_confinedDenseVolumes(unorderedSubVolumes)
241 , m_confinedArbitraryLayers(nullptr)
242 , m_outsideGlueVolumes(nullptr)
243 , m_layerAttemptsCalculator(nullptr)
248 , m_redoNavigation(false)
257 const std::vector<Layer*>*
layers,
258 const std::string& volumeName)
259 :
Volume(htrans, volbounds)
261 , m_motherVolume(nullptr)
262 , m_confinedLayers(nullptr)
263 , m_confinedVolumes(nullptr)
264 , m_confinedDetachedVolumes(nullptr)
265 , m_confinedDenseVolumes(nullptr)
266 , m_confinedArbitraryLayers(
layers)
267 , m_outsideGlueVolumes(nullptr)
268 , m_layerAttemptsCalculator(nullptr)
273 , m_redoNavigation(false)
281 const std::vector<Layer*>*
layers,
282 const std::string& volumeName)
285 , m_motherVolume(nullptr)
286 , m_confinedLayers(nullptr)
287 , m_confinedVolumes(nullptr)
288 , m_confinedDetachedVolumes(nullptr)
289 , m_confinedDenseVolumes(nullptr)
290 , m_confinedArbitraryLayers(
layers)
291 , m_outsideGlueVolumes(nullptr)
292 , m_layerAttemptsCalculator(nullptr)
297 , m_redoNavigation(false)
306 const std::vector<Layer*>*
layers,
307 const std::vector<TrackingVolume*>* unorderedSubVolumes,
309 const std::string& volumeName)
310 :
Volume(htrans, volbounds)
312 , m_motherVolume(nullptr)
313 , m_confinedLayers(nullptr)
314 , m_confinedVolumes(nullptr)
315 , m_confinedDetachedVolumes(nullptr)
316 , m_confinedDenseVolumes(unorderedSubVolumes)
317 , m_confinedArbitraryLayers(
layers)
318 , m_outsideGlueVolumes(nullptr)
319 , m_layerAttemptsCalculator(nullptr)
324 , m_redoNavigation(false)
332 const std::vector<Layer*>*
layers,
333 const std::vector<TrackingVolume*>* unorderedSubVolumes,
335 const std::string& volumeName)
338 , m_motherVolume(nullptr)
339 , m_confinedLayers(nullptr)
340 , m_confinedVolumes(nullptr)
341 , m_confinedDetachedVolumes(nullptr)
342 , m_confinedDenseVolumes(unorderedSubVolumes)
343 , m_confinedArbitraryLayers(
layers)
344 , m_outsideGlueVolumes(nullptr)
345 , m_layerAttemptsCalculator(nullptr)
350 , m_redoNavigation(false)
359 , m_motherVolume(trVol.m_motherVolume)
360 , m_boundarySurfaces{}
361 , m_confinedLayers(
nullptr)
362 , m_confinedVolumes(
nullptr)
363 , m_confinedDetachedVolumes(
nullptr)
364 , m_confinedDenseVolumes(
nullptr)
365 , m_confinedArbitraryLayers(
nullptr)
366 , m_outsideGlueVolumes(
nullptr)
367 , m_layerAttemptsCalculator(
nullptr)
370 , m_name(trVol.m_name)
371 , m_colorCode(trVol.m_colorCode)
372 , m_redoNavigation(trVol.m_redoNavigation)
375 m_boundarySurfaces.reserve(trVol.boundarySurfaces().size());
378 for (
size_t ib = 0;
ib < trVol.boundarySurfaces().
size();
ib++) {
381 out = in ==
nullptr ? this :
nullptr;
383 trVol.boundarySurfaces()[
ib]);
387 trVol.boundarySurfaces()[
ib]);
390 trVol.boundarySurfaces()[
ib]);
393 trVol.boundarySurfaces()[
ib]);
395 m_boundarySurfaces.push_back(
400 m_boundarySurfaces.push_back(
405 m_boundarySurfaces.push_back(
410 m_boundarySurfaces.push_back(
415 m_boundarySurfaces.push_back(
423 if (confinedLayers) {
425 std::vector<Trk::SharedObject<Trk::Layer>> layerOrder;
426 layerOrder.reserve(
layers.size());
446 trVol.confinedArbitraryLayers();
447 if (!confinedArbitraryLayers.empty()) {
449 std::vector<Trk::Layer*> uLayers;
450 uLayers.reserve(confinedArbitraryLayers.size());
451 for (
const auto *confinedArbitraryLayer : confinedArbitraryLayers) {
454 confinedArbitraryLayer);
457 confinedArbitraryLayer);
466 uLayers.push_back(lay);
469 uLayers.push_back(lay);
470 }
else if (sclayer) {
473 uLayers.push_back(lay);
476 uLayers.push_back(lay);
479 m_confinedArbitraryLayers =
new std::vector<Trk::Layer*>(uLayers);
484 trVol.confinedVolumes();
485 if (confinedVolumes) {
489 std::vector<Trk::SharedObject<Trk::TrackingVolume>> volOrder;
490 volOrder.reserve(volumes.size());
491 for (
const auto *volume : volumes) {
506 trVol.confinedDenseVolumes();
507 if (!confinedDenseVolumes.empty()) {
508 std::vector<Trk::TrackingVolume*> newVol;
509 newVol.reserve(confinedDenseVolumes.size());
511 for (
const auto *confinedDenseVolume : confinedDenseVolumes) {
514 newVol.push_back(vol);
516 m_confinedDenseVolumes =
517 new std::vector<Trk::TrackingVolume*>(newVol);
523 delete m_confinedLayers;
524 delete m_confinedVolumes;
525 delete m_confinedDetachedVolumes;
526 if (m_confinedDenseVolumes) {
527 for (
auto * confinedDenseVolume : *m_confinedDenseVolumes){
528 delete confinedDenseVolume;
530 delete m_confinedDenseVolumes;
532 if (m_confinedArbitraryLayers) {
533 for (
auto * confinedArbitraryLayer : *m_confinedArbitraryLayers){
534 delete confinedArbitraryLayer;
536 delete m_confinedArbitraryLayers;
538 delete m_layerAttemptsCalculator;
544 if (m_confinedVolumes) {
545 delete m_confinedVolumes;
546 m_confinedVolumes =
nullptr;
548 if (m_confinedLayers) {
549 delete m_confinedLayers;
550 m_confinedLayers =
nullptr;
552 if (m_confinedDenseVolumes) {
553 for (
auto * confinedDenseVolume : *m_confinedDenseVolumes){
554 delete confinedDenseVolume;
556 delete m_confinedDenseVolumes;
557 m_confinedDenseVolumes =
nullptr;
559 if (m_confinedArbitraryLayers) {
560 for (
auto *confinedArbitraryLayer : *m_confinedArbitraryLayers){
561 delete confinedArbitraryLayer;
563 delete m_confinedArbitraryLayers;
564 m_confinedArbitraryLayers =
nullptr;
572 if (m_confinedLayers)
573 return (confinedLayers()->
object(gp));
575 if (m_confinedArbitraryLayers) {
576 for (
auto * confinedArbitraryLayer : *m_confinedArbitraryLayers){
577 if (confinedArbitraryLayer->isOnLayer(gp)){
578 return confinedArbitraryLayer;
589 if (m_confinedLayers)
590 return (confinedLayers()->
object(gp));
592 if (m_confinedArbitraryLayers) {
593 for (
auto * confinedArbitraryLayer : *m_confinedArbitraryLayers){
594 if (confinedArbitraryLayer->isOnLayer(gp)){
595 return confinedArbitraryLayer;
607 bool associatedResult,
608 bool skipNavLayer)
const
611 if (m_confinedLayers)
612 nextLayer = (confinedLayers()->
nextObject(gp,
mom, associatedResult));
623 nextLayer = (confinedLayers()->
nextObject(gp,
mom, associatedResult));
634 std::vector<const Layer*> layerCandidates;
638 const auto& bSurfaces = boundarySurfaces();
639 for (
size_t ib = 0;
ib < bSurfaces.size(); ++
ib) {
640 if (bSurfaces[
ib]->surfaceRepresentation().materialLayer())
641 layerCandidates.push_back(
642 bSurfaces[
ib]->surfaceRepresentation().materialLayer());
646 if (m_confinedLayers) {
648 const Trk::Layer* assocLayer = associatedLayer(gp);
659 if (previousMatLayer)
660 layerCandidates.push_back(previousMatLayer);
662 layerCandidates.push_back(nextMatLayer);
664 layerCandidates.push_back(assocLayer);
671 if (!layerCandidates.empty()) {
672 const Layer* cLayer =
nullptr;
674 for (
auto& lcIter : layerCandidates) {
680 (*lcIter).surfaceRepresentation().straightLineIntersection(
681 gp, dirScalor *
dir, forceDir, bchk);
685 laySurfIntersection = sfI;
703 return (nVolume && nVolume !=
this)
706 laySurfIntersection,
nullptr,
nullptr,
nullptr, pDir);
712 if (m_confinedVolumes)
713 return (m_confinedVolumes->object(gp));
715 if (m_confinedDetachedVolumes) {
716 for (
auto *confinedDetachedVolume : *m_confinedDetachedVolumes) {
717 if (confinedDetachedVolume->trackingVolume()->inside(gp, 0.001)){
718 return confinedDetachedVolume->trackingVolume();
723 if (m_confinedDenseVolumes) {
724 for (
auto *confinedDenseVolume : *m_confinedDenseVolumes)
725 if (confinedDenseVolume->inside(gp, 0.001)){
726 return confinedDenseVolume;
736 if (m_confinedVolumes)
737 return (m_confinedVolumes->object(gp));
739 if (m_confinedDetachedVolumes) {
740 for (
auto *confinedDetachedVolume : *m_confinedDetachedVolumes) {
741 if (confinedDetachedVolume->trackingVolume()->inside(gp, 0.001)){
742 return confinedDetachedVolume->trackingVolume();
747 if (m_confinedDenseVolumes) {
748 for (
auto * confinedDenseVolume : *m_confinedDenseVolumes){
749 if (confinedDenseVolume->inside(gp, 0.001)){
750 return confinedDenseVolume;
770 double pathLength = 10e10;
772 const auto& bSurfaces = boundarySurfaces();
773 for (
size_t ib = 0;
ib < bSurfaces.size(); ++
ib) {
776 bSurfaces[
ib]->surfaceRepresentation().straightLineIntersection(
777 gp, cDir, forceDir,
true);
784 nVolume = bSurfaces[
ib]->attachedVolume(gp, cDir, attachedDir);
794 if (m_confinedVolumes)
795 return (m_confinedVolumes->nextObject(gp,
mom));
799 std::vector<const Trk::DetachedTrackingVolume*>
803 auto currVols = std::vector<const Trk::DetachedTrackingVolume*>();
806 confinedDetachedVolumes();
807 if (!detVols.empty()) {
808 for (
const auto *detVol : detVols) {
809 if (detVol->trackingVolume()->inside(gp, tol))
810 currVols.push_back(detVol);
823 if (m_confinedLayers) {
828 if (layerptr && layerptr->layerIndex().value() < 0) {
831 layerptr->layerMaterialProperties()
836 layerptr->registerLayerIndex(layIndex);
842 auto& bSurfaces = boundarySurfaces();
843 for (
const auto& bsIter : bSurfaces) {
854 if (confinedVolumes()) {
856 for (
const auto& volumesIter : volumes) {
858 volumesIter->indexContainedStaticLayers(geoSig,
offset);
870 if (m_confinedLayers) {
881 Trk::Layer* materialLayer = laySurf ? laySurf->materialLayer() :
nullptr;
901 if (confinedVolumes()) {
905 volumesIter->indexContainedMaterialLayers(geoSig,
offset);
914 float flin =
pow(fact, 0.33);
916 double invX0 =
X0 > 0. ? 1. /
X0 : 0.;
917 double sum_invX0 = invX0 + flin / mprop.
X0;
920 double invL0 =
L0 > 0. ? 1. /
L0 : 0.;
921 double sum_invL0 = invL0 + flin / mprop.
L0;
927 float n1 = Z > 0. ? rho1 / Z : 0.;
928 float n2 = fact * mprop.
rho / mprop.
Z;
931 n1 =
A > 0. ? rho1 /
A : 0.;
932 n2 = fact * mprop.
rho / mprop.
A;
937 dEdX += flin * mprop.
dEdX;
946 m_geometrySignature = geosign;
948 m_geometryType = geotype;
955 for (
const auto& volumesIter : volumes)
957 volumesIter->sign(geosign, geotype);
961 confinedDetachedVolumes();
962 if (!confDetachedVolumes.empty()) {
963 for (
const auto& volumesIter : confDetachedVolumes) {
965 volumesIter->sign(geosign, geotype);
971 confinedDenseVolumes();
972 if (!confDenseVolumes.empty()) {
973 for (
const auto& volumesIter : confDenseVolumes) {
975 volumesIter->sign(geosign, geotype);
981 std::vector<Trk::SharedObject<Trk::BoundarySurface<Trk::TrackingVolume>>>&
984 return m_boundarySurfaces;
997 return (std::as_const(m_boundarySurfaces)[oa]).get();
1004 m_boundarySurfaces =
1005 std::vector<Trk::SharedObject<Trk::BoundarySurface<Trk::TrackingVolume>>>();
1007 const std::vector<const Trk::Surface*>* surfaces =
1009 std::vector<const Trk::Surface*>::const_iterator surfIter = surfaces->begin();
1012 unsigned int sfCounter = 0;
1013 unsigned int sfNumber = surfaces->size();
1016 m_boundarySurfaces.reserve(sfNumber + 1);
1025 bool subtr = (subtrVol) ? 1 : 0;
1026 bool comb = (combVol) ? 1 : 0;
1028 if (!subtr && !comb) {
1033 for (; surfIter != surfaces->end(); ++surfIter) {
1046 if (spbVol && sfCounter == 1) {
1050 m_boundarySurfaces.push_back(
1058 m_boundarySurfaces.push_back(
1068 m_boundarySurfaces.push_back(
1081 (sfCounter == 4 && sfNumber > 3) ?
nullptr :
this;
1083 m_boundarySurfaces.push_back(
1086 inner, outer, *scsf)));
1092 (sfCounter == 4 && sfNumber > 3) ?
nullptr :
this;
1094 m_boundarySurfaces.push_back(
1097 inner, outer, *csf)));
1104 const std::vector<bool> bOrient =
1107 for (; surfIter != surfaces->end(); ++surfIter) {
1115 m_boundarySurfaces.push_back(
1126 m_boundarySurfaces.push_back(
1143 if (m_confinedLayers) {
1148 m_layerAttemptsCalculator =
1158 if (m_confinedLayers) {
1163 for (; layerIter !=
layers.end(); ++layerIter) {
1166 (**layerIter).setBinUtility(confinedLayers()->binUtility()
1167 ? confinedLayers()->binUtility()
1169 (**layerIter).setPreviousLayer(lastLayer);
1171 (**layerIter).encloseTrackingVolume(*
this);
1173 lastLayer = (*layerIter);
1176 lastLayer =
nullptr;
1177 layerIter =
layers.end();
1179 for (;; --layerIter) {
1181 (**layerIter).setNextLayer(lastLayer);
1183 lastLayer = (*layerIter);
1184 if (layerIter ==
layers.begin()) {
1195 return checkoutLayers;
1201 m_outsideGlueVolumes.store(std::unique_ptr<Trk::GlueVolumesDescriptor>(gvd));
1207 if (!m_outsideGlueVolumes) {
1208 m_outsideGlueVolumes.store(std::make_unique<Trk::GlueVolumesDescriptor>());
1210 return (*m_outsideGlueVolumes);
1216 if (!m_outsideGlueVolumes) {
1217 m_outsideGlueVolumes.set(std::make_unique<Trk::GlueVolumesDescriptor>());
1219 return (*m_outsideGlueVolumes);
1227 this->m_transform = std::make_unique<Amg::Transform3D>(transf);
1229 this->m_transform = std::make_unique<Amg::Transform3D>(shift);
1231 this->m_center.store(
1232 std::make_unique<Amg::Vector3D>(m_transform->translation()));
1247 std::vector<Trk::SharedObject<Trk::Layer>> layerOrder;
1267 std::vector<Trk::Layer*>* unorderedLayers =
nullptr;
1269 confinedArbitraryLayers();
1270 if (!confArbLayers.empty()) {
1272 std::vector<Trk::Layer*> uLayers;
1273 for (
const auto *confArbLayer : confArbLayers) {
1286 uLayers.push_back(lay);
1290 uLayers.push_back(lay);
1291 }
else if (sclayer) {
1295 uLayers.push_back(lay);
1296 }
else if (clayer) {
1299 uLayers.push_back(lay);
1302 unorderedLayers =
new std::vector<Trk::Layer*>(uLayers);
1311 std::vector<Trk::SharedObject<TrackingVolume>> volOrder;
1312 for (
const auto *volume : volumes) {
1327 confinedDenseVolumes();
1328 std::vector<Trk::TrackingVolume*>* newDenseVol =
nullptr;
1329 if (!confDenseVolumes.empty()) {
1330 std::vector<Trk::TrackingVolume*> newVol;
1332 for (
const auto *confDenseVolume : confDenseVolumes) {
1335 newVol.push_back(vol);
1337 newDenseVol =
new std::vector<Trk::TrackingVolume*>(newVol);
1342 if (!confArbLayers.empty() || !confDenseVolumes.empty()) {
1343 if (!confArbLayers.empty() && !confDenseVolumes.empty()) {
1345 *vol, unorderedLayers, newDenseVol, *
this, volumeName());
1346 }
else if (!confArbLayers.empty()) {
1356 *vol, *
this, layerArray, volumeArray, volumeName());
1377 first.surfaceRepresentation().straightLineDistanceEstimate(
pos,
dir);
1379 second.surfaceRepresentation().straightLineDistanceEstimate(
pos,
dir);
1401 confinedArbitraryLayers();
1402 if (!confArbLayers.empty()){
1418 confinedDenseVolumes();
1419 if (!confDenseVolumes.empty())
1434 if (clay->surfaceRepresentation().type() ==
1436 !(center().isApprox(clay->surfaceRepresentation().center()))) {
1437 clay->resizeAndRepositionLayer(volumeBounds(), center(), envelope);
1439 clay->resizeLayer(volumeBounds(), envelope);
1442 msgstream << MSG::WARNING
1443 <<
" ---> found 0 pointer to layer in Volume [ "
1444 << volumeName() <<
" ], indicates problem." <<
endmsg;
1449 for (
const auto& cVolumesIter : confVolumes->
arrayObjects())
1450 cVolumesIter->synchronizeLayers(msgstream, envelope);
1461 for (
const auto& clayIter :
layers) {
1462 if (&(*clayIter) !=
nullptr)
1463 clayIter->compactify(cSurfaces, tSurfaces);
1465 std::cout <<
"WARNING: Attempt to compactify nullptr layer in volume : "
1466 << volumeName() << std::endl;
1471 if (!confArbLayers.empty()) {
1472 for (
const auto& calayIter : confArbLayers) {
1473 if (calayIter !=
nullptr) {
1474 calayIter->compactify(cSurfaces, tSurfaces);
1476 std::cout <<
"WARNING: Attempt to compactify nullptr layer."
1486 for (
const auto& cVolumesIter : volumes) {
1487 cVolumesIter->compactify(cSurfaces, tSurfaces);
1492 confinedDenseVolumes();
1493 if (!confDenseVolumes.empty())
1494 for (
const auto& cVolumesIter : (confDenseVolumes)) {
1495 cVolumesIter->compactify(cSurfaces, tSurfaces);
1499 if (m_confinedDetachedVolumes)
1500 for (
const auto& cdVolumesIter : (*m_confinedDetachedVolumes)) {
1501 cdVolumesIter->compactify(cSurfaces, tSurfaces);
1508 msg <<
"[[ Trk::TrackingVolume ]] called: " << volumeName() << std::endl;
1509 msg <<
'\t' <<
'\t' <<
"# position (x,y,z) : " << center().x() <<
", "
1510 << center().y() <<
", " << center().z() << std::endl;
1511 msg <<
'\t' <<
'\t' <<
"# bounds : " << volumeBounds() <<
endmsg;