Skip to content

Commit 763846a

Browse files
authored
[PWGCF] Local efficiency loader for JCorran (#10092)
1 parent 3d63b46 commit 763846a

File tree

1 file changed

+55
-20
lines changed

1 file changed

+55
-20
lines changed

PWGCF/JCorran/Tasks/jflucWeightsLoader.cxx

Lines changed: 55 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,14 @@ using namespace o2::framework::expressions;
4444
// This workflow creates a table of weights that can be joined with track tables.
4545
struct JflucWeightsLoader {
4646
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");
4748
O2_DEFINE_CONFIGURABLE(cfgForRunNumber, bool, false, "Get CCDB object by run");
4849
O2_DEFINE_CONFIGURABLE(cfgCCDBPath, std::string, "Users/m/mavirta/corrections/NUA/LHC23zzh", "Internal path in CCDB");
4950

5051
THnF* ph = 0;
5152
TFile* pf = 0;
53+
THnF* pheff = 0;
54+
TFile* pfeff = 0;
5255
int runNumber = 0;
5356
int timestamp = 0;
5457
bool useCCDB = false;
@@ -62,6 +65,12 @@ struct JflucWeightsLoader {
6265
pf->Close();
6366
delete pf;
6467
}
68+
if (pheff)
69+
delete pheff;
70+
if (pfeff) {
71+
pfeff->Close();
72+
delete pfeff;
73+
}
6574
}
6675

6776
void initCCDB(int runNum, int ts)
@@ -89,7 +98,7 @@ struct JflucWeightsLoader {
8998
ccdb->setLocalObjectValidityChecking();
9099
ccdb->setFatalWhenNull(false);
91100
} else if (cfgPathPhiWeights.value.substr(0, 8) == "local://") {
92-
LOGF(info, "Using corrections from: %s", cfgPathPhiWeights.value.substr(8).c_str());
101+
LOGF(info, "Using non-uniform acceptance corrections from: %s", cfgPathPhiWeights.value.substr(8).c_str());
93102
pf = new TFile(cfgPathPhiWeights.value.substr(8).c_str(), "read");
94103
if (!pf->IsOpen()) {
95104
delete pf;
@@ -98,7 +107,26 @@ struct JflucWeightsLoader {
98107
}
99108
useCCDB = false;
100109
} else {
101-
LOGF(info, "Didn't find \"local://\" or \"ccdb\"");
110+
LOGF(info, "Didn't find \"local://\" or \"ccdb\" for non-uniform acceptance corrections.");
111+
return;
112+
}
113+
114+
if (cfgPathEffWeights.value.substr(0, 8) == "local://") {
115+
LOGF(info, "Using efficiency corrections from: %s", cfgPathEffWeights.value.substr(8).c_str());
116+
pfeff = new TFile(cfgPathEffWeights.value.substr(8).c_str(), "read");
117+
if (!pfeff->IsOpen()) {
118+
delete pfeff;
119+
pfeff = 0;
120+
LOGF(fatal, "Efficiency correction weights file not found: %s", cfgPathEffWeights.value.substr(8).c_str());
121+
}
122+
//
123+
if (!(pheff = pfeff->Get<THnF>("ccdb_object"))) {
124+
LOGF(warning, "Efficiency correction histogram not found.");
125+
} else {
126+
LOGF(info, "Loaded efficiency correction histogram locally.");
127+
}
128+
} else {
129+
LOGF(info, "Didn't find \"local://\" or \"ccdb\" for efficiency corrections.");
102130
return;
103131
}
104132
}
@@ -109,23 +137,21 @@ struct JflucWeightsLoader {
109137
template <class ProducesT, class CollisionT, class TrackT>
110138
void loadWeights(Produces<ProducesT>& outputT, CollisionT const& collision, TrackT const& tracks)
111139
{
112-
113-
if (!pf && !useCCDB)
114-
LOGF(fatal, "NUA correction weights file has not been opened.");
115-
if (collision.runNumber() != runNumber) {
116-
if (ph)
117-
delete ph;
118-
// Check if NUA correction can be found from a local file and load it
119-
if (!useCCDB && !(ph = static_cast<THnF*>(pf->Get(Form("NUAWeights_%d", collision.runNumber()))))) {
120-
LOGF(warning, "NUA correction histogram not found for run %d.", collision.runNumber());
121-
} else if (useCCDB) { // Check if ccdb file is used and load it
122-
LOGF(info, "Loaded NUA correction histogram from CCDB for run %d.", collision.runNumber());
123-
} else {
124-
LOGF(info, "Loaded NUA correction histogram locally for run %d.", collision.runNumber());
125-
}
126-
runNumber = collision.runNumber();
127-
if (useCCDB) {
128-
initCCDB(runNumber, timestamp);
140+
if (pf || useCCDB) {
141+
if (collision.runNumber() != runNumber) {
142+
if (ph)
143+
delete ph;
144+
if (!useCCDB) {
145+
// Check if NUA correction can be found from a local file and load it
146+
if (!(ph = pf->Get<THnF>(Form("NUAWeights_%d", collision.runNumber()))))
147+
LOGF(warning, "NUA correction histogram not found for run %d.", collision.runNumber());
148+
else
149+
LOGF(info, "Loaded NUA correction histogram locally for run %d.", collision.runNumber());
150+
} else {
151+
initCCDB(collision.runNumber(), timestamp);
152+
LOGF(info, "Loaded NUA correction histogram from CCDB for run %d.", collision.runNumber());
153+
}
154+
runNumber = collision.runNumber();
129155
}
130156
}
131157
for (const auto& track : tracks) {
@@ -149,7 +175,16 @@ struct JflucWeightsLoader {
149175
phiWeight = 1.0f;
150176
}
151177

152-
effWeight = 1.0f; //<--- todo
178+
if (pheff) {
179+
const int effVars[] = {
180+
pheff->GetAxis(0)->FindBin(track.eta()),
181+
pheff->GetAxis(1)->FindBin(track.pt()),
182+
pheff->GetAxis(2)->FindBin(collision.multiplicity()),
183+
pheff->GetAxis(3)->FindBin(collision.posZ())};
184+
effWeight = pheff->GetBinContent(effVars);
185+
} else {
186+
effWeight = 1.0f;
187+
}
153188

154189
outputT(phiWeight, effWeight);
155190
}

0 commit comments

Comments
 (0)