Project
Loading...
Searching...
No Matches
TimeFrameMixin.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_ALICE3GLOBALRECONSTRUCTION_TIMEFRAMEMIXIN_H
17#define ALICEO2_ALICE3GLOBALRECONSTRUCTION_TIMEFRAMEMIXIN_H
18
33#include "Framework/Logger.h"
34
35#include <Rtypes.h>
36#include <TTree.h>
37#include <TRandom3.h>
38#include <gsl/span>
39
40#include <algorithm>
41#include <array>
42#include <cmath>
43#include <limits>
44#include <ranges>
45#include <vector>
46
47#include <nlohmann/json.hpp>
48
49namespace o2::trk
50{
51
52template <int nLayers, class Base>
53class TimeFrameMixin : public Base
54{
55 public:
56 TimeFrameMixin() = default;
57 ~TimeFrameMixin() override = default;
58
59 int loadROFsFromHitTree(TTree* hitsTree, GeometryTGeo* gman, const nlohmann::json& config);
60
61 int loadROFrameData(const std::array<gsl::span<const o2::trkft3::ROFRecord>, nLayers>& layerROFs,
62 const std::array<gsl::span<const o2::trkft3::TRKCluster>, nLayers>& layerClusters,
63 const std::array<gsl::span<const unsigned char>, nLayers>& layerPatterns,
64 const std::array<const dataformats::MCTruthContainer<MCCompLabel>*, nLayers>* mcLabels = nullptr,
65 float yPlaneMLOT = 0.f);
66
67 void getPrimaryVerticesFromMC(TTree* mcHeaderTree, int nRofs, Long64_t nEvents, int inROFpileup);
68
70
71 void deriveAndInitTiming(const std::array<gsl::span<const o2::trkft3::ROFRecord>, nLayers>& layerROFs);
72
73 const o2::InteractionRecord& getTFAnchorIR() const noexcept { return mTFAnchorIR; }
74 const auto& getClusterSensorIDs() const noexcept { return mClusterSensorIDs; }
75
76 protected:
77 void initTimingTables(const std::array<o2::its::LayerTiming, nLayers>& timings);
79 std::array<std::vector<int>, nLayers> mClusterSensorIDs;
82};
83
84template <int nLayers, class Base>
86{
87 static_cast<o2::its::TimeFrame<nLayers>*>(this)->updateROFVertexLookupTable();
88}
89
90template <int nLayers, class Base>
91void TimeFrameMixin<nLayers, Base>::initTimingTables(const std::array<o2::its::LayerTiming, nLayers>& timings)
92{
93 if (mTimingTablesInitialised) {
94 return;
95 }
96 typename o2::its::TimeFrame<nLayers>::ROFOverlapTableN rofOverlapTable;
97 typename o2::its::TimeFrame<nLayers>::ROFVertexLookupTableN rofVertexLookupTable;
99 for (int iLayer{0}; iLayer < nLayers; ++iLayer) {
100 rofOverlapTable.defineLayer(iLayer, timings[iLayer]);
101 rofVertexLookupTable.defineLayer(iLayer, timings[iLayer]);
102 rofMaskTable.defineLayer(iLayer, timings[iLayer]);
103 }
104 rofOverlapTable.init();
105 rofVertexLookupTable.init();
106 rofMaskTable.init();
107 rofMaskTable.resetMask(1u);
108 this->setROFOverlapTable(std::move(rofOverlapTable));
109 this->setROFVertexLookupTable(std::move(rofVertexLookupTable));
110 this->setMultiplicityCutMask(std::move(rofMaskTable));
111 this->useMultiplictyMask();
112 mTimingTablesInitialised = true;
113
114 const auto maskView = this->getROFMaskView();
115 for (int iLayer{0}; iLayer < nLayers; ++iLayer) {
116 LOGP(info, "TRK timing initialised: layer {}: {}", iLayer, timings[iLayer].asString());
117 LOGP(info, "TRK ROF mask: {}", maskView.asString(iLayer));
118 }
119}
120
121template <int nLayers, class Base>
122void TimeFrameMixin<nLayers, Base>::deriveAndInitTiming(const std::array<gsl::span<const o2::trkft3::ROFRecord>, nLayers>& layerROFs)
123{
124 if (mTimingTablesInitialised) {
125 return;
126 }
127
128 o2::InteractionRecord anchor{0, 0};
129 bool haveAnchor = false;
130 for (const auto& span : layerROFs) {
131 if (span.empty()) {
132 continue;
133 }
134 const auto& first = span.front().getBCData();
135 if (!haveAnchor || first.toLong() < anchor.toLong()) {
136 anchor = first;
137 haveAnchor = true;
138 }
139 }
140 mTFAnchorIR = anchor;
141 const int64_t anchorBC = anchor.toLong();
142
143 std::array<o2::its::LayerTiming, nLayers> timings{};
144 for (int iLayer{0}; iLayer < nLayers; ++iLayer) {
145 const auto& span = layerROFs[iLayer];
146 auto& t = timings[iLayer];
147 t.mNROFsTF = static_cast<o2::its::LayerTiming::BCType>(span.size());
148
149 if (span.size() >= 2) {
150 const int64_t delta = span[1].getBCData().toLong() - span[0].getBCData().toLong();
151 if (delta > 0) {
152 t.mROFLength = static_cast<o2::its::LayerTiming::BCType>(delta);
153 } else {
154 LOGP(warning, "TRK layer {}: non-positive BC delta between rofs[0] and rofs[1] ({}); falling back to mROFLength=1", iLayer, delta);
155 t.mROFLength = 1;
156 }
157 } else {
158 if (span.size() == 1) {
159 LOGP(warning, "TRK layer {}: only one input ROF — cannot derive mROFLength; falling back to mROFLength=1", iLayer);
160 }
161 t.mROFLength = 1;
162 }
163
164 if (!span.empty()) {
165 const int64_t bias = span.front().getBCData().toLong() - anchorBC;
166 t.mROFBias = static_cast<o2::its::LayerTiming::BCType>(bias);
167 }
168 t.mROFDelay = 0;
169 t.mROFAddTimeErr = 0;
170 }
171
172 initTimingTables(timings);
173}
174
175template <int nLayers, class Base>
176int TimeFrameMixin<nLayers, Base>::loadROFsFromHitTree(TTree* hitsTree, GeometryTGeo* gman, const nlohmann::json& config)
177{
178 constexpr std::array<int, 2> startLayer{0, 3};
179 const Long64_t nEvents = hitsTree->GetEntries();
180 this->setIsStaggered(true);
181
182 gman->fillMatrixCache(o2::math_utils::bit2Mask(o2::math_utils::TransformType::T2L) | o2::math_utils::bit2Mask(o2::math_utils::TransformType::L2G));
183
184 std::vector<o2::trkft3::Hit>* trkHit = nullptr;
185 hitsTree->SetBranchAddress("TRKHit", &trkHit);
186
187 const int inROFpileup{config.contains("inROFpileup") ? config["inROFpileup"].get<int>() : 1};
188
189 const int nRofs = (nEvents + inROFpileup - 1) / inROFpileup;
190 std::array<o2::its::LayerTiming, nLayers> timings{};
191 for (int iLayer{0}; iLayer < nLayers; ++iLayer) {
192 timings[iLayer].mNROFsTF = static_cast<o2::its::LayerTiming::BCType>(nRofs);
193 timings[iLayer].mROFLength = 1;
194 }
195 this->initTimingTables(timings);
196 const auto& timing = this->getROFOverlapTableView().getLayer(0);
197 if (timing.mNROFsTF != static_cast<o2::its::LayerTiming::BCType>(nRofs)) {
198 LOGP(fatal, "TRK: inconsistent number of ROFs across TFs: timing has {}, hit-tree path produced {}", timing.mNROFsTF, nRofs);
199 }
200
201 for (int iLayer{0}; iLayer < nLayers; ++iLayer) {
202 this->mMinR[iLayer] = std::numeric_limits<float>::max();
203 this->mMaxR[iLayer] = std::numeric_limits<float>::lowest();
204 this->mROFramesClusters[iLayer].clear();
205 this->mROFramesClusters[iLayer].resize(nRofs + 1, 0);
206 this->mUnsortedClusters[iLayer].clear();
207 this->mTrackingFrameInfo[iLayer].clear();
208 this->mClusterExternalIndices[iLayer].clear();
209 mClusterSensorIDs[iLayer].clear();
210 this->mClusterSize[iLayer].clear();
211 }
212
213 std::array<int, nLayers> clusterCountPerLayer{};
214 for (Long64_t iEvent = 0; iEvent < nEvents; ++iEvent) {
215 hitsTree->GetEntry(iEvent);
216 for (const auto& hit : *trkHit) {
217 if (gman->getDisk(hit.GetDetectorID()) != -1) {
218 continue;
219 }
220 int subDetID = gman->getSubDetID(hit.GetDetectorID());
221 const int layer = startLayer[subDetID] + gman->getLayer(hit.GetDetectorID());
222 if (layer >= nLayers) {
223 continue;
224 }
225 ++clusterCountPerLayer[layer];
226 }
227 }
228
229 for (int iLayer{0}; iLayer < nLayers; ++iLayer) {
230 this->mUnsortedClusters[iLayer].reserve(clusterCountPerLayer[iLayer]);
231 this->mTrackingFrameInfo[iLayer].reserve(clusterCountPerLayer[iLayer]);
232 this->mClusterExternalIndices[iLayer].reserve(clusterCountPerLayer[iLayer]);
233 mClusterSensorIDs[iLayer].reserve(clusterCountPerLayer[iLayer]);
234 this->mClusterSize[iLayer].reserve(clusterCountPerLayer[iLayer]);
235 }
236
237 std::array<float, 11> resolution{0.001, 0.001, 0.001, 0.001, 0.004, 0.004, 0.004, 0.004, 0.004, 0.004, 0.004};
238 if (config["geometry"]["pitch"].size() == nLayers) {
239 for (int iLayer{0}; iLayer < config["geometry"]["pitch"].size(); ++iLayer) {
240 LOGP(info, "Setting resolution for layer {} from config", iLayer);
241 LOGP(info, "Layer {} pitch {} cm", iLayer, config["geometry"]["pitch"][iLayer].get<float>());
242 resolution[iLayer] = config["geometry"]["pitch"][iLayer].get<float>() / std::sqrt(12.f);
243 }
244 }
245 LOGP(info, "Number of active parts in VD: {}", gman->getNumberOfActivePartsVD());
246
247 std::array<int, nLayers> hitCounterPerLayer{};
248 std::array<dataformats::MCTruthContainer<MCCompLabel>*, nLayers> labels{};
249 for (int iLayer{0}; iLayer < nLayers; ++iLayer) {
251 this->mClusterLabels[iLayer] = labels[iLayer];
252 }
253
254 int iRof{0};
255 for (Long64_t iEvent = 0; iEvent < nEvents; ++iEvent) {
256 hitsTree->GetEntry(iEvent);
257
258 for (auto& hit : *trkHit) {
259 if (gman->getDisk(hit.GetDetectorID()) != -1) {
260 continue;
261 }
262 int subDetID = gman->getSubDetID(hit.GetDetectorID());
263 const int layer = startLayer[subDetID] + gman->getLayer(hit.GetDetectorID());
264
265 float alpha{0.f};
268 float r{0.f};
269 if (layer >= nLayers) {
270 continue;
271 }
272 if (layer >= 3) {
273 int chipID = hit.GetDetectorID();
274 alpha = gman->getSensorRefAlphaMLOT(chipID);
275 const o2::math_utils::Transform3D& l2g = gman->getMatrixL2G(chipID);
276 auto locXYZ = l2g ^ (hit.GetPos());
277 locXYZ.SetX(locXYZ.X() + gRandom->Gaus(0.0, resolution[layer]));
278 locXYZ.SetZ(locXYZ.Z() + gRandom->Gaus(0.0, resolution[layer]));
279 gloXYZ = gman->getMatrixL2G(chipID) * locXYZ;
280 trkXYZ = gman->getMatrixT2L(chipID - gman->getNumberOfActivePartsVD()) ^ locXYZ;
281 r = std::hypot(gloXYZ.X(), gloXYZ.Y());
282 } else {
283 const auto& hitPos = hit.GetPos();
284 r = std::hypot(hitPos.X(), hitPos.Y());
285 alpha = std::atan2(hitPos.Y(), hitPos.X()) + gRandom->Gaus(0.0, resolution[layer] / r);
286 o2::math_utils::bringTo02Pi(alpha);
287 gloXYZ.SetX(r * std::cos(alpha));
288 gloXYZ.SetY(r * std::sin(alpha));
289 gloXYZ.SetZ(hitPos.Z() + gRandom->Gaus(0.0, resolution[layer]));
290 trkXYZ.SetX(r);
291 trkXYZ.SetY(0.f);
292 trkXYZ.SetZ(gloXYZ.Z());
293 }
294 this->mMinR[layer] = std::min(this->mMinR[layer], r);
295 this->mMaxR[layer] = std::max(this->mMaxR[layer], r);
296 this->addTrackingFrameInfoToLayer(layer, gloXYZ.x(), gloXYZ.y(), gloXYZ.z(), trkXYZ.x(), alpha,
297 std::array<float, 2>{trkXYZ.y(), trkXYZ.z()},
298 std::array<float, 3>{resolution[layer] * resolution[layer], 0., resolution[layer] * resolution[layer]});
299 this->addClusterToLayer(layer, gloXYZ.x(), gloXYZ.y(), gloXYZ.z(), this->mUnsortedClusters[layer].size());
300 mClusterSensorIDs[layer].push_back(hit.GetDetectorID());
301 const int layerHitCounter = hitCounterPerLayer[layer]++;
302 this->addClusterExternalIndexToLayer(layer, layerHitCounter);
303 this->mClusterSize[layer].push_back(1);
304 MCCompLabel label{hit.GetTrackID(), static_cast<int>(iEvent), 0};
305 labels[layer]->addElement(layerHitCounter, label);
306 }
307 trkHit->clear();
308
309 if ((iEvent + 1) % inROFpileup == 0 || iEvent == nEvents - 1) {
310 iRof++;
311 for (unsigned int iLayer{0}; iLayer < this->mUnsortedClusters.size(); ++iLayer) {
312 this->mROFramesClusters[iLayer][iRof] = this->mUnsortedClusters[iLayer].size();
313 }
314 }
315 }
316 return nRofs;
317}
318
319template <int nLayers, class Base>
320int TimeFrameMixin<nLayers, Base>::loadROFrameData(const std::array<gsl::span<const o2::trkft3::ROFRecord>, nLayers>& layerROFs,
321 const std::array<gsl::span<const o2::trkft3::TRKCluster>, nLayers>& layerClusters,
322 const std::array<gsl::span<const unsigned char>, nLayers>& layerPatterns,
323 const std::array<const dataformats::MCTruthContainer<MCCompLabel>*, nLayers>* mcLabels,
324 float yPlaneMLOT)
325{
326 constexpr std::array<int, 2> startLayer{0, 3};
327 this->setIsStaggered(true);
329 geom->fillMatrixCache(o2::math_utils::bit2Mask(o2::math_utils::TransformType::T2L) | o2::math_utils::bit2Mask(o2::math_utils::TransformType::L2G));
330
331 if (!mTimingTablesInitialised) {
332 LOGP(fatal, "TRK::loadROFrameData: timing tables not initialised — call deriveAndInitTiming() first");
333 }
334 int nRofs{0};
335 for (const auto& rofs : layerROFs) {
336 nRofs = std::max(nRofs, static_cast<int>(rofs.size()));
337 }
338
339 for (int iLayer{0}; iLayer < nLayers; ++iLayer) {
340 const auto& timing = this->getROFOverlapTableView().getLayer(iLayer);
341 if (timing.mNROFsTF != static_cast<o2::its::LayerTiming::BCType>(layerROFs[iLayer].size())) {
342 LOGP(fatal, "TRK: inconsistent number of ROFs on layer {}: timing has {}, cluster path received {}", iLayer, timing.mNROFsTF, layerROFs[iLayer].size());
343 }
344 this->mMinR[iLayer] = std::numeric_limits<float>::max();
345 this->mMaxR[iLayer] = std::numeric_limits<float>::lowest();
346 this->mROFramesClusters[iLayer].clear();
347 this->mROFramesClusters[iLayer].resize(layerROFs[iLayer].size() + 1, 0);
348 this->mUnsortedClusters[iLayer].clear();
349 this->mTrackingFrameInfo[iLayer].clear();
350 this->mClusterExternalIndices[iLayer].clear();
351 mClusterSensorIDs[iLayer].clear();
352 this->mClusterSize[iLayer].clear();
353 this->mUnsortedClusters[iLayer].reserve(layerClusters[iLayer].size());
354 this->mTrackingFrameInfo[iLayer].reserve(layerClusters[iLayer].size());
355 this->mClusterExternalIndices[iLayer].reserve(layerClusters[iLayer].size());
356 mClusterSensorIDs[iLayer].reserve(layerClusters[iLayer].size());
357 this->mClusterSize[iLayer].reserve(layerClusters[iLayer].size());
358 }
359
360 std::array<std::vector<size_t>, nLayers> patternOffsetsPerLayer;
361 for (int iLayer{0}; iLayer < nLayers; ++iLayer) {
362 auto& offsets = patternOffsetsPerLayer[iLayer];
363 offsets.resize(layerClusters[iLayer].size(), std::numeric_limits<size_t>::max());
364 size_t pattPos = 0;
365 bool validPatterns = true;
366 for (size_t clusterId{0}; clusterId < layerClusters[iLayer].size(); ++clusterId) {
367 if (pattPos + 2 > layerPatterns[iLayer].size()) {
368 validPatterns = false;
369 break;
370 }
371 offsets[clusterId] = pattPos;
372 const uint8_t rowSpan = layerPatterns[iLayer][pattPos];
373 const uint8_t colSpan = layerPatterns[iLayer][pattPos + 1];
374 const size_t nBytes = (size_t(rowSpan) * colSpan + 7) / 8;
375 if (pattPos + 2 + nBytes > layerPatterns[iLayer].size()) {
376 validPatterns = false;
377 break;
378 }
379 pattPos += 2 + nBytes;
380 }
381 if (!validPatterns || pattPos != layerPatterns[iLayer].size()) {
382 LOGP(fatal, "Malformed TRK pattern stream for layer {}: {} bytes for {} clusters",
383 iLayer, layerPatterns[iLayer].size(), layerClusters[iLayer].size());
384 }
385 }
386
387 for (int iLayer{0}; iLayer < nLayers; ++iLayer) {
388 for (size_t iRof{0}; iRof < layerROFs[iLayer].size(); ++iRof) {
389 const auto& rof = layerROFs[iLayer][iRof];
390 const int first = rof.getFirstEntry();
391 const int last = first + rof.getNEntries();
392
393 for (int clusterId{first}; clusterId < last; ++clusterId) {
394 if (clusterId < 0 || clusterId >= static_cast<int>(layerClusters[iLayer].size())) {
395 LOGP(warning, "Skipping out-of-range TRK cluster {} on layer {}", clusterId, iLayer);
396 continue;
397 }
398
399 const auto& c = layerClusters[iLayer][clusterId];
400 if (c.subDetID < 0 || c.subDetID > 1) {
401 continue;
402 }
403
404 const int clusterLayer = startLayer[c.subDetID] + c.layer;
405 if (clusterLayer != iLayer) {
406 LOGP(error, "Skipping cluster from layer {} found in TRK layer stream {}", clusterLayer, iLayer);
407 continue;
408 }
409
410 const auto pattOffset = patternOffsetsPerLayer[iLayer][clusterId];
411 const uint8_t* pattForCluster = layerPatterns[iLayer].data() + pattOffset;
412 auto locXYZ = TRKClusterer::getClusterLocalCoordinates(c, pattForCluster, yPlaneMLOT);
413
414 const auto gloXYZ = geom->getMatrixL2G(c.chipID) * locXYZ;
415
416 float alpha{0.f};
418 if (c.subDetID == 1) {
419 alpha = geom->getSensorRefAlphaMLOT(c.chipID);
420 trkXYZ = geom->getMatrixT2L(c.chipID - geom->getNumberOfActivePartsVD()) ^ locXYZ;
421 } else {
422 const float r = std::hypot(gloXYZ.X(), gloXYZ.Y());
423 alpha = std::atan2(gloXYZ.Y(), gloXYZ.X());
424 o2::math_utils::bringTo02Pi(alpha);
425 trkXYZ.SetX(r);
426 trkXYZ.SetY(0.f);
427 trkXYZ.SetZ(gloXYZ.Z());
428 }
429
430 const float r = std::hypot(gloXYZ.X(), gloXYZ.Y());
431 this->mMinR[iLayer] = std::min(this->mMinR[iLayer], r);
432 this->mMaxR[iLayer] = std::max(this->mMaxR[iLayer], r);
433
434 const float sigmaY2 = (c.subDetID == 0)
437 const float sigmaZ2 = (c.subDetID == 0)
440
441 this->addTrackingFrameInfoToLayer(iLayer, gloXYZ.x(), gloXYZ.y(), gloXYZ.z(), trkXYZ.x(), alpha,
442 std::array<float, 2>{trkXYZ.y(), trkXYZ.z()},
443 std::array<float, 3>{sigmaY2, 0.f, sigmaZ2});
444 this->addClusterToLayer(iLayer, gloXYZ.x(), gloXYZ.y(), gloXYZ.z(), this->mUnsortedClusters[iLayer].size());
445 mClusterSensorIDs[iLayer].push_back(c.chipID);
446 this->addClusterExternalIndexToLayer(iLayer, clusterId);
447 this->mClusterSize[iLayer].push_back(std::clamp(static_cast<unsigned int>(c.size), 0u, 255u));
448 }
449
450 this->mROFramesClusters[iLayer][iRof + 1] = this->mUnsortedClusters[iLayer].size();
451 }
452 }
453
454 for (auto i = 0; i < this->mNTrackletsPerCluster.size(); ++i) {
455 this->mNTrackletsPerCluster[i].resize(this->mUnsortedClusters[1].size());
456 this->mNTrackletsPerClusterSum[i].resize(this->mUnsortedClusters[1].size() + 1);
457 }
458
459 if (mcLabels != nullptr) {
460 for (int iLayer{0}; iLayer < nLayers; ++iLayer) {
461 this->mClusterLabels[iLayer] = (*mcLabels)[iLayer];
462 }
463 }
464
465 return nRofs;
466}
467
468template <int nLayers, class Base>
469void TimeFrameMixin<nLayers, Base>::getPrimaryVerticesFromMC(TTree* mcHeaderTree, int nRofs, Long64_t nEvents, int inROFpileup)
470{
471 auto mcheader = new o2::dataformats::MCEventHeader;
472 mcHeaderTree->SetBranchAddress("MCEventHeader.", &mcheader);
473
474 this->mPrimaryVertices.clear();
475 this->mPrimaryVerticesLabels.clear();
476
477 const auto& clockLayer = this->getROFOverlapTableView().getClockLayer();
478 const auto rofLength = clockLayer.mROFLength;
479
480 int iRof{0};
481 for (Long64_t iEvent = 0; iEvent < nEvents; ++iEvent) {
482 mcHeaderTree->GetEntry(iEvent);
484 vertex.setTimeStamp(o2::its::TimeEstBC{
485 clockLayer.getROFStartInBC(iRof),
486 static_cast<o2::its::TimeStampErrorType>(rofLength)});
487 vertex.setXYZ(mcheader->GetX(), mcheader->GetY(), mcheader->GetZ());
488 vertex.setNContributors(30);
489 vertex.setChi2(0.f);
490 LOGP(debug, "ROF {}: Added primary vertex at ({}, {}, {})", iRof, mcheader->GetX(), mcheader->GetY(), mcheader->GetZ());
491 this->addPrimaryVertex(vertex);
492 this->addPrimaryVertexLabel({o2::MCCompLabel{o2::MCCompLabel::maxTrackID(), static_cast<int>(iEvent), 0, false}, 1.f});
493 if ((iEvent + 1) % inROFpileup == 0 || iEvent == nEvents - 1) {
494 iRof++;
495 }
496 }
497 updateHostROFVertexLookupTable();
498}
499
500template <int nLayers, class Base>
502{
503 LOGP(info, "TRK: using truth seeds as vertices from DigitizationContext");
504 this->mPrimaryVertices.clear();
505 this->mPrimaryVerticesLabels.clear();
506
507 const auto dc = o2::steer::DigitizationContext::loadFromFile("collisioncontext.root");
508 const auto irs = dc->getEventRecords();
510
511 const int64_t anchorBC = mTFAnchorIR.toLong();
512 const auto& clockLayer = this->getROFOverlapTableView().getClockLayer();
513 const auto rofLength = clockLayer.mROFLength;
514
515 using Vertex = o2::its::Vertex;
516 struct VertEntry {
517 int64_t bc;
519 int event;
520 };
521 std::vector<VertEntry> entries;
522
523 const int iSrc = 0;
524 auto eveId2colId = dc->getCollisionIndicesForSource(iSrc);
525 for (int iEve{0}; iEve < mcReader.getNEvents(iSrc); ++iEve) {
526 const auto& ir = irs[eveId2colId[iEve]];
527 if (!ir.isDummy()) {
528 const auto& eve = mcReader.getMCEventHeader(iSrc, iEve);
529 const int64_t evBC = ir.toLong() - anchorBC;
530 if (evBC >= 0) {
531 Vertex vert;
532 vert.setTimeStamp(o2::its::TimeEstBC{
533 static_cast<o2::its::TimeStampType>(evBC),
534 static_cast<o2::its::TimeStampErrorType>(rofLength)});
535 vert.setNContributors(std::max(1L, std::ranges::count_if(
536 mcReader.getTracks(iSrc, iEve),
537 [](const auto& trk) {
538 return trk.isPrimary() && trk.GetPt() > 0.05 && std::abs(trk.GetEta()) < 1.1;
539 })));
540 vert.setXYZ((float)eve.GetX(), (float)eve.GetY(), (float)eve.GetZ());
541 vert.setChi2(1);
542 constexpr float cov = 50e-9f;
543 vert.setCov(cov, cov, cov, cov, cov, cov);
544 entries.push_back({evBC, vert, iEve});
545 }
546 }
547 mcReader.releaseTracksForSourceAndEvent(iSrc, iEve);
548 }
549
550 // Sort by BC so the lookup table binary search works correctly
551 std::ranges::sort(entries, {}, &VertEntry::bc);
552
553 for (const auto& e : entries) {
554 this->addPrimaryVertex(e.vertex);
555 o2::MCCompLabel lbl(o2::MCCompLabel::maxTrackID(), e.event, iSrc, false);
556 this->addPrimaryVertexLabel({lbl, 1.f});
557 }
558 updateHostROFVertexLookupTable();
559 LOGP(info, "TRK truth seeding: added {} vertices", entries.size());
560}
561
562} // namespace o2::trk
563
564#endif // ALICEO2_ALICE3GLOBALRECONSTRUCTION_TIMEFRAMEMIXIN_H
std::string asString(TDataMember const &dm, char *pointer)
std::ostringstream debug
uint64_t vertex
Definition RawEventData.h:9
uint64_t bc
Definition RawEventData.h:5
std::vector< long > entries
int32_t i
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
configStandalone Reconstruction rec_tpc float
char error[CURL_ERROR_SIZE]
std::vector< o2::MCCompLabel > labels
Definition of a container to keep Monte Carlo truth external to simulation objects.
uint32_t c
Definition RawData.h:2
Definition of the SegmentationChipclass.
Definition of the TRK cluster finder.
static constexpr int maxTrackID()
A container to hold and manage MC truth information/labels.
const Mat3D & getMatrixT2L(int sensID) const
const Mat3D & getMatrixL2G(int sensID) const
static DigitizationContext * loadFromFile(std::string_view filename="")
size_t getNEvents(int source) const
Get number of events.
o2::dataformats::MCEventHeader const & getMCEventHeader(int source, int event) const
retrieves the MCEventHeader for a given eventID and sourceID
void releaseTracksForSourceAndEvent(int source, int event)
API to ask releasing tracks and track references (freeing memory) for source + event.
std::vector< MCTrack > const & getTracks(int source, int event) const
variant returning all tracks for source and event at once
static o2::math_utils::Point3D< float > getClusterLocalCoordinates(const ClusterType &cluster, const uint8_t *patt, float yPlaneMLOT=0.f) noexcept
Definition Clusterer.cxx:28
int getSubDetID(int index) const
float getSensorRefAlphaMLOT(int chipId) const
int getLayer(int index) const
local layer index within the sub-detector (0-based per VD/MLOT)
void fillMatrixCache(int mask)
int getNumberOfActivePartsVD() const
int getDisk(int index) const
static GeometryTGeo * Instance()
static constexpr float PitchColVD
static constexpr float PitchColMLOT
static constexpr float PitchRowMLOT
static constexpr float PitchRowVD
int loadROFsFromHitTree(TTree *hitsTree, GeometryTGeo *gman, const nlohmann::json &config)
const o2::InteractionRecord & getTFAnchorIR() const noexcept
void initTimingTables(const std::array< o2::its::LayerTiming, nLayers > &timings)
int loadROFrameData(const std::array< gsl::span< const o2::trkft3::ROFRecord >, nLayers > &layerROFs, const std::array< gsl::span< const o2::trkft3::TRKCluster >, nLayers > &layerClusters, const std::array< gsl::span< const unsigned char >, nLayers > &layerPatterns, const std::array< const dataformats::MCTruthContainer< MCCompLabel > *, nLayers > *mcLabels=nullptr, float yPlaneMLOT=0.f)
std::array< std::vector< int >, nLayers > mClusterSensorIDs
void getPrimaryVerticesFromMC(TTree *mcHeaderTree, int nRofs, Long64_t nEvents, int inROFpileup)
~TimeFrameMixin() override=default
const auto & getClusterSensorIDs() const noexcept
void deriveAndInitTiming(const std::array< gsl::span< const o2::trkft3::ROFRecord >, nLayers > &layerROFs)
o2::InteractionRecord mTFAnchorIR
struct _cl_event * event
Definition glcorearb.h:2982
GLfloat GLfloat GLfloat alpha
Definition glcorearb.h:279
GLsizeiptr size
Definition glcorearb.h:659
GLuint GLsizei const GLuint const GLintptr * offsets
Definition glcorearb.h:2595
GLint first
Definition glcorearb.h:399
GLuint GLsizei const GLchar * label
Definition glcorearb.h:2519
GLenum GLuint GLint GLint layer
Definition glcorearb.h:1310
o2::dataformats::Vertex< o2::its::TimeEstBC > Vertex
Definition Vertex.h:26
ROFVertexLookupTable< NLayers > ROFVertexLookupTableN
Definition TimeFrame.h:75
ROFOverlapTable< NLayers > ROFOverlapTableN
Definition TimeFrame.h:74
ROFMaskTable< NLayers > ROFMaskTableN
Definition TimeFrame.h:76
const int nEvents
Definition test_Fifo.cxx:27
o2::InteractionRecord ir(0, 0)