ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GeantinoRecordingExample.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file GeantinoRecordingExample.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2017-2018 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 
11 #include <boost/program_options.hpp>
12 
23 
24 namespace po = boost::program_options;
25 
26 int main(int argc, char* argv[]) {
27  // Declare the supported program options.
28  // Setup and parse options
33 
34  // Parse the options
35  auto vm = FW::Options::parse(desc, argc, argv);
36  if (vm.empty()) {
37  return EXIT_FAILURE;
38  }
39 
41 
42  size_t nTracks = 100;
43  int randomSeed1 = 536235167;
44  int randomSeed2 = 729237523;
45 
47 
48  // DETECTOR:
49  // --------------------------------------------------------------------------------
50  // DD4Hep detector definition
51  // read the detector config & dd4hep detector
52  auto dd4HepDetectorConfig =
53  FW::Options::readDD4hepConfig<po::variables_map>(vm);
54  auto geometrySvc =
55  std::make_shared<FW::DD4hep::DD4hepGeometryService>(dd4HepDetectorConfig);
56  std::shared_ptr<const Acts::TrackingGeometry> tGeometry =
57  geometrySvc->trackingGeometry(geoContext);
58 
59  // DD4Hep to Geant4 conversion
60  //
61  FW::DD4hepG4::DD4hepToG4Svc::Config dgConfig("DD4hepToG4",
63  dgConfig.dd4hepService = geometrySvc;
64  auto dd4hepToG4Svc = std::make_shared<FW::DD4hepG4::DD4hepToG4Svc>(dgConfig);
65 
66  // --------------------------------------------------------------------------------
67  // Geant4 JOB:
68  // --------------------------------------------------------------------------------
69  // set up the writer for
70  // ---------------------------------------------------------------------------------
71 
72  // set up the algorithm writing out the material map
74  g4rConfig.geant4Service = dd4hepToG4Svc;
75  g4rConfig.tracksPerEvent = nTracks;
76  g4rConfig.seed1 = randomSeed1;
77  g4rConfig.seed2 = randomSeed2;
78  // create the geant4 algorithm
79  auto g4rAlgorithm =
80  std::make_shared<FW::GeantinoRecording>(g4rConfig, Acts::Logging::INFO);
81 
82  // Output directory
83  std::string outputDir = vm["output-dir"].template as<std::string>();
84  std::string matCollection = g4rConfig.geantMaterialCollection;
85  // std::string trkCollection = g4rConfig.geantTrackStepCollection;
86 
87  if (vm["output-root"].template as<bool>()) {
88  // Write the propagation steps as ROOT TTree
89  FW::RootMaterialTrackWriter::Config matTrackWriterRootConfig;
90  matTrackWriterRootConfig.prePostStep = true;
91  matTrackWriterRootConfig.recalculateTotals = true;
92  matTrackWriterRootConfig.collection = matCollection;
93  matTrackWriterRootConfig.filePath =
94  FW::joinPaths(outputDir, matCollection + ".root");
95  auto matTrackWriterRoot =
96  std::make_shared<FW::RootMaterialTrackWriter>(matTrackWriterRootConfig);
97  g4sequencer.addWriter(matTrackWriterRoot);
98 
99  // // Write track step info as ROOT TTree
100  // FW::RootSimHitWriter::Config stepSimHitWriterRootConfig;
101  // stepSimHitWriterRootConfig.inputSimulatedHits = trkCollection;
102  // stepSimHitWriterRootConfig.filePath =
103  // FW::joinPaths(outputDir, trkCollection + ".root");
104  // stepSimHitWriterRootConfig.treeName = "steps";
105  // auto stepSimHitWriterRoot = std::make_shared<FW::RootSimHitWriter>(
106  // stepSimHitWriterRootConfig, Acts::Logging::INFO);
107  // g4sequencer.addWriter(stepSimHitWriterRoot);
108  }
109 
110  // Append the algorithm and run
111  g4sequencer.addAlgorithm(g4rAlgorithm);
112  g4sequencer.run();
113 }