Geant4  10.02
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 // $Id: G4ParallelWorldProcess.cc 88349 2015-02-16 08:47:16Z gcosmo $
28 // GEANT4 tag $Name: geant4-09-04-ref-00 $
29 //
30 //
31 
32 #include "G4ios.hh"
35 #include "G4Step.hh"
36 #include "G4StepPoint.hh"
37 #include "G4Navigator.hh"
38 #include "G4VTouchable.hh"
39 #include "G4VPhysicalVolume.hh"
40 #include "G4ParticleChange.hh"
41 #include "G4PathFinder.hh"
43 #include "G4ParticleChange.hh"
44 #include "G4StepPoint.hh"
45 #include "G4FieldTrackUpdator.hh"
46 #include "G4Material.hh"
47 #include "G4ProductionCuts.hh"
48 #include "G4ProductionCutsTable.hh"
49 
50 #include "G4SDManager.hh"
51 #include "G4VSensitiveDetector.hh"
52 
57 { return fpHyperStep; }
59 { return fNavIDHyp; }
60 
62 G4ParallelWorldProcess(const G4String& processName,G4ProcessType theType)
63 :G4VProcess(processName,theType), fGhostNavigator(0), fNavigatorID(-1),
64  fFieldTrack('0'),layeredMaterialFlag(false)
65 {
66  if(!fpHyperStep) fpHyperStep = new G4Step();
68 
70 
71  fGhostStep = new G4Step();
74 
78 
79  fGhostWorldName = "** NotDefined **";
80  fGhostWorld = 0;
81  fGhostSafety = 0.;
82  fOnBoundary = false;
83 
85 
86  if (verboseLevel>0)
87  {
88  G4cout << GetProcessName() << " is created " << G4endl;
89  }
90 }
91 
93 {
94  delete fGhostStep;
96  if(nParallelWorlds==0)
97  {
98  delete fpHyperStep;
99  fpHyperStep = 0;
100  }
101 }
102 
104 SetParallelWorld(G4String parallelWorldName)
105 {
106  fGhostWorldName = parallelWorldName;
110 }
111 
114 {
115  fGhostWorldName = parallelWorld->GetName();
116  fGhostWorld = parallelWorld;
119 }
120 
122 {
123  if(fGhostNavigator)
125  else
126  {
127  G4Exception("G4ParallelWorldProcess::StartTracking",
128  "ProcParaWorld000",FatalException,
129  "G4ParallelWorldProcess is used for tracking without having a parallel world assigned");
130  }
132 
137 
138  fGhostSafety = -1.;
139  fOnBoundary = false;
142 
143 // G4VPhysicalVolume* thePhys = fNewGhostTouchable->GetVolume();
144 // if(thePhys)
145 // {
146 // G4Material* ghostMaterial = thePhys->GetLogicalVolume()->GetMaterial();
147 // if(ghostMaterial)
148 // { G4cout << " --- Material : " << ghostMaterial->GetName() << G4endl; }
149 // }
150 
153  {
154  G4StepPoint* realWorldPostStepPoint = trk->GetStep()->GetPostStepPoint();
155  SwitchMaterial(realWorldPostStepPoint);
156  }
158 }
159 
160 G4double
162  const G4Track& /*track*/,
164 {
165 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
166 // At Rest must be registered ONLY for the particle which has other At Rest
167 // process(es).
168 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
169  *condition = Forced;
170  return DBL_MAX;
171 }
172 
174  const G4Track& track,
175  const G4Step& step)
176 {
177 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
178 // At Rest must be registered ONLY for the particle which has other At Rest
179 // process(es).
180 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
182  G4VSensitiveDetector* aSD = 0;
185  fOnBoundary = false;
186  if(aSD)
187  {
188  CopyStep(step);
190 
192 
196  {
199  }
200  else
202 
203  aSD->Hit(fGhostStep);
204  }
205 
206  pParticleChange->Initialize(track);
207  return pParticleChange;
208 }
209 
210 G4double
212  const G4Track& /*track*/,
213  G4double /*previousStepSize*/,
215 {
216  *condition = StronglyForced;
217  return DBL_MAX;
218 }
219 
221  const G4Track& track,
222  const G4Step& step)
223 {
225  G4VSensitiveDetector* aSD = 0;
228  CopyStep(step);
230 
231  if(fOnBoundary)
232  {
234  }
235  else
236  {
238  }
239 
242 
244  {
247  }
248  else
250 
252  if(sd)
253  {
254  sd->Hit(fGhostStep);
255  }
256 
257  pParticleChange->Initialize(track);
259  {
260  G4StepPoint* realWorldPostStepPoint =
261  ((G4Step*)(track.GetStep()))->GetPostStepPoint();
262  SwitchMaterial(realWorldPostStepPoint);
263  }
264  return pParticleChange;
265 }
266 
268  const G4Track& track, G4double previousStepSize, G4double currentMinimumStep,
269  G4double& proposedSafety, G4GPILSelection* selection)
270 {
271  static G4ThreadLocal G4FieldTrack *endTrack_G4MT_TLS_ = 0 ; if (!endTrack_G4MT_TLS_) endTrack_G4MT_TLS_ = new G4FieldTrack ('0') ; G4FieldTrack &endTrack = *endTrack_G4MT_TLS_;
272  //static ELimited eLimited;
273  ELimited eLimited;
274  ELimited eLim = kUndefLimited;
275 
276  *selection = NotCandidateForSelection;
277  G4double returnedStep = DBL_MAX;
278 
279  if (previousStepSize > 0.)
280  { fGhostSafety -= previousStepSize; }
281  if (fGhostSafety < 0.) fGhostSafety = 0.0;
282 
283  if (currentMinimumStep <= fGhostSafety && currentMinimumStep > 0.)
284  {
285  // I have no chance to limit
286  returnedStep = currentMinimumStep;
287  fOnBoundary = false;
288  proposedSafety = fGhostSafety - currentMinimumStep;
289  eLim = kDoNot;
290  }
291  else
292  {
294 
295 #ifdef G4DEBUG_PARALLEL_WORLD_PROCESS
296  if( verboseLevel > 0 ){
297  int localVerb = verboseLevel-1;
298 
299  if( localVerb == 1 ) {
300  G4cout << " Pll Wrl proc::AlongStepGPIL " << this->GetProcessName() << G4endl;
301  }else if( localVerb > 1 ) {
302  G4cout << "----------------------------------------------" << G4endl;
303  G4cout << " ParallelWorldProcess: field Track set to : " << G4endl;
304  G4cout << "----------------------------------------------" << G4endl;
305  G4cout << fFieldTrack << G4endl;
306  G4cout << "----------------------------------------------" << G4endl;
307  }
308  }
309 #endif
310 
311  returnedStep
312  = fPathFinder->ComputeStep(fFieldTrack,currentMinimumStep,fNavigatorID,
313  track.GetCurrentStepNumber(),fGhostSafety,eLimited,
314  endTrack,track.GetVolume());
315  if(eLimited == kDoNot)
316  {
317  fOnBoundary = false;
318  fGhostSafety = fGhostNavigator->ComputeSafety(endTrack.GetPosition());
319  }
320  else
321  {
322  fOnBoundary = true;
323  // fGhostSafetyEnd = 0.0; // At end-point of expected step only
324  }
325  proposedSafety = fGhostSafety;
326  if(eLimited == kUnique || eLimited == kSharedOther) {
327  *selection = CandidateForSelection;
328  }
329  else if (eLimited == kSharedTransport) {
330  returnedStep *= (1.0 + 1.0e-9);
331  }
332  eLim = eLimited;
333  }
334 
336  if(eLim == kUnique || eLim == kSharedOther) fNavIDHyp = fNavigatorID;
337  return returnedStep;
338 }
339 
341  const G4Track& track, const G4Step& )
342 {
343  pParticleChange->Initialize(track);
344  return pParticleChange;
345 }
346 
348 {
350 
351  fGhostStep->SetTrack(step.GetTrack());
356 
357  *fGhostPreStepPoint = *(step.GetPreStepPoint());
359 
361  if(fOnBoundary)
365 
366  if(iParallelWorld==1)
367  {
369 
370  fpHyperStep->SetTrack(step.GetTrack());
375 
378 
379  fpHyperStep->GetPreStepPoint()->SetStepStatus(prevStatHyp);
380  }
381 
382  if(fOnBoundary)
384 }
385 
387 {
388  if(realWorldStepPoint->GetStepStatus()==fWorldBoundary) return;
390  if(thePhys)
391  {
392  G4Material* ghostMaterial = thePhys->GetLogicalVolume()->GetMaterial();
393  if(ghostMaterial)
394  {
395  G4Region* ghostRegion = thePhys->GetLogicalVolume()->GetRegion();
396  G4ProductionCuts* prodCuts =
397  realWorldStepPoint->GetMaterialCutsCouple()->GetProductionCuts();
398  if(ghostRegion)
399  {
400  G4ProductionCuts* ghostProdCuts = ghostRegion->GetProductionCuts();
401  if(ghostProdCuts) prodCuts = ghostProdCuts;
402  }
403  const G4MaterialCutsCouple* ghostMCCouple =
405  ->GetMaterialCutsCouple(ghostMaterial,prodCuts);
406  if(ghostMCCouple)
407  {
408  realWorldStepPoint->SetMaterial(ghostMaterial);
409  realWorldStepPoint->SetMaterialCutsCouple(ghostMCCouple);
411  fpHyperStep->GetPostStepPoint()->SetMaterial(ghostMaterial);
413  }
414  else
415  {
416  G4cout << "!!! MaterialCutsCouple is not found for "
417  << ghostMaterial->GetName() << "." << G4endl
418  << " Material in real world ("
419  << realWorldStepPoint->GetMaterial()->GetName()
420  << ") is used." << G4endl;
421  }
422  }
423  }
424 }
425 
427 {
428  G4int pdgCode = partDef->GetPDGEncoding();
429  if(pdgCode==0)
430  {
431  G4String partName = partDef->GetParticleName();
432  if(partName=="opticalphoton") return false;
433  if(partName=="geantino") return false;
434  if(partName=="chargedgeantino") return false;
435  }
436  else
437  {
438  if(pdgCode==22) return false; // gamma
439  if(pdgCode==11) return false; // electron
440  if(pdgCode==2212) return false; // proton
441  if(pdgCode==-12) return false; // anti_nu_e
442  if(pdgCode==12) return false; // nu_e
443  if(pdgCode==-14) return false; // anti_nu_mu
444  if(pdgCode==14) return false; // nu_mu
445  if(pdgCode==-16) return false; // anti_nu_tau
446  if(pdgCode==16) return false; // nu_tau
447  }
448  return true;
449 }
450 
void PrepareNewTrack(const G4ThreeVector &position, const G4ThreeVector &direction, G4VPhysicalVolume *massStartVol=0)
static G4PathFinder * GetInstance()
Definition: G4PathFinder.cc:57
G4double condition(const G4ErrorSymMatrix &m)
void SetStepLength(G4double value)
virtual void Initialize(const G4Track &)
G4ProductionCuts * GetProductionCuts() const
void CopyStep(const G4Step &step)
G4VParticleChange * AtRestDoIt(const G4Track &, const G4Step &)
void SetTrack(G4Track *value)
G4int verboseLevel
Definition: G4VProcess.hh:368
G4double GetStepLength() const
G4Material * GetMaterial() const
G4bool IsAtRestRequired(G4ParticleDefinition *)
G4StepStatus GetStepStatus() const
const G4String & GetName() const
Definition: G4Material.hh:178
G4Material * GetMaterial() const
ELimited
G4double GetNonIonizingEnergyDeposit() const
const G4ThreeVector & GetPosition() const
G4Navigator * GetNavigatorForTracking() const
G4TouchableHandle CreateTouchableHandle(G4int navId) const
G4SteppingControl GetControlFlag() const
G4double PostStepGetPhysicalInteractionLength(const G4Track &, G4double, G4ForceCondition *)
G4Region * GetRegion() const
G4VPhysicalVolume * fGhostWorld
#define G4ThreadLocal
Definition: tls.hh:89
G4TouchableHandle fNewGhostTouchable
const G4Step * GetStep() const
int G4int
Definition: G4Types.hh:78
const G4MaterialCutsCouple * GetMaterialCutsCouple() const
void SetStepStatus(const G4StepStatus aValue)
const G4String & GetParticleName() const
G4StepStatus
Definition: G4StepStatus.hh:49
static G4ParallelWorldProcessStore * GetInstance()
G4StepPoint * GetPreStepPoint() const
void SetParallelWorld(G4String parallelWorldName)
void SetSensitiveDetector(G4VSensitiveDetector *)
G4GLOB_DLL std::ostream G4cout
G4int GetCurrentStepNumber() const
static G4ThreadLocal G4int nParallelWorlds
const G4String & GetName() const
void SetControlFlag(G4SteppingControl StepControlFlag)
bool G4bool
Definition: G4Types.hh:79
G4double AtRestGetPhysicalInteractionLength(const G4Track &, G4ForceCondition *)
static G4ThreadLocal G4int fNavIDHyp
void SetParallelWorld(G4ParallelWorldProcess *proc, G4String parallelWorldName)
G4double ComputeStep(const G4FieldTrack &pFieldTrack, G4double pCurrentProposedStepLength, G4int navigatorId, G4int stepNo, G4double &pNewSafety, ELimited &limitedStep, G4FieldTrack &EndState, G4VPhysicalVolume *currentVolume)
G4bool Hit(G4Step *aStep)
Definition: G4Step.hh:76
const G4String & GetProcessName() const
Definition: G4VProcess.hh:408
G4double GetTotalEnergyDeposit() const
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
static G4TransportationManager * GetTransportationManager()
void SwitchMaterial(G4StepPoint *)
static G4ProductionCutsTable * GetProductionCutsTable()
G4VPhysicalVolume * GetParallelWorld(const G4String &worldName)
G4int ActivateNavigator(G4Navigator *aNavigator)
G4VParticleChange * AlongStepDoIt(const G4Track &, const G4Step &)
const G4ThreeVector & GetMomentumDirection() const
G4LogicalVolume * GetLogicalVolume() const
const G4MaterialCutsCouple * GetMaterialCutsCouple(G4int i) const
G4Navigator * GetNavigator(const G4String &worldName)
virtual G4VPhysicalVolume * GetVolume(G4int depth=0) const
Definition: G4VTouchable.cc:44
G4VParticleChange aDummyParticleChange
G4StepPoint * GetPostStepPoint() const
void SetNonIonizingEnergyDeposit(G4double value)
G4VParticleChange * pParticleChange
Definition: G4VProcess.hh:283
G4VPhysicalVolume * GetVolume() const
G4ParallelWorldProcess(const G4String &processName="ParaWorld", G4ProcessType theType=fParameterisation)
void SetPushVerbosity(G4bool mode)
#define G4endl
Definition: G4ios.hh:61
void SetTotalEnergyDeposit(G4double value)
G4VSensitiveDetector * GetSensitiveDetector() const
void SetMaterial(G4Material *)
double G4double
Definition: G4Types.hh:76
G4VParticleChange * PostStepDoIt(const G4Track &, const G4Step &)
G4double AlongStepGetPhysicalInteractionLength(const G4Track &, G4double, G4double, G4double &, G4GPILSelection *)
G4TouchableHandle fOldGhostTouchable
virtual G4double ComputeSafety(const G4ThreeVector &globalpoint, const G4double pProposedMaxLength=DBL_MAX, const G4bool keepState=true)
G4ForceCondition
G4Track * GetTrack() const
void SetTouchableHandle(const G4TouchableHandle &apValue)
static G4ThreadLocal G4Step * fpHyperStep
void SetMaterialCutsCouple(const G4MaterialCutsCouple *)
G4ProductionCuts * GetProductionCuts() const
#define DBL_MAX
Definition: templates.hh:83
G4VSensitiveDetector * GetSensitiveDetector() const
G4TransportationManager * fTransportationManager
const G4TouchableHandle & GetTouchableHandle() const
static void Update(G4FieldTrack *, const G4Track *)
static const G4Step * GetHyperStep()
G4GPILSelection
G4ProcessType