Geant4 11.2.2
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4AdjointPrimaryGeneratorAction Class Reference

#include <G4AdjointPrimaryGeneratorAction.hh>

+ Inheritance diagram for G4AdjointPrimaryGeneratorAction:

Public Member Functions

 G4AdjointPrimaryGeneratorAction ()
 
 ~G4AdjointPrimaryGeneratorAction () override
 
 G4AdjointPrimaryGeneratorAction (const G4AdjointPrimaryGeneratorAction &)=delete
 
G4AdjointPrimaryGeneratorActionoperator= (const G4AdjointPrimaryGeneratorAction &)=delete
 
void GeneratePrimaries (G4Event *) override
 
void SetEmin (G4double val)
 
void SetEmax (G4double val)
 
void SetEminIon (G4double val)
 
void SetEmaxIon (G4double val)
 
void SetSphericalAdjointPrimarySource (G4double radius, G4ThreeVector pos)
 
void SetAdjointPrimarySourceOnAnExtSurfaceOfAVolume (const G4String &volume_name)
 
void ConsiderParticleAsPrimary (const G4String &particle_name)
 
void NeglectParticleAsPrimary (const G4String &particle_name)
 
void SetPrimaryIon (G4ParticleDefinition *adjointIon, G4ParticleDefinition *fwdIon)
 
void UpdateListOfPrimaryParticles ()
 
void SetRndmFlag (const G4String &val)
 
size_t GetNbOfAdjointPrimaryTypes ()
 
std::vector< G4ParticleDefinition * > * GetListOfPrimaryFwdParticles ()
 
const G4StringGetPrimaryIonName ()
 
void SetNbPrimaryFwdGammasPerEvent (G4int nb)
 
void SetNbAdjointPrimaryGammasPerEvent (G4int nb)
 
void SetNbAdjointPrimaryElectronsPerEvent (G4int nb)
 
G4ParticleDefinitionGetLastGeneratedFwdPrimaryParticle ()
 
- Public Member Functions inherited from G4VUserPrimaryGeneratorAction
 G4VUserPrimaryGeneratorAction ()
 
virtual ~G4VUserPrimaryGeneratorAction ()=default
 

Detailed Description

Definition at line 80 of file G4AdjointPrimaryGeneratorAction.hh.

Constructor & Destructor Documentation

◆ G4AdjointPrimaryGeneratorAction() [1/2]

G4AdjointPrimaryGeneratorAction::G4AdjointPrimaryGeneratorAction ( )

Definition at line 48 of file G4AdjointPrimaryGeneratorAction.cc.

49{
50 theAdjointPrimaryGenerator = new G4AdjointPrimaryGenerator();
51
52 PrimariesConsideredInAdjointSim[G4String("e-")] = false;
53 PrimariesConsideredInAdjointSim[G4String("gamma")] = false;
54 PrimariesConsideredInAdjointSim[G4String("proton")] = false;
55 PrimariesConsideredInAdjointSim[G4String("ion")] = false;
56
57 ListOfPrimaryFwdParticles.clear();
58 ListOfPrimaryAdjParticles.clear();
59}

◆ ~G4AdjointPrimaryGeneratorAction()

G4AdjointPrimaryGeneratorAction::~G4AdjointPrimaryGeneratorAction ( )
override

Definition at line 63 of file G4AdjointPrimaryGeneratorAction.cc.

64{
65 delete theAdjointPrimaryGenerator;
66}

◆ G4AdjointPrimaryGeneratorAction() [2/2]

G4AdjointPrimaryGeneratorAction::G4AdjointPrimaryGeneratorAction ( const G4AdjointPrimaryGeneratorAction & )
delete

Member Function Documentation

◆ ConsiderParticleAsPrimary()

void G4AdjointPrimaryGeneratorAction::ConsiderParticleAsPrimary ( const G4String & particle_name)

Definition at line 248 of file G4AdjointPrimaryGeneratorAction.cc.

249{
250 if (PrimariesConsideredInAdjointSim.find(particle_name) != PrimariesConsideredInAdjointSim.end())
251 {
252 PrimariesConsideredInAdjointSim[particle_name] = true;
253 }
255}

Referenced by G4AdjointSimManager::ConsiderParticleAsPrimary().

◆ GeneratePrimaries()

void G4AdjointPrimaryGeneratorAction::GeneratePrimaries ( G4Event * anEvent)
overridevirtual

Implements G4VUserPrimaryGeneratorAction.

Definition at line 70 of file G4AdjointPrimaryGeneratorAction.cc.

71{
72 G4int evt_id = anEvent->GetEventID();
73 std::size_t n = ListOfPrimaryAdjParticles.size();
74 index_particle = std::size_t(evt_id) - n * (std::size_t(evt_id) / n);
75
76 G4double E1 = Emin;
77 G4double E2 = Emax;
78 if (ListOfPrimaryAdjParticles[index_particle] == nullptr)
79 UpdateListOfPrimaryParticles(); // ion has not been created yet
80
81 if (ListOfPrimaryAdjParticles[index_particle]->GetParticleName() == "adj_proton") {
82 E1 = EminIon;
83 E2 = EmaxIon;
84 }
85 if (ListOfPrimaryAdjParticles[index_particle]->GetParticleType() == "adjoint_nucleus") {
86 G4int A = ListOfPrimaryAdjParticles[index_particle]->GetAtomicMass();
87 E1 = EminIon * A;
88 E2 = EmaxIon * A;
89 }
90 // Generate first the forwrad primaries
91 theAdjointPrimaryGenerator->GenerateFwdPrimaryVertex(
92 anEvent, ListOfPrimaryFwdParticles[index_particle], E1, E2);
93 G4PrimaryVertex* fwdPrimVertex = anEvent->GetPrimaryVertex();
94
95 p = fwdPrimVertex->GetPrimary()->GetMomentum();
96 pos = fwdPrimVertex->GetPosition();
97 G4double pmag = p.mag();
98 G4double m0 = ListOfPrimaryFwdParticles[index_particle]->GetPDGMass();
99 G4double ekin = std::sqrt(m0 * m0 + pmag * pmag) - m0;
100
101 G4double weight_correction = 1.;
102 // For gamma generate the particle along the backward ray
103 G4ThreeVector dir = -p / p.mag();
104
105 weight_correction = 1.;
106
107 if (ListOfPrimaryFwdParticles[index_particle] == G4Gamma::Gamma() && nb_fwd_gammas_per_event > 1)
108 {
109 G4double weight = (1. / nb_fwd_gammas_per_event);
110 fwdPrimVertex->SetWeight(weight);
111 for (G4int i = 0; i < nb_fwd_gammas_per_event - 1; ++i) {
112 auto newFwdPrimVertex = new G4PrimaryVertex();
113 newFwdPrimVertex->SetPosition(pos.x(), pos.y(), pos.z());
114 newFwdPrimVertex->SetT0(0.);
115 auto aPrimParticle =
116 new G4PrimaryParticle(ListOfPrimaryFwdParticles[index_particle], p.x(), p.y(), p.z());
117 newFwdPrimVertex->SetPrimary(aPrimParticle);
118 newFwdPrimVertex->SetWeight(weight);
119 anEvent->AddPrimaryVertex(newFwdPrimVertex);
120 }
121 }
122
123 // Now generate the adjoint primaries
124 auto adjPrimVertex = new G4PrimaryVertex();
125 adjPrimVertex->SetPosition(pos.x(), pos.y(), pos.z());
126 adjPrimVertex->SetT0(0.);
127 auto aPrimParticle =
128 new G4PrimaryParticle(ListOfPrimaryAdjParticles[index_particle], -p.x(), -p.y(), -p.z());
129
130 adjPrimVertex->SetPrimary(aPrimParticle);
131 anEvent->AddPrimaryVertex(adjPrimVertex);
132
133 // The factor pi is to normalise the weight to the directional flux
135 G4double adjoint_weight =
136 weight_correction * ComputeEnergyDistWeight(ekin, E1, E2) * adjoint_source_area * pi;
137 if (ListOfPrimaryAdjParticles[index_particle]->GetParticleName() == "adj_gamma") {
138 // The weight will be corrected at the end of the track if splitted tracks
139 // are used
140 adjoint_weight = adjoint_weight / nb_adj_primary_gammas_per_event;
141 for (G4int i = 0; i < nb_adj_primary_gammas_per_event - 1; ++i) {
142 auto newAdjPrimVertex = new G4PrimaryVertex();
143 newAdjPrimVertex->SetPosition(pos.x(), pos.y(), pos.z());
144 newAdjPrimVertex->SetT0(0.);
145 aPrimParticle =
146 new G4PrimaryParticle(ListOfPrimaryAdjParticles[index_particle], -p.x(), -p.y(), -p.z());
147 newAdjPrimVertex->SetPrimary(aPrimParticle);
148 newAdjPrimVertex->SetWeight(adjoint_weight);
149 anEvent->AddPrimaryVertex(newAdjPrimVertex);
150 }
151 }
152 else if (ListOfPrimaryAdjParticles[index_particle]->GetParticleName() == "adj_electron") {
153 // The weight will be corrected at the end of the track if splitted tracks
154 // are used
155 adjoint_weight = adjoint_weight / nb_adj_primary_electrons_per_event;
156 for (G4int i = 0; i < nb_adj_primary_electrons_per_event - 1; ++i) {
157 auto newAdjPrimVertex = new G4PrimaryVertex();
158 newAdjPrimVertex->SetPosition(pos.x(), pos.y(), pos.z());
159 newAdjPrimVertex->SetT0(0.);
160 aPrimParticle =
161 new G4PrimaryParticle(ListOfPrimaryAdjParticles[index_particle], -p.x(), -p.y(), -p.z());
162 newAdjPrimVertex->SetPrimary(aPrimParticle);
163 newAdjPrimVertex->SetWeight(adjoint_weight);
164 anEvent->AddPrimaryVertex(newAdjPrimVertex);
165 }
166 }
167 adjPrimVertex->SetWeight(adjoint_weight);
168
169 // Call some methods of G4AdjointSimManager
173}
double G4double
Definition G4Types.hh:83
int G4int
Definition G4Types.hh:85
const G4double A[17]
double z() const
double x() const
double y() const
double mag() const
void GenerateFwdPrimaryVertex(G4Event *anEvt, G4ParticleDefinition *adj_part, G4double E1, G4double E2)
void SetAdjointTrackingMode(G4bool aBool)
void ResetDidOneAdjPartReachExtSourceDuringEvent()
static G4AdjointSimManager * GetInstance()
G4PrimaryVertex * GetPrimaryVertex(G4int i=0) const
Definition G4Event.hh:142
G4int GetEventID() const
Definition G4Event.hh:123
void AddPrimaryVertex(G4PrimaryVertex *aPrimaryVertex)
Definition G4Event.hh:126
static G4Gamma * Gamma()
Definition G4Gamma.cc:81
G4ThreeVector GetMomentum() const
G4ThreeVector GetPosition() const
void SetWeight(G4double w)
G4PrimaryParticle * GetPrimary(G4int i=0) const

◆ GetLastGeneratedFwdPrimaryParticle()

G4ParticleDefinition * G4AdjointPrimaryGeneratorAction::GetLastGeneratedFwdPrimaryParticle ( )
inline

Definition at line 117 of file G4AdjointPrimaryGeneratorAction.hh.

118 {
119 return ListOfPrimaryFwdParticles[index_particle];
120 }

Referenced by G4AdjointSimManager::GetLastGeneratedFwdPrimaryParticle().

◆ GetListOfPrimaryFwdParticles()

std::vector< G4ParticleDefinition * > * G4AdjointPrimaryGeneratorAction::GetListOfPrimaryFwdParticles ( )
inline

◆ GetNbOfAdjointPrimaryTypes()

size_t G4AdjointPrimaryGeneratorAction::GetNbOfAdjointPrimaryTypes ( )
inline

Definition at line 102 of file G4AdjointPrimaryGeneratorAction.hh.

102{ return ListOfPrimaryAdjParticles.size(); }

Referenced by G4AdjointSimManager::RunAdjointSimulation().

◆ GetPrimaryIonName()

const G4String & G4AdjointPrimaryGeneratorAction::GetPrimaryIonName ( )
inline

Definition at line 107 of file G4AdjointPrimaryGeneratorAction.hh.

107{ return ion_name; }

Referenced by G4AdjointSimManager::GetPrimaryIonName().

◆ NeglectParticleAsPrimary()

void G4AdjointPrimaryGeneratorAction::NeglectParticleAsPrimary ( const G4String & particle_name)

Definition at line 259 of file G4AdjointPrimaryGeneratorAction.cc.

260{
261 if (PrimariesConsideredInAdjointSim.find(particle_name) != PrimariesConsideredInAdjointSim.end())
262 {
263 PrimariesConsideredInAdjointSim[particle_name] = false;
264 }
266}

Referenced by G4AdjointSimManager::NeglectParticleAsPrimary().

◆ operator=()

G4AdjointPrimaryGeneratorAction & G4AdjointPrimaryGeneratorAction::operator= ( const G4AdjointPrimaryGeneratorAction & )
delete

◆ SetAdjointPrimarySourceOnAnExtSurfaceOfAVolume()

void G4AdjointPrimaryGeneratorAction::SetAdjointPrimarySourceOnAnExtSurfaceOfAVolume ( const G4String & volume_name)

Definition at line 239 of file G4AdjointPrimaryGeneratorAction.cc.

241{
242 type_of_adjoint_source = "ExternalSurfaceOfAVolume";
243 theAdjointPrimaryGenerator->SetAdjointPrimarySourceOnAnExtSurfaceOfAVolume(volume_name);
244}
void SetAdjointPrimarySourceOnAnExtSurfaceOfAVolume(const G4String &v_name)

Referenced by G4AdjointSimManager::DefineAdjointSourceOnTheExtSurfaceOfAVolume().

◆ SetEmax()

void G4AdjointPrimaryGeneratorAction::SetEmax ( G4double val)

Definition at line 185 of file G4AdjointPrimaryGeneratorAction.cc.

186{
187 Emax = val;
188 EmaxIon = val;
189}

Referenced by G4AdjointSimManager::SetAdjointSourceEmax().

◆ SetEmaxIon()

void G4AdjointPrimaryGeneratorAction::SetEmaxIon ( G4double val)

Definition at line 200 of file G4AdjointPrimaryGeneratorAction.cc.

201{
202 EmaxIon = val;
203}

◆ SetEmin()

void G4AdjointPrimaryGeneratorAction::SetEmin ( G4double val)

Definition at line 177 of file G4AdjointPrimaryGeneratorAction.cc.

178{
179 Emin = val;
180 EminIon = val;
181}

Referenced by G4AdjointSimManager::SetAdjointSourceEmin().

◆ SetEminIon()

void G4AdjointPrimaryGeneratorAction::SetEminIon ( G4double val)

Definition at line 193 of file G4AdjointPrimaryGeneratorAction.cc.

194{
195 EminIon = val;
196}

◆ SetNbAdjointPrimaryElectronsPerEvent()

void G4AdjointPrimaryGeneratorAction::SetNbAdjointPrimaryElectronsPerEvent ( G4int nb)
inline

Definition at line 113 of file G4AdjointPrimaryGeneratorAction.hh.

114 {
115 nb_adj_primary_electrons_per_event = nb;
116 }

Referenced by G4AdjointSimManager::SetNbAdjointPrimaryElectronsPerEvent().

◆ SetNbAdjointPrimaryGammasPerEvent()

void G4AdjointPrimaryGeneratorAction::SetNbAdjointPrimaryGammasPerEvent ( G4int nb)
inline

Definition at line 109 of file G4AdjointPrimaryGeneratorAction.hh.

110 {
111 nb_adj_primary_gammas_per_event = nb;
112 }

Referenced by G4AdjointSimManager::SetNbAdjointPrimaryGammasPerEvent().

◆ SetNbPrimaryFwdGammasPerEvent()

void G4AdjointPrimaryGeneratorAction::SetNbPrimaryFwdGammasPerEvent ( G4int nb)
inline

Definition at line 108 of file G4AdjointPrimaryGeneratorAction.hh.

108{ nb_fwd_gammas_per_event = nb; }

Referenced by G4AdjointSimManager::SetNbOfPrimaryFwdGammasPerEvent().

◆ SetPrimaryIon()

void G4AdjointPrimaryGeneratorAction::SetPrimaryIon ( G4ParticleDefinition * adjointIon,
G4ParticleDefinition * fwdIon )

Definition at line 301 of file G4AdjointPrimaryGeneratorAction.cc.

303{
304 fwd_ion = fwdIon;
305 adj_ion = adjointIon;
307}

Referenced by G4AdjointSimManager::SetPrimaryIon().

◆ SetRndmFlag()

void G4AdjointPrimaryGeneratorAction::SetRndmFlag ( const G4String & val)
inline

Definition at line 101 of file G4AdjointPrimaryGeneratorAction.hh.

101{ rndmFlag = val; }

◆ SetSphericalAdjointPrimarySource()

void G4AdjointPrimaryGeneratorAction::SetSphericalAdjointPrimarySource ( G4double radius,
G4ThreeVector pos )

Definition at line 228 of file G4AdjointPrimaryGeneratorAction.cc.

230{
231 radius_spherical_source = radius;
232 center_spherical_source = center_pos;
233 type_of_adjoint_source = "Spherical";
234 theAdjointPrimaryGenerator->SetSphericalAdjointPrimarySource(radius, center_pos);
235}
void SetSphericalAdjointPrimarySource(G4double radius, G4ThreeVector pos)

Referenced by G4AdjointSimManager::DefineSphericalAdjointSource(), and G4AdjointSimManager::DefineSphericalAdjointSourceWithCentreAtTheCentreOfAVolume().

◆ UpdateListOfPrimaryParticles()

void G4AdjointPrimaryGeneratorAction::UpdateListOfPrimaryParticles ( )

Definition at line 270 of file G4AdjointPrimaryGeneratorAction.cc.

271{
273 ListOfPrimaryFwdParticles.clear();
274 ListOfPrimaryAdjParticles.clear();
275 for (const auto& iter : PrimariesConsideredInAdjointSim) {
276 if (iter.second) {
277 G4String fwd_particle_name = iter.first;
278 if (fwd_particle_name != "ion") {
279 G4String adj_particle_name = G4String("adj_") + fwd_particle_name;
280 ListOfPrimaryFwdParticles.push_back(theParticleTable->FindParticle(fwd_particle_name));
281 ListOfPrimaryAdjParticles.push_back(theParticleTable->FindParticle(adj_particle_name));
282 }
283 else {
284 if (fwd_ion != nullptr) {
285 ion_name = fwd_ion->GetParticleName();
286 G4String adj_ion_name = G4String("adj_") + ion_name;
287 ListOfPrimaryFwdParticles.push_back(fwd_ion);
288 ListOfPrimaryAdjParticles.push_back(adj_ion);
289 }
290 else {
291 ListOfPrimaryFwdParticles.push_back(nullptr);
292 ListOfPrimaryAdjParticles.push_back(nullptr);
293 }
294 }
295 }
296 }
297}
const G4String & GetParticleName() const
G4ParticleDefinition * FindParticle(G4int PDGEncoding)
static G4ParticleTable * GetParticleTable()

Referenced by ConsiderParticleAsPrimary(), GeneratePrimaries(), NeglectParticleAsPrimary(), SetPrimaryIon(), and G4AdjointSimManager::SwitchToAdjointSimulationMode().


The documentation for this class was generated from the following files: