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 #include "G4TransportationManager.hh"
00039
00040 #include <algorithm>
00041
00042 #include "G4GeometryMessenger.hh"
00043 #include "G4PropagatorInField.hh"
00044 #include "G4FieldManager.hh"
00045 #include "G4LogicalVolume.hh"
00046 #include "G4PVPlacement.hh"
00047
00048
00049
00050 G4TransportationManager* G4TransportationManager::fTransportationManager=0;
00051
00052
00053
00054
00055 G4TransportationManager::G4TransportationManager()
00056 {
00057 if (fTransportationManager)
00058 {
00059 G4Exception("G4TransportationManager::G4TransportationManager()",
00060 "GeomNav0002", FatalException,
00061 "Only ONE instance of G4TransportationManager is allowed!");
00062 }
00063
00064
00065
00066 G4Navigator* trackingNavigator = new G4Navigator();
00067 trackingNavigator->Activate(true);
00068 fNavigators.push_back(trackingNavigator);
00069 fActiveNavigators.push_back(trackingNavigator);
00070 fWorlds.push_back(trackingNavigator->GetWorldVolume());
00071
00072 fGeomMessenger = new G4GeometryMessenger(this);
00073 fFieldManager = new G4FieldManager();
00074 fPropagatorInField= new G4PropagatorInField(trackingNavigator,fFieldManager);
00075 fSafetyHelper = new G4SafetyHelper();
00076 }
00077
00078
00079
00080
00081 G4TransportationManager::~G4TransportationManager()
00082 {
00083 delete fFieldManager;
00084 delete fPropagatorInField;
00085 ClearNavigators();
00086 delete fGeomMessenger;
00087 delete fSafetyHelper;
00088 }
00089
00090
00091
00092
00093
00094
00095 G4TransportationManager* G4TransportationManager::GetTransportationManager()
00096 {
00097 static G4TransportationManager theInstance;
00098 if (!fTransportationManager)
00099 fTransportationManager = &theInstance;
00100
00101 return fTransportationManager;
00102 }
00103
00104
00105
00106
00107
00108
00109 void G4TransportationManager::SetFieldManager(G4FieldManager* newFieldManager)
00110 {
00111 fFieldManager = newFieldManager;
00112
00113
00114
00115
00116 if( fPropagatorInField )
00117 {
00118 fPropagatorInField -> SetDetectorFieldManager( newFieldManager );
00119 }
00120 }
00121
00122
00123
00124
00125
00126
00127
00128 void G4TransportationManager::ClearNavigators()
00129 {
00130 std::vector<G4Navigator*>::iterator pNav;
00131 for (pNav=fNavigators.begin(); pNav!=fNavigators.end(); pNav++)
00132 {
00133 delete *pNav;
00134 }
00135 fNavigators.clear();
00136 fActiveNavigators.clear();
00137 fWorlds.clear();
00138 }
00139
00140
00141
00142
00143
00144
00145
00146 G4VPhysicalVolume*
00147 G4TransportationManager::GetParallelWorld( const G4String& worldName )
00148 {
00149 G4VPhysicalVolume* wPV = IsWorldExisting(worldName);
00150 if (!wPV)
00151 {
00152 wPV = GetNavigatorForTracking()->GetWorldVolume();
00153 G4LogicalVolume* wLV = wPV->GetLogicalVolume();
00154 wLV = new G4LogicalVolume(wLV->GetSolid(), 0,
00155 worldName);
00156 wPV = new G4PVPlacement (wPV->GetRotation(),
00157 wPV->GetTranslation(),
00158 wLV, worldName, 0, false, 0);
00159 RegisterWorld(wPV);
00160 }
00161 return wPV;
00162 }
00163
00164
00165
00166
00167
00168
00169
00170
00171 G4Navigator* G4TransportationManager::GetNavigator( const G4String& worldName )
00172 {
00173
00174
00175 std::vector<G4Navigator*>::iterator pNav;
00176 for (pNav=fNavigators.begin(); pNav!=fNavigators.end(); pNav++)
00177 {
00178 if ((*pNav)->GetWorldVolume()->GetName() == worldName) { return *pNav; }
00179 }
00180
00181
00182
00183
00184 G4Navigator* aNavigator = 0;
00185 G4VPhysicalVolume* aWorld = IsWorldExisting(worldName);
00186 if(aWorld)
00187 {
00188 aNavigator = new G4Navigator();
00189 aNavigator->SetWorldVolume(aWorld);
00190 fNavigators.push_back(aNavigator);
00191 }
00192 else
00193 {
00194 G4String message
00195 = "World volume with name -" + worldName
00196 + "- does not exist. Create it first by GetParallelWorld() method!";
00197 G4Exception("G4TransportationManager::GetNavigator(name)",
00198 "GeomNav0002", FatalException, message);
00199 }
00200
00201 return aNavigator;
00202 }
00203
00204
00205
00206
00207
00208
00209
00210
00211 G4Navigator* G4TransportationManager::GetNavigator( G4VPhysicalVolume* aWorld )
00212 {
00213 std::vector<G4Navigator*>::iterator pNav;
00214 for (pNav=fNavigators.begin(); pNav!=fNavigators.end(); pNav++)
00215 {
00216 if ((*pNav)->GetWorldVolume() == aWorld) { return *pNav; }
00217 }
00218 G4Navigator* aNavigator = 0;
00219 std::vector<G4VPhysicalVolume*>::iterator pWorld =
00220 std::find(fWorlds.begin(), fWorlds.end(), aWorld);
00221 if (pWorld != fWorlds.end())
00222 {
00223 aNavigator = new G4Navigator();
00224 aNavigator->SetWorldVolume(aWorld);
00225 fNavigators.push_back(aNavigator);
00226 }
00227 else
00228 {
00229 G4String message
00230 = "World volume with name -" + aWorld->GetName()
00231 + "- does not exist. Create it first by GetParallelWorld() method!";
00232 G4Exception("G4TransportationManager::GetNavigator(pointer)",
00233 "GeomNav0002", FatalException, message);
00234 }
00235
00236 return aNavigator;
00237 }
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247 void G4TransportationManager::DeRegisterNavigator( G4Navigator* aNavigator )
00248 {
00249 if (aNavigator == fNavigators[0])
00250 {
00251 G4Exception("G4TransportationManager::DeRegisterNavigator()",
00252 "GeomNav0003", FatalException,
00253 "The navigator for tracking CANNOT be deregistered!");
00254 }
00255 std::vector<G4Navigator*>::iterator pNav =
00256 std::find(fNavigators.begin(), fNavigators.end(), aNavigator);
00257 if (pNav != fNavigators.end())
00258 {
00259
00260
00261 DeRegisterWorld((*pNav)->GetWorldVolume());
00262
00263
00264
00265 fNavigators.erase(pNav);
00266 }
00267 else
00268 {
00269 G4String message
00270 = "Navigator for volume -" + aNavigator->GetWorldVolume()->GetName()
00271 + "- not found in memory!";
00272 G4Exception("G4TransportationManager::DeRegisterNavigator()",
00273 "GeomNav1002", JustWarning, message);
00274 }
00275 }
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286 G4int G4TransportationManager::ActivateNavigator( G4Navigator* aNavigator )
00287 {
00288 std::vector<G4Navigator*>::iterator pNav =
00289 std::find(fNavigators.begin(), fNavigators.end(), aNavigator);
00290 if (pNav == fNavigators.end())
00291 {
00292 G4String message
00293 = "Navigator for volume -" + aNavigator->GetWorldVolume()->GetName()
00294 + "- not found in memory!";
00295 G4Exception("G4TransportationManager::ActivateNavigator()",
00296 "GeomNav1002", JustWarning, message);
00297 return -1;
00298 }
00299
00300 aNavigator->Activate(true);
00301 G4int id = 0;
00302 std::vector<G4Navigator*>::iterator pActiveNav;
00303 for(pActiveNav=fActiveNavigators.begin();
00304 pActiveNav!=fActiveNavigators.end(); pActiveNav++)
00305 {
00306 if (*pActiveNav == aNavigator) { return id; }
00307 id++;
00308 }
00309
00310 fActiveNavigators.push_back(aNavigator);
00311 return id;
00312 }
00313
00314
00315
00316
00317
00318
00319
00320
00321 void G4TransportationManager::DeActivateNavigator( G4Navigator* aNavigator )
00322 {
00323 std::vector<G4Navigator*>::iterator pNav =
00324 std::find(fNavigators.begin(), fNavigators.end(), aNavigator);
00325 if (pNav != fNavigators.end())
00326 {
00327 (*pNav)->Activate(false);
00328 }
00329 else
00330 {
00331 G4String message
00332 = "Navigator for volume -" + aNavigator->GetWorldVolume()->GetName()
00333 + "- not found in memory!";
00334 G4Exception("G4TransportationManager::DeActivateNavigator()",
00335 "GeomNav1002", JustWarning, message);
00336 }
00337
00338 std::vector<G4Navigator*>::iterator pActiveNav =
00339 std::find(fActiveNavigators.begin(), fActiveNavigators.end(), aNavigator);
00340 if (pActiveNav != fActiveNavigators.end())
00341 {
00342 fActiveNavigators.erase(pActiveNav);
00343 }
00344 }
00345
00346
00347
00348
00349
00350
00351
00352 void G4TransportationManager::InactivateAll( )
00353 {
00354 std::vector<G4Navigator*>::iterator pNav;
00355 for (pNav=fActiveNavigators.begin(); pNav!=fActiveNavigators.end(); pNav++)
00356 {
00357 (*pNav)->Activate(false);
00358 }
00359 fActiveNavigators.clear();
00360
00361
00362
00363 fNavigators[0]->Activate(true);
00364 fActiveNavigators.push_back(fNavigators[0]);
00365 }
00366
00367
00368
00369
00370
00371
00372
00373 G4VPhysicalVolume*
00374 G4TransportationManager::IsWorldExisting ( const G4String& name )
00375 {
00376 std::vector<G4VPhysicalVolume*>::iterator pWorld = fWorlds.begin();
00377 if (*pWorld==0) { *pWorld=fNavigators[0]->GetWorldVolume(); }
00378
00379 for (pWorld=fWorlds.begin(); pWorld!=fWorlds.end(); pWorld++)
00380 {
00381 if ((*pWorld)->GetName() == name ) { return *pWorld; }
00382 }
00383 return 0;
00384 }
00385
00386
00387
00388
00389
00390
00391
00392
00393 G4bool G4TransportationManager::RegisterWorld( G4VPhysicalVolume* aWorld )
00394 {
00395 G4bool done = false;
00396
00397 std::vector<G4VPhysicalVolume*>::iterator pWorld =
00398 std::find(fWorlds.begin(), fWorlds.end(), aWorld);
00399 if (pWorld == fWorlds.end())
00400 {
00401 fWorlds.push_back(aWorld);
00402 done = true;
00403 }
00404 return done;
00405 }
00406
00407
00408
00409
00410
00411
00412
00413
00414 void G4TransportationManager::DeRegisterWorld( G4VPhysicalVolume* aWorld )
00415 {
00416 std::vector<G4VPhysicalVolume*>::iterator pWorld =
00417 std::find(fWorlds.begin(), fWorlds.end(), aWorld);
00418 if (pWorld != fWorlds.end())
00419 {
00420 fWorlds.erase(pWorld);
00421 }
00422 else
00423 {
00424 G4String message
00425 = "World volume -" + aWorld->GetName() + "- not found in memory!";
00426 G4Exception("G4TransportationManager::DeRegisterWorld()",
00427 "GeomNav1002", JustWarning, message);
00428 }
00429 }