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/TestEm16/src/Detecto 27 /// \brief Implementation of the DetectorConst 28 // 29 // 30 //....oooOO0OOooo........oooOO0OOooo........oo 31 //....oooOO0OOooo........oooOO0OOooo........oo 32 33 #include "DetectorConstruction.hh" 34 35 #include "DetectorMessenger.hh" 36 37 #include "G4Box.hh" 38 #include "G4GDMLParser.hh" 39 #include "G4GeometryManager.hh" 40 #include "G4LogicalVolume.hh" 41 #include "G4LogicalVolumeStore.hh" 42 #include "G4Material.hh" 43 #include "G4PVPlacement.hh" 44 #include "G4PhysicalVolumeStore.hh" 45 #include "G4PropagatorInField.hh" 46 #include "G4RunManager.hh" 47 #include "G4SolidStore.hh" 48 #include "G4SystemOfUnits.hh" 49 #include "G4TransportationManager.hh" 50 #include "G4UnitsTable.hh" 51 #include "G4UserLimits.hh" 52 53 //....oooOO0OOooo........oooOO0OOooo........oo 54 55 DetectorConstruction::DetectorConstruction() : 56 { 57 DefineMaterials(); 58 SetMaterial("Iron"); 59 60 // create UserLimits 61 fUserLimits = new G4UserLimits(); 62 63 // create commands for interactive definitio 64 fDetectorMessenger = new DetectorMessenger(t 65 } 66 67 //....oooOO0OOooo........oooOO0OOooo........oo 68 69 G4VPhysicalVolume* DetectorConstruction::Const 70 { 71 return ConstructVolumes(); 72 } 73 74 //....oooOO0OOooo........oooOO0OOooo........oo 75 76 void DetectorConstruction::DefineMaterials() 77 { 78 G4double a, z, density; 79 80 new G4Material("Beryllium", z = 4., a = 9.01 81 new G4Material("Carbon", z = 6., a = 12.011 82 new G4Material("Iron", z = 26., a = 55.85 * 83 84 // define a vacuum with a restgas pressure 85 G4double const Torr = atmosphere / 760.; // 86 G4double pressure = 10e-9 * Torr, 87 temperature = 296.150 * kelvin; // 88 new G4Material("Vacuum", z = 7., a = 14.01 * 89 kStateGas, temperature, press 90 G4cout << *(G4Material::GetMaterialTable()) 91 } 92 93 //....oooOO0OOooo........oooOO0OOooo........oo 94 95 G4VPhysicalVolume* DetectorConstruction::Const 96 { 97 G4GeometryManager::GetInstance()->OpenGeomet 98 G4PhysicalVolumeStore::GetInstance()->Clean( 99 G4LogicalVolumeStore::GetInstance()->Clean() 100 G4SolidStore::GetInstance()->Clean(); 101 102 if (fGeomFileName == G4String()) { 103 auto sBox = new G4Box("Container", fBoxSiz 104 fLBox = new G4LogicalVolume(sBox, fMateria 105 fLBox->SetUserLimits(fUserLimits); 106 fBox = new G4PVPlacement(0, G4ThreeVector( 107 PrintParameters(); 108 } 109 else { 110 G4GDMLParser parser; 111 std::size_t nmat = G4Material::GetNumberOf 112 parser.Read(fGeomFileName.c_str()); // vo 113 if (G4Material::GetNumberOfMaterials() > n 114 const std::vector<G4Material*> MatPtrVec 115 if (G4Material::GetNumberOfMaterials() > 116 G4cout << "Materials defined by " << f 117 for (std::size_t imat = nmat; imat < Mat 118 G4cout << MatPtrVec[imat] << G4endl; 119 } 120 fBox = parser.GetWorldVolume(); 121 } 122 return fBox; 123 } 124 125 //....oooOO0OOooo........oooOO0OOooo........oo 126 127 void DetectorConstruction::PrintParameters() 128 { 129 G4cout << "\n The Box is " << G4BestUnit(fBo 130 << G4endl; 131 } 132 133 //....oooOO0OOooo........oooOO0OOooo........oo 134 135 void DetectorConstruction::SetMaterial(G4Strin 136 { 137 // search the material by its name 138 G4Material* pttoMaterial = G4Material::GetMa 139 if (pttoMaterial) { 140 fMaterial = pttoMaterial; 141 if (fLBox) fLBox->SetMaterial(fMaterial); 142 } 143 G4RunManager::GetRunManager()->PhysicsHasBee 144 } 145 146 //....oooOO0OOooo........oooOO0OOooo........oo 147 148 void DetectorConstruction::SetSize(G4double va 149 { 150 fBoxSize = value; 151 G4RunManager::GetRunManager()->ReinitializeG 152 } 153 154 //....oooOO0OOooo........oooOO0OOooo........oo 155 156 #include "G4AutoDelete.hh" 157 #include "G4GlobalMagFieldMessenger.hh" 158 159 void DetectorConstruction::ConstructSDandField 160 { 161 if (fFieldMessenger.Get() == 0) { 162 // Create global magnetic field messenger. 163 // Uniform magnetic field is then created 164 // the field value is not zero. 165 G4ThreeVector fieldValue = G4ThreeVector() 166 auto msg = new G4GlobalMagFieldMessenger(f 167 // msg->SetVerboseLevel(1); 168 G4AutoDelete::Register(msg); 169 fFieldMessenger.Put(msg); 170 } 171 } 172 173 //....oooOO0OOooo........oooOO0OOooo........oo 174 175 void DetectorConstruction::SetMaxStepSize(G4do 176 { 177 // set the maximum allowed step size 178 // 179 if (val <= DBL_MIN) { 180 G4cout << "\n --->warning from SetMaxStepS 181 << " out of range. Command refused" 182 return; 183 } 184 fUserLimits->SetMaxAllowedStep(val); 185 } 186 187 //....oooOO0OOooo........oooOO0OOooo........oo 188 189 void DetectorConstruction::SetMaxStepLength(G4 190 { 191 // set the maximum length of tracking step 192 // 193 if (val <= DBL_MIN) { 194 G4cout << "\n --->warning from SetMaxStepL 195 << " out of range. Command refused" 196 return; 197 } 198 G4TransportationManager* tmanager = G4Transp 199 tmanager->GetPropagatorInField()->SetLargest 200 } 201 202 void DetectorConstruction::SetGeomFileName(G4S 203 { 204 fGeomFileName = GeomFileName; 205 } 206 207 //....oooOO0OOooo........oooOO0OOooo........oo 208