Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RecTruthTracks.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file RecTruthTracks.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2019-2021 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 
35 
36 #include <memory>
37 
38 using namespace Acts::UnitLiterals;
39 using namespace ActsExamples;
40 
42  int argc, char* argv[],
43  const std::shared_ptr<ActsExamples::IBaseDetector>& detector) {
45 
46  // setup and parse options
47  auto desc = Options::makeDefaultOptions();
53  Options::addOutputOptions(desc, OutputFormat::DirectoryOnly);
54  detector->addOptions(desc);
60 
61  auto vm = Options::parse(desc, argc, argv);
62  if (vm.empty()) {
63  return EXIT_FAILURE;
64  }
65 
67 
68  // Read some standard options
70  auto outputDir = ensureWritableDirectory(vm["output-dir"].as<std::string>());
71  auto rnd = std::make_shared<const ActsExamples::RandomNumbers>(
73 
74  if (vm["fit-directed-navigation"].as<bool>()) {
75  throw std::runtime_error(
76  "Directed navigation not supported anymore in the examples binaries."
77  "Please refer to the RefittingAlgorithm in the python bindings.");
78  }
79 
80  // Setup detector geometry
81  auto geometry = Geometry::build(vm, *detector);
82  auto trackingGeometry = geometry.first;
83  // Add context decorators
84  for (const auto& cdr : geometry.second) {
85  sequencer.addContextDecorator(cdr);
86  }
87  // Setup the magnetic field
89 
90  // Read the sim hits
91  auto simHitReaderCfg = setupSimHitReading(vm, sequencer);
92  // Read the particles
93  auto particleReader = setupParticleReading(vm, sequencer);
94 
95  // Run the sim hits smearing
96  auto digiCfg = setupDigitization(vm, sequencer, rnd, trackingGeometry,
97  simHitReaderCfg.outputSimHits);
98  // Run the particle selection
99  // The pre-selection will select truth particles satisfying provided criteria
100  // from all particles read in by particle reader for further processing. It
101  // has no impact on the truth hits read-in by the cluster reader.
102  TruthSeedSelector::Config particleSelectorCfg =
104  particleSelectorCfg.inputParticles = particleReader.outputParticles;
105  particleSelectorCfg.inputMeasurementParticlesMap =
106  digiCfg.outputMeasurementParticlesMap;
107  particleSelectorCfg.outputParticles = "particles_selected";
108  particleSelectorCfg.nHitsMin = 9;
109  particleSelectorCfg.ptMin = 500._MeV;
110  sequencer.addAlgorithm(
111  std::make_shared<TruthSeedSelector>(particleSelectorCfg, logLevel));
112 
113  // The selected particles
114  const auto& inputParticles = particleSelectorCfg.outputParticles;
115 
116  // Run the particle smearing
117  auto particleSmearingCfg =
118  setupParticleSmearing(vm, sequencer, rnd, inputParticles);
119 
120  // The fitter needs the measurements (proto tracks) and initial
121  // track states (proto states). The elements in both collections
122  // must match and must be created from the same input particles.
123  // Create truth tracks
124  TruthTrackFinder::Config trackFinderCfg;
125  trackFinderCfg.inputParticles = inputParticles;
126  trackFinderCfg.inputMeasurementParticlesMap =
127  digiCfg.outputMeasurementParticlesMap;
128  trackFinderCfg.outputProtoTracks = "prototracks";
129  sequencer.addAlgorithm(
130  std::make_shared<TruthTrackFinder>(trackFinderCfg, logLevel));
131 
132  // setup the fitter
133  const double reverseFilteringMomThreshold = 0.0;
135  fitter.inputMeasurements = digiCfg.outputMeasurements;
136  fitter.inputSourceLinks = digiCfg.outputSourceLinks;
137  fitter.inputProtoTracks = trackFinderCfg.outputProtoTracks;
139  particleSmearingCfg.outputTrackParameters;
140  fitter.outputTracks = "tracks";
141  fitter.pickTrack = vm["fit-pick-track"].as<int>();
142  fitter.fit = makeKalmanFitterFunction(
144  vm["fit-multiple-scattering-correction"].as<bool>(),
145  vm["fit-energy-loss-correction"].as<bool>(), reverseFilteringMomThreshold,
147  vm["fit-ftob-nonlinear-correction"].as<bool>()));
148  sequencer.addAlgorithm(
149  std::make_shared<TrackFittingAlgorithm>(fitter, logLevel));
150 
151  TracksToTrajectories::Config tracksToTrajCfg{};
152  tracksToTrajCfg.inputTracks = fitter.outputTracks;
153  tracksToTrajCfg.outputTrajectories = "trajectories";
154  sequencer.addAlgorithm(
155  (std::make_shared<TracksToTrajectories>(tracksToTrajCfg, logLevel)));
156 
157  // write track states from fitting
158  RootTrajectoryStatesWriter::Config trackStatesWriter;
159  trackStatesWriter.inputTrajectories = tracksToTrajCfg.outputTrajectories;
160  trackStatesWriter.inputParticles = inputParticles;
161  trackStatesWriter.inputSimHits = simHitReaderCfg.outputSimHits;
162  trackStatesWriter.inputMeasurementParticlesMap =
163  digiCfg.outputMeasurementParticlesMap;
164  trackStatesWriter.inputMeasurementSimHitsMap =
165  digiCfg.outputMeasurementSimHitsMap;
166  trackStatesWriter.filePath = outputDir + "/trackstates_fitter.root";
167  sequencer.addWriter(std::make_shared<RootTrajectoryStatesWriter>(
168  trackStatesWriter, logLevel));
169 
170  // write track summary from CKF
171  RootTrajectorySummaryWriter::Config trackSummaryWriter;
172  trackSummaryWriter.inputTrajectories = tracksToTrajCfg.outputTrajectories;
173  trackSummaryWriter.inputParticles = inputParticles;
174  trackSummaryWriter.inputMeasurementParticlesMap =
175  digiCfg.outputMeasurementParticlesMap;
176  trackSummaryWriter.filePath = outputDir + "/tracksummary_fitter.root";
177  sequencer.addWriter(std::make_shared<RootTrajectorySummaryWriter>(
178  trackSummaryWriter, logLevel));
179 
180  // Write CKF performance data
181  // write reconstruction performance data
183  perfFinder.inputProtoTracks = trackFinderCfg.outputProtoTracks;
184  perfFinder.inputParticles = inputParticles;
185  perfFinder.inputMeasurementParticlesMap =
186  digiCfg.outputMeasurementParticlesMap;
187  perfFinder.filePath = outputDir + "/performance_track_finder.root";
188  sequencer.addWriter(
189  std::make_shared<TrackFinderPerformanceWriter>(perfFinder, logLevel));
190 
192  perfFitter.inputTrajectories = tracksToTrajCfg.outputTrajectories;
193  perfFitter.inputParticles = inputParticles;
194  perfFitter.inputMeasurementParticlesMap =
195  digiCfg.outputMeasurementParticlesMap;
196  perfFitter.filePath = outputDir + "/performance_track_fitter.root";
197  sequencer.addWriter(
198  std::make_shared<TrackFitterPerformanceWriter>(perfFitter, logLevel));
199 
200  return sequencer.run();
201 }