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 electromagnetic/TestEm6/src/Detector 26 /// \file electromagnetic/TestEm6/src/DetectorConstruction.cc 27 /// \brief Implementation of the DetectorConst 27 /// \brief Implementation of the DetectorConstruction class 28 // 28 // >> 29 // $Id$ 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 "G4Material.hh" 37 #include "G4Box.hh" 38 #include "G4Box.hh" 38 #include "G4GeometryManager.hh" << 39 #include "G4LogicalVolume.hh" 39 #include "G4LogicalVolume.hh" 40 #include "G4LogicalVolumeStore.hh" << 41 #include "G4Material.hh" << 42 #include "G4NistManager.hh" << 43 #include "G4PVPlacement.hh" 40 #include "G4PVPlacement.hh" >> 41 #include "G4UniformMagField.hh" >> 42 #include "G4UserLimits.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" 47 #include "G4SystemOfUnits.hh" << 48 48 #include "G4UniformMagField.hh" << 49 #include "G4UnitsTable.hh" 49 #include "G4UnitsTable.hh" 50 #include "G4UserLimits.hh" << 50 #include "G4SystemOfUnits.hh" 51 51 52 //....oooOO0OOooo........oooOO0OOooo........oo 52 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 53 53 54 DetectorConstruction::DetectorConstruction() 54 DetectorConstruction::DetectorConstruction() 55 : G4VUserDetectorConstruction(), << 55 :fP_Box(0), fL_Box(0), fBoxSize(500*m), fMaterial(0), fMagField(0) 56 fP_Box(0), << 57 fL_Box(0), << 58 fBoxSize(500 * m), << 59 fMaterial(0), << 60 fMagField(0), << 61 fUserLimits(0), << 62 fDetectorMessenger(0) << 63 { 56 { 64 DefineMaterials(); 57 DefineMaterials(); 65 SetMaterial("Iron"); 58 SetMaterial("Iron"); 66 << 59 67 // create UserLimits 60 // create UserLimits 68 fUserLimits = new G4UserLimits(); 61 fUserLimits = new G4UserLimits(); 69 62 70 // create commands for interactive definitio << 63 // create commands for interactive definition of the detector 71 fDetectorMessenger = new DetectorMessenger(t 64 fDetectorMessenger = new DetectorMessenger(this); 72 } 65 } 73 66 74 //....oooOO0OOooo........oooOO0OOooo........oo 67 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 75 68 76 DetectorConstruction::~DetectorConstruction() 69 DetectorConstruction::~DetectorConstruction() 77 { << 70 { delete fDetectorMessenger;} 78 delete fDetectorMessenger; << 79 } << 80 71 81 //....oooOO0OOooo........oooOO0OOooo........oo 72 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 82 73 83 G4VPhysicalVolume* DetectorConstruction::Const 74 G4VPhysicalVolume* DetectorConstruction::Construct() 84 { 75 { 85 return ConstructVolumes(); 76 return ConstructVolumes(); 86 } 77 } 87 78 88 //....oooOO0OOooo........oooOO0OOooo........oo 79 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 89 80 90 void DetectorConstruction::DefineMaterials() 81 void DetectorConstruction::DefineMaterials() 91 { << 82 { 92 G4double a, z, density; << 83 G4double a, z, density; 93 84 94 new G4Material("Beryllium", z = 4., a = 9.01 << 85 new G4Material("Beryllium", z= 4., a= 9.012182*g/mole, density= 1.848*g/cm3); 95 new G4Material("Carbon", z = 6., a = 12.011 << 86 new G4Material("Carbon", z= 6., a= 12.011*g/mole, density= 2.265*g/cm3); 96 new G4Material("Iron", z = 26., a = 55.85 * << 87 new G4Material("Iron", z=26., a= 55.85*g/mole, density= 7.870*g/cm3); 97 88 98 G4cout << *(G4Material::GetMaterialTable()) << 89 G4cout << *(G4Material::GetMaterialTable()) << G4endl; 99 } 90 } 100 91 101 //....oooOO0OOooo........oooOO0OOooo........oo 92 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 102 << 93 103 G4VPhysicalVolume* DetectorConstruction::Const 94 G4VPhysicalVolume* DetectorConstruction::ConstructVolumes() 104 { 95 { 105 G4GeometryManager::GetInstance()->OpenGeomet 96 G4GeometryManager::GetInstance()->OpenGeometry(); 106 G4PhysicalVolumeStore::GetInstance()->Clean( 97 G4PhysicalVolumeStore::GetInstance()->Clean(); 107 G4LogicalVolumeStore::GetInstance()->Clean() 98 G4LogicalVolumeStore::GetInstance()->Clean(); 108 G4SolidStore::GetInstance()->Clean(); 99 G4SolidStore::GetInstance()->Clean(); 109 << 100 110 G4Box* sBox = new G4Box("Container", // its << 101 G4Box* 111 fBoxSize / 2, fBoxSi << 102 sBox = new G4Box("Container", //its name 112 << 103 fBoxSize/2,fBoxSize/2,fBoxSize/2); //its dimensions 113 fL_Box = new G4LogicalVolume(sBox, // its s << 104 114 fMaterial, // << 105 fL_Box = new G4LogicalVolume(sBox, //its shape 115 fMaterial->GetN << 106 fMaterial, //its material 116 << 107 fMaterial->GetName()); //its name 117 fL_Box->SetUserLimits(fUserLimits); << 108 118 << 109 fL_Box->SetUserLimits(fUserLimits); 119 fP_Box = new G4PVPlacement(0, // no rotatio << 110 120 G4ThreeVector(), << 111 fP_Box = new G4PVPlacement(0, //no rotation 121 fL_Box, // its l << 112 G4ThreeVector(), //at (0,0,0) 122 fMaterial->GetNam << 113 fL_Box, //its logical volume 123 0, // its mother << 114 fMaterial->GetName(), //its name 124 false, // no boo << 115 0, //its mother volume 125 0); // copy numb << 116 false, //no boolean operation 126 << 117 0); //copy number >> 118 127 PrintParameters(); 119 PrintParameters(); 128 << 120 129 // 121 // 130 // always return the root volume << 122 //always return the root volume 131 // 123 // 132 return fP_Box; 124 return fP_Box; 133 } 125 } 134 126 135 //....oooOO0OOooo........oooOO0OOooo........oo 127 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 136 128 137 void DetectorConstruction::PrintParameters() 129 void DetectorConstruction::PrintParameters() 138 { 130 { 139 G4cout << "\n The Box is " << G4BestUnit(fBo << 131 G4cout << "\n The Box is " << G4BestUnit(fBoxSize,"Length") 140 << G4endl; << 132 << " of " << fMaterial->GetName() << G4endl; 141 } 133 } 142 134 143 //....oooOO0OOooo........oooOO0OOooo........oo 135 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 144 136 145 void DetectorConstruction::SetMaterial(const G << 137 void DetectorConstruction::SetMaterial(G4String materialChoice) 146 { 138 { 147 G4cout << "###SetMaterial" << G4endl; << 139 // search the material by its name 148 << 140 G4Material* pttoMaterial = G4Material::GetMaterial(materialChoice); 149 // get the pointer to the existing material << 141 if (pttoMaterial) fMaterial = pttoMaterial; 150 G4Material* mat = G4Material::GetMaterial(na << 151 << 152 // create the material by its name << 153 if (!mat) { << 154 mat = G4NistManager::Instance()->FindOrBui << 155 } << 156 << 157 if (mat && mat != fMaterial) { << 158 G4cout << "### New target material: " << m << 159 fMaterial = mat; << 160 if (fL_Box) { << 161 fL_Box->SetMaterial(mat); << 162 G4RunManager::GetRunManager()->PhysicsHa << 163 } << 164 } << 165 } 142 } 166 143 167 //....oooOO0OOooo........oooOO0OOooo........oo 144 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 168 145 169 void DetectorConstruction::SetSize(G4double va 146 void DetectorConstruction::SetSize(G4double value) 170 { 147 { 171 fBoxSize = value; 148 fBoxSize = value; 172 } << 149 } 173 150 174 //....oooOO0OOooo........oooOO0OOooo........oo 151 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 175 152 176 #include "G4FieldManager.hh" 153 #include "G4FieldManager.hh" 177 #include "G4TransportationManager.hh" 154 #include "G4TransportationManager.hh" 178 155 179 void DetectorConstruction::SetMagField(G4doubl 156 void DetectorConstruction::SetMagField(G4double fieldValue) 180 { 157 { 181 // apply a global uniform magnetic field alo << 158 //apply a global uniform magnetic field along Z axis 182 G4FieldManager* fieldMgr = G4TransportationM << 159 G4FieldManager* fieldMgr 183 << 160 = G4TransportationManager::GetTransportationManager()->GetFieldManager(); 184 if (fMagField) delete fMagField; // delete << 161 185 << 162 if (fMagField) delete fMagField; //delete the existing magn field 186 if (fieldValue != 0.) // create a new one i << 163 187 { << 164 if (fieldValue!=0.) // create a new one if non nul 188 fMagField = new G4UniformMagField(G4ThreeV << 165 { 189 fieldMgr->SetDetectorField(fMagField); << 166 fMagField = new G4UniformMagField(G4ThreeVector(0.,0.,fieldValue)); 190 fieldMgr->CreateChordFinder(fMagField); << 167 fieldMgr->SetDetectorField(fMagField); 191 } << 168 fieldMgr->CreateChordFinder(fMagField); 192 else { << 169 } 193 fMagField = 0; << 170 else 194 fieldMgr->SetDetectorField(fMagField); << 171 { 195 } << 172 fMagField = 0; >> 173 fieldMgr->SetDetectorField(fMagField); >> 174 } 196 } 175 } 197 176 198 //....oooOO0OOooo........oooOO0OOooo........oo 177 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 199 178 200 void DetectorConstruction::SetMaxStepSize(G4do 179 void DetectorConstruction::SetMaxStepSize(G4double val) 201 { 180 { 202 // set the maximum allowed step size 181 // set the maximum allowed step size 203 // 182 // 204 if (val <= DBL_MIN) { << 183 if (val <= DBL_MIN) 205 G4cout << "\n --->warning from SetMaxStepS << 184 { G4cout << "\n --->warning from SetMaxStepSize: maxStep " 206 << " out of range. Command refused" << 185 << val << " out of range. Command refused" << G4endl; 207 return; << 186 return; 208 } << 187 } 209 fUserLimits->SetMaxAllowedStep(val); 188 fUserLimits->SetMaxAllowedStep(val); 210 } << 189 } 211 190 212 //....oooOO0OOooo........oooOO0OOooo........oo 191 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 213 192 214 #include "G4RunManager.hh" << 193 #include "G4RunManager.hh" 215 << 194 216 void DetectorConstruction::UpdateGeometry() 195 void DetectorConstruction::UpdateGeometry() 217 { 196 { 218 G4RunManager::GetRunManager()->DefineWorldVo 197 G4RunManager::GetRunManager()->DefineWorldVolume(ConstructVolumes()); 219 } 198 } 220 199 221 //....oooOO0OOooo........oooOO0OOooo........oo 200 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 222 201