Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-11 09:40:21

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 once
0010 
0011 #include "Acts/Definitions/Units.hpp"
0012 #include "Acts/Geometry/CylinderVolumeBuilder.hpp"
0013 #include "Acts/Geometry/CylinderVolumeHelper.hpp"
0014 #include "Acts/Geometry/GeometryContext.hpp"
0015 #include "Acts/Geometry/GeometryIdentifier.hpp"
0016 #include "Acts/Geometry/TrackingGeometry.hpp"
0017 #include "Acts/Utilities/BinningType.hpp"
0018 #include "Acts/Utilities/Logger.hpp"
0019 #include "ActsPlugins/DD4hep/DD4hepConversionHelpers.hpp"
0020 #include "ActsPlugins/DD4hep/DD4hepLayerBuilder.hpp"
0021 
0022 #include <algorithm>
0023 #include <functional>
0024 #include <memory>
0025 #include <vector>
0026 
0027 #include <DD4hep/DetElement.h>
0028 
0029 namespace Acts {
0030 class CylinderVolumeBuilder;
0031 class CylinderVolumeHelper;
0032 class IMaterialDecorator;
0033 class Logger;
0034 class TrackingGeometry;
0035 }  // namespace Acts
0036 
0037 namespace ActsPlugins {
0038 
0039 /// Sort function which sorts dd4hep::DetElement by their ID
0040 /// @param [in,out] det the dd4hep::DetElements to be sorted
0041 inline void sortDetElementsByID(std::vector<dd4hep::DetElement>& det) {
0042   sort(det.begin(), det.end(),
0043        [](const dd4hep::DetElement& a, const dd4hep::DetElement& b) {
0044          return (a.id() < b.id());
0045        });
0046 }
0047 
0048 /// @brief Global method which creates the TrackingGeometry from DD4hep input
0049 ///
0050 /// This method returns a std::unique_ptr of the TrackingGeometry from the
0051 /// World DD4hep \a DetElement.
0052 /// @pre Before using this method make sure, that the preconditions described in
0053 /// DD4hepPlugins are met.
0054 ///
0055 ///
0056 /// @param [in] worldDetElement the DD4hep DetElement of the world
0057 /// @param [in] logger A logger instance
0058 /// geometry building
0059 /// @param [in] bTypePhi is how the sensitive surfaces (modules) should be
0060 /// binned in a layer in phi direction.
0061 /// @note Possible binningtypes:
0062 ///     - arbitrary   - of the sizes if the surfaces and the distance in between
0063 ///         vary. This mode finds out the bin boundaries by scanning through
0064 /// the         surfaces.
0065 ///     - equidistant - if the sensitive surfaces are placed equidistantly
0066 /// @note equidistant binningtype is recommended because it is faster not only
0067 /// while building the geometry but also for look up during the extrapolation
0068 /// @param [in] bTypeR is how the sensitive surfaces (modules) should be binned
0069 /// in a layer in r direction
0070 /// @param [in] bTypeZ is how the sensitive surfaces (modules) should be binned
0071 /// in a layer in z direction
0072 /// @param [in] layerEnvelopeR the tolerance added to the geometrical extension
0073 /// in r of the layers contained to build the volume envelope around
0074 /// @param [in] layerEnvelopeZ the tolerance added to the geometrical extension
0075 /// in z of the layers contained to build the volume envelope around
0076 /// @param [in] defaultLayerThickness In case no surfaces (to be contained by
0077 /// the layer) are handed over, the layer thickness will be set to this value
0078 /// @note Layers containing surfaces per default are not allowed to be
0079 ///       attached to each other (navigation will fail at this point).
0080 ///       However, to allow material layers (not containing surfaces) to be
0081 ///       attached to each other, this default thickness is needed. In this
0082 ///       way, the layer will be thin (with space to the next layer), but
0083 ///       the material will have the 'real' thickness.
0084 /// @attention The default thickness should be set thin enough that no
0085 ///            touching or overlapping with the next layer can happen.
0086 /// @param [in] sortSubDetectors @c std::function which should be used in order to
0087 ///                              sort all sub detectors (=all Detelements
0088 ///                              collected by the method
0089 ///                              @c collectSubDetectors() ) from bottom to top to
0090 ///                              ensure correct wrapping of the volumes, which
0091 ///                              is needed for navigation. Therefore the
0092 ///                              different hierarchies need to be sorted
0093 ///                              ascending. The default is sorting by ID.
0094 /// @param gctx The geometry context to use
0095 /// @param matDecorator is the material decorator that loads material maps
0096 /// @param geometryIdentifierHook Hook to apply to surfaces during geometry closure.
0097 /// @param detectorElementFactory Factory function to create ActsPlugins::DD4hepDetectorElement
0098 /// or derived classes
0099 ///
0100 /// @exception std::logic_error if an error in the translation occurs
0101 /// @return std::unique_ptr to the full TrackingGeometry
0102 
0103 /// * The Tracking geometry needs to be built from bottom to top to ensure
0104 /// Navigation. Therefore the different hierarchies need to be sorted ascending.
0105 /// Per default the sub detectors are sorted by the id of their
0106 /// dd4hep::DetElement. In case another sorting needs to be applied, the users
0107 /// can provide their own function
0108 
0109 std::unique_ptr<const Acts::TrackingGeometry> convertDD4hepDetector(
0110     dd4hep::DetElement worldDetElement, const Acts::Logger& logger,
0111     Acts::BinningType bTypePhi = Acts::equidistant,
0112     Acts::BinningType bTypeR = Acts::equidistant,
0113     Acts::BinningType bTypeZ = Acts::equidistant,
0114     double layerEnvelopeR = Acts::UnitConstants::mm,
0115     double layerEnvelopeZ = Acts::UnitConstants::mm,
0116     double defaultLayerThickness = Acts::UnitConstants::fm,
0117     const std::function<void(std::vector<dd4hep::DetElement>& detectors)>&
0118         sortSubDetectors = sortDetElementsByID,
0119     const Acts::GeometryContext& gctx = Acts::GeometryContext(),
0120     std::shared_ptr<const Acts::IMaterialDecorator> matDecorator = nullptr,
0121     std::shared_ptr<const Acts::GeometryIdentifierHook> geometryIdentifierHook =
0122         std::make_shared<Acts::GeometryIdentifierHook>(),
0123     const DD4hepLayerBuilder::ElementFactory& detectorElementFactory =
0124         DD4hepLayerBuilder::defaultDetectorElementFactory);
0125 
0126 /// @brief Method internally used to create an Acts::CylinderVolumeBuilder
0127 ///
0128 /// This method creates an Acts::CylinderVolumeBuilder from a sub detector
0129 /// (= 'compound' DetElement or DetElements which are declared as 'isBarrel' or
0130 /// 'isBeampipe' by their extension.
0131 ///
0132 ///
0133 /// @param [in] subDetector the DD4hep DetElement of the subdetector
0134 /// @param [in] logger A logger instance
0135 /// @param [in] bTypePhi is how the sensitive surfaces (modules) should be
0136 /// binned in a layer in phi direction.
0137 /// @note Possible binningtypes:
0138 ///     - arbitrary   - of the sizes if the surfaces and the distance in between
0139 ///         vary. This mode finds out the bin boundaries by scanning through
0140 /// the         surfaces.
0141 ///     - equidistant - if the sensitive surfaces are placed equidistantly
0142 /// @note equidistant binningtype is recommended because it is faster not only
0143 /// while building the geometry but also for look up during the extrapolation
0144 /// @param [in] bTypeR is how the sensitive surfaces (modules) should be binned
0145 /// in a layer in r direction
0146 /// @param [in] bTypeZ is how the sensitive surfaces (modules) should be binned
0147 /// in a layer in z direction
0148 /// @param [in] layerEnvelopeR the tolerance added to the geometrical extension
0149 /// in r of the layers contained to build the volume envelope around
0150 /// @param [in] layerEnvelopeZ the tolerance added to the geometrical extension
0151 /// in z of the layers contained to build the volume envelope around
0152 /// @param [in] defaultLayerThickness In case no surfaces (to be contained by
0153 /// the layer) are handed over, the layer thickness will be set to this value
0154 /// @note Layers containing surfaces per default are not allowed to be
0155 ///       attached to each other (navigation will fail at this point).
0156 ///       However, to allow material layers (not containing surfaces) to be
0157 ///       attached to each other, this default thickness is needed. In this
0158 ///       way, the layer will be thin (with space to the next layer), but
0159 ///       the material will have the 'real' thickness.
0160 /// @param detectorElementFactory Factory function to create ActsPlugins::DD4hepDetectorElement
0161 /// or derived classes
0162 ///
0163 /// @attention The default thickness should be set thin enough that no
0164 ///            touching or overlapping with the next layer can happen.
0165 /// @return std::shared_ptr the Acts::CylinderVolumeBuilder which can be used to
0166 /// build the full tracking geometry
0167 std::shared_ptr<const Acts::CylinderVolumeBuilder> volumeBuilder_dd4hep(
0168     dd4hep::DetElement subDetector, const Acts::Logger& logger,
0169     Acts::BinningType bTypePhi = Acts::equidistant,
0170     Acts::BinningType bTypeR = Acts::equidistant,
0171     Acts::BinningType bTypeZ = Acts::equidistant,
0172     double layerEnvelopeR = Acts::UnitConstants::mm,
0173     double layerEnvelopeZ = Acts::UnitConstants::mm,
0174     double defaultLayerThickness = Acts::UnitConstants::fm,
0175     const DD4hepLayerBuilder::ElementFactory& detectorElementFactory =
0176         DD4hepLayerBuilder::defaultDetectorElementFactory);
0177 
0178 /// Helper method internally used to create a default
0179 /// Acts::CylinderVolumeBuilder
0180 /// @param logger Logging instance
0181 /// @return Shared pointer to CylinderVolumeHelper
0182 std::shared_ptr<const Acts::CylinderVolumeHelper> cylinderVolumeHelper_dd4hep(
0183     const Acts::Logger& logger);
0184 
0185 /// Method internally used by convertDD4hepDetector to collect all sub detectors
0186 /// Sub detector means each 'compound' DetElement or DetElements which are
0187 /// declared as 'isBarrel' or 'isBeampipe' by their extension.
0188 /// @param [in] detElement the dd4hep::DetElement of the volume of which the sub
0189 /// detectors should be collected
0190 /// @param [out] subdetectors the DD4hep::DetElements of the sub detectors
0191 /// contained by detElement
0192 /// @param logger a @c Logger  for output
0193 void collectSubDetectors_dd4hep(dd4hep::DetElement& detElement,
0194                                 std::vector<dd4hep::DetElement>& subdetectors,
0195                                 const Acts::Logger& logger);
0196 
0197 /// Method internally used by convertDD4hepDetector to collect all volumes of a
0198 /// compound detector
0199 /// @param [in] detElement the dd4hep::DetElement of the volume of which the
0200 /// compounds should be collected
0201 /// @param [out] compounds the DD4hep::DetElements of the compounds contained by
0202 /// detElement
0203 void collectCompounds_dd4hep(dd4hep::DetElement& detElement,
0204                              std::vector<dd4hep::DetElement>& compounds);
0205 
0206 /// Method internally used by convertDD4hepDetector
0207 /// @param [in] detElement the dd4hep::DetElement of the volume of which the
0208 /// layers should be collected
0209 /// @param [out] layers the DD4hep::DetElements of the layers contained by
0210 /// detElement
0211 /// @param logger a @c Logger for output
0212 void collectLayers_dd4hep(dd4hep::DetElement& detElement,
0213                           std::vector<dd4hep::DetElement>& layers,
0214                           const Acts::Logger& logger);
0215 
0216 }  // namespace ActsPlugins