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 hadronic/Hadr02/src/DetectorConstruc 26 /// \file hadronic/Hadr02/src/DetectorConstruction.cc 27 /// \brief Implementation of the DetectorConst 27 /// \brief Implementation of the DetectorConstruction class 28 // 28 // >> 29 // $Id: DetectorConstruction.cc 77519 2013-11-25 10:54:57Z gcosmo $ 29 // 30 // 30 ////////////////////////////////////////////// 31 ///////////////////////////////////////////////////////////////////////// 31 // 32 // 32 // DetectorConstruction 33 // DetectorConstruction 33 // 34 // 34 // Created: 31.01.2003 V.Ivanchenko 35 // Created: 31.01.2003 V.Ivanchenko 35 // 36 // 36 // Modified: 37 // Modified: 37 // 04.06.2006 Adoptation of hadr01 (V.Ivanchen 38 // 04.06.2006 Adoptation of hadr01 (V.Ivanchenko) 38 // 39 // 39 ////////////////////////////////////////////// 40 //////////////////////////////////////////////////////////////////////// 40 // << 41 // 41 42 42 #include "DetectorConstruction.hh" 43 #include "DetectorConstruction.hh" 43 << 44 #include "DetectorMessenger.hh" 44 #include "DetectorMessenger.hh" 45 #include "HistoManager.hh" << 46 #include "TargetSD.hh" << 47 45 48 #include "G4Colour.hh" << 46 #include "G4Tubs.hh" 49 #include "G4GeometryManager.hh" << 50 #include "G4LogicalVolume.hh" 47 #include "G4LogicalVolume.hh" 51 #include "G4LogicalVolumeStore.hh" << 52 #include "G4NistManager.hh" << 53 #include "G4PVPlacement.hh" 48 #include "G4PVPlacement.hh" 54 #include "G4PhysicalConstants.hh" << 49 55 #include "G4PhysicalVolumeStore.hh" << 56 #include "G4RunManager.hh" 50 #include "G4RunManager.hh" 57 #include "G4SDManager.hh" << 51 >> 52 #include "G4GeometryManager.hh" >> 53 #include "G4PhysicalVolumeStore.hh" >> 54 #include "G4LogicalVolumeStore.hh" 58 #include "G4SolidStore.hh" 55 #include "G4SolidStore.hh" 59 #include "G4SystemOfUnits.hh" << 56 60 #include "G4Tubs.hh" << 61 #include "G4UnitsTable.hh" << 62 #include "G4VisAttributes.hh" 57 #include "G4VisAttributes.hh" >> 58 #include "G4Colour.hh" >> 59 >> 60 #include "G4UnitsTable.hh" 63 #include "G4ios.hh" 61 #include "G4ios.hh" 64 62 >> 63 #include "TargetSD.hh" >> 64 #include "G4SDManager.hh" >> 65 #include "HistoManager.hh" >> 66 #include "G4NistManager.hh" >> 67 >> 68 #include "G4PhysicalConstants.hh" >> 69 #include "G4SystemOfUnits.hh" >> 70 >> 71 65 //....oooOO0OOooo........oooOO0OOooo........oo 72 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 66 73 67 DetectorConstruction::DetectorConstruction() 74 DetectorConstruction::DetectorConstruction() 68 : G4VUserDetectorConstruction(), << 69 fRadius(10. * cm), << 70 fTargetMaterial(0), << 71 fWorldMaterial(0), << 72 fTargetSD(0), << 73 fLogicTarget(0), << 74 fLogicWorld(0), << 75 fDetectorMessenger(0) << 76 << 77 { 75 { 78 fDetectorMessenger = new DetectorMessenger(t << 76 logicTarget = 0; 79 << 77 logicCheck = 0; 80 fTargetMaterial = G4NistManager::Instance()- << 78 logicWorld = 0; 81 fWorldMaterial = G4NistManager::Instance()-> << 79 detectorMessenger = new DetectorMessenger(this); 82 HistoManager::GetPointer()->SetTargetMateria << 80 >> 81 radius = 10.*cm; >> 82 >> 83 targetMaterial = G4NistManager::Instance()->FindOrBuildMaterial("G4_Al"); >> 84 worldMaterial = >> 85 G4NistManager::Instance()->FindOrBuildMaterial("G4_Galactic"); >> 86 HistoManager::GetPointer()->SetTargetMaterial(targetMaterial); 83 87 84 // Prepare sensitive detectors 88 // Prepare sensitive detectors 85 fTargetSD = new TargetSD("targetSD"); << 89 targetSD = new TargetSD("targetSD"); 86 G4SDManager::GetSDMpointer()->AddNewDetector << 90 (G4SDManager::GetSDMpointer())->AddNewDetector( targetSD ); 87 } << 91 } 88 92 89 //....oooOO0OOooo........oooOO0OOooo........oo 93 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 90 94 91 DetectorConstruction::~DetectorConstruction() 95 DetectorConstruction::~DetectorConstruction() 92 { << 96 { 93 delete fDetectorMessenger; << 97 delete detectorMessenger; 94 } 98 } 95 99 96 G4VPhysicalVolume* DetectorConstruction::Const 100 G4VPhysicalVolume* DetectorConstruction::Construct() 97 { 101 { 98 // Cleanup old geometry 102 // Cleanup old geometry 99 G4GeometryManager::GetInstance()->OpenGeomet 103 G4GeometryManager::GetInstance()->OpenGeometry(); 100 G4PhysicalVolumeStore::GetInstance()->Clean( 104 G4PhysicalVolumeStore::GetInstance()->Clean(); 101 G4LogicalVolumeStore::GetInstance()->Clean() 105 G4LogicalVolumeStore::GetInstance()->Clean(); 102 G4SolidStore::GetInstance()->Clean(); 106 G4SolidStore::GetInstance()->Clean(); 103 107 104 // Sizes 108 // Sizes 105 G4double checkR = fRadius + mm; << 109 G4double checkR = radius + mm; 106 G4double worldR = fRadius + cm; << 110 G4double worldR = radius + cm; 107 G4double targetZ = HistoManager::GetPointer( << 111 G4double targetZ = HistoManager::GetPointer()->Length()*0.5; 108 G4double checkZ = targetZ + mm; << 112 G4double checkZ = targetZ + mm; 109 G4double worldZ = targetZ + cm; << 113 G4double worldZ = targetZ + cm; 110 << 114 111 G4int nSlices = HistoManager::GetPointer()-> << 115 G4int nSlices = HistoManager::GetPointer()->NumberOfSlices(); 112 G4double sliceZ = targetZ / G4double(nSlices << 116 G4double sliceZ = targetZ/G4double(nSlices); 113 << 117 114 // 118 // 115 // World 119 // World 116 G4Tubs* solidW = new G4Tubs("World", 0., wor << 120 G4Tubs* solidW = new G4Tubs("World",0.,worldR,worldZ,0.,twopi); 117 fLogicWorld = new G4LogicalVolume(solidW, fW << 121 logicWorld = new G4LogicalVolume( solidW,worldMaterial,"World"); 118 G4VPhysicalVolume* world = << 122 G4VPhysicalVolume* world = new G4PVPlacement(0,G4ThreeVector(), 119 new G4PVPlacement(0, G4ThreeVector(), fLog << 123 logicWorld,"World",0,false,0); 120 // 124 // 121 // Check volume 125 // Check volume 122 // 126 // 123 G4Tubs* solidC = new G4Tubs("Check", 0., che << 127 G4Tubs* solidC = new G4Tubs("Check",0.,checkR,checkZ,0.,twopi); 124 G4LogicalVolume* logicCheck = new G4LogicalV << 128 logicCheck = new G4LogicalVolume( solidC,worldMaterial,"World"); 125 new G4PVPlacement(0, G4ThreeVector(), logicC << 129 // G4VPhysicalVolume* physC = >> 130 new G4PVPlacement(0,G4ThreeVector(),logicCheck,"World",logicWorld,false,0); 126 131 127 // 132 // 128 // Target volume 133 // Target volume 129 // 134 // 130 G4Tubs* solidA = new G4Tubs("Target", 0., fR << 135 G4Tubs* solidA = new G4Tubs("Target",0.,radius,sliceZ,0.,twopi); 131 fLogicTarget = new G4LogicalVolume(solidA, f << 136 logicTarget = new G4LogicalVolume( solidA,targetMaterial,"Target"); 132 fLogicTarget->SetSensitiveDetector(fTargetSD << 137 logicTarget->SetSensitiveDetector(targetSD); 133 138 134 G4double z = sliceZ - targetZ; 139 G4double z = sliceZ - targetZ; 135 140 136 for (G4int i = 0; i < nSlices; i++) { << 141 for(G4int i=0; i<nSlices; i++) { 137 // physC = << 142 // physC = 138 new G4PVPlacement(0, G4ThreeVector(0.0, 0. << 143 new G4PVPlacement(0,G4ThreeVector(0.0,0.0,z),logicTarget, 139 z += 2.0 * sliceZ; << 144 "Target",logicCheck,false,i); >> 145 z += 2.0*sliceZ; 140 } 146 } 141 G4cout << "### Target consist of " << nSlice << 147 G4cout << "### Target consist of " << nSlices 142 << " disks with R(mm)= " << fRadius / << 148 << " of " << targetMaterial->GetName() 143 << " Total Length(mm)= " << 2.0 * ta << 149 << " disks with R(mm)= " << radius/mm >> 150 << " Width(mm)= " << 2.0*sliceZ/mm >> 151 << " Total Length(mm)= " << 2.0*targetZ/mm >> 152 << " ###" << G4endl; 144 153 145 // colors 154 // colors 146 G4VisAttributes zero = G4VisAttributes::GetI << 155 G4VisAttributes zero = G4VisAttributes::Invisible; 147 fLogicWorld->SetVisAttributes(zero); << 156 logicWorld->SetVisAttributes(&zero); 148 157 149 G4VisAttributes regWcolor(G4Colour(0.3, 0.3, 158 G4VisAttributes regWcolor(G4Colour(0.3, 0.3, 0.3)); 150 logicCheck->SetVisAttributes(regWcolor); << 159 logicCheck->SetVisAttributes(®Wcolor); 151 160 152 G4VisAttributes regCcolor(G4Colour(0., 0.3, 161 G4VisAttributes regCcolor(G4Colour(0., 0.3, 0.7)); 153 fLogicTarget->SetVisAttributes(regCcolor); << 162 logicTarget->SetVisAttributes(®Ccolor); 154 163 155 G4cout << *(G4Material::GetMaterialTable()) 164 G4cout << *(G4Material::GetMaterialTable()) << G4endl; 156 165 157 return world; 166 return world; 158 } 167 } 159 168 160 //....oooOO0OOooo........oooOO0OOooo........oo 169 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 161 170 162 void DetectorConstruction::SetTargetMaterial(c 171 void DetectorConstruction::SetTargetMaterial(const G4String& mat) 163 { 172 { 164 // search the material by its name 173 // search the material by its name 165 G4Material* material = G4NistManager::Instan 174 G4Material* material = G4NistManager::Instance()->FindOrBuildMaterial(mat); 166 << 175 167 if (material && material != fTargetMaterial) << 176 if (material && material != targetMaterial) { 168 HistoManager::GetPointer()->SetTargetMater 177 HistoManager::GetPointer()->SetTargetMaterial(material); 169 fTargetMaterial = material; << 178 targetMaterial = material; 170 if (fLogicTarget) { << 179 if(logicTarget) { logicTarget->SetMaterial(targetMaterial); } 171 fLogicTarget->SetMaterial(fTargetMateria << 172 } << 173 G4RunManager::GetRunManager()->PhysicsHasB 180 G4RunManager::GetRunManager()->PhysicsHasBeenModified(); 174 } 181 } 175 } 182 } 176 183 177 //....oooOO0OOooo........oooOO0OOooo........oo 184 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 178 185 179 void DetectorConstruction::SetWorldMaterial(co 186 void DetectorConstruction::SetWorldMaterial(const G4String& mat) 180 { 187 { 181 // search the material by its name 188 // search the material by its name 182 G4Material* material = G4NistManager::Instan 189 G4Material* material = G4NistManager::Instance()->FindOrBuildMaterial(mat); 183 190 184 if (material && material != fWorldMaterial) << 191 if (material && material != worldMaterial) { 185 fWorldMaterial = material; << 192 worldMaterial = material; 186 if (fLogicWorld) { << 193 if(logicWorld) { logicWorld->SetMaterial(worldMaterial); } 187 fLogicWorld->SetMaterial(fWorldMaterial) << 188 } << 189 G4RunManager::GetRunManager()->PhysicsHasB 194 G4RunManager::GetRunManager()->PhysicsHasBeenModified(); 190 } 195 } 191 } 196 } 192 197 193 //....oooOO0OOooo........oooOO0OOooo........oo 198 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 194 199 195 void DetectorConstruction::SetTargetRadius(G4d << 200 void DetectorConstruction::SetTargetRadius(G4double val) 196 { 201 { 197 if (val > 0.0) { << 202 if(val > 0.0) { 198 fRadius = val; << 203 radius = val; 199 G4RunManager::GetRunManager()->GeometryHas 204 G4RunManager::GetRunManager()->GeometryHasBeenModified(); 200 } << 205 } 201 } 206 } 202 207 203 //....oooOO0OOooo........oooOO0OOooo........oo 208 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 204 209