ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4ImportanceProcess.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4ImportanceProcess.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 // GEANT 4 class source file
30 //
31 // G4ImportanceProcess.cc
32 //
33 // ----------------------------------------------------------------------
34 
35 #include "G4ImportanceProcess.hh"
37 #include "G4GeometryCell.hh"
39 #include "G4VTrackTerminator.hh"
40 #include "G4VIStore.hh"
41 
42 #include "G4Step.hh"
43 #include "G4Navigator.hh"
44 #include "G4VTouchable.hh"
45 #include "G4VPhysicalVolume.hh"
46 #include "G4ParticleChange.hh"
47 #include "G4PathFinder.hh"
49 #include "G4StepPoint.hh"
50 #include "G4FieldTrackUpdator.hh"
51 
52 
54 G4ImportanceProcess(const G4VImportanceAlgorithm &aImportanceAlgorithm,
55  const G4VIStore &aIstore,
56  const G4VTrackTerminator *TrackTerminator,
57  const G4String &aName, G4bool para)
58  : G4VProcess(aName),
59  fParticleChange(new G4ParticleChange),
60  fImportanceAlgorithm(aImportanceAlgorithm),
61  fIStore(aIstore),
62  fPostStepAction(0),
63  fGhostWorldName("NoParallelWorld"),fGhostWorld(0),
64  fGhostNavigator(0), fNavigatorID(-1), fFieldTrack('0'),
65  fParaflag(para), fEndTrack('0'), feLimited(kDoNot)
66 {
67  G4cout << G4endl << G4endl << G4endl;
68  G4cout << "G4ImportanceProcess:: Creating " << G4endl;
69  if (TrackTerminator)
70  {
71  fPostStepAction = new G4SamplingPostStepAction(*TrackTerminator);
72  }
73  else
74  {
76  }
77  if (!fParticleChange)
78  {
79  G4Exception("G4ImportanceProcess::G4ImportanceProcess()",
80  "FatalError", FatalException,
81  "Failed allocation of G4ParticleChange !");
82  }
84 
85 
86  fGhostStep = new G4Step();
89 
92 
93  if (verboseLevel>0)
94  {
95  G4cout << GetProcessName() << " is created " << G4endl;
96  }
97 
98  G4cout << "G4ImportanceProcess:: importance process paraflag is: " << fParaflag << G4endl;
99 
100 }
101 
103 {
104 
105  delete fPostStepAction;
106  delete fParticleChange;
107  // delete fGhostStep;
108  // delete fGhostWorld;
109  // delete fGhostNavigator;
110 
111 }
112 
113 
114 
115 //------------------------------------------------------
116 //
117 // SetParallelWorld
118 //
119 //------------------------------------------------------
121 SetParallelWorld(const G4String &parallelWorldName)
122 {
123  G4cout << G4endl << G4endl << G4endl;
124  G4cout << "G4ImportanceProcess:: SetParallelWorld name = " << parallelWorldName << G4endl;
125 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
126 // Get pointers of the parallel world and its navigator
127 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
128  fGhostWorldName = parallelWorldName;
131 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
132 }
133 
134 // void G4ImportanceProcess::
135 // SetParallelWorld(const G4VPhysicalVolume* parallelWorld)
136 // {
137 // //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
138 // // Get pointer of navigator
139 // //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
140 // // G4cout << " G4ImportanceProcess:: Got here 1 " << G4endl;
141 // // fGhostWorldName = parallelWorld->GetName();
142 // // G4cout << " G4ImportanceProcess:: Got here 2 ghostName:" << fGhostWorldName << G4endl;
143 // fGhostWorld = parallelWorld;
144 // G4cout << " G4ImportanceProcess:: Got here 3 " << G4endl;
145 // fGhostNavigator = fTransportationManager->GetNavigator(parallelWorld);
146 // G4cout << " G4ImportanceProcess:: Got here 4 " << G4endl;
147 // //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
148 // }
149 
150 //------------------------------------------------------
151 //
152 // StartTracking
153 //
154 //------------------------------------------------------
156 {
157 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
158 // Activate navigator and get the navigator ID
159 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
160 // G4cout << " G4ParallelWorldScoringProcess::StartTracking" << G4endl;
161 
162  if(fParaflag) {
163  if(fGhostNavigator)
165  else
166  {
167  G4Exception("G4ImportanceProcess::StartTracking",
168  "ProcParaWorld000",FatalException,
169  "G4ImportanceProcess is used for tracking without having a parallel world assigned");
170  }
171 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
172 
173 // G4cout << "G4ParallelWorldScoringProcess::StartTracking <<<<<<<<<<<<<<<<<< " << G4endl;
174 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
175 // Let PathFinder initialize
176 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
178 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
179 
180 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
181 // Setup initial touchables for the first step
182 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
187 
188  // Initialize
189  fGhostSafety = -1.;
190  fOnBoundary = false;
191  }
192 
193 }
194 
195 
198  G4double ,
200 {
201 // *condition = Forced;
202 // return kInfinity;
203 
204 // *condition = StronglyForced;
205  *condition = Forced;
206  return DBL_MAX;
207 }
208 
211  const G4Step &aStep)
212 {
213  fParticleChange->Initialize(aTrack);
214 
215  if(fParaflag) {
217  //xbug? fOnBoundary = false;
218  CopyStep(aStep);
219 
220  if(fOnBoundary)
221  {
222 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
223 // Locate the point and get new touchable
224 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
225  //?? fPathFinder->Locate(step.GetPostStepPoint()->GetPosition(),
226  //?? step.GetPostStepPoint()->GetMomentumDirection());
228  //AH G4cout << " on boundary " << G4endl;
229 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
230  }
231  else
232  {
233  // Do I need this ??????????????????????????????????????????????????????????
234  // fGhostNavigator->LocateGlobalPointWithinVolume(track.GetPosition());
235  // ?????????????????????????????????????????????????????????????????????????
236 
237  // fPathFinder->ReLocate(track.GetPosition());
238 
239  // reuse the touchable
241  //AH G4cout << " NOT on boundary " << G4endl;
242  }
243 
246 
247 // if ( (aStep.GetPostStepPoint()->GetStepStatus() == fGeomBoundary)
248 // && (aStep.GetStepLength() > kCarTolerance) )
249 // {
250 // if (aTrack.GetTrackStatus()==fStopAndKill)
251 // {
252 // G4cout << "WARNING - G4ImportanceProcess::PostStepDoIt()"
253 // << " StopAndKill track." << G4endl;
254 // }
255 
256 // G4StepPoint *prepoint = aStep.GetPreStepPoint();
257 // G4StepPoint *postpoint = aStep.GetPostStepPoint();
258 // G4GeometryCell prekey(*(prepoint->GetPhysicalVolume()),
259 // prepoint->GetTouchable()->GetReplicaNumber());
260 // G4GeometryCell postkey(*(postpoint->GetPhysicalVolume()),
261 // postpoint->GetTouchable()->GetReplicaNumber());
262 
263 
265  && (aStep.GetStepLength() > kCarTolerance) )
266  {
267  if (aTrack.GetTrackStatus()==fStopAndKill)
268  {
269  G4cout << "WARNING - G4ImportanceProcess::PostStepDoIt()"
270  << " StopAndKill track. on boundary" << G4endl;
271  }
272 
277 
278  //AH
279  /*
280  G4cout << G4endl;
281  G4cout << G4endl;
282  G4cout << " inside parallel importance process " << aTrack.GetCurrentStepNumber() << G4endl;
283  G4cout << G4endl;
284  G4cout << G4endl;
285  G4cout << " prekey: " << fGhostPreStepPoint->GetPhysicalVolume()->GetName() << " replica:"
286  << fGhostPreStepPoint->GetTouchable()->GetReplicaNumber() << G4endl;
287  G4cout << " prekey ISTORE: " << fIStore.GetImportance(prekey) << G4endl;
288  G4cout << " postkey: " << G4endl;
289  G4cout << " postkey ISTORE: " << fIStore.GetImportance(postkey) << G4endl;
290  */
291  //AH
293  Calculate(fIStore.GetImportance(prekey),
294  fIStore.GetImportance(postkey),
295  aTrack.GetWeight());
296  //AH
297  /*
298  G4cout << " prekey weight: " << fIStore.GetImportance(prekey)
299  << " postkey weight: " << fIStore.GetImportance(postkey)
300  << " split weight: " << nw << G4endl;
301  G4cout << " before poststepaction " << G4endl;
302  */
303  //AH
304  fPostStepAction->DoIt(aTrack, fParticleChange, nw);
305  //AH G4cout << " after post step do it " << G4endl;
306  }
307  } else {
308  if ( (aStep.GetPostStepPoint()->GetStepStatus() == fGeomBoundary)
309  && (aStep.GetStepLength() > kCarTolerance) )
310  {
311  //AH G4cout << " inside non-parallel importance process " << G4endl;
312  if (aTrack.GetTrackStatus()==fStopAndKill)
313  {
314  G4cout << "WARNING - G4ImportanceProcess::PostStepDoIt()"
315  << " StopAndKill track. on boundary non-parallel" << G4endl;
316  }
317 
318  G4StepPoint *prepoint = aStep.GetPreStepPoint();
319  G4StepPoint *postpoint = aStep.GetPostStepPoint();
320 
321  G4GeometryCell prekey(*(prepoint->GetPhysicalVolume()),
322  prepoint->GetTouchable()->GetReplicaNumber());
323  G4GeometryCell postkey(*(postpoint->GetPhysicalVolume()),
324  postpoint->GetTouchable()->GetReplicaNumber());
325 
327  Calculate(fIStore.GetImportance(prekey),
328  fIStore.GetImportance(postkey),
329  aTrack.GetWeight());
330  //AH
331  /*
332  G4cout << " prekey weight: " << fIStore.GetImportance(prekey)
333  << " postkey weight: " << fIStore.GetImportance(postkey)
334  << " split weight: " << nw << G4endl;
335  G4cout << " before poststepaction 2 " << G4endl;
336  */
337  //AH
338  fPostStepAction->DoIt(aTrack, fParticleChange, nw);
339  //AH G4cout << " after poststepaction 2 " << G4endl;
340  }
341  }
342  return fParticleChange;
343 }
344 
346 {
348 }
349 
351 {
352  return theProcessName;
353 }
354 
357  const G4Track& track, G4double previousStepSize, G4double currentMinimumStep,
358  G4double& proposedSafety, G4GPILSelection* selection)
359 {
360  if(fParaflag) {
361  *selection = NotCandidateForSelection;
362  G4double returnedStep = DBL_MAX;
363 
364  if (previousStepSize > 0.)
365  { fGhostSafety -= previousStepSize; }
366  // else
367  // { fGhostSafety = -1.; }
368  if (fGhostSafety < 0.) fGhostSafety = 0.0;
369 
370  // ------------------------------------------
371  // Determination of the proposed STEP LENGTH:
372  // ------------------------------------------
373  if (currentMinimumStep <= fGhostSafety && currentMinimumStep > 0.)
374  {
375  // I have no chance to limit
376  returnedStep = currentMinimumStep;
377  fOnBoundary = false;
378  proposedSafety = fGhostSafety - currentMinimumStep;
379  //AH G4cout << " step not limited, why? " << G4endl;
380  }
381  else // (currentMinimumStep > fGhostSafety: I may limit the Step)
382  {
384  //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
385  // ComputeStep
386  //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
387  returnedStep
388  = fPathFinder->ComputeStep(fFieldTrack,currentMinimumStep,fNavigatorID,
390  fEndTrack,track.GetVolume());
391  //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
392  if(feLimited == kDoNot)
393  {
394  //AH G4cout << " computestep came back with not-boundary " << G4endl;
395  // Track is not on the boundary
396  fOnBoundary = false;
397  fGhostSafety = fGhostNavigator->ComputeSafety(fEndTrack.GetPosition());
398  }
399  else
400  {
401  // Track is on the boundary
402  //AH G4cout << " FOUND A BOUNDARY ! " << track.GetCurrentStepNumber() << G4endl;
403  fOnBoundary = true;
404  // proposedSafety = fGhostSafety;
405  }
406  proposedSafety = fGhostSafety;
407  if(feLimited == kUnique || feLimited == kSharedOther) {
408  *selection = CandidateForSelection;
409  }else if (feLimited == kSharedTransport) {
410  returnedStep *= (1.0 + 1.0e-9);
411  // Expand to disable its selection in Step Manager comparison
412  }
413 
414  }
415 
416  // ----------------------------------------------
417  // Returns the fGhostSafety as the proposedSafety
418  // The SteppingManager will take care of keeping
419  // the smallest one.
420  // ----------------------------------------------
421  return returnedStep;
422 
423  } else {
424 
425  return DBL_MAX;
426 
427  }
428 
429 }
430 
434 {
435  return -1.0;
436 }
437 
439 AtRestDoIt(const G4Track&, const G4Step&)
440 {
441  return 0;
442 }
443 
445 AlongStepDoIt(const G4Track& aTrack, const G4Step& )
446 {
447  // Dummy ParticleChange ie: does nothing
448  // Expecting G4Transportation to move the track
449  //AH G4cout << " along step do it " << G4endl;
450  pParticleChange->Initialize(aTrack);
451  return pParticleChange;
452  // return 0;
453 }
454 
456 {
457  fGhostStep->SetTrack(step.GetTrack());
461 
462  *fGhostPreStepPoint = *(step.GetPreStepPoint());
464 
465 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
466 // Set StepStatus for ghost world
467 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
468  if(fOnBoundary)
472 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
473 }