Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
LayerBuilderT.hpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file LayerBuilderT.hpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2016-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 
16 #include "Acts/Geometry/Layer.hpp"
26 
27 #include <iostream>
28 
29 namespace ActsExamples {
30 namespace Generic {
31 
35 
36 using SurfacePosition = std::pair<const Acts::Surface*, Acts::Vector3>;
37 
43 template <typename detector_element_t>
45  public:
48  struct Config {
51 
53  std::vector<ProtoLayerSurfaces> centralProtoLayers;
54 
58  std::vector<std::shared_ptr<const Acts::ISurfaceMaterial>>
60 
62  std::vector<ProtoLayerSurfaces> negativeProtoLayers;
63 
65  std::vector<ProtoLayerSurfaces> positiveProtoLayers;
66 
69 
71  std::vector<std::shared_ptr<const Acts::ISurfaceMaterial>>
73 
75  std::shared_ptr<const Acts::LayerCreator> layerCreator = nullptr;
77  std::shared_ptr<const Acts::ILayerBuilder> centralPassiveLayerBuilder =
78  nullptr;
80  std::shared_ptr<const Acts::ILayerBuilder> posnegPassiveLayerBuilder =
81  nullptr;
82  };
83 
86  LayerBuilderT(const Config& cfg,
87  std::unique_ptr<const Acts::Logger> logger =
88  Acts::getDefaultLogger("LayerBuilderT",
90 
93  const Acts::GeometryContext& gctx) const override;
94 
97  const Acts::GeometryContext& gctx) const override;
98 
101  const Acts::GeometryContext& gctx) const override;
102 
104  const std::string& identification() const override {
105  return m_cfg.layerIdentification;
106  }
107 
108  private:
110  const Acts::GeometryContext& gctx, int side) const;
111 
114 
116  const Acts::Logger& logger() const { return *m_logger; }
117 
119  std::unique_ptr<const Acts::Logger> m_logger;
120 };
121 
122 template <typename detector_element_t>
124  const Acts::GeometryContext& gctx) const {
125  // create the vector
126  Acts::LayerVector cLayers;
127  cLayers.reserve(m_cfg.centralProtoLayers.size());
128  // the layer counter
129  size_t icl = 0;
130  for (auto& cpl : m_cfg.centralProtoLayers) {
131  // create the layer actually
132  Acts::MutableLayerPtr cLayer = m_cfg.layerCreator->cylinderLayer(
133  gctx, cpl.surfaces, cpl.bins0, cpl.bins1, cpl.protoLayer);
134 
135  // the layer is built let's see if it needs material
136  if (!m_cfg.centralLayerMaterial.empty()) {
137  std::shared_ptr<const Acts::ISurfaceMaterial> layerMaterialPtr =
138  m_cfg.centralLayerMaterial.at(icl);
139  // central material
140  if (m_cfg.centralLayerMaterialConcentration.at(icl) == 0.) {
141  // the layer surface is the material surface
142  cLayer->surfaceRepresentation().assignSurfaceMaterial(layerMaterialPtr);
143  ACTS_VERBOSE("- and material at central layer surface.");
144  } else {
145  // approach surface material
146  // get the approach descriptor - at this stage we know that the
147  // approachDescriptor exists
148  auto approachSurfaces =
149  cLayer->approachDescriptor()->containedSurfaces();
150  if (m_cfg.centralLayerMaterialConcentration.at(icl) > 0) {
151  auto mutableOuterSurface =
152  const_cast<Acts::Surface*>(approachSurfaces.at(1));
153  mutableOuterSurface->assignSurfaceMaterial(layerMaterialPtr);
154  ACTS_VERBOSE("- and material at outer approach surface");
155  } else {
156  auto mutableInnerSurface =
157  const_cast<Acts::Surface*>(approachSurfaces.at(0));
158  mutableInnerSurface->assignSurfaceMaterial(layerMaterialPtr);
159  ACTS_VERBOSE("- and material at inner approach surface");
160  }
161  }
162  }
163  // push it into the layer vector
164  cLayers.push_back(cLayer);
165  ++icl;
166  }
167  return cLayers;
168 }
169 
170 template <typename detector_element_t>
172  const Acts::GeometryContext& gctx) const {
173  return constructEndcapLayers(gctx, -1);
174 }
175 
176 template <typename detector_element_t>
178  const Acts::GeometryContext& gctx) const {
179  return constructEndcapLayers(gctx, 1);
180 }
181 
182 template <typename detector_element_t>
185  std::unique_ptr<const Acts::Logger> log)
186  : Acts::ILayerBuilder(), m_cfg(cfg), m_logger(std::move(log)) {}
187 
188 template <typename detector_element_t>
189 const Acts::LayerVector
191  const Acts::GeometryContext& gctx, int side) const {
192  // The from negative or positive proto layers
193  const auto& protoLayers =
194  (side < 0) ? m_cfg.negativeProtoLayers : m_cfg.positiveProtoLayers;
195 
196  // create the vector
197  Acts::LayerVector eLayers;
198  eLayers.reserve(protoLayers.size());
199 
200  // the layer counter
201  size_t ipnl = 0;
202  // loop over the proto layers and create the actual layers
203  for (auto& ple : protoLayers) {
205  Acts::MutableLayerPtr eLayer = m_cfg.layerCreator->discLayer(
206  gctx, ple.surfaces, ple.bins0, ple.bins1, ple.protoLayer);
207 
208  // the layer is built let's see if it needs material
209  if (!m_cfg.posnegLayerMaterial.empty()) {
210  std::shared_ptr<const Acts::ISurfaceMaterial> layerMaterialPtr =
211  m_cfg.posnegLayerMaterial[ipnl];
212  // central material
213  if (m_cfg.posnegLayerMaterialConcentration.at(ipnl) == 0.) {
214  // assign the surface material - the layer surface is the material
215  // surface
216  eLayer->surfaceRepresentation().assignSurfaceMaterial(layerMaterialPtr);
217  ACTS_VERBOSE("- and material at central layer surface.");
218  } else {
219  // approach surface material
220  // get the approach descriptor - at this stage we know that the
221  // approachDescriptor exists
222  auto approachSurfaces =
223  eLayer->approachDescriptor()->containedSurfaces();
224  if (m_cfg.posnegLayerMaterialConcentration.at(ipnl) > 0.) {
225  int sf = side < 0 ? 0 : 1;
226  auto mutableInnerSurface =
227  const_cast<Acts::Surface*>(approachSurfaces.at(sf));
228  mutableInnerSurface->assignSurfaceMaterial(layerMaterialPtr);
229  ACTS_VERBOSE("- and material at outer approach surfaces.");
230  } else {
231  int sf = side < 0 ? 1 : 0;
232  auto mutableOuterSurface =
233  const_cast<Acts::Surface*>(approachSurfaces.at(sf));
234  mutableOuterSurface->assignSurfaceMaterial(layerMaterialPtr);
235  ACTS_VERBOSE("- and material at inner approach surfaces.");
236  }
237  }
238  }
239  // push it into the layer vector
240  eLayers.push_back(eLayer);
241  ++ipnl;
242  }
243  return eLayers;
244 }
245 
246 } // end of namespace Generic
247 } // end of namespace ActsExamples