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