Geant4 Cross Reference |
1 // 1 2 // ******************************************* 3 // * License and Disclaimer 4 // * 5 // * The Geant4 software is copyright of th 6 // * the Geant4 Collaboration. It is provided 7 // * conditions of the Geant4 Software License 8 // * LICENSE and available at http://cern.ch/ 9 // * include a list of copyright holders. 10 // * 11 // * Neither the authors of this software syst 12 // * institutes,nor the agencies providing fin 13 // * work make any representation or warran 14 // * regarding this software system or assum 15 // * use. Please see the license in the file 16 // * for the full disclaimer and the limitatio 17 // * 18 // * This code implementation is the result 19 // * technical work of the GEANT4 collaboratio 20 // * By using, copying, modifying or distri 21 // * any work based on the software) you ag 22 // * use in resulting scientific publicati 23 // * acceptance of all terms of the Geant4 Sof 24 // ******************************************* 25 // 26 /// \file electromagnetic/TestEm9/src/Detector 27 /// \brief Implementation of the DetectorConst 28 // 29 // 30 // 31 ////////////////////////////////////////////// 32 // 33 // TestEm9: Crystal calorimeter 34 // 35 // Created: 31.01.03 V.Ivanchenko 36 // 37 // Modified: 38 // 39 ////////////////////////////////////////////// 40 // 41 42 //....oooOO0OOooo........oooOO0OOooo........oo 43 //....oooOO0OOooo........oooOO0OOooo........oo 44 45 #include "DetectorConstruction.hh" 46 47 #include "DetectorMessenger.hh" 48 49 #include "G4Box.hh" 50 #include "G4Colour.hh" 51 #include "G4GeometryManager.hh" 52 #include "G4LogicalVolume.hh" 53 #include "G4LogicalVolumeStore.hh" 54 #include "G4NistManager.hh" 55 #include "G4PVPlacement.hh" 56 #include "G4PVReplica.hh" 57 #include "G4PhysicalVolumeStore.hh" 58 #include "G4ProductionCuts.hh" 59 #include "G4Region.hh" 60 #include "G4RegionStore.hh" 61 #include "G4RunManager.hh" 62 #include "G4SolidStore.hh" 63 #include "G4SystemOfUnits.hh" 64 #include "G4TransportationManager.hh" 65 #include "G4UnitsTable.hh" 66 #include "G4VisAttributes.hh" 67 #include "G4ios.hh" 68 69 //....oooOO0OOooo........oooOO0OOooo........oo 70 71 DetectorConstruction::DetectorConstruction() 72 : G4VUserDetectorConstruction(), 73 fCalMaterial(0), 74 fVertMaterial(0), 75 fAbsMaterial(0), 76 fWorldMaterial(0), 77 fYorkMaterial(0), 78 fLogicWorld(0), 79 fLogicCal(0), 80 fLogicA1(0), 81 fLogicA2(0), 82 fLogicA3(0), 83 fLogicA4(0), 84 fVertexRegion(0), 85 fMuonRegion(0), 86 fVertexDetectorCuts(0), 87 fMuonDetectorCuts(0), 88 fDetectorMessenger(0) 89 { 90 fDetectorMessenger = new DetectorMessenger(t 91 92 fEcalLength = 36. * cm; 93 fEcalWidth = 6. * cm; 94 fVertexLength = 3. * cm; 95 fPadLength = 0.1 * mm; 96 fPadWidth = 0.02 * mm; 97 fAbsLength = 2. * mm; 98 fWorldZ = 0.0; 99 fLogicWorld = 0; 100 fLogicCal = 0; 101 fLogicA1 = 0; 102 fLogicA2 = 0; 103 fLogicA3 = 0; 104 fLogicA4 = 0; 105 fVertexRegion = 0; 106 fMuonRegion = 0; 107 108 DefineMaterials(); 109 fVertexDetectorCuts = new G4ProductionCuts() 110 fMuonDetectorCuts = new G4ProductionCuts(); 111 } 112 113 //....oooOO0OOooo........oooOO0OOooo........oo 114 115 DetectorConstruction::~DetectorConstruction() 116 { 117 delete fDetectorMessenger; 118 delete fVertexDetectorCuts; 119 delete fMuonDetectorCuts; 120 } 121 122 //....oooOO0OOooo........oooOO0OOooo........oo 123 124 G4VPhysicalVolume* DetectorConstruction::Const 125 { 126 return ConstructVolumes(); 127 } 128 129 //....oooOO0OOooo........oooOO0OOooo........oo 130 131 void DetectorConstruction::DefineMaterials() 132 { 133 // Default materials 134 135 G4NistManager* man = G4NistManager::Instance 136 // man->SetVerbose(1); 137 fWorldMaterial = man->FindOrBuildMaterial("G 138 fAbsMaterial = man->FindOrBuildMaterial("G4_ 139 fVertMaterial = man->FindOrBuildMaterial("G4 140 fYorkMaterial = man->FindOrBuildMaterial("G4 141 fCalMaterial = man->FindOrBuildMaterial("G4_ 142 } 143 144 //....oooOO0OOooo........oooOO0OOooo........oo 145 146 G4VPhysicalVolume* DetectorConstruction::Const 147 { 148 // Cleanup old geometry 149 150 G4GeometryManager::GetInstance()->OpenGeomet 151 152 if (G4NistManager::Instance()->GetVerbose() 153 G4cout << *(G4Material::GetMaterialTable() 154 155 if (fVertexRegion) { 156 delete fVertexRegion; 157 delete fMuonRegion; 158 } 159 fVertexRegion = new G4Region("VertexDetector 160 fVertexRegion->SetProductionCuts(fVertexDete 161 162 fMuonRegion = new G4Region("MuonDetector"); 163 fMuonRegion->SetProductionCuts(fMuonDetector 164 165 G4SolidStore::GetInstance()->Clean(); 166 G4LogicalVolumeStore::GetInstance()->Clean() 167 G4PhysicalVolumeStore::GetInstance()->Clean( 168 169 if (fVertexLength < fPadLength * 5.0) fVerte 170 G4double gap = 0.01 * mm; 171 G4double biggap = 2. * cm; 172 G4double york = 10. * cm; 173 174 fWorldZ = 2. * fVertexLength + 3. * fAbsLeng 175 176 G4double worldX = fEcalWidth * 3.0; 177 G4double vertexZ = -fWorldZ + fVertexLength 178 G4double absZ2 = -fWorldZ + fVertexLength * 179 G4double ecalZ = 180 -fWorldZ + fVertexLength * 4.0 + fAbsLengt 181 G4double yorkZ = 182 -fWorldZ + fVertexLength * 4.0 + fAbsLengt 183 184 // 185 // World 186 // 187 G4Box* solidW = new G4Box("World", worldX, w 188 fLogicWorld = new G4LogicalVolume(solidW, fW 189 G4VPhysicalVolume* world = 190 new G4PVPlacement(0, G4ThreeVector(), "Wor 191 192 // 193 // Ecal 194 // 195 G4Box* solidE = new G4Box("VolE", worldX, wo 196 G4LogicalVolume* logicECal = new G4LogicalVo 197 G4VPhysicalVolume* physE = 198 new G4PVPlacement(0, G4ThreeVector(0., 0., 199 200 G4Box* solidC = new G4Box("Ecal", fEcalWidth 201 fLogicCal = new G4LogicalVolume(solidC, fCal 202 203 G4cout << "Ecal is " << G4BestUnit(fEcalLeng 204 << G4endl; 205 206 // Crystals 207 208 G4double x0 = -(fEcalWidth + gap) * 2.0; 209 G4double y = x0; 210 G4double x; 211 G4int k = 0; 212 G4int i, j; 213 214 for (i = 0; i < 5; i++) { 215 x = x0; 216 for (j = 0; j < 5; j++) { 217 new G4PVPlacement(0, G4ThreeVector(x, y, 218 k++; 219 x += fEcalWidth + gap; 220 } 221 y += fEcalWidth + gap; 222 } 223 224 // Absorber 225 226 G4Box* solidA = new G4Box("Abso", worldX, wo 227 fLogicA2 = new G4LogicalVolume(solidA, fAbsM 228 new G4PVPlacement(0, G4ThreeVector(0., 0., a 229 230 G4cout << "Absorber is " << G4BestUnit(fAbsL 231 << G4endl; 232 233 // York 234 235 G4Box* solidYV = new G4Box("VolY", worldX, w 236 G4LogicalVolume* logicYV = new G4LogicalVolu 237 G4VPhysicalVolume* physYV = 238 new G4PVPlacement(0, G4ThreeVector(0., 0., 239 240 G4Box* solidY = new G4Box("York", worldX, wo 241 G4LogicalVolume* logicY = new G4LogicalVolum 242 new G4PVPlacement(0, G4ThreeVector(), "York" 243 244 fLogicA3 = new G4LogicalVolume(solidA, fAbsM 245 fLogicA4 = new G4LogicalVolume(solidA, fAbsM 246 247 new G4PVPlacement(0, G4ThreeVector(0., 0., - 248 false, 0); 249 new G4PVPlacement(0, G4ThreeVector(0., 0., ( 250 false, 0); 251 252 // Vertex volume 253 G4Box* solidVV = new G4Box("VolV", worldX, w 254 G4LogicalVolume* logicVV = new G4LogicalVolu 255 G4VPhysicalVolume* physVV = 256 new G4PVPlacement(0, G4ThreeVector(0., 0., 257 258 // Absorber 259 fLogicA1 = new G4LogicalVolume(solidA, fAbsM 260 new G4PVPlacement(0, G4ThreeVector(0., 0., f 261 fLogicA1, physVV, false, 0 262 263 // Vertex 264 G4double vertWidth = fEcalWidth / 5.; 265 G4int npads = (G4int)(vertWidth / fPadWidth) 266 // G4cout << " vertWidth= " << vertWidth << 267 // << " npads= " << npads << G4endl 268 // insure beam to hit a middle of central p 269 npads = (npads / 2) * 2 + 1; 270 x0 = -0.5 * (fPadWidth + vertWidth); 271 G4double x1 = 0.5 * vertWidth + gap; 272 G4double z = -(fVertexLength + fAbsLength); 273 274 G4Box* solidVD = new G4Box("VertDet", x1, fE 275 G4LogicalVolume* logicVD = new G4LogicalVolu 276 logicVD->SetSolid(solidVD); 277 278 G4Box* solidV = new G4Box("Vert", fPadWidth 279 G4LogicalVolume* logicV = new G4LogicalVolum 280 281 for (i = 0; i < 3; i++) { 282 new G4PVPlacement(0, G4ThreeVector(0., 0., 283 z += fVertexLength; 284 } 285 x = x0; 286 287 for (j = 0; j < npads; j++) { 288 new G4PVPlacement(0, G4ThreeVector(x, 0., 289 x += fPadWidth; 290 } 291 292 G4cout << "Vertex is " << G4BestUnit(fVertex 293 << G4BestUnit(fPadLength, "Length") < 294 295 // Define region for the vertex detector 296 fVertexRegion->AddRootLogicalVolume(logicVV) 297 fVertexRegion->AddRootLogicalVolume(fLogicA3 298 299 // Define region for the muon detector 300 fMuonRegion->AddRootLogicalVolume(logicYV); 301 302 // color regions 303 logicVV->SetVisAttributes(G4VisAttributes::G 304 logicV->SetVisAttributes(G4VisAttributes::Ge 305 logicECal->SetVisAttributes(G4VisAttributes: 306 logicYV->SetVisAttributes(G4VisAttributes::G 307 308 G4VisAttributes* regWcolor = new G4VisAttrib 309 fLogicWorld->SetVisAttributes(regWcolor); 310 311 G4VisAttributes* regVcolor = new G4VisAttrib 312 logicVD->SetVisAttributes(regVcolor); 313 314 G4VisAttributes* regCcolor = new G4VisAttrib 315 fLogicCal->SetVisAttributes(regCcolor); 316 317 G4VisAttributes* regAcolor = new G4VisAttrib 318 fLogicA1->SetVisAttributes(regAcolor); 319 fLogicA2->SetVisAttributes(regAcolor); 320 fLogicA3->SetVisAttributes(regAcolor); 321 fLogicA4->SetVisAttributes(regAcolor); 322 323 G4VisAttributes* regMcolor = new G4VisAttrib 324 logicY->SetVisAttributes(regMcolor); 325 326 // always return world 327 G4cout << "### New geometry is constructed" 328 329 return world; 330 } 331 332 //....oooOO0OOooo........oooOO0OOooo........oo 333 334 void DetectorConstruction::SetEcalMaterial(con 335 { 336 // search the material by its name 337 G4Material* pttoMaterial = G4NistManager::In 338 if (pttoMaterial && pttoMaterial != fCalMate 339 fCalMaterial = pttoMaterial; 340 if (fLogicCal) { 341 fLogicCal->SetMaterial(fCalMaterial); 342 G4RunManager::GetRunManager()->PhysicsHa 343 } 344 } 345 } 346 347 //....oooOO0OOooo........oooOO0OOooo........oo 348 349 void DetectorConstruction::SetAbsMaterial(cons 350 { 351 // search the material by its name 352 G4Material* pttoMaterial = G4NistManager::In 353 if (pttoMaterial && pttoMaterial != fAbsMate 354 fAbsMaterial = pttoMaterial; 355 if (fLogicA1) { 356 fLogicA1->SetMaterial(fAbsMaterial); 357 fLogicA2->SetMaterial(fAbsMaterial); 358 fLogicA3->SetMaterial(fAbsMaterial); 359 fLogicA4->SetMaterial(fAbsMaterial); 360 G4RunManager::GetRunManager()->PhysicsHa 361 } 362 } 363 } 364 365 //....oooOO0OOooo........oooOO0OOooo........oo 366 367 void DetectorConstruction::UpdateGeometry() 368 { 369 G4RunManager::GetRunManager()->PhysicsHasBee 370 G4RunManager::GetRunManager()->DefineWorldVo 371 } 372 373 //....oooOO0OOooo........oooOO0OOooo........oo 374 375 void DetectorConstruction::SetEcalLength(G4dou 376 { 377 if (val > 0.0) { 378 fEcalLength = val; 379 G4RunManager::GetRunManager()->GeometryHas 380 } 381 } 382 383 //....oooOO0OOooo........oooOO0OOooo........oo 384 385 void DetectorConstruction::SetEcalWidth(G4doub 386 { 387 if (val > 0.0) { 388 fEcalWidth = val; 389 G4RunManager::GetRunManager()->GeometryHas 390 } 391 } 392 393 //....oooOO0OOooo........oooOO0OOooo........oo 394 395 void DetectorConstruction::SetVertexLength(G4d 396 { 397 if (val > 0.0) { 398 fVertexLength = val; 399 G4RunManager::GetRunManager()->GeometryHas 400 } 401 } 402 403 //....oooOO0OOooo........oooOO0OOooo........oo 404 405 void DetectorConstruction::SetPadLength(G4doub 406 { 407 if (val > 0.0) { 408 fPadLength = val; 409 G4RunManager::GetRunManager()->GeometryHas 410 } 411 } 412 413 //....oooOO0OOooo........oooOO0OOooo........oo 414 415 void DetectorConstruction::SetPadWidth(G4doubl 416 { 417 if (val > 0.0) { 418 fPadWidth = val; 419 G4RunManager::GetRunManager()->GeometryHas 420 } 421 } 422 423 //....oooOO0OOooo........oooOO0OOooo........oo 424 425 void DetectorConstruction::SetAbsLength(G4doub 426 { 427 if (val > 0.0) { 428 fAbsLength = val; 429 G4RunManager::GetRunManager()->GeometryHas 430 } 431 } 432 433 //....oooOO0OOooo........oooOO0OOooo........oo 434