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 36 37 #include "G4GeometryManager.hh" << 38 #include "G4LogicalVolume.hh" << 39 #include "G4LogicalVolumeStore.hh" << 40 #include "G4Material.hh" 37 #include "G4Material.hh" 41 #include "G4NistManager.hh" 38 #include "G4NistManager.hh" >> 39 >> 40 #include "G4Tubs.hh" >> 41 #include "G4LogicalVolume.hh" 42 #include "G4PVPlacement.hh" 42 #include "G4PVPlacement.hh" 43 #include "G4PhysicalConstants.hh" << 43 >> 44 #include "G4GeometryManager.hh" 44 #include "G4PhysicalVolumeStore.hh" 45 #include "G4PhysicalVolumeStore.hh" 45 #include "G4RunManager.hh" << 46 #include "G4LogicalVolumeStore.hh" 46 #include "G4SolidStore.hh" 47 #include "G4SolidStore.hh" >> 48 #include "G4RunManager.hh" >> 49 47 #include "G4SystemOfUnits.hh" 50 #include "G4SystemOfUnits.hh" 48 #include "G4Tubs.hh" << 51 #include "G4PhysicalConstants.hh" 49 #include "G4UnitsTable.hh" 52 #include "G4UnitsTable.hh" 50 53 51 //....oooOO0OOooo........oooOO0OOooo........oo 54 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 52 55 53 DetectorConstruction::DetectorConstruction() 56 DetectorConstruction::DetectorConstruction() 54 { << 57 :G4VUserDetectorConstruction(), 55 fTargetLength = 1 * cm; << 58 fTargetMater(0), fLogicTarget(0), 56 fTargetRadius = 0.5 * cm; << 59 fDetectorMater(0), fLogicDetector(0), 57 fDetectorLength = 5 * cm; << 60 fWorldMater(0), fPhysiWorld(0), 58 fDetectorThickness = 2 * cm; << 61 fDetectorMessenger(0) 59 << 62 { 60 fWorldLength = std::max(fTargetLength, fDete << 63 fTargetLength = 1*cm; >> 64 fTargetRadius = 0.5*cm; >> 65 fDetectorLength = 5*cm; >> 66 fDetectorThickness = 2*cm; >> 67 >> 68 fWorldLength = std::max(fTargetLength,fDetectorLength); 61 fWorldRadius = fTargetRadius + fDetectorThic 69 fWorldRadius = fTargetRadius + fDetectorThickness; 62 << 70 63 DefineMaterials(); 71 DefineMaterials(); 64 << 72 65 fDetectorMessenger = new DetectorMessenger(t 73 fDetectorMessenger = new DetectorMessenger(this); 66 } 74 } 67 75 68 //....oooOO0OOooo........oooOO0OOooo........oo 76 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 69 77 70 DetectorConstruction::~DetectorConstruction() 78 DetectorConstruction::~DetectorConstruction() 71 { << 79 { delete fDetectorMessenger;} 72 delete fDetectorMessenger; << 73 } << 74 80 75 //....oooOO0OOooo........oooOO0OOooo........oo 81 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 76 82 77 G4VPhysicalVolume* DetectorConstruction::Const 83 G4VPhysicalVolume* DetectorConstruction::Construct() 78 { 84 { 79 return ConstructVolumes(); 85 return ConstructVolumes(); 80 } 86 } 81 87 82 //....oooOO0OOooo........oooOO0OOooo........oo 88 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 83 89 84 void DetectorConstruction::DefineMaterials() 90 void DetectorConstruction::DefineMaterials() 85 { 91 { 86 // build materials 92 // build materials 87 // 93 // 88 fDetectorMater = new G4Material("Germanium", << 94 fDetectorMater = 89 << 95 new G4Material("Germanium", 32, 72.61*g/mole, 5.323*g/cm3); 90 G4Element* N = new G4Element("Nitrogen", "N" << 96 91 G4Element* O = new G4Element("Oxygen", "O", << 97 92 // << 98 G4Element* N = new G4Element("Nitrogen", "N", 7, 14.01*g/mole); 93 G4int ncomponents; << 99 G4Element* O = new G4Element("Oxygen", "O", 8, 16.00*g/mole); 94 G4double fractionmass; << 100 // 95 G4Material* Air20 = new G4Material("Air", 1. << 101 G4int ncomponents; G4double fractionmass; 96 293. * ke << 102 G4Material* Air20 = new G4Material("Air", 1.205*mg/cm3, ncomponents=2, 97 Air20->AddElement(N, fractionmass = 0.7); << 103 kStateGas, 293.*kelvin, 1.*atmosphere); 98 Air20->AddElement(O, fractionmass = 0.3); << 104 Air20->AddElement(N, fractionmass=0.7); >> 105 Air20->AddElement(O, fractionmass=0.3); 99 // 106 // 100 fWorldMater = Air20; 107 fWorldMater = Air20; 101 << 108 102 // or use G4 materials data base 109 // or use G4 materials data base 103 // 110 // 104 G4NistManager* man = G4NistManager::Instance << 111 G4NistManager* man = G4NistManager::Instance(); 105 fTargetMater = man->FindOrBuildMaterial("G4_ 112 fTargetMater = man->FindOrBuildMaterial("G4_CESIUM_IODIDE"); 106 << 113 107 /// G4cout << *(G4Material::GetMaterialTable << 114 ///G4cout << *(G4Material::GetMaterialTable()) << G4endl; 108 } 115 } 109 116 110 //....oooOO0OOooo........oooOO0OOooo........oo 117 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 111 118 112 G4VPhysicalVolume* DetectorConstruction::Const 119 G4VPhysicalVolume* DetectorConstruction::ConstructVolumes() 113 { 120 { 114 // Cleanup old geometry 121 // Cleanup old geometry 115 G4GeometryManager::GetInstance()->OpenGeomet 122 G4GeometryManager::GetInstance()->OpenGeometry(); 116 G4PhysicalVolumeStore::GetInstance()->Clean( 123 G4PhysicalVolumeStore::GetInstance()->Clean(); 117 G4LogicalVolumeStore::GetInstance()->Clean() 124 G4LogicalVolumeStore::GetInstance()->Clean(); 118 G4SolidStore::GetInstance()->Clean(); 125 G4SolidStore::GetInstance()->Clean(); 119 << 126 120 // World 127 // World 121 // 128 // 122 // (re) compute World dimensions if necessar 129 // (re) compute World dimensions if necessary 123 fWorldLength = std::max(fTargetLength, fDete << 130 fWorldLength = std::max(fTargetLength,fDetectorLength); 124 fWorldRadius = fTargetRadius + fDetectorThic 131 fWorldRadius = fTargetRadius + fDetectorThickness; 125 << 132 126 G4Tubs* sWorld = new G4Tubs("World", // nam << 133 G4Tubs* 127 0., fWorldRadius << 134 sWorld = new G4Tubs("World", //name 128 << 135 0.,fWorldRadius, 0.5*fWorldLength, 0.,twopi); //dimensions 129 G4LogicalVolume* lWorld = new G4LogicalVolum << 136 130 << 137 G4LogicalVolume* 131 << 138 lWorld = new G4LogicalVolume(sWorld, //shape 132 << 139 fWorldMater, //material 133 fPhysiWorld = new G4PVPlacement(0, // no ro << 140 "World"); //name 134 G4ThreeVecto << 141 135 lWorld, // << 142 fPhysiWorld = new G4PVPlacement(0, //no rotation 136 "World", // << 143 G4ThreeVector(), //at (0,0,0) 137 0, // mothe << 144 lWorld, //logical volume 138 false, // n << 145 "World", //name 139 0); // copy << 146 0, //mother volume 140 << 147 false, //no boolean operation >> 148 0); //copy number >> 149 141 // Target 150 // Target 142 // 151 // 143 G4Tubs* sTarget = new G4Tubs("Target", // n << 152 G4Tubs* 144 0., fTargetRadi << 153 sTarget = new G4Tubs("Target", //name 145 << 154 0., fTargetRadius, 0.5*fTargetLength, 0.,twopi); //dimensions 146 fLogicTarget = new G4LogicalVolume(sTarget, << 155 147 fTargetMa << 156 148 "Target") << 157 fLogicTarget = new G4LogicalVolume(sTarget, //shape 149 << 158 fTargetMater, //material 150 new G4PVPlacement(0, // no rotation << 159 "Target"); //name 151 G4ThreeVector(), // at (0 << 160 152 fLogicTarget, // logical << 161 new G4PVPlacement(0, //no rotation 153 "Target", // name << 162 G4ThreeVector(), //at (0,0,0) 154 lWorld, // mother volume << 163 fLogicTarget, //logical volume 155 false, // no boolean oper << 164 "Target", //name 156 0); // copy number << 165 lWorld, //mother volume >> 166 false, //no boolean operation >> 167 0); //copy number 157 168 158 // Detector 169 // Detector 159 // 170 // 160 G4Tubs* sDetector = << 171 G4Tubs* 161 new G4Tubs("Detector", fTargetRadius, fWor << 172 sDetector = new G4Tubs("Detector", >> 173 fTargetRadius, fWorldRadius, 0.5*fDetectorLength, 0.,twopi); >> 174 >> 175 >> 176 fLogicDetector = new G4LogicalVolume(sDetector, //shape >> 177 fDetectorMater, //material >> 178 "Detector"); //name >> 179 >> 180 new G4PVPlacement(0, //no rotation >> 181 G4ThreeVector(), //at (0,0,0) >> 182 fLogicDetector, //logical volume >> 183 "Detector", //name >> 184 lWorld, //mother volume >> 185 false, //no boolean operation >> 186 0); //copy number 162 187 163 fLogicDetector = new G4LogicalVolume(sDetect << 164 fDetect << 165 "Detect << 166 << 167 new G4PVPlacement(0, // no rotation << 168 G4ThreeVector(), // at (0 << 169 fLogicDetector, // logica << 170 "Detector", // name << 171 lWorld, // mother volume << 172 false, // no boolean oper << 173 0); // copy number << 174 188 175 PrintParameters(); 189 PrintParameters(); 176 << 190 177 // always return the root volume << 191 //always return the root volume 178 // 192 // 179 return fPhysiWorld; 193 return fPhysiWorld; 180 } 194 } 181 195 182 //....oooOO0OOooo........oooOO0OOooo........oo 196 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 183 197 184 void DetectorConstruction::PrintParameters() 198 void DetectorConstruction::PrintParameters() 185 { 199 { 186 G4cout << "\n Target : Length = " << G4BestU << 200 G4cout << "\n Target : Length = " << G4BestUnit(fTargetLength,"Length") 187 << " Radius = " << G4BestUnit(fTarget << 201 << " Radius = " << G4BestUnit(fTargetRadius,"Length") 188 << " Material = " << fTargetMater->Ge 202 << " Material = " << fTargetMater->GetName(); 189 G4cout << "\n Detector : Length = " << G4Bes << 203 G4cout << "\n Detector : Length = " << G4BestUnit(fDetectorLength,"Length") 190 << " Tickness = " << G4BestUnit(fDete << 204 << " Tickness = " << G4BestUnit(fDetectorThickness,"Length") 191 << " Material = " << fDetectorMater-> << 205 << " Material = " << fDetectorMater->GetName() << G4endl; 192 G4cout << "\n" << fTargetMater << "\n" << fD 206 G4cout << "\n" << fTargetMater << "\n" << fDetectorMater << G4endl; 193 } 207 } 194 208 195 //....oooOO0OOooo........oooOO0OOooo........oo 209 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 196 210 197 void DetectorConstruction::SetTargetMaterial(G 211 void DetectorConstruction::SetTargetMaterial(G4String materialChoice) 198 { 212 { 199 // search the material by its name 213 // search the material by its name 200 G4Material* pttoMaterial = G4NistManager::In << 214 G4Material* pttoMaterial = 201 << 215 G4NistManager::Instance()->FindOrBuildMaterial(materialChoice); 202 if (pttoMaterial) { << 216 >> 217 if (pttoMaterial) { 203 fTargetMater = pttoMaterial; 218 fTargetMater = pttoMaterial; 204 if (fLogicTarget) { << 219 if(fLogicTarget) { fLogicTarget->SetMaterial(fTargetMater); } 205 fLogicTarget->SetMaterial(fTargetMater); << 206 } << 207 G4RunManager::GetRunManager()->PhysicsHasB 220 G4RunManager::GetRunManager()->PhysicsHasBeenModified(); 208 } << 221 } else { 209 else { << 222 G4cout << "\n--> warning from DetectorConstruction::SetTargetMaterial : " 210 G4cout << "\n--> warning from DetectorCons << 223 << materialChoice << " not found" << G4endl; 211 << " not found" << G4endl; << 224 } 212 } << 213 } 225 } 214 226 215 //....oooOO0OOooo........oooOO0OOooo........oo 227 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 216 228 217 void DetectorConstruction::SetDetectorMaterial 229 void DetectorConstruction::SetDetectorMaterial(G4String materialChoice) 218 { 230 { 219 // search the material by its name 231 // search the material by its name 220 G4Material* pttoMaterial = G4NistManager::In << 232 G4Material* pttoMaterial = 221 << 233 G4NistManager::Instance()->FindOrBuildMaterial(materialChoice); 222 if (pttoMaterial) { << 234 >> 235 if (pttoMaterial) { 223 fDetectorMater = pttoMaterial; 236 fDetectorMater = pttoMaterial; 224 if (fLogicDetector) { << 237 if(fLogicDetector) { fLogicDetector->SetMaterial(fDetectorMater); } 225 fLogicDetector->SetMaterial(fDetectorMat << 226 } << 227 G4RunManager::GetRunManager()->PhysicsHasB 238 G4RunManager::GetRunManager()->PhysicsHasBeenModified(); 228 } << 239 } else { 229 else { << 240 G4cout << "\n--> warning from DetectorConstruction::SetDetectorMaterial : " 230 G4cout << "\n--> warning from DetectorCons << 241 << materialChoice << " not found" << G4endl; 231 << " not found" << G4endl; << 242 } 232 } << 233 } 243 } 234 244 235 //....oooOO0OOooo........oooOO0OOooo........oo 245 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 236 246 237 void DetectorConstruction::SetTargetRadius(G4d 247 void DetectorConstruction::SetTargetRadius(G4double value) 238 { 248 { 239 fTargetRadius = value; 249 fTargetRadius = value; 240 G4RunManager::GetRunManager()->ReinitializeG 250 G4RunManager::GetRunManager()->ReinitializeGeometry(); 241 } 251 } 242 252 243 //....oooOO0OOooo........oooOO0OOooo........oo 253 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 244 254 245 void DetectorConstruction::SetTargetLength(G4d 255 void DetectorConstruction::SetTargetLength(G4double value) 246 { 256 { 247 fTargetLength = value; 257 fTargetLength = value; 248 G4RunManager::GetRunManager()->ReinitializeG 258 G4RunManager::GetRunManager()->ReinitializeGeometry(); 249 } 259 } 250 260 251 //....oooOO0OOooo........oooOO0OOooo........oo 261 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 252 262 253 void DetectorConstruction::SetDetectorThicknes 263 void DetectorConstruction::SetDetectorThickness(G4double value) 254 { 264 { 255 fDetectorThickness = value; 265 fDetectorThickness = value; 256 G4RunManager::GetRunManager()->ReinitializeG 266 G4RunManager::GetRunManager()->ReinitializeGeometry(); 257 } 267 } 258 268 259 //....oooOO0OOooo........oooOO0OOooo........oo 269 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 260 270 261 void DetectorConstruction::SetDetectorLength(G 271 void DetectorConstruction::SetDetectorLength(G4double value) 262 { 272 { 263 fDetectorLength = value; 273 fDetectorLength = value; 264 G4RunManager::GetRunManager()->ReinitializeG 274 G4RunManager::GetRunManager()->ReinitializeGeometry(); 265 } 275 } 266 276 267 //....oooOO0OOooo........oooOO0OOooo........oo 277 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 268 278 269 G4double DetectorConstruction::GetTargetLength 279 G4double DetectorConstruction::GetTargetLength() 270 { 280 { 271 return fTargetLength; 281 return fTargetLength; 272 } 282 } 273 283 274 //....oooOO0OOooo........oooOO0OOooo........oo 284 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 275 285 276 G4double DetectorConstruction::GetTargetRadius 286 G4double DetectorConstruction::GetTargetRadius() 277 { 287 { 278 return fTargetRadius; 288 return fTargetRadius; 279 } 289 } 280 290 281 //....oooOO0OOooo........oooOO0OOooo........oo 291 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 282 292 283 G4Material* DetectorConstruction::GetTargetMat 293 G4Material* DetectorConstruction::GetTargetMaterial() 284 { 294 { 285 return fTargetMater; 295 return fTargetMater; 286 } 296 } 287 297 288 //....oooOO0OOooo........oooOO0OOooo........oo 298 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 289 299 290 G4LogicalVolume* DetectorConstruction::GetLogi 300 G4LogicalVolume* DetectorConstruction::GetLogicTarget() 291 { 301 { 292 return fLogicTarget; 302 return fLogicTarget; 293 } 303 } 294 304 295 //....oooOO0OOooo........oooOO0OOooo........oo 305 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 296 306 297 G4double DetectorConstruction::GetDetectorLeng 307 G4double DetectorConstruction::GetDetectorLength() 298 { 308 { 299 return fDetectorLength; 309 return fDetectorLength; 300 } 310 } 301 311 302 //....oooOO0OOooo........oooOO0OOooo........oo 312 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 303 313 304 G4double DetectorConstruction::GetDetectorThic 314 G4double DetectorConstruction::GetDetectorThickness() 305 { 315 { 306 return fDetectorThickness; 316 return fDetectorThickness; 307 } 317 } 308 318 309 //....oooOO0OOooo........oooOO0OOooo........oo 319 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 310 320 311 G4Material* DetectorConstruction::GetDetectorM 321 G4Material* DetectorConstruction::GetDetectorMaterial() 312 { 322 { 313 return fDetectorMater; 323 return fDetectorMater; 314 } 324 } 315 325 316 //....oooOO0OOooo........oooOO0OOooo........oo 326 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 317 327 318 G4LogicalVolume* DetectorConstruction::GetLogi 328 G4LogicalVolume* DetectorConstruction::GetLogicDetector() 319 { 329 { 320 return fLogicDetector; 330 return fLogicDetector; 321 } 331 } 322 332 323 //....oooOO0OOooo........oooOO0OOooo........oo 333 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 324 334