Skip to content

Commit 97775fd

Browse files
nmallick19alibuild
andauthored
[PWGCF] Run 3 Magnetic Field Path and configurable added (#17782)
Co-authored-by: ALICE Action Bot <alibuild@cern.ch>
1 parent e0461a8 commit 97775fd

1 file changed

Lines changed: 30 additions & 15 deletions

File tree

PWGCF/Tasks/correlations.cxx

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <CCDB/BasicCCDBManager.h>
2727
#include <CommonConstants/MathConstants.h>
2828
#include <CommonConstants/PhysicsConstants.h>
29+
#include <DataFormatsParameters/GRPMagField.h>
2930
#include <DataFormatsParameters/GRPObject.h>
3031
#include <Framework/AnalysisDataModel.h>
3132
#include <Framework/AnalysisHelpers.h>
@@ -114,6 +115,7 @@ struct CorrelationTask {
114115

115116
O2_DEFINE_CONFIGURABLE(cfgEfficiencyTrigger, std::string, "", "CCDB path to efficiency object for trigger particles")
116117
O2_DEFINE_CONFIGURABLE(cfgEfficiencyAssociated, std::string, "", "CCDB path to efficiency object for associated particles")
118+
O2_DEFINE_CONFIGURABLE(cfgUseRun3MagField, bool, false, "false: Run 2 GRPObject; true: Run 3 GRPMagField")
117119

118120
O2_DEFINE_CONFIGURABLE(cfgNoMixedEvents, int, 5, "Number of mixed events per event")
119121
O2_DEFINE_CONFIGURABLE(cfgRejectMixedPhiProngEvents, bool, true, "Reject associated hadrons from either mixed-phi prong event")
@@ -186,6 +188,8 @@ struct CorrelationTask {
186188
PairCuts mPairCuts;
187189

188190
Service<o2::ccdb::BasicCCDBManager> ccdb;
191+
int mCachedRunNumber{-1}; // cached run number for magnetic field -- to avoid re-fetching the magnetic field for the same run, assuming that the magnetic field remains the same for the same run
192+
int mCachedMagField{0}; // cached magnetic field --reduces number of calls to the CCDB
189193

190194
using AodCollisions = soa::Filtered<soa::Join<aod::Collisions, aod::EvSels, aod::CentRun2V0Ms>>;
191195
using AodTracks = soa::Filtered<soa::Join<aod::Tracks, aod::TrackSelection>>;
@@ -331,21 +335,32 @@ struct CorrelationTask {
331335
ccdb->setCreatedNotAfter(now); // TODO must become global parameter from the train creation time
332336
}
333337

334-
int getMagneticField(uint64_t timestamp)
338+
int getMagneticField(int runNumber, uint64_t timestamp)
335339
{
336-
// TODO done only once (and not per run). Will be replaced by CCDBConfigurable
337-
static o2::parameters::GRPObject* grpo = nullptr;
338-
// static o2::parameters::GRPMagField* grpo = nullptr;
339-
if (grpo == nullptr) {
340-
grpo = ccdb->getForTimeStamp<o2::parameters::GRPObject>("GLO/GRP/GRP", timestamp);
341-
// grpo = ccdb->getForTimeStamp<o2::parameters::GRPMagField>("GLO/Config/GRPMagField", timestamp);
340+
static constexpr const char* kGRPPathRun2 = "GLO/GRP/GRP"; // fixed path for now, can be made into a config
341+
static constexpr const char* kGRPPathRun3 = "GLO/Config/GRPMagField"; // fixed path for now, can be made into a config
342+
343+
if (runNumber == mCachedRunNumber) {
344+
return mCachedMagField;
345+
}
346+
347+
if (cfgUseRun3MagField) {
348+
auto* grpmag = ccdb->getForTimeStamp<o2::parameters::GRPMagField>(kGRPPathRun3, timestamp);
349+
if (grpmag == nullptr) {
350+
LOGF(fatal, "Run 3 GRPMagField not found at %s for run %d timestamp %llu", kGRPPathRun3, runNumber, timestamp);
351+
}
352+
mCachedMagField = grpmag->getNominalL3Field();
353+
} else {
354+
auto* grpo = ccdb->getForTimeStamp<o2::parameters::GRPObject>(kGRPPathRun2, timestamp);
342355
if (grpo == nullptr) {
343-
LOGF(fatal, "GRP object not found for timestamp %llu", timestamp);
344-
return 0;
356+
LOGF(fatal, "Run 2 GRPObject not found at %s for run %d timestamp %llu", kGRPPathRun2, runNumber, timestamp);
345357
}
346-
LOGF(info, "Retrieved GRP for timestamp %llu with magnetic field of %d kG", timestamp, grpo->getNominalL3Field());
358+
mCachedMagField = grpo->getNominalL3Field();
347359
}
348-
return grpo->getNominalL3Field();
360+
361+
mCachedRunNumber = runNumber;
362+
LOGF(info, "Run %d: magnetic field %d kG", runNumber, mCachedMagField);
363+
return mCachedMagField;
349364
}
350365

351366
template <class p2typeIterator>
@@ -894,7 +909,7 @@ struct CorrelationTask {
894909
}
895910
registry.fill(HIST("eventcount_same"), -2);
896911
fillQA(collision, multiplicity, tracks);
897-
fillCorrelations<CorrelationContainer::kCFStepReconstructed>(same, tracks, tracks, multiplicity, collision.posZ(), getMagneticField(bc.timestamp()), 1.0f);
912+
fillCorrelations<CorrelationContainer::kCFStepReconstructed>(same, tracks, tracks, multiplicity, collision.posZ(), getMagneticField(bc.runNumber(), bc.timestamp()), 1.0f);
898913
}
899914
PROCESS_SWITCH(CorrelationTask, processSameAOD, "Process same event on AOD", true);
900915

@@ -911,7 +926,7 @@ struct CorrelationTask {
911926
const auto multiplicity = collision.multiplicity();
912927
int field = 0;
913928
if (cfgTwoTrackCut > 0) {
914-
field = getMagneticField(collision.timestamp());
929+
field = getMagneticField(collision.runNumber(), collision.timestamp());
915930
}
916931

917932
int bin = configurableBinningDerived.getBin({collision.posZ(), collision.multiplicity()});
@@ -1011,7 +1026,7 @@ struct CorrelationTask {
10111026

10121027
// LOGF(info, "Tracks: %d and %d entries", tracks1.size(), tracks2.size());
10131028

1014-
fillCorrelations<CorrelationContainer::kCFStepReconstructed>(mixed, tracks1, tracks2, collision1.centRun2V0M(), collision1.posZ(), getMagneticField(bc.timestamp()), 1.0f / it.currentWindowNeighbours());
1029+
fillCorrelations<CorrelationContainer::kCFStepReconstructed>(mixed, tracks1, tracks2, collision1.centRun2V0M(), collision1.posZ(), getMagneticField(bc.runNumber(), bc.timestamp()), 1.0f / it.currentWindowNeighbours());
10151030
}
10161031
}
10171032
PROCESS_SWITCH(CorrelationTask, processMixedAOD, "Process mixed events on AOD", false);
@@ -1045,7 +1060,7 @@ struct CorrelationTask {
10451060
float eventWeight = 1.0f / it.currentWindowNeighbours();
10461061
int field = 0;
10471062
if (cfgTwoTrackCut > 0) {
1048-
field = getMagneticField(collision1.timestamp());
1063+
field = getMagneticField(collision1.runNumber(), collision1.timestamp());
10491064
}
10501065

10511066
if (cfgVerbosity > 0) {

0 commit comments

Comments
 (0)