diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..a189af5eff64bd90c787c087068ffc8aa19fb565 --- /dev/null +++ b/.gitignore @@ -0,0 +1,17 @@ +*.cmake +*.G4Table +*CMakeFiles* +*.ninja* +*.swp +Makefiles +*.gitignore +CMakeCache.txt +*.dylib +*.so +*.gdml +*.root +*.wrl +install_manifest.txt +.DS_store +*NPAnalysis* +.last_* diff --git a/NPSimulation/CMakeLists.txt b/NPSimulation/CMakeLists.txt index 9781c3815fb8e674c591b21e099a2d4be1bf129e..62674a478bd8fb3005d54f48fd3bba47a90559de 100755 --- a/NPSimulation/CMakeLists.txt +++ b/NPSimulation/CMakeLists.txt @@ -42,6 +42,11 @@ EXEC_PROGRAM(${ROOT_CONFIG_EXECUTABLE} set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${root_cflags}") +if(Geant4_gdml_FOUND) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DNPS_GDML") +endif() + + # If the compiler is Clang, silence the unrecognised flags if(${CMAKE_CXX_COMPILER_ID} MATCHES ".*Clang.*") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Qunused-arguments -fcolor-diagnostics -Wno-deprecated-register -Wno-shadow") diff --git a/NPSimulation/Core/DetectorConstruction.cc b/NPSimulation/Core/DetectorConstruction.cc index a8f4c0ce0cb1137df08da7448b1f99082fc0731b..8de3fd16d493f41e54dd64fe5858104cb46bd8fe 100644 --- a/NPSimulation/Core/DetectorConstruction.cc +++ b/NPSimulation/Core/DetectorConstruction.cc @@ -52,7 +52,10 @@ #include "G4SolidStore.hh" #include "G4RunManager.hh" #include "G4SDManager.hh" -// Detector class + +#ifdef NPS_GDML +#include"G4GDMLParser.hh" +#endif // STL #include<cstdlib> @@ -293,3 +296,10 @@ void DetectorConstruction::RedefineGeometry(std::string file){ G4RunManager::GetRunManager()->GeometryHasBeenModified(); G4RunManager::GetRunManager()->Initialize(); } + +//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... +void DetectorConstruction::ExportGeometry(string file){ + G4GDMLParser parser ; + parser.Write(file.c_str(),world_log); +} + diff --git a/NPSimulation/Core/DetectorConstruction.hh b/NPSimulation/Core/DetectorConstruction.hh index 63c6b1d8b9d2161916049ee6f84cbe8d5b3a4c41..451827ca788131ef815734776393f5e238e16cef 100644 --- a/NPSimulation/Core/DetectorConstruction.hh +++ b/NPSimulation/Core/DetectorConstruction.hh @@ -42,45 +42,46 @@ class G4VPhysicalVolume; // ROOT headers #include "TTree.h" -class DetectorConstruction : public G4VUserDetectorConstruction -{ -public: - DetectorConstruction(); - virtual ~DetectorConstruction(); +class DetectorConstruction : public G4VUserDetectorConstruction{ + public: + DetectorConstruction(); + virtual ~DetectorConstruction(); - G4VPhysicalVolume* Construct(); - G4LogicalVolume* GetWorldLogic(); - // Delete every existing bit - void ClearGeometry(); - // Reload the file configuration - void RedefineGeometry(string file=""); - -public: - G4VPhysicalVolume* ReadConfigurationFile(); - void AddDetector(NPS::VDetector*); - void ReadAllSensitive(const G4Event*); + G4VPhysicalVolume* Construct(); + G4LogicalVolume* GetWorldLogic(); + // Delete every existing bit + void ClearGeometry(); + // Reload the file configuration + void RedefineGeometry(string file=""); + // Export the geometry to a gdml file + void ExportGeometry(string); + public: + G4VPhysicalVolume* ReadConfigurationFile(); + void AddDetector(NPS::VDetector*); + void ReadAllSensitive(const G4Event*); -private: - // Logical volumes - G4LogicalVolume* world_log; - //G4LogicalVolume* Chamber_log; - // Physical volumes - G4VPhysicalVolume* world_phys; - //G4VPhysicalVolume* Chamber_phys; + private: + // Logical volumes + G4LogicalVolume* world_log; + //G4LogicalVolume* Chamber_log; - // Virtual Detector Vector - vector<NPS::VDetector*> m_Detectors; + // Physical volumes + G4VPhysicalVolume* world_phys; + //G4VPhysicalVolume* Chamber_phys; + // Virtual Detector Vector + vector<NPS::VDetector*> m_Detectors; -private: // Data about the target - Target* m_Target; - Chamber* m_Chamber; - DetectorMessenger* m_Messenger; -public: // Getter and Setter - Target* GetTarget() {return m_Target;} - Chamber* GetChamber() {return m_Chamber;} + + private: // Data about the target + Target* m_Target; + Chamber* m_Chamber; + DetectorMessenger* m_Messenger; + public: // Getter and Setter + Target* GetTarget() {return m_Target;} + Chamber* GetChamber() {return m_Chamber;} }; #endif diff --git a/NPSimulation/Core/DetectorMessenger.cc b/NPSimulation/Core/DetectorMessenger.cc index 063964b869fb99a3e938ee0edf471acd00bf8d00..ac882998236564ac452d2e660b1df391173111ff 100644 --- a/NPSimulation/Core/DetectorMessenger.cc +++ b/NPSimulation/Core/DetectorMessenger.cc @@ -42,6 +42,10 @@ DetectorMessenger::DetectorMessenger(DetectorConstruction* Det):Detector(Det){ UpdateCmd->SetGuidance("Update detector geometry."); UpdateCmd->SetGuidance("Apply this command after editing your geometry file "); UpdateCmd->AvailableForStates(G4State_Idle); + + ExportCmd = new G4UIcmdWithAString("/det/export_gdml",this); + ExportCmd->SetGuidance("export current geomtry to gdml"); + ExportCmd->AvailableForStates(G4State_Idle); } //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... @@ -53,9 +57,13 @@ DetectorMessenger::~DetectorMessenger(){ //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... -void DetectorMessenger::SetNewValue(G4UIcommand* command, G4String){ - if( command == UpdateCmd ) - { Detector->RedefineGeometry(""); } +void DetectorMessenger::SetNewValue(G4UIcommand* command, G4String value){ + if( command == UpdateCmd ){ + Detector->RedefineGeometry(""); + } + else if(command ==ExportCmd ){ + Detector->ExportGeometry(value); + } } //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... diff --git a/NPSimulation/Core/DetectorMessenger.hh b/NPSimulation/Core/DetectorMessenger.hh index 1708a1cf648b4e6ffece9731922e5aa5b147a35a..28076258248a0c72230a8dddbce4461b379bdd5d 100644 --- a/NPSimulation/Core/DetectorMessenger.hh +++ b/NPSimulation/Core/DetectorMessenger.hh @@ -48,6 +48,7 @@ class DetectorMessenger: public G4UImessenger{ G4UIdirectory* detDir; G4UIcmdWithoutParameter* UpdateCmd; + G4UIcmdWithAString* ExportCmd; }; //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......