Skip to content

Commit 41281c5

Browse files
committed
ITS: add truth seeding
Signed-off-by: Felix Schlepper <felix.schlepper@cern.ch>
1 parent ac2b567 commit 41281c5

9 files changed

Lines changed: 82 additions & 14 deletions

File tree

Detectors/ITSMFT/ITS/tracking/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ o2_add_library(ITStracking
3636
O2::ITSReconstruction
3737
O2::ITSMFTReconstruction
3838
O2::DataFormatsITS
39-
PRIVATE_LINK_LIBRARIES TBB::tbb)
39+
PRIVATE_LINK_LIBRARIES
40+
O2::Steer
41+
TBB::tbb)
4042

4143
o2_add_library(ITSTrackingInterface
4244
TARGETVARNAME targetName

Detectors/ITSMFT/ITS/tracking/include/ITStracking/Configuration.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ struct VertexingParameters {
112112
int zSpan = -1;
113113
bool SaveTimeBenchmarks = false;
114114

115+
bool useTruthSeeding{false}; // overwrite found vertices with MC events
116+
115117
int nThreads = 1;
116118
bool PrintMemory = false; // print allocator usage in epilog report
117119
size_t MaxMemory = std::numeric_limits<size_t>::max();

Detectors/ITSMFT/ITS/tracking/include/ITStracking/TrackingConfigParam.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ struct VertexerParamConfig : public o2::conf::ConfigurableParamHelper<VertexerPa
4848
int ZBins = 1; // z-phi index table configutation: number of z bins
4949
int PhiBins = 128; // z-phi index table configutation: number of phi bins
5050

51+
bool useTruthSeeding{false}; // overwrite seeding vertices with MC truth
52+
5153
int nThreads = 1;
5254
bool printMemory = false;
5355
size_t maxMemory = std::numeric_limits<size_t>::max();

Detectors/ITSMFT/ITS/tracking/include/ITStracking/Vertexer.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ class Vertexer
7575
void validateTracklets(T&&... args);
7676
template <typename... T>
7777
void findVertices(T&&... args);
78-
void findHistVertices();
78+
79+
void addTruthSeeds() { mTraits->addTruthSeedingVertices(); }
7980

8081
template <typename... T>
8182
void initialiseVertexer(T&&... args);
@@ -108,10 +109,11 @@ class Vertexer
108109
Trackleting,
109110
Validating,
110111
Finding,
112+
TruthSeeding,
111113
NStates,
112114
};
113115
State mCurState{Init};
114-
static constexpr std::array<const char*, NStates> StateNames{"Initialisation", "Tracklet finding", "Tracklet validation", "Vertex finding"};
116+
static constexpr std::array<const char*, NStates> StateNames{"Initialisation", "Tracklet finding", "Tracklet validation", "Vertex finding", "Truth seeding"};
115117
};
116118

117119
template <typename... T>

Detectors/ITSMFT/ITS/tracking/include/ITStracking/VertexerTraits.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ class VertexerTraits
7373
virtual void computeVertices(const int iteration = 0);
7474
virtual void adoptTimeFrame(TimeFrame7* tf) noexcept { mTimeFrame = tf; }
7575
virtual void updateVertexingParameters(const std::vector<VertexingParameters>& vrtPar, const TimeFrameGPUParameters& gpuTfPar);
76+
// truth tracking
77+
void addTruthSeedingVertices();
7678

7779
void computeVerticesInRof(int,
7880
gsl::span<const o2::its::Line>&,

Detectors/ITSMFT/ITS/tracking/src/Configuration.cxx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,8 @@ std::vector<VertexingParameters> TrackingMode::getVertexingParameters(TrackingMo
273273
p.nThreads = vc.nThreads;
274274
p.ZBins = vc.ZBins;
275275
p.PhiBins = vc.PhiBins;
276+
277+
p.useTruthSeeding = vc.useTruthSeeding;
276278
}
277279
// set for now outside to not disturb status quo
278280
vertParams[0].vertNsigmaCut = vc.vertNsigmaCut;

Detectors/ITSMFT/ITS/tracking/src/TrackingInterface.cxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,13 +181,13 @@ void ITSTrackingInterface::run(framework::ProcessingContext& pc)
181181
vtxROF.setNEntries(vtxSpan.size());
182182
bool selROF = vtxSpan.empty();
183183
for (auto iV{0}; iV < vtxSpan.size(); ++iV) {
184-
auto& v = vtxSpan[iV];
184+
const auto& v = vtxSpan[iV];
185185
if (multEstConf.isVtxMultCutRequested() && !multEstConf.isPassingVtxMultCut(v.getNContributors())) {
186186
continue; // skip vertex of unwanted multiplicity
187187
}
188188
selROF = true;
189189
vertices.push_back(v);
190-
if (mIsMC) {
190+
if (mIsMC && !VertexerParamConfig::Instance().useTruthSeeding) {
191191
allVerticesLabels.push_back(vMCRecInfo[iV].first);
192192
allVerticesPurities.push_back(vMCRecInfo[iV].second);
193193
}

Detectors/ITSMFT/ITS/tracking/src/Vertexer.cxx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ Vertexer::Vertexer(VertexerTraits* traits) : mTraits(traits)
3636
float Vertexer::clustersToVertices(LogFunc logger)
3737
{
3838
LogFunc evalLog = [](const std::string&) {};
39+
40+
if (mTimeFrame->hasMCinformation() && mVertParams[0].useTruthSeeding) {
41+
return evaluateTask(&Vertexer::addTruthSeeds, StateNames[mCurState = TruthSeeding], 0, evalLog);
42+
}
43+
3944
TrackingParameters trkPars;
4045
TimeFrameGPUParameters tfGPUpar;
4146
mTraits->updateVertexingParameters(mVertParams, tfGPUpar);
@@ -58,14 +63,11 @@ float Vertexer::clustersToVertices(LogFunc logger)
5863
logger(fmt::format("=== ITS {} Seeding vertexer iteration {} summary:", mTraits->getName(), iteration));
5964
trkPars.PhiBins = mTraits->getVertexingParameters()[0].PhiBins;
6065
trkPars.ZBins = mTraits->getVertexingParameters()[0].ZBins;
61-
auto timeInitIteration = evaluateTask(
62-
&Vertexer::initialiseVertexer, StateNames[mCurState = Init], iteration, evalLog, trkPars, iteration);
63-
auto timeTrackletIteration = evaluateTask(
64-
&Vertexer::findTracklets, StateNames[mCurState = Trackleting], iteration, evalLog, iteration);
66+
auto timeInitIteration = evaluateTask(&Vertexer::initialiseVertexer, StateNames[mCurState = Init], iteration, evalLog, trkPars, iteration);
67+
auto timeTrackletIteration = evaluateTask(&Vertexer::findTracklets, StateNames[mCurState = Trackleting], iteration, evalLog, iteration);
6568
nTracklets01 = mTimeFrame->getTotalTrackletsTF(0);
6669
nTracklets12 = mTimeFrame->getTotalTrackletsTF(1);
67-
auto timeSelectionIteration = evaluateTask(
68-
&Vertexer::validateTracklets, StateNames[mCurState = Validating], iteration, evalLog, iteration);
70+
auto timeSelectionIteration = evaluateTask(&Vertexer::validateTracklets, StateNames[mCurState = Validating], iteration, evalLog, iteration);
6971
auto timeVertexingIteration = evaluateTask(&Vertexer::findVertices, StateNames[mCurState = Finding], iteration, evalLog, iteration);
7072
printEpilog(logger, nTracklets01, nTracklets12, mTimeFrame->getNLinesTotal(), mTimeFrame->getTotVertIteration()[iteration], timeInitIteration, timeTrackletIteration, timeSelectionIteration, timeVertexingIteration);
7173
timeInit += timeInitIteration;

Detectors/ITSMFT/ITS/tracking/src/VertexerTraits.cxx

Lines changed: 57 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010
// or submit itself to any jurisdiction.
1111
///
1212

13-
#include <iostream>
1413
#include <memory>
15-
#include <string>
16-
#include <chrono>
14+
#include <ranges>
15+
#include <map>
16+
#include <algorithm>
1717

1818
#include <oneapi/tbb/blocked_range.h>
1919
#include <oneapi/tbb/parallel_for.h>
@@ -22,6 +22,9 @@
2222
#include "ITStracking/BoundedAllocator.h"
2323
#include "ITStracking/ClusterLines.h"
2424
#include "ITStracking/Tracklet.h"
25+
#include "SimulationDataFormat/DigitizationContext.h"
26+
#include "Steer/MCKinematicsReader.h"
27+
#include "ITSMFTBase/DPLAlpideParam.h"
2528

2629
#ifdef VTX_DEBUG
2730
#include "TTree.h"
@@ -692,6 +695,57 @@ void VertexerTraits::computeVerticesInRof(int rofId,
692695
verticesInRof.push_back(foundVertices);
693696
}
694697

698+
void VertexerTraits::addTruthSeedingVertices()
699+
{
700+
LOGP(info, "Using truth seeds as vertices; will skip computations");
701+
mTimeFrame->resetRofPV();
702+
const auto dc = o2::steer::DigitizationContext::loadFromFile("collisioncontext.root");
703+
const auto irs = dc->getEventRecords();
704+
int64_t roFrameBiasInBC = o2::itsmft::DPLAlpideParam<o2::detectors::DetID::ITS>::Instance().roFrameBiasInBC;
705+
int64_t roFrameLengthInBC = o2::itsmft::DPLAlpideParam<o2::detectors::DetID::ITS>::Instance().roFrameLengthInBC;
706+
o2::steer::MCKinematicsReader mcReader(dc);
707+
std::map<int, bounded_vector<Vertex>> vertices;
708+
for (int iSrc{0}; iSrc < mcReader.getNSources(); ++iSrc) {
709+
auto eveId2colId = dc->getCollisionIndicesForSource(iSrc);
710+
for (int iEve{0}; iEve < mcReader.getNEvents(iSrc); ++iEve) {
711+
const auto& ir = irs[eveId2colId[iEve]];
712+
if (!ir.isDummy()) { // do we need this, is this for diffractive events?
713+
const auto& eve = mcReader.getMCEventHeader(iSrc, iEve);
714+
int rofId = (ir.toLong() - roFrameBiasInBC) / roFrameLengthInBC;
715+
if (!vertices.contains(rofId)) {
716+
vertices[rofId] = bounded_vector<Vertex>(mMemoryPool.get());
717+
}
718+
Vertex vert;
719+
vert.setTimeStamp(rofId);
720+
vert.setNContributors(eve.GetNPrim());
721+
vert.setXYZ((float)eve.GetX(), (float)eve.GetY(), (float)eve.GetZ());
722+
vert.setChi2(1);
723+
constexpr float cov = 2.5e-9;
724+
vert.setCov(cov, cov, cov, cov, cov, cov);
725+
vertices[rofId].push_back(vert);
726+
}
727+
}
728+
}
729+
size_t nVerts{0};
730+
for (int iROF{0}; iROF < mTimeFrame->getNrof(); ++iROF) {
731+
bounded_vector<Vertex> verts(mMemoryPool.get());
732+
bounded_vector<std::pair<o2::MCCompLabel, float>> polls(mMemoryPool.get());
733+
if (vertices.contains(iROF)) {
734+
verts = vertices[iROF];
735+
nVerts += verts.size();
736+
for (size_t i{0}; i < verts.size(); ++i) {
737+
o2::MCCompLabel lbl; // unset label for now
738+
polls.emplace_back(lbl, 1.f);
739+
}
740+
} else {
741+
mTimeFrame->getNoVertexROF()++;
742+
}
743+
mTimeFrame->addPrimaryVertices(verts, iROF, 0);
744+
mTimeFrame->addPrimaryVerticesLabels(polls);
745+
}
746+
LOGP(info, "Found {}/{} ROFs with {} vertices -> <NV>={:.2f}", vertices.size(), mTimeFrame->getNrof(), nVerts, (float)nVerts / (float)vertices.size());
747+
}
748+
695749
void VertexerTraits::setNThreads(int n, std::shared_ptr<tbb::task_arena>& arena)
696750
{
697751
#if defined(VTX_DEBUG)

0 commit comments

Comments
 (0)