Skip to content

Commit 75cb458

Browse files
cnkosteralibuild
andauthored
[PWGCF] fixed memory leak in getcorrection (#10601)
Co-authored-by: ALICE Action Bot <alibuild@cern.ch>
1 parent 050db44 commit 75cb458

File tree

1 file changed

+37
-47
lines changed

1 file changed

+37
-47
lines changed

PWGCF/Flow/TableProducer/zdcQVectors.cxx

Lines changed: 37 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,8 @@ using BCsRun3 = soa::Join<aod::BCs, aod::Timestamps, aod::BcSels, aod::Run3Match
7070

7171
namespace o2::analysis::qvectortask
7272
{
73-
7473
int counter = 0;
7574

76-
// step0 -> Energy calib
77-
std::shared_ptr<TProfile2D> energyZN[10] = {{nullptr}};
78-
7975
// Define histogrm names here to use same names for creating and later uploading and retrieving data from ccdb
8076
// Energy calibration:
8177
std::vector<TString> namesEcal(10, "");
@@ -88,8 +84,7 @@ std::vector<double> pyZDC = {-1.75, -1.75, 1.75, 1.75};
8884
double alphaZDC = 0.395;
8985

9086
// q-vectors before (q) and after (qRec) recentering.
91-
std::vector<double> q(4); // start values of [QxA, QyA, QxC, QyC]
92-
std::vector<double> qRec(4); // Recentered values of [QxA, QyA, QxC, QyC]
87+
std::vector<double> q(4); // start values of [QxA, QyA, QxC, QyC]
9388

9489
// for energy calibration
9590
std::vector<double> eZN(8); // uncalibrated energy for the 2x4 towers (a1, a2, a3, a4, c1, c2, c3, c4)
@@ -178,7 +173,7 @@ struct ZdcQVectors {
178173
// Tower mean energies vs. centrality used for tower gain equalisation
179174
for (int tower = 0; tower < 10; tower++) {
180175
namesEcal[tower] = TString::Format("hZN%s_mean_t%i_cent", sides[(tower < 5) ? 0 : 1], tower % 5);
181-
energyZN[tower] = registry.add<TProfile2D>(Form("Energy/%s", namesEcal[tower].Data()), Form("%s", namesEcal[tower].Data()), kTProfile2D, {{1, 0, 1}, axisCent});
176+
registry.add<TProfile2D>(Form("Energy/%s", namesEcal[tower].Data()), Form("%s", namesEcal[tower].Data()), kTProfile2D, {{1, 0, 1}, axisCent});
182177
}
183178

184179
registry.add<TH2>(Form("before/QA/hSPplaneA"), "hSPplaneA", kTH2D, {{100, -4, 4}, axisCent10});
@@ -293,8 +288,8 @@ struct ZdcQVectors {
293288
}
294289
}
295290
// Try to cast to TProfile
296-
if (TProfile* profile2D = dynamic_cast<TProfile*>(obj)) {
297-
if (profile2D->GetEntries() < 1) {
291+
if (TProfile* profile = dynamic_cast<TProfile*>(obj)) {
292+
if (profile->GetEntries() < 1) {
298293
if (counter < 1)
299294
LOGF(info, "%s (TProfile) is empty! Produce calibration file at given step", names[i].Data());
300295
cal.calibfilesLoaded[iteration][step] = false;
@@ -385,14 +380,19 @@ struct ZdcQVectors {
385380
for (std::size_t i = 0; i < sparsePars.size(); i++) {
386381
h->GetAxis(i)->SetRange(sparsePars[i], sparsePars[i]);
387382
}
388-
calibConstant = h->Projection(4)->GetMean();
389383

390-
if (h->Projection(4)->GetEntries() < cfgMinEntriesSparseBin) {
384+
TH1D* tempProj = h->Projection(4);
385+
calibConstant = tempProj->GetMean();
386+
387+
if (tempProj->GetEntries() < cfgMinEntriesSparseBin) {
391388
LOGF(debug, "1 entry in sparse bin! Not used... (increase binsize)");
392389
calibConstant = 0;
393390
isSelected = false;
394391
}
392+
393+
delete tempProj;
395394
}
395+
396396
return calibConstant;
397397
}
398398

@@ -422,6 +422,7 @@ struct ZdcQVectors {
422422
if (cent < 0 || cent > 90) {
423423
isSelected = false;
424424
spTableZDC(runnumber, cent, v[0], v[1], v[2], 0, 0, 0, 0, isSelected, 0, 0);
425+
counter++;
425426
return;
426427
}
427428

@@ -432,6 +433,7 @@ struct ZdcQVectors {
432433
if (!foundBC.has_zdc()) {
433434
isSelected = false;
434435
spTableZDC(runnumber, cent, v[0], v[1], v[2], 0, 0, 0, 0, isSelected, 0, 0);
436+
counter++;
435437
return;
436438
}
437439

@@ -443,7 +445,11 @@ struct ZdcQVectors {
443445

444446
// load new calibrations for new runs only
445447
if (runnumber != lastRunNumber) {
446-
cal.calibfilesLoaded = std::vector<std::vector<bool>>(7, std::vector<bool>(8, false));
448+
cal.calibfilesLoaded.clear();
449+
cal.calibfilesLoaded.resize(7, std::vector<bool>(8, false));
450+
451+
cal.calibList.clear();
452+
cal.calibList.resize(7, std::vector<TList*>(8, nullptr));
447453
lastRunNumber = runnumber;
448454
}
449455

@@ -473,9 +479,6 @@ struct ZdcQVectors {
473479
registry.get<TProfile>(HIST("vmean/hvertex_vz"))->Fill(Form("%d", runnumber), v[2]);
474480
}
475481

476-
if (counter < 1)
477-
LOGF(info, "=====================> .....Start Energy Calibration..... <=====================");
478-
479482
bool isZNAhit = true;
480483
bool isZNChit = true;
481484

@@ -492,20 +495,19 @@ struct ZdcQVectors {
492495
isZNChit = false;
493496

494497
// Fill to get mean energy per tower in 1% centrality bins
495-
for (int tower = 0; tower < 5; tower++) {
496-
if (tower == 0) {
497-
if (isZNAhit)
498-
energyZN[tower]->Fill(Form("%d", runnumber), cent, zdcCol.energyCommonZNA(), 1);
499-
if (isZNChit)
500-
energyZN[tower + 5]->Fill(Form("%d", runnumber), cent, zdcCol.energyCommonZNC(), 1);
501-
LOGF(debug, "Common A tower filled with: %i, %.2f, %.2f", runnumber, cent, zdcCol.energyCommonZNA());
502-
} else {
503-
if (isZNAhit)
504-
energyZN[tower]->Fill(Form("%d", runnumber), cent, eZN[tower - 1], 1);
505-
if (isZNChit)
506-
energyZN[tower + 5]->Fill(Form("%d", runnumber), cent, eZN[tower - 1 + 4], 1);
507-
LOGF(debug, "Tower ZNC[%i] filled with: %i, %.2f, %.2f", tower, runnumber, cent, eZN[tower - 1 + 4]);
508-
}
498+
if (isZNAhit) {
499+
registry.get<TProfile2D>(HIST("Energy/hZNA_mean_t0_cent"))->Fill(Form("%d", runnumber), cent, zdcCol.energyCommonZNA(), 1);
500+
registry.get<TProfile2D>(HIST("Energy/hZNA_mean_t1_cent"))->Fill(Form("%d", runnumber), cent, eZN[0], 1);
501+
registry.get<TProfile2D>(HIST("Energy/hZNA_mean_t2_cent"))->Fill(Form("%d", runnumber), cent, eZN[1], 1);
502+
registry.get<TProfile2D>(HIST("Energy/hZNA_mean_t3_cent"))->Fill(Form("%d", runnumber), cent, eZN[2], 1);
503+
registry.get<TProfile2D>(HIST("Energy/hZNA_mean_t4_cent"))->Fill(Form("%d", runnumber), cent, eZN[3], 1);
504+
}
505+
if (isZNChit) {
506+
registry.get<TProfile2D>(HIST("Energy/hZNC_mean_t0_cent"))->Fill(Form("%d", runnumber), cent, zdcCol.energyCommonZNC(), 1);
507+
registry.get<TProfile2D>(HIST("Energy/hZNC_mean_t1_cent"))->Fill(Form("%d", runnumber), cent, eZN[4], 1);
508+
registry.get<TProfile2D>(HIST("Energy/hZNC_mean_t2_cent"))->Fill(Form("%d", runnumber), cent, eZN[5], 1);
509+
registry.get<TProfile2D>(HIST("Energy/hZNC_mean_t3_cent"))->Fill(Form("%d", runnumber), cent, eZN[6], 1);
510+
registry.get<TProfile2D>(HIST("Energy/hZNC_mean_t4_cent"))->Fill(Form("%d", runnumber), cent, eZN[7], 1);
509511
}
510512

511513
// if ZNA or ZNC not hit correctly.. do not use event in q-vector calculation
@@ -523,13 +525,6 @@ struct ZdcQVectors {
523525
return;
524526
}
525527

526-
if (counter < 1)
527-
LOGF(info, "files for step 0 (energy Calibraton) are open!");
528-
529-
if (counter < 1) {
530-
LOGF(info, "=====================> .....Start Calculating Q-Vectors..... <=====================");
531-
}
532-
533528
// Now start gain equalisation!
534529
// Fill the list with calibration constants.
535530
for (int tower = 0; tower < 10; tower++) {
@@ -575,8 +570,6 @@ struct ZdcQVectors {
575570
}
576571

577572
if (cal.calibfilesLoaded[0][1]) {
578-
if (counter < 1)
579-
LOGF(info, "=====================> Setting v to vmean!");
580573
v[0] = v[0] - getCorrection<TProfile>(0, 1, vnames[0].Data());
581574
v[1] = v[1] - getCorrection<TProfile>(0, 1, vnames[1].Data());
582575
}
@@ -599,21 +592,17 @@ struct ZdcQVectors {
599592
}
600593
}
601594

602-
if (counter < 1)
603-
LOGF(info, "We evaluate cal.atIteration=%i and cal.atStep=%i ", cal.atIteration, cal.atStep);
595+
std::vector<double> qRec(q);
604596

605597
if (cal.atIteration == 0) {
606-
if (counter < 1)
607-
LOGF(warning, "Calibation files missing!!! Output created with q-vectors right after energy gain eq. !!");
608598
if (isSelected)
609599
fillCommonRegistry<kBefore>(q[0], q[1], q[2], q[3], v, centrality);
600+
610601
spTableZDC(runnumber, centrality, v[0], v[1], v[2], q[0], q[1], q[2], q[3], isSelected, 0, 0);
611602
counter++;
612603
return;
613604
} else if (cal.atIteration == 5 && cal.atStep == 4) {
614-
std::vector<double> qRec(4);
615605
fillCommonRegistry<kBefore>(q[0], q[1], q[2], q[3], v, centrality);
616-
qRec = q;
617606

618607
// vector of 4
619608
std::vector<double> corrQxA;
@@ -628,7 +617,6 @@ struct ZdcQVectors {
628617
corrQyA.push_back(getCorrection<THnSparse>(it, 0, names[0][1].Data()));
629618
corrQxC.push_back(getCorrection<THnSparse>(it, 0, names[0][2].Data()));
630619
corrQyC.push_back(getCorrection<THnSparse>(it, 0, names[0][3].Data()));
631-
632620
pb++;
633621

634622
for (int step = 1; step < 5; step++) {
@@ -647,13 +635,15 @@ struct ZdcQVectors {
647635
qRec[3] -= corrQyC[cor];
648636
}
649637

650-
if (counter < 1)
651-
LOGF(info, "Output created with q-vectors at iteration %i and step %i!!!!", cal.atIteration, cal.atStep + 1);
652638
if (isSelected) {
653639
fillCommonRegistry<kAfter>(qRec[0], qRec[1], qRec[2], qRec[3], v, centrality);
654640
registry.fill(HIST("QA/centrality_after"), centrality);
655641
}
642+
656643
spTableZDC(runnumber, centrality, v[0], v[1], v[2], qRec[0], qRec[1], qRec[2], qRec[3], isSelected, cal.atIteration, cal.atStep);
644+
645+
qRec.clear();
646+
657647
counter++;
658648
return;
659649
} else {

0 commit comments

Comments
 (0)