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/TestEm3/src/Detector << 26 // $Id: DetectorConstruction.cc,v 1.20 2007/03/19 20:10:38 vnivanch Exp $ 27 /// \brief Implementation of the DetectorConst << 27 // GEANT4 tag $Name: geant4-09-00 $ 28 // << 29 // 28 // 30 //....oooOO0OOooo........oooOO0OOooo........oo 29 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 31 //....oooOO0OOooo........oooOO0OOooo........oo 30 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 32 31 33 #include "DetectorConstruction.hh" 32 #include "DetectorConstruction.hh" 34 << 35 #include "DetectorMessenger.hh" 33 #include "DetectorMessenger.hh" 36 34 >> 35 #include "G4NistManager.hh" >> 36 #include "G4Material.hh" 37 #include "G4Box.hh" 37 #include "G4Box.hh" 38 #include "G4GeometryManager.hh" << 39 #include "G4LogicalVolume.hh" 38 #include "G4LogicalVolume.hh" 40 #include "G4LogicalVolumeStore.hh" << 41 #include "G4Material.hh" << 42 #include "G4NistManager.hh" << 43 #include "G4PVPlacement.hh" 39 #include "G4PVPlacement.hh" 44 #include "G4PVReplica.hh" 40 #include "G4PVReplica.hh" 45 #include "G4PhysicalConstants.hh" << 41 #include "G4UniformMagField.hh" >> 42 >> 43 #include "G4GeometryManager.hh" 46 #include "G4PhysicalVolumeStore.hh" 44 #include "G4PhysicalVolumeStore.hh" 47 #include "G4RunManager.hh" << 45 #include "G4LogicalVolumeStore.hh" 48 #include "G4SolidStore.hh" 46 #include "G4SolidStore.hh" 49 #include "G4SystemOfUnits.hh" << 50 #include "G4UnitsTable.hh" << 51 47 >> 48 #include "G4UImanager.hh" >> 49 #include "G4UnitsTable.hh" 52 #include <iomanip> 50 #include <iomanip> 53 51 54 //....oooOO0OOooo........oooOO0OOooo........oo 52 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 55 53 56 DetectorConstruction::DetectorConstruction() 54 DetectorConstruction::DetectorConstruction() >> 55 :defaultMaterial(0),solidWorld(0),logicWorld(0),physiWorld(0), >> 56 solidCalor(0),logicCalor(0),physiCalor(0), >> 57 solidLayer(0),logicLayer(0),physiLayer(0), >> 58 magField(0) 57 { 59 { 58 for (G4int i = 0; i < kMaxAbsor; ++i) { << 59 fAbsorMaterial[i] = nullptr; << 60 fAbsorThickness[i] = 0.0; << 61 fSolidAbsor[i] = nullptr; << 62 fLogicAbsor[i] = nullptr; << 63 fPhysiAbsor[i] = nullptr; << 64 } << 65 << 66 // default parameter values of the calorimet 60 // default parameter values of the calorimeter 67 fNbOfAbsor = 2; << 61 NbOfAbsor = 2; 68 fAbsorThickness[1] = 2.3 * mm; << 62 AbsorThickness[1] = 2.3*mm; 69 fAbsorThickness[2] = 5.7 * mm; << 63 AbsorThickness[2] = 5.7*mm; 70 fNbOfLayers = 50; << 64 NbOfLayers = 50; 71 fCalorSizeYZ = 40. * cm; << 65 CalorSizeYZ = 40.*cm; 72 ComputeCalorParameters(); 66 ComputeCalorParameters(); 73 67 74 // materials 68 // materials 75 DefineMaterials(); 69 DefineMaterials(); 76 SetWorldMaterial("Galactic"); 70 SetWorldMaterial("Galactic"); 77 SetAbsorMaterial(1, "G4_Pb"); << 71 SetAbsorMaterial(1,"Lead"); 78 SetAbsorMaterial(2, "G4_lAr"); << 72 SetAbsorMaterial(2,"liquidArgon"); 79 73 80 // create commands for interactive definitio 74 // create commands for interactive definition of the calorimeter 81 fDetectorMessenger = new DetectorMessenger(t << 75 detectorMessenger = new DetectorMessenger(this); 82 } 76 } 83 77 84 //....oooOO0OOooo........oooOO0OOooo........oo 78 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 85 79 86 DetectorConstruction::~DetectorConstruction() 80 DetectorConstruction::~DetectorConstruction() 87 { 81 { 88 delete fDetectorMessenger; << 82 delete detectorMessenger; >> 83 } >> 84 >> 85 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... >> 86 >> 87 G4VPhysicalVolume* DetectorConstruction::Construct() >> 88 { >> 89 return ConstructCalorimeter(); 89 } 90 } 90 91 91 //....oooOO0OOooo........oooOO0OOooo........oo 92 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 92 93 93 void DetectorConstruction::DefineMaterials() 94 void DetectorConstruction::DefineMaterials() 94 { 95 { 95 // This function illustrates the possible wa << 96 // This function illustrates the possible ways to define materials using 96 // G4 database on G4Elements 97 // G4 database on G4Elements 97 G4NistManager* manager = G4NistManager::Inst 98 G4NistManager* manager = G4NistManager::Instance(); 98 manager->SetVerbose(0); 99 manager->SetVerbose(0); 99 // 100 // 100 // define Elements 101 // define Elements 101 // 102 // 102 G4double z, a; << 103 G4double z,a; 103 104 104 G4Element* H = manager->FindOrBuildElement(1 << 105 G4Element* H = manager->FindOrBuildElement(1); 105 G4Element* C = manager->FindOrBuildElement(6 << 106 G4Element* C = manager->FindOrBuildElement(6); 106 G4Element* N = manager->FindOrBuildElement(7 << 107 G4Element* O = manager->FindOrBuildElement(8); 107 G4Element* O = manager->FindOrBuildElement(8 << 108 G4Element* Si = manager->FindOrBuildElement( 108 G4Element* Si = manager->FindOrBuildElement(14); 109 G4Element* Ge = manager->FindOrBuildElement( 109 G4Element* Ge = manager->FindOrBuildElement(32); 110 G4Element* Sb = manager->FindOrBuildElement( 110 G4Element* Sb = manager->FindOrBuildElement(51); 111 G4Element* I = manager->FindOrBuildElement(5 << 111 G4Element* I = manager->FindOrBuildElement(53); 112 G4Element* Cs = manager->FindOrBuildElement( 112 G4Element* Cs = manager->FindOrBuildElement(55); 113 G4Element* Pb = manager->FindOrBuildElement( 113 G4Element* Pb = manager->FindOrBuildElement(82); 114 G4Element* Bi = manager->FindOrBuildElement( 114 G4Element* Bi = manager->FindOrBuildElement(83); 115 115 116 // 116 // 117 // define an Element from isotopes, by relat 117 // define an Element from isotopes, by relative abundance 118 // 118 // 119 G4int iz, n; // iz=number of protons in an << 119 G4int iz, n; //iz=number of protons in an isotope; 120 // n=number of nucleons in an << 120 // n=number of nucleons in an isotope; 121 G4int ncomponents; << 121 G4int ncomponents; 122 G4double abundance; << 122 G4double abundance; 123 << 123 124 G4Isotope* U5 = new G4Isotope("U235", iz = 9 << 124 G4Isotope* U5 = new G4Isotope("U235", iz=92, n=235, a=235.01*g/mole); 125 G4Isotope* U8 = new G4Isotope("U238", iz = 9 << 125 G4Isotope* U8 = new G4Isotope("U238", iz=92, n=238, a=238.03*g/mole); 126 << 126 127 G4Element* U = new G4Element("enriched Urani << 127 G4Element* U = new G4Element("enriched Uranium", "U", ncomponents=2); 128 U->AddIsotope(U5, abundance = 90. * perCent) << 128 U->AddIsotope(U5, abundance= 90.*perCent); 129 U->AddIsotope(U8, abundance = 10. * perCent) << 129 U->AddIsotope(U8, abundance= 10.*perCent); 130 130 131 // 131 // 132 // define simple materials 132 // define simple materials 133 // 133 // 134 G4double density; 134 G4double density; 135 135 136 new G4Material("liquidH2", z = 1., a = 1.008 << 136 new G4Material("liquidH2", z=1., a= 1.008*g/mole, density= 70.8*mg/cm3); 137 new G4Material("Aluminium", z = 13., a = 26. << 137 new G4Material("Aluminium", z=13., a= 26.98*g/mole, density= 2.700*g/cm3); 138 new G4Material("Titanium", z = 22., a = 47.8 << 138 new G4Material("Titanium", z=22., a= 47.867*g/mole, density= 4.54*g/cm3); 139 new G4Material("Iron", z = 26., a = 55.85 * << 139 new G4Material("Iron", z=26., a= 55.85*g/mole, density= 7.870*g/cm3); 140 new G4Material("Copper", z = 29., a = 63.55 << 140 new G4Material("Copper", z=29., a= 63.55*g/mole, density= 8.960*g/cm3); 141 new G4Material("Tungsten", z = 74., a = 183. << 141 new G4Material("Tungsten", z=74., a= 183.85*g/mole, density= 19.30*g/cm3); 142 new G4Material("Gold", z = 79., a = 196.97 * << 142 new G4Material("Gold", z=79., a= 196.97*g/mole, density= 19.32*g/cm3); 143 new G4Material("Uranium", z = 92., a = 238.0 << 143 new G4Material("Uranium", z=92., a= 238.03*g/mole, density= 18.95*g/cm3); 144 144 145 // 145 // 146 // define a material from elements. case 1 146 // define a material from elements. case 1: chemical molecule 147 // 147 // 148 G4int natoms; 148 G4int natoms; 149 149 150 G4Material* H2O = new G4Material("Water", de << 150 G4Material* H2O = 151 H2O->AddElement(H, natoms = 2); << 151 new G4Material("Water", density= 1.000*g/cm3, ncomponents=2); 152 H2O->AddElement(O, natoms = 1); << 152 H2O->AddElement(H, natoms=2); 153 H2O->GetIonisation()->SetMeanExcitationEnerg << 153 H2O->AddElement(O, natoms=1); >> 154 H2O->GetIonisation()->SetMeanExcitationEnergy(75.0*eV); 154 H2O->SetChemicalFormula("H_2O"); 155 H2O->SetChemicalFormula("H_2O"); 155 << 156 156 G4Material* CH = new G4Material("Polystyrene << 157 G4Material* CH = 157 CH->AddElement(C, natoms = 1); << 158 new G4Material("Polystyrene", density= 1.032*g/cm3, ncomponents=2); 158 CH->AddElement(H, natoms = 1); << 159 CH->AddElement(C, natoms=1); 159 << 160 CH->AddElement(H, natoms=1); 160 G4Material* Sci = new G4Material("Scintillat << 161 161 Sci->AddElement(C, natoms = 9); << 162 G4Material* Sci = 162 Sci->AddElement(H, natoms = 10); << 163 new G4Material("Scintillator", density= 1.032*g/cm3, ncomponents=2); 163 << 164 Sci->AddElement(C, natoms=9); 164 Sci->GetIonisation()->SetBirksConstant(0.126 << 165 Sci->AddElement(H, natoms=10); 165 << 166 166 G4Material* Lct = new G4Material("Lucite", d << 167 G4Material* Lct = 167 Lct->AddElement(C, 59.97 * perCent); << 168 new G4Material("Lucite", density= 1.185*g/cm3, ncomponents=3); 168 Lct->AddElement(H, 8.07 * perCent); << 169 Lct->AddElement(C, 59.97*perCent); 169 Lct->AddElement(O, 31.96 * perCent); << 170 Lct->AddElement(H, 8.07*perCent); 170 << 171 Lct->AddElement(O, 31.96*perCent); 171 G4Material* Sili = new G4Material("Silicon", << 172 172 Sili->AddElement(Si, natoms = 1); << 173 G4Material* Sili = 173 << 174 new G4Material("Silicon", density= 2.330*g/cm3, ncomponents=1); 174 G4Material* SiO2 = new G4Material("quartz", << 175 Sili->AddElement(Si, natoms=1); 175 SiO2->AddElement(Si, natoms = 1); << 176 176 SiO2->AddElement(O, natoms = 2); << 177 G4Material* SiO2 = 177 << 178 new G4Material("quartz", density= 2.200*g/cm3, ncomponents=2); 178 G4Material* G10 = new G4Material("NemaG10", << 179 SiO2->AddElement(Si, natoms=1); 179 G10->AddElement(Si, natoms = 1); << 180 SiO2->AddElement(O , natoms=2); 180 G10->AddElement(O, natoms = 2); << 181 181 G10->AddElement(C, natoms = 3); << 182 G4Material* G10 = 182 G10->AddElement(H, natoms = 3); << 183 new G4Material("NemaG10", density= 1.700*g/cm3, ncomponents=4); 183 << 184 G10->AddElement(Si, natoms=1); 184 G4Material* CsI = new G4Material("CsI", dens << 185 G10->AddElement(O , natoms=2); 185 CsI->AddElement(Cs, natoms = 1); << 186 G10->AddElement(C , natoms=3); 186 CsI->AddElement(I, natoms = 1); << 187 G10->AddElement(H , natoms=3); 187 CsI->GetIonisation()->SetMeanExcitationEnerg << 188 188 << 189 G4Material* CsI = 189 G4Material* BGO = new G4Material("BGO", dens << 190 new G4Material("CsI", density= 4.534*g/cm3, ncomponents=2); 190 BGO->AddElement(O, natoms = 12); << 191 CsI->AddElement(Cs, natoms=1); 191 BGO->AddElement(Ge, natoms = 3); << 192 CsI->AddElement(I , natoms=1); 192 BGO->AddElement(Bi, natoms = 4); << 193 CsI->GetIonisation()->SetMeanExcitationEnergy(553.1*eV); 193 << 194 194 // SiNx << 195 G4Material* BGO = 195 density = 3.1 * g / cm3; << 196 new G4Material("BGO", density= 7.10*g/cm3, ncomponents=3); 196 G4Material* SiNx = new G4Material("SiNx", de << 197 BGO->AddElement(O , natoms=12); 197 SiNx->AddElement(Si, 300); << 198 BGO->AddElement(Ge, natoms= 3); 198 SiNx->AddElement(N, 310); << 199 BGO->AddElement(Bi, natoms= 4); 199 SiNx->AddElement(H, 6); << 200 200 201 // 201 // 202 // define gaseous materials using G4 NIST da << 202 // define gaseous materials using G4 NIST database 203 // 203 // 204 G4double fractionmass; 204 G4double fractionmass; 205 << 205 206 G4Material* Air = manager->FindOrBuildMateri 206 G4Material* Air = manager->FindOrBuildMaterial("G4_AIR"); 207 manager->ConstructNewGasMaterial("Air20", "G << 207 manager->ConstructNewGasMaterial("Air20","G4_AIR",293.*kelvin, 1.*atmosphere); 208 208 209 G4Material* lAr = manager->FindOrBuildMateri 209 G4Material* lAr = manager->FindOrBuildMaterial("G4_lAr"); 210 G4Material* lArEm3 = new G4Material("liquidA << 210 G4Material* lArEm3 = new G4Material("liquidArgon", density= 1.390*g/cm3, ncomponents=1); 211 lArEm3->AddMaterial(lAr, fractionmass = 1.0) << 211 lArEm3->AddMaterial(lAr, fractionmass=1.0); 212 212 213 // 213 // 214 // define a material from elements and other 214 // define a material from elements and others materials (mixture of mixtures) 215 // 215 // 216 216 217 G4Material* Lead = new G4Material("Lead", de << 217 G4Material* Lead = new G4Material("Lead", density= 11.35*g/cm3, ncomponents=1); 218 Lead->AddElement(Pb, fractionmass = 1.0); << 218 Lead->AddElement(Pb, fractionmass=1.0); 219 219 220 G4Material* LeadSb = new G4Material("LeadSb" << 220 G4Material* LeadSb = new G4Material("LeadSb", density= 11.35*g/cm3, ncomponents=2); 221 LeadSb->AddElement(Sb, fractionmass = 4. * p << 221 LeadSb->AddElement(Sb, fractionmass=4.*perCent); 222 LeadSb->AddElement(Pb, fractionmass = 96. * << 222 LeadSb->AddElement(Pb, fractionmass=96.*perCent); 223 << 223 224 G4Material* Aerog = new G4Material("Aerogel" << 224 G4Material* Aerog = new G4Material("Aerogel", density= 0.200*g/cm3, ncomponents=3); 225 Aerog->AddMaterial(SiO2, fractionmass = 62.5 << 225 Aerog->AddMaterial(SiO2, fractionmass=62.5*perCent); 226 Aerog->AddMaterial(H2O, fractionmass = 37.4 << 226 Aerog->AddMaterial(H2O , fractionmass=37.4*perCent); 227 Aerog->AddElement(C, fractionmass = 0.1 * pe << 227 Aerog->AddElement (C , fractionmass= 0.1*perCent); 228 228 229 // 229 // 230 // examples of gas in non STP conditions 230 // examples of gas in non STP conditions 231 // 231 // 232 G4double temperature, pressure; 232 G4double temperature, pressure; >> 233 >> 234 G4Material* CO2 = >> 235 new G4Material("CarbonicGas", density= 27.*mg/cm3, ncomponents=2, >> 236 kStateGas, temperature= 325.*kelvin, pressure= 50.*atmosphere); >> 237 CO2->AddElement(C, natoms=1); >> 238 CO2->AddElement(O, natoms=2); >> 239 >> 240 G4Material* steam = >> 241 new G4Material("WaterSteam", density= 1.0*mg/cm3, ncomponents=1, >> 242 kStateGas, temperature= 273*kelvin, pressure= 1*atmosphere); >> 243 steam->AddMaterial(H2O, fractionmass=1.); 233 244 234 G4Material* CO2 = << 235 new G4Material("CarbonicGas", density = 27 << 236 temperature = 325. * kelvin << 237 CO2->AddElement(C, natoms = 1); << 238 CO2->AddElement(O, natoms = 2); << 239 << 240 G4Material* steam = << 241 new G4Material("WaterSteam", density = 1.0 << 242 temperature = 273 * kelvin, << 243 steam->AddMaterial(H2O, fractionmass = 1.); << 244 << 245 new G4Material("ArgonGas", z = 18, a = 39.94 << 246 273.15 * kelvin, 1 * atmosphe << 247 // 245 // 248 // examples of vacuum 246 // examples of vacuum 249 // 247 // 250 248 251 density = universe_mean_density; // from Ph << 249 density = universe_mean_density; //from PhysicalConstants.h 252 pressure = 3.e-18 * pascal; << 250 pressure = 3.e-18*pascal; 253 temperature = 2.73 * kelvin; << 251 temperature = 2.73*kelvin; 254 new G4Material("Galactic", z = 1., a = 1.008 << 252 new G4Material("Galactic", z=1., a=1.008*g/mole, density, 255 pressure); << 253 kStateGas,temperature,pressure); 256 << 254 257 density = 1.e-5 * g / cm3; << 255 density = 1.e-5*g/cm3; 258 pressure = 2.e-2 * bar; << 256 pressure = 2.e-2*bar; 259 temperature = STP_Temperature; // from Phys << 257 temperature = STP_Temperature; //from PhysicalConstants.h 260 G4Material* beam = << 258 G4Material* beam = 261 new G4Material("Beam", density, ncomponent << 259 new G4Material("Beam", density, ncomponents=1, 262 beam->AddMaterial(Air, fractionmass = 1.); << 260 kStateGas,temperature,pressure); >> 261 beam->AddMaterial(Air, fractionmass=1.); 263 262 264 // G4cout << *(G4Material::GetMaterialTable 263 // G4cout << *(G4Material::GetMaterialTable()) << G4endl; 265 } 264 } 266 265 267 //....oooOO0OOooo........oooOO0OOooo........oo 266 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 268 267 269 void DetectorConstruction::ComputeCalorParamet 268 void DetectorConstruction::ComputeCalorParameters() 270 { 269 { 271 // Compute derived parameters of the calorim 270 // Compute derived parameters of the calorimeter 272 fLayerThickness = 0.; << 271 LayerThickness = 0.; 273 for (G4int iAbs = 1; iAbs <= fNbOfAbsor; iAb << 272 for (G4int iAbs=1; iAbs<=NbOfAbsor; iAbs++) { 274 fLayerThickness += fAbsorThickness[iAbs]; << 273 LayerThickness += AbsorThickness[iAbs]; 275 } 274 } 276 fCalorThickness = fNbOfLayers * fLayerThickn << 275 CalorThickness = NbOfLayers*LayerThickness; 277 fWorldSizeX = 1.2 * fCalorThickness; << 276 WorldSizeX = 1.2*CalorThickness; 278 fWorldSizeYZ = 1.2 * fCalorSizeYZ; << 277 WorldSizeYZ = 1.2*CalorSizeYZ; 279 } 278 } 280 279 281 //....oooOO0OOooo........oooOO0OOooo........oo 280 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 282 281 283 G4VPhysicalVolume* DetectorConstruction::Const << 282 G4VPhysicalVolume* DetectorConstruction::ConstructCalorimeter() 284 { 283 { 285 if (fPhysiWorld) { << 286 return fPhysiWorld; << 287 } << 288 // complete the Calor parameters definition 284 // complete the Calor parameters definition 289 ComputeCalorParameters(); 285 ComputeCalorParameters(); 290 286 >> 287 // Cleanup old geometry >> 288 G4GeometryManager::GetInstance()->OpenGeometry(); >> 289 G4PhysicalVolumeStore::GetInstance()->Clean(); >> 290 G4LogicalVolumeStore::GetInstance()->Clean(); >> 291 G4SolidStore::GetInstance()->Clean(); >> 292 291 // 293 // 292 // World 294 // World 293 // 295 // 294 fSolidWorld = new G4Box("World", // its nam << 295 fWorldSizeX / 2, fWo << 296 296 297 fLogicWorld = new G4LogicalVolume(fSolidWorl << 297 solidWorld = new G4Box("World", //its name 298 fWorldMate << 298 WorldSizeX/2,WorldSizeYZ/2,WorldSizeYZ/2); //its size 299 "World"); << 299 300 << 300 logicWorld = new G4LogicalVolume(solidWorld, //its solid 301 fPhysiWorld = new G4PVPlacement(0, // no ro << 301 defaultMaterial, //its material 302 G4ThreeVecto << 302 "World"); //its name 303 fLogicWorld, << 303 304 "World", // << 304 physiWorld = new G4PVPlacement(0, //no rotation 305 0, // its m << 305 G4ThreeVector(), //at (0,0,0) 306 false, // n << 306 logicWorld, //its logical volume 307 0); // copy << 307 "World", //its name >> 308 0, //its mother volume >> 309 false, //no boolean operation >> 310 0); //copy number 308 // 311 // 309 // Calorimeter 312 // Calorimeter 310 // 313 // 311 314 312 fSolidCalor = new G4Box("Calorimeter", fCalo << 315 solidCalor = new G4Box("Calorimeter", //its name 313 << 316 CalorThickness/2,CalorSizeYZ/2,CalorSizeYZ/2);//size 314 fLogicCalor = new G4LogicalVolume(fSolidCalo << 315 317 316 fPhysiCalor = new G4PVPlacement(0, // no ro << 318 logicCalor = new G4LogicalVolume(solidCalor, //its solid 317 G4ThreeVecto << 319 defaultMaterial, //its material 318 fLogicCalor, << 320 "Calorimeter"); //its name 319 "Calorimeter << 321 320 fLogicWorld, << 322 physiCalor = new G4PVPlacement(0, //no rotation 321 false, // n << 323 G4ThreeVector(), //at (0,0,0) 322 0); // copy << 324 logicCalor, //its logical volume >> 325 "Calorimeter", //its name >> 326 logicWorld, //its mother volume >> 327 false, //no boolean operation >> 328 0); //copy number 323 329 324 // 330 // 325 // Layers 331 // Layers 326 // 332 // 327 333 328 fSolidLayer = new G4Box("Layer", fLayerThick << 334 solidLayer = new G4Box("Layer", //its name >> 335 LayerThickness/2,CalorSizeYZ/2,CalorSizeYZ/2); //size >> 336 >> 337 logicLayer = new G4LogicalVolume(solidLayer, //its solid >> 338 defaultMaterial, //its material >> 339 "Layer"); //its name >> 340 if (NbOfLayers > 1) >> 341 physiLayer = new G4PVReplica("Layer", //its name >> 342 logicLayer, //its logical volume >> 343 logicCalor, //its mother >> 344 kXAxis, //axis of replication >> 345 NbOfLayers, //number of replica >> 346 LayerThickness); //witdth of replica >> 347 else >> 348 physiLayer = new G4PVPlacement(0, //no rotation >> 349 G4ThreeVector(), //at (0,0,0) >> 350 logicLayer, //its logical volume >> 351 "Layer", //its name >> 352 logicCalor, //its mother volume >> 353 false, //no boolean operation >> 354 0); //copy number 329 355 330 fLogicLayer = new G4LogicalVolume(fSolidLaye << 331 if (fNbOfLayers > 1) { << 332 fPhysiLayer = << 333 new G4PVReplica("Layer", fLogicLayer, fL << 334 } << 335 else { << 336 fPhysiLayer = << 337 new G4PVPlacement(0, G4ThreeVector(), fL << 338 } << 339 // 356 // 340 // Absorbers 357 // Absorbers 341 // 358 // 342 359 343 G4double xfront = -0.5 * fLayerThickness; << 360 G4double xfront = -0.5*LayerThickness; 344 for (G4int k = 1; k <= fNbOfAbsor; ++k) { << 361 for (G4int k=1; k<=NbOfAbsor; k++) { 345 fSolidAbsor[k] = new G4Box("Absorber", // << 362 solidAbsor[k] = new G4Box("Absorber", //its name 346 fAbsorThickness << 363 AbsorThickness[k]/2,CalorSizeYZ/2,CalorSizeYZ/2); 347 << 364 348 fLogicAbsor[k] = new G4LogicalVolume(fSoli << 365 logicAbsor[k] = new G4LogicalVolume(solidAbsor[k], //its solid 349 fAbso << 366 AbsorMaterial[k], //its material 350 fAbso << 367 AbsorMaterial[k]->GetName()); 351 << 368 352 G4double xcenter = xfront + 0.5 * fAbsorTh << 369 G4double xcenter = xfront+0.5*AbsorThickness[k]; 353 xfront += fAbsorThickness[k]; << 370 xfront += AbsorThickness[k]; 354 fPhysiAbsor[k] = new G4PVPlacement(0, G4Th << 371 physiAbsor[k] = new G4PVPlacement(0, //no rotation 355 fAbsorM << 372 G4ThreeVector(xcenter,0.,0.), //its position 356 k); // << 373 logicAbsor[k], //its logical volume >> 374 AbsorMaterial[k]->GetName(), //its name >> 375 logicLayer, //its mother >> 376 false, //no boulean operat >> 377 k); //copy number >> 378 357 } 379 } 358 380 >> 381 359 PrintCalorParameters(); 382 PrintCalorParameters(); 360 383 361 // always return the fPhysical World << 384 //always return the physical World 362 // 385 // 363 return fPhysiWorld; << 386 return physiWorld; 364 } 387 } 365 388 366 //....oooOO0OOooo........oooOO0OOooo........oo 389 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 367 390 368 void DetectorConstruction::PrintCalorParameter 391 void DetectorConstruction::PrintCalorParameters() 369 { 392 { 370 G4cout << "\n------------------------------- 393 G4cout << "\n-------------------------------------------------------------" 371 << "\n ---> The calorimeter is " << f << 394 << "\n ---> The calorimeter is " << NbOfLayers << " layers of:"; 372 for (G4int i = 1; i <= fNbOfAbsor; ++i) { << 395 for (G4int i=1; i<=NbOfAbsor; i++) 373 G4cout << "\n \t" << std::setw(12) << fAbs << 396 { 374 << G4BestUnit(fAbsorThickness[i], " << 397 G4cout << "\n \t" << std::setw(12) << AbsorMaterial[i]->GetName() <<": " 375 } << 398 << std::setw(6) << G4BestUnit(AbsorThickness[i],"Length"); >> 399 } 376 G4cout << "\n------------------------------- 400 G4cout << "\n-------------------------------------------------------------\n"; >> 401 >> 402 G4cout << "\n" << defaultMaterial << G4endl; >> 403 for (G4int j=1; j<=NbOfAbsor; j++) >> 404 G4cout << "\n" << AbsorMaterial[j] << G4endl; 377 405 378 G4cout << "\n" << fWorldMaterial << G4endl; << 379 for (G4int j = 1; j <= fNbOfAbsor; ++j) { << 380 G4cout << "\n" << fAbsorMaterial[j] << G4e << 381 } << 382 G4cout << "\n------------------------------- 406 G4cout << "\n-------------------------------------------------------------\n"; 383 } 407 } 384 408 385 //....oooOO0OOooo........oooOO0OOooo........oo 409 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 386 410 387 void DetectorConstruction::SetWorldMaterial(co 411 void DetectorConstruction::SetWorldMaterial(const G4String& material) 388 { 412 { 389 // search the material by its name 413 // search the material by its name 390 G4Material* pttoMaterial = G4NistManager::In << 414 G4Material* pttoMaterial = 391 if (pttoMaterial) { << 415 G4NistManager::Instance()->FindOrBuildMaterial(material); 392 fWorldMaterial = pttoMaterial; << 416 if (pttoMaterial) defaultMaterial = pttoMaterial; 393 if (fLogicWorld) { << 394 fLogicWorld->SetMaterial(fWorldMaterial) << 395 fLogicLayer->SetMaterial(fWorldMaterial) << 396 G4RunManager::GetRunManager()->PhysicsHa << 397 } << 398 } << 399 } 417 } 400 418 401 //....oooOO0OOooo........oooOO0OOooo........oo 419 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 402 420 403 void DetectorConstruction::SetNbOfLayers(G4int 421 void DetectorConstruction::SetNbOfLayers(G4int ival) 404 { 422 { 405 // set the number of Layers 423 // set the number of Layers 406 // 424 // 407 if (ival < 1) { << 425 if (ival < 1) 408 G4cout << "\n --->warning from SetfNbOfLay << 426 { G4cout << "\n --->warning from SetNbOfLayers: " 409 << " must be at least 1. Command re << 427 << ival << " must be at least 1. Command refused" << G4endl; 410 return; << 428 return; 411 } << 429 } 412 fNbOfLayers = ival; << 430 NbOfLayers = ival; 413 } 431 } 414 432 415 //....oooOO0OOooo........oooOO0OOooo........oo 433 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 416 434 417 void DetectorConstruction::SetNbOfAbsor(G4int 435 void DetectorConstruction::SetNbOfAbsor(G4int ival) 418 { 436 { 419 // set the number of Absorbers 437 // set the number of Absorbers 420 // 438 // 421 if (ival < 1 || ival > (kMaxAbsor - 1)) { << 439 if (ival < 1 || ival > (MaxAbsor-1)) 422 G4cout << "\n ---> warning from SetfNbOfAb << 440 { G4cout << "\n ---> warning from SetNbOfAbsor: " 423 << kMaxAbsor - 1 << ". Command refu << 441 << ival << " must be at least 1 and and most " << MaxAbsor-1 424 return; << 442 << ". Command refused" << G4endl; 425 } << 443 return; 426 fNbOfAbsor = ival; << 444 } >> 445 NbOfAbsor = ival; 427 } 446 } 428 447 429 //....oooOO0OOooo........oooOO0OOooo........oo 448 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 430 449 431 void DetectorConstruction::SetAbsorMaterial(G4 450 void DetectorConstruction::SetAbsorMaterial(G4int ival, const G4String& material) 432 { 451 { 433 // search the material by its name 452 // search the material by its name 434 // 453 // 435 if (ival > fNbOfAbsor || ival <= 0) { << 454 if (ival > NbOfAbsor || ival <= 0) 436 G4cout << "\n --->warning from SetAbsorMat << 455 { G4cout << "\n --->warning from SetAbsorMaterial: absor number " 437 << " out of range. Command refused" << 456 << ival << " out of range. Command refused" << G4endl; 438 return; << 457 return; 439 } << 440 << 441 G4Material* pttoMaterial = G4NistManager::In << 442 if (pttoMaterial) { << 443 fAbsorMaterial[ival] = pttoMaterial; << 444 if (fLogicAbsor[ival]) { << 445 fLogicAbsor[ival]->SetMaterial(pttoMater << 446 G4RunManager::GetRunManager()->PhysicsHa << 447 } 458 } 448 } << 459 >> 460 G4Material* pttoMaterial = >> 461 G4NistManager::Instance()->FindOrBuildMaterial(material); >> 462 if (pttoMaterial) AbsorMaterial[ival] = pttoMaterial; 449 } 463 } 450 464 451 //....oooOO0OOooo........oooOO0OOooo........oo 465 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 452 466 453 void DetectorConstruction::SetAbsorThickness(G << 467 void DetectorConstruction::SetAbsorThickness(G4int ival,G4double val) 454 { 468 { 455 // change Absorber thickness 469 // change Absorber thickness 456 // 470 // 457 if (ival > fNbOfAbsor || ival <= 0) { << 471 if (ival > NbOfAbsor || ival <= 0) 458 G4cout << "\n --->warning from SetAbsorThi << 472 { G4cout << "\n --->warning from SetAbsorThickness: absor number " 459 << " out of range. Command refused" << 473 << ival << " out of range. Command refused" << G4endl; 460 return; << 474 return; 461 } << 475 } 462 if (val <= DBL_MIN) { << 476 if (val <= DBL_MIN) 463 G4cout << "\n --->warning from SetAbsorThi << 477 { G4cout << "\n --->warning from SetAbsorThickness: thickness " 464 << " out of range. Command refused" << 478 << val << " out of range. Command refused" << G4endl; 465 return; << 479 return; 466 } << 480 } 467 fAbsorThickness[ival] = val; << 481 AbsorThickness[ival] = val; 468 } 482 } 469 483 470 //....oooOO0OOooo........oooOO0OOooo........oo 484 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 471 485 472 void DetectorConstruction::SetCalorSizeYZ(G4do 486 void DetectorConstruction::SetCalorSizeYZ(G4double val) 473 { 487 { 474 // change the transverse size 488 // change the transverse size 475 // 489 // 476 if (val <= DBL_MIN) { << 490 if (val <= DBL_MIN) 477 G4cout << "\n --->warning from SetfCalorSi << 491 { G4cout << "\n --->warning from SetCalorSizeYZ: thickness " 478 << " out of range. Command refused" << 492 << val << " out of range. Command refused" << G4endl; 479 return; << 493 return; 480 } << 494 } 481 fCalorSizeYZ = val; << 495 CalorSizeYZ = val; 482 } 496 } 483 497 484 //....oooOO0OOooo........oooOO0OOooo........oo 498 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 485 499 486 #include "G4AutoDelete.hh" << 500 #include "G4FieldManager.hh" 487 #include "G4GlobalMagFieldMessenger.hh" << 501 #include "G4TransportationManager.hh" 488 502 489 void DetectorConstruction::ConstructSDandField << 503 void DetectorConstruction::SetMagField(G4double fieldValue) 490 { 504 { 491 if (fFieldMessenger.Get() == nullptr) { << 505 //apply a global uniform magnetic field along Z axis 492 // Create global magnetic field messenger. << 506 // 493 // Uniform magnetic field is then created << 507 G4FieldManager* fieldMgr 494 // the field value is not zero. << 508 = G4TransportationManager::GetTransportationManager()->GetFieldManager(); 495 G4ThreeVector fieldValue = G4ThreeVector() << 509 496 G4GlobalMagFieldMessenger* msg = new G4Glo << 510 if(magField) delete magField; //delete the existing magn field 497 // msg->SetVerboseLevel(1); << 511 498 G4AutoDelete::Register(msg); << 512 if(fieldValue!=0.) // create a new one if non nul 499 fFieldMessenger.Put(msg); << 513 { magField = new G4UniformMagField(G4ThreeVector(0.,0.,fieldValue)); >> 514 fieldMgr->SetDetectorField(magField); >> 515 fieldMgr->CreateChordFinder(magField); >> 516 } else { >> 517 magField = 0; >> 518 fieldMgr->SetDetectorField(magField); 500 } 519 } >> 520 } >> 521 >> 522 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... >> 523 >> 524 #include "G4RunManager.hh" >> 525 >> 526 void DetectorConstruction::UpdateGeometry() >> 527 { >> 528 G4RunManager::GetRunManager()->DefineWorldVolume(ConstructCalorimeter()); 501 } 529 } 502 530 503 //....oooOO0OOooo........oooOO0OOooo........oo 531 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 504 532