Geant4 11.4.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4AdjointPrimaryGenerator.cc
Go to the documentation of this file.
1//
2// ********************************************************************
3// * License and Disclaimer *
4// * *
5// * The Geant4 software is copyright of the Copyright Holders of *
6// * the Geant4 Collaboration. It is provided under the terms and *
7// * conditions of the Geant4 Software License, included in the file *
8// * LICENSE and available at http://cern.ch/geant4/license . These *
9// * include a list of copyright holders. *
10// * *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work make any representation or warranty, express or implied, *
14// * regarding this software system or assume any liability for its *
15// * use. Please see the license in the file LICENSE and URL above *
16// * for the full disclaimer and the limitation of liability. *
17// * *
18// * This code implementation is the result of the scientific and *
19// * technical work of the GEANT4 collaboration. *
20// * By using, copying, modifying or distributing the software (or *
21// * any work based on the software) you agree to acknowledge its *
22// * use in resulting scientific publications, and indicate your *
23// * acceptance of all terms of the Geant4 Software license. *
24// ********************************************************************
25//
26// G4AdjointPrimaryGenerator class implementation
27//
28// Author: L. Desorgher, SpaceIT GmbH - November 2009
29// Contract: ESA contract 21435/08/NL/AT
30// Customer: ESA/ESTEC
31// --------------------------------------------------------------------
32
35#include "G4Event.hh"
39#include "G4Navigator.hh"
41#include "G4VPhysicalVolume.hh"
42#include "G4Material.hh"
43#include "Randomize.hh"
44
45
46
47
48// --------------------------------------------------------------------
49//
56
57
58// --------------------------------------------------------------------
59//
61{
62 center_spherical_source = G4ThreeVector(0.,0.,0.);
63 type_of_adjoint_source="Spherical";
64 theSingleParticleSource = new G4SingleParticleSource();
65 theSingleParticleSource->GetEneDist()->SetEnergyDisType("Pow");
66 theSingleParticleSource->GetEneDist()->SetAlpha(-1.);
67 theSingleParticleSource->GetPosDist()->SetPosDisType("Point");
68 theSingleParticleSource->GetAngDist()->SetAngDistType("planar");
69
70 theG4AdjointPosOnPhysVolGenerator = G4AdjointPosOnPhysVolGenerator::GetInstance();
71}
72
73// --------------------------------------------------------------------
74//
76{
77 delete theSingleParticleSource;
78}
79
80// --------------------------------------------------------------------
81//
84 G4double E1, G4double E2)
85{
86 if (type_of_adjoint_source == "ExternalSurfaceOfAVolume")
87 {
88 // Generate position and direction relative to the external surface
89 // of sensitive volume
90
91 G4double costh_to_normal=1.;
92 G4ThreeVector pos =G4ThreeVector(0.,0.,0.);
93 G4ThreeVector direction = G4ThreeVector(0.,0.,1.);
94 theG4AdjointPosOnPhysVolGenerator
95 ->GenerateAPositionOnTheExtSurfaceOfThePhysicalVolume(pos, direction,
96 costh_to_normal);
97 if (costh_to_normal <1.e-4) { costh_to_normal = 1.e-4; }
98
99 // compute now the position along the ray backward direction
100 //
101 theSingleParticleSource->GetAngDist()
102 ->SetParticleMomentumDirection(-direction);
103 theSingleParticleSource->GetPosDist()->SetCentreCoords(pos);
104 }
105
106 theSingleParticleSource->GetEneDist()->SetEmin(E1);
107 theSingleParticleSource->GetEneDist()->SetEmax(E2);
108
109 theSingleParticleSource->SetParticleDefinition(adj_part);
110 theSingleParticleSource->GeneratePrimaryVertex(anEvent);
111}
112
113// --------------------------------------------------------------------
114//
117 G4double E1, G4double E2)
118{
119 if (type_of_adjoint_source == "ExternalSurfaceOfAVolume")
120 {
121 // Generate position and direction relative to the external surface
122 // of sensitive volume
123
124 G4double costh_to_normal=1.;
125 G4ThreeVector pos =G4ThreeVector(0.,0.,0.);
126 G4ThreeVector direction = G4ThreeVector(0.,0.,1.);
127 theG4AdjointPosOnPhysVolGenerator
128 ->GenerateAPositionOnTheExtSurfaceOfThePhysicalVolume(pos, direction,
129 costh_to_normal);
130 if (costh_to_normal <1.e-4) { costh_to_normal =1.e-4; }
131 theSingleParticleSource->GetAngDist()
132 ->SetParticleMomentumDirection(direction);
133 theSingleParticleSource->GetPosDist()->SetCentreCoords(pos);
134 }
135
136 theSingleParticleSource->GetEneDist()->SetEmin(E1);
137 theSingleParticleSource->GetEneDist()->SetEmax(E2);
138
139 theSingleParticleSource->SetParticleDefinition(fwd_part);
140 theSingleParticleSource->GeneratePrimaryVertex(anEvent);
141}
142
143// --------------------------------------------------------------------
144//
147{
148 radius_spherical_source = radius;
149 center_spherical_source = center_pos;
150 type_of_adjoint_source = "Spherical";
151 theSingleParticleSource->GetPosDist()->SetPosDisType("Surface");
152 theSingleParticleSource->GetPosDist()->SetPosDisShape("Sphere");
153 theSingleParticleSource->GetPosDist()->SetCentreCoords(center_pos);
154 theSingleParticleSource->GetPosDist()->SetRadius(radius);
155 theSingleParticleSource->GetAngDist()->SetAngDistType("cos");
156 theSingleParticleSource->GetAngDist()->SetMaxTheta(pi);
157 theSingleParticleSource->GetAngDist()->SetMinTheta(halfpi);
158}
159
160// --------------------------------------------------------------------
161//
164{
165 theG4AdjointPosOnPhysVolGenerator->DefinePhysicalVolume1(volume_name);
166 type_of_adjoint_source ="ExternalSurfaceOfAVolume";
167 theSingleParticleSource->GetPosDist()->SetPosDisType("Point");
168 theSingleParticleSource->GetAngDist()->SetAngDistType("planar");
169}
170
171// --------------------------------------------------------------------
172//
175 G4ThreeVector direction,
177{
178 if (fLinearNavigator == nullptr)
179 {
182 }
183 G4ThreeVector position = glob_pos;
184 G4double safety=1.;
185 G4VPhysicalVolume* thePhysVolume =
186 fLinearNavigator->LocateGlobalPointAndSetup(position);
187 G4double newStep = fLinearNavigator->ComputeStep(position,direction,1.e50,
188 safety);
189 delete theAccumulatedDepthVector;
190 theAccumulatedDepthVector = new G4PhysicsFreeVector();
191
192 G4double acc_depth=0.;
193 G4double acc_length=0.;
194 theAccumulatedDepthVector->InsertValues(acc_length,acc_depth);
195
196 while (newStep > 0. && thePhysVolume != nullptr)
197 {
198 acc_length+=newStep;
199 acc_depth+=newStep*thePhysVolume->GetLogicalVolume()
200 ->GetMaterial()->GetDensity();
201 theAccumulatedDepthVector->InsertValues(acc_length,acc_depth);
202 position=position+newStep*direction;
203 thePhysVolume = fLinearNavigator
204 ->LocateGlobalPointAndSetup(position,nullptr,false);
205 newStep = fLinearNavigator->ComputeStep(position,direction,1.e50,safety);
206 }
207}
208
209// --------------------------------------------------------------------
210//
213{
214 G4double rand = G4UniformRand();
215 G4double distance = theAccumulatedDepthVector->FindLinearEnergy(rand);
216 weight_corr=1.;
217 return distance;
218}
CLHEP::Hep3Vector G4ThreeVector
double G4double
Definition G4Types.hh:83
#define G4UniformRand()
Definition Randomize.hh:52
static G4AdjointPosOnPhysVolGenerator * GetInstance()
void SetSphericalAdjointPrimarySource(G4double radius, G4ThreeVector pos)
void SetAdjointPrimarySourceOnAnExtSurfaceOfAVolume(const G4String &v_name)
static G4AdjointPrimaryGenerator * GetInstance()
void GenerateAdjointPrimaryVertex(G4Event *anEvt, G4ParticleDefinition *adj_part, G4double E1, G4double E2)
G4double SampleDistanceAlongBackRayAndComputeWeightCorrection(G4double &weight_corr)
void GenerateFwdPrimaryVertex(G4Event *anEvt, G4ParticleDefinition *adj_part, G4double E1, G4double E2)
void ComputeAccumulatedDepthVectorAlongBackRay(G4ThreeVector glob_pos, G4ThreeVector direction, G4double ekin, G4ParticleDefinition *aPDef)
G4Material * GetMaterial() const
G4double GetDensity() const
static G4TransportationManager * GetTransportationManager()
G4Navigator * GetNavigatorForTracking() const
G4VPhysicalVolume is an abstract base class for the representation of a positioned volume....
G4LogicalVolume * GetLogicalVolume() const
#define G4ThreadLocal
Definition tls.hh:77