Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:27:43

0001 // This file is part of the Acts project.
0002 //
0003 // Copyright (C) 2020 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 #pragma once
0010 
0011 #include "Acts/Definitions/Algebra.hpp"
0012 #include "Acts/Definitions/Units.hpp"
0013 #include "Acts/Utilities/BinningType.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 Acts {
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   using ParseRange = std::pair<double, double>;
0035 
0036   struct SelectedNode {
0037     // The selected geo node
0038     const TGeoNode* node = nullptr;
0039     // The transform to global
0040     std::unique_ptr<TGeoMatrix> transform = nullptr;
0041   };
0042 
0043   /// @brief Nested state struct
0044   ///
0045   /// This is needed for the recursive parsing of the
0046   /// geometry, it collects the information during the parsing process
0047   /// and keeps track of the built up transform
0048   struct State {
0049     // The current volume
0050     TGeoVolume* volume = nullptr;
0051     // The current node
0052     TGeoNode* node = nullptr;
0053     // Bool on branch
0054     bool onBranch = false;
0055     // The currently collected nodes
0056     std::vector<SelectedNode> selectedNodes = {};
0057   };
0058 
0059   /// @brief Nested configuration struct
0060   ///
0061   /// This contains the parsing configuration
0062   struct Options {
0063     /// Identify the volume by name
0064     std::vector<std::string> volumeNames = {};
0065     /// Identify the sensor(s)/target(s) by name
0066     std::vector<std::string> targetNames = {};
0067     /// The local axis definition of TGeo object wrt Acts::Surface
0068     std::string localAxes = "XYZ";
0069     /// Scaling from TGeo to ROOT
0070     double unit = 1 * UnitConstants::cm;
0071     /// Parse restrictions, several can apply
0072     std::vector<std::pair<BinningValue, ParseRange> > parseRanges = {};
0073   };
0074 
0075   /// The parsing module, it takes the top Volume and recursively steps down
0076   /// @param state [out] The parsing state configuration, passed through
0077   /// @param options [in] The parsing options as required
0078   /// @param gmatrix The current built-up transform to global at this depth
0079   static void select(State& state, const Options& options,
0080                      const TGeoMatrix& gmatrix = TGeoIdentity("ID"));
0081 
0082   /// Simple utility function that recursively finds the node by the volume name
0083   /// in the tgeo branch.
0084   /// @param currentNode [in] the pointer to the current node in the branch
0085   /// @param volumeName  [in] the name of the volume to be searched for
0086   /// @return the pointer to the node corresponding to the volume
0087   static TGeoNode* findNodeRecursive(TGeoNode* currentNode,
0088                                      const char* volumeName);
0089 };
0090 }  // namespace Acts