diff --git a/DataFormats/Reconstruction/include/ReconstructionDataFormats/DecayNBodyIndex.h b/DataFormats/Reconstruction/include/ReconstructionDataFormats/DecayNBodyIndex.h index 5a5a8a9e64cca..001d54db1832b 100644 --- a/DataFormats/Reconstruction/include/ReconstructionDataFormats/DecayNBodyIndex.h +++ b/DataFormats/Reconstruction/include/ReconstructionDataFormats/DecayNBodyIndex.h @@ -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 diff --git a/DataFormats/Reconstruction/src/ReconstructionDataFormatsLinkDef.h b/DataFormats/Reconstruction/src/ReconstructionDataFormatsLinkDef.h index b386830d9872d..16e672aac5b6e 100644 --- a/DataFormats/Reconstruction/src/ReconstructionDataFormatsLinkDef.h +++ b/DataFormats/Reconstruction/src/ReconstructionDataFormatsLinkDef.h @@ -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>> + ; diff --git a/Detectors/GlobalTrackingWorkflow/readers/src/SecondaryVertexReaderSpec.cxx b/Detectors/GlobalTrackingWorkflow/readers/src/SecondaryVertexReaderSpec.cxx index 68d3f31313c56..938ee2407af5a 100644 --- a/Detectors/GlobalTrackingWorkflow/readers/src/SecondaryVertexReaderSpec.cxx +++ b/Detectors/GlobalTrackingWorkflow/readers/src/SecondaryVertexReaderSpec.cxx @@ -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; @@ -64,6 +65,8 @@ class SecondaryVertexReader : public o2::framework::Task std::vector m3BodysIdx, *m3BodysIdxPtr = &m3BodysIdx; std::vector m3Bodys, *m3BodysPtr = &m3Bodys; std::vector mPV23BodyRef, *mPV23BodyRefPtr = &mPV23BodyRef; + std::vector mPoolRej, *mPoolRejPtr = &mPoolRej; // optional, stays empty if the branch is absent + bool mHasPoolRej = false; std::unique_ptr mFile; std::unique_ptr mTree; @@ -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) @@ -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().maxInputTimeslices >= mTree->GetEntries()) { pc.services().get().endOfStream(); @@ -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"; } @@ -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", diff --git a/Detectors/GlobalTrackingWorkflow/src/SecondaryVertexWriterSpec.cxx b/Detectors/GlobalTrackingWorkflow/src/SecondaryVertexWriterSpec.cxx index 7f961536cf1f2..d0cb003654da8 100644 --- a/Detectors/GlobalTrackingWorkflow/src/SecondaryVertexWriterSpec.cxx +++ b/Detectors/GlobalTrackingWorkflow/src/SecondaryVertexWriterSpec.cxx @@ -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 using BranchDefinition = MakeRootTreeWriterSpec::BranchDefinition; @@ -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", @@ -77,7 +79,9 @@ DataProcessorSpec getSecondaryVertexWriterSpec() BranchDefinition>{inp3BodyID, "Decays3BodyID", loggerD}, BranchDefinition>{inp3Body, "Decays3Body"}, - BranchDefinition>{inp3BodyRef, "PV23BodyRefs"})(); + BranchDefinition>{inp3BodyRef, "PV23BodyRefs"}, + + BranchDefinition>{inpPoolRej, "PoolRejections"})(); } } // namespace vertexing diff --git a/Detectors/GlobalTrackingWorkflow/src/SecondaryVertexingSpec.cxx b/Detectors/GlobalTrackingWorkflow/src/SecondaryVertexingSpec.cxx index 406b780e28a15..15ec0b0e7ba43 100644 --- a/Detectors/GlobalTrackingWorkflow/src/SecondaryVertexingSpec.cxx +++ b/Detectors/GlobalTrackingWorkflow/src/SecondaryVertexingSpec.cxx @@ -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>(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", @@ -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{ diff --git a/Detectors/Vertexing/include/DetectorsVertexing/SVertexer.h b/Detectors/Vertexing/include/DetectorsVertexing/SVertexer.h index 4d783b0018fc3..e7f19e64c40d3 100644 --- a/Detectors/Vertexing/include/DetectorsVertexing/SVertexer.h +++ b/Detectors/Vertexing/include/DetectorsVertexing/SVertexer.h @@ -33,10 +33,14 @@ #include "StrangenessTracking/StrangenessTracker.h" #include "DataFormatsTPC/TrackTPC.h" #include +#include #include #include "GPUO2InterfaceRefit.h" #include "DataFormatsTPC/PIDResponse.h" +// uncomment this to enable filling rejection records +// #define _FILL_SV_POOL_REJECTIONS_ + namespace o2 { namespace tpc @@ -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 rejectionKey2GidIv(uint64_t k) + { + GIndex gid; + gid.setRaw(static_cast(k & 0xffffffff)); + return {gid, int(k >> 32)}; + } + enum HypCascade { XiMinus, OmegaMinus, @@ -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) { @@ -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; @@ -186,6 +225,7 @@ class SVertexer std::vector> m3bodyIdxTmp; std::array, 2> mTracksPool{}; // pools of positive and negative seeds sorted in min VtxID std::array, 2> mVtxFirstTrack{}; // 1st pos. and neg. track of the pools for each vertex + std::unordered_map mPoolRejections{}; // key: (vertexID << 32) | GIndex.getRaw(); value: bit pattern (0x1<maxPVContributors < 1) { + reason = RejPVContributor; return false; } @@ -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; } } @@ -466,6 +468,7 @@ void SVertexer::buildT2V(const o2::globaltracking::RecoContainer& recoData) // a std::unordered_map> tmap; std::unordered_map 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; @@ -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, @@ -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 } @@ -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. @@ -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; } @@ -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; }