69G4AdjointSimManager::G4AdjointSimManager()
72 , fUserPrimaryGeneratorAction(0)
73 , fUserTrackingAction(0)
74 , fUserSteppingAction(0)
75 , fUserStackingAction(0)
76 , theAdjointRunAction(0)
77 , theAdjointEventAction(0)
78 , adjoint_tracking_mode(false)
82 , last_fwd_part_PDGEncoding(0)
83 , last_fwd_part_index(0)
85 , ID_of_last_particle_that_reach_the_ext_source(0)
86 , nb_evt_of_last_run(0)
87 , area_of_the_adjoint_source(0)
88 , theAdjointPrimaryWeight(0)
94 theAdjointTrackingAction =
96 theAdjointStackingAction =
98 theAdjointTrackingAction->SetListOfPrimaryFwdParticles(
99 theAdjointPrimaryGeneratorAction->GetListOfPrimaryFwdParticles());
104 user_action_already_defined =
false;
105 use_user_StackingAction =
false;
106 use_user_TrackingAction =
true;
108 adjoint_sim_mode =
false;
110 normalisation_mode = 3;
114 welcome_message =
true;
135G4AdjointSimManager::~G4AdjointSimManager()
137 if(theAdjointRunAction)
138 delete theAdjointRunAction;
139 if(theAdjointPrimaryGeneratorAction)
140 delete theAdjointPrimaryGeneratorAction;
141 if(theAdjointSteppingAction)
142 delete theAdjointSteppingAction;
143 if(theAdjointEventAction)
144 delete theAdjointEventAction;
145 if(theAdjointTrackingAction)
146 delete theAdjointTrackingAction;
147 if(theAdjointStackingAction)
148 delete theAdjointStackingAction;
169 G4cout <<
"****************************************************************"
171 G4cout <<
"*** Geant4 Reverse/Adjoint Monte Carlo mode ***"
173 G4cout <<
"*** Author: L.Desorgher ***" << std::endl;
174 G4cout <<
"*** Company: SpaceIT GmbH, Bern, Switzerland ***"
176 G4cout <<
"*** Sponsored by: ESA/ESTEC contract contract 21435/08/NL/AT ***"
178 G4cout <<
"****************************************************************"
180 welcome_message =
false;
190 nb_evt_of_last_run = nb_evt;
223void G4AdjointSimManager::SetRestOfAdjointActions()
227 if(!user_action_already_defined)
233 theRunManager->G4RunManager::SetUserAction(theAdjointEventAction);
234 theRunManager->G4RunManager::SetUserAction(theAdjointSteppingAction);
235 theRunManager->G4RunManager::SetUserAction(theAdjointTrackingAction);
247 adjoint_sim_mode =
true;
248 ID_of_last_particle_that_reach_the_ext_source = 0;
256 adjoint_sim_mode =
false;
261void G4AdjointSimManager::SetAdjointActions()
265 if(!user_action_already_defined)
270 theRunManager->G4RunManager::SetUserAction(
this);
271 theRunManager->G4RunManager::SetUserAction(theAdjointPrimaryGeneratorAction);
272 theRunManager->G4RunManager::SetUserAction(theAdjointStackingAction);
273 if(use_user_StackingAction)
277 theRunManager->G4RunManager::SetUserAction(theAdjointEventAction);
278 theRunManager->G4RunManager::SetUserAction(theAdjointSteppingAction);
279 theRunManager->G4RunManager::SetUserAction(theAdjointTrackingAction);
280 if(use_user_TrackingAction)
287void G4AdjointSimManager::SetAdjointPrimaryRunAndStackingActions()
291 if(!user_action_already_defined)
297 theRunManager->G4RunManager::SetUserAction(theAdjointRunAction);
298 theRunManager->G4RunManager::SetUserAction(theAdjointPrimaryGeneratorAction);
299 theRunManager->G4RunManager::SetUserAction(theAdjointStackingAction);
300 if(use_user_StackingAction)
307void G4AdjointSimManager::ResetUserActions()
313 theRunManager->G4RunManager::SetUserAction(fUserRunAction);
314 theRunManager->G4RunManager::SetUserAction(fUserEventAction);
315 theRunManager->G4RunManager::SetUserAction(fUserSteppingAction);
316 theRunManager->G4RunManager::SetUserAction(fUserTrackingAction);
317 theRunManager->G4RunManager::SetUserAction(fUserPrimaryGeneratorAction);
318 theRunManager->G4RunManager::SetUserAction(fUserStackingAction);
322void G4AdjointSimManager::ResetRestOfUserActions()
329 theRunManager->G4RunManager::SetUserAction(fUserEventAction);
330 theRunManager->G4RunManager::SetUserAction(fUserSteppingAction);
331 theRunManager->G4RunManager::SetUserAction(fUserTrackingAction);
336void G4AdjointSimManager::ResetUserPrimaryRunAndStackingActions()
341 theRunManager->G4RunManager::SetUserAction(fUserRunAction);
342 theRunManager->G4RunManager::SetUserAction(fUserPrimaryGeneratorAction);
343 theRunManager->G4RunManager::SetUserAction(fUserStackingAction);
347void G4AdjointSimManager::DefineUserActions()
350 fUserTrackingAction =
354 fUserSteppingAction =
361 fUserStackingAction =
363 user_action_already_defined =
true;
376 adjoint_tracking_mode = aBool;
378 if(adjoint_tracking_mode)
380 SetRestOfAdjointActions();
386 ResetRestOfUserActions();
406std::vector<G4ParticleDefinition*>*
467 return theAdjointTrackingAction
481 return theAdjointTrackingAction
497 last_direction /= last_direction.
mag();
498 last_cos_th = last_direction.
z();
503 last_fwd_part_name.
remove(0, 4);
509 std::vector<G4ParticleDefinition*>* aList =
511 last_fwd_part_index = -1;
513 while(i < aList->size() && last_fwd_part_index < 0)
515 if((*aList)[i]->GetParticleName() == last_fwd_part_name)
516 last_fwd_part_index = i;
520 last_ekin = theAdjointSteppingAction->
GetLastEkin();
521 last_ekin_nuc = last_ekin;
525 last_ekin_nuc /= nb_nuc;
530 last_pos_vec.push_back(last_pos);
531 last_direction_vec.push_back(last_direction);
532 last_ekin_vec.push_back(last_ekin);
533 last_ekin_nuc_vec.push_back(last_ekin_nuc);
534 last_cos_th_vec.push_back(last_cos_th);
535 last_weight_vec.push_back(last_weight);
536 last_fwd_part_PDGEncoding_vec.push_back(last_fwd_part_PDGEncoding);
537 last_fwd_part_index_vec.push_back(last_fwd_part_index);
538 ID_of_last_particle_that_reach_the_ext_source++;
539 ID_of_last_particle_that_reach_the_ext_source_vec.push_back(
540 ID_of_last_particle_that_reach_the_ext_source);
575 "ExternalSource", radius, pos, area);
587 "ExternalSource", radius, volume_name, center, area);
596 "ExternalSource", volume_name, area);
611 "AdjointSource", radius, pos, area);
614 area_of_the_adjoint_source = area;
627 "AdjointSource", radius, volume_name, center, area);
630 area_of_the_adjoint_source = area;
641 "AdjointSource", volume_name, area);
642 area_of_the_adjoint_source = area;
645 theAdjointPrimaryGeneratorAction
654 theAdjointPrimaryGeneratorAction->
SetEmin(Emin);
660 theAdjointPrimaryGeneratorAction->
SetEmax(Emax);
688 theAdjointPrimaryGeneratorAction->
SetPrimaryIon(adjointIon, fwdIon);
700 theAdjointPrimaryWeight = aWeight;
708 theAdjointEventAction = anAction;
729 theAdjointRunAction = anAction;
767 if(!adjoint_sim_mode)
772 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)
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()
G4double GetEkinNucAtEndOfLastAdjointTrack(size_t i=0)
G4bool DefineAdjointSourceOnTheExtSurfaceOfAVolume(const G4String &volume_name)
G4double GetCosthAtEndOfLastAdjointTrack(size_t i=0)
const G4String & GetPrimaryIonName()
G4bool DefineExtSourceOnTheExtSurfaceOfAVolume(const G4String &volume_name)
G4ThreeVector GetDirectionAtEndOfLastAdjointTrack(size_t i=0)
G4bool GetDidAdjParticleReachTheExtSource()
std::vector< G4ParticleDefinition * > * GetListOfPrimaryFwdParticles()
void RunAdjointSimulation(G4int nb_evt)
G4double GetEkinAtEndOfLastAdjointTrack(size_t i=0)
G4int GetFwdParticlePDGEncodingAtEndOfLastAdjointTrack(size_t i=0)
G4bool GetAdjointTrackingMode()
const G4String & GetFwdParticleNameAtEndOfLastAdjointTrack()
G4bool DefineSphericalExtSourceWithCentreAtTheCentreOfAVolume(G4double radius, const G4String &volume_name)
void SetNbAdjointPrimaryGammasPerEvent(G4int)
G4double GetWeightAtEndOfLastAdjointTrack(size_t i=0)
void SetAdjointTrackingMode(G4bool aBool)
void ConsiderParticleAsPrimary(const G4String &particle_name)
void SwitchToAdjointSimulationMode()
G4ThreeVector GetPositionAtEndOfLastAdjointTrack(size_t i=0)
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)
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()
void SetNbOfPrimaryFwdGammasPerEvent(G4int)
size_t GetNbOfAdointTracksReachingTheExternalSurface()
void BackToFwdSimulationMode()
G4ParticleDefinition * GetLastGeneratedFwdPrimaryParticle()
void SetAdjointSteppingAction(G4UserSteppingAction *anAction)
G4int GetFwdParticleIndexAtEndOfLastAdjointTrack(size_t i=0)
G4bool DefineSphericalExtSource(G4double radius, G4ThreeVector pos)
size_t GetNbOfPrimaryFwdParticles()
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)
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
virtual void BeamOn(G4int n_event, const char *macroFile=0, G4int n_select=-1)
static G4RunManager * GetRunManager()
const G4UserStackingAction * GetUserStackingAction() const
const G4UserSteppingAction * GetUserSteppingAction() const
const G4UserRunAction * GetUserRunAction() const
G4String & remove(str_size)
virtual void EndOfRunAction(const G4Run *aRun)
virtual void BeginOfRunAction(const G4Run *aRun)