Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:13:08

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/Algebra.hpp"
0012 #include "Acts/Geometry/GeometryContext.hpp"
0013 
0014 #include <string>
0015 
0016 #include <DD4hep/DetFactoryHelper.h>
0017 #include <DD4hep/Objects.h>
0018 #include <DDRec/DetectorData.h>
0019 #include <XML/Utilities.h>
0020 
0021 using namespace dd4hep;
0022 
0023 namespace Acts {
0024 class Surface;
0025 }  // namespace Acts
0026 
0027 namespace DD4hepTestsHelper {
0028 
0029 /// @brief helper to ensure that an extension is set,
0030 /// copied from the ODD detector code
0031 ///
0032 /// @tparam T the type of the extension
0033 /// @param elt the detector element
0034 /// @return the extracted/created extennsion
0035 template <typename T>
0036 T& ensureExtension(dd4hep::DetElement& elt) {
0037   T* ext = elt.extension<T>(false);
0038   if (ext == nullptr) {
0039     ext = new T();
0040   }
0041   elt.addExtension<T>(ext);
0042   return *ext;
0043 }
0044 
0045 /// Helper method to decode the binning from what would appear in the
0046 /// xml into variant parameters, such that it can be understood in the
0047 /// downstream processing.
0048 ///
0049 /// This parses the dediced \< surface_binning \> tag
0050 /// - allowed/understood binnings are x,y,z,phi,r
0051 /// - allowed/unserstood types are equidistant/variable (those are
0052 /// auto-detected)
0053 ///
0054 /// Example for e.g. bname = \"surface_binning\":
0055 ///
0056 /// - Equidistant binning in r and phi:
0057 ///   \<acts_surface_binning nr=\"2\" rmin=\"25\" rmax=\"100\" nphi=\"22\"
0058 ///   phimin=\"-3.1415\" phimax=\"3.1415\" \/ \>
0059 /// - Variable binning in z:
0060 ///   \<acts_surface_binning zboundaries=\"-100,-90,90,100\" \/ \>
0061 ///
0062 /// And 2D combinations of this are allowed.
0063 ///
0064 /// @param variantParams [in,out] the variant parameters that will be overwritten
0065 /// @param xmlBinning the surface binning
0066 /// @param bname the binning base name, e.g. surface_binning, material_binning
0067 /// @param bvals the boundary values, i.e. x,y,z,phi,r
0068 ///
0069 void decodeBinning(dd4hep::rec::VariantParameters& variantParams,
0070                    const xml_comp_t& xmlBinning, const std::string& bname,
0071                    const std::vector<std::string>& bvals);
0072 
0073 /// Helper method to create a Transform3D from an xml detector
0074 /// component
0075 ///
0076 /// @param x_det_comp the xml detector component
0077 ///
0078 /// @return a Transform3D (DD4hep type, aka ROOT::Math type)
0079 Transform3D createTransform(const xml_comp_t& x_det_comp);
0080 
0081 /// Helper method to convert an ACTS transform into XML
0082 ///
0083 /// @param tf the transform in ACTS format
0084 /// @param axes the identification which axes are building the local frame
0085 ///
0086 /// @return a string representing the XML entry
0087 std::string transformToXML(const Acts::Transform3& tf,
0088                            const std::array<int, 2u>& axes = {0, 1});
0089 
0090 /// @brief  Helper method to convert a Surface into XML
0091 ///
0092 /// @param gctx the geometry context of this call
0093 /// @param surface the surface from ACTS to be written
0094 /// @param ref the reference transform
0095 ///
0096 /// @return a string representing the XML entry
0097 std::string surfaceToXML(const Acts::GeometryContext& gctx,
0098                          const Acts::Surface& surface,
0099                          const Acts::Transform3& ref);
0100 
0101 }  // namespace DD4hepTestsHelper