Project
Loading...
Searching...
No Matches
IOUtils.h
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
15
16#ifndef ALICEO2_ITSMFT_TRACKING_IOUTILS_H_
17#define ALICEO2_ITSMFT_TRACKING_IOUTILS_H_
18
19#include <cstddef>
20#include <cstdint>
21
22#ifndef GPUCA_GPUCODE
23#include <format>
24#include <stdexcept>
25#include <string>
26#endif
27
28#include <gsl/gsl>
29
40#include "MathUtils/Cartesian.h"
42
44{
45
46// Host-side facts produced by compact-cluster and geometry decoding.
49 // ITS geometry supplies its cylindrical tracking frame here. Disk
50 // projection uses global coordinates directly.
52 // Intrinsic ALPIDE local row/column covariance, without alignment systematics.
53 // The shared loader adds configured systematics before detector projection.
55 uint32_t nPixels{0};
56 int layer{-1};
57};
58
59} // namespace o2::itsmft::tracking
60
62{
63
68
69template <typename T>
76
77// Decode using dictionary coordinates, errors and pixel counts. Grouped and
78// explicit patterns require their actual bitmap; the group entry is representative.
79// As in ITS tracking, the explicit-pattern stream is assumed to be valid.
80template <typename T = float>
82 const CompClusterExt& c,
83 gsl::span<const unsigned char>::iterator& patterns,
84 const TopologyDictionary* dict)
85{
87 if (dict == nullptr) {
88 throw std::runtime_error("Cluster dictionary is not available");
89 }
90
91 const auto pattID = c.getPatternID();
92 if (pattID != CompCluster::InvalidPatternID) {
93 if (pattID >= dict->getSize()) {
94 throw std::runtime_error("Cluster pattern ID is outside the topology dictionary");
95 }
96 result.sig2Row = dict->getErr2X(pattID);
97 result.sig2Col = dict->getErr2Z(pattID);
98 if (!dict->isGroup(pattID)) {
99 result.nPixels = static_cast<uint32_t>(dict->getNpixels(pattID));
100 result.coordinates = dict->getClusterCoordinates<T>(c);
101 return result;
102 }
103 }
104
105 const o2::itsmft::ClusterPattern pattern{patterns};
106 result.nPixels = static_cast<uint32_t>(pattern.getNPixels());
107 result.coordinates = TopologyDictionary::getClusterCoordinates<T>(c, pattern, pattID != CompCluster::InvalidPatternID);
108 return result;
109}
110
111} // namespace o2::itsmft::ioutils
112
113namespace o2::itsmft::tracking
114{
115
116class TimeFrame;
117
120 o2::detectors::DetID::ID detector{o2::detectors::DetID::ITS};
121 gsl::span<const o2::itsmft::CompClusterExt> clusters{};
122 gsl::span<const unsigned char> patterns{};
123 gsl::span<const o2::itsmft::ROFRecord> rofs{};
126 gsl::span<const LayerId> layerToSurface{};
127};
128
134void loadTimeFrameSources(TimeFrame&, gsl::span<const ClusterSourceInput>,
135 SurfaceCatalogView,
136 std::vector<std::vector<uint32_t>>* externalIndicesBySurface = nullptr,
137 std::vector<std::vector<uint32_t>>* clusterSizesBySurface = nullptr);
138
139namespace detail
140{
141void prepareSources(TimeFrame&, const SurfaceCatalogView&, gsl::span<const ClusterSourceInput>,
142 std::vector<std::vector<uint32_t>>*, std::vector<std::vector<uint32_t>>*, bool requireCompleteMapping = false);
143void validateClusterRanges(const ClusterSourceInput&);
144void appendCluster(TimeFrame&, const SurfaceCatalogView&, const ClusterSourceInput&, const DecodedCluster&,
145 uint32_t, uint32_t, std::vector<std::vector<uint32_t>>&, std::vector<std::vector<uint32_t>>&);
146void storeSourceROFClusters(TimeFrame&, const ClusterSourceInput&, const std::vector<std::vector<int>>&);
147
148// Internal loading loop; geometry decoding and synthetic fixtures share the
149// same stream consumption, diagnostics and measurement insertion.
150template <typename Decode>
152 const Decode& decode, std::vector<std::vector<uint32_t>>& externalIndices,
153 std::vector<std::vector<uint32_t>>& clusterSizes)
154{
155 std::vector<std::vector<int>> boundaries(src.layerToSurface.size(), std::vector<int>(src.rofs.size() + 1, 0));
156 auto patterns = src.patterns.begin();
157 for (uint32_t r = 0; r < src.rofs.size(); ++r) {
158 const auto& rof = src.rofs[r];
159 const auto firstEntry = rof.getFirstEntry();
160 const auto nEntries = rof.getNEntries();
161 for (int32_t clusterId = firstEntry; clusterId < firstEntry + nEntries; ++clusterId) {
162 const auto& cluster = src.clusters[clusterId];
163 const auto externalIndex = static_cast<uint32_t>(clusterId);
164 DecodedCluster decoded;
165 try {
166 decoded = decode(cluster, patterns);
167 } catch (const std::runtime_error& error) {
168 throw std::runtime_error(std::format("Cluster decoding failed: source={} rof={} clusterIndex={}: {}",
169 src.id.value(), r, externalIndex, error.what()));
170 }
171 appendCluster(frame, catalog, src, decoded, r, externalIndex, externalIndices, clusterSizes);
172 }
173 for (size_t layer = 0; layer < src.layerToSurface.size(); ++layer) {
174 boundaries[layer][r + 1] = static_cast<int>(externalIndices[src.layerToSurface[layer].value()].size());
175 }
176 }
177 if (patterns != src.patterns.end()) {
178 throw std::runtime_error(std::format("Trailing cluster pattern data source={} rof={} clusterIndex={}", src.id.value(), static_cast<uint32_t>(src.rofs.size()), static_cast<uint32_t>(src.clusters.size())));
179 }
180 storeSourceROFClusters(frame, src, boundaries);
181}
182} // namespace detail
183
184} // namespace o2::itsmft::tracking
185
186#endif /* ALICEO2_ITSMFT_TRACKING_IOUTILS_H_ */
Definition of the ITSMFT compact cluster.
Definition of the ClusterTopology class.
Shared CA tracking configuration for ITS and MFT.
Definition of the ITSMFT ROFrame (trigger) record.
Definition of a container to keep Monte Carlo truth external to simulation objects.
uint32_t c
Definition RawData.h:2
Definition of the SegmentationAlpide class.
A container to hold and manage MC truth information/labels.
int ID
Detector identifiers: continuous, starting from 0.
Definition DetID.h:63
static constexpr unsigned short InvalidPatternID
Definition CompCluster.h:46
static constexpr float PitchCol
static constexpr float PitchRow
math_utils::Point3D< T > getClusterCoordinates(const CompCluster &cl) const
int getSize() const
Returns the number of elements in the dicionary;.
float getErr2X(int n) const
Returns the error^2 on the x position of the COG for the n_th element.
int getNpixels(int n) const
Returns the number of fired pixels of the n_th element.
bool isGroup(int n) const
Returns true if the element corresponds to a group of rare topologies.
float getErr2Z(int n) const
Returns the error^2 on the z position of the COG for the n_th element.
GLenum src
Definition glcorearb.h:1767
GLuint64EXT * result
Definition glcorearb.h:5662
GLenum GLuint GLint GLint layer
Definition glcorearb.h:1310
GLboolean r
Definition glcorearb.h:1233
constexpr float DefClusErrorRow
Definition IOUtils.h:64
constexpr float DefClusErrorCol
Definition IOUtils.h:65
constexpr float DefClusError2Col
Definition IOUtils.h:67
ClusterData< T > extractClusterData(const CompClusterExt &c, gsl::span< const unsigned char >::iterator &patterns, const TopologyDictionary *dict)
Definition IOUtils.h:81
constexpr float DefClusError2Row
Definition IOUtils.h:66
void loadDecodedSource(TimeFrame &frame, const SurfaceCatalogView &catalog, const ClusterSourceInput &src, const Decode &decode, std::vector< std::vector< uint32_t > > &externalIndices, std::vector< std::vector< uint32_t > > &clusterSizes)
Definition IOUtils.h:151
void validateClusterRanges(const ClusterSourceInput &)
Definition IOUtils.cxx:266
void storeSourceROFClusters(TimeFrame &, const ClusterSourceInput &, const std::vector< std::vector< int > > &)
Definition IOUtils.cxx:328
void appendCluster(TimeFrame &, const SurfaceCatalogView &, const ClusterSourceInput &, const DecodedCluster &, uint32_t, uint32_t, std::vector< std::vector< uint32_t > > &, std::vector< std::vector< uint32_t > > &)
Definition IOUtils.cxx:285
void prepareSources(TimeFrame &, const SurfaceCatalogView &, gsl::span< const ClusterSourceInput >, std::vector< std::vector< uint32_t > > *, std::vector< std::vector< uint32_t > > *, bool requireCompleteMapping=false)
Definition IOUtils.cxx:203
void loadTimeFrameSources(TimeFrame &, gsl::span< const ClusterSourceInput >, SurfaceCatalogView, std::vector< std::vector< uint32_t > > *externalIndicesBySurface=nullptr, std::vector< std::vector< uint32_t > > *clusterSizesBySurface=nullptr)
Definition IOUtils.cxx:337
o2::math_utils::Point3D< T > coordinates
Definition IOUtils.h:71
const o2::itsmft::TopologyDictionary * dictionary
Definition IOUtils.h:124
const o2::dataformats::MCTruthContainer< o2::MCCompLabel > * labels
Definition IOUtils.h:125
gsl::span< const o2::itsmft::CompClusterExt > clusters
Definition IOUtils.h:121
gsl::span< const unsigned char > patterns
Definition IOUtils.h:122
o2::detectors::DetID::ID detector
Definition IOUtils.h:120
gsl::span< const o2::itsmft::ROFRecord > rofs
Definition IOUtils.h:123
gsl::span< const LayerId > layerToSurface
Definition IOUtils.h:126
SurfaceCovariance2F rowColumnCovariance
Definition IOUtils.h:54
SurfaceFramePoint cylinderFrame
Definition IOUtils.h:51
coder decode(ctfImage, triggersD, clustersD)
std::array< uint16_t, 5 > pattern