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 /// \file DetectorConstruction.cc 26 /// \file DetectorConstruction.cc 27 /// \brief Implementation of the DetectorConst 27 /// \brief Implementation of the DetectorConstruction class 28 28 29 #include "DetectorConstruction.hh" 29 #include "DetectorConstruction.hh" 30 30 31 #include "DetectorMessenger.hh" 31 #include "DetectorMessenger.hh" 32 32 33 #include "G4Box.hh" 33 #include "G4Box.hh" 34 #include "G4Colour.hh" 34 #include "G4Colour.hh" 35 #include "G4GeometryManager.hh" << 36 #include "G4LogicalVolume.hh" 35 #include "G4LogicalVolume.hh" 37 #include "G4LogicalVolumeStore.hh" << 38 #include "G4Material.hh" 36 #include "G4Material.hh" 39 #include "G4NistManager.hh" 37 #include "G4NistManager.hh" 40 #include "G4PVPlacement.hh" 38 #include "G4PVPlacement.hh" 41 #include "G4PhysicalVolumeStore.hh" << 42 #include "G4Region.hh" << 43 #include "G4RegionStore.hh" << 44 #include "G4RunManager.hh" << 45 #include "G4SolidStore.hh" << 46 #include "G4SystemOfUnits.hh" 39 #include "G4SystemOfUnits.hh" 47 #include "G4Tubs.hh" 40 #include "G4Tubs.hh" 48 #include "G4VisAttributes.hh" 41 #include "G4VisAttributes.hh" >> 42 #include "G4Region.hh" >> 43 #include "G4RegionStore.hh" >> 44 #include "G4PhysicalVolumeStore.hh" >> 45 #include "G4LogicalVolumeStore.hh" >> 46 #include "G4GeometryManager.hh" >> 47 #include "G4SolidStore.hh" >> 48 >> 49 #include "G4RunManager.hh" 49 50 50 //....oooOO0OOooo........oooOO0OOooo........oo 51 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 51 52 52 DetectorConstruction::DetectorConstruction() 53 DetectorConstruction::DetectorConstruction() 53 : G4VUserDetectorConstruction(), fDiameter(6 << 54 : G4VUserDetectorConstruction(), fDiameter(6*nm), fLength(10*nm) 54 { 55 { 55 fDetectorMessenger = new DetectorMessenger(t << 56 fDetectorMessenger = new DetectorMessenger(this); 56 } 57 } 57 58 58 //....oooOO0OOooo........oooOO0OOooo........oo 59 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 59 60 60 DetectorConstruction::~DetectorConstruction() 61 DetectorConstruction::~DetectorConstruction() 61 { 62 { 62 delete fDetectorMessenger; << 63 delete fDetectorMessenger; 63 } 64 } 64 65 65 //....oooOO0OOooo........oooOO0OOooo........oo 66 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 66 G4VPhysicalVolume* DetectorConstruction::Const << 67 G4VPhysicalVolume* DetectorConstruction::Construct() { 67 { << 68 return ConstructVolumes(); 68 return ConstructVolumes(); << 69 } 69 } 70 70 71 //....oooOO0OOooo........oooOO0OOooo........oo 71 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 72 72 73 G4VPhysicalVolume* DetectorConstruction::Const 73 G4VPhysicalVolume* DetectorConstruction::ConstructVolumes() 74 { 74 { 75 // Cleanup old geometry << 75 // Cleanup old geometry 76 // << 76 // 77 G4GeometryManager::GetInstance()->OpenGeomet << 77 G4GeometryManager::GetInstance()->OpenGeometry(); 78 G4PhysicalVolumeStore::GetInstance()->Clean( << 78 G4PhysicalVolumeStore::GetInstance()->Clean(); 79 G4LogicalVolumeStore::GetInstance()->Clean() << 79 G4LogicalVolumeStore::GetInstance()->Clean(); 80 G4SolidStore::GetInstance()->Clean(); << 80 G4SolidStore::GetInstance()->Clean(); 81 81 82 // << 82 // 83 G4Material* water = G4NistManager::Instance( << 83 G4Material* water = G4NistManager::Instance()->FindOrBuildMaterial("G4_WATER"); 84 84 85 // Geometry parameters << 85 // Geometry parameters 86 G4double worldSize = 150 * nanometer; << 86 G4double worldSize = 150 * nanometer; 87 87 88 G4VSolid* world = new G4Box("world", // its << 88 G4VSolid* world = new G4Box("world", // its name 89 worldSize / 2, w << 89 worldSize/2, worldSize/2, worldSize/2); // its size 90 90 91 G4LogicalVolume* worldLog = new G4LogicalVol << 91 G4LogicalVolume* worldLog = new G4LogicalVolume( 92 << 92 world, // its solid 93 << 93 water, // its material >> 94 "world"); // its name 94 95 95 G4VisAttributes* vis = new G4VisAttributes(G << 96 G4VisAttributes *vis = new G4VisAttributes(G4Colour(G4Colour::Blue())); 96 worldLog->SetVisAttributes(vis); << 97 worldLog->SetVisAttributes(vis); 97 98 98 G4VPhysicalVolume* worldPhys = new G4PVPlace << 99 G4VPhysicalVolume* worldPhys = new G4PVPlacement( 99 << 100 0, // no rotation 100 << 101 G4ThreeVector(), // at (0,0,0) 101 << 102 worldLog, // its logical volume 102 << 103 "world", // its name 103 << 104 0, // its mother volume 104 << 105 false, // no boolean operation 105 << 106 0, // copy number >> 107 true); // checking overlaps forced to YES 106 108 107 G4VSolid* target = new G4Tubs("target", 0, f << 109 G4VSolid* target = new G4Tubs("target", >> 110 0, fDiameter/2, fLength/2, 0, 360*deg); //its size 108 111 109 G4LogicalVolume* targetLog = new G4LogicalVo << 112 G4LogicalVolume* targetLog = new G4LogicalVolume( >> 113 target, >> 114 water, >> 115 "target"); 110 116 111 new G4PVPlacement(0, // no rotation << 117 new G4PVPlacement(0, // no rotation 112 G4ThreeVector(), // at (0 << 118 G4ThreeVector(), // at (0,0,0) 113 targetLog, // its logical << 119 targetLog, // its logical volume 114 "target", // its name << 120 "target", // its name 115 worldLog, // its mother v << 121 worldLog, // its mother volume 116 false, // no boolean oper << 122 false, // no boolean operation 117 0, // copy number << 123 0, // copy number 118 true); // checking overla << 124 true); // checking overlaps force to YES 119 125 120 // A region is needed as splitting is perfor << 126 // A region is needed as splitting is performed in regions 121 G4Region* aRegion = G4RegionStore::GetInstan << 127 G4Region* aRegion = G4RegionStore::GetInstance()->FindOrCreateRegion("Target"); 122 targetLog->SetRegion(aRegion); << 128 targetLog->SetRegion(aRegion); 123 aRegion->AddRootLogicalVolume(targetLog); << 129 aRegion->AddRootLogicalVolume(targetLog); 124 130 125 G4VisAttributes* visTarget = new G4VisAttrib << 131 G4VisAttributes *visTarget = new G4VisAttributes(G4Colour(G4Colour::Blue())); 126 visTarget->SetForceSolid(true); << 132 visTarget->SetForceSolid(true); 127 visTarget->SetVisibility(true); << 133 visTarget->SetVisibility(true); 128 targetLog->SetVisAttributes(visTarget); << 134 targetLog->SetVisAttributes(visTarget); 129 135 130 return worldPhys; << 136 return worldPhys; 131 } 137 } 132 138 133 //....oooOO0OOooo........oooOO0OOooo........oo 139 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 134 140 135 void DetectorConstruction::SetDiameter(G4doubl << 141 void DetectorConstruction::SetDiameter(G4double diameter) { 136 { << 142 fDiameter = diameter; 137 fDiameter = diameter; << 143 G4RunManager::GetRunManager()->GeometryHasBeenModified(); 138 G4RunManager::GetRunManager()->GeometryHasBe << 139 } 144 } 140 145 141 //....oooOO0OOooo........oooOO0OOooo........oo 146 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 142 147 143 void DetectorConstruction::SetLength(G4double << 148 void DetectorConstruction::SetLength(G4double length) { 144 { << 149 fLength = length; 145 fLength = length; << 150 G4RunManager::GetRunManager()->GeometryHasBeenModified(); 146 G4RunManager::GetRunManager()->GeometryHasBe << 147 } 151 } 148 152 149 //....oooOO0OOooo........oooOO0OOooo........oo 153 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 150 154 151 #include "G4RunManager.hh" 155 #include "G4RunManager.hh" 152 156 153 void DetectorConstruction::UpdateGeometry() 157 void DetectorConstruction::UpdateGeometry() 154 { 158 { 155 G4RunManager::GetRunManager()->DefineWorldVo << 159 G4RunManager::GetRunManager()->DefineWorldVolume(ConstructVolumes()); 156 } 160 } 157 161 158 //....oooOO0OOooo........oooOO0OOooo........oo 162 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 159 163