Geant4 Cross Reference

Cross-Referencing   Geant4
Geant4/run/src/G4AdjointPrimaryGeneratorAction.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/G4AdjointPrimaryGeneratorAction.cc (Version 11.3.0) and /run/src/G4AdjointPrimaryGeneratorAction.cc (Version 11.0.p2)


  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 // G4AdjointPrimaryGeneratorAction implementat     26 // G4AdjointPrimaryGeneratorAction implementation
 27 //                                                 27 //
 28 // -------------------------------------------     28 // --------------------------------------------------------------------
 29 //   Class Name:   G4AdjointPrimaryGeneratorAc     29 //   Class Name:   G4AdjointPrimaryGeneratorAction
 30 //   Author:       L. Desorgher, 2007-2009         30 //   Author:       L. Desorgher, 2007-2009
 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 "G4AdjointPrimaryGeneratorAction.hh"      36 #include "G4AdjointPrimaryGeneratorAction.hh"
 37                                                    37 
 38 #include "G4AdjointPrimaryGenerator.hh"            38 #include "G4AdjointPrimaryGenerator.hh"
 39 #include "G4AdjointSimManager.hh"                  39 #include "G4AdjointSimManager.hh"
 40 #include "G4Event.hh"                              40 #include "G4Event.hh"
 41 #include "G4Gamma.hh"                              41 #include "G4Gamma.hh"
 42 #include "G4ParticleDefinition.hh"                 42 #include "G4ParticleDefinition.hh"
 43 #include "G4ParticleTable.hh"                      43 #include "G4ParticleTable.hh"
 44 #include "G4PhysicalConstants.hh"                  44 #include "G4PhysicalConstants.hh"
 45                                                    45 
 46 // -------------------------------------------     46 // --------------------------------------------------------------------
 47 //                                                 47 //
 48 G4AdjointPrimaryGeneratorAction::G4AdjointPrim     48 G4AdjointPrimaryGeneratorAction::G4AdjointPrimaryGeneratorAction()
 49 {                                                  49 {
 50   theAdjointPrimaryGenerator = new G4AdjointPr     50   theAdjointPrimaryGenerator = new G4AdjointPrimaryGenerator();
 51                                                    51 
 52   PrimariesConsideredInAdjointSim[G4String("e- <<  52   PrimariesConsideredInAdjointSim[G4String("e-")]     = false;
 53   PrimariesConsideredInAdjointSim[G4String("ga <<  53   PrimariesConsideredInAdjointSim[G4String("gamma")]  = false;
 54   PrimariesConsideredInAdjointSim[G4String("pr     54   PrimariesConsideredInAdjointSim[G4String("proton")] = false;
 55   PrimariesConsideredInAdjointSim[G4String("io <<  55   PrimariesConsideredInAdjointSim[G4String("ion")]    = false;
 56                                                    56 
 57   ListOfPrimaryFwdParticles.clear();               57   ListOfPrimaryFwdParticles.clear();
 58   ListOfPrimaryAdjParticles.clear();               58   ListOfPrimaryAdjParticles.clear();
 59 }                                                  59 }
 60                                                    60 
 61 // -------------------------------------------     61 // --------------------------------------------------------------------
 62 //                                                 62 //
 63 G4AdjointPrimaryGeneratorAction::~G4AdjointPri     63 G4AdjointPrimaryGeneratorAction::~G4AdjointPrimaryGeneratorAction()
 64 {                                                  64 {
 65   delete theAdjointPrimaryGenerator;               65   delete theAdjointPrimaryGenerator;
 66 }                                                  66 }
 67                                                    67 
 68 // -------------------------------------------     68 // --------------------------------------------------------------------
 69 //                                                 69 //
 70 void G4AdjointPrimaryGeneratorAction::Generate     70 void G4AdjointPrimaryGeneratorAction::GeneratePrimaries(G4Event* anEvent)
 71 {                                                  71 {
 72   G4int evt_id = anEvent->GetEventID();        <<  72   G4int evt_id   = anEvent->GetEventID();
 73   std::size_t n = ListOfPrimaryAdjParticles.si <<  73   std::size_t n  = ListOfPrimaryAdjParticles.size();
 74   index_particle = std::size_t(evt_id) - n * (     74   index_particle = std::size_t(evt_id) - n * (std::size_t(evt_id) / n);
 75                                                    75 
 76   G4double E1 = Emin;                              76   G4double E1 = Emin;
 77   G4double E2 = Emax;                              77   G4double E2 = Emax;
 78   if (ListOfPrimaryAdjParticles[index_particle <<  78   if(ListOfPrimaryAdjParticles[index_particle] == nullptr)
 79     UpdateListOfPrimaryParticles();  // ion ha     79     UpdateListOfPrimaryParticles();  // ion has not been created yet
 80                                                    80 
 81   if (ListOfPrimaryAdjParticles[index_particle <<  81   if(ListOfPrimaryAdjParticles[index_particle]->GetParticleName() ==
                                                   >>  82      "adj_proton")
                                                   >>  83   {
 82     E1 = EminIon;                                  84     E1 = EminIon;
 83     E2 = EmaxIon;                                  85     E2 = EmaxIon;
 84   }                                                86   }
 85   if (ListOfPrimaryAdjParticles[index_particle <<  87   if(ListOfPrimaryAdjParticles[index_particle]->GetParticleType() ==
                                                   >>  88      "adjoint_nucleus")
                                                   >>  89   {
 86     G4int A = ListOfPrimaryAdjParticles[index_     90     G4int A = ListOfPrimaryAdjParticles[index_particle]->GetAtomicMass();
 87     E1 = EminIon * A;                          <<  91     E1      = EminIon * A;
 88     E2 = EmaxIon * A;                          <<  92     E2      = EmaxIon * A;
 89   }                                                93   }
 90   // Generate first the forwrad primaries          94   // Generate first the forwrad primaries
 91   theAdjointPrimaryGenerator->GenerateFwdPrima     95   theAdjointPrimaryGenerator->GenerateFwdPrimaryVertex(
 92     anEvent, ListOfPrimaryFwdParticles[index_p     96     anEvent, ListOfPrimaryFwdParticles[index_particle], E1, E2);
 93   G4PrimaryVertex* fwdPrimVertex = anEvent->Ge     97   G4PrimaryVertex* fwdPrimVertex = anEvent->GetPrimaryVertex();
 94                                                    98 
 95   p = fwdPrimVertex->GetPrimary()->GetMomentum <<  99   p             = fwdPrimVertex->GetPrimary()->GetMomentum();
 96   pos = fwdPrimVertex->GetPosition();          << 100   pos           = fwdPrimVertex->GetPosition();
 97   G4double pmag = p.mag();                        101   G4double pmag = p.mag();
 98   G4double m0 = ListOfPrimaryFwdParticles[inde << 102   G4double m0   = ListOfPrimaryFwdParticles[index_particle]->GetPDGMass();
 99   G4double ekin = std::sqrt(m0 * m0 + pmag * p    103   G4double ekin = std::sqrt(m0 * m0 + pmag * pmag) - m0;
100                                                   104 
101   G4double weight_correction = 1.;                105   G4double weight_correction = 1.;
102   // For gamma generate the particle along the    106   // For gamma generate the particle along the backward ray
103   G4ThreeVector dir = -p / p.mag();               107   G4ThreeVector dir = -p / p.mag();
104                                                   108 
105   weight_correction = 1.;                         109   weight_correction = 1.;
106                                                   110 
107   if (ListOfPrimaryFwdParticles[index_particle << 111   if(ListOfPrimaryFwdParticles[index_particle] == G4Gamma::Gamma() &&
                                                   >> 112      nb_fwd_gammas_per_event > 1)
108   {                                               113   {
109     G4double weight = (1. / nb_fwd_gammas_per_    114     G4double weight = (1. / nb_fwd_gammas_per_event);
110     fwdPrimVertex->SetWeight(weight);             115     fwdPrimVertex->SetWeight(weight);
111     for (G4int i = 0; i < nb_fwd_gammas_per_ev << 116     for(G4int i = 0; i < nb_fwd_gammas_per_event - 1; ++i)
112       auto newFwdPrimVertex = new G4PrimaryVer << 117     {
                                                   >> 118       G4PrimaryVertex* newFwdPrimVertex = new G4PrimaryVertex();
113       newFwdPrimVertex->SetPosition(pos.x(), p    119       newFwdPrimVertex->SetPosition(pos.x(), pos.y(), pos.z());
114       newFwdPrimVertex->SetT0(0.);                120       newFwdPrimVertex->SetT0(0.);
115       auto aPrimParticle =                     << 121       G4PrimaryParticle* aPrimParticle = new G4PrimaryParticle(
116         new G4PrimaryParticle(ListOfPrimaryFwd << 122         ListOfPrimaryFwdParticles[index_particle], p.x(), p.y(), p.z());
117       newFwdPrimVertex->SetPrimary(aPrimPartic    123       newFwdPrimVertex->SetPrimary(aPrimParticle);
118       newFwdPrimVertex->SetWeight(weight);        124       newFwdPrimVertex->SetWeight(weight);
119       anEvent->AddPrimaryVertex(newFwdPrimVert    125       anEvent->AddPrimaryVertex(newFwdPrimVertex);
120     }                                             126     }
121   }                                               127   }
122                                                   128 
123   // Now generate the adjoint primaries           129   // Now generate the adjoint primaries
124   auto adjPrimVertex = new G4PrimaryVertex();  << 130   G4PrimaryVertex* adjPrimVertex = new G4PrimaryVertex();
125   adjPrimVertex->SetPosition(pos.x(), pos.y(),    131   adjPrimVertex->SetPosition(pos.x(), pos.y(), pos.z());
126   adjPrimVertex->SetT0(0.);                       132   adjPrimVertex->SetT0(0.);
127   auto aPrimParticle =                         << 133   G4PrimaryParticle* aPrimParticle = new G4PrimaryParticle(
128     new G4PrimaryParticle(ListOfPrimaryAdjPart << 134     ListOfPrimaryAdjParticles[index_particle], -p.x(), -p.y(), -p.z());
129                                                   135 
130   adjPrimVertex->SetPrimary(aPrimParticle);       136   adjPrimVertex->SetPrimary(aPrimParticle);
131   anEvent->AddPrimaryVertex(adjPrimVertex);       137   anEvent->AddPrimaryVertex(adjPrimVertex);
132                                                   138 
133   // The factor pi is to normalise the weight     139   // The factor pi is to normalise the weight to the directional flux
134   G4double adjoint_source_area = G4AdjointSimM << 140   G4double adjoint_source_area =
135   G4double adjoint_weight =                    << 141     G4AdjointSimManager::GetInstance()->GetAdjointSourceArea();
136     weight_correction * ComputeEnergyDistWeigh << 142   G4double adjoint_weight = weight_correction *
137   if (ListOfPrimaryAdjParticles[index_particle << 143                             ComputeEnergyDistWeight(ekin, E1, E2) *
                                                   >> 144                             adjoint_source_area * pi;
                                                   >> 145   // if (ListOfPrimaryFwdParticles[index_particle]  ==G4Gamma::Gamma())
                                                   >> 146   // adjoint_weight = adjoint_weight/3.;
                                                   >> 147   if(ListOfPrimaryAdjParticles[index_particle]->GetParticleName() ==
                                                   >> 148      "adj_gamma")
                                                   >> 149   {
138     // The weight will be corrected at the end    150     // The weight will be corrected at the end of the track if splitted tracks
139     // are used                                   151     // are used
140     adjoint_weight = adjoint_weight / nb_adj_p    152     adjoint_weight = adjoint_weight / nb_adj_primary_gammas_per_event;
141     for (G4int i = 0; i < nb_adj_primary_gamma << 153     for(G4int i = 0; i < nb_adj_primary_gammas_per_event - 1; ++i)
142       auto newAdjPrimVertex = new G4PrimaryVer << 154     {
                                                   >> 155       G4PrimaryVertex* newAdjPrimVertex = new G4PrimaryVertex();
143       newAdjPrimVertex->SetPosition(pos.x(), p    156       newAdjPrimVertex->SetPosition(pos.x(), pos.y(), pos.z());
144       newAdjPrimVertex->SetT0(0.);                157       newAdjPrimVertex->SetT0(0.);
145       aPrimParticle =                          << 158       aPrimParticle = new G4PrimaryParticle(
146         new G4PrimaryParticle(ListOfPrimaryAdj << 159         ListOfPrimaryAdjParticles[index_particle], -p.x(), -p.y(), -p.z());
147       newAdjPrimVertex->SetPrimary(aPrimPartic    160       newAdjPrimVertex->SetPrimary(aPrimParticle);
148       newAdjPrimVertex->SetWeight(adjoint_weig    161       newAdjPrimVertex->SetWeight(adjoint_weight);
149       anEvent->AddPrimaryVertex(newAdjPrimVert    162       anEvent->AddPrimaryVertex(newAdjPrimVertex);
150     }                                             163     }
151   }                                               164   }
152   else if (ListOfPrimaryAdjParticles[index_par << 165   else if(ListOfPrimaryAdjParticles[index_particle]->GetParticleName() ==
                                                   >> 166           "adj_electron")
                                                   >> 167   {
153     // The weight will be corrected at the end    168     // The weight will be corrected at the end of the track if splitted tracks
154     // are used                                   169     // are used
155     adjoint_weight = adjoint_weight / nb_adj_p    170     adjoint_weight = adjoint_weight / nb_adj_primary_electrons_per_event;
156     for (G4int i = 0; i < nb_adj_primary_elect << 171     for(G4int i = 0; i < nb_adj_primary_electrons_per_event - 1; ++i)
157       auto newAdjPrimVertex = new G4PrimaryVer << 172     {
                                                   >> 173       G4PrimaryVertex* newAdjPrimVertex = new G4PrimaryVertex();
158       newAdjPrimVertex->SetPosition(pos.x(), p    174       newAdjPrimVertex->SetPosition(pos.x(), pos.y(), pos.z());
159       newAdjPrimVertex->SetT0(0.);                175       newAdjPrimVertex->SetT0(0.);
160       aPrimParticle =                          << 176       aPrimParticle = new G4PrimaryParticle(
161         new G4PrimaryParticle(ListOfPrimaryAdj << 177         ListOfPrimaryAdjParticles[index_particle], -p.x(), -p.y(), -p.z());
162       newAdjPrimVertex->SetPrimary(aPrimPartic    178       newAdjPrimVertex->SetPrimary(aPrimParticle);
163       newAdjPrimVertex->SetWeight(adjoint_weig    179       newAdjPrimVertex->SetWeight(adjoint_weight);
164       anEvent->AddPrimaryVertex(newAdjPrimVert    180       anEvent->AddPrimaryVertex(newAdjPrimVertex);
165     }                                             181     }
166   }                                               182   }
167   adjPrimVertex->SetWeight(adjoint_weight);       183   adjPrimVertex->SetWeight(adjoint_weight);
168                                                   184 
169   // Call some methods of G4AdjointSimManager     185   // Call some methods of G4AdjointSimManager
170   G4AdjointSimManager::GetInstance()->SetAdjoi    186   G4AdjointSimManager::GetInstance()->SetAdjointTrackingMode(true);
171   G4AdjointSimManager::GetInstance()->ClearEnd    187   G4AdjointSimManager::GetInstance()->ClearEndOfAdjointTrackInfoVectors();
172   G4AdjointSimManager::GetInstance()->ResetDid << 188   G4AdjointSimManager::GetInstance()
                                                   >> 189     ->ResetDidOneAdjPartReachExtSourceDuringEvent();
                                                   >> 190 
173 }                                                 191 }
174                                                   192 
175 // -------------------------------------------    193 // --------------------------------------------------------------------
176 //                                                194 //
177 void G4AdjointPrimaryGeneratorAction::SetEmin(    195 void G4AdjointPrimaryGeneratorAction::SetEmin(G4double val)
178 {                                                 196 {
179   Emin = val;                                  << 197   Emin    = val;
180   EminIon = val;                                  198   EminIon = val;
181 }                                                 199 }
182                                                   200 
183 // -------------------------------------------    201 // --------------------------------------------------------------------
184 //                                                202 //
185 void G4AdjointPrimaryGeneratorAction::SetEmax(    203 void G4AdjointPrimaryGeneratorAction::SetEmax(G4double val)
186 {                                                 204 {
187   Emax = val;                                  << 205   Emax    = val;
188   EmaxIon = val;                                  206   EmaxIon = val;
189 }                                                 207 }
190                                                   208 
191 // -------------------------------------------    209 // --------------------------------------------------------------------
192 //                                                210 //
193 void G4AdjointPrimaryGeneratorAction::SetEminI    211 void G4AdjointPrimaryGeneratorAction::SetEminIon(G4double val)
194 {                                                 212 {
195   EminIon = val;                                  213   EminIon = val;
196 }                                                 214 }
197                                                   215 
198 // -------------------------------------------    216 // --------------------------------------------------------------------
199 //                                                217 //
200 void G4AdjointPrimaryGeneratorAction::SetEmaxI    218 void G4AdjointPrimaryGeneratorAction::SetEmaxIon(G4double val)
201 {                                                 219 {
202   EmaxIon = val;                                  220   EmaxIon = val;
203 }                                                 221 }
204                                                   222 
205 // -------------------------------------------    223 // --------------------------------------------------------------------
206 //                                                224 //
207 G4double G4AdjointPrimaryGeneratorAction::Comp << 225 G4double G4AdjointPrimaryGeneratorAction::ComputeEnergyDistWeight(G4double E,
                                                   >> 226                                                                   G4double E1,
208                                                   227                                                                   G4double E2)
209 {                                                 228 {
210   // We generate N numbers of primaries with      229   // We generate N numbers of primaries with  a 1/E energy law distribution.
211   // We have therefore  an energy distribution    230   // We have therefore  an energy distribution function
212   //   f(E)=C/E  (1)                              231   //   f(E)=C/E  (1)
213   // with   C a constant that is such that        232   // with   C a constant that is such that
214   //   N=Integral(f(E),E1,E2)=C.std::log(E2/E1    233   //   N=Integral(f(E),E1,E2)=C.std::log(E2/E1)  (2)
215   // Therefore from (2) we get                    234   // Therefore from (2) we get
216   //   C=N/ std::log(E2/E1) (3)                   235   //   C=N/ std::log(E2/E1) (3)
217   // and                                          236   // and
218   //   f(E)=N/ std::log(E2/E1)/E (4)              237   //   f(E)=N/ std::log(E2/E1)/E (4)
219   // For the adjoint simulation we need a ener    238   // For the adjoint simulation we need a energy distribution  f'(E)=1..
220   // To get that we need therefore to apply a     239   // To get that we need therefore to apply a weight to the primary
221   //   W=1/f(E)=E*std::log(E2/E1)/N               240   //   W=1/f(E)=E*std::log(E2/E1)/N
222   //                                              241   //
223   return std::log(E2 / E1) * E / G4AdjointSimM << 242   return std::log(E2 / E1) * E /
                                                   >> 243          G4AdjointSimManager::GetInstance()->GetNbEvtOfLastRun();
224 }                                                 244 }
225                                                   245 
226 // -------------------------------------------    246 // --------------------------------------------------------------------
227 //                                                247 //
228 void G4AdjointPrimaryGeneratorAction::SetSpher << 248 void G4AdjointPrimaryGeneratorAction::SetSphericalAdjointPrimarySource(
229                                                << 249   G4double radius, G4ThreeVector center_pos)
230 {                                                 250 {
231   radius_spherical_source = radius;               251   radius_spherical_source = radius;
232   center_spherical_source = center_pos;           252   center_spherical_source = center_pos;
233   type_of_adjoint_source = "Spherical";        << 253   type_of_adjoint_source  = "Spherical";
234   theAdjointPrimaryGenerator->SetSphericalAdjo << 254   theAdjointPrimaryGenerator->SetSphericalAdjointPrimarySource(radius,
                                                   >> 255                                                                center_pos);
235 }                                                 256 }
236                                                   257 
237 // -------------------------------------------    258 // --------------------------------------------------------------------
238 //                                                259 //
239 void G4AdjointPrimaryGeneratorAction::SetAdjoi << 260 void G4AdjointPrimaryGeneratorAction::
240   const G4String& volume_name)                 << 261   SetAdjointPrimarySourceOnAnExtSurfaceOfAVolume(const G4String& volume_name)
241 {                                                 262 {
242   type_of_adjoint_source = "ExternalSurfaceOfA    263   type_of_adjoint_source = "ExternalSurfaceOfAVolume";
243   theAdjointPrimaryGenerator->SetAdjointPrimar << 264   theAdjointPrimaryGenerator->SetAdjointPrimarySourceOnAnExtSurfaceOfAVolume(
                                                   >> 265     volume_name);
244 }                                                 266 }
245                                                   267 
246 // -------------------------------------------    268 // --------------------------------------------------------------------
247 //                                                269 //
248 void G4AdjointPrimaryGeneratorAction::Consider << 270 void G4AdjointPrimaryGeneratorAction::ConsiderParticleAsPrimary(
                                                   >> 271   const G4String& particle_name)
249 {                                                 272 {
250   if (PrimariesConsideredInAdjointSim.find(par << 273   if(PrimariesConsideredInAdjointSim.find(particle_name) !=
                                                   >> 274      PrimariesConsideredInAdjointSim.end())
251   {                                               275   {
252     PrimariesConsideredInAdjointSim[particle_n    276     PrimariesConsideredInAdjointSim[particle_name] = true;
253   }                                               277   }
254   UpdateListOfPrimaryParticles();                 278   UpdateListOfPrimaryParticles();
255 }                                                 279 }
256                                                   280 
257 // -------------------------------------------    281 // --------------------------------------------------------------------
258 //                                                282 //
259 void G4AdjointPrimaryGeneratorAction::NeglectP << 283 void G4AdjointPrimaryGeneratorAction::NeglectParticleAsPrimary(
                                                   >> 284   const G4String& particle_name)
260 {                                                 285 {
261   if (PrimariesConsideredInAdjointSim.find(par << 286   if(PrimariesConsideredInAdjointSim.find(particle_name) !=
                                                   >> 287      PrimariesConsideredInAdjointSim.end())
262   {                                               288   {
263     PrimariesConsideredInAdjointSim[particle_n    289     PrimariesConsideredInAdjointSim[particle_name] = false;
264   }                                               290   }
265   UpdateListOfPrimaryParticles();                 291   UpdateListOfPrimaryParticles();
266 }                                                 292 }
267                                                   293 
268 // -------------------------------------------    294 // --------------------------------------------------------------------
269 //                                                295 //
270 void G4AdjointPrimaryGeneratorAction::UpdateLi    296 void G4AdjointPrimaryGeneratorAction::UpdateListOfPrimaryParticles()
271 {                                                 297 {
272   G4ParticleTable* theParticleTable = G4Partic    298   G4ParticleTable* theParticleTable = G4ParticleTable::GetParticleTable();
273   ListOfPrimaryFwdParticles.clear();              299   ListOfPrimaryFwdParticles.clear();
274   ListOfPrimaryAdjParticles.clear();              300   ListOfPrimaryAdjParticles.clear();
275   for (const auto& iter : PrimariesConsideredI << 301   for(auto iter = PrimariesConsideredInAdjointSim.cbegin();
276     if (iter.second) {                         << 302       iter != PrimariesConsideredInAdjointSim.cend(); ++iter)
277       G4String fwd_particle_name = iter.first; << 303   {
278       if (fwd_particle_name != "ion") {        << 304     if(iter->second)
                                                   >> 305     {
                                                   >> 306       G4String fwd_particle_name = iter->first;
                                                   >> 307       if(fwd_particle_name != "ion")
                                                   >> 308       {
279         G4String adj_particle_name = G4String(    309         G4String adj_particle_name = G4String("adj_") + fwd_particle_name;
280         ListOfPrimaryFwdParticles.push_back(th << 310         ListOfPrimaryFwdParticles.push_back(
281         ListOfPrimaryAdjParticles.push_back(th << 311           theParticleTable->FindParticle(fwd_particle_name));
                                                   >> 312         ListOfPrimaryAdjParticles.push_back(
                                                   >> 313           theParticleTable->FindParticle(adj_particle_name));
282       }                                           314       }
283       else {                                   << 315       else
284         if (fwd_ion != nullptr) {              << 316       {
285           ion_name = fwd_ion->GetParticleName( << 317         if(fwd_ion)
                                                   >> 318         {
                                                   >> 319           ion_name              = fwd_ion->GetParticleName();
286           G4String adj_ion_name = G4String("ad    320           G4String adj_ion_name = G4String("adj_") + ion_name;
287           ListOfPrimaryFwdParticles.push_back(    321           ListOfPrimaryFwdParticles.push_back(fwd_ion);
288           ListOfPrimaryAdjParticles.push_back(    322           ListOfPrimaryAdjParticles.push_back(adj_ion);
289         }                                         323         }
290         else {                                 << 324         else
                                                   >> 325         {
291           ListOfPrimaryFwdParticles.push_back(    326           ListOfPrimaryFwdParticles.push_back(nullptr);
292           ListOfPrimaryAdjParticles.push_back(    327           ListOfPrimaryAdjParticles.push_back(nullptr);
293         }                                         328         }
294       }                                           329       }
295     }                                             330     }
296   }                                               331   }
297 }                                                 332 }
298                                                   333 
299 // -------------------------------------------    334 // --------------------------------------------------------------------
300 //                                                335 //
301 void G4AdjointPrimaryGeneratorAction::SetPrima << 336 void G4AdjointPrimaryGeneratorAction::SetPrimaryIon(
302                                                << 337   G4ParticleDefinition* adjointIon, G4ParticleDefinition* fwdIon)
303 {                                                 338 {
304   fwd_ion = fwdIon;                               339   fwd_ion = fwdIon;
305   adj_ion = adjointIon;                           340   adj_ion = adjointIon;
306   UpdateListOfPrimaryParticles();                 341   UpdateListOfPrimaryParticles();
307 }                                                 342 }
308                                                   343