Geant4-11
Public Member Functions | Private Member Functions | Private Attributes
G4AdjointPrimaryGeneratorAction Class Reference

#include <G4AdjointPrimaryGeneratorAction.hh>

Inheritance diagram for G4AdjointPrimaryGeneratorAction:
G4VUserPrimaryGeneratorAction

Public Member Functions

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

Private Member Functions

G4double ComputeEnergyDistWeight (G4double energy, G4double E1, G4double E2)
 

Private Attributes

G4ParticleDefinitionadj_ion = nullptr
 
G4ThreeVector center_spherical_source
 
G4ThreeVector direction
 
G4double Emax = 0.0
 
G4double EmaxIon = 0.0
 
G4double Emin = 0.0
 
G4double EminIon = 0.0
 
G4ParticleDefinitionfwd_ion = nullptr
 
std::size_t index_particle = 100000
 
G4String ion_name = "not_defined"
 
std::vector< G4ParticleDefinition * > ListOfPrimaryAdjParticles
 
std::vector< G4ParticleDefinition * > ListOfPrimaryFwdParticles
 
G4int nb_adj_primary_electrons_per_event = 1
 
G4int nb_adj_primary_gammas_per_event = 1
 
G4int nb_fwd_gammas_per_event = 1
 
G4ThreeVector p
 
G4ThreeVector pos
 
std::map< G4String, G4boolPrimariesConsideredInAdjointSim
 
G4double radius_spherical_source = 0.0
 
G4String rndmFlag
 
G4AdjointPrimaryGeneratortheAdjointPrimaryGenerator = nullptr
 
G4String type_of_adjoint_source
 

Detailed Description

Definition at line 80 of file G4AdjointPrimaryGeneratorAction.hh.

Constructor & Destructor Documentation

◆ G4AdjointPrimaryGeneratorAction() [1/2]

G4AdjointPrimaryGeneratorAction::G4AdjointPrimaryGeneratorAction ( )

◆ ~G4AdjointPrimaryGeneratorAction()

G4AdjointPrimaryGeneratorAction::~G4AdjointPrimaryGeneratorAction ( )

Definition at line 63 of file G4AdjointPrimaryGeneratorAction.cc.

64{
66}

References theAdjointPrimaryGenerator.

◆ G4AdjointPrimaryGeneratorAction() [2/2]

G4AdjointPrimaryGeneratorAction::G4AdjointPrimaryGeneratorAction ( const G4AdjointPrimaryGeneratorAction )
delete

Member Function Documentation

◆ ComputeEnergyDistWeight()

G4double G4AdjointPrimaryGeneratorAction::ComputeEnergyDistWeight ( G4double  energy,
G4double  E1,
G4double  E2 
)
private

Definition at line 225 of file G4AdjointPrimaryGeneratorAction.cc.

228{
229 // We generate N numbers of primaries with a 1/E energy law distribution.
230 // We have therefore an energy distribution function
231 // f(E)=C/E (1)
232 // with C a constant that is such that
233 // N=Integral(f(E),E1,E2)=C.std::log(E2/E1) (2)
234 // Therefore from (2) we get
235 // C=N/ std::log(E2/E1) (3)
236 // and
237 // f(E)=N/ std::log(E2/E1)/E (4)
238 // For the adjoint simulation we need a energy distribution f'(E)=1..
239 // To get that we need therefore to apply a weight to the primary
240 // W=1/f(E)=E*std::log(E2/E1)/N
241 //
242 return std::log(E2 / E1) * E /
244}
static G4AdjointSimManager * GetInstance()

References G4AdjointSimManager::GetInstance(), and G4AdjointSimManager::GetNbEvtOfLastRun().

Referenced by GeneratePrimaries().

◆ ConsiderParticleAsPrimary()

void G4AdjointPrimaryGeneratorAction::ConsiderParticleAsPrimary ( const G4String particle_name)

◆ 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;
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 {
91 E1 = EminIon * A;
92 E2 = EmaxIon * A;
93 }
94 // Generate first the forwrad primaries
97 G4PrimaryVertex* fwdPrimVertex = anEvent->GetPrimaryVertex();
98
99 p = fwdPrimVertex->GetPrimary()->GetMomentum();
100 pos = fwdPrimVertex->GetPosition();
101 G4double pmag = p.mag();
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
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(
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(
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(
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(
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}
static constexpr double pi
Definition: G4SIunits.hh:55
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
G4double ComputeEnergyDistWeight(G4double energy, G4double E1, G4double E2)
void GenerateFwdPrimaryVertex(G4Event *anEvt, G4ParticleDefinition *adj_part, G4double E1, G4double E2)
void SetAdjointTrackingMode(G4bool aBool)
void ResetDidOneAdjPartReachExtSourceDuringEvent()
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

References A, G4Event::AddPrimaryVertex(), G4AdjointSimManager::ClearEndOfAdjointTrackInfoVectors(), ComputeEnergyDistWeight(), Emax, EmaxIon, Emin, EminIon, G4Gamma::Gamma(), G4AdjointPrimaryGenerator::GenerateFwdPrimaryVertex(), G4AdjointSimManager::GetAdjointSourceArea(), G4Event::GetEventID(), G4AdjointSimManager::GetInstance(), G4PrimaryParticle::GetMomentum(), G4PrimaryVertex::GetPosition(), G4PrimaryVertex::GetPrimary(), G4Event::GetPrimaryVertex(), index_particle, ListOfPrimaryAdjParticles, ListOfPrimaryFwdParticles, CLHEP::Hep3Vector::mag(), CLHEP::detail::n, nb_adj_primary_electrons_per_event, nb_adj_primary_gammas_per_event, nb_fwd_gammas_per_event, p, pi, pos, G4AdjointSimManager::ResetDidOneAdjPartReachExtSourceDuringEvent(), G4AdjointSimManager::SetAdjointTrackingMode(), G4PrimaryVertex::SetPosition(), G4PrimaryVertex::SetPrimary(), G4PrimaryVertex::SetT0(), G4PrimaryVertex::SetWeight(), theAdjointPrimaryGenerator, UpdateListOfPrimaryParticles(), CLHEP::Hep3Vector::x(), CLHEP::Hep3Vector::y(), and CLHEP::Hep3Vector::z().

◆ GetLastGeneratedFwdPrimaryParticle()

G4ParticleDefinition * G4AdjointPrimaryGeneratorAction::GetLastGeneratedFwdPrimaryParticle ( )
inline

◆ 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 }

References ListOfPrimaryAdjParticles.

Referenced by G4AdjointSimManager::RunAdjointSimulation().

◆ GetPrimaryIonName()

const G4String & G4AdjointPrimaryGeneratorAction::GetPrimaryIonName ( )
inline

Definition at line 119 of file G4AdjointPrimaryGeneratorAction.hh.

References ion_name.

Referenced by G4AdjointSimManager::GetPrimaryIonName().

◆ NeglectParticleAsPrimary()

void G4AdjointPrimaryGeneratorAction::NeglectParticleAsPrimary ( const G4String particle_name)

◆ operator=()

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

◆ SetAdjointPrimarySourceOnAnExtSurfaceOfAVolume()

void G4AdjointPrimaryGeneratorAction::SetAdjointPrimarySourceOnAnExtSurfaceOfAVolume ( const G4String volume_name)

◆ SetEmax()

void G4AdjointPrimaryGeneratorAction::SetEmax ( G4double  val)

Definition at line 203 of file G4AdjointPrimaryGeneratorAction.cc.

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

References Emax, and EmaxIon.

Referenced by G4AdjointSimManager::SetAdjointSourceEmax().

◆ SetEmaxIon()

void G4AdjointPrimaryGeneratorAction::SetEmaxIon ( G4double  val)

Definition at line 218 of file G4AdjointPrimaryGeneratorAction.cc.

219{
220 EmaxIon = val;
221}

References EmaxIon.

◆ SetEmin()

void G4AdjointPrimaryGeneratorAction::SetEmin ( G4double  val)

Definition at line 195 of file G4AdjointPrimaryGeneratorAction.cc.

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

References Emin, and EminIon.

Referenced by G4AdjointSimManager::SetAdjointSourceEmin().

◆ SetEminIon()

void G4AdjointPrimaryGeneratorAction::SetEminIon ( G4double  val)

Definition at line 211 of file G4AdjointPrimaryGeneratorAction.cc.

212{
213 EminIon = val;
214}

References EminIon.

◆ SetNbAdjointPrimaryElectronsPerEvent()

void G4AdjointPrimaryGeneratorAction::SetNbAdjointPrimaryElectronsPerEvent ( G4int  nb)
inline

◆ SetNbAdjointPrimaryGammasPerEvent()

void G4AdjointPrimaryGeneratorAction::SetNbAdjointPrimaryGammasPerEvent ( G4int  nb)
inline

◆ SetNbPrimaryFwdGammasPerEvent()

void G4AdjointPrimaryGeneratorAction::SetNbPrimaryFwdGammasPerEvent ( G4int  nb)
inline

◆ SetPrimaryIon()

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

◆ SetRndmFlag()

void G4AdjointPrimaryGeneratorAction::SetRndmFlag ( const G4String val)
inline

Definition at line 107 of file G4AdjointPrimaryGeneratorAction.hh.

References rndmFlag.

◆ SetSphericalAdjointPrimarySource()

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

◆ UpdateListOfPrimaryParticles()

void G4AdjointPrimaryGeneratorAction::UpdateListOfPrimaryParticles ( )

Definition at line 296 of file G4AdjointPrimaryGeneratorAction.cc.

297{
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;
311 theParticleTable->FindParticle(fwd_particle_name));
313 theParticleTable->FindParticle(adj_particle_name));
314 }
315 else
316 {
317 if(fwd_ion)
318 {
320 G4String adj_ion_name = G4String("adj_") + ion_name;
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()

References adj_ion, G4ParticleTable::FindParticle(), fwd_ion, G4ParticleDefinition::GetParticleName(), G4ParticleTable::GetParticleTable(), ion_name, ListOfPrimaryAdjParticles, ListOfPrimaryFwdParticles, and PrimariesConsideredInAdjointSim.

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

Field Documentation

◆ adj_ion

G4ParticleDefinition* G4AdjointPrimaryGeneratorAction::adj_ion = nullptr
private

◆ center_spherical_source

G4ThreeVector G4AdjointPrimaryGeneratorAction::center_spherical_source
private

◆ direction

G4ThreeVector G4AdjointPrimaryGeneratorAction::direction
private

Definition at line 168 of file G4AdjointPrimaryGeneratorAction.hh.

◆ Emax

G4double G4AdjointPrimaryGeneratorAction::Emax = 0.0
private

Definition at line 154 of file G4AdjointPrimaryGeneratorAction.hh.

Referenced by GeneratePrimaries(), and SetEmax().

◆ EmaxIon

G4double G4AdjointPrimaryGeneratorAction::EmaxIon = 0.0
private

Definition at line 156 of file G4AdjointPrimaryGeneratorAction.hh.

Referenced by GeneratePrimaries(), SetEmax(), and SetEmaxIon().

◆ Emin

G4double G4AdjointPrimaryGeneratorAction::Emin = 0.0
private

Definition at line 153 of file G4AdjointPrimaryGeneratorAction.hh.

Referenced by GeneratePrimaries(), and SetEmin().

◆ EminIon

G4double G4AdjointPrimaryGeneratorAction::EminIon = 0.0
private

Definition at line 155 of file G4AdjointPrimaryGeneratorAction.hh.

Referenced by GeneratePrimaries(), SetEmin(), and SetEminIon().

◆ fwd_ion

G4ParticleDefinition* G4AdjointPrimaryGeneratorAction::fwd_ion = nullptr
private

◆ index_particle

std::size_t G4AdjointPrimaryGeneratorAction::index_particle = 100000
private

◆ ion_name

G4String G4AdjointPrimaryGeneratorAction::ion_name = "not_defined"
private

◆ ListOfPrimaryAdjParticles

std::vector<G4ParticleDefinition*> G4AdjointPrimaryGeneratorAction::ListOfPrimaryAdjParticles
private

◆ ListOfPrimaryFwdParticles

std::vector<G4ParticleDefinition*> G4AdjointPrimaryGeneratorAction::ListOfPrimaryFwdParticles
private

◆ nb_adj_primary_electrons_per_event

G4int G4AdjointPrimaryGeneratorAction::nb_adj_primary_electrons_per_event = 1
private

◆ nb_adj_primary_gammas_per_event

G4int G4AdjointPrimaryGeneratorAction::nb_adj_primary_gammas_per_event = 1
private

◆ nb_fwd_gammas_per_event

G4int G4AdjointPrimaryGeneratorAction::nb_fwd_gammas_per_event = 1
private

◆ p

G4ThreeVector G4AdjointPrimaryGeneratorAction::p
private

Definition at line 168 of file G4AdjointPrimaryGeneratorAction.hh.

Referenced by GeneratePrimaries().

◆ pos

G4ThreeVector G4AdjointPrimaryGeneratorAction::pos
private

Definition at line 168 of file G4AdjointPrimaryGeneratorAction.hh.

Referenced by GeneratePrimaries().

◆ PrimariesConsideredInAdjointSim

std::map<G4String, G4bool> G4AdjointPrimaryGeneratorAction::PrimariesConsideredInAdjointSim
private

◆ radius_spherical_source

G4double G4AdjointPrimaryGeneratorAction::radius_spherical_source = 0.0
private

◆ rndmFlag

G4String G4AdjointPrimaryGeneratorAction::rndmFlag
private

Definition at line 146 of file G4AdjointPrimaryGeneratorAction.hh.

Referenced by SetRndmFlag().

◆ theAdjointPrimaryGenerator

G4AdjointPrimaryGenerator* G4AdjointPrimaryGeneratorAction::theAdjointPrimaryGenerator = nullptr
private

◆ type_of_adjoint_source

G4String G4AdjointPrimaryGeneratorAction::type_of_adjoint_source
private

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