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