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 // 29 // >> 30 30 //....oooOO0OOooo........oooOO0OOooo........oo 31 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 31 //....oooOO0OOooo........oooOO0OOooo........oo 32 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 32 33 33 #include "DetectorConstruction.hh" 34 #include "DetectorConstruction.hh" 34 << 35 #include "DetectorMessenger.hh" 35 #include "DetectorMessenger.hh" >> 36 #include "G4Material.hh" >> 37 #include "G4NistManager.hh" 36 38 37 #include "G4Box.hh" 39 #include "G4Box.hh" 38 #include "G4GeometryManager.hh" << 39 #include "G4LogicalVolume.hh" 40 #include "G4LogicalVolume.hh" 40 #include "G4LogicalVolumeStore.hh" << 41 #include "G4Material.hh" << 42 #include "G4NistManager.hh" << 43 #include "G4PVPlacement.hh" 41 #include "G4PVPlacement.hh" 44 #include "G4PhysicalConstants.hh" << 42 >> 43 #include "G4GeometryManager.hh" 45 #include "G4PhysicalVolumeStore.hh" 44 #include "G4PhysicalVolumeStore.hh" 46 #include "G4RunManager.hh" << 45 #include "G4LogicalVolumeStore.hh" 47 #include "G4SolidStore.hh" 46 #include "G4SolidStore.hh" >> 47 #include "G4RunManager.hh" >> 48 48 #include "G4SystemOfUnits.hh" 49 #include "G4SystemOfUnits.hh" >> 50 #include "G4PhysicalConstants.hh" 49 #include "G4UnitsTable.hh" 51 #include "G4UnitsTable.hh" 50 52 51 //....oooOO0OOooo........oooOO0OOooo........oo 53 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 52 54 53 DetectorConstruction::DetectorConstruction() 55 DetectorConstruction::DetectorConstruction() >> 56 :G4VUserDetectorConstruction(), >> 57 fAbsorMaterial(nullptr), fLAbsor(nullptr), fWorldMaterial(nullptr), >> 58 fWorldVolume(nullptr), fDetectorMessenger(nullptr) 54 { 59 { 55 // default geometrical parameters 60 // default geometrical parameters 56 fAbsorThickness = 1 * cm; << 61 fAbsorThickness = 1*cm; 57 fAbsorSizeYZ = 1 * cm; << 62 fAbsorSizeYZ = 1*cm; 58 fWorldSizeX = 1.2 * fAbsorThickness; << 63 fWorldSizeX = 1.2*fAbsorThickness; 59 fWorldSizeYZ = 1.2 * fAbsorSizeYZ; << 64 fWorldSizeYZ = 1.2*fAbsorSizeYZ; 60 65 61 // materials 66 // materials 62 DefineMaterials(); 67 DefineMaterials(); 63 SetAbsorMaterial("G4_Co"); 68 SetAbsorMaterial("G4_Co"); 64 69 65 // create commands for interactive definitio 70 // create commands for interactive definition of the geometry 66 fDetectorMessenger = new DetectorMessenger(t 71 fDetectorMessenger = new DetectorMessenger(this); 67 } 72 } 68 73 69 //....oooOO0OOooo........oooOO0OOooo........oo 74 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 70 75 71 DetectorConstruction::~DetectorConstruction() 76 DetectorConstruction::~DetectorConstruction() 72 { << 77 { delete fDetectorMessenger;} 73 delete fDetectorMessenger; << 74 } << 75 78 76 //....oooOO0OOooo........oooOO0OOooo........oo 79 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 77 80 78 G4VPhysicalVolume* DetectorConstruction::Const 81 G4VPhysicalVolume* DetectorConstruction::Construct() 79 { 82 { 80 return ConstructVolumes(); 83 return ConstructVolumes(); 81 } 84 } 82 85 83 //....oooOO0OOooo........oooOO0OOooo........oo 86 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 84 87 85 void DetectorConstruction::DefineMaterials() 88 void DetectorConstruction::DefineMaterials() 86 { 89 { 87 // specific element name for thermal neutron 90 // specific element name for thermal neutronHP 88 // (see G4ParticleHPThermalScatteringNames.c 91 // (see G4ParticleHPThermalScatteringNames.cc) 89 92 90 G4int ncomponents, natoms; 93 G4int ncomponents, natoms; 91 94 92 // pressurized water 95 // pressurized water 93 G4Element* H = new G4Element("TS_H_of_Water" << 96 G4Element* H = new G4Element("TS_H_of_Water" ,"H" , 1., 1.0079*g/mole); 94 G4Element* O = new G4Element("Oxygen", "O", << 97 G4Element* O = new G4Element("Oxygen" ,"O" , 8., 16.00*g/mole); 95 G4Material* H2O = new G4Material("Water_ts", << 98 G4Material* H2O = 96 593 * kelvi << 99 new G4Material("Water_ts", 1.000*g/cm3, ncomponents=2, 97 H2O->AddElement(H, natoms = 2); << 100 kStateLiquid, 593*kelvin, 150*bar); 98 H2O->AddElement(O, natoms = 1); << 101 H2O->AddElement(H, natoms=2); 99 H2O->GetIonisation()->SetMeanExcitationEnerg << 102 H2O->AddElement(O, natoms=1); >> 103 H2O->GetIonisation()->SetMeanExcitationEnergy(78.0*eV); 100 104 101 // heavy water 105 // heavy water 102 G4Isotope* H2 = new G4Isotope("H2", 1, 2); << 106 G4Isotope* H2 = new G4Isotope("H2",1,2); 103 G4Element* D = new G4Element("TS_D_of_Heavy_ << 107 G4Element* D = new G4Element("TS_D_of_Heavy_Water", "D", 1); 104 D->AddIsotope(H2, 100 * perCent); << 108 D->AddIsotope(H2, 100*perCent); 105 G4Material* D2O = new G4Material("HeavyWater << 109 G4Material* D2O = new G4Material("HeavyWater", 1.11*g/cm3, ncomponents=2, 106 293.15 * ke << 110 kStateLiquid, 293.15*kelvin, 1*atmosphere); 107 D2O->AddElement(D, natoms = 2); << 111 D2O->AddElement(D, natoms=2); 108 D2O->AddElement(O, natoms = 1); << 112 D2O->AddElement(O, natoms=1); 109 113 110 // graphite 114 // graphite 111 G4Isotope* C12 = new G4Isotope("C12", 6, 12) << 115 G4Isotope* C12 = new G4Isotope("C12", 6, 12); 112 G4Element* C = new G4Element("TS_C_of_Graphi << 116 G4Element* C = new G4Element("TS_C_of_Graphite","C", ncomponents=1); 113 C->AddIsotope(C12, 100. * perCent); << 117 C->AddIsotope(C12, 100.*perCent); 114 G4Material* graphite = new G4Material("graph << 118 G4Material* graphite = 115 293 * << 119 new G4Material("graphite", 2.27*g/cm3, ncomponents=1, 116 graphite->AddElement(C, natoms = 1); << 120 kStateSolid, 293*kelvin, 1*atmosphere); >> 121 graphite->AddElement(C, natoms=1); 117 122 118 // example of vacuum 123 // example of vacuum 119 fWorldMaterial = new G4Material("Galactic", << 124 fWorldMaterial = new G4Material("Galactic", 1, 1.01*g/mole, 120 2.73 * kelvi << 125 universe_mean_density, kStateGas, 2.73*kelvin, 3.e-18*pascal); 121 126 122 /// G4cout << *(G4Material::GetMaterialTable << 127 ///G4cout << *(G4Material::GetMaterialTable()) << G4endl; 123 } 128 } 124 129 125 //....oooOO0OOooo........oooOO0OOooo........oo 130 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 126 131 127 G4Material* DetectorConstruction::MaterialWith << 132 G4Material* DetectorConstruction::MaterialWithSingleIsotope( G4String name, 128 << 133 G4String symbol, G4double density, G4int Z, G4int A) 129 { 134 { 130 // define a material from an isotope << 135 // define a material from an isotope 131 // << 136 // 132 G4int ncomponents; << 137 G4int ncomponents; 133 G4double abundance, massfraction; << 138 G4double abundance, massfraction; 134 << 135 G4Isotope* isotope = new G4Isotope(symbol, Z << 136 139 137 G4Element* element = new G4Element(name, sym << 140 G4Isotope* isotope = new G4Isotope(symbol, Z, A); 138 element->AddIsotope(isotope, abundance = 100 << 141 >> 142 G4Element* element = new G4Element(name, symbol, ncomponents=1); >> 143 element->AddIsotope(isotope, abundance= 100.*perCent); >> 144 >> 145 G4Material* material = new G4Material(name, density, ncomponents=1); >> 146 material->AddElement(element, massfraction=100.*perCent); 139 147 140 G4Material* material = new G4Material(name, << 148 return material; 141 material->AddElement(element, massfraction = << 142 << 143 return material; << 144 } 149 } 145 150 146 //....oooOO0OOooo........oooOO0OOooo........oo 151 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 147 152 148 G4VPhysicalVolume* DetectorConstruction::Const 153 G4VPhysicalVolume* DetectorConstruction::ConstructVolumes() 149 { 154 { 150 // Cleanup old geometry 155 // Cleanup old geometry 151 G4GeometryManager::GetInstance()->OpenGeomet 156 G4GeometryManager::GetInstance()->OpenGeometry(); 152 G4PhysicalVolumeStore::GetInstance()->Clean( 157 G4PhysicalVolumeStore::GetInstance()->Clean(); 153 G4LogicalVolumeStore::GetInstance()->Clean() 158 G4LogicalVolumeStore::GetInstance()->Clean(); 154 G4SolidStore::GetInstance()->Clean(); 159 G4SolidStore::GetInstance()->Clean(); 155 160 156 // World 161 // World 157 // 162 // 158 fWorldSizeX = 1.2 * fAbsorThickness; << 163 fWorldSizeX = 1.2*fAbsorThickness; 159 fWorldSizeYZ = 1.2 * fAbsorSizeYZ; << 164 fWorldSizeYZ = 1.2*fAbsorSizeYZ; 160 << 165 161 G4Box* sWorld = new G4Box("World", // name << 166 G4Box* 162 fWorldSizeX / 2, f << 167 sWorld = new G4Box("World", //name 163 << 168 fWorldSizeX/2,fWorldSizeYZ/2,fWorldSizeYZ/2); //dimensions 164 G4LogicalVolume* lWorld = new G4LogicalVolum << 169 165 << 170 G4LogicalVolume* 166 << 171 lWorld = new G4LogicalVolume(sWorld, //shape 167 << 172 fWorldMaterial, //material 168 fWorldVolume = new G4PVPlacement(0, // no r << 173 "World"); //name 169 G4ThreeVect << 174 170 lWorld, // << 175 fWorldVolume = new G4PVPlacement(0, //no rotation 171 "World", / << 176 G4ThreeVector(), //at (0,0,0) 172 0, // moth << 177 lWorld, //logical volume 173 false, // << 178 "World", //name 174 0); // cop << 179 0, //mother volume 175 << 180 false, //no boolean operation >> 181 0); //copy number >> 182 176 // Absorber 183 // Absorber 177 // 184 // 178 G4Box* sAbsor = new G4Box("Absorber", // na << 185 G4Box* sAbsor = new G4Box("Absorber", //name 179 fAbsorThickness / << 186 fAbsorThickness/2, fAbsorSizeYZ/2, fAbsorSizeYZ/2); //dimensions 180 187 181 fLAbsor = new G4LogicalVolume(sAbsor, // sh << 188 fLAbsor = new G4LogicalVolume(sAbsor, //shape 182 fAbsorMaterial << 189 fAbsorMaterial, //material 183 fAbsorMaterial << 190 fAbsorMaterial->GetName()); //name 184 << 191 185 new G4PVPlacement(0, // no rotation << 192 new G4PVPlacement(0, //no rotation 186 G4ThreeVector(), // at (0 << 193 G4ThreeVector(), //at (0,0,0) 187 fLAbsor, // logical volum << 194 fLAbsor, //logical volume 188 fAbsorMaterial->GetName(), << 195 fAbsorMaterial->GetName(), //name 189 lWorld, // mother volume << 196 lWorld, //mother volume 190 false, // no boolean oper << 197 false, //no boolean operation 191 0); // copy number << 198 0); //copy number 192 199 193 PrintParameters(); 200 PrintParameters(); 194 << 201 195 // always return the root volume << 202 //always return the root volume 196 // 203 // 197 return fWorldVolume; 204 return fWorldVolume; 198 } 205 } 199 206 200 //....oooOO0OOooo........oooOO0OOooo........oo 207 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 201 208 202 void DetectorConstruction::PrintParameters() 209 void DetectorConstruction::PrintParameters() 203 { 210 { 204 G4cout << "\n The Absorber is " << G4BestUni << 211 G4cout << "\n The Absorber is " << G4BestUnit(fAbsorThickness,"Length") 205 << fAbsorMaterial->GetName() << "\n \ << 212 << " of " << fAbsorMaterial->GetName() 206 << fAbsorMaterial << G4endl; << 213 << "\n \n" << fAbsorMaterial << G4endl; 207 } 214 } 208 215 209 //....oooOO0OOooo........oooOO0OOooo........oo 216 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 210 217 211 void DetectorConstruction::SetAbsorMaterial(G4 218 void DetectorConstruction::SetAbsorMaterial(G4String materialChoice) 212 { 219 { 213 // search the material by its name 220 // search the material by its name 214 G4Material* pttoMaterial = G4NistManager::In << 221 G4Material* pttoMaterial = 215 << 222 G4NistManager::Instance()->FindOrBuildMaterial(materialChoice); 216 if (pttoMaterial) { << 223 >> 224 if (pttoMaterial) { 217 fAbsorMaterial = pttoMaterial; 225 fAbsorMaterial = pttoMaterial; 218 if (fLAbsor) { << 226 if(fLAbsor) { fLAbsor->SetMaterial(fAbsorMaterial); } 219 fLAbsor->SetMaterial(fAbsorMaterial); << 220 } << 221 G4RunManager::GetRunManager()->PhysicsHasB 227 G4RunManager::GetRunManager()->PhysicsHasBeenModified(); 222 } << 228 } else { 223 else { << 229 G4cout << "\n--> warning from DetectorConstruction::SetMaterial : " 224 G4cout << "\n--> warning from DetectorCons << 230 << materialChoice << " not found" << G4endl; 225 << " not found" << G4endl; << 231 } 226 } << 227 } 232 } 228 233 229 //....oooOO0OOooo........oooOO0OOooo........oo 234 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 230 235 231 void DetectorConstruction::SetAbsorThickness(G 236 void DetectorConstruction::SetAbsorThickness(G4double value) 232 { 237 { 233 fAbsorThickness = value; 238 fAbsorThickness = value; 234 G4RunManager::GetRunManager()->ReinitializeG 239 G4RunManager::GetRunManager()->ReinitializeGeometry(); 235 } 240 } 236 241 237 //....oooOO0OOooo........oooOO0OOooo........oo 242 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 238 243 239 void DetectorConstruction::SetAbsorSizeYZ(G4do 244 void DetectorConstruction::SetAbsorSizeYZ(G4double value) 240 { 245 { 241 fAbsorSizeYZ = value; 246 fAbsorSizeYZ = value; 242 G4RunManager::GetRunManager()->ReinitializeG 247 G4RunManager::GetRunManager()->ReinitializeGeometry(); 243 } 248 } 244 249 245 //....oooOO0OOooo........oooOO0OOooo........oo 250 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 246 251