Geant4 9.6.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4ParallelWorldScoringProcess.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//
27// $Id$
28//
29//
30
32
33#include "G4ios.hh"
34#include "G4SystemOfUnits.hh"
35#include "G4Step.hh"
36#include "G4Navigator.hh"
37#include "G4VTouchable.hh"
38#include "G4VPhysicalVolume.hh"
39#include "G4ParticleChange.hh"
40#include "G4PathFinder.hh"
42#include "G4ParticleChange.hh"
43#include "G4StepPoint.hh"
46
47#include "G4SDManager.hh"
49
50//--------------------------------
51// Constructor with name and type:
52//--------------------------------
55:G4VProcess(processName,theType), fGhostNavigator(0), fNavigatorID(-1), fFieldTrack('0')
56{
57 pParticleChange = &aDummyParticleChange;
58
59 fGhostStep = new G4Step();
60 fGhostPreStepPoint = fGhostStep->GetPreStepPoint();
61 fGhostPostStepPoint = fGhostStep->GetPostStepPoint();
62
64 fPathFinder = G4PathFinder::GetInstance();
65
66 if (verboseLevel>0)
67 {
68 G4cout << GetProcessName() << " is created " << G4endl;
69 }
70}
71
72// -----------
73// Destructor:
74// -----------
76{
77 delete fGhostStep;
78}
79
80//------------------------------------------------------
81//
82// SetParallelWorld
83//
84//------------------------------------------------------
86SetParallelWorld(G4String parallelWorldName)
87{
88//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
89// Get pointers of the parallel world and its navigator
90//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
91 fGhostWorldName = parallelWorldName;
92 fGhostWorld = fTransportationManager->GetParallelWorld(fGhostWorldName);
93 fGhostNavigator = fTransportationManager->GetNavigator(fGhostWorld);
94//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
95}
96
99{
100//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
101// Get pointer of navigator
102//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
103 fGhostWorldName = parallelWorld->GetName();
104 fGhostWorld = parallelWorld;
105 fGhostNavigator = fTransportationManager->GetNavigator(fGhostWorld);
106//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
107}
108
111{
112 G4int pdgCode = partDef->GetPDGEncoding();
113 if(pdgCode==0)
114 {
115 G4String partName = partDef->GetParticleName();
116 if(partName=="opticalphoton") return false;
117 if(partName=="geantino") return false;
118 if(partName=="chargedgeantino") return false;
119 }
120 else
121 {
122 if(pdgCode==22) return false; // gamma
123 if(pdgCode==11) return false; // electron
124 if(pdgCode==2212) return false; // proton
125 if(pdgCode==-12) return false; // anti_nu_e
126 if(pdgCode==12) return false; // nu_e
127 if(pdgCode==-14) return false; // anti_nu_mu
128 if(pdgCode==14) return false; // nu_mu
129 if(pdgCode==-16) return false; // anti_nu_tau
130 if(pdgCode==16) return false; // nu_tau
131 }
132 return true;
133}
134
135
136//------------------------------------------------------
137//
138// StartTracking
139//
140//------------------------------------------------------
142{
143//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
144// Activate navigator and get the navigator ID
145//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
146// G4cout << " G4ParallelWorldScoringProcess::StartTracking" << G4endl;
147 if(fGhostNavigator)
148 { fNavigatorID = fTransportationManager->ActivateNavigator(fGhostNavigator); }
149 else
150 {
151 G4Exception("G4ParallelWorldScoringProcess::StartTracking",
152 "ProcParaWorld000",FatalException,
153 "G4ParallelWorldScoringProcess is used for tracking without having a parallel world assigned");
154 }
155//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
156
157// G4cout << "G4ParallelWorldScoringProcess::StartTracking <<<<<<<<<<<<<<<<<< " << G4endl;
158//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
159// Let PathFinder initialize
160//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
161 fPathFinder->PrepareNewTrack(trk->GetPosition(),trk->GetMomentumDirection());
162//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
163
164//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
165// Setup initial touchables for the first step
166//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
167 fOldGhostTouchable = fPathFinder->CreateTouchableHandle(fNavigatorID);
168 fGhostPreStepPoint->SetTouchableHandle(fOldGhostTouchable);
169 fNewGhostTouchable = fOldGhostTouchable;
170 fGhostPostStepPoint->SetTouchableHandle(fNewGhostTouchable);
171
172 // Initialize
173 fGhostSafety = -1.;
174 fOnBoundary = false;
175 fGhostPreStepPoint->SetStepStatus(fUndefined);
176 fGhostPostStepPoint->SetStepStatus(fUndefined);
177}
178
179//----------------------------------------------------------
180//
181// AtRestGetPhysicalInteractionLength()
182//
183//----------------------------------------------------------
186 const G4Track& /*track*/,
188{
189 *condition = Forced;
190 return DBL_MAX;
191}
192
193//------------------------------------
194//
195// AtRestDoIt()
196//
197//------------------------------------
199 const G4Track& track,
200 const G4Step& step)
201{
202 fOldGhostTouchable = fGhostPostStepPoint->GetTouchableHandle();
203 G4VSensitiveDetector* aSD = 0;
204 if(fOldGhostTouchable->GetVolume())
205 { aSD = fOldGhostTouchable->GetVolume()->GetLogicalVolume()->GetSensitiveDetector(); }
206 fOnBoundary = false;
207 CopyStep(step);
208 fGhostPreStepPoint->SetSensitiveDetector(aSD);
209
210 fNewGhostTouchable = fOldGhostTouchable;
211
212 fGhostPreStepPoint->SetTouchableHandle(fOldGhostTouchable);
213 fGhostPostStepPoint->SetTouchableHandle(fNewGhostTouchable);
214 if(fNewGhostTouchable->GetVolume())
215 {
216 fGhostPostStepPoint->SetSensitiveDetector(
217 fNewGhostTouchable->GetVolume()->GetLogicalVolume()->GetSensitiveDetector());
218 }
219 else
220 { fGhostPostStepPoint->SetSensitiveDetector(0); }
221
222 if (verboseLevel>1) Verbose(step);
223
224 G4VSensitiveDetector* sd = fGhostPreStepPoint->GetSensitiveDetector();
225 if(sd)
226 {
227 sd->Hit(fGhostStep);
228 }
229
231 return pParticleChange;
232}
233
234//----------------------------------------------------------
235//
236// PostStepGetPhysicalInteractionLength()
237//
238//----------------------------------------------------------
241 const G4Track& /*track*/,
242 G4double /*previousStepSize*/,
244{
245 // I must be invoked anyway to score the hit.
247 return DBL_MAX;
248}
249
250//------------------------------------
251//
252// PostStepDoIt()
253//
254//------------------------------------
256 const G4Track& track,
257 const G4Step& step)
258{
259 fOldGhostTouchable = fGhostPostStepPoint->GetTouchableHandle();
260 G4VSensitiveDetector* aSD = 0;
261 if(fOldGhostTouchable->GetVolume())
262 { aSD = fOldGhostTouchable->GetVolume()->GetLogicalVolume()->GetSensitiveDetector(); }
263 CopyStep(step);
264 fGhostPreStepPoint->SetSensitiveDetector(aSD);
265
266 // fPathFinder->Locate( track.GetPosition(),
267 // track.GetMomentumDirection(),
268 // true);
269
270 // fPathFinder->Locate(step.GetPostStepPoint()->GetPosition(),
271 // step.GetPostStepPoint()->GetMomentumDirection());
272
273 if(fOnBoundary)
274 {
275//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
276// Locate the point and get new touchable
277//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
278 //?? fPathFinder->Locate(step.GetPostStepPoint()->GetPosition(),
279 //?? step.GetPostStepPoint()->GetMomentumDirection());
280 fNewGhostTouchable = fPathFinder->CreateTouchableHandle(fNavigatorID);
281//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
282 }
283 else
284 {
285// Do I need this ??????????????????????????????????????????????????????????
286// fGhostNavigator->LocateGlobalPointWithinVolume(track.GetPosition());
287// ?????????????????????????????????????????????????????????????????????????
288
289 // fPathFinder->ReLocate(track.GetPosition());
290
291 // reuse the touchable
292 fNewGhostTouchable = fOldGhostTouchable;
293 }
294
295 fGhostPreStepPoint->SetTouchableHandle(fOldGhostTouchable);
296 fGhostPostStepPoint->SetTouchableHandle(fNewGhostTouchable);
297
298 if(fNewGhostTouchable->GetVolume())
299 {
300 fGhostPostStepPoint->SetSensitiveDetector(
301 fNewGhostTouchable->GetVolume()->GetLogicalVolume()->GetSensitiveDetector());
302 }
303 else
304 { fGhostPostStepPoint->SetSensitiveDetector(0); }
305
306 if (verboseLevel>1) Verbose(step);
307
308 G4VSensitiveDetector* sd = fGhostPreStepPoint->GetSensitiveDetector();
309 if(sd)
310 {
311 sd->Hit(fGhostStep);
312 }
313
314 pParticleChange->Initialize(track); // Does not change the track properties
315 return pParticleChange;
316}
317
318
319//---------------------------------------
320//
321// AlongStepGetPhysicalInteractionLength
322//
323//---------------------------------------
325 const G4Track& track, G4double previousStepSize, G4double currentMinimumStep,
326 G4double& proposedSafety, G4GPILSelection* selection)
327{
328 static G4FieldTrack endTrack('0');
329 static ELimited eLimited;
330
331 *selection = NotCandidateForSelection;
332 G4double returnedStep = DBL_MAX;
333
334 if (previousStepSize > 0.)
335 { fGhostSafety -= previousStepSize; }
336// else
337// { fGhostSafety = -1.; }
338 if (fGhostSafety < 0.) fGhostSafety = 0.0;
339
340 // ------------------------------------------
341 // Determination of the proposed STEP LENGTH:
342 // ------------------------------------------
343 if (currentMinimumStep <= fGhostSafety && currentMinimumStep > 0.)
344 {
345 // I have no chance to limit
346 returnedStep = currentMinimumStep;
347 fOnBoundary = false;
348 proposedSafety = fGhostSafety - currentMinimumStep;
349 }
350 else // (currentMinimumStep > fGhostSafety: I may limit the Step)
351 {
352 G4FieldTrackUpdator::Update(&fFieldTrack,&track);
353//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
354// ComputeStep
355//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
356 returnedStep
357 = fPathFinder->ComputeStep(fFieldTrack,currentMinimumStep,fNavigatorID,
358 track.GetCurrentStepNumber(),fGhostSafety,eLimited,
359 endTrack,track.GetVolume());
360//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
361 if(eLimited == kDoNot)
362 {
363 // Track is not on the boundary
364 fOnBoundary = false;
365 fGhostSafety = fGhostNavigator->ComputeSafety(endTrack.GetPosition());
366 }
367 else
368 {
369 // Track is on the boundary
370 fOnBoundary = true;
371 // proposedSafety = fGhostSafety;
372 }
373 proposedSafety = fGhostSafety;
374 if(eLimited == kUnique || eLimited == kSharedOther) {
375 *selection = CandidateForSelection;
376 }else if (eLimited == kSharedTransport) {
377 returnedStep *= (1.0 + 1.0e-9);
378 // Expand to disable its selection in Step Manager comparison
379 }
380 }
381
382 // ----------------------------------------------
383 // Returns the fGhostSafety as the proposedSafety
384 // The SteppingManager will take care of keeping
385 // the smallest one.
386 // ----------------------------------------------
387 return returnedStep;
388}
389
391 const G4Track& track, const G4Step& )
392{
393 // Dummy ParticleChange ie: does nothing
394 // Expecting G4Transportation to move the track
396 return pParticleChange;
397}
398
399
400void G4ParallelWorldScoringProcess::CopyStep(const G4Step & step)
401{
402 G4StepStatus prevStat = fGhostPostStepPoint->GetStepStatus();
403
404 fGhostStep->SetTrack(step.GetTrack());
405 fGhostStep->SetStepLength(step.GetStepLength());
408 fGhostStep->SetControlFlag(step.GetControlFlag());
409
410 *fGhostPreStepPoint = *(step.GetPreStepPoint());
411 *fGhostPostStepPoint = *(step.GetPostStepPoint());
412
413//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
414// Set StepStatus for ghost world
415//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
416 fGhostPreStepPoint->SetStepStatus(prevStat);
417 if(fOnBoundary)
418 { fGhostPostStepPoint->SetStepStatus(fGeomBoundary); }
419 else if(fGhostPostStepPoint->GetStepStatus()==fGeomBoundary)
420 { fGhostPostStepPoint->SetStepStatus(fPostStepDoItProc); }
421//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
422}
423
425{
426 G4cout << "In mass geometry ------------------------------------------------" << G4endl;
427 G4cout << " StepLength : " << step.GetStepLength()/mm << " TotalEnergyDeposit : "
428 << step.GetTotalEnergyDeposit()/MeV << G4endl;
429 G4cout << " PreStepPoint : "
430 << step.GetPreStepPoint()->GetPhysicalVolume()->GetName() << " - ";
433 else
434 { G4cout << "NoProcessAssigned"; }
435 G4cout << G4endl;
436 G4cout << " " << step.GetPreStepPoint()->GetPosition() << G4endl;
437 G4cout << " PostStepPoint : ";
440 else
441 { G4cout << "OutOfWorld"; }
442 G4cout << " - ";
445 else
446 { G4cout << "NoProcessAssigned"; }
447 G4cout << G4endl;
448 G4cout << " " << step.GetPostStepPoint()->GetPosition() << G4endl;
449
450 G4cout << "In ghost geometry ------------------------------------------------" << G4endl;
451 G4cout << " StepLength : " << fGhostStep->GetStepLength()/mm
452 << " TotalEnergyDeposit : "
453 << fGhostStep->GetTotalEnergyDeposit()/MeV << G4endl;
454 G4cout << " PreStepPoint : "
455 << fGhostStep->GetPreStepPoint()->GetPhysicalVolume()->GetName() << " ["
456 << fGhostStep->GetPreStepPoint()->GetTouchable()->GetReplicaNumber()
457 << " ]" << " - ";
458 if(fGhostStep->GetPreStepPoint()->GetProcessDefinedStep())
460 else
461 { G4cout << "NoProcessAssigned"; }
462 G4cout << G4endl;
463 G4cout << " " << fGhostStep->GetPreStepPoint()->GetPosition() << G4endl;
464 G4cout << " PostStepPoint : ";
465 if(fGhostStep->GetPostStepPoint()->GetPhysicalVolume())
466 {
467 G4cout << fGhostStep->GetPostStepPoint()->GetPhysicalVolume()->GetName() << " ["
468 << fGhostStep->GetPostStepPoint()->GetTouchable()->GetReplicaNumber()
469 << " ]";
470 }
471 else
472 { G4cout << "OutOfWorld"; }
473 G4cout << " - ";
474 if(fGhostStep->GetPostStepPoint()->GetProcessDefinedStep())
476 else
477 { G4cout << "NoProcessAssigned"; }
478 G4cout << G4endl;
479 G4cout << " " << fGhostStep->GetPostStepPoint()->GetPosition() << " == "
480 << fGhostStep->GetTrack()->GetMomentumDirection()
481 << G4endl;
482
483}
484
G4double condition(const G4ErrorSymMatrix &m)
@ FatalException
G4ForceCondition
@ StronglyForced
@ Forced
G4GPILSelection
@ CandidateForSelection
@ NotCandidateForSelection
ELimited
@ kDoNot
@ kUnique
@ kSharedOther
@ kSharedTransport
G4ProcessType
G4StepStatus
Definition: G4StepStatus.hh:51
@ fGeomBoundary
Definition: G4StepStatus.hh:54
@ fUndefined
Definition: G4StepStatus.hh:66
@ fPostStepDoItProc
Definition: G4StepStatus.hh:60
double G4double
Definition: G4Types.hh:64
int G4int
Definition: G4Types.hh:66
bool G4bool
Definition: G4Types.hh:67
#define G4endl
Definition: G4ios.hh:52
G4DLLIMPORT std::ostream G4cout
static void Update(G4FieldTrack *, const G4Track *)
G4ThreeVector GetPosition() const
G4VSensitiveDetector * GetSensitiveDetector() const
virtual G4double ComputeSafety(const G4ThreeVector &globalpoint, const G4double pProposedMaxLength=DBL_MAX, const G4bool keepState=true)
G4VParticleChange * PostStepDoIt(const G4Track &, const G4Step &)
G4double AtRestGetPhysicalInteractionLength(const G4Track &, G4ForceCondition *)
G4bool IsAtRestRequired(G4ParticleDefinition *partDef)
void SetParallelWorld(G4String parallelWorldName)
G4double AlongStepGetPhysicalInteractionLength(const G4Track &, G4double, G4double, G4double &, G4GPILSelection *)
G4ParallelWorldScoringProcess(const G4String &processName="ParaWorldScore", G4ProcessType theType=fParameterisation)
G4VParticleChange * AtRestDoIt(const G4Track &, const G4Step &)
G4double PostStepGetPhysicalInteractionLength(const G4Track &track, G4double previousStepSize, G4ForceCondition *condition)
G4VParticleChange * AlongStepDoIt(const G4Track &, const G4Step &)
const G4String & GetParticleName() const
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=0)
static G4PathFinder * GetInstance()
Definition: G4PathFinder.cc:57
G4TouchableHandle CreateTouchableHandle(G4int navId) const
void SetSensitiveDetector(G4VSensitiveDetector *)
G4StepStatus GetStepStatus() const
const G4VTouchable * GetTouchable() const
void SetStepStatus(const G4StepStatus aValue)
const G4VProcess * GetProcessDefinedStep() const
void SetTouchableHandle(const G4TouchableHandle &apValue)
const G4ThreeVector & GetPosition() const
const G4TouchableHandle & GetTouchableHandle() const
G4VSensitiveDetector * GetSensitiveDetector() const
G4VPhysicalVolume * GetPhysicalVolume() const
Definition: G4Step.hh:78
G4SteppingControl GetControlFlag() const
G4Track * GetTrack() const
void SetStepLength(G4double value)
void SetNonIonizingEnergyDeposit(G4double value)
G4StepPoint * GetPreStepPoint() const
G4double GetNonIonizingEnergyDeposit() const
G4double GetStepLength() const
G4double GetTotalEnergyDeposit() const
void SetControlFlag(G4SteppingControl StepControlFlag)
void SetTotalEnergyDeposit(G4double value)
G4StepPoint * GetPostStepPoint() const
void SetTrack(G4Track *value)
G4VPhysicalVolume * GetVolume() 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 void Initialize(const G4Track &)
G4LogicalVolume * GetLogicalVolume() const
const G4String & GetName() const
G4int verboseLevel
Definition: G4VProcess.hh:368
G4VParticleChange * pParticleChange
Definition: G4VProcess.hh:283
const G4String & GetProcessName() const
Definition: G4VProcess.hh:379
G4bool Hit(G4Step *aStep)
virtual G4VPhysicalVolume * GetVolume(G4int depth=0) const
Definition: G4VTouchable.cc:44
virtual G4int GetReplicaNumber(G4int depth=0) const
Definition: G4VTouchable.cc:58
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
#define DBL_MAX
Definition: templates.hh:83