File indexing completed on 2025-08-06 08:10:16
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 #pragma once
0014
0015 #include "Acts/Definitions/Algebra.hpp"
0016 #include "Acts/Geometry/CuboidVolumeBounds.hpp"
0017 #include "Acts/Geometry/CutoutCylinderVolumeBounds.hpp"
0018 #include "Acts/Geometry/CylinderVolumeBounds.hpp"
0019 #include "Acts/Geometry/Volume.hpp"
0020 #include "Acts/Utilities/BinUtility.hpp"
0021
0022 #include <stdexcept>
0023
0024 namespace Acts {
0025
0026
0027
0028
0029
0030
0031
0032
0033 BinUtility adjustBinUtility(const BinUtility& bu,
0034 const CylinderVolumeBounds& cBounds,
0035 const Transform3& transform) {
0036
0037 BinUtility uBinUtil(transform);
0038
0039 double minR = cBounds.get(CylinderVolumeBounds::eMinR);
0040 double maxR = cBounds.get(CylinderVolumeBounds::eMaxR);
0041 double minPhi = -cBounds.get(CylinderVolumeBounds::eHalfPhiSector);
0042 double maxPhi = cBounds.get(CylinderVolumeBounds::eHalfPhiSector);
0043 double minZ = -cBounds.get(CylinderVolumeBounds::eHalfLengthZ);
0044 double maxZ = cBounds.get(CylinderVolumeBounds::eHalfLengthZ);
0045
0046 const std::vector<BinningData>& bData = bu.binningData();
0047
0048 for (auto& bd : bData) {
0049
0050 BinningValue bval = bd.binvalue;
0051
0052
0053
0054 if (bd.type == arbitrary) {
0055 throw std::invalid_argument("Arbitrary binning can not be adjusted.");
0056 } else if (bval != binR && bval != binPhi && bval != binZ) {
0057 throw std::invalid_argument("Cylinder volume binning must be: phi, r, z");
0058 }
0059 float min = 0;
0060 float max = 0;
0061
0062 if (bval == binPhi) {
0063 min = minPhi;
0064 max = maxPhi;
0065 } else if (bval == binR) {
0066 min = minR;
0067 max = maxR;
0068 } else if (bval == binZ) {
0069 min = minZ;
0070 max = maxZ;
0071 }
0072
0073 BinningData uBinData(bd.option, bval, bd.bins(), min, max);
0074 uBinUtil += BinUtility(uBinData);
0075 }
0076
0077 return uBinUtil;
0078 }
0079
0080
0081
0082
0083
0084
0085
0086
0087
0088 BinUtility adjustBinUtility(const BinUtility& bu,
0089 const CutoutCylinderVolumeBounds& cBounds,
0090 const Transform3& transform) {
0091
0092 BinUtility uBinUtil(transform);
0093
0094 double minR = cBounds.get(CutoutCylinderVolumeBounds::eMinR);
0095 double maxR = cBounds.get(CutoutCylinderVolumeBounds::eMaxR);
0096 double minPhi = -M_PI;
0097 double maxPhi = M_PI;
0098 double minZ = -cBounds.get(CutoutCylinderVolumeBounds::eHalfLengthZ);
0099 double maxZ = cBounds.get(CutoutCylinderVolumeBounds::eHalfLengthZ);
0100
0101 const std::vector<BinningData>& bData = bu.binningData();
0102
0103 for (auto& bd : bData) {
0104
0105 BinningValue bval = bd.binvalue;
0106
0107
0108
0109 if (bd.type == arbitrary) {
0110 throw std::invalid_argument("Arbitrary binning can not be adjusted.");
0111 } else if (bval != binR && bval != binPhi && bval != binZ) {
0112 throw std::invalid_argument(
0113 "Cutout cylinder volume binning must be: phi, r, z");
0114 }
0115 float min = 0;
0116 float max = 0;
0117
0118 if (bval == binPhi) {
0119 min = minPhi;
0120 max = maxPhi;
0121 } else if (bval == binR) {
0122 min = minR;
0123 max = maxR;
0124 } else if (bval == binZ) {
0125 min = minZ;
0126 max = maxZ;
0127 }
0128
0129 BinningData uBinData(bd.option, bval, bd.bins(), min, max);
0130 uBinUtil += BinUtility(uBinData);
0131 }
0132
0133 return uBinUtil;
0134 }
0135
0136
0137
0138
0139
0140
0141
0142
0143 BinUtility adjustBinUtility(const BinUtility& bu,
0144 const CuboidVolumeBounds& cBounds,
0145 const Transform3& transform) {
0146
0147 BinUtility uBinUtil(transform);
0148
0149 double minX = -cBounds.get(CuboidVolumeBounds::eHalfLengthX);
0150 double maxX = cBounds.get(CuboidVolumeBounds::eHalfLengthX);
0151 double minY = -cBounds.get(CuboidVolumeBounds::eHalfLengthY);
0152 double maxY = cBounds.get(CuboidVolumeBounds::eHalfLengthY);
0153 double minZ = -cBounds.get(CuboidVolumeBounds::eHalfLengthZ);
0154 double maxZ = cBounds.get(CuboidVolumeBounds::eHalfLengthZ);
0155
0156 const std::vector<BinningData>& bData = bu.binningData();
0157
0158 for (auto& bd : bData) {
0159
0160 BinningValue bval = bd.binvalue;
0161
0162
0163
0164 if (bd.type == arbitrary) {
0165 throw std::invalid_argument("Arbitrary binning can not be adjusted.");
0166 } else if (bval != binX && bval != binY && bval != binZ) {
0167 throw std::invalid_argument("Cylinder volume binning must be: x, y, z");
0168 }
0169 float min = 0;
0170 float max = 0;
0171
0172 if (bval == binX) {
0173 min = minX;
0174 max = maxX;
0175 } else if (bval == binY) {
0176 min = minY;
0177 max = maxY;
0178 } else if (bval == binZ) {
0179 min = minZ;
0180 max = maxZ;
0181 }
0182
0183 BinningData uBinData(bd.option, bval, bd.bins(), min, max);
0184 uBinUtil += BinUtility(uBinData);
0185 }
0186 return uBinUtil;
0187 }
0188
0189
0190
0191
0192
0193
0194
0195 BinUtility adjustBinUtility(const BinUtility& bu, const Volume& volume) {
0196 auto cyBounds =
0197 dynamic_cast<const CylinderVolumeBounds*>(&(volume.volumeBounds()));
0198 auto cutcylBounds =
0199 dynamic_cast<const CutoutCylinderVolumeBounds*>(&(volume.volumeBounds()));
0200 auto cuBounds =
0201 dynamic_cast<const CuboidVolumeBounds*>(&(volume.volumeBounds()));
0202
0203 if (cyBounds != nullptr) {
0204
0205 return adjustBinUtility(bu, *cyBounds, volume.transform());
0206
0207 } else if (cutcylBounds != nullptr) {
0208
0209 return adjustBinUtility(bu, *cutcylBounds, volume.transform());
0210
0211 } else if (cuBounds != nullptr) {
0212
0213 return adjustBinUtility(bu, *cuBounds, volume.transform());
0214 }
0215
0216 throw std::invalid_argument(
0217 "Bin adjustment not implemented for this volume yet!");
0218 }
0219
0220 }