36 throw std::invalid_argument(
"Missing cluster output collection");
39 throw std::invalid_argument(
"Missing hit id output collection");
42 throw std::invalid_argument(
"Missing hit-particles map output collection");
45 throw std::invalid_argument(
"Missing simulated hits output collection");
48 throw std::invalid_argument(
"Missing tracking geometry");
58 return "CsvPlanarClusterReader";
61 std::pair<size_t, size_t>
69 using is_transparent =
void;
71 constexpr
bool operator()(
const T& left,
const T& right)
const {
72 return left.hit_id < right.hit_id;
75 constexpr
bool operator()(uint64_t left_id,
const T& right)
const {
76 return left_id < right.hit_id;
79 constexpr
bool operator()(
const T& left, uint64_t right_id)
const {
80 return left.hit_id < right_id;
99 struct CompareGeometryId {
102 auto leftId = extractGeometryId(left).
value();
103 auto rightId = extractGeometryId(right).value();
104 return leftId < rightId;
108 template <
typename Data>
109 inline std::vector<Data> readEverything(
110 const std::string& inputDir,
const std::string&
filename,
111 const std::vector<std::string>& optionalColumns,
size_t event) {
115 std::vector<Data> everything;
117 while (
reader.read(one)) {
118 everything.push_back(one);
124 std::vector<ActsExamples::HitData> readHitsByGeometryId(
125 const std::string& inputDir,
size_t event) {
127 auto hits = readEverything<ActsExamples::HitData>(
128 inputDir,
"hits.csv", {
"geometry_id",
"t"}, event);
130 std::sort(hits.begin(), hits.end(), CompareGeometryId{});
134 std::vector<ActsExamples::CellData> readCellsByHitId(
135 const std::string& inputDir,
size_t event) {
137 auto cells = readEverything<ActsExamples::CellData>(inputDir,
"cells.csv",
138 {
"timestamp"}, event);
140 std::sort(cells.begin(), cells.end(), CompareHitId{});
144 std::vector<ActsExamples::TruthHitData> readTruthHitsByHitId(
145 const std::string& inputDir,
size_t event) {
147 std::vector<std::string> optionalColumns = {
148 "geometry_id",
"tt",
"te",
"deltapx",
149 "deltapy",
"deltapz",
"deltae",
"index",
151 auto truths = readEverything<ActsExamples::TruthHitData>(
152 inputDir,
"truth.csv", optionalColumns, event);
154 std::sort(truths.begin(), truths.end(), CompareHitId{});
167 auto hits = readHitsByGeometryId(m_cfg.inputDir, ctx.
eventNumber);
168 auto cells = readCellsByHitId(m_cfg.inputDir, ctx.
eventNumber);
169 auto truths = readTruthHitsByHitId(m_cfg.inputDir, ctx.
eventNumber);
173 std::vector<uint64_t> hitIds;
176 clusters.reserve(hits.size());
177 hitIds.reserve(hits.size());
178 hitParticlesMap.reserve(truths.size());
179 simHits.reserve(truths.size());
181 for (
const HitData& hit : hits) {
185 std::vector<std::size_t> simHitIndices;
187 auto range =
makeRange(std::equal_range(truths.begin(), truths.end(),
188 hit.hit_id, CompareHitId{}));
189 simHitIndices.reserve(range.size());
190 for (
const auto& truth : range) {
194 const auto simIndex = truth.index;
219 auto inserted = simHits.emplace_hint(simHits.end(), simGeometryId,
220 simParticleId, simPos4, simMom4,
221 simMom4 + simDelta4, simIndex);
222 if (std::next(inserted) != simHits.end()) {
223 ACTS_FATAL(
"Truth hit sorting broke for input hit id " << hit.hit_id);
224 return ProcessCode::ABORT;
226 simHitIndices.push_back(simHits.index_of(inserted));
231 std::vector<Acts::DigitizationCell> digitizationCells;
233 auto range =
makeRange(std::equal_range(cells.begin(), cells.end(),
234 hit.hit_id, CompareHitId{}));
235 for (
const auto&
c : range) {
236 digitizationCells.emplace_back(
c.ch0,
c.ch1,
c.value);
241 auto it = m_surfaces.find(geoId);
242 if (
it == m_surfaces.end() or not
it->second) {
243 ACTS_FATAL(
"Could not retrieve the surface for hit " << hit);
244 return ProcessCode::ABORT;
256 if (not lpResult.ok()) {
257 ACTS_FATAL(
"Global to local transformation did not succeed.");
258 return ProcessCode::ABORT;
260 local = lpResult.value();
268 std::move(cov), local[0], local[1],
time, std::move(digitizationCells));
275 clusters.emplace_hint(clusters.end(), geoId, std::move(cluster));
276 if (std::next(inserted) != clusters.end()) {
277 ACTS_FATAL(
"Something went horribly wrong with the hit sorting");
278 return ProcessCode::ABORT;
280 auto hitIndex = clusters.index_of(inserted);
281 auto truthRange =
makeRange(std::equal_range(truths.begin(), truths.end(),
282 hit.hit_id, CompareHitId{}));
283 for (
const auto& truth : truthRange) {
284 hitParticlesMap.emplace_hint(hitParticlesMap.end(), hitIndex,
289 hitIds.push_back(hit.hit_id);
293 ctx.
eventStore.
add(m_cfg.outputClusters, std::move(clusters));
295 ctx.
eventStore.
add(m_cfg.outputHitParticlesMap, std::move(hitParticlesMap));
296 ctx.
eventStore.
add(m_cfg.outputSimulatedHits, std::move(simHits));