File indexing completed on 2025-01-18 09:11:51
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include "ActsExamples/Io/Csv/CsvSimHitWriter.hpp"
0010
0011 #include "Acts/Definitions/Algebra.hpp"
0012 #include "Acts/Definitions/Common.hpp"
0013 #include "Acts/Definitions/Units.hpp"
0014 #include "Acts/Geometry/GeometryIdentifier.hpp"
0015 #include "ActsExamples/EventData/SimHit.hpp"
0016 #include "ActsExamples/Framework/AlgorithmContext.hpp"
0017 #include "ActsExamples/Io/Csv/CsvInputOutput.hpp"
0018 #include "ActsExamples/Utilities/Paths.hpp"
0019 #include "ActsFatras/EventData/Barcode.hpp"
0020 #include "ActsFatras/EventData/Hit.hpp"
0021
0022 #include <stdexcept>
0023 #include <vector>
0024
0025 #include "CsvOutputData.hpp"
0026
0027 ActsExamples::CsvSimHitWriter::CsvSimHitWriter(
0028 const ActsExamples::CsvSimHitWriter::Config& config,
0029 Acts::Logging::Level level)
0030 : WriterT(config.inputSimHits, "CsvSimHitWriter", level), m_cfg(config) {
0031
0032 if (m_cfg.outputStem.empty()) {
0033 throw std::invalid_argument("Missing output filename stem");
0034 }
0035 }
0036
0037 ActsExamples::ProcessCode ActsExamples::CsvSimHitWriter::writeT(
0038 const AlgorithmContext& ctx, const ActsExamples::SimHitContainer& simHits) {
0039
0040 std::string pathSimHit = perEventFilepath(
0041 m_cfg.outputDir, m_cfg.outputStem + ".csv", ctx.eventNumber);
0042
0043 ActsExamples::NamedTupleCsvWriter<SimHitData> writerSimHit(
0044 pathSimHit, m_cfg.outputPrecision);
0045
0046
0047 SimHitData simhit;
0048
0049 for (const auto& simHit : simHits) {
0050
0051 const Acts::Vector4& globalPos4 = simHit.fourPosition();
0052 const Acts::Vector4& momentum4Before = simHit.momentum4Before();
0053
0054 simhit.geometry_id = simHit.geometryId().value();
0055 simhit.particle_id = simHit.particleId().value();
0056
0057 simhit.tx = globalPos4[Acts::ePos0] / Acts::UnitConstants::mm;
0058 simhit.ty = globalPos4[Acts::ePos1] / Acts::UnitConstants::mm;
0059 simhit.tz = globalPos4[Acts::ePos2] / Acts::UnitConstants::mm;
0060 simhit.tt = globalPos4[Acts::eTime] / Acts::UnitConstants::mm;
0061
0062 simhit.tpx = momentum4Before[Acts::eMom0] / Acts::UnitConstants::GeV;
0063 simhit.tpy = momentum4Before[Acts::eMom1] / Acts::UnitConstants::GeV;
0064 simhit.tpz = momentum4Before[Acts::eMom2] / Acts::UnitConstants::GeV;
0065 simhit.te = momentum4Before[Acts::eEnergy] / Acts::UnitConstants::GeV;
0066
0067 const auto delta4 = simHit.momentum4After() - momentum4Before;
0068 simhit.deltapx = delta4[Acts::eMom0] / Acts::UnitConstants::GeV;
0069 simhit.deltapy = delta4[Acts::eMom1] / Acts::UnitConstants::GeV;
0070 simhit.deltapz = delta4[Acts::eMom2] / Acts::UnitConstants::GeV;
0071 simhit.deltae = delta4[Acts::eEnergy] / Acts::UnitConstants::GeV;
0072
0073 simhit.index = simHit.index();
0074 writerSimHit.append(simhit);
0075 }
0076
0077 return ActsExamples::ProcessCode::SUCCESS;
0078 }