From b6b3c358985da4a16c60bb24f2f8b0510d8d307f Mon Sep 17 00:00:00 2001 From: Maximiliano Puccio Date: Tue, 3 Jun 2025 18:42:10 +0200 Subject: [PATCH 1/2] feat(kinkBuilder): use aod::BCs instead of aod::BCsWithTimestamps The changes in this commit update the usage of the aod::BCsWithTimestamps data source to the more generic aod::BCs data source. This simplifies the code and removes the need for the specific BCsWithTimestamps data source, which is no longer required. The changes ensure that the kinkBuilder functionality continues to work with the updated data source. --- PWGLF/TableProducer/Common/kinkBuilder.cxx | 21 ++++++++++----------- PWGLF/Utils/svPoolCreator.h | 18 +++++++++--------- 2 files changed, 19 insertions(+), 20 deletions(-) diff --git a/PWGLF/TableProducer/Common/kinkBuilder.cxx b/PWGLF/TableProducer/Common/kinkBuilder.cxx index f51e1ba1599..97cd0799669 100644 --- a/PWGLF/TableProducer/Common/kinkBuilder.cxx +++ b/PWGLF/TableProducer/Common/kinkBuilder.cxx @@ -247,7 +247,7 @@ struct kinkBuilder { } template - void fillCandidateData(const Tcolls& collisions, const Ttracks& tracks, aod::AmbiguousTracks const& ambiguousTracks, aod::BCsWithTimestamps const& bcs) + void fillCandidateData(const Tcolls& collisions, const Ttracks& tracks, aod::AmbiguousTracks const& ambiguousTracks, aod::BCs const& bcs) { svCreator.clearPools(); svCreator.fillBC2Coll(collisions, bcs); @@ -274,7 +274,7 @@ struct kinkBuilder { auto trackDaug = tracks.rawIteratorAt(svCand.tr1Idx); auto const& collision = trackMoth.template collision_as(); - auto const& bc = collision.template bc_as(); + auto const& bc = collision.template bc_as(); initCCDB(bc); o2::dataformats::VertexBase primaryVertex; @@ -401,34 +401,34 @@ struct kinkBuilder { } } - void initCCDB(aod::BCsWithTimestamps::iterator const& bc) + void initCCDB(aod::BCs::iterator const& bc) { if (mRunNumber == bc.runNumber()) { return; } - auto run3grp_timestamp = bc.timestamp(); + mRunNumber = bc.runNumber(); - o2::parameters::GRPObject* grpo = ccdb->getForTimeStamp(grpPath, run3grp_timestamp); + o2::parameters::GRPObject* grpo = ccdb->getForRun(grpPath, mRunNumber); o2::parameters::GRPMagField* grpmag = 0x0; if (grpo) { o2::base::Propagator::initFieldFromGRP(grpo); if (inputBz < -990) { // Fetch magnetic field from ccdb for current collision mBz = grpo->getNominalL3Field(); - LOG(info) << "Retrieved GRP for timestamp " << run3grp_timestamp << " with magnetic field of " << mBz << " kZG"; + LOG(info) << "Retrieved GRP for run " << mRunNumber << " with magnetic field of " << mBz << " kZG"; } else { mBz = inputBz; } } else { - grpmag = ccdb->getForTimeStamp(grpmagPath, run3grp_timestamp); + grpmag = ccdb->getForRun(grpmagPath, mRunNumber); if (!grpmag) { - LOG(fatal) << "Got nullptr from CCDB for path " << grpmagPath << " of object GRPMagField and " << grpPath << " of object GRPObject for timestamp " << run3grp_timestamp; + LOG(fatal) << "Got nullptr from CCDB for path " << grpmagPath << " of object GRPMagField and " << grpPath << " of object GRPObject for run " << mRunNumber; } o2::base::Propagator::initFieldFromGRP(grpmag); if (inputBz < -990) { // Fetch magnetic field from ccdb for current collision mBz = std::lround(5.f * grpmag->getL3Current() / 30000.f); - LOG(info) << "Retrieved GRP for timestamp " << run3grp_timestamp << " with magnetic field of " << mBz << " kZG"; + LOG(info) << "Retrieved GRP for run " << mRunNumber << " with magnetic field of " << mBz << " kZG"; } else { mBz = inputBz; } @@ -440,12 +440,11 @@ struct kinkBuilder { mBBparamsDaug[5] = cfgBetheBlochParams->get("Daughter", "resolution"); fitter.setBz(mBz); - mRunNumber = bc.runNumber(); o2::base::Propagator::Instance()->setMatLUT(lut); LOG(info) << "Task initialized for run " << mRunNumber << " with magnetic field " << mBz << " kZG"; } - void process(aod::Collisions const& collisions, TracksFull const& tracks, aod::AmbiguousTracks const& ambiTracks, aod::BCsWithTimestamps const& bcs) + void process(aod::Collisions const& collisions, TracksFull const& tracks, aod::AmbiguousTracks const& ambiTracks, aod::BCs const& bcs) { kinkCandidates.clear(); diff --git a/PWGLF/Utils/svPoolCreator.h b/PWGLF/Utils/svPoolCreator.h index 2414eb7e19b..25da298fe34 100644 --- a/PWGLF/Utils/svPoolCreator.h +++ b/PWGLF/Utils/svPoolCreator.h @@ -73,20 +73,20 @@ class svPoolCreator o2::vertexing::DCAFitterN<2>* getFitter() { return &fitter; } std::array, 4> getTrackCandPool() { return trackCandPool; } - template - void fillBC2Coll(const C& collisions, aod::BCsWithTimestamps const&) + template + void fillBC2Coll(const C& collisions, BC const&) { for (unsigned i = 0; i < collisions.size(); i++) { auto collision = collisions.rawIteratorAt(i); if (!collision.has_bc()) { continue; } - bc2Coll[collision.template bc_as().globalBC()] = i; + bc2Coll[collision.template bc_as().globalBC()] = i; } } - template - void appendTrackCand(const T& trackCand, const C& collisions, int pdgHypo, o2::aod::AmbiguousTracks const& ambiTracks, aod::BCsWithTimestamps const&) + template + void appendTrackCand(const T& trackCand, const C& collisions, int pdgHypo, o2::aod::AmbiguousTracks const& ambiTracks, BC const&) { if (pdgHypo != track0Pdg && pdgHypo != track1Pdg) { LOG(debug) << "Wrong pdg hypothesis"; @@ -97,18 +97,18 @@ class svPoolCreator uint64_t globalBC = BcInvalid; if (trackCand.has_collision()) { if (trackCand.template collision_as().has_bc()) { - globalBC = trackCand.template collision_as().template bc_as().globalBC(); + globalBC = trackCand.template collision_as().template bc_as().globalBC(); } } else if (!skipAmbiTracks) { for (const auto& ambTrack : ambiTracks) { if (ambTrack.trackId() != trackCand.globalIndex()) { continue; } - if (!ambTrack.has_bc() || ambTrack.bc_as().size() == 0) { + if (!ambTrack.has_bc() || ambTrack.bc_as().size() == 0) { globalBC = BcInvalid; break; } - globalBC = ambTrack.bc_as().begin().globalBC(); + globalBC = ambTrack.bc_as().begin().globalBC(); break; } } else { @@ -134,7 +134,7 @@ class svPoolCreator const auto& collision = collisions.rawIteratorAt(i); float collTime = collision.collisionTime(); float collTimeRes2 = collision.collisionTimeRes() * collision.collisionTimeRes(); - uint64_t collBC = collision.template bc_as().globalBC(); + uint64_t collBC = collision.template bc_as().globalBC(); int collIdx = collision.globalIndex(); int64_t bcOffset = globalBC - static_cast(collBC); if (static_cast(std::abs(bcOffset)) > bOffsetMax) { From 27d69bcc5cbe5fde96140d035997cedb18a2afc0 Mon Sep 17 00:00:00 2001 From: Maximiliano Puccio Date: Tue, 3 Jun 2025 20:04:03 +0200 Subject: [PATCH 2/2] Streamline magnetic field initialisation --- PWGLF/TableProducer/Common/kinkBuilder.cxx | 55 ++++++---------------- 1 file changed, 15 insertions(+), 40 deletions(-) diff --git a/PWGLF/TableProducer/Common/kinkBuilder.cxx b/PWGLF/TableProducer/Common/kinkBuilder.cxx index 97cd0799669..d2b25be26a0 100644 --- a/PWGLF/TableProducer/Common/kinkBuilder.cxx +++ b/PWGLF/TableProducer/Common/kinkBuilder.cxx @@ -122,12 +122,9 @@ struct kinkBuilder { Configurable unlikeSignBkg{"unlikeSignBkg", false, "Use unlike sign background"}; // CCDB options - Configurable inputBz{"inputBz", -999, "bz field, -999 is automatic"}; Configurable ccdbPath{"ccdbPath", "http://alice-ccdb.cern.ch", "url of the ccdb repository"}; - Configurable grpPath{"grpPath", "GLO/GRP/GRP", "Path of the grp file"}; Configurable grpmagPath{"grpmagPath", "GLO/Config/GRPMagField", "CCDB path of the GRPMagField object"}; Configurable lutPath{"lutPath", "GLO/Param/MatLUT", "Path of the Lut parametrization"}; - Configurable geoPath{"geoPath", "GLO/Config/GeometryAligned", "Path of the geometry file"}; // PDG codes @@ -174,7 +171,6 @@ struct kinkBuilder { ccdb->setURL(ccdbPath); ccdb->setCaching(true); ccdb->setLocalObjectValidityChecking(); - ccdb->setFatalWhenNull(false); fitter.setPropagateToPCA(true); fitter.setMaxR(200.); fitter.setMinParamChange(1e-3); @@ -183,10 +179,6 @@ struct kinkBuilder { fitter.setMaxChi2(1e9); fitter.setUseAbsDCA(true); - lut = o2::base::MatLayerCylSet::rectifyPtrFromFile(ccdb->get(lutPath)); - int mat{static_cast(cfgMaterialCorrection)}; - fitter.setMatCorrType(static_cast(mat)); - svCreator.setTimeMargin(customVertexerTimeMargin); if (skipAmbiTracks) { svCreator.setSkipAmbiTracks(); @@ -210,6 +202,11 @@ struct kinkBuilder { h2MothMassPt = qaRegistry.add("h2MothMassPt", "; p_{T} (GeV/#it{c}); m (GeV/#it{c}^{2})", HistType::kTH2F, {ptAxis, massAxis}); h2ClsMapPtMoth = qaRegistry.add("h2ClsMapPtMoth", "; p_{T} (GeV/#it{c}); ITS cluster map", HistType::kTH2F, {ptAxis, itsClusterMapAxis}); h2ClsMapPtDaug = qaRegistry.add("h2ClsMapPtDaug", "; p_{T} (GeV/#it{c}); ITS cluster map", HistType::kTH2F, {ptAxis, itsClusterMapAxis}); + + for (int i = 0; i < 5; i++) { + mBBparamsDaug[i] = cfgBetheBlochParams->get("Daughter", Form("p%i", i)); + } + mBBparamsDaug[5] = cfgBetheBlochParams->get("Daughter", "resolution"); } template @@ -283,9 +280,9 @@ struct kinkBuilder { kinkCand.primVtx = {primaryVertex.getX(), primaryVertex.getY(), primaryVertex.getZ()}; o2::track::TrackParCov trackParCovMoth = getTrackParCov(trackMoth); + o2::track::TrackParCov trackParCovMothPV{trackParCovMoth}; o2::base::Propagator::Instance()->PropagateToXBxByBz(trackParCovMoth, LayerRadii[trackMoth.itsNCls() - 1]); - o2::track::TrackParCov trackParCovMothPV = getTrackParCov(trackMoth); std::array dcaInfoMoth; o2::base::Propagator::Instance()->propagateToDCABxByBz({primaryVertex.getX(), primaryVertex.getY(), primaryVertex.getZ()}, trackParCovMothPV, 2.f, static_cast(cfgMaterialCorrection.value), &dcaInfoMoth); @@ -407,39 +404,17 @@ struct kinkBuilder { return; } mRunNumber = bc.runNumber(); + LOG(info) << "Initializing CCDB for run " << mRunNumber; + o2::parameters::GRPMagField* grpmag = ccdb->getForRun(grpmagPath, mRunNumber); + o2::base::Propagator::initFieldFromGRP(grpmag); + mBz = grpmag->getNominalL3Field(); + fitter.setBz(mBz); - o2::parameters::GRPObject* grpo = ccdb->getForRun(grpPath, mRunNumber); - o2::parameters::GRPMagField* grpmag = 0x0; - if (grpo) { - o2::base::Propagator::initFieldFromGRP(grpo); - if (inputBz < -990) { - // Fetch magnetic field from ccdb for current collision - mBz = grpo->getNominalL3Field(); - LOG(info) << "Retrieved GRP for run " << mRunNumber << " with magnetic field of " << mBz << " kZG"; - } else { - mBz = inputBz; - } - } else { - grpmag = ccdb->getForRun(grpmagPath, mRunNumber); - if (!grpmag) { - LOG(fatal) << "Got nullptr from CCDB for path " << grpmagPath << " of object GRPMagField and " << grpPath << " of object GRPObject for run " << mRunNumber; - } - o2::base::Propagator::initFieldFromGRP(grpmag); - if (inputBz < -990) { - // Fetch magnetic field from ccdb for current collision - mBz = std::lround(5.f * grpmag->getL3Current() / 30000.f); - LOG(info) << "Retrieved GRP for run " << mRunNumber << " with magnetic field of " << mBz << " kZG"; - } else { - mBz = inputBz; - } - } - - for (int i = 0; i < 5; i++) { - mBBparamsDaug[i] = cfgBetheBlochParams->get("Daughter", Form("p%i", i)); + if (!lut) { + lut = o2::base::MatLayerCylSet::rectifyPtrFromFile(ccdb->get(lutPath)); + int mat{static_cast(cfgMaterialCorrection)}; + fitter.setMatCorrType(static_cast(mat)); } - mBBparamsDaug[5] = cfgBetheBlochParams->get("Daughter", "resolution"); - - fitter.setBz(mBz); o2::base::Propagator::Instance()->setMatLUT(lut); LOG(info) << "Task initialized for run " << mRunNumber << " with magnetic field " << mBz << " kZG"; }