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