Project
Loading...
Searching...
No Matches
TopologyDictionary.cxx
Go to the documentation of this file.
1// Copyright 2019-2026 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.
11
13
18#include <TFile.h>
19#include <fairlogger/Logger.h>
20#include <fmt/format.h>
21#include <cstring>
22#include <memory>
23#include <stdexcept>
24
25namespace o2::trkft3
26{
27
29
30template <int DetID>
32{
33 if (cluster.layer < 0) {
34 return -1;
35 }
36 if constexpr (DetID == o2::detectors::DetID::TRK) {
37 if (cluster.subDetID == 0) {
38 return cluster.layer;
39 }
40 if (cluster.subDetID == 1) {
41 return o2::trk::constants::VD::petal::nLayers + cluster.layer;
42 }
43 return -1;
44 } else {
45 return cluster.layer;
46 }
47}
48
49template <int DetID>
50math_utils::Point3D<float> TopologyDictionary<DetID>::localToFlat(const ClusterType& cluster, const math_utils::Point3D<float>& local) noexcept
51{
52 if (cluster.subDetID != 0) {
53 return local;
54 }
55 const auto flat = SegmentationChip::curvedToFlat(cluster.layer, local.X(), local.Y());
56 return {flat.X(), flat.Y(), local.Z()};
57}
58
59template <int DetID>
60math_utils::Point3D<float> TopologyDictionary<DetID>::centreOfGravity(const ClusterType& cluster, const unsigned char* pattern) noexcept
61{
62 float cogRow = 0.f, cogCol = 0.f;
63 itsmft::ClusterPattern::getCOG(pattern[0], pattern[1], pattern + 2, cogRow, cogCol);
64 float x = 0.f, z = 0.f;
65 SegmentationChip::detectorToLocalUnchecked(cluster.row, cluster.col, x, z, cluster.subDetID, cluster.layer, cluster.layer);
66 const bool vd = cluster.subDetID == 0;
69 return {x, 0.f, z};
70}
71
72template <int DetID>
73int TopologyDictionary<DetID>::findID(int layer, const unsigned char* pattern) const
74{
75 const auto& data = mLayers.at(layer);
76 const int rowSpan = pattern[0], colSpan = pattern[1];
77 // The hash leaves out a large pattern's last bytes: compare them all.
78 const auto nBytes = static_cast<std::size_t>(2 + ((rowSpan * colSpan + 7) / 8));
79 const auto [first, last] = data.hashMap.equal_range(itsmft::ClusterTopology::getCompleteHash(rowSpan, colSpan, pattern + 2));
80 for (auto it = first; it != last; ++it) {
81 const auto& entryPattern = data.entries[it->second].pattern;
82 if (entryPattern.size() == nBytes && std::memcmp(entryPattern.data(), pattern, nBytes) == 0) {
83 return it->second;
84 }
85 }
86 return static_cast<int>(data.entries.size()) - NGroups + groupOf(rowSpan, colSpan);
87}
88
89template <int DetID>
90math_utils::Point3D<float> TopologyDictionary<DetID>::getFlatCoordinates(const ClusterType& cluster, const unsigned char* pattern, int id) const
91{
92 const int layer = layerOf(cluster);
93 const auto& data = mLayers.at(layer);
94 const auto& entry = data.entries.at(id);
95 math_utils::Point3D<float> flat;
96 if (entry.isGroup) {
97 flat = centreOfGravity(cluster, pattern);
98 } else {
99 float x = 0.f, z = 0.f;
100 SegmentationChip::detectorToLocalUnchecked(cluster.row, cluster.col, x, z, cluster.subDetID, cluster.layer, cluster.layer);
101 const bool vd = cluster.subDetID == 0;
104 }
105 if (mApplyOffsets) {
106 flat.SetX(flat.X() + entry.xOffset);
107 flat.SetZ(flat.Z() + entry.zOffset);
108 }
109 flat.SetY(data.depth);
110 return flat;
111}
112
113template <int DetID>
114math_utils::Point3D<float> TopologyDictionary<DetID>::getClusterCoordinates(const ClusterType& cluster, const unsigned char* pattern, int id) const
115{
116 auto local = getFlatCoordinates(cluster, pattern, id);
117 if (cluster.subDetID == 0) {
118 const auto curved = SegmentationChip::flatToCurved(cluster.layer, local.X(), local.Y());
119 local.SetX(curved.X());
120 local.SetY(curved.Y());
121 }
122 return local;
123}
124
125template <int DetID>
127{
128 LOGP(info, "{} TopologyDictionary: {} layers, offsets {}", o2::detectors::DetID(DetID).getName(), mLayers.size(), mApplyOffsets ? "applied" : "not applied");
129 for (std::size_t layer = 0; layer < mLayers.size(); ++layer) {
130 LOGP(info, " layer {:2}: depth {:6.2f} um, {} common patterns", layer, 1e4 * mLayers[layer].depth, mLayers[layer].entries.size() - NGroups);
131 }
132}
133
134template <int DetID>
135TopologyDictionary<DetID>* TopologyDictionary<DetID>::loadFrom(const std::string& fileName, const std::string& objName)
136{
137 LOGP(info, "Loading {} TopologyDictionary from {} with name {}", o2::detectors::DetID(DetID).getName(), fileName, objName);
138 std::unique_ptr<TFile> file{TFile::Open(fileName.c_str(), "READ")};
139 if (!file || file->IsZombie()) {
140 throw std::runtime_error(fmt::format("Failed to open {}", fileName));
141 }
142 auto* dictionary = file->Get<TopologyDictionary<DetID>>(objName.c_str());
143 if (dictionary == nullptr) {
144 throw std::runtime_error(fmt::format("Failed to load {} from {}", objName, fileName));
145 }
146 return dictionary;
147}
148
151
152} // namespace o2::trkft3
Definition of the ClusterTopology class.
std::string getName(const TDataMember *dm, int index, int size)
Positions and errors of TRK and FT3 clusters per layer and pixel pattern.
std::vector< long > entries
configStandalone Light OpenGL display display_light Apply smoothing to points Enable Z buffer Highlight links Highlight seeds Highlight sector tracks Highlight final tracks Show individual Show related Highlight grid Show only individual collision Color clusters belonging to track objects Set line Enable drawing TPC data Enable drawing TOF data Enable drawing magnetic field Set field line step count Invert colors configStandalone Heavy OpenGL display display_heavy Show tracks with ITS contribution Show tracks with TOF contribution Enable propagation of loopers Show clusters at nominal x of pad row for early transformed data Split CE tracks when they cross the central Mark clusters Mark adjacent clusters Hide rejected tracks Apply filter on tracks to be displayed Separate increase X h configStandalone Camera window renderer OpenGL display display_camera Orient the camera such that the y axis is always upwards Full Screen MultiSample Anti Downsampling Anti Enable Vertical Sync Target frame or if the backend cannot limit to the refresh Use OpenGL indirect draws to reduce number of draw calls Display h configStandalone Vulkan display display_vulkan Have uniform buffers in host accessible device memory h configStandalone Internal display display_internal Number of updates the Qt GUI may send ahead of the last one the display has before it waits for the display Opacity of the console background Number of console lines the history is shortened to this when it reaches twice the size Time in seconds an info message fades out after setInfoTime h OpenGL display display Font size Do not use Freetype for font Renderer for event Frontend to use for event ROOT macros used as track filter Console script file
Definition of the SegmentationChipclass.
Static class with identifiers, bitmasks and names for ALICE detectors.
Definition DetID.h:60
static int getCOG(int rowSpan, int colSpan, const unsigned char patt[MaxPatternBytes], float &xCOG, float &zCOG)
Static: Compute pattern's COG position. Returns the number of fired pixels.
static unsigned long getCompleteHash(int nRow, int nCol, const unsigned char patt[ClusterPattern::MaxPatternBytes])
Compute the complete hash as defined for mHash.
static constexpr math_utils::Vector2D< float > flatToCurved(int layer, float xFlat, float yFlat) noexcept
static void detectorToLocalUnchecked(int row, int col, float &xRow, float &zCol, int subDetID, int layer, int disk) noexcept
static constexpr float PitchColVD
static constexpr float PitchColMLOT
static constexpr float PitchRowMLOT
static constexpr float PitchRowVD
static math_utils::Vector2D< float > curvedToFlat(const int layer, const float xCurved, const float yCurved) noexcept
static int layerOf(const ClusterType &cluster) noexcept
A cluster's layer: TRK's VD layers, then ML/OT (GeometryTGeo::getLayerTRK); FT3's discs....
static math_utils::Point3D< float > localToFlat(const ClusterType &cluster, const math_utils::Point3D< float > &local) noexcept
A point from O2's local frame to the layer's flat frame (the VD's unrolled; elsewhere the same).
int findID(int layer, const unsigned char *pattern) const
The pattern's entry on the layer: its own if it is common, else its group's.
static math_utils::Point3D< float > centreOfGravity(const ClusterType &cluster, const unsigned char *pattern) noexcept
The cluster's centre of gravity in the flat frame at y = 0. pattern: row span, column span,...
static TopologyDictionary * loadFrom(const std::string &fileName, const std::string &objName="ccdb_object")
math_utils::Point3D< float > getClusterCoordinates(const ClusterType &cluster, const unsigned char *pattern, int id) const
The same in O2's local frame: curved on the VD.
math_utils::Point3D< float > getFlatCoordinates(const ClusterType &cluster, const unsigned char *pattern, int id) const
The position in the flat frame: the entry's centre of gravity, plus its offsets if applied,...
GLint GLenum GLint x
Definition glcorearb.h:403
GLint first
Definition glcorearb.h:399
GLint GLint GLsizei GLsizei GLsizei depth
Definition glcorearb.h:470
GLenum GLuint GLint GLint layer
Definition glcorearb.h:1310
GLdouble GLdouble GLdouble z
Definition glcorearb.h:843
constexpr int nLayers
Definition Specs.h:47
std::array< uint16_t, 5 > pattern