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
G4WeightCutOffProcess.cc
Go to the documentation of this file.
Or view
the newest version in sPHENIX GitHub for file G4WeightCutOffProcess.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
//
27
//
28
// ----------------------------------------------------------------------
29
// GEANT 4 class source file
30
//
31
// G4WeightCutOffProcess.cc
32
//
33
// ----------------------------------------------------------------------
34
35
#include "
G4WeightCutOffProcess.hh
"
36
//#include "G4VScorer.hh"
37
#include "
G4GeometryCellStep.hh
"
38
//#include "G4GCellFinder.hh"
39
#include "
G4TouchableHandle.hh
"
40
#include "
G4VIStore.hh
"
41
42
#include "
G4Step.hh
"
43
#include "
G4Navigator.hh
"
44
#include "
G4VTouchable.hh
"
45
#include "
G4VPhysicalVolume.hh
"
46
#include "
G4ParticleChange.hh
"
47
#include "
G4PathFinder.hh
"
48
#include "
G4TransportationManager.hh
"
49
#include "
G4StepPoint.hh
"
50
#include "
G4FieldTrackUpdator.hh
"
51
52
53
G4WeightCutOffProcess::
54
G4WeightCutOffProcess
(
G4double
wsurvival,
55
G4double
wlimit,
56
G4double
isource,
57
G4VIStore
*istore,
58
// const G4VGCellFinder &aGCellFinder,
59
const
G4String
&aName,
G4bool
para)
60
:
G4VProcess
(aName),
61
fParticleChange(new
G4ParticleChange
),
62
fWeightSurvival(wsurvival),
63
fWeightLimit(wlimit),
64
fSourceImportance(isource),
65
fIStore(istore),
66
// fGCellFinder(aGCellFinder),
67
fGhostWorldName(
"NoParallelWorld"
), fGhostWorld(0),
68
fGhostNavigator(0), fNavigatorID(-1), fFieldTrack(
'0'
),
69
fParaflag(para), fEndTrack(
'0'
), feLimited(
kDoNot
)
70
{
71
if
(!
fParticleChange
)
72
{
73
G4Exception
(
"G4WeightCutOffProcess::G4WeightCutOffProcess()"
,
74
"FatalError"
,
FatalException
,
75
"Failed to allocate G4ParticleChange !"
);
76
}
77
78
G4VProcess::pParticleChange
=
fParticleChange
;
79
80
fGhostStep
=
new
G4Step
();
81
fGhostPreStepPoint
=
fGhostStep
->
GetPreStepPoint
();
82
fGhostPostStepPoint
=
fGhostStep
->
GetPostStepPoint
();
83
84
fTransportationManager
=
G4TransportationManager::GetTransportationManager
();
85
fPathFinder
=
G4PathFinder::GetInstance
();
86
87
if
(
verboseLevel
>0)
88
{
89
G4cout
<<
GetProcessName
() <<
" is created "
<<
G4endl
;
90
}
91
}
92
93
G4WeightCutOffProcess::~G4WeightCutOffProcess
()
94
{
95
delete
fParticleChange
;
96
// delete fGhostStep;
97
}
98
99
100
//------------------------------------------------------
101
//
102
// SetParallelWorld
103
//
104
//------------------------------------------------------
105
void
G4WeightCutOffProcess::
106
SetParallelWorld
(
const
G4String
¶llelWorldName)
107
{
108
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
109
// Get pointers of the parallel world and its navigator
110
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
111
fGhostWorldName
= parallelWorldName;
112
fGhostWorld
=
fTransportationManager
->
GetParallelWorld
(
fGhostWorldName
);
113
fGhostNavigator
=
fTransportationManager
->
GetNavigator
(
fGhostWorld
);
114
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
115
}
116
117
void
G4WeightCutOffProcess::
118
SetParallelWorld
(
G4VPhysicalVolume
* parallelWorld)
119
{
120
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
121
// Get pointer of navigator
122
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
123
fGhostWorldName
= parallelWorld->
GetName
();
124
fGhostWorld
= parallelWorld;
125
fGhostNavigator
=
fTransportationManager
->
GetNavigator
(
fGhostWorld
);
126
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
127
}
128
129
//------------------------------------------------------
130
//
131
// StartTracking
132
//
133
//------------------------------------------------------
134
void
G4WeightCutOffProcess::StartTracking
(
G4Track
* trk)
135
{
136
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
137
// Activate navigator and get the navigator ID
138
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
139
// G4cout << " G4ParallelWorldScoringProcess::StartTracking" << G4endl;
140
141
if
(
fParaflag
) {
142
if
(
fGhostNavigator
)
143
{
fNavigatorID
=
fTransportationManager
->
ActivateNavigator
(
fGhostNavigator
); }
144
else
145
{
146
G4Exception
(
"G4WeightCutOffProcess::StartTracking"
,
147
"ProcParaWorld000"
,
FatalException
,
148
"G4WeightCutOffProcess is used for tracking without having a parallel world assigned"
);
149
}
150
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
151
152
// G4cout << "G4ParallelWorldScoringProcess::StartTracking <<<<<<<<<<<<<<<<<< " << G4endl;
153
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
154
// Let PathFinder initialize
155
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
156
fPathFinder
->
PrepareNewTrack
(trk->
GetPosition
(),trk->
GetMomentumDirection
());
157
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
158
159
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
160
// Setup initial touchables for the first step
161
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
162
fOldGhostTouchable
=
fPathFinder
->
CreateTouchableHandle
(
fNavigatorID
);
163
fGhostPreStepPoint
->
SetTouchableHandle
(
fOldGhostTouchable
);
164
fNewGhostTouchable
=
fOldGhostTouchable
;
165
fGhostPostStepPoint
->
SetTouchableHandle
(
fNewGhostTouchable
);
166
167
// Initialize
168
fGhostSafety
= -1.;
169
fOnBoundary
=
false
;
170
}
171
}
172
173
174
G4double
G4WeightCutOffProcess::
175
PostStepGetPhysicalInteractionLength
(
const
G4Track
&,
176
G4double
,
G4ForceCondition
*
condition
)
177
{
178
// *condition = Forced;
179
// return kInfinity;
180
181
// *condition = StronglyForced;
182
*condition =
Forced
;
183
return
DBL_MAX
;
184
}
185
186
G4VParticleChange
*
187
G4WeightCutOffProcess::PostStepDoIt
(
const
G4Track
& aTrack,
188
const
G4Step
&aStep)
189
{
190
fParticleChange
->
Initialize
(aTrack);
191
192
if
(
fParaflag
) {
193
fOldGhostTouchable
=
fGhostPostStepPoint
->
GetTouchableHandle
();
194
//xbug? fOnBoundary = false;
195
CopyStep
(aStep);
196
197
if
(
fOnBoundary
)
198
{
199
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
200
// Locate the point and get new touchable
201
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
202
//?? fPathFinder->Locate(step.GetPostStepPoint()->GetPosition(),
203
//?? step.GetPostStepPoint()->GetMomentumDirection());
204
fNewGhostTouchable
=
fPathFinder
->
CreateTouchableHandle
(
fNavigatorID
);
205
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
206
}
207
else
208
{
209
// Do I need this ??????????????????????????????????????????????????????????
210
// fGhostNavigator->LocateGlobalPointWithinVolume(track.GetPosition());
211
// ?????????????????????????????????????????????????????????????????????????
212
213
// fPathFinder->ReLocate(track.GetPosition());
214
215
// reuse the touchable
216
fNewGhostTouchable
=
fOldGhostTouchable
;
217
}
218
219
fGhostPreStepPoint
->
SetTouchableHandle
(
fOldGhostTouchable
);
220
fGhostPostStepPoint
->
SetTouchableHandle
(
fNewGhostTouchable
);
221
222
}
223
224
if
(
fParaflag
) {
225
G4GeometryCell
postCell(*(
fGhostPostStepPoint
->
GetPhysicalVolume
()),
226
fGhostPostStepPoint
->
GetTouchable
()->
GetReplicaNumber
());
227
228
229
// G4GeometryCell postCell = fGCellFinder.GetPostGeometryCell(aStep);
230
// G4GeometryCell postCell = fGCellFinder.GetPostGeometryCell(fGhostStep);
231
G4double
R
=
fSourceImportance
;
232
if
(
fIStore
)
233
{
234
G4double
i =
fIStore
->
GetImportance
(postCell);
235
if
(i>0)
236
{
237
R/=i;
238
}
239
}
240
G4double
w
= aTrack.
GetWeight
();
241
if
(w<R*
fWeightLimit
)
242
{
243
G4double
ws =
fWeightSurvival
*
R
;
244
G4double
p
= w/(ws);
245
if
(
G4UniformRand
()<
p
)
246
{
247
fParticleChange
->
ProposeTrackStatus
(
fStopAndKill
);
248
}
249
else
250
{
251
fParticleChange
->
ProposeWeight
(ws);
252
}
253
}
254
}
else
{
255
256
G4GeometryCell
postCell(*(aStep.
GetPostStepPoint
()->
GetPhysicalVolume
()),
257
aStep.
GetPostStepPoint
()->
GetTouchable
()->
GetReplicaNumber
());
258
259
// G4GeometryCell postCell = fGCellFinder.GetPostGeometryCell(aStep);
260
// G4GeometryCell postCell = fGCellFinder.GetPostGeometryCell(fGhostStep);
261
G4double
R
=
fSourceImportance
;
262
if
(
fIStore
)
263
{
264
G4double
i =
fIStore
->
GetImportance
(postCell);
265
if
(i>0)
266
{
267
R/=i;
268
}
269
}
270
G4double
w
= aTrack.
GetWeight
();
271
if
(w<R*
fWeightLimit
)
272
{
273
G4double
ws =
fWeightSurvival
*
R
;
274
G4double
p
= w/(ws);
275
if
(
G4UniformRand
()<
p
)
276
{
277
fParticleChange
->
ProposeTrackStatus
(
fStopAndKill
);
278
}
279
else
280
{
281
fParticleChange
->
ProposeWeight
(ws);
282
}
283
}
284
}
285
286
return
fParticleChange
;
287
288
}
289
290
const
G4String
&
G4WeightCutOffProcess::GetName
()
const
291
{
292
return
theProcessName
;
293
}
294
295
G4double
G4WeightCutOffProcess::
296
AlongStepGetPhysicalInteractionLength
(
297
const
G4Track
&
track
,
G4double
previousStepSize,
G4double
currentMinimumStep,
298
G4double
& proposedSafety,
G4GPILSelection
* selection)
299
{
300
if
(
fParaflag
) {
301
302
*selection =
NotCandidateForSelection
;
303
G4double
returnedStep =
DBL_MAX
;
304
305
if
(previousStepSize > 0.)
306
{
fGhostSafety
-= previousStepSize; }
307
// else
308
// { fGhostSafety = -1.; }
309
if
(
fGhostSafety
< 0.)
fGhostSafety
= 0.0;
310
311
// ------------------------------------------
312
// Determination of the proposed STEP LENGTH:
313
// ------------------------------------------
314
if
(currentMinimumStep <= fGhostSafety && currentMinimumStep > 0.)
315
{
316
// I have no chance to limit
317
returnedStep = currentMinimumStep;
318
fOnBoundary
=
false
;
319
proposedSafety =
fGhostSafety
- currentMinimumStep;
320
}
321
else
// (currentMinimumStep > fGhostSafety: I may limit the Step)
322
{
323
G4FieldTrackUpdator::Update
(&
fFieldTrack
,&track);
324
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
325
// ComputeStep
326
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
327
returnedStep
328
=
fPathFinder
->
ComputeStep
(
fFieldTrack
,currentMinimumStep,
fNavigatorID
,
329
track.
GetCurrentStepNumber
(),
fGhostSafety
,
feLimited
,
330
fEndTrack
,track.
GetVolume
());
331
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
332
if
(feLimited ==
kDoNot
)
333
{
334
// Track is not on the boundary
335
fOnBoundary
=
false
;
336
fGhostSafety
=
fGhostNavigator
->
ComputeSafety
(fEndTrack.GetPosition());
337
}
338
else
339
{
340
// Track is on the boundary
341
fOnBoundary
=
true
;
342
proposedSafety =
fGhostSafety
;
343
}
344
//xbug? proposedSafety = fGhostSafety;
345
if
(feLimited ==
kUnique
|| feLimited ==
kSharedOther
) {
346
*selection =
CandidateForSelection
;
347
}
else
if
(feLimited ==
kSharedTransport
) {
348
returnedStep *= (1.0 + 1.0e-9);
349
// Expand to disable its selection in Step Manager comparison
350
}
351
352
}
353
354
// ----------------------------------------------
355
// Returns the fGhostSafety as the proposedSafety
356
// The SteppingManager will take care of keeping
357
// the smallest one.
358
// ----------------------------------------------
359
return
returnedStep;
360
361
}
else
{
362
return
DBL_MAX
;
363
//not sensible! return -1.0;
364
}
365
366
}
367
368
369
G4double
G4WeightCutOffProcess::
370
AtRestGetPhysicalInteractionLength
(
const
G4Track
& ,
371
G4ForceCondition
*)
372
{
373
return
-1.0;
374
}
375
376
G4VParticleChange
*
377
G4WeightCutOffProcess::AtRestDoIt
(
const
G4Track
&,
const
G4Step
&)
378
{
379
return
0;
380
}
381
382
G4VParticleChange
*
383
G4WeightCutOffProcess::AlongStepDoIt
(
const
G4Track
&
track
,
const
G4Step
&)
384
{
385
// Dummy ParticleChange ie: does nothing
386
// Expecting G4Transportation to move the track
387
pParticleChange
->
Initialize
(track);
388
return
pParticleChange
;
389
390
// return 0;
391
}
392
393
void
G4WeightCutOffProcess::CopyStep
(
const
G4Step
&
step
)
394
{
395
fGhostStep
->
SetTrack
(step.
GetTrack
());
396
fGhostStep
->
SetStepLength
(step.
GetStepLength
());
397
fGhostStep
->
SetTotalEnergyDeposit
(step.
GetTotalEnergyDeposit
());
398
fGhostStep
->
SetControlFlag
(step.
GetControlFlag
());
399
400
*
fGhostPreStepPoint
= *(step.
GetPreStepPoint
());
401
*
fGhostPostStepPoint
= *(step.
GetPostStepPoint
());
402
403
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
404
// Set StepStatus for ghost world
405
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
406
if
(
fOnBoundary
)
407
{
fGhostPostStepPoint
->
SetStepStatus
(
fGeomBoundary
); }
408
else
if
(
fGhostPostStepPoint
->
GetStepStatus
()==
fGeomBoundary
)
409
{
fGhostPostStepPoint
->
SetStepStatus
(
fPostStepDoItProc
); }
410
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
411
}
geant4
tree
geant4-10.6-release
source
processes
biasing
importance
src
G4WeightCutOffProcess.cc
Built by
Jin Huang
. updated:
Wed Jun 29 2022 17:25:27
using
1.8.2 with
ECCE GitHub integration