From 647fbadf95afad7e1e113706443afb74345801d2 Mon Sep 17 00:00:00 2001 From: Mattia Faggin Date: Thu, 27 Oct 2022 21:38:32 +0200 Subject: [PATCH] PWGHF: B field setting from CCDB. (#1393) --- .../HFCandidateCreator2Prong.cxx | 47 +++++++++- .../HFCandidateCreator3Prong.cxx | 47 +++++++++- .../HFTrackIndexSkimsCreator.cxx | 91 +++++++++++++------ PWGHF/Utils/utilsBfieldCCDB.h | 55 +++++++++++ 4 files changed, 206 insertions(+), 34 deletions(-) create mode 100644 PWGHF/Utils/utilsBfieldCCDB.h diff --git a/PWGHF/TableProducer/HFCandidateCreator2Prong.cxx b/PWGHF/TableProducer/HFCandidateCreator2Prong.cxx index e926b7e00b977..97b761dfa08e2 100644 --- a/PWGHF/TableProducer/HFCandidateCreator2Prong.cxx +++ b/PWGHF/TableProducer/HFCandidateCreator2Prong.cxx @@ -18,6 +18,7 @@ #include "Framework/AnalysisTask.h" #include "DetectorsVertexing/DCAFitterN.h" #include "PWGHF/DataModel/HFSecondaryVertex.h" +#include "PWGHF/Utils/utilsBfieldCCDB.h" #include "Common/Core/trackUtilities.h" #include "ReconstructionDataFormats/DCA.h" @@ -33,7 +34,7 @@ struct HFCandidateCreator2Prong { Produces rowCandidateBase; Configurable doPvRefit{"doPvRefit", false, "do PV refit excluding the candidate daughters, if contributors"}; - Configurable magneticField{"d_bz", 5., "magnetic field"}; + // Configurable magneticField{"d_bz", 5., "magnetic field"}; Configurable b_propdca{"b_propdca", true, "create tracks version propagated to PCA"}; Configurable d_maxr{"d_maxr", 200., "reject PCA's above this radius"}; Configurable d_maxdzini{"d_maxdzini", 4., "reject (if>0) PCA candidate if tracks DZ exceeds threshold"}; @@ -47,20 +48,46 @@ struct HFCandidateCreator2Prong { OutputObj hDcaXYProngs{TH2F("hDcaXYProngs", "DCAxy of 2-prong candidates;#it{p}_{T} (GeV/#it{c};#it{d}_{xy}) (#mum);entries", 100, 0., 20., 200, -500., 500.)}; OutputObj hDcaZProngs{TH2F("hDcaZProngs", "DCAz of 2-prong candidates;#it{p}_{T} (GeV/#it{c};#it{d}_{z}) (#mum);entries", 100, 0., 20., 200, -500., 500.)}; + /// magnetic field setting from CCDB + Configurable isRun2{"isRun2", false, "enable Run 2 or Run 3 GRP objects for magnetic field"}; + Configurable ccdbUrl{"ccdburl", "http://alice-ccdb.cern.ch", "url of the ccdb repository"}; + Configurable ccdbPathLut{"ccdbPathLut", "GLO/Param/MatLUT", "Path for LUT parametrization"}; + Configurable ccdbPathGeo{"ccdbPathGeo", "GLO/Config/GeometryAligned", "Path of the geometry file"}; + Configurable ccdbPathGrp{"ccdbPathGrp", "GLO/GRP/GRP", "Path of the grp file (Run 2)"}; + Configurable ccdbPathGrpMag{"ccdbPathGrpMag", "GLO/Config/GRPMagField", "CCDB path of the GRPMagField object (Run 3)"}; + Service ccdb; + o2::base::MatLayerCylSet* lut; + o2::base::Propagator::MatCorrType matCorr = o2::base::Propagator::MatCorrType::USEMatCorrLUT; + int runNumber; + float toMicrometers = 10000.; // from cm to µm double massPi = RecoDecay::getMassPDG(kPiPlus); double massK = RecoDecay::getMassPDG(kKPlus); double massPiK{0.}; double massKPi{0.}; + double magneticField = 0.; + + void init(InitContext const&) + { + ccdb->setURL(ccdbUrl); + ccdb->setCaching(true); + ccdb->setLocalObjectValidityChecking(); + lut = o2::base::MatLayerCylSet::rectifyPtrFromFile(ccdb->get(ccdbPathLut)); + if (!o2::base::GeometryManager::isGeometryLoaded()) { + ccdb->get(ccdbPathGeo); + } + runNumber = 0; + } void process(aod::Collisions const& collisions, soa::Join const& rowsTrackIndexProng2, - aod::BigTracks const& tracks) + aod::BigTracks const& tracks, + aod::BCsWithTimestamps const& bcWithTimeStamps) { // 2-prong vertex fitter o2::vertexing::DCAFitterN<2> df; - df.setBz(magneticField); + // df.setBz(magneticField); df.setPropagateToPCA(b_propdca); df.setMaxR(d_maxr); df.setMaxDZIni(d_maxdzini); @@ -76,6 +103,20 @@ struct HFCandidateCreator2Prong { auto trackParVarNeg1 = getTrackParCov(track1); auto collision = track0.collision(); + /// Set the magnetic field from ccdb. + /// The static instance of the propagator was already modified in the HFTrackIndexSkimCreator, + /// but this is not true when running on Run2 data/MC already converted into AO2Ds. + auto bc = track0.collision().bc_as(); + if (runNumber != bc.runNumber()) { + LOG(info) << ">>>>>>>>>>>> Current run number: " << runNumber; + initCCDB(bc, runNumber, ccdb, isRun2 ? ccdbPathGrp : ccdbPathGrpMag, lut, isRun2); + magneticField = o2::base::Propagator::Instance()->getNominalBz(); + LOG(info) << ">>>>>>>>>>>> Magnetic field: " << magneticField; + // df.setBz(magneticField); /// put it outside the 'if'! Otherwise we have a difference wrt bz Configurable (< 1 permille) in Run2 conv. data + // df.print(); + } + df.setBz(magneticField); + // reconstruct the 2-prong secondary vertex if (df.process(trackParVarPos1, trackParVarNeg1) == 0) { continue; diff --git a/PWGHF/TableProducer/HFCandidateCreator3Prong.cxx b/PWGHF/TableProducer/HFCandidateCreator3Prong.cxx index 55636cbbaa65b..7952b2fe63519 100644 --- a/PWGHF/TableProducer/HFCandidateCreator3Prong.cxx +++ b/PWGHF/TableProducer/HFCandidateCreator3Prong.cxx @@ -18,6 +18,7 @@ #include "Framework/AnalysisTask.h" #include "DetectorsVertexing/DCAFitterN.h" #include "PWGHF/DataModel/HFSecondaryVertex.h" +#include "PWGHF/Utils/utilsBfieldCCDB.h" #include "Common/Core/trackUtilities.h" #include "ReconstructionDataFormats/DCA.h" @@ -39,7 +40,7 @@ struct HFCandidateCreator3Prong { Produces rowCandidateBase; Configurable doPvRefit{"doPvRefit", false, "do PV refit excluding the candidate daughters, if contributors"}; - Configurable magneticField{"d_bz", 5., "magnetic field"}; + // Configurable magneticField{"d_bz", 5., "magnetic field"}; Configurable b_propdca{"b_propdca", true, "create tracks version propagated to PCA"}; Configurable d_maxr{"d_maxr", 200., "reject PCA's above this radius"}; Configurable d_maxdzini{"d_maxdzini", 4., "reject (if>0) PCA candidate if tracks DZ exceeds threshold"}; @@ -53,19 +54,45 @@ struct HFCandidateCreator3Prong { OutputObj hDcaXYProngs{TH2F("hDcaXYProngs", "DCAxy of 3-prong candidates;#it{p}_{T} (GeV/#it{c};#it{d}_{xy}) (#mum);entries", 100, 0., 20., 200, -500., 500.)}; OutputObj hDcaZProngs{TH2F("hDcaZProngs", "DCAz of 3-prong candidates;#it{p}_{T} (GeV/#it{c};#it{d}_{z}) (#mum);entries", 100, 0., 20., 200, -500., 500.)}; + /// magnetic field setting from CCDB + Configurable isRun2{"isRun2", false, "enable Run 2 or Run 3 GRP objects for magnetic field"}; + Configurable ccdbUrl{"ccdburl", "http://alice-ccdb.cern.ch", "url of the ccdb repository"}; + Configurable ccdbPathLut{"ccdbPathLut", "GLO/Param/MatLUT", "Path for LUT parametrization"}; + Configurable ccdbPathGeo{"ccdbPathGeo", "GLO/Config/GeometryAligned", "Path of the geometry file"}; + Configurable ccdbPathGrp{"ccdbPathGrp", "GLO/GRP/GRP", "Path of the grp file (Run 2)"}; + Configurable ccdbPathGrpMag{"ccdbPathGrpMag", "GLO/Config/GRPMagField", "CCDB path of the GRPMagField object (Run 3)"}; + Service ccdb; + o2::base::MatLayerCylSet* lut; + o2::base::Propagator::MatCorrType matCorr = o2::base::Propagator::MatCorrType::USEMatCorrLUT; + int runNumber; + float toMicrometers = 10000.; // from cm to µm double massPi = RecoDecay::getMassPDG(kPiPlus); double massK = RecoDecay::getMassPDG(kKPlus); double massPiKPi{0.}; + double magneticField = 0.; + + void init(InitContext const&) + { + ccdb->setURL(ccdbUrl); + ccdb->setCaching(true); + ccdb->setLocalObjectValidityChecking(); + lut = o2::base::MatLayerCylSet::rectifyPtrFromFile(ccdb->get(ccdbPathLut)); + if (!o2::base::GeometryManager::isGeometryLoaded()) { + ccdb->get(ccdbPathGeo); + } + runNumber = 0; + } void process(aod::Collisions const& collisions, soa::Join const& rowsTrackIndexProng3, - aod::BigTracks const& tracks) + aod::BigTracks const& tracks, + aod::BCsWithTimestamps const& bcWithTimeStamps) { // 3-prong vertex fitter o2::vertexing::DCAFitterN<3> df; - df.setBz(magneticField); + // df.setBz(magneticField); df.setPropagateToPCA(b_propdca); df.setMaxR(d_maxr); df.setMaxDZIni(d_maxdzini); @@ -83,6 +110,20 @@ struct HFCandidateCreator3Prong { auto trackParVar2 = getTrackParCov(track2); auto collision = track0.collision(); + /// Set the magnetic field from ccdb. + /// The static instance of the propagator was already modified in the HFTrackIndexSkimCreator, + /// but this is not true when running on Run2 data/MC already converted into AO2Ds. + auto bc = track0.collision().bc_as(); + if (runNumber != bc.runNumber()) { + LOG(info) << ">>>>>>>>>>>> Current run number: " << runNumber; + initCCDB(bc, runNumber, ccdb, isRun2 ? ccdbPathGrp : ccdbPathGrpMag, lut, isRun2); + magneticField = o2::base::Propagator::Instance()->getNominalBz(); + LOG(info) << ">>>>>>>>>>>> Magnetic field: " << magneticField; + // df.setBz(magneticField); /// put it outside the 'if'! Otherwise we have a difference wrt bz Configurable (< 1 permille) in Run2 conv. data + // df.print(); + } + df.setBz(magneticField); + // reconstruct the 3-prong secondary vertex if (df.process(trackParVar0, trackParVar1, trackParVar2) == 0) { continue; diff --git a/PWGHF/TableProducer/HFTrackIndexSkimsCreator.cxx b/PWGHF/TableProducer/HFTrackIndexSkimsCreator.cxx index 6366a451ba959..b3120d2d667ee 100644 --- a/PWGHF/TableProducer/HFTrackIndexSkimsCreator.cxx +++ b/PWGHF/TableProducer/HFTrackIndexSkimsCreator.cxx @@ -35,6 +35,7 @@ #include "DetectorsBase/Propagator.h" // for PV refit #include "DetectorsBase/GeometryManager.h" // for PV refit #include "DataFormatsParameters/GRPMagField.h" // for PV refit +#include "PWGHF/Utils/utilsBfieldCCDB.h" #include @@ -257,7 +258,7 @@ struct HfTagSelTracks { Configurable fillHistograms{"fillHistograms", true, "fill histograms"}; Configurable debug{"debug", true, "debug mode"}; - Configurable bz{"bz", 5., "bz field"}; + // Configurable bz{"bz", 5., "bz field"}; Configurable doPvRefit{"doPvRefit", false, "do PV refit excluding the considered track"}; Configurable isRun2{"isRun2", false, "enable Run 2 or Run 3 GRP objects for magnetic field"}; // quality cut @@ -286,7 +287,8 @@ struct HfTagSelTracks { Configurable ccdbUrl{"ccdburl", "http://alice-ccdb.cern.ch", "url of the ccdb repository"}; Configurable ccdbPathLut{"ccdbPathLut", "GLO/Param/MatLUT", "Path for LUT parametrization"}; Configurable ccdbPathGeo{"ccdbPathGeo", "GLO/Config/GeometryAligned", "Path of the geometry file"}; - Configurable ccdbPathGrp{"ccdbPathGrp", "GLO/Config/GRPMagField", "CCDB path of the GRPMagField object"}; + Configurable ccdbPathGrp{"ccdbPathGrp", "GLO/GRP/GRP", "Path of the grp file (Run 2)"}; + Configurable ccdbPathGrpMag{"ccdbPathGrpMag", "GLO/Config/GRPMagField", "CCDB path of the GRPMagField object (Run 3)"}; // for debugging #ifdef MY_DEBUG @@ -298,8 +300,8 @@ struct HfTagSelTracks { // Needed for PV refitting Service ccdb; o2::base::MatLayerCylSet* lut; - // o2::base::Propagator::MatCorrType matCorr = o2::base::Propagator::MatCorrType::USEMatCorrLUT; - int mRunNumber; + o2::base::Propagator::MatCorrType matCorr = o2::base::Propagator::MatCorrType::USEMatCorrLUT; + int runNumber; HistogramRegistry registry{ "registry", @@ -369,7 +371,7 @@ struct HfTagSelTracks { if (!o2::base::GeometryManager::isGeometryLoaded()) { ccdb->get(ccdbPathGeo); } - mRunNumber = 0; + runNumber = 0; } } @@ -415,10 +417,10 @@ struct HfTagSelTracks { std::vector vecPvRefitContributorUsed(vecPvContributorGlobId.size(), true); /// Prepare the vertex refitting - // Get the magnetic field for the Propagator - o2::base::Propagator::MatCorrType matCorr = o2::base::Propagator::MatCorrType::USEMatCorrLUT; + // set the magnetic field from CCDB auto bc = collision.bc_as(); - if (mRunNumber != bc.runNumber()) { + initCCDB(bc, runNumber, ccdb, isRun2 ? ccdbPathGrp : ccdbPathGrpMag, lut, isRun2); + /*if (runNumber != bc.runNumber()) { if (isRun2) { // Run 2 GRP object o2::parameters::GRPObject* grpo = ccdb->getForTimeStamp(ccdbPathGrp, bc.timestamp()); @@ -430,7 +432,7 @@ struct HfTagSelTracks { LOGF(fatal, "Run 2 GRP object (type o2::parameters::GRPObject) is not available in CCDB for run=%d at timestamp=%llu", bc.runNumber(), bc.timestamp()); } } else { // Run 3 GRP object - o2::parameters::GRPMagField* grpo = ccdb->getForTimeStamp(ccdbPathGrp, bc.timestamp()); + o2::parameters::GRPMagField* grpo = ccdb->getForTimeStamp(ccdbPathGrpMag, bc.timestamp()); if (grpo != nullptr) { o2::base::Propagator::initFieldFromGRP(grpo); o2::base::Propagator::Instance()->setMatLUT(lut); @@ -440,8 +442,8 @@ struct HfTagSelTracks { } } - mRunNumber = bc.runNumber(); - } + runNumber = bc.runNumber(); + }*/ // build the VertexBase to initialize the vertexer o2::dataformats::VertexBase primVtx; @@ -847,7 +849,7 @@ struct HfTrackIndexSkimsCreator { // preselection parameters Configurable pTTolerance{"pTTolerance", 0.1, "pT tolerance in GeV/c for applying preselections before vertex reconstruction"}; // vertexing parameters - Configurable bz{"bz", 5., "magnetic field kG"}; + // Configurable bz{"bz", 5., "magnetic field kG"}; Configurable propToDCA{"propToDCA", true, "create tracks version propagated to PCA"}; Configurable useAbsDCA{"useAbsDCA", true, "Minimise abs. distance rather than chi2"}; Configurable maxRad{"maxRad", 200., "reject PCA's above this radius"}; @@ -882,13 +884,14 @@ struct HfTrackIndexSkimsCreator { Configurable ccdbUrl{"ccdburl", "http://alice-ccdb.cern.ch", "url of the ccdb repository"}; Configurable ccdbPathLut{"ccdbPathLut", "GLO/Param/MatLUT", "Path for LUT parametrization"}; Configurable ccdbPathGeo{"ccdbPathGeo", "GLO/Config/GeometryAligned", "Path of the geometry file"}; - Configurable ccdbPathGrp{"ccdbPathGrp", "GLO/Config/GRPMagField", "CCDB path of the GRPMagField object"}; + Configurable ccdbPathGrp{"ccdbPathGrp", "GLO/GRP/GRP", "Path of the grp file (Run 2)"}; + Configurable ccdbPathGrpMag{"ccdbPathGrpMag", "GLO/Config/GRPMagField", "CCDB path of the GRPMagField object (Run 3)"}; // Needed for PV refitting Service ccdb; o2::base::MatLayerCylSet* lut; - // o2::base::Propagator::MatCorrType matCorr = o2::base::Propagator::MatCorrType::USEMatCorrLUT; - int mRunNumber; + o2::base::Propagator::MatCorrType matCorr = o2::base::Propagator::MatCorrType::USEMatCorrLUT; + int runNumber; HistogramRegistry registry{ "registry", @@ -993,7 +996,7 @@ struct HfTrackIndexSkimsCreator { if (!o2::base::GeometryManager::isGeometryLoaded()) { ccdb->get(ccdbPathGeo); } - mRunNumber = 0; + runNumber = 0; } } @@ -1279,10 +1282,10 @@ struct HfTrackIndexSkimsCreator { std::vector vecPvRefitContributorUsed(vecPvContributorGlobId.size(), true); /// Prepare the vertex refitting - // Get the magnetic field for the Propagator - // o2::base::Propagator::MatCorrType matCorr = o2::base::Propagator::MatCorrType::USEMatCorrLUT; + // set the magnetic field from CCDB auto bc = collision.bc_as(); - if (mRunNumber != bc.runNumber()) { + initCCDB(bc, runNumber, ccdb, isRun2 ? ccdbPathGrp : ccdbPathGrpMag, lut, isRun2); + /*if (runNumber != bc.runNumber()) { if (isRun2) { // Run 2 GRP object o2::parameters::GRPObject* grpo = ccdb->getForTimeStamp(ccdbPathGrp, bc.timestamp()); @@ -1294,7 +1297,7 @@ struct HfTrackIndexSkimsCreator { LOGF(fatal, "Run 2 GRP object (type o2::parameters::GRPObject) is not available in CCDB for run=%d at timestamp=%llu", bc.runNumber(), bc.timestamp()); } } else { // Run 3 GRP object - o2::parameters::GRPMagField* grpo = ccdb->getForTimeStamp(ccdbPathGrp, bc.timestamp()); + o2::parameters::GRPMagField* grpo = ccdb->getForTimeStamp(ccdbPathGrpMag, bc.timestamp()); if (grpo != nullptr) { o2::base::Propagator::initFieldFromGRP(grpo); o2::base::Propagator::Instance()->setMatLUT(lut); @@ -1304,8 +1307,8 @@ struct HfTrackIndexSkimsCreator { } } - mRunNumber = bc.runNumber(); - } + runNumber = bc.runNumber(); + }*/ // build the VertexBase to initialize the vertexer o2::dataformats::VertexBase primVtx; @@ -1491,9 +1494,13 @@ struct HfTrackIndexSkimsCreator { int whichHypo2Prong[n2ProngDecays]; int whichHypo3Prong[n3ProngDecays]; + // set the magnetic field from CCDB + auto bc = collision.bc_as(); + initCCDB(bc, runNumber, ccdb, isRun2 ? ccdbPathGrp : ccdbPathGrpMag, lut, isRun2); + // 2-prong vertex fitter o2::vertexing::DCAFitterN<2> df2; - df2.setBz(bz); + df2.setBz(o2::base::Propagator::Instance()->getNominalBz()); df2.setPropagateToPCA(propToDCA); df2.setMaxR(maxRad); df2.setMaxDZIni(maxDZIni); @@ -1503,7 +1510,7 @@ struct HfTrackIndexSkimsCreator { // 3-prong vertex fitter o2::vertexing::DCAFitterN<3> df3; - df3.setBz(bz); + df3.setBz(o2::base::Propagator::Instance()->getNominalBz()); df3.setPropagateToPCA(propToDCA); df3.setMaxR(maxRad); df3.setMaxDZIni(maxDZIni); @@ -2145,7 +2152,7 @@ struct HfTrackIndexSkimsCreatorCascades { // Configurable triggerindex{"triggerindex", -1, "trigger index"}; // vertexing parameters - Configurable bZ{"bZ", 5., "magnetic field"}; + // Configurable bZ{"bZ", 5., "magnetic field"}; Configurable propDCA{"propDCA", true, "create tracks version propagated to PCA"}; Configurable maxR{"maxR", 200., "reject PCA's above this radius"}; Configurable maxDZIni{"maxDZIni", 4., "reject (if>0) PCA candidate if tracks DZ exceeds threshold"}; @@ -2183,6 +2190,18 @@ struct HfTrackIndexSkimsCreatorCascades { Configurable cutCascInvMassLc{"cutCascInvMassLc", 1., "Lc candidate invariant mass difference wrt PDG"}; // for PbPb 2018: use 0.2 // Configurable cutCascDCADaughters{"cutCascDCADaughters", .1, "DCA between V0 and bachelor in cascade"}; + // magnetic field setting from CCDB + Configurable isRun2{"isRun2", false, "enable Run 2 or Run 3 GRP objects for magnetic field"}; + Configurable ccdbUrl{"ccdburl", "http://alice-ccdb.cern.ch", "url of the ccdb repository"}; + Configurable ccdbPathLut{"ccdbPathLut", "GLO/Param/MatLUT", "Path for LUT parametrization"}; + Configurable ccdbPathGeo{"ccdbPathGeo", "GLO/Config/GeometryAligned", "Path of the geometry file"}; + Configurable ccdbPathGrp{"ccdbPathGrp", "GLO/GRP/GRP", "Path of the grp file (Run 2)"}; + Configurable ccdbPathGrpMag{"ccdbPathGrpMag", "GLO/Config/GRPMagField", "CCDB path of the GRPMagField object (Run 3)"}; + Service ccdb; + o2::base::MatLayerCylSet* lut; + o2::base::Propagator::MatCorrType matCorr = o2::base::Propagator::MatCorrType::USEMatCorrLUT; + int runNumber; + // for debugging #ifdef MY_DEBUG Configurable> indexK0Spos{"indexK0Spos", {729, 2866, 4754, 5457, 6891, 7824, 9243, 9810}, "indices of K0S positive daughters, for debug"}; @@ -2208,6 +2227,18 @@ struct HfTrackIndexSkimsCreatorCascades { double massLc = RecoDecay::getMassPDG(pdg::Code::kLambdaCPlus); double mass2K0sP{0.}; // WHY HERE? + void init(InitContext const&) + { + ccdb->setURL(ccdbUrl); + ccdb->setCaching(true); + ccdb->setLocalObjectValidityChecking(); + lut = o2::base::MatLayerCylSet::rectifyPtrFromFile(ccdb->get(ccdbPathLut)); + if (!o2::base::GeometryManager::isGeometryLoaded()) { + ccdb->get(ccdbPathGeo); + } + runNumber = 0; + } + Filter filterSelectCollisions = (aod::hf_selcollision::whyRejectColl == 0); using SelectedCollisions = soa::Filtered>; @@ -2225,9 +2256,13 @@ struct HfTrackIndexSkimsCreatorCascades { ) // TODO: I am now assuming that the V0s are already filtered with my cuts (David's work to come) { + // set the magnetic field from CCDB + auto bc = collision.bc_as(); + initCCDB(bc, runNumber, ccdb, isRun2 ? ccdbPathGrp : ccdbPathGrpMag, lut, isRun2); + // Define o2 fitter, 2-prong o2::vertexing::DCAFitterN<2> fitter; - fitter.setBz(bZ); + fitter.setBz(o2::base::Propagator::Instance()->getNominalBz()); fitter.setPropagateToPCA(propDCA); fitter.setMaxR(maxR); fitter.setMinParamChange(minParamChange); @@ -2342,9 +2377,9 @@ struct HfTrackIndexSkimsCreatorCascades { MY_DEBUG_MSG(isK0SfromLc, LOG(info) << "KEPT! K0S from Lc with daughters " << indexV0DaughPos << " and " << indexV0DaughNeg); auto trackParCovV0DaughPos = getTrackParCov(trackV0DaughPos); - trackParCovV0DaughPos.propagateTo(v0.posX(), bZ); // propagate the track to the X closest to the V0 vertex + trackParCovV0DaughPos.propagateTo(v0.posX(), o2::base::Propagator::Instance()->getNominalBz()); // propagate the track to the X closest to the V0 vertex auto trackParCovV0DaughNeg = getTrackParCov(trackV0DaughNeg); - trackParCovV0DaughNeg.propagateTo(v0.negX(), bZ); // propagate the track to the X closest to the V0 vertex + trackParCovV0DaughNeg.propagateTo(v0.negX(), o2::base::Propagator::Instance()->getNominalBz()); // propagate the track to the X closest to the V0 vertex std::array pVecV0 = {0., 0., 0.}; std::array pVecBach = {0., 0., 0.}; diff --git a/PWGHF/Utils/utilsBfieldCCDB.h b/PWGHF/Utils/utilsBfieldCCDB.h new file mode 100644 index 0000000000000..b7092bbcf7b82 --- /dev/null +++ b/PWGHF/Utils/utilsBfieldCCDB.h @@ -0,0 +1,55 @@ +// Copyright 2019-2020 CERN and copyright holders of ALICE O2. +// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders. +// All rights not expressly granted are reserved. +// +// This software is distributed under the terms of the GNU General Public +// License v3 (GPL Version 3), copied verbatim in the file "COPYING". +// +// In applying this license CERN does not waive the privileges and immunities +// granted to it by virtue of its status as an Intergovernmental Organization +// or submit itself to any jurisdiction. + +/// \file utilsBfieldCCDB.h +/// \brief Utility to set the B field in analysis querying it from CCDB +/// \author Mattia Faggin , University and INFN Padova, Italy + +#include "CCDB/BasicCCDBManager.h" +#include "DataFormatsParameters/GRPObject.h" +#include "DataFormatsParameters/GRPMagField.h" +#include "DetectorsBase/GeometryManager.h" + +/// \brief Sets up the grp object for magnetic field (w/o matCorr for propagation) +/// \param bc is the bunch crossing +/// \param mRunNumber is an int with the run umber of the previous iteration. If at the current iteration it changes, then the grp object is updated +/// \param ccdb is the o2::ccdb::BasicCCDBManager object +/// \param ccdbPathGrp is the path where the GRP oject is stored +/// \param lut is a pointer to the o2::base::MatLayerCylSet object +/// \param isRun2 tells whether we are analysing Run2 converted data or not (different GRP object type) +void initCCDB(o2::aod::BCsWithTimestamps::iterator const& bc, int& mRunNumber, + o2::framework::Service const& ccdb, std::string ccdbPathGrp, o2::base::MatLayerCylSet* lut, + bool isRun2) +{ + + if (mRunNumber != bc.runNumber()) { + + LOGF(info, "====== initCCDB function called (isRun2==%d)", isRun2); + if (isRun2) { // Run 2 GRP object + o2::parameters::GRPObject* grpo = ccdb->getForTimeStamp(ccdbPathGrp, bc.timestamp()); + if (grpo == nullptr) { + LOGF(fatal, "Run 2 GRP object (type o2::parameters::GRPObject) is not available in CCDB for run=%d at timestamp=%llu", bc.runNumber(), bc.timestamp()); + } + o2::base::Propagator::initFieldFromGRP(grpo); + o2::base::Propagator::Instance()->setMatLUT(lut); + LOGF(info, "Setting magnetic field to %d kG for run %d from its GRP CCDB object (type o2::parameters::GRPObject)", grpo->getNominalL3Field(), bc.runNumber()); + } else { // Run 3 GRP object + o2::parameters::GRPMagField* grpo = ccdb->getForTimeStamp(ccdbPathGrp, bc.timestamp()); + if (grpo == nullptr) { + LOGF(fatal, "Run 3 GRP object (type o2::parameters::GRPMagField) is not available in CCDB for run=%d at timestamp=%llu", bc.runNumber(), bc.timestamp()); + } + o2::base::Propagator::initFieldFromGRP(grpo); + o2::base::Propagator::Instance()->setMatLUT(lut); + LOGF(info, "Setting magnetic field to current %f A for run %d from its GRP CCDB object (type o2::parameters::GRPMagField)", grpo->getL3Current(), bc.runNumber()); + } + mRunNumber = bc.runNumber(); + } +} /// end initCCDB \ No newline at end of file