Geant4 Cross Reference |
1 // 2 // ******************************************************************** 3 // * License and Disclaimer * 4 // * * 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. * 10 // * * 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitation of liability. * 17 // * * 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************************************** 25 // 26 /// \file DetectorConstruction.cc 27 /// \brief Implementation of the DetectorConstruction class 28 // 29 // 30 31 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 32 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 33 34 #include "DetectorConstruction.hh" 35 36 #include "DetectorMessenger.hh" 37 #include "PrimaryGeneratorAction.hh" 38 39 #include "G4Box.hh" 40 #include "G4GeometryManager.hh" 41 #include "G4LogicalVolume.hh" 42 #include "G4LogicalVolumeStore.hh" 43 #include "G4Material.hh" 44 #include "G4NistManager.hh" 45 #include "G4PVPlacement.hh" 46 #include "G4PhysicalConstants.hh" 47 #include "G4PhysicalVolumeStore.hh" 48 #include "G4RunManager.hh" 49 #include "G4SolidStore.hh" 50 #include "G4SystemOfUnits.hh" 51 #include "G4ThreeVector.hh" 52 #include "G4Tubs.hh" 53 #include "globals.hh" 54 55 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 56 57 DetectorConstruction::DetectorConstruction() 58 : fMaterial(nullptr), 59 fExperimentalHall_log(nullptr), 60 fExperimentalHall_phys(nullptr), 61 fLogicLayer(nullptr), 62 fPhysiLayer(nullptr), 63 fLogicScoringUpDown(nullptr), 64 fPhysiScoringUpstream(nullptr), 65 fPhysiScoringDownstream(nullptr), 66 fLogicScoringSide(nullptr), 67 fPhysiScoringSide(nullptr), 68 fDetectorMessenger(nullptr), 69 fThickness(2.0 * CLHEP::m), 70 fDiameter(2.0 * CLHEP::m) //***LOOKHERE*** Default values 71 { 72 fMaterial = G4NistManager::Instance()->FindOrBuildMaterial("G4_Fe"); //***LOOKHERE*** 73 // Default material 74 fDetectorMessenger = new DetectorMessenger(this); 75 } 76 77 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 78 79 DetectorConstruction::~DetectorConstruction() 80 { 81 delete fDetectorMessenger; 82 } 83 84 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 85 86 G4VPhysicalVolume* DetectorConstruction::Construct() 87 { 88 return ConstructLayer(); 89 } 90 91 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 92 93 G4VPhysicalVolume* DetectorConstruction::ConstructLayer() 94 { 95 // Clean old geometry, if any. 96 G4GeometryManager::GetInstance()->OpenGeometry(); 97 G4PhysicalVolumeStore::GetInstance()->Clean(); 98 G4LogicalVolumeStore::GetInstance()->Clean(); 99 G4SolidStore::GetInstance()->Clean(); 100 101 // The target layer is a cylinder, with axis along the z-direction, 102 // and positioned at the center, (0.0, 0.0, 0.0). 103 // The world volume (experimental hall) is a box 20% bigger than the target layer, 104 // and it is filled of "G4_Galactic" material. 105 106 G4double expHall_x = 0.6 * fDiameter; // half dimension along x : 20% bigger than the radius 107 // of the target layer 108 G4double expHall_y = 0.6 * fDiameter; // half dimension along y : 20% bigger than the radius 109 // of the target layer 110 G4double expHall_z = 0.6 * fThickness; // half dimension along z : 20% bigger than the half 111 // thickness of the target layer 112 113 G4Material* vacuum = G4NistManager::Instance()->FindOrBuildMaterial("G4_Galactic"); 114 115 // Experimental hall 116 G4Box* experimentalHall_box = new G4Box("expHall_box", expHall_x, expHall_y, expHall_z); 117 fExperimentalHall_log = new G4LogicalVolume(experimentalHall_box, // solid 118 vacuum, // material 119 "expHall_log", // name 120 0, // field manager 121 0, // sensitive detector 122 0); // user limits 123 fExperimentalHall_phys = new G4PVPlacement(0, // rotation 124 G4ThreeVector(), // translation 125 "expHall", // name 126 fExperimentalHall_log, // logical volume 127 0, // mother physical volume 128 false, // boolean operation 129 0); // copy number 130 131 // Target 132 G4Tubs* solidLayer = new G4Tubs("solidLayer", // name 133 0.0, // inner radius 134 0.5 * fDiameter, // outer radius 135 0.5 * fThickness, // half cylinder length in z 136 0.0, // starting phi angle in rad 137 2.0 * pi); // final phi angle in rad 138 fLogicLayer = new G4LogicalVolume(solidLayer, // solid 139 fMaterial, // material 140 "logicLayer", // name 141 0, // field manager 142 0, // sensitive detector 143 0); // user limits 144 fPhysiLayer = new G4PVPlacement(0, // rotation 145 G4ThreeVector(), // translation 146 "physiLayer", // name 147 fLogicLayer, // logical volume 148 fExperimentalHall_phys, // mother physical volume 149 false, // boolean operation 150 0); // copy number 151 152 // Three scoring volumes: one thin layer downstream of the target ("down") 153 // one thin layer surrounding (lateral) of the target ("side") 154 // one thin layer upstream of the target ("up") 155 G4Tubs* solidScoringUpDown = new G4Tubs("solidScoringUpDown", // name 156 0.0, // inner radius 157 0.5 * fDiameter, // outer radius 158 0.5 * fScoringThickness, // half cylinder length in z 159 0.0, // starting phi angle in rad 160 2.0 * pi); // final phi angle in rad 161 fLogicScoringUpDown = new G4LogicalVolume(solidScoringUpDown, // solid 162 vacuum, // material 163 "logicScoringUpDown", // name 164 0, // field manager 165 0, // sensitive detector 166 0); // user limits 167 G4double zScoringUpDown = 0.5 * (fThickness + fScoringThickness); 168 fPhysiScoringUpstream = new G4PVPlacement(0, // rotation 169 G4ThreeVector(0.0, 0.0, -zScoringUpDown), 170 // translation 171 "physiScoringUpstream", // name 172 fLogicScoringUpDown, // logical volume 173 fExperimentalHall_phys, // mother physical volume 174 false, // boolean operation 175 0); // copy number 176 fPhysiScoringDownstream = new G4PVPlacement(0, // rotation 177 G4ThreeVector(0.0, 0.0, zScoringUpDown), 178 // translation 179 "physiScoringDownstream", // name 180 fLogicScoringUpDown, // logical volume 181 fExperimentalHall_phys, // mother physical volume 182 false, // boolean operation 183 0); // copy number 184 185 G4Tubs* solidScoringSide = new G4Tubs("solidScoringSide", // name 186 0.5 * fDiameter, // inner radius 187 0.5 * fDiameter + fScoringThickness, // outer radius 188 0.5 * fThickness, // half cylinder length in z 189 0.0, // starting phi angle in rad 190 2.0 * pi); // final phi angle in rad 191 fLogicScoringSide = new G4LogicalVolume(solidScoringSide, // solid 192 vacuum, // material 193 "logicScoringSide", // name 194 0, // field manager 195 0, // sensitive detector 196 0); // user limits 197 fPhysiScoringSide = new G4PVPlacement(0, // rotation 198 G4ThreeVector(0.0, 0.0, 0.0), // translation 199 "physiScoringSide", // name 200 fLogicScoringSide, // logical volume 201 fExperimentalHall_phys, // mother physical volume 202 false, // boolean operation 203 0); // copy number 204 205 G4cout << G4endl << "DetectorConstruction::ConstructLayer() : " << G4endl 206 << "\t World (box) size: " << G4endl << "\t \t x : -/+ " << expHall_x << " mm ;" 207 << "\t y : -/+ " << expHall_y << " mm ;" 208 << "\t z : -/+ " << expHall_z << " mm ;" << G4endl 209 << "\t Target layer (cylinder) size: " << G4endl << "\t \t x : -/+ " << 0.5 * fDiameter 210 << " mm ;" 211 << "\t y : -/+ " << 0.5 * fDiameter << " mm ;" 212 << "\t z : -/+ " << 0.5 * fThickness << " mm ;" << G4endl << G4endl << G4endl; 213 214 return fExperimentalHall_phys; 215 } 216 217 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 218 219 void DetectorConstruction::SetMaterial(const G4String name) 220 { 221 fMaterial = G4NistManager::Instance()->FindOrBuildMaterial(name); 222 if (!fMaterial) { 223 G4cout << G4endl << G4endl << "WARNING: the name of the material has not been recognized!" 224 << G4endl << " ===> the default * G4_Fe * will be used." << G4endl << G4endl; 225 fMaterial = G4NistManager::Instance()->FindOrBuildMaterial("G4_Fe"); 226 } 227 if (fLogicLayer) fLogicLayer->SetMaterial(fMaterial); 228 } 229 230 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 231 232 void DetectorConstruction::UpdateGeometry() 233 { 234 G4RunManager::GetRunManager()->ReinitializeGeometry(); 235 PrintParameters(); 236 // Update also the position of the gun 237 const PrimaryGeneratorAction* pPrimaryAction = dynamic_cast<const PrimaryGeneratorAction*>( 238 G4RunManager::GetRunManager()->GetUserPrimaryGeneratorAction()); 239 if (pPrimaryAction) pPrimaryAction->SetGunPosition(); 240 } 241 242 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 243 244 void DetectorConstruction::PrintParameters() 245 { 246 G4cout << G4endl << G4endl << " ------ DetectorConstruction::PrintParameters() ------ " << G4endl 247 << " Material = " << fMaterial->GetName() << G4endl 248 << " Thickness = " << fThickness << " mm" << G4endl 249 << " Diameter = " << fDiameter << " mm" << G4endl 250 << " ScoringThickness = " << fScoringThickness << " mm" << G4endl 251 << " ------------------------------------------------------ " << G4endl << G4endl; 252 } 253 254 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 255