-
Notifications
You must be signed in to change notification settings - Fork 157
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add a spacepoints writer (#970)
* add spacepoint writer * add license * rename files from X2Y to XtoY * clang-format applied * format fixed in one more spot Co-authored-by: Paul Gessinger <hello@paulgessinger.com>
- Loading branch information
1 parent
c8ef092
commit 4f28047
Showing
12 changed files
with
374 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
Examples/Io/Csv/include/ActsExamples/Io/Csv/CsvSpacepointWriter.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
// This file is part of the Acts project. | ||
// | ||
// Copyright (C) 2021 CERN for the benefit of the Acts project | ||
// | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
||
#pragma once | ||
|
||
#include "Acts/Definitions/TrackParametrization.hpp" | ||
#include "Acts/EventData/Measurement.hpp" | ||
#include "Acts/Geometry/GeometryContext.hpp" | ||
#include "Acts/Geometry/GeometryHierarchyMap.hpp" | ||
#include "Acts/Geometry/GeometryIdentifier.hpp" | ||
#include "Acts/Utilities/Helpers.hpp" | ||
#include "ActsExamples/Digitization/DigitizationConfig.hpp" | ||
#include "ActsExamples/EventData/Cluster.hpp" | ||
#include "ActsExamples/EventData/Index.hpp" | ||
#include "ActsExamples/EventData/Measurement.hpp" | ||
#include "ActsExamples/EventData/SimHit.hpp" | ||
#include "ActsExamples/EventData/SimSpacePoint.hpp" | ||
#include "ActsExamples/Framework/WriterT.hpp" | ||
|
||
#include <string> | ||
|
||
namespace ActsExamples { | ||
|
||
/// @class CsvSpacePointWriter | ||
/// | ||
/// This writes one file per event containing information about the | ||
/// spacepoints | ||
/// | ||
/// event000000001-spacepoint.csv | ||
/// event000000002-spacepoint.csv | ||
/// ... | ||
/// | ||
/// Intrinsically thread-safe as one file per event. | ||
class CsvSpacepointWriter final : public WriterT<SimSpacePointContainer> { | ||
public: | ||
struct Config { | ||
/// Which measurement collection to write. | ||
std::string inputSpacepoints; | ||
/// Where to place output files | ||
std::string outputDir; | ||
/// Number of decimal digits for floating point precision in output. | ||
size_t outputPrecision = std::numeric_limits<float>::max_digits10; | ||
}; | ||
|
||
/// Constructor with | ||
/// @param config configuration struct | ||
/// @param level logging level | ||
CsvSpacepointWriter(const Config& config, Acts::Logging::Level level); | ||
|
||
/// Virtual destructor | ||
~CsvSpacepointWriter() final override; | ||
|
||
/// End-of-run hook | ||
ProcessCode endRun() final override; | ||
|
||
protected: | ||
/// This implementation holds the actual writing method | ||
/// and is called by the WriterT<>::write interface | ||
/// | ||
/// @param ctx The Algorithm context with per event information | ||
/// @param spacepoints is the data to be written out | ||
ProcessCode writeT(const AlgorithmContext& ctx, | ||
const SimSpacePointContainer& spacepoints) final override; | ||
|
||
private: | ||
Config m_cfg; | ||
}; | ||
|
||
} // namespace ActsExamples |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// This file is part of the Acts project. | ||
// | ||
// Copyright (C) 2021 CERN for the benefit of the Acts project | ||
// | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
||
#include "ActsExamples/Io/Csv/CsvSpacepointWriter.hpp" | ||
|
||
#include "Acts/Definitions/Units.hpp" | ||
#include "ActsExamples/EventData/SimSpacePoint.hpp" | ||
#include "ActsExamples/Utilities/Paths.hpp" | ||
|
||
#include <ios> | ||
#include <optional> | ||
#include <stdexcept> | ||
|
||
#include <dfe/dfe_io_dsv.hpp> | ||
|
||
#include "CsvOutputData.hpp" | ||
|
||
ActsExamples::CsvSpacepointWriter::CsvSpacepointWriter( | ||
const ActsExamples::CsvSpacepointWriter::Config& config, | ||
Acts::Logging::Level level) | ||
: WriterT(config.inputSpacepoints, "CsvSpacepointWriter", level), | ||
m_cfg(config) {} | ||
|
||
ActsExamples::CsvSpacepointWriter::~CsvSpacepointWriter() {} | ||
|
||
ActsExamples::ProcessCode ActsExamples::CsvSpacepointWriter::endRun() { | ||
// Write the tree | ||
return ProcessCode::SUCCESS; | ||
} | ||
|
||
ActsExamples::ProcessCode ActsExamples::CsvSpacepointWriter::writeT( | ||
const AlgorithmContext& ctx, const SimSpacePointContainer& spacepoints) { | ||
// Open per-event file for all components | ||
std::string pathSP = | ||
perEventFilepath(m_cfg.outputDir, "spacepoint.csv", ctx.eventNumber); | ||
|
||
dfe::NamedTupleCsvWriter<SpacepointData> writerSP(pathSP, | ||
m_cfg.outputPrecision); | ||
|
||
SpacepointData spData; | ||
for (const auto& sp : spacepoints) { | ||
spData.measurement_id = sp.measurementIndex(); | ||
spData.x = sp.x(); | ||
spData.y = sp.y(); | ||
spData.z = sp.z(); | ||
spData.var_r = sp.varianceR(); | ||
spData.var_z = sp.varianceZ(); | ||
writerSP.append(spData); | ||
} | ||
return ActsExamples::ProcessCode::SUCCESS; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
117 changes: 117 additions & 0 deletions
117
Examples/Run/Reconstruction/Common/MeasurementsToSpacepoints.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
// This file is part of the Acts project. | ||
// | ||
// Copyright (C) 2021 CERN for the benefit of the Acts project | ||
// | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
||
#include "Acts/Definitions/Units.hpp" | ||
#include "ActsExamples/Detector/IBaseDetector.hpp" | ||
#include "ActsExamples/Framework/RandomNumbers.hpp" | ||
#include "ActsExamples/Framework/Sequencer.hpp" | ||
#include "ActsExamples/Geometry/CommonGeometry.hpp" | ||
#include "ActsExamples/Io/Csv/CsvOptionsReader.hpp" | ||
#include "ActsExamples/Io/Csv/CsvParticleReader.hpp" // for evaluating performance | ||
#include "ActsExamples/Io/Csv/CsvSimHitReader.hpp" | ||
#include "ActsExamples/Io/Csv/CsvSpacepointWriter.hpp" | ||
#include "ActsExamples/Io/Json/JsonDigitizationConfig.hpp" // to read digi config | ||
#include "ActsExamples/MagneticField/MagneticFieldOptions.hpp" | ||
#include "ActsExamples/Options/CommonOptions.hpp" | ||
#include "ActsExamples/Reconstruction/ReconstructionBase.hpp" | ||
#include "ActsExamples/TrackFinding/SpacePointMaker.hpp" | ||
#include "ActsExamples/TruthTracking/TruthSeedSelector.hpp" // for evaluating performance | ||
#include "ActsExamples/Utilities/Options.hpp" | ||
#include "ActsExamples/Utilities/Paths.hpp" | ||
#include <Acts/Utilities/Logger.hpp> | ||
|
||
#include <iostream> | ||
|
||
#include <boost/program_options.hpp> | ||
|
||
using namespace Acts::UnitLiterals; | ||
using namespace ActsExamples; | ||
|
||
static std::unique_ptr<const Acts::Logger> m_logger; | ||
const Acts::Logger& logger() { | ||
return *m_logger; | ||
} | ||
int runMeasurementsToSP(int argc, char* argv[], | ||
std::shared_ptr<ActsExamples::IBaseDetector> detector) { | ||
// Setup and parse options | ||
auto desc = Options::makeDefaultOptions(); | ||
Options::addSequencerOptions(desc); | ||
Options::addRandomNumbersOptions(desc); | ||
Options::addGeometryOptions(desc); | ||
Options::addMaterialOptions(desc); | ||
Options::addOutputOptions(desc, OutputFormat::Csv | OutputFormat::Root); | ||
Options::addInputOptions(desc); | ||
Options::addMagneticFieldOptions(desc); | ||
|
||
// Add specific options for this geometry | ||
// <TODO> make it as an argument. | ||
// auto detector = std::make_shared<TGeoDetector>(); | ||
detector->addOptions(desc); | ||
|
||
auto vm = Options::parse(desc, argc, argv); | ||
if (vm.empty()) { | ||
return EXIT_FAILURE; | ||
} | ||
|
||
Sequencer sequencer(Options::readSequencerConfig(vm)); | ||
|
||
// Now read the standard options | ||
auto logLevel = Options::readLogLevel(vm); | ||
auto outputDir = ensureWritableDirectory(vm["output-dir"].as<std::string>()); | ||
|
||
m_logger = Acts::getDefaultLogger("MeasurementsToSP", logLevel); | ||
ACTS_INFO("after parsing input options"); | ||
|
||
// The geometry, material and decoration | ||
// build the detector | ||
auto geometry = Geometry::build(vm, *detector); | ||
auto tGeometry = geometry.first; | ||
auto contextDecorators = geometry.second; | ||
auto randomNumbers = | ||
std::make_shared<RandomNumbers>(Options::readRandomNumbersConfig(vm)); | ||
|
||
ACTS_INFO("after building geometry"); | ||
|
||
// Add the decorator to the sequencer | ||
for (auto cdr : contextDecorators) { | ||
sequencer.addContextDecorator(cdr); | ||
} | ||
|
||
ACTS_INFO("after adding context decorator"); | ||
|
||
// Setup the magnetic field | ||
Options::setupMagneticFieldServices(vm, sequencer); | ||
auto magneticField = Options::readMagneticField(vm); | ||
|
||
ACTS_INFO("after setting magnetic field"); | ||
|
||
// Read the inputs | ||
auto simHitReaderCfg = setupSimHitReading(vm, sequencer); | ||
auto particleReader = setupParticleReading(vm, sequencer); | ||
auto measurementsReader = setupMeasurementReading(vm, sequencer); | ||
|
||
ACTS_INFO("after reading SimHits and particles"); | ||
|
||
// Now measurements --> SpacePoints | ||
SpacePointMaker::Config spCfg; | ||
spCfg.inputSourceLinks = measurementsReader.outputSourceLinks; | ||
spCfg.inputMeasurements = measurementsReader.outputMeasurements; | ||
spCfg.outputSpacePoints = "spacepoints"; | ||
spCfg.trackingGeometry = tGeometry; | ||
spCfg.geometrySelection = {Acts::GeometryIdentifier().setVolume(0)}; | ||
sequencer.addAlgorithm(std::make_shared<SpacePointMaker>(spCfg, logLevel)); | ||
|
||
// // write out spacepoints... | ||
CsvSpacepointWriter::Config spWriterCfg; | ||
spWriterCfg.inputSpacepoints = spCfg.outputSpacePoints; | ||
spWriterCfg.outputDir = outputDir; | ||
sequencer.addWriter( | ||
std::make_shared<CsvSpacepointWriter>(spWriterCfg, logLevel)); | ||
|
||
return sequencer.run(); | ||
} |
17 changes: 17 additions & 0 deletions
17
Examples/Run/Reconstruction/Common/MeasurementsToSpacepoints.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// This file is part of the Acts project. | ||
// | ||
// Copyright (C) 2021 CERN for the benefit of the Acts project | ||
// | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
||
#pragma once | ||
|
||
#include <memory> | ||
namespace ActsExamples { | ||
class IBaseDetector; | ||
} | ||
|
||
int runMeasurementsToSP(int argc, char* argv[], | ||
std::shared_ptr<ActsExamples::IBaseDetector> detector); |
Oops, something went wrong.