Analysis Software
Documentation for sPHENIX simulation 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 
22 
23 #include <algorithm>
24 #include <array>
25 #include <climits>
26 #include <functional>
27 #include <memory>
28 #include <string>
29 #include <tuple>
30 #include <utility>
31 #include <vector>
32 
33 class TGeoMatrix;
34 class TGeoVolume;
35 class TGeoNode;
36 
37 namespace Acts {
38 
39 class TGeoDetectorElement;
40 class ITGeoDetectorElementSplitter;
41 class Surface;
42 class ISurfaceMaterial;
43 class ITGeoIdentifierProvider;
44 class LayerCreator;
45 class ProtoLayerHelper;
46 
58  public:
60  struct LayerConfig {
61  public:
62  using RangeConfig = std::pair<BinningValue, std::pair<double, double>>;
63 
64  using SplitConfig = std::pair<BinningValue, double>;
65 
69  std::vector<std::string> sensorNames = {};
73  std::vector<RangeConfig> parseRanges = {};
75  std::vector<SplitConfig> splitConfigs = {};
77  std::pair<double, double> envelope = {1 * UnitConstants::mm,
78  1 * UnitConstants::mm};
80  std::vector<std::pair<int, BinningType>> binning0 = {{-1, equidistant}};
82  std::vector<std::pair<int, BinningType>> binning1 = {{-1, equidistant}};
83 
84  // Default constructor
86  : volumeName(""),
87  sensorNames({}),
88  localAxes("XZY"),
89  envelope(std::pair<double, double>(1 * UnitConstants::mm,
90  1 * UnitConstants::mm)) {}
91  };
92 
93  using ElementFactory = std::function<std::shared_ptr<TGeoDetectorElement>(
94  const Identifier&, const TGeoNode&, const TGeoMatrix& tGeoMatrix,
95  const std::string& axes, double scalor,
96  std::shared_ptr<const Acts::ISurfaceMaterial> material)>;
97 
98  static std::shared_ptr<TGeoDetectorElement> defaultElementFactory(
99  const Identifier& identifier, const TGeoNode& tGeoNode,
100  const TGeoMatrix& tGeoMatrix, const std::string& axes, double scalor,
101  std::shared_ptr<const Acts::ISurfaceMaterial> material);
102 
105  struct Config {
109  double unit = 1 * UnitConstants::cm;
111  std::shared_ptr<const ITGeoIdentifierProvider> identifierProvider = nullptr;
113  std::shared_ptr<const ITGeoDetectorElementSplitter>
118  std::shared_ptr<const LayerCreator> layerCreator = nullptr;
120  std::shared_ptr<const ProtoLayerHelper> protoLayerHelper = nullptr;
122  std::array<std::vector<LayerConfig>, 3> layerConfigurations;
124  std::array<double, 3> layerSplitToleranceR = {-1., -1., -1.};
126  std::array<double, 3> layerSplitToleranceZ = {-1., -1., -1.};
128  bool autoSurfaceBinning = false;
131  };
132 
137  std::unique_ptr<const Logger> logger =
138  getDefaultLogger("TGeoLayerBuilder", Logging::INFO));
139 
141  ~TGeoLayerBuilder() override;
142 
147  const LayerVector negativeLayers(const GeometryContext& gctx) const final;
148 
153  const LayerVector centralLayers(const GeometryContext& gctx) const final;
154 
159  const LayerVector positiveLayers(const GeometryContext& gctx) const final;
160 
162  const std::string& identification() const final;
163 
166  void setConfiguration(const Config& config);
167 
169  Config getConfiguration() const;
170 
172  void setLogger(std::unique_ptr<const Logger> newLogger);
173 
175  const std::vector<std::shared_ptr<const TGeoDetectorElement>>&
176  detectorElements() const;
177 
178  private:
181 
183  std::array<std::string, 3> m_layerTypes = {"Negative", "Central", "Positive"};
184 
186  const Logger& logger() const { return *m_logger; }
187 
189  std::unique_ptr<const Logger> m_logger;
190 
192  std::vector<std::shared_ptr<const TGeoDetectorElement>> m_elementStore;
193 
199  void buildLayers(const GeometryContext& gctx, LayerVector& layers,
200  int type = 0);
201 
203  void registerSplit(std::vector<double>& parameters, double test,
204  double tolerance, std::pair<double, double>& range) const;
205 };
206 
208  std::vector<double>& parameters, double test, double tolerance,
209  std::pair<double, double>& range) const {
210  bool found = false;
211  // min/max setting
212  range.first = std::min(range.first, test);
213  range.second = std::max(range.second, test);
214  // Loop and find the split parameters
215  for (auto& splitPar : parameters) {
216  if (std::abs(test - splitPar) < tolerance) {
217  found = true;
218  }
219  }
220  if (not found) {
221  parameters.push_back(test);
222  }
223 }
224 
226  return m_cfg;
227 }
228 
229 inline const std::vector<std::shared_ptr<const TGeoDetectorElement>>&
231  return m_elementStore;
232 }
233 
235  return m_cfg.configurationName;
236 }
237 
238 } // namespace Acts