EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MaterialMapping.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file MaterialMapping.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2017-2020 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 
13 #include <iostream>
14 #include <stdexcept>
15 
19  : ActsExamples::BareAlgorithm("MaterialMapping", level),
20  m_cfg(cnf),
21  m_mappingState(cnf.geoContext, cnf.magFieldContext),
22  m_mappingStateVol(cnf.geoContext, cnf.magFieldContext) {
24  throw std::invalid_argument("Missing material mapper");
25  } else if (!m_cfg.trackingGeometry) {
26  throw std::invalid_argument("Missing tracking geometry");
27  }
28 
29  ACTS_INFO("This algorithm requires inter-event information, "
30  << "run in single-threaded mode!");
31 
33  // Generate and retrieve the central cache object
36  }
38  // Generate and retrieve the central cache object
41  }
42 }
43 
45  Acts::DetectorMaterialMaps detectorMaterial;
46 
47  if (m_cfg.materialSurfaceMapper && m_cfg.materialVolumeMapper) {
48  // Finalize all the maps using the cached state
49  m_cfg.materialSurfaceMapper->finalizeMaps(m_mappingState);
50  m_cfg.materialVolumeMapper->finalizeMaps(m_mappingStateVol);
51  // Loop over the state, and collect the maps for surfaces
52  for (auto& [key, value] : m_mappingState.surfaceMaterial) {
53  detectorMaterial.first.insert({key, std::move(value)});
54  }
55  // Loop over the state, and collect the maps for volumes
56  for (auto& [key, value] : m_mappingStateVol.volumeMaterial) {
57  detectorMaterial.second.insert({key, std::move(value)});
58  }
59  } else {
60  if (m_cfg.materialSurfaceMapper) {
61  // Finalize all the maps using the cached state
62  m_cfg.materialSurfaceMapper->finalizeMaps(m_mappingState);
63  // Loop over the state, and collect the maps for surfaces
64  for (auto& [key, value] : m_mappingState.surfaceMaterial) {
65  detectorMaterial.first.insert({key, std::move(value)});
66  }
67  // Loop over the state, and collect the maps for volumes
68  for (auto& [key, value] : m_mappingState.volumeMaterial) {
69  detectorMaterial.second.insert({key, std::move(value)});
70  }
71  }
72  if (m_cfg.materialVolumeMapper) {
73  // Finalize all the maps using the cached state
74  m_cfg.materialVolumeMapper->finalizeMaps(m_mappingStateVol);
75  // Loop over the state, and collect the maps for surfaces
76  for (auto& [key, value] : m_mappingStateVol.surfaceMaterial) {
77  detectorMaterial.first.insert({key, std::move(value)});
78  }
79  // Loop over the state, and collect the maps for volumes
80  for (auto& [key, value] : m_mappingStateVol.volumeMaterial) {
81  detectorMaterial.second.insert({key, std::move(value)});
82  }
83  }
84  }
85  // Loop over the available writers and write the maps
86  for (auto& imw : m_cfg.materialWriters) {
87  imw->writeMaterial(detectorMaterial);
88  }
89 }
90 
92  const ActsExamples::AlgorithmContext& context) const {
93  // Take the collection from the EventStore
94  std::vector<Acts::RecordedMaterialTrack> mtrackCollection =
95  context.eventStore.get<std::vector<Acts::RecordedMaterialTrack>>(
96  m_cfg.collection);
97 
98  if (m_cfg.materialSurfaceMapper) {
99  // To make it work with the framework needs a lock guard
100  auto mappingState =
101  const_cast<Acts::SurfaceMaterialMapper::State*>(&m_mappingState);
102 
103  for (auto& mTrack : mtrackCollection) {
104  // Map this one onto the geometry
105  m_cfg.materialSurfaceMapper->mapMaterialTrack(*mappingState, mTrack);
106  }
107  }
108  if (m_cfg.materialVolumeMapper) {
109  // To make it work with the framework needs a lock guard
110  auto mappingState =
111  const_cast<Acts::VolumeMaterialMapper::State*>(&m_mappingStateVol);
112 
113  for (auto& mTrack : mtrackCollection) {
114  // Map this one onto the geometry
115  m_cfg.materialVolumeMapper->mapMaterialTrack(*mappingState, mTrack);
116  }
117  }
118  // Write take the collection to the EventStore
119  context.eventStore.add(m_cfg.mappingMaterialCollection,
120  std::move(mtrackCollection));
122 }