Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:12:37

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