ECCE @ 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-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 
17 #include <boost/program_options.hpp>
18 #include <memory>
19 
32 
33 namespace po = boost::program_options;
34 
35 int materialMappingExample(int argc, char* argv[],
36  FW::IBaseDetector& detector) {
37  // Setup and parse options
46 
47  // Add specific options for this geometry
48  detector.addOptions(desc);
49  auto vm = FW::Options::parse(desc, argc, argv);
50  if (vm.empty()) {
51  return EXIT_FAILURE;
52  }
53 
55 
56  // Get the log level
57  auto logLevel = FW::Options::readLogLevel(vm);
58 
59  // The geometry, material and decoration
60  auto geometry = FW::Geometry::build(vm, detector);
61  auto tGeometry = geometry.first;
62 
66 
67  // Get a Navigator
69 
70  // Straight line stepper
71  using SlStepper = Acts::StraightLineStepper;
73  // Make stepper and propagator
74  SlStepper stepper;
75  Propagator propagator(std::move(stepper), std::move(navigator));
76 
77  auto matCollection = vm["mat-mapping-collection"].template as<std::string>();
78 
79  // ---------------------------------------------------------------------------------
80  // Input directory & input file handling
81  std::string intputDir = vm["input-dir"].template as<std::string>();
82  auto intputFiles = vm["input-files"].template as<read_strings>();
83 
84  if (vm["input-root"].template as<bool>()) {
85  // Read the material step information from a ROOT TTree
86  FW::RootMaterialTrackReader::Config matTrackReaderRootConfig;
87  if (not matCollection.empty()) {
88  matTrackReaderRootConfig.collection = matCollection;
89  }
90  matTrackReaderRootConfig.fileList = intputFiles;
91  auto matTrackReaderRoot =
92  std::make_shared<FW::RootMaterialTrackReader>(matTrackReaderRootConfig);
93  sequencer.addReader(matTrackReaderRoot);
94  }
95 
98  auto smm = std::make_shared<Acts::SurfaceMaterialMapper>(
99  smmConfig, std::move(propagator),
100  Acts::getDefaultLogger("SurfaceMaterialMapper", logLevel));
101 
103  FW::MaterialMapping::Config mmAlgConfig(geoContext, mfContext);
104  mmAlgConfig.materialMapper = smm;
105  mmAlgConfig.trackingGeometry = tGeometry;
106 
107  // Get the file name from the options
108  std::string materialFileName = vm["mat-output-file"].as<std::string>();
109 
110  if (!materialFileName.empty() and vm["output-root"].template as<bool>()) {
111  // The writer of the indexed material
112  FW::RootMaterialWriter::Config rmwConfig("MaterialWriter");
113  rmwConfig.fileName = materialFileName + ".root";
114  FW::RootMaterialWriter rmwImpl(rmwConfig);
115  // Fullfill the IMaterialWriter interface
117  mmAlgConfig.materialWriters.push_back(
118  std::make_shared<RootWriter>(std::move(rmwImpl)));
119 
120  // Write the propagation steps as ROOT TTree
121  FW::RootMaterialTrackWriter::Config matTrackWriterRootConfig;
122  matTrackWriterRootConfig.filePath = materialFileName + "_tracks.root";
123  matTrackWriterRootConfig.collection = mmAlgConfig.mappingMaterialCollection;
124  matTrackWriterRootConfig.storesurface = true;
125  auto matTrackWriterRoot = std::make_shared<FW::RootMaterialTrackWriter>(
126  matTrackWriterRootConfig, logLevel);
127 
128  sequencer.addWriter(matTrackWriterRoot);
129  }
130 
131  if (!materialFileName.empty() and vm["output-json"].template as<bool>()) {
133  std::string fileName = vm["mat-output-file"].template as<std::string>();
134  // the material writer
135  Acts::JsonGeometryConverter::Config jmConverterCfg("JsonGeometryConverter",
137  jmConverterCfg.processSensitives =
138  vm["mat-output-sensitives"].template as<bool>();
139  jmConverterCfg.processApproaches =
140  vm["mat-output-approaches"].template as<bool>();
141  jmConverterCfg.processRepresenting =
142  vm["mat-output-representing"].template as<bool>();
143  jmConverterCfg.processBoundaries =
144  vm["mat-output-boundaries"].template as<bool>();
145  jmConverterCfg.processVolumes =
146  vm["mat-output-volumes"].template as<bool>();
147  jmConverterCfg.writeData = vm["mat-output-data"].template as<bool>();
148  // The writer
149  FW::Json::JsonMaterialWriter jmwImpl(jmConverterCfg,
150  materialFileName + ".json");
151  // Fullfill the IMaterialWriter interface
153  mmAlgConfig.materialWriters.push_back(
154  std::make_shared<JsonWriter>(std::move(jmwImpl)));
155  }
156 
157  // Create the material mapping
158  auto mmAlg = std::make_shared<FW::MaterialMapping>(mmAlgConfig);
159 
160  // Append the Algorithm
161  sequencer.addAlgorithm(mmAlg);
162 
163  // Initiate the run
164  sequencer.run();
165  // Return success code
166  return 0;
167 }