32 #include <dfe/dfe_io_dsv.hpp>
44 throw std::invalid_argument(
"Missing measurement output collection");
56 auto checkRange = [&](
const std::string& fileStem) {
60 throw std::runtime_error(
"event range mismatch for 'event**-" + fileStem +
65 checkRange(
"measurement-simhit-map.csv");
67 checkRange(
"cells.csv");
73 return "CsvMeasurementReader";
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;
99 struct CompareGeometryId {
106 template <
typename Data>
107 inline std::vector<Data> readEverything(
109 const std::vector<std::string>& optionalColumns,
size_t event) {
111 dfe::NamedTupleCsvReader<Data>
reader(path, optionalColumns);
113 std::vector<Data> everything;
115 while (
reader.read(one)) {
116 everything.push_back(one);
122 std::vector<ActsExamples::MeasurementData> readMeasurementsByGeometryId(
125 auto measurements = readEverything<ActsExamples::MeasurementData>(
128 std::sort(measurements.begin(), measurements.end(), CompareGeometryId{});
133 const std::unordered_multimap<std::size_t, ActsExamples::CellData>&
135 std::size_t nMeasurements) {
136 using namespace ActsExamples;
147 const auto& cellData =
it->second;
149 Acts::Vector2::Zero()};
152 static_cast<unsigned int>(cellData.channel0),
153 static_cast<unsigned int>(cellData.channel1)};
155 cluster.
channels.emplace_back(bin, dummySegment, cellData.value);
162 auto compareX = [](
const auto&
a,
const auto&
b) {
163 return a.bin[0] <
b.bin[0];
165 auto compareY = [](
const auto&
a,
const auto&
b) {
166 return a.bin[1] <
b.bin[1];
169 auto [minX, maxX] = std::minmax_element(cluster.
channels.begin(),
171 auto [minY, maxY] = std::minmax_element(cluster.
channels.begin(),
173 cluster.
sizeLoc0 = 1 + maxX->bin[0] - minX->bin[0];
174 cluster.
sizeLoc1 = 1 + maxY->bin[1] - minY->bin[1];
193 auto measurementData =
201 std::list<IndexSourceLink> sourceLinkStorage;
202 orderedMeasurements.reserve(measurementData.size());
204 measurementSimHitsMap.reserve(measurementData.size());
205 sourceLinks.reserve(measurementData.size());
207 auto measurementSimHitLinkData =
208 readEverything<ActsExamples::MeasurementSimHitLink>(
210 for (
auto mshLink : measurementSimHitLinkData) {
211 measurementSimHitsMap.emplace_hint(measurementSimHitsMap.end(),
212 mshLink.measurement_id, mshLink.hit_id);
220 for (
unsigned int ipar = 0;
222 if (((
m.local_key) & (1 << (ipar + 1))) != 0) {
223 dParameters.
indices.push_back(static_cast<Acts::BoundIndices>(ipar));
226 dParameters.
values.push_back(
m.local0);
227 dParameters.
variances.push_back(
m.var_local0);
230 dParameters.
values.push_back(
m.local1);
231 dParameters.
variances.push_back(
m.var_local1);
234 dParameters.
values.push_back(
m.phi);
238 dParameters.
values.push_back(
m.theta);
242 dParameters.
values.push_back(
m.time);
253 const Index index = orderedMeasurements.size();
254 IndexSourceLink& sourceLink = sourceLinkStorage.emplace_back(geoId, index);
261 auto inserted = orderedMeasurements.emplace_hint(
262 orderedMeasurements.end(), geoId,
std::move(measurement));
263 if (
std::next(inserted) != orderedMeasurements.end()) {
264 ACTS_FATAL(
"Something went horribly wrong with the hit sorting");
265 return ProcessCode::ABORT;
268 sourceLinks.insert(sourceLinks.end(), std::cref(sourceLink));
272 for (
auto& [
_, meas] : orderedMeasurements) {
273 measurements.emplace_back(
std::move(meas));
277 if (m_inputHits.isInitialized() &&
278 m_outputMeasurementParticlesMap.isInitialized()) {
279 const auto hits = m_inputHits(ctx);
283 for (
const auto& [measIdx, hitIdx] : measurementSimHitsMap) {
284 const auto& hit = hits.nth(hitIdx);
285 outputMap.emplace(measIdx, hit->particleId());
288 m_outputMeasurementParticlesMap(ctx,
std::move(outputMap));
292 m_outputMeasurements(ctx,
std::move(measurements));
293 m_outputMeasurementSimHitsMap(ctx,
std::move(measurementSimHitsMap));
294 m_outputSourceLinks(ctx,
std::move(sourceLinks));
300 if (
m_cfg.outputClusters.empty()) {
304 std::vector<ActsExamples::CellData> cellData;
309 cellData = readEverything<ActsExamples::CellData>(
311 }
catch (std::runtime_error&
e) {
313 if (
std::string(e.what()).find(
"Missing header column 'measurement_id'") ==
318 const auto oldCellData = readEverything<ActsExamples::CellDataLegacy>(
323 old.channel1, old.timestamp, old.value};
326 cellData.resize(oldCellData.size());
327 std::transform(oldCellData.begin(), oldCellData.end(), cellData.begin(),
331 std::unordered_multimap<std::size_t, ActsExamples::CellData> cellDataMap;
332 for (
const auto&
cd : cellData) {
333 cellDataMap.emplace(
cd.measurement_id,
cd);
336 auto clusters = makeClusters(cellDataMap, orderedMeasurements.size());