Skip to content

Commit 459eabd

Browse files
authored
SVertexer records pools entry rejections (currently #ifdef-ed) (#16218)
1 parent 357a90d commit 459eabd

7 files changed

Lines changed: 94 additions & 4 deletions

File tree

‎DataFormats/Reconstruction/include/ReconstructionDataFormats/DecayNBodyIndex.h‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,15 @@ class CascadeIndex
103103
ClassDefNV(CascadeIndex, 1);
104104
};
105105

106+
// record of the reasons (bit pattern, see SVertexer::PoolRejection) for a track not entering the SVertexer V0 pools for the given vertex
107+
struct PoolRejRecord {
108+
o2::dataformats::GlobalTrackID gid{}; // track GID (raw, with flags)
109+
int vtID = 0; // primary vertex ID for which the track was considered
110+
uint16_t rej = 0; // rejection bits
111+
112+
ClassDefNV(PoolRejRecord, 1);
113+
};
114+
106115
} // namespace o2::dataformats
107116

108117
#endif

‎DataFormats/Reconstruction/src/ReconstructionDataFormatsLinkDef.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@
9898
#pragma link C++ class o2::dataformats::Decay3BodyIndex + ;
9999
#pragma link C++ class o2::dataformats::V0Index + ;
100100
#pragma link C++ class o2::dataformats::CascadeIndex + ;
101+
#pragma link C++ class o2::dataformats::PoolRejRecord + ;
102+
#pragma link C++ class std::vector < o2::dataformats::PoolRejRecord> + ;
101103

102104
#pragma link C++ class std::vector < o2::dataformats::DecayNBodyIndex < 2>> + ;
103105
#pragma link C++ class std::vector < o2::dataformats::DecayNBodyIndex < 3>> + ;

‎Detectors/GlobalTrackingWorkflow/readers/src/SecondaryVertexReaderSpec.cxx‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class SecondaryVertexReader : public o2::framework::Task
4343
using Cascade = o2::dataformats::Cascade;
4444
using Decay3BodyIndex = o2::dataformats::Decay3BodyIndex;
4545
using Decay3Body = o2::dataformats::Decay3Body;
46+
using PoolRejRecord = o2::dataformats::PoolRejRecord;
4647

4748
public:
4849
SecondaryVertexReader() = default;
@@ -64,6 +65,8 @@ class SecondaryVertexReader : public o2::framework::Task
6465
std::vector<Decay3BodyIndex> m3BodysIdx, *m3BodysIdxPtr = &m3BodysIdx;
6566
std::vector<Decay3Body> m3Bodys, *m3BodysPtr = &m3Bodys;
6667
std::vector<RRef> mPV23BodyRef, *mPV23BodyRefPtr = &mPV23BodyRef;
68+
std::vector<PoolRejRecord> mPoolRej, *mPoolRejPtr = &mPoolRej; // optional, stays empty if the branch is absent
69+
bool mHasPoolRej = false;
6770

6871
std::unique_ptr<TFile> mFile;
6972
std::unique_ptr<TTree> mTree;
@@ -79,6 +82,7 @@ class SecondaryVertexReader : public o2::framework::Task
7982
std::string m3BodyIdxBranchName = "Decays3BodyID";
8083
std::string m3BodyBranchName = "Decays3Body";
8184
std::string mPVertex23BodyRefBranchName = "PV23BodyRefs";
85+
std::string mPoolRejBranchName = "PoolRejections";
8286
};
8387

8488
void SecondaryVertexReader::init(InitContext& ic)
@@ -114,6 +118,7 @@ void SecondaryVertexReader::run(ProcessingContext& pc)
114118
pc.outputs().snapshot(Output{"GLO", "DECAYS3BODY_IDX", 0}, m3BodysIdx);
115119
pc.outputs().snapshot(Output{"GLO", "DECAYS3BODY", 0}, m3Bodys);
116120
pc.outputs().snapshot(Output{"GLO", "PVTX_3BODYREFS", 0}, mPV23BodyRef);
121+
pc.outputs().snapshot(Output{"GLO", "SVREJPOOL", 0}, mPoolRej); // empty if the branch is absent
117122

118123
if (noEntry || mTree->GetReadEntry() + pc.services().get<const o2::framework::DeviceSpec>().maxInputTimeslices >= mTree->GetEntries()) {
119124
pc.services().get<ControlService>().endOfStream();
@@ -147,6 +152,12 @@ void SecondaryVertexReader::connectTree()
147152
mTree->SetBranchAddress(m3BodyIdxBranchName.c_str(), &m3BodysIdxPtr);
148153
mTree->SetBranchAddress(m3BodyBranchName.c_str(), &m3BodysPtr);
149154
mTree->SetBranchAddress(mPVertex23BodyRefBranchName.c_str(), &mPV23BodyRefPtr);
155+
mHasPoolRej = mTree->GetBranch(mPoolRejBranchName.c_str()) != nullptr;
156+
if (mHasPoolRej) {
157+
mTree->SetBranchAddress(mPoolRejBranchName.c_str(), &mPoolRejPtr);
158+
} else {
159+
LOG(debug) << "Branch " << mPoolRejBranchName << " not found, will publish empty pool rejection records";
160+
}
150161

151162
LOG(info) << "Loaded " << mSVertexTreeName << " tree from " << mFileName << " with " << mTree->GetEntries() << " entries";
152163
}
@@ -163,6 +174,7 @@ DataProcessorSpec getSecondaryVertexReaderSpec()
163174
outputs.emplace_back("GLO", "DECAYS3BODY_IDX", 0, Lifetime::Timeframe); // found 3 body vertices indices
164175
outputs.emplace_back("GLO", "DECAYS3BODY", 0, Lifetime::Timeframe); // found 3 body Decays
165176
outputs.emplace_back("GLO", "PVTX_3BODYREFS", 0, Lifetime::Timeframe); // prim.vertex -> 3 body Decays refs
177+
outputs.emplace_back("GLO", "SVREJPOOL", 0, Lifetime::Timeframe); // track pool rejection records
166178

167179
return DataProcessorSpec{
168180
"secondary-vertex-reader",

‎Detectors/GlobalTrackingWorkflow/src/SecondaryVertexWriterSpec.cxx‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ using Cascade = o2::dataformats::Cascade;
3434
using CascadeIndex = o2::dataformats::CascadeIndex;
3535
using Decay3Body = o2::dataformats::Decay3Body;
3636
using Decay3BodyIndex = o2::dataformats::Decay3BodyIndex;
37+
using PoolRejRecord = o2::dataformats::PoolRejRecord;
3738

3839
template <typename T>
3940
using BranchDefinition = MakeRootTreeWriterSpec::BranchDefinition<T>;
@@ -63,6 +64,7 @@ DataProcessorSpec getSecondaryVertexWriterSpec()
6364
auto inp3Body = InputSpec{"decays3body", "GLO", "DECAYS3BODY", 0};
6465
auto inp3BodyID = InputSpec{"decays3bodyIdx", "GLO", "DECAYS3BODY_IDX", 0};
6566
auto inp3BodyRef = InputSpec{"pv23bodyref", "GLO", "PVTX_3BODYREFS", 0};
67+
auto inpPoolRej = InputSpec{"poolrej", "GLO", "SVREJPOOL", 0};
6668

6769
return MakeRootTreeWriterSpec("secondary-vertex-writer",
6870
"o2_secondary_vertex.root",
@@ -77,7 +79,9 @@ DataProcessorSpec getSecondaryVertexWriterSpec()
7779

7880
BranchDefinition<std::vector<Decay3BodyIndex>>{inp3BodyID, "Decays3BodyID", loggerD},
7981
BranchDefinition<std::vector<Decay3Body>>{inp3Body, "Decays3Body"},
80-
BranchDefinition<std::vector<RRef>>{inp3BodyRef, "PV23BodyRefs"})();
82+
BranchDefinition<std::vector<RRef>>{inp3BodyRef, "PV23BodyRefs"},
83+
84+
BranchDefinition<std::vector<PoolRejRecord>>{inpPoolRej, "PoolRejections"})();
8185
}
8286

8387
} // namespace vertexing

‎Detectors/GlobalTrackingWorkflow/src/SecondaryVertexingSpec.cxx‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,18 @@ void SecondaryVertexingSpec::run(ProcessingContext& pc)
116116
storeConfigs(pc);
117117
mVertexer.process(recoData, pc);
118118

119+
// pool rejection info (map is empty unless SVertexer was compiled with _FILL_SV_POOL_REJECTIONS_)
120+
const auto& rejMap = mVertexer.getPoolRejections();
121+
auto& poolRej = pc.outputs().make<std::vector<o2d::PoolRejRecord>>(Output{"GLO", "SVREJPOOL", 0}, rejMap.size());
122+
size_t irec = 0;
123+
for (const auto& [key, rej] : rejMap) {
124+
auto [gid, iv] = o2::vertexing::SVertexer::rejectionKey2GidIv(key);
125+
auto& rec = poolRej[irec++];
126+
rec.gid = gid;
127+
rec.vtID = iv;
128+
rec.rej = rej;
129+
}
130+
119131
mTimer.Stop();
120132
auto calls = mVertexer.getNFitterCalls();
121133
LOGP(info, "Found {} V0s ({} fits), {} cascades ({} fits), {} 3-body decays ({} fits), {} strange tracks. Timing: CPU: {:.2f} Real: {:.2f} s",
@@ -312,6 +324,7 @@ DataProcessorSpec getSecondaryVertexingSpec(GTrackID::mask_t src, bool enableCas
312324
LOG(info) << "Strangeness tracker will use MC";
313325
}
314326
}
327+
outputs.emplace_back("GLO", "SVREJPOOL", 0, Lifetime::Timeframe); // track pool rejection records (filled only if SVertexer is built with _FILL_SV_POOL_REJECTIONS_)
315328
outputs.emplace_back("META", "SVERTEXER", 0, Lifetime::Sporadic);
316329

317330
return DataProcessorSpec{

‎Detectors/Vertexing/include/DetectorsVertexing/SVertexer.h‎

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,14 @@
3333
#include "StrangenessTracking/StrangenessTracker.h"
3434
#include "DataFormatsTPC/TrackTPC.h"
3535
#include <numeric>
36+
#include <unordered_map>
3637
#include <algorithm>
3738
#include "GPUO2InterfaceRefit.h"
3839
#include "DataFormatsTPC/PIDResponse.h"
3940

41+
// uncomment this to enable filling rejection records
42+
// #define _FILL_SV_POOL_REJECTIONS_
43+
4044
namespace o2
4145
{
4246
namespace tpc
@@ -77,6 +81,34 @@ class SVertexer
7781
AntiHyperhydrog4,
7882
NHypV0 };
7983

84+
// reasons for a track considered in buildT2V not to enter the POS/NEG pools (bit = 0x1 << reason)
85+
enum PoolRejection : int {
86+
RejTPCExcluded, // TPC-only tracks excluded by mExcludeTPCtracks
87+
RejTPCMaxX, // TPC track X > mTPCTrackMaxX
88+
RejTPCTimeCorr, // correctTPCTrack failed for the unconstrained TPC track clone
89+
RejTPCPhotonNCls, // photon tune: too few TPC clusters
90+
RejTPCPhotonDPV, // photon tune: Z too far from the vertex
91+
RejTPCPhotonRD2, // photon tune: circle too far from the beam line
92+
RejPVContributor, // PV contributor while maxPVContributors < 1
93+
RejMinDCAToPV, // |DCA| to mean vertex < minDCAToPV (and not a heavy ionizing particle)
94+
RejShortITSOnly, // short ITS-only track (see mITSSAminNclu, mRejectITSonlyOBtrack)
95+
NPoolRejections
96+
};
97+
98+
// key of the mPoolRejections map: (vertexID << 32) | GIndex.getRaw()
99+
static uint64_t getPoolRejectionKey(GIndex gid, int iv)
100+
{
101+
return (uint64_t(iv) << 32) | uint64_t(gid.getRaw());
102+
}
103+
104+
// inverse of getPoolRejectionKey: returns the track GIndex and the vertex ID
105+
static std::pair<GIndex, int> rejectionKey2GidIv(uint64_t k)
106+
{
107+
GIndex gid;
108+
gid.setRaw(static_cast<GIndex::Base_t>(k & 0xffffffff));
109+
return {gid, int(k >> 32)};
110+
}
111+
80112
enum HypCascade {
81113
XiMinus,
82114
OmegaMinus,
@@ -123,6 +155,7 @@ class SVertexer
123155
int getN3Bodies() const { return mN3Bodies; }
124156
int getNStrangeTracks() const { return mNStrangeTracks; }
125157
auto& getMeanVertex() const { return mMeanVertex; }
158+
const auto& getPoolRejections() const { return mPoolRejections; } // empty unless compiled with _FILL_SV_POOL_REJECTIONS_
126159
void setMeanVertex(const o2::dataformats::MeanVertexObject* v)
127160
{
128161
if (v == nullptr) {
@@ -158,7 +191,13 @@ class SVertexer
158191
void setupThreads();
159192
void buildT2V(const o2::globaltracking::RecoContainer& recoTracks);
160193
void updateTimeDependentParams();
161-
bool acceptTrack(const GIndex gid, const o2::track::TrackParCov& trc) const;
194+
bool acceptTrack(const GIndex gid, const o2::track::TrackParCov& trc, PoolRejection& reason) const;
195+
void flagPoolRejection(GIndex gid, int iv, PoolRejection reason)
196+
{
197+
#ifdef _FILL_SV_POOL_REJECTIONS_
198+
mPoolRejections[getPoolRejectionKey(gid, iv)] |= uint16_t(0x1 << reason);
199+
#endif
200+
}
162201
bool processTPCTrack(const o2::tpc::TrackTPC& trTPC, GIndex gid, int vtxid);
163202
float correctTPCTrack(TrackCand& trc, const o2::tpc::TrackTPC& tTPC, float tmus, float tmusErr) const;
164203

@@ -186,6 +225,7 @@ class SVertexer
186225
std::vector<std::vector<Decay3BodyIndex>> m3bodyIdxTmp;
187226
std::array<std::vector<TrackCand>, 2> mTracksPool{}; // pools of positive and negative seeds sorted in min VtxID
188227
std::array<std::vector<int>, 2> mVtxFirstTrack{}; // 1st pos. and neg. track of the pools for each vertex
228+
std::unordered_map<uint64_t, uint16_t> mPoolRejections{}; // key: (vertexID << 32) | GIndex.getRaw(); value: bit pattern (0x1<<PoolRejection) of reasons for not entering the pools (filled only if _FILL_SV_POOL_REJECTIONS_ is defined)
189229

190230
o2::dataformats::VertexBase mMeanVertex{{0., 0., 0.}, {0.1 * 0.1, 0., 0.1 * 0.1, 0., 0., 6. * 6.}};
191231
const SVertexerParams* mSVParams = nullptr;

‎Detectors/Vertexing/src/SVertexer.cxx‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -416,9 +416,10 @@ void SVertexer::setupThreads()
416416
}
417417

418418
//__________________________________________________________________
419-
bool SVertexer::acceptTrack(const GIndex gid, const o2::track::TrackParCov& trc) const
419+
bool SVertexer::acceptTrack(const GIndex gid, const o2::track::TrackParCov& trc, PoolRejection& reason) const
420420
{
421421
if (gid.isPVContributor() && mSVParams->maxPVContributors < 1) {
422+
reason = RejPVContributor;
422423
return false;
423424
}
424425

@@ -440,6 +441,7 @@ bool SVertexer::acceptTrack(const GIndex gid, const o2::track::TrackParCov& trc)
440441
}
441442
}
442443
if (std::abs(dca[0]) < mSVParams->minDCAToPV) {
444+
reason = RejMinDCAToPV;
443445
return false;
444446
}
445447
}
@@ -466,6 +468,7 @@ void SVertexer::buildT2V(const o2::globaltracking::RecoContainer& recoData) // a
466468

467469
std::unordered_map<GIndex, std::pair<int, int>> tmap;
468470
std::unordered_map<GIndex, bool> rejmap;
471+
mPoolRejections.clear();
469472
// The last entry is for unassigned tracks, ignore them. A timeframe holding no collision at
470473
// all has no entry, and the subtraction would then wrap around.
471474
int nv = vtxRefs.size() > 0 ? vtxRefs.size() - 1 : 0;
@@ -484,6 +487,7 @@ void SVertexer::buildT2V(const o2::globaltracking::RecoContainer& recoData) // a
484487
}
485488
if (tvid.getSource() == GIndex::TPC) {
486489
if (mSVParams->mExcludeTPCtracks) {
490+
flagPoolRejection(tvid, iv, RejTPCExcluded);
487491
continue;
488492
}
489493
// unconstrained TPC tracks require special treatment: there is no point in checking DCA to mean vertex since it is not precise,
@@ -544,13 +548,16 @@ void SVertexer::buildT2V(const o2::globaltracking::RecoContainer& recoData) // a
544548
nITSclu = itsABTracklet.getNClusters();
545549
}
546550
}
547-
if (!acceptTrack(tvid, trc) && !heavyIonisingParticle) {
551+
PoolRejection accReason{};
552+
if (!acceptTrack(tvid, trc, accReason) && !heavyIonisingParticle) {
553+
flagPoolRejection(tvid, iv, accReason);
548554
if (tvid.isAmbiguous()) {
549555
rejmap[tvid] = true;
550556
}
551557
continue;
552558
}
553559
if ((isTPCloaded && !hasTPC) && (isITSloaded && (nITSclu < mSVParams->mITSSAminNclu && (!shortOBITSOnlyTrack || mSVParams->mRejectITSonlyOBtrack)))) {
560+
flagPoolRejection(tvid, iv, RejShortITSOnly);
554561
continue; // reject short ITS-only
555562
}
556563

@@ -1286,6 +1293,7 @@ void SVertexer::setNThreads(int n)
12861293
bool SVertexer::processTPCTrack(const o2::tpc::TrackTPC& trTPC, GIndex gid, int vtxid)
12871294
{
12881295
if (mSVParams->mTPCTrackMaxX > 0. && trTPC.getX() > mSVParams->mTPCTrackMaxX) {
1296+
flagPoolRejection(gid, vtxid, RejTPCMaxX);
12891297
return true;
12901298
}
12911299
// if TPC trackis unconstrained, try to create in the tracks pool a clone constrained to vtxid vertex time.
@@ -1312,6 +1320,7 @@ bool SVertexer::processTPCTrack(const o2::tpc::TrackTPC& trTPC, GIndex gid, int
13121320
auto err = correctTPCTrack(trLoc, trTPC, twe.getTimeStamp(), twe.getTimeStampError());
13131321
if (err < 0) {
13141322
mTracksPool[posneg].pop_back(); // discard
1323+
flagPoolRejection(gid, vtxid, RejTPCTimeCorr);
13151324
return true;
13161325
}
13171326

@@ -1329,6 +1338,7 @@ bool SVertexer::processTPCTrack(const o2::tpc::TrackTPC& trTPC, GIndex gid, int
13291338
bool dRD2 = drd2 > mSVParams->mTPCTrackXY2Radius;
13301339

13311340
if (dCls || dDPV || dRD2) {
1341+
flagPoolRejection(gid, vtxid, dCls ? RejTPCPhotonNCls : (dDPV ? RejTPCPhotonDPV : RejTPCPhotonRD2));
13321342
mTracksPool[posneg].pop_back();
13331343
return true;
13341344
}

0 commit comments

Comments
 (0)