Geant4 11.2.2
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
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
31
33#include "G4Material.hh"
34#include "G4Navigator.hh"
36#include "G4ParticleChange.hh"
37#include "G4PathFinder.hh"
38#include "G4ProductionCuts.hh"
40#include "G4SDManager.hh"
41#include "G4Step.hh"
42#include "G4StepPoint.hh"
45#include "G4VPhysicalVolume.hh"
47#include "G4VTouchable.hh"
48#include "G4ios.hh"
49
50G4ThreadLocal G4Step* G4ParallelWorldProcess::fpHyperStep = nullptr;
51G4ThreadLocal G4int G4ParallelWorldProcess::nParallelWorlds = 0;
52G4ThreadLocal G4int G4ParallelWorldProcess::fNavIDHyp = 0;
53
55{
56 return fpHyperStep;
57}
58
60{
61 return fNavIDHyp;
62}
63
65 : G4VProcess(processName, theType), fFieldTrack('0')
66{
68 if (fpHyperStep == nullptr) fpHyperStep = new G4Step();
69 iParallelWorld = ++nParallelWorlds;
70
72
73 fGhostStep = new G4Step();
76
80
81 fGhostWorldName = "** NotDefined **";
83
84 if (verboseLevel > 0) {
85 G4cout << GetProcessName() << " is created " << G4endl;
86 }
87}
88
90{
91 delete fGhostStep;
92 nParallelWorlds--;
93 if (nParallelWorlds == 0) {
94 delete fpHyperStep;
95 fpHyperStep = nullptr;
96 }
97}
98
106
114
116{
117 if (fGhostNavigator != nullptr) {
119 }
120 else {
122 "G4ParallelWorldProcess::StartTracking", "ProcParaWorld000", FatalException,
123 "G4ParallelWorldProcess is used for tracking without having a parallel world assigned");
124 }
126
131
132 fGhostSafety = -1.;
133 fOnBoundary = false;
136
137 *(fpHyperStep->GetPostStepPoint()) = *(trk->GetStep()->GetPostStepPoint());
139 G4StepPoint* realWorldPostStepPoint = trk->GetStep()->GetPostStepPoint();
140 SwitchMaterial(realWorldPostStepPoint);
141 G4StepPoint* realWorldPreStepPoint = trk->GetStep()->GetPreStepPoint();
142 SwitchMaterial(realWorldPreStepPoint);
143 G4double velocity = trk->CalculateVelocity();
144 realWorldPostStepPoint->SetVelocity(velocity);
145 realWorldPreStepPoint->SetVelocity(velocity);
146 trk->SetVelocity(velocity);
147 }
148 *(fpHyperStep->GetPreStepPoint()) = *(fpHyperStep->GetPostStepPoint());
149}
150
153{
154 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
155 // At Rest must be registered ONLY for the particle which has other At Rest
156 // process(es).
157 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
158 *condition = Forced;
159 return DBL_MAX;
160}
161
163{
164 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
165 // At Rest must be registered ONLY for the particle which has other At Rest
166 // process(es).
167 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
169 G4VSensitiveDetector* aSD = nullptr;
170 if (fOldGhostTouchable->GetVolume() != nullptr) {
172 }
173 fOnBoundary = false;
174 if (aSD != nullptr) {
175 CopyStep(step);
177
179
182 if (fNewGhostTouchable->GetVolume() != nullptr) {
185 }
186 else {
188 }
189
190 aSD->Hit(fGhostStep);
191 }
192
194 return pParticleChange;
195}
196
204
245
247 G4double previousStepSize,
248 G4double currentMinimumStep,
249 G4double& proposedSafety,
250 G4GPILSelection* selection)
251{
252 static G4ThreadLocal G4FieldTrack* endTrack_G4MT_TLS_ = nullptr;
253 if (endTrack_G4MT_TLS_ == nullptr) endTrack_G4MT_TLS_ = new G4FieldTrack('0');
254 G4FieldTrack& endTrack = *endTrack_G4MT_TLS_;
255 // static ELimited eLimited;
256 ELimited eLimited;
257 ELimited eLim = kUndefLimited;
258
259 *selection = NotCandidateForSelection;
260 G4double returnedStep = DBL_MAX;
261
262 if (previousStepSize > 0.) {
263 fGhostSafety -= previousStepSize;
264 }
265 if (fGhostSafety < 0.) fGhostSafety = 0.0;
266
267 if (currentMinimumStep <= fGhostSafety && currentMinimumStep > 0.) {
268 // I have no chance to limit
269 returnedStep = currentMinimumStep;
270 fOnBoundary = false;
271 proposedSafety = fGhostSafety - currentMinimumStep;
272 eLim = kDoNot;
273 }
274 else {
276
277#ifdef G4DEBUG_PARALLEL_WORLD_PROCESS
278 if (verboseLevel > 0) {
279 int localVerb = verboseLevel - 1;
280
281 if (localVerb == 1) {
282 G4cout << " Pll Wrl proc::AlongStepGPIL " << this->GetProcessName() << G4endl;
283 }
284 else if (localVerb > 1) {
285 G4cout << "----------------------------------------------" << G4endl;
286 G4cout << " ParallelWorldProcess: field Track set to : " << G4endl;
287 G4cout << "----------------------------------------------" << G4endl;
289 G4cout << "----------------------------------------------" << G4endl;
290 }
291 }
292#endif
293
294 returnedStep = fPathFinder->ComputeStep(fFieldTrack, currentMinimumStep, fNavigatorID,
295 track.GetCurrentStepNumber(), fGhostSafety, eLimited,
296 endTrack, track.GetVolume());
297 if (eLimited == kDoNot) {
298 fOnBoundary = false;
300 }
301 else {
302 fOnBoundary = true;
303 // fGhostSafetyEnd = 0.0; // At end-point of expected step only
304 }
305 proposedSafety = fGhostSafety;
306 if (eLimited == kUnique || eLimited == kSharedOther) {
307 *selection = CandidateForSelection;
308 }
309 else if (eLimited == kSharedTransport) {
310 returnedStep *= (1.0 + 1.0e-9);
311 }
312 eLim = eLimited;
313 }
314
315 if (iParallelWorld == nParallelWorlds) fNavIDHyp = 0;
316 if (eLim == kUnique || eLim == kSharedOther) fNavIDHyp = fNavigatorID;
317 return returnedStep;
318}
319
325
327{
329
335 fGhostStep->SetSecondary((const_cast<G4Step&>(step)).GetfSecondary());
336
339
341 if (fOnBoundary) {
343 }
346 }
347
348 if (iParallelWorld == 1) {
349 G4StepStatus prevStatHyp = fpHyperStep->GetPostStepPoint()->GetStepStatus();
350
351 fpHyperStep->SetTrack(step.GetTrack());
352 fpHyperStep->SetStepLength(step.GetStepLength());
353 fpHyperStep->SetTotalEnergyDeposit(step.GetTotalEnergyDeposit());
355 fpHyperStep->SetControlFlag(step.GetControlFlag());
356
357 *(fpHyperStep->GetPreStepPoint()) = *(fpHyperStep->GetPostStepPoint());
358 *(fpHyperStep->GetPostStepPoint()) = *(step.GetPostStepPoint());
359
360 fpHyperStep->GetPreStepPoint()->SetStepStatus(prevStatHyp);
361 }
362
363 if (fOnBoundary) {
365 }
366}
367
369{
370 if (realWorldStepPoint->GetStepStatus() == fWorldBoundary) return;
372 if (thePhys != nullptr) {
373 G4Material* ghostMaterial = thePhys->GetLogicalVolume()->GetMaterial();
374 if (ghostMaterial != nullptr) {
375 G4Region* ghostRegion = thePhys->GetLogicalVolume()->GetRegion();
376 G4ProductionCuts* prodCuts = realWorldStepPoint->GetMaterialCutsCouple()->GetProductionCuts();
377 if (ghostRegion != nullptr) {
378 G4ProductionCuts* ghostProdCuts = ghostRegion->GetProductionCuts();
379 if (ghostProdCuts != nullptr) prodCuts = ghostProdCuts;
380 }
381 const G4MaterialCutsCouple* ghostMCCouple =
383 prodCuts);
384 if (ghostMCCouple != nullptr) {
385 realWorldStepPoint->SetMaterial(ghostMaterial);
386 realWorldStepPoint->SetMaterialCutsCouple(ghostMCCouple);
387 *(fpHyperStep->GetPostStepPoint()) = *(fGhostPostStepPoint);
388 fpHyperStep->GetPostStepPoint()->SetMaterial(ghostMaterial);
389 fpHyperStep->GetPostStepPoint()->SetMaterialCutsCouple(ghostMCCouple);
390 }
391 else {
392 G4cout << "!!! MaterialCutsCouple is not found for " << ghostMaterial->GetName() << "."
393 << G4endl << " Material in real world ("
394 << realWorldStepPoint->GetMaterial()->GetName() << ") is used." << G4endl;
395 }
396 }
397 }
398}
399
401{
402 G4int pdgCode = partDef->GetPDGEncoding();
403 if (pdgCode == 0) {
404 G4String partName = partDef->GetParticleName();
405 if (partName == "geantino") return false;
406 if (partName == "chargedgeantino") return false;
407 }
408 else {
409 if (pdgCode == 11 || pdgCode == 2212) return false; // electrons and proton
410 pdgCode = std::abs(pdgCode);
411 if (pdgCode == 22) return false; // gamma and optical photons
412 if (pdgCode == 12 || pdgCode == 14 || pdgCode == 16) return false; // all neutronos
413 }
414 return true;
415}
G4double condition(const G4ErrorSymMatrix &m)
@ FatalException
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
G4ForceCondition
@ StronglyForced
@ Forced
G4GPILSelection
@ CandidateForSelection
@ NotCandidateForSelection
@ kDoNot
@ kUndefLimited
@ kUnique
@ kSharedOther
@ kSharedTransport
G4ProcessType
G4StepStatus
@ fGeomBoundary
@ fWorldBoundary
@ fUndefined
@ fPostStepDoItProc
double G4double
Definition G4Types.hh:83
bool G4bool
Definition G4Types.hh:86
int G4int
Definition G4Types.hh:85
#define G4endl
Definition G4ios.hh:67
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
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, const G4String &parallelWorldName)
G4double AlongStepGetPhysicalInteractionLength(const G4Track &, G4double, G4double, G4double &, G4GPILSelection *) override
G4VParticleChange * AlongStepDoIt(const G4Track &, const G4Step &) override
G4VParticleChange aDummyParticleChange
static const G4Step * GetHyperStep()
G4TransportationManager * fTransportationManager
void CopyStep(const G4Step &step)
G4double PostStepGetPhysicalInteractionLength(const G4Track &, G4double, G4ForceCondition *) override
G4VParticleChange * PostStepDoIt(const G4Track &, const G4Step &) override
G4VParticleChange * AtRestDoIt(const G4Track &, const G4Step &) override
void StartTracking(G4Track *) override
G4double AtRestGetPhysicalInteractionLength(const G4Track &, G4ForceCondition *) override
void SwitchMaterial(G4StepPoint *)
G4ParallelWorldProcess(const G4String &processName="ParaWorld", G4ProcessType theType=fParallel)
void SetParallelWorld(G4String parallelWorldName)
G4bool IsAtRestRequired(G4ParticleDefinition *)
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()
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
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)
virtual G4VPhysicalVolume * GetVolume(G4int depth=0) const
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
void SetProcessSubType(G4int)
G4VParticleChange * pParticleChange
const G4String & GetProcessName() const
G4bool Hit(G4Step *aStep)
#define DBL_MAX
Definition templates.hh:62
#define G4ThreadLocal
Definition tls.hh:77