Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TrackReaderVertexingPerformanceWriterExample.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file TrackReaderVertexingPerformanceWriterExample.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2020-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 
14 
29 
30 #include <memory>
31 
32 using namespace Acts::UnitLiterals;
33 using namespace ActsExamples;
34 
35 int main(int argc, char* argv[]) {
36  // setup and parse options
37  auto desc = Options::makeDefaultOptions();
43  Options::addOutputOptions(desc, OutputFormat::DirectoryOnly);
45  auto vars = Options::parse(desc, argc, argv);
46  if (vars.empty()) {
47  return EXIT_FAILURE;
48  }
49 
50  // basic setup
51  auto logLevel = Options::readLogLevel(vars);
52  auto rnd =
53  std::make_shared<RandomNumbers>(Options::readRandomNumbersConfig(vars));
54  Sequencer sequencer(Options::readSequencerConfig(vars));
55 
56  auto inputDir = vars["input-dir"].as<std::string>();
57  auto outputDir =
58  ensureWritableDirectory(vars["output-dir"].as<std::string>());
59 
60  // Setup the magnetic field
62 
63  RootParticleReader::Config particleReaderConfig;
64  particleReaderConfig.particleCollection = "allTruthParticles";
65  particleReaderConfig.filePath = inputDir + "/particles_initial.root";
66  particleReaderConfig.treeName = "particles";
67  sequencer.addReader(std::make_shared<RootParticleReader>(
68  particleReaderConfig, Acts::Logging::INFO));
69 
70  // add additional particle selection
71  auto select = Options::readParticleSelectorConfig(vars);
72  select.inputParticles = particleReaderConfig.particleCollection;
73  select.outputParticles = "detectorAcceptanceSelectedTruthParticles";
74  sequencer.addAlgorithm(
75  std::make_shared<ActsExamples::ParticleSelector>(select, logLevel));
76 
77  RootTrajectorySummaryReader::Config trackSummaryReader;
78  trackSummaryReader.outputTracks = "fittedTrackParameters";
79  trackSummaryReader.outputParticles = "associatedTruthParticles";
80  trackSummaryReader.filePath = inputDir + "/tracksummary_fitter.root";
81  sequencer.addReader(std::make_shared<RootTrajectorySummaryReader>(
82  trackSummaryReader, logLevel));
83 
84  // Apply some primary vertexing selection cuts
85  TrackParameterSelector::Config trackSelectorConfig;
86  trackSelectorConfig.inputTrackParameters = trackSummaryReader.outputTracks;
87  trackSelectorConfig.outputTrackParameters = "selectedTracks";
88  trackSelectorConfig.absEtaMax = vars["vertexing-eta-max"].as<double>();
89  trackSelectorConfig.loc0Max = vars["vertexing-rho-max"].as<double>() * 1_mm;
90  trackSelectorConfig.ptMin = vars["vertexing-pt-min"].as<double>() * 1_MeV;
91  sequencer.addAlgorithm(
92  std::make_shared<TrackParameterSelector>(trackSelectorConfig, logLevel));
93 
94  // find vertices
96  findVertices.bField = magneticField;
97  findVertices.inputTrackParameters = trackSelectorConfig.outputTrackParameters;
98  findVertices.outputProtoVertices = "fittedProtoVertices";
99  findVertices.outputVertices = "fittedVertices";
100  sequencer.addAlgorithm(std::make_shared<AdaptiveMultiVertexFinderAlgorithm>(
101  findVertices, logLevel));
102 
103  // write track parameters from fitting
104  VertexPerformanceWriter::Config vertexWriterConfig;
105  vertexWriterConfig.inputAllTruthParticles =
106  particleReaderConfig.particleCollection;
107  vertexWriterConfig.inputSelectedTruthParticles = select.outputParticles;
108  vertexWriterConfig.inputAssociatedTruthParticles =
109  trackSummaryReader.outputParticles;
110  vertexWriterConfig.inputTrackParameters = trackSummaryReader.outputTracks;
111  vertexWriterConfig.inputVertices = findVertices.outputVertices;
112  vertexWriterConfig.filePath = outputDir + "/vertexperformance_AMVF.root";
113  vertexWriterConfig.treeName = "amvf";
114  sequencer.addWriter(
115  std::make_shared<VertexPerformanceWriter>(vertexWriterConfig, logLevel));
116 
117  return sequencer.run();
118 }