ECCE @ 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-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 // MaterialMapping.cpp
12 
14 
15 #include <iostream>
16 #include <stdexcept>
17 
19 
22  : FW::BareAlgorithm("MaterialMapping", level),
23  m_cfg(cnf),
24  m_mappingState(cnf.geoContext, cnf.magFieldContext) {
25  if (!m_cfg.materialMapper) {
26  throw std::invalid_argument("Missing material mapper");
27  } else if (!m_cfg.trackingGeometry) {
28  throw std::invalid_argument("Missing tracking geometry");
29  }
30 
31  ACTS_INFO("This algorithm requires inter-event information, "
32  << "run in single-threaded mode!");
33 
34  // Generate and retrieve the central cache object
35  m_mappingState = m_cfg.materialMapper->createState(
37 }
38 
40  // Finalize all the maps using the cached state
41  m_cfg.materialMapper->finalizeMaps(m_mappingState);
42 
43  Acts::DetectorMaterialMaps detectorMaterial;
44 
45  // Loop over the state, and collect the maps for surfaces
46  for (auto& [key, value] : m_mappingState.surfaceMaterial) {
47  detectorMaterial.first.insert({key, std::move(value)});
48  }
49 
50  // Loop over the available writers and write the maps
51  for (auto& imw : m_cfg.materialWriters) {
52  imw->writeMaterial(detectorMaterial);
53  }
54 }
55 
57  const FW::AlgorithmContext& context) const {
58  // Write to the collection to the EventStore
59  std::vector<Acts::RecordedMaterialTrack> mtrackCollection =
60  context.eventStore.get<std::vector<Acts::RecordedMaterialTrack>>(
61  m_cfg.collection);
62 
63  // To make it work with the framework needs a lock guard
64  auto mappingState =
65  const_cast<Acts::SurfaceMaterialMapper::State*>(&m_mappingState);
66 
67  for (auto& mTrack : mtrackCollection) {
68  // Map this one onto the geometry
69  m_cfg.materialMapper->mapMaterialTrack(*mappingState, mTrack);
70  }
71 
72  context.eventStore.add(m_cfg.mappingMaterialCollection,
73  std::move(mtrackCollection));
74 
76 }