Geant4 10.7.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4AdjointSimManager.cc
Go to the documentation of this file.
1//
2// ********************************************************************
3// * License and Disclaimer *
4// * *
5// * The Geant4 software is copyright of the Copyright Holders of *
6// * the Geant4 Collaboration. It is provided under the terms and *
7// * conditions of the Geant4 Software License, included in the file *
8// * LICENSE and available at http://cern.ch/geant4/license . These *
9// * include a list of copyright holders. *
10// * *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work make any representation or warranty, express or implied, *
14// * regarding this software system or assume any liability for its *
15// * use. Please see the license in the file LICENSE and URL above *
16// * for the full disclaimer and the limitation of liability. *
17// * *
18// * This code implementation is the result of the scientific and *
19// * technical work of the GEANT4 collaboration. *
20// * By using, copying, modifying or distributing the software (or *
21// * any work based on the software) you agree to acknowledge its *
22// * use in resulting scientific publications, and indicate your *
23// * acceptance of all terms of the Geant4 Software license. *
24// ********************************************************************
25//
26//
27/////////////////////////////////////////////////////////////////////////////
28// Class Name: G4AdjointCrossSurfChecker
29// Author: L. Desorgher
30// Organisation: SpaceIT GmbH
31// Contract: ESA contract 21435/08/NL/AT
32// Customer: ESA/ESTEC
33/////////////////////////////////////////////////////////////////////////////
34
36#include "G4Run.hh"
37#include "G4RunManager.hh"
38
39#include "G4UserEventAction.hh"
40#include "G4UserRunAction.hh"
45
50
52
54
55#include "G4ParticleTable.hh"
56#include "G4PhysicsLogVector.hh"
57/*
58#ifdef G4MULTITHREADED
59#include "G4MTAdjointSimManager.hh"
60#endif
61*/
62
63////////////////////////////////////////////////////////////////////////////////
64//
65G4ThreadLocal G4AdjointSimManager* G4AdjointSimManager::instance = 0;
66
67////////////////////////////////////////////////////////////////////////////////
68//
69G4AdjointSimManager::G4AdjointSimManager()
70 : fUserRunAction(0)
71 , fUserEventAction(0)
72 , fUserPrimaryGeneratorAction(0)
73 , fUserTrackingAction(0)
74 , fUserSteppingAction(0)
75 , fUserStackingAction(0)
76 , theAdjointRunAction(0)
77 , theAdjointEventAction(0)
78 , adjoint_tracking_mode(false)
79 , last_ekin(0)
80 , last_ekin_nuc(0)
81 , last_cos_th(0)
82 , last_fwd_part_PDGEncoding(0)
83 , last_fwd_part_index(0)
84 , last_weight(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)
89{
90 // Create adjoint actions;
91 //----------------------
92 theAdjointPrimaryGeneratorAction = new G4AdjointPrimaryGeneratorAction();
93 theAdjointSteppingAction = new G4AdjointSteppingAction();
94 theAdjointTrackingAction =
95 new G4AdjointTrackingAction(theAdjointSteppingAction);
96 theAdjointStackingAction =
97 new G4AdjointStackingAction(theAdjointTrackingAction);
98 theAdjointTrackingAction->SetListOfPrimaryFwdParticles(
99 theAdjointPrimaryGeneratorAction->GetListOfPrimaryFwdParticles());
100 // Create messenger
101 //----------------
102 theMessenger = new G4AdjointSimMessenger(this);
103
104 user_action_already_defined = false;
105 use_user_StackingAction = false;
106 use_user_TrackingAction = true;
107
108 adjoint_sim_mode = false;
109
110 normalisation_mode = 3;
111
112 nb_nuc = 1.;
113
114 welcome_message = true;
115
116 // Define user action and set this class instance as RunAction
117 //----------------
118 // DefineUserActions();
119 // G4RunManager* theRunManager = G4RunManager::GetRunManager();
120
121 // theRunManager->G4RunManager::SetUserAction(this);
122 /*
123 #ifdef G4MULTITHREADED
124
125 if (theRunManager->GetRunManagerType() == G4RunManager::workerRM){
126 G4cout<<"Here"<<std::endl;
127 //G4MTAdjointSimManager::GetInstance()->RegisterLocalManager(this);
128 G4cout<<"Here1"<<std::endl;
129 }
130 #endif
131 */
132}
133////////////////////////////////////////////////////////////////////////////////
134//
135G4AdjointSimManager::~G4AdjointSimManager()
136{
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;
149 if(theMessenger)
150 delete theMessenger;
151}
152////////////////////////////////////////////////////////////////////////////////
153//
155{
156 if(instance == 0)
157 instance = new G4AdjointSimManager;
158 return instance;
159}
160////////////////////////////////////////////////////////////////////////////////
161//
163{
164 if(G4RunManager::GetRunManager()->GetRunManagerType() !=
166 return; // only for sequential mode
167 if(welcome_message)
168 {
169 G4cout << "****************************************************************"
170 << std::endl;
171 G4cout << "*** Geant4 Reverse/Adjoint Monte Carlo mode ***"
172 << std::endl;
173 G4cout << "*** Author: L.Desorgher ***" << std::endl;
174 G4cout << "*** Company: SpaceIT GmbH, Bern, Switzerland ***"
175 << std::endl;
176 G4cout << "*** Sponsored by: ESA/ESTEC contract contract 21435/08/NL/AT ***"
177 << std::endl;
178 G4cout << "****************************************************************"
179 << std::endl;
180 welcome_message = false;
181 }
182
183 // Switch to adjoint simulation mode
184 //---------------------------------------------------------
186
187 // Make the run
188 //------------
189
190 nb_evt_of_last_run = nb_evt;
192 nb_evt * theAdjointPrimaryGeneratorAction->GetNbOfAdjointPrimaryTypes());
193 // G4RunManager::GetRunManager()->BeamOn(theAdjointPrimaryGeneratorAction->GetNbOfAdjointPrimaryTypes()*2*nb_evt);
194
195 // Back to Fwd Simulation Mode
196 //--------------------------------
198
199 /*
200 //Register the weight vector
201 //--------------------------
202 std::ofstream FileOutputElectronWeight("ElectronWeight.txt", std::ios::out);
203 FileOutputElectronWeight<<std::setiosflags(std::ios::scientific);
204 FileOutputElectronWeight<<std::setprecision(6);
205 G4bool aBool = electron_last_weight_vector->Store(FileOutputElectronWeight,
206 true); FileOutputElectronWeight.close();
207
208 std::ofstream FileOutputProtonWeight("ProtonWeight.txt", std::ios::out);
209 FileOutputProtonWeight<<std::setiosflags(std::ios::scientific);
210 FileOutputProtonWeight<<std::setprecision(6);
211 aBool = proton_last_weight_vector->Store(FileOutputProtonWeight, true);
212 FileOutputProtonWeight.close();
213
214 std::ofstream FileOutputGammaWeight("GammaWeight.txt", std::ios::out);
215 FileOutputGammaWeight<<std::setiosflags(std::ios::scientific);
216 FileOutputGammaWeight<<std::setprecision(6);
217 aBool = gamma_last_weight_vector->Store(FileOutputGammaWeight, true);
218 FileOutputGammaWeight.close();
219 */
220}
221////////////////////////////////////////////////////////////////////////////////
222//
223void G4AdjointSimManager::SetRestOfAdjointActions()
224{
225 G4RunManager* theRunManager = G4RunManager::GetRunManager();
226
227 if(!user_action_already_defined)
228 DefineUserActions();
229
230 // Replace the user action by the adjoint actions
231 //-------------------------------------------------
232
233 theRunManager->G4RunManager::SetUserAction(theAdjointEventAction);
234 theRunManager->G4RunManager::SetUserAction(theAdjointSteppingAction);
235 theRunManager->G4RunManager::SetUserAction(theAdjointTrackingAction);
236}
237////////////////////////////////////////////////////////////////////////////////
238//
240{ // Replace the user defined actions by the adjoint actions
241 //---------------------------------------------------------
242 SetAdjointActions();
243
244 // Update the list of primaries
245 //-----------------------------
246 theAdjointPrimaryGeneratorAction->UpdateListOfPrimaryParticles();
247 adjoint_sim_mode = true;
248 ID_of_last_particle_that_reach_the_ext_source = 0;
249}
250////////////////////////////////////////////////////////////////////////////////
251//
253{ // Restore the user defined actions
254 //--------------------------------
255 ResetUserActions();
256 adjoint_sim_mode = false;
257}
258
259////////////////////////////////////////////////////////////////////////////////
260//
261void G4AdjointSimManager::SetAdjointActions()
262{
263 G4RunManager* theRunManager = G4RunManager::GetRunManager();
264
265 if(!user_action_already_defined)
266 DefineUserActions();
267
268 // Replace the user action by the adjoint actions
269 //-------------------------------------------------
270 theRunManager->G4RunManager::SetUserAction(this);
271 theRunManager->G4RunManager::SetUserAction(theAdjointPrimaryGeneratorAction);
272 theRunManager->G4RunManager::SetUserAction(theAdjointStackingAction);
273 if(use_user_StackingAction)
274 theAdjointStackingAction->SetUserFwdStackingAction(fUserStackingAction);
275 else
276 theAdjointStackingAction->SetUserFwdStackingAction(0);
277 theRunManager->G4RunManager::SetUserAction(theAdjointEventAction);
278 theRunManager->G4RunManager::SetUserAction(theAdjointSteppingAction);
279 theRunManager->G4RunManager::SetUserAction(theAdjointTrackingAction);
280 if(use_user_TrackingAction)
281 theAdjointTrackingAction->SetUserForwardTrackingAction(fUserTrackingAction);
282 else
283 theAdjointTrackingAction->SetUserForwardTrackingAction(0);
284}
285////////////////////////////////////////////////////////////////////////////////
286//
287void G4AdjointSimManager::SetAdjointPrimaryRunAndStackingActions()
288{
289 G4RunManager* theRunManager = G4RunManager::GetRunManager();
290
291 if(!user_action_already_defined)
292 DefineUserActions();
293
294 // Replace the user action by the adjoint actions
295 //-------------------------------------------------
296
297 theRunManager->G4RunManager::SetUserAction(theAdjointRunAction);
298 theRunManager->G4RunManager::SetUserAction(theAdjointPrimaryGeneratorAction);
299 theRunManager->G4RunManager::SetUserAction(theAdjointStackingAction);
300 if(use_user_StackingAction)
301 theAdjointStackingAction->SetUserFwdStackingAction(fUserStackingAction);
302 else
303 theAdjointStackingAction->SetUserFwdStackingAction(0);
304}
305////////////////////////////////////////////////////////////////////////////////
306//
307void G4AdjointSimManager::ResetUserActions()
308{
309 G4RunManager* theRunManager = G4RunManager::GetRunManager();
310
311 // Restore the user defined actions
312 //-------------------------------
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);
319}
320////////////////////////////////////////////////////////////////////////////////
321//
322void G4AdjointSimManager::ResetRestOfUserActions()
323{
324 G4RunManager* theRunManager = G4RunManager::GetRunManager();
325
326 // Restore the user defined actions
327 //-------------------------------
328
329 theRunManager->G4RunManager::SetUserAction(fUserEventAction);
330 theRunManager->G4RunManager::SetUserAction(fUserSteppingAction);
331 theRunManager->G4RunManager::SetUserAction(fUserTrackingAction);
332}
333
334////////////////////////////////////////////////////////////////////////////////
335//
336void G4AdjointSimManager::ResetUserPrimaryRunAndStackingActions()
337{
338 G4RunManager* theRunManager = G4RunManager::GetRunManager();
339 // Restore the user defined actions
340 //-------------------------------
341 theRunManager->G4RunManager::SetUserAction(fUserRunAction);
342 theRunManager->G4RunManager::SetUserAction(fUserPrimaryGeneratorAction);
343 theRunManager->G4RunManager::SetUserAction(fUserStackingAction);
344}
345////////////////////////////////////////////////////////////////////////////////
346//
347void G4AdjointSimManager::DefineUserActions()
348{
349 G4RunManager* theRunManager = G4RunManager::GetRunManager();
350 fUserTrackingAction =
351 const_cast<G4UserTrackingAction*>(theRunManager->GetUserTrackingAction());
352 fUserEventAction =
353 const_cast<G4UserEventAction*>(theRunManager->GetUserEventAction());
354 fUserSteppingAction =
355 const_cast<G4UserSteppingAction*>(theRunManager->GetUserSteppingAction());
356 theAdjointSteppingAction->SetUserForwardSteppingAction(fUserSteppingAction);
357 fUserPrimaryGeneratorAction = const_cast<G4VUserPrimaryGeneratorAction*>(
358 theRunManager->GetUserPrimaryGeneratorAction());
359 fUserRunAction =
360 const_cast<G4UserRunAction*>(theRunManager->GetUserRunAction());
361 fUserStackingAction =
362 const_cast<G4UserStackingAction*>(theRunManager->GetUserStackingAction());
363 user_action_already_defined = true;
364}
365///////////////////////////////////////////////////////////////////////////////
366//
368{
369 return theAdjointTrackingAction->GetIsAdjointTrackingMode();
370}
371///////////////////////////////////////////////////////////////////////////////
372//
374 G4bool aBool) // could be removed
375{
376 adjoint_tracking_mode = aBool;
377
378 if(adjoint_tracking_mode)
379 {
380 SetRestOfAdjointActions();
381 theAdjointStackingAction->SetAdjointMode(true);
382 theAdjointStackingAction->SetKillTracks(false);
383 }
384 else
385 {
386 ResetRestOfUserActions();
387 theAdjointStackingAction->SetAdjointMode(false);
389 {
390 theAdjointStackingAction->SetKillTracks(false);
392 }
393 else
394 theAdjointStackingAction->SetKillTracks(true);
395 }
396}
397///////////////////////////////////////////////////////////////////////////////
398//
400{
402}
403
404///////////////////////////////////////////////////////////////////////////////
405//
406std::vector<G4ParticleDefinition*>*
408{
409 return theAdjointPrimaryGeneratorAction->GetListOfPrimaryFwdParticles();
410}
411///////////////////////////////////////////////////////////////////////////////
412//
414{
415 return theAdjointPrimaryGeneratorAction->GetListOfPrimaryFwdParticles()
416 ->size();
417}
418
419///////////////////////////////////////////////////////////////////////////////
420//
422{
423 return theAdjointTrackingAction->GetPositionAtEndOfLastAdjointTrack(i);
424}
425
426///////////////////////////////////////////////////////////////////////////////
427//
429{
430 return theAdjointTrackingAction->GetDirectionAtEndOfLastAdjointTrack(i);
431}
432//////////////////////////////////////////////////////////////////////////////
433//
435{
436 return theAdjointTrackingAction->GetEkinAtEndOfLastAdjointTrack(i);
437}
438///////////////////////////////////////////////////////////////////////////////
439//
441{
442 return theAdjointTrackingAction->GetEkinNucAtEndOfLastAdjointTrack(i);
443}
444///////////////////////////////////////////////////////////////////////////////
445//
447{
448 return theAdjointTrackingAction->GetWeightAtEndOfLastAdjointTrack(i);
449}
450///////////////////////////////////////////////////////////////////////////////
451//
453{
454 return theAdjointTrackingAction->GetCosthAtEndOfLastAdjointTrack(i);
455}
456///////////////////////////////////////////////////////////////////////////////
457//
459{
460 return theAdjointTrackingAction->GetFwdParticleNameAtEndOfLastAdjointTrack();
461}
462///////////////////////////////////////////////////////////////////////////////
463//
465 size_t i)
466{
467 return theAdjointTrackingAction
469}
470
471///////////////////////////////////////////////////////////////////////////////
472//
474{
475 return theAdjointTrackingAction->GetLastFwdParticleIndex(i);
476}
477///////////////////////////////////////////////////////////////////////////////
478//
480{
481 return theAdjointTrackingAction
483}
484///////////////////////////////////////////////////////////////////////////////
485//
487{
488 theAdjointTrackingAction->ClearEndOfAdjointTrackInfoVectors();
489}
490
491///////////////////////////////////////////////////////////////////////////////
492//
494{
495 last_pos = theAdjointSteppingAction->GetLastPosition();
496 last_direction = theAdjointSteppingAction->GetLastMomentum();
497 last_direction /= last_direction.mag();
498 last_cos_th = last_direction.z();
499 G4ParticleDefinition* aPartDef = theAdjointSteppingAction->GetLastPartDef();
500
501 last_fwd_part_name = aPartDef->GetParticleName();
502
503 last_fwd_part_name.remove(0, 4);
504
505 last_fwd_part_PDGEncoding = G4ParticleTable::GetParticleTable()
506 ->FindParticle(last_fwd_part_name)
507 ->GetPDGEncoding();
508
509 std::vector<G4ParticleDefinition*>* aList =
510 theAdjointPrimaryGeneratorAction->GetListOfPrimaryFwdParticles();
511 last_fwd_part_index = -1;
512 size_t i = 0;
513 while(i < aList->size() && last_fwd_part_index < 0)
514 {
515 if((*aList)[i]->GetParticleName() == last_fwd_part_name)
516 last_fwd_part_index = i;
517 i++;
518 }
519
520 last_ekin = theAdjointSteppingAction->GetLastEkin();
521 last_ekin_nuc = last_ekin;
522 if(aPartDef->GetParticleType() == "adjoint_nucleus")
523 {
524 nb_nuc = double(aPartDef->GetBaryonNumber());
525 last_ekin_nuc /= nb_nuc;
526 }
527
528 last_weight = theAdjointSteppingAction->GetLastWeight();
529
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);
541
542 /* G4PhysicsLogVector* theWeightVector=0;
543 if (last_fwd_part_name =="e-") theWeightVector=electron_last_weight_vector;
544 else if (last_fwd_part_name =="gamma")
545 theWeightVector=gamma_last_weight_vector; else if (last_fwd_part_name
546 =="proton") theWeightVector=proton_last_weight_vector;
547
548 if (theWeightVector){
549
550 size_t ind = size_t(std::log10(last_weight/theAdjointPrimaryWeight)*10. +
551 200); G4double low_val =theWeightVector->GetLowEdgeEnergy(ind); G4bool aBool =
552 true; G4double bin_weight = theWeightVector->GetValue(low_val, aBool)+1.;
553 theWeightVector->PutValue(ind, bin_weight);
554 }
555 */
556 /*if ((last_weight/theAdjointPrimaryWeight)>1.) last_weight*=1000. ;
557 else if ( (last_weight/theAdjointPrimaryWeight)>0.1) last_weight*=100. ;
558 else if ( (last_weight/theAdjointPrimaryWeight)>0.01) last_weight*=10. ;*/
559
560 // G4cout <<"Last Weight
561 // "<<last_weight<<'\t'<<theAdjointPrimaryWeight<<'\t'<<last_weight/theAdjointPrimaryWeight<<std::endl;
562 /*if (last_weight/theAdjointPrimaryWeight >10.) {
563 G4cout<<"Warning a weight increase by a factor :
564 "<<last_weight/theAdjointPrimaryWeight<<std::endl;
565 }
566 */
567}
568///////////////////////////////////////////////////////////////////////////////
569//
571 G4ThreeVector pos)
572{
573 G4double area;
575 "ExternalSource", radius, pos, area);
576}
577///////////////////////////////////////////////////////////////////////////////
578//
579G4bool
581 G4double radius, const G4String& volume_name)
582{
583 G4double area;
584 G4ThreeVector center;
587 "ExternalSource", radius, volume_name, center, area);
588}
589///////////////////////////////////////////////////////////////////////////////
590//
592 const G4String& volume_name)
593{
594 G4double area;
596 "ExternalSource", volume_name, area);
597}
598///////////////////////////////////////////////////////////////////////////////
599//
601{
602 theAdjointSteppingAction->SetExtSourceEMax(Emax);
603}
604///////////////////////////////////////////////////////////////////////////////
605//
607 G4ThreeVector pos)
608{
609 G4double area;
611 "AdjointSource", radius, pos, area);
612 theAdjointPrimaryGeneratorAction->SetSphericalAdjointPrimarySource(radius,
613 pos);
614 area_of_the_adjoint_source = area;
615 return aBool;
616}
617///////////////////////////////////////////////////////////////////////////////
618//
619G4bool
621 G4double radius, const G4String& volume_name)
622{
623 G4double area;
624 G4ThreeVector center;
627 "AdjointSource", radius, volume_name, center, area);
628 theAdjointPrimaryGeneratorAction->SetSphericalAdjointPrimarySource(radius,
629 center);
630 area_of_the_adjoint_source = area;
631 return aBool;
632}
633///////////////////////////////////////////////////////////////////////////////
634//
636 const G4String& volume_name)
637{
638 G4double area;
639 G4bool aBool =
641 "AdjointSource", volume_name, area);
642 area_of_the_adjoint_source = area;
643 if(aBool)
644 {
645 theAdjointPrimaryGeneratorAction
647 }
648 return aBool;
649}
650///////////////////////////////////////////////////////////////////////////////
651//
653{
654 theAdjointPrimaryGeneratorAction->SetEmin(Emin);
655}
656///////////////////////////////////////////////////////////////////////////////
657//
659{
660 theAdjointPrimaryGeneratorAction->SetEmax(Emax);
661}
662///////////////////////////////////////////////////////////////////////////////
663//
665 const G4String& particle_name)
666{
667 theAdjointPrimaryGeneratorAction->ConsiderParticleAsPrimary(particle_name);
668}
669///////////////////////////////////////////////////////////////////////////////
670//
672 const G4String& particle_name)
673{
674 theAdjointPrimaryGeneratorAction->NeglectParticleAsPrimary(particle_name);
675}
676///////////////////////////////////////////////////////////////////////////////
677//
678/*void G4AdjointSimManager::SetPrimaryIon(G4int Z, G4int A)
679{
680 theAdjointPrimaryGeneratorAction->SetPrimaryIon(Z, A);
681}
682*/
683///////////////////////////////////////////////////////////////////////////////
684//
686 G4ParticleDefinition* fwdIon)
687{
688 theAdjointPrimaryGeneratorAction->SetPrimaryIon(adjointIon, fwdIon);
689}
690///////////////////////////////////////////////////////////////////////////////
691//
693{
694 return theAdjointPrimaryGeneratorAction->GetPrimaryIonName();
695}
696///////////////////////////////////////////////////////////////////////////////
697//
699{
700 theAdjointPrimaryWeight = aWeight;
701 theAdjointSteppingAction->SetPrimWeight(aWeight);
702}
703
704///////////////////////////////////////////////////////////////////////////////
705//
707{
708 theAdjointEventAction = anAction;
709}
710///////////////////////////////////////////////////////////////////////////////
711//
713 G4UserSteppingAction* anAction)
714{
715 theAdjointSteppingAction->SetUserAdjointSteppingAction(anAction);
716}
717///////////////////////////////////////////////////////////////////////////////
718//
720 G4UserStackingAction* anAction)
721{
722 theAdjointStackingAction->SetUserAdjointStackingAction(anAction);
723}
724
725///////////////////////////////////////////////////////////////////////////////
726//
728{
729 theAdjointRunAction = anAction;
730}
731///////////////////////////////////////////////////////////////////////////////
732//
734{
735 theAdjointPrimaryGeneratorAction->SetNbPrimaryFwdGammasPerEvent(nb);
736}
737///////////////////////////////////////////////////////////////////////////////
738//
740{
741 theAdjointPrimaryGeneratorAction->SetNbAdjointPrimaryGammasPerEvent(nb);
742}
743///////////////////////////////////////////////////////////////////////////////
744//
746{
747 theAdjointPrimaryGeneratorAction->SetNbAdjointPrimaryElectronsPerEvent(nb);
748}
749///////////////////////////////////////////////////////////////////////////////
750//
752{
753 /*
754 if (!adjoint_sim_mode){
755 if(fUserRunAction) fUserRunAction->BeginOfRunAction(aRun);
756 }
757 else {
758 if (theAdjointRunAction) theAdjointRunAction->BeginOfRunAction(aRun);
759 }
760 */
761 fUserRunAction->BeginOfRunAction(aRun);
762}
763///////////////////////////////////////////////////////////////////////////////
764//
766{
767 if(!adjoint_sim_mode)
768 {
769 if(fUserRunAction)
770 fUserRunAction->EndOfRunAction(aRun);
771 }
772 else if(theAdjointRunAction)
773 theAdjointRunAction->EndOfRunAction(aRun);
774 /*
775 #ifdef G4MULTITHREADED
776 if (G4RunManager::GetRunManager()->GetRunManagerType() ==
777 G4RunManager::workerRM){ if (adjoint_sim_mode) BackToFwdSimulationMode();
778 }
779 #endif
780 */
781}
782///////////////////////////////////////////////////////////////////////////////
783//
785{
786 return theAdjointPrimaryGeneratorAction->GetLastGeneratedFwdPrimaryParticle();
787}
788///////////////////////////////////////////////////////////////////////////////
789//
791{
792 theAdjointSteppingAction->ResetDidOneAdjPartReachExtSourceDuringEvent();
793}
double G4double
Definition: G4Types.hh:83
bool G4bool
Definition: G4Types.hh:86
int G4int
Definition: G4Types.hh:85
G4GLOB_DLL std::ostream G4cout
double z() const
double mag() const
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 &center, G4double &area)
std::vector< G4ParticleDefinition * > * GetListOfPrimaryFwdParticles()
void ConsiderParticleAsPrimary(const G4String &particle_name)
void SetAdjointPrimarySourceOnAnExtSurfaceOfAVolume(const G4String &volume_name)
void SetSphericalAdjointPrimarySource(G4double radius, G4ThreeVector pos)
G4ParticleDefinition * GetLastGeneratedFwdPrimaryParticle()
void NeglectParticleAsPrimary(const G4String &particle_name)
void SetPrimaryIon(G4ParticleDefinition *adjointIon, G4ParticleDefinition *fwdIon)
void SetAdjointStackingAction(G4UserStackingAction *anAction)
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)
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)
G4ThreeVector GetPositionAtEndOfLastAdjointTrack(size_t i=0)
void SetAdjointRunAction(G4UserRunAction *anAction)
void SetExtSourceEmax(G4double Emax)
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()
G4ParticleDefinition * GetLastGeneratedFwdPrimaryParticle()
void SetAdjointSteppingAction(G4UserSteppingAction *anAction)
G4int GetFwdParticleIndexAtEndOfLastAdjointTrack(size_t i=0)
G4bool DefineSphericalExtSource(G4double radius, G4ThreeVector pos)
G4bool DefineSphericalAdjointSource(G4double radius, G4ThreeVector pos)
void SetPrimaryIon(G4ParticleDefinition *adjointIon, G4ParticleDefinition *fwdIon)
void SetUserFwdStackingAction(G4UserStackingAction *anAction)
void SetUserAdjointStackingAction(G4UserStackingAction *anAction)
G4ParticleDefinition * GetLastPartDef()
void SetUserForwardSteppingAction(G4UserSteppingAction *anAction)
void SetExtSourceEMax(G4double Emax)
void SetUserAdjointSteppingAction(G4UserSteppingAction *anAction)
void SetPrimWeight(G4double weight)
G4double GetEkinAtEndOfLastAdjointTrack(std::size_t i=0)
G4double GetEkinNucAtEndOfLastAdjointTrack(std::size_t i=0)
G4ThreeVector GetPositionAtEndOfLastAdjointTrack(std::size_t i=0)
const G4String & GetFwdParticleNameAtEndOfLastAdjointTrack()
G4int GetFwdParticlePDGEncodingAtEndOfLastAdjointTrack(std::size_t i=0)
G4double GetWeightAtEndOfLastAdjointTrack(std::size_t i=0)
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
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()
Definition: G4RunManager.cc:84
const G4UserStackingAction * GetUserStackingAction() const
const G4UserSteppingAction * GetUserSteppingAction() const
const G4UserRunAction * GetUserRunAction() const
Definition: G4Run.hh:49
G4String & remove(str_size)
virtual void EndOfRunAction(const G4Run *aRun)
virtual void BeginOfRunAction(const G4Run *aRun)
#define G4ThreadLocal
Definition: tls.hh:77