Skip to content

Commit 82fe172

Browse files
committed
Fix memory leak; fix formatting
1 parent 17c15b3 commit 82fe172

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

GeneratorParam/GeneratorParam.cxx

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ void GeneratorParam::GenerateEvent() {
193193
//
194194
// Generate one event
195195
//
196-
fParticles->Clear();
196+
fParticles->Delete(); // clearing previous event AND deleting the particles inside since owning
197197

198198
Float_t polar[3] = {
199199
0, 0, 0}; // Polarisation of the parent particle (for GEANT tracking)
@@ -420,12 +420,11 @@ void GeneratorParam::GenerateEvent() {
420420
//
421421
// Parent
422422
// --- For Exodus --------------------------------//
423-
auto particle = new TParticle(
424-
pdg, ((decayed) ? 11 : 1), -1, -1, -1, -1, p[0], p[1], p[2],
425-
energy, origin0[0], origin0[1], origin0[2], time0
426-
);
427-
particle->SetWeight(wgtp);
428-
fParticles->Add(particle);
423+
auto particle = new TParticle(
424+
pdg, ((decayed) ? 11 : 1), -1, -1, -1, -1, p[0], p[1], p[2],
425+
energy, origin0[0], origin0[1], origin0[2], time0);
426+
particle->SetWeight(wgtp);
427+
fParticles->Add(particle);
429428
vParent[0] = nt;
430429
nt++;
431430
fNprimaries++;
@@ -460,14 +459,14 @@ void GeneratorParam::GenerateEvent() {
460459
iparent = -1;
461460
}
462461
auto parentP = (TParticle *)fParticles->At(iparent);
463-
if (parentP->GetFirstDaughter() == -1)
462+
if (parentP->GetFirstDaughter() == -1) {
464463
parentP->SetFirstDaughter(nt);
464+
}
465465
parentP->SetLastDaughter(nt);
466-
auto particle = new TParticle(kf, ksc, iparent, -1, -1, -1, pc[0],
466+
auto particle = new TParticle(kf, ksc, iparent, -1, -1, -1, pc[0],
467467
pc[1], pc[2], ec, och0[0], och0[1],
468-
och0[2], time0 + iparticle->T()
469-
);
470-
particle->SetWeight(weight * wgtch);
468+
och0[2], time0 + iparticle->T());
469+
particle->SetWeight(weight * wgtch);
471470
fParticles->Add(particle);
472471

473472
vParent[i] = nt;
@@ -484,10 +483,10 @@ void GeneratorParam::GenerateEvent() {
484483
} else {
485484
// nodecay option, so parent will be tracked by GEANT (pions, kaons,
486485
// eta, omegas, baryons)
487-
auto particle = new TParticle(pdg, 1, -1, -1, -1, -1, p[0], p[1], p[2],
486+
auto particle = new TParticle(pdg, 1, -1, -1, -1, -1, p[0], p[1], p[2],
488487
energy, origin0[0], origin0[1],
489488
origin0[2], time0);
490-
particle->SetWeight(wgtp);
489+
particle->SetWeight(wgtp);
491490
fParticles->Add(particle);
492491
ipa++;
493492
fNprimaries++;

0 commit comments

Comments
 (0)