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 31 //....oooOO0OOooo........oooOO0OOooo........oo 31 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 32 //....oooOO0OOooo........oooOO0OOooo........oo 32 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 33 33 34 #include "DetectorConstruction.hh" 34 #include "DetectorConstruction.hh" 35 << 36 #include "DetectorMessenger.hh" 35 #include "DetectorMessenger.hh" 37 #include "PrimaryGeneratorAction.hh" 36 #include "PrimaryGeneratorAction.hh" 38 << 39 #include "G4Box.hh" << 40 #include "G4GeometryManager.hh" << 41 #include "G4LogicalVolume.hh" << 42 #include "G4LogicalVolumeStore.hh" << 43 #include "G4Material.hh" 37 #include "G4Material.hh" 44 #include "G4NistManager.hh" 38 #include "G4NistManager.hh" >> 39 #include "G4Box.hh" >> 40 #include "G4Tubs.hh" >> 41 #include "G4LogicalVolume.hh" >> 42 #include "G4ThreeVector.hh" 45 #include "G4PVPlacement.hh" 43 #include "G4PVPlacement.hh" 46 #include "G4PhysicalConstants.hh" << 44 #include "globals.hh" >> 45 #include "G4GeometryManager.hh" 47 #include "G4PhysicalVolumeStore.hh" 46 #include "G4PhysicalVolumeStore.hh" 48 #include "G4RunManager.hh" << 47 #include "G4LogicalVolumeStore.hh" 49 #include "G4SolidStore.hh" 48 #include "G4SolidStore.hh" >> 49 #include "G4RunManager.hh" 50 #include "G4SystemOfUnits.hh" 50 #include "G4SystemOfUnits.hh" 51 #include "G4ThreeVector.hh" << 51 #include "G4PhysicalConstants.hh" 52 #include "G4Tubs.hh" << 52 53 #include "globals.hh" << 54 << 55 //....oooOO0OOooo........oooOO0OOooo........oo 53 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 56 54 57 DetectorConstruction::DetectorConstruction() << 55 DetectorConstruction::DetectorConstruction() : 58 : fMaterial(nullptr), << 56 fMaterial( nullptr ), fExperimentalHall_log( nullptr ), fExperimentalHall_phys( nullptr ), 59 fExperimentalHall_log(nullptr), << 57 fLogicLayer( nullptr ), fPhysiLayer( nullptr ), 60 fExperimentalHall_phys(nullptr), << 58 fLogicScoringUpDown( nullptr ), fPhysiScoringUpstream( nullptr ), 61 fLogicLayer(nullptr), << 59 fPhysiScoringDownstream( nullptr ), 62 fPhysiLayer(nullptr), << 60 fLogicScoringSide( nullptr ), fPhysiScoringSide( nullptr ), 63 fLogicScoringUpDown(nullptr), << 61 fDetectorMessenger( nullptr ), 64 fPhysiScoringUpstream(nullptr), << 62 fThickness( 2.0*CLHEP::m ), fDiameter( 2.0*CLHEP::m ) //***LOOKHERE*** Default values 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** << 71 { 63 { 72 fMaterial = G4NistManager::Instance()->FindO << 64 fMaterial = G4NistManager::Instance()->FindOrBuildMaterial( "G4_Fe" ); //***LOOKHERE*** 73 << 65 // Default material 74 fDetectorMessenger = new DetectorMessenger(t << 66 fDetectorMessenger = new DetectorMessenger( this ); 75 } 67 } 76 68 77 //....oooOO0OOooo........oooOO0OOooo........oo 69 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 78 70 79 DetectorConstruction::~DetectorConstruction() << 71 DetectorConstruction::~DetectorConstruction() { 80 { << 81 delete fDetectorMessenger; 72 delete fDetectorMessenger; 82 } 73 } 83 74 84 //....oooOO0OOooo........oooOO0OOooo........oo 75 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 85 76 86 G4VPhysicalVolume* DetectorConstruction::Const << 77 G4VPhysicalVolume* DetectorConstruction::Construct() { 87 { << 88 return ConstructLayer(); 78 return ConstructLayer(); 89 } 79 } 90 80 91 //....oooOO0OOooo........oooOO0OOooo........oo 81 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 92 82 93 G4VPhysicalVolume* DetectorConstruction::Const << 83 G4VPhysicalVolume* DetectorConstruction::ConstructLayer() { 94 { << 95 // Clean old geometry, if any. 84 // Clean old geometry, if any. 96 G4GeometryManager::GetInstance()->OpenGeomet 85 G4GeometryManager::GetInstance()->OpenGeometry(); 97 G4PhysicalVolumeStore::GetInstance()->Clean( 86 G4PhysicalVolumeStore::GetInstance()->Clean(); 98 G4LogicalVolumeStore::GetInstance()->Clean() 87 G4LogicalVolumeStore::GetInstance()->Clean(); 99 G4SolidStore::GetInstance()->Clean(); 88 G4SolidStore::GetInstance()->Clean(); 100 89 101 // The target layer is a cylinder, with axis 90 // The target layer is a cylinder, with axis along the z-direction, 102 // and positioned at the center, (0.0, 0.0, 91 // and positioned at the center, (0.0, 0.0, 0.0). 103 // The world volume (experimental hall) is a 92 // The world volume (experimental hall) is a box 20% bigger than the target layer, 104 // and it is filled of "G4_Galactic" materia 93 // and it is filled of "G4_Galactic" material. 105 94 106 G4double expHall_x = 0.6 * fDiameter; // ha << 95 G4double expHall_x = 0.6*fDiameter; // half dimension along x : 20% bigger than the radius 107 // << 96 // of the target layer 108 G4double expHall_y = 0.6 * fDiameter; // ha << 97 G4double expHall_y = 0.6*fDiameter; // half dimension along y : 20% bigger than the radius 109 // << 98 // of the target layer 110 G4double expHall_z = 0.6 * fThickness; // h << 99 G4double expHall_z = 0.6*fThickness; // half dimension along z : 20% bigger than the half 111 // << 100 // thickness of the target layer 112 101 113 G4Material* vacuum = G4NistManager::Instance << 102 G4Material* vacuum = G4NistManager::Instance()->FindOrBuildMaterial( "G4_Galactic" ); 114 103 115 // Experimental hall 104 // Experimental hall 116 G4Box* experimentalHall_box = new G4Box("exp << 105 G4Box* experimentalHall_box = new G4Box( "expHall_box", expHall_x, expHall_y, expHall_z ); 117 fExperimentalHall_log = new G4LogicalVolume( << 106 fExperimentalHall_log = new G4LogicalVolume( experimentalHall_box, // solid 118 << 107 vacuum, // material 119 << 108 "expHall_log", // name 120 << 109 0, // field manager 121 << 110 0, // sensitive detector 122 << 111 0 ); // user limits 123 fExperimentalHall_phys = new G4PVPlacement(0 << 112 fExperimentalHall_phys = new G4PVPlacement( 0, // rotation 124 G << 113 G4ThreeVector(), // translation 125 " << 114 "expHall", // name 126 f << 115 fExperimentalHall_log, // logical volume 127 0 << 116 0, // mother physical volume 128 f << 117 false, // boolean operation 129 0 << 118 0 ); // copy number 130 119 131 // Target 120 // Target 132 G4Tubs* solidLayer = new G4Tubs("solidLayer" << 121 G4Tubs* solidLayer = new G4Tubs( "solidLayer", // name 133 0.0, // inn << 122 0.0, // inner radius 134 0.5 * fDiame << 123 0.5*fDiameter, // outer radius 135 0.5 * fThick << 124 0.5*fThickness, // half cylinder length in z 136 0.0, // sta << 125 0.0, // starting phi angle in rad 137 2.0 * pi); << 126 2.0*pi ); // final phi angle in rad 138 fLogicLayer = new G4LogicalVolume(solidLayer << 127 fLogicLayer = new G4LogicalVolume( solidLayer, // solid 139 fMaterial, << 128 fMaterial, // material 140 "logicLaye << 129 "logicLayer", // name 141 0, // fie << 130 0, // field manager 142 0, // sen << 131 0, // sensitive detector 143 0); // us << 132 0 ); // user limits 144 fPhysiLayer = new G4PVPlacement(0, // rotat << 133 fPhysiLayer = new G4PVPlacement( 0, // rotation 145 G4ThreeVecto << 134 G4ThreeVector(), // translation 146 "physiLayer" << 135 "physiLayer", // name 147 fLogicLayer, << 136 fLogicLayer, // logical volume 148 fExperimenta << 137 fExperimentalHall_phys, // mother physical volume 149 false, // b << 138 false, // boolean operation 150 0); // copy << 139 0 ); // copy number 151 140 152 // Three scoring volumes: one thin layer dow 141 // Three scoring volumes: one thin layer downstream of the target ("down") 153 // one thin layer sur 142 // one thin layer surrounding (lateral) of the target ("side") 154 // one thin layer ups 143 // one thin layer upstream of the target ("up") 155 G4Tubs* solidScoringUpDown = new G4Tubs("sol << 144 G4Tubs* solidScoringUpDown = new G4Tubs( "solidScoringUpDown", // name 156 0.0, << 145 0.0, // inner radius 157 0.5 << 146 0.5*fDiameter, // outer radius 158 0.5 << 147 0.5*fScoringThickness, // half cylinder length in z 159 0.0, << 148 0.0, // starting phi angle in rad 160 2.0 << 149 2.0*pi ); // final phi angle in rad 161 fLogicScoringUpDown = new G4LogicalVolume(so << 150 fLogicScoringUpDown = new G4LogicalVolume( solidScoringUpDown, // solid 162 va << 151 vacuum, // material 163 "l << 152 "logicScoringUpDown", // name 164 0, << 153 0, // field manager 165 0, << 154 0, // sensitive detector 166 0) << 155 0 ); // user limits 167 G4double zScoringUpDown = 0.5 * (fThickness << 156 G4double zScoringUpDown = 0.5*(fThickness + fScoringThickness); 168 fPhysiScoringUpstream = new G4PVPlacement(0, << 157 fPhysiScoringUpstream = new G4PVPlacement( 0, // rotation 169 G4 << 158 G4ThreeVector( 0.0, 0.0, -zScoringUpDown ), 170 // << 159 // translation 171 "p << 160 "physiScoringUpstream", // name 172 fL << 161 fLogicScoringUpDown, // logical volume 173 fE << 162 fExperimentalHall_phys, // mother physical volume 174 fa << 163 false, // boolean operation 175 0) << 164 0 ); // copy number 176 fPhysiScoringDownstream = new G4PVPlacement( << 165 fPhysiScoringDownstream = new G4PVPlacement( 0, // rotation 177 << 166 G4ThreeVector( 0.0, 0.0, zScoringUpDown ), 178 << 167 // translation 179 << 168 "physiScoringDownstream", // name 180 << 169 fLogicScoringUpDown, // logical volume 181 << 170 fExperimentalHall_phys, // mother physical volume 182 << 171 false, // boolean operation 183 << 172 0 ); // copy number 184 << 173 185 G4Tubs* solidScoringSide = new G4Tubs("solid << 174 G4Tubs* solidScoringSide = new G4Tubs( "solidScoringSide", // name 186 0.5 * << 175 0.5*fDiameter, // inner radius 187 0.5 * << 176 0.5*fDiameter + fScoringThickness, // outer radius 188 0.5 * << 177 0.5*fThickness, // half cylinder length in z 189 0.0, << 178 0.0, // starting phi angle in rad 190 2.0 * << 179 2.0*pi ); // final phi angle in rad 191 fLogicScoringSide = new G4LogicalVolume(soli << 180 fLogicScoringSide = new G4LogicalVolume( solidScoringSide, // solid 192 vacu << 181 vacuum, // material 193 "log << 182 "logicScoringSide", // name 194 0, << 183 0, // field manager 195 0, << 184 0, // sensitive detector 196 0); << 185 0 ); // user limits 197 fPhysiScoringSide = new G4PVPlacement(0, // << 186 fPhysiScoringSide = new G4PVPlacement( 0, // rotation 198 G4Thre << 187 G4ThreeVector( 0.0, 0.0, 0.0 ), // translation 199 "physi << 188 "physiScoringSide", // name 200 fLogic << 189 fLogicScoringSide, // logical volume 201 fExper << 190 fExperimentalHall_phys, // mother physical volume 202 false, << 191 false, // boolean operation 203 0); / << 192 0 ); // copy number 204 << 193 205 G4cout << G4endl << "DetectorConstruction::C << 194 G4cout << G4endl 206 << "\t World (box) size: " << G4endl << 195 << "DetectorConstruction::ConstructLayer() : " << G4endl 207 << "\t y : -/+ " << expHall_y << " mm << 196 << "\t World (box) size: " << G4endl 208 << "\t z : -/+ " << expHall_z << " mm << 197 << "\t \t x : -/+ " << expHall_x << " mm ;" 209 << "\t Target layer (cylinder) size: << 198 << "\t y : -/+ " << expHall_y << " mm ;" 210 << " mm ;" << 199 << "\t z : -/+ " << expHall_z << " mm ;" << G4endl 211 << "\t y : -/+ " << 0.5 * fDiameter < << 200 << "\t Target layer (cylinder) size: " << G4endl 212 << "\t z : -/+ " << 0.5 * fThickness << 201 << "\t \t x : -/+ " << 0.5*fDiameter << " mm ;" >> 202 << "\t y : -/+ " << 0.5*fDiameter << " mm ;" >> 203 << "\t z : -/+ " << 0.5*fThickness << " mm ;" << G4endl >> 204 << G4endl << G4endl; 213 205 214 return fExperimentalHall_phys; 206 return fExperimentalHall_phys; 215 } 207 } 216 208 217 //....oooOO0OOooo........oooOO0OOooo........oo 209 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 218 210 219 void DetectorConstruction::SetMaterial(const G << 211 void DetectorConstruction::SetMaterial( const G4String name ) { 220 { << 212 fMaterial = G4NistManager::Instance()->FindOrBuildMaterial( name ); 221 fMaterial = G4NistManager::Instance()->FindO << 213 if ( ! fMaterial ) { 222 if (!fMaterial) { << 214 G4cout << G4endl << G4endl 223 G4cout << G4endl << G4endl << "WARNING: th << 215 << "WARNING: the name of the material has not been recognized!" << G4endl 224 << G4endl << " ===> the default << 216 << " ===> the default * G4_Fe * will be used." 225 fMaterial = G4NistManager::Instance()->Fin << 217 << G4endl << G4endl; >> 218 fMaterial = G4NistManager::Instance()->FindOrBuildMaterial( "G4_Fe" ); 226 } 219 } 227 if (fLogicLayer) fLogicLayer->SetMaterial(fM << 220 if ( fLogicLayer ) fLogicLayer->SetMaterial( fMaterial ); 228 } 221 } 229 222 230 //....oooOO0OOooo........oooOO0OOooo........oo 223 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 231 224 232 void DetectorConstruction::UpdateGeometry() << 225 void DetectorConstruction::UpdateGeometry() { 233 { << 234 G4RunManager::GetRunManager()->ReinitializeG 226 G4RunManager::GetRunManager()->ReinitializeGeometry(); 235 PrintParameters(); 227 PrintParameters(); 236 // Update also the position of the gun 228 // Update also the position of the gun 237 const PrimaryGeneratorAction* pPrimaryAction << 229 const PrimaryGeneratorAction* pPrimaryAction = dynamic_cast< const PrimaryGeneratorAction* >( 238 G4RunManager::GetRunManager()->GetUserPrim << 230 G4RunManager::GetRunManager()->GetUserPrimaryGeneratorAction() ); 239 if (pPrimaryAction) pPrimaryAction->SetGunPo << 231 if ( pPrimaryAction ) pPrimaryAction->SetGunPosition(); 240 } 232 } 241 233 242 //....oooOO0OOooo........oooOO0OOooo........oo 234 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 243 235 244 void DetectorConstruction::PrintParameters() << 236 void DetectorConstruction::PrintParameters() { 245 { << 237 G4cout << G4endl << G4endl 246 G4cout << G4endl << G4endl << " ------ Dete << 238 << " ------ DetectorConstruction::PrintParameters() ------ " << G4endl 247 << " Material = " << fMateria 239 << " Material = " << fMaterial->GetName() << G4endl 248 << " Thickness = " << fThickne 240 << " Thickness = " << fThickness << " mm" << G4endl 249 << " Diameter = " << fDiamete << 241 << " Diameter = " << fDiameter << " mm" << G4endl 250 << " ScoringThickness = " << fScoring << 242 << " ScoringThickness = " << fScoringThickness << " mm" << G4endl 251 << " -------------------------------- << 243 << " ------------------------------------------------------ " >> 244 << G4endl << G4endl; 252 } 245 } 253 246 254 //....oooOO0OOooo........oooOO0OOooo........oo 247 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 255 248