Geant4  10.03.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4AdjointPrimaryGeneratorAction Class Reference

#include <G4AdjointPrimaryGeneratorAction.hh>

Inheritance diagram for G4AdjointPrimaryGeneratorAction:
Collaboration diagram for G4AdjointPrimaryGeneratorAction:

Public Member Functions

 G4AdjointPrimaryGeneratorAction ()
 
 ~G4AdjointPrimaryGeneratorAction ()
 
void GeneratePrimaries (G4Event *)
 
void SetRndmFlag (const G4String &val)
 
void SetEmin (G4double val)
 
void SetEmax (G4double val)
 
void SetEminIon (G4double val)
 
void SetEmaxIon (G4double val)
 
void SetSphericalAdjointPrimarySource (G4double radius, G4ThreeVector pos)
 
void SetAdjointPrimarySourceOnAnExtSurfaceOfAVolume (const G4String &volume_name)
 
void ConsiderParticleAsPrimary (const G4String &particle_name)
 
void NeglectParticleAsPrimary (const G4String &particle_name)
 
void SetPrimaryIon (G4ParticleDefinition *adjointIon, G4ParticleDefinition *fwdIon)
 
void UpdateListOfPrimaryParticles ()
 
size_t GetNbOfAdjointPrimaryTypes ()
 
std::vector
< G4ParticleDefinition * > * 
GetListOfPrimaryFwdParticles ()
 
const G4StringGetPrimaryIonName ()
 
void SetNbPrimaryFwdGammasPerEvent (G4int nb)
 
void SetNbAdjointPrimaryGammasPerEvent (G4int nb)
 
void SetNbAdjointPrimaryElectronsPerEvent (G4int nb)
 
G4ParticleDefinitionGetLastGeneratedFwdPrimaryParticle ()
 
- Public Member Functions inherited from G4VUserPrimaryGeneratorAction
 G4VUserPrimaryGeneratorAction ()
 
virtual ~G4VUserPrimaryGeneratorAction ()
 

Detailed Description

Definition at line 78 of file G4AdjointPrimaryGeneratorAction.hh.

Constructor & Destructor Documentation

G4AdjointPrimaryGeneratorAction::G4AdjointPrimaryGeneratorAction ( )

Definition at line 49 of file G4AdjointPrimaryGeneratorAction.cc.

50  : Emin(0.), Emax(0.), EminIon(0.), EmaxIon(0.),
51  index_particle(100000),
52  radius_spherical_source(0.), fwd_ion(0), adj_ion(0),
53  ion_name("not_defined")
54 {
55  theAdjointPrimaryGenerator= new G4AdjointPrimaryGenerator();
56 
57  PrimariesConsideredInAdjointSim[G4String("e-")]=false;
58  PrimariesConsideredInAdjointSim[G4String("gamma")]=false;
59  PrimariesConsideredInAdjointSim[G4String("proton")]=false;
60  PrimariesConsideredInAdjointSim[G4String("ion")]=false;
61 
62  ListOfPrimaryFwdParticles.clear();
63  ListOfPrimaryAdjParticles.clear();
64  nb_fwd_gammas_per_event = 1;
65  nb_adj_primary_gammas_per_event = 1;
66  nb_adj_primary_electrons_per_event = 1;
67 
68 }
static const G4double Emin
static const G4double Emax
G4AdjointPrimaryGeneratorAction::~G4AdjointPrimaryGeneratorAction ( )

Definition at line 71 of file G4AdjointPrimaryGeneratorAction.cc.

72 {
73  delete theAdjointPrimaryGenerator;
74 }

Member Function Documentation

void G4AdjointPrimaryGeneratorAction::ConsiderParticleAsPrimary ( const G4String particle_name)

Definition at line 313 of file G4AdjointPrimaryGeneratorAction.cc.

314 {
315  if (PrimariesConsideredInAdjointSim.find(particle_name) != PrimariesConsideredInAdjointSim.end()){
316  PrimariesConsideredInAdjointSim[particle_name]=true;
317  }
319 }

Here is the call graph for this function:

Here is the caller graph for this function:

void G4AdjointPrimaryGeneratorAction::GeneratePrimaries ( G4Event anEvent)
virtual

Implements G4VUserPrimaryGeneratorAction.

Definition at line 77 of file G4AdjointPrimaryGeneratorAction.cc.

78 {
79 
80  G4int evt_id=anEvent->GetEventID();
81  size_t n=ListOfPrimaryAdjParticles.size();
82  index_particle=size_t(evt_id)-n*(size_t(evt_id)/n);
83 
84 
85  G4double E1=Emin;
86  G4double E2=Emax;
87  if (!ListOfPrimaryAdjParticles[index_particle]) UpdateListOfPrimaryParticles();//ion has not been created yet
88 
89  if (ListOfPrimaryAdjParticles[index_particle]->GetParticleName() == "adj_proton") {
90  E1=EminIon;
91  E2=EmaxIon;
92  }
93  if (ListOfPrimaryAdjParticles[index_particle]->GetParticleType() == "adjoint_nucleus") {
94  G4int A= ListOfPrimaryAdjParticles[index_particle]->GetAtomicMass();
95  E1=EminIon*A;
96  E2=EmaxIon*A;
97  }
98  //Generate first the forwrad primaries
99  theAdjointPrimaryGenerator->GenerateFwdPrimaryVertex(anEvent,ListOfPrimaryFwdParticles[index_particle],E1,E2);
100  G4PrimaryVertex* fwdPrimVertex = anEvent->GetPrimaryVertex();
101 
102  p=fwdPrimVertex->GetPrimary()->GetMomentum();
103  pos=fwdPrimVertex->GetPosition();
104  G4double pmag=p.mag();
105  G4double m0=ListOfPrimaryFwdParticles[index_particle]->GetPDGMass();
106  G4double ekin=std::sqrt( m0*m0 + pmag*pmag) -m0;
107 
108  G4double weight_correction=1.;
109  //For gamma generate the particle along the backward ray
110  G4ThreeVector dir=-p/p.mag();
111 
112  /*if (ListOfPrimaryAdjParticles[index_particle]->GetParticleName() == "adj_gamma"){
113 
114  theAdjointPrimaryGenerator
115  ->ComputeAccumulatedDepthVectorAlongBackRay(pos,dir,ekin,ListOfPrimaryAdjParticles[index_particle]);
116 
117 
118  G4double distance = theAdjointPrimaryGenerator
119  ->SampleDistanceAlongBackRayAndComputeWeightCorrection(weight_correction);
120 
121  //pos=pos+dir*distance;
122  //fwdPrimVertex->SetPosition(pos[0],pos[1],pos[2]);
123  }
124  */
125  weight_correction=1.;
126 
127  if (ListOfPrimaryFwdParticles[index_particle] ==G4Gamma::Gamma() && nb_fwd_gammas_per_event>1 ){
128  G4double weight = (1./nb_fwd_gammas_per_event);
129  fwdPrimVertex->SetWeight(weight);
130  for (int i=0;i<nb_fwd_gammas_per_event-1;i++){
131  G4PrimaryVertex* newFwdPrimVertex = new G4PrimaryVertex();
132  newFwdPrimVertex->SetPosition(pos.x(),pos.y(),pos.z());
133  newFwdPrimVertex->SetT0(0.);
134  G4PrimaryParticle* aPrimParticle = new G4PrimaryParticle(ListOfPrimaryFwdParticles[index_particle],
135  p.x(),p.y(),p.z());
136  newFwdPrimVertex->SetPrimary(aPrimParticle);
137  newFwdPrimVertex->SetWeight(weight);
138  anEvent->AddPrimaryVertex(newFwdPrimVertex);
139  }
140  }
141 
142  //Now generate the adjoint primaries
143  G4PrimaryVertex* adjPrimVertex = new G4PrimaryVertex();
144  adjPrimVertex->SetPosition(pos.x(),pos.y(),pos.z());
145  adjPrimVertex->SetT0(0.);
146  G4PrimaryParticle* aPrimParticle = new G4PrimaryParticle(ListOfPrimaryAdjParticles[index_particle],
147  -p.x(),-p.y(),-p.z());
148 
149  adjPrimVertex->SetPrimary(aPrimParticle);
150  anEvent->AddPrimaryVertex(adjPrimVertex);
151 
152  //The factor pi is to normalise the weight to the directional flux
154  G4double adjoint_weight = weight_correction*ComputeEnergyDistWeight(ekin,E1,E2)*adjoint_source_area*pi;
155  //if (ListOfPrimaryFwdParticles[index_particle] ==G4Gamma::Gamma()) adjoint_weight = adjoint_weight/3.;
156  if (ListOfPrimaryAdjParticles[index_particle]->GetParticleName() == "adj_gamma") {
157  //The weight will be corrected at the end of the track if splitted tracks are used
158  adjoint_weight = adjoint_weight/nb_adj_primary_gammas_per_event;
159  for (int i=0;i<nb_adj_primary_gammas_per_event-1;i++){
160  G4PrimaryVertex* newAdjPrimVertex = new G4PrimaryVertex();
161  newAdjPrimVertex->SetPosition(pos.x(),pos.y(),pos.z());
162  newAdjPrimVertex->SetT0(0.);
163  aPrimParticle = new G4PrimaryParticle(ListOfPrimaryAdjParticles[index_particle],
164  -p.x(),-p.y(),-p.z());
165  newAdjPrimVertex->SetPrimary(aPrimParticle);
166  newAdjPrimVertex->SetWeight(adjoint_weight);
167  anEvent->AddPrimaryVertex(newAdjPrimVertex);
168  }
169  }
170  else if (ListOfPrimaryAdjParticles[index_particle]->GetParticleName() == "adj_electron") {
171  //The weight will be corrected at the end of the track if splitted tracks are used
172  adjoint_weight = adjoint_weight/nb_adj_primary_electrons_per_event;
173  for (int i=0;i<nb_adj_primary_electrons_per_event-1;i++){
174  G4PrimaryVertex* newAdjPrimVertex = new G4PrimaryVertex();
175  newAdjPrimVertex->SetPosition(pos.x(),pos.y(),pos.z());
176  newAdjPrimVertex->SetT0(0.);
177  aPrimParticle = new G4PrimaryParticle(ListOfPrimaryAdjParticles[index_particle],
178  -p.x(),-p.y(),-p.z());
179  newAdjPrimVertex->SetPrimary(aPrimParticle);
180  newAdjPrimVertex->SetWeight(adjoint_weight);
181  anEvent->AddPrimaryVertex(newAdjPrimVertex);
182  }
183  }
184  adjPrimVertex->SetWeight(adjoint_weight);
185 
186  //Call some methods of G4AdjointSimManager
190 
191  /* if ( !last_generated_part_was_adjoint ) {
192 
193  index_particle++;
194  if (index_particle >= ListOfPrimaryAdjParticles.size()) index_particle =0;
195 
196 
197  G4double E1=Emin;
198  G4double E2=Emax;
199  if (!ListOfPrimaryAdjParticles[index_particle]) UpdateListOfPrimaryParticles();//ion has not been created yet
200 
201  if (ListOfPrimaryAdjParticles[index_particle]->GetParticleName() == "adj_proton") {
202  E1=EminIon;
203  E2=EmaxIon;
204  }
205  if (ListOfPrimaryAdjParticles[index_particle]->GetParticleType() == "adjoint_nucleus") {
206  G4int A= ListOfPrimaryAdjParticles[index_particle]->GetAtomicMass();
207  E1=EminIon*A;
208  E2=EmaxIon*A;
209  }
210  theAdjointPrimaryGenerator->GenerateAdjointPrimaryVertex(anEvent,
211  ListOfPrimaryAdjParticles[index_particle],
212  E1,E2);
213  G4PrimaryVertex* aPrimVertex = anEvent->GetPrimaryVertex();
214 
215 
216  p=aPrimVertex->GetPrimary()->GetMomentum();
217  pos=aPrimVertex->GetPosition();
218  G4double pmag=p.mag();
219 
220  G4double m0=ListOfPrimaryAdjParticles[index_particle]->GetPDGMass();
221  G4double ekin=std::sqrt( m0*m0 + pmag*pmag) -m0;
222 
223 
224  //The factor pi is to normalise the weight to the directional flux
225  G4double adjoint_source_area = G4AdjointSimManager::GetInstance()->GetAdjointSourceArea();
226  G4double adjoint_weight = ComputeEnergyDistWeight(ekin,E1,E2)*adjoint_source_area*pi;
227 
228  aPrimVertex->SetWeight(adjoint_weight);
229 
230  last_generated_part_was_adjoint =true;
231  G4AdjointSimManager::GetInstance()->SetAdjointTrackingMode(true);
232  G4AdjointSimManager::GetInstance()->RegisterAdjointPrimaryWeight(adjoint_weight);
233  }
234  else {
235  //fwd particle equivalent to the last generated adjoint particle ios generated
236  G4PrimaryVertex* aPrimVertex = new G4PrimaryVertex();
237  aPrimVertex->SetPosition(pos.x(),pos.y(),pos.z());
238  aPrimVertex->SetT0(0.);
239  G4PrimaryParticle* aPrimParticle = new G4PrimaryParticle(ListOfPrimaryFwdParticles[index_particle],
240  -p.x(),-p.y(),-p.z());
241 
242  aPrimVertex->SetPrimary(aPrimParticle);
243  anEvent->AddPrimaryVertex(aPrimVertex);
244  last_generated_part_was_adjoint =false;
245  G4AdjointSimManager::GetInstance()->SetAdjointTrackingMode(false);
246  */
247 
248 }
static G4AdjointSimManager * GetInstance()
G4ThreeVector GetMomentum() const
G4ThreeVector GetPosition() const
void SetWeight(G4double w)
const char * p
Definition: xmltok.h:285
void AddPrimaryVertex(G4PrimaryVertex *aPrimaryVertex)
Definition: G4Event.hh:154
int G4int
Definition: G4Types.hh:78
G4int GetEventID() const
Definition: G4Event.hh:151
G4PrimaryParticle * GetPrimary(G4int i=0) const
double A(double temperature)
void SetAdjointTrackingMode(G4bool aBool)
const G4int n
G4PrimaryVertex * GetPrimaryVertex(G4int i=0) const
Definition: G4Event.hh:167
static G4Gamma * Gamma()
Definition: G4Gamma.cc:86
void GenerateFwdPrimaryVertex(G4Event *anEvt, G4ParticleDefinition *adj_part, G4double E1, G4double E2)
void SetT0(G4double t0)
static const G4double Emin
void SetPrimary(G4PrimaryParticle *pp)
void SetPosition(G4double x0, G4double y0, G4double z0)
static const G4double Emax
static constexpr double pi
Definition: G4SIunits.hh:75
double G4double
Definition: G4Types.hh:76
double mag() const
static const G4double pos
void ResetDidOneAdjPartReachExtSourceDuringEvent()

Here is the call graph for this function:

G4ParticleDefinition* G4AdjointPrimaryGeneratorAction::GetLastGeneratedFwdPrimaryParticle ( )
inline

Definition at line 106 of file G4AdjointPrimaryGeneratorAction.hh.

106 {return ListOfPrimaryFwdParticles[index_particle];}

Here is the caller graph for this function:

std::vector<G4ParticleDefinition*>* G4AdjointPrimaryGeneratorAction::GetListOfPrimaryFwdParticles ( )
inline

Definition at line 100 of file G4AdjointPrimaryGeneratorAction.hh.

100  {
101  return &ListOfPrimaryFwdParticles;}

Here is the caller graph for this function:

size_t G4AdjointPrimaryGeneratorAction::GetNbOfAdjointPrimaryTypes ( )
inline

Definition at line 99 of file G4AdjointPrimaryGeneratorAction.hh.

99 {return ListOfPrimaryAdjParticles.size();}

Here is the caller graph for this function:

const G4String& G4AdjointPrimaryGeneratorAction::GetPrimaryIonName ( )
inline

Definition at line 102 of file G4AdjointPrimaryGeneratorAction.hh.

102 {return ion_name;}

Here is the caller graph for this function:

void G4AdjointPrimaryGeneratorAction::NeglectParticleAsPrimary ( const G4String particle_name)

Definition at line 322 of file G4AdjointPrimaryGeneratorAction.cc.

323 {
324  if (PrimariesConsideredInAdjointSim.find(particle_name) != PrimariesConsideredInAdjointSim.end()){
325  PrimariesConsideredInAdjointSim[particle_name]= false;
326  }
328 }

Here is the call graph for this function:

Here is the caller graph for this function:

void G4AdjointPrimaryGeneratorAction::SetAdjointPrimarySourceOnAnExtSurfaceOfAVolume ( const G4String volume_name)

Definition at line 306 of file G4AdjointPrimaryGeneratorAction.cc.

307 {
308  type_of_adjoint_source ="ExternalSurfaceOfAVolume";
309  theAdjointPrimaryGenerator->SetAdjointPrimarySourceOnAnExtSurfaceOfAVolume(volume_name);
310 }
void SetAdjointPrimarySourceOnAnExtSurfaceOfAVolume(const G4String &volume_name)

Here is the call graph for this function:

Here is the caller graph for this function:

void G4AdjointPrimaryGeneratorAction::SetEmax ( G4double  val)

Definition at line 258 of file G4AdjointPrimaryGeneratorAction.cc.

259 {
260  Emax=val;
261  EmaxIon=val;
262 }
static const G4double Emax

Here is the caller graph for this function:

void G4AdjointPrimaryGeneratorAction::SetEmaxIon ( G4double  val)

Definition at line 271 of file G4AdjointPrimaryGeneratorAction.cc.

272 {
273  EmaxIon=val;
274 }
void G4AdjointPrimaryGeneratorAction::SetEmin ( G4double  val)

Definition at line 251 of file G4AdjointPrimaryGeneratorAction.cc.

252 {
253  Emin=val;
254  EminIon=val;
255 }
static const G4double Emin

Here is the caller graph for this function:

void G4AdjointPrimaryGeneratorAction::SetEminIon ( G4double  val)

Definition at line 265 of file G4AdjointPrimaryGeneratorAction.cc.

266 {
267  EminIon=val;
268 }
void G4AdjointPrimaryGeneratorAction::SetNbAdjointPrimaryElectronsPerEvent ( G4int  nb)
inline

Definition at line 105 of file G4AdjointPrimaryGeneratorAction.hh.

105 {nb_adj_primary_electrons_per_event=nb;}

Here is the caller graph for this function:

void G4AdjointPrimaryGeneratorAction::SetNbAdjointPrimaryGammasPerEvent ( G4int  nb)
inline

Definition at line 104 of file G4AdjointPrimaryGeneratorAction.hh.

104 {nb_adj_primary_gammas_per_event=nb;}

Here is the caller graph for this function:

void G4AdjointPrimaryGeneratorAction::SetNbPrimaryFwdGammasPerEvent ( G4int  nb)
inline

Definition at line 103 of file G4AdjointPrimaryGeneratorAction.hh.

103 {nb_fwd_gammas_per_event=nb;}

Here is the caller graph for this function:

void G4AdjointPrimaryGeneratorAction::SetPrimaryIon ( G4ParticleDefinition adjointIon,
G4ParticleDefinition fwdIon 
)

Definition at line 371 of file G4AdjointPrimaryGeneratorAction.cc.

372 {
373  fwd_ion = fwdIon;
374  adj_ion = adjointIon;
376 }

Here is the call graph for this function:

Here is the caller graph for this function:

void G4AdjointPrimaryGeneratorAction::SetRndmFlag ( const G4String val)
inline

Definition at line 88 of file G4AdjointPrimaryGeneratorAction.hh.

88 { rndmFlag = val;}
void G4AdjointPrimaryGeneratorAction::SetSphericalAdjointPrimarySource ( G4double  radius,
G4ThreeVector  pos 
)

Definition at line 297 of file G4AdjointPrimaryGeneratorAction.cc.

298 {
299  radius_spherical_source = radius;
300  center_spherical_source = center_pos;
301  type_of_adjoint_source ="Spherical";
302  theAdjointPrimaryGenerator->SetSphericalAdjointPrimarySource(radius,center_pos);
303 }
void SetSphericalAdjointPrimarySource(G4double radius, G4ThreeVector pos)

Here is the call graph for this function:

Here is the caller graph for this function:

void G4AdjointPrimaryGeneratorAction::UpdateListOfPrimaryParticles ( )

Definition at line 331 of file G4AdjointPrimaryGeneratorAction.cc.

332 {
334  ListOfPrimaryFwdParticles.clear();
335  ListOfPrimaryAdjParticles.clear();
336  std::map<G4String, G4bool>::iterator iter;
337  for( iter = PrimariesConsideredInAdjointSim.begin(); iter != PrimariesConsideredInAdjointSim.end(); ++iter ) {
338  if(iter->second) {
339  G4String fwd_particle_name = iter->first;
340  if ( fwd_particle_name != "ion") {
341  G4String adj_particle_name = G4String("adj_") + fwd_particle_name;
342  ListOfPrimaryFwdParticles.push_back(theParticleTable->FindParticle(fwd_particle_name));
343  ListOfPrimaryAdjParticles.push_back(theParticleTable->FindParticle(adj_particle_name));
344  /*
345  if ( fwd_particle_name == "gamma") {
346  for (G4int i=0;i<2;i++){
347  ListOfPrimaryFwdParticles.push_back(theParticleTable->FindParticle(fwd_particle_name));
348  ListOfPrimaryAdjParticles.push_back(theParticleTable->FindParticle(adj_particle_name));
349  }
350  }
351  */
352  }
353  else {
354  if (fwd_ion ){
355  ion_name=fwd_ion->GetParticleName();
356  G4String adj_ion_name=G4String("adj_") +ion_name;
357  ListOfPrimaryFwdParticles.push_back(fwd_ion);
358  ListOfPrimaryAdjParticles.push_back(adj_ion);
359  }
360  else {
361  ListOfPrimaryFwdParticles.push_back(0);
362  ListOfPrimaryAdjParticles.push_back(0);
363 
364  }
365  }
366  }
367  }
368 }
G4ParticleDefinition * FindParticle(G4int PDGEncoding)
G4int first(char) const
const G4String & GetParticleName() const
static G4ParticleTable * GetParticleTable()

Here is the call graph for this function:

Here is the caller graph for this function:


The documentation for this class was generated from the following files: