Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-11-05 08:55:20

0001 // This file is part of the ACTS project.
0002 //
0003 // Copyright (C) 2016 CERN for the benefit of the ACTS project
0004 //
0005 // This Source Code Form is subject to the terms of the Mozilla Public
0006 // License, v. 2.0. If a copy of the MPL was not distributed with this
0007 // file, You can obtain one at https://mozilla.org/MPL/2.0/.
0008 
0009 #pragma GCC diagnostic push
0010 #if __GNUC__ == 15
0011 #pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
0012 #endif
0013 #include <boost/test/data/test_case.hpp>
0014 #pragma GCC diagnostic pop
0015 #include <boost/test/unit_test.hpp>
0016 
0017 #include "Acts/Geometry/CylinderVolumeBuilder.hpp"
0018 
0019 #include <utility>
0020 
0021 namespace bdata = boost::unit_test::data;
0022 
0023 using namespace Acts;
0024 
0025 namespace ActsTests {
0026 
0027 /// Unit test for testing the wraps() function of the CylinderVolumeBuilder
0028 BOOST_DATA_TEST_CASE(
0029     CylinderVolumeBuilder_wraps,
0030     bdata::random((bdata::engine = std::mt19937(), bdata::seed = 1,
0031                    bdata::distribution =
0032                        std::uniform_real_distribution<double>(-15., -11.))) ^
0033         bdata::random((bdata::engine = std::mt19937(), bdata::seed = 2,
0034                        bdata::distribution =
0035                            std::uniform_real_distribution<double>(11., 15.))) ^
0036         bdata::random((bdata::engine = std::mt19937(), bdata::seed = 3,
0037                        bdata::distribution =
0038                            std::uniform_real_distribution<double>(-10., 10.))) ^
0039         bdata::random((bdata::engine = std::mt19937(), bdata::seed = 4,
0040                        bdata::distribution =
0041                            std::uniform_real_distribution<double>(0., 4.))) ^
0042         bdata::random((bdata::engine = std::mt19937(), bdata::seed = 5,
0043                        bdata::distribution =
0044                            std::uniform_real_distribution<double>(11., 15.))) ^
0045         bdata::random((bdata::engine = std::mt19937(), bdata::seed = 6,
0046                        bdata::distribution =
0047                            std::uniform_real_distribution<double>(10., 15.))) ^
0048         bdata::xrange(100),
0049     left, right, central, inner, outer, length, index) {
0050   (void)index;
0051   // inner volume
0052   VolumeConfig innerConfig;
0053   innerConfig.rMin = 0.;
0054   innerConfig.rMax = 10.;
0055   innerConfig.zMin = -10.;
0056   innerConfig.zMax = 10.;
0057 
0058   // volume to the left of the inner volume
0059   VolumeConfig outerConfig1;
0060   outerConfig1.rMin = inner;
0061   outerConfig1.rMax = inner + 5.;
0062   outerConfig1.zMin = left - 5.;
0063   outerConfig1.zMax = left;
0064 
0065   // volume to the right of the inner volume
0066   VolumeConfig outerConfig2;
0067   outerConfig2.rMin = inner;
0068   outerConfig2.rMax = inner + 5.;
0069   outerConfig2.zMin = right;
0070   outerConfig2.zMax = right + 5.;
0071 
0072   // volume around the inner volume
0073   VolumeConfig outerConfig3;
0074   outerConfig3.rMin = outer;
0075   outerConfig3.rMax = outer + 5.;
0076   outerConfig3.zMin = central - 5.;
0077   outerConfig3.zMax = central + 5.;
0078 
0079   // volume inside the inner volume
0080   VolumeConfig outerConfig4;
0081   outerConfig4.rMin = inner;
0082   outerConfig4.rMax = inner + 5.;
0083   outerConfig4.zMin = central - 5.;
0084   outerConfig4.zMax = central + 5.;
0085 
0086   // volume around the inner volume config
0087   VolumeConfig outerConfig5;
0088   outerConfig5.rMin = outer;
0089   outerConfig5.rMax = outer + 5.;
0090   outerConfig5.zMin = -length;
0091   outerConfig5.zMax = length;
0092 
0093   // volume around inner volume with same z boundaries
0094   VolumeConfig outerConfig6;
0095   outerConfig6.rMin = outer;
0096   outerConfig6.rMax = outer + 5.;
0097   outerConfig6.zMin = -10.;
0098   outerConfig6.zMax = 10.;
0099 
0100   // check if first volume wraps around the inner volume (wrapping in z)
0101   BOOST_CHECK(outerConfig1.wraps(innerConfig));
0102   // check if second volume wraps around the inner volume (wrapping in z)
0103   BOOST_CHECK(outerConfig2.wraps(innerConfig));
0104   // check if third volume wraps around the inner volume (wrapping in r)
0105   BOOST_CHECK(outerConfig3.wraps(innerConfig));
0106   // check if volume at inside the inner volume can not be wrapped
0107   BOOST_CHECK(!outerConfig4.wraps(innerConfig));
0108   // check if outside volume can not be wrapped around inside volume
0109   BOOST_CHECK(!innerConfig.wraps(outerConfig3));
0110   // check if outside volume contains inside volume
0111   BOOST_CHECK(outerConfig5.wraps(innerConfig));
0112   // check if inside volume is not contained by outside volume
0113   BOOST_CHECK(!innerConfig.wraps(outerConfig5));
0114   // check if outside volume wraps around the inside volume
0115   BOOST_CHECK(outerConfig6.wraps(innerConfig));
0116 }
0117 
0118 /// Unit test for testing the contains(), containsInR() and containsInZ()
0119 /// function of the CylinderVolumeBuilder
0120 BOOST_DATA_TEST_CASE(
0121     CylinderVolumeBuilder_containes,
0122     bdata::random((bdata::engine = std::mt19937(), bdata::seed = 1,
0123                    bdata::distribution =
0124                        std::uniform_real_distribution<double>(-15., -11.))) ^
0125         bdata::random((bdata::engine = std::mt19937(), bdata::seed = 2,
0126                        bdata::distribution =
0127                            std::uniform_real_distribution<double>(11., 15.))) ^
0128         bdata::random((bdata::engine = std::mt19937(), bdata::seed = 3,
0129                        bdata::distribution =
0130                            std::uniform_real_distribution<double>(-10., 10.))) ^
0131         bdata::random((bdata::engine = std::mt19937(), bdata::seed = 4,
0132                        bdata::distribution =
0133                            std::uniform_real_distribution<double>(0., 4.))) ^
0134         bdata::random((bdata::engine = std::mt19937(), bdata::seed = 5,
0135                        bdata::distribution =
0136                            std::uniform_real_distribution<double>(10., 15.))) ^
0137         bdata::random((bdata::engine = std::mt19937(), bdata::seed = 6,
0138                        bdata::distribution =
0139                            std::uniform_real_distribution<double>(10., 15.))) ^
0140         bdata::xrange(100),
0141     left, right, central, inner, outer, length, index) {
0142   (void)index;
0143   // inner volume
0144   VolumeConfig innerConfig;
0145   innerConfig.rMin = 0.;
0146   innerConfig.rMax = 10.;
0147   innerConfig.zMin = -10.;
0148   innerConfig.zMax = 10.;
0149 
0150   // volume to the left of the inner volume
0151   VolumeConfig outerConfig1;
0152   outerConfig1.rMin = inner;
0153   outerConfig1.rMax = inner + 5.;
0154   outerConfig1.zMin = left - 5.;
0155   outerConfig1.zMax = left;
0156 
0157   // volume to the right of the inner volume
0158   VolumeConfig outerConfig2;
0159   outerConfig2.rMin = inner;
0160   outerConfig2.rMax = inner + 5.;
0161   outerConfig2.zMin = right;
0162   outerConfig2.zMax = right + 5.;
0163 
0164   // volume around the inner volume in r
0165   VolumeConfig outerConfig3;
0166   outerConfig3.rMin = outer;
0167   outerConfig3.rMax = outer + 5.;
0168   outerConfig3.zMin = central - 5.;
0169   outerConfig3.zMax = central + 5.;
0170 
0171   // volume inside the inner volume
0172   VolumeConfig outerConfig4;
0173   outerConfig4.rMin = inner;
0174   outerConfig4.rMax = inner + 5.;
0175   outerConfig4.zMin = central - 5.;
0176   outerConfig4.zMax = central + 5.;
0177 
0178   // volume around the inner volume config
0179   VolumeConfig outerConfig5;
0180   outerConfig5.rMin = outer;
0181   outerConfig5.rMax = outer + 5.;
0182   outerConfig5.zMin = -length;
0183   outerConfig5.zMax = length;
0184 
0185   // volume around inner volume with same z boundaries
0186   VolumeConfig outerConfig6;
0187   outerConfig6.rMin = outer;
0188   outerConfig6.rMax = outer + 5.;
0189   outerConfig6.zMin = -10.;
0190   outerConfig6.zMax = 10.;
0191 
0192   // volume inside the inner volume config in z
0193   VolumeConfig innerConfig1;
0194   innerConfig1.rMin = outer;
0195   innerConfig1.rMax = outer + 5.;
0196   innerConfig1.zMin = inner - 5.;
0197   innerConfig1.zMax = inner + 5.;
0198 
0199   // check if first volume wraps around the inner volume (wrapping in z)
0200   BOOST_CHECK(!outerConfig1.contains(innerConfig));
0201   // check if second volume wraps around the inner volume (wrapping in z)
0202   BOOST_CHECK(!outerConfig2.contains(innerConfig));
0203   // check if volume at inside the inner volume can not be wrapped
0204   BOOST_CHECK(!outerConfig4.contains(innerConfig));
0205   // check if outside volume can not be wrapped around inside volume
0206   BOOST_CHECK(!innerConfig.contains(outerConfig3));
0207   // check if outside volume contains inside volume
0208   BOOST_CHECK(outerConfig5.contains(innerConfig));
0209   // check if inside volume is not contained by outside volume
0210   BOOST_CHECK(!innerConfig.contains(outerConfig5));
0211   // check if inside volume is not contained by outside volume
0212   BOOST_CHECK(!outerConfig6.contains(innerConfig));
0213 
0214   // containment checks in r and z for volumes which either contain in r or z
0215   BOOST_CHECK(innerConfig.containsInZ(innerConfig1));
0216   BOOST_CHECK(!innerConfig.containsInR(innerConfig1));
0217   BOOST_CHECK(innerConfig1.containsInR(innerConfig));
0218   BOOST_CHECK(!innerConfig1.containsInZ(innerConfig));
0219 }
0220 
0221 /// Unit test for testing the coverlapsInR()
0222 /// function of the CylinderVolumeBuilder
0223 BOOST_DATA_TEST_CASE(
0224     CylinderVolumeBuilder_overlapsInR,
0225     bdata::random((
0226         bdata::engine = std::mt19937(), bdata::seed = 1,
0227         bdata::distribution = std::uniform_real_distribution<double>(0., 4.))) ^
0228         bdata::random((bdata::engine = std::mt19937(), bdata::seed = 2,
0229                        bdata::distribution =
0230                            std::uniform_real_distribution<double>(11., 15.))) ^
0231         bdata::xrange(100),
0232     inner, outer, index) {
0233   (void)index;
0234   // reference volume
0235   VolumeConfig Config0;
0236   Config0.rMin = 5.;
0237   Config0.rMax = 10.;
0238   Config0.zMin = -10.;
0239   Config0.zMax = 10.;
0240   Config0.present = true;
0241 
0242   // volume inside volume0
0243   VolumeConfig Config1;
0244   Config1.rMin = 0.;
0245   Config1.rMax = inner;
0246   Config1.zMin = -10.;
0247   Config1.zMax = 10.;
0248 
0249   // volume outside volume0
0250   VolumeConfig Config2;
0251   Config2.rMin = outer;
0252   Config2.rMax = outer + 5.;
0253   Config2.zMin = -10.;
0254   Config2.zMax = 10.;
0255 
0256   // volume overlapping with rMin
0257   VolumeConfig Config3;
0258   Config3.rMin = inner + 5;
0259   Config3.rMax = outer + 5.;
0260   Config3.zMin = -10.;
0261   Config3.zMax = 10.;
0262 
0263   // volume overlapping with rMax
0264   VolumeConfig Config4;
0265   Config4.rMin = inner;
0266   Config4.rMax = inner + 5.;
0267   Config4.zMin = -10.;
0268   Config4.zMax = 10.;
0269 
0270   // volume overlapping with rMin and rMax
0271   VolumeConfig Config5;
0272   Config5.rMin = 5.;
0273   Config5.rMax = inner + 5.;
0274   Config5.zMin = -10.;
0275   Config5.zMax = 10.;
0276 
0277   // volume does not overlap with volume completely inside
0278   BOOST_CHECK(!Config0.overlapsInR(Config1));
0279   // volume does not overlap with volume completely outside
0280   BOOST_CHECK(!Config0.overlapsInR(Config2));
0281   // volume overlaps with rMin
0282   BOOST_CHECK(Config0.overlapsInR(Config3));
0283   // volume overlaps with rMax
0284   BOOST_CHECK(Config0.overlapsInR(Config4));
0285   // volume overlaps with rMin and rMax
0286   BOOST_CHECK(Config0.overlapsInR(Config5));
0287 }
0288 
0289 /// Unit test for testing the coverlapsInZ()
0290 /// function of the CylinderVolumeBuilder
0291 BOOST_DATA_TEST_CASE(
0292     CylinderVolumeBuilder_overlapsInZ,
0293     bdata::random((bdata::engine = std::mt19937(), bdata::seed = 1,
0294                    bdata::distribution =
0295                        std::uniform_real_distribution<double>(-15., -11.))) ^
0296         bdata::random((bdata::engine = std::mt19937(), bdata::seed = 2,
0297                        bdata::distribution =
0298                            std::uniform_real_distribution<double>(11., 15.))) ^
0299         bdata::random((bdata::engine = std::mt19937(), bdata::seed = 3,
0300                        bdata::distribution =
0301                            std::uniform_real_distribution<double>(0., 4.))) ^
0302         bdata::xrange(100),
0303     left, right, inner, index) {
0304   (void)index;
0305   // inner volume
0306   VolumeConfig Config0;
0307   Config0.rMin = 0.;
0308   Config0.rMax = 10.;
0309   Config0.zMin = -10.;
0310   Config0.zMax = 10.;
0311   Config0.present = true;
0312 
0313   // volume to the left of volume0
0314   VolumeConfig Config1;
0315   Config1.rMin = 10.;
0316   Config1.rMax = 20.;
0317   Config1.zMin = left - 5.;
0318   Config1.zMax = left;
0319 
0320   // volume to the right of volume0
0321   VolumeConfig Config2;
0322   Config2.rMin = 10.;
0323   Config2.rMax = 20.;
0324   Config2.zMin = right;
0325   Config2.zMax = right + 5.;
0326 
0327   // volume around volume0 with same z boundaries
0328   VolumeConfig Config3;
0329   Config3.rMin = 10.;
0330   Config3.rMax = 20.;
0331   Config3.zMin = -10.;
0332   Config3.zMax = 10.;
0333 
0334   // volume inside volume0 config in z
0335   VolumeConfig Config4;
0336   Config4.rMin = 10.;
0337   Config4.rMax = 20.;
0338   Config4.zMin = inner - 5.;
0339   Config4.zMax = inner + 5.;
0340 
0341   // volume around volume0 config in z
0342   VolumeConfig Config5;
0343   Config5.rMin = 10.;
0344   Config5.rMax = 20.;
0345   Config5.zMin = left;
0346   Config5.zMax = right;
0347 
0348   // volume overlapping on the left
0349   VolumeConfig Config6;
0350   Config6.rMin = 10.;
0351   Config6.rMax = 20.;
0352   Config6.zMin = left;
0353   Config6.zMax = left + 10.;
0354 
0355   // volume overlapping on the right
0356   VolumeConfig Config7;
0357   Config7.rMin = 10.;
0358   Config7.rMax = 20.;
0359   Config7.zMin = right - 10.;
0360   Config7.zMax = right;
0361 
0362   // volume to the right and left do not overlap
0363   BOOST_CHECK(!Config0.overlapsInZ(Config1));
0364   BOOST_CHECK(!Config0.overlapsInZ(Config2));
0365   // volume with same boundaries overlaps
0366   BOOST_CHECK(Config0.overlapsInZ(Config3));
0367   // inside volume overlaps
0368   BOOST_CHECK(Config0.overlapsInZ(Config4));
0369   // volume around overlaps
0370   BOOST_CHECK(Config0.overlapsInZ(Config5));
0371   // volume overlaps on the sides
0372   BOOST_CHECK(Config0.overlapsInZ(Config6));
0373   BOOST_CHECK(Config0.overlapsInZ(Config7));
0374 }
0375 
0376 }  // namespace ActsTests