Geant4 10.7.0
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(fParaflag) {
208 fOldGhostTouchable = fGhostPostStepPoint->GetTouchableHandle();
209 //xbug? fOnBoundary = false;
210 CopyStep(aStep);
211
212 if(fOnBoundary)
213 {
214//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
215// Locate the point and get new touchable
216//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
217 //?? fPathFinder->Locate(step.GetPostStepPoint()->GetPosition(),
218 //?? step.GetPostStepPoint()->GetMomentumDirection());
219 fNewGhostTouchable = fPathFinder->CreateTouchableHandle(fNavigatorID);
220 //AH G4cout << " on boundary " << G4endl;
221//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
222 }
223 else
224 {
225 // Do I need this ??????????????????????????????????????????????????????????
226 // fGhostNavigator->LocateGlobalPointWithinVolume(track.GetPosition());
227 // ?????????????????????????????????????????????????????????????????????????
228
229 // fPathFinder->ReLocate(track.GetPosition());
230
231 // reuse the touchable
232 fNewGhostTouchable = fOldGhostTouchable;
233 //AH G4cout << " NOT on boundary " << G4endl;
234 }
235
236 fGhostPreStepPoint->SetTouchableHandle(fOldGhostTouchable);
237 fGhostPostStepPoint->SetTouchableHandle(fNewGhostTouchable);
238
239// if ( (aStep.GetPostStepPoint()->GetStepStatus() == fGeomBoundary)
240// && (aStep.GetStepLength() > kCarTolerance) )
241// {
242// if (aTrack.GetTrackStatus()==fStopAndKill)
243// {
244// G4cout << "WARNING - G4ImportanceProcess::PostStepDoIt()"
245// << " StopAndKill track." << G4endl;
246// }
247
248// G4StepPoint *prepoint = aStep.GetPreStepPoint();
249// G4StepPoint *postpoint = aStep.GetPostStepPoint();
250// G4GeometryCell prekey(*(prepoint->GetPhysicalVolume()),
251// prepoint->GetTouchable()->GetReplicaNumber());
252// G4GeometryCell postkey(*(postpoint->GetPhysicalVolume()),
253// postpoint->GetTouchable()->GetReplicaNumber());
254
255
256 if ( (fGhostPostStepPoint->GetStepStatus() == fGeomBoundary)
257 && (aStep.GetStepLength() > kCarTolerance) )
258 {
259 if (aTrack.GetTrackStatus()==fStopAndKill)
260 {
261 G4cout << "WARNING - G4ImportanceProcess::PostStepDoIt()"
262 << " StopAndKill track. on boundary" << G4endl;
263 }
264
265 G4GeometryCell prekey(*(fGhostPreStepPoint->GetPhysicalVolume()),
266 fGhostPreStepPoint->GetTouchable()->GetReplicaNumber());
267 G4GeometryCell postkey(*(fGhostPostStepPoint->GetPhysicalVolume()),
268 fGhostPostStepPoint->GetTouchable()->GetReplicaNumber());
269
270 //AH
271 /*
272 G4cout << G4endl;
273 G4cout << G4endl;
274 G4cout << " inside parallel importance process " << aTrack.GetCurrentStepNumber() << G4endl;
275 G4cout << G4endl;
276 G4cout << G4endl;
277 G4cout << " prekey: " << fGhostPreStepPoint->GetPhysicalVolume()->GetName() << " replica:"
278 << fGhostPreStepPoint->GetTouchable()->GetReplicaNumber() << G4endl;
279 G4cout << " prekey ISTORE: " << fIStore.GetImportance(prekey) << G4endl;
280 G4cout << " postkey: " << G4endl;
281 G4cout << " postkey ISTORE: " << fIStore.GetImportance(postkey) << G4endl;
282 */
283 //AH
284 G4Nsplit_Weight nw = fImportanceAlgorithm.
285 Calculate(fIStore.GetImportance(prekey),
286 fIStore.GetImportance(postkey),
287 aTrack.GetWeight());
288 //AH
289 /*
290 G4cout << " prekey weight: " << fIStore.GetImportance(prekey)
291 << " postkey weight: " << fIStore.GetImportance(postkey)
292 << " split weight: " << nw << G4endl;
293 G4cout << " before poststepaction " << G4endl;
294 */
295 //AH
296 fPostStepAction->DoIt(aTrack, fParticleChange, nw);
297 //AH G4cout << " after post step do it " << G4endl;
298 }
299 } else {
300 if ( (aStep.GetPostStepPoint()->GetStepStatus() == fGeomBoundary)
301 && (aStep.GetStepLength() > kCarTolerance) )
302 {
303 //AH G4cout << " inside non-parallel importance process " << G4endl;
304 if (aTrack.GetTrackStatus()==fStopAndKill)
305 {
306 G4cout << "WARNING - G4ImportanceProcess::PostStepDoIt()"
307 << " StopAndKill track. on boundary non-parallel" << G4endl;
308 }
309
310 G4StepPoint *prepoint = aStep.GetPreStepPoint();
311 G4StepPoint *postpoint = aStep.GetPostStepPoint();
312
313 G4GeometryCell prekey(*(prepoint->GetPhysicalVolume()),
314 prepoint->GetTouchable()->GetReplicaNumber());
315 G4GeometryCell postkey(*(postpoint->GetPhysicalVolume()),
316 postpoint->GetTouchable()->GetReplicaNumber());
317
318 G4Nsplit_Weight nw = fImportanceAlgorithm.
319 Calculate(fIStore.GetImportance(prekey),
320 fIStore.GetImportance(postkey),
321 aTrack.GetWeight());
322 //AH
323 /*
324 G4cout << " prekey weight: " << fIStore.GetImportance(prekey)
325 << " postkey weight: " << fIStore.GetImportance(postkey)
326 << " split weight: " << nw << G4endl;
327 G4cout << " before poststepaction 2 " << G4endl;
328 */
329 //AH
330 fPostStepAction->DoIt(aTrack, fParticleChange, nw);
331 //AH G4cout << " after poststepaction 2 " << G4endl;
332 }
333 }
334 return fParticleChange;
335}
336
338{
339 fParticleChange->ProposeTrackStatus(fStopAndKill);
340}
341
343{
344 return theProcessName;
345}
346
349 const G4Track& track, G4double previousStepSize, G4double currentMinimumStep,
350 G4double& proposedSafety, G4GPILSelection* selection)
351{
352 if(fParaflag) {
353 *selection = NotCandidateForSelection;
354 G4double returnedStep = DBL_MAX;
355
356 if (previousStepSize > 0.)
357 { fGhostSafety -= previousStepSize; }
358 // else
359 // { fGhostSafety = -1.; }
360 if (fGhostSafety < 0.) fGhostSafety = 0.0;
361
362 // ------------------------------------------
363 // Determination of the proposed STEP LENGTH:
364 // ------------------------------------------
365 if (currentMinimumStep <= fGhostSafety && currentMinimumStep > 0.)
366 {
367 // I have no chance to limit
368 returnedStep = currentMinimumStep;
369 fOnBoundary = false;
370 proposedSafety = fGhostSafety - currentMinimumStep;
371 //AH G4cout << " step not limited, why? " << G4endl;
372 }
373 else // (currentMinimumStep > fGhostSafety: I may limit the Step)
374 {
375 G4FieldTrackUpdator::Update(&fFieldTrack,&track);
376 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
377 // ComputeStep
378 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
379 returnedStep
380 = fPathFinder->ComputeStep(fFieldTrack,currentMinimumStep,fNavigatorID,
381 track.GetCurrentStepNumber(),fGhostSafety,feLimited,
382 fEndTrack,track.GetVolume());
383 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
384 if(feLimited == kDoNot)
385 {
386 //AH G4cout << " computestep came back with not-boundary " << G4endl;
387 // Track is not on the boundary
388 fOnBoundary = false;
389 fGhostSafety = fGhostNavigator->ComputeSafety(fEndTrack.GetPosition());
390 }
391 else
392 {
393 // Track is on the boundary
394 //AH G4cout << " FOUND A BOUNDARY ! " << track.GetCurrentStepNumber() << G4endl;
395 fOnBoundary = true;
396 // proposedSafety = fGhostSafety;
397 }
398 proposedSafety = fGhostSafety;
399 if(feLimited == kUnique || feLimited == kSharedOther) {
400 *selection = CandidateForSelection;
401 }else if (feLimited == kSharedTransport) {
402 returnedStep *= (1.0 + 1.0e-9);
403 // Expand to disable its selection in Step Manager comparison
404 }
405
406 }
407
408 // ----------------------------------------------
409 // Returns the fGhostSafety as the proposedSafety
410 // The SteppingManager will take care of keeping
411 // the smallest one.
412 // ----------------------------------------------
413 return returnedStep;
414
415 } else {
416
417 return DBL_MAX;
418
419 }
420
421}
422
426{
427 return -1.0;
428}
429
431AtRestDoIt(const G4Track&, const G4Step&)
432{
433 return nullptr;
434}
435
437AlongStepDoIt(const G4Track& aTrack, const G4Step& )
438{
439 // Dummy ParticleChange ie: does nothing
440 // Expecting G4Transportation to move the track
441 //AH G4cout << " along step do it " << G4endl;
443 return pParticleChange;
444}
445
446void G4ImportanceProcess::CopyStep(const G4Step & step)
447{
448 fGhostStep->SetTrack(step.GetTrack());
449 fGhostStep->SetStepLength(step.GetStepLength());
451 fGhostStep->SetControlFlag(step.GetControlFlag());
452
453 *fGhostPreStepPoint = *(step.GetPreStepPoint());
454 *fGhostPostStepPoint = *(step.GetPostStepPoint());
455
456//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
457// Set StepStatus for ghost world
458//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
459 if(fOnBoundary)
460 { fGhostPostStepPoint->SetStepStatus(fGeomBoundary); }
461 else if(fGhostPostStepPoint->GetStepStatus()==fGeomBoundary)
462 { fGhostPostStepPoint->SetStepStatus(fPostStepDoItProc); }
463//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
464}
G4double condition(const G4ErrorSymMatrix &m)
@ FatalException
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.cc:35
G4ForceCondition
@ Forced
G4GPILSelection
@ CandidateForSelection
@ NotCandidateForSelection
@ kDoNot
@ kUnique
@ kSharedOther
@ kSharedTransport
@ fParallel
@ fGeomBoundary
Definition: G4StepStatus.hh:43
@ fPostStepDoItProc
Definition: G4StepStatus.hh:49
@ fStopAndKill
double G4double
Definition: G4Types.hh:83
bool G4bool
Definition: G4Types.hh:86
#define G4endl
Definition: G4ios.hh:57
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)
virtual void Initialize(const G4Track &)
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()
Definition: G4PathFinder.cc:52
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
Definition: G4Step.hh:62
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)
G4TrackStatus GetTrackStatus() const
G4VPhysicalVolume * GetVolume() 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
Definition: G4VProcess.hh:356
G4String theProcessName
Definition: G4VProcess.hh:341
G4VParticleChange * pParticleChange
Definition: G4VProcess.hh:321
const G4String & GetProcessName() const
Definition: G4VProcess.hh:382
virtual G4int GetReplicaNumber(G4int depth=0) const
Definition: G4VTouchable.cc:55
#define DBL_MAX
Definition: templates.hh:62