Skip to content

Commit 6d2c1d3

Browse files
authored
ITS: opt. vertex cont. output (#14507)
Signed-off-by: Felix Schlepper <felix.schlepper@cern.ch>
1 parent 0c0f2b9 commit 6d2c1d3

File tree

9 files changed

+79
-2
lines changed

9 files changed

+79
-2
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ struct VertexingParameters {
113113
bool SaveTimeBenchmarks = false;
114114

115115
bool useTruthSeeding = false; // overwrite found vertices with MC events
116+
bool outputContLabels = false;
116117

117118
int nThreads = 1;
118119
bool PrintMemory = false; // print allocator usage in epilog report

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,18 @@ struct TimeFrame {
7373
gsl::span<const Vertex> getPrimaryVertices(int rofId) const;
7474
gsl::span<const Vertex> getPrimaryVertices(int romin, int romax) const;
7575
gsl::span<const std::pair<MCCompLabel, float>> getPrimaryVerticesMCRecInfo(const int rofId) const;
76+
gsl::span<const MCCompLabel> getPrimaryVerticesContributors(const int rofId) const;
7677
gsl::span<const std::array<float, 2>> getPrimaryVerticesXAlpha(int rofId) const;
7778
void fillPrimaryVerticesXandAlpha();
7879
int getPrimaryVerticesNum(int rofId = -1) const;
7980
void addPrimaryVertices(const bounded_vector<Vertex>& vertices);
8081
void addPrimaryVerticesLabels(bounded_vector<std::pair<MCCompLabel, float>>& labels);
82+
void addPrimaryVerticesContributorLabels(bounded_vector<MCCompLabel>& labels);
8183
void addPrimaryVertices(const bounded_vector<Vertex>& vertices, const int rofId, const int iteration);
8284
void addPrimaryVertices(const gsl::span<const Vertex>& vertices, const int rofId, const int iteration);
8385
void addPrimaryVerticesInROF(const bounded_vector<Vertex>& vertices, const int rofId, const int iteration);
8486
void addPrimaryVerticesLabelsInROF(const bounded_vector<std::pair<MCCompLabel, float>>& labels, const int rofId);
87+
void addPrimaryVerticesContributorLabelsInROF(const bounded_vector<MCCompLabel>& labels, const int rofId);
8588
void removePrimaryVerticesInROf(const int rofId);
8689
int loadROFrameData(const o2::itsmft::ROFRecord& rof, gsl::span<const itsmft::Cluster> clusters,
8790
const dataformats::MCTruthContainer<MCCompLabel>* mcLabels = nullptr);
@@ -342,6 +345,7 @@ struct TimeFrame {
342345
std::array<bounded_vector<int>, 2> mTrackletsIndexROF;
343346
std::vector<bounded_vector<MCCompLabel>> mLinesLabels;
344347
std::vector<std::pair<MCCompLabel, float>> mVerticesMCRecInfo;
348+
bounded_vector<MCCompLabel> mVerticesContributorLabels;
345349
std::array<uint32_t, 2> mTotalTracklets = {0, 0};
346350
unsigned int mNoVertexROF = 0;
347351
bounded_vector<int> mTotVertPerIteration;
@@ -371,6 +375,22 @@ inline gsl::span<const std::pair<MCCompLabel, float>> TimeFrame<nLayers>::getPri
371375
return {&(mVerticesMCRecInfo[start]), static_cast<gsl::span<const std::pair<MCCompLabel, float>>::size_type>(delta)};
372376
}
373377

378+
template <int nLayers>
379+
inline gsl::span<const MCCompLabel> TimeFrame<nLayers>::getPrimaryVerticesContributors(const int rofId) const
380+
{
381+
// count the number of cont. in rofs before target rof
382+
unsigned int start{0}, delta{0};
383+
const auto& pvsBefore = getPrimaryVertices(0, rofId - 1);
384+
for (const auto& pv : pvsBefore) {
385+
start += pv.getNContributors();
386+
}
387+
const auto& pvsIn = getPrimaryVertices(rofId);
388+
for (const auto& pv : pvsIn) {
389+
delta += pv.getNContributors();
390+
}
391+
return {&(mVerticesContributorLabels[start]), static_cast<gsl::span<const MCCompLabel>::size_type>(delta)};
392+
}
393+
374394
template <int nLayers>
375395
inline gsl::span<const Vertex> TimeFrame<nLayers>::getPrimaryVertices(int romin, int romax) const
376396
{

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +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
51+
bool useTruthSeeding{false}; // overwrite seeding vertices with MC truth
52+
bool outputContLabels{false}; // output additioanlly for each vertex its contributing line labels
5253

5354
int nThreads = 1;
5455
bool printMemory = false;

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,7 @@ std::vector<VertexingParameters> TrackingMode::getVertexingParameters(TrackingMo
284284
p.PhiBins = vc.PhiBins;
285285

286286
p.useTruthSeeding = vc.useTruthSeeding;
287+
p.outputContLabels = vc.outputContLabels;
287288
}
288289
// set for now outside to not disturb status quo
289290
vertParams[0].vertNsigmaCut = vc.vertNsigmaCut;

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,12 @@ void TimeFrame<nLayers>::addPrimaryVerticesLabels(bounded_vector<std::pair<MCCom
8585
mVerticesMCRecInfo.insert(mVerticesMCRecInfo.end(), labels.begin(), labels.end());
8686
}
8787

88+
template <int nLayers>
89+
void TimeFrame<nLayers>::addPrimaryVerticesContributorLabels(bounded_vector<MCCompLabel>& labels)
90+
{
91+
mVerticesContributorLabels.insert(mVerticesContributorLabels.end(), labels.begin(), labels.end());
92+
}
93+
8894
template <int nLayers>
8995
void TimeFrame<nLayers>::addPrimaryVerticesInROF(const bounded_vector<Vertex>& vertices, const int rofId, const int iteration)
9096
{
@@ -101,6 +107,18 @@ void TimeFrame<nLayers>::addPrimaryVerticesLabelsInROF(const bounded_vector<std:
101107
mVerticesMCRecInfo.insert(mVerticesMCRecInfo.begin() + mROFramesPV[rofId], labels.begin(), labels.end());
102108
}
103109

110+
template <int nLayers>
111+
void TimeFrame<nLayers>::addPrimaryVerticesContributorLabelsInROF(const bounded_vector<MCCompLabel>& labels, const int rofId)
112+
{
113+
// count the number of cont. in rofs before and including the target rof
114+
unsigned int n{0};
115+
const auto& pvs = getPrimaryVertices(0, rofId);
116+
for (const auto& pv : pvs) {
117+
n += pv.getNContributors();
118+
}
119+
mVerticesContributorLabels.insert(mVerticesContributorLabels.begin() + n, labels.begin(), labels.end());
120+
}
121+
104122
template <int nLayers>
105123
void TimeFrame<nLayers>::addPrimaryVertices(const gsl::span<const Vertex>& vertices, const int rofId, const int iteration)
106124
{
@@ -295,6 +313,7 @@ void TimeFrame<nLayers>::initialise(const int iteration, const TrackingParameter
295313
deepVectorClear(mLinesLabels);
296314
if (resetVertices) {
297315
deepVectorClear(mVerticesMCRecInfo);
316+
deepVectorClear(mVerticesContributorLabels);
298317
}
299318
clearResizeBoundedVector(mTracks, mNrof, mMemoryPool.get());
300319
clearResizeBoundedVector(mTracksLabel, mNrof, mMemoryPool.get());
@@ -646,6 +665,7 @@ void TimeFrame<nLayers>::setMemoryPool(std::shared_ptr<BoundedMemoryResource>& p
646665
initVector(mClusterSize);
647666
initVector(mPValphaX);
648667
initVector(mBogusClusters);
668+
initVector(mVerticesContributorLabels);
649669
initArrays(mTrackletsIndexROF);
650670
initVectors(mTracks);
651671
initVectors(mTracklets);
@@ -689,6 +709,8 @@ void TimeFrame<nLayers>::wipe()
689709
deepVectorClear(mBogusClusters);
690710
deepVectorClear(mTrackletsIndexROF);
691711
deepVectorClear(mPrimaryVertices);
712+
deepVectorClear(mTrackletClusters);
713+
deepVectorClear(mVerticesContributorLabels);
692714
}
693715

694716
template class TimeFrame<7>;

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ void ITSTrackingInterface::run(framework::ProcessingContext& pc)
117117
static pmr::vector<float> dummyMCPurVerts;
118118
auto& allTrackLabels = mIsMC ? pc.outputs().make<std::vector<o2::MCCompLabel>>(Output{"ITS", "TRACKSMCTR", 0}) : dummyMCLabTracks;
119119
auto& allVerticesLabels = mIsMC ? pc.outputs().make<std::vector<o2::MCCompLabel>>(Output{"ITS", "VERTICESMCTR", 0}) : dummyMCLabVerts;
120+
bool writeContLabels = mIsMC && o2::its::VertexerParamConfig::Instance().outputContLabels;
121+
auto& allVerticesContLabels = writeContLabels ? pc.outputs().make<std::vector<o2::MCCompLabel>>(Output{"ITS", "VERTICESMCTRCONT", 0}) : dummyMCLabVerts;
120122
auto& allVerticesPurities = mIsMC ? pc.outputs().make<std::vector<float>>(Output{"ITS", "VERTICESMCPUR", 0}) : dummyMCPurVerts;
121123

122124
std::uint32_t roFrame = 0;
@@ -159,6 +161,7 @@ void ITSTrackingInterface::run(framework::ProcessingContext& pc)
159161
}
160162
const auto& multEstConf = FastMultEstConfig::Instance(); // parameters for mult estimation and cuts
161163
gsl::span<const std::pair<MCCompLabel, float>> vMCRecInfo;
164+
gsl::span<const MCCompLabel> vMCContLabels;
162165
for (auto iRof{0}; iRof < trackROFspan.size(); ++iRof) {
163166
std::vector<Vertex> vtxVecLoc;
164167
auto& vtxROF = vertROFvec.emplace_back(trackROFspan[iRof]);
@@ -167,6 +170,9 @@ void ITSTrackingInterface::run(framework::ProcessingContext& pc)
167170
auto vtxSpan = mTimeFrame->getPrimaryVertices(iRof);
168171
if (mIsMC) {
169172
vMCRecInfo = mTimeFrame->getPrimaryVerticesMCRecInfo(iRof);
173+
if (o2::its::VertexerParamConfig::Instance().outputContLabels) {
174+
vMCContLabels = mTimeFrame->getPrimaryVerticesContributors(iRof);
175+
}
170176
}
171177
if (o2::its::TrackerParamConfig::Instance().doUPCIteration) {
172178
if (!vtxSpan.empty()) {
@@ -186,17 +192,22 @@ void ITSTrackingInterface::run(framework::ProcessingContext& pc)
186192
}
187193
vtxROF.setNEntries(vtxSpan.size());
188194
bool selROF = vtxSpan.empty();
189-
for (auto iV{0}; iV < vtxSpan.size(); ++iV) {
195+
for (int iV{0}, iVC{0}; iV < vtxSpan.size(); ++iV) {
190196
const auto& v = vtxSpan[iV];
191197
if (multEstConf.isVtxMultCutRequested() && !multEstConf.isPassingVtxMultCut(v.getNContributors())) {
198+
iVC += v.getNContributors();
192199
continue; // skip vertex of unwanted multiplicity
193200
}
194201
selROF = true;
195202
vertices.push_back(v);
196203
if (mIsMC && !VertexerParamConfig::Instance().useTruthSeeding) {
197204
allVerticesLabels.push_back(vMCRecInfo[iV].first);
198205
allVerticesPurities.push_back(vMCRecInfo[iV].second);
206+
if (o2::its::VertexerParamConfig::Instance().outputContLabels) {
207+
allVerticesContLabels.insert(allVerticesContLabels.end(), vMCContLabels.begin() + iVC, vMCContLabels.begin() + iVC + v.getNContributors());
208+
}
199209
}
210+
iVC += v.getNContributors();
200211
}
201212
if (processingMask[iRof] && !selROF) { // passed selection in clusters and not in vertex multiplicity
202213
LOGP(info, "ROF {} rejected by the vertex multiplicity selection [{},{}]", iRof, multEstConf.cutMultVtxLow, multEstConf.cutMultVtxHigh);
@@ -291,6 +302,9 @@ void ITSTrackingInterface::run(framework::ProcessingContext& pc)
291302
if (mIsMC) {
292303
LOGP(info, "ITSTracker pushed {} track labels", allTrackLabels.size());
293304
LOGP(info, "ITSTracker pushed {} vertex labels", allVerticesLabels.size());
305+
if (!allVerticesContLabels.empty()) {
306+
LOGP(info, "ITSTracker pushed {} vertex contributor labels", allVerticesContLabels.size());
307+
}
294308
LOGP(info, "ITSTracker pushed {} vertex purities", allVerticesPurities.size());
295309
}
296310
}

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,7 @@ void VertexerTraits::computeVertices(const int iteration)
388388
auto nsigmaCut{std::min(mVrtParams[iteration].vertNsigmaCut * mVrtParams[iteration].vertNsigmaCut * (mVrtParams[iteration].vertRadiusSigma * mVrtParams[iteration].vertRadiusSigma + mVrtParams[iteration].trackletSigma * mVrtParams[iteration].trackletSigma), 1.98f)};
389389
bounded_vector<Vertex> vertices(mMemoryPool.get());
390390
bounded_vector<std::pair<o2::MCCompLabel, float>> polls(mMemoryPool.get());
391+
bounded_vector<o2::MCCompLabel> contLabels(mMemoryPool.get());
391392
#ifdef VTX_DEBUG
392393
std::vector<std::vector<ClusterLines>> dbg_clusLines(mTimeFrame->getNrof());
393394
#endif
@@ -511,18 +512,27 @@ void VertexerTraits::computeVertices(const int iteration)
511512
labels.push_back(mTimeFrame->getLinesLabel(rofId)[index]); // then we can use nContributors from vertices to get the labels
512513
}
513514
polls.push_back(computeMain(labels));
515+
if (mVrtParams[iteration].outputContLabels) {
516+
contLabels.insert(contLabels.end(), labels.begin(), labels.end());
517+
}
514518
}
515519
}
516520
}
517521
if (!iteration) {
518522
mTimeFrame->addPrimaryVertices(vertices, rofId, iteration);
519523
if (mTimeFrame->hasMCinformation()) {
520524
mTimeFrame->addPrimaryVerticesLabels(polls);
525+
if (mVrtParams[iteration].outputContLabels) {
526+
mTimeFrame->addPrimaryVerticesContributorLabels(contLabels);
527+
}
521528
}
522529
} else {
523530
mTimeFrame->addPrimaryVerticesInROF(vertices, rofId, iteration);
524531
if (mTimeFrame->hasMCinformation()) {
525532
mTimeFrame->addPrimaryVerticesLabelsInROF(polls, rofId);
533+
if (mVrtParams[iteration].outputContLabels) {
534+
mTimeFrame->addPrimaryVerticesContributorLabelsInROF(contLabels, rofId);
535+
}
526536
}
527537
}
528538
if (vertices.empty() && !(iteration && (int)mTimeFrame->getPrimaryVertices(rofId).size() > mVrtParams[iteration].vertPerRofThreshold)) {

Detectors/ITSMFT/ITS/workflow/src/TrackWriterSpec.cxx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "SimulationDataFormat/MCCompLabel.h"
2121
#include "SimulationDataFormat/MCTruthContainer.h"
2222
#include "ReconstructionDataFormats/Vertex.h"
23+
#include "ITStracking/TrackingConfigParam.h"
2324

2425
using namespace o2::framework;
2526

@@ -39,6 +40,7 @@ DataProcessorSpec getTrackWriterSpec(bool useMC)
3940
{
4041
// Spectators for logging
4142
// this is only to restore the original behavior
43+
const auto writeContLabels = VertexerParamConfig::Instance().outputContLabels && useMC;
4244
auto tracksSize = std::make_shared<int>(0);
4345
auto tracksSizeGetter = [tracksSize](std::vector<o2::its::TrackITS> const& tracks) {
4446
*tracksSize = tracks.size();
@@ -69,6 +71,11 @@ DataProcessorSpec getTrackWriterSpec(bool useMC)
6971
"ITSVertexMCTruth",
7072
(useMC ? 1 : 0), // one branch if mc labels enabled
7173
""},
74+
BranchDefinition<LabelsType>{InputSpec{"labelsVerticesContributors", "ITS", "VERTICESMCTRCONT", 0},
75+
"ITSVertexMCTruthCont",
76+
(writeContLabels ? 1 : 0), // one branch if
77+
// requested
78+
""},
7279
BranchDefinition<ROFRecLblT>{InputSpec{"MC2ROframes", "ITS", "ITSTrackMC2ROF", 0},
7380
"ITSTracksMC2ROF",
7481
(useMC ? 1 : 0), // one branch if mc labels enabled

Detectors/ITSMFT/ITS/workflow/src/TrackerSpec.cxx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ DataProcessorSpec getTrackerSpec(bool useMC, bool useGeom, int trgType, Tracking
120120
inputs.emplace_back("itsmclabels", "ITS", "CLUSTERSMCTR", 0, Lifetime::Timeframe);
121121
inputs.emplace_back("ITSMC2ROframes", "ITS", "CLUSTERSMC2ROF", 0, Lifetime::Timeframe);
122122
outputs.emplace_back("ITS", "VERTICESMCTR", 0, Lifetime::Timeframe);
123+
outputs.emplace_back("ITS", "VERTICESMCTRCONT", 0, Lifetime::Timeframe);
123124
outputs.emplace_back("ITS", "VERTICESMCPUR", 0, Lifetime::Timeframe);
124125
outputs.emplace_back("ITS", "TRACKSMCTR", 0, Lifetime::Timeframe);
125126
outputs.emplace_back("ITS", "ITSTrackMC2ROF", 0, Lifetime::Timeframe);

0 commit comments

Comments
 (0)