ECCE @ 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-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 
11 #include <list>
12 #include <vector>
13 
29 #include "TGeoManager.h"
30 
31 namespace FW {
32 namespace TGeo {
33 
35 // from a TGeo object.
43 template <typename variable_maps_t>
44 std::shared_ptr<const Acts::TrackingGeometry> buildTGeoDetector(
45  variable_maps_t& vm, const Acts::GeometryContext& context,
46  std::vector<std::shared_ptr<const Acts::TGeoDetectorElement>>&
47  detElementStore) {
48  Acts::Logging::Level surfaceLogLevel =
49  Acts::Logging::Level(vm["geo-surface-loglevel"].template as<size_t>());
50  Acts::Logging::Level layerLogLevel =
51  Acts::Logging::Level(vm["geo-layer-loglevel"].template as<size_t>());
52  Acts::Logging::Level volumeLogLevel =
53  Acts::Logging::Level(vm["geo-volume-loglevel"].template as<size_t>());
54 
55  // configure surface array creator
57  auto surfaceArrayCreator = std::make_shared<const Acts::SurfaceArrayCreator>(
58  sacConfig,
59  Acts::getDefaultLogger("SurfaceArrayCreator", surfaceLogLevel));
60  // configure the layer creator that uses the surface array creator
62  lcConfig.surfaceArrayCreator = surfaceArrayCreator;
63  auto layerCreator = std::make_shared<const Acts::LayerCreator>(
64  lcConfig, Acts::getDefaultLogger("LayerCreator", layerLogLevel));
65  // configure the layer array creator
67  auto layerArrayCreator = std::make_shared<const Acts::LayerArrayCreator>(
68  lacConfig, Acts::getDefaultLogger("LayerArrayCreator", layerLogLevel));
69  // tracking volume array creator
71  auto tVolumeArrayCreator =
72  std::make_shared<const Acts::TrackingVolumeArrayCreator>(
73  tvacConfig,
74  Acts::getDefaultLogger("TrackingVolumeArrayCreator", volumeLogLevel));
75  // configure the cylinder volume helper
77  cvhConfig.layerArrayCreator = layerArrayCreator;
78  cvhConfig.trackingVolumeArrayCreator = tVolumeArrayCreator;
79  auto cylinderVolumeHelper =
80  std::make_shared<const Acts::CylinderVolumeHelper>(
81  cvhConfig,
82  Acts::getDefaultLogger("CylinderVolumeHelper", volumeLogLevel));
83  //-------------------------------------------------------------------------------------
84 
85  // list the volume builders
86  std::list<std::shared_ptr<const Acts::ITrackingVolumeBuilder>> volumeBuilders;
87 
88  std::string rootFileName = vm["geo-tgeo-filename"].template as<std::string>();
89  // import the file from
90  TGeoManager::Import(rootFileName.c_str());
91 
92  bool firstOne = true;
93 
94  auto layerBuilderConfigs =
95  FW::Options::readTGeoLayerBuilderConfigs<variable_maps_t>(vm,
96  layerCreator);
97 
98  // remember the layer builders to collect the detector elements
99  std::vector<std::shared_ptr<const Acts::TGeoLayerBuilder>> tgLayerBuilders;
100 
101  for (auto& lbc : layerBuilderConfigs) {
102  auto layerBuilder = std::make_shared<const Acts::TGeoLayerBuilder>(
103  lbc, Acts::getDefaultLogger(lbc.configurationName + "LayerBuilder",
104  layerLogLevel));
105  // remember the layer builder
106  tgLayerBuilders.push_back(layerBuilder);
107  // build the pixel volume
109  volumeConfig.trackingVolumeHelper = cylinderVolumeHelper;
110  volumeConfig.volumeName = lbc.configurationName;
111  volumeConfig.buildToRadiusZero = firstOne;
112  volumeConfig.layerEnvelopeR = {1. * Acts::units::_mm,
113  5. * Acts::units::_mm};
114  volumeConfig.layerBuilder = layerBuilder;
115  volumeConfig.volumeSignature = 0;
116  auto volumeBuilder = std::make_shared<const Acts::CylinderVolumeBuilder>(
117  volumeConfig,
118  Acts::getDefaultLogger(lbc.configurationName + "VolumeBuilder",
119  volumeLogLevel));
120  // add to the list of builders
121  volumeBuilders.push_back(volumeBuilder);
122  // remember that you've built to the beam pipe already
123  firstOne = false;
124  }
125 
126  //-------------------------------------------------------------------------------------
127  // create the tracking geometry
129  // Add the builders
130  for (auto& vb : volumeBuilders) {
131  tgConfig.trackingVolumeBuilders.push_back(
132  [=](const auto& c, const auto& inner, const auto&) {
133  return vb->trackingVolume(c, inner);
134  });
135  }
136  // Add the helper
137  tgConfig.trackingVolumeHelper = cylinderVolumeHelper;
138  auto cylinderGeometryBuilder =
139  std::make_shared<const Acts::TrackingGeometryBuilder>(
140  tgConfig,
141  Acts::getDefaultLogger("TrackerGeometryBuilder", volumeLogLevel));
142  // get the geometry
143  auto trackingGeometry = cylinderGeometryBuilder->trackingGeometry(context);
144  // collect the detector element store
145  for (auto& lBuilder : tgLayerBuilders) {
146  auto detElements = lBuilder->detectorElements();
147  detElementStore.insert(detElementStore.begin(), detElements.begin(),
148  detElements.end());
149  }
150 
152  return trackingGeometry;
153 }
154 
155 } // namespace TGeo
156 } // namespace FW