source: trunk/source/processes/scoring/src/G4ParallelWorldScoringProcess.cc @ 1245

Last change on this file since 1245 was 1228, checked in by garnier, 14 years ago

update geant4.9.3 tag

File size: 16.8 KB
Line 
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: G4ParallelWorldScoringProcess.cc,v 1.11 2008/09/06 06:18:12 asaim Exp $
28// GEANT4 tag $Name: geant4-09-03 $
29//
30//
31
32#include "G4ios.hh"
33#include "G4ParallelWorldScoringProcess.hh"
34#include "G4Step.hh"
35#include "G4Navigator.hh"
36#include "G4VTouchable.hh"
37#include "G4VPhysicalVolume.hh"
38#include "G4ParticleChange.hh"
39#include "G4PathFinder.hh"
40#include "G4TransportationManager.hh"
41#include "G4ParticleChange.hh"
42#include "G4StepPoint.hh"
43#include "G4FieldTrackUpdator.hh"
44
45#include "G4SDManager.hh"
46#include "G4VSensitiveDetector.hh"
47
48//--------------------------------
49// Constructor with name and type:
50//--------------------------------
51G4ParallelWorldScoringProcess::
52G4ParallelWorldScoringProcess(const G4String& processName,G4ProcessType theType)
53:G4VProcess(processName,theType), fGhostNavigator(0), fNavigatorID(-1), fFieldTrack('0')
54{
55  pParticleChange = &aDummyParticleChange;
56
57  fGhostStep = new G4Step();
58  fGhostPreStepPoint = fGhostStep->GetPreStepPoint();
59  fGhostPostStepPoint = fGhostStep->GetPostStepPoint();
60
61  fTransportationManager = G4TransportationManager::GetTransportationManager();
62  fPathFinder = G4PathFinder::GetInstance();
63
64  if (verboseLevel>0)
65  {
66    G4cout << GetProcessName() << " is created " << G4endl;
67  }
68}
69
70// -----------
71// Destructor:
72// -----------
73G4ParallelWorldScoringProcess::~G4ParallelWorldScoringProcess()
74{
75  delete fGhostStep;
76}
77
78//------------------------------------------------------
79//
80// SetParallelWorld
81//
82//------------------------------------------------------
83void G4ParallelWorldScoringProcess::
84SetParallelWorld(G4String parallelWorldName)
85{
86//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
87// Get pointers of the parallel world and its navigator
88//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
89  fGhostWorldName = parallelWorldName;
90  fGhostWorld = fTransportationManager->GetParallelWorld(fGhostWorldName);
91  fGhostNavigator = fTransportationManager->GetNavigator(fGhostWorld);
92//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
93}
94
95void G4ParallelWorldScoringProcess::
96SetParallelWorld(G4VPhysicalVolume* parallelWorld)
97{
98//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
99// Get pointer of navigator
100//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
101  fGhostWorldName = parallelWorld->GetName();
102  fGhostWorld = parallelWorld;
103  fGhostNavigator = fTransportationManager->GetNavigator(fGhostWorld);
104//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
105}
106
107//------------------------------------------------------
108//
109// StartTracking
110//
111//------------------------------------------------------
112void G4ParallelWorldScoringProcess::StartTracking(G4Track* trk)
113{
114//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
115// Activate navigator and get the navigator ID
116//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
117// G4cout << " G4ParallelWorldScoringProcess::StartTracking" << G4endl;
118  if(fGhostNavigator)
119  { fNavigatorID = fTransportationManager->ActivateNavigator(fGhostNavigator); }
120  else
121  {
122    G4Exception("G4ParallelWorldScoringProcess::StartTracking",
123       "ProcParaWorld000",FatalException,
124       "G4ParallelWorldScoringProcess is used for tracking without having a parallel world assigned");
125  }
126//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
127
128// G4cout << "G4ParallelWorldScoringProcess::StartTracking <<<<<<<<<<<<<<<<<< " << G4endl;
129//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
130// Let PathFinder initialize
131//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
132  fPathFinder->PrepareNewTrack(trk->GetPosition(),trk->GetMomentumDirection());
133//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
134
135//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
136// Setup initial touchables for the first step
137//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
138  fOldGhostTouchable = fPathFinder->CreateTouchableHandle(fNavigatorID);
139  fGhostPreStepPoint->SetTouchableHandle(fOldGhostTouchable);
140  fNewGhostTouchable = fOldGhostTouchable;
141  fGhostPostStepPoint->SetTouchableHandle(fNewGhostTouchable);
142
143  // Initialize
144  fGhostSafety = -1.;
145  fOnBoundary = false;
146  fGhostPreStepPoint->SetStepStatus(fUndefined);
147  fGhostPostStepPoint->SetStepStatus(fUndefined);
148}
149
150//----------------------------------------------------------
151//
152//  AtRestGetPhysicalInteractionLength()
153//
154//----------------------------------------------------------
155G4double
156G4ParallelWorldScoringProcess::AtRestGetPhysicalInteractionLength(
157         const G4Track& /*track*/, 
158         G4ForceCondition* condition)
159{
160  *condition = Forced;
161  return DBL_MAX;
162}
163
164//------------------------------------
165//
166//             AtRestDoIt()
167//
168//------------------------------------
169G4VParticleChange* G4ParallelWorldScoringProcess::AtRestDoIt(
170     const G4Track& track,
171     const G4Step& step)
172{ 
173  fOldGhostTouchable = fGhostPostStepPoint->GetTouchableHandle();
174  G4VSensitiveDetector* aSD = 0;
175  if(fOldGhostTouchable->GetVolume())
176  { aSD = fOldGhostTouchable->GetVolume()->GetLogicalVolume()->GetSensitiveDetector(); }
177  fOnBoundary = false;
178  CopyStep(step);
179  fGhostPreStepPoint->SetSensitiveDetector(aSD);
180
181  fNewGhostTouchable = fOldGhostTouchable;
182 
183  fGhostPreStepPoint->SetTouchableHandle(fOldGhostTouchable);
184  fGhostPostStepPoint->SetTouchableHandle(fNewGhostTouchable);
185  if(fNewGhostTouchable->GetVolume())
186  {
187    fGhostPostStepPoint->SetSensitiveDetector(
188      fNewGhostTouchable->GetVolume()->GetLogicalVolume()->GetSensitiveDetector());
189  }
190  else
191  { fGhostPostStepPoint->SetSensitiveDetector(0); }
192
193  if (verboseLevel>1) Verbose(step);
194
195  G4VSensitiveDetector* sd = fGhostPreStepPoint->GetSensitiveDetector();
196  if(sd)
197  {
198    sd->Hit(fGhostStep);
199  }
200
201  pParticleChange->Initialize(track);
202  return pParticleChange;
203}
204
205//----------------------------------------------------------
206//
207//  PostStepGetPhysicalInteractionLength()
208//
209//----------------------------------------------------------
210G4double
211G4ParallelWorldScoringProcess::PostStepGetPhysicalInteractionLength(
212         const G4Track& /*track*/, 
213         G4double   /*previousStepSize*/, 
214         G4ForceCondition* condition)
215{
216  // I must be invoked anyway to score the hit.
217  *condition = StronglyForced;
218  return DBL_MAX;
219}
220
221//------------------------------------
222//
223//             PostStepDoIt()
224//
225//------------------------------------
226G4VParticleChange* G4ParallelWorldScoringProcess::PostStepDoIt(
227     const G4Track& track,
228     const G4Step& step)
229{ 
230  fOldGhostTouchable = fGhostPostStepPoint->GetTouchableHandle();
231  G4VSensitiveDetector* aSD = 0;
232  if(fOldGhostTouchable->GetVolume())
233  { aSD = fOldGhostTouchable->GetVolume()->GetLogicalVolume()->GetSensitiveDetector(); }
234  CopyStep(step);
235  fGhostPreStepPoint->SetSensitiveDetector(aSD);
236
237  //  fPathFinder->Locate( track.GetPosition(),
238  //                       track.GetMomentumDirection(),
239  //                       true);
240
241  //  fPathFinder->Locate(step.GetPostStepPoint()->GetPosition(),
242  //                      step.GetPostStepPoint()->GetMomentumDirection());
243
244  if(fOnBoundary)
245  {
246//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
247// Locate the point and get new touchable
248//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
249  //??  fPathFinder->Locate(step.GetPostStepPoint()->GetPosition(),
250  //??                      step.GetPostStepPoint()->GetMomentumDirection());
251    fNewGhostTouchable = fPathFinder->CreateTouchableHandle(fNavigatorID);
252//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
253  }
254  else
255  {
256// Do I need this ??????????????????????????????????????????????????????????
257// fGhostNavigator->LocateGlobalPointWithinVolume(track.GetPosition());
258// ?????????????????????????????????????????????????????????????????????????
259
260    // fPathFinder->ReLocate(track.GetPosition());
261
262    // reuse the touchable
263    fNewGhostTouchable = fOldGhostTouchable;
264  }
265   
266  fGhostPreStepPoint->SetTouchableHandle(fOldGhostTouchable);
267  fGhostPostStepPoint->SetTouchableHandle(fNewGhostTouchable);
268
269  if(fNewGhostTouchable->GetVolume())
270  {
271    fGhostPostStepPoint->SetSensitiveDetector(
272      fNewGhostTouchable->GetVolume()->GetLogicalVolume()->GetSensitiveDetector());
273  }
274  else
275  { fGhostPostStepPoint->SetSensitiveDetector(0); }
276
277  if (verboseLevel>1) Verbose(step);
278
279  G4VSensitiveDetector* sd = fGhostPreStepPoint->GetSensitiveDetector();
280  if(sd)
281  {
282    sd->Hit(fGhostStep);
283  }
284
285  pParticleChange->Initialize(track); // Does not change the track properties
286  return pParticleChange;
287}
288
289
290//---------------------------------------
291//
292//  AlongStepGetPhysicalInteractionLength
293//
294//---------------------------------------
295G4double G4ParallelWorldScoringProcess::AlongStepGetPhysicalInteractionLength(
296            const G4Track& track, G4double  previousStepSize, G4double  currentMinimumStep,
297            G4double& proposedSafety, G4GPILSelection* selection)
298{
299  static G4FieldTrack endTrack('0');
300  static ELimited eLimited;
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  {
323    G4FieldTrackUpdator::Update(&fFieldTrack,&track);
324//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
325// ComputeStep
326//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
327    returnedStep
328      = fPathFinder->ComputeStep(fFieldTrack,currentMinimumStep,fNavigatorID,
329                     track.GetCurrentStepNumber(),fGhostSafety,eLimited,
330                     endTrack,track.GetVolume());
331//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
332    if(eLimited == kDoNot)
333    {
334      // Track is not on the boundary
335      fOnBoundary = false;
336      fGhostSafety = fGhostNavigator->ComputeSafety(endTrack.GetPosition());
337    }
338    else
339    {
340      // Track is on the boundary
341      fOnBoundary = true;
342      // proposedSafety = fGhostSafety;
343    }
344    proposedSafety = fGhostSafety;
345    if(eLimited == kUnique || eLimited == kSharedOther) {
346       *selection = CandidateForSelection;
347    }else if (eLimited == kSharedTransport) { 
348       returnedStep *= (1.0 + 1.0e-9); 
349         // Expand to disable its selection in Step Manager comparison
350    }
351  }
352
353  // ----------------------------------------------
354  // Returns the fGhostSafety as the proposedSafety
355  // The SteppingManager will take care of keeping
356  // the smallest one.
357  // ----------------------------------------------
358  return returnedStep;
359}
360
361G4VParticleChange* G4ParallelWorldScoringProcess::AlongStepDoIt(
362    const G4Track& track, const G4Step& )
363{
364  // Dummy ParticleChange ie: does nothing
365  // Expecting G4Transportation to move the track
366  pParticleChange->Initialize(track);
367  return pParticleChange; 
368}
369
370
371void G4ParallelWorldScoringProcess::CopyStep(const G4Step & step)
372{
373  G4StepStatus prevStat = fGhostPostStepPoint->GetStepStatus();
374
375  fGhostStep->SetTrack(step.GetTrack());
376  fGhostStep->SetStepLength(step.GetStepLength());
377  fGhostStep->SetTotalEnergyDeposit(step.GetTotalEnergyDeposit());
378  fGhostStep->SetNonIonizingEnergyDeposit(step.GetNonIonizingEnergyDeposit());
379  fGhostStep->SetControlFlag(step.GetControlFlag());
380
381  *fGhostPreStepPoint = *(step.GetPreStepPoint());
382  *fGhostPostStepPoint = *(step.GetPostStepPoint());
383
384//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
385// Set StepStatus for ghost world
386//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
387  fGhostPreStepPoint->SetStepStatus(prevStat);
388  if(fOnBoundary)
389  { fGhostPostStepPoint->SetStepStatus(fGeomBoundary); }
390  else if(fGhostPostStepPoint->GetStepStatus()==fGeomBoundary)
391  { fGhostPostStepPoint->SetStepStatus(fPostStepDoItProc); }
392//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
393}
394
395void G4ParallelWorldScoringProcess::Verbose(const G4Step& step) const
396{
397  G4cout << "In mass geometry ------------------------------------------------" << G4endl;
398  G4cout << " StepLength : " << step.GetStepLength()/mm << "      TotalEnergyDeposit : "
399         << step.GetTotalEnergyDeposit()/MeV << G4endl;
400  G4cout << " PreStepPoint : "
401         << step.GetPreStepPoint()->GetPhysicalVolume()->GetName() << " - ";
402  if(step.GetPreStepPoint()->GetProcessDefinedStep())
403  { G4cout << step.GetPreStepPoint()->GetProcessDefinedStep()->GetProcessName(); }
404  else
405  { G4cout << "NoProcessAssigned"; }
406  G4cout << G4endl;
407  G4cout << "                " << step.GetPreStepPoint()->GetPosition() << G4endl;
408  G4cout << " PostStepPoint : ";
409  if(step.GetPostStepPoint()->GetPhysicalVolume()) 
410  { G4cout << step.GetPostStepPoint()->GetPhysicalVolume()->GetName(); }
411  else
412  { G4cout << "OutOfWorld"; }
413  G4cout << " - ";
414  if(step.GetPostStepPoint()->GetProcessDefinedStep())
415  { G4cout << step.GetPostStepPoint()->GetProcessDefinedStep()->GetProcessName(); }
416  else
417  { G4cout << "NoProcessAssigned"; }
418  G4cout << G4endl;
419  G4cout << "                 " << step.GetPostStepPoint()->GetPosition() << G4endl;
420
421  G4cout << "In ghost geometry ------------------------------------------------" << G4endl;
422  G4cout << " StepLength : " << fGhostStep->GetStepLength()/mm
423         << "      TotalEnergyDeposit : "
424         << fGhostStep->GetTotalEnergyDeposit()/MeV << G4endl;
425  G4cout << " PreStepPoint : "
426         << fGhostStep->GetPreStepPoint()->GetPhysicalVolume()->GetName() << " ["
427           << fGhostStep->GetPreStepPoint()->GetTouchable()->GetReplicaNumber()
428           << " ]" << " - ";
429  if(fGhostStep->GetPreStepPoint()->GetProcessDefinedStep())
430  { G4cout << fGhostStep->GetPreStepPoint()->GetProcessDefinedStep()->GetProcessName(); }
431  else
432  { G4cout << "NoProcessAssigned"; }
433  G4cout << G4endl;
434  G4cout << "                " << fGhostStep->GetPreStepPoint()->GetPosition() << G4endl;
435  G4cout << " PostStepPoint : ";
436  if(fGhostStep->GetPostStepPoint()->GetPhysicalVolume()) 
437  {
438    G4cout << fGhostStep->GetPostStepPoint()->GetPhysicalVolume()->GetName() << " ["
439           << fGhostStep->GetPostStepPoint()->GetTouchable()->GetReplicaNumber()
440           << " ]";
441  }
442  else
443  { G4cout << "OutOfWorld"; }
444  G4cout << " - ";
445  if(fGhostStep->GetPostStepPoint()->GetProcessDefinedStep())
446  { G4cout << fGhostStep->GetPostStepPoint()->GetProcessDefinedStep()->GetProcessName(); }
447  else
448  { G4cout << "NoProcessAssigned"; }
449  G4cout << G4endl;
450  G4cout << "                 " << fGhostStep->GetPostStepPoint()->GetPosition() << " == "
451         << fGhostStep->GetTrack()->GetMomentumDirection() 
452         << G4endl;
453
454}
455
Note: See TracBrowser for help on using the repository browser.