Geant4 11.2.2
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4ImportanceProcess.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// G4ImportanceProcess
27//
28// Author: Michael Dressel, 2002
29// --------------------------------------------------------------------
30
33#include "G4GeometryCell.hh"
35#include "G4VTrackTerminator.hh"
36#include "G4VIStore.hh"
37
38#include "G4Step.hh"
39#include "G4Navigator.hh"
40#include "G4VTouchable.hh"
41#include "G4VPhysicalVolume.hh"
42#include "G4ParticleChange.hh"
43#include "G4PathFinder.hh"
45#include "G4StepPoint.hh"
47
48
50G4ImportanceProcess(const G4VImportanceAlgorithm &aImportanceAlgorithm,
51 const G4VIStore &aIstore,
52 const G4VTrackTerminator *TrackTerminator,
53 const G4String &aName, G4bool para)
54 : G4VProcess(aName, fParallel),
55 fParticleChange(new G4ParticleChange),
56 fImportanceAlgorithm(aImportanceAlgorithm),
57 fIStore(aIstore),
58 fParaflag(para)
59{
60 G4cout << "### G4ImportanceProcess:: Creating " << G4endl;
61 if (TrackTerminator != nullptr)
62 {
63 fPostStepAction = new G4SamplingPostStepAction(*TrackTerminator);
64 }
65 else
66 {
67 fPostStepAction = new G4SamplingPostStepAction(*this);
68 }
69 if (fParticleChange == nullptr)
70 {
71 G4Exception("G4ImportanceProcess::G4ImportanceProcess()",
72 "FatalError", FatalException,
73 "Failed allocation of G4ParticleChange !");
74 }
75 G4VProcess::pParticleChange = fParticleChange;
76
77
78 fGhostStep = new G4Step();
79 fGhostPreStepPoint = fGhostStep->GetPreStepPoint();
80 fGhostPostStepPoint = fGhostStep->GetPostStepPoint();
81
83 fPathFinder = G4PathFinder::GetInstance();
84
85 if (verboseLevel>0)
86 {
87 G4cout << GetProcessName() << " is created " << G4endl;
88 }
89
90 G4cout << "G4ImportanceProcess:: importance process paraflag is: " << fParaflag << G4endl;
91
92}
93
95{
96
97 delete fPostStepAction;
98 delete fParticleChange;
99 // delete fGhostStep;
100 // delete fGhostWorld;
101 // delete fGhostNavigator;
102
103}
104
105
106
107//------------------------------------------------------
108//
109// SetParallelWorld
110//
111//------------------------------------------------------
113SetParallelWorld(const G4String &parallelWorldName)
114{
115 G4cout << G4endl << G4endl << G4endl;
116 G4cout << "G4ImportanceProcess:: SetParallelWorld name = " << parallelWorldName << G4endl;
117//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
118// Get pointers of the parallel world and its navigator
119//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
120 fGhostWorldName = parallelWorldName;
121 fGhostWorld = fTransportationManager->GetParallelWorld(fGhostWorldName);
122 fGhostNavigator = fTransportationManager->GetNavigator(fGhostWorld);
123//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
124}
125
126// void G4ImportanceProcess::
127// SetParallelWorld(const G4VPhysicalVolume* parallelWorld)
128// {
129// //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
130// // Get pointer of navigator
131// //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
132// // G4cout << " G4ImportanceProcess:: Got here 1 " << G4endl;
133// // fGhostWorldName = parallelWorld->GetName();
134// // G4cout << " G4ImportanceProcess:: Got here 2 ghostName:" << fGhostWorldName << G4endl;
135// fGhostWorld = parallelWorld;
136// G4cout << " G4ImportanceProcess:: Got here 3 " << G4endl;
137// fGhostNavigator = fTransportationManager->GetNavigator(parallelWorld);
138// G4cout << " G4ImportanceProcess:: Got here 4 " << G4endl;
139// //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
140// }
141
142//------------------------------------------------------
143//
144// StartTracking
145//
146//------------------------------------------------------
148{
149//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
150// Activate navigator and get the navigator ID
151//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
152// G4cout << " G4ParallelWorldScoringProcess::StartTracking" << G4endl;
153
154 if(fParaflag) {
155 if(fGhostNavigator != nullptr)
156 { fNavigatorID = fTransportationManager->ActivateNavigator(fGhostNavigator); }
157 else
158 {
159 G4Exception("G4ImportanceProcess::StartTracking",
160 "ProcParaWorld000",FatalException,
161 "G4ImportanceProcess is used for tracking without having a parallel world assigned");
162 }
163//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
164
165// G4cout << "G4ParallelWorldScoringProcess::StartTracking <<<<<<<<<<<<<<<<<< " << G4endl;
166//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
167// Let PathFinder initialize
168//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
169 fPathFinder->PrepareNewTrack(trk->GetPosition(),trk->GetMomentumDirection());
170//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
171
172//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
173// Setup initial touchables for the first step
174//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
175 fOldGhostTouchable = fPathFinder->CreateTouchableHandle(fNavigatorID);
176 fGhostPreStepPoint->SetTouchableHandle(fOldGhostTouchable);
177 fNewGhostTouchable = fOldGhostTouchable;
178 fGhostPostStepPoint->SetTouchableHandle(fNewGhostTouchable);
179
180 // Initialize
181 fGhostSafety = -1.;
182 fOnBoundary = false;
183 }
184
185}
186
187
190 G4double ,
192{
193// *condition = Forced;
194// return kInfinity;
195
196// *condition = StronglyForced;
197 *condition = Forced;
198 return DBL_MAX;
199}
200
203 const G4Step &aStep)
204{
205 fParticleChange->Initialize(aTrack);
206
207 if(aTrack.GetNextVolume() == nullptr) {
208 return fParticleChange;
209 }
210
211 if(fParaflag) {
212 fOldGhostTouchable = fGhostPostStepPoint->GetTouchableHandle();
213 //xbug? fOnBoundary = false;
214 CopyStep(aStep);
215
216 if(fOnBoundary)
217 {
218//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
219// Locate the point and get new touchable
220//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
221 //?? fPathFinder->Locate(step.GetPostStepPoint()->GetPosition(),
222 //?? step.GetPostStepPoint()->GetMomentumDirection());
223 fNewGhostTouchable = fPathFinder->CreateTouchableHandle(fNavigatorID);
224 //AH G4cout << " on boundary " << G4endl;
225//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
226 }
227 else
228 {
229 // Do I need this ??????????????????????????????????????????????????????????
230 // fGhostNavigator->LocateGlobalPointWithinVolume(track.GetPosition());
231 // ?????????????????????????????????????????????????????????????????????????
232
233 // fPathFinder->ReLocate(track.GetPosition());
234
235 // reuse the touchable
236 fNewGhostTouchable = fOldGhostTouchable;
237 //AH G4cout << " NOT on boundary " << G4endl;
238 }
239
240 fGhostPreStepPoint->SetTouchableHandle(fOldGhostTouchable);
241 fGhostPostStepPoint->SetTouchableHandle(fNewGhostTouchable);
242
243// if ( (aStep.GetPostStepPoint()->GetStepStatus() == fGeomBoundary)
244// && (aStep.GetStepLength() > kCarTolerance) )
245// {
246// if (aTrack.GetTrackStatus()==fStopAndKill)
247// {
248// G4cout << "WARNING - G4ImportanceProcess::PostStepDoIt()"
249// << " StopAndKill track." << G4endl;
250// }
251
252// G4StepPoint *prepoint = aStep.GetPreStepPoint();
253// G4StepPoint *postpoint = aStep.GetPostStepPoint();
254// G4GeometryCell prekey(*(prepoint->GetPhysicalVolume()),
255// prepoint->GetTouchable()->GetReplicaNumber());
256// G4GeometryCell postkey(*(postpoint->GetPhysicalVolume()),
257// postpoint->GetTouchable()->GetReplicaNumber());
258
259
260 if ( (fGhostPostStepPoint->GetStepStatus() == fGeomBoundary)
261 && (aStep.GetStepLength() > kCarTolerance) )
262 {
263 if (aTrack.GetTrackStatus()==fStopAndKill)
264 {
265 G4cout << "WARNING - G4ImportanceProcess::PostStepDoIt()"
266 << " StopAndKill track. on boundary" << G4endl;
267 }
268
269 G4GeometryCell prekey(*(fGhostPreStepPoint->GetPhysicalVolume()),
270 fGhostPreStepPoint->GetTouchable()->GetReplicaNumber());
271 G4GeometryCell postkey(*(fGhostPostStepPoint->GetPhysicalVolume()),
272 fGhostPostStepPoint->GetTouchable()->GetReplicaNumber());
273
274 //AH
275 /*
276 G4cout << G4endl;
277 G4cout << G4endl;
278 G4cout << " inside parallel importance process " << aTrack.GetCurrentStepNumber() << G4endl;
279 G4cout << G4endl;
280 G4cout << G4endl;
281 G4cout << " prekey: " << fGhostPreStepPoint->GetPhysicalVolume()->GetName() << " replica:"
282 << fGhostPreStepPoint->GetTouchable()->GetReplicaNumber() << G4endl;
283 G4cout << " prekey ISTORE: " << fIStore.GetImportance(prekey) << G4endl;
284 G4cout << " postkey: " << G4endl;
285 G4cout << " postkey ISTORE: " << fIStore.GetImportance(postkey) << G4endl;
286 */
287 //AH
288 G4Nsplit_Weight nw = fImportanceAlgorithm.
289 Calculate(fIStore.GetImportance(prekey),
290 fIStore.GetImportance(postkey),
291 aTrack.GetWeight());
292 //AH
293 /*
294 G4cout << " prekey weight: " << fIStore.GetImportance(prekey)
295 << " postkey weight: " << fIStore.GetImportance(postkey)
296 << " split weight: " << nw << G4endl;
297 G4cout << " before poststepaction " << G4endl;
298 */
299 //AH
300 fPostStepAction->DoIt(aTrack, fParticleChange, nw);
301 //AH G4cout << " after post step do it " << G4endl;
302 }
303 } else {
304 if ( (aStep.GetPostStepPoint()->GetStepStatus() == fGeomBoundary)
305 && (aStep.GetStepLength() > kCarTolerance) )
306 {
307 //AH G4cout << " inside non-parallel importance process " << G4endl;
308 if (aTrack.GetTrackStatus()==fStopAndKill)
309 {
310 G4cout << "WARNING - G4ImportanceProcess::PostStepDoIt()"
311 << " StopAndKill track. on boundary non-parallel" << G4endl;
312 }
313
314 G4StepPoint *prepoint = aStep.GetPreStepPoint();
315 G4StepPoint *postpoint = aStep.GetPostStepPoint();
316
317 G4GeometryCell prekey(*(prepoint->GetPhysicalVolume()),
318 prepoint->GetTouchable()->GetReplicaNumber());
319 G4GeometryCell postkey(*(postpoint->GetPhysicalVolume()),
320 postpoint->GetTouchable()->GetReplicaNumber());
321
322 G4Nsplit_Weight nw = fImportanceAlgorithm.
323 Calculate(fIStore.GetImportance(prekey),
324 fIStore.GetImportance(postkey),
325 aTrack.GetWeight());
326 //AH
327 /*
328 G4cout << " prekey weight: " << fIStore.GetImportance(prekey)
329 << " postkey weight: " << fIStore.GetImportance(postkey)
330 << " split weight: " << nw << G4endl;
331 G4cout << " before poststepaction 2 " << G4endl;
332 */
333 //AH
334 fPostStepAction->DoIt(aTrack, fParticleChange, nw);
335 //AH G4cout << " after poststepaction 2 " << G4endl;
336 }
337 }
338 return fParticleChange;
339}
340
342{
343 fParticleChange->ProposeTrackStatus(fStopAndKill);
344}
345
347{
348 return theProcessName;
349}
350
353 const G4Track& track, G4double previousStepSize, G4double currentMinimumStep,
354 G4double& proposedSafety, G4GPILSelection* selection)
355{
356 if(fParaflag) {
357 *selection = NotCandidateForSelection;
358 G4double returnedStep = DBL_MAX;
359
360 if (previousStepSize > 0.)
361 { fGhostSafety -= previousStepSize; }
362 // else
363 // { fGhostSafety = -1.; }
364 if (fGhostSafety < 0.) fGhostSafety = 0.0;
365
366 // ------------------------------------------
367 // Determination of the proposed STEP LENGTH:
368 // ------------------------------------------
369 if (currentMinimumStep <= fGhostSafety && currentMinimumStep > 0.)
370 {
371 // I have no chance to limit
372 returnedStep = currentMinimumStep;
373 fOnBoundary = false;
374 proposedSafety = fGhostSafety - currentMinimumStep;
375 //AH G4cout << " step not limited, why? " << G4endl;
376 }
377 else // (currentMinimumStep > fGhostSafety: I may limit the Step)
378 {
379 G4FieldTrackUpdator::Update(&fFieldTrack,&track);
380 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
381 // ComputeStep
382 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
383 returnedStep
384 = fPathFinder->ComputeStep(fFieldTrack,currentMinimumStep,fNavigatorID,
385 track.GetCurrentStepNumber(),fGhostSafety,feLimited,
386 fEndTrack,track.GetVolume());
387 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
388 if(feLimited == kDoNot)
389 {
390 //AH G4cout << " computestep came back with not-boundary " << G4endl;
391 // Track is not on the boundary
392 fOnBoundary = false;
393 fGhostSafety = fGhostNavigator->ComputeSafety(fEndTrack.GetPosition());
394 }
395 else
396 {
397 // Track is on the boundary
398 //AH G4cout << " FOUND A BOUNDARY ! " << track.GetCurrentStepNumber() << G4endl;
399 fOnBoundary = true;
400 // proposedSafety = fGhostSafety;
401 }
402 proposedSafety = fGhostSafety;
403 if(feLimited == kUnique || feLimited == kSharedOther) {
404 *selection = CandidateForSelection;
405 }else if (feLimited == kSharedTransport) {
406 returnedStep *= (1.0 + 1.0e-9);
407 // Expand to disable its selection in Step Manager comparison
408 }
409
410 }
411
412 // ----------------------------------------------
413 // Returns the fGhostSafety as the proposedSafety
414 // The SteppingManager will take care of keeping
415 // the smallest one.
416 // ----------------------------------------------
417 return returnedStep;
418
419 } else {
420
421 return DBL_MAX;
422
423 }
424
425}
426
433
435AtRestDoIt(const G4Track&, const G4Step&)
436{
437 return nullptr;
438}
439
441AlongStepDoIt(const G4Track& aTrack, const G4Step& )
442{
443 // Dummy ParticleChange ie: does nothing
444 // Expecting G4Transportation to move the track
445 //AH G4cout << " along step do it " << G4endl;
447 return pParticleChange;
448}
449
450void G4ImportanceProcess::CopyStep(const G4Step & step)
451{
452 fGhostStep->SetTrack(step.GetTrack());
453 fGhostStep->SetStepLength(step.GetStepLength());
455 fGhostStep->SetControlFlag(step.GetControlFlag());
456
457 *fGhostPreStepPoint = *(step.GetPreStepPoint());
458 *fGhostPostStepPoint = *(step.GetPostStepPoint());
459
460//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
461// Set StepStatus for ghost world
462//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
463 if(fOnBoundary)
464 { fGhostPostStepPoint->SetStepStatus(fGeomBoundary); }
465 else if(fGhostPostStepPoint->GetStepStatus()==fGeomBoundary)
466 { fGhostPostStepPoint->SetStepStatus(fPostStepDoItProc); }
467//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
468}
G4double condition(const G4ErrorSymMatrix &m)
@ FatalException
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
G4ForceCondition
@ Forced
G4GPILSelection
@ CandidateForSelection
@ NotCandidateForSelection
@ kDoNot
@ kUnique
@ kSharedOther
@ kSharedTransport
@ fParallel
@ fGeomBoundary
@ fPostStepDoItProc
@ fStopAndKill
double G4double
Definition G4Types.hh:83
bool G4bool
Definition G4Types.hh:86
#define G4endl
Definition G4ios.hh:67
G4GLOB_DLL std::ostream G4cout
static void Update(G4FieldTrack *, const G4Track *)
G4ThreeVector GetPosition() const
virtual G4VParticleChange * AlongStepDoIt(const G4Track &, const G4Step &)
virtual G4VParticleChange * AtRestDoIt(const G4Track &, const G4Step &)
void SetParallelWorld(const G4String &parallelWorldName)
virtual void KillTrack() const
virtual G4double AlongStepGetPhysicalInteractionLength(const G4Track &, G4double, G4double, G4double &, G4GPILSelection *)
virtual G4VParticleChange * PostStepDoIt(const G4Track &, const G4Step &)
virtual G4double PostStepGetPhysicalInteractionLength(const G4Track &aTrack, G4double previousStepSize, G4ForceCondition *condition)
G4ImportanceProcess(const G4VImportanceAlgorithm &aImportanceAlgorithm, const G4VIStore &aIstore, const G4VTrackTerminator *TrackTerminator, const G4String &aName="ImportanceProcess", G4bool para=false)
void StartTracking(G4Track *)
virtual G4double AtRestGetPhysicalInteractionLength(const G4Track &, G4ForceCondition *)
virtual const G4String & GetName() const
virtual G4double ComputeSafety(const G4ThreeVector &globalpoint, const G4double pProposedMaxLength=DBL_MAX, const G4bool keepState=true)
void Initialize(const G4Track &) override
G4double ComputeStep(const G4FieldTrack &pFieldTrack, G4double pCurrentProposedStepLength, G4int navigatorId, G4int stepNo, G4double &pNewSafety, ELimited &limitedStep, G4FieldTrack &EndState, G4VPhysicalVolume *currentVolume)
void PrepareNewTrack(const G4ThreeVector &position, const G4ThreeVector &direction, G4VPhysicalVolume *massStartVol=nullptr)
static G4PathFinder * GetInstance()
G4TouchableHandle CreateTouchableHandle(G4int navId) const
void DoIt(const G4Track &aTrack, G4ParticleChange *aParticleChange, const G4Nsplit_Weight &nw)
G4StepStatus GetStepStatus() const
const G4VTouchable * GetTouchable() const
void SetStepStatus(const G4StepStatus aValue)
void SetTouchableHandle(const G4TouchableHandle &apValue)
const G4TouchableHandle & GetTouchableHandle() const
G4VPhysicalVolume * GetPhysicalVolume() const
G4SteppingControl GetControlFlag() const
G4Track * GetTrack() const
void SetStepLength(G4double value)
G4StepPoint * GetPreStepPoint() const
G4double GetStepLength() const
G4double GetTotalEnergyDeposit() const
void SetControlFlag(G4SteppingControl StepControlFlag)
void SetTotalEnergyDeposit(G4double value)
G4StepPoint * GetPostStepPoint() const
void SetTrack(G4Track *value)
virtual G4int GetReplicaNumber(G4int depth=0) const
G4TrackStatus GetTrackStatus() const
G4VPhysicalVolume * GetVolume() const
G4VPhysicalVolume * GetNextVolume() const
G4double GetWeight() const
const G4ThreeVector & GetPosition() const
G4int GetCurrentStepNumber() const
const G4ThreeVector & GetMomentumDirection() const
G4VPhysicalVolume * GetParallelWorld(const G4String &worldName)
static G4TransportationManager * GetTransportationManager()
G4int ActivateNavigator(G4Navigator *aNavigator)
G4Navigator * GetNavigator(const G4String &worldName)
virtual G4double GetImportance(const G4GeometryCell &gCell) const =0
void ProposeTrackStatus(G4TrackStatus status)
virtual void Initialize(const G4Track &)
G4int verboseLevel
G4String theProcessName
G4VParticleChange * pParticleChange
const G4String & GetProcessName() const
#define DBL_MAX
Definition templates.hh:62