Project
Loading...
Searching...
No Matches
TrackerACTS.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.
11
18
19#ifndef ALICE3_GLOBALRECONSTRUCTION_INCLUDE_TRACKERACTS_H_
20#define ALICE3_GLOBALRECONSTRUCTION_INCLUDE_TRACKERACTS_H_
21
22#include <Acts/Definitions/Units.hpp>
23#include <chrono>
24#include <cmath>
25#include <fstream>
26#include <iomanip>
27#include <memory>
28#include <string>
29#include <string_view>
30#include <Framework/Logger.h>
31#include <nlohmann/json.hpp>
32#include <array>
33#include <vector>
34#include <unordered_set>
37#include <TH2F.h>
38
39class TFile;
40class TTree;
41namespace Acts
42{
43class Surface;
44class BoundTrackParameters;
45} // namespace Acts
46namespace o2::trk
47{
48
53
55 {
56 std::ifstream input(configName);
57 if (!input) {
58 return;
59 }
60 LOG(info) << "Loading ACTS tracker configuration from " << configName;
61 nlohmann::json config;
62 try {
63 input >> config;
64 } catch (const nlohmann::json::parse_error& e) {
65 LOG(error) << "Failed to parse ACTS tracker configuration file " << configName << ": " << e.what();
66 return;
67 }
68 if (!config.is_object()) {
69 LOG(error) << "ACTS tracker configuration file " << configName << " must contain a JSON object";
70 return;
71 }
72
73 const auto load = [&config](const char* key, auto& value) {
74 if (!config.contains(key)) {
75 return;
76 }
77 try {
78 config.at(key).get_to(value);
79 } catch (const nlohmann::json::exception& e) {
80 LOG(error) << "Failed to load ACTS tracker configuration parameter " << key << ": " << e.what();
81 }
82 };
83
84 load("minPt", minPt);
85 load("maxImpactParameter", maxImpactParameter);
86 load("cotThetaMax", cotThetaMax);
87 load("deltaRMinBottom", deltaRMinBottom);
88 load("deltaRMaxBottom", deltaRMaxBottom);
89 load("deltaRMinTop", deltaRMinTop);
90 load("deltaRMaxTop", deltaRMaxTop);
91 load("zMin", zMin);
92 load("zMax", zMax);
93 load("collisionRegionMin", collisionRegionMin);
94 load("collisionRegionMax", collisionRegionMax);
95 load("maxSeedsPerMiddleSP", maxSeedsPerMiddleSP);
96 load("deltaPhiMax", deltaPhiMax);
97 load("writeDebugTrees", writeDebugTrees);
98 load("dumpTrackingGeometry", dumpTrackingGeometry);
99 load("debugMaxTimeFrames", debugMaxTimeFrames);
100 load("debugFileName", debugFileName);
101 load("geometryDumpFileName", geometryDumpFileName);
102 }
103
105 {
106 const nlohmann::json config = {
107 {"minPt", minPt},
108 {"maxImpactParameter", maxImpactParameter},
109 {"cotThetaMax", cotThetaMax},
110 {"deltaRMinBottom", deltaRMinBottom},
111 {"deltaRMaxBottom", deltaRMaxBottom},
112 {"deltaRMinTop", deltaRMinTop},
113 {"deltaRMaxTop", deltaRMaxTop},
114 {"zMin", zMin},
115 {"zMax", zMax},
116 {"collisionRegionMin", collisionRegionMin},
117 {"collisionRegionMax", collisionRegionMax},
118 {"maxSeedsPerMiddleSP", maxSeedsPerMiddleSP},
119 {"deltaPhiMax", deltaPhiMax},
120 {"writeDebugTrees", writeDebugTrees},
121 {"dumpTrackingGeometry", dumpTrackingGeometry},
122 {"debugMaxTimeFrames", debugMaxTimeFrames},
123 {"debugFileName", debugFileName},
124 {"geometryDumpFileName", geometryDumpFileName},
125 };
126 std::ofstream output(configName);
127 if (!output) {
128 LOG(error) << "Failed to open ACTS tracker configuration file " << configName;
129 return;
130 }
131
132 output << config.dump(2) << '\n';
133 if (!output) {
134 LOG(error) << "Failed to write ACTS tracker configuration file " << configName;
135 }
136 LOG(info) << "Saved ACTS tracker configuration to " << configName;
137 }
138
140 float minPt = 0.4f * Acts::UnitConstants::GeV;
142 float maxImpactParameter = 10.f * Acts::UnitConstants::mm;
144 float cotThetaMax = std::sinh(4.0f);
145
147 float deltaRMinBottom = 5.f * Acts::UnitConstants::mm;
148 float deltaRMaxBottom = 200.f * Acts::UnitConstants::mm;
150 float deltaRMinTop = 5.f * Acts::UnitConstants::mm;
151 float deltaRMaxTop = 200.f * Acts::UnitConstants::mm;
152
154 float zMin = -3000.f * Acts::UnitConstants::mm;
155 float zMax = 3000.f * Acts::UnitConstants::mm;
156
158 float collisionRegionMin = -150.f * Acts::UnitConstants::mm;
159 float collisionRegionMax = 150.f * Acts::UnitConstants::mm;
160
164 float deltaPhiMax = 0.1f;
165
167 bool writeDebugTrees = false;
173 std::string debugFileName = "TrackerACTS_debug.root";
175 std::string geometryDumpFileName = "TrackerACTS_geometry.json";
176
177 static constexpr const char* configName = "TrackerACTSConfig.json";
178};
179
183 float x{0.f};
184 float y{0.f};
185 float z{0.f};
187 int layer{-1};
188 int clusterId{-1};
190 int rof{-1};
191 int sensorId{-1};
193 const Acts::Surface* surface{nullptr};
194
196 float r() const { return std::hypot(x, y); }
198 float radius() const { return r(); }
200 float phi() const { return std::atan2(y, x); }
201
203 float varianceR{0.01f};
204 float varianceZ{0.01f};
205};
206
208struct SeedACTS {
209 const SpacePoint* bottom{nullptr};
210 const SpacePoint* middle{nullptr};
211 const SpacePoint* top{nullptr};
213 float quality{0.f};
214};
215
221template <int nLayers>
223{
224 public:
225 TrackerACTS();
226 ~TrackerACTS();
227
233 void adoptSensorIDs(const std::array<std::vector<int>, nLayers>& sensorIDs)
234 {
235 mSensorIDs = &sensorIDs;
236 }
237
239 void clustersToTracks();
240
242 void setConfig(const TrackerACTSConfig& cfg) { mConfig = cfg; }
244 TrackerACTSConfig& getConfig() { return mConfig; }
246 const TrackerACTSConfig& getConfig() const { return mConfig; }
247
249 void printSummary() const;
250
251 private:
252 // Debug resources are allocated only if requested and closed at destruction.
253 std::unique_ptr<TFile> mDebugFile;
254 TTree* mClusterTree = nullptr; // Owned by mDebugFile
255 TTree* mSeedTree = nullptr; // Owned by mDebugFile
256 TTree* mROFTree = nullptr; // Owned by mDebugFile
257 std::unique_ptr<TH2F> mHistSpacePoints;
258 bool mGeometryDumped = false;
259
260 struct DebugClusterRecord {
261 int tf = 0, rof = 0, layer = 0, clusterId = -1;
262 int externalId = -1, sensorId = -1, mappingStatus = 0;
263 unsigned long long geometryId = 0;
264 float x = 0.f, y = 0.f, z = 0.f;
265 float r = 0.f, phi = 0.f;
266 float varianceR = 0.f, varianceZ = 0.f;
267 } mDebugCluster;
268
269 struct DebugSeedRecord {
270 int tf = 0, rof = 0, seedId = 0;
271 float quality = 0.f;
272 int layer[3] = {}, clusterId[3] = {}, sensorId[3] = {};
273 unsigned long long geometryId[3] = {};
274 float x[3] = {}, y[3] = {}, z[3] = {}, r[3] = {}, phi[3] = {};
275 } mDebugSeed;
276
277 struct DebugROFRecord {
278 int tf = 0, rof = 0, nSpacePoints = 0, nSeeds = 0;
279 int nAcceptedTracks = 0;
280 } mDebugROF;
281
282 void initDebugOutput();
283 void dumpGeometryOnce();
284 bool isDebugTimeFrame() const;
285 void fillDebugSeeds(int rof);
286
288 void buildSpacePoints(int rof);
289
291 void createSeeds();
292
294 void findTracks();
295
297 bool acceptTrack(const Acts::BoundTrackParameters& inner,
298 const Acts::BoundTrackParameters& outer,
299 const SeedACTS& seed, float chi2);
301 void computeTracksMClabels();
302
304 template <typename Func>
305 float evaluateTask(Func&& task, std::string_view taskName);
306
307 // Configuration
308 TrackerACTSConfig mConfig;
309
310 // TimeFrame data
311 o2::its::TimeFrame<nLayers>* mTimeFrame = nullptr;
312
313 // Space points built from clusters
314 std::vector<SpacePoint> mSpacePoints;
315 std::vector<std::vector<const SpacePoint*>> mSpacePointsPerLayer;
316
317 // Seeds
318 std::vector<SeedACTS> mSeeds;
319 // Avoid accepting seeds which reuse a cluster already assigned to a track.
320 std::unordered_set<uint64_t> mAcceptedClusters;
321 // Layer-local indices in mUnsortedClusters, in the same order as getTracks().
322 // Keep them separate from the external indices stored in TrackITSExt.
323 std::vector<std::array<int, nLayers>> mAcceptedTrackClusterIndices;
324
325 // Tracking state
326 unsigned int mTimeFrameCounter{0};
327 double mTotalTime{0.};
328 const std::array<std::vector<int>, nLayers>* mSensorIDs = nullptr;
329 // Tracking states for logging
330 enum State {
331 SpacePointBuilding = 0,
332 Seeding,
333 TrackFinding,
334 NStates,
335 };
336 State mCurState{SpacePointBuilding};
337 static constexpr std::array<const char*, NStates> StateNames{
338 "Space point building",
339 "ACTS seeding",
340 "Track finding"};
341};
342
343template <int nLayers>
344template <typename Func>
345float TrackerACTS<nLayers>::evaluateTask(Func&& task, std::string_view taskName)
346{
347 LOG(debug) << " + Starting " << taskName;
348 const auto start = std::chrono::high_resolution_clock::now();
349 task();
350 const auto end = std::chrono::high_resolution_clock::now();
351 std::chrono::duration<double, std::milli> diff{end - start};
352
353 LOG(debug) << " - " << taskName << " completed in: " << std::fixed << std::setprecision(2) << diff.count() << " ms";
354 return static_cast<float>(diff.count());
355}
356
357} // namespace o2::trk
358
359#endif /* ALICE3_GLOBALRECONSTRUCTION_INCLUDE_TRACKERACTS_H_ */
std::ostringstream debug
Timeframe settings Average distance in cm of events merged into Randomize distance around average distance of merged events Simulate correct bunch interactions instead of placing only the average number of events A value[n] sets TFlen for[n] collisions in Number of bunches per trainsort Number of bunch trains Instantaneous interaction rate Do not simulate border Total number of collisions to be placed in the interior of all time Do not select random but walk over array of events in stride steps h Event generator settings h configStandalone Use CPU for GPU Force usage of the specified GPU device no CPU fallback Continue processing after an error First event to Number of events to Number of iterations to Number of iterations to Number of initial iterations excluded from const char e
char error[CURL_ERROR_SIZE]
float chi2
void output(const std::map< std::string, ChannelStat > &channels)
Definition rawdump.cxx:197
Definition of the ITS track.
StringRef key
void adoptSensorIDs(const std::array< std::vector< int >, nLayers > &sensorIDs)
void setConfig(const TrackerACTSConfig &cfg)
Replace the current tracker configuration.
void clustersToTracks()
Build space points, find tracks, and publish accepted tracks in the TimeFrame.
void adoptTimeFrame(o2::its::TimeFrame< nLayers > &tf)
void printSummary() const
Print the accumulated tracking timing and processing summary.
TrackerACTSConfig & getConfig()
Access the tracker configuration for modification.
const TrackerACTSConfig & getConfig() const
Read-only access to the tracker configuration.
GLint GLenum GLint x
Definition glcorearb.h:403
GLuint GLuint end
Definition glcorearb.h:469
GLdouble GLdouble GLdouble GLdouble top
Definition glcorearb.h:4077
GLint y
Definition glcorearb.h:270
GLsizei const GLfloat * value
Definition glcorearb.h:819
GLint GLint bottom
Definition glcorearb.h:1979
GLenum GLuint GLint GLint layer
Definition glcorearb.h:1310
GLdouble GLdouble GLdouble z
Definition glcorearb.h:843
const bool const int nLayers
std::unique_ptr< GPUReconstructionTimeframe > tf
Three-space-point seed ordered from the innermost to outermost measurement.
float quality
ACTS seed quality value.
const SpacePoint * middle
Cluster-derived space point passed to the ACTS seeding algorithms.
const Acts::Surface * surface
Geometry surface associated with this measurement; not owned by the space point.
float radius() const
Radius accessor required by the ACTS cylindrical-grid element concept.
float r() const
Transverse radius in mm.
float phi() const
Azimuthal angle in radians.
int rof
Readout-frame and sensor indices identifying the source measurement.
float varianceR
Estimated radial and longitudinal position variances, in mm^2.
float deltaRMinBottom
Minimum and maximum radial separation for bottom-to-middle space-point pairs.
float minPt
Minimum transverse momentum accepted by the seeding algorithms.
float deltaPhiMax
Reserved maximum azimuthal angle difference for doublets (radians); currently unused.
float collisionRegionMin
Longitudinal range of the collision region used when constructing seeds.
float deltaRMinTop
Minimum and maximum radial separation for middle-to-top space-point pairs.
int debugMaxTimeFrames
Number of time frames with debug output; 0 disables it and -1 means all.
float maxImpactParameter
Maximum transverse distance of closest approach used in seeding.
float zMin
Longitudinal range used to select space points for seeding.
static constexpr const char * configName
std::string debugFileName
Destination ROOT file for diagnostic output.
float deltaRMaxTop
Max deltaR for middle-top.
bool writeDebugTrees
Enable diagnostic ROOT trees and histograms; disabled by default.
float maxSeedsPerMiddleSP
Maximum number of seeds retained for each middle space point.
float cotThetaMax
Maximum absolute cot(theta); the default corresponds approximately to |eta| = 4.
bool dumpTrackingGeometry
Write a JSON snapshot of the tracking geometry on the first use.
std::string geometryDumpFileName
Destination JSON file for the tracking-geometry snapshot.
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"