ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4WeightCutOffProcess.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4WeightCutOffProcess.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 // G4WeightCutOffProcess.cc
32 //
33 // ----------------------------------------------------------------------
34 
35 #include "G4WeightCutOffProcess.hh"
36 //#include "G4VScorer.hh"
37 #include "G4GeometryCellStep.hh"
38 //#include "G4GCellFinder.hh"
39 #include "G4TouchableHandle.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 
55  G4double wlimit,
56  G4double isource,
57  G4VIStore *istore,
58  // const G4VGCellFinder &aGCellFinder,
59  const G4String &aName, G4bool para)
60  : G4VProcess(aName),
61  fParticleChange(new G4ParticleChange),
62  fWeightSurvival(wsurvival),
63  fWeightLimit(wlimit),
64  fSourceImportance(isource),
65  fIStore(istore),
66  // fGCellFinder(aGCellFinder),
67  fGhostWorldName("NoParallelWorld"), fGhostWorld(0),
68  fGhostNavigator(0), fNavigatorID(-1), fFieldTrack('0'),
69  fParaflag(para), fEndTrack('0'), feLimited(kDoNot)
70 {
71  if (!fParticleChange)
72  {
73  G4Exception("G4WeightCutOffProcess::G4WeightCutOffProcess()",
74  "FatalError", FatalException,
75  "Failed to allocate G4ParticleChange !");
76  }
77 
79 
80  fGhostStep = new G4Step();
83 
86 
87  if (verboseLevel>0)
88  {
89  G4cout << GetProcessName() << " is created " << G4endl;
90  }
91 }
92 
94 {
95  delete fParticleChange;
96  // delete fGhostStep;
97 }
98 
99 
100 //------------------------------------------------------
101 //
102 // SetParallelWorld
103 //
104 //------------------------------------------------------
106 SetParallelWorld(const G4String &parallelWorldName)
107 {
108 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
109 // Get pointers of the parallel world and its navigator
110 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
111  fGhostWorldName = parallelWorldName;
114 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
115 }
116 
119 {
120 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
121 // Get pointer of navigator
122 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
123  fGhostWorldName = parallelWorld->GetName();
124  fGhostWorld = parallelWorld;
126 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
127 }
128 
129 //------------------------------------------------------
130 //
131 // StartTracking
132 //
133 //------------------------------------------------------
135 {
136 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
137 // Activate navigator and get the navigator ID
138 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
139 // G4cout << " G4ParallelWorldScoringProcess::StartTracking" << G4endl;
140 
141  if(fParaflag) {
142  if(fGhostNavigator)
144  else
145  {
146  G4Exception("G4WeightCutOffProcess::StartTracking",
147  "ProcParaWorld000",FatalException,
148  "G4WeightCutOffProcess is used for tracking without having a parallel world assigned");
149  }
150 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
151 
152 // G4cout << "G4ParallelWorldScoringProcess::StartTracking <<<<<<<<<<<<<<<<<< " << G4endl;
153 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
154 // Let PathFinder initialize
155 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
157 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
158 
159 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
160 // Setup initial touchables for the first step
161 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
166 
167  // Initialize
168  fGhostSafety = -1.;
169  fOnBoundary = false;
170  }
171 }
172 
173 
177 {
178 // *condition = Forced;
179 // return kInfinity;
180 
181 // *condition = StronglyForced;
182  *condition = Forced;
183  return DBL_MAX;
184 }
185 
188  const G4Step &aStep)
189 {
190  fParticleChange->Initialize(aTrack);
191 
192  if(fParaflag) {
194  //xbug? fOnBoundary = false;
195  CopyStep(aStep);
196 
197  if(fOnBoundary)
198  {
199 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
200 // Locate the point and get new touchable
201 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
202  //?? fPathFinder->Locate(step.GetPostStepPoint()->GetPosition(),
203  //?? step.GetPostStepPoint()->GetMomentumDirection());
205 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
206  }
207  else
208  {
209  // Do I need this ??????????????????????????????????????????????????????????
210  // fGhostNavigator->LocateGlobalPointWithinVolume(track.GetPosition());
211  // ?????????????????????????????????????????????????????????????????????????
212 
213  // fPathFinder->ReLocate(track.GetPosition());
214 
215  // reuse the touchable
217  }
218 
221 
222  }
223 
224  if(fParaflag) {
227 
228 
229  // G4GeometryCell postCell = fGCellFinder.GetPostGeometryCell(aStep);
230  // G4GeometryCell postCell = fGCellFinder.GetPostGeometryCell(fGhostStep);
232  if (fIStore)
233  {
234  G4double i = fIStore->GetImportance(postCell);
235  if (i>0)
236  {
237  R/=i;
238  }
239  }
240  G4double w = aTrack.GetWeight();
241  if (w<R*fWeightLimit)
242  {
244  G4double p = w/(ws);
245  if (G4UniformRand()<p)
246  {
248  }
249  else
250  {
252  }
253  }
254  } else {
255 
256  G4GeometryCell postCell(*(aStep.GetPostStepPoint()->GetPhysicalVolume()),
258 
259  // G4GeometryCell postCell = fGCellFinder.GetPostGeometryCell(aStep);
260  // G4GeometryCell postCell = fGCellFinder.GetPostGeometryCell(fGhostStep);
262  if (fIStore)
263  {
264  G4double i = fIStore->GetImportance(postCell);
265  if (i>0)
266  {
267  R/=i;
268  }
269  }
270  G4double w = aTrack.GetWeight();
271  if (w<R*fWeightLimit)
272  {
274  G4double p = w/(ws);
275  if (G4UniformRand()<p)
276  {
278  }
279  else
280  {
282  }
283  }
284  }
285 
286  return fParticleChange;
287 
288 }
289 
291 {
292  return theProcessName;
293 }
294 
297  const G4Track& track, G4double previousStepSize, G4double currentMinimumStep,
298  G4double& proposedSafety, G4GPILSelection* selection)
299 {
300  if(fParaflag) {
301 
302  *selection = NotCandidateForSelection;
303  G4double returnedStep = DBL_MAX;
304 
305  if (previousStepSize > 0.)
306  { fGhostSafety -= previousStepSize; }
307  // else
308  // { fGhostSafety = -1.; }
309  if (fGhostSafety < 0.) fGhostSafety = 0.0;
310 
311  // ------------------------------------------
312  // Determination of the proposed STEP LENGTH:
313  // ------------------------------------------
314  if (currentMinimumStep <= fGhostSafety && currentMinimumStep > 0.)
315  {
316  // I have no chance to limit
317  returnedStep = currentMinimumStep;
318  fOnBoundary = false;
319  proposedSafety = fGhostSafety - currentMinimumStep;
320  }
321  else // (currentMinimumStep > fGhostSafety: I may limit the Step)
322  {
324  //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
325  // ComputeStep
326  //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
327  returnedStep
328  = fPathFinder->ComputeStep(fFieldTrack,currentMinimumStep,fNavigatorID,
330  fEndTrack,track.GetVolume());
331  //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
332  if(feLimited == kDoNot)
333  {
334  // Track is not on the boundary
335  fOnBoundary = false;
336  fGhostSafety = fGhostNavigator->ComputeSafety(fEndTrack.GetPosition());
337  }
338  else
339  {
340  // Track is on the boundary
341  fOnBoundary = true;
342  proposedSafety = fGhostSafety;
343  }
344  //xbug? proposedSafety = fGhostSafety;
345  if(feLimited == kUnique || feLimited == kSharedOther) {
346  *selection = CandidateForSelection;
347  }else if (feLimited == kSharedTransport) {
348  returnedStep *= (1.0 + 1.0e-9);
349  // Expand to disable its selection in Step Manager comparison
350  }
351 
352  }
353 
354  // ----------------------------------------------
355  // Returns the fGhostSafety as the proposedSafety
356  // The SteppingManager will take care of keeping
357  // the smallest one.
358  // ----------------------------------------------
359  return returnedStep;
360 
361  } else {
362  return DBL_MAX;
363  //not sensible! return -1.0;
364  }
365 
366 }
367 
368 
372 {
373  return -1.0;
374 }
375 
378 {
379  return 0;
380 }
381 
384 {
385  // Dummy ParticleChange ie: does nothing
386  // Expecting G4Transportation to move the track
387  pParticleChange->Initialize(track);
388  return pParticleChange;
389 
390  // return 0;
391 }
392 
394 {
395  fGhostStep->SetTrack(step.GetTrack());
399 
400  *fGhostPreStepPoint = *(step.GetPreStepPoint());
402 
403 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
404 // Set StepStatus for ghost world
405 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
406  if(fOnBoundary)
410 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
411 }