Skip to content

Commit a5c8b75

Browse files
mpuccioCopilot
andcommitted
ALICE3: fix initialisation with MC vertices
Co-authored-by: Copilot <copilot@github.com>
1 parent 428f7ab commit a5c8b75

2 files changed

Lines changed: 21 additions & 66 deletions

File tree

Detectors/Upgrades/ALICE3/GlobalReconstruction/reconstruction/include/ALICE3GlobalReconstruction/TimeFrameMixin.h

Lines changed: 20 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@
4141
#include <array>
4242
#include <cmath>
4343
#include <limits>
44-
#include <map>
45-
#include <memory_resource>
4644
#include <ranges>
4745
#include <vector>
4846

@@ -68,7 +66,7 @@ class TimeFrameMixin : public Base
6866

6967
void getPrimaryVerticesFromMC(TTree* mcHeaderTree, int nRofs, Long64_t nEvents, int inROFpileup);
7068

71-
void addTruthSeedingVertices(gsl::span<const o2::trk::ROFRecord> rofs);
69+
void addTruthSeedingVertices();
7270

7371
void deriveAndInitTiming(const std::array<gsl::span<const o2::trk::ROFRecord>, nLayers>& layerROFs);
7472

@@ -483,7 +481,7 @@ void TimeFrameMixin<nLayers, Base>::getPrimaryVerticesFromMC(TTree* mcHeaderTree
483481
}
484482

485483
template <int nLayers, class Base>
486-
void TimeFrameMixin<nLayers, Base>::addTruthSeedingVertices(gsl::span<const o2::trk::ROFRecord> rofs)
484+
void TimeFrameMixin<nLayers, Base>::addTruthSeedingVertices()
487485
{
488486
LOGP(info, "TRK: using truth seeds as vertices from DigitizationContext");
489487
this->mPrimaryVertices.clear();
@@ -493,44 +491,29 @@ void TimeFrameMixin<nLayers, Base>::addTruthSeedingVertices(gsl::span<const o2::
493491
const auto irs = dc->getEventRecords();
494492
o2::steer::MCKinematicsReader mcReader(dc);
495493

496-
std::vector<int64_t> rofStartBC(rofs.size());
497-
for (size_t i = 0; i < rofs.size(); ++i) {
498-
rofStartBC[i] = rofs[i].getBCData().toLong();
499-
}
500-
494+
const int64_t anchorBC = mTFAnchorIR.toLong();
501495
const auto& clockLayer = this->getROFOverlapTableView().getClockLayer();
502496
const auto rofLength = clockLayer.mROFLength;
503497

504498
using Vertex = o2::its::Vertex;
505-
struct VertInfo {
506-
std::pmr::vector<Vertex> vertices;
507-
std::pmr::vector<int> srcs;
508-
std::pmr::vector<int> events;
499+
struct VertEntry {
500+
int64_t bc;
501+
Vertex vertex;
502+
int event;
509503
};
510-
std::map<int, VertInfo> vertMap;
504+
std::vector<VertEntry> entries;
511505

512506
const int iSrc = 0;
513507
auto eveId2colId = dc->getCollisionIndicesForSource(iSrc);
514508
for (int iEve{0}; iEve < mcReader.getNEvents(iSrc); ++iEve) {
515509
const auto& ir = irs[eveId2colId[iEve]];
516510
if (!ir.isDummy()) {
517511
const auto& eve = mcReader.getMCEventHeader(iSrc, iEve);
518-
const int64_t evBC = ir.toLong();
519-
auto it = std::upper_bound(rofStartBC.begin(), rofStartBC.end(), evBC);
520-
if (it != rofStartBC.begin()) {
521-
--it;
522-
int rofId = static_cast<int>(std::distance(rofStartBC.begin(), it));
523-
auto* mr = this->mMemoryPool.get();
524-
if (!vertMap.contains(rofId)) {
525-
vertMap[rofId] = {
526-
.vertices = std::pmr::vector<Vertex>(mr),
527-
.srcs = std::pmr::vector<int>(mr),
528-
.events = std::pmr::vector<int>(mr),
529-
};
530-
}
512+
const int64_t evBC = ir.toLong() - anchorBC;
513+
if (evBC >= 0) {
531514
Vertex vert;
532515
vert.setTimeStamp(o2::its::TimeEstBC{
533-
clockLayer.getROFStartInBC(rofId),
516+
static_cast<o2::its::TimeStampType>(evBC),
534517
static_cast<o2::its::TimeStampErrorType>(rofLength)});
535518
vert.setNContributors(std::max(1L, std::ranges::count_if(
536519
mcReader.getTracks(iSrc, iEve),
@@ -541,39 +524,22 @@ void TimeFrameMixin<nLayers, Base>::addTruthSeedingVertices(gsl::span<const o2::
541524
vert.setChi2(1);
542525
constexpr float cov = 50e-9f;
543526
vert.setCov(cov, cov, cov, cov, cov, cov);
544-
vertMap[rofId].vertices.push_back(vert);
545-
vertMap[rofId].srcs.push_back(iSrc);
546-
vertMap[rofId].events.push_back(iEve);
527+
entries.push_back({evBC, vert, iEve});
547528
}
548529
}
549530
mcReader.releaseTracksForSourceAndEvent(iSrc, iEve);
550531
}
551532

552-
size_t nVerts{0};
553-
auto* mr = this->mMemoryPool.get();
554-
for (int iROF{0}; iROF < static_cast<int>(rofs.size()); ++iROF) {
555-
std::pmr::vector<Vertex> verts(mr);
556-
std::pmr::vector<std::pair<o2::MCCompLabel, float>> polls(mr);
557-
if (vertMap.contains(iROF)) {
558-
const auto& info = vertMap[iROF];
559-
verts = info.vertices;
560-
nVerts += verts.size();
561-
for (size_t i{0}; i < verts.size(); ++i) {
562-
o2::MCCompLabel lbl(o2::MCCompLabel::maxTrackID(), info.events[i], info.srcs[i], false);
563-
polls.emplace_back(lbl, 1.f);
564-
}
565-
}
566-
for (const auto& vert : verts) {
567-
this->addPrimaryVertex(vert);
568-
}
569-
for (const auto& label : polls) {
570-
this->addPrimaryVertexLabel(label);
571-
}
533+
// Sort by BC so the lookup table binary search works correctly
534+
std::ranges::sort(entries, {}, &VertEntry::bc);
535+
536+
for (const auto& e : entries) {
537+
this->addPrimaryVertex(e.vertex);
538+
o2::MCCompLabel lbl(o2::MCCompLabel::maxTrackID(), e.event, iSrc, false);
539+
this->addPrimaryVertexLabel({lbl, 1.f});
572540
}
573541
updateHostROFVertexLookupTable();
574-
LOGP(info, "TRK truth seeding: {}/{} ROFs with {} vertices -> <NV>={:.2f}",
575-
vertMap.size(), rofs.size(), nVerts,
576-
vertMap.size() > 0 ? (float)nVerts / (float)vertMap.size() : 0.f);
542+
LOGP(info, "TRK truth seeding: added {} vertices", entries.size());
577543
}
578544

579545
} // namespace o2::trk

Detectors/Upgrades/ALICE3/GlobalReconstruction/workflow/src/TrackerSpec.cxx

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -337,20 +337,9 @@ void TrackerDPL::run(ProcessingContext& pc)
337337

338338
timeFrame.deriveAndInitTiming(layerROFs);
339339

340-
std::vector<o2::trk::ROFRecord> truthSeedROFs;
341-
truthSeedROFs.reserve(nInputRofs);
342-
for (size_t iRof = 0; iRof < nInputRofs; ++iRof) {
343-
for (int iLayer = 0; iLayer < nLayers; ++iLayer) {
344-
if (iRof < layerROFs[iLayer].size()) {
345-
truthSeedROFs.push_back(layerROFs[iLayer][iRof]);
346-
break;
347-
}
348-
}
349-
}
350-
351340
const float yPlaneMLOT = 0.0010f;
352341
nRofs = timeFrame.loadROFrameData(layerROFs, layerClusters, layerPatterns, mIsMC ? &layerLabels : nullptr, yPlaneMLOT);
353-
timeFrame.addTruthSeedingVertices(truthSeedROFs);
342+
timeFrame.addTruthSeedingVertices();
354343
}
355344

356345
const auto trackingLoopStart = std::chrono::steady_clock::now();

0 commit comments

Comments
 (0)