ECCE @ EIC Software
Reference for
ECCE @ EIC
simulation and reconstruction software on GitHub
Home page
Related Pages
Modules
Namespaces
Classes
Files
External Links
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
G4AdjointPrimaryGenerator.cc
Go to the documentation of this file.
Or view
the newest version in sPHENIX GitHub for file G4AdjointPrimaryGenerator.cc
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
//
28
// Class Name: G4AdjointCrossSurfChecker
29
// Author: L. Desorgher
30
// Organisation: SpaceIT GmbH
31
// Contract: ESA contract 21435/08/NL/AT
32
// Customer: ESA/ESTEC
34
35
#include "
G4AdjointPrimaryGenerator.hh
"
36
#include "
G4PhysicalConstants.hh
"
37
#include "
G4Event.hh
"
38
#include "
G4SingleParticleSource.hh
"
39
#include "
G4ParticleDefinition.hh
"
40
#include "
G4AdjointPosOnPhysVolGenerator.hh
"
41
#include "
G4Navigator.hh
"
42
#include "
G4TransportationManager.hh
"
43
#include "
G4VPhysicalVolume.hh
"
44
#include "
G4Material.hh
"
45
#include "
Randomize.hh
"
46
/*
47
#include "G4AdjointCSManager.hh"
48
#include "G4MaterialCutsCouple.hh"
49
*/
51
//
52
G4AdjointPrimaryGenerator::G4AdjointPrimaryGenerator
()
53
: radius_spherical_source(0.),fLinearNavigator(0),theAccumulatedDepthVector(0)
54
{
55
center_spherical_source
=
G4ThreeVector
(0.,0.,0.);
56
type_of_adjoint_source
=
"Spherical"
;
57
theSingleParticleSource
=
new
G4SingleParticleSource
();
58
59
theSingleParticleSource
->
GetEneDist
()->
SetEnergyDisType
(
"Pow"
);
60
theSingleParticleSource
->
GetEneDist
()->
SetAlpha
(-1.);
61
theSingleParticleSource
->
GetPosDist
()->
SetPosDisType
(
"Point"
);
62
theSingleParticleSource
->
GetAngDist
()->
SetAngDistType
(
"planar"
);
63
64
theG4AdjointPosOnPhysVolGenerator
=
G4AdjointPosOnPhysVolGenerator::GetInstance
();
65
66
}
68
//
69
G4AdjointPrimaryGenerator::~G4AdjointPrimaryGenerator
()
70
{
71
delete
theSingleParticleSource
;
72
}
74
//
75
void
G4AdjointPrimaryGenerator::GenerateAdjointPrimaryVertex
(
G4Event
* anEvent,
G4ParticleDefinition
* adj_part,
G4double
E1,
G4double
E2)
76
{
77
if
(
type_of_adjoint_source
==
"ExternalSurfaceOfAVolume"
) {
78
79
//Generate position and direction relative to the external surface of sensitive volume
80
//-------------------------------------------------------------
81
82
G4double
costh_to_normal=1.;
83
G4ThreeVector
pos
=
G4ThreeVector
(0.,0.,0.);
84
G4ThreeVector
direction =
G4ThreeVector
(0.,0.,1.);
85
theG4AdjointPosOnPhysVolGenerator
->
GenerateAPositionOnTheExtSurfaceOfThePhysicalVolume
(pos, direction,costh_to_normal);
86
if
(costh_to_normal <1.
e
-4) costh_to_normal =1.e-4;
87
//compute now the position along the ray backward direction
88
89
theSingleParticleSource
->
GetAngDist
()->
SetParticleMomentumDirection
(-direction);
90
theSingleParticleSource
->
GetPosDist
()->
SetCentreCoords
(pos);
91
}
92
93
theSingleParticleSource
->
GetEneDist
()->
SetEmin
(E1);
94
theSingleParticleSource
->
GetEneDist
()->
SetEmax
(E2);
95
96
theSingleParticleSource
->
SetParticleDefinition
(adj_part);
97
theSingleParticleSource
->
GeneratePrimaryVertex
(anEvent);
98
99
100
101
}
103
//
104
void
G4AdjointPrimaryGenerator::GenerateFwdPrimaryVertex
(
G4Event
* anEvent,
G4ParticleDefinition
* fwd_part,
G4double
E1,
G4double
E2)
105
{
106
if
(
type_of_adjoint_source
==
"ExternalSurfaceOfAVolume"
) {
107
108
//Generate position and direction relative to the external surface of sensitive volume
109
//-------------------------------------------------------------
110
111
G4double
costh_to_normal=1.;
112
G4ThreeVector
pos
=
G4ThreeVector
(0.,0.,0.);
113
G4ThreeVector
direction =
G4ThreeVector
(0.,0.,1.);
114
theG4AdjointPosOnPhysVolGenerator
->
GenerateAPositionOnTheExtSurfaceOfThePhysicalVolume
(pos, direction,costh_to_normal);
115
if
(costh_to_normal <1.
e
-4) costh_to_normal =1.e-4;
116
theSingleParticleSource
->
GetAngDist
()->
SetParticleMomentumDirection
(direction);
117
theSingleParticleSource
->
GetPosDist
()->
SetCentreCoords
(pos);
118
}
119
120
theSingleParticleSource
->
GetEneDist
()->
SetEmin
(E1);
121
theSingleParticleSource
->
GetEneDist
()->
SetEmax
(E2);
122
123
theSingleParticleSource
->
SetParticleDefinition
(fwd_part);
124
theSingleParticleSource
->
GeneratePrimaryVertex
(anEvent);
125
}
127
//
128
void
G4AdjointPrimaryGenerator::SetSphericalAdjointPrimarySource
(
G4double
radius
,
G4ThreeVector
center_pos)
129
{
130
radius_spherical_source
=
radius
;
131
center_spherical_source
= center_pos;
132
type_of_adjoint_source
=
"Spherical"
;
133
theSingleParticleSource
->
GetPosDist
()->
SetPosDisType
(
"Surface"
);
134
theSingleParticleSource
->
GetPosDist
()->
SetPosDisShape
(
"Sphere"
);
135
theSingleParticleSource
->
GetPosDist
()->
SetCentreCoords
(center_pos);
136
theSingleParticleSource
->
GetPosDist
()->
SetRadius
(radius);
137
theSingleParticleSource
->
GetAngDist
()->
SetAngDistType
(
"cos"
);
138
theSingleParticleSource
->
GetAngDist
()->
SetMaxTheta
(
pi
);
139
theSingleParticleSource
->
GetAngDist
()->
SetMinTheta
(
halfpi
);
140
}
142
//
143
void
G4AdjointPrimaryGenerator::SetAdjointPrimarySourceOnAnExtSurfaceOfAVolume
(
const
G4String
& volume_name)
144
{
145
theG4AdjointPosOnPhysVolGenerator
->
DefinePhysicalVolume1
(volume_name);
146
type_of_adjoint_source
=
"ExternalSurfaceOfAVolume"
;
147
theSingleParticleSource
->
GetPosDist
()->
SetPosDisType
(
"Point"
);
148
theSingleParticleSource
->
GetAngDist
()->
SetAngDistType
(
"planar"
);
149
}
150
152
//
153
void
G4AdjointPrimaryGenerator::ComputeAccumulatedDepthVectorAlongBackRay
(
154
G4ThreeVector
glob_pos,
155
G4ThreeVector
direction,
156
G4double
,
157
G4ParticleDefinition
*)
158
{
if
(!
fLinearNavigator
)
fLinearNavigator
=
159
G4TransportationManager::GetTransportationManager
()
160
->
GetNavigatorForTracking
();
161
G4ThreeVector
position
= glob_pos;
162
G4double
safety=1.;
163
G4VPhysicalVolume
* thePhysVolume =
164
fLinearNavigator
->
LocateGlobalPointAndSetup
(position);
165
G4double
newStep =
fLinearNavigator
->
ComputeStep
(position,direction,1.e50,
166
safety);
167
if
(
theAccumulatedDepthVector
)
delete
theAccumulatedDepthVector
;
168
theAccumulatedDepthVector
=
new
G4PhysicsOrderedFreeVector
();
169
//if (theAccumulatedCSDepthVector) delete theAccumulatedCSDepthVector;
170
//theAccumulatedCSDepthVector = new G4PhysicsOrderedFreeVector();
171
172
G4double
acc_depth=0.;
173
G4double
acc_length=0.;
174
//G4double acc_cs_depth=0.;
175
//theAccumulatedCSDepthVector->InsertValues(acc_cs_depth, acc_length);
176
theAccumulatedDepthVector
->
InsertValues
(acc_length,acc_depth);
177
178
while
(newStep > 0. && thePhysVolume) {
179
acc_length+=newStep;
180
/*
181
const G4MaterialCutsCouple* theMatCutsCouple=
182
thePhysVolume->GetLogicalVolume()->GetMaterialCutsCouple();
183
184
185
acc_cs_depth+=newStep*G4AdjointCSManager::GetAdjointCSManager()->GetTotalAdjointCS(aPartDef,
186
ekin,
187
theMatCutsCouple);
188
theAccumulatedCSDepthVector->InsertValues(acc_cs_depth, acc_length);*/
189
190
acc_depth+=newStep*thePhysVolume->
GetLogicalVolume
()->
GetMaterial
()->
GetDensity
();
191
theAccumulatedDepthVector
->
InsertValues
(acc_length,acc_depth);
192
position=position+newStep*direction;
193
thePhysVolume =
194
fLinearNavigator
->
LocateGlobalPointAndSetup
(position,0,
false
);
195
newStep =
fLinearNavigator
->
ComputeStep
(position,direction,1.e50,
196
safety);
197
}
198
199
200
}
202
//
203
G4double
G4AdjointPrimaryGenerator::SampleDistanceAlongBackRayAndComputeWeightCorrection
(
G4double
& weight_corr)
204
{
G4double
rand =
G4UniformRand
();
205
G4double
distance =
theAccumulatedDepthVector
->
FindLinearEnergy
(rand);
206
/*
207
G4double acc_cs_depth=theAccumulatedCSDepthVector->GetEnergy(distance);
208
weight_corr=std::exp(-acc_cs_depth);*/
209
weight_corr=1.;
210
return
distance;
211
}
212
213
214
215
geant4
tree
geant4-10.6-release
source
event
src
G4AdjointPrimaryGenerator.cc
Built by
Jin Huang
. updated:
Wed Jun 29 2022 17:25:13
using
1.8.2 with
ECCE GitHub integration