File indexing completed on 2026-09-20 08:30:56
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029 #include "OpNoviceGDMLDetectorConstruction.hh"
0030
0031 #include "OpNoviceDetectorMessenger.hh"
0032
0033 #include "G4GDMLParser.hh"
0034 #include "G4LogicalVolumeStore.hh"
0035 #include "G4NistManager.hh"
0036 #include "G4PhysicalVolumeStore.hh"
0037 #include "G4RunManager.hh"
0038 #include "G4VisAttributes.hh"
0039 #include "globals.hh"
0040
0041
0042 OpNoviceGDMLDetectorConstruction::OpNoviceGDMLDetectorConstruction(G4String fname)
0043 : G4VUserDetectorConstruction()
0044 {
0045 fGdmlFile = fname;
0046
0047 fDetectorMessenger = new OpNoviceDetectorMessenger(this);
0048
0049 G4cout << "Building detector from GDML file: " << fname << G4endl << G4endl;
0050 }
0051
0052
0053 OpNoviceGDMLDetectorConstruction::~OpNoviceGDMLDetectorConstruction()
0054 {
0055 delete fDetectorMessenger;
0056 delete fParser;
0057 }
0058
0059
0060 G4VPhysicalVolume* OpNoviceGDMLDetectorConstruction::Construct()
0061 {
0062 ReadGDML();
0063 G4VPhysicalVolume* worldPhysVol = fParser->GetWorldVolume();
0064 if (fDumpGdml) fParser->Write(fDumpGdmlFileName, worldPhysVol);
0065 return worldPhysVol;
0066 }
0067
0068
0069 void OpNoviceGDMLDetectorConstruction::ConstructSDandField() {}
0070
0071
0072 void OpNoviceGDMLDetectorConstruction::ReadGDML()
0073 {
0074 fParser = new G4GDMLParser();
0075 fParser->Read(fGdmlFile, false);
0076 G4VPhysicalVolume* world = fParser->GetWorldVolume();
0077
0078 G4LogicalVolume* pworldLogical = world->GetLogicalVolume();
0079 pworldLogical->SetVisAttributes(nullptr);
0080 G4cout << world->GetTranslation() << G4endl << G4endl;
0081 if (fVerbose) {
0082 G4cout << "Found world: " << world->GetName() << G4endl;
0083 G4cout << "world LV: " << world->GetLogicalVolume()->GetName() << G4endl;
0084 }
0085 G4LogicalVolumeStore* pLVStore = G4LogicalVolumeStore::GetInstance();
0086 if (fVerbose) {
0087 G4cout << "Found " << pLVStore->size() << " logical volumes." << G4endl << G4endl;
0088 }
0089 G4PhysicalVolumeStore* pPVStore = G4PhysicalVolumeStore::GetInstance();
0090 if (fVerbose) {
0091 G4cout << "Found " << pPVStore->size() << " physical volumes." << G4endl << G4endl;
0092 }
0093 }
0094
0095
0096 void OpNoviceGDMLDetectorConstruction::UpdateGeometry()
0097 {
0098 G4RunManager::GetRunManager()->DefineWorldVolume(Construct());
0099 }
0100
0101
0102 void OpNoviceGDMLDetectorConstruction::SetDumpGdml(G4bool val)
0103 {
0104 fDumpGdml = val;
0105 }
0106
0107
0108 G4bool OpNoviceGDMLDetectorConstruction::IsDumpGdml() const
0109 {
0110 return fDumpGdml;
0111 }
0112
0113
0114 void OpNoviceGDMLDetectorConstruction::SetVerbose(G4bool val)
0115 {
0116 fVerbose = val;
0117 }
0118
0119
0120 G4bool OpNoviceGDMLDetectorConstruction::IsVerbose() const
0121 {
0122 return fVerbose;
0123 }
0124
0125
0126 void OpNoviceGDMLDetectorConstruction::SetDumpGdmlFile(G4String val)
0127 {
0128 fDumpGdmlFileName = val;
0129 }
0130
0131
0132 G4String OpNoviceGDMLDetectorConstruction::GetDumpGdmlFileName() const
0133 {
0134 return fDumpGdmlFileName;
0135 }