52 , index_particle(100000)
53 , radius_spherical_source(0.)
56 , ion_name(
"not_defined")
60 PrimariesConsideredInAdjointSim[
G4String(
"e-")] =
false;
61 PrimariesConsideredInAdjointSim[
G4String(
"gamma")] =
false;
62 PrimariesConsideredInAdjointSim[
G4String(
"proton")] =
false;
63 PrimariesConsideredInAdjointSim[
G4String(
"ion")] =
false;
65 ListOfPrimaryFwdParticles.clear();
66 ListOfPrimaryAdjParticles.clear();
67 nb_fwd_gammas_per_event = 1;
68 nb_adj_primary_gammas_per_event = 1;
69 nb_adj_primary_electrons_per_event = 1;
75 delete theAdjointPrimaryGenerator;
82 size_t n = ListOfPrimaryAdjParticles.size();
83 index_particle = size_t(evt_id) - n * (size_t(evt_id) / n);
87 if(!ListOfPrimaryAdjParticles[index_particle])
90 if(ListOfPrimaryAdjParticles[index_particle]->GetParticleName() ==
96 if(ListOfPrimaryAdjParticles[index_particle]->GetParticleType() ==
99 G4int A = ListOfPrimaryAdjParticles[index_particle]->GetAtomicMass();
105 anEvent, ListOfPrimaryFwdParticles[index_particle], E1, E2);
111 G4double m0 = ListOfPrimaryFwdParticles[index_particle]->GetPDGMass();
112 G4double ekin = std::sqrt(m0 * m0 + pmag * pmag) - m0;
132 weight_correction = 1.;
134 if(ListOfPrimaryFwdParticles[index_particle] ==
G4Gamma::Gamma() &&
135 nb_fwd_gammas_per_event > 1)
137 G4double weight = (1. / nb_fwd_gammas_per_event);
139 for(
int i = 0; i < nb_fwd_gammas_per_event - 1; i++)
143 newFwdPrimVertex->
SetT0(0.);
145 ListOfPrimaryFwdParticles[index_particle], p.
x(), p.
y(), p.
z());
155 adjPrimVertex->
SetT0(0.);
157 ListOfPrimaryAdjParticles[index_particle], -p.
x(), -p.
y(), -p.
z());
165 G4double adjoint_weight = weight_correction *
166 ComputeEnergyDistWeight(ekin, E1, E2) *
167 adjoint_source_area * pi;
170 if(ListOfPrimaryAdjParticles[index_particle]->GetParticleName() ==
175 adjoint_weight = adjoint_weight / nb_adj_primary_gammas_per_event;
176 for(
int i = 0; i < nb_adj_primary_gammas_per_event - 1; i++)
180 newAdjPrimVertex->
SetT0(0.);
182 ListOfPrimaryAdjParticles[index_particle], -p.
x(), -p.
y(), -p.
z());
184 newAdjPrimVertex->
SetWeight(adjoint_weight);
188 else if(ListOfPrimaryAdjParticles[index_particle]->GetParticleName() ==
193 adjoint_weight = adjoint_weight / nb_adj_primary_electrons_per_event;
194 for(
int i = 0; i < nb_adj_primary_electrons_per_event - 1; i++)
198 newAdjPrimVertex->
SetT0(0.);
200 ListOfPrimaryAdjParticles[index_particle], -p.
x(), -p.
y(), -p.
z());
202 newAdjPrimVertex->
SetWeight(adjoint_weight);
206 adjPrimVertex->
SetWeight(adjoint_weight);
301G4double G4AdjointPrimaryGeneratorAction::ComputeEnergyDistWeight(
G4double E,
318 return std::log(E2 / E1) * E /
326 radius_spherical_source = radius;
327 center_spherical_source = center_pos;
328 type_of_adjoint_source =
"Spherical";
337 type_of_adjoint_source =
"ExternalSurfaceOfAVolume";
346 if(PrimariesConsideredInAdjointSim.find(particle_name) !=
347 PrimariesConsideredInAdjointSim.end())
349 PrimariesConsideredInAdjointSim[particle_name] =
true;
358 if(PrimariesConsideredInAdjointSim.find(particle_name) !=
359 PrimariesConsideredInAdjointSim.end())
361 PrimariesConsideredInAdjointSim[particle_name] =
false;
370 ListOfPrimaryFwdParticles.clear();
371 ListOfPrimaryAdjParticles.clear();
372 std::map<G4String, G4bool>::iterator iter;
373 for(iter = PrimariesConsideredInAdjointSim.begin();
374 iter != PrimariesConsideredInAdjointSim.end(); ++iter)
379 if(fwd_particle_name !=
"ion")
382 ListOfPrimaryFwdParticles.push_back(
384 ListOfPrimaryAdjParticles.push_back(
401 ListOfPrimaryFwdParticles.push_back(fwd_ion);
402 ListOfPrimaryAdjParticles.push_back(adj_ion);
406 ListOfPrimaryFwdParticles.push_back(0);
407 ListOfPrimaryAdjParticles.push_back(0);
419 adj_ion = adjointIon;
double A(double temperature)
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
std::size_t first(char) const