EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ConvertDD4hepMaterial.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file ConvertDD4hepMaterial.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 
14 #include "Acts/Geometry/Layer.hpp"
19 
20 #include <boost/foreach.hpp>
21 #include <boost/tokenizer.hpp>
22 
23 #include "XML/XMLElements.h"
24 
25 std::shared_ptr<Acts::ProtoSurfaceMaterial> Acts::createProtoMaterial(
26  const ActsExtension& actsExtension, const std::string& valueTag,
27  const std::vector<std::pair<const std::string, Acts::BinningOption> >&
28  binning) {
29  // Create the bin utility
31  // Loop over the bins
32  for (auto& bin : binning) {
33  // finding the iterator position to determine the binning value
34  auto bit = std::find(Acts::binningValueNames.begin(),
35  Acts::binningValueNames.end(), bin.first);
36  size_t indx = std::distance(Acts::binningValueNames.begin(), bit);
38  Acts::BinningOption bopt = bin.second;
39  double min = 0.;
40  double max = 0.;
41  if (bopt == Acts::closed) {
42  min = -M_PI;
43  max = M_PI;
44  }
45  int bins = actsExtension.getValue(bin.first, valueTag);
46  if (bins >= 1) {
47  bu += Acts::BinUtility(bins, min, max, bopt, bval);
48  }
49  }
50  return std::make_shared<Acts::ProtoSurfaceMaterial>(bu);
51 }
52 
54  const ActsExtension& actsExtension, Layer& layer,
55  const std::vector<std::pair<const std::string, Acts::BinningOption> >&
56  binning) {
57  // Start with the representing surface
58  std::vector<std::string> materialOptions = {"layer_material_representing"};
59  std::vector<const Surface*> materialSurfaces = {
60  &(layer.surfaceRepresentation())};
61  // Now fill (optionally) with the approach surfaces
62  auto aDescriptor = layer.approachDescriptor();
63  if (aDescriptor != nullptr and aDescriptor->containedSurfaces().size() >= 2) {
64  // Add the inner and outer approach surface
65  const std::vector<const Surface*>& aSurfaces =
66  aDescriptor->containedSurfaces();
67  materialOptions.push_back("layer_material_inner");
68  materialSurfaces.push_back(aSurfaces[0]);
69  materialOptions.push_back("layer_material_outer");
70  materialSurfaces.push_back(aSurfaces[1]);
71  }
72 
73  // Now loop over it and create the ProtoMaterial
74  for (unsigned int is = 0; is < materialOptions.size(); ++is) {
75  if (actsExtension.hasValue(materialOptions[is])) {
76  // Create the material and assign it
77  auto psMaterial =
78  createProtoMaterial(actsExtension, materialOptions[is], binning);
79  // const_cast (ugly - to be changed after internal geometry stored
80  // non-const)
81  Surface* surface = const_cast<Surface*>(materialSurfaces[is]);
82  surface->assignSurfaceMaterial(psMaterial);
83  }
84  }
85 }
86 
87 void Acts::addCylinderLayerProtoMaterial(dd4hep::DetElement detElement,
88  Layer& cylinderLayer,
89  Logging::Level loggingLevel) {
90  ACTS_LOCAL_LOGGER(Acts::getDefaultLogger("DD4hepConversion", loggingLevel));
92  "Translating DD4hep material into Acts material for CylinderLayer : "
93  << detElement.name());
94  // Get the Acts extension in order to prepare the ProtoMaterial
95  auto actsExtension = detElement.extension<ActsExtension>();
96  if (actsExtension != nullptr and actsExtension->hasType("layer_material")) {
97  addLayerProtoMaterial(*actsExtension, cylinderLayer,
98  {{"binPhi", Acts::closed}, {"binZ", Acts::open}});
99  }
100 }
101 
102 void Acts::xmlToProtoSurfaceMaterial(const xml_comp_t& x_material,
103  ActsExtension& actsExtension,
104  const std::string& baseTag) {
105  // Add the layer material flag
106  actsExtension.addType(baseTag);
107  // prepare everything here
108  std::string mSurface = x_material.attr<std::string>("surface");
109  std::string mBinning = x_material.attr<std::string>("binning");
110  boost::char_separator<char> sep(",");
111  boost::tokenizer binTokens(mBinning, sep);
112  const auto n = std::distance(binTokens.begin(), binTokens.end());
113  if (n == 2) {
114  // Fill the bins
115  auto bin = binTokens.begin();
116  std::string bin0 = *(bin);
117  std::string bin1 = *(++bin);
118  size_t nBins0 = x_material.attr<int>("bins0");
119  size_t nBins1 = x_material.attr<int>("bins1");
120  // Add the material tags
121  std::string btmSurface = baseTag + std::string("_") + mSurface;
122  actsExtension.addValue(nBins0, bin0, btmSurface);
123  actsExtension.addValue(nBins1, bin1, btmSurface);
124  }
125 }
126 
127 void Acts::addDiscLayerProtoMaterial(dd4hep::DetElement detElement,
128  Layer& discLayer,
129  Logging::Level loggingLevel) {
130  ACTS_LOCAL_LOGGER(Acts::getDefaultLogger("DD4hepConversion", loggingLevel));
131  ACTS_VERBOSE("Translating DD4hep material into Acts material for DiscLayer : "
132  << detElement.name());
133 
134  // Get the Acts extension
135  auto actsExtension = detElement.extension<ActsExtension>();
136  if (actsExtension != nullptr and actsExtension->hasType("layer_material")) {
137  addLayerProtoMaterial(*actsExtension, discLayer,
138  {{"binPhi", Acts::closed}, {"binR", Acts::open}});
139  }
140 }