Geant4 Cross Reference

Cross-Referencing   Geant4
Geant4/run/src/G4AdjointSimManager.cc

Version: [ ReleaseNotes ] [ 1.0 ] [ 1.1 ] [ 2.0 ] [ 3.0 ] [ 3.1 ] [ 3.2 ] [ 4.0 ] [ 4.0.p1 ] [ 4.0.p2 ] [ 4.1 ] [ 4.1.p1 ] [ 5.0 ] [ 5.0.p1 ] [ 5.1 ] [ 5.1.p1 ] [ 5.2 ] [ 5.2.p1 ] [ 5.2.p2 ] [ 6.0 ] [ 6.0.p1 ] [ 6.1 ] [ 6.2 ] [ 6.2.p1 ] [ 6.2.p2 ] [ 7.0 ] [ 7.0.p1 ] [ 7.1 ] [ 7.1.p1 ] [ 8.0 ] [ 8.0.p1 ] [ 8.1 ] [ 8.1.p1 ] [ 8.1.p2 ] [ 8.2 ] [ 8.2.p1 ] [ 8.3 ] [ 8.3.p1 ] [ 8.3.p2 ] [ 9.0 ] [ 9.0.p1 ] [ 9.0.p2 ] [ 9.1 ] [ 9.1.p1 ] [ 9.1.p2 ] [ 9.1.p3 ] [ 9.2 ] [ 9.2.p1 ] [ 9.2.p2 ] [ 9.2.p3 ] [ 9.2.p4 ] [ 9.3 ] [ 9.3.p1 ] [ 9.3.p2 ] [ 9.4 ] [ 9.4.p1 ] [ 9.4.p2 ] [ 9.4.p3 ] [ 9.4.p4 ] [ 9.5 ] [ 9.5.p1 ] [ 9.5.p2 ] [ 9.6 ] [ 9.6.p1 ] [ 9.6.p2 ] [ 9.6.p3 ] [ 9.6.p4 ] [ 10.0 ] [ 10.0.p1 ] [ 10.0.p2 ] [ 10.0.p3 ] [ 10.0.p4 ] [ 10.1 ] [ 10.1.p1 ] [ 10.1.p2 ] [ 10.1.p3 ] [ 10.2 ] [ 10.2.p1 ] [ 10.2.p2 ] [ 10.2.p3 ] [ 10.3 ] [ 10.3.p1 ] [ 10.3.p2 ] [ 10.3.p3 ] [ 10.4 ] [ 10.4.p1 ] [ 10.4.p2 ] [ 10.4.p3 ] [ 10.5 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /run/src/G4AdjointSimManager.cc (Version 11.3.0) and /run/src/G4AdjointSimManager.cc (Version 10.2.p1)


  1 //                                                  1 //
  2 // *******************************************      2 // ********************************************************************
  3 // * License and Disclaimer                         3 // * License and Disclaimer                                           *
  4 // *                                                4 // *                                                                  *
  5 // * The  Geant4 software  is  copyright of th      5 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
  6 // * the Geant4 Collaboration.  It is provided      6 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
  7 // * conditions of the Geant4 Software License      7 // * conditions of the Geant4 Software License,  included in the file *
  8 // * LICENSE and available at  http://cern.ch/      8 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
  9 // * include a list of copyright holders.           9 // * include a list of copyright holders.                             *
 10 // *                                               10 // *                                                                  *
 11 // * Neither the authors of this software syst     11 // * Neither the authors of this software system, nor their employing *
 12 // * institutes,nor the agencies providing fin     12 // * institutes,nor the agencies providing financial support for this *
 13 // * work  make  any representation or  warran     13 // * work  make  any representation or  warranty, express or implied, *
 14 // * regarding  this  software system or assum     14 // * regarding  this  software system or assume any liability for its *
 15 // * use.  Please see the license in the file      15 // * use.  Please see the license in the file  LICENSE  and URL above *
 16 // * for the full disclaimer and the limitatio     16 // * for the full disclaimer and the limitation of liability.         *
 17 // *                                               17 // *                                                                  *
 18 // * This  code  implementation is the result      18 // * This  code  implementation is the result of  the  scientific and *
 19 // * technical work of the GEANT4 collaboratio     19 // * technical work of the GEANT4 collaboration.                      *
 20 // * By using,  copying,  modifying or  distri     20 // * By using,  copying,  modifying or  distributing the software (or *
 21 // * any work based  on the software)  you  ag     21 // * any work based  on the software)  you  agree  to acknowledge its *
 22 // * use  in  resulting  scientific  publicati     22 // * use  in  resulting  scientific  publications,  and indicate your *
 23 // * acceptance of all terms of the Geant4 Sof     23 // * acceptance of all terms of the Geant4 Software license.          *
 24 // *******************************************     24 // ********************************************************************
 25 //                                                 25 //
 26 // G4AdjointCrossSurfChecker implementation    <<  26 // $Id: G4AdjointSimManager.cc 86968 2014-11-21 11:52:04Z gcosmo $
 27 //                                                 27 //
 28 // ------------------------------------------- <<  28 /////////////////////////////////////////////////////////////////////////////
 29 //   Class Name:   G4AdjointCrossSurfChecker   <<  29 //      Class Name: G4AdjointCrossSurfChecker
 30 //   Author:       L. Desorgher, 2007-2009     <<  30 //  Author:         L. Desorgher
 31 //   Organisation: SpaceIT GmbH                <<  31 //  Organisation:   SpaceIT GmbH
 32 //   Contract:     ESA contract 21435/08/NL/AT <<  32 //  Contract: ESA contract 21435/08/NL/AT
 33 //   Customer:     ESA/ESTEC                   <<  33 //  Customer:       ESA/ESTEC
 34 // ------------------------------------------- <<  34 /////////////////////////////////////////////////////////////////////////////
 35                                                    35 
 36 #include "G4AdjointSimManager.hh"                  36 #include "G4AdjointSimManager.hh"
                                                   >>  37 #include "G4Run.hh"
                                                   >>  38 #include "G4RunManager.hh"
                                                   >>  39 
                                                   >>  40 #include "G4UserEventAction.hh"
                                                   >>  41 #include "G4VUserPrimaryGeneratorAction.hh"
                                                   >>  42 #include "G4UserTrackingAction.hh"
                                                   >>  43 #include "G4UserSteppingAction.hh"
                                                   >>  44 #include "G4UserStackingAction.hh"
                                                   >>  45 #include "G4UserRunAction.hh"
 37                                                    46 
 38 #include "G4AdjointCrossSurfChecker.hh"        << 
 39 #include "G4AdjointPrimaryGeneratorAction.hh"      47 #include "G4AdjointPrimaryGeneratorAction.hh"
 40 #include "G4AdjointSimMessenger.hh"            << 
 41 #include "G4AdjointStackingAction.hh"          << 
 42 #include "G4AdjointSteppingAction.hh"              48 #include "G4AdjointSteppingAction.hh"
                                                   >>  49 #include "G4AdjointStackingAction.hh"
 43 #include "G4AdjointTrackingAction.hh"              50 #include "G4AdjointTrackingAction.hh"
                                                   >>  51 
                                                   >>  52 #include "G4AdjointSimMessenger.hh"
                                                   >>  53 
                                                   >>  54 #include "G4AdjointCrossSurfChecker.hh"
                                                   >>  55 
 44 #include "G4ParticleTable.hh"                      56 #include "G4ParticleTable.hh"
 45 #include "G4PhysicsLogVector.hh"                   57 #include "G4PhysicsLogVector.hh"
 46 #include "G4Run.hh"                            <<  58 /*
 47 #include "G4RunManager.hh"                     <<  59 #ifdef G4MULTITHREADED
 48 #include "G4WorkerRunManager.hh"               <<  60 #include "G4MTAdjointSimManager.hh"
 49 #include "G4UserEventAction.hh"                <<  61 #endif
 50 #include "G4UserRunAction.hh"                  <<  62 */
 51 #include "G4UserStackingAction.hh"             <<  63 
 52 #include "G4UserSteppingAction.hh"             <<  64 ////////////////////////////////////////////////////////////////////////////////
 53 #include "G4UserTrackingAction.hh"             <<  65 //
 54 #include "G4VUserPrimaryGeneratorAction.hh"    <<  66 G4ThreadLocal G4AdjointSimManager* G4AdjointSimManager::instance = 0;
                                                   >>  67 
                                                   >>  68 ////////////////////////////////////////////////////////////////////////////////
                                                   >>  69 //
                                                   >>  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)
                                                   >>  78 { 
                                                   >>  79  //Create adjoint actions;
                                                   >>  80  //----------------------
                                                   >>  81  theAdjointPrimaryGeneratorAction = new G4AdjointPrimaryGeneratorAction(); 
                                                   >>  82  theAdjointSteppingAction = new G4AdjointSteppingAction();
                                                   >>  83  theAdjointStackingAction = new G4AdjointStackingAction();
                                                   >>  84  theAdjointTrackingAction = new G4AdjointTrackingAction(theAdjointSteppingAction);
                                                   >>  85  theAdjointTrackingAction->SetListOfPrimaryFwdParticles(
                                                   >>  86  theAdjointPrimaryGeneratorAction->GetListOfPrimaryFwdParticles());
                                                   >>  87  //Create messenger
                                                   >>  88  //----------------
                                                   >>  89   theMessenger = new G4AdjointSimMessenger(this);
                                                   >>  90   
                                                   >>  91   user_action_already_defined=false;
                                                   >>  92   use_user_StackingAction = false; 
                                                   >>  93   use_user_TrackingAction =true;
 55                                                    94 
 56 // ------------------------------------------- <<  95   adjoint_sim_mode = false;
 57 //                                             <<  96   
 58 G4ThreadLocal G4AdjointSimManager* G4AdjointSi <<  97   normalisation_mode=3;
                                                   >>  98   
                                                   >>  99   nb_nuc=1.;
                                                   >> 100   
                                                   >> 101   welcome_message =true;
                                                   >> 102   
                                                   >> 103   //Define user action and set this class instance  as RunAction
                                                   >> 104   //----------------
                                                   >> 105   DefineUserActions();
                                                   >> 106   G4RunManager* theRunManager = G4RunManager::GetRunManager();
 59                                                   107 
 60 // ------------------------------------------- << 108   theRunManager->G4RunManager::SetUserAction(this);
 61 //                                             << 109 /*
 62 G4AdjointSimManager::G4AdjointSimManager()     << 110 #ifdef G4MULTITHREADED
 63 {                                              << 
 64   theAdjointPrimaryGeneratorAction = new G4Adj << 
 65   theAdjointSteppingAction = new G4AdjointStep << 
 66   theAdjointTrackingAction = new G4AdjointTrac << 
 67   theAdjointStackingAction = new G4AdjointStac << 
 68   theAdjointTrackingAction->SetListOfPrimaryFw << 
 69   theAdjointPrimaryGeneratorAction->GetListOfP << 
 70                                                   111 
 71   theMessenger = new G4AdjointSimMessenger(thi << 112  if (theRunManager->GetRunManagerType() == G4RunManager::workerRM){
                                                   >> 113      G4cout<<"Here"<<std::endl;
                                                   >> 114      //G4MTAdjointSimManager::GetInstance()->RegisterLocalManager(this);
                                                   >> 115      G4cout<<"Here1"<<std::endl;
                                                   >> 116  }
                                                   >> 117 #endif
                                                   >> 118 */
 72 }                                                 119 }
 73                                                << 120 ////////////////////////////////////////////////////////////////////////////////
 74 // ------------------------------------------- << 
 75 //                                                121 //
 76 G4AdjointSimManager::~G4AdjointSimManager()       122 G4AdjointSimManager::~G4AdjointSimManager()
 77 {                                              << 123 { 
 78   delete theAdjointRunAction;                  << 124   if (theAdjointRunAction) delete theAdjointRunAction;
 79   delete theAdjointPrimaryGeneratorAction;     << 125   if (theAdjointPrimaryGeneratorAction) delete theAdjointPrimaryGeneratorAction;
 80   delete theAdjointSteppingAction;             << 126   if (theAdjointSteppingAction) delete theAdjointSteppingAction;
 81   delete theAdjointEventAction;                << 127   if (theAdjointEventAction) delete theAdjointEventAction;
 82   delete theAdjointTrackingAction;             << 128   if (theAdjointTrackingAction) delete theAdjointTrackingAction;
 83   delete theAdjointStackingAction;             << 129   if (theAdjointStackingAction) delete theAdjointStackingAction;
 84   delete theMessenger;                         << 130   if (theMessenger) delete theMessenger;
 85 }                                                 131 }
 86                                                << 132 ////////////////////////////////////////////////////////////////////////////////
 87 // ------------------------------------------- << 
 88 //                                                133 //
 89 G4AdjointSimManager* G4AdjointSimManager::GetI    134 G4AdjointSimManager* G4AdjointSimManager::GetInstance()
 90 {                                                 135 {
 91   if (instance == nullptr) instance = new G4Ad << 136   if (instance == 0) instance = new G4AdjointSimManager;
 92   return instance;                                137   return instance;
 93 }                                                 138 }
 94                                                << 139 ////////////////////////////////////////////////////////////////////////////////
 95 // ------------------------------------------- << 
 96 //                                                140 //
 97 void G4AdjointSimManager::RunAdjointSimulation    141 void G4AdjointSimManager::RunAdjointSimulation(G4int nb_evt)
 98 {                                              << 142 { if (G4RunManager::GetRunManager()->GetRunManagerType() != G4RunManager::sequentialRM) return; //only for sequential mode
 99                                                << 
100   if (welcome_message) {                          143   if (welcome_message) {
101     G4cout << "******************************* << 144     G4cout<<"****************************************************************"<<std::endl;
102     G4cout << "*** Geant4 Reverse/Adjoint Mont << 145   G4cout<<"*** Geant4 Reverse/Adjoint Monte Carlo mode          ***"<<std::endl;
103     G4cout << "*** Author:       L.Desorgher   << 146   G4cout<<"*** Author:  L.Desorgher             ***"<<std::endl;
104     G4cout << "*** Company:      SpaceIT GmbH, << 147   G4cout<<"*** Company: SpaceIT GmbH, Bern, Switzerland         ***"<<std::endl;
105     G4cout << "*** Sponsored by: ESA/ESTEC con << 148   G4cout<<"*** Sponsored by: ESA/ESTEC contract contract 21435/08/NL/AT ***"<<std::endl;  
106     G4cout << "******************************* << 149   G4cout<<"****************************************************************"<<std::endl;
107     welcome_message = false;                   << 150   welcome_message=false;
108   }                                            << 151   } 
109                                                << 152   
110   // Switch to adjoint simulation mode         << 153   //Switch to adjoint simulation mode
111   //------------------------------------------    154   //---------------------------------------------------------
112   SwitchToAdjointSimulationMode();                155   SwitchToAdjointSimulationMode();
113                                                << 156   
114   // Make the run                              << 157   //Make the run
115   //------------                                  158   //------------
116   nb_evt_of_last_run = nb_evt;                 << 159   
117   if (G4Threading::G4GetThreadId() < 0){       << 160   nb_evt_of_last_run =nb_evt;
118     G4RunManager::GetRunManager()->BeamOn(     << 161   G4RunManager::GetRunManager()->BeamOn(nb_evt*theAdjointPrimaryGeneratorAction->GetNbOfAdjointPrimaryTypes());
119     G4int(nb_evt * theAdjointPrimaryGeneratorA << 162   //G4RunManager::GetRunManager()->BeamOn(theAdjointPrimaryGeneratorAction->GetNbOfAdjointPrimaryTypes()*2*nb_evt);
120   }                                            << 
121 }                                              << 
122                                                   163 
123 // ------------------------------------------- << 164   //Back to Fwd Simulation Mode
                                                   >> 165   //--------------------------------
                                                   >> 166   BackToFwdSimulationMode();
                                                   >> 167 
                                                   >> 168   /*
                                                   >> 169   //Register the weight vector
                                                   >> 170   //--------------------------
                                                   >> 171   std::ofstream FileOutputElectronWeight("ElectronWeight.txt", std::ios::out);
                                                   >> 172   FileOutputElectronWeight<<std::setiosflags(std::ios::scientific);
                                                   >> 173   FileOutputElectronWeight<<std::setprecision(6);
                                                   >> 174   G4bool aBool = electron_last_weight_vector->Store(FileOutputElectronWeight, true);
                                                   >> 175   FileOutputElectronWeight.close();
                                                   >> 176   
                                                   >> 177   std::ofstream FileOutputProtonWeight("ProtonWeight.txt", std::ios::out);
                                                   >> 178   FileOutputProtonWeight<<std::setiosflags(std::ios::scientific);
                                                   >> 179   FileOutputProtonWeight<<std::setprecision(6);
                                                   >> 180   aBool = proton_last_weight_vector->Store(FileOutputProtonWeight, true);
                                                   >> 181   FileOutputProtonWeight.close();
                                                   >> 182   
                                                   >> 183   std::ofstream FileOutputGammaWeight("GammaWeight.txt", std::ios::out);
                                                   >> 184   FileOutputGammaWeight<<std::setiosflags(std::ios::scientific);
                                                   >> 185   FileOutputGammaWeight<<std::setprecision(6);
                                                   >> 186   aBool = gamma_last_weight_vector->Store(FileOutputGammaWeight, true);
                                                   >> 187   FileOutputGammaWeight.close();
                                                   >> 188   */  
                                                   >> 189 }
                                                   >> 190 ////////////////////////////////////////////////////////////////////////////////
124 //                                                191 //
125 void G4AdjointSimManager::SetRestOfAdjointActi    192 void G4AdjointSimManager::SetRestOfAdjointActions()
126 { if (G4Threading::G4GetThreadId() == -1) retu << 193 {
127   G4RunManager* theRunManager = G4RunManager:: << 194   G4RunManager* theRunManager =  G4RunManager::GetRunManager();
128                                                   195 
129   if (!user_action_already_defined) DefineUser    196   if (!user_action_already_defined) DefineUserActions();
130                                                   197 
131   // Replace the user action by the adjoint ac << 198  //Replace the user action by the adjoint actions
132   //------------------------------------------ << 199  //-------------------------------------------------
133                                                   200 
134   theRunManager->G4RunManager::SetUserAction(t    201   theRunManager->G4RunManager::SetUserAction(theAdjointEventAction);
135   theRunManager->G4RunManager::SetUserAction(t    202   theRunManager->G4RunManager::SetUserAction(theAdjointSteppingAction);
136   theRunManager->G4RunManager::SetUserAction(t    203   theRunManager->G4RunManager::SetUserAction(theAdjointTrackingAction);
137 }                                              << 
138                                                   204 
139 // ------------------------------------------- << 205 }
                                                   >> 206 ////////////////////////////////////////////////////////////////////////////////
140 //                                                207 //
141 void G4AdjointSimManager::SwitchToAdjointSimul    208 void G4AdjointSimManager::SwitchToAdjointSimulationMode()
142 {                                              << 209 { //Replace the user defined actions by the adjoint actions
143   // Replace the user defined actions by the a << 
144   //------------------------------------------    210   //---------------------------------------------------------
145   SetAdjointActions();                            211   SetAdjointActions();
146                                                   212 
147   // Update the list of primaries              << 213   //Update the list of primaries
148   //-----------------------------                 214   //-----------------------------
149   if (G4Threading::G4GetThreadId() != -1)  the << 215   theAdjointPrimaryGeneratorAction->UpdateListOfPrimaryParticles();
150   adjoint_sim_mode = true;                     << 216   adjoint_sim_mode=true;
151   ID_of_last_particle_that_reach_the_ext_sourc << 217   ID_of_last_particle_that_reach_the_ext_source=0;
152                                                << 
153 }                                                 218 }
154                                                << 219 ////////////////////////////////////////////////////////////////////////////////
155 // ------------------------------------------- << 
156 //                                                220 //
157 void G4AdjointSimManager::BackToFwdSimulationM    221 void G4AdjointSimManager::BackToFwdSimulationMode()
158 {                                              << 222 {  //Restore the user defined actions
159   // Restore the user defined actions          << 223    //--------------------------------
160   //--------------------------------           << 224    ResetUserActions();
161   ResetUserActions();                          << 225    adjoint_sim_mode=false;
162   adjoint_sim_mode = false;                    << 
163 }                                                 226 }
164                                                   227 
165 // ------------------------------------------- << 228 ////////////////////////////////////////////////////////////////////////////////
166 //                                                229 //
167 void G4AdjointSimManager::SetAdjointActions()     230 void G4AdjointSimManager::SetAdjointActions()
168 {                                              << 231 {  
169   auto theRunManager = G4RunManager::GetRunMan << 232   G4RunManager* theRunManager =  G4RunManager::GetRunManager();
170                                                << 233   
171                                                << 
172   if (!user_action_already_defined) DefineUser    234   if (!user_action_already_defined) DefineUserActions();
173                                                   235 
174                                                << 236  //Replace the user action by the adjoint actions
175   // Replace the user action by the adjoint ac << 237  //------------------------------------------------- 
176   //------------------------------------------ << 238   
177   theRunManager->G4RunManager::SetUserAction(t << 
178   if (G4RunManager::GetRunManager()->GetRunMan << 
179       G4RunManager::GetRunManager()->GetRunMan << 
180   theRunManager->G4RunManager::SetUserAction(t    239   theRunManager->G4RunManager::SetUserAction(theAdjointPrimaryGeneratorAction);
181   theRunManager->G4RunManager::SetUserAction(t    240   theRunManager->G4RunManager::SetUserAction(theAdjointStackingAction);
182   if (use_user_StackingAction)                 << 241   if (use_user_StackingAction)  theAdjointStackingAction->SetUserFwdStackingAction(fUserStackingAction);
183     theAdjointStackingAction->SetUserFwdStacki << 242   else theAdjointStackingAction->SetUserFwdStackingAction(0);
184   else                                         << 
185     theAdjointStackingAction->SetUserFwdStacki << 
186   theRunManager->G4RunManager::SetUserAction(t    243   theRunManager->G4RunManager::SetUserAction(theAdjointEventAction);
187   theRunManager->G4RunManager::SetUserAction(t    244   theRunManager->G4RunManager::SetUserAction(theAdjointSteppingAction);
188   theRunManager->G4RunManager::SetUserAction(t    245   theRunManager->G4RunManager::SetUserAction(theAdjointTrackingAction);
189   if (use_user_TrackingAction)                 << 246   if (use_user_TrackingAction)  theAdjointTrackingAction->SetUserForwardTrackingAction(fUserTrackingAction);
190     theAdjointTrackingAction->SetUserForwardTr << 247   else theAdjointTrackingAction->SetUserForwardTrackingAction(0);
191   else                                         << 
192     theAdjointTrackingAction->SetUserForwardTr << 
193 }                                              << 
194 }                                                 248 }
195                                                << 249 ////////////////////////////////////////////////////////////////////////////////
196 // ------------------------------------------- << 
197 //                                                250 //
198 void G4AdjointSimManager::SetAdjointPrimaryRun    251 void G4AdjointSimManager::SetAdjointPrimaryRunAndStackingActions()
199 {                                              << 252 {  
200   G4RunManager* theRunManager = G4RunManager:: << 253   G4RunManager* theRunManager =  G4RunManager::GetRunManager();
201                                                << 254   
202   if (!user_action_already_defined) DefineUser    255   if (!user_action_already_defined) DefineUserActions();
203                                                << 256   
204   // Replace the user action by the adjoint ac << 257  //Replace the user action by the adjoint actions
205   //------------------------------------------ << 258  //------------------------------------------------- 
206                                                << 259   
207   theRunManager->G4RunManager::SetUserAction(t    260   theRunManager->G4RunManager::SetUserAction(theAdjointRunAction);
208   if (G4Threading::G4GetThreadId() != -1) {    << 
209   theRunManager->G4RunManager::SetUserAction(t    261   theRunManager->G4RunManager::SetUserAction(theAdjointPrimaryGeneratorAction);
210   theRunManager->G4RunManager::SetUserAction(t    262   theRunManager->G4RunManager::SetUserAction(theAdjointStackingAction);
211   if (use_user_StackingAction)                 << 263   if (use_user_StackingAction)  theAdjointStackingAction->SetUserFwdStackingAction(fUserStackingAction);
212     theAdjointStackingAction->SetUserFwdStacki << 264   else theAdjointStackingAction->SetUserFwdStackingAction(0);
213   else                                         << 
214     theAdjointStackingAction->SetUserFwdStacki << 
215 }                                              << 
216 }                                                 265 }
217                                                << 266 ////////////////////////////////////////////////////////////////////////////////
218 // ------------------------------------------- << 
219 //                                                267 //
220 void G4AdjointSimManager::ResetUserActions()      268 void G4AdjointSimManager::ResetUserActions()
221 {                                                 269 {
222   G4RunManager* theRunManager = G4RunManager:: << 270   G4RunManager* theRunManager =  G4RunManager::GetRunManager();
223                                                   271 
224   // Restore the user defined actions          << 272   //Restore the user defined actions
225   //-------------------------------               273   //-------------------------------
226   theRunManager->G4RunManager::SetUserAction(f << 274 
227   if (G4Threading::G4GetThreadId() != -1) {    << 
228   theRunManager->G4RunManager::SetUserAction(f    275   theRunManager->G4RunManager::SetUserAction(fUserEventAction);
229   theRunManager->G4RunManager::SetUserAction(f    276   theRunManager->G4RunManager::SetUserAction(fUserSteppingAction);
230   theRunManager->G4RunManager::SetUserAction(f    277   theRunManager->G4RunManager::SetUserAction(fUserTrackingAction);
231   theRunManager->G4RunManager::SetUserAction(f    278   theRunManager->G4RunManager::SetUserAction(fUserPrimaryGeneratorAction);
232   theRunManager->G4RunManager::SetUserAction(f    279   theRunManager->G4RunManager::SetUserAction(fUserStackingAction);
233   }                                            << 
234 }                                                 280 }
235                                                << 281 ////////////////////////////////////////////////////////////////////////////////
236 // ------------------------------------------- << 
237 //                                                282 //
238 void G4AdjointSimManager::ResetRestOfUserActio    283 void G4AdjointSimManager::ResetRestOfUserActions()
239 {                                              << 284 {
240   if (G4Threading::G4GetThreadId() == -1) retu << 285   G4RunManager* theRunManager =  G4RunManager::GetRunManager();
241   G4RunManager* theRunManager = G4RunManager:: << 286   
242                                                << 287   //Restore the user defined actions
243   // Restore the user defined actions          << 
244   //-------------------------------               288   //-------------------------------
245                                                << 289  
246   theRunManager->G4RunManager::SetUserAction(f    290   theRunManager->G4RunManager::SetUserAction(fUserEventAction);
247   theRunManager->G4RunManager::SetUserAction(f    291   theRunManager->G4RunManager::SetUserAction(fUserSteppingAction);
248   theRunManager->G4RunManager::SetUserAction(f    292   theRunManager->G4RunManager::SetUserAction(fUserTrackingAction);
249 }                                                 293 }
250                                                   294 
251 // ------------------------------------------- << 295 ////////////////////////////////////////////////////////////////////////////////
252 //                                                296 //
253 void G4AdjointSimManager::ResetUserPrimaryRunA    297 void G4AdjointSimManager::ResetUserPrimaryRunAndStackingActions()
254 {                                              << 298 { 
255   G4RunManager* theRunManager = G4RunManager:: << 299   G4RunManager* theRunManager =  G4RunManager::GetRunManager();
256   // Restore the user defined actions          << 300   //Restore the user defined actions
257   //-------------------------------               301   //-------------------------------
258   theRunManager->G4RunManager::SetUserAction(f    302   theRunManager->G4RunManager::SetUserAction(fUserRunAction);
259   if (G4Threading::G4GetThreadId() != -1) {    << 
260   theRunManager->G4RunManager::SetUserAction(f    303   theRunManager->G4RunManager::SetUserAction(fUserPrimaryGeneratorAction);
261   theRunManager->G4RunManager::SetUserAction(f    304   theRunManager->G4RunManager::SetUserAction(fUserStackingAction);
262   }                                            << 
263 }                                                 305 }
264                                                << 306 ////////////////////////////////////////////////////////////////////////////////
265 // ------------------------------------------- << 
266 //                                                307 //
267 void G4AdjointSimManager::DefineUserActions()     308 void G4AdjointSimManager::DefineUserActions()
268 {                                              << 309 { 
269   G4RunManager* theRunManager = G4RunManager:: << 310    G4RunManager* theRunManager =  G4RunManager::GetRunManager();
270   fUserRunAction =                             << 311    fUserTrackingAction= const_cast<G4UserTrackingAction* >( theRunManager->GetUserTrackingAction() );
271     const_cast<G4UserRunAction*>(theRunManager << 312    fUserEventAction= const_cast<G4UserEventAction* >( theRunManager->GetUserEventAction() ); 
272  if (G4Threading::G4GetThreadId() != -1) {     << 313    fUserSteppingAction= const_cast<G4UserSteppingAction* >( theRunManager->GetUserSteppingAction() );
273   fUserTrackingAction = const_cast<G4UserTrack << 314    theAdjointSteppingAction->SetUserForwardSteppingAction(fUserSteppingAction);
274   fUserEventAction = const_cast<G4UserEventAct << 315    fUserPrimaryGeneratorAction= const_cast<G4VUserPrimaryGeneratorAction* >( theRunManager->GetUserPrimaryGeneratorAction() );
275   fUserSteppingAction = const_cast<G4UserStepp << 316    fUserRunAction= const_cast<G4UserRunAction*>( theRunManager->GetUserRunAction() );
276   theAdjointSteppingAction->SetUserForwardStep << 317    fUserStackingAction= const_cast<G4UserStackingAction* >( theRunManager->GetUserStackingAction() );
277   fUserPrimaryGeneratorAction =                << 318    user_action_already_defined=true;  
278     const_cast<G4VUserPrimaryGeneratorAction*> << 
279   fUserStackingAction = const_cast<G4UserStack << 
280   user_action_already_defined = true;          << 
281  }                                             << 
282 }                                                 319 }
283                                                << 320 ///////////////////////////////////////////////////////////////////////////////
284 // ------------------------------------------- << 
285 //                                                321 //
286 G4bool G4AdjointSimManager::GetAdjointTracking << 322 G4bool G4AdjointSimManager::GetAdjointTrackingMode(){
287 {                                              << 323   return  theAdjointTrackingAction->GetIsAdjointTrackingMode();
288   return theAdjointTrackingAction->GetIsAdjoin << 
289 }                                                 324 }
290                                                << 325 ///////////////////////////////////////////////////////////////////////////////
291 // ------------------------------------------- << 
292 //                                                326 //
293 void G4AdjointSimManager::SetAdjointTrackingMo << 327 void G4AdjointSimManager::SetAdjointTrackingMode(G4bool aBool)//could be removed
294 {                                                 328 {
295   adjoint_tracking_mode = aBool;                  329   adjoint_tracking_mode = aBool;
296                                                << 330  
297   if (adjoint_tracking_mode) {                    331   if (adjoint_tracking_mode) {
298     SetRestOfAdjointActions();                 << 332     SetRestOfAdjointActions();
299     theAdjointStackingAction->SetAdjointMode(t << 333   theAdjointStackingAction->SetAdjointMode(true);
300     theAdjointStackingAction->SetKillTracks(fa << 334   theAdjointStackingAction->SetKillTracks(false);
301   }                                            << 335   
                                                   >> 336   } 
302   else {                                          337   else {
303     ResetRestOfUserActions();                  << 338     
304     theAdjointStackingAction->SetAdjointMode(f << 339     ResetRestOfUserActions();
305     if (GetDidAdjParticleReachTheExtSource())  << 340   theAdjointStackingAction->SetAdjointMode(false);
306       theAdjointStackingAction->SetKillTracks( << 341   if (GetDidAdjParticleReachTheExtSource()){
307       RegisterAtEndOfAdjointTrack();           << 342     theAdjointStackingAction->SetKillTracks(false);
308     }                                          << 343     RegisterAtEndOfAdjointTrack();
309     else                                       << 344   }
310       theAdjointStackingAction->SetKillTracks( << 345   else theAdjointStackingAction->SetKillTracks(true);
311   }                                            << 346   } 
312 }                                                 347 }
313                                                << 348 ///////////////////////////////////////////////////////////////////////////////
314 // ------------------------------------------- << 
315 //                                                349 //
316 G4bool G4AdjointSimManager::GetDidAdjParticleR    350 G4bool G4AdjointSimManager::GetDidAdjParticleReachTheExtSource()
317 {                                                 351 {
318   return (GetNbOfAdointTracksReachingTheExtern << 352   return theAdjointSteppingAction->GetDidAdjParticleReachTheExtSource();
319 }                                                 353 }
320                                                << 354 ///////////////////////////////////////////////////////////////////////////////
321 // ------------------------------------------- << 
322 //                                                355 //
323 std::vector<G4ParticleDefinition*>* G4AdjointS << 356 std::vector<G4ParticleDefinition*>*  G4AdjointSimManager::GetListOfPrimaryFwdParticles()
324 {                                                 357 {
325   return theAdjointPrimaryGeneratorAction->Get    358   return theAdjointPrimaryGeneratorAction->GetListOfPrimaryFwdParticles();
326 }                                                 359 }
327                                                << 360 ///////////////////////////////////////////////////////////////////////////////
328 // ------------------------------------------- << 
329 //                                                361 //
330 std::size_t G4AdjointSimManager::GetNbOfPrimar << 362 size_t G4AdjointSimManager::GetNbOfPrimaryFwdParticles()
331 {                                                 363 {
332   return theAdjointPrimaryGeneratorAction->Get    364   return theAdjointPrimaryGeneratorAction->GetListOfPrimaryFwdParticles()->size();
333 }                                                 365 }
334                                                   366 
335 // ------------------------------------------- << 367 ///////////////////////////////////////////////////////////////////////////////
336 //                                                368 //
337 G4ThreeVector G4AdjointSimManager::GetPosition << 369 G4ThreeVector  G4AdjointSimManager::GetPositionAtEndOfLastAdjointTrack(){
338 {                                              << 370    return theAdjointTrackingAction->GetPositionAtEndOfLastAdjointTrack();
339   return theAdjointTrackingAction->GetPosition << 
340 }                                                 371 }
341                                                   372 
342 // ------------------------------------------- << 373 ///////////////////////////////////////////////////////////////////////////////
343 //                                                374 //
344 G4ThreeVector G4AdjointSimManager::GetDirectio << 375 G4ThreeVector G4AdjointSimManager::GetDirectionAtEndOfLastAdjointTrack(){
345 {                                              << 376    return theAdjointTrackingAction->GetDirectionAtEndOfLastAdjointTrack();
346   return theAdjointTrackingAction->GetDirectio << 
347 }                                                 377 }
348                                                << 378 //////////////////////////////////////////////////////////////////////////////
349 // ------------------------------------------- << 
350 //                                                379 //
351 G4double G4AdjointSimManager::GetEkinAtEndOfLa << 380 G4double G4AdjointSimManager::GetEkinAtEndOfLastAdjointTrack(){
352 {                                              << 381  return theAdjointTrackingAction->GetEkinAtEndOfLastAdjointTrack();
353   return theAdjointTrackingAction->GetEkinAtEn << 
354 }                                                 382 }
355                                                << 383 ///////////////////////////////////////////////////////////////////////////////
356 // ------------------------------------------- << 
357 //                                                384 //
358 G4double G4AdjointSimManager::GetEkinNucAtEndO << 385 G4double G4AdjointSimManager::GetEkinNucAtEndOfLastAdjointTrack(){
359 {                                              << 386  return theAdjointTrackingAction->GetEkinNucAtEndOfLastAdjointTrack();
360   return theAdjointTrackingAction->GetEkinNucA << 
361 }                                                 387 }
362                                                << 388 ///////////////////////////////////////////////////////////////////////////////
363 // ------------------------------------------- << 
364 //                                                389 //
365 G4double G4AdjointSimManager::GetWeightAtEndOf << 390 G4double G4AdjointSimManager::GetWeightAtEndOfLastAdjointTrack(){
366 {                                              << 391  return theAdjointTrackingAction->GetWeightAtEndOfLastAdjointTrack();
367   return theAdjointTrackingAction->GetWeightAt << 
368 }                                                 392 }
369                                                << 393 ///////////////////////////////////////////////////////////////////////////////
370 // ------------------------------------------- << 
371 //                                                394 //
372 G4double G4AdjointSimManager::GetCosthAtEndOfL << 395 G4double G4AdjointSimManager::GetCosthAtEndOfLastAdjointTrack(){
373 {                                              << 396  return theAdjointTrackingAction->GetCosthAtEndOfLastAdjointTrack();
374   return theAdjointTrackingAction->GetCosthAtE << 
375 }                                                 397 }
376                                                << 398 ///////////////////////////////////////////////////////////////////////////////
377 // ------------------------------------------- << 
378 //                                                399 //
379 const G4String& G4AdjointSimManager::GetFwdPar    400 const G4String& G4AdjointSimManager::GetFwdParticleNameAtEndOfLastAdjointTrack()
380 {                                              << 401 {return theAdjointTrackingAction->GetFwdParticleNameAtEndOfLastAdjointTrack();
381   return theAdjointTrackingAction->GetFwdParti << 
382 }                                                 402 }
383                                                << 403 ///////////////////////////////////////////////////////////////////////////////
384 // ------------------------------------------- << 
385 //                                                404 //
386 G4int G4AdjointSimManager::GetFwdParticlePDGEn << 405 G4int G4AdjointSimManager::GetFwdParticlePDGEncodingAtEndOfLastAdjointTrack(){
387 {                                              << 406  return theAdjointTrackingAction->GetFwdParticlePDGEncodingAtEndOfLastAdjointTrack();
388   return theAdjointTrackingAction->GetFwdParti << 
389 }                                                 407 }
390                                                   408 
391 // ------------------------------------------- << 409 ///////////////////////////////////////////////////////////////////////////////
392 //                                                410 //
393 G4int G4AdjointSimManager::GetFwdParticleIndex << 411 G4int G4AdjointSimManager::GetFwdParticleIndexAtEndOfLastAdjointTrack()
394 {                                              << 412 {return theAdjointTrackingAction->GetLastFwdParticleIndex();
395   return theAdjointTrackingAction->GetLastFwdP << 
396 }                                                 413 }
397                                                   414 
398 // ------------------------------------------- << 415 ///////////////////////////////////////////////////////////////////////////////
399 //                                             << 
400 std::size_t G4AdjointSimManager::GetNbOfAdoint << 
401 {                                              << 
402   return theAdjointTrackingAction->GetNbOfAdoi << 
403 }                                              << 
404                                                << 
405 // ------------------------------------------- << 
406 //                                             << 
407 void G4AdjointSimManager::ClearEndOfAdjointTra << 
408 {                                              << 
409   theAdjointTrackingAction->ClearEndOfAdjointT << 
410 }                                              << 
411                                                << 
412 // ------------------------------------------- << 
413 //                                                416 //
414 void G4AdjointSimManager::RegisterAtEndOfAdjoi    417 void G4AdjointSimManager::RegisterAtEndOfAdjointTrack()
415 {                                                 418 {
416   last_pos = theAdjointSteppingAction->GetLast << 419   last_pos = theAdjointSteppingAction->GetLastPosition();  
417   last_direction = theAdjointSteppingAction->G    420   last_direction = theAdjointSteppingAction->GetLastMomentum();
418   last_direction /= last_direction.mag();      << 421   last_direction /=last_direction.mag();
419   last_cos_th = last_direction.z();            << 422   last_cos_th =  last_direction.z();
420   G4ParticleDefinition* aPartDef = theAdjointS << 423   G4ParticleDefinition* aPartDef= theAdjointSteppingAction->GetLastPartDef(); 
421                                                << 424     
422   last_fwd_part_name = aPartDef->GetParticleNa << 425   last_fwd_part_name= aPartDef->GetParticleName();
423                                                << 426  
424   last_fwd_part_name.erase(0, 4);              << 427   last_fwd_part_name.remove(0,4);
425                                                << 428   
426   last_fwd_part_PDGEncoding =                  << 429   last_fwd_part_PDGEncoding=G4ParticleTable::GetParticleTable()->FindParticle(last_fwd_part_name)->GetPDGEncoding();
427     G4ParticleTable::GetParticleTable()->FindP << 430   
428                                                << 431   std::vector<G4ParticleDefinition*>* aList = theAdjointPrimaryGeneratorAction->GetListOfPrimaryFwdParticles();
429   std::vector<G4ParticleDefinition*>* aList =  << 432   last_fwd_part_index=-1;
430     theAdjointPrimaryGeneratorAction->GetListO << 433   size_t i=0;
431   last_fwd_part_index = -1;                    << 434   while(i<aList->size() && last_fwd_part_index<0) {
432   G4int i = 0;                                 << 435     if ((*aList)[i]->GetParticleName() == last_fwd_part_name) last_fwd_part_index=i;
433   while (i < (G4int)aList->size() && last_fwd_ << 436   i++;
434     if ((*aList)[i]->GetParticleName() == last << 
435     ++i;                                       << 
436   }                                               437   }
437                                                << 438   
438   last_ekin = theAdjointSteppingAction->GetLas    439   last_ekin = theAdjointSteppingAction->GetLastEkin();
439   last_ekin_nuc = last_ekin;                      440   last_ekin_nuc = last_ekin;
440   if (aPartDef->GetParticleType() == "adjoint_    441   if (aPartDef->GetParticleType() == "adjoint_nucleus") {
441     nb_nuc = static_cast<G4double>(aPartDef->G << 442     nb_nuc=double(aPartDef->GetBaryonNumber());
442     last_ekin_nuc /= nb_nuc;                   << 443     last_ekin_nuc /=nb_nuc;
443   }                                               444   }
444                                                   445 
445   last_weight = theAdjointSteppingAction->GetL << 446   last_weight = theAdjointSteppingAction->GetLastWeight(); 
                                                   >> 447   
                                                   >> 448   /* G4PhysicsLogVector* theWeightVector=0;
                                                   >> 449   if (last_fwd_part_name =="e-")  theWeightVector=electron_last_weight_vector;
                                                   >> 450   else if (last_fwd_part_name =="gamma") theWeightVector=gamma_last_weight_vector;
                                                   >> 451   else if (last_fwd_part_name =="proton") theWeightVector=proton_last_weight_vector;
                                                   >> 452   
                                                   >> 453   if (theWeightVector){
446                                                   454 
447   last_pos_vec.push_back(last_pos);            << 455   size_t ind =  size_t(std::log10(last_weight/theAdjointPrimaryWeight)*10. + 200);
448   last_direction_vec.push_back(last_direction) << 456     G4double low_val =theWeightVector->GetLowEdgeEnergy(ind);
449   last_ekin_vec.push_back(last_ekin);          << 457     G4bool aBool = true;
450   last_ekin_nuc_vec.push_back(last_ekin_nuc);  << 458     G4double bin_weight = theWeightVector->GetValue(low_val, aBool)+1.;
451   last_cos_th_vec.push_back(last_cos_th);      << 459     theWeightVector->PutValue(ind, bin_weight);
452   last_weight_vec.push_back(last_weight);      << 460   }
453   last_fwd_part_PDGEncoding_vec.push_back(last << 461   */
454   last_fwd_part_index_vec.push_back(last_fwd_p << 462   /*if ((last_weight/theAdjointPrimaryWeight)>1.) last_weight*=1000. ;
455   ID_of_last_particle_that_reach_the_ext_sourc << 463   else if ( (last_weight/theAdjointPrimaryWeight)>0.1) last_weight*=100. ;
456   ID_of_last_particle_that_reach_the_ext_sourc << 464   else if ( (last_weight/theAdjointPrimaryWeight)>0.01) last_weight*=10. ;*/
457     ID_of_last_particle_that_reach_the_ext_sou << 465   
                                                   >> 466   
                                                   >> 467   //G4cout <<"Last Weight "<<last_weight<<'\t'<<theAdjointPrimaryWeight<<'\t'<<last_weight/theAdjointPrimaryWeight<<std::endl;
                                                   >> 468   /*if (last_weight/theAdjointPrimaryWeight >10.) {
                                                   >> 469     G4cout<<"Warning a weight increase by a factor : "<<last_weight/theAdjointPrimaryWeight<<std::endl;
                                                   >> 470   }
                                                   >> 471   */
                                                   >> 472  
                                                   >> 473    ID_of_last_particle_that_reach_the_ext_source++;
458 }                                                 474 }
459                                                << 475 ///////////////////////////////////////////////////////////////////////////////
460 // ------------------------------------------- << 
461 //                                                476 //
462 G4bool G4AdjointSimManager::DefineSphericalExt << 477 G4bool  G4AdjointSimManager::DefineSphericalExtSource(G4double radius, G4ThreeVector pos)
463 {                                              << 478 { 
464   G4double area;                               << 479    G4double area;
465   return G4AdjointCrossSurfChecker::GetInstanc << 480    return G4AdjointCrossSurfChecker::GetInstance()->AddaSphericalSurface("ExternalSource", radius, pos, area);
466                                                << 
467 }                                                 481 }
468                                                << 482 ///////////////////////////////////////////////////////////////////////////////
469 // ------------------------------------------- << 
470 //                                                483 //
471 G4bool G4AdjointSimManager::DefineSphericalExt << 484 G4bool  G4AdjointSimManager::DefineSphericalExtSourceWithCentreAtTheCentreOfAVolume(G4double radius, const G4String& volume_name)
472   G4double radius, const G4String& volume_name << 
473 {                                                 485 {
474   G4double area;                               << 486    G4double area;
475   G4ThreeVector center;                        << 487    G4ThreeVector center;
476   return G4AdjointCrossSurfChecker::GetInstanc << 488    return G4AdjointCrossSurfChecker::GetInstance()->AddaSphericalSurfaceWithCenterAtTheCenterOfAVolume( "ExternalSource", radius, volume_name,center, area);
477     ->AddaSphericalSurfaceWithCenterAtTheCente << 
478                                                << 
479 }                                                 489 }
480                                                << 490 ///////////////////////////////////////////////////////////////////////////////
481 // ------------------------------------------- << 
482 //                                                491 //
483 G4bool G4AdjointSimManager::DefineExtSourceOnT << 492 G4bool  G4AdjointSimManager::DefineExtSourceOnTheExtSurfaceOfAVolume(const G4String& volume_name)
484 {                                                 493 {
485   G4double area;                               << 494    G4double area;
486   return G4AdjointCrossSurfChecker::GetInstanc << 495    return G4AdjointCrossSurfChecker::GetInstance()->AddanExtSurfaceOfAvolume( "ExternalSource", volume_name,area);
487                                                << 
488 }                                                 496 }
489                                                << 497 ///////////////////////////////////////////////////////////////////////////////
490 // ------------------------------------------- << 
491 //                                                498 //
492 void G4AdjointSimManager::SetExtSourceEmax(G4d << 499 void  G4AdjointSimManager::SetExtSourceEmax(G4double Emax)
493 {                                                 500 {
494   theAdjointSteppingAction->SetExtSourceEMax(E    501   theAdjointSteppingAction->SetExtSourceEMax(Emax);
495 }                                                 502 }
496                                                << 503 ///////////////////////////////////////////////////////////////////////////////
497 // ------------------------------------------- << 
498 //                                             << 
499 G4bool G4AdjointSimManager::DefineSphericalAdj << 
500 {                                              << 
501   G4double area;                               << 
502   G4bool aBool = G4AdjointCrossSurfChecker::Ge << 
503                                                << 
504   theAdjointPrimaryGeneratorAction->SetSpheric << 
505   area_of_the_adjoint_source = area;           << 
506   return aBool;                                << 
507 }                                              << 
508                                                << 
509 // ------------------------------------------- << 
510 //                                                504 //
511 G4bool G4AdjointSimManager::DefineSphericalAdj << 505 G4bool  G4AdjointSimManager::DefineSphericalAdjointSource(G4double radius, G4ThreeVector pos)
512   G4double radius, const G4String& volume_name << 506 { 
513 {                                              << 507    G4double area;
514   G4double area;                               << 508    G4bool aBool = G4AdjointCrossSurfChecker::GetInstance()->AddaSphericalSurface("AdjointSource", radius, pos, area); 
515   G4ThreeVector center;                        << 509    theAdjointPrimaryGeneratorAction->SetSphericalAdjointPrimarySource(radius, pos); 
516   G4bool aBool =                               << 510    area_of_the_adjoint_source=area;
517     G4AdjointCrossSurfChecker::GetInstance()-> << 511    return aBool;  
518       "AdjointSource", radius, volume_name, ce << 512 }
519   theAdjointPrimaryGeneratorAction->SetSpheric << 513 ///////////////////////////////////////////////////////////////////////////////
520   area_of_the_adjoint_source = area;           << 514 //
521   return aBool;                                << 515 G4bool  G4AdjointSimManager::DefineSphericalAdjointSourceWithCentreAtTheCentreOfAVolume(G4double radius, const G4String& volume_name)
522 }                                              << 516 {
523                                                << 517    G4double area;
524 // ------------------------------------------- << 518    G4ThreeVector center;
525 //                                             << 519    G4bool aBool = G4AdjointCrossSurfChecker::GetInstance()->AddaSphericalSurfaceWithCenterAtTheCenterOfAVolume( "AdjointSource", radius, volume_name,center, area);
526 G4bool G4AdjointSimManager::DefineAdjointSourc << 520    theAdjointPrimaryGeneratorAction->SetSphericalAdjointPrimarySource(radius, center);
527 {                                              << 521    area_of_the_adjoint_source=area;
528   G4double area;                               << 522    return aBool;
529   G4bool aBool = G4AdjointCrossSurfChecker::Ge << 523 }
530     "AdjointSource", volume_name, area);       << 524 ///////////////////////////////////////////////////////////////////////////////
531   area_of_the_adjoint_source = area;           << 525 //
532   if (aBool) {                                 << 526 G4bool  G4AdjointSimManager::DefineAdjointSourceOnTheExtSurfaceOfAVolume(const G4String& volume_name)
533     theAdjointPrimaryGeneratorAction->SetAdjoi << 527 {
534   }                                            << 528    G4double area;
535   return aBool;                                << 529    G4bool aBool = G4AdjointCrossSurfChecker::GetInstance()->AddanExtSurfaceOfAvolume( "AdjointSource", volume_name,area); 
                                                   >> 530    area_of_the_adjoint_source=area; 
                                                   >> 531    if (aBool) { 
                                                   >> 532     theAdjointPrimaryGeneratorAction->SetAdjointPrimarySourceOnAnExtSurfaceOfAVolume(volume_name);
                                                   >> 533    }
                                                   >> 534    return aBool;
536 }                                                 535 }
537                                                << 536 ///////////////////////////////////////////////////////////////////////////////
538 // ------------------------------------------- << 
539 //                                                537 //
540 void G4AdjointSimManager::SetAdjointSourceEmin    538 void G4AdjointSimManager::SetAdjointSourceEmin(G4double Emin)
541 {                                                 539 {
542   theAdjointPrimaryGeneratorAction->SetEmin(Em    540   theAdjointPrimaryGeneratorAction->SetEmin(Emin);
543 }                                                 541 }
544                                                << 542 ///////////////////////////////////////////////////////////////////////////////
545 // ------------------------------------------- << 
546 //                                                543 //
547 void G4AdjointSimManager::SetAdjointSourceEmax    544 void G4AdjointSimManager::SetAdjointSourceEmax(G4double Emax)
548 {                                                 545 {
549   theAdjointPrimaryGeneratorAction->SetEmax(Em    546   theAdjointPrimaryGeneratorAction->SetEmax(Emax);
550 }                                                 547 }
551                                                << 548 ///////////////////////////////////////////////////////////////////////////////
552 // ------------------------------------------- << 
553 //                                                549 //
554 void G4AdjointSimManager::ConsiderParticleAsPr    550 void G4AdjointSimManager::ConsiderParticleAsPrimary(const G4String& particle_name)
555 {                                                 551 {
556   theAdjointPrimaryGeneratorAction->ConsiderPa    552   theAdjointPrimaryGeneratorAction->ConsiderParticleAsPrimary(particle_name);
557 }                                                 553 }
558                                                << 554 ///////////////////////////////////////////////////////////////////////////////
559 // ------------------------------------------- << 
560 //                                                555 //
561 void G4AdjointSimManager::NeglectParticleAsPri    556 void G4AdjointSimManager::NeglectParticleAsPrimary(const G4String& particle_name)
562 {                                                 557 {
563   theAdjointPrimaryGeneratorAction->NeglectPar    558   theAdjointPrimaryGeneratorAction->NeglectParticleAsPrimary(particle_name);
564 }                                                 559 }
565                                                << 560 ///////////////////////////////////////////////////////////////////////////////
566 // ------------------------------------------- << 
567 //                                                561 //
568 void G4AdjointSimManager::SetPrimaryIon(G4Part << 562 /*void G4AdjointSimManager::SetPrimaryIon(G4int Z, G4int A)
569                                         G4Part << 563 {
                                                   >> 564   theAdjointPrimaryGeneratorAction->SetPrimaryIon(Z, A);
                                                   >> 565 }
                                                   >> 566 */
                                                   >> 567 ///////////////////////////////////////////////////////////////////////////////
                                                   >> 568 //
                                                   >> 569 void G4AdjointSimManager::SetPrimaryIon(G4ParticleDefinition* adjointIon, G4ParticleDefinition* fwdIon)
570 {                                                 570 {
571   theAdjointPrimaryGeneratorAction->SetPrimary    571   theAdjointPrimaryGeneratorAction->SetPrimaryIon(adjointIon, fwdIon);
572 }                                                 572 }
573                                                << 573 ///////////////////////////////////////////////////////////////////////////////
574 // ------------------------------------------- << 
575 //                                                574 //
576 const G4String& G4AdjointSimManager::GetPrimar    575 const G4String& G4AdjointSimManager::GetPrimaryIonName()
577 {                                                 576 {
578   return theAdjointPrimaryGeneratorAction->Get    577   return theAdjointPrimaryGeneratorAction->GetPrimaryIonName();
579 }                                                 578 }
580                                                << 579 ///////////////////////////////////////////////////////////////////////////////
581 // ------------------------------------------- << 
582 //                                                580 //
583 void G4AdjointSimManager::RegisterAdjointPrima    581 void G4AdjointSimManager::RegisterAdjointPrimaryWeight(G4double aWeight)
584 {                                                 582 {
585   theAdjointPrimaryWeight = aWeight;              583   theAdjointPrimaryWeight = aWeight;
586   theAdjointSteppingAction->SetPrimWeight(aWei    584   theAdjointSteppingAction->SetPrimWeight(aWeight);
587 }                                              << 585 } 
588                                                   586 
589 // ------------------------------------------- << 587 ///////////////////////////////////////////////////////////////////////////////
590 //                                                588 //
591 void G4AdjointSimManager::SetAdjointEventActio    589 void G4AdjointSimManager::SetAdjointEventAction(G4UserEventAction* anAction)
592 {                                                 590 {
593   theAdjointEventAction = anAction;               591   theAdjointEventAction = anAction;
594 }                                                 592 }
595                                                << 593 ///////////////////////////////////////////////////////////////////////////////
596 // ------------------------------------------- << 
597 //                                                594 //
598 void G4AdjointSimManager::SetAdjointSteppingAc    595 void G4AdjointSimManager::SetAdjointSteppingAction(G4UserSteppingAction* anAction)
599 {                                                 596 {
600   theAdjointSteppingAction->SetUserAdjointStep    597   theAdjointSteppingAction->SetUserAdjointSteppingAction(anAction);
601 }                                                 598 }
602                                                << 599 ///////////////////////////////////////////////////////////////////////////////
603 // ------------------------------------------- << 
604 //                                                600 //
605 void G4AdjointSimManager::SetAdjointStackingAc    601 void G4AdjointSimManager::SetAdjointStackingAction(G4UserStackingAction* anAction)
606 {                                                 602 {
607   theAdjointStackingAction->SetUserAdjointStac    603   theAdjointStackingAction->SetUserAdjointStackingAction(anAction);
608 }                                                 604 }
609                                                   605 
610 // ------------------------------------------- << 606 ///////////////////////////////////////////////////////////////////////////////
611 //                                                607 //
612 void G4AdjointSimManager::SetAdjointRunAction(    608 void G4AdjointSimManager::SetAdjointRunAction(G4UserRunAction* anAction)
613 {                                                 609 {
614   theAdjointRunAction = anAction;              << 610   theAdjointRunAction=anAction;
615 }                                              << 611 } 
616                                                << 612 ///////////////////////////////////////////////////////////////////////////////
617 // ------------------------------------------- << 
618 //                                                613 //
619 void G4AdjointSimManager::SetNbOfPrimaryFwdGam    614 void G4AdjointSimManager::SetNbOfPrimaryFwdGammasPerEvent(G4int nb)
620 {                                                 615 {
621   theAdjointPrimaryGeneratorAction->SetNbPrima    616   theAdjointPrimaryGeneratorAction->SetNbPrimaryFwdGammasPerEvent(nb);
622 }                                                 617 }
623                                                << 618 ///////////////////////////////////////////////////////////////////////////////
624 // ------------------------------------------- << 
625 //                                             << 
626 void G4AdjointSimManager::SetNbAdjointPrimaryG << 
627 {                                              << 
628   theAdjointPrimaryGeneratorAction->SetNbAdjoi << 
629 }                                              << 
630                                                << 
631 // ------------------------------------------- << 
632 //                                             << 
633 void G4AdjointSimManager::SetNbAdjointPrimaryE << 
634 {                                              << 
635   theAdjointPrimaryGeneratorAction->SetNbAdjoi << 
636 }                                              << 
637                                                << 
638 // ------------------------------------------- << 
639 //                                                619 //
640 void G4AdjointSimManager::BeginOfRunAction(con    620 void G4AdjointSimManager::BeginOfRunAction(const G4Run* aRun)
641 {  if (!adjoint_sim_mode){                     << 
642     if(fUserRunAction  != nullptr) fUserRunAct << 
643    }                                           << 
644    else {                                      << 
645     if (theAdjointRunAction  != nullptr) theAd << 
646    }                                           << 
647                                                << 
648   //fUserRunAction->BeginOfRunAction(aRun);    << 
649 }                                              << 
650                                                << 
651 // ------------------------------------------- << 
652 //                                             << 
653 void G4AdjointSimManager::EndOfRunAction(const << 
654 {                                                 621 {
655   if (!adjoint_sim_mode) {                     << 
656     if (fUserRunAction != nullptr) fUserRunAct << 
657   }                                            << 
658   else if (theAdjointRunAction != nullptr)     << 
659     theAdjointRunAction->EndOfRunAction(aRun); << 
660                                                << 
661   BackToFwdSimulationMode();                   << 
662                                                   622 
                                                   >> 623  if (!adjoint_sim_mode){
                                                   >> 624   if(fUserRunAction) fUserRunAction->BeginOfRunAction(aRun);
                                                   >> 625  }
                                                   >> 626  else {
                                                   >> 627   if (theAdjointRunAction) theAdjointRunAction->BeginOfRunAction(aRun);
                                                   >> 628  }
663 }                                                 629 }
664                                                << 630 ///////////////////////////////////////////////////////////////////////////////
665 // ------------------------------------------- << 
666 //                                                631 //
667 G4ParticleDefinition* G4AdjointSimManager::Get << 632 void G4AdjointSimManager::EndOfRunAction(const G4Run* aRun)
668 {                                              << 633 {if (!adjoint_sim_mode){
669   return theAdjointPrimaryGeneratorAction->Get << 634   if(fUserRunAction) fUserRunAction->EndOfRunAction(aRun);
670 }                                              << 635  }
                                                   >> 636  else if (theAdjointRunAction) theAdjointRunAction->EndOfRunAction(aRun);
                                                   >> 637 /*
                                                   >> 638 #ifdef G4MULTITHREADED
                                                   >> 639  if (G4RunManager::GetRunManager()->GetRunManagerType() == G4RunManager::workerRM){
                                                   >> 640   if (adjoint_sim_mode) BackToFwdSimulationMode();
                                                   >> 641  }
                                                   >> 642 #endif
                                                   >> 643 */
671                                                   644 
672 // ------------------------------------------- << 
673 //                                             << 
674 void G4AdjointSimManager::ResetDidOneAdjPartRe << 
675 {                                              << 
676   theAdjointSteppingAction->ResetDidOneAdjPart << 
677 }                                                 645 }
678                                                   646