Geant4 11.1.1
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 ()
 
 G4AdjointPrimaryGeneratorAction (const G4AdjointPrimaryGeneratorAction &)=delete
 
G4AdjointPrimaryGeneratorActionoperator= (const G4AdjointPrimaryGeneratorAction &)=delete
 
void GeneratePrimaries (G4Event *)
 
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 ()
 
virtual void GeneratePrimaries (G4Event *anEvent)=0
 

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 ( )

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 270 of file G4AdjointPrimaryGeneratorAction.cc.

272{
273 if(PrimariesConsideredInAdjointSim.find(particle_name) !=
274 PrimariesConsideredInAdjointSim.end())
275 {
276 PrimariesConsideredInAdjointSim[particle_name] = true;
277 }
279}

Referenced by G4AdjointSimManager::ConsiderParticleAsPrimary().

◆ GeneratePrimaries()

void G4AdjointPrimaryGeneratorAction::GeneratePrimaries ( G4Event anEvent)
virtual

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() ==
82 "adj_proton")
83 {
84 E1 = EminIon;
85 E2 = EmaxIon;
86 }
87 if(ListOfPrimaryAdjParticles[index_particle]->GetParticleType() ==
88 "adjoint_nucleus")
89 {
90 G4int A = ListOfPrimaryAdjParticles[index_particle]->GetAtomicMass();
91 E1 = EminIon * A;
92 E2 = EmaxIon * A;
93 }
94 // Generate first the forwrad primaries
95 theAdjointPrimaryGenerator->GenerateFwdPrimaryVertex(
96 anEvent, ListOfPrimaryFwdParticles[index_particle], E1, E2);
97 G4PrimaryVertex* fwdPrimVertex = anEvent->GetPrimaryVertex();
98
99 p = fwdPrimVertex->GetPrimary()->GetMomentum();
100 pos = fwdPrimVertex->GetPosition();
101 G4double pmag = p.mag();
102 G4double m0 = ListOfPrimaryFwdParticles[index_particle]->GetPDGMass();
103 G4double ekin = std::sqrt(m0 * m0 + pmag * pmag) - m0;
104
105 G4double weight_correction = 1.;
106 // For gamma generate the particle along the backward ray
107 G4ThreeVector dir = -p / p.mag();
108
109 weight_correction = 1.;
110
111 if(ListOfPrimaryFwdParticles[index_particle] == G4Gamma::Gamma() &&
112 nb_fwd_gammas_per_event > 1)
113 {
114 G4double weight = (1. / nb_fwd_gammas_per_event);
115 fwdPrimVertex->SetWeight(weight);
116 for(G4int i = 0; i < nb_fwd_gammas_per_event - 1; ++i)
117 {
118 G4PrimaryVertex* newFwdPrimVertex = new G4PrimaryVertex();
119 newFwdPrimVertex->SetPosition(pos.x(), pos.y(), pos.z());
120 newFwdPrimVertex->SetT0(0.);
121 G4PrimaryParticle* aPrimParticle = new G4PrimaryParticle(
122 ListOfPrimaryFwdParticles[index_particle], p.x(), p.y(), p.z());
123 newFwdPrimVertex->SetPrimary(aPrimParticle);
124 newFwdPrimVertex->SetWeight(weight);
125 anEvent->AddPrimaryVertex(newFwdPrimVertex);
126 }
127 }
128
129 // Now generate the adjoint primaries
130 G4PrimaryVertex* adjPrimVertex = new G4PrimaryVertex();
131 adjPrimVertex->SetPosition(pos.x(), pos.y(), pos.z());
132 adjPrimVertex->SetT0(0.);
133 G4PrimaryParticle* aPrimParticle = new G4PrimaryParticle(
134 ListOfPrimaryAdjParticles[index_particle], -p.x(), -p.y(), -p.z());
135
136 adjPrimVertex->SetPrimary(aPrimParticle);
137 anEvent->AddPrimaryVertex(adjPrimVertex);
138
139 // The factor pi is to normalise the weight to the directional flux
140 G4double adjoint_source_area =
142 G4double adjoint_weight = weight_correction *
143 ComputeEnergyDistWeight(ekin, E1, E2) *
144 adjoint_source_area * pi;
145 // if (ListOfPrimaryFwdParticles[index_particle] ==G4Gamma::Gamma())
146 // adjoint_weight = adjoint_weight/3.;
147 if(ListOfPrimaryAdjParticles[index_particle]->GetParticleName() ==
148 "adj_gamma")
149 {
150 // The weight will be corrected at the end of the track if splitted tracks
151 // are used
152 adjoint_weight = adjoint_weight / nb_adj_primary_gammas_per_event;
153 for(G4int i = 0; i < nb_adj_primary_gammas_per_event - 1; ++i)
154 {
155 G4PrimaryVertex* newAdjPrimVertex = new G4PrimaryVertex();
156 newAdjPrimVertex->SetPosition(pos.x(), pos.y(), pos.z());
157 newAdjPrimVertex->SetT0(0.);
158 aPrimParticle = new G4PrimaryParticle(
159 ListOfPrimaryAdjParticles[index_particle], -p.x(), -p.y(), -p.z());
160 newAdjPrimVertex->SetPrimary(aPrimParticle);
161 newAdjPrimVertex->SetWeight(adjoint_weight);
162 anEvent->AddPrimaryVertex(newAdjPrimVertex);
163 }
164 }
165 else if(ListOfPrimaryAdjParticles[index_particle]->GetParticleName() ==
166 "adj_electron")
167 {
168 // The weight will be corrected at the end of the track if splitted tracks
169 // are used
170 adjoint_weight = adjoint_weight / nb_adj_primary_electrons_per_event;
171 for(G4int i = 0; i < nb_adj_primary_electrons_per_event - 1; ++i)
172 {
173 G4PrimaryVertex* newAdjPrimVertex = new G4PrimaryVertex();
174 newAdjPrimVertex->SetPosition(pos.x(), pos.y(), pos.z());
175 newAdjPrimVertex->SetT0(0.);
176 aPrimParticle = new G4PrimaryParticle(
177 ListOfPrimaryAdjParticles[index_particle], -p.x(), -p.y(), -p.z());
178 newAdjPrimVertex->SetPrimary(aPrimParticle);
179 newAdjPrimVertex->SetWeight(adjoint_weight);
180 anEvent->AddPrimaryVertex(newAdjPrimVertex);
181 }
182 }
183 adjPrimVertex->SetWeight(adjoint_weight);
184
185 // Call some methods of G4AdjointSimManager
190
191}
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:137
G4int GetEventID() const
Definition: G4Event.hh:118
void AddPrimaryVertex(G4PrimaryVertex *aPrimaryVertex)
Definition: G4Event.hh:121
static G4Gamma * Gamma()
Definition: G4Gamma.cc:85
G4ThreeVector GetMomentum() const
void SetPosition(G4double x0, G4double y0, G4double z0)
G4ThreeVector GetPosition() const
void SetPrimary(G4PrimaryParticle *pp)
void SetWeight(G4double w)
void SetT0(G4double t0)
G4PrimaryParticle * GetPrimary(G4int i=0) const
const G4double pi

◆ GetLastGeneratedFwdPrimaryParticle()

G4ParticleDefinition * G4AdjointPrimaryGeneratorAction::GetLastGeneratedFwdPrimaryParticle ( )
inline

Definition at line 135 of file G4AdjointPrimaryGeneratorAction.hh.

136 {
137 return ListOfPrimaryFwdParticles[index_particle];
138 }

Referenced by G4AdjointSimManager::GetLastGeneratedFwdPrimaryParticle().

◆ GetListOfPrimaryFwdParticles()

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

◆ GetNbOfAdjointPrimaryTypes()

size_t G4AdjointPrimaryGeneratorAction::GetNbOfAdjointPrimaryTypes ( )
inline

Definition at line 111 of file G4AdjointPrimaryGeneratorAction.hh.

112 {
113 return ListOfPrimaryAdjParticles.size();
114 }

◆ GetPrimaryIonName()

const G4String & G4AdjointPrimaryGeneratorAction::GetPrimaryIonName ( )
inline

Definition at line 119 of file G4AdjointPrimaryGeneratorAction.hh.

120 {
121 return ion_name;
122 }

Referenced by G4AdjointSimManager::GetPrimaryIonName().

◆ NeglectParticleAsPrimary()

void G4AdjointPrimaryGeneratorAction::NeglectParticleAsPrimary ( const G4String particle_name)

Definition at line 283 of file G4AdjointPrimaryGeneratorAction.cc.

285{
286 if(PrimariesConsideredInAdjointSim.find(particle_name) !=
287 PrimariesConsideredInAdjointSim.end())
288 {
289 PrimariesConsideredInAdjointSim[particle_name] = false;
290 }
292}

Referenced by G4AdjointSimManager::NeglectParticleAsPrimary().

◆ operator=()

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

◆ SetAdjointPrimarySourceOnAnExtSurfaceOfAVolume()

void G4AdjointPrimaryGeneratorAction::SetAdjointPrimarySourceOnAnExtSurfaceOfAVolume ( const G4String volume_name)

Definition at line 260 of file G4AdjointPrimaryGeneratorAction.cc.

262{
263 type_of_adjoint_source = "ExternalSurfaceOfAVolume";
264 theAdjointPrimaryGenerator->SetAdjointPrimarySourceOnAnExtSurfaceOfAVolume(
265 volume_name);
266}
void SetAdjointPrimarySourceOnAnExtSurfaceOfAVolume(const G4String &v_name)

Referenced by G4AdjointSimManager::DefineAdjointSourceOnTheExtSurfaceOfAVolume().

◆ SetEmax()

void G4AdjointPrimaryGeneratorAction::SetEmax ( G4double  val)

Definition at line 203 of file G4AdjointPrimaryGeneratorAction.cc.

204{
205 Emax = val;
206 EmaxIon = val;
207}

Referenced by G4AdjointSimManager::SetAdjointSourceEmax().

◆ SetEmaxIon()

void G4AdjointPrimaryGeneratorAction::SetEmaxIon ( G4double  val)

Definition at line 218 of file G4AdjointPrimaryGeneratorAction.cc.

219{
220 EmaxIon = val;
221}

◆ SetEmin()

void G4AdjointPrimaryGeneratorAction::SetEmin ( G4double  val)

Definition at line 195 of file G4AdjointPrimaryGeneratorAction.cc.

196{
197 Emin = val;
198 EminIon = val;
199}

Referenced by G4AdjointSimManager::SetAdjointSourceEmin().

◆ SetEminIon()

void G4AdjointPrimaryGeneratorAction::SetEminIon ( G4double  val)

Definition at line 211 of file G4AdjointPrimaryGeneratorAction.cc.

212{
213 EminIon = val;
214}

◆ SetNbAdjointPrimaryElectronsPerEvent()

void G4AdjointPrimaryGeneratorAction::SetNbAdjointPrimaryElectronsPerEvent ( G4int  nb)
inline

Definition at line 131 of file G4AdjointPrimaryGeneratorAction.hh.

132 {
133 nb_adj_primary_electrons_per_event = nb;
134 }

Referenced by G4AdjointSimManager::SetNbAdjointPrimaryElectronsPerEvent().

◆ SetNbAdjointPrimaryGammasPerEvent()

void G4AdjointPrimaryGeneratorAction::SetNbAdjointPrimaryGammasPerEvent ( G4int  nb)
inline

Definition at line 127 of file G4AdjointPrimaryGeneratorAction.hh.

128 {
129 nb_adj_primary_gammas_per_event = nb;
130 }

Referenced by G4AdjointSimManager::SetNbAdjointPrimaryGammasPerEvent().

◆ SetNbPrimaryFwdGammasPerEvent()

void G4AdjointPrimaryGeneratorAction::SetNbPrimaryFwdGammasPerEvent ( G4int  nb)
inline

Definition at line 123 of file G4AdjointPrimaryGeneratorAction.hh.

124 {
125 nb_fwd_gammas_per_event = nb;
126 }

Referenced by G4AdjointSimManager::SetNbOfPrimaryFwdGammasPerEvent().

◆ SetPrimaryIon()

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

Definition at line 336 of file G4AdjointPrimaryGeneratorAction.cc.

338{
339 fwd_ion = fwdIon;
340 adj_ion = adjointIon;
342}

Referenced by G4AdjointSimManager::SetPrimaryIon().

◆ SetRndmFlag()

void G4AdjointPrimaryGeneratorAction::SetRndmFlag ( const G4String val)
inline

Definition at line 107 of file G4AdjointPrimaryGeneratorAction.hh.

108 {
109 rndmFlag = val;
110 }

◆ SetSphericalAdjointPrimarySource()

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

Definition at line 248 of file G4AdjointPrimaryGeneratorAction.cc.

250{
251 radius_spherical_source = radius;
252 center_spherical_source = center_pos;
253 type_of_adjoint_source = "Spherical";
254 theAdjointPrimaryGenerator->SetSphericalAdjointPrimarySource(radius,
255 center_pos);
256}
void SetSphericalAdjointPrimarySource(G4double radius, G4ThreeVector pos)

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

◆ UpdateListOfPrimaryParticles()

void G4AdjointPrimaryGeneratorAction::UpdateListOfPrimaryParticles ( )

Definition at line 296 of file G4AdjointPrimaryGeneratorAction.cc.

297{
299 ListOfPrimaryFwdParticles.clear();
300 ListOfPrimaryAdjParticles.clear();
301 for(auto iter = PrimariesConsideredInAdjointSim.cbegin();
302 iter != PrimariesConsideredInAdjointSim.cend(); ++iter)
303 {
304 if(iter->second)
305 {
306 G4String fwd_particle_name = iter->first;
307 if(fwd_particle_name != "ion")
308 {
309 G4String adj_particle_name = G4String("adj_") + fwd_particle_name;
310 ListOfPrimaryFwdParticles.push_back(
311 theParticleTable->FindParticle(fwd_particle_name));
312 ListOfPrimaryAdjParticles.push_back(
313 theParticleTable->FindParticle(adj_particle_name));
314 }
315 else
316 {
317 if(fwd_ion)
318 {
319 ion_name = fwd_ion->GetParticleName();
320 G4String adj_ion_name = G4String("adj_") + ion_name;
321 ListOfPrimaryFwdParticles.push_back(fwd_ion);
322 ListOfPrimaryAdjParticles.push_back(adj_ion);
323 }
324 else
325 {
326 ListOfPrimaryFwdParticles.push_back(nullptr);
327 ListOfPrimaryAdjParticles.push_back(nullptr);
328 }
329 }
330 }
331 }
332}
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: