Geant4 11.1.1
Toolkit for the simulation of the passage of particles through matter
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
G4ParallelWorldProcess.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//
28//
29
30#include "G4ios.hh"
33#include "G4Step.hh"
34#include "G4StepPoint.hh"
35#include "G4Navigator.hh"
36#include "G4VTouchable.hh"
37#include "G4VPhysicalVolume.hh"
38#include "G4ParticleChange.hh"
39#include "G4PathFinder.hh"
41#include "G4ParticleChange.hh"
42#include "G4StepPoint.hh"
44#include "G4Material.hh"
45#include "G4ProductionCuts.hh"
48
49#include "G4SDManager.hh"
51
52G4ThreadLocal G4Step* G4ParallelWorldProcess::fpHyperStep = 0;
53G4ThreadLocal G4int G4ParallelWorldProcess::nParallelWorlds = 0;
54G4ThreadLocal G4int G4ParallelWorldProcess::fNavIDHyp = 0;
56{ return fpHyperStep; }
58{ return fNavIDHyp; }
59
61G4ParallelWorldProcess(const G4String& processName,G4ProcessType theType)
62:G4VProcess(processName,theType),fGhostWorld(nullptr),fGhostNavigator(nullptr),
63 fNavigatorID(-1),fFieldTrack('0'),fGhostSafety(0.),fOnBoundary(false),
64 layeredMaterialFlag(false)
65{
67 if(!fpHyperStep) fpHyperStep = new G4Step();
68 iParallelWorld = ++nParallelWorlds;
69
71
72 fGhostStep = new G4Step();
75
79
80 fGhostWorldName = "** NotDefined **";
82
83 if (verboseLevel>0)
84 {
85 G4cout << GetProcessName() << " is created " << G4endl;
86 }
87}
88
90{
91 delete fGhostStep;
92 nParallelWorlds--;
93 if(nParallelWorlds==0)
94 {
95 delete fpHyperStep;
96 fpHyperStep = 0;
97 }
98}
99
101SetParallelWorld(G4String parallelWorldName)
102{
103 fGhostWorldName = parallelWorldName;
107}
108
111{
112 fGhostWorldName = parallelWorld->GetName();
113 fGhostWorld = parallelWorld;
116}
117
119{
122 else
123 {
124 G4Exception("G4ParallelWorldProcess::StartTracking",
125 "ProcParaWorld000",FatalException,
126 "G4ParallelWorldProcess is used for tracking without having a parallel world assigned");
127 }
129
134
135 fGhostSafety = -1.;
136 fOnBoundary = false;
139
140// G4VPhysicalVolume* thePhys = fNewGhostTouchable->GetVolume();
141// if(thePhys)
142// {
143// G4Material* ghostMaterial = thePhys->GetLogicalVolume()->GetMaterial();
144// if(ghostMaterial)
145// { G4cout << " --- Material : " << ghostMaterial->GetName() << G4endl; }
146// }
147
148 *(fpHyperStep->GetPostStepPoint()) = *(trk->GetStep()->GetPostStepPoint());
150 {
151 G4StepPoint* realWorldPostStepPoint = trk->GetStep()->GetPostStepPoint();
152 SwitchMaterial(realWorldPostStepPoint);
153 G4StepPoint *realWorldPreStepPoint = trk->GetStep()->GetPreStepPoint();
154 SwitchMaterial(realWorldPreStepPoint);
155 G4double velocity = trk->CalculateVelocity();
156 realWorldPostStepPoint->SetVelocity(velocity);
157 realWorldPreStepPoint->SetVelocity(velocity);
158 trk->SetVelocity(velocity);
159 }
160 *(fpHyperStep->GetPreStepPoint()) = *(fpHyperStep->GetPostStepPoint());
161}
162
165 const G4Track& /*track*/,
167{
168//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
169// At Rest must be registered ONLY for the particle which has other At Rest
170// process(es).
171//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
172 *condition = Forced;
173 return DBL_MAX;
174}
175
177 const G4Track& track,
178 const G4Step& step)
179{
180//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
181// At Rest must be registered ONLY for the particle which has other At Rest
182// process(es).
183//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
185 G4VSensitiveDetector* aSD = 0;
188 fOnBoundary = false;
189 if(aSD)
190 {
191 CopyStep(step);
193
195
199 {
202 }
203 else
205
206 aSD->Hit(fGhostStep);
207 }
208
210 return pParticleChange;
211}
212
215 const G4Track& /*track*/,
216 G4double /*previousStepSize*/,
218{
220 return DBL_MAX;
221}
222
224 const G4Track& track,
225 const G4Step& step)
226{
228 G4VSensitiveDetector* aSD = 0;
231 CopyStep(step);
233
234 if(fOnBoundary)
235 {
237 }
238 else
239 {
241 }
242
245
247 {
250 }
251 else
253
255 if(sd)
256 {
257 sd->Hit(fGhostStep);
258 }
259
262 {
263 G4StepPoint* realWorldPostStepPoint =
264 ((G4Step*)(track.GetStep()))->GetPostStepPoint();
265 SwitchMaterial(realWorldPostStepPoint);
266 }
267 return pParticleChange;
268}
269
271 const G4Track& track, G4double previousStepSize, G4double currentMinimumStep,
272 G4double& proposedSafety, G4GPILSelection* selection)
273{
274 static G4ThreadLocal G4FieldTrack *endTrack_G4MT_TLS_ = 0 ; if (!endTrack_G4MT_TLS_) endTrack_G4MT_TLS_ = new G4FieldTrack ('0') ; G4FieldTrack &endTrack = *endTrack_G4MT_TLS_;
275 //static ELimited eLimited;
276 ELimited eLimited;
277 ELimited eLim = kUndefLimited;
278
279 *selection = NotCandidateForSelection;
280 G4double returnedStep = DBL_MAX;
281
282 if (previousStepSize > 0.)
283 { fGhostSafety -= previousStepSize; }
284 if (fGhostSafety < 0.) fGhostSafety = 0.0;
285
286 if (currentMinimumStep <= fGhostSafety && currentMinimumStep > 0.)
287 {
288 // I have no chance to limit
289 returnedStep = currentMinimumStep;
290 fOnBoundary = false;
291 proposedSafety = fGhostSafety - currentMinimumStep;
292 eLim = kDoNot;
293 }
294 else
295 {
297
298#ifdef G4DEBUG_PARALLEL_WORLD_PROCESS
299 if( verboseLevel > 0 ){
300 int localVerb = verboseLevel-1;
301
302 if( localVerb == 1 ) {
303 G4cout << " Pll Wrl proc::AlongStepGPIL " << this->GetProcessName() << G4endl;
304 }else if( localVerb > 1 ) {
305 G4cout << "----------------------------------------------" << G4endl;
306 G4cout << " ParallelWorldProcess: field Track set to : " << G4endl;
307 G4cout << "----------------------------------------------" << G4endl;
309 G4cout << "----------------------------------------------" << G4endl;
310 }
311 }
312#endif
313
314 returnedStep
315 = fPathFinder->ComputeStep(fFieldTrack,currentMinimumStep,fNavigatorID,
316 track.GetCurrentStepNumber(),fGhostSafety,eLimited,
317 endTrack,track.GetVolume());
318 if(eLimited == kDoNot)
319 {
320 fOnBoundary = false;
322 }
323 else
324 {
325 fOnBoundary = true;
326 // fGhostSafetyEnd = 0.0; // At end-point of expected step only
327 }
328 proposedSafety = fGhostSafety;
329 if(eLimited == kUnique || eLimited == kSharedOther) {
330 *selection = CandidateForSelection;
331 }
332 else if (eLimited == kSharedTransport) {
333 returnedStep *= (1.0 + 1.0e-9);
334 }
335 eLim = eLimited;
336 }
337
338 if(iParallelWorld==nParallelWorlds) fNavIDHyp = 0;
339 if(eLim == kUnique || eLim == kSharedOther) fNavIDHyp = fNavigatorID;
340 return returnedStep;
341}
342
344 const G4Track& track, const G4Step& )
345{
347 return pParticleChange;
348}
349
351{
353
359 fGhostStep->SetSecondary((const_cast<G4Step&>(step)).GetfSecondary());
360
363
365 if(fOnBoundary)
369
370 if(iParallelWorld==1)
371 {
372 G4StepStatus prevStatHyp = fpHyperStep->GetPostStepPoint()->GetStepStatus();
373
374 fpHyperStep->SetTrack(step.GetTrack());
375 fpHyperStep->SetStepLength(step.GetStepLength());
376 fpHyperStep->SetTotalEnergyDeposit(step.GetTotalEnergyDeposit());
378 fpHyperStep->SetControlFlag(step.GetControlFlag());
379
380 *(fpHyperStep->GetPreStepPoint()) = *(fpHyperStep->GetPostStepPoint());
381 *(fpHyperStep->GetPostStepPoint()) = *(step.GetPostStepPoint());
382
383 fpHyperStep->GetPreStepPoint()->SetStepStatus(prevStatHyp);
384 }
385
386 if(fOnBoundary)
387 { fpHyperStep->GetPostStepPoint()->SetStepStatus(fGeomBoundary); }
388}
389
391{
392 if(realWorldStepPoint->GetStepStatus()==fWorldBoundary) return;
394 if(thePhys)
395 {
396 G4Material* ghostMaterial = thePhys->GetLogicalVolume()->GetMaterial();
397 if(ghostMaterial)
398 {
399 G4Region* ghostRegion = thePhys->GetLogicalVolume()->GetRegion();
400 G4ProductionCuts* prodCuts =
401 realWorldStepPoint->GetMaterialCutsCouple()->GetProductionCuts();
402 if(ghostRegion)
403 {
404 G4ProductionCuts* ghostProdCuts = ghostRegion->GetProductionCuts();
405 if(ghostProdCuts) prodCuts = ghostProdCuts;
406 }
407 const G4MaterialCutsCouple* ghostMCCouple =
409 ->GetMaterialCutsCouple(ghostMaterial,prodCuts);
410 if(ghostMCCouple)
411 {
412 realWorldStepPoint->SetMaterial(ghostMaterial);
413 realWorldStepPoint->SetMaterialCutsCouple(ghostMCCouple);
414 *(fpHyperStep->GetPostStepPoint()) = *(fGhostPostStepPoint);
415 fpHyperStep->GetPostStepPoint()->SetMaterial(ghostMaterial);
416 fpHyperStep->GetPostStepPoint()->SetMaterialCutsCouple(ghostMCCouple);
417 }
418 else
419 {
420 G4cout << "!!! MaterialCutsCouple is not found for "
421 << ghostMaterial->GetName() << "." << G4endl
422 << " Material in real world ("
423 << realWorldStepPoint->GetMaterial()->GetName()
424 << ") is used." << G4endl;
425 }
426 }
427 }
428}
429
431{
432 G4int pdgCode = partDef->GetPDGEncoding();
433 if(pdgCode==0)
434 {
435 G4String partName = partDef->GetParticleName();
436 if(partName=="geantino") return false;
437 if(partName=="chargedgeantino") return false;
438 }
439 else
440 {
441 if(pdgCode==11 || pdgCode==2212) return false; // electrons and proton
442 pdgCode = std::abs(pdgCode);
443 if(pdgCode==22) return false; // gamma and optical photons
444 if(pdgCode==12 || pdgCode==14 || pdgCode==16) return false; // all neutronos
445 }
446 return true;
447}
448
G4double condition(const G4ErrorSymMatrix &m)
@ FatalException
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.cc:59
G4ForceCondition
@ StronglyForced
@ Forced
G4GPILSelection
@ CandidateForSelection
@ NotCandidateForSelection
ELimited
@ kDoNot
@ kUndefLimited
@ kUnique
@ kSharedOther
@ kSharedTransport
G4ProcessType
G4StepStatus
Definition: G4StepStatus.hh:40
@ fGeomBoundary
Definition: G4StepStatus.hh:43
@ fWorldBoundary
Definition: G4StepStatus.hh:41
@ fUndefined
Definition: G4StepStatus.hh:55
@ fPostStepDoItProc
Definition: G4StepStatus.hh:49
double G4double
Definition: G4Types.hh:83
bool G4bool
Definition: G4Types.hh:86
int G4int
Definition: G4Types.hh:85
#define G4endl
Definition: G4ios.hh:57
G4GLOB_DLL std::ostream G4cout
static void Update(G4FieldTrack *, const G4Track *)
G4ThreeVector GetPosition() const
G4VSensitiveDetector * GetSensitiveDetector() const
G4Region * GetRegion() const
G4Material * GetMaterial() const
G4ProductionCuts * GetProductionCuts() const
const G4String & GetName() const
Definition: G4Material.hh:172
void SetPushVerbosity(G4bool mode)
virtual G4double ComputeSafety(const G4ThreeVector &globalpoint, const G4double pProposedMaxLength=DBL_MAX, const G4bool keepState=true)
static G4ParallelWorldProcessStore * GetInstance()
void SetParallelWorld(G4ParallelWorldProcess *proc, G4String parallelWorldName)
G4TouchableHandle fNewGhostTouchable
G4VParticleChange * AlongStepDoIt(const G4Track &, const G4Step &)
G4double AtRestGetPhysicalInteractionLength(const G4Track &, G4ForceCondition *)
G4VParticleChange aDummyParticleChange
static const G4Step * GetHyperStep()
G4VParticleChange * PostStepDoIt(const G4Track &, const G4Step &)
G4TransportationManager * fTransportationManager
void CopyStep(const G4Step &step)
G4VPhysicalVolume * fGhostWorld
G4TouchableHandle fOldGhostTouchable
void SwitchMaterial(G4StepPoint *)
G4double AlongStepGetPhysicalInteractionLength(const G4Track &, G4double, G4double, G4double &, G4GPILSelection *)
G4ParallelWorldProcess(const G4String &processName="ParaWorld", G4ProcessType theType=fParallel)
void SetParallelWorld(G4String parallelWorldName)
G4double PostStepGetPhysicalInteractionLength(const G4Track &, G4double, G4ForceCondition *)
G4bool IsAtRestRequired(G4ParticleDefinition *)
G4VParticleChange * AtRestDoIt(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=nullptr)
static G4PathFinder * GetInstance()
Definition: G4PathFinder.cc:52
G4TouchableHandle CreateTouchableHandle(G4int navId) const
const G4MaterialCutsCouple * GetMaterialCutsCouple(G4int i) const
static G4ProductionCutsTable * GetProductionCutsTable()
G4ProductionCuts * GetProductionCuts() const
void SetSensitiveDetector(G4VSensitiveDetector *)
void SetMaterial(G4Material *)
G4StepStatus GetStepStatus() const
void SetStepStatus(const G4StepStatus aValue)
void SetVelocity(G4double v)
void SetTouchableHandle(const G4TouchableHandle &apValue)
G4Material * GetMaterial() const
const G4TouchableHandle & GetTouchableHandle() const
void SetMaterialCutsCouple(const G4MaterialCutsCouple *)
const G4MaterialCutsCouple * GetMaterialCutsCouple() const
G4VSensitiveDetector * GetSensitiveDetector() const
Definition: G4Step.hh:62
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 SetSecondary(G4TrackVector *value)
void SetControlFlag(G4SteppingControl StepControlFlag)
void SetTotalEnergyDeposit(G4double value)
G4StepPoint * GetPostStepPoint() const
void SetTrack(G4Track *value)
void SetVelocity(G4double val)
G4VPhysicalVolume * GetVolume() const
const G4ThreeVector & GetPosition() const
G4int GetCurrentStepNumber() const
const G4ThreeVector & GetMomentumDirection() const
G4double CalculateVelocity() const
const G4Step * GetStep() const
G4VPhysicalVolume * GetParallelWorld(const G4String &worldName)
static G4TransportationManager * GetTransportationManager()
G4Navigator * GetNavigatorForTracking() const
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:360
void SetProcessSubType(G4int)
Definition: G4VProcess.hh:410
G4VParticleChange * pParticleChange
Definition: G4VProcess.hh:325
const G4String & GetProcessName() const
Definition: G4VProcess.hh:386
G4bool Hit(G4Step *aStep)
virtual G4VPhysicalVolume * GetVolume(G4int depth=0) const
Definition: G4VTouchable.cc:34
#define DBL_MAX
Definition: templates.hh:62
#define G4ThreadLocal
Definition: tls.hh:77