File indexing completed on 2025-01-18 10:13:56
0001
0002
0003
0004
0005
0006
0007
0008 #pragma once
0009
0010 #include "VecGeom/base/Global.h"
0011
0012 #include "VecGeom/volumes/PlacedVolume.h"
0013 #include "VecGeom/base/Vector3D.h"
0014 #include "VecGeom/management/GeoManager.h"
0015 #include "VecGeom/navigation/NavigationState.h"
0016 #include "VecGeom/base/Transformation3D.h"
0017 #include "VecGeom/volumes/kernel/BoxImplementation.h"
0018
0019 #include <map>
0020 #include <vector>
0021
0022 namespace vecgeom {
0023 inline namespace VECGEOM_IMPL_NAMESPACE {
0024
0025
0026
0027
0028 class ABBoxManager {
0029 public:
0030 typedef float Real_t;
0031 using Float_v = vecgeom::VectorBackend::Float_v;
0032
0033 typedef Vector3D<Float_v> ABBox_v;
0034
0035 typedef Vector3D<Precision> ABBox_s;
0036
0037
0038
0039 typedef ABBox_s *ABBoxContainer_t;
0040 typedef ABBox_v *ABBoxContainer_v;
0041
0042 typedef std::pair<unsigned int, double> BoxIdDistancePair_t;
0043
0044
0045 template <typename C, typename Compare>
0046 static void sort(C &v, Compare cmp)
0047 {
0048 std::sort(v.begin(), v.end(), cmp);
0049 }
0050
0051 struct HitBoxComparatorFunctor {
0052 bool operator()(BoxIdDistancePair_t const &left, BoxIdDistancePair_t const &right)
0053 {
0054 return left.second < right.second;
0055 }
0056 };
0057
0058 using FP_t = HitBoxComparatorFunctor;
0059
0060 private:
0061 std::vector<ABBoxContainer_t> fVolToABBoxesMap;
0062 std::vector<ABBoxContainer_v> fVolToABBoxesMap_v;
0063
0064 public:
0065
0066 static void ComputeABBox(VPlacedVolume const *pvol, ABBox_s *lower, ABBox_s *upper);
0067 static void ComputeSplittedABBox(VPlacedVolume const *pvol, std::vector<ABBox_s> &lower, std::vector<ABBox_s> &upper,
0068 int numOfSlices);
0069
0070 static ABBoxManager &Instance()
0071 {
0072 static ABBoxManager instance;
0073 return instance;
0074 }
0075
0076
0077
0078
0079 void InitABBoxes(LogicalVolume const *lvol);
0080
0081
0082 template <typename Container>
0083 void InitABBoxes(Container const &lvolumes)
0084 {
0085 for (auto lvol : lvolumes) {
0086 InitABBoxes(lvol);
0087 }
0088 }
0089
0090 void InitABBoxesForCompleteGeometry()
0091 {
0092 auto &container = GeoManager::Instance().GetLogicalVolumesMap();
0093 fVolToABBoxesMap.resize(container.size(), nullptr);
0094 fVolToABBoxesMap_v.resize(container.size(), nullptr);
0095 std::vector<LogicalVolume const *> logicalvolumes(container.size());
0096 logicalvolumes.resize(0);
0097 for (auto p : container) {
0098 logicalvolumes.push_back(p.second);
0099 }
0100 InitABBoxes(logicalvolumes);
0101 }
0102
0103
0104 void RemoveABBoxes(LogicalVolume const *lvol);
0105
0106
0107
0108 ABBoxContainer_t GetABBoxes(LogicalVolume const *lvol, int &size)
0109 {
0110 size = lvol->GetDaughtersp()->size();
0111 return fVolToABBoxesMap[lvol->id()];
0112 }
0113
0114
0115
0116 ABBoxContainer_v GetABBoxes_v(LogicalVolume const *lvol, int &size)
0117 {
0118 int ndaughters = lvol->GetDaughtersp()->size();
0119 int extra = (ndaughters % vecCore::VectorSize<Float_v>() > 0) ? 1 : 0;
0120 size = ndaughters / vecCore::VectorSize<Float_v>() + extra;
0121 return fVolToABBoxesMap_v[lvol->id()];
0122 }
0123 };
0124
0125
0126 template <typename stream>
0127 stream &operator<<(stream &s, std::vector<ABBoxManager::BoxIdDistancePair_t> const &list)
0128 {
0129 for (auto i : list) {
0130 s << "(" << i.first << "," << i.second << ")"
0131 << " ";
0132 }
0133 return s;
0134 }
0135 }
0136 }