Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,15 @@ class CascadeIndex
ClassDefNV(CascadeIndex, 1);
};

// record of the reasons (bit pattern, see SVertexer::PoolRejection) for a track not entering the SVertexer V0 pools for the given vertex
struct PoolRejRecord {
o2::dataformats::GlobalTrackID gid{}; // track GID (raw, with flags)
int vtID = 0; // primary vertex ID for which the track was considered
uint16_t rej = 0; // rejection bits

ClassDefNV(PoolRejRecord, 1);
};

} // namespace o2::dataformats

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@
#pragma link C++ class o2::dataformats::Decay3BodyIndex + ;
#pragma link C++ class o2::dataformats::V0Index + ;
#pragma link C++ class o2::dataformats::CascadeIndex + ;
#pragma link C++ class o2::dataformats::PoolRejRecord + ;
#pragma link C++ class std::vector < o2::dataformats::PoolRejRecord> + ;

#pragma link C++ class std::vector < o2::dataformats::DecayNBodyIndex < 2>> + ;
#pragma link C++ class std::vector < o2::dataformats::DecayNBodyIndex < 3>> + ;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class SecondaryVertexReader : public o2::framework::Task
using Cascade = o2::dataformats::Cascade;
using Decay3BodyIndex = o2::dataformats::Decay3BodyIndex;
using Decay3Body = o2::dataformats::Decay3Body;
using PoolRejRecord = o2::dataformats::PoolRejRecord;

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

std::unique_ptr<TFile> mFile;
std::unique_ptr<TTree> mTree;
Expand All @@ -79,6 +82,7 @@ class SecondaryVertexReader : public o2::framework::Task
std::string m3BodyIdxBranchName = "Decays3BodyID";
std::string m3BodyBranchName = "Decays3Body";
std::string mPVertex23BodyRefBranchName = "PV23BodyRefs";
std::string mPoolRejBranchName = "PoolRejections";
};

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

if (noEntry || mTree->GetReadEntry() + pc.services().get<const o2::framework::DeviceSpec>().maxInputTimeslices >= mTree->GetEntries()) {
pc.services().get<ControlService>().endOfStream();
Expand Down Expand Up @@ -147,6 +152,12 @@ void SecondaryVertexReader::connectTree()
mTree->SetBranchAddress(m3BodyIdxBranchName.c_str(), &m3BodysIdxPtr);
mTree->SetBranchAddress(m3BodyBranchName.c_str(), &m3BodysPtr);
mTree->SetBranchAddress(mPVertex23BodyRefBranchName.c_str(), &mPV23BodyRefPtr);
mHasPoolRej = mTree->GetBranch(mPoolRejBranchName.c_str()) != nullptr;
if (mHasPoolRej) {
mTree->SetBranchAddress(mPoolRejBranchName.c_str(), &mPoolRejPtr);
} else {
LOG(degug) << "Branch " << mPoolRejBranchName << " not found, will publish empty pool rejection records";
}

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

return DataProcessorSpec{
"secondary-vertex-reader",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ using Cascade = o2::dataformats::Cascade;
using CascadeIndex = o2::dataformats::CascadeIndex;
using Decay3Body = o2::dataformats::Decay3Body;
using Decay3BodyIndex = o2::dataformats::Decay3BodyIndex;
using PoolRejRecord = o2::dataformats::PoolRejRecord;

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

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

BranchDefinition<std::vector<Decay3BodyIndex>>{inp3BodyID, "Decays3BodyID", loggerD},
BranchDefinition<std::vector<Decay3Body>>{inp3Body, "Decays3Body"},
BranchDefinition<std::vector<RRef>>{inp3BodyRef, "PV23BodyRefs"})();
BranchDefinition<std::vector<RRef>>{inp3BodyRef, "PV23BodyRefs"},

BranchDefinition<std::vector<PoolRejRecord>>{inpPoolRej, "PoolRejections"})();
}

} // namespace vertexing
Expand Down
13 changes: 13 additions & 0 deletions Detectors/GlobalTrackingWorkflow/src/SecondaryVertexingSpec.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,18 @@ void SecondaryVertexingSpec::run(ProcessingContext& pc)
storeConfigs(pc);
mVertexer.process(recoData, pc);

// pool rejection info (map is empty unless SVertexer was compiled with _FILL_SV_POOL_REJECTIONS_)
const auto& rejMap = mVertexer.getPoolRejections();
auto& poolRej = pc.outputs().make<std::vector<o2d::PoolRejRecord>>(Output{"GLO", "SVREJPOOL", 0}, rejMap.size());
size_t irec = 0;
for (const auto& [key, rej] : rejMap) {
auto [gid, iv] = o2::vertexing::SVertexer::rejectionKey2GidIv(key);
auto& rec = poolRej[irec++];
rec.gid = gid;
rec.vtID = iv;
rec.rej = rej;
}

mTimer.Stop();
auto calls = mVertexer.getNFitterCalls();
LOGP(info, "Found {} V0s ({} fits), {} cascades ({} fits), {} 3-body decays ({} fits), {} strange tracks. Timing: CPU: {:.2f} Real: {:.2f} s",
Expand Down Expand Up @@ -312,6 +324,7 @@ DataProcessorSpec getSecondaryVertexingSpec(GTrackID::mask_t src, bool enableCas
LOG(info) << "Strangeness tracker will use MC";
}
}
outputs.emplace_back("GLO", "SVREJPOOL", 0, Lifetime::Timeframe); // track pool rejection records (filled only if SVertexer is built with _FILL_SV_POOL_REJECTIONS_)
outputs.emplace_back("META", "SVERTEXER", 0, Lifetime::Sporadic);

return DataProcessorSpec{
Expand Down
42 changes: 41 additions & 1 deletion Detectors/Vertexing/include/DetectorsVertexing/SVertexer.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,14 @@
#include "StrangenessTracking/StrangenessTracker.h"
#include "DataFormatsTPC/TrackTPC.h"
#include <numeric>
#include <unordered_map>
#include <algorithm>
#include "GPUO2InterfaceRefit.h"
#include "DataFormatsTPC/PIDResponse.h"

// uncomment this to enable filling rejection records
// #define _FILL_SV_POOL_REJECTIONS_

namespace o2
{
namespace tpc
Expand Down Expand Up @@ -77,6 +81,34 @@ class SVertexer
AntiHyperhydrog4,
NHypV0 };

// reasons for a track considered in buildT2V not to enter the POS/NEG pools (bit = 0x1 << reason)
enum PoolRejection : int {
RejTPCExcluded, // TPC-only tracks excluded by mExcludeTPCtracks
RejTPCMaxX, // TPC track X > mTPCTrackMaxX
RejTPCTimeCorr, // correctTPCTrack failed for the unconstrained TPC track clone
RejTPCPhotonNCls, // photon tune: too few TPC clusters
RejTPCPhotonDPV, // photon tune: Z too far from the vertex
RejTPCPhotonRD2, // photon tune: circle too far from the beam line
RejPVContributor, // PV contributor while maxPVContributors < 1
RejMinDCAToPV, // |DCA| to mean vertex < minDCAToPV (and not a heavy ionizing particle)
RejShortITSOnly, // short ITS-only track (see mITSSAminNclu, mRejectITSonlyOBtrack)
NPoolRejections
};

// key of the mPoolRejections map: (vertexID << 32) | GIndex.getRaw()
static uint64_t getPoolRejectionKey(GIndex gid, int iv)
{
return (uint64_t(iv) << 32) | uint64_t(gid.getRaw());
}

// inverse of getPoolRejectionKey: returns the track GIndex and the vertex ID
static std::pair<GIndex, int> rejectionKey2GidIv(uint64_t k)
{
GIndex gid;
gid.setRaw(static_cast<GIndex::Base_t>(k & 0xffffffff));
return {gid, int(k >> 32)};
}

enum HypCascade {
XiMinus,
OmegaMinus,
Expand Down Expand Up @@ -123,6 +155,7 @@ class SVertexer
int getN3Bodies() const { return mN3Bodies; }
int getNStrangeTracks() const { return mNStrangeTracks; }
auto& getMeanVertex() const { return mMeanVertex; }
const auto& getPoolRejections() const { return mPoolRejections; } // empty unless compiled with _FILL_SV_POOL_REJECTIONS_
void setMeanVertex(const o2::dataformats::MeanVertexObject* v)
{
if (v == nullptr) {
Expand Down Expand Up @@ -158,7 +191,13 @@ class SVertexer
void setupThreads();
void buildT2V(const o2::globaltracking::RecoContainer& recoTracks);
void updateTimeDependentParams();
bool acceptTrack(const GIndex gid, const o2::track::TrackParCov& trc) const;
bool acceptTrack(const GIndex gid, const o2::track::TrackParCov& trc, PoolRejection& reason) const;
void flagPoolRejection(GIndex gid, int iv, PoolRejection reason)
{
#ifdef _FILL_SV_POOL_REJECTIONS_
mPoolRejections[getPoolRejectionKey(gid, iv)] |= uint16_t(0x1 << reason);
#endif
}
bool processTPCTrack(const o2::tpc::TrackTPC& trTPC, GIndex gid, int vtxid);
float correctTPCTrack(TrackCand& trc, const o2::tpc::TrackTPC& tTPC, float tmus, float tmusErr) const;

Expand Down Expand Up @@ -186,6 +225,7 @@ class SVertexer
std::vector<std::vector<Decay3BodyIndex>> m3bodyIdxTmp;
std::array<std::vector<TrackCand>, 2> mTracksPool{}; // pools of positive and negative seeds sorted in min VtxID
std::array<std::vector<int>, 2> mVtxFirstTrack{}; // 1st pos. and neg. track of the pools for each vertex
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)

o2::dataformats::VertexBase mMeanVertex{{0., 0., 0.}, {0.1 * 0.1, 0., 0.1 * 0.1, 0., 0., 6. * 6.}};
const SVertexerParams* mSVParams = nullptr;
Expand Down
14 changes: 12 additions & 2 deletions Detectors/Vertexing/src/SVertexer.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -416,9 +416,10 @@ void SVertexer::setupThreads()
}

//__________________________________________________________________
bool SVertexer::acceptTrack(const GIndex gid, const o2::track::TrackParCov& trc) const
bool SVertexer::acceptTrack(const GIndex gid, const o2::track::TrackParCov& trc, PoolRejection& reason) const
{
if (gid.isPVContributor() && mSVParams->maxPVContributors < 1) {
reason = RejPVContributor;
return false;
}

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

std::unordered_map<GIndex, std::pair<int, int>> tmap;
std::unordered_map<GIndex, bool> rejmap;
mPoolRejections.clear();
// The last entry is for unassigned tracks, ignore them. A timeframe holding no collision at
// all has no entry, and the subtraction would then wrap around.
int nv = vtxRefs.size() > 0 ? vtxRefs.size() - 1 : 0;
Expand All @@ -484,6 +487,7 @@ void SVertexer::buildT2V(const o2::globaltracking::RecoContainer& recoData) // a
}
if (tvid.getSource() == GIndex::TPC) {
if (mSVParams->mExcludeTPCtracks) {
flagPoolRejection(tvid, iv, RejTPCExcluded);
continue;
}
// unconstrained TPC tracks require special treatment: there is no point in checking DCA to mean vertex since it is not precise,
Expand Down Expand Up @@ -544,13 +548,16 @@ void SVertexer::buildT2V(const o2::globaltracking::RecoContainer& recoData) // a
nITSclu = itsABTracklet.getNClusters();
}
}
if (!acceptTrack(tvid, trc) && !heavyIonisingParticle) {
PoolRejection accReason{};
if (!acceptTrack(tvid, trc, accReason) && !heavyIonisingParticle) {
flagPoolRejection(tvid, iv, accReason);
if (tvid.isAmbiguous()) {
rejmap[tvid] = true;
}
continue;
}
if ((isTPCloaded && !hasTPC) && (isITSloaded && (nITSclu < mSVParams->mITSSAminNclu && (!shortOBITSOnlyTrack || mSVParams->mRejectITSonlyOBtrack)))) {
flagPoolRejection(tvid, iv, RejShortITSOnly);
continue; // reject short ITS-only
}

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

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

if (dCls || dDPV || dRD2) {
flagPoolRejection(gid, vtxid, dCls ? RejTPCPhotonNCls : (dDPV ? RejTPCPhotonDPV : RejTPCPhotonRD2));
mTracksPool[posneg].pop_back();
return true;
}
Expand Down