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 //....oooOO0OOooo........oooOO0OOooo........oo 30 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 31 //....oooOO0OOooo........oooOO0OOooo........oo 31 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 32 32 33 #include "DetectorConstruction.hh" 33 #include "DetectorConstruction.hh" 34 << 35 #include "DetectorMessenger.hh" 34 #include "DetectorMessenger.hh" >> 35 #include "G4Material.hh" >> 36 #include "G4NistManager.hh" 36 37 37 #include "G4Box.hh" 38 #include "G4Box.hh" 38 #include "G4GeometryManager.hh" << 39 #include "G4Tubs.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" 48 #include "G4SystemOfUnits.hh" << 47 #include "G4RunManager.hh" 49 #include "G4Tubs.hh" << 48 50 #include "G4UnitsTable.hh" 49 #include "G4UnitsTable.hh" >> 50 #include "G4SystemOfUnits.hh" >> 51 #include "G4PhysicalConstants.hh" 51 52 52 //....oooOO0OOooo........oooOO0OOooo........oo 53 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 53 54 54 DetectorConstruction::DetectorConstruction() 55 DetectorConstruction::DetectorConstruction() 55 { 56 { 56 fAbsorRadius = 15 * mm; << 57 fAbsorRadius = 15*mm; 57 fAbsorLength = 60 * mm; << 58 fAbsorLength = 60*mm; 58 fContainThickness = 2.4 * mm; << 59 fContainThickness = 2.4*mm; 59 DefineMaterials(); 60 DefineMaterials(); 60 SetAbsorMaterial("BeO"); << 61 SetAbsorMaterial ("BeO"); 61 SetContainMaterial("Stainless-Steel"); 62 SetContainMaterial("Stainless-Steel"); 62 fDetectorMessenger = new DetectorMessenger(t 63 fDetectorMessenger = new DetectorMessenger(this); 63 } 64 } 64 65 65 //....oooOO0OOooo........oooOO0OOooo........oo 66 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 66 67 67 DetectorConstruction::~DetectorConstruction() 68 DetectorConstruction::~DetectorConstruction() 68 { << 69 { delete fDetectorMessenger;} 69 delete fDetectorMessenger; << 70 } << 71 70 72 //....oooOO0OOooo........oooOO0OOooo........oo 71 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 73 72 74 G4VPhysicalVolume* DetectorConstruction::Const 73 G4VPhysicalVolume* DetectorConstruction::Construct() 75 { 74 { 76 return ConstructVolumes(); 75 return ConstructVolumes(); 77 } 76 } 78 77 79 //....oooOO0OOooo........oooOO0OOooo........oo 78 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 80 79 81 void DetectorConstruction::DefineMaterials() 80 void DetectorConstruction::DefineMaterials() 82 { 81 { 83 G4int ncomponents, natoms; 82 G4int ncomponents, natoms; 84 << 83 85 G4Element* Be = new G4Element("Beryllium", " << 84 G4Element* Be = new G4Element("Beryllium","Be" , 4., 9.01*g/mole); 86 G4Element* N = new G4Element("Nitrogen", "N" << 85 G4Element* N = new G4Element("Nitrogen" ,"N" , 7., 14.01*g/mole); 87 G4Element* O = new G4Element("Oxygen", "O", << 86 G4Element* O = new G4Element("Oxygen" ,"O" , 8., 16.00*g/mole); 88 G4Element* Cr = new G4Element("Chromium", "C << 87 G4Element* Cr = new G4Element("Chromium" ,"Cr" , 24., 51.99*g/mole); 89 G4Element* Fe = new G4Element("Iron", "Fe", << 88 G4Element* Fe = new G4Element("Iron" ,"Fe" , 26., 55.84*g/mole); 90 G4Element* Ni = new G4Element("Nickel", "Ni" << 89 G4Element* Ni = new G4Element("Nickel" ,"Ni" , 28., 58.69*g/mole); 91 << 90 92 G4Material* BeO = new G4Material("BeO", 3.05 << 91 G4Material* BeO = 93 BeO->AddElement(Be, natoms = 1); << 92 new G4Material("BeO", 3.05*g/cm3, ncomponents=2); 94 BeO->AddElement(O, natoms = 1); << 93 BeO->AddElement(Be, natoms=1); 95 << 94 BeO->AddElement( O, natoms=1); 96 G4Material* inox = new G4Material("Stainless << 95 97 inox->AddElement(Fe, 74 * perCent); << 96 G4Material* inox = 98 inox->AddElement(Cr, 18 * perCent); << 97 new G4Material("Stainless-Steel", 8*g/cm3, ncomponents=3); 99 inox->AddElement(Ni, 8 * perCent); << 98 inox->AddElement(Fe, 74*perCent); 100 << 99 inox->AddElement(Cr, 18*perCent); 101 G4Material* Air = new G4Material("Air", 1.29 << 100 inox->AddElement(Ni, 8*perCent); 102 Air->AddElement(N, 70. * perCent); << 101 103 Air->AddElement(O, 30. * perCent); << 102 G4Material* Air = >> 103 new G4Material("Air", 1.290*mg/cm3, ncomponents=2); >> 104 Air->AddElement(N, 70.*perCent); >> 105 Air->AddElement(O, 30.*perCent); 104 106 105 fWorldMaterial = Air; 107 fWorldMaterial = Air; 106 << 108 107 /// G4cout << *(G4Material::GetMaterialTable << 109 ///G4cout << *(G4Material::GetMaterialTable()) << G4endl; 108 } 110 } 109 111 110 //....oooOO0OOooo........oooOO0OOooo........oo 112 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 111 113 112 G4Material* DetectorConstruction::MaterialWith << 114 G4Material* DetectorConstruction::MaterialWithSingleIsotope( G4String name, 113 << 115 G4String symbol, G4double density, G4int Z, G4int A) 114 { 116 { 115 // define a material from an isotope << 117 // define a material from an isotope 116 // << 118 // 117 G4int ncomponents; << 119 G4int ncomponents; 118 G4double abundance, massfraction; << 120 G4double abundance, massfraction; 119 121 120 G4Isotope* isotope = new G4Isotope(symbol, Z << 122 G4Isotope* isotope = new G4Isotope(symbol, Z, A); >> 123 >> 124 G4Element* element = new G4Element(name, symbol, ncomponents=1); >> 125 element->AddIsotope(isotope, abundance= 100.*perCent); >> 126 >> 127 G4Material* material = new G4Material(name, density, ncomponents=1); >> 128 material->AddElement(element, massfraction=100.*perCent); 121 129 122 G4Element* element = new G4Element(name, sym << 130 return material; 123 element->AddIsotope(isotope, abundance = 100 << 124 << 125 G4Material* material = new G4Material(name, << 126 material->AddElement(element, massfraction = << 127 << 128 return material; << 129 } 131 } 130 132 131 //....oooOO0OOooo........oooOO0OOooo........oo 133 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 132 134 133 G4VPhysicalVolume* DetectorConstruction::Const 135 G4VPhysicalVolume* DetectorConstruction::ConstructVolumes() 134 { 136 { 135 // Cleanup old geometry 137 // Cleanup old geometry 136 G4GeometryManager::GetInstance()->OpenGeomet 138 G4GeometryManager::GetInstance()->OpenGeometry(); 137 G4PhysicalVolumeStore::GetInstance()->Clean( 139 G4PhysicalVolumeStore::GetInstance()->Clean(); 138 G4LogicalVolumeStore::GetInstance()->Clean() 140 G4LogicalVolumeStore::GetInstance()->Clean(); 139 G4SolidStore::GetInstance()->Clean(); 141 G4SolidStore::GetInstance()->Clean(); 140 << 142 141 // compute dimensions 143 // compute dimensions 142 G4double ContainRadius = fAbsorRadius + fCon 144 G4double ContainRadius = fAbsorRadius + fContainThickness; 143 G4double ContainLength = fAbsorLength + 2 * << 145 G4double ContainLength = fAbsorLength + 2*fContainThickness; 144 << 146 145 G4double WorldSizeXY = 2.4 * ContainRadius; << 147 G4double WorldSizeXY = 2.4*ContainRadius; 146 G4double WorldSizeZ = 1.2 * ContainLength; << 148 G4double WorldSizeZ = 1.2*ContainLength; 147 << 149 148 // World 150 // World 149 // 151 // 150 G4Box* sWorld = new G4Box("World", // name << 152 G4Box* 151 0.5 * WorldSizeXY, << 153 sWorld = new G4Box("World", //name 152 << 154 0.5*WorldSizeXY,0.5*WorldSizeXY,0.5*WorldSizeZ); //dimensions 153 G4LogicalVolume* lWorld = new G4LogicalVolum << 155 154 << 156 G4LogicalVolume* 155 << 157 lWorld = new G4LogicalVolume(sWorld, //shape 156 << 158 fWorldMaterial, //material 157 fPWorld = new G4PVPlacement(0, // no rotati << 159 "World"); //name 158 G4ThreeVector(), << 160 159 lWorld, // logi << 161 fPWorld = new G4PVPlacement(0, //no rotation 160 "World", // nam << 162 G4ThreeVector(), //at (0,0,0) 161 0, // mother vo << 163 lWorld, //logical volume 162 false, // no bo << 164 "World", //name 163 0); // copy num << 165 0, //mother volume >> 166 false, //no boolean operation >> 167 0); //copy number 164 168 165 // Container 169 // Container 166 // 170 // 167 G4Tubs* sContain = new G4Tubs("Container", << 171 G4Tubs* 168 0., ContainRad << 172 sContain = new G4Tubs("Container", //name 169 << 173 0., ContainRadius, 0.5*ContainLength, 0., twopi); //dimensions 170 fLContain = new G4LogicalVolume(sContain, / << 174 171 fContainMate << 175 fLContain = new G4LogicalVolume(sContain, //shape 172 fContainMate << 176 fContainMaterial, //material 173 << 177 fContainMaterial->GetName()); //name 174 new G4PVPlacement(0, // no rotation << 178 175 G4ThreeVector(), // at (0 << 179 new G4PVPlacement(0, //no rotation 176 fLContain, // logical vol << 180 G4ThreeVector(), //at (0,0,0) 177 fContainMaterial->GetName( << 181 fLContain, //logical volume 178 lWorld, // mother volume << 182 fContainMaterial->GetName(), //name 179 false, // no boolean oper << 183 lWorld, //mother volume 180 0); // copy number << 184 false, //no boolean operation >> 185 0); //copy number 181 186 182 // Absorber 187 // Absorber 183 // 188 // 184 G4Tubs* sAbsor = new G4Tubs("Absorber", // << 189 G4Tubs* 185 0., fAbsorRadius << 190 sAbsor = new G4Tubs("Absorber", //name 186 << 191 0., fAbsorRadius, 0.5*fAbsorLength, 0., twopi); //dimensions 187 fLAbsor = new G4LogicalVolume(sAbsor, // sh << 192 188 fAbsorMaterial << 193 fLAbsor = new G4LogicalVolume(sAbsor, //shape 189 fAbsorMaterial << 194 fAbsorMaterial, //material 190 << 195 fAbsorMaterial->GetName()); //name 191 new G4PVPlacement(0, // no rotation << 196 192 G4ThreeVector(), // at (0 << 197 new G4PVPlacement(0, //no rotation 193 fLAbsor, // logical volum << 198 G4ThreeVector(), //at (0,0,0) 194 fAbsorMaterial->GetName(), << 199 fLAbsor, //logical volume 195 fLContain, // mother vol << 200 fAbsorMaterial->GetName(), //name 196 false, // no boolean oper << 201 fLContain, //mother volume 197 0); // copy number << 202 false, //no boolean operation >> 203 0); //copy number 198 204 199 PrintParameters(); 205 PrintParameters(); 200 << 206 201 // always return the root volume << 207 //always return the root volume 202 // 208 // 203 return fPWorld; 209 return fPWorld; 204 } 210 } 205 211 206 //....oooOO0OOooo........oooOO0OOooo........oo 212 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 207 213 208 void DetectorConstruction::PrintParameters() 214 void DetectorConstruction::PrintParameters() 209 { 215 { 210 G4cout << "\n The Absorber is a cylinder of << 216 G4cout << "\n The Absorber is a cylinder of " << fAbsorMaterial->GetName() 211 << " radius = " << G4BestUnit(fAbsor << 217 << " radius = " << G4BestUnit(fAbsorRadius,"Length") 212 << " length = " << G4BestUnit(fAbsor << 218 << " length = " << G4BestUnit(fAbsorLength,"Length") << G4endl; 213 G4cout << " The Container is a cylinder of " << 219 G4cout << " The Container is a cylinder of " << fContainMaterial->GetName() 214 << " thickness = " << G4BestUnit(fCo << 220 << " thickness = " << G4BestUnit(fContainThickness,"Length") << G4endl; 215 << 221 216 G4cout << "\n" << fAbsorMaterial << G4endl; << 222 G4cout << "\n" << fAbsorMaterial << G4endl; 217 G4cout << "\n" << fContainMaterial << G4endl << 223 G4cout << "\n" << fContainMaterial << G4endl; 218 } 224 } 219 225 220 //....oooOO0OOooo........oooOO0OOooo........oo 226 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 221 227 222 void DetectorConstruction::SetAbsorMaterial(G4 228 void DetectorConstruction::SetAbsorMaterial(G4String materialChoice) 223 { 229 { 224 // search the material by its name 230 // search the material by its name 225 G4Material* pttoMaterial = G4NistManager::In << 231 G4Material* pttoMaterial = 226 << 232 G4NistManager::Instance()->FindOrBuildMaterial(materialChoice); 227 if (pttoMaterial) { << 233 >> 234 if (pttoMaterial) { 228 fAbsorMaterial = pttoMaterial; 235 fAbsorMaterial = pttoMaterial; 229 if (fLAbsor) { << 236 if(fLAbsor) { fLAbsor->SetMaterial(fAbsorMaterial); } 230 fLAbsor->SetMaterial(fAbsorMaterial); << 231 } << 232 G4RunManager::GetRunManager()->PhysicsHasB 237 G4RunManager::GetRunManager()->PhysicsHasBeenModified(); 233 } << 238 } else { 234 else { << 239 G4cout << "\n--> warning from DetectorConstruction::SetAbsorMaterial : " 235 G4cout << "\n--> warning from DetectorCons << 240 << materialChoice << " not found" << G4endl; 236 << " not found" << G4endl; << 241 } 237 } << 238 } 242 } 239 243 240 //....oooOO0OOooo........oooOO0OOooo........oo 244 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 241 245 242 void DetectorConstruction::SetContainMaterial( 246 void DetectorConstruction::SetContainMaterial(G4String materialChoice) 243 { 247 { 244 // search the material by its name 248 // search the material by its name 245 G4Material* pttoMaterial = G4NistManager::In << 249 G4Material* pttoMaterial = 246 << 250 G4NistManager::Instance()->FindOrBuildMaterial(materialChoice); 247 if (pttoMaterial) { << 251 >> 252 if (pttoMaterial) { 248 fContainMaterial = pttoMaterial; 253 fContainMaterial = pttoMaterial; 249 if (fLContain) { << 254 if(fLContain) { fLContain->SetMaterial(fContainMaterial); } 250 fLContain->SetMaterial(fContainMaterial) << 251 } << 252 G4RunManager::GetRunManager()->PhysicsHasB 255 G4RunManager::GetRunManager()->PhysicsHasBeenModified(); 253 } << 256 } else { 254 else { << 257 G4cout << "\n--> warning from DetectorConstruction::SetContainMaterial : " 255 G4cout << "\n--> warning from DetectorCons << 258 << materialChoice << " not found" << G4endl; 256 << " not found" << G4endl; << 259 } 257 } << 258 } 260 } 259 261 260 //....oooOO0OOooo........oooOO0OOooo........oo 262 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 261 263 262 void DetectorConstruction::SetAbsorRadius(G4do 264 void DetectorConstruction::SetAbsorRadius(G4double value) 263 { 265 { 264 fAbsorRadius = value; 266 fAbsorRadius = value; 265 G4RunManager::GetRunManager()->ReinitializeG 267 G4RunManager::GetRunManager()->ReinitializeGeometry(); 266 } 268 } 267 269 268 //....oooOO0OOooo........oooOO0OOooo........oo 270 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 269 271 270 void DetectorConstruction::SetAbsorLength(G4do 272 void DetectorConstruction::SetAbsorLength(G4double value) 271 { 273 { 272 fAbsorLength = value; 274 fAbsorLength = value; 273 G4RunManager::GetRunManager()->ReinitializeG 275 G4RunManager::GetRunManager()->ReinitializeGeometry(); 274 } 276 } 275 277 276 //....oooOO0OOooo........oooOO0OOooo........oo 278 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 277 279 278 void DetectorConstruction::SetContainThickness 280 void DetectorConstruction::SetContainThickness(G4double value) 279 { 281 { 280 fContainThickness = value; 282 fContainThickness = value; 281 G4RunManager::GetRunManager()->ReinitializeG 283 G4RunManager::GetRunManager()->ReinitializeGeometry(); 282 } 284 } 283 285 284 //....oooOO0OOooo........oooOO0OOooo........oo 286 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... >> 287 285 288