Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
HoughExample.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file HoughExample.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 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  // Hough algorithm
120  houghCfg.inputSpacePoints = {
121  spCfg.outputSpacePoints,
122  };
123  houghCfg.outputSeeds = "seeds";
124  houghCfg.outputProtoTracks = "prototracks";
125 
126  houghCfg.inputMeasurements = digiCfg.outputMeasurements;
127  houghCfg.trackingGeometry = tGeometry;
128  houghCfg.inputSourceLinks = digiCfg.outputSourceLinks;
130 
131  houghCfg.subRegions = {0, 1};
132 
133  houghCfg.xMin = -0.05; // minphi
134  houghCfg.xMax = 0.25; // maxphi
135  houghCfg.yMin = -1.25; // min q/pt, -1/0.8 GeV
136  houghCfg.yMax = 1.25; // max q/pt, +1/0.8 GeV
137 
138  houghCfg.houghHistSize_x = 216;
139  houghCfg.houghHistSize_y = 216; // i.e. number of bins in q/pT
140 
141  houghCfg.hitExtend_x = {
142  2, 1, 0, 0, 0,
143  0, 0, 0, 0, 0}; // Hit lines will fill extra bins in x by this amount on
144  // each side, size == nLayers
145  houghCfg.nLayers = 10;
146 
147  houghCfg.threshold = {9}; // Minimum point value post-convolution to accept
148  // as a road (inclusive)
149 
150  houghCfg.localMaxWindowSize =
151  0; // Only create roads from a local maximum, requires traceHits
152  houghCfg.kA = 0.0003; // Assume B = 2T constant.
153 
154  houghCfg.fieldCorrector
156  houghCfg.layerIDFinder
158  houghCfg.sliceTester
160 
161  sequencer.addAlgorithm(
162  std::make_shared<HoughTransformSeeder>(houghCfg, logLevel));
163 
164  // Algorithm estimating track parameter from seed
165  TrackParamsEstimationAlgorithm::Config paramsEstimationCfg;
166  paramsEstimationCfg.inputSeeds = houghCfg.outputSeeds;
167  paramsEstimationCfg.outputTrackParameters = "estimatedparameters";
168  paramsEstimationCfg.trackingGeometry = tGeometry;
169  paramsEstimationCfg.magneticField = magneticField;
170  sequencer.addAlgorithm(std::make_shared<TrackParamsEstimationAlgorithm>(
171  paramsEstimationCfg, logLevel));
172 
173  // Seeding performance Writers
175  tfPerfCfg.inputProtoTracks = houghCfg.outputProtoTracks;
176  tfPerfCfg.inputParticles = inputParticles;
177  tfPerfCfg.inputMeasurementParticlesMap =
178  digiCfg.outputMeasurementParticlesMap;
179  tfPerfCfg.filePath = outputDir + "/performance_seeding_trees.root";
180  sequencer.addWriter(
181  std::make_shared<TrackFinderPerformanceWriter>(tfPerfCfg, logLevel));
182 
184  seedPerfCfg.inputSeeds = houghCfg.outputSeeds;
185  seedPerfCfg.inputParticles = inputParticles;
186  seedPerfCfg.inputMeasurementParticlesMap =
187  digiCfg.outputMeasurementParticlesMap;
188  seedPerfCfg.filePath = outputDir + "/performance_seeding.root";
189  sequencer.addWriter(
190  std::make_shared<SeedingPerformanceWriter>(seedPerfCfg, logLevel));
191 
192  // The track parameters estimation writer
193  RootTrackParameterWriter::Config trackParamsWriterCfg;
194  trackParamsWriterCfg.inputTrackParameters =
195  paramsEstimationCfg.outputTrackParameters;
196  trackParamsWriterCfg.inputProtoTracks = houghCfg.outputProtoTracks;
197  trackParamsWriterCfg.inputParticles = particleReader.outputParticles;
198  trackParamsWriterCfg.inputSimHits = simHitReaderCfg.outputSimHits;
199  trackParamsWriterCfg.inputMeasurementParticlesMap =
200  digiCfg.outputMeasurementParticlesMap;
201  trackParamsWriterCfg.inputMeasurementSimHitsMap =
202  digiCfg.outputMeasurementSimHitsMap;
203  trackParamsWriterCfg.filePath = outputDir + "/estimatedparams.root";
204  trackParamsWriterCfg.treeName = "estimatedparams";
205  sequencer.addWriter(std::make_shared<RootTrackParameterWriter>(
206  trackParamsWriterCfg, logLevel));
207 
208  return sequencer.run();
209 }