Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer 3 // * License and Disclaimer * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/ 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. 9 // * include a list of copyright holders. * 10 // * 10 // * * 11 // * Neither the authors of this software syst 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitatio 16 // * for the full disclaimer and the limitation of liability. * 17 // * 17 // * * 18 // * This code implementation is the result 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboratio 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distri 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you ag 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publicati 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Sof 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************* 24 // ******************************************************************** 25 // 25 // 26 26 27 #include "OpNoviceGDMLDetectorConstruction.hh" 27 #include "OpNoviceGDMLDetectorConstruction.hh" 28 << 29 #include "OpNoviceDetectorMessenger.hh" 28 #include "OpNoviceDetectorMessenger.hh" 30 29 >> 30 #include "globals.hh" 31 #include "G4GDMLParser.hh" 31 #include "G4GDMLParser.hh" 32 #include "G4LogicalVolumeStore.hh" 32 #include "G4LogicalVolumeStore.hh" 33 #include "G4NistManager.hh" 33 #include "G4NistManager.hh" 34 #include "G4PhysicalVolumeStore.hh" 34 #include "G4PhysicalVolumeStore.hh" 35 #include "G4RunManager.hh" 35 #include "G4RunManager.hh" 36 #include "G4VisAttributes.hh" 36 #include "G4VisAttributes.hh" 37 #include "globals.hh" << 38 37 39 //....oooOO0OOooo........oooOO0OOooo........oo 38 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 40 OpNoviceGDMLDetectorConstruction::OpNoviceGDML << 39 OpNoviceGDMLDetectorConstruction::OpNoviceGDMLDetectorConstruction( >> 40 G4String fname) 41 : G4VUserDetectorConstruction() 41 : G4VUserDetectorConstruction() 42 { 42 { 43 fGdmlFile = fname; << 43 fDumpGdmlFileName = "OpNovice_dump.gdml"; >> 44 fVerbose = false; >> 45 fDumpGdml = false; >> 46 fGdmlFile = fname; 44 // create a messenger for this class 47 // create a messenger for this class 45 fDetectorMessenger = new OpNoviceDetectorMes 48 fDetectorMessenger = new OpNoviceDetectorMessenger(this); 46 49 47 G4cout << "Building detector from GDML file: 50 G4cout << "Building detector from GDML file: " << fname << G4endl << G4endl; 48 } 51 } 49 52 50 //....oooOO0OOooo........oooOO0OOooo........oo 53 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 51 OpNoviceGDMLDetectorConstruction::~OpNoviceGDM 54 OpNoviceGDMLDetectorConstruction::~OpNoviceGDMLDetectorConstruction() 52 { 55 { 53 delete fDetectorMessenger; 56 delete fDetectorMessenger; 54 delete fParser; 57 delete fParser; 55 } 58 } 56 59 57 //....oooOO0OOooo........oooOO0OOooo........oo 60 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 58 G4VPhysicalVolume* OpNoviceGDMLDetectorConstru 61 G4VPhysicalVolume* OpNoviceGDMLDetectorConstruction::Construct() 59 { 62 { 60 ReadGDML(); 63 ReadGDML(); 61 G4VPhysicalVolume* worldPhysVol = fParser->G 64 G4VPhysicalVolume* worldPhysVol = fParser->GetWorldVolume(); 62 if (fDumpGdml) fParser->Write(fDumpGdmlFileN << 65 if(fDumpGdml) >> 66 fParser->Write(fDumpGdmlFileName, worldPhysVol); 63 return worldPhysVol; 67 return worldPhysVol; 64 } 68 } 65 69 66 //....oooOO0OOooo........oooOO0OOooo........oo 70 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 67 void OpNoviceGDMLDetectorConstruction::Constru 71 void OpNoviceGDMLDetectorConstruction::ConstructSDandField() {} 68 72 69 //....oooOO0OOooo........oooOO0OOooo........oo 73 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 70 void OpNoviceGDMLDetectorConstruction::ReadGDM 74 void OpNoviceGDMLDetectorConstruction::ReadGDML() 71 { 75 { 72 fParser = new G4GDMLParser(); 76 fParser = new G4GDMLParser(); 73 fParser->Read(fGdmlFile, false); 77 fParser->Read(fGdmlFile, false); 74 G4VPhysicalVolume* world = fParser->GetWorld 78 G4VPhysicalVolume* world = fParser->GetWorldVolume(); 75 // GDML parser makes world invisible. make i 79 // GDML parser makes world invisible. make it visible again. 76 G4LogicalVolume* pworldLogical = world->GetL 80 G4LogicalVolume* pworldLogical = world->GetLogicalVolume(); 77 pworldLogical->SetVisAttributes(nullptr); << 81 pworldLogical->SetVisAttributes(0); 78 G4cout << world->GetTranslation() << G4endl 82 G4cout << world->GetTranslation() << G4endl << G4endl; 79 if (fVerbose) { << 83 if(fVerbose) >> 84 { 80 G4cout << "Found world: " << world->GetNa 85 G4cout << "Found world: " << world->GetName() << G4endl; 81 G4cout << "world LV: " << world->GetLogic 86 G4cout << "world LV: " << world->GetLogicalVolume()->GetName() << G4endl; 82 } 87 } 83 G4LogicalVolumeStore* pLVStore = G4LogicalVo 88 G4LogicalVolumeStore* pLVStore = G4LogicalVolumeStore::GetInstance(); 84 if (fVerbose) { << 89 if(fVerbose) 85 G4cout << "Found " << pLVStore->size() << << 90 { >> 91 G4cout << "Found " << pLVStore->size() << " logical volumes." << G4endl >> 92 << G4endl; 86 } 93 } 87 G4PhysicalVolumeStore* pPVStore = G4Physical 94 G4PhysicalVolumeStore* pPVStore = G4PhysicalVolumeStore::GetInstance(); 88 if (fVerbose) { << 95 if(fVerbose) 89 G4cout << "Found " << pPVStore->size() << << 96 { >> 97 G4cout << "Found " << pPVStore->size() << " physical volumes." << G4endl >> 98 << G4endl; 90 } 99 } 91 } 100 } 92 101 93 //....oooOO0OOooo........oooOO0OOooo........oo 102 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 94 void OpNoviceGDMLDetectorConstruction::UpdateG 103 void OpNoviceGDMLDetectorConstruction::UpdateGeometry() 95 { 104 { 96 G4RunManager::GetRunManager()->DefineWorldVo 105 G4RunManager::GetRunManager()->DefineWorldVolume(Construct()); 97 } 106 } 98 107 99 //....oooOO0OOooo........oooOO0OOooo........oo 108 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 100 void OpNoviceGDMLDetectorConstruction::SetDump 109 void OpNoviceGDMLDetectorConstruction::SetDumpGdml(G4bool val) 101 { 110 { 102 fDumpGdml = val; 111 fDumpGdml = val; 103 } 112 } 104 113 105 //....oooOO0OOooo........oooOO0OOooo........oo 114 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 106 G4bool OpNoviceGDMLDetectorConstruction::IsDum 115 G4bool OpNoviceGDMLDetectorConstruction::IsDumpGdml() const 107 { 116 { 108 return fDumpGdml; 117 return fDumpGdml; 109 } 118 } 110 119 111 //....oooOO0OOooo........oooOO0OOooo........oo 120 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 112 void OpNoviceGDMLDetectorConstruction::SetVerb 121 void OpNoviceGDMLDetectorConstruction::SetVerbose(G4bool val) 113 { 122 { 114 fVerbose = val; 123 fVerbose = val; 115 } 124 } 116 125 117 //....oooOO0OOooo........oooOO0OOooo........oo 126 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 118 G4bool OpNoviceGDMLDetectorConstruction::IsVer << 127 G4bool OpNoviceGDMLDetectorConstruction::IsVerbose() const { return fVerbose; } 119 { << 120 return fVerbose; << 121 } << 122 128 123 //....oooOO0OOooo........oooOO0OOooo........oo 129 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 124 void OpNoviceGDMLDetectorConstruction::SetDump 130 void OpNoviceGDMLDetectorConstruction::SetDumpGdmlFile(G4String val) 125 { 131 { 126 fDumpGdmlFileName = val; 132 fDumpGdmlFileName = val; 127 } 133 } 128 134 129 //....oooOO0OOooo........oooOO0OOooo........oo 135 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 130 G4String OpNoviceGDMLDetectorConstruction::Get 136 G4String OpNoviceGDMLDetectorConstruction::GetDumpGdmlFileName() const 131 { 137 { 132 return fDumpGdmlFileName; 138 return fDumpGdmlFileName; 133 } 139 } 134 140