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/Surfaces/CylinderBounds.hpp"
0017 #include "Acts/Surfaces/RadialBounds.hpp"
0018 #include "Acts/Surfaces/RectangleBounds.hpp"
0019 #include "Acts/Surfaces/Surface.hpp"
0020 #include "Acts/Surfaces/TrapezoidBounds.hpp"
0021 #include "Acts/Utilities/BinUtility.hpp"
0022
0023 #include <stdexcept>
0024
0025 namespace Acts {
0026
0027
0028
0029
0030
0031
0032
0033
0034 static inline BinUtility adjustBinUtility(const BinUtility& bu,
0035 const RadialBounds& rBounds,
0036 const Transform3& transform) {
0037
0038 BinUtility uBinUtil(transform);
0039
0040
0041 double minR = rBounds.get(RadialBounds::eMinR);
0042 double maxR = rBounds.get(RadialBounds::eMaxR);
0043 double minPhi = rBounds.get(RadialBounds::eAveragePhi) -
0044 rBounds.get(RadialBounds::eHalfPhiSector);
0045 double maxPhi = rBounds.get(RadialBounds::eAveragePhi) +
0046 rBounds.get(RadialBounds::eHalfPhiSector);
0047
0048 const std::vector<BinningData>& bData = bu.binningData();
0049
0050 for (auto& bd : bData) {
0051
0052 BinningValue bval = bd.binvalue;
0053
0054
0055
0056 if (bd.type == arbitrary) {
0057 throw std::invalid_argument("Arbitrary binning can not be adjusted.");
0058 } else if (bval != binR && bval != binPhi) {
0059 throw std::invalid_argument("Disc binning must be: phi, r");
0060 }
0061 float min = 0., max = 0.;
0062
0063 if (bval == binPhi) {
0064 min = minPhi;
0065 max = maxPhi;
0066 } else {
0067 min = minR;
0068 max = maxR;
0069 }
0070
0071 BinningData uBinData(bd.option, bval, bd.bins(), min, max);
0072 uBinUtil += BinUtility(uBinData);
0073 }
0074 return uBinUtil;
0075 }
0076
0077
0078
0079
0080
0081
0082
0083
0084 static inline BinUtility adjustBinUtility(const BinUtility& bu,
0085 const CylinderBounds& cBounds,
0086 const Transform3& transform) {
0087
0088 BinUtility uBinUtil(transform);
0089
0090
0091 double cR = cBounds.get(CylinderBounds::eR);
0092 double cHz = cBounds.get(CylinderBounds::eHalfLengthZ);
0093 double avgPhi = cBounds.get(CylinderBounds::eAveragePhi);
0094 double halfPhi = cBounds.get(CylinderBounds::eHalfPhiSector);
0095 double minPhi = avgPhi - halfPhi;
0096 double maxPhi = avgPhi + halfPhi;
0097
0098
0099 const std::vector<BinningData>& bData = bu.binningData();
0100
0101 for (auto& bd : bData) {
0102
0103 BinningValue bval = bd.binvalue;
0104
0105
0106
0107 if (bd.type == arbitrary) {
0108 throw std::invalid_argument("Arbitrary binning can not be adjusted.");
0109 } else if (bval != binRPhi && bval != binPhi && bval != binZ) {
0110 throw std::invalid_argument("Cylinder binning must be: rphi, phi, z");
0111 }
0112 float min = 0., max = 0.;
0113
0114 if (bval == binPhi) {
0115 min = minPhi;
0116 max = maxPhi;
0117 } else if (bval == binRPhi) {
0118 min = cR * minPhi;
0119 max = cR * maxPhi;
0120 } else {
0121 min = -cHz;
0122 max = cHz;
0123 }
0124
0125 BinningData uBinData(bd.option, bval, bd.bins(), min, max);
0126 uBinUtil += BinUtility(uBinData);
0127 }
0128 return uBinUtil;
0129 }
0130
0131
0132
0133
0134
0135
0136
0137
0138 static inline BinUtility adjustBinUtility(const BinUtility& bu,
0139 const RectangleBounds& pBounds,
0140 const Transform3& transform) {
0141
0142 BinUtility uBinUtil(transform);
0143
0144
0145 double minX = pBounds.get(RectangleBounds::eMinX);
0146 double minY = pBounds.get(RectangleBounds::eMinY);
0147 double maxX = pBounds.get(RectangleBounds::eMaxX);
0148 double maxY = pBounds.get(RectangleBounds::eMaxY);
0149
0150
0151 const std::vector<BinningData>& bData = bu.binningData();
0152
0153 for (auto& bd : bData) {
0154
0155 BinningValue bval = bd.binvalue;
0156
0157
0158
0159 if (bd.type == arbitrary) {
0160 throw std::invalid_argument("Arbitrary binning can not be adjusted.");
0161 } else if (bval != binX && bval != binY) {
0162 throw std::invalid_argument("Rectangle binning must be: x, y. ");
0163 }
0164 float min = 0., max = 0.;
0165
0166 if (bval == binX) {
0167 min = minX;
0168 max = maxX;
0169 } else {
0170 min = minY;
0171 max = maxY;
0172 }
0173
0174 BinningData uBinData(bd.option, bval, bd.bins(), min, max);
0175 uBinUtil += BinUtility(uBinData);
0176 }
0177
0178 return uBinUtil;
0179 }
0180
0181
0182
0183
0184
0185
0186
0187
0188 static inline BinUtility adjustBinUtility(const BinUtility& bu,
0189 const TrapezoidBounds& pBounds,
0190 const Transform3& transform) {
0191
0192 BinUtility uBinUtil(transform);
0193
0194
0195
0196 double halfX = std::max(pBounds.get(Acts::TrapezoidBounds::eHalfLengthXnegY),
0197 pBounds.get(Acts::TrapezoidBounds::eHalfLengthXposY));
0198 double halfY = pBounds.get(Acts::TrapezoidBounds::eHalfLengthY);
0199
0200
0201 const std::vector<BinningData>& bData = bu.binningData();
0202
0203 for (auto& bd : bData) {
0204
0205 BinningValue bval = bd.binvalue;
0206
0207
0208
0209 if (bd.type == arbitrary) {
0210 throw std::invalid_argument("Arbitrary binning can not be adjusted.");
0211 } else if (bval != binX && bval != binY) {
0212 throw std::invalid_argument("Rectangle binning must be: x, y. ");
0213 }
0214 float min = 0., max = 0.;
0215
0216 if (bval == binX) {
0217 min = -1 * halfX;
0218 max = halfX;
0219 } else {
0220 min = -1 * halfY;
0221 max = halfY;
0222 }
0223
0224 BinningData uBinData(bd.option, bval, bd.bins(), min, max);
0225 uBinUtil += BinUtility(uBinData);
0226 }
0227
0228 return uBinUtil;
0229 }
0230
0231
0232
0233
0234
0235
0236
0237
0238 static inline BinUtility adjustBinUtility(const BinUtility& bu,
0239 const Surface& surface,
0240 const GeometryContext& gctx) {
0241
0242 if (surface.type() == Surface::Cylinder) {
0243
0244 auto cBounds = dynamic_cast<const CylinderBounds*>(&(surface.bounds()));
0245
0246 return adjustBinUtility(bu, *cBounds, surface.transform(gctx));
0247
0248 } else if (surface.type() == Surface::Disc) {
0249
0250 auto rBounds = dynamic_cast<const RadialBounds*>(&(surface.bounds()));
0251
0252 return adjustBinUtility(bu, *rBounds, surface.transform(gctx));
0253 } else if (surface.type() == Surface::Plane) {
0254 if (surface.bounds().type() == SurfaceBounds::eRectangle) {
0255
0256 auto pBounds = dynamic_cast<const RectangleBounds*>(&(surface.bounds()));
0257
0258 return adjustBinUtility(bu, *pBounds, surface.transform(gctx));
0259 } else if (surface.bounds().type() == SurfaceBounds::eTrapezoid) {
0260
0261 auto pBounds = dynamic_cast<const TrapezoidBounds*>(&(surface.bounds()));
0262
0263 return adjustBinUtility(bu, *pBounds, surface.transform(gctx));
0264 } else {
0265 throw std::invalid_argument(
0266 "Bin adjustment not implemented for this type of plane surface yet!");
0267 }
0268 }
0269
0270 throw std::invalid_argument(
0271 "Bin adjustment not implemented for this surface yet!");
0272 }
0273
0274 }