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