ECCE @ 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 
10 // TGeoLayerBuilder.h, Acts project, TGeoDetector plugin
12 
13 #pragma once
14 #include <climits>
21 #include "Acts/Utilities/Units.hpp"
22 
23 class TGeoMatrix;
24 class TGeoVolume;
25 class TGeoNode;
26 
27 namespace Acts {
28 
29 class TGeoDetectorElement;
30 class Surface;
31 
32 using NodeTransform = std::pair<TGeoNode*, std::shared_ptr<const Transform3D>>;
33 using namespace Acts::UnitLiterals;
34 
46  public:
48  struct LayerConfig {
49  public:
51  std::string layerName = "";
53  std::string sensorName = "";
55  std::string localAxes = "xyz";
57  std::pair<double, double> parseRangeR = {
60  std::pair<double, double> parseRangeZ = {
64  std::pair<double, double> envelope = {0_mm, 0_mm};
66  std::pair<double, double> splitRangeR = {
70  std::vector<double> splitParametersR = {};
72  std::pair<double, double> splitRangeZ = {
76  std::vector<double> splitParametersZ = {};
78  size_t binsLoc0{1};
80  size_t binsLoc1{1};
81 
82  // Default constructor
84  : layerName(""),
85  sensorName(""),
86  localAxes("XZY"),
87  envelope(std::pair<double, double>(1_mm, 1_mm)) {}
88  };
89 
92  struct Config {
94  std::string configurationName = "undefined";
96  double unit = 1_cm;
98  std::shared_ptr<const ITGeoIdentifierProvider> identifierProvider = nullptr;
100  std::shared_ptr<const LayerCreator> layerCreator = nullptr;
102  std::array<std::vector<LayerConfig>, 3> layerConfigurations;
104  std::array<double, 3> layerSplitToleranceR = {-1., -1., -1.};
106  std::array<double, 3> layerSplitToleranceZ = {-1., -1., -1.};
108  bool checkRingLayout = false;
110  double ringTolerance = 0_mm;
111  };
112 
117  std::unique_ptr<const Logger> logger =
118  getDefaultLogger("LayerArrayCreator", Logging::INFO));
119 
121  ~TGeoLayerBuilder() override;
122 
127  const LayerVector negativeLayers(const GeometryContext& gctx) const final;
128 
133  const LayerVector centralLayers(const GeometryContext& gctx) const final;
134 
139  const LayerVector positiveLayers(const GeometryContext& gctx) const final;
140 
142  const std::string& identification() const final;
143 
146  void setConfiguration(const Config& config);
147 
149  Config getConfiguration() const;
150 
152  void setLogger(std::unique_ptr<const Logger> newLogger);
153 
155  const std::vector<std::shared_ptr<const TGeoDetectorElement>>&
156  detectorElements() const;
157 
158  private:
160  Config m_cfg;
161 
163  std::array<std::string, 3> m_layerTypes = {"Negative", "Central", "Positive"};
164 
166  const Logger& logger() const { return *m_logger; }
167 
169  std::unique_ptr<const Logger> m_logger;
170 
172  std::vector<std::shared_ptr<const TGeoDetectorElement>> m_elementStore;
173 
185  void resolveSensitive(
186  const GeometryContext& gctx,
187  std::vector<std::shared_ptr<const Surface>>& layerSurfaces,
188  TGeoVolume* tgVolume, TGeoNode* tgNode, const TGeoMatrix& tgTransform,
189  LayerConfig& layerConfig, int type, bool correctBranch = false,
190  const std::string& offset = "");
191 
197  void buildLayers(const GeometryContext& gctx, LayerVector& layers,
198  int type = 0);
199 
203  bool match(const char* first, const char* second) const;
204 
206  void registerSplit(std::vector<double>& parameters, double test,
207  double tolerance, std::pair<double, double>& range) const;
208 };
209 
211  std::vector<double>& parameters, double test, double tolerance,
212  std::pair<double, double>& range) const {
213  bool found = false;
214  // min/max setting
215  range.first = std::min(range.first, test);
216  range.second = std::max(range.second, test);
217  // Loop and find the split parameters
218  for (auto& splitPar : parameters) {
219  if (std::abs(test - splitPar) < tolerance) {
220  found = true;
221  }
222  }
223  if (not found) {
224  parameters.push_back(test);
225  }
226 }
227 
229  return m_cfg;
230 }
231 
232 inline const std::vector<std::shared_ptr<const TGeoDetectorElement>>&
234  return m_elementStore;
235 }
236 
237 inline const std::string& TGeoLayerBuilder::identification() const {
238  return m_cfg.configurationName;
239 }
240 
241 // The main function that checks if two given strings
242 // match. The first string may contain wildcard characters
243 inline bool TGeoLayerBuilder::match(const char* first,
244  const char* second) const {
245  // If we reach at the end of both strings, we are done
246  if (*first == '\0' && *second == '\0') {
247  return true;
248  }
249 
250  // Make sure that the characters after '*' are present
251  // in second string. This function assumes that the first
252  // string will not contain two consecutive '*'
253  if (*first == '*' && *(first + 1) != '\0' && *second == '\0') {
254  return false;
255  }
256 
257  // If the first string contains '?', or current characters
258  // of both strings match
259  if (*first == '?' || *first == *second) {
260  return match(first + 1, second + 1);
261  }
262 
263  // If there is *, then there are two possibilities
264  // a) We consider current character of second string
265  // b) We ignore current character of second string.
266  if (*first == '*') {
267  return match(first + 1, second) || match(first, second + 1);
268  }
269  return false;
270 }
271 } // namespace Acts