EIC 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 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 
28 #include <Acts/Utilities/Units.hpp>
29 
30 #include <memory>
31 
32 using namespace Acts::UnitLiterals;
33 using namespace ActsExamples;
34 
35 int main(int argc, char* argv[]) {
36  GenericDetector detector;
37 
38  // setup and parse options
46  detector.addOptions(desc);
48 
49  auto vm = Options::parse(desc, argc, argv);
50  if (vm.empty()) {
51  return EXIT_FAILURE;
52  }
53 
55 
56  // Read some standard options
57  auto logLevel = Options::readLogLevel(vm);
58  auto inputDir = vm["input-dir"].as<std::string>();
59  auto outputDir = ensureWritableDirectory(vm["output-dir"].as<std::string>());
60  auto rnd = std::make_shared<ActsExamples::RandomNumbers>(
62 
63  // Setup detector geometry
64  auto geometry = Geometry::build(vm, detector);
65  auto trackingGeometry = geometry.first;
66  // Add context decorators
67  for (auto cdr : geometry.second) {
68  sequencer.addContextDecorator(cdr);
69  }
70  // Setup the magnetic field
72 
73  // Read particles (initial states) and clusters from CSV files
74  auto particleReader = Options::readCsvParticleReaderConfig(vm);
75  particleReader.inputStem = "particles_initial";
76  particleReader.outputParticles = "particles_initial";
77  sequencer.addReader(
78  std::make_shared<CsvParticleReader>(particleReader, logLevel));
79  // Read clusters from CSV files
80  auto clusterReaderCfg = Options::readCsvPlanarClusterReaderConfig(vm);
81  clusterReaderCfg.trackingGeometry = trackingGeometry;
82  clusterReaderCfg.outputClusters = "clusters";
83  clusterReaderCfg.outputHitIds = "hit_ids";
84  clusterReaderCfg.outputHitParticlesMap = "hit_particles_map";
85  clusterReaderCfg.outputSimulatedHits = "hits";
86  sequencer.addReader(
87  std::make_shared<CsvPlanarClusterReader>(clusterReaderCfg, logLevel));
88 
89  // Pre-select particles
90  // The pre-selection will select truth particles satisfying provided criteria
91  // from all particles read in by particle reader for further processing. It
92  // has no impact on the truth hits read-in by the cluster reader.
93  // @TODO: add options for truth particle selection criteria
94  TruthSeedSelector::Config particleSelectorCfg;
95  particleSelectorCfg.inputParticles = particleReader.outputParticles;
96  particleSelectorCfg.inputHitParticlesMap =
97  clusterReaderCfg.outputHitParticlesMap;
98  particleSelectorCfg.outputParticles = "particles_selected";
99  particleSelectorCfg.nHitsMin = 1;
100  sequencer.addAlgorithm(
101  std::make_shared<TruthSeedSelector>(particleSelectorCfg, logLevel));
102 
103  // Create smeared measurements
104  HitSmearing::Config hitSmearingCfg;
105  hitSmearingCfg.inputSimulatedHits = clusterReaderCfg.outputSimulatedHits;
106  hitSmearingCfg.outputSourceLinks = "sourcelinks";
107  hitSmearingCfg.sigmaLoc0 = 25_um;
108  hitSmearingCfg.sigmaLoc1 = 100_um;
109  hitSmearingCfg.randomNumbers = rnd;
110  hitSmearingCfg.trackingGeometry = trackingGeometry;
111  sequencer.addAlgorithm(
112  std::make_shared<HitSmearing>(hitSmearingCfg, logLevel));
113 
114  // The fitter needs the measurements (proto tracks) and initial
115  // track states (proto states). The elements in both collections
116  // must match and must be created from the same input particles.
117  const auto& inputParticles = particleSelectorCfg.outputParticles;
118  // Create truth tracks
119  TruthTrackFinder::Config trackFinderCfg;
120  trackFinderCfg.inputParticles = inputParticles;
121  trackFinderCfg.inputHitParticlesMap = clusterReaderCfg.outputHitParticlesMap;
122  trackFinderCfg.outputProtoTracks = "prototracks";
123  sequencer.addAlgorithm(
124  std::make_shared<TruthTrackFinder>(trackFinderCfg, logLevel));
125  // Create smeared particles states
126  ParticleSmearing::Config particleSmearingCfg;
127  particleSmearingCfg.inputParticles = inputParticles;
128  particleSmearingCfg.outputTrackParameters = "smearedparameters";
129  particleSmearingCfg.randomNumbers = rnd;
130  // Gaussian sigmas to smear particle parameters
131  particleSmearingCfg.sigmaD0 = 20_um;
132  particleSmearingCfg.sigmaD0PtA = 30_um;
133  particleSmearingCfg.sigmaD0PtB = 0.3 / 1_GeV;
134  particleSmearingCfg.sigmaZ0 = 20_um;
135  particleSmearingCfg.sigmaZ0PtA = 30_um;
136  particleSmearingCfg.sigmaZ0PtB = 0.3 / 1_GeV;
137  particleSmearingCfg.sigmaPhi = 1_degree;
138  particleSmearingCfg.sigmaTheta = 1_degree;
139  particleSmearingCfg.sigmaPRel = 0.01;
140  particleSmearingCfg.sigmaT0 = 1_ns;
141  sequencer.addAlgorithm(
142  std::make_shared<ParticleSmearing>(particleSmearingCfg, logLevel));
143 
144  // setup the fitter
146  fitter.inputSourceLinks = hitSmearingCfg.outputSourceLinks;
147  fitter.inputProtoTracks = trackFinderCfg.outputProtoTracks;
149  particleSmearingCfg.outputTrackParameters;
150  fitter.outputTrajectories = "trajectories";
151  fitter.fit =
152  FittingAlgorithm::makeFitterFunction(trackingGeometry, magneticField);
153  sequencer.addAlgorithm(std::make_shared<FittingAlgorithm>(fitter, logLevel));
154 
155  // write tracks from fitting
156  RootTrajectoryWriter::Config trackWriter;
157  trackWriter.inputParticles = inputParticles;
158  trackWriter.inputTrajectories = fitter.outputTrajectories;
159  trackWriter.outputDir = outputDir;
160  trackWriter.outputFilename = "tracks.root";
161  trackWriter.outputTreename = "tracks";
162  sequencer.addWriter(
163  std::make_shared<RootTrajectoryWriter>(trackWriter, logLevel));
164 
165  // write reconstruction performance data
167  perfFinder.inputParticles = inputParticles;
168  perfFinder.inputHitParticlesMap = clusterReaderCfg.outputHitParticlesMap;
169  perfFinder.inputProtoTracks = trackFinderCfg.outputProtoTracks;
170  perfFinder.outputDir = outputDir;
171  sequencer.addWriter(
172  std::make_shared<TrackFinderPerformanceWriter>(perfFinder, logLevel));
174  perfFitter.inputParticles = inputParticles;
175  perfFitter.inputTrajectories = fitter.outputTrajectories;
176  perfFitter.outputDir = outputDir;
177  sequencer.addWriter(
178  std::make_shared<TrackFitterPerformanceWriter>(perfFitter, logLevel));
179 
180  return sequencer.run();
181 }