File indexing completed on 2025-01-18 09:10:51
0001
0002
0003
0004
0005
0006
0007
0008
0009 #pragma once
0010
0011
0012
0013 #include "Acts/Definitions/Algebra.hpp"
0014 #include "Acts/Utilities/AxisDefinitions.hpp"
0015 #include "Acts/Utilities/Enumerate.hpp"
0016 #include "Acts/Utilities/Helpers.hpp"
0017 #include "Acts/Utilities/RangeXD.hpp"
0018
0019 #include <array>
0020 #include <bitset>
0021 #include <optional>
0022 #include <ostream>
0023 #include <string>
0024 #include <vector>
0025
0026 namespace Acts {
0027
0028 using Envelope = std::array<double, 2>;
0029
0030 constexpr Envelope zeroEnvelope = {0, 0};
0031
0032
0033 struct ExtentEnvelope {
0034
0035
0036
0037 Envelope& operator[](AxisDirection aDir) {
0038 return m_values.at(toUnderlying(aDir));
0039 }
0040
0041
0042
0043
0044 const Envelope& operator[](AxisDirection aDir) const {
0045 return m_values.at(toUnderlying(aDir));
0046 }
0047
0048
0049
0050 explicit ExtentEnvelope(const Envelope& envelope = zeroEnvelope) {
0051 for (auto& val : m_values) {
0052 val = envelope;
0053 }
0054 }
0055
0056
0057
0058 constexpr static ExtentEnvelope Zero() {
0059 return ExtentEnvelope{{
0060 zeroEnvelope,
0061 zeroEnvelope,
0062 zeroEnvelope,
0063 zeroEnvelope,
0064 zeroEnvelope,
0065 zeroEnvelope,
0066 zeroEnvelope,
0067 zeroEnvelope,
0068 zeroEnvelope,
0069 }};
0070 }
0071
0072
0073 struct Arguments {
0074 Envelope x = zeroEnvelope;
0075 Envelope y = zeroEnvelope;
0076 Envelope z = zeroEnvelope;
0077 Envelope r = zeroEnvelope;
0078 Envelope phi = zeroEnvelope;
0079 Envelope rPhi = zeroEnvelope;
0080 Envelope theta = zeroEnvelope;
0081 Envelope eta = zeroEnvelope;
0082 Envelope mag = zeroEnvelope;
0083 };
0084
0085
0086
0087 constexpr explicit ExtentEnvelope(Arguments&& args) {
0088 using enum AxisDirection;
0089 m_values[toUnderlying(AxisX)] = args.x;
0090 m_values[toUnderlying(AxisY)] = args.y;
0091 m_values[toUnderlying(AxisZ)] = args.z;
0092 m_values[toUnderlying(AxisR)] = args.r;
0093 m_values[toUnderlying(AxisPhi)] = args.phi;
0094 m_values[toUnderlying(AxisTheta)] = args.theta;
0095 m_values[toUnderlying(AxisEta)] = args.eta;
0096 m_values[toUnderlying(AxisMag)] = args.mag;
0097 }
0098
0099
0100
0101
0102
0103 friend bool operator==(const ExtentEnvelope& lhs, const ExtentEnvelope& rhs) {
0104 return lhs.m_values == rhs.m_values;
0105 }
0106
0107 private:
0108 std::array<Envelope, numAxisDirections()> m_values{};
0109 };
0110
0111
0112
0113
0114
0115
0116
0117 class Extent {
0118 public:
0119
0120 explicit Extent(const ExtentEnvelope& envelope = ExtentEnvelope::Zero());
0121
0122
0123 bool operator==(const Extent& e) const;
0124
0125
0126
0127
0128
0129
0130
0131
0132 void extend(const Vector3& vtx,
0133 const std::vector<AxisDirection>& aDirs = allAxisDirections(),
0134 bool applyEnv = true, bool fillHistograms = false);
0135
0136
0137
0138
0139
0140
0141
0142
0143
0144 template <typename vector_iterator_t>
0145 void extend(const vector_iterator_t& start, const vector_iterator_t& end,
0146 const std::vector<AxisDirection>& aDirs = allAxisDirections(),
0147 bool applyEnv = true, bool fillHistograms = false) {
0148 for (vector_iterator_t vIt = start; vIt < end; ++vIt) {
0149 extend(*vIt, aDirs, applyEnv, fillHistograms);
0150 }
0151 }
0152
0153
0154
0155
0156
0157
0158
0159
0160
0161
0162
0163
0164
0165
0166
0167 void extend(const Extent& rhs,
0168 const std::vector<AxisDirection>& aDirs = allAxisDirections(),
0169 bool applyEnv = true);
0170
0171
0172
0173
0174
0175
0176
0177
0178 void addConstrain(const Extent& rhs,
0179 const ExtentEnvelope& envelope = ExtentEnvelope::Zero());
0180
0181
0182
0183
0184
0185
0186 void set(AxisDirection aDir, double min, double max);
0187
0188
0189
0190
0191
0192 void setMin(AxisDirection aDir, double min);
0193
0194
0195
0196
0197
0198 void setMax(AxisDirection aDir, double max);
0199
0200
0201
0202
0203 void setEnvelope(const ExtentEnvelope& envelope = ExtentEnvelope::Zero());
0204
0205
0206
0207
0208
0209
0210 auto range(AxisDirection aDir) { return m_range[toUnderlying(aDir)]; }
0211
0212
0213
0214
0215
0216
0217 Range1D<double> range(AxisDirection aDir) const;
0218
0219
0220 const RangeXD<numAxisDirections(), double>& range() const;
0221
0222
0223
0224
0225
0226
0227 template <unsigned int kSUBDIM>
0228 RangeXD<kSUBDIM, double> range(
0229 const std::array<AxisDirection, kSUBDIM>& axisDirections) const {
0230 RangeXD<kSUBDIM, double> rRange;
0231 for (auto [i, v] : enumerate(axisDirections)) {
0232 rRange[i] = range(v);
0233 }
0234 return rRange;
0235 }
0236
0237
0238 ExtentEnvelope& envelope();
0239
0240
0241 const ExtentEnvelope& envelope() const;
0242
0243
0244
0245
0246 const std::array<std::vector<double>, numAxisDirections()>& valueHistograms()
0247 const;
0248
0249
0250
0251
0252 double min(AxisDirection aDir) const {
0253 return m_range[toUnderlying(aDir)].min();
0254 }
0255
0256
0257
0258
0259 double max(AxisDirection aDir) const {
0260 return m_range[toUnderlying(aDir)].max();
0261 }
0262
0263
0264
0265
0266 double medium(AxisDirection aDir) const {
0267 return 0.5 * (m_range[toUnderlying(aDir)].min() +
0268 m_range[toUnderlying(aDir)].max());
0269 }
0270
0271
0272
0273
0274 double interval(AxisDirection aDir) const {
0275 return m_range[toUnderlying(aDir)].size();
0276 }
0277
0278
0279
0280
0281
0282
0283
0284
0285 bool contains(const Extent& rhs,
0286 std::optional<AxisDirection> aDir = std::nullopt) const;
0287
0288
0289
0290
0291
0292
0293 bool contains(const Vector3& vtx) const;
0294
0295
0296
0297
0298
0299
0300
0301
0302 bool intersects(const Extent& rhs,
0303 std::optional<AxisDirection> aDir = std::nullopt) const;
0304
0305
0306
0307
0308 bool constrains(AxisDirection aDir) const;
0309
0310
0311 bool constrains() const;
0312
0313
0314
0315
0316 std::string toString(const std::string& indent = "") const;
0317
0318 private:
0319
0320 std::bitset<numAxisDirections()> m_constrains{0};
0321
0322 RangeXD<numAxisDirections(), double> m_range;
0323
0324 ExtentEnvelope m_envelope = ExtentEnvelope::Zero();
0325
0326 std::array<std::vector<double>, numAxisDirections()> m_valueHistograms;
0327 };
0328
0329 inline Range1D<double> Acts::Extent::range(AxisDirection aDir) const {
0330 return m_range[toUnderlying(aDir)];
0331 }
0332
0333 inline const RangeXD<numAxisDirections(), double>& Extent::range() const {
0334 return m_range;
0335 }
0336
0337 inline ExtentEnvelope& Extent::envelope() {
0338 return m_envelope;
0339 }
0340
0341 inline const ExtentEnvelope& Extent::envelope() const {
0342 return m_envelope;
0343 }
0344
0345 inline const std::array<std::vector<double>, numAxisDirections()>&
0346 Extent::valueHistograms() const {
0347 return m_valueHistograms;
0348 }
0349
0350
0351 std::ostream& operator<<(std::ostream& sl, const Extent& rhs);
0352
0353 }