00001 //---------------------------------------------------------------------------// 00002 //Description: Geant4 Class 00003 //Author: Wu Chen(wuchen@mail.ihep.ac.cn) 00004 //Created: 17 Oct, 2012 00005 //Comment: 00006 //---------------------------------------------------------------------------// 00007 00008 #include "DetectorConstruction.hh" 00009 00010 #include "G4GeometryManager.hh" 00011 #include "G4PhysicalVolumeStore.hh" 00012 #include "G4LogicalVolumeStore.hh" 00013 #include "G4SolidStore.hh" 00014 #include "G4UserLimits.hh" 00015 00016 #include "DetectorMessenger.hh" 00017 #include "MaterialSvc.hh" 00018 #include "MyFieldSvc.hh" 00019 #include "MyDetectorManager.hh" 00020 00021 #include <stdlib.h> 00022 00023 DetectorConstruction::DetectorConstruction(){ 00024 detectorMessenger = new DetectorMessenger(this); 00025 pMyFieldSvc = MyFieldSvc::GetMyFieldSvc(); 00026 pMyDetectorManager = MyDetectorManager::GetMyDetectorManager(); 00027 } 00028 00029 DetectorConstruction::~DetectorConstruction(){ 00030 delete detectorMessenger; 00031 } 00032 00033 G4VPhysicalVolume* DetectorConstruction::Construct(){ 00034 G4String CardName; 00035 00036 //=>Material 00037 CardName = getenv("MATERIALLISTROOT"); 00038 MaterialSvc* materialSvc = MaterialSvc::GetMaterialSvc(); 00039 materialSvc->SetMaterial(CardName); 00040 00041 //=>MagField 00042 CardName = getenv("MAGFIELDCARDROOT"); 00043 pMyFieldSvc->ReadCard( CardName ); 00044 00045 //=>Geometry 00046 CardName = getenv("GEOCARDROOT"); 00047 pMyDetectorManager->ReadCard( CardName ); 00048 00049 //=>ConstructDetector 00050 return ConstructDetector(); 00051 } 00052 00053 G4VPhysicalVolume* DetectorConstruction::ConstructDetector() 00054 { 00055 // Clean old geometry, if any 00056 G4GeometryManager::GetInstance()->OpenGeometry(); 00057 G4PhysicalVolumeStore::GetInstance()->Clean(); 00058 G4LogicalVolumeStore::GetInstance()->Clean(); 00059 G4SolidStore::GetInstance()->Clean(); 00060 00061 // Geometry 00062 world_pvol = pMyDetectorManager->SetGeometry(); 00063 00064 //MagField 00065 G4LogicalVolume* world_lvol = world_pvol->GetLogicalVolume(); 00066 pMyFieldSvc->SetField(world_lvol); 00067 00068 // reset userlimit 00069 world_pvol->GetLogicalVolume()->SetUserLimits(new G4UserLimits()); 00070 00071 //always return the physical world 00072 return world_pvol; 00073 } 00074 00075 #include "G4RunManager.hh" 00076 00077 void DetectorConstruction::ReloadGeo(G4String file_name){ 00078 pMyDetectorManager->ClearGeo(); 00079 pMyDetectorManager->ReadCard(file_name); 00080 UpdateGeometry(); 00081 } 00082 00083 void DetectorConstruction::ResetMag(G4String file_name){ 00084 pMyFieldSvc->ReadCard(file_name); 00085 pMyFieldSvc->SetField(world_pvol->GetLogicalVolume()); 00086 } 00087 00088 void DetectorConstruction::UpdateGeometry() 00089 { 00090 G4RunManager::GetRunManager()->DefineWorldVolume(ConstructDetector()); 00091 }