From 1b9c102fcf2b6e12dc4db9c18b714b155d9a5cae Mon Sep 17 00:00:00 2001 From: Wouter Deconinck Date: Thu, 14 Oct 2021 17:10:08 -0500 Subject: [PATCH] BeamTarget as object in PrimaryGenerator, fewer pointers --- include/remollPrimaryGeneratorAction.hh | 5 +++-- src/remollPrimaryGeneratorAction.cc | 12 ++++-------- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/include/remollPrimaryGeneratorAction.hh b/include/remollPrimaryGeneratorAction.hh index 8b61e7224..fa36863bf 100644 --- a/include/remollPrimaryGeneratorAction.hh +++ b/include/remollPrimaryGeneratorAction.hh @@ -1,6 +1,8 @@ #ifndef remollPrimaryGeneratorAction_h #define remollPrimaryGeneratorAction_h 1 +#include "remollBeamTarget.hh" + #include "G4VUserPrimaryGeneratorAction.hh" #include "G4VPrimaryGenerator.hh" #include "G4String.hh" @@ -10,7 +12,6 @@ class G4GenericMessenger; class G4ParticleGun; class G4Event; -class remollBeamTarget; class remollVEventGen; class remollEvent; @@ -38,7 +39,7 @@ class remollPrimaryGeneratorAction : public G4VUserPrimaryGeneratorAction G4ParticleGun* fParticleGun; - remollBeamTarget *fBeamTarg; + remollBeamTarget fBeamTarg; remollEvent *fEvent; diff --git a/src/remollPrimaryGeneratorAction.cc b/src/remollPrimaryGeneratorAction.cc index 3850472ae..d36f916bf 100644 --- a/src/remollPrimaryGeneratorAction.cc +++ b/src/remollPrimaryGeneratorAction.cc @@ -35,7 +35,7 @@ #include "remollGenHyperon.hh" remollPrimaryGeneratorAction::remollPrimaryGeneratorAction() -: fEventGen(0),fPriGen(0),fParticleGun(0),fBeamTarg(0),fEvent(0),fMessenger(0),fEffCrossSection(0) +: fEventGen(0),fPriGen(0),fParticleGun(0),fEvent(0),fMessenger(0),fEffCrossSection(0) { static bool has_been_warned = false; if (! has_been_warned) { @@ -72,9 +72,6 @@ remollPrimaryGeneratorAction::remollPrimaryGeneratorAction() #endif #endif - // Create beam target - fBeamTarg = new remollBeamTarget(); - // Default generator G4String default_generator = "moller"; SetGenerator(default_generator); @@ -91,7 +88,6 @@ remollPrimaryGeneratorAction::~remollPrimaryGeneratorAction() fPriGenMap.clear(); if (fEvGenMessenger) delete fEvGenMessenger; if (fMessenger) delete fMessenger; - if (fBeamTarg) delete fBeamTarg; if (fEventGen) delete fEventGen; } @@ -131,7 +127,7 @@ void remollPrimaryGeneratorAction::SetGenerator(G4String& genname) // Set the beam target if (fEventGen) { - fEventGen->SetBeamTarget(fBeamTarg); + fEventGen->SetBeamTarget(&fBeamTarg); } } @@ -206,10 +202,10 @@ void remollPrimaryGeneratorAction::GeneratePrimaries(G4Event* anEvent) // Calculate rate SamplingType_t sampling_type = fEventGen->GetSamplingType(); if (fEvent->fRate == 0) { // If the rate is set to 0 then calculate it using the cross section - fEvent->fRate = fEvent->fEffXs * fBeamTarg->GetEffLumin(sampling_type) / nthrown; + fEvent->fRate = fEvent->fEffXs * fBeamTarg.GetEffLumin(sampling_type) / nthrown; } else { // For LUND - calculate rate and cross section - fEvent->fEffXs = fEvent->fRate * nthrown / fBeamTarg->GetEffLumin(sampling_type); + fEvent->fEffXs = fEvent->fRate * nthrown / fBeamTarg.GetEffLumin(sampling_type); fEvent->fRate = fEvent->fRate / nthrown; }