Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SeedingExample.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file SeedingExample.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 
32 
33 #include <memory>
34 
35 #include <boost/program_options.hpp>
36 
37 using namespace Acts::UnitLiterals;
38 using namespace ActsExamples;
39 
41  int argc, char* argv[],
42  const std::shared_ptr<ActsExamples::IBaseDetector>& detector) {
43  // Setup and parse options
44  auto desc = Options::makeDefaultOptions();
49  Options::addOutputOptions(desc, OutputFormat::DirectoryOnly);
54  // Add specific options for this geometry
55  detector->addOptions(desc);
56  auto vm = Options::parse(desc, argc, argv);
57  if (vm.empty()) {
58  return EXIT_FAILURE;
59  }
61 
62  // Now read the standard options
64  auto outputDir = ensureWritableDirectory(vm["output-dir"].as<std::string>());
65 
66  // The geometry, material and decoration
67  auto geometry = Geometry::build(vm, *detector);
68  auto tGeometry = geometry.first;
69  auto contextDecorators = geometry.second;
70  auto rnd =
71  std::make_shared<RandomNumbers>(Options::readRandomNumbersConfig(vm));
72 
73  // Add the decorator to the sequencer
74  for (const auto& cdr : contextDecorators) {
75  sequencer.addContextDecorator(cdr);
76  }
77 
78  // Setup the magnetic field
81 
82  // Read the sim hits
83  auto simHitReaderCfg = setupSimHitReading(vm, sequencer);
84  // Read the particles
85  auto particleReader = setupParticleReading(vm, sequencer);
86 
87  // Run the sim hits smearing
88  auto digiCfg = setupDigitization(vm, sequencer, rnd, tGeometry,
89  simHitReaderCfg.outputSimHits);
90 
91  // Run the particle selection
92  // The pre-selection will select truth particles satisfying provided criteria
93  // from all particles read in by particle reader for further processing. It
94  // has no impact on the truth hits read-in by the cluster reader.
95  TruthSeedSelector::Config particleSelectorCfg;
96  particleSelectorCfg.inputParticles = particleReader.outputParticles;
97  particleSelectorCfg.inputMeasurementParticlesMap =
98  digiCfg.outputMeasurementParticlesMap;
99  particleSelectorCfg.outputParticles = "particles_selected";
100  particleSelectorCfg.ptMin = 1_GeV;
101  particleSelectorCfg.etaMax = 2.5;
102  particleSelectorCfg.etaMin = -2.5;
103  particleSelectorCfg.nHitsMin = 9;
104  sequencer.addAlgorithm(
105  std::make_shared<TruthSeedSelector>(particleSelectorCfg, logLevel));
106 
107  // The selected particles
108  const auto& inputParticles = particleSelectorCfg.outputParticles;
109 
110  // Create space points
112  spCfg.inputSourceLinks = digiCfg.outputSourceLinks;
113  spCfg.inputMeasurements = digiCfg.outputMeasurements;
114  spCfg.outputSpacePoints = "spacepoints";
115  spCfg.trackingGeometry = tGeometry;
116  sequencer.addAlgorithm(std::make_shared<SpacePointMaker>(spCfg, logLevel));
117 
118  // Seeding algorithm
119  SeedingAlgorithm::Config seedingCfg;
120  seedingCfg.inputSpacePoints = {
121  spCfg.outputSpacePoints,
122  };
123  seedingCfg.outputSeeds = "seeds";
124  seedingCfg.gridConfig.rMax = 200._mm;
125  seedingCfg.seedFinderConfig.rMax = seedingCfg.gridConfig.rMax;
126 
127  seedingCfg.seedFilterConfig.deltaRMin = 1_mm;
128  seedingCfg.seedFinderConfig.deltaRMin = seedingCfg.seedFilterConfig.deltaRMin;
129  seedingCfg.seedFinderConfig.deltaRMinTopSP =
130  seedingCfg.seedFilterConfig.deltaRMin;
132  seedingCfg.seedFilterConfig.deltaRMin;
133 
134  seedingCfg.gridConfig.deltaRMax = 60._mm;
135  seedingCfg.seedFinderConfig.deltaRMax = seedingCfg.gridConfig.deltaRMax;
136  seedingCfg.seedFinderConfig.deltaRMaxTopSP = seedingCfg.gridConfig.deltaRMax;
138  seedingCfg.gridConfig.deltaRMax;
139 
140  seedingCfg.seedFinderConfig.collisionRegionMin = -250_mm;
141  seedingCfg.seedFinderConfig.collisionRegionMax = 250._mm;
142 
143  seedingCfg.gridConfig.zMin = -2000._mm;
144  seedingCfg.gridConfig.zMax = 2000._mm;
145  seedingCfg.seedFinderConfig.zMin = seedingCfg.gridConfig.zMin;
146  seedingCfg.seedFinderConfig.zMax = seedingCfg.gridConfig.zMax;
147 
148  seedingCfg.seedFilterConfig.maxSeedsPerSpM = 1;
149  seedingCfg.seedFinderConfig.maxSeedsPerSpM =
150  seedingCfg.seedFilterConfig.maxSeedsPerSpM;
151 
152  seedingCfg.gridConfig.cotThetaMax = 7.40627; // 2.7 eta
153  seedingCfg.seedFinderConfig.cotThetaMax = seedingCfg.gridConfig.cotThetaMax;
154 
155  seedingCfg.seedFinderConfig.sigmaScattering = 5;
156  seedingCfg.seedFinderConfig.radLengthPerSeed = 0.5;
157 
158  seedingCfg.gridConfig.minPt = 500._MeV;
159  seedingCfg.seedFinderConfig.minPt = seedingCfg.gridConfig.minPt;
160 
161  seedingCfg.gridOptions.bFieldInZ = 1.99724_T;
162 
163  seedingCfg.seedFinderOptions.bFieldInZ = seedingCfg.gridOptions.bFieldInZ;
164  seedingCfg.seedFinderOptions.beamPos = {0_mm, 0_mm};
165 
166  seedingCfg.seedFinderConfig.impactMax = 3._mm;
167 
168  sequencer.addAlgorithm(
169  std::make_shared<SeedingAlgorithm>(seedingCfg, logLevel));
170 
171  SeedsToPrototracks::Config seedsToPrototrackCfg;
172  seedsToPrototrackCfg.inputSeeds = seedingCfg.outputSeeds;
173  seedsToPrototrackCfg.outputProtoTracks = "prototracks";
174  sequencer.addAlgorithm(
175  std::make_shared<SeedsToPrototracks>(seedsToPrototrackCfg, logLevel));
176 
177  // Algorithm estimating track parameter from seed
178  TrackParamsEstimationAlgorithm::Config paramsEstimationCfg;
179  paramsEstimationCfg.inputSeeds = seedingCfg.outputSeeds;
180  paramsEstimationCfg.outputTrackParameters = "estimatedparameters";
181  paramsEstimationCfg.trackingGeometry = tGeometry;
182  paramsEstimationCfg.magneticField = magneticField;
183  sequencer.addAlgorithm(std::make_shared<TrackParamsEstimationAlgorithm>(
184  paramsEstimationCfg, logLevel));
185 
186  // Seeding performance Writers
188  tfPerfCfg.inputProtoTracks = seedsToPrototrackCfg.outputProtoTracks;
189  tfPerfCfg.inputParticles = inputParticles;
190  tfPerfCfg.inputMeasurementParticlesMap =
191  digiCfg.outputMeasurementParticlesMap;
192  tfPerfCfg.filePath = outputDir + "/performance_seeding_trees.root";
193  sequencer.addWriter(
194  std::make_shared<TrackFinderPerformanceWriter>(tfPerfCfg, logLevel));
195 
197  seedPerfCfg.inputSeeds = seedingCfg.outputSeeds;
198  seedPerfCfg.inputParticles = inputParticles;
199  seedPerfCfg.inputMeasurementParticlesMap =
200  digiCfg.outputMeasurementParticlesMap;
201  seedPerfCfg.filePath = outputDir + "/performance_seeding.root";
202  sequencer.addWriter(
203  std::make_shared<SeedingPerformanceWriter>(seedPerfCfg, logLevel));
204 
205  // The track parameters estimation writer
206  RootTrackParameterWriter::Config trackParamsWriterCfg;
207  trackParamsWriterCfg.inputTrackParameters =
208  paramsEstimationCfg.outputTrackParameters;
209  trackParamsWriterCfg.inputProtoTracks =
210  seedsToPrototrackCfg.outputProtoTracks;
211  trackParamsWriterCfg.inputParticles = particleReader.outputParticles;
212  trackParamsWriterCfg.inputSimHits = simHitReaderCfg.outputSimHits;
213  trackParamsWriterCfg.inputMeasurementParticlesMap =
214  digiCfg.outputMeasurementParticlesMap;
215  trackParamsWriterCfg.inputMeasurementSimHitsMap =
216  digiCfg.outputMeasurementSimHitsMap;
217  trackParamsWriterCfg.filePath = outputDir + "/estimatedparams.root";
218  trackParamsWriterCfg.treeName = "estimatedparams";
219  sequencer.addWriter(std::make_shared<RootTrackParameterWriter>(
220  trackParamsWriterCfg, logLevel));
221 
222  return sequencer.run();
223 }