34 throw std::invalid_argument(
"Missing cluster output collection");
37 throw std::invalid_argument(
"Missing hit id output collection");
40 throw std::invalid_argument(
"Missing hit-particles map output collection");
43 throw std::invalid_argument(
"Missing simulated hits output collection");
46 throw std::invalid_argument(
"Missing tracking geometry");
55 return "CsvPlanarClusterReader";
65 using is_transparent =
void;
67 constexpr
bool operator()(
const T&
left,
const T&
right)
const {
68 return left.hit_id < right.hit_id;
71 constexpr
bool operator()(uint64_t left_id,
const T&
right)
const {
72 return left_id < right.hit_id;
75 constexpr
bool operator()(
const T&
left, uint64_t right_id)
const {
76 return left.hit_id < right_id;
94 struct CompareGeometryId {
96 auto leftId = extractGeometryId(left).
value();
97 auto rightId = extractGeometryId(right).value();
98 return leftId < rightId;
102 template <
typename Data>
103 inline std::vector<Data> readEverything(
104 const std::string& inputDir,
const std::string&
filename,
105 const std::vector<std::string>& optionalColumns,
size_t event) {
109 std::vector<Data> everything;
111 while (reader.read(one)) {
112 everything.push_back(one);
118 std::vector<FW::HitData> readHitsByGeoId(
const std::string& inputDir,
121 auto hits = readEverything<FW::HitData>(inputDir,
"hits.csv",
122 {
"geometry_id",
"t"}, event);
124 std::sort(
hits.begin(),
hits.end(), CompareGeometryId{});
128 std::vector<FW::CellData> readCellsByHitId(
const std::string& inputDir,
132 readEverything<FW::CellData>(inputDir,
"cells.csv", {
"timestamp"}, event);
134 std::sort(cells.begin(), cells.end(), CompareHitId{});
138 std::vector<FW::TruthHitData> readTruthHitsByHitId(
const std::string& inputDir,
141 std::vector<std::string> optionalColumns = {
142 "geometry_id",
"tt",
"te",
"deltapx",
143 "deltapy",
"deltapz",
"deltae",
"index",
145 auto truths = readEverything<FW::TruthHitData>(inputDir,
"truth.csv",
146 optionalColumns, event);
148 std::sort(truths.begin(), truths.end(), CompareHitId{});
162 auto cells = readCellsByHitId(m_cfg.inputDir, ctx.
eventNumber);
163 auto truths = readTruthHitsByHitId(m_cfg.inputDir, ctx.
eventNumber);
167 std::vector<uint64_t> hitIds;
170 clusters.reserve(
hits.size());
171 hitIds.reserve(
hits.size());
172 hitParticlesMap.reserve(truths.size());
173 simHits.reserve(truths.size());
179 std::vector<std::size_t> simHitIndices;
181 auto range =
makeRange(std::equal_range(truths.begin(), truths.end(),
182 hit.hit_id, CompareHitId{}));
183 simHitIndices.reserve(range.size());
184 for (
const auto& truth : range) {
188 const auto simIndex = truth.index;
213 auto inserted = simHits.emplace_hint(simHits.end(), simGeometryId,
214 simParticleId, simPos4, simMom4,
215 simMom4 + simDelta4, simIndex);
216 if (std::next(inserted) != simHits.end()) {
217 ACTS_FATAL(
"Truth hit sorting broke for input hit id " << hit.hit_id);
218 return ProcessCode::ABORT;
220 simHitIndices.push_back(simHits.index_of(inserted));
225 std::vector<Acts::DigitizationCell> digitizationCells;
227 auto range =
makeRange(std::equal_range(cells.begin(), cells.end(),
228 hit.hit_id, CompareHitId{}));
229 for (
const auto&
c : range) {
230 digitizationCells.emplace_back(
c.ch0,
c.ch1,
c.value);
235 auto it = m_surfaces.find(geoId);
236 if (
it == m_surfaces.end() or not
it->second) {
237 ACTS_FATAL(
"Could not retrieve the surface for hit " << hit);
238 return ProcessCode::ABORT;
256 std::move(cov), local[0], local[1],
time, std::move(digitizationCells));
263 clusters.emplace_hint(clusters.end(), geoId, std::move(cluster));
264 if (std::next(inserted) != clusters.end()) {
265 ACTS_FATAL(
"Something went horribly wrong with the hit sorting");
266 return ProcessCode::ABORT;
268 auto hitIndex = clusters.index_of(inserted);
269 auto truthRange =
makeRange(std::equal_range(truths.begin(), truths.end(),
270 hit.hit_id, CompareHitId{}));
271 for (
const auto& truth : truthRange) {
272 hitParticlesMap.emplace_hint(hitParticlesMap.end(), hitIndex,
277 hitIds.push_back(hit.hit_id);
281 ctx.
eventStore.
add(m_cfg.outputClusters, std::move(clusters));
283 ctx.
eventStore.
add(m_cfg.outputHitParticlesMap, std::move(hitParticlesMap));
284 ctx.
eventStore.
add(m_cfg.outputSimulatedHits, std::move(simHits));