41 #include <dfe/dfe_io_dsv.hpp>
45 using namespace ActsExamples;
54 throw std::invalid_argument(
"Missing tracking geometry");
58 throw std::invalid_argument(
"Could not identify the world volume");
63 return "CsvTrackingGeometryWriter";
68 using SurfaceWriter = dfe::NamedTupleCsvWriter<SurfaceData>;
69 using SurfaceGridWriter = dfe::NamedTupleCsvWriter<SurfaceGridData>;
70 using LayerVolumeWriter = dfe::NamedTupleCsvWriter<LayerVolumeData>;
99 std::array<float*, 7> dataBoundParameters = {
100 &
data.bound_param0, &
data.bound_param1, &
data.bound_param2,
101 &
data.bound_param3, &
data.bound_param4, &
data.bound_param5,
105 data.bounds_type =
static_cast<int>(
bounds.type());
106 auto boundValues =
bounds.values();
108 if (boundValues.size() > dataBoundParameters.size()) {
109 throw std::invalid_argument(
110 "Bound types with too many parameters. Should never happen.");
113 for (
size_t ipar = 0; ipar < boundValues.size(); ++ipar) {
114 (*dataBoundParameters[ipar]) = boundValues[ipar];
117 if (
surface.associatedDetectorElement() !=
nullptr) {
118 data.module_t =
surface.associatedDetectorElement()->thickness() /
121 const auto* detElement =
123 surface.associatedDetectorElement());
125 if (detElement !=
nullptr and detElement->digitizationModule()) {
130 &(dModule->segmentation()));
144 fillSurfaceData(data, surface, geoCtx);
145 sfWriter.append(data);
154 void writeCylinderLayerVolume(
155 LayerVolumeWriter& lvWriter,
const Acts::Layer& lv,
157 std::vector<Acts::ActsScalar>& representingBoundValues,
158 std::vector<Acts::ActsScalar>& volumeBoundValues,
159 std::vector<Acts::ActsScalar>& lastBoundValues,
bool last) {
168 auto lTranslation = transform.translation();
171 representingBoundValues = {
172 representingBoundValues[0],
173 representingBoundValues[1],
174 lTranslation.z() - representingBoundValues[2],
175 lTranslation.z() + representingBoundValues[2],
176 representingBoundValues[4] - representingBoundValues[3],
177 representingBoundValues[4] + representingBoundValues[3]};
181 isCylinderLayer ? representingBoundValues[0] : volumeBoundValues[0];
183 isCylinderLayer ? representingBoundValues[1] : volumeBoundValues[1];
185 isCylinderLayer ? volumeBoundValues[2] : representingBoundValues[2];
187 isCylinderLayer ? volumeBoundValues[3] : representingBoundValues[3];
188 lvDims.
min_v2 = representingBoundValues[4];
189 lvDims.
max_v2 = representingBoundValues[5];
196 if (isCylinderLayer) {
197 nlvDims.
min_v0 = lastBoundValues[0];
198 nlvDims.
max_v0 = representingBoundValues[0];
199 nlvDims.
min_v1 = lastBoundValues[2];
200 nlvDims.
max_v1 = lastBoundValues[3];
202 lastBoundValues[0] = representingBoundValues[1];
204 nlvDims.
min_v0 = lastBoundValues[0];
205 nlvDims.
max_v0 = lastBoundValues[1];
206 nlvDims.
min_v1 = lastBoundValues[2];
207 nlvDims.
max_v1 = representingBoundValues[2];
209 lastBoundValues[2] = representingBoundValues[3];
211 nlvDims.
min_v2 = representingBoundValues[4];
212 nlvDims.
max_v2 = representingBoundValues[5];
213 lvWriter.append(nlvDims);
215 lvWriter.append(lvDims);
224 llvDims.
min_v0 = lastBoundValues[0];
225 llvDims.
max_v0 = lastBoundValues[1];
226 llvDims.
min_v1 = lastBoundValues[2];
227 llvDims.
max_v1 = lastBoundValues[3];
228 llvDims.
min_v2 = representingBoundValues[4];
229 llvDims.
max_v2 = representingBoundValues[5];
231 lvWriter.append(llvDims);
236 void writeBoundarySurface(SurfaceWriter&
writer,
240 fillSurfaceData(data, bsurface.surfaceRepresentation(),
geoCtx);
245 void writeVolume(SurfaceWriter& sfWriter, SurfaceGridWriter& sfGridWriter,
246 LayerVolumeWriter& lvWriter,
248 bool writeBoundary,
bool writeSurfaceGrid,
252 const auto& vTransform = volume.
transform();
255 std::vector<Acts::ActsScalar> volumeBoundValues =
257 std::vector<Acts::ActsScalar> lastBoundValues;
260 auto vTranslation = vTransform.translation();
262 volumeBoundValues = {
263 volumeBoundValues[0],
264 volumeBoundValues[1],
265 vTranslation.z() - volumeBoundValues[2],
266 vTranslation.z() + volumeBoundValues[2],
267 volumeBoundValues[4] - volumeBoundValues[3],
268 volumeBoundValues[4] + volumeBoundValues[3],
270 lastBoundValues = volumeBoundValues;
273 unsigned int layerIdx = 0;
278 if (layers.size() == 3 and writeLayerVolume) {
279 auto slayer = layers[1];
281 plvDims.
geometry_id = slayer->geometryId().value();
282 plvDims.
volume_id = slayer->geometryId().volume();
283 plvDims.
layer_id = slayer->geometryId().layer();
284 plvDims.
min_v0 = volumeBoundValues[0];
285 plvDims.
max_v0 = volumeBoundValues[1];
286 plvDims.
min_v1 = volumeBoundValues[2];
287 plvDims.
max_v1 = volumeBoundValues[3];
288 lvWriter.append(plvDims);
292 for (
const auto&
layer : layers) {
299 if (writeLayerVolume) {
300 writeSurface(sfWriter,
layer->surfaceRepresentation(),
geoCtx);
306 const auto* rVolume =
layer->representingVolume();
309 if (rVolume !=
nullptr and writeLayerVolume and layers.size() > 3) {
311 std::vector<Acts::ActsScalar> representingBoundValues =
312 rVolume->volumeBounds().values();
314 bool last = (layerIdx + 2 ==
316 writeCylinderLayerVolume(lvWriter, *
layer, rVolume->transform(),
317 representingBoundValues, volumeBoundValues,
318 lastBoundValues, last);
323 if (
layer->surfaceArray() !=
nullptr) {
324 auto sfArray =
layer->surfaceArray();
327 if (writeSurfaceGrid) {
334 auto binning = sfArray->binningValues();
335 auto axes = sfArray->getAxes();
336 if (not binning.empty() and binning.size() == 2 and
338 auto loc0Values = axes[0]->getBinEdges();
342 sfGrid.
max_loc0 = loc0Values[loc0Values.size() - 1];
344 auto loc1Values = axes[1]->getBinEdges();
348 sfGrid.
max_loc1 = loc1Values[loc1Values.size() - 1];
350 sfGridWriter.append(sfGrid);
354 if (writeSensitive) {
355 for (
auto surface : sfArray->surfaces()) {
356 if (surface !=
nullptr) {
357 writeSurface(sfWriter, *surface, geoCtx);
363 writeSurface(sfWriter,
layer->surfaceRepresentation(),
geoCtx);
372 writeBoundarySurface(sfWriter, *bsurface, geoCtx);
378 for (
const auto& confined : volume.
confinedVolumes()->arrayObjects()) {
379 writeVolume(sfWriter, sfGridWriter, lvWriter, *confined.get(),
380 writeSensitive, writeBoundary, writeSurfaceGrid,
381 writeLayerVolume,
geoCtx);
392 SurfaceWriter sfWriter(
396 SurfaceGridWriter sfGridWriter(
400 LayerVolumeWriter lvWriter(
413 SurfaceGridWriter sfGridWriter(