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
00037
00038
00039
00040
00041
00042
00043 #include "G4FastSimulationManager.hh"
00044 #include "G4GlobalFastSimulationManager.hh"
00045 #include "G4PVPlacement.hh"
00046 #include "G4TransportationManager.hh"
00047
00048
00049
00050
00051
00052 G4FastSimulationManager::
00053 G4FastSimulationManager(G4Envelope *anEnvelope,
00054 G4bool IsUnique) :
00055 fFastTrack(anEnvelope,IsUnique),fTriggedFastSimulationModel(0),
00056 fLastCrossedParticle(0)
00057 {
00058
00059
00060 anEnvelope->SetFastSimulationManager(this);
00061
00062
00063 G4GlobalFastSimulationManager::GetGlobalFastSimulationManager()->
00064 AddFastSimulationManager(this);
00065 }
00066
00067
00068
00069
00070 G4FastSimulationManager::~G4FastSimulationManager()
00071 {
00072
00073
00074
00075
00076 if(fFastTrack.GetEnvelope()->GetFastSimulationManager()==this)
00077 fFastTrack.GetEnvelope()->ClearFastSimulationManager();
00078
00079 G4GlobalFastSimulationManager::GetGlobalFastSimulationManager()->
00080 RemoveFastSimulationManager(this);
00081 }
00082
00083
00084
00085
00086
00087 G4bool
00088 G4FastSimulationManager::ActivateFastSimulationModel(const G4String& aName)
00089 {
00090 size_t iModel;
00091
00092
00093 for (iModel=0; iModel<ModelList.size(); iModel++)
00094 if(ModelList[iModel]->GetName() == aName)
00095 return true;
00096
00097
00098
00099 for (iModel=0; iModel<fInactivatedModels.size(); iModel++)
00100 if(fInactivatedModels[iModel]->GetName() == aName) {
00101 ModelList.
00102 push_back (fInactivatedModels.removeAt(iModel));
00103
00104 fLastCrossedParticle=0;
00105 return true;
00106 }
00107 return false;
00108 }
00109
00110 G4bool
00111 G4FastSimulationManager::InActivateFastSimulationModel(const G4String& aName)
00112 {
00113
00114
00115 for (size_t iModel=0; iModel<ModelList.size(); iModel++)
00116 if(ModelList[iModel]->GetName() == aName) {
00117 fInactivatedModels.
00118 push_back (ModelList.removeAt(iModel));
00119
00120 fLastCrossedParticle=0;
00121 return true;
00122 }
00123 return false;
00124 }
00125
00126 G4VFastSimulationModel*
00127 G4FastSimulationManager::GetFastSimulationModel(const G4String& modelName,
00128 const G4VFastSimulationModel* previousFound,
00129 bool &foundPrevious) const
00130 {
00131 G4VFastSimulationModel* model = 0;
00132 for (size_t iModel=0; iModel<ModelList.size(); iModel++)
00133 {
00134 if(ModelList[iModel]->GetName() == modelName)
00135 {
00136 if (previousFound == 0)
00137 {
00138 model = ModelList[iModel];
00139 break;
00140 }
00141 else
00142 {
00143 if (ModelList[iModel] == previousFound)
00144 {
00145 foundPrevious = true;
00146 continue;
00147 }
00148 if (foundPrevious)
00149 {
00150 model = ModelList[iModel];
00151 break;
00152 }
00153 }
00154 }
00155 }
00156 return model;
00157 }
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182 G4bool
00183 G4FastSimulationManager::
00184 PostStepGetFastSimulationManagerTrigger(const G4Track& track,
00185 const G4Navigator* theNavigator)
00186 {
00187 size_t iModel;
00188
00189
00190 if(fLastCrossedParticle!=track.GetDefinition()) {
00191 fLastCrossedParticle=track.GetDefinition();
00192 fApplicableModelList.clear();
00193
00194 if(ModelList.size()==0) return false;
00195 for (iModel=0; iModel<ModelList.size(); iModel++)
00196 if(ModelList[iModel]->IsApplicable(*(track.GetDefinition())))
00197 fApplicableModelList.push_back (ModelList[iModel]);
00198 }
00199
00200
00201 if(fApplicableModelList.size()==0) return false;
00202
00203
00204 fFastTrack.SetCurrentTrack(track,theNavigator);
00205
00206
00207
00208 if(fFastTrack.OnTheBoundaryButExiting()) return false;
00209
00210
00211 for (iModel=0; iModel<fApplicableModelList.size(); iModel++)
00212
00213
00214
00215
00216
00217 if(fApplicableModelList[iModel]->ModelTrigger(fFastTrack)) {
00218
00219
00220
00221
00222
00223
00224 fFastStep.Initialize(fFastTrack);
00225
00226
00227
00228 fTriggedFastSimulationModel=fApplicableModelList[iModel];
00229 return true;
00230 }
00231
00232
00233
00234
00235 return false;
00236 }
00237
00238 G4VParticleChange* G4FastSimulationManager::InvokePostStepDoIt()
00239 {
00240
00241 fTriggedFastSimulationModel->DoIt(fFastTrack,fFastStep);
00242 return &fFastStep;
00243 }
00244
00245
00246
00247
00248 G4bool
00249 G4FastSimulationManager::AtRestGetFastSimulationManagerTrigger(const G4Track& track,
00250 const G4Navigator* theNavigator)
00251 {
00252 size_t iModel;
00253
00254
00255 if(fLastCrossedParticle!=track.GetDefinition()) {
00256 fLastCrossedParticle=track.GetDefinition();
00257 fApplicableModelList.clear();
00258
00259 if(ModelList.size()==0) return false;
00260 for (iModel=0; iModel<ModelList.size(); iModel++)
00261 if(ModelList[iModel]->IsApplicable(*(track.GetDefinition())))
00262 fApplicableModelList.push_back (ModelList[iModel]);
00263 }
00264
00265
00266 if(fApplicableModelList.size()==0) return false;
00267
00268
00269 fFastTrack.SetCurrentTrack(track,theNavigator);
00270
00271
00272
00273
00274
00275
00276 for (iModel=0; iModel < fApplicableModelList.size(); iModel++)
00277 if(fApplicableModelList[iModel]->AtRestModelTrigger(fFastTrack))
00278 {
00279 fFastStep.Initialize(fFastTrack);
00280 fTriggedFastSimulationModel=fApplicableModelList[iModel];
00281 return true;
00282 }
00283
00284
00285
00286
00287 return false;
00288 }
00289
00290 G4VParticleChange* G4FastSimulationManager::InvokeAtRestDoIt()
00291 {
00292 fTriggedFastSimulationModel->AtRestDoIt(fFastTrack,fFastStep);
00293 return &fFastStep;
00294 }
00295
00296 void
00297 G4FastSimulationManager::ListTitle() const
00298 {
00299 G4cout << fFastTrack.GetEnvelope()->GetName();
00300
00301 if (fFastTrack.GetEnvelope()->GetWorldPhysical() == G4TransportationManager::GetTransportationManager()->GetNavigatorForTracking()->GetWorldVolume()) G4cout << " (mass geom.)";
00302 else G4cout << " (// geom.)";
00303
00304 }
00305
00306 void
00307 G4FastSimulationManager::ListModels() const
00308 {
00309 size_t iModel;
00310
00311 G4cout << "Current Models for the ";
00312 ListTitle();
00313 G4cout << " envelope:\n";
00314
00315 for (iModel=0; iModel<ModelList.size(); iModel++)
00316 G4cout << " " << ModelList[iModel]->GetName() << "\n";
00317
00318 for (iModel=0; iModel<fInactivatedModels.size(); iModel++)
00319 G4cout << " " << fInactivatedModels[iModel]->GetName()
00320 << "(inactivated)\n";
00321 }
00322
00323 void
00324 G4FastSimulationManager::ListModels(const G4String& aName) const
00325 {
00326 size_t iModel;
00327 G4int titled = 0;
00328 G4ParticleTable* theParticleTable=
00329 G4ParticleTable::GetParticleTable();
00330
00331
00332 for (iModel=0; iModel<ModelList.size(); iModel++)
00333 if(ModelList[iModel]->GetName() == aName ||
00334 aName == "all" ) {
00335 if(!(titled++)){
00336 G4cout << "In the envelope ";
00337 ListTitle();
00338 G4cout << ",\n";
00339 }
00340 G4cout << " the model " << ModelList[iModel]->GetName()
00341 << " is applicable for :\n ";
00342
00343 G4int list_started=0;
00344 for (G4int iParticle=0; iParticle<theParticleTable->entries();
00345 iParticle++)
00346 if(ModelList[iModel]->
00347 IsApplicable(*(theParticleTable->
00348 GetParticle(iParticle)))) {
00349 if(list_started++) G4cout << ", ";
00350 G4cout << theParticleTable->
00351 GetParticle(iParticle)->GetParticleName();
00352 }
00353 G4cout <<G4endl;
00354 }
00355
00356
00357 for (iModel=0; iModel<fInactivatedModels.size(); iModel++)
00358 if(fInactivatedModels[iModel]->GetName() == aName ||
00359 aName == "all" ) {
00360 if(!(titled++)){
00361 G4cout << "In the envelope ";
00362 ListTitle();
00363 G4cout << ",\n";
00364 }
00365 G4cout << " the model " << fInactivatedModels[iModel]->GetName()
00366 << " (inactivated) is applicable for :\n ";
00367
00368 G4int list_started=0;
00369 for (G4int iParticle=0; iParticle<theParticleTable->entries();
00370 iParticle++)
00371 if(fInactivatedModels[iModel]->
00372 IsApplicable(*(theParticleTable->
00373 GetParticle(iParticle)))) {
00374 if(list_started++) G4cout << ", ";
00375 G4cout << theParticleTable->
00376 GetParticle(iParticle)->GetParticleName();
00377 }
00378 G4cout <<G4endl;
00379 }
00380 }
00381
00382 void
00383 G4FastSimulationManager::ListModels(const G4ParticleDefinition* aPD) const
00384 {
00385 size_t iModel;
00386 G4bool unique=true;
00387
00388
00389 for (iModel=0; iModel<ModelList.size(); iModel++)
00390 if(ModelList[iModel]->IsApplicable(*aPD)) {
00391 G4cout << "Envelope ";
00392 ListTitle();
00393 G4cout << ", Model "
00394 << ModelList[iModel]->GetName()
00395 << "." << G4endl;
00396 }
00397
00398 for (iModel=0; iModel<fInactivatedModels.size(); iModel++)
00399 if(fInactivatedModels[iModel]->IsApplicable(*aPD)) {
00400 G4cout << "Envelope ";
00401 ListTitle();
00402 G4cout << ", Model "
00403 << fInactivatedModels[iModel]->GetName()
00404 << " (inactivated)." << G4endl;
00405 }
00406
00407 if( !unique )
00408 {
00409 G4ExceptionDescription ed;
00410 ed << "Two or more Models are available for the same particle type, in the same envelope/region." << G4endl;
00411 G4Exception("G4FastSimulationManager::ListModels(const G4ParticleDefinition* aPD) const",
00412 "FastSim001",
00413 JustWarning, ed,
00414 "Models risk to exclude each other.");
00415 }
00416 unique=false;
00417 }