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.0.p4)


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