61G4AdjointSimManager::G4AdjointSimManager()
75G4AdjointSimManager::~G4AdjointSimManager()
77 delete theAdjointRunAction;
78 delete theAdjointPrimaryGeneratorAction;
79 delete theAdjointSteppingAction;
80 delete theAdjointEventAction;
81 delete theAdjointTrackingAction;
82 delete theAdjointStackingAction;
100 if (welcome_message) {
101 G4cout <<
"****************************************************************" << std::endl;
102 G4cout <<
"*** Geant4 Reverse/Adjoint Monte Carlo mode ***" << std::endl;
103 G4cout <<
"*** Author: L.Desorgher ***" << std::endl;
104 G4cout <<
"*** Company: SpaceIT GmbH, Bern, Switzerland ***" << std::endl;
105 G4cout <<
"*** Sponsored by: ESA/ESTEC contract contract 21435/08/NL/AT ***" << std::endl;
106 G4cout <<
"****************************************************************" << std::endl;
107 welcome_message =
false;
116 nb_evt_of_last_run = nb_evt;
127void G4AdjointSimManager::SetRestOfAdjointActions()
131 if (!user_action_already_defined) DefineUserActions();
136 theRunManager->G4RunManager::SetUserAction(theAdjointEventAction);
137 theRunManager->G4RunManager::SetUserAction(theAdjointSteppingAction);
138 theRunManager->G4RunManager::SetUserAction(theAdjointTrackingAction);
152 adjoint_sim_mode =
true;
153 ID_of_last_particle_that_reach_the_ext_source = 0;
163 adjoint_sim_mode =
false;
168void G4AdjointSimManager::SetAdjointActions()
172 if (!user_action_already_defined) DefineUserActions();
176 theRunManager->G4RunManager::SetUserAction(
this);
177 theRunManager->G4RunManager::SetUserAction(theAdjointPrimaryGeneratorAction);
178 theRunManager->G4RunManager::SetUserAction(theAdjointStackingAction);
179 if (use_user_StackingAction)
183 theRunManager->G4RunManager::SetUserAction(theAdjointEventAction);
184 theRunManager->G4RunManager::SetUserAction(theAdjointSteppingAction);
185 theRunManager->G4RunManager::SetUserAction(theAdjointTrackingAction);
186 if (use_user_TrackingAction)
194void G4AdjointSimManager::SetAdjointPrimaryRunAndStackingActions()
198 if (!user_action_already_defined) DefineUserActions();
203 theRunManager->G4RunManager::SetUserAction(theAdjointRunAction);
204 theRunManager->G4RunManager::SetUserAction(theAdjointPrimaryGeneratorAction);
205 theRunManager->G4RunManager::SetUserAction(theAdjointStackingAction);
206 if (use_user_StackingAction)
214void G4AdjointSimManager::ResetUserActions()
220 theRunManager->G4RunManager::SetUserAction(fUserRunAction);
221 theRunManager->G4RunManager::SetUserAction(fUserEventAction);
222 theRunManager->G4RunManager::SetUserAction(fUserSteppingAction);
223 theRunManager->G4RunManager::SetUserAction(fUserTrackingAction);
224 theRunManager->G4RunManager::SetUserAction(fUserPrimaryGeneratorAction);
225 theRunManager->G4RunManager::SetUserAction(fUserStackingAction);
230void G4AdjointSimManager::ResetRestOfUserActions()
237 theRunManager->G4RunManager::SetUserAction(fUserEventAction);
238 theRunManager->G4RunManager::SetUserAction(fUserSteppingAction);
239 theRunManager->G4RunManager::SetUserAction(fUserTrackingAction);
244void G4AdjointSimManager::ResetUserPrimaryRunAndStackingActions()
249 theRunManager->G4RunManager::SetUserAction(fUserRunAction);
250 theRunManager->G4RunManager::SetUserAction(fUserPrimaryGeneratorAction);
251 theRunManager->G4RunManager::SetUserAction(fUserStackingAction);
256void G4AdjointSimManager::DefineUserActions()
263 fUserPrimaryGeneratorAction =
267 user_action_already_defined =
true;
281 adjoint_tracking_mode = aBool;
283 if (adjoint_tracking_mode) {
284 SetRestOfAdjointActions();
289 ResetRestOfUserActions();
404 last_direction /= last_direction.
mag();
405 last_cos_th = last_direction.
z();
410 last_fwd_part_name.erase(0, 4);
412 last_fwd_part_PDGEncoding =
415 std::vector<G4ParticleDefinition*>* aList =
417 last_fwd_part_index = -1;
419 while (i < (
G4int)aList->size() && last_fwd_part_index < 0) {
420 if ((*aList)[i]->GetParticleName() == last_fwd_part_name) last_fwd_part_index = i;
424 last_ekin = theAdjointSteppingAction->
GetLastEkin();
425 last_ekin_nuc = last_ekin;
428 last_ekin_nuc /= nb_nuc;
433 last_pos_vec.push_back(last_pos);
434 last_direction_vec.push_back(last_direction);
435 last_ekin_vec.push_back(last_ekin);
436 last_ekin_nuc_vec.push_back(last_ekin_nuc);
437 last_cos_th_vec.push_back(last_cos_th);
438 last_weight_vec.push_back(last_weight);
439 last_fwd_part_PDGEncoding_vec.push_back(last_fwd_part_PDGEncoding);
440 last_fwd_part_index_vec.push_back(last_fwd_part_index);
441 ID_of_last_particle_that_reach_the_ext_source++;
442 ID_of_last_particle_that_reach_the_ext_source_vec.push_back(
443 ID_of_last_particle_that_reach_the_ext_source);
491 area_of_the_adjoint_source = area;
504 "AdjointSource", radius, volume_name, center, area);
506 area_of_the_adjoint_source = area;
516 "AdjointSource", volume_name, area);
517 area_of_the_adjoint_source = area;
528 theAdjointPrimaryGeneratorAction->
SetEmin(Emin);
535 theAdjointPrimaryGeneratorAction->
SetEmax(Emax);
557 theAdjointPrimaryGeneratorAction->
SetPrimaryIon(adjointIon, fwdIon);
571 theAdjointPrimaryWeight = aWeight;
579 theAdjointEventAction = anAction;
600 theAdjointRunAction = anAction;
635 if (!adjoint_sim_mode) {
636 if (fUserRunAction !=
nullptr) fUserRunAction->
EndOfRunAction(aRun);
638 else if (theAdjointRunAction !=
nullptr)
G4GLOB_DLL std::ostream G4cout
G4bool AddaSphericalSurface(const G4String &SurfaceName, G4double radius, G4ThreeVector pos, G4double &area)
G4bool AddanExtSurfaceOfAvolume(const G4String &SurfaceName, const G4String &volume_name, G4double &area)
static G4AdjointCrossSurfChecker * GetInstance()
G4bool AddaSphericalSurfaceWithCenterAtTheCenterOfAVolume(const G4String &SurfaceName, G4double radius, const G4String &volume_name, G4ThreeVector ¢er, G4double &area)
void UpdateListOfPrimaryParticles()
void SetNbAdjointPrimaryElectronsPerEvent(G4int nb)
std::vector< G4ParticleDefinition * > * GetListOfPrimaryFwdParticles()
void ConsiderParticleAsPrimary(const G4String &particle_name)
void SetAdjointPrimarySourceOnAnExtSurfaceOfAVolume(const G4String &volume_name)
void SetNbAdjointPrimaryGammasPerEvent(G4int nb)
const G4String & GetPrimaryIonName()
void SetSphericalAdjointPrimarySource(G4double radius, G4ThreeVector pos)
G4ParticleDefinition * GetLastGeneratedFwdPrimaryParticle()
void SetNbPrimaryFwdGammasPerEvent(G4int nb)
size_t GetNbOfAdjointPrimaryTypes()
void SetEmin(G4double val)
void NeglectParticleAsPrimary(const G4String &particle_name)
void SetPrimaryIon(G4ParticleDefinition *adjointIon, G4ParticleDefinition *fwdIon)
void SetEmax(G4double val)
void SetAdjointStackingAction(G4UserStackingAction *anAction)
void ClearEndOfAdjointTrackInfoVectors()
G4bool DefineAdjointSourceOnTheExtSurfaceOfAVolume(const G4String &volume_name)
const G4String & GetPrimaryIonName()
G4bool DefineExtSourceOnTheExtSurfaceOfAVolume(const G4String &volume_name)
G4double GetEkinAtEndOfLastAdjointTrack(std::size_t i=0)
G4int GetFwdParticlePDGEncodingAtEndOfLastAdjointTrack(std::size_t i=0)
G4bool GetDidAdjParticleReachTheExtSource()
std::vector< G4ParticleDefinition * > * GetListOfPrimaryFwdParticles()
void RunAdjointSimulation(G4int nb_evt)
G4double GetCosthAtEndOfLastAdjointTrack(std::size_t i=0)
void BeginOfRunAction(const G4Run *aRun) override
G4bool GetAdjointTrackingMode()
const G4String & GetFwdParticleNameAtEndOfLastAdjointTrack()
G4bool DefineSphericalExtSourceWithCentreAtTheCentreOfAVolume(G4double radius, const G4String &volume_name)
void SetNbAdjointPrimaryGammasPerEvent(G4int)
void SetAdjointTrackingMode(G4bool aBool)
void ConsiderParticleAsPrimary(const G4String &particle_name)
void SwitchToAdjointSimulationMode()
std::size_t GetNbOfPrimaryFwdParticles()
void SetAdjointRunAction(G4UserRunAction *anAction)
void SetExtSourceEmax(G4double Emax)
void RegisterAtEndOfAdjointTrack()
void SetAdjointSourceEmax(G4double Emax)
void RegisterAdjointPrimaryWeight(G4double aWeight)
void SetAdjointSourceEmin(G4double Emin)
G4double GetWeightAtEndOfLastAdjointTrack(std::size_t i=0)
void ResetDidOneAdjPartReachExtSourceDuringEvent()
void SetAdjointEventAction(G4UserEventAction *anAction)
void NeglectParticleAsPrimary(const G4String &particle_name)
G4bool DefineSphericalAdjointSourceWithCentreAtTheCentreOfAVolume(G4double radius, const G4String &volume_name)
void SetNbAdjointPrimaryElectronsPerEvent(G4int)
static G4AdjointSimManager * GetInstance()
G4int GetFwdParticleIndexAtEndOfLastAdjointTrack(std::size_t i=0)
G4double GetEkinNucAtEndOfLastAdjointTrack(std::size_t i=0)
void SetNbOfPrimaryFwdGammasPerEvent(G4int)
G4ThreeVector GetDirectionAtEndOfLastAdjointTrack(std::size_t i=0)
void BackToFwdSimulationMode()
G4ParticleDefinition * GetLastGeneratedFwdPrimaryParticle()
void SetAdjointSteppingAction(G4UserSteppingAction *anAction)
G4bool DefineSphericalExtSource(G4double radius, G4ThreeVector pos)
G4ThreeVector GetPositionAtEndOfLastAdjointTrack(std::size_t i=0)
std::size_t GetNbOfAdointTracksReachingTheExternalSurface()
G4bool DefineSphericalAdjointSource(G4double radius, G4ThreeVector pos)
void SetPrimaryIon(G4ParticleDefinition *adjointIon, G4ParticleDefinition *fwdIon)
void EndOfRunAction(const G4Run *aRun) override
void SetKillTracks(G4bool aBool)
void SetAdjointMode(G4bool aBool)
void SetUserFwdStackingAction(G4UserStackingAction *anAction)
void SetUserAdjointStackingAction(G4UserStackingAction *anAction)
G4ParticleDefinition * GetLastPartDef()
void SetUserForwardSteppingAction(G4UserSteppingAction *anAction)
void SetExtSourceEMax(G4double Emax)
void SetUserAdjointSteppingAction(G4UserSteppingAction *anAction)
void ResetDidOneAdjPartReachExtSourceDuringEvent()
G4ThreeVector GetLastMomentum()
void SetPrimWeight(G4double weight)
G4ThreeVector GetLastPosition()
G4double GetEkinAtEndOfLastAdjointTrack(std::size_t i=0)
void SetListOfPrimaryFwdParticles(std::vector< G4ParticleDefinition * > *aListOfParticles)
G4double GetEkinNucAtEndOfLastAdjointTrack(std::size_t i=0)
G4ThreeVector GetPositionAtEndOfLastAdjointTrack(std::size_t i=0)
G4bool GetIsAdjointTrackingMode()
const G4String & GetFwdParticleNameAtEndOfLastAdjointTrack()
G4int GetFwdParticlePDGEncodingAtEndOfLastAdjointTrack(std::size_t i=0)
G4double GetWeightAtEndOfLastAdjointTrack(std::size_t i=0)
void ClearEndOfAdjointTrackInfoVectors()
std::size_t GetNbOfAdointTracksReachingTheExternalSurface()
G4ThreeVector GetDirectionAtEndOfLastAdjointTrack(std::size_t i=0)
G4int GetLastFwdParticleIndex(std::size_t i=0)
G4double GetCosthAtEndOfLastAdjointTrack(std::size_t i=0)
void SetUserForwardTrackingAction(G4UserTrackingAction *anAction)
const G4String & GetParticleType() const
G4int GetPDGEncoding() const
G4int GetBaryonNumber() const
const G4String & GetParticleName() const
G4ParticleDefinition * FindParticle(G4int PDGEncoding)
static G4ParticleTable * GetParticleTable()
const G4UserTrackingAction * GetUserTrackingAction() const
const G4VUserPrimaryGeneratorAction * GetUserPrimaryGeneratorAction() const
const G4UserEventAction * GetUserEventAction() const
static G4RunManager * GetRunManager()
virtual void BeamOn(G4int n_event, const char *macroFile=nullptr, G4int n_select=-1)
const G4UserStackingAction * GetUserStackingAction() const
const G4UserSteppingAction * GetUserSteppingAction() const
const G4UserRunAction * GetUserRunAction() const
virtual void EndOfRunAction(const G4Run *)
virtual void BeginOfRunAction(const G4Run *)