ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4WeightWindowProcess.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4WeightWindowProcess.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 // G4WeightWindowProcess.cc
32 //
33 // ----------------------------------------------------------------------
34 
35 #include "G4WeightWindowProcess.hh"
37 #include "G4GeometryCell.hh"
39 #include "G4VTrackTerminator.hh"
40 #include "G4PlaceOfAction.hh"
41 #include "G4VWeightWindowStore.hh"
42 
43 #include "G4Step.hh"
44 #include "G4Navigator.hh"
45 #include "G4VTouchable.hh"
46 #include "G4VPhysicalVolume.hh"
47 #include "G4ParticleChange.hh"
48 #include "G4PathFinder.hh"
50 #include "G4StepPoint.hh"
51 #include "G4FieldTrackUpdator.hh"
52 
53 
55  const G4VWeightWindowAlgorithm &aWeightWindowAlgorithm,
56  const G4VWeightWindowStore &aWWStore,
57  const G4VTrackTerminator *TrackTerminator,
58  G4PlaceOfAction placeOfAction,
59  const G4String &aName, G4bool para)
60  : G4VProcess(aName),
61  fParticleChange(new G4ParticleChange),
62  fWeightWindowAlgorithm(aWeightWindowAlgorithm),
63  fWeightWindowStore(aWWStore),
64  fPostStepAction(0),
65  fPlaceOfAction(placeOfAction),
66  fGhostWorldName("NoParallelWorld"),fGhostWorld(0),
67  fGhostNavigator(0), fNavigatorID(-1), fFieldTrack('0'),
68  fParaflag(), fEndTrack('0'), feLimited(kDoNot)
69 {
70  if (TrackTerminator)
71  {
72  fPostStepAction = new G4SamplingPostStepAction(*TrackTerminator);
73  }
74  else
75  {
77  }
78  if (!fParticleChange)
79  {
80  G4Exception("G4WeightWindowProcess::G4WeightWindowProcess()",
81  "FatalError", FatalException,
82  "Failed allocation of G4ParticleChange !");
83  }
85 
86  fGhostStep = new G4Step();
89 
92 
93  if (verboseLevel>0)
94  {
95  G4cout << GetProcessName() << " is created " << G4endl;
96  }
97 
98  fParaflag = para;
99 
100 }
101 
103 {
104 
105  delete fPostStepAction;
106  delete fParticleChange;
107  // delete fGhostStep;
108 
109 }
110 
111 
112 //------------------------------------------------------
113 //
114 // SetParallelWorld
115 //
116 //------------------------------------------------------
118 SetParallelWorld(const G4String &parallelWorldName)
119 {
120 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
121 // Get pointers of the parallel world and its navigator
122 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
123  fGhostWorldName = parallelWorldName;
126 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
127 }
128 
131 {
132 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
133 // Get pointer of navigator
134 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
135  fGhostWorldName = parallelWorld->GetName();
136  fGhostWorld = parallelWorld;
138 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
139 }
140 
141 //------------------------------------------------------
142 //
143 // StartTracking
144 //
145 //------------------------------------------------------
147 {
148 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
149 // Activate navigator and get the navigator ID
150 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
151 // G4cout << " G4ParallelWorldScoringProcess::StartTracking" << G4endl;
152 
153  if(fParaflag) {
154  if(fGhostNavigator)
156  else
157  {
158  G4Exception("G4WeightWindowProcess::StartTracking",
159  "ProcParaWorld000",FatalException,
160  "G4WeightWindowProcess is used for tracking without having a parallel world assigned");
161  }
162 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
163 
164 // G4cout << "G4ParallelWorldScoringProcess::StartTracking <<<<<<<<<<<<<<<<<< " << G4endl;
165 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
166 // Let PathFinder initialize
167 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
169 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
170 
171 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
172 // Setup initial touchables for the first step
173 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
178 
179  // Initialize
180  fGhostSafety = -1.;
181  fOnBoundary = false;
182  }
183 }
184 
185 
188  G4double ,
190 {
191 // *condition = Forced;
192 // return kInfinity;
193 
194 // *condition = StronglyForced;
195  *condition = Forced;
196  return DBL_MAX;
197 }
198 
201  const G4Step &aStep)
202 {
203 
204  fParticleChange->Initialize(aTrack);
205 
206  if(fParaflag) {
208  //xbug? fOnBoundary = false;
209  CopyStep(aStep);
210 
211  if(fOnBoundary)
212  {
213 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
214 // Locate the point and get new touchable
215 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
216  //?? fPathFinder->Locate(step.GetPostStepPoint()->GetPosition(),
217  //?? step.GetPostStepPoint()->GetMomentumDirection());
219 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
220  }
221  else
222  {
223  // Do I need this ??????????????????????????????????????????????????????????
224  // fGhostNavigator->LocateGlobalPointWithinVolume(track.GetPosition());
225  // ?????????????????????????????????????????????????????????????????????????
226 
227  // fPathFinder->ReLocate(track.GetPosition());
228 
229  // reuse the touchable
231  }
232 
235 
236  }
237 
238  if (aStep.GetStepLength() > kCarTolerance)
239  {
240 // if ( ( fPlaceOfAction == onBoundaryAndCollision)
241 // || ( (fPlaceOfAction == onBoundary) &&
242 // (aStep.GetPostStepPoint()->GetStepStatus() == fGeomBoundary) )
243 // || ( (fPlaceOfAction == onCollision) &&
244 // (aStep.GetPostStepPoint()->GetStepStatus() != fGeomBoundary) ) )
245  if(fParaflag) {
247  || ( (fPlaceOfAction == onBoundary) &&
249  || ( (fPlaceOfAction == onCollision) &&
251  {
252 
253 // G4StepPoint *postpoint = aStep.GetPostStepPoint();
254 
255 // G4GeometryCell postCell(*(postpoint->GetPhysicalVolume()),
256 // postpoint->GetTouchable()->GetReplicaNumber());
257 
260  G4Nsplit_Weight nw =
263  aTrack.GetKineticEnergy()));
264  fPostStepAction->DoIt(aTrack, fParticleChange, nw);
265  }
266  } else {
268  || ( (fPlaceOfAction == onBoundary) &&
270  || ( (fPlaceOfAction == onCollision) &&
271  (aStep.GetPostStepPoint()->GetStepStatus() != fGeomBoundary) ) )
272  {
273 
274  G4StepPoint *postpoint = aStep.GetPostStepPoint();
275 
276  G4GeometryCell postCell(*(postpoint->GetPhysicalVolume()),
277  postpoint->GetTouchable()->GetReplicaNumber());
278 
279  G4Nsplit_Weight nw =
282  aTrack.GetKineticEnergy()));
283  fPostStepAction->DoIt(aTrack, fParticleChange, nw);
284  }
285  }
286  }
287  return fParticleChange;
288 }
289 
291 {
293 }
294 
296 {
298 }
299 
302  const G4Track& track, G4double previousStepSize, G4double currentMinimumStep,
303  G4double& proposedSafety, G4GPILSelection* selection)
304 {
305  if(fParaflag)
306  {
307  *selection = NotCandidateForSelection;
308  G4double returnedStep = DBL_MAX;
309 
310  if (previousStepSize > 0.)
311  { fGhostSafety -= previousStepSize; }
312  // else
313  // { fGhostSafety = -1.; }
314  if (fGhostSafety < 0.) fGhostSafety = 0.0;
315 
316  // ------------------------------------------
317  // Determination of the proposed STEP LENGTH:
318  // ------------------------------------------
319  if (currentMinimumStep <= fGhostSafety && currentMinimumStep > 0.)
320  {
321  // I have no chance to limit
322  returnedStep = currentMinimumStep;
323  fOnBoundary = false;
324  proposedSafety = fGhostSafety - currentMinimumStep;
325  }
326  else // (currentMinimumStep > fGhostSafety: I may limit the Step)
327  {
329  //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
330  // ComputeStep
331  //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
332  returnedStep
333  = fPathFinder->ComputeStep(fFieldTrack,currentMinimumStep,fNavigatorID,
335  fEndTrack,track.GetVolume());
336  //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
337  if(feLimited == kDoNot)
338  {
339  // Track is not on the boundary
340  fOnBoundary = false;
341  fGhostSafety = fGhostNavigator->ComputeSafety(fEndTrack.GetPosition());
342  // fGhostSafety = fGhostNavigator->ComputeSafety(endTrack.GetPosition(), DBL_MAX, true);
343  }
344  else
345  {
346  // Track is on the boundary
347  fOnBoundary = true;
348  proposedSafety = fGhostSafety;
349  }
350  //xbug? proposedSafety = fGhostSafety;
351  if(feLimited == kUnique || feLimited == kSharedOther) {
352  *selection = CandidateForSelection;
353  }else if (feLimited == kSharedTransport) {
354  returnedStep *= (1.0 + 1.0e-9);
355  // Expand to disable its selection in Step Manager comparison
356  }
357 
358  }
359 
360  // ----------------------------------------------
361  // Returns the fGhostSafety as the proposedSafety
362  // The SteppingManager will take care of keeping
363  // the smallest one.
364  // ----------------------------------------------
365  return returnedStep;
366 
367  } else {
368  return DBL_MAX;
369  // not sensible - time goes backwards! return -1.0;
370  }
371 
372 }
373 
377 {
378  return -1.0;
379 }
380 
382 AtRestDoIt(const G4Track&, const G4Step&)
383 {
384  return 0;
385 }
386 
389 {
390  // Dummy ParticleChange ie: does nothing
391  // Expecting G4Transportation to move the track
392  pParticleChange->Initialize(track);
393  return pParticleChange;
394 
395  // return 0;
396 }
397 
399 {
400  fGhostStep->SetTrack(step.GetTrack());
404 
405  *fGhostPreStepPoint = *(step.GetPreStepPoint());
407 
408 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
409 // Set StepStatus for ghost world
410 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
411  if(fOnBoundary)
415 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
416 }