Geant4 9.6.0
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 ()
 
void GeneratePrimaries (G4Event *)
 
void SetRndmFlag (const G4String &val)
 
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 ()
 
size_t GetNbOfAdjointPrimaryTypes ()
 
std::vector< G4ParticleDefinition * > GetListOfPrimaryFwdParticles ()
 
const G4StringGetPrimaryIonName ()
 
- Public Member Functions inherited from G4VUserPrimaryGeneratorAction
 G4VUserPrimaryGeneratorAction ()
 
virtual ~G4VUserPrimaryGeneratorAction ()
 
virtual void GeneratePrimaries (G4Event *anEvent)=0
 

Detailed Description

Definition at line 78 of file G4AdjointPrimaryGeneratorAction.hh.

Constructor & Destructor Documentation

◆ G4AdjointPrimaryGeneratorAction()

G4AdjointPrimaryGeneratorAction::G4AdjointPrimaryGeneratorAction ( )

Definition at line 47 of file G4AdjointPrimaryGeneratorAction.cc.

48 : Emin(0.), Emax(0.), EminIon(0.), EmaxIon(0.), NbOfAdjointPrimaryTypes(0),
49 index_particle(100000), last_generated_part_was_adjoint(false),
50 radius_spherical_source(0.), fwd_ion(0), adj_ion(0),
51 ion_name("not_defined")
52{
53 theAdjointPrimaryGenerator= new G4AdjointPrimaryGenerator();
54
55 PrimariesConsideredInAdjointSim[G4String("e-")]=false;
56 PrimariesConsideredInAdjointSim[G4String("gamma")]=false;
57 PrimariesConsideredInAdjointSim[G4String("proton")]=false;
58 PrimariesConsideredInAdjointSim[G4String("ion")]=false;
59
60 ListOfPrimaryFwdParticles.clear();
61 ListOfPrimaryAdjParticles.clear();
62}

◆ ~G4AdjointPrimaryGeneratorAction()

G4AdjointPrimaryGeneratorAction::~G4AdjointPrimaryGeneratorAction ( )

Definition at line 65 of file G4AdjointPrimaryGeneratorAction.cc.

66{
67 delete theAdjointPrimaryGenerator;
68}

Member Function Documentation

◆ ConsiderParticleAsPrimary()

void G4AdjointPrimaryGeneratorAction::ConsiderParticleAsPrimary ( const G4String particle_name)

Definition at line 194 of file G4AdjointPrimaryGeneratorAction.cc.

195{
196 if (PrimariesConsideredInAdjointSim.find(particle_name) != PrimariesConsideredInAdjointSim.end()){
197 PrimariesConsideredInAdjointSim[particle_name]=true;
198 }
200}

Referenced by G4AdjointSimManager::ConsiderParticleAsPrimary().

◆ GeneratePrimaries()

void G4AdjointPrimaryGeneratorAction::GeneratePrimaries ( G4Event anEvent)
virtual

Implements G4VUserPrimaryGeneratorAction.

Definition at line 71 of file G4AdjointPrimaryGeneratorAction.cc.

72{
73 if ( !last_generated_part_was_adjoint ) {
74
75 index_particle++;
76 if (index_particle >= ListOfPrimaryAdjParticles.size()) index_particle =0;
77
78
79 G4double E1=Emin;
80 G4double E2=Emax;
81 if (!ListOfPrimaryAdjParticles[index_particle]) UpdateListOfPrimaryParticles();//ion has not been created yet
82
83 if (ListOfPrimaryAdjParticles[index_particle]->GetParticleName() == "adj_proton") {
84 E1=EminIon;
85 E2=EmaxIon;
86 }
87 if (ListOfPrimaryAdjParticles[index_particle]->GetParticleType() == "adjoint_nucleus") {
88 G4int A= ListOfPrimaryAdjParticles[index_particle]->GetAtomicMass();
89 E1=EminIon*A;
90 E2=EmaxIon*A;
91 }
92 theAdjointPrimaryGenerator->GenerateAdjointPrimaryVertex(anEvent,
93 ListOfPrimaryAdjParticles[index_particle],
94 E1,E2);
95 G4PrimaryVertex* aPrimVertex = anEvent->GetPrimaryVertex();
96
97
98 p=aPrimVertex->GetPrimary()->GetMomentum();
99 pos=aPrimVertex->GetPosition();
100 G4double pmag=p.mag();
101
102 G4double m0=ListOfPrimaryAdjParticles[index_particle]->GetPDGMass();
103 G4double ekin=std::sqrt( m0*m0 + pmag*pmag) -m0;
104
105
106 //The factor pi is to normalise the weight to the directional flux
108 G4double adjoint_weight = ComputeEnergyDistWeight(ekin,E1,E2)*adjoint_source_area*pi;
109
110 aPrimVertex->SetWeight(adjoint_weight);
111
112 last_generated_part_was_adjoint =true;
115 }
116 else {
117 //fwd particle equivalent to the last generated adjoint particle ios generated
118 G4PrimaryVertex* aPrimVertex = new G4PrimaryVertex();
119 aPrimVertex->SetPosition(pos.x(),pos.y(),pos.z());
120 aPrimVertex->SetT0(0.);
121 G4PrimaryParticle* aPrimParticle = new G4PrimaryParticle(ListOfPrimaryFwdParticles[index_particle],
122 -p.x(),-p.y(),-p.z());
123
124 aPrimVertex->SetPrimary(aPrimParticle);
125 anEvent->AddPrimaryVertex(aPrimVertex);
126 last_generated_part_was_adjoint =false;
128 }
129}
double G4double
Definition: G4Types.hh:64
int G4int
Definition: G4Types.hh:66
double z() const
double x() const
double y() const
double mag() const
void GenerateAdjointPrimaryVertex(G4Event *anEvt, G4ParticleDefinition *adj_part, G4double E1, G4double E2)
void SetAdjointTrackingMode(G4bool aBool)
void RegisterAdjointPrimaryWeight(G4double aWeight)
static G4AdjointSimManager * GetInstance()
G4PrimaryVertex * GetPrimaryVertex(G4int i=0) const
Definition: G4Event.hh:155
void AddPrimaryVertex(G4PrimaryVertex *aPrimaryVertex)
Definition: G4Event.hh:142
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

◆ GetListOfPrimaryFwdParticles()

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

Definition at line 100 of file G4AdjointPrimaryGeneratorAction.hh.

100{return ListOfPrimaryFwdParticles;}

Referenced by G4AdjointSimManager::GetListOfPrimaryFwdParticles(), and G4AdjointSimManager::RegisterAtEndOfAdjointTrack().

◆ GetNbOfAdjointPrimaryTypes()

size_t G4AdjointPrimaryGeneratorAction::GetNbOfAdjointPrimaryTypes ( )
inline

Definition at line 99 of file G4AdjointPrimaryGeneratorAction.hh.

99{return ListOfPrimaryAdjParticles.size();}

Referenced by G4AdjointSimManager::RunAdjointSimulation().

◆ GetPrimaryIonName()

const G4String & G4AdjointPrimaryGeneratorAction::GetPrimaryIonName ( )
inline

Definition at line 101 of file G4AdjointPrimaryGeneratorAction.hh.

101{return ion_name;}

Referenced by G4AdjointSimManager::GetPrimaryIonName().

◆ NeglectParticleAsPrimary()

void G4AdjointPrimaryGeneratorAction::NeglectParticleAsPrimary ( const G4String particle_name)

Definition at line 203 of file G4AdjointPrimaryGeneratorAction.cc.

204{
205 if (PrimariesConsideredInAdjointSim.find(particle_name) != PrimariesConsideredInAdjointSim.end()){
206 PrimariesConsideredInAdjointSim[particle_name]= false;
207 }
209}

Referenced by G4AdjointSimManager::NeglectParticleAsPrimary().

◆ SetAdjointPrimarySourceOnAnExtSurfaceOfAVolume()

void G4AdjointPrimaryGeneratorAction::SetAdjointPrimarySourceOnAnExtSurfaceOfAVolume ( const G4String volume_name)

Definition at line 187 of file G4AdjointPrimaryGeneratorAction.cc.

188{
189 type_of_adjoint_source ="ExternalSurfaceOfAVolume";
190 theAdjointPrimaryGenerator->SetAdjointPrimarySourceOnAnExtSurfaceOfAVolume(volume_name);
191}
void SetAdjointPrimarySourceOnAnExtSurfaceOfAVolume(const G4String &volume_name)

Referenced by G4AdjointSimManager::DefineAdjointSourceOnTheExtSurfaceOfAVolume().

◆ SetEmax()

void G4AdjointPrimaryGeneratorAction::SetEmax ( G4double  val)

Definition at line 139 of file G4AdjointPrimaryGeneratorAction.cc.

140{
141 Emax=val;
142 EmaxIon=val;
143}

Referenced by G4AdjointSimManager::SetAdjointSourceEmax().

◆ SetEmaxIon()

void G4AdjointPrimaryGeneratorAction::SetEmaxIon ( G4double  val)

Definition at line 152 of file G4AdjointPrimaryGeneratorAction.cc.

153{
154 EmaxIon=val;
155}

◆ SetEmin()

void G4AdjointPrimaryGeneratorAction::SetEmin ( G4double  val)

Definition at line 132 of file G4AdjointPrimaryGeneratorAction.cc.

133{
134 Emin=val;
135 EminIon=val;
136}

Referenced by G4AdjointSimManager::SetAdjointSourceEmin().

◆ SetEminIon()

void G4AdjointPrimaryGeneratorAction::SetEminIon ( G4double  val)

Definition at line 146 of file G4AdjointPrimaryGeneratorAction.cc.

147{
148 EminIon=val;
149}

◆ SetPrimaryIon()

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

Definition at line 244 of file G4AdjointPrimaryGeneratorAction.cc.

245{
246 fwd_ion = fwdIon;
247 adj_ion = adjointIon;
249}

Referenced by G4AdjointSimManager::SetPrimaryIon().

◆ SetRndmFlag()

void G4AdjointPrimaryGeneratorAction::SetRndmFlag ( const G4String val)
inline

Definition at line 88 of file G4AdjointPrimaryGeneratorAction.hh.

88{ rndmFlag = val;}

◆ SetSphericalAdjointPrimarySource()

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

Definition at line 178 of file G4AdjointPrimaryGeneratorAction.cc.

179{
180 radius_spherical_source = radius;
181 center_spherical_source = center_pos;
182 type_of_adjoint_source ="Spherical";
183 theAdjointPrimaryGenerator->SetSphericalAdjointPrimarySource(radius,center_pos);
184}
void SetSphericalAdjointPrimarySource(G4double radius, G4ThreeVector pos)

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

◆ UpdateListOfPrimaryParticles()

void G4AdjointPrimaryGeneratorAction::UpdateListOfPrimaryParticles ( )

Definition at line 212 of file G4AdjointPrimaryGeneratorAction.cc.

213{
215 ListOfPrimaryFwdParticles.clear();
216 ListOfPrimaryAdjParticles.clear();
217 std::map<G4String, G4bool>::iterator iter;
218 for( iter = PrimariesConsideredInAdjointSim.begin(); iter != PrimariesConsideredInAdjointSim.end(); ++iter ) {
219 if(iter->second) {
220 G4String fwd_particle_name = iter->first;
221 if ( fwd_particle_name != "ion") {
222 G4String adj_particle_name = G4String("adj_") + fwd_particle_name;
223 ListOfPrimaryFwdParticles.push_back(theParticleTable->FindParticle(fwd_particle_name));
224 ListOfPrimaryAdjParticles.push_back(theParticleTable->FindParticle(adj_particle_name));
225 }
226 else {
227 if (fwd_ion ){
228 ion_name=fwd_ion->GetParticleName();
229 G4String adj_ion_name=G4String("adj_") +ion_name;
230 ListOfPrimaryFwdParticles.push_back(fwd_ion);
231 ListOfPrimaryAdjParticles.push_back(adj_ion);
232 }
233 else {
234 ListOfPrimaryFwdParticles.push_back(0);
235 ListOfPrimaryAdjParticles.push_back(0);
236
237 }
238 }
239 }
240 }
241}
const G4String & GetParticleName() const
G4ParticleDefinition * FindParticle(G4int PDGEncoding)
static G4ParticleTable * GetParticleTable()
G4int first(char) const

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


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