ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4ParallelWorldProcess.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4ParallelWorldProcess.cc
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"
43 #include "G4FieldTrackUpdator.hh"
44 #include "G4Material.hh"
45 #include "G4ProductionCuts.hh"
46 #include "G4ProductionCutsTable.hh"
47 
48 #include "G4SDManager.hh"
49 #include "G4VSensitiveDetector.hh"
50 
55 { return fpHyperStep; }
57 { return fNavIDHyp; }
58 
60 G4ParallelWorldProcess(const G4String& processName,G4ProcessType theType)
61 :G4VProcess(processName,theType),fGhostWorld(nullptr),fGhostNavigator(nullptr),
62  fNavigatorID(-1),fFieldTrack('0'),fGhostSafety(0.),fOnBoundary(false),
63  layeredMaterialFlag(false)
64 {
65  SetProcessSubType(491);
66  if(!fpHyperStep) fpHyperStep = new G4Step();
68 
70 
71  fGhostStep = new G4Step();
74 
78 
79  fGhostWorldName = "** NotDefined **";
81 
82  if (verboseLevel>0)
83  {
84  G4cout << GetProcessName() << " is created " << G4endl;
85  }
86 }
87 
89 {
90  delete fGhostStep;
92  if(nParallelWorlds==0)
93  {
94  delete fpHyperStep;
95  fpHyperStep = 0;
96  }
97 }
98 
100 SetParallelWorld(G4String parallelWorldName)
101 {
102  fGhostWorldName = parallelWorldName;
106 }
107 
110 {
111  fGhostWorldName = parallelWorld->GetName();
112  fGhostWorld = parallelWorld;
115 }
116 
118 {
119  if(fGhostNavigator)
121  else
122  {
123  G4Exception("G4ParallelWorldProcess::StartTracking",
124  "ProcParaWorld000",FatalException,
125  "G4ParallelWorldProcess is used for tracking without having a parallel world assigned");
126  }
128 
133 
134  fGhostSafety = -1.;
135  fOnBoundary = false;
138 
139 // G4VPhysicalVolume* thePhys = fNewGhostTouchable->GetVolume();
140 // if(thePhys)
141 // {
142 // G4Material* ghostMaterial = thePhys->GetLogicalVolume()->GetMaterial();
143 // if(ghostMaterial)
144 // { G4cout << " --- Material : " << ghostMaterial->GetName() << G4endl; }
145 // }
146 
149  {
150  G4StepPoint* realWorldPostStepPoint = trk->GetStep()->GetPostStepPoint();
151  SwitchMaterial(realWorldPostStepPoint);
152  G4StepPoint *realWorldPreStepPoint = trk->GetStep()->GetPreStepPoint();
153  SwitchMaterial(realWorldPreStepPoint);
154  G4double velocity = trk->CalculateVelocity();
155  realWorldPostStepPoint->SetVelocity(velocity);
156  realWorldPreStepPoint->SetVelocity(velocity);
157  trk->SetVelocity(velocity);
158  }
160 }
161 
162 G4double
164  const G4Track& /*track*/,
166 {
167 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
168 // At Rest must be registered ONLY for the particle which has other At Rest
169 // process(es).
170 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
171  *condition = Forced;
172  return DBL_MAX;
173 }
174 
176  const G4Track& track,
177  const G4Step& step)
178 {
179 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
180 // At Rest must be registered ONLY for the particle which has other At Rest
181 // process(es).
182 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
184  G4VSensitiveDetector* aSD = 0;
187  fOnBoundary = false;
188  if(aSD)
189  {
190  CopyStep(step);
192 
194 
198  {
201  }
202  else
204 
205  aSD->Hit(fGhostStep);
206  }
207 
208  pParticleChange->Initialize(track);
209  return pParticleChange;
210 }
211 
212 G4double
214  const G4Track& /*track*/,
215  G4double /*previousStepSize*/,
217 {
218  *condition = StronglyForced;
219  return DBL_MAX;
220 }
221 
223  const G4Track& track,
224  const G4Step& step)
225 {
227  G4VSensitiveDetector* aSD = 0;
230  CopyStep(step);
232 
233  if(fOnBoundary)
234  {
236  }
237  else
238  {
240  }
241 
244 
246  {
249  }
250  else
252 
254  if(sd)
255  {
256  sd->Hit(fGhostStep);
257  }
258 
259  pParticleChange->Initialize(track);
261  {
262  G4StepPoint* realWorldPostStepPoint =
263  ((G4Step*)(track.GetStep()))->GetPostStepPoint();
264  SwitchMaterial(realWorldPostStepPoint);
265  }
266  return pParticleChange;
267 }
268 
270  const G4Track& track, G4double previousStepSize, G4double currentMinimumStep,
271  G4double& proposedSafety, G4GPILSelection* selection)
272 {
273  static G4ThreadLocal G4FieldTrack *endTrack_G4MT_TLS_ = 0 ; if (!endTrack_G4MT_TLS_) endTrack_G4MT_TLS_ = new G4FieldTrack ('0') ; G4FieldTrack &endTrack = *endTrack_G4MT_TLS_;
274  //static ELimited eLimited;
275  ELimited eLimited;
276  ELimited eLim = kUndefLimited;
277 
278  *selection = NotCandidateForSelection;
279  G4double returnedStep = DBL_MAX;
280 
281  if (previousStepSize > 0.)
282  { fGhostSafety -= previousStepSize; }
283  if (fGhostSafety < 0.) fGhostSafety = 0.0;
284 
285  if (currentMinimumStep <= fGhostSafety && currentMinimumStep > 0.)
286  {
287  // I have no chance to limit
288  returnedStep = currentMinimumStep;
289  fOnBoundary = false;
290  proposedSafety = fGhostSafety - currentMinimumStep;
291  eLim = kDoNot;
292  }
293  else
294  {
296 
297 #ifdef G4DEBUG_PARALLEL_WORLD_PROCESS
298  if( verboseLevel > 0 ){
299  int localVerb = verboseLevel-1;
300 
301  if( localVerb == 1 ) {
302  G4cout << " Pll Wrl proc::AlongStepGPIL " << this->GetProcessName() << G4endl;
303  }else if( localVerb > 1 ) {
304  G4cout << "----------------------------------------------" << G4endl;
305  G4cout << " ParallelWorldProcess: field Track set to : " << G4endl;
306  G4cout << "----------------------------------------------" << G4endl;
307  G4cout << fFieldTrack << G4endl;
308  G4cout << "----------------------------------------------" << G4endl;
309  }
310  }
311 #endif
312 
313  returnedStep
314  = fPathFinder->ComputeStep(fFieldTrack,currentMinimumStep,fNavigatorID,
315  track.GetCurrentStepNumber(),fGhostSafety,eLimited,
316  endTrack,track.GetVolume());
317  if(eLimited == kDoNot)
318  {
319  fOnBoundary = false;
320  fGhostSafety = fGhostNavigator->ComputeSafety(endTrack.GetPosition());
321  }
322  else
323  {
324  fOnBoundary = true;
325  // fGhostSafetyEnd = 0.0; // At end-point of expected step only
326  }
327  proposedSafety = fGhostSafety;
328  if(eLimited == kUnique || eLimited == kSharedOther) {
329  *selection = CandidateForSelection;
330  }
331  else if (eLimited == kSharedTransport) {
332  returnedStep *= (1.0 + 1.0e-9);
333  }
334  eLim = eLimited;
335  }
336 
338  if(eLim == kUnique || eLim == kSharedOther) fNavIDHyp = fNavigatorID;
339  return returnedStep;
340 }
341 
343  const G4Track& track, const G4Step& )
344 {
345  pParticleChange->Initialize(track);
346  return pParticleChange;
347 }
348 
350 {
352 
353  fGhostStep->SetTrack(step.GetTrack());
358  fGhostStep->SetSecondary((const_cast<G4Step&>(step)).GetfSecondary());
359 
360  *fGhostPreStepPoint = *(step.GetPreStepPoint());
362 
364  if(fOnBoundary)
368 
369  if(iParallelWorld==1)
370  {
372 
373  fpHyperStep->SetTrack(step.GetTrack());
378 
381 
382  fpHyperStep->GetPreStepPoint()->SetStepStatus(prevStatHyp);
383  }
384 
385  if(fOnBoundary)
387 }
388 
390 {
391  if(realWorldStepPoint->GetStepStatus()==fWorldBoundary) return;
393  if(thePhys)
394  {
395  G4Material* ghostMaterial = thePhys->GetLogicalVolume()->GetMaterial();
396  if(ghostMaterial)
397  {
398  G4Region* ghostRegion = thePhys->GetLogicalVolume()->GetRegion();
399  G4ProductionCuts* prodCuts =
400  realWorldStepPoint->GetMaterialCutsCouple()->GetProductionCuts();
401  if(ghostRegion)
402  {
403  G4ProductionCuts* ghostProdCuts = ghostRegion->GetProductionCuts();
404  if(ghostProdCuts) prodCuts = ghostProdCuts;
405  }
406  const G4MaterialCutsCouple* ghostMCCouple =
408  ->GetMaterialCutsCouple(ghostMaterial,prodCuts);
409  if(ghostMCCouple)
410  {
411  realWorldStepPoint->SetMaterial(ghostMaterial);
412  realWorldStepPoint->SetMaterialCutsCouple(ghostMCCouple);
414  fpHyperStep->GetPostStepPoint()->SetMaterial(ghostMaterial);
416  }
417  else
418  {
419  G4cout << "!!! MaterialCutsCouple is not found for "
420  << ghostMaterial->GetName() << "." << G4endl
421  << " Material in real world ("
422  << realWorldStepPoint->GetMaterial()->GetName()
423  << ") is used." << G4endl;
424  }
425  }
426  }
427 }
428 
430 {
431  G4int pdgCode = partDef->GetPDGEncoding();
432  if(pdgCode==0)
433  {
434  G4String partName = partDef->GetParticleName();
435  if(partName=="opticalphoton") return false;
436  if(partName=="geantino") return false;
437  if(partName=="chargedgeantino") return false;
438  }
439  else
440  {
441  if(pdgCode==22) return false; // gamma
442  if(pdgCode==11) return false; // electron
443  if(pdgCode==2212) return false; // proton
444  if(pdgCode==-12) return false; // anti_nu_e
445  if(pdgCode==12) return false; // nu_e
446  if(pdgCode==-14) return false; // anti_nu_mu
447  if(pdgCode==14) return false; // nu_mu
448  if(pdgCode==-16) return false; // anti_nu_tau
449  if(pdgCode==16) return false; // nu_tau
450  }
451  return true;
452 }
453