Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-27 07:24:26

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 // Project include(s)
0010 #include "detray/definitions/units.hpp"
0011 #include "detray/geometry/mask.hpp"
0012 #include "detray/navigation/volume_graph.hpp"
0013 #include "detray/test/common/build_telescope_detector.hpp"
0014 #include "detray/test/common/build_toy_detector.hpp"
0015 #include "detray/tracks/tracks.hpp"
0016 #include "detray/tracks/trajectories.hpp"
0017 
0018 // Example linear algebra plugin: std::array
0019 #include "detray/tutorial/types.hpp"
0020 
0021 // Vecmem include(s)
0022 #include <vecmem/memory/host_memory_resource.hpp>
0023 
0024 // System include(s)
0025 #include <cstdlib>
0026 #include <iostream>
0027 
0028 /// Show how to build the test detectors.
0029 ///
0030 /// Toy detector: Pixel section of the ACTS Generic detector (TrackML).
0031 ///
0032 /// Telescope detector: Array of surfaces of a given type in a portal box.
0033 int main(int argc, char** argv) {
0034   using algebra_t = detray::tutorial::algebra_t;
0035   using scalar = detray::tutorial::scalar;
0036 
0037   std::clog << "Detector Tutorial\n=================\n\n";
0038 
0039   // Memory resource to allocate the detector data stores
0040   vecmem::host_memory_resource host_mr;
0041 
0042   //
0043   // Toy detector
0044   //
0045   detray::toy_det_config<scalar> toy_cfg{};
0046   // Number of barrel layers (0 - 4)
0047   toy_cfg.n_brl_layers(4u);
0048   // Number of endcap layers on either side (0 - 7)
0049   // Note: The detector must be configured with 4 barrel layers to be able to
0050   // add any encap layers
0051   toy_cfg.n_edc_layers(1u);
0052 
0053   // Read toy detector config from commandline, if it was given
0054   if (argc == 3) {
0055     toy_cfg.n_brl_layers(
0056         static_cast<unsigned int>(std::abs(std::atoi(argv[1]))));
0057     toy_cfg.n_edc_layers(
0058         static_cast<unsigned int>(std::abs(std::atoi(argv[2]))));
0059   }
0060 
0061   // Fill the detector
0062   const auto [toy_det, names] =
0063       detray::build_toy_detector<algebra_t>(host_mr, toy_cfg);
0064 
0065   // Print the volume graph of the toy detector
0066   std::clog << "\nToy detector:\n"
0067             << "-------------\n"
0068             << detray::volume_graph{toy_det}.to_string() << std::endl;
0069 
0070   //
0071   // Telescope detector
0072   //
0073 
0074   // The telescope detector is built according to a 'pilot trajectory'
0075   // (either a helix or a ray) along which the modules are placed in given
0076   // distances. The world portals are constructed from a bounding box around
0077   // the test surfaces (the envelope is configurable).
0078 
0079   // Volume link of the sensitive mask that is resolved during navigation:
0080   // belongs to volume zero
0081   constexpr detray::dindex vol_nav_link{0u};
0082 
0083   // Build from given module positions (places 11 surfaces)
0084   std::vector<scalar> positions = {
0085       0.f * detray::unit<scalar>::mm,   50.f * detray::unit<scalar>::mm,
0086       100.f * detray::unit<scalar>::mm, 150.f * detray::unit<scalar>::mm,
0087       200.f * detray::unit<scalar>::mm, 250.f * detray::unit<scalar>::mm,
0088       300.f * detray::unit<scalar>::mm, 350.f * detray::unit<scalar>::mm,
0089       400.f * detray::unit<scalar>::mm, 450.f * detray::unit<scalar>::mm,
0090       500.f * detray::unit<scalar>::mm};
0091 
0092   //
0093   // Case 1: Defaults: Straight telescope in z-direction,
0094   //         10 rectangle surfaces, 500mm in length, modules evenly spaced,
0095   //         silicon material (80mm)
0096   const auto [tel_det1, tel_names1] =
0097       detray::build_telescope_detector<algebra_t, detray::rectangle2D>(host_mr);
0098 
0099   std::clog << "\nTelescope detector - case 1:\n"
0100             << "----------------------------\n"
0101             << detray::volume_graph{tel_det1}.to_string() << std::endl;
0102 
0103   //
0104   // Case 2: Straight telescope in z-direction, 15 trapezoid surfaces, 2000mm
0105   //         in length, modules evenly spaced, silicon material (80mm)
0106 
0107   // Mask with a trapezoid shape
0108   using trapezoid_t = detray::mask<detray::trapezoid2D, algebra_t>;
0109 
0110   constexpr scalar hx_min_y{10.f * detray::unit<scalar>::mm};
0111   constexpr scalar hx_max_y{30.f * detray::unit<scalar>::mm};
0112   constexpr scalar hy{20.f * detray::unit<scalar>::mm};
0113   constexpr scalar divisor{10.f / (20.f * hy)};
0114   trapezoid_t trapezoid{vol_nav_link, hx_min_y, hx_max_y, hy, divisor};
0115 
0116   detray::tel_det_config trp_cfg{trapezoid};
0117   trp_cfg.n_surfaces(15).length(2000.f * detray::unit<scalar>::mm);
0118 
0119   const auto [tel_det2, tel_names2] =
0120       detray::build_telescope_detector<algebra_t>(host_mr, trp_cfg);
0121 
0122   std::clog << "\nTelescope detector - case 2:\n"
0123             << "----------------------------\n"
0124             << detray::volume_graph{tel_det2}.to_string() << std::endl;
0125 
0126   //
0127   // Case 3: Straight telescope in x-direction, 11 rectangle surfaces, 2000mm
0128   //         in length, modules places according to 'positions',
0129   //         silicon material (80mm)
0130 
0131   // Mask with a rectangular shape (20x20 mm)
0132   detray::mask<detray::rectangle2D, algebra_t> rectangle{
0133       vol_nav_link, 20.f * detray::unit<scalar>::mm,
0134       20.f * detray::unit<scalar>::mm};
0135 
0136   // Pilot trajectory in x-direction
0137   detray::detail::ray<algebra_t> x_track{
0138       {0.f, 0.f, 0.f}, 0.f, {1.f, 0.f, 0.f}, -1.f};
0139 
0140   detray::tel_det_config rct_cfg{rectangle};
0141   rct_cfg.positions(positions).pilot_track(x_track);
0142 
0143   const auto [tel_det3, tel_names3] =
0144       build_telescope_detector<algebra_t>(host_mr, rct_cfg);
0145 
0146   std::clog << "\nTelescope detector - case 3:\n"
0147             << "----------------------------\n"
0148             << detray::volume_graph{tel_det3}.to_string() << std::endl;
0149 
0150   //
0151   // Case 4: Bent telescope along helical track, 11 trapezoid surfaces,
0152   //         modules spaced according to given positions,
0153   //         silicon material (80mm)
0154 
0155   // Pilot track in x-direction
0156   detray::free_track_parameters<algebra_t> y_track{
0157       {0.f, 0.f, 0.f}, 0.f, {1.f, 0.f, 0.f}, -1.f};
0158 
0159   // Helix in a constant B-field 1T in z-direction
0160   using helix_t = detray::detail::helix<algebra_t>;
0161   detray::tutorial::vector3 B_z{0.f, 0.f, 1.f * detray::unit<scalar>::T};
0162   helix_t helix(y_track, B_z);
0163 
0164   detray::tel_det_config htrp_cfg{trapezoid, helix};
0165   htrp_cfg.positions(positions);
0166 
0167   const auto [tel_det4, tel_names4] =
0168       detray::build_telescope_detector<algebra_t>(host_mr, htrp_cfg);
0169 
0170   std::clog << "\nTelescope detector - case 4:\n"
0171             << "----------------------------\n"
0172             << detray::volume_graph{tel_det4}.to_string() << std::endl;
0173 }