37 #include <dfe/dfe_io_dsv.hpp>
49 throw std::invalid_argument(
"Missing cluster output collection");
52 throw std::invalid_argument(
"Missing hit id output collection");
55 throw std::invalid_argument(
"Missing hit-particles map output collection");
58 throw std::invalid_argument(
"Missing simulated hits output collection");
61 throw std::invalid_argument(
"Missing tracking geometry");
73 return "CsvPlanarClusterReader";
76 std::pair<size_t, size_t>
84 using is_transparent = void;
86 constexpr
bool operator()(
const T&
left,
const T& right)
const {
87 return left.hit_id < right.hit_id;
90 constexpr
bool operator()(uint64_t left_id,
const T& right)
const {
91 return left_id < right.hit_id;
94 constexpr
bool operator()(
const T&
left, uint64_t right_id)
const {
95 return left.hit_id < right_id;
105 struct CompareGeometryId {
108 auto leftId = extractGeometryId(left).value();
109 auto rightId = extractGeometryId(right).value();
110 return leftId < rightId;
114 template <
typename Data>
115 inline std::vector<Data> readEverything(
117 const std::vector<std::string>& optionalColumns,
size_t event) {
119 dfe::NamedTupleCsvReader<Data>
reader(path, optionalColumns);
121 std::vector<Data> everything;
123 while (
reader.read(one)) {
124 everything.push_back(one);
130 std::vector<ActsExamples::HitData> readHitsByGeometryId(
133 auto hits = readEverything<ActsExamples::HitData>(
136 std::sort(hits.begin(), hits.end(), CompareGeometryId{});
140 std::vector<ActsExamples::CellDataLegacy> readCellsByHitId(
143 auto cells = readEverything<ActsExamples::CellDataLegacy>(
146 std::sort(cells.begin(), cells.end(), CompareHitId{});
150 std::vector<ActsExamples::TruthHitData> readTruthHitsByHitId(
153 std::vector<std::string> optionalColumns = {
154 "geometry_id",
"tt",
"te",
"deltapx",
155 "deltapy",
"deltapz",
"deltae",
"index",
157 auto truths = readEverything<ActsExamples::TruthHitData>(
160 std::sort(truths.begin(), truths.end(), CompareHitId{});
179 std::vector<uint64_t> hitIds;
182 clusters.reserve(hits.size());
183 hitIds.reserve(hits.size());
184 hitParticlesMap.reserve(truths.size());
185 simHits.reserve(truths.size());
187 for (
const HitData& hit : hits) {
191 std::vector<std::size_t> simHitIndices;
193 auto range =
makeRange(std::equal_range(truths.begin(), truths.end(),
194 hit.hit_id, CompareHitId{}));
195 simHitIndices.reserve(range.size());
196 for (
const auto& truth : range) {
200 const auto simIndex = truth.index;
225 auto inserted = simHits.emplace_hint(simHits.end(), simGeometryId,
226 simParticleId, simPos4, simMom4,
227 simMom4 + simDelta4, simIndex);
228 if (
std::next(inserted) != simHits.end()) {
229 ACTS_FATAL(
"Truth hit sorting broke for input hit id " << hit.hit_id);
230 return ProcessCode::ABORT;
232 simHitIndices.push_back(simHits.index_of(inserted));
237 std::vector<Acts::DigitizationCell> digitizationCells;
239 auto range =
makeRange(std::equal_range(cells.begin(), cells.end(),
240 hit.hit_id, CompareHitId{}));
241 for (
const auto&
c : range) {
242 digitizationCells.emplace_back(
c.channel0,
c.channel1,
c.value);
248 if (surface ==
nullptr) {
249 ACTS_FATAL(
"Could not retrieve the surface for hit " << hit);
250 return ProcessCode::ABORT;
261 if (not lpResult.ok()) {
262 ACTS_FATAL(
"Global to local transformation did not succeed.");
263 return ProcessCode::ABORT;
265 local = lpResult.value();
281 clusters.emplace_hint(clusters.end(), geoId,
std::move(cluster));
282 if (
std::next(inserted) != clusters.end()) {
283 ACTS_FATAL(
"Something went horribly wrong with the hit sorting");
284 return ProcessCode::ABORT;
286 auto hitIndex = clusters.index_of(inserted);
287 auto truthRange =
makeRange(std::equal_range(truths.begin(), truths.end(),
288 hit.hit_id, CompareHitId{}));
289 for (
const auto& truth : truthRange) {
290 hitParticlesMap.emplace_hint(hitParticlesMap.end(), hitIndex,
295 hitIds.push_back(hit.hit_id);
299 m_outputClusters(ctx,
std::move(clusters));
301 m_outputMeasurementParticlesMap(ctx,
std::move(hitParticlesMap));
302 m_outputSimHits(ctx,
std::move(simHits));