#include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace RAT; #include using namespace std; G4LogicalVolume* Detector::FindLogicalVolume( const G4String& volume ) { G4String suffixName = volume + "_logical"; G4LogicalVolumeStore* store = G4LogicalVolumeStore::GetInstance(); for( vector::iterator iTer = store->begin(); iTer != store->end(); ++iTer ) { if( (*iTer)->GetName() == volume || (*iTer)->GetName() == suffixName ) return *iTer; } if( volume != "world" ) warn << "Detector::FindLogicalVolume cannot find " << volume << newline; return NULL; } G4VPhysicalVolume* Detector::FindPhysicalVolume( const G4String& volume, bool check ) { G4PhysicalVolumeStore* store = G4PhysicalVolumeStore::GetInstance(); for( vector::iterator iTer = store->begin(); iTer != store->end(); ++iTer ) { if( (*iTer)->GetName() == volume ) return *iTer; } if( volume != "world" && check ) Log::Die( "Detector::FindPhysicalVolume cannot find " + volume ); return NULL; } vector Detector::GetActiveVolumes() { G4VPhysicalVolume* activeVolume = G4TransportationManager::GetTransportationManager()->GetNavigatorForTracking()->LocateGlobalPointAndSetup( G4ThreeVector( 0.0, 0.0, 0.0 ), 0, false ); vector volumes; volumes.push_back( activeVolume ); string volumeName = activeVolume->GetName(); const string top( "_top" ); const string bottom( "_bottom" ); if( volumeName.find( top, volumeName.length() - top.length() ) != string::npos ) volumes.push_back( FindPhysicalVolume( volumeName.substr( 0, volumeName.length() - top.length() ) + "_bottom" ) ); else if( volumeName.find( bottom, volumeName.length() - bottom.length() ) != string::npos ) volumes.push_back( FindPhysicalVolume( volumeName.substr( 0, volumeName.length() - bottom.length() ) + "_top" ) ); return volumes; } vector Detector::GetActiveElectrons() { vector activeVolumes = GetActiveVolumes(); vector results; for( vector::iterator iVolume = activeVolumes.begin(); iVolume != activeVolumes.end(); ++iVolume ) { G4LogicalVolume* logicalVolume = (*iVolume)->GetLogicalVolume(); results.push_back( logicalVolume->GetMaterial()->GetTotNbOfElectPerVolume() * logicalVolume->GetSolid()->GetCubicVolume() ); } return results; } G4VPhysicalVolume* Detector::Construct() { info << "Detector::Construct: Constructing detector materials." << newline; Materials::ConstructMaterials(); Optics::LoadOptics(); Surfaces::LoadSurfaces(); // Load the relevant geo and pmtinfo files. DB *db = DB::Get(); DBLinkPtr ldetector = db->GetLink("DETECTOR"); const string geoFile = ldetector->GetS( "geo_file" ); info << "Detector::Construct: Loading detector geometry from " << geoFile << newline; if( db->Load( geoFile ) == 0 ) Log::Die("Detector::Construct: Could not open detector geometry" ); const string pmtFile = ldetector->GetS( "pmt_info_file" ); info << "Detector::Construct: Loading pmt info from " << pmtFile << newline; if( db->Load( pmtFile ) == 0 ) Log::Die( "Detector::Construct: Could not open pmt info" ); // Now can construct the geometry, first delete any existing geo G4GeometryManager::GetInstance()->OpenGeometry(); if( !G4GeometryManager::GetInstance()->IsGeometryClosed() ) CleanGeometry(); // Detector exists, clean (delete) it // Now construct the geometry info << "Detector::Construct: Constructing geometry." << newline; Geometry::Get()->ConstructGeometries( "GEO", fCheckOverlaps ); return GetWorld(); } Detector::Detector() : fCheckOverlaps(false) { fMessenger = new DetectorMessenger( this ); } Detector::~Detector() { G4GeometryManager::GetInstance()->OpenGeometry(); CleanGeometry(); delete fMessenger; } void Detector::CleanGeometry() { G4PhysicalVolumeStore::GetInstance()->Clean(); G4LogicalVolumeStore::GetInstance()->Clean(); G4SolidStore::GetInstance()->Clean(); }