Back to home page

EIC code displayed by LXR

 
 

    


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

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/Definitions/Units.hpp"
0013 #include "Acts/Utilities/AxisDefinitions.hpp"
0014 
0015 #include <memory>
0016 #include <string>
0017 #include <utility>
0018 #include <vector>
0019 
0020 #include "TGeoMatrix.h"
0021 
0022 class TGeoNode;
0023 class TGeoVolume;
0024 
0025 namespace ActsPlugins {
0026 
0027 /// @brief TGeoParser is a helper struct that
0028 /// walks recursively through a TGeometry and selects by
0029 /// string comparison the TGeoNodes that match the criteria
0030 ///
0031 /// It also buils up the global transform for the conversion
0032 /// into an ACTS Surface
0033 struct TGeoParser {
0034   /// Type alias for parsing range as min/max bounds pair
0035   using ParseRange = std::pair<double, double>;
0036 
0037   struct SelectedNode {
0038     // The selected geo node
0039     const TGeoNode* node = nullptr;
0040     // The transform to global
0041     std::unique_ptr<TGeoMatrix> transform = nullptr;
0042   };
0043 
0044   /// @brief Nested state struct
0045   ///
0046   /// This is needed for the recursive parsing of the
0047   /// geometry, it collects the information during the parsing process
0048   /// and keeps track of the built up transform
0049   struct State {
0050     /// The current ROOT geometry volume being parsed
0051     TGeoVolume* volume = nullptr;
0052     /// The current ROOT geometry node being parsed
0053     TGeoNode* node = nullptr;
0054     /// Flag indicating if parsing is on the selected geometry branch
0055     bool onBranch = false;
0056     /// Collection of nodes selected during parsing
0057     std::vector<SelectedNode> selectedNodes = {};
0058   };
0059 
0060   /// @brief Nested configuration struct
0061   ///
0062   /// This contains the parsing configuration
0063   struct Options {
0064     /// Identify the volume by name
0065     std::vector<std::string> volumeNames = {};
0066     /// Identify the sensor(s)/target(s) by name
0067     std::vector<std::string> targetNames = {};
0068     /// The local axis definition of TGeo object wrt Acts::Surface
0069     std::string localAxes = "XYZ";
0070     /// Scaling from TGeo to ROOT
0071     double unit = 1 * Acts::UnitConstants::cm;
0072     /// Parse restrictions, several can apply
0073     std::vector<std::pair<Acts::AxisDirection, ParseRange> > parseRanges = {};
0074   };
0075 
0076   /// The parsing module, it takes the top Volume and recursively steps down
0077   /// @param state [out] The parsing state configuration, passed through
0078   /// @param options [in] The parsing options as required
0079   /// @param gmatrix The current built-up transform to global at this depth
0080   static void select(State& state, const Options& options,
0081                      const TGeoMatrix& gmatrix = TGeoIdentity("ID"));
0082 
0083   /// Simple utility function that recursively finds the node by the volume name
0084   /// in the tgeo branch.
0085   /// @param currentNode [in] the pointer to the current node in the branch
0086   /// @param volumeName  [in] the name of the volume to be searched for
0087   /// @return the pointer to the node corresponding to the volume
0088   static TGeoNode* findNodeRecursive(TGeoNode* currentNode,
0089                                      const char* volumeName);
0090 };
0091 }  // namespace ActsPlugins