Skip to content

Commit 92aedb9

Browse files
committed
[PWGCF] CCDB access added properly for NUA and NUE corrections
1 parent 088b554 commit 92aedb9

File tree

1 file changed

+71
-35
lines changed

1 file changed

+71
-35
lines changed

PWGCF/JCorran/Tasks/jflucWeightsLoader.cxx

Lines changed: 71 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,12 @@
88
// In applying this license CERN does not waive the privileges and immunities
99
// granted to it by virtue of its status as an Intergovernmental Organization
1010
// or submit itself to any jurisdiction.
11-
/// \author Jasper Parkkila (jparkkil@cern.ch)
11+
///
12+
/// \file jflucWeightsLoader.cxx
13+
/// \brief Task to load the NUA and NUE weights from local files or CCDB.
14+
/// \author Jasper Parkkila (jparkkil@cern.ch), Maxim Virta (maxim.virta@cern.ch)
1215
/// \since May 2024
13-
// o2-linter: disable='doc/file'
16+
/// The weights are loaded from the local files or CCDB and stored in the JWeights table.
1417

1518
#include "PWGCF/DataModel/CorrelationsDerived.h"
1619
#include "PWGCF/JCorran/DataModel/JCatalyst.h"
@@ -43,19 +46,21 @@ using namespace o2::framework::expressions;
4346
// The standalone jfluc code expects the entire list of tracks for an event. At the same time, it expects weights together with other track attributes.
4447
// This workflow creates a table of weights that can be joined with track tables.
4548
struct JflucWeightsLoader {
46-
O2_DEFINE_CONFIGURABLE(cfgPathPhiWeights, std::string, "http://alice-ccdb.cern.ch", "Local (local://) or CCDB path for the phi acceptance correction histogram");
47-
O2_DEFINE_CONFIGURABLE(cfgPathEffWeights, std::string, "", "Local (local://) or CCDB path for the efficiency correction histogram");
49+
O2_DEFINE_CONFIGURABLE(cfgPathPhiWeights, std::string, "Users/m/mavirta/corrections/NUA/LHC23zzh", "Local (local://) or CCDB path for the phi acceptance correction histogram");
50+
O2_DEFINE_CONFIGURABLE(cfgPathEffWeights, std::string, "Users/m/mavirta/corrections/NUE/LHC23zzh", "Local (local://) or CCDB path for the efficiency correction histogram");
4851
O2_DEFINE_CONFIGURABLE(cfgForRunNumber, bool, false, "Get CCDB object by run");
49-
O2_DEFINE_CONFIGURABLE(cfgCCDBPath, std::string, "Users/m/mavirta/corrections/NUA/LHC23zzh", "Internal path in CCDB");
5052

5153
THnF* ph = 0;
5254
TFile* pf = 0;
5355
THnF* pheff = 0;
5456
TFile* pfeff = 0;
5557
int runNumber = 0;
5658
int timestamp = 0;
57-
bool useCCDB = false;
59+
bool useNUAFromCCDB = false;
60+
bool useEffFromCCDB = false;
5861
Service<o2::ccdb::BasicCCDBManager> ccdb;
62+
std::string ccdbURL = "http://alice-ccdb.cern.ch";
63+
enum { kNUA, kEFF };
5964

6065
~JflucWeightsLoader()
6166
{
@@ -73,12 +78,20 @@ struct JflucWeightsLoader {
7378
}
7479
}
7580

76-
void initCCDB(int runNum, int ts)
81+
void initCCDB(int runNum, int ts, int NUAorEFF = kNUA)
7782
{
7883
if (cfgForRunNumber) {
79-
ph = ccdb->getForRun<THnF>(cfgCCDBPath, runNum);
84+
if (NUAorEFF == kNUA) {
85+
ph = ccdb->getForRun<THnF>(cfgPathPhiWeights, runNum);
86+
} else {
87+
pheff = ccdb->getForRun<THnF>(cfgPathEffWeights, runNum);
88+
}
8089
} else {
81-
ph = ccdb->getForTimeStamp<THnF>(cfgCCDBPath, ts);
90+
if (NUAorEFF == kNUA) {
91+
ph = ccdb->getForTimeStamp<THnF>(cfgPathPhiWeights, ts);
92+
} else {
93+
pheff = ccdb->getForTimeStamp<THnF>(cfgPathEffWeights, ts);
94+
}
8295
}
8396
}
8497

@@ -90,40 +103,49 @@ struct JflucWeightsLoader {
90103

91104
if (doprocessLoadWeights && doprocessLoadWeightsCF)
92105
LOGF(fatal, "Only one of JTracks or CFTracks processing can be enabled at a time.");
93-
if (cfgPathPhiWeights.value.find("ccdb") != std::string::npos) {
94-
LOGF(info, "Using corrections from: ccdb");
95-
useCCDB = true;
96-
ccdb->setURL(cfgPathPhiWeights);
97-
ccdb->setCaching(true);
98-
ccdb->setLocalObjectValidityChecking();
99-
ccdb->setFatalWhenNull(false);
100-
} else if (cfgPathPhiWeights.value.substr(0, 8) == "local://") {
101-
LOGF(info, "Using non-uniform acceptance corrections from: %s", cfgPathPhiWeights.value.substr(8).c_str());
106+
107+
// NUA corrections from local file or CCDB
108+
if (cfgPathPhiWeights.value.substr(0, 8) == "local://") {
109+
LOGF(info, "Using NUA corrections locally from: %s", cfgPathPhiWeights.value.substr(8).c_str());
102110
pf = new TFile(cfgPathPhiWeights.value.substr(8).c_str(), "read");
103111
if (!pf->IsOpen()) {
104112
delete pf;
105113
pf = 0;
106114
LOGF(fatal, "NUA correction weights file not found: %s", cfgPathPhiWeights.value.substr(8).c_str());
107115
}
108-
useCCDB = false;
116+
useNUAFromCCDB = false;
109117
} else {
110-
LOGF(info, "Didn't find \"local://\" or \"ccdb\" for non-uniform acceptance corrections.");
118+
LOGF(info, "Assuming NUA corrections from CCDB.");
119+
useNUAFromCCDB = true;
120+
ccdb->setURL(ccdbURL.data()); // default CCDB URL
121+
ccdb->setCaching(true);
122+
ccdb->setLocalObjectValidityChecking();
123+
ccdb->setFatalWhenNull(false);
111124
}
112125

126+
// Efficiency corrections from local file or CCDB
113127
if (cfgPathEffWeights.value.substr(0, 8) == "local://") {
114-
LOGF(info, "Using efficiency corrections from: %s", cfgPathEffWeights.value.substr(8).c_str());
128+
LOGF(info, "Using efficiency corrections locally from: %s", cfgPathEffWeights.value.substr(8).c_str());
115129
pfeff = new TFile(cfgPathEffWeights.value.substr(8).c_str(), "read");
116130
if (!pfeff->IsOpen()) {
117131
delete pfeff;
118132
pfeff = 0;
119133
LOGF(fatal, "Efficiency correction weights file not found: %s", cfgPathEffWeights.value.substr(8).c_str());
120-
} else if (!(pheff = pfeff->Get<THnF>("ccdb_object"))) {
121-
LOGF(warning, "Efficiency correction histogram not found.");
122134
} else {
123135
LOGF(info, "Loaded efficiency correction histogram locally.");
124136
}
137+
useEffFromCCDB = false;
125138
} else {
126-
LOGF(info, "Didn't find \"local://\" or \"ccdb\" for efficiency corrections.");
139+
LOGF(info, "Assuming efficiency corrections from CCDB.");
140+
useEffFromCCDB = true;
141+
// If NUA corrections are from CCDB, use the same CCDB URL for efficiency corrections
142+
if (!useNUAFromCCDB) {
143+
ccdb->setURL(ccdbURL.data()); // default CCDB URL
144+
ccdb->setCaching(true);
145+
ccdb->setLocalObjectValidityChecking();
146+
ccdb->setFatalWhenNull(false);
147+
}
148+
127149
}
128150
}
129151

@@ -133,23 +155,38 @@ struct JflucWeightsLoader {
133155
template <class ProducesT, class CollisionT, class TrackT>
134156
void loadWeights(Produces<ProducesT>& outputT, CollisionT const& collision, TrackT const& tracks)
135157
{
136-
if (pf || useCCDB) {
158+
if (pf || useNUAFromCCDB) {
137159
if (collision.runNumber() != runNumber) {
138160
if (ph)
139161
delete ph;
140-
if (!useCCDB) {
162+
if (!useNUAFromCCDB) {
141163
// Check if NUA correction can be found from a local file and load it
142164
if (!(ph = pf->Get<THnF>(Form("NUAWeights_%d", collision.runNumber()))))
143165
LOGF(warning, "NUA correction histogram not found for run %d.", collision.runNumber());
144166
else
145167
LOGF(info, "Loaded NUA correction histogram locally for run %d.", collision.runNumber());
146168
} else {
147-
initCCDB(collision.runNumber(), timestamp);
169+
initCCDB(collision.runNumber(), timestamp, kNUA);
148170
LOGF(info, "Loaded NUA correction histogram from CCDB for run %d.", collision.runNumber());
149171
}
150172
runNumber = collision.runNumber();
151173
}
152174
}
175+
if (pfeff) {
176+
if (collision.runNumber() != runNumber) {
177+
if (pheff) delete pheff;
178+
if (!useEffFromCCDB) {
179+
if (!(pheff = pfeff->Get<THnF>("ccdb_object"))) {
180+
LOGF(warning, "Efficiency correction histogram not found.");
181+
} else {
182+
LOGF(info, "Loaded NUE correction histogram locally for run %d.", collision.runNumber());
183+
}
184+
} else {
185+
initCCDB(collision.runNumber(), timestamp, kEFF);
186+
LOGF(info, "Loaded efficiency correction histogram from CCDB for run %d.", collision.runNumber());
187+
}
188+
}
189+
}
153190
for (const auto& track : tracks) {
154191
float phiWeight, effWeight;
155192
if (ph) {
@@ -165,19 +202,18 @@ struct JflucWeightsLoader {
165202
break;
166203
}
167204
}*/
168-
const double coords[] = {collision.multiplicity(), static_cast<double>(partType), track.phi(), track.eta(), collision.posZ()};
169-
phiWeight = ph->GetBinContent(ph->GetBin(coords));
205+
// NUA corrections are a function of multiplicity, partType, phi, eta, and z-vertex
206+
const double nuaCoords[] = {collision.multiplicity(), static_cast<double>(partType), track.phi(), track.eta(), collision.posZ()};
207+
phiWeight = ph->GetBinContent(ph->GetBin(nuaCoords));
170208
} else {
171209
phiWeight = 1.0f;
172210
}
173211

174212
if (pheff) {
175-
const int effVars[] = {
176-
pheff->GetAxis(0)->FindBin(track.eta()),
177-
pheff->GetAxis(1)->FindBin(track.pt()),
178-
pheff->GetAxis(2)->FindBin(collision.multiplicity()),
179-
pheff->GetAxis(3)->FindBin(collision.posZ())};
180-
effWeight = pheff->GetBinContent(effVars);
213+
// Efficiency corrections are a function of eta, pT, multiplicity, and z-vertex
214+
const double nueCoords[] = {track.eta(), track.pt(), collision.multiplicity(), collision.posZ()};
215+
216+
effWeight = pheff->GetBinContent(pheff->GetBin(nueCoords));
181217
} else {
182218
effWeight = 1.0f;
183219
}

0 commit comments

Comments
 (0)