Geant4.10
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions
G4AdjointPrimaryGeneratorAction Class Reference

#include <G4AdjointPrimaryGeneratorAction.hh>

Inheritance diagram for G4AdjointPrimaryGeneratorAction:
G4VUserPrimaryGeneratorAction

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 ()
 
- 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 47 of file G4AdjointPrimaryGeneratorAction.cc.

48  : Emin(0.), Emax(0.), EminIon(0.), EmaxIon(0.),
49  index_particle(100000),
50  radius_spherical_source(0.), fwd_ion(0), adj_ion(0),
51  ion_name("not_defined")
52 {
53  theAdjointPrimaryGenerator= new G4AdjointPrimaryGenerator();
54 
55  PrimariesConsideredInAdjointSim[G4String("e-")]=false;
56  PrimariesConsideredInAdjointSim[G4String("gamma")]=false;
57  PrimariesConsideredInAdjointSim[G4String("proton")]=false;
58  PrimariesConsideredInAdjointSim[G4String("ion")]=false;
59 
60  ListOfPrimaryFwdParticles.clear();
61  ListOfPrimaryAdjParticles.clear();
62 }
G4AdjointPrimaryGeneratorAction::~G4AdjointPrimaryGeneratorAction ( )

Definition at line 65 of file G4AdjointPrimaryGeneratorAction.cc.

66 {
67  delete theAdjointPrimaryGenerator;
68 }

Member Function Documentation

void G4AdjointPrimaryGeneratorAction::ConsiderParticleAsPrimary ( const G4String particle_name)

Definition at line 243 of file G4AdjointPrimaryGeneratorAction.cc.

References UpdateListOfPrimaryParticles().

Referenced by G4AdjointSimManager::ConsiderParticleAsPrimary().

244 {
245  if (PrimariesConsideredInAdjointSim.find(particle_name) != PrimariesConsideredInAdjointSim.end()){
246  PrimariesConsideredInAdjointSim[particle_name]=true;
247  }
249 }
void G4AdjointPrimaryGeneratorAction::GeneratePrimaries ( G4Event anEvent)
virtual

Implements G4VUserPrimaryGeneratorAction.

Definition at line 71 of file G4AdjointPrimaryGeneratorAction.cc.

References G4Event::AddPrimaryVertex(), G4AdjointPrimaryGenerator::GenerateFwdPrimaryVertex(), G4AdjointSimManager::GetAdjointSourceArea(), G4Event::GetEventID(), G4AdjointSimManager::GetInstance(), G4PrimaryParticle::GetMomentum(), G4PrimaryVertex::GetPosition(), G4PrimaryVertex::GetPrimary(), G4Event::GetPrimaryVertex(), CLHEP::Hep3Vector::mag(), n, python.hepunit::pi, G4AdjointSimManager::SetAdjointTrackingMode(), G4PrimaryVertex::SetPosition(), G4PrimaryVertex::SetPrimary(), G4PrimaryVertex::SetT0(), G4PrimaryVertex::SetWeight(), UpdateListOfPrimaryParticles(), CLHEP::Hep3Vector::x(), CLHEP::Hep3Vector::y(), and CLHEP::Hep3Vector::z().

72 { G4int evt_id=anEvent->GetEventID();
73  size_t n=ListOfPrimaryAdjParticles.size();
74  index_particle=size_t(evt_id)-n*(size_t(evt_id)/n);
75 
76 
77  G4double E1=Emin;
78  G4double E2=Emax;
79  if (!ListOfPrimaryAdjParticles[index_particle]) UpdateListOfPrimaryParticles();//ion has not been created yet
80 
81  if (ListOfPrimaryAdjParticles[index_particle]->GetParticleName() == "adj_proton") {
82  E1=EminIon;
83  E2=EmaxIon;
84  }
85  if (ListOfPrimaryAdjParticles[index_particle]->GetParticleType() == "adjoint_nucleus") {
86  G4int A= ListOfPrimaryAdjParticles[index_particle]->GetAtomicMass();
87  E1=EminIon*A;
88  E2=EmaxIon*A;
89  }
90  theAdjointPrimaryGenerator->GenerateFwdPrimaryVertex(anEvent,ListOfPrimaryFwdParticles[index_particle],E1,E2);
91  G4PrimaryVertex* fwdPrimVertex = anEvent->GetPrimaryVertex();
92 
93  p=fwdPrimVertex->GetPrimary()->GetMomentum();
94  pos=fwdPrimVertex->GetPosition();
95  G4double pmag=p.mag();
96 
97 
98  G4double m0=ListOfPrimaryFwdParticles[index_particle]->GetPDGMass();
99  G4double ekin=std::sqrt( m0*m0 + pmag*pmag) -m0;
100 
101  G4PrimaryVertex* adjPrimVertex = new G4PrimaryVertex();
102  adjPrimVertex->SetPosition(pos.x(),pos.y(),pos.z());
103  adjPrimVertex->SetT0(0.);
104  G4PrimaryParticle* aPrimParticle = new G4PrimaryParticle(ListOfPrimaryAdjParticles[index_particle],
105  -p.x(),-p.y(),-p.z());
106 
107  adjPrimVertex->SetPrimary(aPrimParticle);
108  anEvent->AddPrimaryVertex(adjPrimVertex);
109 
110  //The factor pi is to normalise the weight to the directional flux
112  G4double adjoint_weight = ComputeEnergyDistWeight(ekin,E1,E2)*adjoint_source_area*pi;
113  adjPrimVertex->SetWeight(adjoint_weight);
114 
115 
116 
118 
119 
120 
121  /* if ( !last_generated_part_was_adjoint ) {
122 
123  index_particle++;
124  if (index_particle >= ListOfPrimaryAdjParticles.size()) index_particle =0;
125 
126 
127  G4double E1=Emin;
128  G4double E2=Emax;
129  if (!ListOfPrimaryAdjParticles[index_particle]) UpdateListOfPrimaryParticles();//ion has not been created yet
130 
131  if (ListOfPrimaryAdjParticles[index_particle]->GetParticleName() == "adj_proton") {
132  E1=EminIon;
133  E2=EmaxIon;
134  }
135  if (ListOfPrimaryAdjParticles[index_particle]->GetParticleType() == "adjoint_nucleus") {
136  G4int A= ListOfPrimaryAdjParticles[index_particle]->GetAtomicMass();
137  E1=EminIon*A;
138  E2=EmaxIon*A;
139  }
140  theAdjointPrimaryGenerator->GenerateAdjointPrimaryVertex(anEvent,
141  ListOfPrimaryAdjParticles[index_particle],
142  E1,E2);
143  G4PrimaryVertex* aPrimVertex = anEvent->GetPrimaryVertex();
144 
145 
146  p=aPrimVertex->GetPrimary()->GetMomentum();
147  pos=aPrimVertex->GetPosition();
148  G4double pmag=p.mag();
149 
150  G4double m0=ListOfPrimaryAdjParticles[index_particle]->GetPDGMass();
151  G4double ekin=std::sqrt( m0*m0 + pmag*pmag) -m0;
152 
153 
154  //The factor pi is to normalise the weight to the directional flux
155  G4double adjoint_source_area = G4AdjointSimManager::GetInstance()->GetAdjointSourceArea();
156  G4double adjoint_weight = ComputeEnergyDistWeight(ekin,E1,E2)*adjoint_source_area*pi;
157 
158  aPrimVertex->SetWeight(adjoint_weight);
159 
160  last_generated_part_was_adjoint =true;
161  G4AdjointSimManager::GetInstance()->SetAdjointTrackingMode(true);
162  G4AdjointSimManager::GetInstance()->RegisterAdjointPrimaryWeight(adjoint_weight);
163  }
164  else {
165  //fwd particle equivalent to the last generated adjoint particle ios generated
166  G4PrimaryVertex* aPrimVertex = new G4PrimaryVertex();
167  aPrimVertex->SetPosition(pos.x(),pos.y(),pos.z());
168  aPrimVertex->SetT0(0.);
169  G4PrimaryParticle* aPrimParticle = new G4PrimaryParticle(ListOfPrimaryFwdParticles[index_particle],
170  -p.x(),-p.y(),-p.z());
171 
172  aPrimVertex->SetPrimary(aPrimParticle);
173  anEvent->AddPrimaryVertex(aPrimVertex);
174  last_generated_part_was_adjoint =false;
175  G4AdjointSimManager::GetInstance()->SetAdjointTrackingMode(false);
176  */
177 
178 }
static G4AdjointSimManager * GetInstance()
G4ThreeVector GetMomentum() const
G4ThreeVector GetPosition() const
double x() const
void SetWeight(G4double w)
const char * p
Definition: xmltok.h:285
void AddPrimaryVertex(G4PrimaryVertex *aPrimaryVertex)
Definition: G4Event.hh:143
int G4int
Definition: G4Types.hh:78
double z() const
G4int GetEventID() const
Definition: G4Event.hh:140
G4PrimaryParticle * GetPrimary(G4int i=0) const
void SetAdjointTrackingMode(G4bool aBool)
const G4int n
G4PrimaryVertex * GetPrimaryVertex(G4int i=0) const
Definition: G4Event.hh:156
void GenerateFwdPrimaryVertex(G4Event *anEvt, G4ParticleDefinition *adj_part, G4double E1, G4double E2)
void SetT0(G4double t0)
double y() const
void SetPrimary(G4PrimaryParticle *pp)
void SetPosition(G4double x0, G4double y0, G4double z0)
double G4double
Definition: G4Types.hh:76
double mag() const
std::vector<G4ParticleDefinition*> G4AdjointPrimaryGeneratorAction::GetListOfPrimaryFwdParticles ( )
inline
size_t G4AdjointPrimaryGeneratorAction::GetNbOfAdjointPrimaryTypes ( )
inline

Definition at line 99 of file G4AdjointPrimaryGeneratorAction.hh.

Referenced by G4AdjointSimManager::RunAdjointSimulation().

99 {return ListOfPrimaryAdjParticles.size();}
const G4String& G4AdjointPrimaryGeneratorAction::GetPrimaryIonName ( )
inline

Definition at line 101 of file G4AdjointPrimaryGeneratorAction.hh.

Referenced by G4AdjointSimManager::GetPrimaryIonName().

101 {return ion_name;}
void G4AdjointPrimaryGeneratorAction::NeglectParticleAsPrimary ( const G4String particle_name)

Definition at line 252 of file G4AdjointPrimaryGeneratorAction.cc.

References UpdateListOfPrimaryParticles().

Referenced by G4AdjointSimManager::NeglectParticleAsPrimary().

253 {
254  if (PrimariesConsideredInAdjointSim.find(particle_name) != PrimariesConsideredInAdjointSim.end()){
255  PrimariesConsideredInAdjointSim[particle_name]= false;
256  }
258 }
void G4AdjointPrimaryGeneratorAction::SetAdjointPrimarySourceOnAnExtSurfaceOfAVolume ( const G4String volume_name)

Definition at line 236 of file G4AdjointPrimaryGeneratorAction.cc.

References G4AdjointPrimaryGenerator::SetAdjointPrimarySourceOnAnExtSurfaceOfAVolume().

Referenced by G4AdjointSimManager::DefineAdjointSourceOnTheExtSurfaceOfAVolume().

237 {
238  type_of_adjoint_source ="ExternalSurfaceOfAVolume";
239  theAdjointPrimaryGenerator->SetAdjointPrimarySourceOnAnExtSurfaceOfAVolume(volume_name);
240 }
void SetAdjointPrimarySourceOnAnExtSurfaceOfAVolume(const G4String &volume_name)
void G4AdjointPrimaryGeneratorAction::SetEmax ( G4double  val)

Definition at line 188 of file G4AdjointPrimaryGeneratorAction.cc.

Referenced by G4AdjointSimManager::SetAdjointSourceEmax().

189 {
190  Emax=val;
191  EmaxIon=val;
192 }
void G4AdjointPrimaryGeneratorAction::SetEmaxIon ( G4double  val)

Definition at line 201 of file G4AdjointPrimaryGeneratorAction.cc.

202 {
203  EmaxIon=val;
204 }
void G4AdjointPrimaryGeneratorAction::SetEmin ( G4double  val)

Definition at line 181 of file G4AdjointPrimaryGeneratorAction.cc.

Referenced by G4AdjointSimManager::SetAdjointSourceEmin().

182 {
183  Emin=val;
184  EminIon=val;
185 }
void G4AdjointPrimaryGeneratorAction::SetEminIon ( G4double  val)

Definition at line 195 of file G4AdjointPrimaryGeneratorAction.cc.

196 {
197  EminIon=val;
198 }
void G4AdjointPrimaryGeneratorAction::SetPrimaryIon ( G4ParticleDefinition adjointIon,
G4ParticleDefinition fwdIon 
)

Definition at line 293 of file G4AdjointPrimaryGeneratorAction.cc.

References UpdateListOfPrimaryParticles().

Referenced by G4AdjointSimManager::SetPrimaryIon().

294 {
295  fwd_ion = fwdIon;
296  adj_ion = adjointIon;
298 }
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 227 of file G4AdjointPrimaryGeneratorAction.cc.

References G4AdjointPrimaryGenerator::SetSphericalAdjointPrimarySource().

Referenced by G4AdjointSimManager::DefineSphericalAdjointSource(), and G4AdjointSimManager::DefineSphericalAdjointSourceWithCentreAtTheCentreOfAVolume().

228 {
229  radius_spherical_source = radius;
230  center_spherical_source = center_pos;
231  type_of_adjoint_source ="Spherical";
232  theAdjointPrimaryGenerator->SetSphericalAdjointPrimarySource(radius,center_pos);
233 }
void SetSphericalAdjointPrimarySource(G4double radius, G4ThreeVector pos)
void G4AdjointPrimaryGeneratorAction::UpdateListOfPrimaryParticles ( )

Definition at line 261 of file G4AdjointPrimaryGeneratorAction.cc.

References G4ParticleTable::FindParticle(), G4String::first(), G4ParticleDefinition::GetParticleName(), and G4ParticleTable::GetParticleTable().

Referenced by ConsiderParticleAsPrimary(), GeneratePrimaries(), NeglectParticleAsPrimary(), SetPrimaryIon(), and G4AdjointSimManager::SwitchToAdjointSimulationMode().

262 {
264  ListOfPrimaryFwdParticles.clear();
265  ListOfPrimaryAdjParticles.clear();
266  std::map<G4String, G4bool>::iterator iter;
267  for( iter = PrimariesConsideredInAdjointSim.begin(); iter != PrimariesConsideredInAdjointSim.end(); ++iter ) {
268  if(iter->second) {
269  G4String fwd_particle_name = iter->first;
270  if ( fwd_particle_name != "ion") {
271  G4String adj_particle_name = G4String("adj_") + fwd_particle_name;
272  ListOfPrimaryFwdParticles.push_back(theParticleTable->FindParticle(fwd_particle_name));
273  ListOfPrimaryAdjParticles.push_back(theParticleTable->FindParticle(adj_particle_name));
274  }
275  else {
276  if (fwd_ion ){
277  ion_name=fwd_ion->GetParticleName();
278  G4String adj_ion_name=G4String("adj_") +ion_name;
279  ListOfPrimaryFwdParticles.push_back(fwd_ion);
280  ListOfPrimaryAdjParticles.push_back(adj_ion);
281  }
282  else {
283  ListOfPrimaryFwdParticles.push_back(0);
284  ListOfPrimaryAdjParticles.push_back(0);
285 
286  }
287  }
288  }
289  }
290 }
G4ParticleDefinition * FindParticle(G4int PDGEncoding)
G4int first(char) const
const G4String & GetParticleName() const
static G4ParticleTable * GetParticleTable()

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