EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TGeoLayerBuilder.hpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file TGeoLayerBuilder.hpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2017-2018 CERN for the benefit of the Acts project
4 //
5 // This Source Code Form is subject to the terms of the Mozilla Public
6 // License, v. 2.0. If a copy of the MPL was not distributed with this
7 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 
9 #pragma once
10 
20 #include "Acts/Utilities/Units.hpp"
21 
22 #include <climits>
23 #include <tuple>
24 
25 class TGeoMatrix;
26 class TGeoVolume;
27 class TGeoNode;
28 
29 namespace Acts {
30 
31 class TGeoDetectorElement;
32 class Surface;
33 
34 using namespace Acts::UnitLiterals;
35 
47  public:
49  struct LayerConfig {
50  public:
51  using RangeConfig = std::pair<BinningValue, std::pair<double, double>>;
52 
53  using SplitConfig = std::pair<BinningValue, double>;
54 
56  std::string volumeName = "";
58  std::vector<std::string> sensorNames = {};
60  std::string localAxes = "XYZ";
62  std::vector<RangeConfig> parseRanges = {};
64  std::vector<SplitConfig> splitConfigs = {};
66  std::pair<double, double> envelope = {0_mm, 0_mm};
68  std::tuple<int, BinningType> binning0 = {-1, equidistant};
70  std::tuple<int, BinningType> binning1 = {-1, equidistant};
71 
72  // Default constructor
74  : volumeName(""),
75  sensorNames({}),
76  localAxes("XZY"),
77  envelope(std::pair<double, double>(1_mm, 1_mm)) {}
78  };
79 
82  struct Config {
84  std::string configurationName = "undefined";
86  double unit = 1_cm;
88  std::shared_ptr<const ITGeoIdentifierProvider> identifierProvider = nullptr;
90  std::shared_ptr<const LayerCreator> layerCreator = nullptr;
92  std::shared_ptr<const ProtoLayerHelper> protoLayerHelper = nullptr;
94  std::array<std::vector<LayerConfig>, 3> layerConfigurations;
96  std::array<double, 3> layerSplitToleranceR = {-1., -1., -1.};
98  std::array<double, 3> layerSplitToleranceZ = {-1., -1., -1.};
100  bool autoSurfaceBinning = false;
103  };
104 
109  std::unique_ptr<const Logger> logger =
110  getDefaultLogger("TGeoLayerBuilder", Logging::INFO));
111 
113  ~TGeoLayerBuilder() override;
114 
119  const LayerVector negativeLayers(const GeometryContext& gctx) const final;
120 
125  const LayerVector centralLayers(const GeometryContext& gctx) const final;
126 
131  const LayerVector positiveLayers(const GeometryContext& gctx) const final;
132 
134  const std::string& identification() const final;
135 
138  void setConfiguration(const Config& config);
139 
141  Config getConfiguration() const;
142 
144  void setLogger(std::unique_ptr<const Logger> newLogger);
145 
147  const std::vector<std::shared_ptr<const TGeoDetectorElement>>&
148  detectorElements() const;
149 
150  private:
152  Config m_cfg;
153 
155  std::array<std::string, 3> m_layerTypes = {"Negative", "Central", "Positive"};
156 
158  const Logger& logger() const { return *m_logger; }
159 
161  std::unique_ptr<const Logger> m_logger;
162 
164  std::vector<std::shared_ptr<const TGeoDetectorElement>> m_elementStore;
165 
171  void buildLayers(const GeometryContext& gctx, LayerVector& layers,
172  int type = 0);
173 
175  void registerSplit(std::vector<double>& parameters, double test,
176  double tolerance, std::pair<double, double>& range) const;
177 };
178 
180  std::vector<double>& parameters, double test, double tolerance,
181  std::pair<double, double>& range) const {
182  bool found = false;
183  // min/max setting
184  range.first = std::min(range.first, test);
185  range.second = std::max(range.second, test);
186  // Loop and find the split parameters
187  for (auto& splitPar : parameters) {
188  if (std::abs(test - splitPar) < tolerance) {
189  found = true;
190  }
191  }
192  if (not found) {
193  parameters.push_back(test);
194  }
195 }
196 
198  return m_cfg;
199 }
200 
201 inline const std::vector<std::shared_ptr<const TGeoDetectorElement>>&
203  return m_elementStore;
204 }
205 
206 inline const std::string& TGeoLayerBuilder::identification() const {
207  return m_cfg.configurationName;
208 }
209 
210 } // namespace Acts