Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer << 3 // * DISCLAIMER * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th << 5 // * The following disclaimer summarizes all the specific disclaimers * 6 // * the Geant4 Collaboration. It is provided << 6 // * of contributors to this software. The specific disclaimers,which * 7 // * conditions of the Geant4 Software License << 7 // * govern, are listed with their locations in: * 8 // * LICENSE and available at http://cern.ch/ << 8 // * http://cern.ch/geant4/license * 9 // * include a list of copyright holders. << 10 // * 9 // * * 11 // * Neither the authors of this software syst 10 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 11 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 12 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 13 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file << 14 // * use. * 16 // * for the full disclaimer and the limitatio << 17 // * 15 // * * 18 // * This code implementation is the result << 16 // * This code implementation is the intellectual property of the * 19 // * technical work of the GEANT4 collaboratio << 17 // * GEANT4 collaboration. * 20 // * By using, copying, modifying or distri << 18 // * By copying, distributing or modifying the Program (or any work * 21 // * any work based on the software) you ag << 19 // * based on the Program) you indicate your acceptance of this * 22 // * use in resulting scientific publicati << 20 // * statement, and all its terms. * 23 // * acceptance of all terms of the Geant4 Sof << 24 // ******************************************* 21 // ******************************************************************** 25 // 22 // 26 /// \file electromagnetic/TestEm7/src/Detector << 23 // $Id: DetectorConstruction.cc,v 1.4 2003/11/25 15:19:05 gcosmo Exp $ 27 /// \brief Implementation of the DetectorConst << 24 // GEANT4 tag $Name: geant4-07-01 $ 28 // << 29 // 25 // 30 //....oooOO0OOooo........oooOO0OOooo........oo 26 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 31 //....oooOO0OOooo........oooOO0OOooo........oo 27 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 32 28 33 #include "DetectorConstruction.hh" 29 #include "DetectorConstruction.hh" 34 << 35 #include "DetectorMessenger.hh" 30 #include "DetectorMessenger.hh" 36 31 >> 32 #include "G4Material.hh" 37 #include "G4Box.hh" 33 #include "G4Box.hh" 38 #include "G4FieldManager.hh" << 39 #include "G4GeometryManager.hh" << 40 #include "G4LogicalVolume.hh" 34 #include "G4LogicalVolume.hh" 41 #include "G4LogicalVolumeStore.hh" << 42 #include "G4Material.hh" << 43 #include "G4NistManager.hh" << 44 #include "G4PVPlacement.hh" 35 #include "G4PVPlacement.hh" 45 #include "G4PhysicalConstants.hh" << 36 #include "G4UniformMagField.hh" >> 37 >> 38 #include "G4GeometryManager.hh" 46 #include "G4PhysicalVolumeStore.hh" 39 #include "G4PhysicalVolumeStore.hh" 47 #include "G4RunManager.hh" << 40 #include "G4LogicalVolumeStore.hh" 48 #include "G4SolidStore.hh" 41 #include "G4SolidStore.hh" 49 #include "G4SystemOfUnits.hh" << 42 50 #include "G4TransportationManager.hh" << 51 #include "G4UniformMagField.hh" << 52 #include "G4UnitsTable.hh" 43 #include "G4UnitsTable.hh" 53 44 54 //....oooOO0OOooo........oooOO0OOooo........oo 45 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 55 46 56 DetectorConstruction::DetectorConstruction() 47 DetectorConstruction::DetectorConstruction() 57 : G4VUserDetectorConstruction(), fMagField(n << 58 { 48 { 59 // default parameter values 49 // default parameter values 60 fAbsorSizeX = fAbsorSizeYZ = 20 * cm; << 50 absorSizeX = absorSizeYZ = 20*cm; 61 fWorldSizeX = fWorldSizeYZ = 1.2 * fAbsorSiz << 51 worldSizeX = worldSizeYZ = 1.2*absorSizeX; 62 << 52 63 fTallyNumber = 0; << 53 worldMaterial = absorMaterial = 0; 64 for (G4int j = 0; j < kMaxTally; j++) { << 54 magField = 0; 65 fTallySize[j] = fTallyPosition[j] = G4Thre << 55 lAbsor = 0; 66 fTallyMass[j] = 0.; << 56 67 fLTally[j] = nullptr; << 57 tallySize = G4ThreeVector(); 68 } << 58 tallyMaterial = 0; 69 << 59 tallyMass = 0.; >> 60 tallyNumber = 0; >> 61 tallyPosition = new G4ThreeVector[MaxTally]; >> 62 lTally = 0; >> 63 70 DefineMaterials(); 64 DefineMaterials(); >> 65 SetMaterial("Water"); >> 66 SetTallyMaterial("Water"); 71 67 72 // create commands for interactive definitio << 68 // create commands for interactive definition of the detector 73 fDetectorMessenger = new DetectorMessenger(t << 69 detectorMessenger = new DetectorMessenger(this); 74 } 70 } 75 71 76 //....oooOO0OOooo........oooOO0OOooo........oo 72 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 77 73 78 DetectorConstruction::~DetectorConstruction() 74 DetectorConstruction::~DetectorConstruction() >> 75 { delete [] tallyPosition; delete detectorMessenger;} >> 76 >> 77 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... >> 78 >> 79 G4VPhysicalVolume* DetectorConstruction::Construct() 79 { 80 { 80 delete fDetectorMessenger; << 81 return ConstructVolumes(); 81 } 82 } 82 83 83 //....oooOO0OOooo........oooOO0OOooo........oo 84 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 84 85 85 void DetectorConstruction::DefineMaterials() 86 void DetectorConstruction::DefineMaterials() 86 { << 87 { 87 // << 88 // 88 // define Elements << 89 // define Elements 89 // << 90 // 90 G4double z, a; << 91 G4double z, a; 91 92 92 G4Element* H = new G4Element("Hydrogen", "H" << 93 G4Element* H = new G4Element("Hydrogen", "H", z= 1, a= 1.008*g/mole); 93 G4Element* N = new G4Element("Nitrogen", "N" << 94 G4Element* N = new G4Element("Nitrogen", "N", z= 7, a= 14.01*g/mole); 94 G4Element* O = new G4Element("Oxygen", "O", << 95 G4Element* O = new G4Element("Oxygen" , "O", z= 8, a= 16.00*g/mole); 95 96 96 // << 97 // 97 // define Materials. << 98 // define Materials. 98 // << 99 // 99 G4double density, temperature, pressure; << 100 G4double density, temperature, pressure; 100 G4int ncomponents, natoms; << 101 G4int ncomponents, natoms; 101 G4double fractionmass; << 102 G4double fractionmass; 102 << 103 103 G4Material* H2O = new G4Material("Water", de << 104 G4Material* H2O = 104 H2O->AddElement(H, natoms = 2); << 105 new G4Material("Water", density= 1.000*g/cm3, ncomponents=2); 105 H2O->AddElement(O, natoms = 1); << 106 H2O->AddElement(H, natoms=2); 106 H2O->GetIonisation()->SetMeanExcitationEnerg << 107 H2O->AddElement(O, natoms=1); 107 << 108 H2O->GetIonisation()->SetMeanExcitationEnergy(75.0*eV); 108 // In this line both G4_WATER and Water_1.05 << 109 109 G4NistManager::Instance()->BuildMaterialWith << 110 G4Material* Air = 110 << 111 new G4Material("Air" , density= 1.290*mg/cm3, ncomponents=2); 111 G4Material* Air = new G4Material("Air", dens << 112 Air->AddElement(N, fractionmass=0.7); 112 Air->AddElement(N, fractionmass = 0.7); << 113 Air->AddElement(O, fractionmass=0.3); 113 Air->AddElement(O, fractionmass = 0.3); << 114 114 << 115 density = universe_mean_density; //from PhysicalConstants.h 115 density = 1.e-5 * g / cm3; << 116 pressure = 3.e-18*pascal; 116 pressure = 2.e-2 * bar; << 117 temperature = 2.73*kelvin; 117 temperature = STP_Temperature; // From Phys << 118 G4Material* vacuum = 118 G4Material* vac = new G4Material("TechVacuum << 119 new G4Material("Galactic",z= 1,a= 1.008*g/mole,density, 119 vac->AddMaterial(Air, 1.); << 120 kStateGas,temperature,pressure); 120 << 121 121 density = universe_mean_density; // from Ph << 122 G4cout << *(G4Material::GetMaterialTable()) << G4endl; 122 pressure = 3.e-18 * pascal; << 123 123 temperature = 2.73 * kelvin; << 124 //default materials 124 G4Material* vacuum = new G4Material("Galacti << 125 worldMaterial = vacuum; 125 temperat << 126 << 127 // default materials << 128 fAbsorMaterial = H2O; << 129 fWorldMaterial = vacuum; << 130 } 126 } 131 127 132 //....oooOO0OOooo........oooOO0OOooo........oo 128 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... >> 129 >> 130 G4VPhysicalVolume* DetectorConstruction::ConstructVolumes() >> 131 { >> 132 G4GeometryManager::GetInstance()->OpenGeometry(); >> 133 G4PhysicalVolumeStore::GetInstance()->Clean(); >> 134 G4LogicalVolumeStore::GetInstance()->Clean(); >> 135 G4SolidStore::GetInstance()->Clean(); 133 136 134 G4VPhysicalVolume* DetectorConstruction::Const << 135 { << 136 // World 137 // World 137 // 138 // 138 G4Box* sWorld = new G4Box("World", // name << 139 G4Box* 139 fWorldSizeX / 2, f << 140 sWorld = new G4Box("World", //name 140 << 141 worldSizeX/2,worldSizeYZ/2,worldSizeYZ/2); //dimensions 141 fLWorld = new G4LogicalVolume(sWorld, // sh << 142 142 fWorldMaterial << 143 G4LogicalVolume* 143 "World"); // << 144 lWorld = new G4LogicalVolume(sWorld, //shape 144 << 145 worldMaterial, //material 145 G4VPhysicalVolume* pWorld = new G4PVPlacemen << 146 "World"); //name 146 << 147 147 << 148 G4VPhysicalVolume* 148 << 149 pWorld = new G4PVPlacement(0, //no rotation 149 << 150 G4ThreeVector(), //at (0,0,0) 150 << 151 lWorld, //logical volume 151 << 152 "World", //name 152 // << 153 0, //mother volume >> 154 false, //no boolean operation >> 155 0); //copy number >> 156 // 153 // Absorber 157 // Absorber 154 // << 158 // 155 G4Box* sAbsor = new G4Box("Absorber", // na << 159 G4Box* 156 fAbsorSizeX / 2, f << 160 sAbsor = new G4Box("Absorber", //name 157 << 161 absorSizeX/2,absorSizeYZ/2,absorSizeYZ/2); //dimensions 158 fLAbsor = new G4LogicalVolume(sAbsor, // sh << 162 159 fAbsorMaterial << 163 lAbsor = new G4LogicalVolume(sAbsor, //shape 160 "Absorber"); << 164 absorMaterial, //material 161 << 165 "Absorber"); //name 162 new G4PVPlacement(0, // no rotation << 166 163 G4ThreeVector(0., 0., 0.), << 167 164 fLAbsor, // logical volum << 168 new G4PVPlacement(0, //no rotation 165 "Absorber", // name << 169 G4ThreeVector(), //at (0,0,0) 166 fLWorld, // mother volum << 170 lAbsor, //logical volume 167 false, // no boolean oper << 171 "Absorber", //name 168 0); // copy number << 172 lWorld, //mother volume >> 173 false, //no boolean operation >> 174 0); //copy number 169 // 175 // 170 // Tallies (optional) 176 // Tallies (optional) 171 // 177 // 172 if (fTallyNumber > 0) { << 178 if (tallyNumber > 0) { 173 for (G4int j = 0; j < fTallyNumber; ++j) { << 179 G4Box* 174 G4Box* sTally = << 180 sTally = new G4Box("Tally",tallySize.x()/2,tallySize.y()/2,tallySize.z()/2); 175 new G4Box("Tally", fTallySize[j].x() / << 181 lTally = new G4LogicalVolume(sTally,tallyMaterial,"Tally"); 176 << 182 177 fLTally[j] = new G4LogicalVolume(sTally, << 183 for (G4int j=0; j<tallyNumber; j++) 178 << 184 { 179 new G4PVPlacement(0, // no rotation << 185 new G4PVPlacement(0, //no rotation 180 fTallyPosition[j], // << 186 tallyPosition[j], //position 181 fLTally[j], // logica << 187 lTally, //logical volume 182 "Tally", // name << 188 "Tally", //name 183 fLAbsor, // mother v << 189 lAbsor, //mother volume 184 false, // no boolean << 190 false, //no boolean operation 185 j + 1); // copy numbe << 191 j); //copy number 186 << 192 } 187 fTallyMass[j] = << 193 188 fTallySize[j].x() * fTallySize[j].y() << 194 tallyMass = tallySize.x()*tallySize.y()*tallySize.z() 189 } << 195 *(tallyMaterial->GetDensity()); 190 } << 196 } 191 197 192 PrintParameters(); 198 PrintParameters(); 193 << 199 194 // << 195 // always return the World volume << 196 // 200 // >> 201 //always return the World volume >> 202 // 197 return pWorld; 203 return pWorld; 198 } 204 } 199 205 200 //....oooOO0OOooo........oooOO0OOooo........oo 206 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 201 207 202 void DetectorConstruction::PrintParameters() c << 208 void DetectorConstruction::PrintParameters() 203 { 209 { 204 G4cout << *(G4Material::GetMaterialTable()) << 205 G4cout << "\n------------------------------- 210 G4cout << "\n---------------------------------------------------------\n"; 206 G4cout << "---> The Absorber is " << G4BestU << 211 G4cout << "---> The Absorber is " << G4BestUnit(absorSizeX,"Length") 207 << fAbsorMaterial->GetName() << G4end << 212 << " of " << absorMaterial->GetName() << G4endl; 208 G4cout << "\n------------------------------- 213 G4cout << "\n---------------------------------------------------------\n"; 209 << 214 210 if (fTallyNumber > 0) { << 215 if (tallyNumber > 0) { 211 G4cout << "---> There are " << fTallyNumbe << 216 G4cout << "---> There are " << tallyNumber << " tallies : " 212 for (G4int j = 0; j < fTallyNumber; ++j) { << 217 << G4BestUnit(tallySize,"Length") 213 G4cout << "fTally " << j << ": " << fAbs << 218 << " of " << tallyMaterial->GetName() << G4endl; 214 << ", mass = " << G4BestUnit(fTa << 219 215 << " size = " << G4BestUnit(fTall << 220 for (G4int j=0; j<tallyNumber; j++) 216 << " position = " << G4BestUnit(f << 221 G4cout << "tally " << j << ": " 217 } << 222 << "position = " << G4BestUnit(tallyPosition[j],"Length") << G4endl; 218 G4cout << "\n----------------------------- 223 G4cout << "\n---------------------------------------------------------\n"; 219 } << 224 } 220 } 225 } 221 226 222 //....oooOO0OOooo........oooOO0OOooo........oo 227 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 223 228 224 void DetectorConstruction::SetSizeX(G4double v 229 void DetectorConstruction::SetSizeX(G4double value) 225 { 230 { 226 fAbsorSizeX = value; << 231 absorSizeX = value; worldSizeX = 1.2*absorSizeX; 227 fWorldSizeX = 1.2 * fAbsorSizeX; << 228 } 232 } 229 << 233 230 //....oooOO0OOooo........oooOO0OOooo........oo 234 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 231 235 232 void DetectorConstruction::SetSizeYZ(G4double 236 void DetectorConstruction::SetSizeYZ(G4double value) 233 { 237 { 234 fAbsorSizeYZ = value; << 238 absorSizeYZ = value; 235 fWorldSizeYZ = 1.2 * fAbsorSizeYZ; << 239 worldSizeYZ = 1.2*absorSizeYZ; 236 } << 240 } 237 241 238 //....oooOO0OOooo........oooOO0OOooo........oo 242 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 239 243 240 void DetectorConstruction::SetMaterial(const G << 244 void DetectorConstruction::SetMaterial(G4String materialChoice) 241 { 245 { 242 // search the material by its name << 246 // search the material by its name 243 G4Material* pttoMaterial = G4NistManager::In << 247 G4Material* pttoMaterial = G4Material::GetMaterial(materialChoice); 244 if (pttoMaterial && pttoMaterial != fAbsorMa << 248 if (pttoMaterial) absorMaterial = pttoMaterial; 245 // change target material everywhere << 246 fAbsorMaterial = pttoMaterial; << 247 for (G4int j = 0; j < fTallyNumber; ++j) { << 248 if (fLTally[j]) { << 249 fLTally[j]->SetMaterial(pttoMaterial); << 250 fTallyMass[j] = << 251 fTallySize[j].x() * fTallySize[j].y( << 252 } << 253 } << 254 if (fLAbsor) { << 255 fLAbsor->SetMaterial(fAbsorMaterial); << 256 G4RunManager::GetRunManager()->PhysicsHa << 257 } << 258 } << 259 } 249 } 260 250 261 //....oooOO0OOooo........oooOO0OOooo........oo 251 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 262 252 263 void DetectorConstruction::SetWorldMaterial(co << 253 #include "G4FieldManager.hh" 264 { << 254 #include "G4TransportationManager.hh" 265 // search the material by its name << 266 G4Material* pttoMaterial = G4NistManager::In << 267 if (pttoMaterial && pttoMaterial != fWorldMa << 268 fWorldMaterial = pttoMaterial; << 269 if (fLWorld) { << 270 fLWorld->SetMaterial(fAbsorMaterial); << 271 G4RunManager::GetRunManager()->PhysicsHa << 272 } << 273 } << 274 } << 275 << 276 //....oooOO0OOooo........oooOO0OOooo........oo << 277 255 278 void DetectorConstruction::SetMagField(G4doubl 256 void DetectorConstruction::SetMagField(G4double fieldValue) 279 { 257 { 280 // apply a global uniform magnetic field alo << 258 //apply a global uniform magnetic field along Z axis 281 G4FieldManager* fieldMgr = G4TransportationM << 259 G4FieldManager* fieldMgr 282 << 260 = G4TransportationManager::GetTransportationManager()->GetFieldManager(); 283 if (fMagField) delete fMagField; // delete << 261 284 << 262 if (magField) delete magField; //delete the existing magn field 285 if (fieldValue != 0.) // create a new one i << 263 286 { << 264 if (fieldValue!=0.) // create a new one if non nul 287 fMagField = new G4UniformMagField(G4ThreeV << 265 { 288 fieldMgr->SetDetectorField(fMagField); << 266 magField = new G4UniformMagField(G4ThreeVector(0.,0.,fieldValue)); 289 fieldMgr->CreateChordFinder(fMagField); << 267 fieldMgr->SetDetectorField(magField); 290 } << 268 fieldMgr->CreateChordFinder(magField); 291 else { << 269 } 292 fMagField = nullptr; << 270 else 293 fieldMgr->SetDetectorField(fMagField); << 271 { 294 } << 272 magField = 0; >> 273 fieldMgr->SetDetectorField(magField); >> 274 } 295 } 275 } 296 //....oooOO0OOooo........oooOO0OOooo........oo 276 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 297 277 298 void DetectorConstruction::SetTallyNumber(G4in << 278 void DetectorConstruction::SetTallySize(G4ThreeVector value) 299 { 279 { 300 if (value >= 0 && value < kMaxTally) { << 280 tallySize = value; 301 fTallyNumber = value; << 281 } 302 } << 303 else { << 304 G4cout << "### DetectorConstruction::SetTa << 305 << "number " << value << " is ignor << 306 } << 307 } << 308 282 309 //....oooOO0OOooo........oooOO0OOooo........oo 283 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 310 284 311 void DetectorConstruction::SetTallySize(G4int << 285 void DetectorConstruction::SetTallyMaterial(G4String materialChoice) 312 { 286 { 313 if (j >= 0 && j < kMaxTally) { << 287 // search the material by its name 314 fTallySize[j] = value; << 288 G4Material* pttoMaterial = G4Material::GetMaterial(materialChoice); 315 } << 289 if (pttoMaterial) tallyMaterial = pttoMaterial; 316 else { << 317 G4cout << "### DetectorConstruction::SetTa << 318 << "number " << j << " is ignored" << 319 } << 320 } 290 } 321 291 322 //....oooOO0OOooo........oooOO0OOooo........oo 292 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 323 293 324 void DetectorConstruction::SetTallyPosition(G4 << 294 void DetectorConstruction::SetTallyPosition(G4ThreeVector value) 325 { 295 { 326 if (j >= 0 && j < kMaxTally) { << 296 if (tallyNumber < MaxTally) { 327 fTallyPosition[j] = value; << 297 tallyPosition[tallyNumber] = value; >> 298 tallyNumber++; 328 } 299 } 329 else { << 300 } 330 G4cout << "### DetectorConstruction::SetTa << 331 << "number " << j << " is ignored" << 332 } << 333 } << 334 301 335 G4double DetectorConstruction::GetTallyMass(G4 << 302 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 336 { << 337 if (j >= 0 && j < kMaxTally) { << 338 return fTallyMass[j]; << 339 } << 340 else { << 341 G4cout << "### DetectorConstruction::GetTa << 342 << "number " << j << " is ignored" << 343 return 0.0; << 344 } << 345 } << 346 303 347 const G4LogicalVolume* DetectorConstruction::G << 304 #include "G4RunManager.hh" >> 305 >> 306 void DetectorConstruction::UpdateGeometry() 348 { 307 { 349 if (j >= 0 && j < kMaxTally) { << 308 G4RunManager::GetRunManager()->DefineWorldVolume(ConstructVolumes()); 350 return fLTally[j]; << 351 } << 352 else { << 353 G4cout << "### DetectorConstruction::GetLO << 354 << "number " << j << " is ignored" << 355 return nullptr; << 356 } << 357 } 309 } 358 310 359 //....oooOO0OOooo........oooOO0OOooo........oo 311 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 360 312