EIC 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 
15 #include "Acts/Geometry/Layer.hpp"
27 
28 #include <iostream>
29 
30 namespace ActsExamples {
31 namespace Generic {
32 
36 
37 typedef std::pair<const Acts::Surface*, Acts::Vector3D> SurfacePosition;
38 
44 template <typename detector_element_t>
46  public:
49  struct Config {
51  std::string layerIdentification = "";
52 
54  std::vector<ProtoLayerSurfaces> centralProtoLayers;
55 
59  std::vector<std::shared_ptr<const Acts::ISurfaceMaterial>>
61 
63  std::vector<ProtoLayerSurfaces> negativeProtoLayers;
64 
66  std::vector<ProtoLayerSurfaces> positiveProtoLayers;
67 
70 
72  std::vector<std::shared_ptr<const Acts::ISurfaceMaterial>>
74 
76  std::shared_ptr<const Acts::LayerCreator> layerCreator = nullptr;
78  std::shared_ptr<const Acts::ILayerBuilder> centralPassiveLayerBuilder =
79  nullptr;
81  std::shared_ptr<const Acts::ILayerBuilder> posnegPassiveLayerBuilder =
82  nullptr;
83  };
84 
87  LayerBuilderT(const Config& cfg,
88  std::unique_ptr<const Acts::Logger> logger =
89  Acts::getDefaultLogger("LayerBuilderT",
91 
94  const Acts::GeometryContext& gctx) const final override;
95 
98  const Acts::GeometryContext& gctx) const final override;
99 
102  const Acts::GeometryContext& gctx) const final override;
103 
105  const std::string& identification() const final override {
106  return m_cfg.layerIdentification;
107  }
108 
109  private:
111  const Acts::GeometryContext& gctx, int side) const;
112 
115 
117  const Acts::Logger& logger() const { return *m_logger; }
118 
120  std::unique_ptr<const Acts::Logger> m_logger;
121 };
122 
123 template <typename detector_element_t>
125  const Acts::GeometryContext& gctx) const {
126  // create the vector
127  Acts::LayerVector cLayers;
128  cLayers.reserve(m_cfg.centralProtoLayers.size());
129  // the layer counter
130  size_t icl = 0;
131  for (auto& cpl : m_cfg.centralProtoLayers) {
132  // create the layer actually
133  Acts::MutableLayerPtr cLayer = m_cfg.layerCreator->cylinderLayer(
134  gctx, cpl.surfaces, cpl.bins0, cpl.bins1, cpl.protoLayer);
135 
136  // the layer is built let's see if it needs material
137  if (m_cfg.centralLayerMaterial.size()) {
138  std::shared_ptr<const Acts::ISurfaceMaterial> layerMaterialPtr =
139  m_cfg.centralLayerMaterial.at(icl);
140  // central material
141  if (m_cfg.centralLayerMaterialConcentration.at(icl) == 0.) {
142  // the layer surface is the material surface
143  cLayer->surfaceRepresentation().assignSurfaceMaterial(layerMaterialPtr);
144  ACTS_VERBOSE("- and material at central layer surface.");
145  } else {
146  // approach surface material
147  // get the approach descriptor - at this stage we know that the
148  // approachDescriptor exists
149  auto approachSurfaces =
150  cLayer->approachDescriptor()->containedSurfaces();
151  if (m_cfg.centralLayerMaterialConcentration.at(icl) > 0) {
152  auto mutableOuterSurface =
153  const_cast<Acts::Surface*>(approachSurfaces.at(1));
154  mutableOuterSurface->assignSurfaceMaterial(layerMaterialPtr);
155  ACTS_VERBOSE("- and material at outer approach surface");
156  } else {
157  auto mutableInnerSurface =
158  const_cast<Acts::Surface*>(approachSurfaces.at(0));
159  mutableInnerSurface->assignSurfaceMaterial(layerMaterialPtr);
160  ACTS_VERBOSE("- and material at inner approach surface");
161  }
162  }
163  }
164  // push it into the layer vector
165  cLayers.push_back(cLayer);
166  ++icl;
167  }
168  return cLayers;
169 }
170 
171 template <typename detector_element_t>
173  const Acts::GeometryContext& gctx) const {
174  return constructEndcapLayers(gctx, -1);
175 }
176 
177 template <typename detector_element_t>
179  const Acts::GeometryContext& gctx) const {
180  return constructEndcapLayers(gctx, 1);
181 }
182 
183 template <typename detector_element_t>
186  std::unique_ptr<const Acts::Logger> log)
187  : Acts::ILayerBuilder(), m_cfg(cfg), m_logger(std::move(log)) {}
188 
189 template <typename detector_element_t>
190 const Acts::LayerVector
192  const Acts::GeometryContext& gctx, int side) const {
193  // The from negative or positive proto layers
194  const auto& protoLayers =
195  (side < 0) ? m_cfg.negativeProtoLayers : m_cfg.positiveProtoLayers;
196 
197  // create the vector
198  Acts::LayerVector eLayers;
199  eLayers.reserve(protoLayers.size());
200 
201  // the layer counter
202  size_t ipnl = 0;
203  // loop over the proto layers and create the actual layers
204  for (auto& ple : protoLayers) {
206  Acts::MutableLayerPtr eLayer = m_cfg.layerCreator->discLayer(
207  gctx, ple.surfaces, ple.bins0, ple.bins1, ple.protoLayer);
208 
209  // the layer is built let's see if it needs material
210  if (m_cfg.posnegLayerMaterial.size()) {
211  std::shared_ptr<const Acts::ISurfaceMaterial> layerMaterialPtr =
212  m_cfg.posnegLayerMaterial[ipnl];
213  // central material
214  if (m_cfg.posnegLayerMaterialConcentration.at(ipnl) == 0.) {
215  // assign the surface material - the layer surface is the material
216  // surface
217  eLayer->surfaceRepresentation().assignSurfaceMaterial(layerMaterialPtr);
218  ACTS_VERBOSE("- and material at central layer surface.");
219  } else {
220  // approach surface material
221  // get the approach descriptor - at this stage we know that the
222  // approachDescriptor exists
223  auto approachSurfaces =
224  eLayer->approachDescriptor()->containedSurfaces();
225  if (m_cfg.posnegLayerMaterialConcentration.at(ipnl) > 0.) {
226  int sf = side < 0 ? 0 : 1;
227  auto mutableInnerSurface =
228  const_cast<Acts::Surface*>(approachSurfaces.at(sf));
229  mutableInnerSurface->assignSurfaceMaterial(layerMaterialPtr);
230  ACTS_VERBOSE("- and material at outer approach surfaces.");
231  } else {
232  int sf = side < 0 ? 1 : 0;
233  auto mutableOuterSurface =
234  const_cast<Acts::Surface*>(approachSurfaces.at(sf));
235  mutableOuterSurface->assignSurfaceMaterial(layerMaterialPtr);
236  ACTS_VERBOSE("- and material at inner approach surfaces.");
237  }
238  }
239  }
240  // push it into the layer vector
241  eLayers.push_back(eLayer);
242  ++ipnl;
243  }
244  return eLayers;
245 }
246 
247 } // end of namespace Generic
248 } // end of namespace ActsExamples