70 G4AdjointSimManager::G4AdjointSimManager():
71 fUserRunAction(0), fUserEventAction(0),fUserPrimaryGeneratorAction(0),
72 fUserTrackingAction(0), fUserSteppingAction(0), fUserStackingAction(0),
73 theAdjointRunAction(0), theAdjointEventAction(0),
74 adjoint_tracking_mode(false),last_ekin(0),last_ekin_nuc(0),
75 last_cos_th(0),last_fwd_part_PDGEncoding(0),last_fwd_part_index(0),
76 last_weight(0), ID_of_last_particle_that_reach_the_ext_source(0),
77 nb_evt_of_last_run(0),area_of_the_adjoint_source(0),theAdjointPrimaryWeight(0)
85 theAdjointTrackingAction->SetListOfPrimaryFwdParticles(
86 theAdjointPrimaryGeneratorAction->GetListOfPrimaryFwdParticles());
91 user_action_already_defined=
false;
92 use_user_StackingAction =
false;
93 use_user_TrackingAction =
true;
95 adjoint_sim_mode =
false;
101 welcome_message =
true;
122 G4AdjointSimManager::~G4AdjointSimManager()
124 if (theAdjointRunAction)
delete theAdjointRunAction;
125 if (theAdjointPrimaryGeneratorAction)
delete theAdjointPrimaryGeneratorAction;
126 if (theAdjointSteppingAction)
delete theAdjointSteppingAction;
127 if (theAdjointEventAction)
delete theAdjointEventAction;
128 if (theAdjointTrackingAction)
delete theAdjointTrackingAction;
129 if (theAdjointStackingAction)
delete theAdjointStackingAction;
130 if (theMessenger)
delete theMessenger;
143 if (welcome_message) {
144 G4cout<<
"****************************************************************"<<std::endl;
145 G4cout<<
"*** Geant4 Reverse/Adjoint Monte Carlo mode ***"<<std::endl;
146 G4cout<<
"*** Author: L.Desorgher ***"<<std::endl;
147 G4cout<<
"*** Company: SpaceIT GmbH, Bern, Switzerland ***"<<std::endl;
148 G4cout<<
"*** Sponsored by: ESA/ESTEC contract contract 21435/08/NL/AT ***"<<std::endl;
149 G4cout<<
"****************************************************************"<<std::endl;
150 welcome_message=
false;
160 nb_evt_of_last_run =nb_evt;
192 void G4AdjointSimManager::SetRestOfAdjointActions()
196 if (!user_action_already_defined) DefineUserActions();
201 theRunManager->G4RunManager::SetUserAction(theAdjointEventAction);
202 theRunManager->G4RunManager::SetUserAction(theAdjointSteppingAction);
203 theRunManager->G4RunManager::SetUserAction(theAdjointTrackingAction);
216 adjoint_sim_mode=
true;
217 ID_of_last_particle_that_reach_the_ext_source=0;
225 adjoint_sim_mode=
false;
230 void G4AdjointSimManager::SetAdjointActions()
234 if (!user_action_already_defined) DefineUserActions();
239 theRunManager->G4RunManager::SetUserAction(
this);
240 theRunManager->G4RunManager::SetUserAction(theAdjointPrimaryGeneratorAction);
241 theRunManager->G4RunManager::SetUserAction(theAdjointStackingAction);
244 theRunManager->G4RunManager::SetUserAction(theAdjointEventAction);
245 theRunManager->G4RunManager::SetUserAction(theAdjointSteppingAction);
246 theRunManager->G4RunManager::SetUserAction(theAdjointTrackingAction);
252 void G4AdjointSimManager::SetAdjointPrimaryRunAndStackingActions()
256 if (!user_action_already_defined) DefineUserActions();
261 theRunManager->G4RunManager::SetUserAction(theAdjointRunAction);
262 theRunManager->G4RunManager::SetUserAction(theAdjointPrimaryGeneratorAction);
263 theRunManager->G4RunManager::SetUserAction(theAdjointStackingAction);
269 void G4AdjointSimManager::ResetUserActions()
275 theRunManager->G4RunManager::SetUserAction(fUserRunAction);
276 theRunManager->G4RunManager::SetUserAction(fUserEventAction);
277 theRunManager->G4RunManager::SetUserAction(fUserSteppingAction);
278 theRunManager->G4RunManager::SetUserAction(fUserTrackingAction);
279 theRunManager->G4RunManager::SetUserAction(fUserPrimaryGeneratorAction);
280 theRunManager->G4RunManager::SetUserAction(fUserStackingAction);
284 void G4AdjointSimManager::ResetRestOfUserActions()
291 theRunManager->G4RunManager::SetUserAction(fUserEventAction);
292 theRunManager->G4RunManager::SetUserAction(fUserSteppingAction);
293 theRunManager->G4RunManager::SetUserAction(fUserTrackingAction);
298 void G4AdjointSimManager::ResetUserPrimaryRunAndStackingActions()
303 theRunManager->G4RunManager::SetUserAction(fUserRunAction);
304 theRunManager->G4RunManager::SetUserAction(fUserPrimaryGeneratorAction);
305 theRunManager->G4RunManager::SetUserAction(fUserStackingAction);
309 void G4AdjointSimManager::DefineUserActions()
319 user_action_already_defined=
true;
330 adjoint_tracking_mode = aBool;
332 if (adjoint_tracking_mode) {
333 SetRestOfAdjointActions();
340 ResetRestOfUserActions();
434 last_direction /=last_direction.
mag();
435 last_cos_th = last_direction.
z();
440 last_fwd_part_name.
remove(0,4);
445 last_fwd_part_index=-1;
447 while(i<aList->size() && last_fwd_part_index<0) {
448 if ((*aList)[i]->GetParticleName() == last_fwd_part_name) last_fwd_part_index=i;
452 last_ekin = theAdjointSteppingAction->
GetLastEkin();
453 last_ekin_nuc = last_ekin;
456 last_ekin_nuc /=nb_nuc;
463 last_pos_vec.push_back(last_pos);
464 last_direction_vec.push_back(last_direction);
465 last_ekin_vec.push_back(last_ekin);
466 last_ekin_nuc_vec.push_back(last_ekin_nuc);
467 last_cos_th_vec.push_back(last_cos_th);
468 last_weight_vec.push_back(last_weight);
469 last_fwd_part_PDGEncoding_vec.push_back(last_fwd_part_PDGEncoding);
470 last_fwd_part_index_vec.push_back(last_fwd_part_index);
471 ID_of_last_particle_that_reach_the_ext_source++;
472 ID_of_last_particle_that_reach_the_ext_source_vec.push_back(ID_of_last_particle_that_reach_the_ext_source);
541 area_of_the_adjoint_source=area;
552 area_of_the_adjoint_source=area;
561 area_of_the_adjoint_source=area;
571 theAdjointPrimaryGeneratorAction->
SetEmin(Emin);
577 theAdjointPrimaryGeneratorAction->
SetEmax(Emax);
602 theAdjointPrimaryGeneratorAction->
SetPrimaryIon(adjointIon, fwdIon);
614 theAdjointPrimaryWeight = aWeight;
622 theAdjointEventAction = anAction;
641 theAdjointRunAction=anAction;
678 {
if (!adjoint_sim_mode){
681 else if (theAdjointRunAction) theAdjointRunAction->
EndOfRunAction(aRun);
static G4AdjointSimManager * GetInstance()
void UpdateListOfPrimaryParticles()
G4int GetLastFwdParticleIndex(size_t i=0)
const G4VUserPrimaryGeneratorAction * GetUserPrimaryGeneratorAction() const
size_t GetNbOfPrimaryFwdParticles()
G4double GetCosthAtEndOfLastAdjointTrack(size_t i=0)
G4ThreeVector GetLastPosition()
G4ParticleDefinition * FindParticle(G4int PDGEncoding)
void ClearEndOfAdjointTrackInfoVectors()
G4int GetFwdParticleIndexAtEndOfLastAdjointTrack(size_t i=0)
std::vector< G4ParticleDefinition * > * GetListOfPrimaryFwdParticles()
G4bool AddaSphericalSurface(const G4String &SurfaceName, G4double radius, G4ThreeVector pos, G4double &area)
G4bool GetDidAdjParticleReachTheExtSource()
void SetAdjointSourceEmax(G4double Emax)
G4double GetEkinNucAtEndOfLastAdjointTrack(size_t i=0)
G4String & remove(str_size)
void SetAdjointStackingAction(G4UserStackingAction *anAction)
void SwitchToAdjointSimulationMode()
void SetNbAdjointPrimaryElectronsPerEvent(G4int nb)
G4ThreeVector GetPositionAtEndOfLastAdjointTrack(size_t i=0)
void SetEmax(G4double val)
virtual void EndOfRunAction(const G4Run *aRun)
G4ThreeVector GetDirectionAtEndOfLastAdjointTrack(size_t i=0)
virtual void BeamOn(G4int n_event, const char *macroFile=0, G4int n_select=-1)
G4bool DefineSphericalAdjointSourceWithCentreAtTheCentreOfAVolume(G4double radius, const G4String &volume_name)
void SetNbAdjointPrimaryGammasPerEvent(G4int nb)
G4int GetPDGEncoding() const
const G4String & GetFwdParticleNameAtEndOfLastAdjointTrack()
void SetUserAdjointStackingAction(G4UserStackingAction *anAction)
G4bool DefineSphericalAdjointSource(G4double radius, G4ThreeVector pos)
G4ParticleDefinition * GetLastGeneratedFwdPrimaryParticle()
G4double GetCosthAtEndOfLastAdjointTrack(size_t i=0)
const G4UserSteppingAction * GetUserSteppingAction() const
const G4String & GetParticleName() const
virtual void EndOfRunAction(const G4Run *aRun)
void SetAdjointSourceEmin(G4double Emin)
G4bool AddaSphericalSurfaceWithCenterAtTheCenterOfAVolume(const G4String &SurfaceName, G4double radius, const G4String &volume_name, G4ThreeVector ¢er, G4double &area)
G4bool GetIsAdjointTrackingMode()
void ClearEndOfAdjointTrackInfoVectors()
void SetNbPrimaryFwdGammasPerEvent(G4int nb)
void SetPrimaryIon(G4ParticleDefinition *adjointIon, G4ParticleDefinition *fwdIon)
void ConsiderParticleAsPrimary(const G4String &particle_name)
G4GLOB_DLL std::ostream G4cout
void SetAdjointTrackingMode(G4bool aBool)
const G4UserStackingAction * GetUserStackingAction() const
G4AdjointPrimaryGeneratorAction()
virtual void BeginOfRunAction(const G4Run *aRun)
G4bool DefineAdjointSourceOnTheExtSurfaceOfAVolume(const G4String &volume_name)
void ResetDidOneAdjPartReachExtSourceDuringEvent()
void SetNbOfPrimaryFwdGammasPerEvent(G4int)
G4double GetEkinNucAtEndOfLastAdjointTrack(size_t i=0)
const G4UserEventAction * GetUserEventAction() const
G4int GetFwdParticlePDGEncodingAtEndOfLastAdjointTrack(size_t i=0)
size_t GetNbOfAdjointPrimaryTypes()
void RunAdjointSimulation(G4int nb_evt)
const G4UserTrackingAction * GetUserTrackingAction() const
const G4String & GetParticleType() const
size_t GetNbOfAdointTracksReachingTheExternalSurface()
const G4String & GetPrimaryIonName()
void SetUserForwardSteppingAction(G4UserSteppingAction *anAction)
G4double GetWeightAtEndOfLastAdjointTrack(size_t i=0)
G4bool DefineSphericalExtSourceWithCentreAtTheCentreOfAVolume(G4double radius, const G4String &volume_name)
const G4String & GetFwdParticleNameAtEndOfLastAdjointTrack()
void SetPrimaryIon(G4ParticleDefinition *adjointIon, G4ParticleDefinition *fwdIon)
const G4String & GetPrimaryIonName()
G4bool DefineSphericalExtSource(G4double radius, G4ThreeVector pos)
void BackToFwdSimulationMode()
static G4AdjointCrossSurfChecker * GetInstance()
void SetPrimWeight(G4double weight)
G4ParticleDefinition * GetLastPartDef()
static G4RunManager * GetRunManager()
G4double GetEkinAtEndOfLastAdjointTrack(size_t i=0)
void SetExtSourceEMax(G4double Emax)
void SetAdjointRunAction(G4UserRunAction *anAction)
G4bool GetAdjointTrackingMode()
G4bool AddanExtSurfaceOfAvolume(const G4String &SurfaceName, const G4String &volume_name, G4double &area)
void SetAdjointEventAction(G4UserEventAction *anAction)
static G4ParticleTable * GetParticleTable()
G4ThreeVector GetPositionAtEndOfLastAdjointTrack(size_t i=0)
void NeglectParticleAsPrimary(const G4String &particle_name)
void ConsiderParticleAsPrimary(const G4String &particle_name)
void SetAdjointPrimarySourceOnAnExtSurfaceOfAVolume(const G4String &volume_name)
std::vector< G4ParticleDefinition * > * GetListOfPrimaryFwdParticles()
virtual void BeginOfRunAction(const G4Run *aRun)
static const G4double Emin
G4int GetFwdParticlePDGEncodingAtEndOfLastAdjointTrack(size_t i=0)
void RegisterAdjointPrimaryWeight(G4double aWeight)
G4bool DefineExtSourceOnTheExtSurfaceOfAVolume(const G4String &volume_name)
static const G4double Emax
void SetNbAdjointPrimaryElectronsPerEvent(G4int)
void SetNbAdjointPrimaryGammasPerEvent(G4int)
void SetUserAdjointSteppingAction(G4UserSteppingAction *anAction)
G4ParticleDefinition * GetLastGeneratedFwdPrimaryParticle()
const G4UserRunAction * GetUserRunAction() const
void SetKillTracks(G4bool aBool)
void SetUserFwdStackingAction(G4UserStackingAction *anAction)
void SetUserForwardTrackingAction(G4UserTrackingAction *anAction)
void SetExtSourceEmax(G4double Emax)
void RegisterAtEndOfAdjointTrack()
void SetSphericalAdjointPrimarySource(G4double radius, G4ThreeVector pos)
G4ThreeVector GetDirectionAtEndOfLastAdjointTrack(size_t i=0)
void SetAdjointMode(G4bool aBool)
void SetAdjointSteppingAction(G4UserSteppingAction *anAction)
G4double GetEkinAtEndOfLastAdjointTrack(size_t i=0)
G4double GetWeightAtEndOfLastAdjointTrack(size_t i=0)
static const G4double pos
G4ThreeVector GetLastMomentum()
void SetEmin(G4double val)
size_t GetNbOfAdointTracksReachingTheExternalSurface()
void NeglectParticleAsPrimary(const G4String &particle_name)
void ResetDidOneAdjPartReachExtSourceDuringEvent()
G4int GetBaryonNumber() const