Skip to content

Commit 26ae16d

Browse files
authored
[PWGCF/FemtoUniverse] Fix dangling pointer when loading histograms from CCDB (#11369)
1 parent 925fd95 commit 26ae16d

File tree

2 files changed

+32
-12
lines changed

2 files changed

+32
-12
lines changed

PWGCF/FemtoUniverse/Core/FemtoUniverseEfficiencyCorrection.h

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,6 @@ class EfficiencyCorrection
110110
LOGF(fatal, notify("Unknown configuration for efficiency variables"));
111111
break;
112112
}
113-
} else {
114-
hLoaded[idx] = nullptr;
115113
}
116114
}
117115
}
@@ -201,17 +199,18 @@ class EfficiencyCorrection
201199

202200
auto bin = -1;
203201
if (config->confEffCorVariables.value == "pt") {
204-
bin = hLoaded[partNo - 1]->FindBin(particle.pt());
202+
bin = hWeights->FindBin(particle.pt());
205203
} else if (config->confEffCorVariables.value == "pt,eta") {
206-
bin = hLoaded[partNo - 1]->FindBin(particle.pt(), particle.eta());
204+
bin = hWeights->FindBin(particle.pt(), particle.eta());
207205
} else if (config->confEffCorVariables.value == "pt,mult") {
208-
bin = hLoaded[partNo - 1]->FindBin(particle.pt(), particle.fdCollision().multV0M());
206+
bin = hWeights->FindBin(particle.pt(), particle.fdCollision().multV0M());
209207
} else if (config->confEffCorVariables.value == "pt,eta,mult") {
210-
bin = hLoaded[partNo - 1]->FindBin(particle.pt(), particle.eta(), particle.fdCollision().multV0M());
208+
bin = hWeights->FindBin(particle.pt(), particle.eta(), particle.fdCollision().multV0M());
211209
} else {
212210
LOGF(fatal, notify("Unknown configuration for efficiency variables"));
213211
return weight;
214212
}
213+
215214
weight = hWeights->GetBinContent(bin);
216215
}
217216

@@ -229,11 +228,21 @@ class EfficiencyCorrection
229228
if (!hist) {
230229
return true;
231230
}
232-
for (auto idx = 0; idx <= hist->GetNbinsX() + 1; idx++) {
233-
if (hist->GetBinContent(idx) > 0) {
234-
return false;
231+
232+
const int nBinsX = hist->GetNbinsX() + 2;
233+
const int nBinsY = hist->GetNbinsY() + 2;
234+
const int nBinsZ = hist->GetNbinsZ() + 2;
235+
236+
for (int x = 0; x < nBinsX; ++x) {
237+
for (int y = 0; y < nBinsY; ++y) {
238+
for (int z = 0; z < nBinsZ; ++z) {
239+
if (hist->GetBinContent(x, y, z) != 0) {
240+
return false;
241+
}
242+
}
235243
}
236244
}
245+
237246
return true;
238247
}
239248

@@ -247,11 +256,14 @@ class EfficiencyCorrection
247256
}
248257

249258
if (isHistEmpty(hWeights)) {
250-
LOGF(warn, notify("Histogram \"%s/%ld\" has been loaded, but it is empty"), config->confEffCorCCDBUrl.value, timestamp);
259+
LOGF(warn, notify("Histogram \"%s/%ld\" has been loaded, but it is empty"), config->confEffCorCCDBPath.value, timestamp);
251260
}
252261

262+
auto clonedHist = static_cast<H*>(hWeights->Clone());
263+
clonedHist->SetDirectory(nullptr);
264+
253265
LOGF(info, notify("Successfully loaded %ld"), timestamp);
254-
return hWeights;
266+
return clonedHist;
255267
}
256268

257269
auto getDimensionFromVariables() -> size_t
@@ -266,7 +278,7 @@ class EfficiencyCorrection
266278
bool shouldFillHistograms{false};
267279

268280
o2::ccdb::BasicCCDBManager& ccdb{o2::ccdb::BasicCCDBManager::instance()};
269-
std::array<TH1*, 2> hLoaded{};
281+
std::array<TH1*, 2> hLoaded{nullptr, nullptr};
270282

271283
framework::HistogramRegistry* histRegistry{};
272284
static constexpr std::string_view histDirectory{"EfficiencyCorrection"};

PWGCF/FemtoUniverse/Macros/calculateEfficiencyCorrection.cxx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,10 @@ auto calculateEfficiencyCorrection(const fs::path& resultsPath, const fs::path&
148148
histWeights->Reset();
149149
setAxisTitles(histWeights, projection);
150150

151+
auto* histCont{cloneHistogram(histPrimary, "hCont")};
152+
histCont->Reset();
153+
setAxisTitles(histCont, projection);
154+
151155
forEachBin(histPrimary, [&](int x, int y, int z) {
152156
auto primVal{histPrimary->GetBinContent(x, y, z)};
153157
auto primErr{histPrimary->GetBinError(x, y, z)};
@@ -178,6 +182,9 @@ auto calculateEfficiencyCorrection(const fs::path& resultsPath, const fs::path&
178182
contErr = std::sqrt(std::pow(secErr / totalVal, 2) + std::pow((secVal * totalErr / std::pow(totalVal, 2)), 2));
179183
}
180184

185+
histCont->SetBinContent(x, y, z, contVal);
186+
histCont->SetBinError(x, y, z, contErr);
187+
181188
auto weightVal{0.};
182189
auto weightErr{0.};
183190
if (effVal > 0) {
@@ -190,6 +197,7 @@ auto calculateEfficiencyCorrection(const fs::path& resultsPath, const fs::path&
190197
});
191198

192199
outputFile->WriteTObject(histEfficiency);
200+
outputFile->WriteTObject(histCont);
193201
outputFile->WriteTObject(histWeights);
194202

195203
outputFile->Close();

0 commit comments

Comments
 (0)