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