Geant4  10.03.p03
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4WeightWindowProcess.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: G4WeightWindowProcess.cc 88804 2015-03-10 17:12:21Z gcosmo $
28 //
29 // ----------------------------------------------------------------------
30 // GEANT 4 class source file
31 //
32 // G4WeightWindowProcess.cc
33 //
34 // ----------------------------------------------------------------------
35 
36 #include "G4WeightWindowProcess.hh"
38 #include "G4GeometryCell.hh"
40 #include "G4VTrackTerminator.hh"
41 #include "G4PlaceOfAction.hh"
42 #include "G4VWeightWindowStore.hh"
43 
44 #include "G4Step.hh"
45 #include "G4Navigator.hh"
46 #include "G4VTouchable.hh"
47 #include "G4VPhysicalVolume.hh"
48 #include "G4ParticleChange.hh"
49 #include "G4PathFinder.hh"
51 #include "G4StepPoint.hh"
52 #include "G4FieldTrackUpdator.hh"
53 
54 
56  const G4VWeightWindowAlgorithm &aWeightWindowAlgorithm,
57  const G4VWeightWindowStore &aWWStore,
58  const G4VTrackTerminator *TrackTerminator,
59  G4PlaceOfAction placeOfAction,
60  const G4String &aName, G4bool para)
61  : G4VProcess(aName),
62  fParticleChange(new G4ParticleChange),
63  fWeightWindowAlgorithm(aWeightWindowAlgorithm),
64  fWeightWindowStore(aWWStore),
65  fPostStepAction(0),
66  fPlaceOfAction(placeOfAction),
67  fGhostWorldName("NoParallelWorld"),fGhostWorld(0),
68  fGhostNavigator(0), fNavigatorID(-1), fFieldTrack('0'),
69  fParaflag(), fEndTrack('0'), feLimited(kDoNot)
70 {
71  if (TrackTerminator)
72  {
73  fPostStepAction = new G4SamplingPostStepAction(*TrackTerminator);
74  }
75  else
76  {
77  fPostStepAction = new G4SamplingPostStepAction(*this);
78  }
79  if (!fParticleChange)
80  {
81  G4Exception("G4WeightWindowProcess::G4WeightWindowProcess()",
82  "FatalError", FatalException,
83  "Failed allocation of G4ParticleChange !");
84  }
85  G4VProcess::pParticleChange = fParticleChange;
86 
87  fGhostStep = new G4Step();
88  fGhostPreStepPoint = fGhostStep->GetPreStepPoint();
89  fGhostPostStepPoint = fGhostStep->GetPostStepPoint();
90 
91  fTransportationManager = G4TransportationManager::GetTransportationManager();
92  fPathFinder = G4PathFinder::GetInstance();
93 
94  if (verboseLevel>0)
95  {
96  G4cout << GetProcessName() << " is created " << G4endl;
97  }
98 
99  fParaflag = para;
100 
101 }
102 
104 {
105 
106  delete fPostStepAction;
107  delete fParticleChange;
108  // delete fGhostStep;
109 
110 }
111 
112 
113 //------------------------------------------------------
114 //
115 // SetParallelWorld
116 //
117 //------------------------------------------------------
119 SetParallelWorld(const G4String &parallelWorldName)
120 {
121 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
122 // Get pointers of the parallel world and its navigator
123 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
124  fGhostWorldName = parallelWorldName;
125  fGhostWorld = fTransportationManager->GetParallelWorld(fGhostWorldName);
126  fGhostNavigator = fTransportationManager->GetNavigator(fGhostWorld);
127 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
128 }
129 
132 {
133 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
134 // Get pointer of navigator
135 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
136  fGhostWorldName = parallelWorld->GetName();
137  fGhostWorld = parallelWorld;
138  fGhostNavigator = fTransportationManager->GetNavigator(fGhostWorld);
139 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
140 }
141 
142 //------------------------------------------------------
143 //
144 // StartTracking
145 //
146 //------------------------------------------------------
148 {
149 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
150 // Activate navigator and get the navigator ID
151 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
152 // G4cout << " G4ParallelWorldScoringProcess::StartTracking" << G4endl;
153 
154  if(fParaflag) {
155  if(fGhostNavigator)
156  { fNavigatorID = fTransportationManager->ActivateNavigator(fGhostNavigator); }
157  else
158  {
159  G4Exception("G4WeightWindowProcess::StartTracking",
160  "ProcParaWorld000",FatalException,
161  "G4WeightWindowProcess is used for tracking without having a parallel world assigned");
162  }
163 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
164 
165 // G4cout << "G4ParallelWorldScoringProcess::StartTracking <<<<<<<<<<<<<<<<<< " << G4endl;
166 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
167 // Let PathFinder initialize
168 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
169  fPathFinder->PrepareNewTrack(trk->GetPosition(),trk->GetMomentumDirection());
170 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
171 
172 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
173 // Setup initial touchables for the first step
174 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
175  fOldGhostTouchable = fPathFinder->CreateTouchableHandle(fNavigatorID);
176  fGhostPreStepPoint->SetTouchableHandle(fOldGhostTouchable);
177  fNewGhostTouchable = fOldGhostTouchable;
178  fGhostPostStepPoint->SetTouchableHandle(fNewGhostTouchable);
179 
180  // Initialize
181  fGhostSafety = -1.;
182  fOnBoundary = false;
183  }
184 }
185 
186 
189  G4double ,
191 {
192 // *condition = Forced;
193 // return kInfinity;
194 
195 // *condition = StronglyForced;
196  *condition = Forced;
197  return DBL_MAX;
198 }
199 
202  const G4Step &aStep)
203 {
204 
205  fParticleChange->Initialize(aTrack);
206 
207  if(fParaflag) {
208  fOldGhostTouchable = fGhostPostStepPoint->GetTouchableHandle();
209  //xbug? fOnBoundary = false;
210  CopyStep(aStep);
211 
212  if(fOnBoundary)
213  {
214 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
215 // Locate the point and get new touchable
216 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
217  //?? fPathFinder->Locate(step.GetPostStepPoint()->GetPosition(),
218  //?? step.GetPostStepPoint()->GetMomentumDirection());
219  fNewGhostTouchable = fPathFinder->CreateTouchableHandle(fNavigatorID);
220 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
221  }
222  else
223  {
224  // Do I need this ??????????????????????????????????????????????????????????
225  // fGhostNavigator->LocateGlobalPointWithinVolume(track.GetPosition());
226  // ?????????????????????????????????????????????????????????????????????????
227 
228  // fPathFinder->ReLocate(track.GetPosition());
229 
230  // reuse the touchable
231  fNewGhostTouchable = fOldGhostTouchable;
232  }
233 
234  fGhostPreStepPoint->SetTouchableHandle(fOldGhostTouchable);
235  fGhostPostStepPoint->SetTouchableHandle(fNewGhostTouchable);
236 
237  }
238 
239  if (aStep.GetStepLength() > kCarTolerance)
240  {
241 // if ( ( fPlaceOfAction == onBoundaryAndCollision)
242 // || ( (fPlaceOfAction == onBoundary) &&
243 // (aStep.GetPostStepPoint()->GetStepStatus() == fGeomBoundary) )
244 // || ( (fPlaceOfAction == onCollision) &&
245 // (aStep.GetPostStepPoint()->GetStepStatus() != fGeomBoundary) ) )
246  if(fParaflag) {
247  if ( ( fPlaceOfAction == onBoundaryAndCollision)
248  || ( (fPlaceOfAction == onBoundary) &&
249  (fGhostPostStepPoint->GetStepStatus() == fGeomBoundary) )
250  || ( (fPlaceOfAction == onCollision) &&
251  (fGhostPostStepPoint->GetStepStatus() != fGeomBoundary) ) )
252  {
253 
254 // G4StepPoint *postpoint = aStep.GetPostStepPoint();
255 
256 // G4GeometryCell postCell(*(postpoint->GetPhysicalVolume()),
257 // postpoint->GetTouchable()->GetReplicaNumber());
258 
259  G4GeometryCell postCell(*(fGhostPostStepPoint->GetPhysicalVolume()),
260  fGhostPostStepPoint->GetTouchable()->GetReplicaNumber());
261  G4Nsplit_Weight nw =
262  fWeightWindowAlgorithm.Calculate(aTrack.GetWeight(),
263  fWeightWindowStore.GetLowerWeight(postCell,
264  aTrack.GetKineticEnergy()));
265  fPostStepAction->DoIt(aTrack, fParticleChange, nw);
266  }
267  } else {
268  if ( ( fPlaceOfAction == onBoundaryAndCollision)
269  || ( (fPlaceOfAction == onBoundary) &&
271  || ( (fPlaceOfAction == onCollision) &&
272  (aStep.GetPostStepPoint()->GetStepStatus() != fGeomBoundary) ) )
273  {
274 
275  G4StepPoint *postpoint = aStep.GetPostStepPoint();
276 
277  G4GeometryCell postCell(*(postpoint->GetPhysicalVolume()),
278  postpoint->GetTouchable()->GetReplicaNumber());
279 
280  G4Nsplit_Weight nw =
281  fWeightWindowAlgorithm.Calculate(aTrack.GetWeight(),
282  fWeightWindowStore.GetLowerWeight(postCell,
283  aTrack.GetKineticEnergy()));
284  fPostStepAction->DoIt(aTrack, fParticleChange, nw);
285  }
286  }
287  }
288  return fParticleChange;
289 }
290 
292 {
293  fParticleChange->ProposeTrackStatus(fStopAndKill);
294 }
295 
297 {
299 }
300 
303  const G4Track& track, G4double previousStepSize, G4double currentMinimumStep,
304  G4double& proposedSafety, G4GPILSelection* selection)
305 {
306  if(fParaflag)
307  {
308  *selection = NotCandidateForSelection;
309  G4double returnedStep = DBL_MAX;
310 
311  if (previousStepSize > 0.)
312  { fGhostSafety -= previousStepSize; }
313  // else
314  // { fGhostSafety = -1.; }
315  if (fGhostSafety < 0.) fGhostSafety = 0.0;
316 
317  // ------------------------------------------
318  // Determination of the proposed STEP LENGTH:
319  // ------------------------------------------
320  if (currentMinimumStep <= fGhostSafety && currentMinimumStep > 0.)
321  {
322  // I have no chance to limit
323  returnedStep = currentMinimumStep;
324  fOnBoundary = false;
325  proposedSafety = fGhostSafety - currentMinimumStep;
326  }
327  else // (currentMinimumStep > fGhostSafety: I may limit the Step)
328  {
329  G4FieldTrackUpdator::Update(&fFieldTrack,&track);
330  //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
331  // ComputeStep
332  //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
333  returnedStep
334  = fPathFinder->ComputeStep(fFieldTrack,currentMinimumStep,fNavigatorID,
335  track.GetCurrentStepNumber(),fGhostSafety,feLimited,
336  fEndTrack,track.GetVolume());
337  //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
338  if(feLimited == kDoNot)
339  {
340  // Track is not on the boundary
341  fOnBoundary = false;
342  fGhostSafety = fGhostNavigator->ComputeSafety(fEndTrack.GetPosition());
343  // fGhostSafety = fGhostNavigator->ComputeSafety(endTrack.GetPosition(), DBL_MAX, true);
344  }
345  else
346  {
347  // Track is on the boundary
348  fOnBoundary = true;
349  proposedSafety = fGhostSafety;
350  }
351  //xbug? proposedSafety = fGhostSafety;
352  if(feLimited == kUnique || feLimited == kSharedOther) {
353  *selection = CandidateForSelection;
354  }else if (feLimited == kSharedTransport) {
355  returnedStep *= (1.0 + 1.0e-9);
356  // Expand to disable its selection in Step Manager comparison
357  }
358 
359  }
360 
361  // ----------------------------------------------
362  // Returns the fGhostSafety as the proposedSafety
363  // The SteppingManager will take care of keeping
364  // the smallest one.
365  // ----------------------------------------------
366  return returnedStep;
367 
368  } else {
369  return DBL_MAX;
370  // not sensible - time goes backwards! return -1.0;
371  }
372 
373 }
374 
378 {
379  return -1.0;
380 }
381 
383 AtRestDoIt(const G4Track&, const G4Step&)
384 {
385  return 0;
386 }
387 
389 AlongStepDoIt(const G4Track& track, const G4Step&)
390 {
391  // Dummy ParticleChange ie: does nothing
392  // Expecting G4Transportation to move the track
393  pParticleChange->Initialize(track);
394  return pParticleChange;
395 
396  // return 0;
397 }
398 
399 void G4WeightWindowProcess::CopyStep(const G4Step & step)
400 {
401  fGhostStep->SetTrack(step.GetTrack());
402  fGhostStep->SetStepLength(step.GetStepLength());
403  fGhostStep->SetTotalEnergyDeposit(step.GetTotalEnergyDeposit());
404  fGhostStep->SetControlFlag(step.GetControlFlag());
405 
406  *fGhostPreStepPoint = *(step.GetPreStepPoint());
407  *fGhostPostStepPoint = *(step.GetPostStepPoint());
408 
409 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
410 // Set StepStatus for ghost world
411 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
412  if(fOnBoundary)
413  { fGhostPostStepPoint->SetStepStatus(fGeomBoundary); }
414  else if(fGhostPostStepPoint->GetStepStatus()==fGeomBoundary)
415  { fGhostPostStepPoint->SetStepStatus(fPostStepDoItProc); }
416 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
417 }
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 G4VParticleChange * AtRestDoIt(const G4Track &, const G4Step &)
virtual void Initialize(const G4Track &)
void SetTrack(G4Track *value)
G4int verboseLevel
Definition: G4VProcess.hh:368
void SetParallelWorld(const G4String &parallelWorldName)
G4double GetStepLength() const
G4StepStatus GetStepStatus() const
const G4ThreeVector & GetPosition() const
G4TouchableHandle CreateTouchableHandle(G4int navId) const
G4SteppingControl GetControlFlag() const
const G4VTouchable * GetTouchable() const
void SetStepStatus(const G4StepStatus aValue)
G4StepPoint * GetPreStepPoint() const
G4double GetKineticEnergy() const
G4GLOB_DLL std::ostream G4cout
G4int GetCurrentStepNumber() const
G4VPhysicalVolume * GetPhysicalVolume() const
G4PlaceOfAction
const G4String & GetName() const
virtual G4double AtRestGetPhysicalInteractionLength(const G4Track &, G4ForceCondition *)
void SetControlFlag(G4SteppingControl StepControlFlag)
bool G4bool
Definition: G4Types.hh:79
G4double ComputeStep(const G4FieldTrack &pFieldTrack, G4double pCurrentProposedStepLength, G4int navigatorId, G4int stepNo, G4double &pNewSafety, ELimited &limitedStep, G4FieldTrack &EndState, G4VPhysicalVolume *currentVolume)
virtual const G4String & GetName() const
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()
virtual void Initialize(const G4Track &)
G4VPhysicalVolume * GetParallelWorld(const G4String &worldName)
G4int ActivateNavigator(G4Navigator *aNavigator)
void DoIt(const G4Track &aTrack, G4ParticleChange *aParticleChange, const G4Nsplit_Weight &nw)
const G4ThreeVector & GetMomentumDirection() const
virtual G4VParticleChange * AlongStepDoIt(const G4Track &, const G4Step &)
G4Navigator * GetNavigator(const G4String &worldName)
virtual void KillTrack() const
G4StepPoint * GetPostStepPoint() const
virtual G4int GetReplicaNumber(G4int depth=0) const
Definition: G4VTouchable.cc:58
G4VParticleChange * pParticleChange
Definition: G4VProcess.hh:283
G4VPhysicalVolume * GetVolume() const
virtual G4Nsplit_Weight Calculate(G4double init_w, G4double lowerWeightBound) const =0
G4double GetWeight() const
#define G4endl
Definition: G4ios.hh:61
G4WeightWindowProcess(const G4VWeightWindowAlgorithm &aWeightWindowAlgorithm, const G4VWeightWindowStore &aWWStore, const G4VTrackTerminator *TrackTerminator, G4PlaceOfAction placeOfAction, const G4String &aName="WeightWindowProcess", G4bool para=false)
virtual G4double PostStepGetPhysicalInteractionLength(const G4Track &aTrack, G4double previousStepSize, G4ForceCondition *condition)
void SetTotalEnergyDeposit(G4double value)
virtual G4double GetLowerWeight(const G4GeometryCell &gCell, G4double partEnergy) const =0
double G4double
Definition: G4Types.hh:76
virtual G4double AlongStepGetPhysicalInteractionLength(const G4Track &, G4double, G4double, G4double &, G4GPILSelection *)
void ProposeTrackStatus(G4TrackStatus status)
virtual G4double ComputeSafety(const G4ThreeVector &globalpoint, const G4double pProposedMaxLength=DBL_MAX, const G4bool keepState=true)
G4ForceCondition
G4Track * GetTrack() const
virtual G4VParticleChange * PostStepDoIt(const G4Track &, const G4Step &)
void SetTouchableHandle(const G4TouchableHandle &apValue)
#define DBL_MAX
Definition: templates.hh:83
const G4TouchableHandle & GetTouchableHandle() const
static void Update(G4FieldTrack *, const G4Track *)
G4GPILSelection