52 PrimariesConsideredInAdjointSim[
G4String(
"e-")] =
false;
53 PrimariesConsideredInAdjointSim[
G4String(
"gamma")] =
false;
54 PrimariesConsideredInAdjointSim[
G4String(
"proton")] =
false;
55 PrimariesConsideredInAdjointSim[
G4String(
"ion")] =
false;
57 ListOfPrimaryFwdParticles.clear();
58 ListOfPrimaryAdjParticles.clear();
65 delete theAdjointPrimaryGenerator;
73 std::size_t n = ListOfPrimaryAdjParticles.size();
74 index_particle = std::size_t(evt_id) - n * (std::size_t(evt_id) / n);
78 if(ListOfPrimaryAdjParticles[index_particle] ==
nullptr)
81 if(ListOfPrimaryAdjParticles[index_particle]->GetParticleName() ==
87 if(ListOfPrimaryAdjParticles[index_particle]->GetParticleType() ==
90 G4int A = ListOfPrimaryAdjParticles[index_particle]->GetAtomicMass();
96 anEvent, ListOfPrimaryFwdParticles[index_particle], E1, E2);
102 G4double m0 = ListOfPrimaryFwdParticles[index_particle]->GetPDGMass();
103 G4double ekin = std::sqrt(m0 * m0 + pmag * pmag) - m0;
109 weight_correction = 1.;
111 if(ListOfPrimaryFwdParticles[index_particle] ==
G4Gamma::Gamma() &&
112 nb_fwd_gammas_per_event > 1)
114 G4double weight = (1. / nb_fwd_gammas_per_event);
116 for(
G4int i = 0; i < nb_fwd_gammas_per_event - 1; ++i)
120 newFwdPrimVertex->
SetT0(0.);
122 ListOfPrimaryFwdParticles[index_particle], p.
x(), p.
y(), p.
z());
132 adjPrimVertex->
SetT0(0.);
134 ListOfPrimaryAdjParticles[index_particle], -p.
x(), -p.
y(), -p.
z());
142 G4double adjoint_weight = weight_correction *
143 ComputeEnergyDistWeight(ekin, E1, E2) *
144 adjoint_source_area * pi;
147 if(ListOfPrimaryAdjParticles[index_particle]->GetParticleName() ==
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)
157 newAdjPrimVertex->
SetT0(0.);
159 ListOfPrimaryAdjParticles[index_particle], -p.
x(), -p.
y(), -p.
z());
161 newAdjPrimVertex->
SetWeight(adjoint_weight);
165 else if(ListOfPrimaryAdjParticles[index_particle]->GetParticleName() ==
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)
175 newAdjPrimVertex->
SetT0(0.);
177 ListOfPrimaryAdjParticles[index_particle], -p.
x(), -p.
y(), -p.
z());
179 newAdjPrimVertex->
SetWeight(adjoint_weight);
183 adjPrimVertex->
SetWeight(adjoint_weight);
225G4double G4AdjointPrimaryGeneratorAction::ComputeEnergyDistWeight(
G4double E,
242 return std::log(E2 / E1) * E /
251 radius_spherical_source = radius;
252 center_spherical_source = center_pos;
253 type_of_adjoint_source =
"Spherical";
263 type_of_adjoint_source =
"ExternalSurfaceOfAVolume";
273 if(PrimariesConsideredInAdjointSim.find(particle_name) !=
274 PrimariesConsideredInAdjointSim.end())
276 PrimariesConsideredInAdjointSim[particle_name] =
true;
286 if(PrimariesConsideredInAdjointSim.find(particle_name) !=
287 PrimariesConsideredInAdjointSim.end())
289 PrimariesConsideredInAdjointSim[particle_name] =
false;
299 ListOfPrimaryFwdParticles.clear();
300 ListOfPrimaryAdjParticles.clear();
301 for(
auto iter = PrimariesConsideredInAdjointSim.cbegin();
302 iter != PrimariesConsideredInAdjointSim.cend(); ++iter)
306 G4String fwd_particle_name = iter->first;
307 if(fwd_particle_name !=
"ion")
310 ListOfPrimaryFwdParticles.push_back(
312 ListOfPrimaryAdjParticles.push_back(
321 ListOfPrimaryFwdParticles.push_back(fwd_ion);
322 ListOfPrimaryAdjParticles.push_back(adj_ion);
326 ListOfPrimaryFwdParticles.push_back(
nullptr);
327 ListOfPrimaryAdjParticles.push_back(
nullptr);
340 adj_ion = adjointIon;
void UpdateListOfPrimaryParticles()
void GeneratePrimaries(G4Event *)
void ConsiderParticleAsPrimary(const G4String &particle_name)
void SetAdjointPrimarySourceOnAnExtSurfaceOfAVolume(const G4String &volume_name)
void SetSphericalAdjointPrimarySource(G4double radius, G4ThreeVector pos)
void SetEminIon(G4double val)
void SetEmin(G4double val)
void NeglectParticleAsPrimary(const G4String &particle_name)
void SetPrimaryIon(G4ParticleDefinition *adjointIon, G4ParticleDefinition *fwdIon)
~G4AdjointPrimaryGeneratorAction()
void SetEmaxIon(G4double val)
void SetEmax(G4double val)
G4AdjointPrimaryGeneratorAction()
void SetSphericalAdjointPrimarySource(G4double radius, G4ThreeVector pos)
void SetAdjointPrimarySourceOnAnExtSurfaceOfAVolume(const G4String &v_name)
void GenerateFwdPrimaryVertex(G4Event *anEvt, G4ParticleDefinition *adj_part, G4double E1, G4double E2)
void ClearEndOfAdjointTrackInfoVectors()
void SetAdjointTrackingMode(G4bool aBool)
G4double GetAdjointSourceArea()
void ResetDidOneAdjPartReachExtSourceDuringEvent()
G4int GetNbEvtOfLastRun()
static G4AdjointSimManager * GetInstance()
G4PrimaryVertex * GetPrimaryVertex(G4int i=0) const
void AddPrimaryVertex(G4PrimaryVertex *aPrimaryVertex)
const G4String & GetParticleName() const
G4ParticleDefinition * FindParticle(G4int PDGEncoding)
static G4ParticleTable * GetParticleTable()
G4ThreeVector GetMomentum() const
void SetPosition(G4double x0, G4double y0, G4double z0)
G4ThreeVector GetPosition() const
void SetPrimary(G4PrimaryParticle *pp)
void SetWeight(G4double w)
G4PrimaryParticle * GetPrimary(G4int i=0) const