Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-03 08:09:25

0001 // This file is part of the Acts project.
0002 //
0003 // Copyright (C) 2018 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 http://mozilla.org/MPL/2.0/.
0008 
0009 ///  Boost include(s)
0010 #define BOOST_TEST_MODULE AbortList Tests
0011 
0012 #include <boost/test/included/unit_test.hpp>
0013 // leave blank line
0014 
0015 #include <boost/test/data/test_case.hpp>
0016 // leave blank line
0017 
0018 #include <boost/test/output_test_stream.hpp>
0019 // leave blank line
0020 
0021 #include "Acts/Utilities/Definitions.hpp"
0022 #include "Fatras/Kernel/PhysicsList.hpp"
0023 #include "Fatras/Kernel/Process.hpp"
0024 #include "Fatras/Kernel/SelectorList.hpp"
0025 #include "Particle.hpp"
0026 #include <algorithm>
0027 #include <random>
0028 
0029 namespace bdata = boost::unit_test::data;
0030 namespace tt = boost::test_tools;
0031 
0032 namespace Fatras {
0033 
0034 namespace Test {
0035 
0036 /// the generator
0037 typedef std::mt19937 Generator;
0038 
0039 /// The detector
0040 struct Detector {};
0041 
0042 /// The selector
0043 struct Selector {
0044 
0045   /// call operator
0046   template <typename detector_t, typename particle_t>
0047   bool operator()(const detector_t &, const particle_t &) const {
0048     return true;
0049   }
0050 };
0051 
0052 /// The scattering formula
0053 struct EnergyDecreaser {
0054 
0055   // constant 10 percent of enery loss
0056   double cvalue = 0.90;
0057 
0058   template <typename generator_t, typename detector_t, typename particle_t>
0059   std::vector<particle_t> operator()(generator_t &, const detector_t &,
0060                                      particle_t &in) const {
0061 
0062     in.energyLoss((1. - cvalue) * in.E());
0063     return {};
0064   }
0065 };
0066 
0067 /// Test the scattering implementation
0068 BOOST_DATA_TEST_CASE(
0069     Process_test_,
0070     bdata::random(
0071         (bdata::seed = 20,
0072          bdata::distribution = std::uniform_real_distribution<>(0., 1.))) ^
0073         bdata::random(
0074             (bdata::seed = 21,
0075              bdata::distribution = std::uniform_real_distribution<>(0., 1.))) ^
0076         bdata::random(
0077             (bdata::seed = 22,
0078              bdata::distribution = std::uniform_real_distribution<>(0., 1.))) ^
0079         bdata::random((
0080             bdata::seed = 23,
0081             bdata::distribution = std::uniform_real_distribution<>(1., 100.))) ^
0082         bdata::xrange(100),
0083     x, y, z, p, index) {
0084   // standard generator
0085   Generator generator;
0086 
0087   // Dummy detctor
0088   Detector detector;
0089 
0090   // create the particle and set the momentum
0091   /// position at 0.,0.,0
0092   Acts::Vector3D position{0., 0., 0.};
0093   // pT of 1 GeV
0094   Acts::Vector3D momentum =
0095       p * Acts::units::_GeV * Acts::Vector3D(x, y, z).normalized();
0096   // positively charged
0097   double q = 1.;
0098   double m = 105.658367 * Acts::units::_MeV; // muon mass
0099 
0100   // create the particle
0101   Particle particle(position, momentum, m, q, 13, 1);
0102 
0103   // outgoing particles (always none for scattering)
0104   std::vector<Particle> outgoing;
0105 
0106   // T"{he select all list
0107   typedef SelectorListAND<Selector> All;
0108   typedef Process<EnergyDecreaser, All, All, All> EnergyLoss;
0109   EnergyLoss cEnergyLoss;
0110 
0111   // energy loss is not allowed to throw abort command
0112   BOOST_CHECK(!cEnergyLoss(generator, detector, particle, outgoing));
0113 
0114   // check the the particle momentum magnitude is NOT identical
0115   BOOST_CHECK(momentum.norm() != particle.momentum().norm());
0116 
0117   // let's test this as part of a physics list
0118   PhysicsList<EnergyLoss> energyLossPhysics;
0119 
0120   // scattering is not allowed to throw abort command
0121   BOOST_CHECK(!energyLossPhysics(generator, detector, particle, outgoing));
0122 }
0123 
0124 } // namespace Test
0125 } // namespace Fatras