Skip to content

Commit 1287bc6

Browse files
committed
ITS: add truth seeding
Signed-off-by: Felix Schlepper <felix.schlepper@cern.ch>
1 parent 82d072d commit 1287bc6

File tree

9 files changed

+84
-14
lines changed

9 files changed

+84
-14
lines changed

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
@@ -282,6 +282,8 @@ std::vector<VertexingParameters> TrackingMode::getVertexingParameters(TrackingMo
282282
p.nThreads = vc.nThreads;
283283
p.ZBins = vc.ZBins;
284284
p.PhiBins = vc.PhiBins;
285+
286+
p.useTruthSeeding = vc.useTruthSeeding;
285287
}
286288
// set for now outside to not disturb status quo
287289
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
@@ -187,13 +187,13 @@ void ITSTrackingInterface::run(framework::ProcessingContext& pc)
187187
vtxROF.setNEntries(vtxSpan.size());
188188
bool selROF = vtxSpan.empty();
189189
for (auto iV{0}; iV < vtxSpan.size(); ++iV) {
190-
auto& v = vtxSpan[iV];
190+
const auto& v = vtxSpan[iV];
191191
if (multEstConf.isVtxMultCutRequested() && !multEstConf.isPassingVtxMultCut(v.getNContributors())) {
192192
continue; // skip vertex of unwanted multiplicity
193193
}
194194
selROF = true;
195195
vertices.push_back(v);
196-
if (mIsMC) {
196+
if (mIsMC && !VertexerParamConfig::Instance().useTruthSeeding) {
197197
allVerticesLabels.push_back(vMCRecInfo[iV].first);
198198
allVerticesPurities.push_back(vMCRecInfo[iV].second);
199199
}

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: 59 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"
@@ -693,6 +696,59 @@ void VertexerTraits::computeVerticesInRof(int rofId,
693696
verticesInRof.push_back(foundVertices);
694697
}
695698

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

0 commit comments

Comments
 (0)