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 electromagnetic/TestEm11/src/Detecto << 26 // $Id: DetectorConstruction.cc,v 1.8 2007/11/07 17:22:16 maire Exp $ 27 /// \brief Implementation of the DetectorConst << 27 // GEANT4 tag $Name: geant4-09-02 $ 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" 38 #include "G4Box.hh" 37 #include "G4Box.hh" 39 #include "G4GeometryManager.hh" << 40 #include "G4GlobalMagFieldMessenger.hh" << 41 #include "G4LogicalVolume.hh" 38 #include "G4LogicalVolume.hh" 42 #include "G4LogicalVolumeStore.hh" << 39 #include "G4VPhysicalVolume.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" << 52 #include "G4UImanager.hh" << 53 #include "G4UniformMagField.hh" << 54 #include "G4UnitsTable.hh" << 55 48 56 #include <iomanip> << 49 #include "G4UnitsTable.hh" 57 50 58 //....oooOO0OOooo........oooOO0OOooo........oo 51 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 59 52 60 DetectorConstruction::DetectorConstruction() 53 DetectorConstruction::DetectorConstruction() 61 { 54 { 62 // default parameter values of the absorbers << 55 // default parameter values 63 fNbOfAbsor = 1; << 56 absorSizeX = absorSizeYZ = 1*mm; 64 fAbsorThickness[0] = 0. * mm; // dummy, for << 57 nbOfLayers = 1; 65 fAbsorThickness[1] = 1. * mm; << 58 66 fAbsorSizeYZ = 1. * mm; << 59 absorMaterial = 0; 67 for (G4int iAbs = 0; iAbs < kMaxAbsor; iAbs+ << 60 magField = 0; 68 fNbOfDivisions[iAbs] = 1; << 61 pAbsor = 0; 69 } << 62 70 ComputeParameters(); << 71 << 72 // materials << 73 DefineMaterials(); 63 DefineMaterials(); 74 SetAbsorMaterial(1, "G4_Si"); << 64 SetMaterial("G4_Si"); 75 65 76 // create commands for interactive definitio << 66 // create commands for interactive definition of the detector 77 fDetectorMessenger = new DetectorMessenger(t << 67 detectorMessenger = new DetectorMessenger(this); 78 } 68 } 79 69 80 //....oooOO0OOooo........oooOO0OOooo........oo 70 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 81 71 82 DetectorConstruction::~DetectorConstruction() 72 DetectorConstruction::~DetectorConstruction() 83 { << 73 { delete detectorMessenger;} 84 delete fDetectorMessenger; << 85 } << 86 74 87 //....oooOO0OOooo........oooOO0OOooo........oo 75 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 88 76 89 G4VPhysicalVolume* DetectorConstruction::Const 77 G4VPhysicalVolume* DetectorConstruction::Construct() 90 { 78 { 91 return ConstructVolumes(); 79 return ConstructVolumes(); 92 } 80 } 93 81 94 //....oooOO0OOooo........oooOO0OOooo........oo 82 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 95 83 96 void DetectorConstruction::DefineMaterials() 84 void DetectorConstruction::DefineMaterials() 97 { << 85 { 98 G4NistManager* man = G4NistManager::Instance 86 G4NistManager* man = G4NistManager::Instance(); 99 << 87 100 man->FindOrBuildMaterial("G4_Al"); << 88 G4bool isotopes = false; 101 man->FindOrBuildMaterial("G4_Si"); << 89 102 man->FindOrBuildMaterial("G4_Fe"); << 90 man->FindOrBuildMaterial("G4_Al", isotopes); 103 man->FindOrBuildMaterial("G4_Cu"); << 91 man->FindOrBuildMaterial("G4_Si", isotopes); 104 man->FindOrBuildMaterial("G4_Ge"); << 92 man->FindOrBuildMaterial("G4_Fe", isotopes); 105 man->FindOrBuildMaterial("G4_Mo"); << 93 man->FindOrBuildMaterial("G4_Ge", isotopes); 106 man->FindOrBuildMaterial("G4_Ta"); << 94 man->FindOrBuildMaterial("G4_Mo", isotopes); 107 man->FindOrBuildMaterial("G4_W"); << 95 man->FindOrBuildMaterial("G4_Ta", isotopes); 108 man->FindOrBuildMaterial("G4_Au"); << 96 man->FindOrBuildMaterial("G4_W" , isotopes); 109 man->FindOrBuildMaterial("G4_Pb"); << 97 man->FindOrBuildMaterial("G4_Au", isotopes); 110 man->FindOrBuildMaterial("G4_PbWO4"); << 98 man->FindOrBuildMaterial("G4_Pb", isotopes); 111 man->FindOrBuildMaterial("G4_SODIUM_IODIDE") << 99 man->FindOrBuildMaterial("G4_PbWO4", isotopes); 112 << 100 man->FindOrBuildMaterial("G4_SODIUM_IODIDE", isotopes); 113 man->FindOrBuildMaterial("G4_AIR"); << 101 114 man->FindOrBuildMaterial("G4_WATER"); << 102 man->FindOrBuildMaterial("G4_AIR" , isotopes); 115 << 103 ///man->FindOrBuildMaterial("G4_WATER", isotopes); 116 G4Element* H = man->FindOrBuildElement("H"); << 104 117 G4Element* O = man->FindOrBuildElement("O"); << 105 G4Element* H = man->FindOrBuildElement("H", isotopes); 118 << 106 G4Element* O = man->FindOrBuildElement("O", isotopes); 119 G4Material* H2O = new G4Material("Water", 1. << 107 >> 108 G4Material* H2O = >> 109 new G4Material("Water", 1.000*g/cm3, 2); 120 H2O->AddElement(H, 2); 110 H2O->AddElement(H, 2); 121 H2O->AddElement(O, 1); 111 H2O->AddElement(O, 1); 122 H2O->GetIonisation()->SetMeanExcitationEnerg << 112 H2O->GetIonisation()->SetMeanExcitationEnergy(75.0*eV); 123 << 113 124 G4double density = universe_mean_density; / << 114 G4cout << *(G4Material::GetMaterialTable()) << G4endl; 125 G4double pressure = 3.e-18 * pascal; << 126 G4double temperature = 2.73 * kelvin; << 127 G4Material* Galactic = << 128 new G4Material("Galactic", 1., 1.008 * g / << 129 << 130 fDefaultMaterial = Galactic; << 131 << 132 // G4cout << *(G4Material::GetMaterialTable << 133 } 115 } 134 116 135 //....oooOO0OOooo........oooOO0OOooo........oo 117 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 136 << 118 137 void DetectorConstruction::ComputeParameters() << 138 { << 139 // Compute total thickness of absorbers << 140 fAbsorSizeX = 0.; << 141 for (G4int iAbs = 1; iAbs <= fNbOfAbsor; iAb << 142 fAbsorSizeX += fAbsorThickness[iAbs]; << 143 } << 144 } << 145 << 146 //....oooOO0OOooo........oooOO0OOooo........oo << 147 << 148 G4VPhysicalVolume* DetectorConstruction::Const 119 G4VPhysicalVolume* DetectorConstruction::ConstructVolumes() 149 { 120 { 150 // complete the Calor parameters definition << 151 ComputeParameters(); << 152 << 153 // Cleanup old geometry << 154 G4GeometryManager::GetInstance()->OpenGeomet 121 G4GeometryManager::GetInstance()->OpenGeometry(); 155 G4PhysicalVolumeStore::GetInstance()->Clean( 122 G4PhysicalVolumeStore::GetInstance()->Clean(); 156 G4LogicalVolumeStore::GetInstance()->Clean() 123 G4LogicalVolumeStore::GetInstance()->Clean(); 157 G4SolidStore::GetInstance()->Clean(); 124 G4SolidStore::GetInstance()->Clean(); 158 << 125 159 // << 126 // Absorber 160 // World << 161 // << 162 G4Box* solidWorld = new G4Box("World", // n << 163 fAbsorSizeX / << 164 << 165 G4LogicalVolume* logicWorld = new G4LogicalV << 166 << 167 << 168 << 169 fPhysiWorld = new G4PVPlacement(0, // no ro << 170 G4ThreeVecto << 171 logicWorld, << 172 "World", // << 173 0, // mothe << 174 false, // n << 175 0); // copy << 176 << 177 // 127 // 178 // Absorbers << 128 G4Box* 179 // << 129 sAbsor = new G4Box("Absorber", //name 180 fXfront[0] = -0.5 * fAbsorSizeX; << 130 absorSizeX/2,absorSizeYZ/2,absorSizeYZ/2); //size 181 // << 131 182 for (G4int k = 1; k <= fNbOfAbsor; k++) { << 132 G4LogicalVolume* 183 G4Material* material = fAbsorMaterial[k]; << 133 lAbsor = new G4LogicalVolume(sAbsor, //solid 184 G4String matname = material->GetName(); << 134 absorMaterial, //material 185 << 135 "Absorber"); //name 186 G4Box* solidAbsor = << 136 187 new G4Box(matname, fAbsorThickness[k] / << 137 pAbsor = new G4PVPlacement(0, //no rotation 188 << 138 G4ThreeVector(), //at (0,0,0) 189 G4LogicalVolume* logicAbsor = new G4Logica << 139 lAbsor, //logical volume 190 << 140 "Absorber", //name 191 << 141 0, //mother volume 192 << 142 false, //no boolean operation 193 fXfront[k] = fXfront[k - 1] + fAbsorThickn << 143 0); //copy number 194 G4double xcenter = fXfront[k] + 0.5 * fAbs << 144 195 G4ThreeVector position = G4ThreeVector(xce << 145 // Layers 196 << 146 // 197 new G4PVPlacement(0, // no rotation << 147 layerThickness = absorSizeX/nbOfLayers; 198 position, // position << 148 199 logicAbsor, // logical << 149 if (nbOfLayers > 1) { 200 matname, // name << 150 201 logicWorld, // mother << 151 G4Box* 202 false, // no boulean op << 152 sLayer = new G4Box("Layer", //name 203 k); // copy number << 153 layerThickness/2,absorSizeYZ/2,absorSizeYZ/2); //dimensions 204 << 154 205 // divisions, if any << 155 G4LogicalVolume* 206 // << 156 lLayer = new G4LogicalVolume(sLayer, //shape 207 G4double LayerThickness = fAbsorThickness[ << 157 absorMaterial, //material 208 G4Box* solidLayer = new G4Box(matname, Lay << 158 "Layer"); //name 209 << 159 210 G4LogicalVolume* logicLayer = new G4Logica << 160 new G4PVReplica("Layer", //name 211 << 161 lLayer, //logical volume 212 << 162 lAbsor, //mother volume 213 << 163 kXAxis, //axis of replica 214 new G4PVReplica(matname, // name << 164 nbOfLayers, //number of replica 215 logicLayer, // logical vo << 165 layerThickness); //width of replica 216 logicAbsor, // mother << 166 } 217 kXAxis, // axis of replic << 218 fNbOfDivisions[k], // num << 219 LayerThickness); // witdt << 220 } << 221 167 222 PrintParameters(); 168 PrintParameters(); 223 << 169 224 // always return the physical World << 225 // 170 // 226 return fPhysiWorld; << 171 //always return the root volume >> 172 // >> 173 return pAbsor; 227 } 174 } 228 175 229 //....oooOO0OOooo........oooOO0OOooo........oo 176 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 230 177 231 void DetectorConstruction::PrintParameters() 178 void DetectorConstruction::PrintParameters() 232 { 179 { 233 G4cout << "\n------------------------------- << 180 G4cout << "\n---------------------------------------------------------\n"; 234 << "\n ---> The Absorber is " << fNbO << 181 G4cout << "---> The Absorber is " << G4BestUnit(absorSizeX,"Length") 235 for (G4int i = 1; i <= fNbOfAbsor; i++) { << 182 << " of " << absorMaterial->GetName() << " divided in " << nbOfLayers 236 G4cout << "\n \t" << std::setw(16) << fAbs << 183 << " slices of " << G4BestUnit(layerThickness,"Length") << G4endl; 237 << G4BestUnit(fAbsorThickness[i], " << 184 G4cout << "\n---------------------------------------------------------\n"; 238 << " slices"; << 239 } << 240 G4cout << "\n------------------------------- << 241 } 185 } 242 186 243 //....oooOO0OOooo........oooOO0OOooo........oo 187 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 244 188 245 void DetectorConstruction::SetNbOfAbsor(G4int << 189 void DetectorConstruction::SetSizeX(G4double value) 246 { 190 { 247 // set the number of Absorbers << 191 absorSizeX = value; 248 // << 249 if (ival < 1 || ival > (kMaxAbsor - 1)) { << 250 G4cout << "\n ---> warning from SetfNbOfAb << 251 << kMaxAbsor - 1 << ". Command refu << 252 return; << 253 } << 254 fNbOfAbsor = ival; << 255 G4RunManager::GetRunManager()->ReinitializeG << 256 } 192 } 257 << 193 258 //....oooOO0OOooo........oooOO0OOooo........oo 194 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 259 195 260 void DetectorConstruction::SetAbsorMaterial(G4 << 196 void DetectorConstruction::SetSizeYZ(G4double value) 261 { 197 { 262 // search the material by its name << 198 absorSizeYZ = value; 263 // << 199 } 264 if (iabs > fNbOfAbsor || iabs <= 0) { << 265 G4cout << "\n --->warning from SetfAbsorMa << 266 << " out of range. Command refused" << 267 return; << 268 } << 269 << 270 G4Material* pttoMaterial = G4NistManager::In << 271 if (pttoMaterial) { << 272 fAbsorMaterial[iabs] = pttoMaterial; << 273 G4RunManager::GetRunManager()->PhysicsHasB << 274 G4cout << "\n " << pttoMaterial << G4endl; << 275 } << 276 } << 277 200 278 //....oooOO0OOooo........oooOO0OOooo........oo 201 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 279 202 280 void DetectorConstruction::SetAbsorThickness(G << 203 void DetectorConstruction::SetMaterial(G4String materialChoice) 281 { 204 { 282 // change Absorber thickness << 205 // search the material by its name 283 // << 206 G4Material* pttoMaterial = G4Material::GetMaterial(materialChoice); 284 if (iabs > fNbOfAbsor || iabs <= 0) { << 207 if (pttoMaterial) absorMaterial = pttoMaterial; 285 G4cout << "\n --->warning from SetfAbsorTh << 286 << " out of range. Command refused" << 287 return; << 288 } << 289 if (val <= DBL_MIN) { << 290 G4cout << "\n --->warning from SetfAbsorTh << 291 << " out of range. Command refused" << 292 return; << 293 } << 294 fAbsorThickness[iabs] = val; << 295 G4RunManager::GetRunManager()->ReinitializeG << 296 } 208 } 297 209 298 //....oooOO0OOooo........oooOO0OOooo........oo 210 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 299 211 300 void DetectorConstruction::SetAbsorSizeYZ(G4do << 212 void DetectorConstruction::SetNbOfLayers(G4int value) 301 { 213 { 302 // change the transverse size << 214 nbOfLayers = value; 303 // << 304 if (val <= DBL_MIN) { << 305 G4cout << "\n --->warning from SetfAbsorSi << 306 << " out of range. Command refused" << 307 return; << 308 } << 309 fAbsorSizeYZ = val; << 310 G4RunManager::GetRunManager()->ReinitializeG << 311 } 215 } 312 << 216 313 //....oooOO0OOooo........oooOO0OOooo........oo 217 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 314 218 315 void DetectorConstruction::SetNbOfDivisions(G4 << 219 #include "G4FieldManager.hh" >> 220 #include "G4TransportationManager.hh" >> 221 >> 222 void DetectorConstruction::SetMagField(G4double fieldValue) 316 { 223 { 317 // set the number of divisions << 224 //apply a global uniform magnetic field along Z axis 318 // << 225 G4FieldManager* fieldMgr 319 if (iabs > fNbOfAbsor || iabs < 1) { << 226 = G4TransportationManager::GetTransportationManager()->GetFieldManager(); 320 G4cout << "\n --->warning from SetNbOfDivi << 227 321 << " out of range. Command refused" << 228 if (magField) delete magField; //delete the existing magn field 322 return; << 229 323 } << 230 if (fieldValue!=0.) // create a new one if non nul 324 << 231 { 325 if (ival < 1) { << 232 magField = new G4UniformMagField(G4ThreeVector(0.,0.,fieldValue)); 326 G4cout << "\n --->warning from SetNbOfDivi << 233 fieldMgr->SetDetectorField(magField); 327 << " must be at least 1. Command re << 234 fieldMgr->CreateChordFinder(magField); 328 return; << 235 } 329 } << 236 else 330 fNbOfDivisions[iabs] = ival; << 237 { 331 G4RunManager::GetRunManager()->ReinitializeG << 238 magField = 0; >> 239 fieldMgr->SetDetectorField(magField); >> 240 } 332 } 241 } 333 242 334 //....oooOO0OOooo........oooOO0OOooo........oo 243 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 335 244 336 void DetectorConstruction::ConstructSDandField << 245 #include "G4RunManager.hh" >> 246 >> 247 void DetectorConstruction::UpdateGeometry() 337 { 248 { 338 if (fFieldMessenger.Get() == 0) { << 249 G4RunManager::GetRunManager()->DefineWorldVolume(ConstructVolumes()); 339 // Create global magnetic field messenger. << 340 // Uniform magnetic field is then created << 341 // the field value is not zero. << 342 G4ThreeVector fieldValue = G4ThreeVector() << 343 G4GlobalMagFieldMessenger* msg = new G4Glo << 344 // msg->SetVerboseLevel(1); << 345 G4AutoDelete::Register(msg); << 346 fFieldMessenger.Put(msg); << 347 } << 348 } 250 } 349 251 350 //....oooOO0OOooo........oooOO0OOooo........oo 252 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 351 253