65G4AdjointSimManager::G4AdjointSimManager()
71 theAdjointTrackingAction =
73 theAdjointStackingAction =
92G4AdjointSimManager::~G4AdjointSimManager()
94 delete theAdjointRunAction;
95 delete theAdjointPrimaryGeneratorAction;
96 delete theAdjointSteppingAction;
97 delete theAdjointEventAction;
98 delete theAdjointTrackingAction;
99 delete theAdjointStackingAction;
107 if(instance ==
nullptr)
121 G4cout <<
"****************************************************************"
123 G4cout <<
"*** Geant4 Reverse/Adjoint Monte Carlo mode ***"
125 G4cout <<
"*** Author: L.Desorgher ***"
127 G4cout <<
"*** Company: SpaceIT GmbH, Bern, Switzerland ***"
129 G4cout <<
"*** Sponsored by: ESA/ESTEC contract contract 21435/08/NL/AT ***"
131 G4cout <<
"****************************************************************"
133 welcome_message =
false;
142 nb_evt_of_last_run = nb_evt;
144 ->
BeamOn(
G4int(nb_evt*theAdjointPrimaryGeneratorAction
145 ->GetNbOfAdjointPrimaryTypes()) );
176void G4AdjointSimManager::SetRestOfAdjointActions()
180 if(!user_action_already_defined)
186 theRunManager->G4RunManager::SetUserAction(theAdjointEventAction);
187 theRunManager->G4RunManager::SetUserAction(theAdjointSteppingAction);
188 theRunManager->G4RunManager::SetUserAction(theAdjointTrackingAction);
202 adjoint_sim_mode =
true;
203 ID_of_last_particle_that_reach_the_ext_source = 0;
213 adjoint_sim_mode =
false;
218void G4AdjointSimManager::SetAdjointActions()
222 if(!user_action_already_defined)
227 theRunManager->G4RunManager::SetUserAction(
this);
228 theRunManager->G4RunManager::SetUserAction(theAdjointPrimaryGeneratorAction);
229 theRunManager->G4RunManager::SetUserAction(theAdjointStackingAction);
230 if(use_user_StackingAction)
234 theRunManager->G4RunManager::SetUserAction(theAdjointEventAction);
235 theRunManager->G4RunManager::SetUserAction(theAdjointSteppingAction);
236 theRunManager->G4RunManager::SetUserAction(theAdjointTrackingAction);
237 if(use_user_TrackingAction)
245void G4AdjointSimManager::SetAdjointPrimaryRunAndStackingActions()
249 if(!user_action_already_defined)
255 theRunManager->G4RunManager::SetUserAction(theAdjointRunAction);
256 theRunManager->G4RunManager::SetUserAction(theAdjointPrimaryGeneratorAction);
257 theRunManager->G4RunManager::SetUserAction(theAdjointStackingAction);
258 if(use_user_StackingAction)
266void G4AdjointSimManager::ResetUserActions()
272 theRunManager->G4RunManager::SetUserAction(fUserRunAction);
273 theRunManager->G4RunManager::SetUserAction(fUserEventAction);
274 theRunManager->G4RunManager::SetUserAction(fUserSteppingAction);
275 theRunManager->G4RunManager::SetUserAction(fUserTrackingAction);
276 theRunManager->G4RunManager::SetUserAction(fUserPrimaryGeneratorAction);
277 theRunManager->G4RunManager::SetUserAction(fUserStackingAction);
282void G4AdjointSimManager::ResetRestOfUserActions()
289 theRunManager->G4RunManager::SetUserAction(fUserEventAction);
290 theRunManager->G4RunManager::SetUserAction(fUserSteppingAction);
291 theRunManager->G4RunManager::SetUserAction(fUserTrackingAction);
296void G4AdjointSimManager::ResetUserPrimaryRunAndStackingActions()
301 theRunManager->G4RunManager::SetUserAction(fUserRunAction);
302 theRunManager->G4RunManager::SetUserAction(fUserPrimaryGeneratorAction);
303 theRunManager->G4RunManager::SetUserAction(fUserStackingAction);
308void G4AdjointSimManager::DefineUserActions()
311 fUserTrackingAction =
315 fUserSteppingAction =
322 fUserStackingAction =
324 user_action_already_defined =
true;
339 adjoint_tracking_mode = aBool;
341 if(adjoint_tracking_mode)
343 SetRestOfAdjointActions();
349 ResetRestOfUserActions();
370std::vector<G4ParticleDefinition*>*
444 return theAdjointTrackingAction
461 return theAdjointTrackingAction
478 last_direction /= last_direction.
mag();
479 last_cos_th = last_direction.
z();
484 last_fwd_part_name.erase(0, 4);
490 std::vector<G4ParticleDefinition*>* aList =
492 last_fwd_part_index = -1;
494 while(i < (
G4int)aList->size() && last_fwd_part_index < 0)
496 if((*aList)[i]->GetParticleName() == last_fwd_part_name)
497 last_fwd_part_index = i;
501 last_ekin = theAdjointSteppingAction->
GetLastEkin();
502 last_ekin_nuc = last_ekin;
506 last_ekin_nuc /= nb_nuc;
511 last_pos_vec.push_back(last_pos);
512 last_direction_vec.push_back(last_direction);
513 last_ekin_vec.push_back(last_ekin);
514 last_ekin_nuc_vec.push_back(last_ekin_nuc);
515 last_cos_th_vec.push_back(last_cos_th);
516 last_weight_vec.push_back(last_weight);
517 last_fwd_part_PDGEncoding_vec.push_back(last_fwd_part_PDGEncoding);
518 last_fwd_part_index_vec.push_back(last_fwd_part_index);
519 ID_of_last_particle_that_reach_the_ext_source++;
520 ID_of_last_particle_that_reach_the_ext_source_vec.push_back(
521 ID_of_last_particle_that_reach_the_ext_source);
531 "ExternalSource", radius, pos, area);
544 "ExternalSource", radius, volume_name, center, area);
554 "ExternalSource", volume_name, area);
571 "AdjointSource", radius, pos, area);
574 area_of_the_adjoint_source = area;
588 "AdjointSource", radius, volume_name, center, area);
591 area_of_the_adjoint_source = area;
603 "AdjointSource", volume_name, area);
604 area_of_the_adjoint_source = area;
607 theAdjointPrimaryGeneratorAction
617 theAdjointPrimaryGeneratorAction->
SetEmin(Emin);
624 theAdjointPrimaryGeneratorAction->
SetEmax(Emax);
648 theAdjointPrimaryGeneratorAction->
SetPrimaryIon(adjointIon, fwdIon);
662 theAdjointPrimaryWeight = aWeight;
670 theAdjointEventAction = anAction;
694 theAdjointRunAction = anAction;
737 if(!adjoint_sim_mode)
742 else if(theAdjointRunAction)
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)
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)
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()
virtual void BeginOfRunAction(const G4Run *aRun)
void SetAdjointSourceEmax(G4double Emax)
void RegisterAdjointPrimaryWeight(G4double aWeight)
void SetAdjointSourceEmin(G4double Emin)
virtual void EndOfRunAction(const G4Run *aRun)
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 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 *aRun)
virtual void BeginOfRunAction(const G4Run *aRun)