EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MaterialMappingBase.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file MaterialMappingBase.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 
29 
30 #include <memory>
31 
32 #include <boost/program_options.hpp>
33 
34 namespace po = boost::program_options;
35 
36 int materialMappingExample(int argc, char* argv[],
37  ActsExamples::IBaseDetector& detector) {
38  // Setup and parse options
47 
48  // Add specific options for this geometry
49  detector.addOptions(desc);
50  auto vm = ActsExamples::Options::parse(desc, argc, argv);
51  if (vm.empty()) {
52  return EXIT_FAILURE;
53  }
54 
55  ActsExamples::Sequencer sequencer(
57 
58  // Get the log level
59  auto logLevel = ActsExamples::Options::readLogLevel(vm);
60 
61  // The geometry, material and decoration
62  auto geometry = ActsExamples::Geometry::build(vm, detector);
63  auto tGeometry = geometry.first;
64 
68 
69  // Straight line stepper
70  using SlStepper = Acts::StraightLineStepper;
72 
73  auto matCollection = vm["mat-mapping-collection"].template as<std::string>();
74  auto mapSurface = vm["mat-mapping-surfaces"].template as<bool>();
75  auto mapVolume = vm["mat-mapping-volumes"].template as<bool>();
76  auto volumeStep = vm["mat-mapping-volume-stepsize"].template as<float>();
77  if (!mapSurface && !mapVolume) {
78  return EXIT_FAILURE;
79  }
80  // ---------------------------------------------------------------------------------
81  // Input directory & input file handling
82  std::string intputDir = vm["input-dir"].template as<std::string>();
83  auto intputFiles = vm["input-files"].template as<read_strings>();
84 
85  if (vm["input-root"].template as<bool>()) {
86  // Read the material step information from a ROOT TTree
87  ActsExamples::RootMaterialTrackReader::Config matTrackReaderRootConfig;
88  if (not matCollection.empty()) {
89  matTrackReaderRootConfig.collection = matCollection;
90  }
91  matTrackReaderRootConfig.fileList = intputFiles;
92  auto matTrackReaderRoot =
93  std::make_shared<ActsExamples::RootMaterialTrackReader>(
94  matTrackReaderRootConfig);
95  sequencer.addReader(matTrackReaderRoot);
96  }
97 
99  ActsExamples::MaterialMapping::Config mmAlgConfig(geoContext, mfContext);
100  if (mapSurface) {
101  // Get a Navigator
103  // Make stepper and propagator
104  SlStepper stepper;
105  Propagator propagator(std::move(stepper), std::move(navigator));
108  auto smm = std::make_shared<Acts::SurfaceMaterialMapper>(
109  smmConfig, std::move(propagator),
110  Acts::getDefaultLogger("SurfaceMaterialMapper", logLevel));
111  mmAlgConfig.materialSurfaceMapper = smm;
112  }
113  if (mapVolume) {
114  // Get a Navigator
116  // Make stepper and propagator
117  SlStepper stepper;
118  Propagator propagator(std::move(stepper), std::move(navigator));
121  vmmConfig.mappingStep = volumeStep;
122  auto vmm = std::make_shared<Acts::VolumeMaterialMapper>(
123  vmmConfig, std::move(propagator),
124  Acts::getDefaultLogger("VolumeMaterialMapper", logLevel));
125  mmAlgConfig.materialVolumeMapper = vmm;
126  }
127  mmAlgConfig.trackingGeometry = tGeometry;
128 
129  // Get the file name from the options
130  std::string materialFileName = vm["mat-output-file"].as<std::string>();
131 
132  if (!materialFileName.empty() and vm["output-root"].template as<bool>()) {
133  // The writer of the indexed material
134  ActsExamples::RootMaterialWriter::Config rmwConfig("MaterialWriter");
135  rmwConfig.fileName = materialFileName + ".root";
136  ActsExamples::RootMaterialWriter rmwImpl(rmwConfig);
137  // Fullfill the IMaterialWriter interface
138  using RootWriter =
140  mmAlgConfig.materialWriters.push_back(
141  std::make_shared<RootWriter>(std::move(rmwImpl)));
142 
143  if (mapSurface) {
144  // Write the propagation steps as ROOT TTree
145  ActsExamples::RootMaterialTrackWriter::Config matTrackWriterRootConfig;
146  matTrackWriterRootConfig.filePath = materialFileName + "_tracks.root";
147  matTrackWriterRootConfig.collection =
148  mmAlgConfig.mappingMaterialCollection;
149  matTrackWriterRootConfig.storeSurface = true;
150  matTrackWriterRootConfig.storeVolume = true;
151  auto matTrackWriterRoot =
152  std::make_shared<ActsExamples::RootMaterialTrackWriter>(
153  matTrackWriterRootConfig, logLevel);
154  sequencer.addWriter(matTrackWriterRoot);
155  }
156  }
157 
158  if (!materialFileName.empty() and vm["output-json"].template as<bool>()) {
160  std::string fileName = vm["mat-output-file"].template as<std::string>();
161  // the material writer
162  Acts::JsonGeometryConverter::Config jmConverterCfg("JsonGeometryConverter",
164  jmConverterCfg.processSensitives =
165  vm["mat-output-sensitives"].template as<bool>();
166  jmConverterCfg.processApproaches =
167  vm["mat-output-approaches"].template as<bool>();
168  jmConverterCfg.processRepresenting =
169  vm["mat-output-representing"].template as<bool>();
170  jmConverterCfg.processBoundaries =
171  vm["mat-output-boundaries"].template as<bool>();
172  jmConverterCfg.processVolumes =
173  vm["mat-output-volumes"].template as<bool>();
174  jmConverterCfg.writeData = vm["mat-output-data"].template as<bool>();
175  // The writer
176  ActsExamples::JsonMaterialWriter jmwImpl(jmConverterCfg,
177  materialFileName + ".json");
178  // Fullfill the IMaterialWriter interface
179  using JsonWriter =
181  mmAlgConfig.materialWriters.push_back(
182  std::make_shared<JsonWriter>(std::move(jmwImpl)));
183  }
184 
185  // Create the material mapping
186  auto mmAlg = std::make_shared<ActsExamples::MaterialMapping>(mmAlgConfig);
187 
188  // Append the Algorithm
189  sequencer.addAlgorithm(mmAlg);
190 
191  // Initiate the run
192  sequencer.run();
193  // Return success code
194  return 0;
195 }