Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DD4hepMaterialConverter.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file DD4hepMaterialConverter.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2019 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 
10 #include "Acts/Geometry/Layer.hpp"
12 #include "Acts/Plugins/DD4hep/ConvertDD4hepMaterial.hpp"
16 
17 #include <algorithm>
18 #include <cmath>
19 #include <cstddef>
20 #include <iterator>
21 #include <ostream>
22 
23 #include <boost/foreach.hpp>
24 #include <boost/tokenizer.hpp>
25 
26 std::shared_ptr<Acts::ProtoSurfaceMaterial> Acts::createProtoMaterial(
27  const dd4hep::rec::VariantParameters& params, const std::string& valueTag,
28  const std::vector<std::pair<const std::string, Acts::BinningOption> >&
29  binning,
30  const Logger& logger) {
31  using namespace std::string_literals;
32 
33  // Create the bin utility
35  // Loop over the bins
36  for (auto& bin : binning) {
37  // finding the iterator position to determine the binning value
38  auto bit = std::find(Acts::binningValueNames().begin(),
39  Acts::binningValueNames().end(), bin.first);
40  size_t indx = std::distance(Acts::binningValueNames().begin(), bit);
42  Acts::BinningOption bopt = bin.second;
43  double min = 0.;
44  double max = 0.;
45  if (bopt == Acts::closed) {
46  min = -M_PI;
47  max = M_PI;
48  }
49  int bins = params.get<int>(valueTag + "_"s + bin.first);
50  ACTS_VERBOSE(" - material binning for " << bin.first << " on " << valueTag
51  << ": " << bins);
52  if (bins >= 1) {
53  bu += Acts::BinUtility(bins, min, max, bopt, bval);
54  }
55  }
56  return std::make_shared<Acts::ProtoSurfaceMaterial>(bu);
57 }
58 
60  const dd4hep::rec::VariantParameters& params, Layer& layer,
61  const std::vector<std::pair<const std::string, Acts::BinningOption> >&
62  binning,
63  const Logger& logger) {
64  ACTS_VERBOSE("addLayerProtoMaterial");
65  // Start with the representing surface
66  std::vector<std::string> materialOptions = {"layer_material_representing"};
67  std::vector<const Surface*> materialSurfaces = {
68  &(layer.surfaceRepresentation())};
69  // Now fill (optionally) with the approach surfaces
70  auto aDescriptor = layer.approachDescriptor();
71  if (aDescriptor != nullptr and aDescriptor->containedSurfaces().size() >= 2) {
72  // Add the inner and outer approach surface
73  const std::vector<const Surface*>& aSurfaces =
74  aDescriptor->containedSurfaces();
75  materialOptions.push_back("layer_material_inner");
76  materialSurfaces.push_back(aSurfaces[0]);
77  materialOptions.push_back("layer_material_outer");
78  materialSurfaces.push_back(aSurfaces[1]);
79  }
80 
81  // Now loop over it and create the ProtoMaterial
82  for (unsigned int is = 0; is < materialOptions.size(); ++is) {
83  // if (actsExtension.hasValue(materialOptions[is])) {
84  ACTS_VERBOSE(" - checking material for: " << materialOptions[is]);
85  if (params.contains(materialOptions[is])) {
86  ACTS_VERBOSE(" - have material");
87  // Create the material and assign it
88  auto psMaterial =
89  createProtoMaterial(params, materialOptions[is], binning, logger);
90  // const_cast (ugly - to be changed after internal geometry stored
91  // non-const)
92  Surface* surface = const_cast<Surface*>(materialSurfaces[is]);
93  surface->assignSurfaceMaterial(psMaterial);
94  }
95  }
96 }
97 
98 void Acts::addCylinderLayerProtoMaterial(dd4hep::DetElement detElement,
99  Layer& cylinderLayer,
100  const Logger& logger) {
101  ACTS_VERBOSE(
102  "Translating DD4hep material into Acts material for CylinderLayer : "
103  << detElement.name());
104  if (hasParams(detElement)) {
105  ACTS_VERBOSE(" params: " << getParams(detElement));
106  } else {
107  ACTS_VERBOSE(" NO params");
108  }
109  if (getParamOr<bool>("layer_material", detElement, false)) {
110  addLayerProtoMaterial(getParams(detElement), cylinderLayer,
111  {{"binPhi", Acts::closed}, {"binZ", Acts::open}},
112  logger);
113  }
114 }
115 
116 void Acts::addDiscLayerProtoMaterial(dd4hep::DetElement detElement,
117  Layer& discLayer, const Logger& logger) {
118  ACTS_VERBOSE("Translating DD4hep material into Acts material for DiscLayer : "
119  << detElement.name());
120 
121  if (hasParams(detElement)) {
122  ACTS_VERBOSE(" params: " << getParams(detElement));
123  } else {
124  ACTS_VERBOSE(" NO params");
125  }
126  if (getParamOr<bool>("layer_material", detElement, false)) {
127  addLayerProtoMaterial(getParams(detElement), discLayer,
128  {{"binPhi", Acts::closed}, {"binR", Acts::open}},
129  logger);
130  }
131 }