EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
BuildTGeoDetector.hpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file BuildTGeoDetector.hpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2016-2020 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 
25 #include "Acts/Utilities/Units.hpp"
26 
30 
31 #include <list>
32 #include <vector>
33 
34 #include "TGeoManager.h"
35 
36 namespace ActsExamples {
37 
38 namespace TGeo {
39 
41 // from a TGeo object.
49 template <typename variable_maps_t>
50 std::shared_ptr<const Acts::TrackingGeometry> buildTGeoDetector(
51  variable_maps_t& vm, const Acts::GeometryContext& context,
52  std::vector<std::shared_ptr<const Acts::TGeoDetectorElement>>&
53  detElementStore,
54  std::shared_ptr<const Acts::IMaterialDecorator> mdecorator) {
55  Acts::Logging::Level surfaceLogLevel =
56  Acts::Logging::Level(vm["geo-surface-loglevel"].template as<size_t>());
57  Acts::Logging::Level layerLogLevel =
58  Acts::Logging::Level(vm["geo-layer-loglevel"].template as<size_t>());
59  Acts::Logging::Level volumeLogLevel =
60  Acts::Logging::Level(vm["geo-volume-loglevel"].template as<size_t>());
61 
62  // configure surface array creator
64  auto surfaceArrayCreator = std::make_shared<const Acts::SurfaceArrayCreator>(
65  sacConfig,
66  Acts::getDefaultLogger("SurfaceArrayCreator", surfaceLogLevel));
67  // configure the proto layer helper
69  auto protoLayerHelper = std::make_shared<const Acts::ProtoLayerHelper>(
70  plhConfig, Acts::getDefaultLogger("ProtoLayerHelper", layerLogLevel));
71  // configure the layer creator that uses the surface array creator
73  lcConfig.surfaceArrayCreator = surfaceArrayCreator;
74  auto layerCreator = std::make_shared<const Acts::LayerCreator>(
75  lcConfig, Acts::getDefaultLogger("LayerCreator", layerLogLevel));
76  // configure the layer array creator
78  auto layerArrayCreator = std::make_shared<const Acts::LayerArrayCreator>(
79  lacConfig, Acts::getDefaultLogger("LayerArrayCreator", layerLogLevel));
80  // tracking volume array creator
82  auto tVolumeArrayCreator =
83  std::make_shared<const Acts::TrackingVolumeArrayCreator>(
84  tvacConfig,
85  Acts::getDefaultLogger("TrackingVolumeArrayCreator", volumeLogLevel));
86  // configure the cylinder volume helper
88  cvhConfig.layerArrayCreator = layerArrayCreator;
89  cvhConfig.trackingVolumeArrayCreator = tVolumeArrayCreator;
90  auto cylinderVolumeHelper =
91  std::make_shared<const Acts::CylinderVolumeHelper>(
92  cvhConfig,
93  Acts::getDefaultLogger("CylinderVolumeHelper", volumeLogLevel));
94 
95  //-------------------------------------------------------------------------------------
96  // list the volume builders
97  std::list<std::shared_ptr<const Acts::ITrackingVolumeBuilder>> volumeBuilders;
98 
99  std::string rootFileName = vm["geo-tgeo-filename"].template as<std::string>();
100 
101 
102  // Create a beam pipe if configured to do so
103  auto beamPipeParameters =
104  vm["geo-tgeo-bp-parameters"].template as<read_range>();
105  if (beamPipeParameters.size() > 2) {
108  bplConfig.layerIdentification = "BeamPipe";
109  bplConfig.centralLayerRadii = std::vector<double>(1, beamPipeParameters[0]);
110  bplConfig.centralLayerHalflengthZ =
111  std::vector<double>(1, beamPipeParameters[1]);
112  bplConfig.centralLayerThickness =
113  std::vector<double>(1, beamPipeParameters[2]);
114  auto beamPipeBuilder = std::make_shared<const Acts::PassiveLayerBuilder>(
115  bplConfig,
116  Acts::getDefaultLogger("BeamPipeLayerBuilder", layerLogLevel));
117  // create the volume for the beam pipe
119  bpvConfig.trackingVolumeHelper = cylinderVolumeHelper;
120  bpvConfig.volumeName = "BeamPipe";
121  bpvConfig.layerBuilder = beamPipeBuilder;
122  bpvConfig.layerEnvelopeR = {1. * Acts::UnitConstants::mm,
124  bpvConfig.buildToRadiusZero = true;
125  auto beamPipeVolumeBuilder =
126  std::make_shared<const Acts::CylinderVolumeBuilder>(
127 
128 
129  bpvConfig,
130  Acts::getDefaultLogger("BeamPipeVolumeBuilder", volumeLogLevel));
131  // add to the list of builders
132  volumeBuilders.push_back(beamPipeVolumeBuilder);
133 
134  }
135 
136 
137 
138 
139  // import the file from
140  TGeoManager::Import(rootFileName.c_str());
141 
142  auto layerBuilderConfigs =
143  ActsExamples::Options::readTGeoLayerBuilderConfigs<variable_maps_t>(vm);
144 
145  // remember the layer builders to collect the detector elements
146  std::vector<std::shared_ptr<const Acts::TGeoLayerBuilder>> tgLayerBuilders;
147 
148  for (auto& lbc : layerBuilderConfigs) {
149  std::shared_ptr<const Acts::LayerCreator> layerCreatorLB = nullptr;
150 
151  if (lbc.autoSurfaceBinning) {
152  // Configure surface array creator (optionally) per layer builder
153  // (in order to configure them to work appropriately)
155  sacConfigLB.surfaceMatcher = lbc.surfaceBinMatcher;
156  auto surfaceArrayCreatorLB =
157  std::make_shared<const Acts::SurfaceArrayCreator>(
158  sacConfigLB, Acts::getDefaultLogger(
159  lbc.configurationName + "SurfaceArrayCreator",
160  surfaceLogLevel));
161  // configure the layer creator that uses the surface array creator
162  Acts::LayerCreator::Config lcConfigLB;
163  lcConfigLB.surfaceArrayCreator = surfaceArrayCreatorLB;
164  layerCreatorLB = std::make_shared<const Acts::LayerCreator>(
165  lcConfigLB,
166  Acts::getDefaultLogger(lbc.configurationName + "LayerCreator",
167  layerLogLevel));
168  }
169 
170  // Configure the proto layer helper
171  Acts::ProtoLayerHelper::Config plhConfigLB;
172  auto protoLayerHelperLB = std::make_shared<const Acts::ProtoLayerHelper>(
173  plhConfigLB,
174  Acts::getDefaultLogger(lbc.configurationName + "ProtoLayerHelper",
175  layerLogLevel));
176 
177  //-------------------------------------------------------------------------------------
178  lbc.layerCreator =
179  (layerCreatorLB != nullptr) ? layerCreatorLB : layerCreator;
180  lbc.protoLayerHelper =
181  (protoLayerHelperLB != nullptr) ? protoLayerHelperLB : protoLayerHelper;
182 
183  auto layerBuilder = std::make_shared<const Acts::TGeoLayerBuilder>(
184  lbc, Acts::getDefaultLogger(lbc.configurationName + "LayerBuilder",
185  layerLogLevel));
186  // remember the layer builder
187  tgLayerBuilders.push_back(layerBuilder);
188 
189  // build the pixel volume
191  volumeConfig.trackingVolumeHelper = cylinderVolumeHelper;
192  volumeConfig.volumeName = lbc.configurationName;
193  volumeConfig.buildToRadiusZero = (volumeBuilders.size() == 0);
194  volumeConfig.layerEnvelopeR = {1. * Acts::UnitConstants::mm,
196  auto ringLayoutConfiguration =
197  [&](const std::vector<Acts::TGeoLayerBuilder::LayerConfig>& lConfigs)
198  -> void {
199  for (const auto& lcfg : lConfigs) {
200  for (const auto& scfg : lcfg.splitConfigs) {
201  if (scfg.first == Acts::binR and scfg.second > 0.) {
202  volumeConfig.ringTolerance =
203  std::max(volumeConfig.ringTolerance, scfg.second);
204  volumeConfig.checkRingLayout = true;
205  }
206  }
207  }
208  };
209  ringLayoutConfiguration(lbc.layerConfigurations[0]);
210  ringLayoutConfiguration(lbc.layerConfigurations[2]);
211  volumeConfig.layerBuilder = layerBuilder;
212  volumeConfig.volumeSignature = 0;
213  auto volumeBuilder = std::make_shared<const Acts::CylinderVolumeBuilder>(
214  volumeConfig,
215  Acts::getDefaultLogger(lbc.configurationName + "VolumeBuilder",
216  volumeLogLevel));
217  // add to the list of builders
218  volumeBuilders.push_back(volumeBuilder);
219  }
220 
221  //-------------------------------------------------------------------------------------
222  // create the tracking geometry
224  // Add the builders
225  tgConfig.materialDecorator = mdecorator;
226 
227  for (auto& vb : volumeBuilders) {
228  tgConfig.trackingVolumeBuilders.push_back(
229  [=](const auto& gcontext, const auto& inner, const auto&) {
230  return vb->trackingVolume(gcontext, inner);
231  });
232  }
233  // Add the helper
234  tgConfig.trackingVolumeHelper = cylinderVolumeHelper;
235  auto cylinderGeometryBuilder =
236  std::make_shared<const Acts::TrackingGeometryBuilder>(
237  tgConfig,
238  Acts::getDefaultLogger("TrackerGeometryBuilder", volumeLogLevel));
239  // get the geometry
240  auto trackingGeometry = cylinderGeometryBuilder->trackingGeometry(context);
241  // collect the detector element store
242  for (auto& lBuilder : tgLayerBuilders) {
243  auto detElements = lBuilder->detectorElements();
244  detElementStore.insert(detElementStore.begin(), detElements.begin(),
245  detElements.end());
246  }
247 
249  return trackingGeometry;
250 }
251 
252 } // namespace TGeo
253 } // namespace ActsExamples