00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 #include "G4ImportanceProcess.hh"
00037 #include "G4VImportanceAlgorithm.hh"
00038 #include "G4GeometryCell.hh"
00039 #include "G4SamplingPostStepAction.hh"
00040 #include "G4VTrackTerminator.hh"
00041 #include "G4VIStore.hh"
00042
00043 #include "G4Step.hh"
00044 #include "G4Navigator.hh"
00045 #include "G4VTouchable.hh"
00046 #include "G4VPhysicalVolume.hh"
00047 #include "G4ParticleChange.hh"
00048 #include "G4PathFinder.hh"
00049 #include "G4TransportationManager.hh"
00050 #include "G4StepPoint.hh"
00051 #include "G4FieldTrackUpdator.hh"
00052
00053
00054 G4ImportanceProcess::
00055 G4ImportanceProcess(const G4VImportanceAlgorithm &aImportanceAlgorithm,
00056 const G4VIStore &aIstore,
00057 const G4VTrackTerminator *TrackTerminator,
00058 const G4String &aName, G4bool para)
00059 : G4VProcess(aName),
00060 fParticleChange(new G4ParticleChange),
00061 fImportanceAlgorithm(aImportanceAlgorithm),
00062 fIStore(aIstore),
00063 fPostStepAction(0),
00064 fGhostNavigator(0), fNavigatorID(-1), fFieldTrack('0'),
00065 paraflag(para)
00066
00067 {
00068 if (TrackTerminator)
00069 {
00070 fPostStepAction = new G4SamplingPostStepAction(*TrackTerminator);
00071 }
00072 else
00073 {
00074 fPostStepAction = new G4SamplingPostStepAction(*this);
00075 }
00076 if (!fParticleChange)
00077 {
00078 G4Exception("G4ImportanceProcess::G4ImportanceProcess()",
00079 "FatalError", FatalException,
00080 "Failed allocation of G4ParticleChange !");
00081 }
00082 G4VProcess::pParticleChange = fParticleChange;
00083
00084
00085 fGhostStep = new G4Step();
00086 fGhostPreStepPoint = fGhostStep->GetPreStepPoint();
00087 fGhostPostStepPoint = fGhostStep->GetPostStepPoint();
00088
00089 fTransportationManager = G4TransportationManager::GetTransportationManager();
00090 fPathFinder = G4PathFinder::GetInstance();
00091
00092 if (verboseLevel>0)
00093 {
00094 G4cout << GetProcessName() << " is created " << G4endl;
00095 }
00096
00097 G4cout << " importance process paraflag is: " << paraflag << G4endl;
00098
00099 }
00100
00101 G4ImportanceProcess::~G4ImportanceProcess()
00102 {
00103
00104 delete fPostStepAction;
00105 delete fParticleChange;
00106 delete fGhostStep;
00107
00108 }
00109
00110
00111
00112
00113
00114
00115
00116
00117 void G4ImportanceProcess::
00118 SetParallelWorld(G4String parallelWorldName)
00119 {
00120
00121
00122
00123 fGhostWorldName = parallelWorldName;
00124 fGhostWorld = fTransportationManager->GetParallelWorld(fGhostWorldName);
00125 fGhostNavigator = fTransportationManager->GetNavigator(fGhostWorld);
00126
00127 }
00128
00129 void G4ImportanceProcess::
00130 SetParallelWorld(G4VPhysicalVolume* parallelWorld)
00131 {
00132
00133
00134
00135 fGhostWorldName = parallelWorld->GetName();
00136 fGhostWorld = parallelWorld;
00137 fGhostNavigator = fTransportationManager->GetNavigator(fGhostWorld);
00138
00139 }
00140
00141
00142
00143
00144
00145
00146 void G4ImportanceProcess::StartTracking(G4Track* trk)
00147 {
00148
00149
00150
00151
00152
00153 if(paraflag) {
00154 if(fGhostNavigator)
00155 { fNavigatorID = fTransportationManager->ActivateNavigator(fGhostNavigator); }
00156 else
00157 {
00158 G4Exception("G4ImportanceProcess::StartTracking",
00159 "ProcParaWorld000",FatalException,
00160 "G4ImportanceProcess is used for tracking without having a parallel world assigned");
00161 }
00162
00163
00164
00165
00166
00167
00168 fPathFinder->PrepareNewTrack(trk->GetPosition(),trk->GetMomentumDirection());
00169
00170
00171
00172
00173
00174 fOldGhostTouchable = fPathFinder->CreateTouchableHandle(fNavigatorID);
00175 fGhostPreStepPoint->SetTouchableHandle(fOldGhostTouchable);
00176 fNewGhostTouchable = fOldGhostTouchable;
00177 fGhostPostStepPoint->SetTouchableHandle(fNewGhostTouchable);
00178
00179
00180 fGhostSafety = -1.;
00181 fOnBoundary = false;
00182 }
00183
00184 }
00185
00186
00187 G4double G4ImportanceProcess::
00188 PostStepGetPhysicalInteractionLength(const G4Track& ,
00189 G4double ,
00190 G4ForceCondition* condition)
00191 {
00192
00193
00194
00195
00196 *condition = Forced;
00197 return DBL_MAX;
00198 }
00199
00200 G4VParticleChange *
00201 G4ImportanceProcess::PostStepDoIt(const G4Track &aTrack,
00202 const G4Step &aStep)
00203 {
00204 fParticleChange->Initialize(aTrack);
00205
00206 if(paraflag) {
00207 fOldGhostTouchable = fGhostPostStepPoint->GetTouchableHandle();
00208
00209 CopyStep(aStep);
00210
00211 if(fOnBoundary)
00212 {
00213
00214
00215
00216
00217
00218 fNewGhostTouchable = fPathFinder->CreateTouchableHandle(fNavigatorID);
00219
00220
00221 }
00222 else
00223 {
00224
00225
00226
00227
00228
00229
00230
00231 fNewGhostTouchable = fOldGhostTouchable;
00232
00233 }
00234
00235 fGhostPreStepPoint->SetTouchableHandle(fOldGhostTouchable);
00236 fGhostPostStepPoint->SetTouchableHandle(fNewGhostTouchable);
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255 if ( (fGhostPostStepPoint->GetStepStatus() == fGeomBoundary)
00256 && (aStep.GetStepLength() > kCarTolerance) )
00257 {
00258 if (aTrack.GetTrackStatus()==fStopAndKill)
00259 {
00260 G4cout << "WARNING - G4ImportanceProcess::PostStepDoIt()"
00261 << " StopAndKill track. on boundary" << G4endl;
00262 }
00263
00264 G4GeometryCell prekey(*(fGhostPreStepPoint->GetPhysicalVolume()),
00265 fGhostPreStepPoint->GetTouchable()->GetReplicaNumber());
00266 G4GeometryCell postkey(*(fGhostPostStepPoint->GetPhysicalVolume()),
00267 fGhostPostStepPoint->GetTouchable()->GetReplicaNumber());
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283 G4Nsplit_Weight nw = fImportanceAlgorithm.
00284 Calculate(fIStore.GetImportance(prekey),
00285 fIStore.GetImportance(postkey),
00286 aTrack.GetWeight());
00287
00288
00289
00290
00291
00292
00293
00294
00295 fPostStepAction->DoIt(aTrack, fParticleChange, nw);
00296
00297 }
00298 } else {
00299 if ( (aStep.GetPostStepPoint()->GetStepStatus() == fGeomBoundary)
00300 && (aStep.GetStepLength() > kCarTolerance) )
00301 {
00302
00303 if (aTrack.GetTrackStatus()==fStopAndKill)
00304 {
00305 G4cout << "WARNING - G4ImportanceProcess::PostStepDoIt()"
00306 << " StopAndKill track. on boundary non-parallel" << G4endl;
00307 }
00308
00309 G4StepPoint *prepoint = aStep.GetPreStepPoint();
00310 G4StepPoint *postpoint = aStep.GetPostStepPoint();
00311
00312 G4GeometryCell prekey(*(prepoint->GetPhysicalVolume()),
00313 prepoint->GetTouchable()->GetReplicaNumber());
00314 G4GeometryCell postkey(*(postpoint->GetPhysicalVolume()),
00315 postpoint->GetTouchable()->GetReplicaNumber());
00316
00317 G4Nsplit_Weight nw = fImportanceAlgorithm.
00318 Calculate(fIStore.GetImportance(prekey),
00319 fIStore.GetImportance(postkey),
00320 aTrack.GetWeight());
00321
00322
00323
00324
00325
00326
00327
00328
00329 fPostStepAction->DoIt(aTrack, fParticleChange, nw);
00330
00331 }
00332 }
00333 return fParticleChange;
00334 }
00335
00336 void G4ImportanceProcess::KillTrack() const
00337 {
00338 fParticleChange->ProposeTrackStatus(fStopAndKill);
00339 }
00340
00341 const G4String &G4ImportanceProcess::GetName() const
00342 {
00343 return theProcessName;
00344 }
00345
00346 G4double G4ImportanceProcess::
00347 AlongStepGetPhysicalInteractionLength(
00348 const G4Track& track, G4double previousStepSize, G4double currentMinimumStep,
00349 G4double& proposedSafety, G4GPILSelection* selection)
00350 {
00351
00352
00353
00354 if(paraflag) {
00355 static G4FieldTrack endTrack('0');
00356 static ELimited eLimited;
00357
00358 *selection = NotCandidateForSelection;
00359 G4double returnedStep = DBL_MAX;
00360
00361 if (previousStepSize > 0.)
00362 { fGhostSafety -= previousStepSize; }
00363
00364
00365 if (fGhostSafety < 0.) fGhostSafety = 0.0;
00366
00367
00368
00369
00370 if (currentMinimumStep <= fGhostSafety && currentMinimumStep > 0.)
00371 {
00372
00373 returnedStep = currentMinimumStep;
00374 fOnBoundary = false;
00375 proposedSafety = fGhostSafety - currentMinimumStep;
00376
00377 }
00378 else
00379 {
00380 G4FieldTrackUpdator::Update(&fFieldTrack,&track);
00381
00382
00383
00384 returnedStep
00385 = fPathFinder->ComputeStep(fFieldTrack,currentMinimumStep,fNavigatorID,
00386 track.GetCurrentStepNumber(),fGhostSafety,eLimited,
00387 endTrack,track.GetVolume());
00388
00389 if(eLimited == kDoNot)
00390 {
00391
00392
00393 fOnBoundary = false;
00394 fGhostSafety = fGhostNavigator->ComputeSafety(endTrack.GetPosition());
00395 }
00396 else
00397 {
00398
00399
00400 fOnBoundary = true;
00401
00402 }
00403 proposedSafety = fGhostSafety;
00404 if(eLimited == kUnique || eLimited == kSharedOther) {
00405 *selection = CandidateForSelection;
00406 }else if (eLimited == kSharedTransport) {
00407 returnedStep *= (1.0 + 1.0e-9);
00408
00409 }
00410
00411 }
00412
00413
00414
00415
00416
00417
00418 return returnedStep;
00419
00420 } else {
00421
00422 return DBL_MAX;
00423
00424 }
00425
00426 }
00427
00428 G4double G4ImportanceProcess::
00429 AtRestGetPhysicalInteractionLength(const G4Track& ,
00430 G4ForceCondition*)
00431 {
00432 return -1.0;
00433 }
00434
00435 G4VParticleChange* G4ImportanceProcess::
00436 AtRestDoIt(const G4Track&, const G4Step&)
00437 {
00438 return 0;
00439 }
00440
00441 G4VParticleChange* G4ImportanceProcess::
00442 AlongStepDoIt(const G4Track& aTrack, const G4Step& )
00443 {
00444
00445
00446
00447 pParticleChange->Initialize(aTrack);
00448 return pParticleChange;
00449
00450 }
00451
00452 void G4ImportanceProcess::CopyStep(const G4Step & step)
00453 {
00454 fGhostStep->SetTrack(step.GetTrack());
00455 fGhostStep->SetStepLength(step.GetStepLength());
00456 fGhostStep->SetTotalEnergyDeposit(step.GetTotalEnergyDeposit());
00457 fGhostStep->SetControlFlag(step.GetControlFlag());
00458
00459 *fGhostPreStepPoint = *(step.GetPreStepPoint());
00460 *fGhostPostStepPoint = *(step.GetPostStepPoint());
00461
00462
00463
00464
00465 if(fOnBoundary)
00466 { fGhostPostStepPoint->SetStepStatus(fGeomBoundary); }
00467 else if(fGhostPostStepPoint->GetStepStatus()==fGeomBoundary)
00468 { fGhostPostStepPoint->SetStepStatus(fPostStepDoItProc); }
00469
00470 }