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" 36 35 37 #include "G4AutoDelete.hh" << 36 #include "G4NistManager.hh" >> 37 #include "G4Material.hh" 38 #include "G4Box.hh" 38 #include "G4Box.hh" 39 #include "G4GeometryManager.hh" << 40 #include "G4GlobalMagFieldMessenger.hh" << 41 #include "G4LogicalVolume.hh" 39 #include "G4LogicalVolume.hh" 42 #include "G4LogicalVolumeStore.hh" << 43 #include "G4Material.hh" << 44 #include "G4NistManager.hh" << 45 #include "G4PVPlacement.hh" 40 #include "G4PVPlacement.hh" 46 #include "G4PVReplica.hh" 41 #include "G4PVReplica.hh" 47 #include "G4PhysicalConstants.hh" << 42 #include "G4UniformMagField.hh" >> 43 >> 44 #include "G4GeometryManager.hh" 48 #include "G4PhysicalVolumeStore.hh" 45 #include "G4PhysicalVolumeStore.hh" 49 #include "G4RunManager.hh" << 46 #include "G4LogicalVolumeStore.hh" 50 #include "G4SolidStore.hh" 47 #include "G4SolidStore.hh" 51 #include "G4SystemOfUnits.hh" << 48 52 #include "G4UImanager.hh" 49 #include "G4UImanager.hh" 53 #include "G4UniformMagField.hh" << 54 #include "G4UnitsTable.hh" 50 #include "G4UnitsTable.hh" 55 << 51 #include "G4PhysicalConstants.hh" >> 52 #include "G4SystemOfUnits.hh" >> 53 #include "G4GlobalMagFieldMessenger.hh" >> 54 #include "G4AutoDelete.hh" >> 55 #include "G4RunManager.hh" 56 #include <iomanip> 56 #include <iomanip> 57 57 58 //....oooOO0OOooo........oooOO0OOooo........oo 58 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 59 59 60 DetectorConstruction::DetectorConstruction() 60 DetectorConstruction::DetectorConstruction() >> 61 :G4VUserDetectorConstruction(),fDefaultMaterial(0),fPhysiWorld(0), >> 62 fDetectorMessenger(0) 61 { 63 { 62 // default parameter values of the absorbers 64 // default parameter values of the absorbers 63 fNbOfAbsor = 1; 65 fNbOfAbsor = 1; 64 fAbsorThickness[0] = 0 * mm; // dummy, for << 66 fAbsorThickness[0] = 0*mm; //dummy, for initialization 65 fAbsorThickness[1] = 1 * mm; << 67 fAbsorThickness[1] = 1*mm; 66 fAbsorSizeYZ = 1 * mm; << 68 fAbsorSizeYZ = 1*mm; 67 69 68 ComputeParameters(); 70 ComputeParameters(); 69 71 70 // materials 72 // materials 71 DefineMaterials(); 73 DefineMaterials(); 72 SetAbsorMaterial(1, "G4_Si"); << 74 SetAbsorMaterial(1,"G4_Si"); 73 75 74 // create commands for interactive definitio 76 // create commands for interactive definition of the calorimeter 75 fDetectorMessenger = new DetectorMessenger(t 77 fDetectorMessenger = new DetectorMessenger(this); 76 } 78 } 77 79 78 //....oooOO0OOooo........oooOO0OOooo........oo 80 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 79 81 80 DetectorConstruction::~DetectorConstruction() 82 DetectorConstruction::~DetectorConstruction() 81 { 83 { 82 delete fDetectorMessenger; 84 delete fDetectorMessenger; 83 } 85 } 84 86 85 //....oooOO0OOooo........oooOO0OOooo........oo 87 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 86 88 87 G4VPhysicalVolume* DetectorConstruction::Const 89 G4VPhysicalVolume* DetectorConstruction::Construct() 88 { 90 { 89 return ConstructVolumes(); 91 return ConstructVolumes(); 90 } 92 } 91 93 92 //....oooOO0OOooo........oooOO0OOooo........oo 94 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 93 95 94 void DetectorConstruction::DefineMaterials() 96 void DetectorConstruction::DefineMaterials() 95 { 97 { 96 G4NistManager* man = G4NistManager::Instance 98 G4NistManager* man = G4NistManager::Instance(); 97 99 98 man->FindOrBuildMaterial("G4_AIR"); 100 man->FindOrBuildMaterial("G4_AIR"); 99 << 101 100 G4Element* H = man->FindOrBuildElement("H"); << 102 G4Element* H = man->FindOrBuildElement("H"); 101 G4Element* O = man->FindOrBuildElement("O"); 103 G4Element* O = man->FindOrBuildElement("O"); 102 << 104 103 G4Material* H2O = new G4Material("Water", 1. << 105 G4Material* H2O = >> 106 new G4Material("Water", 1.000*g/cm3, 2); 104 H2O->AddElement(H, 2); 107 H2O->AddElement(H, 2); 105 H2O->AddElement(O, 1); 108 H2O->AddElement(O, 1); 106 H2O->GetIonisation()->SetMeanExcitationEnerg << 109 H2O->GetIonisation()->SetMeanExcitationEnergy(78.0*eV); 107 110 108 G4Element* Hf = man->FindOrBuildElement("Hf" 111 G4Element* Hf = man->FindOrBuildElement("Hf"); 109 << 112 110 G4Material* HfO2 = new G4Material("HfO2", 9. << 113 G4Material* HfO2 = new G4Material("HfO2", 9.68*g/cm3, 2); 111 HfO2->AddElement(Hf, 1); 114 HfO2->AddElement(Hf, 1); 112 HfO2->AddElement(O, 2); << 115 HfO2->AddElement(O , 2); 113 << 116 114 // example of vacuum 117 // example of vacuum 115 G4double density = universe_mean_density; / << 118 G4double density = universe_mean_density; //from PhysicalConstants.h 116 G4double pressure = 3.e-18 * pascal; << 119 G4double pressure = 3.e-18*pascal; 117 G4double temperature = 2.73 * kelvin; << 120 G4double temperature = 2.73*kelvin; 118 G4Material* Galactic = << 121 G4Material* Galactic = 119 new G4Material("Galactic", 1., 1.008 * g / << 122 new G4Material("Galactic", 1., 1.008*g/mole, density, 120 << 123 kStateGas,temperature,pressure); >> 124 121 fDefaultMaterial = Galactic; 125 fDefaultMaterial = Galactic; 122 << 126 123 // G4cout << *(G4Material::GetMaterialTable 127 // G4cout << *(G4Material::GetMaterialTable()) << G4endl; 124 } 128 } 125 129 126 //....oooOO0OOooo........oooOO0OOooo........oo 130 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 127 131 128 G4Material* DetectorConstruction::MaterialWith << 132 G4Material* DetectorConstruction::MaterialWithSingleIsotope( G4String name, 129 << 133 G4String symbol, G4double density, G4int Z, G4int A) 130 { 134 { 131 // define a material from an isotope << 135 // define a material from an isotope 132 // << 136 // 133 G4int ncomponents; << 137 G4int ncomponents; 134 G4double abundance, massfraction; << 138 G4double abundance, massfraction; 135 << 139 136 G4Isotope* isotope = new G4Isotope(symbol, Z << 140 G4Isotope* isotope = new G4Isotope(symbol, Z, A); 137 << 141 138 G4Element* element = new G4Element(name, sym << 142 G4Element* element = new G4Element(name, symbol, ncomponents=1); 139 element->AddIsotope(isotope, abundance = 100 << 143 element->AddIsotope(isotope, abundance= 100.*perCent); 140 << 144 141 G4Material* material = new G4Material(name, << 145 G4Material* material = new G4Material(name, density, ncomponents=1); 142 material->AddElement(element, massfraction = << 146 material->AddElement(element, massfraction=100.*perCent); 143 147 144 return material; << 148 return material; 145 } 149 } 146 150 147 //....oooOO0OOooo........oooOO0OOooo........oo 151 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 148 152 149 void DetectorConstruction::ComputeParameters() 153 void DetectorConstruction::ComputeParameters() 150 { 154 { 151 // Compute total thickness of absorbers 155 // Compute total thickness of absorbers 152 fAbsorSizeX = 0.; 156 fAbsorSizeX = 0.; 153 for (G4int iAbs = 1; iAbs <= fNbOfAbsor; iAb << 157 for (G4int iAbs=1; iAbs<=fNbOfAbsor; iAbs++) { 154 fAbsorSizeX += fAbsorThickness[iAbs]; 158 fAbsorSizeX += fAbsorThickness[iAbs]; 155 } 159 } 156 fWorldSizeX = 1.2 * fAbsorSizeX; << 160 fWorldSizeX = 1.2*fAbsorSizeX; 157 fWorldSizeYZ = 1.2 * fAbsorSizeYZ; << 161 fWorldSizeYZ = 1.2*fAbsorSizeYZ; 158 } 162 } 159 163 160 //....oooOO0OOooo........oooOO0OOooo........oo 164 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 161 165 162 G4VPhysicalVolume* DetectorConstruction::Const 166 G4VPhysicalVolume* DetectorConstruction::ConstructVolumes() 163 { 167 { 164 // complete the Calor parameters definition 168 // complete the Calor parameters definition 165 ComputeParameters(); 169 ComputeParameters(); 166 170 167 // Cleanup old geometry 171 // Cleanup old geometry 168 G4GeometryManager::GetInstance()->OpenGeomet 172 G4GeometryManager::GetInstance()->OpenGeometry(); 169 G4PhysicalVolumeStore::GetInstance()->Clean( 173 G4PhysicalVolumeStore::GetInstance()->Clean(); 170 G4LogicalVolumeStore::GetInstance()->Clean() 174 G4LogicalVolumeStore::GetInstance()->Clean(); 171 G4SolidStore::GetInstance()->Clean(); 175 G4SolidStore::GetInstance()->Clean(); 172 176 173 // 177 // 174 // World 178 // World 175 // 179 // 176 G4Box* solidWorld = new G4Box("World", // n << 180 G4Box* solidWorld = 177 fWorldSizeX / << 181 new G4Box("World", //name 178 << 182 fWorldSizeX/2,fWorldSizeYZ/2,fWorldSizeYZ/2); //size 179 G4LogicalVolume* logicWorld = new G4LogicalV << 183 180 << 184 G4LogicalVolume* logicWorld = 181 << 185 new G4LogicalVolume(solidWorld, //solid 182 << 186 fDefaultMaterial, //material 183 fPhysiWorld = new G4PVPlacement(0, // no ro << 187 "World"); //name 184 G4ThreeVecto << 188 185 logicWorld, << 189 fPhysiWorld = 186 "World", // << 190 new G4PVPlacement(0, //no rotation 187 0, // mothe << 191 G4ThreeVector(), //at (0,0,0) 188 false, // n << 192 logicWorld, //logical volume 189 0); // copy << 193 "World", //name 190 << 194 0, //mother volume >> 195 false, //no boolean operation >> 196 0); //copy number >> 197 191 // 198 // 192 // Absorbers 199 // Absorbers 193 // 200 // 194 fXfront[0] = -0.5 * fAbsorSizeX; << 201 fXfront[0] = -0.5*fAbsorSizeX; 195 // 202 // 196 for (G4int k = 1; k <= fNbOfAbsor; k++) { << 203 for (G4int k=1; k<=fNbOfAbsor; k++) { 197 G4Material* material = fAbsorMaterial[k]; 204 G4Material* material = fAbsorMaterial[k]; 198 G4String matname = material->GetName(); 205 G4String matname = material->GetName(); 199 << 206 200 G4Box* solidAbsor = 207 G4Box* solidAbsor = 201 new G4Box(matname, fAbsorThickness[k] / << 208 new G4Box(matname,fAbsorThickness[k]/2,fAbsorSizeYZ/2,fAbsorSizeYZ/2); 202 209 203 G4LogicalVolume* logicAbsor = new G4Logica << 210 G4LogicalVolume* logicAbsor = 204 << 211 new G4LogicalVolume(solidAbsor, // solid 205 << 212 material, // material 206 << 213 matname); // name 207 fXfront[k] = fXfront[k - 1] + fAbsorThickn << 214 208 G4double xcenter = fXfront[k] + 0.5 * fAbs << 215 fXfront[k] = fXfront[k-1] + fAbsorThickness[k-1]; 209 G4ThreeVector position = G4ThreeVector(xce << 216 G4double xcenter = fXfront[k]+0.5*fAbsorThickness[k]; 210 << 217 G4ThreeVector position = G4ThreeVector(xcenter,0.,0.); 211 new G4PVPlacement(0, // no rotation << 218 212 position, // position << 219 new G4PVPlacement(0, //no rotation 213 logicAbsor, // logical << 220 position, //position 214 matname, // name << 221 logicAbsor, //logical volume 215 logicWorld, // mother << 222 matname, //name 216 false, // no boulean op << 223 logicWorld, //mother 217 k); // copy number << 224 false, //no boulean operat >> 225 k); //copy number 218 } 226 } 219 227 220 PrintParameters(); 228 PrintParameters(); 221 229 222 // always return the physical World << 230 //always return the physical World 223 // 231 // 224 return fPhysiWorld; 232 return fPhysiWorld; 225 } 233 } 226 234 227 //....oooOO0OOooo........oooOO0OOooo........oo 235 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 228 236 229 void DetectorConstruction::PrintParameters() 237 void DetectorConstruction::PrintParameters() 230 { 238 { 231 G4cout << "\n------------------------------- 239 G4cout << "\n-------------------------------------------------------------" 232 << "\n ---> The Absorber is " << fNbO 240 << "\n ---> The Absorber is " << fNbOfAbsor << " layers of:"; 233 for (G4int i = 1; i <= fNbOfAbsor; i++) { << 241 for (G4int i=1; i<=fNbOfAbsor; i++) 234 G4cout << "\n \t" << std::setw(12) << fAbs << 242 { 235 << G4BestUnit(fAbsorThickness[i], " << 243 G4cout << "\n \t" << std::setw(12) << fAbsorMaterial[i]->GetName() <<": " 236 } << 244 << std::setw(6) << G4BestUnit(fAbsorThickness[i],"Length"); 237 G4cout << "\n------------------------------- << 245 } >> 246 G4cout << "\n-------------------------------------------------------------\n" >> 247 << G4endl; 238 } 248 } 239 249 240 //....oooOO0OOooo........oooOO0OOooo........oo 250 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 241 251 242 void DetectorConstruction::SetNbOfAbsor(G4int 252 void DetectorConstruction::SetNbOfAbsor(G4int ival) 243 { 253 { 244 // set the number of Absorbers 254 // set the number of Absorbers 245 // 255 // 246 if (ival < 1 || ival > (kMaxAbsor - 1)) { << 256 if (ival < 1 || ival > (kMaxAbsor-1)) 247 G4cout << "\n ---> warning from SetfNbOfAb << 257 { G4cout << "\n ---> warning from SetfNbOfAbsor: " 248 << kMaxAbsor - 1 << ". Command refu << 258 << ival << " must be at least 1 and and most " << kMaxAbsor-1 249 return; << 259 << ". Command refused" << G4endl; 250 } << 260 return; >> 261 } 251 fNbOfAbsor = ival; 262 fNbOfAbsor = ival; 252 G4RunManager::GetRunManager()->ReinitializeG 263 G4RunManager::GetRunManager()->ReinitializeGeometry(); 253 } 264 } 254 265 255 //....oooOO0OOooo........oooOO0OOooo........oo 266 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 256 267 257 void DetectorConstruction::SetAbsorMaterial(G4 << 268 void DetectorConstruction::SetAbsorMaterial(G4int iabs,const G4String& material) 258 { 269 { 259 // search the material by its name 270 // search the material by its name 260 // 271 // 261 if (iabs > fNbOfAbsor || iabs <= 0) { << 272 if (iabs > fNbOfAbsor || iabs <= 0) 262 G4cout << "\n --->warning from SetfAbsorMa << 273 { G4cout << "\n --->warning from SetfAbsorMaterial: absor number " 263 << " out of range. Command refused" << 274 << iabs << " out of range. Command refused" << G4endl; 264 return; << 275 return; 265 } << 276 } 266 277 267 G4Material* pttoMaterial = G4NistManager::In << 278 G4Material* pttoMaterial = >> 279 G4NistManager::Instance()->FindOrBuildMaterial(material); 268 if (pttoMaterial) { 280 if (pttoMaterial) { 269 fAbsorMaterial[iabs] = pttoMaterial; << 281 fAbsorMaterial[iabs] = pttoMaterial; 270 G4RunManager::GetRunManager()->PhysicsHasB << 282 G4RunManager::GetRunManager()->PhysicsHasBeenModified(); 271 } 283 } 272 } 284 } 273 285 274 //....oooOO0OOooo........oooOO0OOooo........oo 286 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 275 287 276 void DetectorConstruction::SetAbsorThickness(G << 288 void DetectorConstruction::SetAbsorThickness(G4int iabs,G4double val) 277 { 289 { 278 // change Absorber thickness 290 // change Absorber thickness 279 // 291 // 280 if (iabs > fNbOfAbsor || iabs <= 0) { << 292 if (iabs > fNbOfAbsor || iabs <= 0) 281 G4cout << "\n --->warning from SetfAbsorTh << 293 { G4cout << "\n --->warning from SetfAbsorThickness: absor number " 282 << " out of range. Command refused" << 294 << iabs << " out of range. Command refused" << G4endl; 283 return; << 295 return; 284 } << 296 } 285 if (val <= DBL_MIN) { << 297 if (val <= DBL_MIN) 286 G4cout << "\n --->warning from SetfAbsorTh << 298 { G4cout << "\n --->warning from SetfAbsorThickness: thickness " 287 << " out of range. Command refused" << 299 << val << " out of range. Command refused" << G4endl; 288 return; << 300 return; 289 } << 301 } 290 fAbsorThickness[iabs] = val; 302 fAbsorThickness[iabs] = val; 291 G4RunManager::GetRunManager()->ReinitializeG 303 G4RunManager::GetRunManager()->ReinitializeGeometry(); 292 } 304 } 293 305 294 //....oooOO0OOooo........oooOO0OOooo........oo 306 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 295 307 296 void DetectorConstruction::SetAbsorSizeYZ(G4do 308 void DetectorConstruction::SetAbsorSizeYZ(G4double val) 297 { 309 { 298 // change the transverse size 310 // change the transverse size 299 // 311 // 300 if (val <= DBL_MIN) { << 312 if (val <= DBL_MIN) 301 G4cout << "\n --->warning from SetfAbsorSi << 313 { G4cout << "\n --->warning from SetfAbsorSizeYZ: thickness " 302 << " out of range. Command refused" << 314 << val << " out of range. Command refused" << G4endl; 303 return; << 315 return; 304 } << 316 } 305 fAbsorSizeYZ = val; 317 fAbsorSizeYZ = val; 306 G4RunManager::GetRunManager()->ReinitializeG 318 G4RunManager::GetRunManager()->ReinitializeGeometry(); 307 } 319 } 308 320 309 //....oooOO0OOooo........oooOO0OOooo........oo 321 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 310 322 311 void DetectorConstruction::ConstructSDandField 323 void DetectorConstruction::ConstructSDandField() 312 { 324 { 313 if (fFieldMessenger.Get() == 0) { << 325 if ( fFieldMessenger.Get() == 0 ) { 314 // Create global magnetic field messenger. << 326 // Create global magnetic field messenger. 315 // Uniform magnetic field is then created << 327 // Uniform magnetic field is then created automatically if 316 // the field value is not zero. << 328 // the field value is not zero. 317 G4ThreeVector fieldValue = G4ThreeVector() << 329 G4ThreeVector fieldValue = G4ThreeVector(); 318 G4GlobalMagFieldMessenger* msg = new G4Glo << 330 G4GlobalMagFieldMessenger* msg = 319 // msg->SetVerboseLevel(1); << 331 new G4GlobalMagFieldMessenger(fieldValue); 320 G4AutoDelete::Register(msg); << 332 //msg->SetVerboseLevel(1); 321 fFieldMessenger.Put(msg); << 333 G4AutoDelete::Register(msg); 322 } << 334 fFieldMessenger.Put( msg ); >> 335 } 323 } 336 } 324 337 325 //....oooOO0OOooo........oooOO0OOooo........oo 338 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... >> 339 326 340